fix: correct inverted logic in prepare_paths - entities without paths were being skipped

The condition 'if ambulatory.current_path.is_none() || pending_async.is_some()' was backwards.
It should skip entities that ALREADY have a path, not entities WITHOUT a path.

Fixed to properly skip entities with existing paths or pending async tasks.
This commit is contained in:
2026-03-18 16:47:51 +00:00
parent c902cff908
commit d2ec1fb5dc
2 changed files with 42 additions and 17726 deletions
File diff suppressed because it is too large Load Diff
+41 -34
View File
@@ -176,44 +176,51 @@ pub fn prepare_paths(
tilemap: Res<TileMap>, tilemap: Res<TileMap>,
) { ) {
for (entity, mut ambulatory, transform, pending_async) in query.iter_mut() { for (entity, mut ambulatory, transform, pending_async) in query.iter_mut() {
if let Some(target) = ambulatory.target { if ambulatory.current_path.is_some() {
if ambulatory.current_path.is_none() || pending_async.is_some() { continue;
continue; }
} if pending_async.is_some() {
let start = transform.translation.as_ivec3(); continue;
let goal = target.as_ivec3() - ivec3(0, 0, ITILE_SIZE); }
let distance = octile_distance_3d(start, goal) / ITILE_SIZE; if ambulatory.target.is_none() {
continue;
}
let Some(target) = ambulatory.target else {
continue;
};
let start = transform.translation.as_ivec3();
let goal = target.as_ivec3() - ivec3(0, 0, ITILE_SIZE);
let distance = octile_distance_3d(start, goal) / ITILE_SIZE;
if distance <= PATHFINDER_SHORT_PATH_MAX_TILES { if distance <= PATHFINDER_SHORT_PATH_MAX_TILES {
let path = calculate_path_benchmarked(&tilemap, start, goal);
ambulatory.current_path = Some(path);
ambulatory.path_index = 0;
} else {
let provisional = calculate_provisional_path(
&tilemap,
start,
goal,
PATHFINDER_PROVISIONAL_NODE_LIMIT,
);
if !provisional.is_empty() {
ambulatory.current_path = Some(provisional.clone());
ambulatory.path_index = 0;
let request_id = counter.next();
let pending =
crate::entities::shared_systems::async_pathfinding::spawn_async_path_task(
&tilemap,
start,
goal,
provisional,
request_id,
);
commands.entity(entity).insert(pending);
} else {
let path = calculate_path_benchmarked(&tilemap, start, goal); let path = calculate_path_benchmarked(&tilemap, start, goal);
ambulatory.current_path = Some(path); ambulatory.current_path = Some(path);
ambulatory.path_index = 0; ambulatory.path_index = 0;
} else {
let provisional = calculate_provisional_path(
&tilemap,
start,
goal,
PATHFINDER_PROVISIONAL_NODE_LIMIT,
);
if !provisional.is_empty() {
ambulatory.current_path = Some(provisional.clone());
ambulatory.path_index = 0;
let request_id = counter.next();
let pending =
crate::entities::shared_systems::async_pathfinding::spawn_async_path_task(
&tilemap,
start,
goal,
provisional,
request_id,
);
commands.entity(entity).insert(pending);
} else {
let path = calculate_path_benchmarked(&tilemap, start, goal);
ambulatory.current_path = Some(path);
ambulatory.path_index = 0;
}
} }
} }
} }