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>
impl<const P: usize, const E: usize, S, A> SensorOccupancyTracker<P, E, S, A>
Sourcepub const fn new() -> SensorOccupancyTracker<P, E, S, A>
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.
Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
False after reported input loss, until reset or complete reconciliation.
Sourcepub fn pair_count(&self) -> usize
pub fn pair_count(&self) -> usize
Cached pairs, including inactive mappings awaiting their stop events.
Sourcepub fn active_pairs(&self, occupancy: Occupancy<S, A>) -> usize
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.
Sourcepub fn occupants(&self) -> impl Iterator<Item = Occupancy<S, A>>
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.
Sourcepub fn pending_events(&self) -> usize
pub fn pending_events(&self) -> usize
Undrained logical output count.
Sourcepub fn events(&self) -> impl ExactSizeIterator
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.
Sourcepub fn pop_event(&mut self) -> Option<OccupancyEvent<S, A>>
pub fn pop_event(&mut self) -> Option<OccupancyEvent<S, A>>
Acknowledge and return the oldest event, freeing one output slot.
Sourcepub fn clear_events(&mut self)
pub fn clear_events(&mut self)
Acknowledge all output without changing occupancy or completeness.
Sourcepub fn mark_incomplete(&mut self)
pub fn mark_incomplete(&mut self)
Report dropped/truncated/reordered input. Freeze future updates/removals without clearing mappings, emitting exits, or discarding accepted output.
Sourcepub fn reset(&mut self)
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).
Sourcepub fn consume(
&mut self,
event: ContactEvent,
resolve: impl FnOnce(ColliderHandle, ColliderHandle) -> StartResolution<S, A>,
) -> Result<PairUpdate, TriggerError>
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.
Sourcepub fn consume_batch(
&mut self,
events: &[ContactEvent],
completeness: InputCompleteness,
resolve: impl FnMut(ColliderHandle, ColliderHandle) -> StartResolution<S, A>,
) -> Result<usize, BatchError>
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.
Sourcepub fn remove_actor(&mut self, actor: A) -> Result<usize, TriggerError>
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.
Sourcepub fn remove_sensor(&mut self, sensor: S) -> Result<usize, TriggerError>
pub fn remove_sensor(&mut self, sensor: S) -> Result<usize, TriggerError>
Sensor equivalent of remove_actor; returns logical exits emitted.
Sourcepub fn reconcile(
&mut self,
pairs: &[ResolvedPair<S, A>],
completeness: InputCompleteness,
) -> Result<(), TriggerError>
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>
impl<const PAIRS: usize, const EVENTS: usize, S, A> Clone for SensorOccupancyTracker<PAIRS, EVENTS, S, A>
Source§fn clone(&self) -> SensorOccupancyTracker<PAIRS, EVENTS, S, A>
fn clone(&self) -> SensorOccupancyTracker<PAIRS, EVENTS, S, A>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more