SlideShare a Scribd company logo
1 of 23
Chapter 3.3
Programming Fundamentals
2
Data Structures
 Arrays
 Elements are adjacent in memory (great
cache consistency)
 They never grow or get reallocated
 In C++ there's no check for going out of
bounds
 Inserting and deleting elements in the
middle is expensive
3
Data Structures
 Linked lists
 Very cheap to add/remove elements.
 Available in the STL (std::list)
 Every element is allocated separately

Lots of little allocations
 Not placed contiguously in memory
4
Data Structures
 Dictionaries
 Maps a set of keys to some data.
 std::map, std::hash, etc
 Very fast access to data
 Perfect for mapping IDs to pointers, or
resource handles to objects
5
Data Structures
 Stacks
 First in, last out
 std::stack adaptor in STL
 Queues
 First in, first out
 std::deque
6
Data Structures
 Bit packing
 Fold all necessary data into a smaller
number of bits
 Very useful for storing boolean flags

(pack 32 in a double word)
 Possible to apply to numerical values if we
can give up range or accuracy
 Very low level trick

Only use when absolutely necessary
7
Object Oriented Design
 Concepts
 Class

Abstract specification of a data type
 Instance

A region of memory with associated semantics to
store all the data members of a class
 Object

Another name for an instance of a class
8
Object Oriented Design
 Inheritance
 Models “is-a” relationship
 Extends behavior of existing classes by
making minor changes
9
Object Oriented Design
 Inheritance
 UML diagram representing inheritance
E n e m y B o s s S u p e r D u p e r B o s s
10
Object Oriented Design
 Polymorphism
 The ability to refer to an object through a
reference (or pointer) of the type of a parent
class
 Key concept of object oriented design
11
Object Oriented Design
 Multiple Inheritance
 Allows a class to have more than one base
class
 Derived class adopts characteristics of all
parent classes
 Huge potential for problems (clashes,
casting, etc)
 Multiple inheritance of abstract interfaces is
much less error prone
12
Component Systems
 Limitations of inheritance
 Tight coupling
 Unclear flow of control
 Not flexible enough
 Static hierarchy
13
Component Systems
 Component system organization
 Use aggregation (composition) instead of
inheritance
 A game entity can “own” multiple
components that determine its behavior
 Each component can execute whenever the
entity is updated
 Messages can be passed between
components and to other entities
14
Component Systems
 Component system organization
G a m e E n t i t y
N a m e = s w o r d
R e n d e r C o m p C o l l i s i o n C o m p D a m a g e C o m p P i c k u p C o m p W i e l d C o m p
15
Component Systems
 Data-Driven Composition
 The structure of the game entities can be
specified in data
 Components are created and loaded at
runtime
 Very easy to change (which is very
important in game development)
16
Component Systems
 Analysis
 Very hard to debug
 Performance can be a bottleneck
 Keeping code and data synchronized can
be a challenge
 Extremely flexible

Great for experimentation and varied gameplay
 Not very useful if problem/game is very well
known ahead of time
17
Design Patterns
 Singleton
 Implements a single instance of a class with
global point of creation and access
 Don't overuse it!!!
S i n g l e t o n
s t a t ic S in g le t o n & G e t I n s t a n c e ( ) ;
/ / R e g u la r m e m b e r f u n c t io n s . . .
s t a t ic S in g le t o n u n iq u e I n s t a n c e ;
18
Design Patterns
 Object Factory
 Creates objects by name
 Pluggable factory allows for new object
types to be registered at runtime
 Extremely useful in game development for
creating new objects, loading games, or
instantiating new content after game ships
19
Design Patterns
 Object factory
O b j e c t F a c t o r y
P r o d u c t * C r e a t e O b je c t ( P r o d u c t T y p e t y p e ) ;
C r e a t e P r o d u c t
P r o d u c t
20
Design Patterns
 Observer
 Allows objects to be notified of specific
events with minimal coupling to the source
of the event
 Two parts

subject and observer
21
Design Patterns
 Observer
S u b j e c t
A t t a c h ( O b s e r v e r * ) ;
D e t a c h ( O b s e r v e r * ) ;
N o t if y ( ) ;
O b s e r v e r
U p d a t e ( ) ;
C o n c r e t e O b s e r v e r
U p d a t e ( ) ;
C o n c r e t e S u b j e c t
22
Design Patterns
 Composite
 Allow a group of objects to be treated as a
single object
 Very useful for GUI elements, hierarchical
objects, inventory systems, etc
23
Design Patterns
 Composite
C o m p o s i t e
O p e r a t io n ( ) ;
lis t < C o m p o n e n t * > c h ild r e n
S p e c i f i c C o m p o n e n t
O p e r a t io n ( ) ;
C o m p o n e n t
O p e r a t io n ( ) ;

More Related Content

What's hot (16)

A well-typed program never goes wrong
A well-typed program never goes wrongA well-typed program never goes wrong
A well-typed program never goes wrong
 
C++ Constructor destructor
C++ Constructor destructorC++ Constructor destructor
C++ Constructor destructor
 
Writing Node.js Bindings - General Principles - Gabriel Schulhof
Writing Node.js Bindings - General Principles - Gabriel SchulhofWriting Node.js Bindings - General Principles - Gabriel Schulhof
Writing Node.js Bindings - General Principles - Gabriel Schulhof
 
Concept of constructors
Concept of constructorsConcept of constructors
Concept of constructors
 
Constructor and destructor
Constructor and destructorConstructor and destructor
Constructor and destructor
 
Constructor & Destructor
Constructor & DestructorConstructor & Destructor
Constructor & Destructor
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
04. constructor & destructor
04. constructor & destructor04. constructor & destructor
04. constructor & destructor
 
Eugene Burmako
Eugene BurmakoEugene Burmako
Eugene Burmako
 
Generics C#
Generics C#Generics C#
Generics C#
 
Structure in c
Structure in cStructure in c
Structure in c
 
C++lecture9
C++lecture9C++lecture9
C++lecture9
 
C#ppt
C#pptC#ppt
C#ppt
 
Semmle Codeql
Semmle Codeql Semmle Codeql
Semmle Codeql
 
Jvmls 2019 feedback valhalla update
Jvmls 2019 feedback   valhalla updateJvmls 2019 feedback   valhalla update
Jvmls 2019 feedback valhalla update
 
Tutconstructordes
TutconstructordesTutconstructordes
Tutconstructordes
 

Similar to 3.3 programming fundamentals

Introduction to-csharp-1229579367461426-1
Introduction to-csharp-1229579367461426-1Introduction to-csharp-1229579367461426-1
Introduction to-csharp-1229579367461426-1Sachin Singh
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharpSatish Verma
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharpvoegtu
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharpvoegtu
 
Object oriented programming using c++
Object oriented programming using c++Object oriented programming using c++
Object oriented programming using c++Hoang Nguyen
 
Event sourcing and CQRS: Lessons from the trenches
Event sourcing and CQRS: Lessons from the trenchesEvent sourcing and CQRS: Lessons from the trenches
Event sourcing and CQRS: Lessons from the trenchesDavid Jiménez Martínez
 
Forensic Memory Analysis of Android's Dalvik Virtual Machine
Forensic Memory Analysis of Android's Dalvik Virtual MachineForensic Memory Analysis of Android's Dalvik Virtual Machine
Forensic Memory Analysis of Android's Dalvik Virtual MachineSource Conference
 
Introduction to c#
Introduction to c#Introduction to c#
Introduction to c#singhadarsh
 
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)PROIDEA
 
Essentials of Multithreaded System Programming in C++
Essentials of Multithreaded System Programming in C++Essentials of Multithreaded System Programming in C++
Essentials of Multithreaded System Programming in C++Shuo Chen
 
An Introduction to Game Programming with Flash: An Introduction to Flash and ...
An Introduction to Game Programming with Flash: An Introduction to Flash and ...An Introduction to Game Programming with Flash: An Introduction to Flash and ...
An Introduction to Game Programming with Flash: An Introduction to Flash and ...Krzysztof Opałka
 
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Ovidiu Farauanu
 
the productive programer: mechanics
the productive programer: mechanicsthe productive programer: mechanics
the productive programer: mechanicselliando dias
 
Beware of Pointers
Beware of PointersBeware of Pointers
Beware of Pointersppd1961
 
Kid171 chap02 english version
Kid171 chap02 english versionKid171 chap02 english version
Kid171 chap02 english versionFrank S.C. Tseng
 
3.4 game architecture
3.4 game architecture3.4 game architecture
3.4 game architectureSayed Ahmed
 
Skiron - Experiments in CPU Design in D
Skiron - Experiments in CPU Design in DSkiron - Experiments in CPU Design in D
Skiron - Experiments in CPU Design in DMithun Hunsur
 

Similar to 3.3 programming fundamentals (20)

Introduction to-csharp-1229579367461426-1
Introduction to-csharp-1229579367461426-1Introduction to-csharp-1229579367461426-1
Introduction to-csharp-1229579367461426-1
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharp
 
Scope Stack Allocation
Scope Stack AllocationScope Stack Allocation
Scope Stack Allocation
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharp
 
Introduction to csharp
Introduction to csharpIntroduction to csharp
Introduction to csharp
 
Object oriented programming using c++
Object oriented programming using c++Object oriented programming using c++
Object oriented programming using c++
 
Event sourcing and CQRS: Lessons from the trenches
Event sourcing and CQRS: Lessons from the trenchesEvent sourcing and CQRS: Lessons from the trenches
Event sourcing and CQRS: Lessons from the trenches
 
Forensic Memory Analysis of Android's Dalvik Virtual Machine
Forensic Memory Analysis of Android's Dalvik Virtual MachineForensic Memory Analysis of Android's Dalvik Virtual Machine
Forensic Memory Analysis of Android's Dalvik Virtual Machine
 
Lecture-05-DSA
Lecture-05-DSALecture-05-DSA
Lecture-05-DSA
 
Introduction to c#
Introduction to c#Introduction to c#
Introduction to c#
 
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
 
Essentials of Multithreaded System Programming in C++
Essentials of Multithreaded System Programming in C++Essentials of Multithreaded System Programming in C++
Essentials of Multithreaded System Programming in C++
 
An Introduction to Game Programming with Flash: An Introduction to Flash and ...
An Introduction to Game Programming with Flash: An Introduction to Flash and ...An Introduction to Game Programming with Flash: An Introduction to Flash and ...
An Introduction to Game Programming with Flash: An Introduction to Flash and ...
 
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
Functional Patterns for C++ Multithreading (C++ Dev Meetup Iasi)
 
the productive programer: mechanics
the productive programer: mechanicsthe productive programer: mechanics
the productive programer: mechanics
 
Lect1.pptx
Lect1.pptxLect1.pptx
Lect1.pptx
 
Beware of Pointers
Beware of PointersBeware of Pointers
Beware of Pointers
 
Kid171 chap02 english version
Kid171 chap02 english versionKid171 chap02 english version
Kid171 chap02 english version
 
3.4 game architecture
3.4 game architecture3.4 game architecture
3.4 game architecture
 
Skiron - Experiments in CPU Design in D
Skiron - Experiments in CPU Design in DSkiron - Experiments in CPU Design in D
Skiron - Experiments in CPU Design in D
 

More from Sayed Ahmed

Workplace, Data Analytics, and Ethics
Workplace, Data Analytics, and EthicsWorkplace, Data Analytics, and Ethics
Workplace, Data Analytics, and EthicsSayed Ahmed
 
Python py charm anaconda jupyter installation and basic commands
Python py charm anaconda jupyter   installation and basic commandsPython py charm anaconda jupyter   installation and basic commands
Python py charm anaconda jupyter installation and basic commandsSayed Ahmed
 
[not edited] Demo on mobile app development using ionic framework
[not edited] Demo on mobile app development using ionic framework[not edited] Demo on mobile app development using ionic framework
[not edited] Demo on mobile app development using ionic frameworkSayed Ahmed
 
Sap hana-ide-overview-nodev
Sap hana-ide-overview-nodevSap hana-ide-overview-nodev
Sap hana-ide-overview-nodevSayed Ahmed
 
Will be an introduction to
Will be an introduction toWill be an introduction to
Will be an introduction toSayed Ahmed
 
Whm and cpanel overview hosting control panel overview
Whm and cpanel overview   hosting control panel overviewWhm and cpanel overview   hosting control panel overview
Whm and cpanel overview hosting control panel overviewSayed Ahmed
 
Web application development using zend framework
Web application development using zend frameworkWeb application development using zend framework
Web application development using zend frameworkSayed Ahmed
 
Web design and_html_part_3
Web design and_html_part_3Web design and_html_part_3
Web design and_html_part_3Sayed Ahmed
 
Web design and_html_part_2
Web design and_html_part_2Web design and_html_part_2
Web design and_html_part_2Sayed Ahmed
 
Web design and_html
Web design and_htmlWeb design and_html
Web design and_htmlSayed Ahmed
 
Visual studio ide shortcuts
Visual studio ide shortcutsVisual studio ide shortcuts
Visual studio ide shortcutsSayed Ahmed
 
Unit tests in_symfony
Unit tests in_symfonyUnit tests in_symfony
Unit tests in_symfonySayed Ahmed
 
Telerik this is sayed
Telerik this is sayedTelerik this is sayed
Telerik this is sayedSayed Ahmed
 
System analysis and_design
System analysis and_designSystem analysis and_design
System analysis and_designSayed Ahmed
 
Story telling and_narrative
Story telling and_narrativeStory telling and_narrative
Story telling and_narrativeSayed Ahmed
 

More from Sayed Ahmed (20)

Workplace, Data Analytics, and Ethics
Workplace, Data Analytics, and EthicsWorkplace, Data Analytics, and Ethics
Workplace, Data Analytics, and Ethics
 
Python py charm anaconda jupyter installation and basic commands
Python py charm anaconda jupyter   installation and basic commandsPython py charm anaconda jupyter   installation and basic commands
Python py charm anaconda jupyter installation and basic commands
 
[not edited] Demo on mobile app development using ionic framework
[not edited] Demo on mobile app development using ionic framework[not edited] Demo on mobile app development using ionic framework
[not edited] Demo on mobile app development using ionic framework
 
Sap hana-ide-overview-nodev
Sap hana-ide-overview-nodevSap hana-ide-overview-nodev
Sap hana-ide-overview-nodev
 
Invest wisely
Invest wiselyInvest wisely
Invest wisely
 
Will be an introduction to
Will be an introduction toWill be an introduction to
Will be an introduction to
 
Whm and cpanel overview hosting control panel overview
Whm and cpanel overview   hosting control panel overviewWhm and cpanel overview   hosting control panel overview
Whm and cpanel overview hosting control panel overview
 
Web application development using zend framework
Web application development using zend frameworkWeb application development using zend framework
Web application development using zend framework
 
Web design and_html_part_3
Web design and_html_part_3Web design and_html_part_3
Web design and_html_part_3
 
Web design and_html_part_2
Web design and_html_part_2Web design and_html_part_2
Web design and_html_part_2
 
Web design and_html
Web design and_htmlWeb design and_html
Web design and_html
 
Visual studio ide shortcuts
Visual studio ide shortcutsVisual studio ide shortcuts
Visual studio ide shortcuts
 
Virtualization
VirtualizationVirtualization
Virtualization
 
User interfaces
User interfacesUser interfaces
User interfaces
 
Unreal
UnrealUnreal
Unreal
 
Unit tests in_symfony
Unit tests in_symfonyUnit tests in_symfony
Unit tests in_symfony
 
Telerik this is sayed
Telerik this is sayedTelerik this is sayed
Telerik this is sayed
 
System analysis and_design
System analysis and_designSystem analysis and_design
System analysis and_design
 
Symfony 2
Symfony 2Symfony 2
Symfony 2
 
Story telling and_narrative
Story telling and_narrativeStory telling and_narrative
Story telling and_narrative
 

Recently uploaded

Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 

Recently uploaded (20)

Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 

3.3 programming fundamentals

  • 2. 2 Data Structures  Arrays  Elements are adjacent in memory (great cache consistency)  They never grow or get reallocated  In C++ there's no check for going out of bounds  Inserting and deleting elements in the middle is expensive
  • 3. 3 Data Structures  Linked lists  Very cheap to add/remove elements.  Available in the STL (std::list)  Every element is allocated separately  Lots of little allocations  Not placed contiguously in memory
  • 4. 4 Data Structures  Dictionaries  Maps a set of keys to some data.  std::map, std::hash, etc  Very fast access to data  Perfect for mapping IDs to pointers, or resource handles to objects
  • 5. 5 Data Structures  Stacks  First in, last out  std::stack adaptor in STL  Queues  First in, first out  std::deque
  • 6. 6 Data Structures  Bit packing  Fold all necessary data into a smaller number of bits  Very useful for storing boolean flags  (pack 32 in a double word)  Possible to apply to numerical values if we can give up range or accuracy  Very low level trick  Only use when absolutely necessary
  • 7. 7 Object Oriented Design  Concepts  Class  Abstract specification of a data type  Instance  A region of memory with associated semantics to store all the data members of a class  Object  Another name for an instance of a class
  • 8. 8 Object Oriented Design  Inheritance  Models “is-a” relationship  Extends behavior of existing classes by making minor changes
  • 9. 9 Object Oriented Design  Inheritance  UML diagram representing inheritance E n e m y B o s s S u p e r D u p e r B o s s
  • 10. 10 Object Oriented Design  Polymorphism  The ability to refer to an object through a reference (or pointer) of the type of a parent class  Key concept of object oriented design
  • 11. 11 Object Oriented Design  Multiple Inheritance  Allows a class to have more than one base class  Derived class adopts characteristics of all parent classes  Huge potential for problems (clashes, casting, etc)  Multiple inheritance of abstract interfaces is much less error prone
  • 12. 12 Component Systems  Limitations of inheritance  Tight coupling  Unclear flow of control  Not flexible enough  Static hierarchy
  • 13. 13 Component Systems  Component system organization  Use aggregation (composition) instead of inheritance  A game entity can “own” multiple components that determine its behavior  Each component can execute whenever the entity is updated  Messages can be passed between components and to other entities
  • 14. 14 Component Systems  Component system organization G a m e E n t i t y N a m e = s w o r d R e n d e r C o m p C o l l i s i o n C o m p D a m a g e C o m p P i c k u p C o m p W i e l d C o m p
  • 15. 15 Component Systems  Data-Driven Composition  The structure of the game entities can be specified in data  Components are created and loaded at runtime  Very easy to change (which is very important in game development)
  • 16. 16 Component Systems  Analysis  Very hard to debug  Performance can be a bottleneck  Keeping code and data synchronized can be a challenge  Extremely flexible  Great for experimentation and varied gameplay  Not very useful if problem/game is very well known ahead of time
  • 17. 17 Design Patterns  Singleton  Implements a single instance of a class with global point of creation and access  Don't overuse it!!! S i n g l e t o n s t a t ic S in g le t o n & G e t I n s t a n c e ( ) ; / / R e g u la r m e m b e r f u n c t io n s . . . s t a t ic S in g le t o n u n iq u e I n s t a n c e ;
  • 18. 18 Design Patterns  Object Factory  Creates objects by name  Pluggable factory allows for new object types to be registered at runtime  Extremely useful in game development for creating new objects, loading games, or instantiating new content after game ships
  • 19. 19 Design Patterns  Object factory O b j e c t F a c t o r y P r o d u c t * C r e a t e O b je c t ( P r o d u c t T y p e t y p e ) ; C r e a t e P r o d u c t P r o d u c t
  • 20. 20 Design Patterns  Observer  Allows objects to be notified of specific events with minimal coupling to the source of the event  Two parts  subject and observer
  • 21. 21 Design Patterns  Observer S u b j e c t A t t a c h ( O b s e r v e r * ) ; D e t a c h ( O b s e r v e r * ) ; N o t if y ( ) ; O b s e r v e r U p d a t e ( ) ; C o n c r e t e O b s e r v e r U p d a t e ( ) ; C o n c r e t e S u b j e c t
  • 22. 22 Design Patterns  Composite  Allow a group of objects to be treated as a single object  Very useful for GUI elements, hierarchical objects, inventory systems, etc
  • 23. 23 Design Patterns  Composite C o m p o s i t e O p e r a t io n ( ) ; lis t < C o m p o n e n t * > c h ild r e n S p e c i f i c C o m p o n e n t O p e r a t io n ( ) ; C o m p o n e n t O p e r a t io n ( ) ;