I have been trying to get my head around using an entity component system for a game. But I am struggling to understand how I should do 'game-logic'.
What I have so far:
- Components are essentially just dumb data holders, no logic beyond getters and setters.
- Systems do processing on groups of components. E.g a PhysicsSystem might process all entities containing Transform and Velocity components.
- Entities are just integers.
My question is, how do I add 'entity-specific' or 'game' logic? For example, I will have an entity which represents the player. How do I go about moving the player entity?
Couples ideas I had, not sure if any are good?
- Create a 'MovementSystem' which uses a component (e.g PlayerMovementComponent). Then give just my player entity the PlayerMovementComponent. This is basically just a system which only ever processed the one entity... seems a big fudgey.
- Create a Script or Behaviour component which holds a
std::function(or maybe could reference a lua script), could then have lambdas which allow unique game logic to be given to entities. This seems to go against the data-orientated approach I’m trying to follow?
- Create a Player class, have it reference the entity Id then give the player class an update method hooking into the game loop. This update method can edit its referenced entities components before the systems process. This is basically disconnecting myself entirely from the ECS for game-logic... not a fan of this idea (also will make my game loop bloat as more unique entities are required).
Hopefully, I can get some comments on the 3 ideas above and some new ideas or thoughts I can pursue.