Skip to content

Commit ba66966

Browse files
Move SystemRegistry to a field on World
1 parent 870b12d commit ba66966

2 files changed

Lines changed: 15 additions & 20 deletions

File tree

crates/bevy_ecs/src/system/system_registry.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ use crate::world::{Mut, World};
1313
///
1414
/// Any [`Commands`](crate::system::Commands) generated by these systems (but not other systems), will immediately be applied.
1515
///
16-
/// This type is stored as a [`Resource`](crate::system::Resource) on each [`World`], initialized by default.
17-
/// However, it will likely be easier to use the corresponding methods on [`World`],
16+
/// This type is stored as a field on each [`World`].
17+
/// Geneerally speaking, you should use the corresponding methods on [`World`],
1818
/// to avoid having to worry about split mutable borrows yourself.
1919
///
2020
/// # Limitations
@@ -293,9 +293,7 @@ impl World {
293293
system: S,
294294
label: L,
295295
) {
296-
self.resource_scope(|world, mut registry: Mut<SystemRegistry>| {
297-
registry.register_system(world, system, label);
298-
});
296+
self.system_registry.register_system(self, system, label);
299297
}
300298

301299
pub fn register_system_with_labels<
@@ -308,9 +306,8 @@ impl World {
308306
system: S,
309307
labels: LI,
310308
) {
311-
self.resource_scope(|world, mut registry: Mut<SystemRegistry>| {
312-
registry.register_system_with_labels(world, system, labels);
313-
});
309+
self.system_registry
310+
.register_system_with_labels(self, system, labels);
314311
}
315312

316313
/// Runs the supplied system on the [`World`] a single time
@@ -325,9 +322,7 @@ impl World {
325322
/// at once, and want parallel execution of these systems.
326323
#[inline]
327324
pub fn run_system<Params, S: IntoSystem<(), (), Params> + 'static>(&mut self, system: S) {
328-
self.resource_scope(|world, mut registry: Mut<SystemRegistry>| {
329-
registry.run_system(world, system);
330-
});
325+
self.system_registry.run_system(self, system);
331326
}
332327

333328
/// Runs the system corresponding to the supplied [`SystemLabel`] on the [`World`] a single time
@@ -344,9 +339,7 @@ impl World {
344339
/// at once, and want parallel execution of these systems.
345340
#[inline]
346341
pub fn run_systems_by_label<L: SystemLabel>(&mut self, label: L) {
347-
self.resource_scope(|world, mut registry: Mut<SystemRegistry>| {
348-
registry.run_systems_by_label(world, label);
349-
});
342+
self.system_registry.run_systems_by_label(self, label);
350343
}
351344
}
352345

crates/bevy_ecs/src/world/mod.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -83,16 +83,20 @@ pub struct World {
8383
pub(crate) storages: Storages,
8484
pub(crate) bundles: Bundles,
8585
pub(crate) removed_components: SparseSet<ComponentId, Vec<Entity>>,
86-
/// Access cache used by [WorldCell].
86+
/// Access cache used by [`WorldCell`].
8787
pub(crate) archetype_component_access: ArchetypeComponentAccess,
8888
main_thread_validator: MainThreadValidator,
8989
pub(crate) change_tick: AtomicU32,
9090
pub(crate) last_change_tick: u32,
91+
/// Stores the systems associated with this [`World`],
92+
///
93+
/// These system can be manually run using [`World::run_system`].
94+
pub system_registry: SystemRegistry,
9195
}
9296

9397
impl Default for World {
9498
fn default() -> Self {
95-
let mut world = Self {
99+
World {
96100
id: WorldId::new().expect("More `bevy` `World`s have been created than is supported"),
97101
entities: Default::default(),
98102
components: Default::default(),
@@ -106,10 +110,8 @@ impl Default for World {
106110
// are detected on first system runs and for direct world queries.
107111
change_tick: AtomicU32::new(1),
108112
last_change_tick: 0,
109-
};
110-
// This resource is required by bevy_ecs itself, so cannot be included in a plugin
111-
world.init_resource::<SystemRegistry>();
112-
world
113+
system_registry: Default::default(),
114+
}
113115
}
114116
}
115117

0 commit comments

Comments
 (0)