Skip to main content
2 of 3
Improved title
Zymus
  • 131
  • 8

How should I poll for component state changes when designing an ECS?

I'm implementing an ECS and have run into a predicament.

Let's say my main loop is something like

while (true) { // timing logic in here somewhere for (GameSystem system : systems) { for (GameEntity entity : entities) { system.update(entity); } } } 

Components need to have their state updated, but how exactly that state gets updated is kind of blurry.

Should there be something before the systems are iterated to update the current state of the components, or within the systems, call code like

void update(GameEntity entity) { Optional<Position> position = entity.getComponent(Position.class); if (position.isPresent()) { position.getLatestState(); } // do something } 

which polls some sort of event queue, but then each component must know how to get it's latest status, and know where to get those updates from. My feeling is that this should be a proactive state update, not a reactive state update.

So then how should we update the state of the components?

Zymus
  • 131
  • 8