Skip to content

Commit

Permalink
feat: add helper for initializing system parameters. (#204)
Browse files Browse the repository at this point in the history
  • Loading branch information
zicklag committed Sep 26, 2023
1 parent 0117f96 commit b64eb2c
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions framework_crates/bones_ecs/src/world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ impl World {
///
/// If all the system parameters have already been initialized, by calling
/// [`initialize()`][System::initialize] on the system, then this will work fine.
///
/// You can also use [`world.init_param()`][Self::init_param] to manually initialize specific
/// parameters if you know which ones will need to be initialized.
pub fn run_initialized_system<'system, Args, In, Out, S>(&self, system: S, input: In) -> Out
where
In: 'system,
Expand All @@ -114,6 +117,16 @@ impl World {
self.resource_mut()
}

/// Initialize a system parameter.
///
/// It is not necessary to do this manually unless you are going to run a system using
/// [`world.run_initialized_system()`][Self::run_initialized_system()] and you need to make sure
/// one of it's parameters are pre-initialized.
pub fn init_param<P: SystemParam>(&mut self) -> &mut Self {
P::initialize(self);
self
}

/// Insert a resource.
pub fn insert_resource<R: HasSchema>(&mut self, resource: R) -> Option<AtomicResource<R>> {
self.resources.insert(resource)
Expand Down

0 comments on commit b64eb2c

Please sign in to comment.