group2 0.1.0
CSE 125 Group 2
Loading...
Searching...
No Matches
PhaseDiagnostic.hpp
Go to the documentation of this file.
1
21
22#pragma once
23
24#include <cstdint>
25#include <entt/entt.hpp>
26#include <glm/vec3.hpp>
27#include <string_view>
28
29namespace physics::diag
30{
31
33enum class PhaseFlag : uint32_t
34{
35 None = 0,
36 Grounded = 1u << 0,
37 WallRunning = 1u << 1,
38 Sliding = 1u << 2,
39 GrappleActive = 1u << 5,
40 DoubleJumped = 1u << 6,
41 GravityFlipped = 1u << 7,
45 DepenCancelled = 1u << 8,
48 DeepPenetration = 1u << 9,
52 BumpExhausted = 1u << 10,
55 SuspectedPhase = 1u << 11,
58 InvalidState = 1u << 12,
60 WallrunBlocked = 1u << 13,
65};
66
68{
69 return static_cast<PhaseFlag>(static_cast<uint32_t>(a) | static_cast<uint32_t>(b));
70}
71inline PhaseFlag& operator|=(PhaseFlag& a, PhaseFlag b) noexcept
72{
73 a = a | b;
74 return a;
75}
76inline bool any(PhaseFlag a) noexcept
77{
78 return static_cast<uint32_t>(a) != 0u;
79}
80
84{
85 uint64_t tick = 0;
86 entt::entity entity{entt::null};
87 glm::vec3 posBefore{0.0f};
88 glm::vec3 posAfterDepen{0.0f};
89 glm::vec3 posAfter{0.0f};
90 glm::vec3 velBefore{0.0f};
91 glm::vec3 velAfter{0.0f};
92 glm::vec3 lastHitNormal{0.0f};
93 float depenPushDistance = 0.0f;
94 int bumpHits = 0;
95 int moveMode = 0;
96 int wallrunSide = 0;
97 int jumpCount = 0;
99 char note[48] = {0};
100};
101
107void setFilePrefix(std::string_view prefix);
108
111void startRecording();
112
114void stopRecording();
115
119void setEnabled(bool on);
120[[nodiscard]] bool isEnabled() noexcept;
121
125void recordFrame(const PlayerFrame& frame) noexcept;
126
132{
133 entt::entity entity{entt::null};
134 glm::vec3 posBefore{0.0f};
135 glm::vec3 posAfter{0.0f};
136 glm::vec3 velBefore{0.0f};
137 glm::vec3 velAfter{0.0f};
138 int modeBefore = 0;
139 int modeAfter = 0;
140 bool groundedBefore = false;
141 bool groundedAfter = false;
142 bool inputForward = false;
143 bool inputBack = false;
144 bool inputLeft = false;
145 bool inputRight = false;
146 bool inputJump = false;
147 bool inputCrouch = false;
148 bool inputGrapple = false;
149 float yaw = 0.0f;
150 float pitch = 0.0f;
151 bool wallFront = false;
152 float groundDistance = 1e30f;
153 glm::vec3 frontNormal{0.0f};
154 glm::vec3 frontPoint{0.0f};
156 char note[64] = {0};
157};
158
161void recordMovementFrame(const MovementFrame& frame) noexcept;
162
166{
167 entt::entity entity{entt::null};
168 uint64_t elapsedUs = 0;
169 int substeps = 0;
173 int sweepHits = 0;
174 bool usedWalkCapsule = false;
175 bool caExhausted = false;
176 bool grounded = false;
177 int moveMode = 0;
178};
179
181void recordKccTimingFrame(const KccTimingFrame& frame) noexcept;
182
187void annotate(entt::entity entity, std::string_view label) noexcept;
188
192void consumeAnnotation(entt::entity entity, char (&out)[48]) noexcept;
193
201{
202 uint32_t triId = 0;
203 glm::vec3 playerPos{0.0f};
204 glm::vec3 faceNormal{0.0f};
205 glm::vec3 v0{0.0f};
206 glm::vec3 v1{0.0f};
207 glm::vec3 v2{0.0f};
208 float signedDist = 0.0f;
209 float minkowskiR = 0.0f;
210 float depth = 0.0f;
211 int region = 0;
212 uint8_t edgeFlags = 0;
213 uint8_t vertFlags = 0;
214};
215
221void recordDepenContact(const DepenContact& contact) noexcept;
222
223} // namespace physics::diag
Definition DeterminismHash.cpp:16
PhaseFlag
Bitfield flags attached to each logged row — auto-detected.
Definition PhaseDiagnostic.hpp:34
@ WallrunCeilingConstrained
Wallrun was vertically constrained by a head/ceiling contact.
Definition PhaseDiagnostic.hpp:62
@ DepenCancelled
Depen found overlaps but the aggregated push direction cancelled out (rare; either trapped between mi...
Definition PhaseDiagnostic.hpp:45
@ DeepPenetration
Depen had to push the player by >20 u in one tick — the player was deep inside geometry before depen.
Definition PhaseDiagnostic.hpp:48
@ SuspectedPhase
Actual per-tick position delta exceeded velocity * dt by > 2× + 5 u — the player likely tunnelled thr...
Definition PhaseDiagnostic.hpp:55
@ DoubleJumped
Definition PhaseDiagnostic.hpp:40
@ BumpExhausted
The bump loop consumed all 4 iterations and still had remainingTime > 0 — the player was grinding aga...
Definition PhaseDiagnostic.hpp:52
@ GrappleActive
Definition PhaseDiagnostic.hpp:39
@ None
Definition PhaseDiagnostic.hpp:35
@ KccOscillationResolved
KCC detected and resolved a repeated ABAB depen/sweep oscillation.
Definition PhaseDiagnostic.hpp:64
@ Grounded
Definition PhaseDiagnostic.hpp:36
@ WallRunning
Definition PhaseDiagnostic.hpp:37
@ GravityFlipped
Definition PhaseDiagnostic.hpp:41
@ Sliding
Definition PhaseDiagnostic.hpp:38
@ InvalidState
A position, velocity, normal, or stored movement vector was non-finite.
Definition PhaseDiagnostic.hpp:58
@ WallrunBlocked
Wallrun was constrained by a non-traversable blocker contact.
Definition PhaseDiagnostic.hpp:60
void setFilePrefix(std::string_view prefix)
Set the filename prefix used for this process's diagnostic CSVs.
Definition PhaseDiagnostic.cpp:224
void setEnabled(bool on)
Enable / disable telemetry.
Definition PhaseDiagnostic.cpp:249
PhaseFlag operator|(PhaseFlag a, PhaseFlag b) noexcept
Definition PhaseDiagnostic.hpp:67
void recordDepenContact(const DepenContact &c) noexcept
Append one depen-contact row to its own CSV log (depen-trace-<timestamp>.csv in the working dir).
Definition PhaseDiagnostic.cpp:483
void consumeAnnotation(entt::entity entity, char(&out)[48]) noexcept
Drain any queued annotation for entity into out, then clear it.
Definition PhaseDiagnostic.cpp:270
PhaseFlag & operator|=(PhaseFlag &a, PhaseFlag b) noexcept
Definition PhaseDiagnostic.hpp:71
void annotate(entt::entity entity, std::string_view label) noexcept
Attach a text annotation to the NEXT frame recorded for the given entity.
Definition PhaseDiagnostic.cpp:262
bool isEnabled() noexcept
Definition PhaseDiagnostic.cpp:257
void stopRecording()
Stop telemetry and close every open CSV file.
Definition PhaseDiagnostic.cpp:243
void recordMovementFrame(const MovementFrame &f) noexcept
Append a MovementSystem telemetry row to movement-diag-<timestamp>.csv.
Definition PhaseDiagnostic.cpp:377
void recordKccTimingFrame(const KccTimingFrame &f) noexcept
Append KCC timing telemetry to kcc-timing-<timestamp>.csv.
Definition PhaseDiagnostic.cpp:454
void startRecording()
Start a fresh telemetry session.
Definition PhaseDiagnostic.cpp:232
bool any(PhaseFlag a) noexcept
Definition PhaseDiagnostic.hpp:76
void recordFrame(const PlayerFrame &f) noexcept
Append a player's per-tick frame to the open CSV log.
Definition PhaseDiagnostic.cpp:285
One row of depen-contact telemetry.
Definition PhaseDiagnostic.hpp:201
glm::vec3 faceNormal
Cooked face normal of the offending triangle.
Definition PhaseDiagnostic.hpp:204
glm::vec3 v2
Definition PhaseDiagnostic.hpp:207
uint32_t triId
Definition PhaseDiagnostic.hpp:202
uint8_t edgeFlags
Cooked active-edge mask (bit i ⇔ edge i active per Phase 2 welding).
Definition PhaseDiagnostic.hpp:212
uint8_t vertFlags
Cooked active-vertex mask.
Definition PhaseDiagnostic.hpp:213
float minkowskiR
|faceN|·halfExtents — depth would saturate at 2·R (s = -R).
Definition PhaseDiagnostic.hpp:209
glm::vec3 v1
Definition PhaseDiagnostic.hpp:206
int region
Closest feature on the triangle: 0=Face, 1=Edge0, 2=Edge1, 3=Edge2, 4=Vert0, 5=Vert1,...
Definition PhaseDiagnostic.hpp:211
float signedDist
dot(faceN, playerPos - v0). Negative ⇒ player on back side.
Definition PhaseDiagnostic.hpp:208
float depth
MTV magnitude = R - signedDist.
Definition PhaseDiagnostic.hpp:210
glm::vec3 playerPos
Player capsule center at the moment of overlap.
Definition PhaseDiagnostic.hpp:203
glm::vec3 v0
Definition PhaseDiagnostic.hpp:205
One row of timing telemetry for the player KCC.
Definition PhaseDiagnostic.hpp:166
entt::entity entity
Definition PhaseDiagnostic.hpp:167
int sweepQueries
Definition PhaseDiagnostic.hpp:172
int clearanceQueries
Definition PhaseDiagnostic.hpp:171
uint64_t elapsedUs
Definition PhaseDiagnostic.hpp:168
int substeps
Definition PhaseDiagnostic.hpp:169
bool caExhausted
Definition PhaseDiagnostic.hpp:175
bool grounded
Definition PhaseDiagnostic.hpp:176
int moveMode
Definition PhaseDiagnostic.hpp:177
int caIterations
Definition PhaseDiagnostic.hpp:170
bool usedWalkCapsule
Definition PhaseDiagnostic.hpp:174
int sweepHits
Definition PhaseDiagnostic.hpp:173
One row captured around MovementSystem, before CollisionSystem/KCC.
Definition PhaseDiagnostic.hpp:132
bool inputForward
Definition PhaseDiagnostic.hpp:142
bool groundedBefore
Definition PhaseDiagnostic.hpp:140
glm::vec3 frontNormal
Definition PhaseDiagnostic.hpp:153
PhaseFlag flags
Definition PhaseDiagnostic.hpp:155
glm::vec3 velBefore
Definition PhaseDiagnostic.hpp:136
bool inputGrapple
Definition PhaseDiagnostic.hpp:148
float groundDistance
Definition PhaseDiagnostic.hpp:152
glm::vec3 velAfter
Definition PhaseDiagnostic.hpp:137
glm::vec3 posBefore
Definition PhaseDiagnostic.hpp:134
bool inputRight
Definition PhaseDiagnostic.hpp:145
bool inputBack
Definition PhaseDiagnostic.hpp:143
bool inputLeft
Definition PhaseDiagnostic.hpp:144
float yaw
Definition PhaseDiagnostic.hpp:149
int modeBefore
Definition PhaseDiagnostic.hpp:138
float pitch
Definition PhaseDiagnostic.hpp:150
bool inputJump
Definition PhaseDiagnostic.hpp:146
int modeAfter
Definition PhaseDiagnostic.hpp:139
bool wallFront
Definition PhaseDiagnostic.hpp:151
bool groundedAfter
Definition PhaseDiagnostic.hpp:141
glm::vec3 frontPoint
Definition PhaseDiagnostic.hpp:154
bool inputCrouch
Definition PhaseDiagnostic.hpp:147
char note[64]
Definition PhaseDiagnostic.hpp:156
glm::vec3 posAfter
Definition PhaseDiagnostic.hpp:135
entt::entity entity
Definition PhaseDiagnostic.hpp:133
One row of telemetry — captured per player per tick.
Definition PhaseDiagnostic.hpp:84
glm::vec3 posAfter
Final position, after bump loop + slope snap.
Definition PhaseDiagnostic.hpp:89
glm::vec3 velBefore
Velocity at tick start (already integrated by movement).
Definition PhaseDiagnostic.hpp:90
int bumpHits
Number of bump iterations that hit something.
Definition PhaseDiagnostic.hpp:94
int moveMode
MoveMode enum cast to int.
Definition PhaseDiagnostic.hpp:95
glm::vec3 posBefore
Position at tick start, BEFORE depen.
Definition PhaseDiagnostic.hpp:87
char note[48]
Free-form annotation slot (e.g., "wallrun-enter").
Definition PhaseDiagnostic.hpp:99
PhaseFlag flags
Definition PhaseDiagnostic.hpp:98
glm::vec3 velAfter
Velocity at tick end.
Definition PhaseDiagnostic.hpp:91
glm::vec3 posAfterDepen
After depen, BEFORE bump loop.
Definition PhaseDiagnostic.hpp:88
uint64_t tick
Definition PhaseDiagnostic.hpp:85
int jumpCount
Definition PhaseDiagnostic.hpp:97
glm::vec3 lastHitNormal
Normal of the last sweep hit in the bump loop (or 0).
Definition PhaseDiagnostic.hpp:92
float depenPushDistance
|posAfterDepen - posBefore|.
Definition PhaseDiagnostic.hpp:93
entt::entity entity
Definition PhaseDiagnostic.hpp:86
int wallrunSide
WallSide enum (None=0, Left=1, Right=2).
Definition PhaseDiagnostic.hpp:96