| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <Jolt/Core/NonCopyable.h> |
| 8 |
#include <Jolt/Physics/Collision/ObjectLayer.h> |
| 9 |
|
| 10 |
JPH_NAMESPACE_BEGIN |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
class BroadPhaseLayer |
| 18 |
{ |
| 19 |
public: |
| 20 |
using Type = uint8; |
| 21 |
|
| 22 |
JPH_INLINE BroadPhaseLayer() = default; |
| 23 |
JPH_INLINE explicit constexpr BroadPhaseLayer(Type inValue) : mValue(inValue) { } |
| 24 |
JPH_INLINE constexpr BroadPhaseLayer(const BroadPhaseLayer &) = default; |
| 25 |
JPH_INLINE BroadPhaseLayer & operator = (const BroadPhaseLayer &) = default; |
| 26 |
|
| 27 |
JPH_INLINE constexpr bool operator == (const BroadPhaseLayer &inRHS) const |
| 28 |
{ |
| 29 |
return mValue == inRHS.mValue; |
| 30 |
} |
| 31 |
|
| 32 |
JPH_INLINE constexpr bool operator != (const BroadPhaseLayer &inRHS) const |
| 33 |
{ |
| 34 |
return mValue != inRHS.mValue; |
| 35 |
} |
| 36 |
|
| 37 |
JPH_INLINE constexpr bool operator < (const BroadPhaseLayer &inRHS) const |
| 38 |
{ |
| 39 |
return mValue < inRHS.mValue; |
| 40 |
} |
| 41 |
|
| 42 |
JPH_INLINE explicit constexpr operator Type() const |
| 43 |
{ |
| 44 |
return mValue; |
| 45 |
} |
| 46 |
|
| 47 |
JPH_INLINE Type GetValue() const |
| 48 |
{ |
| 49 |
return mValue; |
| 50 |
} |
| 51 |
|
| 52 |
private: |
| 53 |
Type mValue; |
| 54 |
}; |
| 55 |
|
| 56 |
|
| 57 |
static constexpr BroadPhaseLayer cBroadPhaseLayerInvalid(0xff); |
| 58 |
|
| 59 |
|
| 60 |
class JPH_EXPORT BroadPhaseLayerInterface : public NonCopyable |
| 61 |
{ |
| 62 |
public: |
| 63 |
|
| 64 |
virtual ~BroadPhaseLayerInterface() = default; |
| 65 |
|
| 66 |
|
| 67 |
virtual uint GetNumBroadPhaseLayers() const = 0; |
| 68 |
|
| 69 |
|
| 70 |
virtual BroadPhaseLayer GetBroadPhaseLayer(ObjectLayer inLayer) const = 0; |
| 71 |
|
| 72 |
#if defined(JPH_EXTERNAL_PROFILE) || defined(JPH_PROFILE_ENABLED) |
| 73 |
|
| 74 |
virtual const char * GetBroadPhaseLayerName(BroadPhaseLayer inLayer) const = 0; |
| 75 |
#endif |
| 76 |
}; |
| 77 |
|
| 78 |
|
| 79 |
class JPH_EXPORT ObjectVsBroadPhaseLayerFilter : public NonCopyable |
| 80 |
{ |
| 81 |
public: |
| 82 |
|
| 83 |
virtual ~ObjectVsBroadPhaseLayerFilter() = default; |
| 84 |
|
| 85 |
|
| 86 |
virtual bool ShouldCollide([[maybe_unused]] ObjectLayer inLayer1, [[maybe_unused]] BroadPhaseLayer inLayer2) const |
| 87 |
{ |
| 88 |
return true; |
| 89 |
} |
| 90 |
}; |
| 91 |
|
| 92 |
|
| 93 |
class JPH_EXPORT BroadPhaseLayerFilter : public NonCopyable |
| 94 |
{ |
| 95 |
public: |
| 96 |
|
| 97 |
virtual ~BroadPhaseLayerFilter() = default; |
| 98 |
|
| 99 |
|
| 100 |
virtual bool ShouldCollide([[maybe_unused]] BroadPhaseLayer inLayer) const |
| 101 |
{ |
| 102 |
return true; |
| 103 |
} |
| 104 |
}; |
| 105 |
|
| 106 |
|
| 107 |
class JPH_EXPORT DefaultBroadPhaseLayerFilter : public BroadPhaseLayerFilter |
| 108 |
{ |
| 109 |
public: |
| 110 |
|
| 111 |
DefaultBroadPhaseLayerFilter(const ObjectVsBroadPhaseLayerFilter &inObjectVsBroadPhaseLayerFilter, ObjectLayer inLayer) : |
| 112 |
mObjectVsBroadPhaseLayerFilter(inObjectVsBroadPhaseLayerFilter), |
| 113 |
mLayer(inLayer) |
| 114 |
{ |
| 115 |
} |
| 116 |
|
| 117 |
|
| 118 |
virtual bool ShouldCollide(BroadPhaseLayer inLayer) const override |
| 119 |
{ |
| 120 |
return mObjectVsBroadPhaseLayerFilter.ShouldCollide(mLayer, inLayer); |
| 121 |
} |
| 122 |
|
| 123 |
private: |
| 124 |
const ObjectVsBroadPhaseLayerFilter &mObjectVsBroadPhaseLayerFilter; |
| 125 |
ObjectLayer mLayer; |
| 126 |
}; |
| 127 |
|
| 128 |
|
| 129 |
class JPH_EXPORT SpecifiedBroadPhaseLayerFilter : public BroadPhaseLayerFilter |
| 130 |
{ |
| 131 |
public: |
| 132 |
|
| 133 |
explicit SpecifiedBroadPhaseLayerFilter(BroadPhaseLayer inLayer) : |
| 134 |
mLayer(inLayer) |
| 135 |
{ |
| 136 |
} |
| 137 |
|
| 138 |
|
| 139 |
virtual bool ShouldCollide(BroadPhaseLayer inLayer) const override |
| 140 |
{ |
| 141 |
return mLayer == inLayer; |
| 142 |
} |
| 143 |
|
| 144 |
private: |
| 145 |
BroadPhaseLayer mLayer; |
| 146 |
}; |
| 147 |
|
| 148 |
JPH_NAMESPACE_END |