Hello, I'm building a simple spatial partitioning grid for an isometric 2D virtual world (~1k players). I want to handle it the simplest way possible and optimize later if necessary, but I'm trying to avoid putting work into an architecture that will clearly not work, so I could use some input.
I have something sort of like this right now:
// My world map is a tile map, tiles are grouped into 16x16 chunks.
// EntityID is entt::entity
// TileExtent is just a rect (x, y, xLength, yLength).
class EntityLocator
{
public:
// Sets the entity's location to the tiles that contain the given AABB.
void setEntityLocation(EntityID entity, BoundingBox boundingBox);
// Returns all entities that are located within the given extent.
std::vector<EntityID> getEntitiesInExtent(const TileExtent& tileExtent);
private:
// The outer vector is a 2D grid stored in row-major order, corresponding
// to the tiles in the tile map.
// Each element in the grid is a vector of entities--the entities that
// are currently located in that tile.
std::vector<std::vector<EntityID>> entityGrid;
// A map of entity ID -> the tiles that the entity is located in.
// Used to easily clear out old entity data before setting their new
// location.
std::unordered_map<EntityID, TileExtent> entityMap;
}
Is this along the lines of how you build one of these things? Adding/removing entities from the vectors in each of the grid tiles takes a lot of operations, but it seems manageable. The grid will take up a decent amount of RAM on the server side (for a large 100x100 chunk world it'd be ~51MB), but it isn't that much relative to the 4GB that my server has.