pub struct StateMachine<Context> {
pub bb: Blackboard,
pub active: bool,
/* private fields */
}Expand description
A generic Finite State Machine.
Fields§
§bb: Blackboard§active: boolImplementations§
Source§impl<Context> StateMachine<Context>
impl<Context> StateMachine<Context>
pub fn new() -> Self
Sourcepub fn add_state(&mut self, state: Box<dyn FsmState<Context>>) -> usize
pub fn add_state(&mut self, state: Box<dyn FsmState<Context>>) -> usize
Add a state. First added = index 0.
Sourcepub fn start(&mut self, ctx: &mut Context, idx: usize)
pub fn start(&mut self, ctx: &mut Context, idx: usize)
Start the FSM in state idx.
Sourcepub fn tick(&mut self, ctx: &mut Context, dt: f32)
pub fn tick(&mut self, ctx: &mut Context, dt: f32)
Tick the current state. Handles transitions automatically.
pub fn current_state_name(&self) -> &str
pub fn current_index(&self) -> usize
Trait Implementations§
Auto Trait Implementations§
impl<Context> Freeze for StateMachine<Context>
impl<Context> !RefUnwindSafe for StateMachine<Context>
impl<Context> Send for StateMachine<Context>
impl<Context> Sync for StateMachine<Context>
impl<Context> Unpin for StateMachine<Context>
impl<Context> UnsafeUnpin for StateMachine<Context>
impl<Context> !UnwindSafe for StateMachine<Context>
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
Mutably borrows from an owned value. Read more
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>
Convert
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>
Convert
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)
Convert
&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)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.