Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
BroadPhase.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
9
11
12// Shorthand function to ifdef out code if broadphase stats tracking is off
13#ifdef JPH_TRACK_BROADPHASE_STATS
14 #define JPH_IF_TRACK_BROADPHASE_STATS(...) __VA_ARGS__
15#else
16 #define JPH_IF_TRACK_BROADPHASE_STATS(...)
17#endif // JPH_TRACK_BROADPHASE_STATS
18
19class BodyManager;
20struct BodyPair;
21
23
26{
27public:
32 virtual void Init(BodyManager *inBodyManager, const BroadPhaseLayerInterface &inLayerInterface);
33
35 virtual void Optimize() { /* Optionally overridden by implementation */ }
36
38 virtual void FrameSync() { /* Optionally overridden by implementation */ }
39
41 virtual void LockModifications() { /* Optionally overridden by implementation */ }
42
44 struct UpdateState { void *mData[4]; };
45
48 virtual UpdateState UpdatePrepare() { return UpdateState(); }
49
51 virtual void UpdateFinalize([[maybe_unused]] const UpdateState &inUpdateState) { /* Optionally overridden by implementation */ }
52
54 virtual void UnlockModifications() { /* Optionally overridden by implementation */ }
55
57 using AddState = void *;
58
62 virtual AddState AddBodiesPrepare([[maybe_unused]] BodyID *ioBodies, [[maybe_unused]] int inNumber) { return nullptr; } // By default the broadphase doesn't support this
63
66 virtual void AddBodiesFinalize(BodyID *ioBodies, int inNumber, AddState inAddState) = 0;
67
71 virtual void AddBodiesAbort([[maybe_unused]] BodyID *ioBodies, [[maybe_unused]] int inNumber, [[maybe_unused]] AddState inAddState) { /* By default nothing needs to be done */ }
72
75 virtual void RemoveBodies(BodyID *ioBodies, int inNumber) = 0;
76
79 virtual void NotifyBodiesAABBChanged(BodyID *ioBodies, int inNumber, bool inTakeLock = true) = 0;
80
82 virtual void NotifyBodiesLayerChanged(BodyID *ioBodies, int inNumber) = 0;
83
93 virtual void FindCollidingPairs(BodyID *ioActiveBodies, int inNumActiveBodies, float inSpeculativeContactDistance, const ObjectVsBroadPhaseLayerFilter &inObjectVsBroadPhaseLayerFilter, const ObjectLayerPairFilter &inObjectLayerPairFilter, BodyPairCollector &ioPairCollector) const = 0;
94
96 virtual void CastAABoxNoLock(const AABoxCast &inBox, CastShapeBodyCollector &ioCollector, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter) const = 0;
97
99 virtual AABox GetBounds() const = 0;
100
101#ifdef JPH_TRACK_BROADPHASE_STATS
104 virtual void ReportStats() { /* Can be implemented by derived classes */ }
105#endif // JPH_TRACK_BROADPHASE_STATS
106
107protected:
109 BodyManager * mBodyManager = nullptr;
110};
111
#define JPH_EXPORT
Definition: Core.h:236
#define JPH_NAMESPACE_END
Definition: Core.h:378
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:372
Axis aligned box.
Definition: AABox.h:16
ID of a body. This is a way of reasoning about bodies in a multithreaded simulation while avoiding ra...
Definition: BodyID.h:13
Class that contains all bodies.
Definition: BodyManager.h:44
Used to do coarse collision detection operations to quickly prune out bodies that will not collide.
Definition: BroadPhase.h:26
virtual void AddBodiesAbort(BodyID *ioBodies, int inNumber, AddState inAddState)
Definition: BroadPhase.h:71
virtual void AddBodiesFinalize(BodyID *ioBodies, int inNumber, AddState inAddState)=0
virtual void LockModifications()
Must be called before UpdatePrepare to prevent modifications from being made to the tree.
Definition: BroadPhase.h:41
virtual void NotifyBodiesAABBChanged(BodyID *ioBodies, int inNumber, bool inTakeLock=true)=0
virtual void CastAABoxNoLock(const AABoxCast &inBox, CastShapeBodyCollector &ioCollector, const BroadPhaseLayerFilter &inBroadPhaseLayerFilter, const ObjectLayerFilter &inObjectLayerFilter) const =0
Same as BroadPhaseQuery::CastAABox but can be implemented in a way to take no broad phase locks.
virtual void FrameSync()
Must be called just before updating the broadphase when none of the body mutexes are locked.
Definition: BroadPhase.h:38
virtual void UnlockModifications()
Must be called after UpdateFinalize to allow modifications to the broadphase.
Definition: BroadPhase.h:54
virtual void NotifyBodiesLayerChanged(BodyID *ioBodies, int inNumber)=0
Call whenever the layer (and optionally the aabb as well) of a body changes (can change order of ioBo...
virtual void Optimize()
Should be called after many objects have been inserted to make the broadphase more efficient,...
Definition: BroadPhase.h:35
virtual void UpdateFinalize(const UpdateState &inUpdateState)
Finalizing the update will quickly apply the changes.
Definition: BroadPhase.h:51
virtual AABox GetBounds() const =0
Get the bounding box of all objects in the broadphase.
virtual AddState AddBodiesPrepare(BodyID *ioBodies, int inNumber)
Definition: BroadPhase.h:62
virtual void RemoveBodies(BodyID *ioBodies, int inNumber)=0
void * AddState
Handle used during adding bodies to the broadphase.
Definition: BroadPhase.h:57
virtual void FindCollidingPairs(BodyID *ioActiveBodies, int inNumActiveBodies, float inSpeculativeContactDistance, const ObjectVsBroadPhaseLayerFilter &inObjectVsBroadPhaseLayerFilter, const ObjectLayerPairFilter &inObjectLayerPairFilter, BodyPairCollector &ioPairCollector) const =0
virtual UpdateState UpdatePrepare()
Definition: BroadPhase.h:48
Filter class for broadphase layers.
Definition: BroadPhaseLayer.h:94
Interface that the application should implement to allow mapping object layers to broadphase layers.
Definition: BroadPhaseLayer.h:61
Definition: BroadPhaseQuery.h:29
Virtual interface that allows collecting multiple collision results.
Definition: CollisionCollector.h:45
Filter class for object layers.
Definition: ObjectLayer.h:28
Filter class to test if two objects can collide based on their object layer. Used while finding colli...
Definition: ObjectLayer.h:50
Class to test if an object can collide with a broadphase layer. Used while finding collision pairs.
Definition: BroadPhaseLayer.h:80
Structure that holds AABox moving linearly through 3d space.
Definition: AABoxCast.h:13
Structure that holds a body pair.
Definition: BodyPair.h:14
Context used during broadphase update.
Definition: BroadPhase.h:44