pub struct Transition<S> { /* private fields */ }Expand description
Where a machine goes next, and how it gets there.
A state on its own reads as one that takes the default fade, so a
transition that states no knob is Some(State::Idle.into()).
Implementations§
Source§impl<S> Transition<S>
impl<S> Transition<S>
Sourcepub const DEFAULT_FADE: Duration
pub const DEFAULT_FADE: Duration
The fade a transition takes to blend out of the state it leaves when
no call sets one: 150 milliseconds.
Sourcepub fn fade(self, over: Duration) -> Self
pub fn fade(self, over: Duration) -> Self
Takes over to blend out of the state it leaves;
Transition::DEFAULT_FADE until set.
The state it leaves plays on under the fade, and a fade longer than what the state it enters plays holds that motion’s last key.
Examples found in repository?
368 fn next(&self, input: &ElfInput, at: Progress) -> Option<Transition<Self>> {
369 match (self, input) {
370 (Self::Death, _) => None,
371 (_, ElfInput { dying: true, .. }) => Some(Self::Death.fade(DEATH_FADE)),
372 (_, ElfInput { hit: true, .. }) if *self != Self::Hit => {
373 Some(Self::Hit.fade(HIT_ENTER_FADE))
374 }
375 (Self::Hit, _) if at.ended() => Some(ElfState::grounded(input).fade(HIT_EXIT_FADE)),
376 (Self::Attack, ElfInput { attack: true, .. }) if at.past(ATTACK_RELEASE) => Some(
377 Self::Attack
378 .restarted()
379 .entering_at(ATTACK_CHAIN_ENTRY)
380 .fade(ATTACK_CHAIN_FADE),
381 ),
382 (Self::Attack, _) if at.past(ATTACK_RELEASE) => {
383 Some(ElfState::grounded(input).fade(ATTACK_EXIT_FADE))
384 }
385 (Self::SitDown | Self::Sit | Self::StandUp, i) if i.speed > WALK_THRESHOLD => {
386 Some(Self::Locomotion.fade(STAND_EXIT_FADE))
387 }
388 (Self::SitDown | Self::Sit | Self::StandUp, ElfInput { attack: true, .. }) => {
389 Some(Self::Attack.fade(ATTACK_ENTER_FADE))
390 }
391 (Self::SitDown | Self::Sit | Self::StandUp, ElfInput { jump: true, .. }) => {
392 Some(Self::Jump.fade(JUMP_ENTER_FADE))
393 }
394 (Self::SitDown, _) if at.ended() => Some(Self::Sit.at_once()),
395 (Self::Sit, ElfInput { interact: true, .. }) => Some(Self::StandUp.fade(STAND_UP_FADE)),
396 (Self::StandUp, _) if at.ended() => Some(Self::Idle.fade(STAND_EXIT_FADE)),
397 (Self::Jump, ElfInput { landed: true, .. }) => {
398 Some(ElfState::grounded(input).fade(JUMP_EXIT_FADE))
399 }
400 (Self::Jump, _) if at.ended() => Some(ElfState::grounded(input).fade(JUMP_EXIT_FADE)),
401 (
402 Self::Idle | Self::Locomotion,
403 ElfInput {
404 interact: true,
405 near_seat: true,
406 ..
407 },
408 ) => Some(Self::SitDown.fade(SIT_DOWN_FADE)),
409 (Self::Idle | Self::Locomotion, ElfInput { attack: true, .. }) => {
410 Some(Self::Attack.fade(ATTACK_ENTER_FADE))
411 }
412 (Self::Idle | Self::Locomotion, ElfInput { jump: true, .. }) => {
413 Some(Self::Jump.fade(JUMP_ENTER_FADE))
414 }
415 (Self::Idle, ElfInput { dance: true, .. }) => Some(Self::Dance.fade(DANCE_FADE)),
416 (Self::Dance, i) if i.speed > WALK_THRESHOLD => {
417 Some(Self::Locomotion.fade(IDLE_LOCOMOTION_FADE))
418 }
419 (Self::Idle, i) if i.speed > WALK_THRESHOLD => {
420 Some(Self::Locomotion.fade(IDLE_LOCOMOTION_FADE))
421 }
422 (Self::Locomotion, i) if i.speed <= WALK_THRESHOLD => {
423 Some(Self::Idle.fade(IDLE_LOCOMOTION_FADE))
424 }
425 _ => None,
426 }
427 }Sourcepub fn at_once(self) -> Self
pub fn at_once(self) -> Self
Enters with no fade, which drops the state it leaves at the instant it enters.
Sourcepub fn entering_at(self, fraction: f32) -> Self
pub fn entering_at(self, fraction: f32) -> Self
Enters fraction of the way into what the state it enters plays, a
fraction held inside 0.0..=1.0; the start of it until set.
Required if you want to skip the first part of a clip a state enters part way through.
Examples found in repository?
368 fn next(&self, input: &ElfInput, at: Progress) -> Option<Transition<Self>> {
369 match (self, input) {
370 (Self::Death, _) => None,
371 (_, ElfInput { dying: true, .. }) => Some(Self::Death.fade(DEATH_FADE)),
372 (_, ElfInput { hit: true, .. }) if *self != Self::Hit => {
373 Some(Self::Hit.fade(HIT_ENTER_FADE))
374 }
375 (Self::Hit, _) if at.ended() => Some(ElfState::grounded(input).fade(HIT_EXIT_FADE)),
376 (Self::Attack, ElfInput { attack: true, .. }) if at.past(ATTACK_RELEASE) => Some(
377 Self::Attack
378 .restarted()
379 .entering_at(ATTACK_CHAIN_ENTRY)
380 .fade(ATTACK_CHAIN_FADE),
381 ),
382 (Self::Attack, _) if at.past(ATTACK_RELEASE) => {
383 Some(ElfState::grounded(input).fade(ATTACK_EXIT_FADE))
384 }
385 (Self::SitDown | Self::Sit | Self::StandUp, i) if i.speed > WALK_THRESHOLD => {
386 Some(Self::Locomotion.fade(STAND_EXIT_FADE))
387 }
388 (Self::SitDown | Self::Sit | Self::StandUp, ElfInput { attack: true, .. }) => {
389 Some(Self::Attack.fade(ATTACK_ENTER_FADE))
390 }
391 (Self::SitDown | Self::Sit | Self::StandUp, ElfInput { jump: true, .. }) => {
392 Some(Self::Jump.fade(JUMP_ENTER_FADE))
393 }
394 (Self::SitDown, _) if at.ended() => Some(Self::Sit.at_once()),
395 (Self::Sit, ElfInput { interact: true, .. }) => Some(Self::StandUp.fade(STAND_UP_FADE)),
396 (Self::StandUp, _) if at.ended() => Some(Self::Idle.fade(STAND_EXIT_FADE)),
397 (Self::Jump, ElfInput { landed: true, .. }) => {
398 Some(ElfState::grounded(input).fade(JUMP_EXIT_FADE))
399 }
400 (Self::Jump, _) if at.ended() => Some(ElfState::grounded(input).fade(JUMP_EXIT_FADE)),
401 (
402 Self::Idle | Self::Locomotion,
403 ElfInput {
404 interact: true,
405 near_seat: true,
406 ..
407 },
408 ) => Some(Self::SitDown.fade(SIT_DOWN_FADE)),
409 (Self::Idle | Self::Locomotion, ElfInput { attack: true, .. }) => {
410 Some(Self::Attack.fade(ATTACK_ENTER_FADE))
411 }
412 (Self::Idle | Self::Locomotion, ElfInput { jump: true, .. }) => {
413 Some(Self::Jump.fade(JUMP_ENTER_FADE))
414 }
415 (Self::Idle, ElfInput { dance: true, .. }) => Some(Self::Dance.fade(DANCE_FADE)),
416 (Self::Dance, i) if i.speed > WALK_THRESHOLD => {
417 Some(Self::Locomotion.fade(IDLE_LOCOMOTION_FADE))
418 }
419 (Self::Idle, i) if i.speed > WALK_THRESHOLD => {
420 Some(Self::Locomotion.fade(IDLE_LOCOMOTION_FADE))
421 }
422 (Self::Locomotion, i) if i.speed <= WALK_THRESHOLD => {
423 Some(Self::Idle.fade(IDLE_LOCOMOTION_FADE))
424 }
425 _ => None,
426 }
427 }Trait Implementations§
Source§impl<S: Clone> Clone for Transition<S>
impl<S: Clone> Clone for Transition<S>
Source§fn clone(&self) -> Transition<S>
fn clone(&self) -> Transition<S>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<S: Debug> Debug for Transition<S>
impl<S: Debug> Debug for Transition<S>
Source§impl<S> From<S> for Transition<S>
impl<S> From<S> for Transition<S>
Source§fn from(into: S) -> Self
fn from(into: S) -> Self
Into into over Transition::DEFAULT_FADE, from the start of
what it plays.
Auto Trait Implementations§
impl<S> Freeze for Transition<S>where
S: Freeze,
impl<S> RefUnwindSafe for Transition<S>where
S: RefUnwindSafe,
impl<S> Send for Transition<S>where
S: Send,
impl<S> Sync for Transition<S>where
S: Sync,
impl<S> Unpin for Transition<S>where
S: Unpin,
impl<S> UnsafeUnpin for Transition<S>where
S: UnsafeUnpin,
impl<S> UnwindSafe for Transition<S>where
S: UnwindSafe,
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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> DowncastSync for T
impl<T> DowncastSync for T
impl<S, T> Duplex<S> for Twhere
T: FromSample<S> + ToSample<S>,
Source§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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