Struct AbilityBank

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

Implementations§

Source§

impl<const N: usize> AbilityBank<N>

Source

pub fn new( owner: u64, specs: &[AbilitySpec], ) -> Result<AbilityBank<N>, AbilityError>

Source

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

Source

pub fn charges(&self, id: usize) -> Option<u8>

Source

pub fn remaining(&self, id: usize) -> Option<f32>

Source

pub fn availability( &self, id: usize, pool: &ResourcePool, enabled: bool, ) -> Result<AbilityAvailability, AbilityError>

Inspect whether a new reservation or immediate activation can succeed.

Reads only immutable references and allocates no storage. Charges and pool value already exclude anything spent by pending reservations. Recharge is driven only by Self::advance, not by previews or presentation time.

A valid slot returns a snapshot even when blocked. An unknown slot returns AbilityError::Invalid when enabled, or AbilityError::Blocked when disabled, preserving Self::begin’s host-condition-first error order. For unchanged inputs, availability(...).and_then(|a| a.check()) matches both begin(...).map(|_| ()) and Self::activate.

use ferravex_play::ability::{AbilityBank, AbilityBlocker, AbilitySpec, ResourcePool};
let mut bank = AbilityBank::<1>::new(1, &[AbilitySpec {
    charges: 2, recharge_seconds: 0.5, cost: 3.0,
}]).unwrap();
let mut pool = ResourcePool::new(6.0, 6.0, 0.0).unwrap();
let hud = bank.availability(0, &pool, true).unwrap();
assert_eq!((hud.charges, hud.max_charges), (2, 2));
assert_eq!((hud.resource_cost, hud.resource_available), (3.0, 6.0));
assert_eq!(hud.blocker, None);
assert!(!hud.reserved);
assert_eq!(pool.value(), 6.0);

let token = bank.begin(0, &mut pool, true).unwrap();
let busy = bank.availability(0, &pool, true).unwrap();
assert_eq!(busy.blocker, Some(AbilityBlocker::Busy));
assert_eq!((busy.charges, busy.resource_available), (1, 3.0));
bank.cancel(token, &mut pool).unwrap();
assert_eq!(bank.availability(0, &pool, true).unwrap(), hud);
Source

pub fn begin( &mut self, id: usize, pool: &mut ResourcePool, enabled: bool, ) -> Result<Reservation, AbilityError>

Source

pub fn commit(&mut self, token: Reservation) -> Result<(), AbilityError>

Source

pub fn cancel( &mut self, token: Reservation, pool: &mut ResourcePool, ) -> Result<(), AbilityError>

Refund only to the same resource pool used by begin. The host owns the pool; do not move reservations across actors, lives, banks or resource accounts.

Source

pub fn activate( &mut self, id: usize, pool: &mut ResourcePool, enabled: bool, ) -> Result<(), AbilityError>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<const N: usize> UnwindSafe for AbilityBank<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> 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, 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.