Skip to content

Commit

Permalink
- Clarifying behavior of what happens when doing a Break step operati…
Browse files Browse the repository at this point in the history
…on on a multi-archetype query (will now cancel the whole operation irrespective of archetypes being iterated)
  • Loading branch information
recatek committed Jul 20, 2024
1 parent 890a0c3 commit 0d6d9ef
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
16 changes: 11 additions & 5 deletions macros/src/generate/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ pub fn generate_query_iter(
// Continue
},
EcsStep::Break => {
break;
return;
},
}
}
Expand All @@ -299,7 +299,10 @@ pub fn generate_query_iter(
"query matched no archetypes in world",
))
} else {
Ok(quote!(#(#queries)*))
Ok(quote!(
// Use a closure so we can use return to cancel other archetype iterations
(||{#(#queries)*})();
))
}
}

Expand Down Expand Up @@ -378,7 +381,7 @@ pub fn generate_query_iter_destroy(
// Continue
},
EcsStepDestroy::Break => {
break;
return;
},
EcsStepDestroy::ContinueDestroy => {
let entity = slices.entity[idx];
Expand All @@ -387,7 +390,7 @@ pub fn generate_query_iter_destroy(
EcsStepDestroy::BreakDestroy => {
let entity = slices.entity[idx];
archetype.destroy(entity);
break;
return;
},
}
}
Expand All @@ -402,7 +405,10 @@ pub fn generate_query_iter_destroy(
"query matched no archetypes in world",
))
} else {
Ok(quote!(#(#queries)*))
Ok(quote!(
// Use a closure so we can use return to cancel other archetype iterations
(||{#(#queries)*})();
))
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,10 @@ mod macros {
/// or continue and also immediately remove that entity after that iteration step. The
/// entity and its handle are not preserved after this process. Note that this iterates the
/// world in a different order from the normal `ecs_iter!` (which should not be relied upon
/// for deterministic iteration anyway). This is also slightly slower than normal `ecs_iter!`.
/// for deterministic iteration anyway). This is also a bit slower than normal `ecs_iter!`.
///
/// Note that performing an early-out break will end the iteration for all archetypes. This
/// can have unpredictable order, and is recommended only for searching for single entities.
///
/// # Example
///
Expand Down

0 comments on commit 0d6d9ef

Please sign in to comment.