Struct EncounterDirector

Source
pub struct EncounterDirector { /* private fields */ }

Implementations§

Source§

impl EncounterDirector

Source

pub fn new(config: EncounterConfig) -> Result<EncounterDirector, DirectorError>

Source

pub fn credits(&self) -> u32

Source

pub fn pacing(&self) -> Pacing

Source

pub fn advance(&mut self, dt: f32, pressure: f32) -> Result<(), DirectorError>

Pressure is a host-authored 0..1 measure of danger. Hysteresis prevents a constantly injured player from retriggering recovery every frame.

Source

pub fn preview(&self, cost: u32, alive: usize) -> AdmissionPreview

Inspect admission without spending credits, advancing timers or changing pressure hysteresis. Uses the same checks as Self::admit.

A blocked request reports the first reason in this order: zero cost, insufficient credits, alive limit, pacing. This ensures a pacing countdown is returned only when the cost and alive count already pass. The result describes this instant; it does not reserve a later spawn.

use ferravex_play::encounter::{AdmissionPreview, EncounterConfig, EncounterDirector};
let mut director = EncounterDirector::new(EncounterConfig {
    credits: 3, max_alive: 2, interval: 0.5,
    first_delay: 0.25, recovery_seconds: 1.0,
}).unwrap();
assert_eq!(director.preview(1, 0), AdmissionPreview::Pacing {
    cooldown: 0.25, recovery: 0.0,
});
assert_eq!(director.preview(1, 0).next_available_in(), Some(0.25));
director.advance(0.25, 0.0).unwrap();
assert!(director.preview(1, 0).is_ready());
assert_eq!(director.credits(), 3); // Previewing spends nothing.
assert!(director.admit(1, 0)); // Validate the spawn location first.
assert_eq!(director.credits(), 2);
assert_eq!(director.preview(1, 2), AdmissionPreview::AliveLimit {
    alive: 2, limit: 2,
});
Source

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

At most one admission per interval, no catch-up spawn bursts. Check the location first: successful admission spends credits exactly once. Self::preview provides the same decision and a reason without mutation.

Trait Implementations§

Source§

impl Clone for EncounterDirector

Source§

fn clone(&self) -> EncounterDirector

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 Debug for EncounterDirector

Source§

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

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

impl Copy for EncounterDirector

Auto Trait Implementations§

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.