Struct SensorOccupancyTracker

Source
pub struct SensorOccupancyTracker<const PAIRS: usize, const EVENTS: usize, S = ColliderHandle, A = RigidBodyHandle> { /* private fields */ }
Expand description

Inline pair mappings and a bounded FIFO of logical events. PAIRS counts cached physical pairs (including explicitly removed occupants awaiting stops). EVENTS counts undrained output. Zero capacities are supported. See the module recipe for the default generational-handle keys.

Implementations§

Source§

impl<const P: usize, const E: usize, S, A> SensorOccupancyTracker<P, E, S, A>
where S: Copy + Eq, A: Copy + Eq,

Source

pub const fn new() -> SensorOccupancyTracker<P, E, S, A>

Empty, authoritative baseline. Create before observing the world’s first step, or reconcile existing overlaps before consuming subsequent deltas.

Source

pub fn is_complete(&self) -> bool

False after reported input loss, until reset or complete reconciliation.

Source

pub fn pair_count(&self) -> usize

Cached pairs, including inactive mappings awaiting their stop events.

Source

pub fn active_pairs(&self, occupancy: Occupancy<S, A>) -> usize

Number of accepted active child pairs for this logical occupant. After input loss this is historical retained state, not authoritative occupancy.

Source

pub fn occupants(&self) -> impl Iterator<Item = Occupancy<S, A>>

Distinct active logical occupants in first retained slot order, without allocation. Historical only when is_complete() is false.

Source

pub fn pending_events(&self) -> usize

Undrained logical output count.

Source

pub fn events(&self) -> impl ExactSizeIterator

Borrow output as copied events in FIFO order. Reading does not acknowledge it; use pop_event() or clear_events() to free output capacity.

Source

pub fn pop_event(&mut self) -> Option<OccupancyEvent<S, A>>

Acknowledge and return the oldest event, freeing one output slot.

Source

pub fn clear_events(&mut self)

Acknowledge all output without changing occupancy or completeness.

Source

pub fn mark_incomplete(&mut self)

Report dropped/truncated/reordered input. Freeze future updates/removals without clearing mappings, emitting exits, or discarding accepted output.

Source

pub fn reset(&mut self)

Clear all state and queued output without emitting exits. Caller must establish a known empty baseline (for example, a scene restart).

Source

pub fn consume( &mut self, event: ContactEvent, resolve: impl FnOnce(ColliderHandle, ColliderHandle) -> StartResolution<S, A>, ) -> Result<PairUpdate, TriggerError>

Consume one actual world event. Resolve only unknown starts, using canonical collider order. Stops use cached keys, including after removal. One physical pair cannot change logical identity while retained. Errors leave the tracker unchanged; retry this event before later input or call mark_incomplete(). The callback may run before a capacity error.

Source

pub fn consume_batch( &mut self, events: &[ContactEvent], completeness: InputCompleteness, resolve: impl FnMut(ColliderHandle, ColliderHandle) -> StartResolution<S, A>, ) -> Result<usize, BatchError>

Consume a chronological batch, reporting its accepted prefix on error. Incomplete input freezes the tracker and consumes zero events, even when the supplied prefix looks usable. Complete empty batches do nothing.

Source

pub fn remove_actor(&mut self, actor: A) -> Result<usize, TriggerError>

Explicitly remove an actor’s currently active occupants, emitting one exit per sensor. Preflight all output capacity before mutation. Retain inactive mappings until stops, so duplicate starts cannot resurrect removed pairs. New pairs may enter again; this is not a permanent actor ban.

Source

pub fn remove_sensor(&mut self, sensor: S) -> Result<usize, TriggerError>

Sensor equivalent of remove_actor; returns logical exits emitted.

Source

pub fn reconcile( &mut self, pairs: &[ResolvedPair<S, A>], completeness: InputCompleteness, ) -> Result<(), TriggerError>

Atomically replace the baseline with a caller-asserted complete snapshot of relevant physical pairs. No collision detection is performed. Success clears pending output, restores completeness and emits no events: reconcile consumer state explicitly through occupants(). Reject incomplete, over-capacity, self-pair or duplicate-pair snapshots without changing anything, including output and the previous completeness flag.

use ferravex_physics::triggers::{
    BatchError, InputCompleteness, SensorOccupancyTracker, StartResolution,
    TriggerError,
};
// Game-owned keys are supported without a physics/frontend dependency.
let mut tracker = SensorOccupancyTracker::<8, 4, u16, u32>::new();
let result = tracker.consume_batch(&[], InputCompleteness::Incomplete,
    |_, _| StartResolution::Ignore);
assert_eq!(result, Err(BatchError {
    consumed: 0, error: TriggerError::IncompleteInput,
}));
assert!(!tracker.is_complete());
// This caller knows its relevant overlap set is empty. For a nonempty
// baseline, supply every relevant pair as a ResolvedPair instead.
tracker.reconcile(&[], InputCompleteness::Complete).unwrap();
assert!(tracker.is_complete());
assert_eq!(tracker.occupants().count(), 0);
assert_eq!(tracker.pending_events(), 0); // No synthetic recovery events.
tracker.reset(); // Appropriate for a known-empty scene restart, too.

Trait Implementations§

Source§

impl<const PAIRS: usize, const EVENTS: usize, S, A> Clone for SensorOccupancyTracker<PAIRS, EVENTS, S, A>
where S: Clone, A: Clone,

Source§

fn clone(&self) -> SensorOccupancyTracker<PAIRS, EVENTS, S, A>

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 PAIRS: usize, const EVENTS: usize, S, A> Debug for SensorOccupancyTracker<PAIRS, EVENTS, S, A>
where S: Debug, A: Debug,

Source§

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

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

impl<const P: usize, const E: usize, S, A> Default for SensorOccupancyTracker<P, E, S, A>
where S: Copy + Eq, A: Copy + Eq,

Source§

fn default() -> SensorOccupancyTracker<P, E, S, A>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<const PAIRS: usize, const EVENTS: usize, S, A> Freeze for SensorOccupancyTracker<PAIRS, EVENTS, S, A>
where S: Freeze, A: Freeze,

§

impl<const PAIRS: usize, const EVENTS: usize, S, A> RefUnwindSafe for SensorOccupancyTracker<PAIRS, EVENTS, S, A>

§

impl<const PAIRS: usize, const EVENTS: usize, S, A> Send for SensorOccupancyTracker<PAIRS, EVENTS, S, A>
where S: Send, A: Send,

§

impl<const PAIRS: usize, const EVENTS: usize, S, A> Sync for SensorOccupancyTracker<PAIRS, EVENTS, S, A>
where S: Sync, A: Sync,

§

impl<const PAIRS: usize, const EVENTS: usize, S, A> Unpin for SensorOccupancyTracker<PAIRS, EVENTS, S, A>
where S: Unpin, A: Unpin,

§

impl<const PAIRS: usize, const EVENTS: usize, S, A> UnwindSafe for SensorOccupancyTracker<PAIRS, EVENTS, S, A>
where S: UnwindSafe, A: UnwindSafe,

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.