pub struct ProjectileBudget<const N: usize> { /* private fields */ }Expand description
Bounded, allocation-free policy for one projectile lifetime. See module recipe.
Implementations§
Source§impl<const N: usize> ProjectileBudget<N>
impl<const N: usize> ProjectileBudget<N>
Sourcepub fn new(pierces: u8, bounces: u8) -> Result<ProjectileBudget<N>, LoopError>
pub fn new(pierces: u8, bounces: u8) -> Result<ProjectileBudget<N>, LoopError>
Requires 1 <= N <= 256 and pierces < N. No change to authored defaults.
pub fn alive(&self) -> bool
Sourcepub fn state(&self) -> ProjectileState
pub fn state(&self) -> ProjectileState
Observe budgets without granting contacts or changing lifetime history.
Sourcepub fn has_hit(&self, id: u64) -> bool
pub fn has_hit(&self, id: u64) -> bool
Whether this exact host generation identity has been admitted, even if now inactive. This does not establish that the target is still valid.
Sourcepub fn target(&mut self, id: u64) -> HitResult
pub fn target(&mut self, id: u64) -> HitResult
Supply a unique generational target ID after confirmed collision. Legacy
result; use Self::target_report to distinguish admission/stop reasons.
Sourcepub fn target_report(&mut self, id: u64) -> TargetReport
pub fn target_report(&mut self, id: u64) -> TargetReport
Admit one caller-confirmed target with the legacy ordering and budgets. An inactive projectile wins over a duplicate ID. The final accepted hit stops travel without decrementing the already-zero pierce count. See the module recipe for geometry, damage and feedback composition.
Sourcepub fn wall(
&mut self,
velocity: Vec2,
normal: Vec2,
) -> Result<Option<Vec2>, LoopError>
pub fn wall( &mut self, velocity: Vec2, normal: Vec2, ) -> Result<Option<Vec2>, LoopError>
Separating contacts spend no bounce; invalid vectors leave state intact.
Sourcepub fn wall_report(
&mut self,
velocity: Vec2,
normal: Vec2,
) -> Result<WallReport, LoopError>
pub fn wall_report( &mut self, velocity: Vec2, normal: Vec2, ) -> Result<WallReport, LoopError>
Validate vectors, then admit a caller-confirmed wall contact. Velocity
must be finite with each component in [-1e6, 1e6]; normal must be finite
and nonzero. Normalization uses the existing Vec2::try_normalize, even
for huge finite or subnormal normals. Invalid input returns
LoopError::Invalid before any mutation, including when inactive.
There is no epsilon, restitution change, post-reflection speed clamp or
extra numerical rejection. dot >= 0 preserves the supplied velocity.
use ferravex_math::Vec2;
use ferravex_play::gameplay::{LoopError, projectile::{ProjectileBudget, WallOutcome}};
fn main() {
let mut budget = ProjectileBudget::<1>::new(0, 1).unwrap();
let tangent = budget.wall_report(Vec2::Y, Vec2::X).unwrap();
assert_eq!(tangent.outcome, WallOutcome::Tangent);
assert_eq!(tangent.state.remaining_bounces, 1);
let bounce = budget.wall_report(-Vec2::X, Vec2::X * f32::MAX).unwrap();
assert_eq!((bounce.outcome, bounce.velocity), (WallOutcome::Bounced, Some(Vec2::X)));
let stop = budget.wall_report(-Vec2::X, Vec2::X).unwrap();
assert_eq!(stop.outcome, WallOutcome::BounceExhausted);
assert!(!stop.state.alive);
assert_eq!(budget.wall_report(Vec2::X, Vec2::ZERO), Err(LoopError::Invalid));
}Trait Implementations§
Source§impl<const N: usize> Clone for ProjectileBudget<N>
impl<const N: usize> Clone for ProjectileBudget<N>
Source§fn clone(&self) -> ProjectileBudget<N>
fn clone(&self) -> ProjectileBudget<N>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more