Hello.
I want to implement Spatial partition like http://gameprogrammingpatterns.com/spatial-partition.html
And all is good, but i have a question, i cannot decide on design cause i feel its going to be slow, so i need help.
I have objects that will represent anything in my game
class Object
{
public:
Object();
Object(sf::Vector2f & Position, sf::Vector2f & Size, glob::Layer Layer, CollisionBase & CollSett, EntityBase & EntitySetting, bool IsInUse = false);
sf::Vector2f pos;
sf::Vector2f size;
glob::Layer layer;
CollisionBase collSett;
EntityBase entitySetting;
bool isInUse;
int myVecID;//For finding this object, comparing not actual ID
};
Each object has EntityBase and CollisionBase, entityBase is used for drawing, while collisionBase is used for collision and the class looks like this
class CollisionBase
{
public:
CollisionBase(bool IsColideWith = false, std::vector<Collision> & ListCollision = std::vector<Collision>{});
bool isColideWith;
std::vector<Collision> listCollision;
};
class Collision
{
public:
Collision(sf::Vector2f & PosOffset, sf::Vector2f & Size);
sf::Vector2f posOffset;
sf::Vector2f size;
};
So implementing spatial partition would mean i have references to objects in vectors that are small areas, or do i put the main data of objects in those small containers?
If i want to hold references i have a issue, each object is in vector that often resizes, meaning the reference will be invalid after resizing occurs
My question would be, how do i store references of the objects CollisionBase object, because that is all i need in the Spatial partition.
The objects are stored in this way
std::vector<Object> listObject;