Skip to main content

AnimationStates

Trait AnimationStates 

Source
pub trait AnimationStates:
    Copy
    + Eq
    + Debug
    + Sized {
    type Clip: Clip;
    type Input: Default;

    // Required methods
    fn entry() -> Self;
    fn motion(&self, input: &Self::Input) -> Motion<Self::Clip>;
    fn next(
        &self,
        input: &Self::Input,
        at: Progress,
    ) -> Option<Transition<Self>>;

    // Provided methods
    fn fade(self, over: Duration) -> Transition<Self> { ... }
    fn at_once(self) -> Transition<Self> { ... }
    fn entering_at(self, fraction: f32) -> Transition<Self> { ... }
    fn restarted(self) -> Transition<Self> { ... }
}
Expand description

The states a game poses one mesh through, and what each of them plays.

Required if you want a machine to pose a draw: write the states as a fieldless enum, state what each of them plays and where it goes from there, and keep an Animator of them beside every mesh the game poses.

Required Associated Types§

Source

type Clip: Clip

The clip vocabulary of the mesh these states pose.

Source

type Input: Default

What the states read to decide, the game’s own to write; a machine reads the default until animate first runs it.

Required Methods§

Source

fn entry() -> Self

The state a machine starts in.

Source

fn motion(&self, input: &Self::Input) -> Motion<Self::Clip>

What this state plays, read every tick.

Source

fn next(&self, input: &Self::Input, at: Progress) -> Option<Transition<Self>>

Where the machine goes from this state, read every tick; at is how far along what it plays is, and nothing at all keeps it where it is.

While a fade runs this is the state being faded into, so this state and nothing both leave that fade running, and any other interrupts it.

Provided Methods§

Source

fn fade(self, over: Duration) -> Transition<Self>

Into this state over over; see Transition::fade.

Examples found in repository?
examples/animation.rs (line 371)
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    }
Source

fn at_once(self) -> Transition<Self>

Into this state with no fade; see Transition::at_once.

Examples found in repository?
examples/animation.rs (line 394)
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    }
Source

fn entering_at(self, fraction: f32) -> Transition<Self>

Into this state, entering fraction of the way in; see Transition::entering_at.

Source

fn restarted(self) -> Transition<Self>

Into this state from the start of what it plays again; see Transition::restarted.

Examples found in repository?
examples/animation.rs (line 378)
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    }

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§