Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
SubShapeIDPair.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
10
12
15{
16public:
18
20 SubShapeIDPair() = default;
21 SubShapeIDPair(const BodyID &inBody1ID, const SubShapeID &inSubShapeID1, const BodyID &inBody2ID, const SubShapeID &inSubShapeID2) : mBody1ID(inBody1ID), mSubShapeID1(inSubShapeID1), mBody2ID(inBody2ID), mSubShapeID2(inSubShapeID2) { }
22 SubShapeIDPair(const SubShapeIDPair &) = default;
23
25 inline bool operator == (const SubShapeIDPair &inRHS) const
26 {
27 return UVec4::sLoadInt4(reinterpret_cast<const uint32 *>(this)) == UVec4::sLoadInt4(reinterpret_cast<const uint32 *>(&inRHS));
28 }
29
31 inline bool operator < (const SubShapeIDPair &inRHS) const
32 {
33 if (mBody1ID != inRHS.mBody1ID)
34 return mBody1ID < inRHS.mBody1ID;
35
36 if (mSubShapeID1.GetValue() != inRHS.mSubShapeID1.GetValue())
37 return mSubShapeID1.GetValue() < inRHS.mSubShapeID1.GetValue();
38
39 if (mBody2ID != inRHS.mBody2ID)
40 return mBody2ID < inRHS.mBody2ID;
41
42 return mSubShapeID2.GetValue() < inRHS.mSubShapeID2.GetValue();
43 }
44
45 const BodyID & GetBody1ID() const { return mBody1ID; }
46 const SubShapeID & GetSubShapeID1() const { return mSubShapeID1; }
47 const BodyID & GetBody2ID() const { return mBody2ID; }
48 const SubShapeID & GetSubShapeID2() const { return mSubShapeID2; }
49
50 uint64 GetHash() const { return HashBytes(this, sizeof(SubShapeIDPair)); }
51
52private:
53 BodyID mBody1ID;
54 SubShapeID mSubShapeID1;
55 BodyID mBody2ID;
56 SubShapeID mSubShapeID2;
57};
58
59static_assert(sizeof(SubShapeIDPair) == 16, "Unexpected size");
60static_assert(alignof(SubShapeIDPair) == 4, "Assuming 4 byte aligned");
61
63
65
66namespace std
67{
69 template <>
70 struct hash<JPH::SubShapeIDPair>
71 {
72 inline size_t operator () (const JPH::SubShapeIDPair &inRHS) const
73 {
74 return static_cast<size_t>(inRHS.GetHash());
75 }
76 };
77}
78
#define JPH_SUPPRESS_WARNINGS_STD_BEGIN
Definition: Core.h:245
uint32_t uint32
Definition: Core.h:312
#define JPH_SUPPRESS_WARNINGS_STD_END
Definition: Core.h:255
#define JPH_NAMESPACE_END
Definition: Core.h:240
uint64_t uint64
Definition: Core.h:313
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:234
JPH_NAMESPACE_BEGIN uint64 HashBytes(const void *inData, uint inSize, uint64 inSeed=0xcbf29ce484222325UL)
Definition: HashCombine.h:15
#define JPH_OVERRIDE_NEW_DELETE
Macro to override the new and delete functions.
Definition: Memory.h:29
ID of a body. This is a way of reasoning about bodies in a multithreaded simulation while avoiding ra...
Definition: BodyID.h:13
A sub shape id contains a path to an element (usually a triangle or other primitive type) of a compou...
Definition: SubShapeID.h:23
Type GetValue() const
Get the value of the path to the sub shape ID.
Definition: SubShapeID.h:52
A pair of bodies and their sub shape ID's. Can be used as a key in a map to find a contact point.
Definition: SubShapeIDPair.h:15
bool operator==(const SubShapeIDPair &inRHS) const
Equality operator.
Definition: SubShapeIDPair.h:25
const SubShapeID & GetSubShapeID2() const
Definition: SubShapeIDPair.h:48
uint64 GetHash() const
Definition: SubShapeIDPair.h:50
JPH_OVERRIDE_NEW_DELETE SubShapeIDPair()=default
Constructor.
const BodyID & GetBody1ID() const
Definition: SubShapeIDPair.h:45
SubShapeIDPair(const BodyID &inBody1ID, const SubShapeID &inSubShapeID1, const BodyID &inBody2ID, const SubShapeID &inSubShapeID2)
Definition: SubShapeIDPair.h:21
SubShapeIDPair(const SubShapeIDPair &)=default
const SubShapeID & GetSubShapeID1() const
Definition: SubShapeIDPair.h:46
bool operator<(const SubShapeIDPair &inRHS) const
Less than operator, used to consistently order contact points for a deterministic simulation.
Definition: SubShapeIDPair.h:31
const BodyID & GetBody2ID() const
Definition: SubShapeIDPair.h:47
static JPH_INLINE UVec4 sLoadInt4(const uint32 *inV)
Load 4 ints from memory.
Definition: UVec4.inl:78
Definition: Reference.h:207