Processing component pools problem - Entity Subsystem
- by mani3xis
Architecture description
I'm creating (designing) an entity system and I ran into many problems. I'm trying to keep it Data-Oriented and efficient as much as possible. My components are POD structures (array of bytes to be precise) allocated in homogeneous pools. Each pool has a ComponentDescriptor - it just contains component name, field types and field names.
Entity is just a pointer to array of components (where address acts like an entity ID). EntityPrototype contains entity name and array of component names. Finally Subsystem (System or Processor) which works on component pools.
Actual problem
The problem is that some components dependents on others (Model, Sprite, PhysicalBody, Animation depends on Transform component) which makes a lot of problems when it comes to processing them.
For example, lets define some entities using [S]prite, [P]hysicalBody and [H]ealth:
Tank: Transform, Sprite, PhysicalBody
BgTree: Transform, Sprite
House: Transform, Sprite, Health
and create 4 Tanks, 5 BgTrees and 2 Houses and my pools will look like:
TTTTTTTTTTT // Transform pool
SSSSSSSSSSS // Sprite pool
PPPP // PhysicalBody pool
HH // Health component
There is no way to process them using indices. I spend 3 days working on it and I still don't have any ideas. In previous designs TransformComponent was bound to the entity - but it wasn't a good idea. Can you give me some advices how to process them? Or maybe I should change the overall design? Maybe I should create pools of entites (pools of component pools) - but I guess it will be a nightmare for CPU caches.
Thanks