|
|
|
|
|
by lionkor
1095 days ago
|
|
Am I crazy or is your approach to ECS similar to a data oriented ECS? In a fully, brutally data-oriented ECS, you would allocate all components of the same type in the same memory block, so you'd effectively end up with a std::vector<TransformComponent> and a std::vector<PhysicsComponent>, etc.
Each entity then holds ids, such as a pair of `what` component and `index` into the respective vector.
This ensures that, like your approach, the cache is used well, and that memory fragmentation is minimal. I find your project(s) very, very inspiring as I love working on similar problems among others (github.com/lionkor), thank you for sharing! |
|
struct player { components::transform transform; components::health health; };
struct box { components::transform transform; components::physics physics; };
Then my ECS simply holds a std::vector<player> and a std::vector<box> rather than having a vector per each type of component. I also use the integer identifiers like you describe but with a twist - there is one more indirection involved so that deleting from the vectors does not invalidate existing indices pointing to vector elements. It's still exactly O(1). See the section on the Memory pool in the game repo's README.