pub struct SimpleScheduler { /* private fields */ }Expand description
Scheduler for the Soroban-first SimpleWorld runtime.
Systems can be grouped into stages and ordered relative to each other using
SystemConfig::before() and SystemConfig::after(). Each system receives
a deferred CommandQueue through SystemContext; queued commands are
applied after the system finishes.
§Example
use cougr_core::scheduler::{ScheduleStage, SimpleScheduler, SystemConfig};
use cougr_core::simple_world::SimpleWorld;
use soroban_sdk::{symbol_short, Bytes, Env};
fn physics_system(world: &mut SimpleWorld, env: &Env) {
let entity = world.spawn_entity();
world.add_component(entity, symbol_short!("physics"), Bytes::new(env));
}
fn scoring_system(world: &mut SimpleWorld, env: &Env) {
let entity = world.spawn_entity();
world.add_component(entity, symbol_short!("scoring"), Bytes::new(env));
}
let env = Env::default();
let mut world = SimpleWorld::new(&env);
let mut scheduler = SimpleScheduler::new();
scheduler.add_system("physics", physics_system);
scheduler.add_system_with_config(
"scoring",
scoring_system,
SystemConfig::new()
.in_stage(ScheduleStage::Update)
.after("physics"),
);
scheduler.run_all(&mut world, &env).unwrap();
assert_eq!(scheduler.system_count(), 2);Implementations§
Source§impl SimpleScheduler
impl SimpleScheduler
pub fn new() -> Self
Sourcepub fn add_system<F>(&mut self, name: &'static str, system: F)
pub fn add_system<F>(&mut self, name: &'static str, system: F)
Add a world/env system to the Update stage.
Sourcepub fn add_system_with_config<F>(
&mut self,
name: &'static str,
system: F,
config: SystemConfig,
)
pub fn add_system_with_config<F>( &mut self, name: &'static str, system: F, config: SystemConfig, )
Add a world/env system with explicit scheduling rules.
Sourcepub fn add_system_in_stage<F>(
&mut self,
stage: ScheduleStage,
name: &'static str,
system: F,
)
pub fn add_system_in_stage<F>( &mut self, stage: ScheduleStage, name: &'static str, system: F, )
Add a world/env system directly to a specific stage.
Sourcepub fn add_context_system<F>(&mut self, name: &'static str, system: F)where
F: for<'w, 'e, 'c> FnMut(&mut SystemContext<'w, 'e, 'c>) + 'static,
pub fn add_context_system<F>(&mut self, name: &'static str, system: F)where
F: for<'w, 'e, 'c> FnMut(&mut SystemContext<'w, 'e, 'c>) + 'static,
Add a context-aware system to the Update stage.
Sourcepub fn add_context_system_with_config<F>(
&mut self,
name: &'static str,
system: F,
config: SystemConfig,
)where
F: for<'w, 'e, 'c> FnMut(&mut SystemContext<'w, 'e, 'c>) + 'static,
pub fn add_context_system_with_config<F>(
&mut self,
name: &'static str,
system: F,
config: SystemConfig,
)where
F: for<'w, 'e, 'c> FnMut(&mut SystemContext<'w, 'e, 'c>) + 'static,
Add a context-aware system with explicit scheduling rules.
Sourcepub fn add_context_system_in_stage<F>(
&mut self,
stage: ScheduleStage,
name: &'static str,
system: F,
)where
F: for<'w, 'e, 'c> FnMut(&mut SystemContext<'w, 'e, 'c>) + 'static,
pub fn add_context_system_in_stage<F>(
&mut self,
stage: ScheduleStage,
name: &'static str,
system: F,
)where
F: for<'w, 'e, 'c> FnMut(&mut SystemContext<'w, 'e, 'c>) + 'static,
Add a context-aware system directly to a specific stage.
Sourcepub fn add_simple_system<S>(&mut self, name: &'static str, system: S)where
S: AppSystem + 'static,
pub fn add_simple_system<S>(&mut self, name: &'static str, system: S)where
S: AppSystem + 'static,
Add any pre-built runtime system to the default Update stage.
Sourcepub fn add_simple_system_with_config<S>(
&mut self,
name: &'static str,
system: S,
config: SystemConfig,
)where
S: AppSystem + 'static,
pub fn add_simple_system_with_config<S>(
&mut self,
name: &'static str,
system: S,
config: SystemConfig,
)where
S: AppSystem + 'static,
Add any pre-built runtime system with explicit scheduling rules.
Sourcepub fn add_simple_system_in_stage<S>(
&mut self,
stage: ScheduleStage,
name: &'static str,
system: S,
)where
S: AppSystem + 'static,
pub fn add_simple_system_in_stage<S>(
&mut self,
stage: ScheduleStage,
name: &'static str,
system: S,
)where
S: AppSystem + 'static,
Add any pre-built runtime system directly to a specific stage.
Sourcepub fn add_system_spec<S>(&mut self, spec: SystemSpec<S>)where
S: AppSystem + 'static,
pub fn add_system_spec<S>(&mut self, spec: SystemSpec<S>)where
S: AppSystem + 'static,
Add a declarative runtime system spec.
Sourcepub fn add_systems<G>(&mut self, group: G)where
G: SystemGroup,
pub fn add_systems<G>(&mut self, group: G)where
G: SystemGroup,
Add one or more runtime systems using the modern declarative API.
Sourcepub fn add_systems_in_stage<G>(&mut self, stage: ScheduleStage, group: G)where
G: SystemGroup,
pub fn add_systems_in_stage<G>(&mut self, stage: ScheduleStage, group: G)where
G: SystemGroup,
Add one or more runtime systems while forcing them into a stage.
Sourcepub fn configure_system(
&mut self,
name: &str,
config: SystemConfig,
) -> Result<(), ScheduleError>
pub fn configure_system( &mut self, name: &str, config: SystemConfig, ) -> Result<(), ScheduleError>
Update the scheduling config for an already-registered system.
Sourcepub fn run_all(
&mut self,
world: &mut SimpleWorld,
env: &Env,
) -> Result<(), ScheduleError>
pub fn run_all( &mut self, world: &mut SimpleWorld, env: &Env, ) -> Result<(), ScheduleError>
Validate and execute the full schedule.
Sourcepub fn run_stage(
&mut self,
stage: ScheduleStage,
world: &mut SimpleWorld,
env: &Env,
) -> Result<(), ScheduleError>
pub fn run_stage( &mut self, stage: ScheduleStage, world: &mut SimpleWorld, env: &Env, ) -> Result<(), ScheduleError>
Validate and execute only a single stage.
Sourcepub fn system_count(&self) -> usize
pub fn system_count(&self) -> usize
Returns the number of registered systems.
Sourcepub fn system_names(&self) -> Vec<&str>
pub fn system_names(&self) -> Vec<&str>
Returns the system names in registration order.
Sourcepub fn stage_system_names(
&self,
stage: ScheduleStage,
) -> Result<Vec<&str>, ScheduleError>
pub fn stage_system_names( &self, stage: ScheduleStage, ) -> Result<Vec<&str>, ScheduleError>
Returns the system names assigned to a given stage in execution order.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for SimpleScheduler
impl !RefUnwindSafe for SimpleScheduler
impl !Send for SimpleScheduler
impl !Sync for SimpleScheduler
impl Unpin for SimpleScheduler
impl UnsafeUnpin for SimpleScheduler
impl !UnwindSafe for SimpleScheduler
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T, U, V, W, E, C> Compare<(T, U, V, W)> for C
impl<T, U, V, W, E, C> Compare<(T, U, V, W)> for C
type Error = E
fn compare( &self, a: &(T, U, V, W), b: &(T, U, V, W), ) -> Result<Ordering, <C as Compare<(T, U, V, W)>>::Error>
Source§impl<T, U, V, W, X, E, C> Compare<(T, U, V, W, X)> for C
impl<T, U, V, W, X, E, C> Compare<(T, U, V, W, X)> for C
type Error = E
fn compare( &self, a: &(T, U, V, W, X), b: &(T, U, V, W, X), ) -> Result<Ordering, <C as Compare<(T, U, V, W, X)>>::Error>
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more