Move system initialization in systems.c, properly delete all entities when unloading map
This commit is contained in:
56
game/systems/systems.c
Normal file
56
game/systems/systems.c
Normal file
@@ -0,0 +1,56 @@
|
||||
#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;
|
||||
|
||||
}
|
||||
@@ -163,29 +163,9 @@ void drawPlayerInputUI();
|
||||
* MISC
|
||||
**********************************/
|
||||
|
||||
static void setupSystems(ecs_world_t *ecs) {
|
||||
extern ecs_entity_t renderCollidersSystem;
|
||||
extern ecs_entity_t renderDebugPathSystem;
|
||||
|
||||
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);
|
||||
}
|
||||
void setupSystems();
|
||||
|
||||
#endif //PIXELDEFENSE_SYSTEMS_H
|
||||
|
||||
Reference in New Issue
Block a user