Skip to content

Commit 91ef673

Browse files
use InteriorMutableWorld for QueryState/Query
1 parent 4f04a57 commit 91ef673

File tree

9 files changed

+172
-93
lines changed

9 files changed

+172
-93
lines changed

crates/bevy_ecs/macros/src/fetch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ pub fn derive_world_query_impl(ast: DeriveInput) -> TokenStream {
222222
}
223223

224224
unsafe fn init_fetch<'__w>(
225-
_world: &'__w #path::world::World,
225+
_world: #path::world::interior_mutable_world::InteriorMutableWorld<'__w>,
226226
state: &Self::State,
227227
_last_change_tick: u32,
228228
_change_tick: u32

crates/bevy_ecs/src/query/fetch.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use crate::{
55
entity::Entity,
66
query::{Access, DebugCheckedUnwrap, FilteredAccess},
77
storage::{ComponentSparseSet, Table, TableRow},
8-
world::{Mut, World},
8+
world::{interior_mutable_world::InteriorMutableWorld, Mut, World},
99
};
1010
use bevy_ecs_macros::all_tuples;
1111
pub use bevy_ecs_macros::WorldQuery;
@@ -331,7 +331,7 @@ pub unsafe trait WorldQuery {
331331
/// `state` must have been initialized (via [`WorldQuery::init_state`]) using the same `world` passed
332332
/// in to this function.
333333
unsafe fn init_fetch<'w>(
334-
world: &'w World,
334+
world: InteriorMutableWorld<'w>,
335335
state: &Self::State,
336336
last_change_tick: u32,
337337
change_tick: u32,
@@ -462,7 +462,7 @@ unsafe impl WorldQuery for Entity {
462462
const IS_ARCHETYPAL: bool = true;
463463

464464
unsafe fn init_fetch<'w>(
465-
_world: &'w World,
465+
_world: InteriorMutableWorld<'w>,
466466
_state: &Self::State,
467467
_last_change_tick: u32,
468468
_change_tick: u32,
@@ -544,7 +544,7 @@ unsafe impl<T: Component> WorldQuery for &T {
544544
const IS_ARCHETYPAL: bool = true;
545545

546546
unsafe fn init_fetch<'w>(
547-
world: &'w World,
547+
world: InteriorMutableWorld<'w>,
548548
&component_id: &ComponentId,
549549
_last_change_tick: u32,
550550
_change_tick: u32,
@@ -689,7 +689,7 @@ unsafe impl<'__w, T: Component> WorldQuery for &'__w mut T {
689689
const IS_ARCHETYPAL: bool = true;
690690

691691
unsafe fn init_fetch<'w>(
692-
world: &'w World,
692+
world: InteriorMutableWorld<'w>,
693693
&component_id: &ComponentId,
694694
last_change_tick: u32,
695695
change_tick: u32,
@@ -833,7 +833,7 @@ unsafe impl<T: WorldQuery> WorldQuery for Option<T> {
833833
const IS_ARCHETYPAL: bool = T::IS_ARCHETYPAL;
834834

835835
unsafe fn init_fetch<'w>(
836-
world: &'w World,
836+
world: InteriorMutableWorld<'w>,
837837
state: &T::State,
838838
last_change_tick: u32,
839839
change_tick: u32,
@@ -1027,7 +1027,7 @@ unsafe impl<T: Component> WorldQuery for ChangeTrackers<T> {
10271027
const IS_ARCHETYPAL: bool = true;
10281028

10291029
unsafe fn init_fetch<'w>(
1030-
world: &'w World,
1030+
world: InteriorMutableWorld<'w>,
10311031
&component_id: &ComponentId,
10321032
last_change_tick: u32,
10331033
change_tick: u32,
@@ -1174,7 +1174,7 @@ macro_rules! impl_tuple_fetch {
11741174
}
11751175

11761176
#[allow(clippy::unused_unit)]
1177-
unsafe fn init_fetch<'w>(_world: &'w World, state: &Self::State, _last_change_tick: u32, _change_tick: u32) -> Self::Fetch<'w> {
1177+
unsafe fn init_fetch<'w>(_world: InteriorMutableWorld<'w>, state: &Self::State, _last_change_tick: u32, _change_tick: u32) -> Self::Fetch<'w> {
11781178
let ($($name,)*) = state;
11791179
($($name::init_fetch(_world, $name, _last_change_tick, _change_tick),)*)
11801180
}
@@ -1283,7 +1283,7 @@ macro_rules! impl_anytuple_fetch {
12831283
}
12841284

12851285
#[allow(clippy::unused_unit)]
1286-
unsafe fn init_fetch<'w>(_world: &'w World, state: &Self::State, _last_change_tick: u32, _change_tick: u32) -> Self::Fetch<'w> {
1286+
unsafe fn init_fetch<'w>(_world: InteriorMutableWorld<'w>, state: &Self::State, _last_change_tick: u32, _change_tick: u32) -> Self::Fetch<'w> {
12871287
let ($($name,)*) = state;
12881288
($(($name::init_fetch(_world, $name, _last_change_tick, _change_tick), false),)*)
12891289
}
@@ -1422,7 +1422,7 @@ unsafe impl<Q: WorldQuery> WorldQuery for NopWorldQuery<Q> {
14221422

14231423
#[inline(always)]
14241424
unsafe fn init_fetch(
1425-
_world: &World,
1425+
_world: InteriorMutableWorld<'_>,
14261426
_state: &Q::State,
14271427
_last_change_tick: u32,
14281428
_change_tick: u32,

crates/bevy_ecs/src/query/filter.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::{
44
entity::Entity,
55
query::{Access, DebugCheckedUnwrap, FilteredAccess, WorldQuery},
66
storage::{Column, ComponentSparseSet, Table, TableRow},
7-
world::World,
7+
world::{interior_mutable_world::InteriorMutableWorld, World},
88
};
99
use bevy_ecs_macros::all_tuples;
1010
use bevy_ptr::{ThinSlicePtr, UnsafeCellDeref};
@@ -51,7 +51,7 @@ unsafe impl<T: Component> WorldQuery for With<T> {
5151
fn shrink<'wlong: 'wshort, 'wshort>(_: Self::Item<'wlong>) -> Self::Item<'wshort> {}
5252

5353
unsafe fn init_fetch(
54-
_world: &World,
54+
_world: InteriorMutableWorld<'_>,
5555
_state: &ComponentId,
5656
_last_change_tick: u32,
5757
_change_tick: u32,
@@ -153,7 +153,7 @@ unsafe impl<T: Component> WorldQuery for Without<T> {
153153
fn shrink<'wlong: 'wshort, 'wshort>(_: Self::Item<'wlong>) -> Self::Item<'wshort> {}
154154

155155
unsafe fn init_fetch(
156-
_world: &World,
156+
_world: InteriorMutableWorld<'_>,
157157
_state: &ComponentId,
158158
_last_change_tick: u32,
159159
_change_tick: u32,
@@ -277,7 +277,7 @@ macro_rules! impl_query_filter_tuple {
277277

278278
const IS_ARCHETYPAL: bool = true $(&& $filter::IS_ARCHETYPAL)*;
279279

280-
unsafe fn init_fetch<'w>(world: &'w World, state: &Self::State, last_change_tick: u32, change_tick: u32) -> Self::Fetch<'w> {
280+
unsafe fn init_fetch<'w>(world: InteriorMutableWorld<'w>, state: &Self::State, last_change_tick: u32, change_tick: u32) -> Self::Fetch<'w> {
281281
let ($($filter,)*) = state;
282282
($(OrFetch {
283283
fetch: $filter::init_fetch(world, $filter, last_change_tick, change_tick),
@@ -432,7 +432,7 @@ macro_rules! impl_tick_filter {
432432
item
433433
}
434434

435-
unsafe fn init_fetch<'w>(world: &'w World, &id: &ComponentId, last_change_tick: u32, change_tick: u32) -> Self::Fetch<'w> {
435+
unsafe fn init_fetch<'w>(world: InteriorMutableWorld<'w>, &id: &ComponentId, last_change_tick: u32, change_tick: u32) -> Self::Fetch<'w> {
436436
Self::Fetch::<'w> {
437437
table_ticks: None,
438438
sparse_set: (T::Storage::STORAGE_TYPE == StorageType::SparseSet)

crates/bevy_ecs/src/query/iter.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use crate::{
22
archetype::{ArchetypeEntity, ArchetypeId, Archetypes},
33
entity::{Entities, Entity},
4-
prelude::World,
54
query::{ArchetypeFilter, DebugCheckedUnwrap, QueryState, WorldQuery},
65
storage::{TableId, TableRow, Tables},
6+
world::interior_mutable_world::InteriorMutableWorld,
77
};
88
use std::{borrow::Borrow, iter::FusedIterator, marker::PhantomData, mem::MaybeUninit};
99

@@ -27,15 +27,15 @@ impl<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery> QueryIter<'w, 's, Q, F> {
2727
/// This does not validate that `world.id()` matches `query_state.world_id`. Calling this on a `world`
2828
/// with a mismatched [`WorldId`](crate::world::WorldId) is unsound.
2929
pub(crate) unsafe fn new(
30-
world: &'w World,
30+
world: InteriorMutableWorld<'w>,
3131
query_state: &'s QueryState<Q, F>,
3232
last_change_tick: u32,
3333
change_tick: u32,
3434
) -> Self {
3535
QueryIter {
3636
query_state,
3737
tables: &world.storages().tables,
38-
archetypes: &world.archetypes,
38+
archetypes: world.archetypes(),
3939
cursor: QueryIterationCursor::init(world, query_state, last_change_tick, change_tick),
4040
}
4141
}
@@ -95,7 +95,7 @@ where
9595
/// This does not validate that `world.id()` matches `query_state.world_id`. Calling this on a `world`
9696
/// with a mismatched [`WorldId`](crate::world::WorldId) is unsound.
9797
pub(crate) unsafe fn new<EntityList: IntoIterator<IntoIter = I>>(
98-
world: &'w World,
98+
world: InteriorMutableWorld<'w>,
9999
query_state: &'s QueryState<Q, F>,
100100
entity_list: EntityList,
101101
last_change_tick: u32,
@@ -115,9 +115,9 @@ where
115115
);
116116
QueryManyIter {
117117
query_state,
118-
entities: &world.entities,
119-
archetypes: &world.archetypes,
120-
tables: &world.storages.tables,
118+
entities: world.entities(),
119+
archetypes: world.archetypes(),
120+
tables: &world.storages().tables,
121121
fetch,
122122
filter,
123123
entity_iter: entity_list.into_iter(),
@@ -297,7 +297,7 @@ impl<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery, const K: usize>
297297
/// This does not validate that `world.id()` matches `query_state.world_id`. Calling this on a
298298
/// `world` with a mismatched [`WorldId`](crate::world::WorldId) is unsound.
299299
pub(crate) unsafe fn new(
300-
world: &'w World,
300+
world: InteriorMutableWorld<'w>,
301301
query_state: &'s QueryState<Q, F>,
302302
last_change_tick: u32,
303303
change_tick: u32,
@@ -329,7 +329,7 @@ impl<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery, const K: usize>
329329
QueryCombinationIter {
330330
query_state,
331331
tables: &world.storages().tables,
332-
archetypes: &world.archetypes,
332+
archetypes: world.archetypes(),
333333
cursors: array.assume_init(),
334334
}
335335
}
@@ -495,7 +495,7 @@ impl<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery> QueryIterationCursor<'w, 's,
495495
const IS_DENSE: bool = Q::IS_DENSE && F::IS_DENSE;
496496

497497
unsafe fn init_empty(
498-
world: &'w World,
498+
world: InteriorMutableWorld<'w>,
499499
query_state: &'s QueryState<Q, F>,
500500
last_change_tick: u32,
501501
change_tick: u32,
@@ -508,7 +508,7 @@ impl<'w, 's, Q: WorldQuery, F: ReadOnlyWorldQuery> QueryIterationCursor<'w, 's,
508508
}
509509

510510
unsafe fn init(
511-
world: &'w World,
511+
world: InteriorMutableWorld<'w>,
512512
query_state: &'s QueryState<Q, F>,
513513
last_change_tick: u32,
514514
change_tick: u32,

0 commit comments

Comments
 (0)