Struct ScoreChain

Source
pub struct ScoreChain { /* private fields */ }
Expand description

Allocation-free scoring with an authored simulation-time chain window. Expiry occurs on advancement at the inclusive remaining <= 1e-9 boundary, including a zero-delta advance. A newly awarded sub-epsilon window remains active until advancement. See the module example for receipts and resets.

Implementations§

Source§

impl ScoreChain

Source

pub fn new( window: f32, per_tier: u32, maximum: u32, ) -> Result<ScoreChain, LoopError>

Source

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

Source

pub fn advance_with_outcome( &mut self, dt: f32, ) -> Result<ChainAdvance, LoopError>

Advance once per executed simulation tick, reporting expiry once.

Invalid dt (non-finite, negative, or above 3600 seconds) returns LoopError::Invalid with every field unchanged, even if idle. Total and best survive expiry. See the module example.

Source

pub fn award(&mut self, base: u32) -> u64

Legacy saturating award, returning nominal points even at total saturation. Zero is a no-op. Use Self::award_with_receipt for actual total changes.

Source

pub fn preview_award(&self, base: u32) -> Option<ScoreAward>

Forecast the legacy saturating policy without mutating or refreshing time.

Zero returns None without changes. Tier is one-based and uncapped; multiplier is capped. Overflow flags describe lost increments, rather than a counter merely reaching its maximum. See the module example.

Source

pub fn award_with_receipt(&mut self, base: u32) -> Option<ScoreAward>

Accept with explicit saturation, sharing the exact policy of Self::award.

A nonzero base always increments/saturates the chain, updates best and refreshes the window, even if total cannot increase. Receipt flags expose each overflow independently. Zero returns None and changes nothing. Emit feedback only from this accepted result, never from a preview. See the module example; total changes concern this helper only, not any separate narrower counter maintained by a consumer.

Source

pub fn try_award( &mut self, base: u32, ) -> Result<Option<ScoreAward>, ScoreOverflow>

Accept only if both chain increment and nominal total addition fit.

Either overflow returns ScoreOverflow before any mutation. Zero returns Ok(None) even at counter bounds. Successful receipts have both saturation flags false. Games that already committed an action and require legacy saturation should use Self::award_with_receipt instead; rejection here does not roll back another system’s accepted action. See the module example for usage.

Source

pub fn multiplier(&self) -> u32

Source

pub fn chain(&self) -> u32

Source

pub fn best(&self) -> u32

Source

pub fn total(&self) -> u64

Source

pub fn remaining_life(&self) -> Option<f64>

Remaining simulation seconds for an active chain, at internal precision. Never advances or expires the chain, even at/below epsilon. None means no active chain. See the module example.

Source

pub fn reset(&mut self, mode: ChainReset)

Apply the explicit clearing/retention policy, retaining authoring settings. See ChainReset and the module example for each mode’s fields.

Source

pub fn break_chain(&mut self)

Legacy break: clear chain and remaining time, retain total, best and settings.

Trait Implementations§

Source§

impl Clone for ScoreChain

Source§

fn clone(&self) -> ScoreChain

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 ScoreChain

Source§

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

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

impl Copy for ScoreChain

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.