Remove entity map in favor of spatial grid

This commit is contained in:
2023-11-16 16:31:19 +01:00
parent 6974a80611
commit 3ec6e9ad47
12 changed files with 310 additions and 255 deletions

View File

@@ -32,8 +32,6 @@ bool bzMain(BzAppDesc *appDesc, int argc, const char **argv) {
appDesc->render = (BzAppRenderFunc) render;
appDesc->imguiRender = (BzAppRenderFunc) imguiRender;
Game *game = bzAlloc(sizeof(*game));
bzMemSet(game, 0, sizeof(*game));
appDesc->userData = NULL;
appDesc->useFlecs = true;
@@ -99,11 +97,12 @@ bool init(void *userData) {
.objectGroups[OBJECTS_GAME]=(BzTileObjectsDesc) {"Game"},
.objectGroups[OBJECTS_ENTITIES]=(BzTileObjectsDesc ) {"Entities"}
});
game->entityMap = entityMapCreate(&(EntityMapDesc) {
game->entityGrid = bzSpatialGridCreate(&(BzSpatialGridDesc) {
.maxWidth=game->map.width * game->map.tileWidth,
.maxHeight=game->map.height * game->map.tileHeight,
.cellResolution=game->map.tileWidth,
.cellDepth=16
.cellWidth=game->map.tileWidth * 2,
.cellHeight=game->map.tileHeight * 2,
.userDataSize=sizeof(ecs_entity_t)
});
bzTileMapOverrideLayer(&game->map, LAYER_BUILDING_OWNER, initBuildingsLayer);
@@ -129,6 +128,10 @@ void deinit(void *userData) {
bzTilesetDestroy(&game->buildingsTileset);
bzTilesetDestroy(&game->entitiesTileset);
bzObjectPoolDestroy(game->pools.pathData);
bzSpatialGridDestroy(game->entityGrid);
ecs_singleton_remove(ECS, Game);
}
@@ -226,6 +229,8 @@ void render(float dt, void *userData) {
game->input.buildingSize.sizeY * height, placeColor);
}
bzSpatialGridDrawDebugGrid(game->entityGrid);
Vector2 worldPos = GetScreenToWorld2D(GetMousePosition(), game->camera);
int tileX = (int) worldPos.x / 16;