benreid24 / BLIB

Small organized collection of common code I have accumulated over the years that has amassed into a proper 2d game engine
1 stars 0 forks source link

Implement entity relationships in ECS #173

Closed benreid24 closed 11 months ago

benreid24 commented 1 year ago

Entity id should become 64 bits. Use the top 32 for metadata (version id, etc), and the bottom 32 as the index.

Parenting

Implement parenting at the ECS level. Parent-child relationships should be quickly query-able and usable by components/systems. Deleting a parent should also delete all children.

Entity -> parent: Map in vector using entity as index

Parent -> children: Entity-indexed vector stores starting index into vector of child ids. Child vector nodes store child id and next index (essentially a linked list). Minimizes allocations while maintaining O(1) add and remove.

Provide templated base class for components:

template<typename T>
struct ParentAware {
    void parentSet(T* parent);
    void parentRemoved();
};

Dependencies

Add information allowing entities to depend on other entities. Block deletion (unless forced) of entities with dependencies. Allows for reference counted relationships in the ECS natively. Example: Slideshow -> AnimationPlayer. Use similar data approach as parenting.