Howdy!
Apologies if this isn't the right place to ask (I was debating with either General or Graphics but chose this
). Anyway, at first I was rendering my map with a simple vector but I wanted to extend this further. I wanted to have layers that can be rendered in the order they are in (floor first, player next, anything above player goes after etc.) so I extended this with a 2D vector of layers with tiles. No problem. Most of the time (at least in my vision) there's going to be less tiles for every layer added. So the worst case being every layer filled with tiles is unlikely. However, I want to extend this with an unordered_map. The reason for this is because I have an entity base class that every tile and player derives. If I were to keep a 2D vector then finding a certain entity would take O(N) (let's say, Player 3). However, using a map I can find "Player" and find the second player in however many players there are (in this case 3). But, if I were to render everything, I would get something like this:
// The container:
// std::vector<std::unordered_map<std::string, std::vector<Entity*> > > entityLayerList;
for (auto& layerIndex : entityLayerList) {
for (auto& entityList : layerIndex) {
for (Entity* entityIndex : entityList.second) {
}
}
}
Which scares me because this is way too many loops. Is there a better way to deal this? Should I go back to a 2D array and figure out ways to properly cast from entities to their own objects? Any feedback would be appreciated!