pub trait CharacterContactListener:
Send
+ Sync
+ 'static {
// Provided methods
fn adjust_body_velocity(
&self,
character: CharacterId,
body: BodyId,
user_data: u64,
velocity: &mut BodyVelocity,
) { ... }
fn contact_validate(
&self,
character: CharacterId,
contact: &CharacterContact,
) -> bool { ... }
fn contact_added(
&self,
character: CharacterId,
contact: &CharacterContact,
settings: &mut CharacterContactSettings,
) { ... }
fn contact_persisted(
&self,
character: CharacterId,
contact: &CharacterContact,
settings: &mut CharacterContactSettings,
) { ... }
fn contact_removed(
&self,
character: CharacterId,
contact: CharacterContactKey,
) { ... }
}Expand description
Changes how characters touch bodies and each other (Jolt CharacterContactListener); see
PhysicsWorld::set_character_contact_listener.
Jolt calls the methods on the thread that calls
update_character or
refresh_character_contacts, during that call,
for the character it updates. A method must not touch the world; one that locks a value which
also guards the world can deadlock. For a replayable run its decisions must depend only on its
arguments and on data fixed for the update.
adjust_body_velocity and
contact_validate may be called any number of times per update, in
no fixed order, also for hits Jolt then does not use. Added, persisted and removed contacts
follow the character’s contacts: one update or refresh (stick to floor and walk stairs
included) reports each contact at most once, as added when it is new and as persisted when the
character touched it at the end of its previous update or refresh, also when no listener was
set then. Removals arrive after the update, sorted by CharacterContactKey.
A panic in a method that Jolt calls is caught; Jolt then keeps its own value for that call,
the methods of the rest of that update are skipped (as are the query filter’s, which reject),
and the update resumes the panic after Jolt returned. Removals of that update are not
delivered. contact_removed runs after Jolt returned and is not
caught: its panic leaves the update at once, the removals sorted before it have been
delivered and the rest of that update’s removals are lost. An update that panicked is outside
the replay guarantee.
Provided Methods§
Sourcefn adjust_body_velocity(
&self,
character: CharacterId,
body: BodyId,
user_data: u64,
velocity: &mut BodyVelocity,
)
fn adjust_body_velocity( &self, character: CharacterId, body: BodyId, user_data: u64, velocity: &mut BodyVelocity, )
The velocity of body as character sees it: what the character stands on moves it
along (moving platforms, conveyors). Jolt passes the body’s own velocity, zero for a static
body; user_data is the body’s
BodySettings::user_data. Called while Jolt holds the
body’s read lock.
Sourcefn contact_validate(
&self,
character: CharacterId,
contact: &CharacterContact,
) -> bool
fn contact_validate( &self, character: CharacterId, contact: &CharacterContact, ) -> bool
Whether character may collide with the body or character of contact. The default
accepts every contact, as Jolt does without a listener.
Sourcefn contact_added(
&self,
character: CharacterId,
contact: &CharacterContact,
settings: &mut CharacterContactSettings,
)
fn contact_added( &self, character: CharacterId, contact: &CharacterContact, settings: &mut CharacterContactSettings, )
character touches the body or character of contact for the first time; settings
may be changed for it.
Sourcefn contact_persisted(
&self,
character: CharacterId,
contact: &CharacterContact,
settings: &mut CharacterContactSettings,
)
fn contact_persisted( &self, character: CharacterId, contact: &CharacterContact, settings: &mut CharacterContactSettings, )
character still touches the body or character of contact; settings may be changed
for this update.
Sourcefn contact_removed(&self, character: CharacterId, contact: CharacterContactKey)
fn contact_removed(&self, character: CharacterId, contact: CharacterContactKey)
character no longer touches what contact names. Called after the update or refresh
returned; the body or character may no longer exist.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".