| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <Jolt/Physics/Collision/BroadPhase/BroadPhaseLayer.h> |
| 8 |
#include <Jolt/Physics/Collision/ObjectLayerPairFilterMask.h> |
| 9 |
|
| 10 |
JPH_NAMESPACE_BEGIN |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
class BroadPhaseLayerInterfaceMask : public BroadPhaseLayerInterface |
| 18 |
{ |
| 19 |
public: |
| 20 |
JPH_OVERRIDE_NEW_DELETE |
| 21 |
|
| 22 |
explicit BroadPhaseLayerInterfaceMask(uint inNumBroadPhaseLayers) |
| 23 |
{ |
| 24 |
JPH_ASSERT(inNumBroadPhaseLayers > 0); |
| 25 |
mMapping.resize(inNumBroadPhaseLayers); |
| 26 |
|
| 27 |
#if defined(JPH_EXTERNAL_PROFILE) || defined(JPH_PROFILE_ENABLED) |
| 28 |
mBroadPhaseLayerNames.resize(inNumBroadPhaseLayers, "Undefined"); |
| 29 |
#endif |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
void ConfigureLayer(BroadPhaseLayer inBroadPhaseLayer, uint32 inGroupsToInclude, uint32 inGroupsToExclude) |
| 34 |
{ |
| 35 |
JPH_ASSERT((BroadPhaseLayer::Type)inBroadPhaseLayer < (uint)mMapping.size()); |
| 36 |
Mapping &m = mMapping[(BroadPhaseLayer::Type)inBroadPhaseLayer]; |
| 37 |
m.mGroupsToInclude = inGroupsToInclude; |
| 38 |
m.mGroupsToExclude = inGroupsToExclude; |
| 39 |
} |
| 40 |
|
| 41 |
virtual uint GetNumBroadPhaseLayers() const override |
| 42 |
{ |
| 43 |
return (uint)mMapping.size(); |
| 44 |
} |
| 45 |
|
| 46 |
virtual BroadPhaseLayer GetBroadPhaseLayer(ObjectLayer inLayer) const override |
| 47 |
{ |
| 48 |
|
| 49 |
uint32 group = ObjectLayerPairFilterMask::sGetGroup(inLayer); |
| 50 |
for (const Mapping &m : mMapping) |
| 51 |
if ((group & m.mGroupsToInclude) != 0 && (group & m.mGroupsToExclude) == 0) |
| 52 |
return BroadPhaseLayer(BroadPhaseLayer::Type(&m - mMapping.data())); |
| 53 |
|
| 54 |
|
| 55 |
return BroadPhaseLayer(BroadPhaseLayer::Type(mMapping.size() - 1)); |
| 56 |
} |
| 57 |
|
| 58 |
|
| 59 |
inline bool ShouldCollide(ObjectLayer inLayer1, BroadPhaseLayer inLayer2) const |
| 60 |
{ |
| 61 |
uint32 mask = ObjectLayerPairFilterMask::sGetMask(inLayer1); |
| 62 |
const Mapping &m = mMapping[(BroadPhaseLayer::Type)inLayer2]; |
| 63 |
return &m == &mMapping.back() |
| 64 |
|| (m.mGroupsToInclude & mask) != 0; |
| 65 |
} |
| 66 |
|
| 67 |
#if defined(JPH_EXTERNAL_PROFILE) || defined(JPH_PROFILE_ENABLED) |
| 68 |
void SetBroadPhaseLayerName(BroadPhaseLayer inLayer, const char *inName) |
| 69 |
{ |
| 70 |
mBroadPhaseLayerNames[(BroadPhaseLayer::Type)inLayer] = inName; |
| 71 |
} |
| 72 |
|
| 73 |
virtual const char * GetBroadPhaseLayerName(BroadPhaseLayer inLayer) const override |
| 74 |
{ |
| 75 |
return mBroadPhaseLayerNames[(BroadPhaseLayer::Type)inLayer]; |
| 76 |
} |
| 77 |
#endif |
| 78 |
|
| 79 |
private: |
| 80 |
struct Mapping |
| 81 |
{ |
| 82 |
uint32 mGroupsToInclude = 0; |
| 83 |
uint32 mGroupsToExclude = ~uint32(0); |
| 84 |
}; |
| 85 |
Array<Mapping> mMapping; |
| 86 |
|
| 87 |
#if defined(JPH_EXTERNAL_PROFILE) || defined(JPH_PROFILE_ENABLED) |
| 88 |
Array<const char *> mBroadPhaseLayerNames; |
| 89 |
#endif |
| 90 |
}; |
| 91 |
|
| 92 |
JPH_NAMESPACE_END |