+ All Categories
Home > Software > Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

Date post: 14-Apr-2017
Category:
Upload: simon-schmid
View: 611 times
Download: 0 times
Share this document with a friend
87
ENTITY COMPONENT SYSTEM ARCHITECTURE Clean, fast and simple with Entitas and Unity
Transcript
Page 1: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

ENTITY COMPONENT SYSTEM

ARCHITECTUREClean, fast and simple with Entitas and Unity

Page 2: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

ARCHITECTUREwhy it matters

Page 3: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

Simon SchmidEngineer

Page 4: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 5: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 6: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 7: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 8: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 9: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

GAME DEVELOPMENTis hard

Page 10: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

GAME ENGINE

Page 11: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

ARCHITECTUREstill?

Page 12: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

DESIGN PATTERNS

Page 13: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

WHY SHOULD Icare

Page 14: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 15: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 16: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 17: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

WHY SHOULD Icare

Page 18: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 19: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

ENTITY COMPONENT SYSTEMARCHITECTURE

Page 20: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

ENTITAS#1 ECS ON GITHUB

Page 21: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

ENTITAS

cleanfast

simple

Page 22: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

ENTITASINTRODUCTION

Page 23: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 24: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 25: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 26: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 27: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 28: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

UNITY COMPONENTS:Data + Behaviour

ENTITAS COMPONENTSData only

Page 29: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

public class Archer : Troop {

public int health; public float speed; // ...

void Awake() { // ... }

void Start() { // ... }

void Update() { // ... }}

Page 30: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

public class Archer : Troop { // Inheritance

public int health; public float speed; // Data // ...

void Awake() { // ... } // Initialization

void Start() { // ... }

void Update() { // ... // Update }}

Page 31: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

// Data only - no behaviour

public class PositionComponent : IComponent { public Vector3 value;}

public class MovableComponent : IComponent {}

Page 32: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

+------------------+ | 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 | +------------+

Page 33: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 34: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

LOGIC?

Page 35: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

Games are interactive simulations— Maxim Zaks

Page 36: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

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); } }}

Page 37: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

SINGLE RESPONSIBILITYprinciple

Page 38: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

SYSTEMSChain of Responsibility

+------------+ +------------+ +------------+ +------------+| | | | | | | || System | +---> | System | +---> | System | +---> | System || | | | | | | |+------------+ +------------+ +------------+ +------------+

Page 39: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

SYSTEMSChain of Responsibility

|-------------------------------- Game Loop --------------------------------|

+------------+ +------------+ +------------+ +------------+| | | | | | | || System | +---> | System | +---> | System | +---> | System || | | | | | | |+------------+ +------------+ +------------+ +------------+

Page 40: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

SYSTEMS IN ENTITAS- Initialize System- Execute System- Reactive System

Page 41: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

DEMOMatch One

Page 42: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 43: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

ENTITAS

▸ cleanfast

simple

Page 44: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

CLEANSeparation of concerns

Composition over InheritanceSingle responsibility principle

Consistency

Page 45: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

SEPARATION OFCONCERNS

Page 46: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 47: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

Composition overINHERITANCE

Page 48: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 49: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 50: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 51: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 52: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 53: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 54: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 55: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 56: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 57: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 58: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 59: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 60: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 61: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 62: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 63: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 64: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 65: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 66: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 67: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 68: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

SINGLE RESPONSIBILITYprinciple

Page 69: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

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); } }}

Page 70: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

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));};

Page 71: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

CONSISTENCY

Page 72: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

CLEANSeparation of concerns

Composition over InheritanceSingle responsibility principle

Consistency

Page 73: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

ENTITAS

clean▸ fastsimple

Page 74: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 75: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

UNITY VS ENTITAS: Objects1000 objects with 2 components

Memory: 9x (2.9 MB vs 0.32 MB)CPU: 17x (105 ms vs 6 ms)

Page 76: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016
Page 77: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

ENTITAS VS UNITY: Logicupdate 25000 objects

Memory: 5x (36.4 MB vs 7.6 MB)CPU: 2x (20.5 ms vs 9.6 ms)

Page 78: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

UNITY BLOG10000 Update() calls by Valentin Simonov

Page 79: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

ENTITAS

cleanfast

▸ simple

Page 80: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

SIMPLEsimilar to Unity

simple conventionseasy to add features

Visual DebuggingReusing code

Page 81: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

SYSTEMSChain of Responsibility

+------------+ +------------+ +------------+ +------------+| | | | | | | || System | +---> | System | +---> | System | +---> | System || | | | | | | |+------------+ +------------+ +------------+ +------------+

Page 82: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

SYSTEMSChain of Responsibility

+------------+ +------------+ +------------+| | | | | || System | +---> | System | +------------------------> | System || | | | | |+------------+ +------------+ +------------+

Page 83: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

SYSTEMSChain of Responsibility

+------------+ +------------+ +------------+ +------------+| | | | | | | || System | +---> | System | +---> | System | +---> | System || | | | | | | |+------------+ +------------+ +------------+ +------------+

Page 84: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

SIMPLEsimilar to Unity

simple conventionseasy to add features

Visual DebuggingReusing code

Page 85: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

ENTITAS ISopen source

GITHUB.COM/SSCHMID/ENTITAS-CSHARP

Page 86: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

WOOGA.COM/JOBS

Page 87: Clean, fast and simple with Entitas and Unity - Unite Melbourne 2016

QUESTIONS?#ENTITAS

GITHUB.COM/SSCHMID/ENTITAS-CSHARP


Recommended