“The computing scientist’s 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 2
Hello! » 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 3
ECS? @parisba | @The_McJones | @TheMartianLife 6
If you Google ECS, you'll probably get Unity, or Amazon. Or something entirely unrelated. Sorry. @parisba | @The_McJones | @TheMartianLife 7
This is not a games talk! Mostly. @parisba | @The_McJones | @TheMartianLife 8
Before we start.. Is anyone using ECS, or working in games? @parisba | @The_McJones | @TheMartianLife 9
Overview » What is ECS? » History Lesson » ECS Implementations » What ECS is good for » What ECS is not good for » Summary @parisba | @The_McJones | @TheMartianLife 10
What is ECS? @parisba | @The_McJones | @TheMartianLife 11
Entity Component Systems @parisba | @The_McJones | @TheMartianLife 12
There's the short answer, and the long answer... @parisba | @The_McJones | @TheMartianLife 13
ECS?! @parisba | @The_McJones | @TheMartianLife 14
Strict separation between data and logic @parisba | @The_McJones | @TheMartianLife 15
Oh, ECS... @parisba | @The_McJones | @TheMartianLife 16
The Impetus Games really only have two needs: » performance » flexibility @parisba | @The_McJones | @TheMartianLife 17
Performance (you've only got ~16.6 milliseconds) @parisba | @The_McJones | @TheMartianLife 18
Flexibility (with jillions of objects and factors) @parisba | @The_McJones | @TheMartianLife 19
ECS encourages both Performance + Flexibility @parisba | @The_McJones | @TheMartianLife 20
The key word being 'encourages' You can, of course, mess it up. @parisba | @The_McJones | @TheMartianLife 21
So what? Everything is fine already! @parisba | @The_McJones | @TheMartianLife 22
It's a bit messy. @parisba | @The_McJones | @TheMartianLife 26
God Objects @parisba | @The_McJones | @TheMartianLife 27
History Lesson! @parisba | @The_McJones | @TheMartianLife 29
Early 'ECS' @parisba | @The_McJones | @TheMartianLife 30
Adam Martin's ECS » Entities have IDs » Components have data » Systems have logic @parisba | @The_McJones | @TheMartianLife 32
Let's look at these one by one... @parisba | @The_McJones | @TheMartianLife 33
Entity » an object in your game, uh, software » anything, really, a player, an enemy, anything » an identifier, no logic @parisba | @The_McJones | @TheMartianLife 34
Entity Two excellent descriptions of an entity (in games): » everything but the terrain » assemblages @parisba | @The_McJones | @TheMartianLife 35
Entities are boring. Just a thing to reference. @parisba | @The_McJones | @TheMartianLife 36
Isn't this just a primary key? @parisba | @The_McJones | @TheMartianLife 37
Yes, yes it is. @parisba | @The_McJones | @TheMartianLife 38
Components » it has some data @parisba | @The_McJones | @TheMartianLife 39
Components Also pretty boring. A flag that may also hold raw data for one aspect of a thing. @parisba | @The_McJones | @TheMartianLife 40
System @parisba | @The_McJones | @TheMartianLife 41
Systems 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 42
ECS or EC? @parisba | @The_McJones | @TheMartianLife 43
ECS in use today @parisba | @The_McJones | @TheMartianLife 44
It's very popular. In games. @parisba | @The_McJones | @TheMartianLife 45
To do this... @parisba | @The_McJones | @TheMartianLife 46
We're gonna talk about games. Sorry. @parisba | @The_McJones | @TheMartianLife 47
Games are very dynamic @parisba | @The_McJones | @TheMartianLife 48
Game worlds are built out of entities @parisba | @The_McJones | @TheMartianLife 49
A tree is different from a human who is different from an alien who is different from... @parisba | @The_McJones | @TheMartianLife 50
Games are in constant development flux @parisba | @The_McJones | @TheMartianLife 51
@parisba | @The_McJones | @TheMartianLife 52
@parisba | @The_McJones | @TheMartianLife 53
games are made up of moving parts @parisba | @The_McJones | @TheMartianLife 54
But... @parisba | @The_McJones | @TheMartianLife 55
There is common pool of aspects » Position data » Visuals data » Animation data » Sound data » Gameplay data @parisba | @The_McJones | @TheMartianLife 56
What 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 57
What 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 58
Separating data from behaviour @parisba | @The_McJones | @TheMartianLife 59
Objects? @parisba | @The_McJones | @TheMartianLife 60
Objects and (rigid, mostly) class hierarchies @parisba | @The_McJones | @TheMartianLife 61
Complex hierarchies @parisba | @The_McJones | @TheMartianLife 62
Composition, not Inheritance @parisba | @The_McJones | @TheMartianLife 64
Composing entities @parisba | @The_McJones | @TheMartianLife 65
Composing entities Benefits: 1. Easy to add new entities. 2. Easy to change entities. 3. Performant! @parisba | @The_McJones | @TheMartianLife 66
ECS and Games, now @parisba | @The_McJones | @TheMartianLife 68
Entity @parisba | @The_McJones | @TheMartianLife 69
Entity Examples: - Crate - Ball - Enemy - Player - Traffic light @parisba | @The_McJones | @TheMartianLife 70
Component @parisba | @The_McJones | @TheMartianLife 71
Component Examples » position (an x and a y) » velocity » sprite(s) » health value » character name » player (tag) @parisba | @The_McJones | @TheMartianLife 72
System @parisba | @The_McJones | @TheMartianLife 73
System Examples » player control » render » gravity » movement » AI control @parisba | @The_McJones | @TheMartianLife 74
Games, Games, Games @parisba | @The_McJones | @TheMartianLife 75
ECS doesn't necessarily mean less code. Theoretically it means better code, though. @parisba | @The_McJones | @TheMartianLife 76
What ECS is good for @parisba | @The_McJones | @TheMartianLife 77
Performance? @parisba | @The_McJones | @TheMartianLife 78
“The purpose of all programs, and all parts of those programs, is to transform data from one form to another.” Mike Acton
Data Oriented Design @parisba | @The_McJones | @TheMartianLife 80
Data-oriented Design is tricky @parisba | @The_McJones | @TheMartianLife 81
You never do just one thing @parisba | @The_McJones | @TheMartianLife 82
Cache Misses @parisba | @The_McJones | @TheMartianLife 86
Cache misses suck @parisba | @The_McJones | @TheMartianLife 87
Data-oriented Design = Programming for Good Memory Access @parisba | @The_McJones | @TheMartianLife 89
ECS encourages Data- oriented Design @parisba | @The_McJones | @TheMartianLife 90
Caches, memory speed, oh my! @parisba | @The_McJones | @TheMartianLife 91
Parallelisation @parisba | @The_McJones | @TheMartianLife 92
Lots of tasks. Large set of data. @parisba | @The_McJones | @TheMartianLife 93
Structure around consuming data as a stream. @parisba | @The_McJones | @TheMartianLife 94
Complex, interlocking systems. @parisba | @The_McJones | @TheMartianLife 95
Composability The biggest advantage @parisba | @The_McJones | @TheMartianLife 96
ECS 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 97
GUI Programming @parisba | @The_McJones | @TheMartianLife 98
A NEAT SIDE-EFFECT OF ECS! @parisba | @The_McJones | @TheMartianLife 99
In practice, it's not that easy... @parisba | @The_McJones | @TheMartianLife 100
Recommend
More recommend