Struct ProjectileBudget

Source
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>

Source

pub fn new(pierces: u8, bounces: u8) -> Result<ProjectileBudget<N>, LoopError>

Requires 1 <= N <= 256 and pierces < N. No change to authored defaults.

Source

pub fn alive(&self) -> bool

Source

pub fn state(&self) -> ProjectileState

Observe budgets without granting contacts or changing lifetime history.

Source

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.

Source

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.

Source

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.

Source

pub fn wall( &mut self, velocity: Vec2, normal: Vec2, ) -> Result<Option<Vec2>, LoopError>

Separating contacts spend no bounce; invalid vectors leave state intact.

Source

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>

Source§

fn clone(&self) -> ProjectileBudget<N>

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<const N: usize> Debug for ProjectileBudget<N>

Source§

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

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

impl<const N: usize> Copy for ProjectileBudget<N>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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