My game represents its map as a 2D array of tiles, each of which stores a stack of layers. I'm looking for a data structure to efficiently represent this .
I want to be able to add layers dynamically, so fixed arrays won't do.
Additionally, the layers are applied in zones, to make sure that terrain is always drawn before items and monsters, and that items/monsters are drawn before the player. This is the order:
terrainlayer terraineffectlayers itemlayers monsterlayers playerlayers specialeffectslayers
I want to store all those zones in the same data structure, so I can traverse it from end to end in either direction. I also need to be able to add a monster layer that would automatically go at the end of
monsterlayers data structure while still having a global object that would let me traverse from the all the layers. I also need the ability to access the data structure with index, so I can get the 3rd monster in the tile easily or remove the 3rd monster. Add will always be sequential, but remove are at random indexes.
Does a data structure like this already exist or do I need to make some sort of vector/doubly linked list/deque hybrid?
I have already seen this question but it doesn't help me.