pub struct AbilityBank<const N: usize> { /* private fields */ }Implementations§
Source§impl<const N: usize> AbilityBank<N>
impl<const N: usize> AbilityBank<N>
pub fn new( owner: u64, specs: &[AbilitySpec], ) -> Result<AbilityBank<N>, AbilityError>
pub fn advance(&mut self, dt: f32) -> Result<(), AbilityError>
pub fn charges(&self, id: usize) -> Option<u8>
pub fn remaining(&self, id: usize) -> Option<f32>
Sourcepub fn availability(
&self,
id: usize,
pool: &ResourcePool,
enabled: bool,
) -> Result<AbilityAvailability, AbilityError>
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);pub fn begin( &mut self, id: usize, pool: &mut ResourcePool, enabled: bool, ) -> Result<Reservation, AbilityError>
pub fn commit(&mut self, token: Reservation) -> Result<(), AbilityError>
Sourcepub fn cancel(
&mut self,
token: Reservation,
pool: &mut ResourcePool,
) -> Result<(), AbilityError>
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.