Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
-
Upload
simon-schmid -
Category
Software
-
view
611 -
download
0
Transcript of Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
ENTITY COMPONENT SYSTEM
ARCHITECTUREClean, fast and simple with Entitas and Unity
ARCHITECTUREwhy it matters
Simon SchmidEngineer
GAME DEVELOPMENTis hard
GAME ENGINE
ARCHITECTUREstill?
DESIGN PATTERNS
WHY SHOULD Icare
WHY SHOULD Icare
ENTITY COMPONENT SYSTEMARCHITECTURE
ENTITAS#1 ECS ON GITHUB
ENTITAS
cleanfast
simple
ENTITASINTRODUCTION
UNITY COMPONENTS:Data + Behaviour
ENTITAS COMPONENTSData only
public class Archer : Troop {
public int health; public float speed; // ...
void Awake() { // ... }
void Start() { // ... }
void Update() { // ... }}
public class Archer : Troop { // Inheritance
public int health; public float speed; // Data // ...
void Awake() { // ... } // Initialization
void Start() { // ... }
void Update() { // ... // Update }}
// Data only - no behaviour
public class PositionComponent : IComponent { public Vector3 value;}
public class MovableComponent : IComponent {}
+------------------+ | Pool | |------------------| | 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 | +------------------+ +-----------+ +-----------+ | | | +-------------+ | | e | Groups | | e e | +---> | +------------+ | e | | | | e | e | e | +--------|----+ e | | e | | e e | +------------+
LOGIC?
Games are interactive simulations— Maxim Zaks
public class MovementSystem : IExecuteSystem {
public void Execute() {
var movables = Pools.pool.GetGroup( Matcher.AllOf( Matcher.Velocity, Matcher.Position ));
foreach (var e in movables.GetEntities()) { var pos = e.position.value; e.ReplacePosition(pos + e.velocity.value); } }}
SINGLE RESPONSIBILITYprinciple
SYSTEMSChain of Responsibility
+------------+ +------------+ +------------+ +------------+| | | | | | | || System | +---> | System | +---> | System | +---> | System || | | | | | | |+------------+ +------------+ +------------+ +------------+
SYSTEMSChain of Responsibility
|-------------------------------- Game Loop --------------------------------|
+------------+ +------------+ +------------+ +------------+| | | | | | | || System | +---> | System | +---> | System | +---> | System || | | | | | | |+------------+ +------------+ +------------+ +------------+
SYSTEMS IN ENTITAS- Initialize System- Execute System- Reactive System
DEMOMatch One
ENTITAS
▸ cleanfast
simple
CLEANSeparation of concerns
Composition over InheritanceSingle responsibility principle
Consistency
SEPARATION OFCONCERNS
Composition overINHERITANCE
SINGLE RESPONSIBILITYprinciple
public class MovementSystem : IExecuteSystem {
public void Execute() {
var movables = Pools.pool.GetGroup( Matcher.AllOf( Matcher.Velocity, Matcher.Position ));
foreach (var e in movables.GetEntities()) { var pos = e.position.value; e.ReplacePosition(pos + e.velocity.value); } }}
it["adds velocity to position"] = () => {
// given var pool = Pools.sharedInstance.core; var entity = pool.CreateEntity() .AddPosition(Vector3.one) .AddVelocity(Vector3.one);
var system = pool.CreateSystem(new MovementSystem());
// when system.Execute();
// then entity.position.value.should_be(new Vector3(2, 2, 2));};
CONSISTENCY
CLEANSeparation of concerns
Composition over InheritanceSingle responsibility principle
Consistency
ENTITAS
clean▸ fastsimple
UNITY VS ENTITAS: Objects1000 objects with 2 components
Memory: 9x (2.9 MB vs 0.32 MB)CPU: 17x (105 ms vs 6 ms)
ENTITAS VS UNITY: Logicupdate 25000 objects
Memory: 5x (36.4 MB vs 7.6 MB)CPU: 2x (20.5 ms vs 9.6 ms)
UNITY BLOG10000 Update() calls by Valentin Simonov
ENTITAS
cleanfast
▸ simple
SIMPLEsimilar to Unity
simple conventionseasy to add features
Visual DebuggingReusing code
SYSTEMSChain of Responsibility
+------------+ +------------+ +------------+ +------------+| | | | | | | || System | +---> | System | +---> | System | +---> | System || | | | | | | |+------------+ +------------+ +------------+ +------------+
SYSTEMSChain of Responsibility
+------------+ +------------+ +------------+| | | | | || System | +---> | System | +------------------------> | System || | | | | |+------------+ +------------+ +------------+
SYSTEMSChain of Responsibility
+------------+ +------------+ +------------+ +------------+| | | | | | | || System | +---> | System | +---> | System | +---> | System || | | | | | | |+------------+ +------------+ +------------+ +------------+
SIMPLEsimilar to Unity
simple conventionseasy to add features
Visual DebuggingReusing code
ENTITAS ISopen source
GITHUB.COM/SSCHMID/ENTITAS-CSHARP
WOOGA.COM/JOBS
QUESTIONS?#ENTITAS
GITHUB.COM/SSCHMID/ENTITAS-CSHARP