Engine²
Open-source game engine written in C++.
Loading...
Searching...
No Matches
ContactListenerImpl.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "core/Core.hpp"
4#include "entity/Entity.hpp"
5
6// clang-format off
7#include <Jolt/Jolt.h>
8// clang-format on
9
10#include <Jolt/Physics/Body/Body.h>
11#include <Jolt/Physics/Collision/ContactListener.h>
12#include <mutex>
13#include <vector>
14
16
17namespace Physics::Resource {
18class PhysicsManager;
19}
20
21namespace Physics::Utils {
22
36class ContactListenerImpl final : public JPH::ContactListener {
37 public:
39
40 explicit ContactListenerImpl(Engine::Core &core) : _core(core) {}
41 ~ContactListenerImpl() override = default;
42
43 JPH::ValidateResult OnContactValidate([[maybe_unused]] const JPH::Body &inBody1,
44 [[maybe_unused]] const JPH::Body &inBody2,
45 [[maybe_unused]] JPH::RVec3Arg inBaseOffset,
46 [[maybe_unused]] const JPH::CollideShapeResult &inCollisionResult) override
47 {
48 return JPH::ValidateResult::AcceptAllContactsForThisBodyPair;
49 }
50
70 void OnContactAdded(const JPH::Body &inBody1, const JPH::Body &inBody2, const JPH::ContactManifold &inManifold,
71 JPH::ContactSettings &ioSettings) override;
72
83 void OnContactPersisted(const JPH::Body &inBody1, const JPH::Body &inBody2, const JPH::ContactManifold &inManifold,
84 JPH::ContactSettings &ioSettings) override;
85
93 void OnContactRemoved(const JPH::SubShapeIDPair &inSubShapePair) override;
94
101
102 private:
104 std::mutex _bufferMutex;
105 std::vector<Physics::Event::CollisionAddedEvent> _bufferedAdded;
106 std::vector<Physics::Event::CollisionPersistedEvent> _bufferedPersisted;
107 std::vector<Physics::Event::CollisionRemovedEvent> _bufferedRemoved;
108};
109
110} // namespace Physics::Utils
The core is the place where all the data of the engine is stored. It contains the registry (entities)...
Definition Core.hpp:33
Definition PhysicsManager.hpp:25
void OnContactRemoved(const JPH::SubShapeIDPair &inSubShapePair) override
Called when two bodies cease to make contact.
Definition ContactListenerImpl.cpp:48
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.
Definition ContactListenerImpl.cpp:38
std::vector< Physics::Event::CollisionPersistedEvent > _bufferedPersisted
Definition ContactListenerImpl.hpp:106
JPH::ValidateResult OnContactValidate(const JPH::Body &inBody1, const JPH::Body &inBody2, JPH::RVec3Arg inBaseOffset, const JPH::CollideShapeResult &inCollisionResult) override
Definition ContactListenerImpl.hpp:43
void ProcessBufferedEvents(Engine::Core &core)
Flush buffered events to the main thread EventManager (should be called from main thread).
Definition ContactListenerImpl.cpp:68
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.
Definition ContactListenerImpl.cpp:28
Engine::Core & _core
Definition ContactListenerImpl.hpp:103
~ContactListenerImpl() override=default
std::vector< Physics::Event::CollisionAddedEvent > _bufferedAdded
Definition ContactListenerImpl.hpp:105
ContactListenerImpl(Engine::Core &core)
Definition ContactListenerImpl.hpp:40
std::vector< Physics::Event::CollisionRemovedEvent > _bufferedRemoved
Definition ContactListenerImpl.hpp:107
std::mutex _bufferMutex
Definition ContactListenerImpl.hpp:104
Definition BodyEntityMap.hpp:12
Definition BiMap.hpp:7