Add destructor for SpatialGridID and Path, remove unused Animation code

This commit is contained in:
2023-12-29 09:06:53 +01:00
parent 0c9fae7781
commit 6e2c68cb70
4 changed files with 25 additions and 100 deletions

View File

@@ -35,48 +35,16 @@ static Position getBottomLeftPos(Position pos, Size size) {
return (Position) {pos.x - size.x * 0.5f, pos.y - size.y * 0.5f};
}
void entitySpatialRemove(ecs_iter_t *it) {
Game *game = ecs_singleton_get_mut(ECS, Game);
SpatialGridID *spatialID = ecs_field(it, SpatialGridID, 1);
for (i32 i = 0; i < it->count; i++) {
bzSpatialGridRemove(game->entityGrid, spatialID[i]);
}
}
void entityPathRemove(ecs_iter_t *it) {
Game *game = ecs_singleton_get_mut(ECS, Game);
BzObjectPool *pool = game->pools.pathData;
Path *path = ecs_field(it, Path, 1);
for (i32 i = 0; i < it->count; i++) {
ecs_entity_t entity = it->entities[i];
ecs_remove(ECS, entity, TargetPosition);
PathData *cur = path[i].paths;
while (cur) {
bzObjectPoolRelease(pool, cur);
cur = cur->next;
}
}
}
void entitySetAnimationState(ecs_iter_t *it) {
/*
Animation *anim = ecs_field(it, Animation, 1);
AnimationType *animType = ecs_field(it, AnimationType , 2);
for (i32 i = 0; i < it->count; i++) {
EntityType entityType = anim[i].entityType;
AnimationType type = animType[i];
BZ_ASSERT(entityHasAnimation(entityType, type));
anim[i].animType = type;
anim[i].sequence = getEntityAnimation(entityType, type);
}
*/
}
void entityUpdateSpatialID(ecs_iter_t *it) {
Game *game = ecs_singleton_get_mut(ECS, Game);
Position *position = ecs_field(it, Position, 1);
@@ -194,64 +162,6 @@ void entityFollowPath(ecs_iter_t *it) {
}
}
/*
void entityHarvestTaskSystem(ecs_iter_t *it) {
Game *game = ecs_singleton_get_mut(ECS, Game);
const Position *position = ecs_field(it, Position, 1);
const Rotation *rotation = ecs_field(it, Rotation, 2);
const HarvestTask *harvestTask = ecs_field(it, HarvestTask, 3);
for (i32 i = 0; i < it->count; i++) {
const ecs_entity_t entity = it->entities[i];
const ecs_entity_t targetEntity = harvestTask[i].entity;
const Position *pTarget = ecs_get(ECS, targetEntity, Position);
BZ_ASSERT(pTarget);
const Position target = *pTarget;
const f32 DST_LIMIT = 10.0f;
Resource *resource = ecs_get_mut(ECS, targetEntity, Resource);
if (resource->amount <= 0) {
ecs_delete(ECS, targetEntity);
ecs_remove(ECS, entity, HarvestTask);
continue;
}
const f32 dst = Vector2Distance(position[i], target);
if (!ecs_has(ECS, entity, Path) && dst > DST_LIMIT) {
bzLogInfo("%.2f", dst);
// Pathfind to target
entitySetPath(entity, target, game);
continue;
} else if (dst < DST_LIMIT && !ecs_has(ECS, entity, Path)) {
if (!ecs_has(ECS, entity, Path)) {
bzLogInfo("Mine");
resource->amount -= 5;
}
ecs_remove(ECS, entity, Path);
// MINE
// find nearest warehouse for wood
ecs_entity_t storage = findNearestStorage(RES_WOOD);
if (storage) {
const Position *storagePos = ecs_get(ECS, storage, Position);
BZ_ASSERT(storagePos);
entitySetPath(entity, *storagePos, game);
}
}
// Harvest
const i32 carryCapacity = 5;
}
}
*/
void entityUpdateAnimationState(ecs_iter_t *it) {
Animation *anim = ecs_field(it, Animation, 1);
TextureRegion *text = ecs_field(it, TextureRegion, 2);