sdslabs / Rootex

An advanced C++ 3D game engine powering an in-production game yet to be announced

Home Page:https://rootex.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Optimize `m_Instances` for ComponentSets

sin3point14 opened this issue · comments

commented

based on this:

I have  Vector<Component> where object is a a custom class I wrote. there are lots of Entity classes that contain an Component * member which point into this Vector. Everything was fine until i deleted an element from the Vector. Now all Entitys point to incorrect Component. I don't care about the order of elements in the Vector but what them to be contiguous in memory to ensure cache coherence.

One way to fix this is to update all the Component pointers but this can cause performance loss.

Another is to add an isValid member to Component and instead of deleting anything from the Vector I set isValid to false when I need to delete a Component. While adding a new Component i'll first search for any member that has isValid as false. if i find one i'll create a new object in place else i'll append to the Vector. In both cases I can return the pointer to owner Entity. 
But this would involve writing a lot of dirty if ... else blocks all over the place and writing custom iterators and what not.

So I was wondering if there is any such data structure available in STL or some other library i can use?

Dependency pointers of other components are still getting swapped. That needs to be solved too

Fixed by #589