SlideShare a Scribd company logo
1 of 35
Download to read offline
Entity Component System
for App developers
@iceX33
History & Facts
4 First known game 1998 Thief: The Dark Project
4 My first encounter 2012 With ECS
4 Articles that convinced me "What is an entity system
framework for game development?" by Richard Lord
4 ObjectiveC library I used: Entitas
4 Two Apps I built with Entitas UIKonf-App & Resi App
DEMO
Entity | Component | System
----> State <------> Behaviour
What is a Component
public protocol Component {}
public protocol UniqueComopnent : Component {}
Component is a value type
struct TickComponent : UniqueComopnent{
let value : UInt64
}
struct ElixirComponent : UniqueComopnent{
let value : Float
}
struct ConsumeElixirComponent : Component{
let value : Int
}
struct PauseComponent : UniqueComopnent{}
struct JumpIntTimeComponent : UniqueComopnent{
let value : UInt64
}
Entity is a collection of components
public final class Entity {
private var _components : [ComponentId:Component]
...
}
e.set(ConsumeElixirComponent(value:2))
let amount = e.get(ConsumeElixirComponent.self)?.value
e.remove(ConsumeElixirComponent.self)
Components = Lego pieces
Entites = things you build
with them
let ctx = Context()
let e = ctx.createEntity()
e.set(NameComponent(value:"Maxim"))
let g = ctx.getEntityGroup(NameComponent.matcher)
assert(g.count == 1)
e.set(NameComponent(value:"Leo"), overwrite:true)
assert(g.count == 1)
e.remove(NameComponent.self)
assert(g.count == 0)
What about behaviour
What is a System
public protocol ASystem : class {}
public protocol InitialiseSystem : ASystem {
func initialize()
}
public protocol ExecuteSystem : ASystem {
func execute()
}
public protocol CleanupSystem : ASystem {
func cleanup()
}
System Example
class TickUpdateSystem : InitialiseSystem, ExecuteSystem {
let ctx : Context
init(ctx : Context) {
self.ctx = ctx
}
func initialize() {
ctx.setUniqueEntityWith(TickComponent(value: 0))
}
func execute() {
guard ctx.hasUniqueComponent(PauseComponent.self) == false,
let currentTick = ctx.uniqueComponent(TickComponent.self)?.value else {
return
}
ctx.setUniqueEntityWith(TickComponent(value: currentTick + 1))
}
}
Reactive System
Reactive System
public protocol ReactiveSystem : ExecuteSystem {
var collector : Collector! {get set}
var limit : Int {get}
func execute(input : ArraySlice<Entity>)
}
public extension ReactiveSystem {
func execute(){
if let collector = collector {
let entities = collector.pull(limit)
if entities.count > 0 {
execute(input: entities)
}
}
}
var limit : Int { return -1 }
}
Reactive System Example
class ElixirProduceSystem : InitialiseSystem, ReactiveSystem {
var collector: Collector!
let ctx : Context
private let productionFrequency = 3
private let elixirCapacity : Float = 10
private let productionStep : Float = 0.01
private(set) var limit: Int = 1
init(ctx : Context) {
self.ctx = ctx
collector = Collector(group: ctx.entityGroup(TickComponent.matcher), changeType: .added)
}
func initialize() {
ctx.setUniqueEntityWith(ElixirComponent(value: 0))
}
func execute(input: ArraySlice<Entity>) {
guard let tick = input.first?.get(TickComponent.self)?.value,
(tick % UInt64(productionFrequency)) == 0,
let elixirAmount = ctx.uniqueComponent(ElixirComponent.self)?.value else{
return
}
let newAmount = min(elixirCapacity, elixirAmount + productionStep)
ctx.setUniqueEntityWith(ElixirComponent(value: newAmount))
}
}
What about UI
UI Action
@IBAction func pauseResume(_ sender: UIButton) {
if ctx.hasUniqueComponent(PauseComponent.self) {
ctx.destroyUniqueEntity(PauseComponent.matcher)
} else {
ctx.setUniqueEntityWith(PauseComponent())
}
}
@IBAction func consumeAction(_ sender: UIButton) {
ctx.createEntity().set(ConsumeElixirComponent(value: sender.tag))
}
@IBAction func timeTravel(_ sender: UISlider) {
ctx.setUniqueEntityWith(JumpIntTimeComponent(value: UInt64(sender.value)))
}
What about Reactive UI
protocol TickListener {
func tickChanged(tick : UInt64)
}
struct TickListenerComponent : Component {
let ref : TickListener
}
protocol PauseListener {
func pauseStateChanged(paused : Bool)
}
struct PauseListenerComponent : Component {
let ref : PauseListener
}
protocol ElixirListener {
func elixirChanged(amount : Float)
}
struct ElixirListenerComponent : Component {
let ref : ElixirListener
}
ViewController is a listener
class ViewController: UIViewController, TickListener, ElixirListener, PauseListener {
...
override func viewDidLoad() {
ctx.createEntity()
.set(TickListenerComponent(ref: self))
.set(ElixirListenerComponent(ref: self))
.set(PauseListenerComponent(ref: self))
}
...
}
Or if you like it less monolithic
struct ConsumeButtonController : PauseListener, ElixirListener {
let consumeButton : UIButton
let consumeButtonProgress: UIProgressView
let ctx : Context
func pauseStateChanged(paused: Bool) {
consumeButton.isEnabled = !paused
}
func elixirChanged(amount: Float) {
let paused = ctx.hasUniqueComponent(PauseComponent.self)
consumeButton.isEnabled = consumeButton.tag <= Int(amount) && !paused
consumeButtonProgress.progress = 1 - min(1, (amount / Float(consumeButton.tag)))
}
}
Reactive System + UIKit
class NotifyPauseListenersSystem : ReactiveSystem {
var collector: Collector!
let ctx : Context
var limit: Int = 1
let listeners : Group
init(ctx : Context) {
self.ctx = ctx
collector = Collector(group: ctx.entityGroup(PauseComponent.matcher), changeType: .addedAndRemoved)
listeners = ctx.entityGroup(PauseListenerComponent.matcher)
}
func execute(input: ArraySlice<Entity>) {
let paused = ctx.hasUniqueComponent(PauseComponent.self)
for e in listeners {
e.get(PauseListenerComponent.self)?
.ref.pauseStateChanged(paused: paused)
}
}
}
Show me the code & tests
ECS
vs.
MVC | MVVM | Rx | ReSwift
Bonus material
Questions?
@iceX33
Thank you!

More Related Content

What's hot

Mastering Kotlin Standard Library
Mastering Kotlin Standard LibraryMastering Kotlin Standard Library
Mastering Kotlin Standard LibraryNelson Glauber Leal
 
Building serverless application on the Apache Openwhisk platform
Building serverless application on the Apache Openwhisk platformBuilding serverless application on the Apache Openwhisk platform
Building serverless application on the Apache Openwhisk platformLucio Grenzi
 
Concurrent Collections Object In Dot Net 4
Concurrent Collections Object In Dot Net 4Concurrent Collections Object In Dot Net 4
Concurrent Collections Object In Dot Net 4Neeraj Kaushik
 
OSGi World Congress Workshop Exercise - P Kriens
OSGi World Congress Workshop Exercise - P KriensOSGi World Congress Workshop Exercise - P Kriens
OSGi World Congress Workshop Exercise - P Kriensmfrancis
 
Mirage For Beginners
Mirage For BeginnersMirage For Beginners
Mirage For BeginnersWilson Su
 
Akka.NET streams and reactive streams
Akka.NET streams and reactive streamsAkka.NET streams and reactive streams
Akka.NET streams and reactive streamsBartosz Sypytkowski
 
Behind modern concurrency primitives
Behind modern concurrency primitivesBehind modern concurrency primitives
Behind modern concurrency primitivesBartosz Sypytkowski
 
Swift Sequences & Collections
Swift Sequences & CollectionsSwift Sequences & Collections
Swift Sequences & CollectionsCocoaHeads France
 
Servletand sessiontracking
Servletand sessiontrackingServletand sessiontracking
Servletand sessiontrackingvamsi krishna
 
Correcting Common Async/Await Mistakes in .NET
Correcting Common Async/Await Mistakes in .NETCorrecting Common Async/Await Mistakes in .NET
Correcting Common Async/Await Mistakes in .NETBrandon Minnick, MBA
 
Threading in iOS / Cocoa Touch
Threading in iOS / Cocoa TouchThreading in iOS / Cocoa Touch
Threading in iOS / Cocoa Touchmobiledeveloperpl
 
Vapor – Swift is not only for iOS anymore
Vapor – Swift is not only for iOS anymoreVapor – Swift is not only for iOS anymore
Vapor – Swift is not only for iOS anymoreMilan Vít
 
Correcting Common .NET Async/Await Mistakes
Correcting Common .NET Async/Await MistakesCorrecting Common .NET Async/Await Mistakes
Correcting Common .NET Async/Await MistakesBrandon Minnick, MBA
 

What's hot (20)

Mastering Kotlin Standard Library
Mastering Kotlin Standard LibraryMastering Kotlin Standard Library
Mastering Kotlin Standard Library
 
Building serverless application on the Apache Openwhisk platform
Building serverless application on the Apache Openwhisk platformBuilding serverless application on the Apache Openwhisk platform
Building serverless application on the Apache Openwhisk platform
 
Concurrent Collections Object In Dot Net 4
Concurrent Collections Object In Dot Net 4Concurrent Collections Object In Dot Net 4
Concurrent Collections Object In Dot Net 4
 
Forgive me for i have allocated
Forgive me for i have allocatedForgive me for i have allocated
Forgive me for i have allocated
 
Posfix
PosfixPosfix
Posfix
 
OSGi World Congress Workshop Exercise - P Kriens
OSGi World Congress Workshop Exercise - P KriensOSGi World Congress Workshop Exercise - P Kriens
OSGi World Congress Workshop Exercise - P Kriens
 
Parallel streams in java 8
Parallel streams in java 8Parallel streams in java 8
Parallel streams in java 8
 
Understanding greenlet
Understanding greenletUnderstanding greenlet
Understanding greenlet
 
Android Threading
Android ThreadingAndroid Threading
Android Threading
 
Mirage For Beginners
Mirage For BeginnersMirage For Beginners
Mirage For Beginners
 
Akka.NET streams and reactive streams
Akka.NET streams and reactive streamsAkka.NET streams and reactive streams
Akka.NET streams and reactive streams
 
Behind modern concurrency primitives
Behind modern concurrency primitivesBehind modern concurrency primitives
Behind modern concurrency primitives
 
Swift Sequences & Collections
Swift Sequences & CollectionsSwift Sequences & Collections
Swift Sequences & Collections
 
Selenium inputs
Selenium inputsSelenium inputs
Selenium inputs
 
Servletand sessiontracking
Servletand sessiontrackingServletand sessiontracking
Servletand sessiontracking
 
Correcting Common Async/Await Mistakes in .NET
Correcting Common Async/Await Mistakes in .NETCorrecting Common Async/Await Mistakes in .NET
Correcting Common Async/Await Mistakes in .NET
 
Threading in iOS / Cocoa Touch
Threading in iOS / Cocoa TouchThreading in iOS / Cocoa Touch
Threading in iOS / Cocoa Touch
 
Vapor – Swift is not only for iOS anymore
Vapor – Swift is not only for iOS anymoreVapor – Swift is not only for iOS anymore
Vapor – Swift is not only for iOS anymore
 
Correcting Common .NET Async/Await Mistakes
Correcting Common .NET Async/Await MistakesCorrecting Common .NET Async/Await Mistakes
Correcting Common .NET Async/Await Mistakes
 
Python, do you even async?
Python, do you even async?Python, do you even async?
Python, do you even async?
 

Viewers also liked

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 Maxim Zaks
 
Park West Gallery New Year's Eve Fine Art Collection [2010]
Park West Gallery New Year's Eve Fine Art Collection [2010]Park West Gallery New Year's Eve Fine Art Collection [2010]
Park West Gallery New Year's Eve Fine Art Collection [2010]parkwestgal
 
Certificate in PIP-Shell GTL
Certificate in PIP-Shell GTLCertificate in PIP-Shell GTL
Certificate in PIP-Shell GTLgilbertdt
 
Daily Newsletter: 20th December, 2010
Daily Newsletter: 20th December, 2010Daily Newsletter: 20th December, 2010
Daily Newsletter: 20th December, 2010Fullerton Securities
 
El modernismo
El modernismoEl modernismo
El modernismomoresita
 
Roboty związane z montażem przewodów instalacji gazowych oraz podłączaniem ur...
Roboty związane z montażem przewodów instalacji gazowych oraz podłączaniem ur...Roboty związane z montażem przewodów instalacji gazowych oraz podłączaniem ur...
Roboty związane z montażem przewodów instalacji gazowych oraz podłączaniem ur...Szymon Konkol - Publikacje Cyfrowe
 
Ta emot praktikanter med uppehållstillstånd #welcometalent
Ta emot praktikanter med uppehållstillstånd #welcometalent Ta emot praktikanter med uppehållstillstånd #welcometalent
Ta emot praktikanter med uppehållstillstånd #welcometalent LinkedIn Nordic
 
The Science of Monitoring Yourself
The Science of Monitoring YourselfThe Science of Monitoring Yourself
The Science of Monitoring YourselfMary Thengvall
 
Avoiding a Lost Generation (Part2): Ten key recommendations to support youth ...
Avoiding a Lost Generation (Part2): Ten key recommendations to support youth ...Avoiding a Lost Generation (Part2): Ten key recommendations to support youth ...
Avoiding a Lost Generation (Part2): Ten key recommendations to support youth ...EY
 
Evaluation Question 1 (ii)
Evaluation Question 1 (ii)Evaluation Question 1 (ii)
Evaluation Question 1 (ii)mediagroup16
 
Guido Everaert - Storytelling & Content Strategy
Guido Everaert - Storytelling & Content StrategyGuido Everaert - Storytelling & Content Strategy
Guido Everaert - Storytelling & Content StrategySanoma Belgium
 
Thirkell Elementary - Park West Gallery - Beyond Basics
Thirkell Elementary - Park West Gallery - Beyond BasicsThirkell Elementary - Park West Gallery - Beyond Basics
Thirkell Elementary - Park West Gallery - Beyond Basicsparkwestgal
 
Guia de estudio de la materia de taller de lectura y redacción 2
Guia de estudio de la materia de taller de lectura y redacción 2Guia de estudio de la materia de taller de lectura y redacción 2
Guia de estudio de la materia de taller de lectura y redacción 2Aleyda Ortiz
 
Video Marketing Cycle
Video Marketing CycleVideo Marketing Cycle
Video Marketing Cyclejazz4us
 

Viewers also liked (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
 
Pmi
PmiPmi
Pmi
 
Park West Gallery New Year's Eve Fine Art Collection [2010]
Park West Gallery New Year's Eve Fine Art Collection [2010]Park West Gallery New Year's Eve Fine Art Collection [2010]
Park West Gallery New Year's Eve Fine Art Collection [2010]
 
Andres Felipe Orozco Garcia
Andres Felipe Orozco GarciaAndres Felipe Orozco Garcia
Andres Felipe Orozco Garcia
 
Certificate in PIP-Shell GTL
Certificate in PIP-Shell GTLCertificate in PIP-Shell GTL
Certificate in PIP-Shell GTL
 
Daily Newsletter: 20th December, 2010
Daily Newsletter: 20th December, 2010Daily Newsletter: 20th December, 2010
Daily Newsletter: 20th December, 2010
 
El modernismo
El modernismoEl modernismo
El modernismo
 
02 celula
02 celula02 celula
02 celula
 
Roboty związane z montażem przewodów instalacji gazowych oraz podłączaniem ur...
Roboty związane z montażem przewodów instalacji gazowych oraz podłączaniem ur...Roboty związane z montażem przewodów instalacji gazowych oraz podłączaniem ur...
Roboty związane z montażem przewodów instalacji gazowych oraz podłączaniem ur...
 
Ta emot praktikanter med uppehållstillstånd #welcometalent
Ta emot praktikanter med uppehållstillstånd #welcometalent Ta emot praktikanter med uppehållstillstånd #welcometalent
Ta emot praktikanter med uppehållstillstånd #welcometalent
 
Kwantologia stosowana 6
Kwantologia stosowana 6Kwantologia stosowana 6
Kwantologia stosowana 6
 
The Science of Monitoring Yourself
The Science of Monitoring YourselfThe Science of Monitoring Yourself
The Science of Monitoring Yourself
 
Avoiding a Lost Generation (Part2): Ten key recommendations to support youth ...
Avoiding a Lost Generation (Part2): Ten key recommendations to support youth ...Avoiding a Lost Generation (Part2): Ten key recommendations to support youth ...
Avoiding a Lost Generation (Part2): Ten key recommendations to support youth ...
 
Evaluation Question 1 (ii)
Evaluation Question 1 (ii)Evaluation Question 1 (ii)
Evaluation Question 1 (ii)
 
科伦网络
科伦网络科伦网络
科伦网络
 
-{-_-}-
-{-_-}--{-_-}-
-{-_-}-
 
Guido Everaert - Storytelling & Content Strategy
Guido Everaert - Storytelling & Content StrategyGuido Everaert - Storytelling & Content Strategy
Guido Everaert - Storytelling & Content Strategy
 
Thirkell Elementary - Park West Gallery - Beyond Basics
Thirkell Elementary - Park West Gallery - Beyond BasicsThirkell Elementary - Park West Gallery - Beyond Basics
Thirkell Elementary - Park West Gallery - Beyond Basics
 
Guia de estudio de la materia de taller de lectura y redacción 2
Guia de estudio de la materia de taller de lectura y redacción 2Guia de estudio de la materia de taller de lectura y redacción 2
Guia de estudio de la materia de taller de lectura y redacción 2
 
Video Marketing Cycle
Video Marketing CycleVideo Marketing Cycle
Video Marketing Cycle
 

Similar to Entity Component System - for App developers

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
 
Blending Culture in Twitter Client
Blending Culture in Twitter ClientBlending Culture in Twitter Client
Blending Culture in Twitter ClientKenji Tanaka
 
Taming Core Data by Arek Holko, Macoscope
Taming Core Data by Arek Holko, MacoscopeTaming Core Data by Arek Holko, Macoscope
Taming Core Data by Arek Holko, MacoscopeMacoscope
 
Execution model and other must-know's
Execution model and other must-know'sExecution model and other must-know's
Execution model and other must-know'sPablo Enfedaque
 
Appium Automation with Kotlin
Appium Automation with KotlinAppium Automation with Kotlin
Appium Automation with KotlinRapidValue
 
Kostas Kloudas - Extending Flink's Streaming APIs
Kostas Kloudas - Extending Flink's Streaming APIsKostas Kloudas - Extending Flink's Streaming APIs
Kostas Kloudas - Extending Flink's Streaming APIsVerverica
 
12advanced Swing
12advanced Swing12advanced Swing
12advanced SwingAdil Jafri
 
Introduction to Akka - Atlanta Java Users Group
Introduction to Akka - Atlanta Java Users GroupIntroduction to Akka - Atlanta Java Users Group
Introduction to Akka - Atlanta Java Users GroupRoy Russo
 
Build Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerBuild Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerC4Media
 
The Singleton Pattern In Java
The Singleton Pattern In JavaThe Singleton Pattern In Java
The Singleton Pattern In JavaKohei Nozaki
 
Coherence SIG: Advanced usage of indexes in coherence
Coherence SIG: Advanced usage of indexes in coherenceCoherence SIG: Advanced usage of indexes in coherence
Coherence SIG: Advanced usage of indexes in coherencearagozin
 
Why Spring <3 Kotlin
Why Spring <3 KotlinWhy Spring <3 Kotlin
Why Spring <3 KotlinVMware Tanzu
 
History of asynchronous in .NET
History of asynchronous in .NETHistory of asynchronous in .NET
History of asynchronous in .NETMarcin Tyborowski
 
Javascript 攻佔桌面應用程式:使用 electron
Javascript 攻佔桌面應用程式:使用 electronJavascript 攻佔桌面應用程式:使用 electron
Javascript 攻佔桌面應用程式:使用 electronYao Nien Chung
 

Similar to Entity Component System - for App developers (20)

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
 
Blending Culture in Twitter Client
Blending Culture in Twitter ClientBlending Culture in Twitter Client
Blending Culture in Twitter Client
 
Taming Core Data by Arek Holko, Macoscope
Taming Core Data by Arek Holko, MacoscopeTaming Core Data by Arek Holko, Macoscope
Taming Core Data by Arek Holko, Macoscope
 
Execution model and other must-know's
Execution model and other must-know'sExecution model and other must-know's
Execution model and other must-know's
 
Appium Automation with Kotlin
Appium Automation with KotlinAppium Automation with Kotlin
Appium Automation with Kotlin
 
Kostas Kloudas - Extending Flink's Streaming APIs
Kostas Kloudas - Extending Flink's Streaming APIsKostas Kloudas - Extending Flink's Streaming APIs
Kostas Kloudas - Extending Flink's Streaming APIs
 
Pharos
PharosPharos
Pharos
 
The zen of async: Best practices for best performance
The zen of async: Best practices for best performanceThe zen of async: Best practices for best performance
The zen of async: Best practices for best performance
 
12advanced Swing
12advanced Swing12advanced Swing
12advanced Swing
 
IoT in salsa Serverless
IoT in salsa ServerlessIoT in salsa Serverless
IoT in salsa Serverless
 
#JavaFX.forReal() - ElsassJUG
#JavaFX.forReal() - ElsassJUG#JavaFX.forReal() - ElsassJUG
#JavaFX.forReal() - ElsassJUG
 
Introduction to Akka - Atlanta Java Users Group
Introduction to Akka - Atlanta Java Users GroupIntroduction to Akka - Atlanta Java Users Group
Introduction to Akka - Atlanta Java Users Group
 
Build Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerBuild Your Own WebAssembly Compiler
Build Your Own WebAssembly Compiler
 
The Singleton Pattern In Java
The Singleton Pattern In JavaThe Singleton Pattern In Java
The Singleton Pattern In Java
 
Coherence SIG: Advanced usage of indexes in coherence
Coherence SIG: Advanced usage of indexes in coherenceCoherence SIG: Advanced usage of indexes in coherence
Coherence SIG: Advanced usage of indexes in coherence
 
Reactive Extensions
Reactive ExtensionsReactive Extensions
Reactive Extensions
 
Why Spring <3 Kotlin
Why Spring <3 KotlinWhy Spring <3 Kotlin
Why Spring <3 Kotlin
 
History of asynchronous in .NET
History of asynchronous in .NETHistory of asynchronous in .NET
History of asynchronous in .NET
 
Javascript 攻佔桌面應用程式:使用 electron
Javascript 攻佔桌面應用程式:使用 electronJavascript 攻佔桌面應用程式:使用 electron
Javascript 攻佔桌面應用程式:使用 electron
 
AFPS_2011
AFPS_2011AFPS_2011
AFPS_2011
 

More from Maxim Zaks

Entity Component System - a different approach to game and app development
Entity Component System - a different approach to game and app developmentEntity Component System - a different approach to game and app development
Entity Component System - a different approach to game and app developmentMaxim Zaks
 
Nitty Gritty of Data Serialisation
Nitty Gritty of Data SerialisationNitty Gritty of Data Serialisation
Nitty Gritty of Data SerialisationMaxim Zaks
 
Wind of change
Wind of changeWind of change
Wind of changeMaxim Zaks
 
Data model mal anders
Data model mal andersData model mal anders
Data model mal andersMaxim Zaks
 
Talk Binary to Me
Talk Binary to MeTalk Binary to Me
Talk Binary to MeMaxim Zaks
 
Beyond JSON - An Introduction to FlatBuffers
Beyond JSON - An Introduction to FlatBuffersBeyond JSON - An Introduction to FlatBuffers
Beyond JSON - An Introduction to FlatBuffersMaxim Zaks
 
Beyond JSON @ Mobile.Warsaw
Beyond JSON @ Mobile.WarsawBeyond JSON @ Mobile.Warsaw
Beyond JSON @ Mobile.WarsawMaxim Zaks
 
Beyond JSON @ dot swift 2016
Beyond JSON @ dot swift 2016Beyond JSON @ dot swift 2016
Beyond JSON @ dot swift 2016Maxim Zaks
 
Beyond JSON with FlatBuffers
Beyond JSON with FlatBuffersBeyond JSON with FlatBuffers
Beyond JSON with FlatBuffersMaxim Zaks
 
Basics of Computer Science
Basics of Computer ScienceBasics of Computer Science
Basics of Computer ScienceMaxim Zaks
 
UIKonf App & Data Driven Design @swift.berlin
UIKonf App & Data Driven Design @swift.berlinUIKonf App & Data Driven Design @swift.berlin
UIKonf App & Data Driven Design @swift.berlinMaxim Zaks
 
Swift the implicit parts
Swift the implicit partsSwift the implicit parts
Swift the implicit partsMaxim Zaks
 
Currying in Swift
Currying in SwiftCurrying in Swift
Currying in SwiftMaxim Zaks
 
Promise of an API
Promise of an APIPromise of an API
Promise of an APIMaxim Zaks
 
96% macoun 2013
96% macoun 201396% macoun 2013
96% macoun 2013Maxim Zaks
 
Diagnose of Agile @ Wooga 04.2013
Diagnose of Agile @ Wooga 04.2013Diagnose of Agile @ Wooga 04.2013
Diagnose of Agile @ Wooga 04.2013Maxim Zaks
 
Start playing @ mobile.cologne 2013
Start playing @ mobile.cologne 2013Start playing @ mobile.cologne 2013
Start playing @ mobile.cologne 2013Maxim Zaks
 
Under Cocos2D Tree @mdvecon 2013
Under Cocos2D Tree @mdvecon 2013Under Cocos2D Tree @mdvecon 2013
Under Cocos2D Tree @mdvecon 2013Maxim Zaks
 
Don&rsquo;t do Agile, be Agile @NSConf 2013
Don&rsquo;t do Agile, be Agile @NSConf 2013Don&rsquo;t do Agile, be Agile @NSConf 2013
Don&rsquo;t do Agile, be Agile @NSConf 2013Maxim Zaks
 
Test Essentials @mdevcon 2012
Test Essentials @mdevcon 2012Test Essentials @mdevcon 2012
Test Essentials @mdevcon 2012Maxim Zaks
 

More from Maxim Zaks (20)

Entity Component System - a different approach to game and app development
Entity Component System - a different approach to game and app developmentEntity Component System - a different approach to game and app development
Entity Component System - a different approach to game and app development
 
Nitty Gritty of Data Serialisation
Nitty Gritty of Data SerialisationNitty Gritty of Data Serialisation
Nitty Gritty of Data Serialisation
 
Wind of change
Wind of changeWind of change
Wind of change
 
Data model mal anders
Data model mal andersData model mal anders
Data model mal anders
 
Talk Binary to Me
Talk Binary to MeTalk Binary to Me
Talk Binary to Me
 
Beyond JSON - An Introduction to FlatBuffers
Beyond JSON - An Introduction to FlatBuffersBeyond JSON - An Introduction to FlatBuffers
Beyond JSON - An Introduction to FlatBuffers
 
Beyond JSON @ Mobile.Warsaw
Beyond JSON @ Mobile.WarsawBeyond JSON @ Mobile.Warsaw
Beyond JSON @ Mobile.Warsaw
 
Beyond JSON @ dot swift 2016
Beyond JSON @ dot swift 2016Beyond JSON @ dot swift 2016
Beyond JSON @ dot swift 2016
 
Beyond JSON with FlatBuffers
Beyond JSON with FlatBuffersBeyond JSON with FlatBuffers
Beyond JSON with FlatBuffers
 
Basics of Computer Science
Basics of Computer ScienceBasics of Computer Science
Basics of Computer Science
 
UIKonf App & Data Driven Design @swift.berlin
UIKonf App & Data Driven Design @swift.berlinUIKonf App & Data Driven Design @swift.berlin
UIKonf App & Data Driven Design @swift.berlin
 
Swift the implicit parts
Swift the implicit partsSwift the implicit parts
Swift the implicit parts
 
Currying in Swift
Currying in SwiftCurrying in Swift
Currying in Swift
 
Promise of an API
Promise of an APIPromise of an API
Promise of an API
 
96% macoun 2013
96% macoun 201396% macoun 2013
96% macoun 2013
 
Diagnose of Agile @ Wooga 04.2013
Diagnose of Agile @ Wooga 04.2013Diagnose of Agile @ Wooga 04.2013
Diagnose of Agile @ Wooga 04.2013
 
Start playing @ mobile.cologne 2013
Start playing @ mobile.cologne 2013Start playing @ mobile.cologne 2013
Start playing @ mobile.cologne 2013
 
Under Cocos2D Tree @mdvecon 2013
Under Cocos2D Tree @mdvecon 2013Under Cocos2D Tree @mdvecon 2013
Under Cocos2D Tree @mdvecon 2013
 
Don&rsquo;t do Agile, be Agile @NSConf 2013
Don&rsquo;t do Agile, be Agile @NSConf 2013Don&rsquo;t do Agile, be Agile @NSConf 2013
Don&rsquo;t do Agile, be Agile @NSConf 2013
 
Test Essentials @mdevcon 2012
Test Essentials @mdevcon 2012Test Essentials @mdevcon 2012
Test Essentials @mdevcon 2012
 

Recently uploaded

SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxJisc
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibitjbellavia9
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptxMaritesTamaniVerdade
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxAmanpreet Kaur
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Jisc
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 

Recently uploaded (20)

SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 

Entity Component System - for App developers

  • 1. Entity Component System for App developers @iceX33
  • 2. History & Facts 4 First known game 1998 Thief: The Dark Project 4 My first encounter 2012 With ECS 4 Articles that convinced me "What is an entity system framework for game development?" by Richard Lord 4 ObjectiveC library I used: Entitas 4 Two Apps I built with Entitas UIKonf-App & Resi App
  • 4. Entity | Component | System ----> State <------> Behaviour
  • 5. What is a Component public protocol Component {} public protocol UniqueComopnent : Component {}
  • 6. Component is a value type struct TickComponent : UniqueComopnent{ let value : UInt64 } struct ElixirComponent : UniqueComopnent{ let value : Float } struct ConsumeElixirComponent : Component{ let value : Int } struct PauseComponent : UniqueComopnent{} struct JumpIntTimeComponent : UniqueComopnent{ let value : UInt64 }
  • 7. Entity is a collection of components public final class Entity { private var _components : [ComponentId:Component] ... } e.set(ConsumeElixirComponent(value:2)) let amount = e.get(ConsumeElixirComponent.self)?.value e.remove(ConsumeElixirComponent.self)
  • 8. Components = Lego pieces Entites = things you build with them
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14. let ctx = Context() let e = ctx.createEntity() e.set(NameComponent(value:"Maxim")) let g = ctx.getEntityGroup(NameComponent.matcher) assert(g.count == 1) e.set(NameComponent(value:"Leo"), overwrite:true) assert(g.count == 1) e.remove(NameComponent.self) assert(g.count == 0)
  • 16.
  • 17. What is a System public protocol ASystem : class {} public protocol InitialiseSystem : ASystem { func initialize() } public protocol ExecuteSystem : ASystem { func execute() } public protocol CleanupSystem : ASystem { func cleanup() }
  • 18. System Example class TickUpdateSystem : InitialiseSystem, ExecuteSystem { let ctx : Context init(ctx : Context) { self.ctx = ctx } func initialize() { ctx.setUniqueEntityWith(TickComponent(value: 0)) } func execute() { guard ctx.hasUniqueComponent(PauseComponent.self) == false, let currentTick = ctx.uniqueComponent(TickComponent.self)?.value else { return } ctx.setUniqueEntityWith(TickComponent(value: currentTick + 1)) } }
  • 20. Reactive System public protocol ReactiveSystem : ExecuteSystem { var collector : Collector! {get set} var limit : Int {get} func execute(input : ArraySlice<Entity>) } public extension ReactiveSystem { func execute(){ if let collector = collector { let entities = collector.pull(limit) if entities.count > 0 { execute(input: entities) } } } var limit : Int { return -1 } }
  • 21. Reactive System Example class ElixirProduceSystem : InitialiseSystem, ReactiveSystem { var collector: Collector! let ctx : Context private let productionFrequency = 3 private let elixirCapacity : Float = 10 private let productionStep : Float = 0.01 private(set) var limit: Int = 1 init(ctx : Context) { self.ctx = ctx collector = Collector(group: ctx.entityGroup(TickComponent.matcher), changeType: .added) } func initialize() { ctx.setUniqueEntityWith(ElixirComponent(value: 0)) } func execute(input: ArraySlice<Entity>) { guard let tick = input.first?.get(TickComponent.self)?.value, (tick % UInt64(productionFrequency)) == 0, let elixirAmount = ctx.uniqueComponent(ElixirComponent.self)?.value else{ return } let newAmount = min(elixirCapacity, elixirAmount + productionStep) ctx.setUniqueEntityWith(ElixirComponent(value: newAmount)) } }
  • 23.
  • 24. UI Action @IBAction func pauseResume(_ sender: UIButton) { if ctx.hasUniqueComponent(PauseComponent.self) { ctx.destroyUniqueEntity(PauseComponent.matcher) } else { ctx.setUniqueEntityWith(PauseComponent()) } } @IBAction func consumeAction(_ sender: UIButton) { ctx.createEntity().set(ConsumeElixirComponent(value: sender.tag)) } @IBAction func timeTravel(_ sender: UISlider) { ctx.setUniqueEntityWith(JumpIntTimeComponent(value: UInt64(sender.value))) }
  • 26.
  • 27. protocol TickListener { func tickChanged(tick : UInt64) } struct TickListenerComponent : Component { let ref : TickListener } protocol PauseListener { func pauseStateChanged(paused : Bool) } struct PauseListenerComponent : Component { let ref : PauseListener } protocol ElixirListener { func elixirChanged(amount : Float) } struct ElixirListenerComponent : Component { let ref : ElixirListener }
  • 28. ViewController is a listener class ViewController: UIViewController, TickListener, ElixirListener, PauseListener { ... override func viewDidLoad() { ctx.createEntity() .set(TickListenerComponent(ref: self)) .set(ElixirListenerComponent(ref: self)) .set(PauseListenerComponent(ref: self)) } ... }
  • 29. Or if you like it less monolithic struct ConsumeButtonController : PauseListener, ElixirListener { let consumeButton : UIButton let consumeButtonProgress: UIProgressView let ctx : Context func pauseStateChanged(paused: Bool) { consumeButton.isEnabled = !paused } func elixirChanged(amount: Float) { let paused = ctx.hasUniqueComponent(PauseComponent.self) consumeButton.isEnabled = consumeButton.tag <= Int(amount) && !paused consumeButtonProgress.progress = 1 - min(1, (amount / Float(consumeButton.tag))) } }
  • 30. Reactive System + UIKit class NotifyPauseListenersSystem : ReactiveSystem { var collector: Collector! let ctx : Context var limit: Int = 1 let listeners : Group init(ctx : Context) { self.ctx = ctx collector = Collector(group: ctx.entityGroup(PauseComponent.matcher), changeType: .addedAndRemoved) listeners = ctx.entityGroup(PauseListenerComponent.matcher) } func execute(input: ArraySlice<Entity>) { let paused = ctx.hasUniqueComponent(PauseComponent.self) for e in listeners { e.get(PauseListenerComponent.self)? .ref.pauseStateChanged(paused: paused) } } }
  • 31. Show me the code & tests
  • 32. ECS vs. MVC | MVVM | Rx | ReSwift