Rootex icon indicating copy to clipboard operation
Rootex copied to clipboard

Optimize `m_Instances` for ComponentSets

Open sin3point14 opened this issue 4 years ago • 1 comments

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?

sin3point14 avatar Jan 31 '22 22:01 sin3point14

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

r41k0u avatar Feb 03 '22 22:02 r41k0u

Fixed by #589

Bashar-Ahmed avatar Oct 02 '22 11:10 Bashar-Ahmed