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) { }
23 SubShapeIDPair(const SubShapeIDPair &) = default;
24
26 inline bool operator == (const SubShapeIDPair &inRHS) const
27 {
28 return UVec4::sLoadInt4(reinterpret_cast<const uint32 *>(this)) == UVec4::sLoadInt4(reinterpret_cast<const uint32 *>(&inRHS));
29 }
30
32 inline bool operator < (const SubShapeIDPair &inRHS) const
33 {
34 if (mBody1ID != inRHS.mBody1ID)
35 return mBody1ID < inRHS.mBody1ID;
36
37 if (mSubShapeID1.GetValue() != inRHS.mSubShapeID1.GetValue())
38 return mSubShapeID1.GetValue() < inRHS.mSubShapeID1.GetValue();
39
40 if (mBody2ID != inRHS.mBody2ID)
41 return mBody2ID < inRHS.mBody2ID;
42
43 return mSubShapeID2.GetValue() < inRHS.mSubShapeID2.GetValue();
44 }
45
46 const BodyID & GetBody1ID() const { return mBody1ID; }
47 const SubShapeID & GetSubShapeID1() const { return mSubShapeID1; }
48 const BodyID & GetBody2ID() const { return mBody2ID; }
49 const SubShapeID & GetSubShapeID2() const { return mSubShapeID2; }
50
51 uint64 GetHash() const { return HashBytes(this, sizeof(SubShapeIDPair)); }
52
53private:
54 BodyID mBody1ID;
55 SubShapeID mSubShapeID1;
56 BodyID mBody2ID;
57 SubShapeID mSubShapeID2;
58};
59
60static_assert(sizeof(SubShapeIDPair) == 16, "Unexpected size");
61static_assert(alignof(SubShapeIDPair) == 4, "Assuming 4 byte aligned");
62
64
66
67namespace std
68{
70 template <>
71 struct hash<JPH::SubShapeIDPair>
72 {
73 inline size_t operator () (const JPH::SubShapeIDPair &inRHS) const
74 {
75 return static_cast<size_t>(inRHS.GetHash());
76 }
77 };
78}
79
#define JPH_SUPPRESS_WARNINGS_STD_BEGIN
Definition: Core.h:372
#define JPH_SUPPRESS_WARNINGS_STD_END
Definition: Core.h:384
std::uint64_t uint64
Definition: Core.h:443
#define JPH_NAMESPACE_END
Definition: Core.h:367
std::uint32_t uint32
Definition: Core.h:442
#define JPH_NAMESPACE_BEGIN
Definition: Core.h:361
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:26
const SubShapeID & GetSubShapeID2() const
Definition: SubShapeIDPair.h:49
uint64 GetHash() const
Definition: SubShapeIDPair.h:51
JPH_OVERRIDE_NEW_DELETE SubShapeIDPair()=default
Constructor.
const BodyID & GetBody1ID() const
Definition: SubShapeIDPair.h:46
SubShapeIDPair(const BodyID &inBody1ID, const SubShapeID &inSubShapeID1, const BodyID &inBody2ID, const SubShapeID &inSubShapeID2)
Definition: SubShapeIDPair.h:21
SubShapeIDPair(const SubShapeIDPair &)=default
SubShapeIDPair & operator=(const SubShapeIDPair &)=default
const SubShapeID & GetSubShapeID1() const
Definition: SubShapeIDPair.h:47
bool operator<(const SubShapeIDPair &inRHS) const
Less than operator, used to consistently order contact points for a deterministic simulation.
Definition: SubShapeIDPair.h:32
const BodyID & GetBody2ID() const
Definition: SubShapeIDPair.h:48
static JPH_INLINE UVec4 sLoadInt4(const uint32 *inV)
Load 4 ints from memory.
Definition: UVec4.inl:78
Definition: Reference.h:204