Skip to content

Commit

Permalink
Move SystemRegistry to a field on World
Browse files Browse the repository at this point in the history
  • Loading branch information
alice-i-cecile committed Apr 18, 2022
1 parent 870b12d commit ba66966
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 20 deletions.
21 changes: 7 additions & 14 deletions crates/bevy_ecs/src/system/system_registry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use crate::world::{Mut, World};
///
/// Any [`Commands`](crate::system::Commands) generated by these systems (but not other systems), will immediately be applied.
///
/// This type is stored as a [`Resource`](crate::system::Resource) on each [`World`], initialized by default.
/// However, it will likely be easier to use the corresponding methods on [`World`],
/// This type is stored as a field on each [`World`].
/// Geneerally speaking, you should use the corresponding methods on [`World`],
/// to avoid having to worry about split mutable borrows yourself.
///
/// # Limitations
Expand Down Expand Up @@ -293,9 +293,7 @@ impl World {
system: S,
label: L,
) {
self.resource_scope(|world, mut registry: Mut<SystemRegistry>| {
registry.register_system(world, system, label);
});
self.system_registry.register_system(self, system, label);
}

pub fn register_system_with_labels<
Expand All @@ -308,9 +306,8 @@ impl World {
system: S,
labels: LI,
) {
self.resource_scope(|world, mut registry: Mut<SystemRegistry>| {
registry.register_system_with_labels(world, system, labels);
});
self.system_registry
.register_system_with_labels(self, system, labels);
}

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

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

Expand Down
14 changes: 8 additions & 6 deletions crates/bevy_ecs/src/world/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,20 @@ pub struct World {
pub(crate) storages: Storages,
pub(crate) bundles: Bundles,
pub(crate) removed_components: SparseSet<ComponentId, Vec<Entity>>,
/// Access cache used by [WorldCell].
/// Access cache used by [`WorldCell`].
pub(crate) archetype_component_access: ArchetypeComponentAccess,
main_thread_validator: MainThreadValidator,
pub(crate) change_tick: AtomicU32,
pub(crate) last_change_tick: u32,
/// Stores the systems associated with this [`World`],
///
/// These system can be manually run using [`World::run_system`].
pub system_registry: SystemRegistry,
}

impl Default for World {
fn default() -> Self {
let mut world = Self {
World {
id: WorldId::new().expect("More `bevy` `World`s have been created than is supported"),
entities: Default::default(),
components: Default::default(),
Expand All @@ -106,10 +110,8 @@ impl Default for World {
// are detected on first system runs and for direct world queries.
change_tick: AtomicU32::new(1),
last_change_tick: 0,
};
// This resource is required by bevy_ecs itself, so cannot be included in a plugin
world.init_resource::<SystemRegistry>();
world
system_registry: Default::default(),
}
}
}

Expand Down

0 comments on commit ba66966

Please sign in to comment.