Skip to content

Commit 53de75a

Browse files
committed
Pass query change ticks to QueryParIter instead of always using change ticks from World.
1 parent fd1af7c commit 53de75a

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

crates/bevy_ecs/src/query/par_iter.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::world::World;
1+
use crate::{component::Tick, world::World};
22
use bevy_tasks::ComputeTaskPool;
33
use std::ops::Range;
44

@@ -81,6 +81,8 @@ impl BatchingStrategy {
8181
pub struct QueryParIter<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery> {
8282
pub(crate) world: &'w World,
8383
pub(crate) state: &'s QueryState<Q, F>,
84+
pub(crate) last_run: Tick,
85+
pub(crate) this_run: Tick,
8486
pub(crate) batching_strategy: BatchingStrategy,
8587
}
8688

@@ -148,21 +150,17 @@ impl<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery> QueryParIter<'w, 's, Q, F> {
148150
) {
149151
let thread_count = ComputeTaskPool::get().thread_num();
150152
if thread_count <= 1 {
151-
self.state.for_each_unchecked_manual(
152-
self.world,
153-
func,
154-
self.world.last_change_tick(),
155-
self.world.read_change_tick(),
156-
);
153+
self.state
154+
.for_each_unchecked_manual(self.world, func, self.last_run, self.this_run);
157155
} else {
158156
// Need a batch size of at least 1.
159157
let batch_size = self.get_batch_size(thread_count).max(1);
160158
self.state.par_for_each_unchecked_manual(
161159
self.world,
162160
batch_size,
163161
func,
164-
self.world.last_change_tick(),
165-
self.world.read_change_tick(),
162+
self.last_run,
163+
self.this_run,
166164
);
167165
}
168166
}

crates/bevy_ecs/src/query/state.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,8 @@ impl<Q: WorldQuery, F: ReadOnlyWorldQuery> QueryState<Q, F> {
820820
QueryParIter {
821821
world,
822822
state: self,
823+
last_run: world.last_change_tick(),
824+
this_run: world.read_change_tick(),
823825
batching_strategy: BatchingStrategy::new(),
824826
}
825827
}
@@ -835,6 +837,8 @@ impl<Q: WorldQuery, F: ReadOnlyWorldQuery> QueryState<Q, F> {
835837
QueryParIter {
836838
world,
837839
state: self,
840+
last_run: world.last_change_tick(),
841+
this_run: world.read_change_tick(),
838842
batching_strategy: BatchingStrategy::new(),
839843
}
840844
}

crates/bevy_ecs/src/system/query.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,8 @@ impl<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery> Query<'w, 's, Q, F> {
728728
QueryParIter {
729729
world: self.world,
730730
state: self.state.as_readonly(),
731+
last_run: self.last_run,
732+
this_run: self.this_run,
731733
batching_strategy: BatchingStrategy::new(),
732734
}
733735
}
@@ -742,6 +744,8 @@ impl<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery> Query<'w, 's, Q, F> {
742744
QueryParIter {
743745
world: self.world,
744746
state: self.state,
747+
last_run: self.last_run,
748+
this_run: self.this_run,
745749
batching_strategy: BatchingStrategy::new(),
746750
}
747751
}

0 commit comments

Comments
 (0)