adam4813/Sigma — pull request #156 by catageek (2014-01-26 22:40:23+00:00)
Title: Replace VectorMap by MapArray container for components.

VectorMap suffers from recurrent pointers invalidation due to the dynamic behaviour of vectors. Moreover, iterators give elements in the order of insertion and not the natural order of entity IDs.

These issues lead to the necessity of a constant synchronization of pointers in entity instances, and the bad usage of CPU cache when iterating in natural order, such as when using a BitArray iterator.

This PR propose a new data structure that doesn't have these issues. Pointers are constant during the life of the application and iterators are in natural order.

The data structure is now an ordered map of arrays. Each array is a chunk of 16 components for consecutive entity IDs. The complexity is O(log(n/16)). Since pointers are now constant, the result can be cached by the caller. The address of each chunk can also be cached to avoid to access the map, thus accessing the data of the chunk by index. This data structure consumes more memory since an empty component is created in the empty slots of the chunk. A proper id management is needed to try to use all slots.

This PR shows the effect of this data structure on the orientation component initialized in BulletMover. There is no more need for a "Orientation" object wrapping a pointer to be passed to the entity. Instead the raw pointer is stored since it is always valid.

This simplification allows a big simplification of EntitySystem, since we don't need to centralize the storage of data, but only a bit of information to tell whether an entity has a component or not before trying to access the data (which may be undefined even if the pointer is valid).

The biggest simplification is that we get rid of the need to synchronize the pointers, which is a pain.