#include "systems.h" #include "../game_state.h" ecs_entity_t renderCollidersSystem; ecs_entity_t renderDebugPathSystem; ECS_DTOR(SpatialGridID, gridID, { Game *game = ecs_singleton_get_mut(ECS, Game); bzSpatialGridRemove(game->entityGrid, *gridID); }) ECS_DTOR(Path, path, { Game *game = ecs_singleton_get_mut(ECS, Game); BzObjectPool *pool = game->pools.pathData; PathData *cur = path[i].paths; while (cur) { bzObjectPoolRelease(pool, cur); cur = cur->next; } }) void setupSystems() { ecs_set_hooks(ECS, SpatialGridID, { .dtor = ecs_dtor(SpatialGridID) }); ecs_set_hooks(ECS, Path, { .dtor = ecs_dtor(Path) }); ECS_OBSERVER(ECS, entityPathRemove, EcsOnRemove, Path); ECS_SYSTEM(ECS, entityUpdateSpatialID, EcsOnUpdate, Position, Size, Velocity, SpatialGridID); ECS_SYSTEM(ECS, entityUpdateKinematic, EcsOnUpdate, Position, Rotation, Velocity, Steering); ECS_SYSTEM(ECS, entityMoveToTarget, EcsOnUpdate, Position, Rotation, Velocity, TargetPosition, Steering); ECS_SYSTEM(ECS, entityFollowPath, EcsOnUpdate, Path); ECS_SYSTEM(ECS, handleUnitActionsSystem, EcsOnUpdate, UnitAction); ECS_SYSTEM(ECS, updateUnitAISystem, EcsOnUpdate, UnitAI, UnitAction); // Needs to be called after AI update, since it removes finished actions ECS_SYSTEM(ECS, updateUnitActionsSystem, EcsOnUpdate, UnitAction); ECS_SYSTEM(ECS, updateAnimationState, EcsOnUpdate, Animation, TextureRegion); ECS_SYSTEM(ECS, updateAnimation, EcsOnUpdate, Animation, TextureRegion); ECS_SYSTEM(ECS, updateEasingSystem, EcsOnUpdate, Easing, Position, Size, Rotation); ECS_SYSTEM(ECS, renderDebugPath, EcsOnUpdate, Path); ECS_SYSTEM(ECS, renderColliders, EcsOnUpdate, Position, Size); ECS_SYSTEM(ECS, renderRotationDirection, EcsOnUpdate, Position, Rotation); renderDebugPathSystem = renderDebugPath; renderCollidersSystem = renderColliders; }