Fix bug with follow path system

This commit is contained in:
2023-12-07 11:35:35 +01:00
parent ddb562a62e
commit e7e4d1e4ce
4 changed files with 22 additions and 9 deletions

View File

@@ -9,7 +9,7 @@ static Position getBottomLeftPos(Position pos, Size size) {
return (Position) {pos.x - size.x * 0.5f, pos.y - size.y * 0.5f};
}
void entitySpatialRemoved(ecs_iter_t *it) {
void entitySpatialRemove(ecs_iter_t *it) {
Game *game = ecs_singleton_get_mut(ECS, Game);
Position *pos = ecs_field(it, Position, 1);
SpatialGridID *spatialID = ecs_field(it, SpatialGridID , 2);
@@ -20,7 +20,7 @@ void entitySpatialRemoved(ecs_iter_t *it) {
}
void entityPathRemoved(ecs_iter_t *it) {
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);
@@ -154,11 +154,11 @@ void entityFollowPath(ecs_iter_t *it) {
for (i32 i = 0; i < it->count; i++) {
ecs_entity_t entity = it->entities[i];
TargetPosition target = path[i].paths->waypoints[path[i].curWaypoint];
Path *entityPath = &path[i];
TargetPosition target = entityPath->paths->waypoints[entityPath->curWaypoint];
if (!ecs_has(ECS, entity, TargetPosition)) {
ecs_set_ptr(ECS, entity, TargetPosition, &target);
path[i].curWaypoint++;
if (path[i].curWaypoint >= path[i].paths->numWaypoints) {
path[i].curWaypoint = 0;
PathData *oldPath = path[i].paths;
@@ -166,6 +166,8 @@ void entityFollowPath(ecs_iter_t *it) {
path[i].paths = path[i].paths->next;
if (!path[i].paths) ecs_remove(ECS, it->entities[i], Path);
}
ecs_set_ptr(ECS, entity, TargetPosition, &target);
path[i].curWaypoint++;
}
}
}