Nomad Game Engine: Part 2 — ECS

Niko Savas
May 31, 2016 · 8 min read

Entity Component System

Entities and Components

Three entities
Our 7 components
Entities and their components
Changing how the game works is as easy as adding or removing a component!

ECS with a data-driven approach

struct Entity {
unsigned int id;
struct HealthComponent {
int currentHealth;
int maxHealth;
Data oriented components

Component Managers

Component Managers hold all the components (the number below each component is the entity associated with it)
Memory layout for our two possibilities
The bomb reduces maximum health by 20%
foreach(entity hit by bomb):
HealthComponent hp = entity.getHealth();
hp.maxHealth = hp.maxHealth * 0.8;
Memory accesses for updating a single component


Movement System

struct Transform {
int x;
int y;
struct Motion {
Vec2 velocity;
Vec2 acceleration;
void update(int dt){
for(entity in m_entities){
TransformComponent position = entity.getTransform();
MotionComponent motion = entity.getMotion();
position.x += motion.velocity.x;
position.y += motion.velocity.y;
motion.velocity.x += motion.acceleration.x;
motion.velocity.y += motion.acceleration.y;
Movement System memory accesses

Back to our example

The systems we would need to create our game.

Current Progress

Current progress of Nomad.

Niko Savas

Written by —

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade