SlideShare ist ein Scribd-Unternehmen logo
1 von 56
Downloaden Sie, um offline zu lesen
Entity system architecture
with Unity
Maxim Zaks | @icex33 | github.com/mzaks
Simon Schmid | @s_schmid | github.com/sschmid
Wooga
Unity pain points
4 Testability
4 Code sharing
4 Co-dependent logic
4 Querying
4 Deleting code
Testability
Code sharing
Co-dependent logic
Co-dependent logic
Co-dependent logic
Querying
Deleting code
Entitas
Match One Demo
Components are just data
4 no Methods, no Start(), no Update()
4 no inheritance
+-----------+
| Component |
|-----------|
| Data |
+-----------+
PositionComponent
using Entitas;
public class PositionComponent : IComponent
{
public int x;
public int y;
}
GameBoardElementComponent
using Entitas;
public class GameBoardElementComponent : IComponent
{
}
Entity is a container for components
+-----------+
| Entity |
|-----------|
| Component |
| |
| Component |
| |
| Component |
+-----------+
Entity
4 Add Components
4 Replace Components
4 Remove Components
Create Blocker Entity
public static Entity CreateBlocker(this Pool pool, int x, int y)
{
return pool.CreateEntity()
.IsGameBoardElement(true)
.AddPosition(x, y)
.AddResource(Res.Blocker);
}
Pool contains all entities
+------------------+
| Pool |
|------------------|
| e e |
| e e |
| e e |
| e e e |
| e e |
| e e |
| e e e |
| e e e |
+------------------+
Pool
4 Create Entity
4 Destroy Entity
4 Get all Entities
4 Get Group
Groups are subsets of entities
4 Performance optimization for querying
4 Matcher is a filter description
+-------------+ Groups:
| e | Subsets of entities in the pool
| e e | for blazing fast querying
| +------------+
| e | | |
| e | e | e |
+--------|----+ e |
| e |
| e e |
+------------+
Get Group from pool
_pool.GetGroup(
Matcher.AllOf(
Matcher.GameBoardElement,
Matcher.Position
)
);
+------------------+
| Pool | Entitas in a nutshell
|------------------|
| e e | +-----------+
| e e---|----> | Entity |
| e e | |-----------|
| e e e | | Component |
| e e | | | +-----------+
| e e | | Component-|----> | Component |
| e e e | | | |-----------|
| e e e | | Component | | Data |
+------------------+ +-----------+ +-----------+
|
|
| +-------------+ Groups:
| | e | Subsets of entities in the pool
| | e e | for blazing fast querying
+---> | +------------+
| e | | |
| e | e | e |
+--------|----+ e |
| e |
| e e |
+------------+
Behaviour
System
4 Start / Execute
4 No State!!!
+------------------+ +-----------------------------+
| Pool | | System |
|------------------| |-----------------------------|
| e e | | - Execute |
| e e | | |
| e e | | +-------------+ |
| e e e | | | e | Groups |
| e e |+----|->| e e | |
| e e | | | +------------+ |
| e e e | | | e | | | |
| e e e | | | e | e | e | |
+------------------+ | +--------|----+ e | |
| | e | |
| | e e | |
| +------------+ |
+-----------------------------+
MoveSystem
public void Execute() {
var movables = _pool.GetGroup(
Matcher.AllOf(
Matcher.Move,
Matcher.Position
));
foreach (var e in movables.GetEntities()) {
var move = e.move;
var pos = e.position;
e.ReplacePosition(pos.x, pos.y + move.speed, pos.z);
}
}
Chain of Responsibility
| |
|-------------------------------- Game Loop --------------------------------|
| |
+------------+ +------------+ +------------+ +------------+
| | | | | | | |
| System | +---> | System | +---> | System | +---> | System |
| | | | | | | |
+------------+ +------------+ +------------+ +------------+
return new Systems()
.Add( pool.CreateGameBoardSystem ())
.Add( pool.CreateCreateGameBoardCacheSystem ())
.Add( pool.CreateFallSystem ())
.Add( pool.CreateFillSystem ())
.Add( pool.CreateProcessInputSystem ())
.Add( pool.CreateRemoveViewSystem ())
.Add( pool.CreateAddViewSystem ())
.Add( pool.CreateRenderPositionSystem ())
.Add( pool.CreateDestroySystem ())
.Add( pool.CreateScoreSystem ());
Reacting to changes in a Group
4 On Entity added
4 On Entity removed
ScoreLabelController
void Start() {
_pool.GetGroup(Matcher.Score).OnEntityAdded +=
(group, entity) => updateScore(entity.score.value);
updateScore(_pool.score.value);
}
void updateScore(int score) {
_label.text = "Score " + score;
}
Reactive System
4 Executed only when entities in a group have changed
4 Aggregate and process changes
Render Position System
public class RenderPositionSystem : IReactiveSystem {
public IMatcher trigger { get { return Matcher.AllOf(Matcher.Position, Matcher.View); } }
public GroupEventType eventType { get { return GroupEventType.OnEntityAdded; } }
public void Execute(Entity[] entities) {
foreach (var e in entities) {
var pos = e.position;
e.view.gameObject.transform.position = new Vector3(pos.x, pos.y);
}
}
}
Optimizations
Components
mutable vs immutable
Entity
Dictionary vs Array
Dictionary
e.AddComponent(new PositionComponent());
var component = e.GetComponent<PositionComponent>();
Array
e.AddComponent(new PositionComponent(), 5);
var component = (PositionComponent)e.GetComponent(5);
Code Generator
Before Code Generation
PositionComponent component;
if (e.HasComponent(ComponentIds.Position)) {
e.WillRemoveComponent(ComponentIds.Position);
component = (PositionComponent)e.GetComponent(ComponentIds.Position);
} else {
component = new PositionComponent();
}
component.x = 10;
component.y = 10;
e.ReplaceComponent(ComponentIds.Position, component);
After Code Generation
e.ReplacePosition(10, 10);
Code Generator Demo
var pool = Pools.pool;
var e = pool.CreateEntity();
e.AddPosition(1, 2, 3);
e.ReplacePosition(4, 5, 6);
e.RemovePosition();
var posX = e.position.x;
var hasPos = e.hasPosition;
e.isMovable = true;
e.isMovable = false;
var isMovable = e.isMovable;
Visual Debugging Demo
Entitas is
open sourcegithub.com/sschmid/Entitas-CSharp
Recap
Unity pain points
4 Testability
4 Code sharing
4 Co-dependent logic
4 Querying
4 Deleting code
Advantages
4 Straightforward to achieve Determinism and
therefore Replay
4 Simulation Speed (2x, 4x)
4 Headless Simulation, just remove systems which rely
on GameObjects (render systems)
4 Save Game (Serialization / Deserialization) send
data to backend on change
Q&AMaxim Zaks | @icex33 | github.com/mzaks
Simon Schmid | @s_schmid | github.com/sschmid
tinyurl.com/entitas

Weitere ähnliche Inhalte

Andere mochten auch

The Wooga way to create successful games_SBGames Brazil 2012_Thiago Apella
The Wooga way to create successful games_SBGames Brazil 2012_Thiago ApellaThe Wooga way to create successful games_SBGames Brazil 2012_Thiago Apella
The Wooga way to create successful games_SBGames Brazil 2012_Thiago Apella
Wooga
 
2012_11_28_Dont think about working at other companies_BeuthHS_Anne
2012_11_28_Dont think about working at other companies_BeuthHS_Anne2012_11_28_Dont think about working at other companies_BeuthHS_Anne
2012_11_28_Dont think about working at other companies_BeuthHS_Anne
Wooga
 
Social games and their clean code_Clean Code Days_Dresden 2013
Social games and their clean code_Clean Code Days_Dresden 2013Social games and their clean code_Clean Code Days_Dresden 2013
Social games and their clean code_Clean Code Days_Dresden 2013
Wooga
 
Prototyping_Wooga Game Jam
Prototyping_Wooga Game JamPrototyping_Wooga Game Jam
Prototyping_Wooga Game Jam
Wooga
 
What lies ahead of HTML5_Ooop Munich 2013_Krzysztof Szafranek
What lies ahead of HTML5_Ooop Munich 2013_Krzysztof SzafranekWhat lies ahead of HTML5_Ooop Munich 2013_Krzysztof Szafranek
What lies ahead of HTML5_Ooop Munich 2013_Krzysztof Szafranek
Wooga
 
How to hire the best people for your startup-Gitta Blat-Head of People
How to hire the best people for your startup-Gitta Blat-Head of PeopleHow to hire the best people for your startup-Gitta Blat-Head of People
How to hire the best people for your startup-Gitta Blat-Head of People
Wooga
 

Andere mochten auch (20)

Story of Warlords: Bringing a turn-based strategy game to mobile
Story of Warlords: Bringing a turn-based strategy game to mobile Story of Warlords: Bringing a turn-based strategy game to mobile
Story of Warlords: Bringing a turn-based strategy game to mobile
 
Heyworks: Cравнительный анализ решений для клиент-серверного взаимодействия и...
Heyworks: Cравнительный анализ решений для клиент-серверного взаимодействия и...Heyworks: Cравнительный анализ решений для клиент-серверного взаимодействия и...
Heyworks: Cравнительный анализ решений для клиент-серверного взаимодействия и...
 
Deterministic Simulation - What modern online games can learn from the Game B...
Deterministic Simulation - What modern online games can learn from the Game B...Deterministic Simulation - What modern online games can learn from the Game B...
Deterministic Simulation - What modern online games can learn from the Game B...
 
Intro To Starling Framework for ActionScript 3.0
Intro To Starling Framework for ActionScript 3.0Intro To Starling Framework for ActionScript 3.0
Intro To Starling Framework for ActionScript 3.0
 
Эволюция сервисов видео монетизации Unity Ads и сервиса реплей-шеринга Everyp...
Эволюция сервисов видео монетизации Unity Ads и сервиса реплей-шеринга Everyp...Эволюция сервисов видео монетизации Unity Ads и сервиса реплей-шеринга Everyp...
Эволюция сервисов видео монетизации Unity Ads и сервиса реплей-шеринга Everyp...
 
2013 07-24 casual-connect_needle_in_haystack_slideshare
2013 07-24 casual-connect_needle_in_haystack_slideshare2013 07-24 casual-connect_needle_in_haystack_slideshare
2013 07-24 casual-connect_needle_in_haystack_slideshare
 
Two Ann(e)s and one Julia_Wooga Lady Power from Berlin_SGA2014
Two Ann(e)s and one Julia_Wooga Lady Power from Berlin_SGA2014Two Ann(e)s and one Julia_Wooga Lady Power from Berlin_SGA2014
Two Ann(e)s and one Julia_Wooga Lady Power from Berlin_SGA2014
 
Leveling up in localization! - Susan Alma & Dario Quondamstefano
Leveling up in localization! - Susan Alma & Dario QuondamstefanoLeveling up in localization! - Susan Alma & Dario Quondamstefano
Leveling up in localization! - Susan Alma & Dario Quondamstefano
 
The Wooga way to create successful games_SBGames Brazil 2012_Thiago Apella
The Wooga way to create successful games_SBGames Brazil 2012_Thiago ApellaThe Wooga way to create successful games_SBGames Brazil 2012_Thiago Apella
The Wooga way to create successful games_SBGames Brazil 2012_Thiago Apella
 
2012_11_28_Dont think about working at other companies_BeuthHS_Anne
2012_11_28_Dont think about working at other companies_BeuthHS_Anne2012_11_28_Dont think about working at other companies_BeuthHS_Anne
2012_11_28_Dont think about working at other companies_BeuthHS_Anne
 
From Keyboards to Fingertips - Rethink Game Design_QuoVadis 2013
From Keyboards to Fingertips - Rethink Game Design_QuoVadis 2013From Keyboards to Fingertips - Rethink Game Design_QuoVadis 2013
From Keyboards to Fingertips - Rethink Game Design_QuoVadis 2013
 
Evoloution of Ideas
Evoloution of IdeasEvoloution of Ideas
Evoloution of Ideas
 
Social games and their clean code_Clean Code Days_Dresden 2013
Social games and their clean code_Clean Code Days_Dresden 2013Social games and their clean code_Clean Code Days_Dresden 2013
Social games and their clean code_Clean Code Days_Dresden 2013
 
Reaching the World with awesome Games_SGAC13
Reaching the World with awesome Games_SGAC13Reaching the World with awesome Games_SGAC13
Reaching the World with awesome Games_SGAC13
 
Prototyping_Wooga Game Jam
Prototyping_Wooga Game JamPrototyping_Wooga Game Jam
Prototyping_Wooga Game Jam
 
Instagram Celebrities: are they the new cats? - Targetsummit Berlin 2015
Instagram Celebrities: are they the new cats? - Targetsummit Berlin 2015Instagram Celebrities: are they the new cats? - Targetsummit Berlin 2015
Instagram Celebrities: are they the new cats? - Targetsummit Berlin 2015
 
What lies ahead of HTML5_Ooop Munich 2013_Krzysztof Szafranek
What lies ahead of HTML5_Ooop Munich 2013_Krzysztof SzafranekWhat lies ahead of HTML5_Ooop Munich 2013_Krzysztof Szafranek
What lies ahead of HTML5_Ooop Munich 2013_Krzysztof Szafranek
 
In it for the long haul - How Wooga boosts long-term retention
In it for the long haul - How Wooga boosts long-term retentionIn it for the long haul - How Wooga boosts long-term retention
In it for the long haul - How Wooga boosts long-term retention
 
Storytelling in social games
Storytelling in social gamesStorytelling in social games
Storytelling in social games
 
How to hire the best people for your startup-Gitta Blat-Head of People
How to hire the best people for your startup-Gitta Blat-Head of PeopleHow to hire the best people for your startup-Gitta Blat-Head of People
How to hire the best people for your startup-Gitta Blat-Head of People
 

Ähnlich wie Entitas System Architecture with Unity - Maxim Zaks and Simon Schmid

15 protips for mysql users pfz
15 protips for mysql users   pfz15 protips for mysql users   pfz
15 protips for mysql users pfz
Joshua Thijssen
 
The story and tech of Read the Docs
The story and tech of Read the DocsThe story and tech of Read the Docs
The story and tech of Read the Docs
ericholscher
 
pytest로 파이썬 코드 테스트하기
pytest로 파이썬 코드 테스트하기pytest로 파이썬 코드 테스트하기
pytest로 파이썬 코드 테스트하기
Yeongseon Choe
 

Ähnlich wie Entitas System Architecture with Unity - Maxim Zaks and Simon Schmid (20)

Entity system architecture with Unity @Unite Europe 2015
Entity system architecture with Unity @Unite Europe 2015 Entity system architecture with Unity @Unite Europe 2015
Entity system architecture with Unity @Unite Europe 2015
 
MySQL Kitchen : spice up your everyday SQL queries
MySQL Kitchen : spice up your everyday SQL queriesMySQL Kitchen : spice up your everyday SQL queries
MySQL Kitchen : spice up your everyday SQL queries
 
Pyspark
PysparkPyspark
Pyspark
 
15 protips for mysql users pfz
15 protips for mysql users   pfz15 protips for mysql users   pfz
15 protips for mysql users pfz
 
Observability of InfluxDB IOx: Tracing, Metrics and System Tables
Observability of InfluxDB IOx: Tracing, Metrics and System TablesObservability of InfluxDB IOx: Tracing, Metrics and System Tables
Observability of InfluxDB IOx: Tracing, Metrics and System Tables
 
BigQuery implementation
BigQuery implementationBigQuery implementation
BigQuery implementation
 
M|18 User Defined Function
M|18 User Defined FunctionM|18 User Defined Function
M|18 User Defined Function
 
The story and tech of Read the Docs
The story and tech of Read the DocsThe story and tech of Read the Docs
The story and tech of Read the Docs
 
ITGM8. Всеволод Брекелов (Grid Dinamics) Component tests. let's do that!
ITGM8. Всеволод Брекелов (Grid Dinamics) Component tests. let's do that!ITGM8. Всеволод Брекелов (Grid Dinamics) Component tests. let's do that!
ITGM8. Всеволод Брекелов (Grid Dinamics) Component tests. let's do that!
 
CoreOS in anger : firing up wordpress across a 3 machine CoreOS cluster
CoreOS in anger : firing up wordpress across a 3 machine CoreOS cluster CoreOS in anger : firing up wordpress across a 3 machine CoreOS cluster
CoreOS in anger : firing up wordpress across a 3 machine CoreOS cluster
 
pytest로 파이썬 코드 테스트하기
pytest로 파이썬 코드 테스트하기pytest로 파이썬 코드 테스트하기
pytest로 파이썬 코드 테스트하기
 
How to build and run oci containers
How to build and run oci containersHow to build and run oci containers
How to build and run oci containers
 
Real
RealReal
Real
 
Running automated tests with Sparx Enterprise Architect add-ins, London EA Us...
Running automated tests with Sparx Enterprise Architect add-ins, London EA Us...Running automated tests with Sparx Enterprise Architect add-ins, London EA Us...
Running automated tests with Sparx Enterprise Architect add-ins, London EA Us...
 
Cruel (SQL) Intentions
Cruel (SQL) IntentionsCruel (SQL) Intentions
Cruel (SQL) Intentions
 
Planet-HTML5-Game-Engine Javascript Performance Enhancement
Planet-HTML5-Game-Engine Javascript Performance EnhancementPlanet-HTML5-Game-Engine Javascript Performance Enhancement
Planet-HTML5-Game-Engine Javascript Performance Enhancement
 
忙しい人のためのSphinx 入門 demo
忙しい人のためのSphinx 入門 demo忙しい人のためのSphinx 入門 demo
忙しい人のためのSphinx 入門 demo
 
Quick and Dirty GUI Applications using GUIDeFATE
Quick and Dirty GUI Applications using GUIDeFATEQuick and Dirty GUI Applications using GUIDeFATE
Quick and Dirty GUI Applications using GUIDeFATE
 
Introduction to Git Source Control
Introduction to Git Source ControlIntroduction to Git Source Control
Introduction to Git Source Control
 
Perf Tuning Short
Perf Tuning ShortPerf Tuning Short
Perf Tuning Short
 

Mehr von Wooga

Riak & Wooga_Geeek2Geeek Meetup2014 Berlin
Riak & Wooga_Geeek2Geeek Meetup2014 BerlinRiak & Wooga_Geeek2Geeek Meetup2014 Berlin
Riak & Wooga_Geeek2Geeek Meetup2014 Berlin
Wooga
 
Staying in the Game: Game localization practices for the mobile market
Staying in the Game: Game localization practices for the mobile marketStaying in the Game: Game localization practices for the mobile market
Staying in the Game: Game localization practices for the mobile market
Wooga
 
Startup Weekend_Makers and Games_Philipp Stelzer
Startup Weekend_Makers and Games_Philipp StelzerStartup Weekend_Makers and Games_Philipp Stelzer
Startup Weekend_Makers and Games_Philipp Stelzer
Wooga
 
CodeFest 2014_Mobile Game Development
CodeFest 2014_Mobile Game DevelopmentCodeFest 2014_Mobile Game Development
CodeFest 2014_Mobile Game Development
Wooga
 
Pocket Gamer Connects 2014_The Experience of Entering the Korean Market
Pocket Gamer Connects 2014_The Experience of Entering the Korean MarketPocket Gamer Connects 2014_The Experience of Entering the Korean Market
Pocket Gamer Connects 2014_The Experience of Entering the Korean Market
Wooga
 
Riak at Wooga_Riak Meetup Sept 2013
Riak at Wooga_Riak Meetup Sept 2013Riak at Wooga_Riak Meetup Sept 2013
Riak at Wooga_Riak Meetup Sept 2013
Wooga
 

Mehr von Wooga (20)

Saying No to the CEO: A Deep Look at Independent Teams - Adam Telfer
Saying No to the CEO: A Deep Look at Independent Teams - Adam TelferSaying No to the CEO: A Deep Look at Independent Teams - Adam Telfer
Saying No to the CEO: A Deep Look at Independent Teams - Adam Telfer
 
Innovation dank DevOps (DevOpsCon Berlin 2015)
Innovation dank DevOps (DevOpsCon Berlin 2015)Innovation dank DevOps (DevOpsCon Berlin 2015)
Innovation dank DevOps (DevOpsCon Berlin 2015)
 
Big Fish, small pond - strategies for surviving in a maturing market - Ed Biden
Big Fish, small pond - strategies for surviving in a maturing market - Ed BidenBig Fish, small pond - strategies for surviving in a maturing market - Ed Biden
Big Fish, small pond - strategies for surviving in a maturing market - Ed Biden
 
Review mining aps2014 berlin
Review mining aps2014 berlinReview mining aps2014 berlin
Review mining aps2014 berlin
 
Riak & Wooga_Geeek2Geeek Meetup2014 Berlin
Riak & Wooga_Geeek2Geeek Meetup2014 BerlinRiak & Wooga_Geeek2Geeek Meetup2014 Berlin
Riak & Wooga_Geeek2Geeek Meetup2014 Berlin
 
Staying in the Game: Game localization practices for the mobile market
Staying in the Game: Game localization practices for the mobile marketStaying in the Game: Game localization practices for the mobile market
Staying in the Game: Game localization practices for the mobile market
 
Startup Weekend_Makers and Games_Philipp Stelzer
Startup Weekend_Makers and Games_Philipp StelzerStartup Weekend_Makers and Games_Philipp Stelzer
Startup Weekend_Makers and Games_Philipp Stelzer
 
DevOps goes Mobile (daho.am)
DevOps goes Mobile (daho.am)DevOps goes Mobile (daho.am)
DevOps goes Mobile (daho.am)
 
DevOps goes Mobile - Jax 2014 - Jesper Richter-Reichhelm
DevOps goes Mobile - Jax 2014 - Jesper Richter-ReichhelmDevOps goes Mobile - Jax 2014 - Jesper Richter-Reichhelm
DevOps goes Mobile - Jax 2014 - Jesper Richter-Reichhelm
 
CodeFest 2014_Mobile Game Development
CodeFest 2014_Mobile Game DevelopmentCodeFest 2014_Mobile Game Development
CodeFest 2014_Mobile Game Development
 
Jelly Splash: Puzzling your way to the top of the App Stores - GDC 2014
Jelly Splash: Puzzling your way to the top of the App Stores - GDC 2014Jelly Splash: Puzzling your way to the top of the App Stores - GDC 2014
Jelly Splash: Puzzling your way to the top of the App Stores - GDC 2014
 
Pocket Gamer Connects 2014_The Experience of Entering the Korean Market
Pocket Gamer Connects 2014_The Experience of Entering the Korean MarketPocket Gamer Connects 2014_The Experience of Entering the Korean Market
Pocket Gamer Connects 2014_The Experience of Entering the Korean Market
 
How to stand out in a hit driven business - Game Connection Paris 2013 - SebK...
How to stand out in a hit driven business - Game Connection Paris 2013 - SebK...How to stand out in a hit driven business - Game Connection Paris 2013 - SebK...
How to stand out in a hit driven business - Game Connection Paris 2013 - SebK...
 
DevOps the Wooga way (Webmontag Berlin)
DevOps the Wooga way (Webmontag Berlin)DevOps the Wooga way (Webmontag Berlin)
DevOps the Wooga way (Webmontag Berlin)
 
Why Having Impact Matters for Good Developers (GOTO Berlin)
Why Having Impact Matters for Good Developers (GOTO Berlin)Why Having Impact Matters for Good Developers (GOTO Berlin)
Why Having Impact Matters for Good Developers (GOTO Berlin)
 
Beyond Devops_GOTOBerlin2013_Tim Lossen
Beyond Devops_GOTOBerlin2013_Tim LossenBeyond Devops_GOTOBerlin2013_Tim Lossen
Beyond Devops_GOTOBerlin2013_Tim Lossen
 
2013 10-03-ngs-samuli snellman-bridging
2013 10-03-ngs-samuli snellman-bridging2013 10-03-ngs-samuli snellman-bridging
2013 10-03-ngs-samuli snellman-bridging
 
Reliving the history of multiplayer games
Reliving the history of multiplayer gamesReliving the history of multiplayer games
Reliving the history of multiplayer games
 
Riak at Wooga_Riak Meetup Sept 2013
Riak at Wooga_Riak Meetup Sept 2013Riak at Wooga_Riak Meetup Sept 2013
Riak at Wooga_Riak Meetup Sept 2013
 
Programmin games - A 10 minute crash course
Programmin games - A 10 minute crash courseProgrammin games - A 10 minute crash course
Programmin games - A 10 minute crash course
 

Kürzlich hochgeladen

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Kürzlich hochgeladen (20)

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 

Entitas System Architecture with Unity - Maxim Zaks and Simon Schmid

  • 2. Maxim Zaks | @icex33 | github.com/mzaks Simon Schmid | @s_schmid | github.com/sschmid
  • 4.
  • 5. Unity pain points 4 Testability 4 Code sharing 4 Co-dependent logic 4 Querying 4 Deleting code
  • 13.
  • 15.
  • 16. Components are just data 4 no Methods, no Start(), no Update() 4 no inheritance +-----------+ | Component | |-----------| | Data | +-----------+
  • 17. PositionComponent using Entitas; public class PositionComponent : IComponent { public int x; public int y; }
  • 18. GameBoardElementComponent using Entitas; public class GameBoardElementComponent : IComponent { }
  • 19. Entity is a container for components +-----------+ | Entity | |-----------| | Component | | | | Component | | | | Component | +-----------+
  • 20. Entity 4 Add Components 4 Replace Components 4 Remove Components
  • 21. Create Blocker Entity public static Entity CreateBlocker(this Pool pool, int x, int y) { return pool.CreateEntity() .IsGameBoardElement(true) .AddPosition(x, y) .AddResource(Res.Blocker); }
  • 22. Pool contains all entities +------------------+ | Pool | |------------------| | e e | | e e | | e e | | e e e | | e e | | e e | | e e e | | e e e | +------------------+
  • 23. Pool 4 Create Entity 4 Destroy Entity 4 Get all Entities 4 Get Group
  • 24. Groups are subsets of entities 4 Performance optimization for querying 4 Matcher is a filter description +-------------+ Groups: | e | Subsets of entities in the pool | e e | for blazing fast querying | +------------+ | e | | | | e | e | e | +--------|----+ e | | e | | e e | +------------+
  • 25. Get Group from pool _pool.GetGroup( Matcher.AllOf( Matcher.GameBoardElement, Matcher.Position ) );
  • 26. +------------------+ | Pool | Entitas in a nutshell |------------------| | e e | +-----------+ | e e---|----> | Entity | | e e | |-----------| | e e e | | Component | | e e | | | +-----------+ | e e | | Component-|----> | Component | | e e e | | | |-----------| | e e e | | Component | | Data | +------------------+ +-----------+ +-----------+ | | | +-------------+ Groups: | | e | Subsets of entities in the pool | | e e | for blazing fast querying +---> | +------------+ | e | | | | e | e | e | +--------|----+ e | | e | | e e | +------------+
  • 28. System 4 Start / Execute 4 No State!!!
  • 29. +------------------+ +-----------------------------+ | Pool | | System | |------------------| |-----------------------------| | e e | | - Execute | | e e | | | | e e | | +-------------+ | | e e e | | | e | Groups | | e e |+----|->| e e | | | e e | | | +------------+ | | e e e | | | e | | | | | e e e | | | e | e | e | | +------------------+ | +--------|----+ e | | | | e | | | | e e | | | +------------+ | +-----------------------------+
  • 30. MoveSystem public void Execute() { var movables = _pool.GetGroup( Matcher.AllOf( Matcher.Move, Matcher.Position )); foreach (var e in movables.GetEntities()) { var move = e.move; var pos = e.position; e.ReplacePosition(pos.x, pos.y + move.speed, pos.z); } }
  • 31. Chain of Responsibility | | |-------------------------------- Game Loop --------------------------------| | | +------------+ +------------+ +------------+ +------------+ | | | | | | | | | System | +---> | System | +---> | System | +---> | System | | | | | | | | | +------------+ +------------+ +------------+ +------------+
  • 32. return new Systems() .Add( pool.CreateGameBoardSystem ()) .Add( pool.CreateCreateGameBoardCacheSystem ()) .Add( pool.CreateFallSystem ()) .Add( pool.CreateFillSystem ()) .Add( pool.CreateProcessInputSystem ()) .Add( pool.CreateRemoveViewSystem ()) .Add( pool.CreateAddViewSystem ()) .Add( pool.CreateRenderPositionSystem ()) .Add( pool.CreateDestroySystem ()) .Add( pool.CreateScoreSystem ());
  • 33. Reacting to changes in a Group 4 On Entity added 4 On Entity removed
  • 34. ScoreLabelController void Start() { _pool.GetGroup(Matcher.Score).OnEntityAdded += (group, entity) => updateScore(entity.score.value); updateScore(_pool.score.value); } void updateScore(int score) { _label.text = "Score " + score; }
  • 35. Reactive System 4 Executed only when entities in a group have changed 4 Aggregate and process changes
  • 36. Render Position System public class RenderPositionSystem : IReactiveSystem { public IMatcher trigger { get { return Matcher.AllOf(Matcher.Position, Matcher.View); } } public GroupEventType eventType { get { return GroupEventType.OnEntityAdded; } } public void Execute(Entity[] entities) { foreach (var e in entities) { var pos = e.position; e.view.gameObject.transform.position = new Vector3(pos.x, pos.y); } } }
  • 39.
  • 40.
  • 42. Dictionary e.AddComponent(new PositionComponent()); var component = e.GetComponent<PositionComponent>(); Array e.AddComponent(new PositionComponent(), 5); var component = (PositionComponent)e.GetComponent(5);
  • 43.
  • 44.
  • 46. Before Code Generation PositionComponent component; if (e.HasComponent(ComponentIds.Position)) { e.WillRemoveComponent(ComponentIds.Position); component = (PositionComponent)e.GetComponent(ComponentIds.Position); } else { component = new PositionComponent(); } component.x = 10; component.y = 10; e.ReplaceComponent(ComponentIds.Position, component);
  • 49. var pool = Pools.pool; var e = pool.CreateEntity(); e.AddPosition(1, 2, 3); e.ReplacePosition(4, 5, 6); e.RemovePosition(); var posX = e.position.x; var hasPos = e.hasPosition; e.isMovable = true; e.isMovable = false; var isMovable = e.isMovable;
  • 51.
  • 53. Recap
  • 54. Unity pain points 4 Testability 4 Code sharing 4 Co-dependent logic 4 Querying 4 Deleting code
  • 55. Advantages 4 Straightforward to achieve Determinism and therefore Replay 4 Simulation Speed (2x, 4x) 4 Headless Simulation, just remove systems which rely on GameObjects (render systems) 4 Save Game (Serialization / Deserialization) send data to backend on change
  • 56. Q&AMaxim Zaks | @icex33 | github.com/mzaks Simon Schmid | @s_schmid | github.com/sschmid tinyurl.com/entitas