Struct WaveSequence

Source
pub struct WaveSequence<const N: usize> { /* private fields */ }

Implementations§

Source§

impl<const N: usize> WaveSequence<N>

Source

pub fn new( specs: [WaveSpec; N], max_alive: u16, ) -> Result<WaveSequence<N>, LoopError>

Source

pub fn index(&self) -> usize

Source

pub fn finished(&self) -> bool

Source

pub fn resting(&self) -> bool

Source

pub fn preview(&self, cost: u32, alive: usize) -> Result<WavePreview, LoopError>

Inspect upcoming authoring, spawn budget and countdowns without changing timers, pressure hysteresis, credits or clear-event delivery.

cost == 0 returns LoopError::Invalid in every phase. For other costs, an active wave delegates admission checks to EncounterDirector::preview. Exhausted credits await a clear event, even if alive == 0; rest and finished phases cannot admit spawns.

Countdown values describe simulation time at this instant, not wall time or a guarantee of later admission. Continue to call Self::advance on authoritative fixed ticks (at most 0.25 seconds per call), including while displaying a local preview menu. A preview never consumes a tick.

use ferravex_play::encounter::AdmissionPreview;
use ferravex_play::gameplay::waves::{WaveSequence, WaveSpec, WaveStatus};
let spec = WaveSpec { credits: 2, interval: 0.125, rest: 0.25, reward: 5 };
let mut waves = WaveSequence::new([spec; 2], 2).unwrap();
let preview = waves.preview(1, 0).unwrap();
assert_eq!(preview.index, 0);
assert_eq!(preview.spec, spec);
assert_eq!(preview.upcoming, Some(spec));
assert_eq!(preview.remaining_credits, 2);
assert_eq!(preview.remaining_spawns, 2);
assert_eq!(preview.status, WaveStatus::Active(AdmissionPreview::Ready));
assert!(waves.admit(2, 0)); // Only accepted admissions spend credits.
assert_eq!(waves.preview(1, 1).unwrap().status,
    WaveStatus::AwaitingClear { alive: 1 });
assert_eq!(waves.advance(0.125, 0.0, 0).unwrap().unwrap().reward, 5);
assert_eq!(waves.preview(1, 0).unwrap().status,
    WaveStatus::Resting { remaining: 0.25 });
waves.advance(0.25, 0.0, 0).unwrap();
assert_eq!(waves.preview(1, 0).unwrap().upcoming, None);
Source

pub fn reset(&mut self) -> Result<(), LoopError>

Restart at wave zero with the same validated specifications and alive cap. Restores the credit budget and clears cooldown, pressure recovery and its hysteresis, rest and completion state. Does not emit a clear event or reward.

The host must reset actors, earned rewards and other run state separately. Subsequent clears can award rewards again for the new run. Reconstructs the first director before mutation, propagating any validation error without changing the sequence. No allocation or catch-up is performed.

use ferravex_play::encounter::AdmissionPreview;
use ferravex_play::gameplay::waves::{WaveSequence, WaveSpec, WaveStatus};
let spec = WaveSpec { credits: 1, interval: 0.125, rest: 0.0, reward: 5 };
let mut waves = WaveSequence::new([spec], 1).unwrap();
assert!(waves.admit(1, 0));
assert!(waves.advance(0.0, 0.0, 0).unwrap().is_some());
assert!(waves.finished());
waves.reset().unwrap();
assert!(!waves.finished());
assert_eq!(waves.preview(1, 0).unwrap().status,
    WaveStatus::Active(AdmissionPreview::Ready));
assert_eq!(waves.advance(0.0, 0.0, 0).unwrap(), None);
assert!(waves.admit(1, 0));
Source

pub fn admit(&mut self, cost: u32, alive: usize) -> bool

Source

pub fn advance( &mut self, dt: f32, pressure: f32, alive: usize, ) -> Result<Option<WaveCleared>, LoopError>

Reports each cleared wave exactly once, after admitted actors are gone. Rest begins on the following update; a frame never skips an authored wave.

Trait Implementations§

Source§

impl<const N: usize> Clone for WaveSequence<N>

Source§

fn clone(&self) -> WaveSequence<N>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const N: usize> Debug for WaveSequence<N>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<const N: usize> Copy for WaveSequence<N>

Auto Trait Implementations§

§

impl<const N: usize> Freeze for WaveSequence<N>

§

impl<const N: usize> RefUnwindSafe for WaveSequence<N>

§

impl<const N: usize> Send for WaveSequence<N>

§

impl<const N: usize> Sync for WaveSequence<N>

§

impl<const N: usize> Unpin for WaveSequence<N>

§

impl<const N: usize> UnwindSafe for WaveSequence<N>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.