SlideShare ist ein Scribd-Unternehmen logo
1 von 31
Globalcode – Open4education
Design Patterns in Game Programming
Bruno Cicanci
Senior Software Engineer @ Aquiris Game Studio
Globalcode – Open4education
Agenda
Who am I?
Design Patterns
Other Patterns
Software Architecture
Globalcode – Open4education
Who am I?
Bruno Cicanci (@cicanci)
Senior Software Engineer at Aquiris Game Studio
14+ years as a professional programmer
9+ years working with mobile games
20+ games developed
10+ years blogging: gamedeveloper.com.br
Globalcode – Open4education
Design Patterns
Command
Flyweight
Observer
Prototype
Singleton
State
Globalcode – Open4education
Command: The problem
void InputHandler::handleInput()
{
if (isPressed(BUTTON_X)) jump();
else if (isPressed(BUTTON_Y)) fireGun();
else if (isPressed(BUTTON_A)) swapWeapon();
else if (isPressed(BUTTON_B)) reloadWeapon();
}
https://gameprogrammingpatterns.com/command.html
Globalcode – Open4education
Command: The solution
class Command
{
public:
virtual ~Command() {}
virtual void execute() = 0;
};
class JumpCommand : public Command
{
public:
virtual void execute() { jump(); }
};
void InputHandler::handleInput()
{
if (isPressed(BUTTON_X))
buttonX_->execute();
else if (isPressed(BUTTON_Y))
buttonY_->execute();
else if (isPressed(BUTTON_A))
buttonA_->execute();
else if (isPressed(BUTTON_B))
buttonB_->execute();
}
https://gameprogrammingpatterns.com/command.html
Globalcode – Open4education
Command: The usage
Input
Undo
Redo
https://gameprogrammingpatterns.com/command.html
Globalcode – Open4education
Flyweight: The problem
class Tree
{
private:
Mesh mesh_;
Texture bark_;
Texture leaves_;
Vector position_;
double height_;
double thickness_;
Color barkTint_;
Color leafTint_;
};
https://gameprogrammingpatterns.com/flyweight.html
Globalcode – Open4education
Flyweight: The solution
class TreeModel
{
private:
Mesh mesh_;
Texture bark_;
Texture leaves_;
};
class Tree
{
private:
TreeModel* model_;
Vector position_;
double height_;
double thickness_;
Color barkTint_;
Color leafTint_;
};
https://gameprogrammingpatterns.com/flyweight.html
Globalcode – Open4education
Flyweight: The usage
Multiple instances
Tile maps
https://gameprogrammingpatterns.com/flyweight.html
Globalcode – Open4education
Observer: The problem
void Physics::updateEntity(Entity& entity)
{
bool wasOnSurface = entity.isOnSurface();
entity.accelerate(GRAVITY);
entity.update();
if (wasOnSurface && !entity.isOnSurface() && entity.isHero())
{
unlockFallOffBridge();
}
}
https://gameprogrammingpatterns.com/observer.html
Globalcode – Open4education
Observer: The solution (1)
class Observer
{
public:
virtual ~Observer() {}
virtual void onNotify(const Entity& entity, Event
event) = 0;
};
class Achievements : public Observer
{
public:
virtual void onNotify(const Entity& entity, Event event)
{
switch (event)
{
case EVENT_ENTITY_FELL:
if (entity.isHero())
{
unlock(ACHIEVEMENT_FELL_OFF_BRIDGE);
}
break;
}
}
private:
void unlock(Achievement achievement) { }
};
https://gameprogrammingpatterns.com/observer.html
Globalcode – Open4education
Observer: The solution (2)
class Subject
{
private:
Observer* observers[MAX_OBSERVERS];
int numObservers;
protected:
void notify(const Entity& entity, Event event)
{
for (int i = 0; i < numObservers; i++)
{
observers[i]->onNotify(entity, event);
}
}
public:
void addObserver(Observer* observer) { }
void removeObserver(Observer* observer) { }
};
class Physics : public Subject
{
public:
void updateEntity(Entity& entity);
{
bool wasOnSurface = entity.isOnSurface();
entity.accelerate(GRAVITY);
entity.update();
if (wasOnSurface && !entity.isOnSurface())
{
notify(entity, EVENT_START_FALL);
}
}
};
https://gameprogrammingpatterns.com/observer.html
Globalcode – Open4education
Observer: The usage
Achievements
VFX/SFX
Events
Messages
Callbacks async
https://gameprogrammingpatterns.com/observer.html
Globalcode – Open4education
Prototype: The problem
class Monster { };
class Ghost : public Monster {};
class Demon : public Monster {};
class Sorcerer : public Monster {};
class Spawner
{
public:
virtual ~Spawner() {}
virtual Monster* spawnMonster() = 0;
};
class GhostSpawner : public Spawner
{
public:
virtual Monster* spawnMonster()
{
return new Ghost();
}
};
...
https://gameprogrammingpatterns.com/prototype.html
Globalcode – Open4education
Prototype: The solution (1)
class Monster
{
public:
virtual ~Monster() {}
virtual Monster* clone() = 0;
};
class Ghost : public Monster {
public:
Ghost(int health, int speed)
: health_(health), speed_(speed)
{}
virtual Monster* clone()
{
return new Ghost(health_, speed_);
}
private:
int health_;
int speed_;
}
https://gameprogrammingpatterns.com/prototype.html
Globalcode – Open4education
Prototype: The solution (2)
class Spawner
{
public:
Spawner(Monster* prototype)
: prototype_(prototype)
{}
Monster* spawnMonster()
{
return prototype_->clone();
}
private:
Monster* prototype_;
};
https://gameprogrammingpatterns.com/prototype.html
Globalcode – Open4education
Prototype: The usage
Spawner
Player Items
Shoots
Loot
https://gameprogrammingpatterns.com/prototype.html
Globalcode – Open4education
States: The problem
void Heroine::handleInput(Input input)
{
if (input == PRESS_B)
{
if (!isJumping_ && !isDucking_)
{
// Jump...
}
}
else if (input == PRESS_DOWN)
{
if (!isJumping_)
{
isDucking_ = true;
}
}
else if (input == RELEASE_DOWN)
{
if (isDucking_)
{
isDucking_ = false;
}
}
}
https://gameprogrammingpatterns.com/state.html
Globalcode – Open4education
States: The solution
void Heroine::handleInput(Input input)
{
switch (state_)
{
case STATE_STANDING:
if (input == PRESS_B)
{
state_ = STATE_JUMPING;
}
else if (input == PRESS_DOWN)
{
state_ = STATE_DUCKING;
}
break;
case STATE_JUMPING:
if (input == PRESS_DOWN)
{
state_ = STATE_DIVING;
}
break;
case STATE_DUCKING:
if (input == RELEASE_DOWN)
{
state_ = STATE_STANDING;
}
break;
}
}
https://gameprogrammingpatterns.com/state.html
Globalcode – Open4education
States: The usage
Animations
Screen states
Character actions
https://gameprogrammingpatterns.com/state.html
Globalcode – Open4education
Singleton: The problem
Ensure that only one instance of the singleton class ever exists;
and provide global access to that instance.
Gang of Four, Design Patterns
https://gameprogrammingpatterns.com/singleton.html
Globalcode – Open4education
Singleton: The solution
class FileSystem
{
public:
static FileSystem& instance()
{
if (instance_ == NULL) instance_ = new FileSystem();
return *instance_;
}
private:
FileSystem() {}
static FileSystem* instance_;
};
https://gameprogrammingpatterns.com/singleton.html
Globalcode – Open4education
Singleton: The usage
“Friends don’t let friends create singletons.”
Robert Nystrom, Game Programming Patterns
https://gameprogrammingpatterns.com/singleton.html
Globalcode – Open4education
Other Patterns
Sequencing Patterns
Double Buffer
Game Loop
Update Method
Behavioral Patterns
Bytecode
Subclass Sandbox
Type Object
Decoupling Patterns
Component
Event Queue
Service Locator
Optimization Patterns
Data Locality
Dirty Flag
Object Pool
Spatial Partition
https://gameprogrammingpatterns.com
Globalcode – Open4education
Game Programming Patterns
gameprogrammingpatterns.com
Globalcode – Open4education
Software Architecture
It is not about making diagrams
It is about solving problems
… and communicating the solution!
K.I.S.S.
Occam's razor
Less is more
Globalcode – Open4education
SOLID Principles
Single Responsibility
Open/Closed
Liskov Substitution
Interface Segregation
Dependency Inversion
https://devopedia.org/solid-design-principles
gamedeveloper.com.br ggdevcast.com.br
aquiris.com.br/work-with-us
Obrigado!

Weitere ähnliche Inhalte

Was ist angesagt?

Puppeteer can automate that! - Frontmania
Puppeteer can automate that! - FrontmaniaPuppeteer can automate that! - Frontmania
Puppeteer can automate that! - FrontmaniaÖnder Ceylan
 
UX UI para Programadores
UX UI para Programadores UX UI para Programadores
UX UI para Programadores Monica Mesquita
 
Full Stack Vs Mean Stack Vs MERN Stack Comparison & Benefits
Full Stack Vs Mean Stack Vs MERN Stack Comparison & BenefitsFull Stack Vs Mean Stack Vs MERN Stack Comparison & Benefits
Full Stack Vs Mean Stack Vs MERN Stack Comparison & BenefitsAvya Technology Pvt. Ltd.
 
Web development with Python
Web development with PythonWeb development with Python
Web development with PythonRaman Balyan
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsVikash Singh
 
Presentation on mini dictionary using C language
Presentation on  mini dictionary using C languagePresentation on  mini dictionary using C language
Presentation on mini dictionary using C languagePriya Yadav
 
Detecting headless browsers
Detecting headless browsersDetecting headless browsers
Detecting headless browsersSergey Shekyan
 
Visual Basic Programming
Visual Basic ProgrammingVisual Basic Programming
Visual Basic ProgrammingOsama Yaseen
 
Text analytics in social media
Text analytics in social mediaText analytics in social media
Text analytics in social mediaJeremiah Fadugba
 
Introduction to MERN Stack
Introduction to MERN StackIntroduction to MERN Stack
Introduction to MERN StackSurya937648
 
Dictionary project report.docx
Dictionary project report.docxDictionary project report.docx
Dictionary project report.docxkishoreadhikari2
 
PROPOSAL FOR A STUDENT REPOSITORY PROJECT
PROPOSAL FOR A STUDENT REPOSITORY PROJECTPROPOSAL FOR A STUDENT REPOSITORY PROJECT
PROPOSAL FOR A STUDENT REPOSITORY PROJECTSamuel Nengolong
 

Was ist angesagt? (20)

Puppeteer can automate that! - Frontmania
Puppeteer can automate that! - FrontmaniaPuppeteer can automate that! - Frontmania
Puppeteer can automate that! - Frontmania
 
UX UI para Programadores
UX UI para Programadores UX UI para Programadores
UX UI para Programadores
 
Complexity in array
Complexity in arrayComplexity in array
Complexity in array
 
Full Stack Vs Mean Stack Vs MERN Stack Comparison & Benefits
Full Stack Vs Mean Stack Vs MERN Stack Comparison & BenefitsFull Stack Vs Mean Stack Vs MERN Stack Comparison & Benefits
Full Stack Vs Mean Stack Vs MERN Stack Comparison & Benefits
 
Web development with Python
Web development with PythonWeb development with Python
Web development with Python
 
Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
Introduction To C#
Introduction To C#Introduction To C#
Introduction To C#
 
Android UI
Android UIAndroid UI
Android UI
 
Presentation on mini dictionary using C language
Presentation on  mini dictionary using C languagePresentation on  mini dictionary using C language
Presentation on mini dictionary using C language
 
Python Interpreter.pdf
Python Interpreter.pdfPython Interpreter.pdf
Python Interpreter.pdf
 
Detecting headless browsers
Detecting headless browsersDetecting headless browsers
Detecting headless browsers
 
Java rmi
Java rmiJava rmi
Java rmi
 
Visual Basic Programming
Visual Basic ProgrammingVisual Basic Programming
Visual Basic Programming
 
Data science
Data scienceData science
Data science
 
Text analytics in social media
Text analytics in social mediaText analytics in social media
Text analytics in social media
 
Introduction to MERN Stack
Introduction to MERN StackIntroduction to MERN Stack
Introduction to MERN Stack
 
Dictionary project report.docx
Dictionary project report.docxDictionary project report.docx
Dictionary project report.docx
 
real.pdf
real.pdfreal.pdf
real.pdf
 
PROPOSAL FOR A STUDENT REPOSITORY PROJECT
PROPOSAL FOR A STUDENT REPOSITORY PROJECTPROPOSAL FOR A STUDENT REPOSITORY PROJECT
PROPOSAL FOR A STUDENT REPOSITORY PROJECT
 
Project report
Project reportProject report
Project report
 

Ähnlich wie Design Patterns in Game Programming

Programação de Jogos - Design Patterns
Programação de Jogos - Design PatternsProgramação de Jogos - Design Patterns
Programação de Jogos - Design PatternsBruno Cicanci
 
[Droidcon Paris 2013]Multi-Versioning Android Tips
[Droidcon Paris 2013]Multi-Versioning Android Tips[Droidcon Paris 2013]Multi-Versioning Android Tips
[Droidcon Paris 2013]Multi-Versioning Android TipsKenichi Kambara
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerGarth Gilmour
 
Adding Love to an API (or How to Expose C++ in Unity)
Adding Love to an API (or How to Expose C++ in Unity)Adding Love to an API (or How to Expose C++ in Unity)
Adding Love to an API (or How to Expose C++ in Unity)Unity Technologies
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerGarth Gilmour
 
Core Java Meetup #9 - Quiz Questions - 6th May
Core Java Meetup #9 - Quiz Questions - 6th MayCore Java Meetup #9 - Quiz Questions - 6th May
Core Java Meetup #9 - Quiz Questions - 6th MayCodeOps Technologies LLP
 
School For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine BasicsSchool For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine BasicsNick Pruehs
 
Controlando windows like a boss com Intel Real Sense SDK
Controlando windows like a boss com Intel Real Sense SDKControlando windows like a boss com Intel Real Sense SDK
Controlando windows like a boss com Intel Real Sense SDKAndre Carlucci
 
A split screen-viable UI event system - Unite Copenhagen 2019
A split screen-viable UI event system - Unite Copenhagen 2019A split screen-viable UI event system - Unite Copenhagen 2019
A split screen-viable UI event system - Unite Copenhagen 2019Unity Technologies
 
Android Code Puzzles (DroidCon Amsterdam 2012)
Android Code Puzzles (DroidCon Amsterdam 2012)Android Code Puzzles (DroidCon Amsterdam 2012)
Android Code Puzzles (DroidCon Amsterdam 2012)Danny Preussler
 
C# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewC# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewPaulo Morgado
 
Rapid prototyping with ScriptableObjects
Rapid prototyping with ScriptableObjectsRapid prototyping with ScriptableObjects
Rapid prototyping with ScriptableObjectsGiorgio Pomettini
 
.Net december 2017 updates - Tamir Dresher
.Net december 2017 updates - Tamir Dresher.Net december 2017 updates - Tamir Dresher
.Net december 2017 updates - Tamir DresherTamir Dresher
 
Antidebugging eu não quero que você mexa no meu código
Antidebugging   eu não quero que você mexa no meu códigoAntidebugging   eu não quero que você mexa no meu código
Antidebugging eu não quero que você mexa no meu códigoWanderley Caloni
 
Csise15 codehunt
Csise15 codehuntCsise15 codehunt
Csise15 codehuntTao Xie
 

Ähnlich wie Design Patterns in Game Programming (20)

Programação de Jogos - Design Patterns
Programação de Jogos - Design PatternsProgramação de Jogos - Design Patterns
Programação de Jogos - Design Patterns
 
Unity3D Programming
Unity3D ProgrammingUnity3D Programming
Unity3D Programming
 
[Droidcon Paris 2013]Multi-Versioning Android Tips
[Droidcon Paris 2013]Multi-Versioning Android Tips[Droidcon Paris 2013]Multi-Versioning Android Tips
[Droidcon Paris 2013]Multi-Versioning Android Tips
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
 
Adding Love to an API (or How to Expose C++ in Unity)
Adding Love to an API (or How to Expose C++ in Unity)Adding Love to an API (or How to Expose C++ in Unity)
Adding Love to an API (or How to Expose C++ in Unity)
 
Lies Told By The Kotlin Compiler
Lies Told By The Kotlin CompilerLies Told By The Kotlin Compiler
Lies Told By The Kotlin Compiler
 
Modern c++
Modern c++Modern c++
Modern c++
 
Core Java Meetup #9 - Quiz Questions - 6th May
Core Java Meetup #9 - Quiz Questions - 6th MayCore Java Meetup #9 - Quiz Questions - 6th May
Core Java Meetup #9 - Quiz Questions - 6th May
 
School For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine BasicsSchool For Games 2015 - Unity Engine Basics
School For Games 2015 - Unity Engine Basics
 
Controlando windows like a boss com Intel Real Sense SDK
Controlando windows like a boss com Intel Real Sense SDKControlando windows like a boss com Intel Real Sense SDK
Controlando windows like a boss com Intel Real Sense SDK
 
A split screen-viable UI event system - Unite Copenhagen 2019
A split screen-viable UI event system - Unite Copenhagen 2019A split screen-viable UI event system - Unite Copenhagen 2019
A split screen-viable UI event system - Unite Copenhagen 2019
 
Android Code Puzzles (DroidCon Amsterdam 2012)
Android Code Puzzles (DroidCon Amsterdam 2012)Android Code Puzzles (DroidCon Amsterdam 2012)
Android Code Puzzles (DroidCon Amsterdam 2012)
 
Unity3 d devfest-2014
Unity3 d devfest-2014Unity3 d devfest-2014
Unity3 d devfest-2014
 
C# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewC# 6.0 - April 2014 preview
C# 6.0 - April 2014 preview
 
Rapid prototyping with ScriptableObjects
Rapid prototyping with ScriptableObjectsRapid prototyping with ScriptableObjects
Rapid prototyping with ScriptableObjects
 
.Net december 2017 updates - Tamir Dresher
.Net december 2017 updates - Tamir Dresher.Net december 2017 updates - Tamir Dresher
.Net december 2017 updates - Tamir Dresher
 
Antidebugging eu não quero que você mexa no meu código
Antidebugging   eu não quero que você mexa no meu códigoAntidebugging   eu não quero que você mexa no meu código
Antidebugging eu não quero que você mexa no meu código
 
Csise15 codehunt
Csise15 codehuntCsise15 codehunt
Csise15 codehunt
 
Tech Gig Webex26.03.2012
Tech Gig Webex26.03.2012Tech Gig Webex26.03.2012
Tech Gig Webex26.03.2012
 
Introduction to-java
Introduction to-javaIntroduction to-java
Introduction to-java
 

Mehr von Bruno Cicanci

Optimizing Unity games for mobile devices
Optimizing Unity games for mobile devicesOptimizing Unity games for mobile devices
Optimizing Unity games for mobile devicesBruno Cicanci
 
It's all about the game
It's all about the gameIt's all about the game
It's all about the gameBruno Cicanci
 
Game Jams - Como fazer um jogo em 48 horas
Game Jams - Como fazer um jogo em 48 horasGame Jams - Como fazer um jogo em 48 horas
Game Jams - Como fazer um jogo em 48 horasBruno Cicanci
 
Design Patterns na Programação de Jogo
Design Patterns na Programação de JogoDesign Patterns na Programação de Jogo
Design Patterns na Programação de JogoBruno Cicanci
 
It’s all about the game
It’s all about the gameIt’s all about the game
It’s all about the gameBruno Cicanci
 
Desenvolvimento de Jogos com Corona SDK
Desenvolvimento de Jogos com Corona SDKDesenvolvimento de Jogos com Corona SDK
Desenvolvimento de Jogos com Corona SDKBruno Cicanci
 
Desenvolvimento de jogos com Cocos2d-x
Desenvolvimento de jogos com Cocos2d-xDesenvolvimento de jogos com Cocos2d-x
Desenvolvimento de jogos com Cocos2d-xBruno Cicanci
 
TDC 2012 - Desenvolvimento de Jogos Mobile
TDC 2012 - Desenvolvimento de Jogos MobileTDC 2012 - Desenvolvimento de Jogos Mobile
TDC 2012 - Desenvolvimento de Jogos MobileBruno Cicanci
 
Desenvolvimento de Jogos Para Dispositivos Móveis - UFRJ - GECOM2011
Desenvolvimento de Jogos Para Dispositivos Móveis - UFRJ - GECOM2011Desenvolvimento de Jogos Para Dispositivos Móveis - UFRJ - GECOM2011
Desenvolvimento de Jogos Para Dispositivos Móveis - UFRJ - GECOM2011Bruno Cicanci
 

Mehr von Bruno Cicanci (9)

Optimizing Unity games for mobile devices
Optimizing Unity games for mobile devicesOptimizing Unity games for mobile devices
Optimizing Unity games for mobile devices
 
It's all about the game
It's all about the gameIt's all about the game
It's all about the game
 
Game Jams - Como fazer um jogo em 48 horas
Game Jams - Como fazer um jogo em 48 horasGame Jams - Como fazer um jogo em 48 horas
Game Jams - Como fazer um jogo em 48 horas
 
Design Patterns na Programação de Jogo
Design Patterns na Programação de JogoDesign Patterns na Programação de Jogo
Design Patterns na Programação de Jogo
 
It’s all about the game
It’s all about the gameIt’s all about the game
It’s all about the game
 
Desenvolvimento de Jogos com Corona SDK
Desenvolvimento de Jogos com Corona SDKDesenvolvimento de Jogos com Corona SDK
Desenvolvimento de Jogos com Corona SDK
 
Desenvolvimento de jogos com Cocos2d-x
Desenvolvimento de jogos com Cocos2d-xDesenvolvimento de jogos com Cocos2d-x
Desenvolvimento de jogos com Cocos2d-x
 
TDC 2012 - Desenvolvimento de Jogos Mobile
TDC 2012 - Desenvolvimento de Jogos MobileTDC 2012 - Desenvolvimento de Jogos Mobile
TDC 2012 - Desenvolvimento de Jogos Mobile
 
Desenvolvimento de Jogos Para Dispositivos Móveis - UFRJ - GECOM2011
Desenvolvimento de Jogos Para Dispositivos Móveis - UFRJ - GECOM2011Desenvolvimento de Jogos Para Dispositivos Móveis - UFRJ - GECOM2011
Desenvolvimento de Jogos Para Dispositivos Móveis - UFRJ - GECOM2011
 

Kürzlich hochgeladen

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVshikhaohhpro
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfCionsystems
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfkalichargn70th171
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionSolGuruz
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendArshad QA
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsAndolasoft Inc
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 

Kürzlich hochgeladen (20)

Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Active Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdfActive Directory Penetration Testing, cionsystems.com.pdf
Active Directory Penetration Testing, cionsystems.com.pdf
 
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdfThe Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
The Essentials of Digital Experience Monitoring_ A Comprehensive Guide.pdf
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 
Test Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and BackendTest Automation Strategy for Frontend and Backend
Test Automation Strategy for Frontend and Backend
 
How To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.jsHow To Use Server-Side Rendering with Nuxt.js
How To Use Server-Side Rendering with Nuxt.js
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
Exploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the ProcessExploring iOS App Development: Simplifying the Process
Exploring iOS App Development: Simplifying the Process
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 

Design Patterns in Game Programming

  • 1. Globalcode – Open4education Design Patterns in Game Programming Bruno Cicanci Senior Software Engineer @ Aquiris Game Studio
  • 2. Globalcode – Open4education Agenda Who am I? Design Patterns Other Patterns Software Architecture
  • 3. Globalcode – Open4education Who am I? Bruno Cicanci (@cicanci) Senior Software Engineer at Aquiris Game Studio 14+ years as a professional programmer 9+ years working with mobile games 20+ games developed 10+ years blogging: gamedeveloper.com.br
  • 4. Globalcode – Open4education Design Patterns Command Flyweight Observer Prototype Singleton State
  • 5. Globalcode – Open4education Command: The problem void InputHandler::handleInput() { if (isPressed(BUTTON_X)) jump(); else if (isPressed(BUTTON_Y)) fireGun(); else if (isPressed(BUTTON_A)) swapWeapon(); else if (isPressed(BUTTON_B)) reloadWeapon(); } https://gameprogrammingpatterns.com/command.html
  • 6. Globalcode – Open4education Command: The solution class Command { public: virtual ~Command() {} virtual void execute() = 0; }; class JumpCommand : public Command { public: virtual void execute() { jump(); } }; void InputHandler::handleInput() { if (isPressed(BUTTON_X)) buttonX_->execute(); else if (isPressed(BUTTON_Y)) buttonY_->execute(); else if (isPressed(BUTTON_A)) buttonA_->execute(); else if (isPressed(BUTTON_B)) buttonB_->execute(); } https://gameprogrammingpatterns.com/command.html
  • 7. Globalcode – Open4education Command: The usage Input Undo Redo https://gameprogrammingpatterns.com/command.html
  • 8. Globalcode – Open4education Flyweight: The problem class Tree { private: Mesh mesh_; Texture bark_; Texture leaves_; Vector position_; double height_; double thickness_; Color barkTint_; Color leafTint_; }; https://gameprogrammingpatterns.com/flyweight.html
  • 9. Globalcode – Open4education Flyweight: The solution class TreeModel { private: Mesh mesh_; Texture bark_; Texture leaves_; }; class Tree { private: TreeModel* model_; Vector position_; double height_; double thickness_; Color barkTint_; Color leafTint_; }; https://gameprogrammingpatterns.com/flyweight.html
  • 10. Globalcode – Open4education Flyweight: The usage Multiple instances Tile maps https://gameprogrammingpatterns.com/flyweight.html
  • 11. Globalcode – Open4education Observer: The problem void Physics::updateEntity(Entity& entity) { bool wasOnSurface = entity.isOnSurface(); entity.accelerate(GRAVITY); entity.update(); if (wasOnSurface && !entity.isOnSurface() && entity.isHero()) { unlockFallOffBridge(); } } https://gameprogrammingpatterns.com/observer.html
  • 12. Globalcode – Open4education Observer: The solution (1) class Observer { public: virtual ~Observer() {} virtual void onNotify(const Entity& entity, Event event) = 0; }; class Achievements : public Observer { public: virtual void onNotify(const Entity& entity, Event event) { switch (event) { case EVENT_ENTITY_FELL: if (entity.isHero()) { unlock(ACHIEVEMENT_FELL_OFF_BRIDGE); } break; } } private: void unlock(Achievement achievement) { } }; https://gameprogrammingpatterns.com/observer.html
  • 13. Globalcode – Open4education Observer: The solution (2) class Subject { private: Observer* observers[MAX_OBSERVERS]; int numObservers; protected: void notify(const Entity& entity, Event event) { for (int i = 0; i < numObservers; i++) { observers[i]->onNotify(entity, event); } } public: void addObserver(Observer* observer) { } void removeObserver(Observer* observer) { } }; class Physics : public Subject { public: void updateEntity(Entity& entity); { bool wasOnSurface = entity.isOnSurface(); entity.accelerate(GRAVITY); entity.update(); if (wasOnSurface && !entity.isOnSurface()) { notify(entity, EVENT_START_FALL); } } }; https://gameprogrammingpatterns.com/observer.html
  • 14. Globalcode – Open4education Observer: The usage Achievements VFX/SFX Events Messages Callbacks async https://gameprogrammingpatterns.com/observer.html
  • 15. Globalcode – Open4education Prototype: The problem class Monster { }; class Ghost : public Monster {}; class Demon : public Monster {}; class Sorcerer : public Monster {}; class Spawner { public: virtual ~Spawner() {} virtual Monster* spawnMonster() = 0; }; class GhostSpawner : public Spawner { public: virtual Monster* spawnMonster() { return new Ghost(); } }; ... https://gameprogrammingpatterns.com/prototype.html
  • 16. Globalcode – Open4education Prototype: The solution (1) class Monster { public: virtual ~Monster() {} virtual Monster* clone() = 0; }; class Ghost : public Monster { public: Ghost(int health, int speed) : health_(health), speed_(speed) {} virtual Monster* clone() { return new Ghost(health_, speed_); } private: int health_; int speed_; } https://gameprogrammingpatterns.com/prototype.html
  • 17. Globalcode – Open4education Prototype: The solution (2) class Spawner { public: Spawner(Monster* prototype) : prototype_(prototype) {} Monster* spawnMonster() { return prototype_->clone(); } private: Monster* prototype_; }; https://gameprogrammingpatterns.com/prototype.html
  • 18. Globalcode – Open4education Prototype: The usage Spawner Player Items Shoots Loot https://gameprogrammingpatterns.com/prototype.html
  • 19. Globalcode – Open4education States: The problem void Heroine::handleInput(Input input) { if (input == PRESS_B) { if (!isJumping_ && !isDucking_) { // Jump... } } else if (input == PRESS_DOWN) { if (!isJumping_) { isDucking_ = true; } } else if (input == RELEASE_DOWN) { if (isDucking_) { isDucking_ = false; } } } https://gameprogrammingpatterns.com/state.html
  • 20. Globalcode – Open4education States: The solution void Heroine::handleInput(Input input) { switch (state_) { case STATE_STANDING: if (input == PRESS_B) { state_ = STATE_JUMPING; } else if (input == PRESS_DOWN) { state_ = STATE_DUCKING; } break; case STATE_JUMPING: if (input == PRESS_DOWN) { state_ = STATE_DIVING; } break; case STATE_DUCKING: if (input == RELEASE_DOWN) { state_ = STATE_STANDING; } break; } } https://gameprogrammingpatterns.com/state.html
  • 21. Globalcode – Open4education States: The usage Animations Screen states Character actions https://gameprogrammingpatterns.com/state.html
  • 22. Globalcode – Open4education Singleton: The problem Ensure that only one instance of the singleton class ever exists; and provide global access to that instance. Gang of Four, Design Patterns https://gameprogrammingpatterns.com/singleton.html
  • 23. Globalcode – Open4education Singleton: The solution class FileSystem { public: static FileSystem& instance() { if (instance_ == NULL) instance_ = new FileSystem(); return *instance_; } private: FileSystem() {} static FileSystem* instance_; }; https://gameprogrammingpatterns.com/singleton.html
  • 24. Globalcode – Open4education Singleton: The usage “Friends don’t let friends create singletons.” Robert Nystrom, Game Programming Patterns https://gameprogrammingpatterns.com/singleton.html
  • 25. Globalcode – Open4education Other Patterns Sequencing Patterns Double Buffer Game Loop Update Method Behavioral Patterns Bytecode Subclass Sandbox Type Object Decoupling Patterns Component Event Queue Service Locator Optimization Patterns Data Locality Dirty Flag Object Pool Spatial Partition https://gameprogrammingpatterns.com
  • 26. Globalcode – Open4education Game Programming Patterns gameprogrammingpatterns.com
  • 27. Globalcode – Open4education Software Architecture It is not about making diagrams It is about solving problems … and communicating the solution! K.I.S.S. Occam's razor Less is more
  • 28. Globalcode – Open4education SOLID Principles Single Responsibility Open/Closed Liskov Substitution Interface Segregation Dependency Inversion https://devopedia.org/solid-design-principles