Remove multiple colliders, add spatial index component

This commit is contained in:
2023-11-17 15:13:30 +01:00
parent 208cdc6b6f
commit 021df6d77a
11 changed files with 122 additions and 95 deletions

View File

@@ -12,6 +12,19 @@ void entityAdded(ecs_iter_t *it) {
}
void entityUpdatePhysics(ecs_iter_t *it) {
Game *game = ecs_singleton_get_mut(ECS, Game);
Position *pos = ecs_field(it, Position, 1);
Size *size = ecs_field(it, Size, 2);
//MoveForce *force = ecs_field(it, MoveForce, 3);
SpatialGridID *spatialID = ecs_field(it, SpatialGridID, 3);
for (i32 i = 0; i < it->count; i++) {
//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);
}
}
@@ -46,6 +59,7 @@ void renderEntities(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.width, dst.height, RED);
}
}
@@ -74,6 +88,7 @@ void updatePos(ecs_iter_t *it) {
#include <stdlib.h>
void targetFinish(ecs_iter_t *it) {
const Game *game = ecs_singleton_get(ECS, Game);
if (game == NULL) return;
for (i32 i = 0; i < it->count; i++) {
ecs_entity_t e = it->entities[i];