I have divided my 2D game map into 100x100 pixel pieces (the map size will be integer multiple of dimensions of the piece size). Each map piece contains a list of map objects in it; so that a short list of nearby game object will be available all the time for each given location on the map. I preferred this structure in order to increase performance of the collision detection algorithm.
My question is:
What will happen to the memory allocated by std::vector<MapPieces> when I add a new game object pointer to any of the GameObjects instance? I mean, when a game object overlaps the area of a MapPiece instance and I add its pointer the the GameObjets list, will the entire std::vector<MapPieces> reallocate in the memory? If yes, what kind of container should I prefer instead of std::list<std::shared_ptr<GameObject>> GameObjects?
class GameMap
{
public:
// ...
std::vector<MapPiece> MapPieces;
// ...
};
class MapPiece
{
public:
// ...
std::list<std::shared_ptr<GameObject>> GameObjects;
// ...
};