Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
StateRecorder.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
9
11
12class Body;
13class Constraint;
14class BodyID;
15
16JPH_SUPPRESS_WARNING_PUSH
17JPH_GCC_SUPPRESS_WARNING("-Wshadow") // GCC complains about the 'Constraints' value conflicting with the 'Constraints' typedef
18
19
21{
22 None = 0,
23 Global = 1,
24 Bodies = 2,
25 Contacts = 4,
26 Constraints = 8,
28};
29
30JPH_SUPPRESS_WARNING_POP
31
34{
35 return EStateRecorderState(uint8(inLHS) | uint8(inRHS));
36}
37
40{
41 return EStateRecorderState(uint8(inLHS) & uint8(inRHS));
42}
43
46{
47 return EStateRecorderState(uint8(inLHS) ^ uint8(inRHS));
48}
49
52{
53 return EStateRecorderState(~uint8(inAllowedDOFs));
54}
55
58{
59 ioLHS = ioLHS | inRHS;
60 return ioLHS;
61}
62
65{
66 ioLHS = ioLHS & inRHS;
67 return ioLHS;
68}
69
72{
73 ioLHS = ioLHS ^ inRHS;
74 return ioLHS;
75}
76
79{
80public:
82 virtual ~StateRecorderFilter() = default;
83
86
88 virtual bool ShouldSaveBody([[maybe_unused]] const Body &inBody) const { return true; }
89
91 virtual bool ShouldSaveConstraint([[maybe_unused]] const Constraint &inConstraint) const { return true; }
92
94 virtual bool ShouldSaveContact([[maybe_unused]] const BodyID &inBody1, [[maybe_unused]] const BodyID &inBody2) const { return true; }
95
99
101 virtual bool ShouldRestoreContact([[maybe_unused]] const BodyID &inBody1, [[maybe_unused]] const BodyID &inBody2) const { return true; }
102
104};
105
110{
111public:
113 StateRecorder() = default;
114 StateRecorder(const StateRecorder &inRHS) : mIsValidating(inRHS.mIsValidating) { }
115
121 void SetValidating(bool inValidating) { mIsValidating = inValidating; }
122 bool IsValidating() const { return mIsValidating; }
123
128 void SetIsLastPart(bool inIsLastPart) { mIsLastPart = inIsLastPart; }
129 bool IsLastPart() const { return mIsLastPart; }
130
131private:
132 bool mIsValidating = false;
133 bool mIsLastPart = true;
134};
135
std::uint8_t uint8
Definition Core.h:482
#define JPH_EXPORT
Definition Core.h:271
#define JPH_GCC_SUPPRESS_WARNING(w)
Definition Core.h:308
#define JPH_NAMESPACE_END
Definition Core.h:414
#define JPH_NAMESPACE_BEGIN
Definition Core.h:408
constexpr EStateRecorderState & operator&=(EStateRecorderState &ioLHS, EStateRecorderState inRHS)
Bitwise AND assignment operator for EStateRecorderState.
Definition StateRecorder.h:64
constexpr EStateRecorderState operator^(EStateRecorderState inLHS, EStateRecorderState inRHS)
Bitwise XOR operator for EStateRecorderState.
Definition StateRecorder.h:45
constexpr EStateRecorderState operator&(EStateRecorderState inLHS, EStateRecorderState inRHS)
Bitwise AND operator for EStateRecorderState.
Definition StateRecorder.h:39
constexpr EStateRecorderState & operator^=(EStateRecorderState &ioLHS, EStateRecorderState inRHS)
Bitwise XOR assignment operator for EStateRecorderState.
Definition StateRecorder.h:71
constexpr EStateRecorderState & operator|=(EStateRecorderState &ioLHS, EStateRecorderState inRHS)
Bitwise OR assignment operator for EStateRecorderState.
Definition StateRecorder.h:57
EStateRecorderState
A bit field that determines which aspects of the simulation to save.
Definition StateRecorder.h:21
@ Bodies
Save the state of bodies.
@ Global
Save global physics system state (delta time, gravity, etc.)
@ None
Save nothing.
@ Contacts
Save the state of contacts.
@ All
Save all state.
constexpr EStateRecorderState operator~(EStateRecorderState inAllowedDOFs)
Bitwise NOT operator for EStateRecorderState.
Definition StateRecorder.h:51
JPH_SUPPRESS_WARNING_POP constexpr EStateRecorderState operator|(EStateRecorderState inLHS, EStateRecorderState inRHS)
Bitwise OR operator for EStateRecorderState.
Definition StateRecorder.h:33
Definition Body.h:35
ID of a body. This is a way of reasoning about bodies in a multithreaded simulation while avoiding ra...
Definition BodyID.h:13
Base class for all physics constraints. A constraint removes one or more degrees of freedom for a rig...
Definition Constraint.h:103
User callbacks that allow determining which parts of the simulation should be saved by a StateRecorde...
Definition StateRecorder.h:79
virtual bool ShouldSaveConstraint(const Constraint &inConstraint) const
If the state of a specific constraint should be saved.
Definition StateRecorder.h:91
virtual bool ShouldRestoreContact(const BodyID &inBody1, const BodyID &inBody2) const
If the state of a specific contact should be restored.
Definition StateRecorder.h:101
virtual bool ShouldSaveContact(const BodyID &inBody1, const BodyID &inBody2) const
If the state of a specific contact should be saved.
Definition StateRecorder.h:94
virtual ~StateRecorderFilter()=default
Destructor.
virtual bool ShouldSaveBody(const Body &inBody) const
If the state of a specific body should be saved.
Definition StateRecorder.h:88
Definition StateRecorder.h:110
bool IsLastPart() const
Definition StateRecorder.h:129
bool IsValidating() const
Definition StateRecorder.h:122
StateRecorder(const StateRecorder &inRHS)
Definition StateRecorder.h:114
void SetValidating(bool inValidating)
Definition StateRecorder.h:121
void SetIsLastPart(bool inIsLastPart)
Definition StateRecorder.h:128
StateRecorder()=default
Constructor.
Simple binary input stream.
Definition StreamIn.h:13
Simple binary output stream.
Definition StreamOut.h:13