Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
DeterminismLog.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2022 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
7//#define JPH_ENABLE_DETERMINISM_LOG
8#ifdef JPH_ENABLE_DETERMINISM_LOG
9
12
14#include <iomanip>
15#include <fstream>
17
19
21class DeterminismLog
22{
23private:
24 JPH_INLINE uint32 Convert(float inValue) const
25 {
26 return *(uint32 *)&inValue;
27 }
28
29 JPH_INLINE uint64 Convert(double inValue) const
30 {
31 return *(uint64 *)&inValue;
32 }
33
34public:
35 DeterminismLog()
36 {
37 mLog.open("detlog.txt", std::ios::out | std::ios::trunc | std::ios::binary); // Binary because we don't want a difference between Unix and Windows line endings.
38 mLog.fill('0');
39 }
40
41 DeterminismLog & operator << (char inValue)
42 {
43 mLog << inValue;
44 return *this;
45 }
46
47 DeterminismLog & operator << (const char *inValue)
48 {
49 mLog << std::dec << inValue;
50 return *this;
51 }
52
53 DeterminismLog & operator << (const string &inValue)
54 {
55 mLog << std::dec << inValue;
56 return *this;
57 }
58
59 DeterminismLog & operator << (const BodyID &inValue)
60 {
61 mLog << std::hex << std::setw(8) << inValue.GetIndexAndSequenceNumber();
62 return *this;
63 }
64
65 DeterminismLog & operator << (const SubShapeID &inValue)
66 {
67 mLog << std::hex << std::setw(8) << inValue.GetValue();
68 return *this;
69 }
70
71 DeterminismLog & operator << (float inValue)
72 {
73 mLog << std::hex << std::setw(8) << Convert(inValue);
74 return *this;
75 }
76
77 DeterminismLog & operator << (int inValue)
78 {
79 mLog << inValue;
80 return *this;
81 }
82
83 DeterminismLog & operator << (uint32 inValue)
84 {
85 mLog << std::hex << std::setw(8) << inValue;
86 return *this;
87 }
88
89 DeterminismLog & operator << (uint64 inValue)
90 {
91 mLog << std::hex << std::setw(16) << inValue;
92 return *this;
93 }
94
95 DeterminismLog & operator << (Vec3Arg inValue)
96 {
97 mLog << std::hex << std::setw(8) << Convert(inValue.GetX()) << " " << std::setw(8) << Convert(inValue.GetY()) << " " << std::setw(8) << Convert(inValue.GetZ());
98 return *this;
99 }
100
101 DeterminismLog & operator << (DVec3Arg inValue)
102 {
103 mLog << std::hex << std::setw(16) << Convert(inValue.GetX()) << " " << std::setw(16) << Convert(inValue.GetY()) << " " << std::setw(16) << Convert(inValue.GetZ());
104 return *this;
105 }
106
107 DeterminismLog & operator << (Vec4Arg inValue)
108 {
109 mLog << std::hex << std::setw(8) << Convert(inValue.GetX()) << " " << std::setw(8) << Convert(inValue.GetY()) << " " << std::setw(8) << Convert(inValue.GetZ()) << " " << std::setw(8) << Convert(inValue.GetW());
110 return *this;
111 }
112
113 DeterminismLog & operator << (const Float3 &inValue)
114 {
115 mLog << std::hex << std::setw(8) << Convert(inValue.x) << " " << std::setw(8) << Convert(inValue.y) << " " << std::setw(8) << Convert(inValue.z);
116 return *this;
117 }
118
119 DeterminismLog & operator << (Mat44Arg inValue)
120 {
121 *this << inValue.GetColumn4(0) << " " << inValue.GetColumn4(1) << " " << inValue.GetColumn4(2) << " " << inValue.GetColumn4(3);
122 return *this;
123 }
124
125 DeterminismLog & operator << (DMat44Arg inValue)
126 {
127 *this << inValue.GetColumn4(0) << " " << inValue.GetColumn4(1) << " " << inValue.GetColumn4(2) << " " << inValue.GetTranslation();
128 return *this;
129 }
130
131 DeterminismLog & operator << (QuatArg inValue)
132 {
133 *this << inValue.GetXYZW();
134 return *this;
135 }
136
137 // Singleton instance
138 static DeterminismLog sLog;
139
140private:
141 std::ofstream mLog;
142};
143
145#define JPH_DET_LOG(...) DeterminismLog::sLog << __VA_ARGS__ << '\n'
146
148
149#else
150
151JPH_SUPPRESS_WARNING_PUSH
153
155#define JPH_DET_LOG(...)
156
157JPH_SUPPRESS_WARNING_POP
158
159#endif // JPH_ENABLE_DETERMINISM_LOG
#define JPH_SUPPRESS_WARNINGS
Definition Core.h:291
#define JPH_SUPPRESS_WARNINGS_STD_BEGIN
Definition Core.h:384
#define JPH_SUPPRESS_WARNINGS_STD_END
Definition Core.h:396
std::uint64_t uint64
Definition Core.h:450
#define JPH_NAMESPACE_END
Definition Core.h:379
std::uint32_t uint32
Definition Core.h:449
#define JPH_NAMESPACE_BEGIN
Definition Core.h:373
ID of a body. This is a way of reasoning about bodies in a multithreaded simulation while avoiding ra...
Definition BodyID.h:13
uint32 GetIndexAndSequenceNumber() const
Returns the index and sequence number combined in an uint32.
Definition BodyID.h:58
Holds a 4x4 matrix of floats with the last column consisting of doubles.
Definition DMat44.h:13
JPH_INLINE Vec4 GetColumn4(uint inCol) const
Definition DMat44.h:115
JPH_INLINE DVec3 GetTranslation() const
Definition DMat44.h:111
Definition DVec3.h:14
JPH_INLINE double GetZ() const
Definition DVec3.h:149
JPH_INLINE double GetY() const
Definition DVec3.h:148
JPH_INLINE double GetX() const
Get individual components.
Definition DVec3.h:147
Class that holds 3 floats. Used as a storage class. Convert to Vec3 for calculations.
Definition Float3.h:13
float y
Definition Float3.h:39
float z
Definition Float3.h:40
float x
Definition Float3.h:38
Holds a 4x4 matrix of floats, but supports also operations on the 3x3 upper left part of the matrix.
Definition Mat44.h:13
JPH_INLINE Vec4 GetColumn4(uint inCol) const
Definition Mat44.h:160
Definition Quat.h:33
JPH_INLINE Vec4 GetXYZW() const
Get the quaternion as a Vec4.
Definition Quat.h:84
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
Definition Vec3.h:17
JPH_INLINE float GetX() const
Get individual components.
Definition Vec3.h:124
JPH_INLINE float GetY() const
Definition Vec3.h:125
JPH_INLINE float GetZ() const
Definition Vec3.h:126
Definition Vec4.h:14
JPH_INLINE float GetW() const
Definition Vec4.h:116
JPH_INLINE float GetX() const
Get individual components.
Definition Vec4.h:113
JPH_INLINE float GetZ() const
Definition Vec4.h:115
JPH_INLINE float GetY() const
Definition Vec4.h:114