1234567891011121314151617181920212223242526272829303132333435363738 |
- // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
- // SPDX-License-Identifier: MIT
- #pragma once
- #include <Jolt/Physics/Collision/ContactListener.h>
- #include <Jolt/Physics/StateRecorder.h>
- #include <Jolt/Core/Mutex.h>
- #include <Jolt/Core/UnorderedMap.h>
- // Tests the contact listener callbacks
- class ContactListenerImpl : public ContactListener
- {
- public:
- // See: ContactListener
- virtual ValidateResult OnContactValidate(const Body &inBody1, const Body &inBody2, const CollideShapeResult &inCollisionResult) override;
- virtual void OnContactAdded(const Body &inBody1, const Body &inBody2, const ContactManifold &inManifold, ContactSettings &ioSettings) override;
- virtual void OnContactPersisted(const Body &inBody1, const Body &inBody2, const ContactManifold &inManifold, ContactSettings &ioSettings) override;
- virtual void OnContactRemoved(const SubShapeIDPair &inSubShapePair) override;
- // Saving / restoring state for replay
- void SaveState(StateRecorder &inStream) const;
- void RestoreState(StateRecorder &inStream);
- // Draw the current contact state
- void DrawState();
- // Ability to defer to the next contact listener after this one handles the callback
- void SetNextListener(ContactListener *inListener) { mNext = inListener; }
- private:
- // Map that keeps track of the current state of contacts based on the contact listener callbacks
- using StateMap = UnorderedMap<SubShapeIDPair, ContactPoints>;
- Mutex mStateMutex;
- StateMap mState;
- ContactListener * mNext = nullptr;
- };
|