🎮 Comprendre l’ECS : la brique invisible derrière les jeux modernes
on October 13, 2025
- entities (players, enemies, objects, tiles), * behaviors (movement, attack, effect), * and systems (rendering, AI, collisions, status effects, etc.).
Classic object-oriented approaches quickly end up creating overly deep hierarchies: Player extends Character extends Entity extends Drawable extends Object
… Result: a gas factory.
This is where the ECS — Entity Component System comes in.
⚙️ The basic idea
The ECS starts from a simple principle:
separate data, behavior, and execution.
| Element | Role | Example | | ------------- | ------------------------------------------- | --------------------------------------------------------- | | Entity | Unique Identifier | #23 = Warrior on square (3,2)
| | Component | Raw data (no logic) | Position(3,2)
, Life(10)
, Attack(3)
| | System | Behavior (acts on some components) | MovementSystem
, CombatSystem
, RenderingSystem
|
ECS doesn't replace object-oriented programming—it deconstructs it to make it scalable. Instead of writing what each class does, you define how data interacts.
đź§© Concrete example
Let's take a simplified example in GDScript (Godot):
# Component Position class_name CPosition extends Resource @export var q:int @export var r:int
# Life Component class_name CVie extends Resource @export var hp:int = 10
# Rendering system extends Node const CPosition = preload("res://components/CPosition.gd")
func process_system(dt): for entity in get_entities_with([CPosition]): var pos = entity.get_component(CPosition) draw_unit(pos.q, pos.r)
Here :
- the entity doesn't "do" anything — it contains components; * systems trigger on entities that have a certain set of components.
It's a data-driven approach: everything is driven by data.
đź§® Why it's powerful
ECS isn't just a trendy design pattern. It's a structuring approach that solves three major problems:
1. Scalability
You can add new behaviors without breaking old ones:
Adding a
CInvisible
component is enough for a “Rendering” system to ignore your entity.
2. Replay and Simulation
You can replay a game by applying the same sequence of events, because all game state is pure data, serializable, diffable, and testable.
3. Performance
Modern ECS (like Flecs, EnTT or Unity DOTS) store data in contiguous memory. The CPU loves this:
fewer calls, less cache-miss, more speed.
đź§± In Darkwaar 5
Darkwaar 5 is based on a lightweight ECS in GDScript, without an external engine. The goal is to have:
- a central world (
World
), * simple entities (one Node per character or object), * components (Resource
) for data, * systems (Node
) for logic.
Simplified example:
# GameRoot.gd @onready var world := $World
func _ready(): var unit = world.create_entity() unit.add_component(CPosition.new()) unit.add_component(CVie.new())
Each frame:
- the
World
passes over the active systems; * the systems traverse the entities that concern them; * and the logic executes on the raw data.
This separation makes it easy to add:
- a buff system (temporary effects), * a combat resolution system, * or a puzzle system for levels.
🧩 ECS ≠magic
ECS doesn't do "better" than an object-oriented approach: it makes it easier to maintain.
But there is a cost: you have to think in data streams, not object hierarchies.
- No “Player.move()”, but a
SystemMouvement
which reads theCPosition
andCVitesse
. * No “Enemy.attack()”, but aSystemCombat
which reads theCCombat
andCVie
.
It's a paradigm shift—but once understood, everything becomes clearer.
đź§ What Darkwood remembers from it
At Darkwood, ECS isn't just a game architecture. It's a way of thinking about modularity:
- In Darkwaar, it structures the gameplay and puzzles. * In Uniflow, it inspires the logic of data flows. * In Flow, it serves as the basis for the visual composition of automations.
Same fight: separate data, behaviors and execution logic.
đź”® And after?
The next step for Darkwaar 5:
- integrate the ECS into the isometric map system; * link each box to an entity; * and synchronize the components between the view (top) and the HUD (bottom).
This will lay the foundation for an open-source isometric tactical engine, designed for procedural generation, puzzles, and emergent systems.