SlideShare ist ein Scribd-Unternehmen logo
1 von 58
Downloaden Sie, um offline zu lesen
Game Models
A Different Approach
Nick Prühs
July 12, 2013
About Me
„Best Bachelor“ Computer Science
Kiel University, 2009
Master Games
Hamburg University of Applied Sciences, 2011
Lead Programmer
Daedalic Entertainment, 2011-2012
Co-Founder
slash games, 2013
2 / 58
PART I
ENTITY SYSTEMS
3 / 58
Objectives
• To understand the disadvantages of inheritance-
based game models
• To learn how to build an aggregation-based game
models
• To understand the advantages and disadvantages of
aggregation-based game models
4 / 58
“Say you’re an engineer…
… set out to create a new Game Object System from scratch, and you’re going to ‘do it right the first time’. You
talk to your designer and say ‘What kind of content are we going to have in this game?’
They respond with ‘Oh lots of stuff, trees, and birds, and bushes, and keys and locks and … <trailing off>’
And your eyes glaze over as you start thinking of fancy C++ ways to solve the problem.
The object oriented programming sages tell you to try to determine Is-A relationships and abstract functionality
and all that other fun stuff. You go to the book store and buy a C++ book just to be sure, and it tells you to fire
up your $5000 UML editor. [...]”
- Scott Bilas
5 / 58
Entities
• object in your game world
• can (or cannot)…
• be visible
• move around
• attack
• explode
• be targeted
• become selected
• follow a path
• common across all genres
6 / 58
Entities
7 / 58
Approach #1: Inheritance
• Entity base class
• that class and its subclasses encapsulate the main
game logic
8 / 58
Example #1: Unreal Engine 3
• base class Actor
• rendering
• animation
• sound
• physics
• almost everything in Unreal is an Actor
• Pawn extends by taking damage
• Projectile extends by spawning impact effects
9 / 58
Drawbacks of inheritance-based game models
• Diamond of Death
10 / 58
Drawbacks of inheritance-based game models
• code added to the root of the inheritance tree
causes big overhead
• code added to the leafs of the tree tends to get
copied
• root and leaf classes tend to get very big
11 / 58
Where is Waldo?
public override void Update(float dt)
{
this.SystemManager.Update(dt);
this.EventManager.ProcessEvents(dt);
}
12 / 58
Where is Waldo?
public override void Update(float dt)
{
this.SystemManager.Update(dt);
this.EventManager.ProcessEvents(dt);
}
13 / 58
Where is Waldo?
public override void Update(float dt)
{
base.Update(dt);
this.SystemManager.Update(dt);
this.EventManager.ProcessEvents(dt);
}
14 / 58
Drawbacks of inheritance-based game models
• always need to understand all base classes along
the inheritance tree
• impossible to enforce calling base class functions
• Someone will forget it. Trust me.
• And you’re gonna spend your whole evening finding that one
missing base.Update().
• deep class hierarchies will more likely run into call
order issues
15 / 58
Inheritance-based game models are…
• … difficult to develop
• … difficult to maintain
• … difficult to extend
16 / 58
“There are probably hundreds of ways…
… you could decompose your systems and come up with a set of
classes […], and eventually, all of them are wrong. This isn’t to say
that they won’t work, but games are constantly changing,
constantly invalidating your carefully planned designs. [...]
So you hand off your new Game Object System and go work on
other things.
Then one day your designer says that they want a new type of
“alien” asteroid that acts just like a heat seeking missile, except it’s
still an asteroid.”
- Scott Bilas
17 / 58
Approach #2: Aggregation
• popular since Gas Powered Games’ Dungeon Siege
• introduced long before
• entities are aggregations of components
• which in turn encapsulate independent functionality
• corresponds to recommendations by the Gang of Four
• “favor object composition over class inheritance”
• similar approach is used by the Unity3D game engine
• just for clarification: Unreal uses components as well, called
ActorComponent
18 / 58
Approach #2a
• create an Entity class
• add references to all available components
• has obvious disadvantages:
• many component references will be null pointers for
most entities
• big unnecessary memory overhead
• Entity class has to be updated each time a new
component is introduced
19 / 58
Approach #2b
• create an Entity class
• introduce a common base class for components
• entities hold a collection of Component objects
• reduced the memory overhead
• increased extensibility
• already gets close to an optimal solution
• easy to build, maintain and debug
• easy to implement new design ideas without breaking
existing code
20 / 58
However, we can do better.
21 / 58
Approach #2c: Entity Systems
There is no Entity class at all.
22 / 58
Approach #2c: Entity Systems
23 / 58
Approach #2c: Entity Systems
• game entities are nothing more than just an id
• thus, no data or methods on entities
• no methods on components, either: all
functionality goes into what is called a system
• PhysicsSystem
• HealthSystem
• FightSystem
• entirely operate on their corresponding
components
24 / 58
“All the data goes into the Components.
All of it. Think you can take some “really common”
data, e. g. the x-/y-/z-coordinates of the in-game
object, and put it into the Entity itself? Nope. Don’t
go there. As soon as you start migrating data into the
Entity, you’ve lost. By definition the only valid place
for the data is inside the Component.”
- Adam Martin
25 / 58
Example #2: Simple Fight
26 / 58
Example #2: Simple Fight
27 / 58
Example #2: Simple Fight
28 / 58
Example #2: Simple Fight
29 / 58
Example #2: Simple Fight
30 / 58
Example #2: Simple Fight
31 / 58
Example #2: Simple Fight
32 / 58
Example #2: Simple Fight
33 / 58
Example #2: Simple Fight
34 / 58
Example #2: Simple Fight
35 / 58
Inter-System Communication
Systems communicate by the means of events, only.
• no coupling between systems
• easy to add or remove systems at any time
• great architectural advantage for general game features
• need multiplayer? just send the events over the network!
• need AI? just make it create events which are handled just
like player input is!
• need replays? just write all events with timestamps to a file!
36 / 58
Entity Systems – Implementation
DEMO
37 / 58
Advantages of Entity Systems
• update order is obvious
• components can easily be pooled and re-used
• independent systems can be updated by separate
threads
• data can easily be serialized and stored in a
database
38 / 58
Disadvantages of Entity Systems (?)
• lookups cause performance hit
• resist the urge to add cross-component references – this
would make you lose all of the advantages mentioned
before
• just don’t flood your system with unnecessary
component types – just as you would always do
• misbelief that it takes longer to “get the job done”
• used at the InnoGames Game Jam #3 for creating a
multi-platform multi-player real-time tactics game in just
48 hours – spending the little extra effort at the
beginning pays off
• Always.
39 / 58
Conclusion
• inheritance-based game models show a lot of
disadvantages
• entity systems are easy to maintain and debug
• provide great extensibility without the necessity of
modifying existing code
• show better performance characteristics for both
memory and CPU load
• easy to implement commonly used features
• scripting
• serialization
• logging
40 / 58
PART II
ENTITY SYSTEMS & UNITY
41 / 58
Objectives
• To learn how to write .NET libraries for Unity3D
• To learn how to use entity systems with Unity3D
42 / 58
Entity Systems & Unity
43 / 58
Entity Systems & Unity – Project Structure
• Source folder
• Unity project
• Logic project
• Build project
• Unit Tests
• Vendor folder
• third party libraries
44 / 58
Entity Systems & Unity – Setup
1. Create Unity project as usual.
2. Create shared solution.
1. Switch target framework to .NET 3.5.
2. Add Unity project to game solution.
3. Create Build project.
1. Add reference to logic project.
2. Write batch file for copying .dlls to the Unity Plugins
folder (see next slide).
3. Set post-build event.
45 / 58
Entity Systems & Unity – Post-Build Script
REM Copies all libraries to the Unity Plugins folder.
SET PATH_TO_UNITY_PROJECT=%1
SET DLL_TARGET_DIR=%PATH_TO_UNITY_PROJECT%AssetsPlugins
SET DLL_SOURCE_DIR=%2
XCOPY "%DLL_SOURCE_DIR%*.dll" "%DLL_TARGET_DIR%" /D /Y
Visual Studio Build Event:
$(ProjectDir)PostBuild.bat $(ProjectDir)..Unity $(TargetDir)
46 / 58
Entity Systems & Unity – Write Logic Base
• Game class
• GameSystem base class
• virtual initialization method
• reference to type-casted game
• GameEvent enum
47 / 58
Entity Systems & Unity – Link to Unity
1. Create GameBehaviour passing Unity Start and
Update to the logic.
2. Create LogBehaviour passing all logic events to the
Unity log.
3. Add game systems, components and events as
desired.
4. Add entity-object-map to GameBehaviour.
5. Implement OnEntityCreated an OnEntityRemoved
event handler.
48 / 58
Gotcha!
Don’t forget to rebuild the solution!
49 / 58
Gotcha!
Don’t forget to add new game
systems to your game class!
50 / 58
Hint
Override ToString in event data
classes for more useful log output!
51 / 58
Entity Systems & Unity –
Unit Testing
After all, this is one of the reasons we did that, right?
1. Add the unit test framework of your choice to the
Vendor folder (e.g. NUnit).
2. Add unit test project to the solution and add a
reference to the framework.
3. Write unit tests as usual.
52 / 58
Gotcha!
Don’t forget to initialize, start and
update your game in unit tests!
53 / 58
Entity Systems & Unity – Setup MonoDevelop
1. Ensure solution file has version 11:
Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2008
2. Add „After Build“ Custom Command in
PostBuildLibraries project options.
54 / 58
Future Prospects
• Attribute Tables
• store arbitrary key-value-pairs
• used for initializing all components of an entity
• Blueprints
• consist of a list of components and an attribute table
• created with some kind of editor tool by designers
• used for creating entites at run-time
• Hierarchical Attribute Tables
• used for overloading blueprints with specific entity
attribute values
• e.g. reduced initial health
55 / 58
Future Prospects
• building physics system outside of Unity
• requires own Vector2 and Vector3 data structures (and
conversions)
• position of Unity game objects should always reflect
physics position
• converting PDBs to MDBs
• provides more verbose debug output in Unity
56 / 58
References
• Mick West. Evolve Your Hierarchy. http://cowboyprogramming.com/2007/01/05/evolve-your-
heirachy/, January 2007.
• Levi Baker. Entity Systems Part 1: Entity and EntityManager.
http://blog.chronoclast.com/2010/12/entity-systems-part-1-entity-and.html, December 2010.
• Kyle Wilson. Game Object Structure: Inheritance vs. Aggregation.
http://gamearchitect.net/Articles/GameObjects1.html, July 2002.
• Adam Martin. Entity Systems are the future of MMOG development – Part 1. http://t-
machine.org/index.php/2007/09/03/entity-systems-are-the-future-of-mmog-development-part-
1/, September 2007.
• Adam Martin. Entity Systems: what makes good Components? good Entities? http://t-
machine.org/index.php/2012/03/16/entity-systems-what-makes-good-components-good-
entities/, March 2012.
• Scott Bilas. A Data-Driven Game Object System.
http://scottbilas.com/files/2002/gdc_san_jose/game_objects_slides_with_notes.pdf, Slides,
GDC 2002.
• Scott Bilas. A Data-Driven Game Object System.
http://scottbilas.com/files/2002/gdc_san_jose/game_objects_paper.pdf, Paper, GDC 2002.
• Insomniac Games. A Dynamic Component Architecture for High Performance Gameplay.
http://www.insomniacgames.com/a-dynamic-component-architecture-for-high-performance-
gameplay/, June 2010.
57 / 58
Thank you for your attention!
Contact
Mail
dev@npruehs.de
Blog
http://www.npruehs.de
Twitter
@npruehs
Github
https://github.com/npruehs
58 / 58

Weitere ähnliche Inhalte

Was ist angesagt?

Eight Rules for Making Your First Great Game
Eight Rules for Making Your First Great GameEight Rules for Making Your First Great Game
Eight Rules for Making Your First Great GameNick Pruehs
 
Game Programming 09 - AI
Game Programming 09 - AIGame Programming 09 - AI
Game Programming 09 - AINick Pruehs
 
Developing applications and games in Unity engine - Matej Jariabka, Rudolf Ka...
Developing applications and games in Unity engine - Matej Jariabka, Rudolf Ka...Developing applications and games in Unity engine - Matej Jariabka, Rudolf Ka...
Developing applications and games in Unity engine - Matej Jariabka, Rudolf Ka...gamifi.cc
 
Game Programming 06 - Automated Testing
Game Programming 06 - Automated TestingGame Programming 06 - Automated Testing
Game Programming 06 - Automated TestingNick Pruehs
 
Game Programming 07 - Procedural Content Generation
Game Programming 07 - Procedural Content GenerationGame Programming 07 - Procedural Content Generation
Game Programming 07 - Procedural Content GenerationNick Pruehs
 
Scene Graphs & Component Based Game Engines
Scene Graphs & Component Based Game EnginesScene Graphs & Component Based Game Engines
Scene Graphs & Component Based Game EnginesBryan Duggan
 
Unity scene file collaboration
Unity scene file collaborationUnity scene file collaboration
Unity scene file collaborationNoam Gat
 
Choosing A Game Engine - More Than Frames Per Second
Choosing A Game Engine - More Than Frames Per SecondChoosing A Game Engine - More Than Frames Per Second
Choosing A Game Engine - More Than Frames Per SecondNoam Gat
 
Cmd unity withc
Cmd unity withcCmd unity withc
Cmd unity withcumairnoora
 
Android Jumpstart Jfokus
Android Jumpstart JfokusAndroid Jumpstart Jfokus
Android Jumpstart JfokusLars Vogel
 
Building Multiplayer Games (w/ Unity)
Building Multiplayer Games (w/ Unity)Building Multiplayer Games (w/ Unity)
Building Multiplayer Games (w/ Unity)Noam Gat
 
Unity Programming
Unity Programming Unity Programming
Unity Programming Sperasoft
 
Game Engine Overview
Game Engine OverviewGame Engine Overview
Game Engine OverviewSharad Mitra
 

Was ist angesagt? (20)

Eight Rules for Making Your First Great Game
Eight Rules for Making Your First Great GameEight Rules for Making Your First Great Game
Eight Rules for Making Your First Great Game
 
Game Programming 09 - AI
Game Programming 09 - AIGame Programming 09 - AI
Game Programming 09 - AI
 
Developing applications and games in Unity engine - Matej Jariabka, Rudolf Ka...
Developing applications and games in Unity engine - Matej Jariabka, Rudolf Ka...Developing applications and games in Unity engine - Matej Jariabka, Rudolf Ka...
Developing applications and games in Unity engine - Matej Jariabka, Rudolf Ka...
 
Game Programming 06 - Automated Testing
Game Programming 06 - Automated TestingGame Programming 06 - Automated Testing
Game Programming 06 - Automated Testing
 
Game Programming 07 - Procedural Content Generation
Game Programming 07 - Procedural Content GenerationGame Programming 07 - Procedural Content Generation
Game Programming 07 - Procedural Content Generation
 
Scene Graphs & Component Based Game Engines
Scene Graphs & Component Based Game EnginesScene Graphs & Component Based Game Engines
Scene Graphs & Component Based Game Engines
 
Unity scene file collaboration
Unity scene file collaborationUnity scene file collaboration
Unity scene file collaboration
 
Soc research
Soc researchSoc research
Soc research
 
Choosing A Game Engine - More Than Frames Per Second
Choosing A Game Engine - More Than Frames Per SecondChoosing A Game Engine - More Than Frames Per Second
Choosing A Game Engine - More Than Frames Per Second
 
Cmd unity withc
Cmd unity withcCmd unity withc
Cmd unity withc
 
Android Jumpstart Jfokus
Android Jumpstart JfokusAndroid Jumpstart Jfokus
Android Jumpstart Jfokus
 
unity basics
unity basicsunity basics
unity basics
 
Building Multiplayer Games (w/ Unity)
Building Multiplayer Games (w/ Unity)Building Multiplayer Games (w/ Unity)
Building Multiplayer Games (w/ Unity)
 
Unity Programming
Unity Programming Unity Programming
Unity Programming
 
Unity 3d
Unity 3dUnity 3d
Unity 3d
 
Unity
UnityUnity
Unity
 
Presentación Unity
Presentación UnityPresentación Unity
Presentación Unity
 
Game Engine Overview
Game Engine OverviewGame Engine Overview
Game Engine Overview
 
Game development unity
Game development unityGame development unity
Game development unity
 
Unity 3D, A game engine
Unity 3D, A game engineUnity 3D, A game engine
Unity 3D, A game engine
 

Andere mochten auch

Entity System Architecture with Unity - Unite Europe 2015
Entity System Architecture with Unity - Unite Europe 2015Entity System Architecture with Unity - Unite Europe 2015
Entity System Architecture with Unity - Unite Europe 2015Simon Schmid
 
ECS architecture with Unity by example - Unite Europe 2016
ECS architecture with Unity by example - Unite Europe 2016ECS architecture with Unity by example - Unite Europe 2016
ECS architecture with Unity by example - Unite Europe 2016Simon Schmid
 
The use of data-oriented programming paradigm in Unity games
The use of data-oriented programming paradigm in Unity gamesThe use of data-oriented programming paradigm in Unity games
The use of data-oriented programming paradigm in Unity gamesDevGAMM Conference
 
Game Programming 03 - Git Flow
Game Programming 03 - Git FlowGame Programming 03 - Git Flow
Game Programming 03 - Git FlowNick Pruehs
 
Game Programming 10 - Localization
Game Programming 10 - LocalizationGame Programming 10 - Localization
Game Programming 10 - LocalizationNick Pruehs
 
Game Programming 08 - Tool Development
Game Programming 08 - Tool DevelopmentGame Programming 08 - Tool Development
Game Programming 08 - Tool DevelopmentNick Pruehs
 
Game Programming 13 - Debugging & Performance Optimization
Game Programming 13 - Debugging & Performance OptimizationGame Programming 13 - Debugging & Performance Optimization
Game Programming 13 - Debugging & Performance OptimizationNick Pruehs
 
Game Programming 04 - Style & Design Principles
Game Programming 04 - Style & Design PrinciplesGame Programming 04 - Style & Design Principles
Game Programming 04 - Style & Design PrinciplesNick Pruehs
 
Tool Development A - Git
Tool Development A - GitTool Development A - Git
Tool Development A - GitNick Pruehs
 
Designing an actor model game architecture with Pony
Designing an actor model game architecture with PonyDesigning an actor model game architecture with Pony
Designing an actor model game architecture with PonyNick Pruehs
 
Game Programming 12 - Shaders
Game Programming 12 - ShadersGame Programming 12 - Shaders
Game Programming 12 - ShadersNick Pruehs
 
Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016Simon Schmid
 
Game Programming 11 - Game Physics
Game Programming 11 - Game PhysicsGame Programming 11 - Game Physics
Game Programming 11 - Game PhysicsNick Pruehs
 
Game Development Challenges
Game Development ChallengesGame Development Challenges
Game Development ChallengesNick Pruehs
 
Scrum - but... Agile Game Development in Small Teams
Scrum - but... Agile Game Development in Small TeamsScrum - but... Agile Game Development in Small Teams
Scrum - but... Agile Game Development in Small TeamsNick Pruehs
 
Game Programming 05 - Development Tools
Game Programming 05 - Development ToolsGame Programming 05 - Development Tools
Game Programming 05 - Development ToolsNick Pruehs
 

Andere mochten auch (17)

Entity System Architecture with Unity - Unite Europe 2015
Entity System Architecture with Unity - Unite Europe 2015Entity System Architecture with Unity - Unite Europe 2015
Entity System Architecture with Unity - Unite Europe 2015
 
ECS architecture with Unity by example - Unite Europe 2016
ECS architecture with Unity by example - Unite Europe 2016ECS architecture with Unity by example - Unite Europe 2016
ECS architecture with Unity by example - Unite Europe 2016
 
The use of data-oriented programming paradigm in Unity games
The use of data-oriented programming paradigm in Unity gamesThe use of data-oriented programming paradigm in Unity games
The use of data-oriented programming paradigm in Unity games
 
Producing for indies
Producing for indiesProducing for indies
Producing for indies
 
Game Programming 03 - Git Flow
Game Programming 03 - Git FlowGame Programming 03 - Git Flow
Game Programming 03 - Git Flow
 
Game Programming 10 - Localization
Game Programming 10 - LocalizationGame Programming 10 - Localization
Game Programming 10 - Localization
 
Game Programming 08 - Tool Development
Game Programming 08 - Tool DevelopmentGame Programming 08 - Tool Development
Game Programming 08 - Tool Development
 
Game Programming 13 - Debugging & Performance Optimization
Game Programming 13 - Debugging & Performance OptimizationGame Programming 13 - Debugging & Performance Optimization
Game Programming 13 - Debugging & Performance Optimization
 
Game Programming 04 - Style & Design Principles
Game Programming 04 - Style & Design PrinciplesGame Programming 04 - Style & Design Principles
Game Programming 04 - Style & Design Principles
 
Tool Development A - Git
Tool Development A - GitTool Development A - Git
Tool Development A - Git
 
Designing an actor model game architecture with Pony
Designing an actor model game architecture with PonyDesigning an actor model game architecture with Pony
Designing an actor model game architecture with Pony
 
Game Programming 12 - Shaders
Game Programming 12 - ShadersGame Programming 12 - Shaders
Game Programming 12 - Shaders
 
Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
 
Game Programming 11 - Game Physics
Game Programming 11 - Game PhysicsGame Programming 11 - Game Physics
Game Programming 11 - Game Physics
 
Game Development Challenges
Game Development ChallengesGame Development Challenges
Game Development Challenges
 
Scrum - but... Agile Game Development in Small Teams
Scrum - but... Agile Game Development in Small TeamsScrum - but... Agile Game Development in Small Teams
Scrum - but... Agile Game Development in Small Teams
 
Game Programming 05 - Development Tools
Game Programming 05 - Development ToolsGame Programming 05 - Development Tools
Game Programming 05 - Development Tools
 

Ähnlich wie Game Models - A Different Approach

Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...
Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...
Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...Lviv Startup Club
 
Create a Scalable and Destructible World in HITMAN 2*
Create a Scalable and Destructible World in HITMAN 2*Create a Scalable and Destructible World in HITMAN 2*
Create a Scalable and Destructible World in HITMAN 2*Intel® Software
 
ITCamp 2011 - Catalin Zima - Common pitfalls in Windows Phone 7 game development
ITCamp 2011 - Catalin Zima - Common pitfalls in Windows Phone 7 game developmentITCamp 2011 - Catalin Zima - Common pitfalls in Windows Phone 7 game development
ITCamp 2011 - Catalin Zima - Common pitfalls in Windows Phone 7 game developmentITCamp
 
Tales from the Optimization Trenches - Unite Copenhagen 2019
Tales from the Optimization Trenches - Unite Copenhagen 2019Tales from the Optimization Trenches - Unite Copenhagen 2019
Tales from the Optimization Trenches - Unite Copenhagen 2019Unity Technologies
 
Introduction to html5 game programming with impact js
Introduction to html5 game programming with impact jsIntroduction to html5 game programming with impact js
Introduction to html5 game programming with impact jsLuca Galli
 
HoloLens Unity Build Pipelines on Azure DevOps
HoloLens Unity Build Pipelines on Azure DevOpsHoloLens Unity Build Pipelines on Azure DevOps
HoloLens Unity Build Pipelines on Azure DevOpsSarah Sexton
 
Understanding and improving games through machine learning - Natasha Latysheva
Understanding and improving games through machine learning - Natasha LatyshevaUnderstanding and improving games through machine learning - Natasha Latysheva
Understanding and improving games through machine learning - Natasha LatyshevaLauren Cormack
 
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法Unite2017Tokyo
 
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法Unity Technologies Japan K.K.
 
A new way to inspire and stimulate learning
A new way to inspire and stimulate learningA new way to inspire and stimulate learning
A new way to inspire and stimulate learningLee Stott
 
Creating great Unity games for Windows 10 - Part 1
Creating great Unity games for Windows 10 - Part 1Creating great Unity games for Windows 10 - Part 1
Creating great Unity games for Windows 10 - Part 1Jiri Danihelka
 
PowerShell - Be A Cool Blue Kid
PowerShell - Be A Cool Blue KidPowerShell - Be A Cool Blue Kid
PowerShell - Be A Cool Blue KidMatthew Johnson
 
Debugging multiplayer games
Debugging multiplayer gamesDebugging multiplayer games
Debugging multiplayer gamesMaciej Siniło
 
Optimizing mobile applications - Ian Dundore, Mark Harkness
Optimizing mobile applications - Ian Dundore, Mark HarknessOptimizing mobile applications - Ian Dundore, Mark Harkness
Optimizing mobile applications - Ian Dundore, Mark Harknessozlael ozlael
 
Initial design (Game Architecture)
Initial design (Game Architecture)Initial design (Game Architecture)
Initial design (Game Architecture)Rajkumar Pawar
 
Sephy engine development document
Sephy engine development documentSephy engine development document
Sephy engine development documentJaejun Kim
 
Threading Game Engines: QUAKE 4 & Enemy Territory QUAKE Wars
Threading Game Engines: QUAKE 4 & Enemy Territory QUAKE WarsThreading Game Engines: QUAKE 4 & Enemy Territory QUAKE Wars
Threading Game Engines: QUAKE 4 & Enemy Territory QUAKE Warspsteinb
 
3.4 game architecture
3.4 game architecture3.4 game architecture
3.4 game architectureSayed Ahmed
 

Ähnlich wie Game Models - A Different Approach (20)

Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...
Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...
Шлигін Олександр “Розробка ігор в Unity загальні помилки” GameDev Conference ...
 
Create a Scalable and Destructible World in HITMAN 2*
Create a Scalable and Destructible World in HITMAN 2*Create a Scalable and Destructible World in HITMAN 2*
Create a Scalable and Destructible World in HITMAN 2*
 
ITCamp 2011 - Catalin Zima - Common pitfalls in Windows Phone 7 game development
ITCamp 2011 - Catalin Zima - Common pitfalls in Windows Phone 7 game developmentITCamp 2011 - Catalin Zima - Common pitfalls in Windows Phone 7 game development
ITCamp 2011 - Catalin Zima - Common pitfalls in Windows Phone 7 game development
 
Tales from the Optimization Trenches - Unite Copenhagen 2019
Tales from the Optimization Trenches - Unite Copenhagen 2019Tales from the Optimization Trenches - Unite Copenhagen 2019
Tales from the Optimization Trenches - Unite Copenhagen 2019
 
Introduction to html5 game programming with impact js
Introduction to html5 game programming with impact jsIntroduction to html5 game programming with impact js
Introduction to html5 game programming with impact js
 
HoloLens Unity Build Pipelines on Azure DevOps
HoloLens Unity Build Pipelines on Azure DevOpsHoloLens Unity Build Pipelines on Azure DevOps
HoloLens Unity Build Pipelines on Azure DevOps
 
Understanding and improving games through machine learning - Natasha Latysheva
Understanding and improving games through machine learning - Natasha LatyshevaUnderstanding and improving games through machine learning - Natasha Latysheva
Understanding and improving games through machine learning - Natasha Latysheva
 
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
 
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
【Unite 2017 Tokyo】インスタンシングを用いた美麗なグラフィックの実現方法
 
A new way to inspire and stimulate learning
A new way to inspire and stimulate learningA new way to inspire and stimulate learning
A new way to inspire and stimulate learning
 
Creating great Unity games for Windows 10 - Part 1
Creating great Unity games for Windows 10 - Part 1Creating great Unity games for Windows 10 - Part 1
Creating great Unity games for Windows 10 - Part 1
 
Unity 3D VS your team
Unity 3D VS your teamUnity 3D VS your team
Unity 3D VS your team
 
PowerShell - Be A Cool Blue Kid
PowerShell - Be A Cool Blue KidPowerShell - Be A Cool Blue Kid
PowerShell - Be A Cool Blue Kid
 
Debugging multiplayer games
Debugging multiplayer gamesDebugging multiplayer games
Debugging multiplayer games
 
0507 057 01 98 * Adana Cukurova Klima Servisleri
0507 057 01 98 * Adana Cukurova Klima Servisleri0507 057 01 98 * Adana Cukurova Klima Servisleri
0507 057 01 98 * Adana Cukurova Klima Servisleri
 
Optimizing mobile applications - Ian Dundore, Mark Harkness
Optimizing mobile applications - Ian Dundore, Mark HarknessOptimizing mobile applications - Ian Dundore, Mark Harkness
Optimizing mobile applications - Ian Dundore, Mark Harkness
 
Initial design (Game Architecture)
Initial design (Game Architecture)Initial design (Game Architecture)
Initial design (Game Architecture)
 
Sephy engine development document
Sephy engine development documentSephy engine development document
Sephy engine development document
 
Threading Game Engines: QUAKE 4 & Enemy Territory QUAKE Wars
Threading Game Engines: QUAKE 4 & Enemy Territory QUAKE WarsThreading Game Engines: QUAKE 4 & Enemy Territory QUAKE Wars
Threading Game Engines: QUAKE 4 & Enemy Territory QUAKE Wars
 
3.4 game architecture
3.4 game architecture3.4 game architecture
3.4 game architecture
 

Mehr von Nick Pruehs

Unreal Engine Basics 06 - Animation, Audio, Visual Effects
Unreal Engine Basics 06 - Animation, Audio, Visual EffectsUnreal Engine Basics 06 - Animation, Audio, Visual Effects
Unreal Engine Basics 06 - Animation, Audio, Visual EffectsNick Pruehs
 
Unreal Engine Basics 05 - User Interface
Unreal Engine Basics 05 - User InterfaceUnreal Engine Basics 05 - User Interface
Unreal Engine Basics 05 - User InterfaceNick Pruehs
 
Unreal Engine Basics 04 - Behavior Trees
Unreal Engine Basics 04 - Behavior TreesUnreal Engine Basics 04 - Behavior Trees
Unreal Engine Basics 04 - Behavior TreesNick Pruehs
 
Unreal Engine Basics 03 - Gameplay
Unreal Engine Basics 03 - GameplayUnreal Engine Basics 03 - Gameplay
Unreal Engine Basics 03 - GameplayNick Pruehs
 
Unreal Engine Basics 02 - Unreal Editor
Unreal Engine Basics 02 - Unreal EditorUnreal Engine Basics 02 - Unreal Editor
Unreal Engine Basics 02 - Unreal EditorNick Pruehs
 
Unreal Engine Basics 01 - Game Framework
Unreal Engine Basics 01 - Game FrameworkUnreal Engine Basics 01 - Game Framework
Unreal Engine Basics 01 - Game FrameworkNick Pruehs
 
Game Programming - Cloud Development
Game Programming - Cloud DevelopmentGame Programming - Cloud Development
Game Programming - Cloud DevelopmentNick Pruehs
 
Game Programming - Git
Game Programming - GitGame Programming - Git
Game Programming - GitNick Pruehs
 
Game Programming 01 - Introduction
Game Programming 01 - IntroductionGame Programming 01 - Introduction
Game Programming 01 - IntroductionNick Pruehs
 
Game Programming 00 - Exams
Game Programming 00 - ExamsGame Programming 00 - Exams
Game Programming 00 - ExamsNick Pruehs
 

Mehr von Nick Pruehs (10)

Unreal Engine Basics 06 - Animation, Audio, Visual Effects
Unreal Engine Basics 06 - Animation, Audio, Visual EffectsUnreal Engine Basics 06 - Animation, Audio, Visual Effects
Unreal Engine Basics 06 - Animation, Audio, Visual Effects
 
Unreal Engine Basics 05 - User Interface
Unreal Engine Basics 05 - User InterfaceUnreal Engine Basics 05 - User Interface
Unreal Engine Basics 05 - User Interface
 
Unreal Engine Basics 04 - Behavior Trees
Unreal Engine Basics 04 - Behavior TreesUnreal Engine Basics 04 - Behavior Trees
Unreal Engine Basics 04 - Behavior Trees
 
Unreal Engine Basics 03 - Gameplay
Unreal Engine Basics 03 - GameplayUnreal Engine Basics 03 - Gameplay
Unreal Engine Basics 03 - Gameplay
 
Unreal Engine Basics 02 - Unreal Editor
Unreal Engine Basics 02 - Unreal EditorUnreal Engine Basics 02 - Unreal Editor
Unreal Engine Basics 02 - Unreal Editor
 
Unreal Engine Basics 01 - Game Framework
Unreal Engine Basics 01 - Game FrameworkUnreal Engine Basics 01 - Game Framework
Unreal Engine Basics 01 - Game Framework
 
Game Programming - Cloud Development
Game Programming - Cloud DevelopmentGame Programming - Cloud Development
Game Programming - Cloud Development
 
Game Programming - Git
Game Programming - GitGame Programming - Git
Game Programming - Git
 
Game Programming 01 - Introduction
Game Programming 01 - IntroductionGame Programming 01 - Introduction
Game Programming 01 - Introduction
 
Game Programming 00 - Exams
Game Programming 00 - ExamsGame Programming 00 - Exams
Game Programming 00 - Exams
 

Kürzlich hochgeladen

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
[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
 
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
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
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
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
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
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 

Kürzlich hochgeladen (20)

A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
[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
 
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
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
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
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
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
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 

Game Models - A Different Approach

  • 1. Game Models A Different Approach Nick Prühs July 12, 2013
  • 2. About Me „Best Bachelor“ Computer Science Kiel University, 2009 Master Games Hamburg University of Applied Sciences, 2011 Lead Programmer Daedalic Entertainment, 2011-2012 Co-Founder slash games, 2013 2 / 58
  • 4. Objectives • To understand the disadvantages of inheritance- based game models • To learn how to build an aggregation-based game models • To understand the advantages and disadvantages of aggregation-based game models 4 / 58
  • 5. “Say you’re an engineer… … set out to create a new Game Object System from scratch, and you’re going to ‘do it right the first time’. You talk to your designer and say ‘What kind of content are we going to have in this game?’ They respond with ‘Oh lots of stuff, trees, and birds, and bushes, and keys and locks and … <trailing off>’ And your eyes glaze over as you start thinking of fancy C++ ways to solve the problem. The object oriented programming sages tell you to try to determine Is-A relationships and abstract functionality and all that other fun stuff. You go to the book store and buy a C++ book just to be sure, and it tells you to fire up your $5000 UML editor. [...]” - Scott Bilas 5 / 58
  • 6. Entities • object in your game world • can (or cannot)… • be visible • move around • attack • explode • be targeted • become selected • follow a path • common across all genres 6 / 58
  • 8. Approach #1: Inheritance • Entity base class • that class and its subclasses encapsulate the main game logic 8 / 58
  • 9. Example #1: Unreal Engine 3 • base class Actor • rendering • animation • sound • physics • almost everything in Unreal is an Actor • Pawn extends by taking damage • Projectile extends by spawning impact effects 9 / 58
  • 10. Drawbacks of inheritance-based game models • Diamond of Death 10 / 58
  • 11. Drawbacks of inheritance-based game models • code added to the root of the inheritance tree causes big overhead • code added to the leafs of the tree tends to get copied • root and leaf classes tend to get very big 11 / 58
  • 12. Where is Waldo? public override void Update(float dt) { this.SystemManager.Update(dt); this.EventManager.ProcessEvents(dt); } 12 / 58
  • 13. Where is Waldo? public override void Update(float dt) { this.SystemManager.Update(dt); this.EventManager.ProcessEvents(dt); } 13 / 58
  • 14. Where is Waldo? public override void Update(float dt) { base.Update(dt); this.SystemManager.Update(dt); this.EventManager.ProcessEvents(dt); } 14 / 58
  • 15. Drawbacks of inheritance-based game models • always need to understand all base classes along the inheritance tree • impossible to enforce calling base class functions • Someone will forget it. Trust me. • And you’re gonna spend your whole evening finding that one missing base.Update(). • deep class hierarchies will more likely run into call order issues 15 / 58
  • 16. Inheritance-based game models are… • … difficult to develop • … difficult to maintain • … difficult to extend 16 / 58
  • 17. “There are probably hundreds of ways… … you could decompose your systems and come up with a set of classes […], and eventually, all of them are wrong. This isn’t to say that they won’t work, but games are constantly changing, constantly invalidating your carefully planned designs. [...] So you hand off your new Game Object System and go work on other things. Then one day your designer says that they want a new type of “alien” asteroid that acts just like a heat seeking missile, except it’s still an asteroid.” - Scott Bilas 17 / 58
  • 18. Approach #2: Aggregation • popular since Gas Powered Games’ Dungeon Siege • introduced long before • entities are aggregations of components • which in turn encapsulate independent functionality • corresponds to recommendations by the Gang of Four • “favor object composition over class inheritance” • similar approach is used by the Unity3D game engine • just for clarification: Unreal uses components as well, called ActorComponent 18 / 58
  • 19. Approach #2a • create an Entity class • add references to all available components • has obvious disadvantages: • many component references will be null pointers for most entities • big unnecessary memory overhead • Entity class has to be updated each time a new component is introduced 19 / 58
  • 20. Approach #2b • create an Entity class • introduce a common base class for components • entities hold a collection of Component objects • reduced the memory overhead • increased extensibility • already gets close to an optimal solution • easy to build, maintain and debug • easy to implement new design ideas without breaking existing code 20 / 58
  • 21. However, we can do better. 21 / 58
  • 22. Approach #2c: Entity Systems There is no Entity class at all. 22 / 58
  • 23. Approach #2c: Entity Systems 23 / 58
  • 24. Approach #2c: Entity Systems • game entities are nothing more than just an id • thus, no data or methods on entities • no methods on components, either: all functionality goes into what is called a system • PhysicsSystem • HealthSystem • FightSystem • entirely operate on their corresponding components 24 / 58
  • 25. “All the data goes into the Components. All of it. Think you can take some “really common” data, e. g. the x-/y-/z-coordinates of the in-game object, and put it into the Entity itself? Nope. Don’t go there. As soon as you start migrating data into the Entity, you’ve lost. By definition the only valid place for the data is inside the Component.” - Adam Martin 25 / 58
  • 26. Example #2: Simple Fight 26 / 58
  • 27. Example #2: Simple Fight 27 / 58
  • 28. Example #2: Simple Fight 28 / 58
  • 29. Example #2: Simple Fight 29 / 58
  • 30. Example #2: Simple Fight 30 / 58
  • 31. Example #2: Simple Fight 31 / 58
  • 32. Example #2: Simple Fight 32 / 58
  • 33. Example #2: Simple Fight 33 / 58
  • 34. Example #2: Simple Fight 34 / 58
  • 35. Example #2: Simple Fight 35 / 58
  • 36. Inter-System Communication Systems communicate by the means of events, only. • no coupling between systems • easy to add or remove systems at any time • great architectural advantage for general game features • need multiplayer? just send the events over the network! • need AI? just make it create events which are handled just like player input is! • need replays? just write all events with timestamps to a file! 36 / 58
  • 37. Entity Systems – Implementation DEMO 37 / 58
  • 38. Advantages of Entity Systems • update order is obvious • components can easily be pooled and re-used • independent systems can be updated by separate threads • data can easily be serialized and stored in a database 38 / 58
  • 39. Disadvantages of Entity Systems (?) • lookups cause performance hit • resist the urge to add cross-component references – this would make you lose all of the advantages mentioned before • just don’t flood your system with unnecessary component types – just as you would always do • misbelief that it takes longer to “get the job done” • used at the InnoGames Game Jam #3 for creating a multi-platform multi-player real-time tactics game in just 48 hours – spending the little extra effort at the beginning pays off • Always. 39 / 58
  • 40. Conclusion • inheritance-based game models show a lot of disadvantages • entity systems are easy to maintain and debug • provide great extensibility without the necessity of modifying existing code • show better performance characteristics for both memory and CPU load • easy to implement commonly used features • scripting • serialization • logging 40 / 58
  • 41. PART II ENTITY SYSTEMS & UNITY 41 / 58
  • 42. Objectives • To learn how to write .NET libraries for Unity3D • To learn how to use entity systems with Unity3D 42 / 58
  • 43. Entity Systems & Unity 43 / 58
  • 44. Entity Systems & Unity – Project Structure • Source folder • Unity project • Logic project • Build project • Unit Tests • Vendor folder • third party libraries 44 / 58
  • 45. Entity Systems & Unity – Setup 1. Create Unity project as usual. 2. Create shared solution. 1. Switch target framework to .NET 3.5. 2. Add Unity project to game solution. 3. Create Build project. 1. Add reference to logic project. 2. Write batch file for copying .dlls to the Unity Plugins folder (see next slide). 3. Set post-build event. 45 / 58
  • 46. Entity Systems & Unity – Post-Build Script REM Copies all libraries to the Unity Plugins folder. SET PATH_TO_UNITY_PROJECT=%1 SET DLL_TARGET_DIR=%PATH_TO_UNITY_PROJECT%AssetsPlugins SET DLL_SOURCE_DIR=%2 XCOPY "%DLL_SOURCE_DIR%*.dll" "%DLL_TARGET_DIR%" /D /Y Visual Studio Build Event: $(ProjectDir)PostBuild.bat $(ProjectDir)..Unity $(TargetDir) 46 / 58
  • 47. Entity Systems & Unity – Write Logic Base • Game class • GameSystem base class • virtual initialization method • reference to type-casted game • GameEvent enum 47 / 58
  • 48. Entity Systems & Unity – Link to Unity 1. Create GameBehaviour passing Unity Start and Update to the logic. 2. Create LogBehaviour passing all logic events to the Unity log. 3. Add game systems, components and events as desired. 4. Add entity-object-map to GameBehaviour. 5. Implement OnEntityCreated an OnEntityRemoved event handler. 48 / 58
  • 49. Gotcha! Don’t forget to rebuild the solution! 49 / 58
  • 50. Gotcha! Don’t forget to add new game systems to your game class! 50 / 58
  • 51. Hint Override ToString in event data classes for more useful log output! 51 / 58
  • 52. Entity Systems & Unity – Unit Testing After all, this is one of the reasons we did that, right? 1. Add the unit test framework of your choice to the Vendor folder (e.g. NUnit). 2. Add unit test project to the solution and add a reference to the framework. 3. Write unit tests as usual. 52 / 58
  • 53. Gotcha! Don’t forget to initialize, start and update your game in unit tests! 53 / 58
  • 54. Entity Systems & Unity – Setup MonoDevelop 1. Ensure solution file has version 11: Microsoft Visual Studio Solution File, Format Version 11.00 # Visual Studio 2008 2. Add „After Build“ Custom Command in PostBuildLibraries project options. 54 / 58
  • 55. Future Prospects • Attribute Tables • store arbitrary key-value-pairs • used for initializing all components of an entity • Blueprints • consist of a list of components and an attribute table • created with some kind of editor tool by designers • used for creating entites at run-time • Hierarchical Attribute Tables • used for overloading blueprints with specific entity attribute values • e.g. reduced initial health 55 / 58
  • 56. Future Prospects • building physics system outside of Unity • requires own Vector2 and Vector3 data structures (and conversions) • position of Unity game objects should always reflect physics position • converting PDBs to MDBs • provides more verbose debug output in Unity 56 / 58
  • 57. References • Mick West. Evolve Your Hierarchy. http://cowboyprogramming.com/2007/01/05/evolve-your- heirachy/, January 2007. • Levi Baker. Entity Systems Part 1: Entity and EntityManager. http://blog.chronoclast.com/2010/12/entity-systems-part-1-entity-and.html, December 2010. • Kyle Wilson. Game Object Structure: Inheritance vs. Aggregation. http://gamearchitect.net/Articles/GameObjects1.html, July 2002. • Adam Martin. Entity Systems are the future of MMOG development – Part 1. http://t- machine.org/index.php/2007/09/03/entity-systems-are-the-future-of-mmog-development-part- 1/, September 2007. • Adam Martin. Entity Systems: what makes good Components? good Entities? http://t- machine.org/index.php/2012/03/16/entity-systems-what-makes-good-components-good- entities/, March 2012. • Scott Bilas. A Data-Driven Game Object System. http://scottbilas.com/files/2002/gdc_san_jose/game_objects_slides_with_notes.pdf, Slides, GDC 2002. • Scott Bilas. A Data-Driven Game Object System. http://scottbilas.com/files/2002/gdc_san_jose/game_objects_paper.pdf, Paper, GDC 2002. • Insomniac Games. A Dynamic Component Architecture for High Performance Gameplay. http://www.insomniacgames.com/a-dynamic-component-architecture-for-high-performance- gameplay/, June 2010. 57 / 58
  • 58. Thank you for your attention! Contact Mail dev@npruehs.de Blog http://www.npruehs.de Twitter @npruehs Github https://github.com/npruehs 58 / 58