I am looking for a way of doing an efficient caching system for an ES.
all update are made in memory (but only requiered/active parts of the DB are loaded) and periodically the cache is saved to the DB, the problem I found is that how to efficiently cache components of my entities without explode memory and keep an extremly fast acces to component based on their entity ID ?
for now I got something like the following :
use native array for memory storing
=> String componentLabel[];
=> Point3D componentLocation[];
and use an hastable to get entity index in natives arrays :
=> Hashtable<Integer,Integer> entityIDtoNativeArrayIndex;
I only use one hastable that give me the index of the entity for each possible components, I was wondering if anybody have a better idea ? one problem I could face later will be that :
- memory used for an entity with only one component will be always equals to the size of all componenets.
- a new componenent will make a big memory grow (for all active entity it will exist an entry).
any (simple…) idea to compact this structure (wich is basically a 2D array with size equals to activeEntity*nbComponent) in an efficient manner ?
EDIT:
what I need is to be able to get a list of all entity having a component of type “XXX” while still being able to faslty access some other component of those entities.
something that may look like :
havingPhysics[]=getListOfHavingPhysics();
for(int n=0;n<havingPhysics.length;n++)
{
applyPhysics(havingPhysics[n]);
}
havingAppearance[]=getListOfHavingAppearance();
for(int n=0;n<havingAppearance.length;n++)
{
applyAppearance(havingAppearance[n]);
}
where havingAppearance & havingPhysics may overlap