| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
#pragma once |
| 6 |
|
| 7 |
#include <Jolt/Core/NonCopyable.h> |
| 8 |
|
| 9 |
JPH_NAMESPACE_BEGIN |
| 10 |
|
| 11 |
|
| 12 |
#ifndef JPH_OBJECT_LAYER_BITS |
| 13 |
#define JPH_OBJECT_LAYER_BITS 16 |
| 14 |
#endif |
| 15 |
#if JPH_OBJECT_LAYER_BITS == 16 |
| 16 |
using ObjectLayer = uint16; |
| 17 |
#elif JPH_OBJECT_LAYER_BITS == 32 |
| 18 |
using ObjectLayer = uint32; |
| 19 |
#else |
| 20 |
#error "JPH_OBJECT_LAYER_BITS must be 16 or 32" |
| 21 |
#endif |
| 22 |
|
| 23 |
|
| 24 |
static constexpr ObjectLayer cObjectLayerInvalid = ObjectLayer(~ObjectLayer(0U)); |
| 25 |
|
| 26 |
|
| 27 |
class JPH_EXPORT ObjectLayerFilter : public NonCopyable |
| 28 |
{ |
| 29 |
public: |
| 30 |
|
| 31 |
virtual ~ObjectLayerFilter() = default; |
| 32 |
|
| 33 |
|
| 34 |
virtual bool ShouldCollide([[maybe_unused]] ObjectLayer inLayer) const |
| 35 |
{ |
| 36 |
return true; |
| 37 |
} |
| 38 |
|
| 39 |
#ifdef JPH_TRACK_BROADPHASE_STATS |
| 40 |
|
| 41 |
virtual String GetDescription() const |
| 42 |
{ |
| 43 |
return "No Description"; |
| 44 |
} |
| 45 |
#endif |
| 46 |
}; |
| 47 |
|
| 48 |
|
| 49 |
class JPH_EXPORT ObjectLayerPairFilter : public NonCopyable |
| 50 |
{ |
| 51 |
public: |
| 52 |
|
| 53 |
virtual ~ObjectLayerPairFilter() = default; |
| 54 |
|
| 55 |
|
| 56 |
virtual bool ShouldCollide([[maybe_unused]] ObjectLayer inLayer1, [[maybe_unused]] ObjectLayer inLayer2) const |
| 57 |
{ |
| 58 |
return true; |
| 59 |
} |
| 60 |
}; |
| 61 |
|
| 62 |
|
| 63 |
class JPH_EXPORT DefaultObjectLayerFilter : public ObjectLayerFilter |
| 64 |
{ |
| 65 |
public: |
| 66 |
|
| 67 |
DefaultObjectLayerFilter(const ObjectLayerPairFilter &inObjectLayerPairFilter, ObjectLayer inLayer) : |
| 68 |
mObjectLayerPairFilter(inObjectLayerPairFilter), |
| 69 |
mLayer(inLayer) |
| 70 |
{ |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
DefaultObjectLayerFilter(const DefaultObjectLayerFilter &inRHS) : |
| 75 |
mObjectLayerPairFilter(inRHS.mObjectLayerPairFilter), |
| 76 |
mLayer(inRHS.mLayer) |
| 77 |
{ |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
virtual bool ShouldCollide(ObjectLayer inLayer) const override |
| 82 |
{ |
| 83 |
return mObjectLayerPairFilter.ShouldCollide(mLayer, inLayer); |
| 84 |
} |
| 85 |
|
| 86 |
private: |
| 87 |
const ObjectLayerPairFilter & mObjectLayerPairFilter; |
| 88 |
ObjectLayer mLayer; |
| 89 |
}; |
| 90 |
|
| 91 |
|
| 92 |
class JPH_EXPORT SpecifiedObjectLayerFilter : public ObjectLayerFilter |
| 93 |
{ |
| 94 |
public: |
| 95 |
|
| 96 |
explicit SpecifiedObjectLayerFilter(ObjectLayer inLayer) : |
| 97 |
mLayer(inLayer) |
| 98 |
{ |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
virtual bool ShouldCollide(ObjectLayer inLayer) const override |
| 103 |
{ |
| 104 |
return mLayer == inLayer; |
| 105 |
} |
| 106 |
|
| 107 |
private: |
| 108 |
ObjectLayer mLayer; |
| 109 |
}; |
| 110 |
|
| 111 |
JPH_NAMESPACE_END |