“The computing scientist’s main challenge is not to get confused by the complexities of their
- wn making. ”
- E. W. Dijkstra
The computing scientists main challenge is not to get confused by - - PowerPoint PPT Presentation
The computing scientists main challenge is not to get confused by the complexities of their own making. E. W. Dijkstra Entity-Component Systems + You ( They're not just for games anymore ) @parisba | @The_McJones | @TheMartianLife
“The computing scientist’s main challenge is not to get confused by the complexities of their
Entity-Component
Systems + You
(They're not just for games anymore)
@parisba | @The_McJones | @TheMartianLife 2Hello!
» Paris (@parisba) » Game developer, PhD Computing, Author » Tim (@The_McJones) » Game developer, PhD Computing, Author » Mars (@TheMartianLife) » Software developer, Research & Teaching Assistant, Upcoming Author @parisba | @The_McJones | @TheMartianLife 3ECS?
@parisba | @The_McJones | @TheMartianLife 6If you Google ECS, you'll probably get Unity, or Amazon.
Or something entirely unrelated.
Sorry. @parisba | @The_McJones | @TheMartianLife 7This is not a games talk!
Mostly. @parisba | @The_McJones | @TheMartianLife 8Before we start..
Is anyone using ECS, or working in games? @parisba | @The_McJones | @TheMartianLife 9Overview
» What is ECS? » History Lesson » ECS Implementations » What ECS is good for » What ECS is not good for » Summary @parisba | @The_McJones | @TheMartianLife 10What is ECS?
@parisba | @The_McJones | @TheMartianLife 11Entity Component Systems
@parisba | @The_McJones | @TheMartianLife 12ECS?!
@parisba | @The_McJones | @TheMartianLife 14Strict separation between data and logic
@parisba | @The_McJones | @TheMartianLife 15Oh, ECS...
@parisba | @The_McJones | @TheMartianLife 16The Impetus
Games really only have two needs: » performance » flexibility @parisba | @The_McJones | @TheMartianLife 17Performance
(you've only got ~16.6 milliseconds)
@parisba | @The_McJones | @TheMartianLife 18Flexibility
(with jillions of objects and factors)
@parisba | @The_McJones | @TheMartianLife 19ECS encourages both
Performance + Flexibility
@parisba | @The_McJones | @TheMartianLife 20The key word being 'encourages'
You can, of course, mess it up. @parisba | @The_McJones | @TheMartianLife 21So what?
Everything is fine already! @parisba | @The_McJones | @TheMartianLife 22It's a bit messy.
@parisba | @The_McJones | @TheMartianLife 26God Objects
@parisba | @The_McJones | @TheMartianLife 27History Lesson!
@parisba | @The_McJones | @TheMartianLife 29Early 'ECS'
@parisba | @The_McJones | @TheMartianLife 30Adam Martin's ECS
» Entities have IDs » Components have data » Systems have logic @parisba | @The_McJones | @TheMartianLife 32Let's look at these
Entity
» an object in your game, uh, software » anything, really, a player, an enemy, anything » an identifier, no logic @parisba | @The_McJones | @TheMartianLife 34Entity
Two excellent descriptions of an entity (in games): » everything but the terrain » assemblages @parisba | @The_McJones | @TheMartianLife 35Entities are boring.
Just a thing to reference. @parisba | @The_McJones | @TheMartianLife 36Isn't this just a primary key?
@parisba | @The_McJones | @TheMartianLife 37Yes, yes it is.
@parisba | @The_McJones | @TheMartianLife 38Components
» it has some data @parisba | @The_McJones | @TheMartianLife 39Components
Also pretty boring.
A flag that may also hold raw data for one aspect of a thing. @parisba | @The_McJones | @TheMartianLife 40System
@parisba | @The_McJones | @TheMartianLife 41Systems are the interesting bit.
Logic that runs continuously and performs actions on every Entity that has a Component of the aspect the System is designed to work with. @parisba | @The_McJones | @TheMartianLife 42ECS or EC?
@parisba | @The_McJones | @TheMartianLife 43ECS in use today
@parisba | @The_McJones | @TheMartianLife 44It's very popular.
In games.
@parisba | @The_McJones | @TheMartianLife 45To do this...
@parisba | @The_McJones | @TheMartianLife 46We're gonna talk about games. Sorry.
@parisba | @The_McJones | @TheMartianLife 47Games are very dynamic
@parisba | @The_McJones | @TheMartianLife 48Game worlds are built out of entities
@parisba | @The_McJones | @TheMartianLife 49A tree is different from a human who is different from an alien who is different from...
@parisba | @The_McJones | @TheMartianLife 50Games are in constant development flux
@parisba | @The_McJones | @TheMartianLife 51games are made up of moving parts
@parisba | @The_McJones | @TheMartianLife 54But...
@parisba | @The_McJones | @TheMartianLife 55There is common pool of aspects
» Position data » Visuals data » Animation data » Sound data » Gameplay data @parisba | @The_McJones | @TheMartianLife 56What a game seems like
1.Player presses walk forward 2.Move the player forward 3.Check if enemy can see the player avatar 4.Move towards the player 5.If in range swing sword 6.Deal damage to the player @parisba | @The_McJones | @TheMartianLife 57What a game is actually doing
1.Receive user input 2.Raycast from enemy to player avatar 3.Update avatar and enemy position 4.Deal damage 5.Update animations 6.Render frame @parisba | @The_McJones | @TheMartianLife 58Separating data from behaviour
@parisba | @The_McJones | @TheMartianLife 59Objects?
@parisba | @The_McJones | @TheMartianLife 60Objects and (rigid, mostly) class hierarchies
@parisba | @The_McJones | @TheMartianLife 61Complex hierarchies
@parisba | @The_McJones | @TheMartianLife 62Composition, not Inheritance
@parisba | @The_McJones | @TheMartianLife 64Composing entities
@parisba | @The_McJones | @TheMartianLife 65Composing entities
Benefits:ECS and Games, now
@parisba | @The_McJones | @TheMartianLife 68Entity
@parisba | @The_McJones | @TheMartianLife 69Entity
Examples:Component
@parisba | @The_McJones | @TheMartianLife 71Component Examples
» position (an x and a y) » velocity » sprite(s) » health value » character name » player (tag) @parisba | @The_McJones | @TheMartianLife 72System
@parisba | @The_McJones | @TheMartianLife 73System Examples
» player control » render » gravity » movement » AI control @parisba | @The_McJones | @TheMartianLife 74Games, Games, Games
@parisba | @The_McJones | @TheMartianLife 75ECS doesn't necessarily mean less code.
Theoretically it means better code, though. @parisba | @The_McJones | @TheMartianLife 76What ECS is good for
@parisba | @The_McJones | @TheMartianLife 77Performance?
@parisba | @The_McJones | @TheMartianLife 78“The purpose of all programs, and all parts of those programs, is to transform data from
Data Oriented Design
@parisba | @The_McJones | @TheMartianLife 80Data-oriented Design is tricky
@parisba | @The_McJones | @TheMartianLife 81You never do just
Cache Misses
@parisba | @The_McJones | @TheMartianLife 86Cache misses
Data-oriented Design = Programming for Good Memory Access
@parisba | @The_McJones | @TheMartianLife 89ECS encourages Data-
Caches, memory speed, oh my!
@parisba | @The_McJones | @TheMartianLife 91Parallelisation
@parisba | @The_McJones | @TheMartianLife 92Lots of tasks. Large set of data.
@parisba | @The_McJones | @TheMartianLife 93Structure around consuming data as a stream.
@parisba | @The_McJones | @TheMartianLife 94Complex, interlocking systems.
@parisba | @The_McJones | @TheMartianLife 95Composability
The biggest advantage
@parisba | @The_McJones | @TheMartianLife 96ECS is great for...
» GUI Programming » Editors » Audio systems » VFX systems » Simulations » A service registry » ... almost anything that's event-driven » ... anything you want to easily unit test @parisba | @The_McJones | @TheMartianLife 97GUI Programming
@parisba | @The_McJones | @TheMartianLife 98A NEAT SIDE-EFFECT OF ECS!
@parisba | @The_McJones | @TheMartianLife 99In practice, it's not that easy...
@parisba | @The_McJones | @TheMartianLife 100What ECS is not good for
» Disk heavy operations » Unchanging data and procedures » Heavily hierarchical data @parisba | @The_McJones | @TheMartianLife 101How would you go about
making an ECS?
@parisba | @The_McJones | @TheMartianLife 102Quick and Dirty way
@parisba | @The_McJones | @TheMartianLife 103Start with our entities
@parisba | @The_McJones | @TheMartianLife 104now we need some components
@parisba | @The_McJones | @TheMartianLife 106how do we connect entities and components?
@parisba | @The_McJones | @TheMartianLife 108What about the systems?
@parisba | @The_McJones | @TheMartianLife 111It gets better, of course
This approach isn't the best for large scale, but its the simplest way to get started. @parisba | @The_McJones | @TheMartianLife 116implementations
@parisba | @The_McJones | @TheMartianLife 117ECS implementations
» Rust (Specs): https://github.com/slide-rs/specs » C++ (EnTT): https://github.com/skypjack/entt » Elixir: https://github.com/yosriady/ecs » C# (Entitas): https://github.com/sschmid/Entitas-CSharp » Java (Artemis): http://gamadu.com/artemis/ » C# (EgoCS): https://github.com/andoowhy/EgoCS » C++ (EntityX): https://github.com/alecthomas/entityx » C++ (Anax): https://github.com/miguelmartin75/anax » ...and many, many more! @parisba | @The_McJones | @TheMartianLife 118None of this is new.
@parisba | @The_McJones | @TheMartianLife 119Entities Components Systems
@parisba | @The_McJones | @TheMartianLife 121ECS = Composable
@parisba | @The_McJones | @TheMartianLife 122ECS is composition
Data-oriented Design
@parisba | @The_McJones | @TheMartianLife 124Strengths
» Performance (hopefully) » Flexibility » No heirarchy to remember » Systems have many of the advantages of microservices/functional programming @parisba | @The_McJones | @TheMartianLife 125Weaknesses
» More code upfront » Harder to keep everything in your head » No clear starting point @parisba | @The_McJones | @TheMartianLife 126Pick and choose the ideas you like
There is no one 'right way'. @parisba | @The_McJones | @TheMartianLife 127Resources
» Slides will go up on the SACon website shortly » Talk resources can be found at https://lab.to/SAConNYC19Resources @parisba | @The_McJones | @TheMartianLife 128Review us!
@parisba | @The_McJones | @TheMartianLife 129Thank you!
» Find us online: » @parisba » @The_McJones » @TheMartianLife » Chat with us at 'Meet the Experts'! 3:05PM today! Sponsor Pavilion! Come and tell us we're wrong! » Stay warm + enjoy the rest of your #OReillySACon <3 @parisba | @The_McJones | @TheMartianLife 130