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>
impl<P: HbProfile> Collider<P>
Sourcepub fn next_time(&self) -> f64
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.
Sourcepub fn set_time(&mut self, time: f64)
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.
Sourcepub fn next(&mut self) -> Option<(HbEvent, P, P)>
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
.
Sourcepub fn get_hitbox(&self, id: HbId) -> Hitbox
pub fn get_hitbox(&self, id: HbId) -> Hitbox
Returns the current state of the hitbox with the given id
.
Sourcepub fn add_hitbox(&mut self, profile: P, hitbox: Hitbox) -> Vec<P>
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.
Sourcepub fn set_hitbox_vel(&mut self, id: HbId, vel: HbVel)
pub fn set_hitbox_vel(&mut self, id: HbId, vel: HbVel)
Updates the velocity information of the hitbox with the given id
.
Sourcepub fn remove_hitbox(&mut self, id: HbId) -> Vec<P>
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.
Sourcepub fn get_overlaps(&self, id: HbId) -> Vec<P>
pub fn get_overlaps(&self, id: HbId) -> Vec<P>
Returns the profiles of all currently tracked overlaps on the hitbox with the given id
.
Sourcepub fn is_overlapping(&self, id_1: HbId, id_2: HbId) -> bool
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
.
Sourcepub fn query_overlaps(&self, shape: &PlacedShape, profile: &P) -> Vec<P>
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
.