Tweak spatial grid size, add colliders rendering

This commit is contained in:
2023-11-17 19:39:49 +01:00
parent 66dba151ed
commit 2167d10501
4 changed files with 30 additions and 7 deletions

View File

@@ -22,8 +22,9 @@ void entityUpdatePhysics(ecs_iter_t *it) {
//bzSpatialGridUpdate(game->entityGrid, spatialID[i], pos[i].x, pos[i].y, size[i].x, size[i].y);
ecs_entity_t *e = bzSpatialGridGetData(game->entityGrid, spatialID[i]);
BZ_ASSERT(*e == it->entities[i]);
bzSpatialGridRemove(game->entityGrid, spatialID[i]);
spatialID[i] = bzSpatialGridInsert(game->entityGrid, &(it->entities[i]), pos[i].x, pos[i].y, size[i].x, size[i].y);
f32 posX = pos[i].x - size[i].x * 0.5f;
f32 posY = pos[i].y - size[i].y * 0.5f;
bzSpatialGridUpdate(game->entityGrid, spatialID[i], posX, posY, size[i].x, size[i].y);
}
}
@@ -59,7 +60,6 @@ static void render(ecs_iter_t *it) {
if (t[i].flipX) src.width *= -1.0f;
if (t[i].flipY) src.height *= -1.0f;
DrawTexturePro(t[i].texture, src, dst, origin, r[i], WHITE);
//DrawRectangleLines(dst.x - dst.width * 0.5f, dst.y - dst.height * 0.5f, dst.width, dst.height, RED);
}
}
@@ -73,6 +73,17 @@ void renderEntities(ecs_iter_t *it) {
render(it);
}
void renderColliders(ecs_iter_t *it) {
Position *pos = ecs_field(it, Position, 1);
Size *size = ecs_field(it, Size, 2);
for (i32 i = 0; i < it->count; i++) {
f32 posX = pos[i].x - size[i].x * 0.5f;
f32 posY = pos[i].y - size[i].y * 0.5f;
DrawRectangleLines(posX, posY, size[i].x, size[i].y, RED);
}
}
void updatePos(ecs_iter_t *it) {
Position *pos = ecs_field(it, Position, 1);
TargetPosition *target = ecs_field(it, TargetPosition, 2);