Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
BroadPhaseLayerInterfaceMask.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2023 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
9
11
18{
19public:
21
23 {
25 mMapping.resize(inNumBroadPhaseLayers);
26
27#if defined(JPH_EXTERNAL_PROFILE) || defined(JPH_PROFILE_ENABLED)
28 mBroadPhaseLayerNames.resize(inNumBroadPhaseLayers, "Undefined");
29#endif // JPH_EXTERNAL_PROFILE || JPH_PROFILE_ENABLED
30 }
31
32 // Configures a broadphase layer.
40
41 virtual uint GetNumBroadPhaseLayers() const override
42 {
43 return (uint)mMapping.size();
44 }
45
47 {
48 // Try to find the first broadphase layer that matches
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 // Fall back to the last broadphase layer
55 return BroadPhaseLayer(BroadPhaseLayer::Type(mMapping.size() - 1));
56 }
57
60 {
62 const Mapping &m = mMapping[(BroadPhaseLayer::Type)inLayer2];
63 return &m == &mMapping.back() // Last layer may collide with anything
64 || (m.mGroupsToInclude & mask) != 0; // Mask allows it to collide with objects that could reside in this layer
65 }
66
67#if defined(JPH_EXTERNAL_PROFILE) || defined(JPH_PROFILE_ENABLED)
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 // JPH_EXTERNAL_PROFILE || JPH_PROFILE_ENABLED
78
79private:
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 // JPH_EXTERNAL_PROFILE || JPH_PROFILE_ENABLED
90};
91
unsigned int uint
Definition Core.h:439
#define JPH_NAMESPACE_END
Definition Core.h:367
std::uint32_t uint32
Definition Core.h:442
#define JPH_NAMESPACE_BEGIN
Definition Core.h:361
#define JPH_ASSERT(...)
Definition IssueReporting.h:33
AllocateFunction Allocate
Definition Memory.cpp:59
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition Memory.h:29
uint16 ObjectLayer
Definition ObjectLayer.h:16
std::vector< T, STLAllocator< T > > Array
Definition STLAllocator.h:81
Definition BroadPhaseLayer.h:18
uint8 Type
Definition BroadPhaseLayer.h:20
Interface that the application should implement to allow mapping object layers to broadphase layers.
Definition BroadPhaseLayer.h:61
Definition BroadPhaseLayerInterfaceMask.h:18
void ConfigureLayer(BroadPhaseLayer inBroadPhaseLayer, uint32 inGroupsToInclude, uint32 inGroupsToExclude)
Definition BroadPhaseLayerInterfaceMask.h:33
void SetBroadPhaseLayerName(BroadPhaseLayer inLayer, const char *inName)
Definition BroadPhaseLayerInterfaceMask.h:68
virtual uint GetNumBroadPhaseLayers() const override
Return the number of broadphase layers there are.
Definition BroadPhaseLayerInterfaceMask.h:41
virtual BroadPhaseLayer GetBroadPhaseLayer(ObjectLayer inLayer) const override
Convert an object layer to the corresponding broadphase layer.
Definition BroadPhaseLayerInterfaceMask.h:46
JPH_OVERRIDE_NEW_DELETE BroadPhaseLayerInterfaceMask(uint inNumBroadPhaseLayers)
Definition BroadPhaseLayerInterfaceMask.h:22
virtual const char * GetBroadPhaseLayerName(BroadPhaseLayer inLayer) const override
Get the user readable name of a broadphase layer (debugging purposes)
Definition BroadPhaseLayerInterfaceMask.h:73
bool ShouldCollide(ObjectLayer inLayer1, BroadPhaseLayer inLayer2) const
Returns true if an object layer should collide with a broadphase layer, this function is being called...
Definition BroadPhaseLayerInterfaceMask.h:59
static uint32 sGetGroup(ObjectLayer inObjectLayer)
Get the group bits from an ObjectLayer.
Definition ObjectLayerPairFilterMask.h:33
static uint32 sGetMask(ObjectLayer inObjectLayer)
Get the mask bits from an ObjectLayer.
Definition ObjectLayerPairFilterMask.h:39