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
18{
19 None = 0,
20 Global = 1,
21 Bodies = 2,
22 Contacts = 4,
23 Constraints = 8,
25};
26
29{
30 return EStateRecorderState(uint8(inLHS) | uint8(inRHS));
31}
32
35{
36 return EStateRecorderState(uint8(inLHS) & uint8(inRHS));
37}
38
41{
42 return EStateRecorderState(uint8(inLHS) ^ uint8(inRHS));
43}
44
47{
48 return EStateRecorderState(~uint8(inAllowedDOFs));
49}
50
53{
54 ioLHS = ioLHS | inRHS;
55 return ioLHS;
56}
57
60{
61 ioLHS = ioLHS & inRHS;
62 return ioLHS;
63}
64
67{
68 ioLHS = ioLHS ^ inRHS;
69 return ioLHS;
70}
71
74{
75public:
77 virtual ~StateRecorderFilter() = default;
78
81
83 virtual bool ShouldSaveBody([[maybe_unused]] const Body &inBody) const { return true; }
84
86 virtual bool ShouldSaveConstraint([[maybe_unused]] const Constraint &inConstraint) const { return true; }
87
89 virtual bool ShouldSaveContact([[maybe_unused]] const BodyID &inBody1, [[maybe_unused]] const BodyID &inBody2) const { return true; }
90
94
96 virtual bool ShouldRestoreContact([[maybe_unused]] const BodyID &inBody1, [[maybe_unused]] const BodyID &inBody2) const { return true; }
97
99};
100
105{
106public:
108 StateRecorder() = default;
109 StateRecorder(const StateRecorder &inRHS) : mIsValidating(inRHS.mIsValidating) { }
110
116 void SetValidating(bool inValidating) { mIsValidating = inValidating; }
117 bool IsValidating() const { return mIsValidating; }
118
123 void SetIsLastPart(bool inIsLastPart) { mIsLastPart = inIsLastPart; }
124 bool IsLastPart() const { return mIsLastPart; }
125
126private:
127 bool mIsValidating = false;
128 bool mIsLastPart = true;
129};
130
std::uint8_t uint8
Definition Core.h:454
#define JPH_EXPORT
Definition Core.h:236
#define JPH_NAMESPACE_END
Definition Core.h:379
#define JPH_NAMESPACE_BEGIN
Definition Core.h:373
constexpr EStateRecorderState operator|(EStateRecorderState inLHS, EStateRecorderState inRHS)
Bitwise OR operator for EStateRecorderState.
Definition StateRecorder.h:28
constexpr EStateRecorderState & operator&=(EStateRecorderState &ioLHS, EStateRecorderState inRHS)
Bitwise AND assignment operator for EStateRecorderState.
Definition StateRecorder.h:59
constexpr EStateRecorderState operator^(EStateRecorderState inLHS, EStateRecorderState inRHS)
Bitwise XOR operator for EStateRecorderState.
Definition StateRecorder.h:40
constexpr EStateRecorderState operator&(EStateRecorderState inLHS, EStateRecorderState inRHS)
Bitwise AND operator for EStateRecorderState.
Definition StateRecorder.h:34
constexpr EStateRecorderState & operator^=(EStateRecorderState &ioLHS, EStateRecorderState inRHS)
Bitwise XOR assignment operator for EStateRecorderState.
Definition StateRecorder.h:66
constexpr EStateRecorderState & operator|=(EStateRecorderState &ioLHS, EStateRecorderState inRHS)
Bitwise OR assignment operator for EStateRecorderState.
Definition StateRecorder.h:52
EStateRecorderState
A bit field that determines which aspects of the simulation to save.
Definition StateRecorder.h:18
@ 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:46
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:74
virtual bool ShouldSaveConstraint(const Constraint &inConstraint) const
If the state of a specific constraint should be saved.
Definition StateRecorder.h:86
virtual bool ShouldRestoreContact(const BodyID &inBody1, const BodyID &inBody2) const
If the state of a specific contact should be restored.
Definition StateRecorder.h:96
virtual bool ShouldSaveContact(const BodyID &inBody1, const BodyID &inBody2) const
If the state of a specific contact should be saved.
Definition StateRecorder.h:89
virtual ~StateRecorderFilter()=default
Destructor.
virtual bool ShouldSaveBody(const Body &inBody) const
If the state of a specific body should be saved.
Definition StateRecorder.h:83
Definition StateRecorder.h:105
bool IsLastPart() const
Definition StateRecorder.h:124
bool IsValidating() const
Definition StateRecorder.h:117
StateRecorder(const StateRecorder &inRHS)
Definition StateRecorder.h:109
void SetValidating(bool inValidating)
Definition StateRecorder.h:116
void SetIsLastPart(bool inIsLastPart)
Definition StateRecorder.h:123
StateRecorder()=default
Constructor.
Simple binary input stream.
Definition StreamIn.h:13
Simple binary output stream.
Definition StreamOut.h:13