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:
@@ -176,44 +176,51 @@ pub fn prepare_paths(
|
||||
tilemap: Res<TileMap>,
|
||||
) {
|
||||
for (entity, mut ambulatory, transform, pending_async) in query.iter_mut() {
|
||||
if let Some(target) = ambulatory.target {
|
||||
if ambulatory.current_path.is_none() || pending_async.is_some() {
|
||||
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 ambulatory.current_path.is_some() {
|
||||
continue;
|
||||
}
|
||||
if pending_async.is_some() {
|
||||
continue;
|
||||
}
|
||||
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);
|
||||
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);
|
||||
ambulatory.current_path = Some(path);
|
||||
ambulatory.path_index = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user