Struct Collider

Source
pub struct Collider<P: HbProfile> { /* private fields */ }
Expand description

A structure that tracks hitboxes and returns collide/separate events.

Collider manages events using a “simulation time” that the user updates as necessary. This time starts at 0.0.

Implementations§

Source§

impl<P: HbProfile> Collider<P>

Source

pub fn new() -> Collider<P>

Constructs a new Collider instance.

Source

pub fn time(&self) -> f64

Returns the current simulation time.

Source

pub fn next_time(&self) -> f64

Returns the time at which self.next() needs to be called again.

Even if self.next_time() == self.time(), there is a chance that calling self.next() will return None, having processed an internal event. Regardless, after self.next() has been called repeatedly until it returns None, then self.next_time() will be greater than self.time() again.

This is a fast constant-time operation. The result may be infinity.

Source

pub fn set_time(&mut self, time: f64)

Advances the simulation time to the given value.

The positions of all hitboxes will be updated based on the velocities of the hitboxes. Will panic if time exceeds self.next_time(). Will also panic if time is less than self.time() (i.e. cannot rewind time).

The hitboxes are updated implicitly, and this is actually a fast constant-time operation.

Source

pub fn next(&mut self) -> Option<(HbEvent, P, P)>

Processes and returns the next Collide or Separate event, or returns None if there are no more events that occured at the given time (although an internal event might have been processed if None is returned). Will always return None if self.next_time() > self.time().

The returned value is a tuple, denoting the type of event (Collide or Separate) and the two hitbox profiles involved, in increasing order by HbId.

Source

pub fn get_hitbox(&self, id: HbId) -> Hitbox

Returns the current state of the hitbox with the given id.

Source

pub fn add_hitbox(&mut self, profile: P, hitbox: Hitbox) -> Vec<P>

Adds a new hitbox to the collider.

The profile is used to track the hitbox over time; Collider will return this profile in certain methods, and the ID in this profile can be used to make updates to the hitbox. This method will panic if there is an ID clash. hitbox is the initial state of the hitbox.

Returns a vector of all hitbox profiles that this new hitbox collided with as it was added. Note that separate collision events will not be generated for these collisions.

Source

pub fn set_hitbox_vel(&mut self, id: HbId, vel: HbVel)

Updates the velocity information of the hitbox with the given id.

Source

pub fn remove_hitbox(&mut self, id: HbId) -> Vec<P>

Removes the hitbox with the given id from all tracking.

Returns a vector of all hitbox profiles that this hitbox separated from as it was removed. No further events will be generated for this hitbox.

Source

pub fn get_overlaps(&self, id: HbId) -> Vec<P>

Returns the profiles of all currently tracked overlaps on the hitbox with the given id.

Source

pub fn is_overlapping(&self, id_1: HbId, id_2: HbId) -> bool

Returns true if there is a currently tracked overlap between the hitboxes with id_1 and id_2.

Source

pub fn query_overlaps(&self, shape: &PlacedShape, profile: &P) -> Vec<P>

Returns the profiles of all hitboxes that overlap the given shape and interact with the given profile.

Auto Trait Implementations§

§

impl<P> Freeze for Collider<P>

§

impl<P> RefUnwindSafe for Collider<P>
where P: RefUnwindSafe,

§

impl<P> Send for Collider<P>
where P: Send,

§

impl<P> Sync for Collider<P>
where P: Sync,

§

impl<P> Unpin for Collider<P>
where P: Unpin,

§

impl<P> UnwindSafe for Collider<P>
where P: 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> 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, 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.