|
| | ContactListenerImpl ()=delete |
| | ContactListenerImpl (Engine::Core &core) |
| | ~ContactListenerImpl () override=default |
| JPH::ValidateResult | OnContactValidate (const JPH::Body &inBody1, const JPH::Body &inBody2, JPH::RVec3Arg inBaseOffset, const JPH::CollideShapeResult &inCollisionResult) override |
| void | OnContactAdded (const JPH::Body &inBody1, const JPH::Body &inBody2, const JPH::ContactManifold &inManifold, JPH::ContactSettings &ioSettings) override |
| | Called when two bodies start to make contact.
|
| void | OnContactPersisted (const JPH::Body &inBody1, const JPH::Body &inBody2, const JPH::ContactManifold &inManifold, JPH::ContactSettings &ioSettings) override |
| | Called when two bodies continue to make contact.
|
| void | OnContactRemoved (const JPH::SubShapeIDPair &inSubShapePair) override |
| | Called when two bodies cease to make contact.
|
| void | ProcessBufferedEvents (Engine::Core &core) |
| | Flush buffered events to the main thread EventManager (should be called from main thread).
|
ContactListener implementation.
This is used to define callbacks for contact events between bodies. Callbacks will be called with the Core, as well as the two entities that collided.
- Note
- Jolt will call these callbacks from physics worker threads. To avoid concurrent access to engine resources (like the entt registry) and the EventManager, events are buffered in worker threads and flushed to the main thread by calling ProcessBufferedEvents(core) from the main physics update system. Do NOT call EventManager::PushEvent() directly in these callbacks.
| void Physics::Utils::ContactListenerImpl::OnContactAdded |
( |
const JPH::Body & | inBody1, |
|
|
const JPH::Body & | inBody2, |
|
|
const JPH::ContactManifold & | inManifold, |
|
|
JPH::ContactSettings & | ioSettings ) |
|
override |
Called when two bodies start to make contact.
Right now we use 32 bits for entities IDs with EnTT but Jolt stores user data as 64 bits so we have to mask the upper 32 bits auto entity1 = static_cast<Engine::Entity>(inBody1.GetUserData() & ENTITY_ID_MASK); auto entity2 = static_cast<Engine::Entity>(inBody2.GetUserData() & ENTITY_ID_MASK);
Validate entity ids and buffer the event on a worker thread; it will be flushed on the main thread by the PhysicsUpdate system.
Buffer the event. Can't safely access the registry from a physics worker thread, so defer any entity validity checks until ProcessBufferedEvents (main thread).
- Parameters
-
| inBody1 | The first body involved in the contact. |
| inBody2 | The second body involved in the contact. |
| inManifold | The contact manifold containing contact points. |
| ioSettings | Contact settings that can be modified. |