Remove bugs with ecs hooks
This commit is contained in:
@@ -50,6 +50,13 @@ ECS_MOVE(SpatialGridID, dst, src, {
|
|||||||
*dst = *src;
|
*dst = *src;
|
||||||
*src = 0;
|
*src = 0;
|
||||||
})
|
})
|
||||||
|
void spatialIDRemoved(ecs_iter_t *it) {
|
||||||
|
Game *game = ecs_singleton_get_mut(ECS, Game);
|
||||||
|
SpatialGridID *spatialID = ecs_field(it, SpatialGridID, 1);
|
||||||
|
for (int i = 0; i < it->count; i++) {
|
||||||
|
bzSpatialGridRemove(game->entityGrid, spatialID[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
ECS_DTOR(Path, path, {
|
ECS_DTOR(Path, path, {
|
||||||
Game *game = ecs_singleton_get_mut(ECS, Game);
|
Game *game = ecs_singleton_get_mut(ECS, Game);
|
||||||
BzObjectPool *pool = game->pools.pathData;
|
BzObjectPool *pool = game->pools.pathData;
|
||||||
@@ -89,16 +96,34 @@ ECS_MOVE(Building, dst, src, {
|
|||||||
*dst = *src;
|
*dst = *src;
|
||||||
*src = (Building) {.type = 0};
|
*src = (Building) {.type = 0};
|
||||||
})
|
})
|
||||||
|
void buildingRemoved(ecs_iter_t *it) {
|
||||||
|
Game *game = ecs_singleton_get_mut(ECS, Game);
|
||||||
|
Building *building = ecs_field(it, Building, 1);
|
||||||
|
for (int i = 0; i < it->count; i++) {
|
||||||
|
Vec2i pos = building[i].pos;
|
||||||
|
Vec2i size = building[i].size;
|
||||||
|
bzTileMapSetCollisions(&game->map, false, COLL_LAYER_BUILDINGS, pos.x, pos.y, size.x, size.y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ECS_DTOR(AttachedEntity, attacked, {
|
ECS_DTOR(AttachedEntity, attached, {
|
||||||
if (ecs_is_alive(ECS, attacked->entity))
|
if (ecs_is_alive(ECS, attached->entity))
|
||||||
ecs_delete(ECS, attacked->entity);
|
ecs_delete(ECS, attached->entity);
|
||||||
attacked->entity = 0;
|
attached->entity = 0;
|
||||||
})
|
})
|
||||||
ECS_MOVE(AttachedEntity, dst, src, {
|
ECS_MOVE(AttachedEntity, dst, src, {
|
||||||
*dst = *src;
|
*dst = *src;
|
||||||
src->entity = 0;
|
src->entity = 0;
|
||||||
})
|
})
|
||||||
|
void attachedRemoved(ecs_iter_t *it) {
|
||||||
|
AttachedEntity *attached = ecs_field(it, AttachedEntity , 1);
|
||||||
|
for (int i = 0; i < it->count; i++) {
|
||||||
|
const ecs_entity_t entity = attached[i].entity;
|
||||||
|
if (ecs_is_alive(ECS, entity))
|
||||||
|
ecs_delete(ECS, entity);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void delayDeleteUpdate(ecs_iter_t *it) {
|
void delayDeleteUpdate(ecs_iter_t *it) {
|
||||||
DelayDelete *delay = ecs_field(it, DelayDelete, 1);
|
DelayDelete *delay = ecs_field(it, DelayDelete, 1);
|
||||||
@@ -108,28 +133,32 @@ void delayDeleteUpdate(ecs_iter_t *it) {
|
|||||||
for (i32 i = 0; i < it->count; i++) {
|
for (i32 i = 0; i < it->count; i++) {
|
||||||
delay[i].elapsed += dt;
|
delay[i].elapsed += dt;
|
||||||
|
|
||||||
if (delay[i].elapsed >= delay[i].time)
|
if (delay[i].elapsed >= delay[i].time) {
|
||||||
ecs_delete(ECS, it->entities[i]);
|
ecs_delete(ECS, it->entities[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setupSystems() {
|
void setupSystems() {
|
||||||
ecs_set_hooks(ECS, SpatialGridID, {
|
ecs_set_hooks(ECS, SpatialGridID, {
|
||||||
.dtor = ecs_dtor(SpatialGridID),
|
.dtor = ecs_dtor(SpatialGridID),
|
||||||
.move_dtor = ecs_move(SpatialGridID)
|
.move_dtor = ecs_move(SpatialGridID),
|
||||||
|
.on_remove = spatialIDRemoved,
|
||||||
});
|
});
|
||||||
ecs_set_hooks(ECS, Path, {
|
ecs_set_hooks(ECS, Path, {
|
||||||
.dtor = ecs_dtor(Path),
|
.dtor = ecs_dtor(Path),
|
||||||
.move = ecs_move(Path),
|
.move = ecs_move(Path),
|
||||||
.on_remove = pathRemoved
|
.on_remove = pathRemoved,
|
||||||
});
|
});
|
||||||
ecs_set_hooks(ECS, Building, {
|
ecs_set_hooks(ECS, Building, {
|
||||||
.dtor = ecs_dtor(Building),
|
.dtor = ecs_dtor(Building),
|
||||||
.move_dtor = ecs_move(Building)
|
.move_dtor = ecs_move(Building),
|
||||||
|
.on_remove = buildingRemoved,
|
||||||
});
|
});
|
||||||
ecs_set_hooks(ECS, AttachedEntity, {
|
ecs_set_hooks(ECS, AttachedEntity, {
|
||||||
.dtor = ecs_dtor(AttachedEntity),
|
.dtor = ecs_dtor(AttachedEntity),
|
||||||
.move_dtor = ecs_move(AttachedEntity)
|
.move_dtor = ecs_move(AttachedEntity),
|
||||||
|
.on_remove = attachedRemoved,
|
||||||
});
|
});
|
||||||
|
|
||||||
ECS_OBSERVER(ECS, entityPathRemove, EcsOnRemove, Path);
|
ECS_OBSERVER(ECS, entityPathRemove, EcsOnRemove, Path);
|
||||||
|
|||||||
Reference in New Issue
Block a user