2
3#include <cmath>
4#include <cstdio>
5#include <cstdlib>
6#include <limits>
7#include <set>
8#include <vector>
9
11
12static int checks = 0;
13static void Check(bool value, const char* description)
14{
15 ++checks;
16 if (!value)
17 {
18 std::fprintf(stderr, "FAIL: %s\n", description);
19 std::exit(1);
20 }
21}
22
24{
27 result.
available[
static_cast<int>(gesture)] =
true;
30 return result;
31}
32
35{
36 return scheduler.
Update({dt, eligible, movement, finished});
37}
38
39static void CheckInterrupts()
40{
43 {
44 Scheduler scheduler(100, 200, Single(gesture));
45 auto command =
Update(scheduler, 0.1);
47 command =
Update(scheduler, 0.01, movement);
49 Check(command.blendSeconds == 0.35, "shared neutral blend duration");
51 command =
Update(scheduler, 0.25, movement,
true);
53 "requested movement starts after neutral is reached");
54 }
55
61 "movement from hip hold uses authored exit");
62 Check(command.blendSeconds == 0.35, "arbitrary hold phase blends into authored exit");
66
71 "releasing input while exiting must not start stale movement");
72
78 "latest input wins during the exit blend");
79
84}
85
86static void CheckNaturalHipExit()
87{
89 settings.minHipHoldSeconds = 3.0;
90 settings.maxHipHoldSeconds = 7.0;
91 std::set<int> holds;
92 for (std::uint64_t avatar = 0; avatar != 128; ++avatar)
93 {
94 Scheduler scheduler(avatar, 999, settings);
97 int ticks = 0;
99 while (++ticks < 1000)
100 {
101 command =
Update(scheduler, 0.01);
103 }
104 Check(command.clip ==
Clip::HipExit && command.blendSeconds == 0.35,
105 "natural hold completion blends arbitrary breathing phase into authored exit");
106 Check(ticks >= 300 && ticks <= 701, "hold timing stays inside configured range");
107 holds.insert(ticks);
109 "completed hip exit returns to a fresh neutral delay");
110 }
111 Check(holds.size() > 90, "hip holds vary independently between avatars");
112}
113
114static void CheckHipExitHostProtocol()
115{
116
117
118
119 for (const double authoredDuration : {0.65, 0.75})
120 {
125 Check(exit.clip ==
Clip::HipExit && exit.blendSeconds == 0.35,
"hip exit has explicit preblend");
126 const int blendTicks = static_cast<int>(std::lround(exit.blendSeconds * 100.0));
127 const int clipTicks = static_cast<int>(std::lround(authoredDuration * 100.0));
128 for (int tick = 1; tick < blendTicks + clipTicks; ++tick)
130 "walking waits for first-frame preblend and the entire exit clip");
133 "movement begins only after host completes both exit phases");
134 }
135}
136
137static void CheckTimingAndAvailability()
138{
139 std::set<int> delays;
142 for (std::uint64_t avatar = 0; avatar != 512; ++avatar)
143 {
144 Scheduler scheduler(avatar, 12345, available);
145 Scheduler duplicate(avatar, 12345, available);
146 int ticks = 0;
147 while (++ticks < 3000)
148 {
149 const auto first =
Update(scheduler, 0.01);
150 const auto second =
Update(duplicate, 0.01);
151 Check(first.kind == second.kind && first.clip == second.clip, "same avatar seed is reproducible");
153 }
154 Check(ticks >= 1200 && ticks <= 2401, "first delay remains 12 to 24 seconds");
155 delays.insert(ticks);
156 }
157 Check(delays.size() > 350, "avatars do not synchronize their first gesture");
158
160 for (int t = 0; t != 100; ++t)
164
166 {
167 auto single = Single(gesture);
169 const auto command =
Update(scheduler, 0.1);
173 Check(command.clip == expected, "selection respects the available profile clips");
174 }
175
177 for (int t = 0; t != 100; ++t)
179 "seated or moving avatars cannot acquire a waiting gesture");
181}
182
183static void CheckCooldownAndVariation()
184{
190 for (int second = 0; second != 42; ++second)
193
202 std::array<int, GestureCount> counts = {};
203 bool finished = false;
204 for (int tick = 0; tick != 10000; ++tick)
205 {
207 finished = false;
210 finished = true;
212 Check(command.clip != previous, "available alternatives prevent immediate gesture repetition");
213 previous = command.clip;
216 }
217 Check(counts[0] + counts[1] > counts[3] && counts[3] > counts[2], "configured weights favor subtle weight shifts");
218 Check(counts[0] > 0 && counts[1] > 0, "both directional weight shifts remain independently reachable");
219 Check(std::abs(counts[0] - counts[1]) < 0.15 * (counts[0] + counts[1]),
220 "left and right shifts retain balanced configured weights");
221 Check(counts[2] > 0, "watch remains reachable with a lower weight");
222}
223
224static void CheckDirectionalCooldowns()
225{
228
229
233 const auto first =
Update(scheduler, 0.1);
235 "directional-only availability selects a directional shift");
237 const auto second =
Update(scheduler, 0.1);
240 "cooldown of one side does not block the other side");
242 const auto third =
Update(scheduler, 13.0);
244 "right cooldown expires independently while left is still cooling down");
247 "both individual cooldowns prevent a premature directional replay");
249 "a ready direction remains playable when its opposite is unavailable");
250}
251
252static void CheckPoseBlends()
253{
262 const auto start =
BlendPose(from, to, 0.0, 0.35);
263 const auto middle =
BlendPose(from, to, 0.175, 0.35);
264 const auto end =
BlendPose(from, to, 0.35, 0.35);
267 "first blended frame preserves every sampled pose component");
270 "last blended frame exactly matches the target pose");
271 Check(std::abs(middle.anglesDegrees[0][0] - 180.0) < 1.0e-12 &&
272 std::abs(middle.anglesDegrees[0][1] + 180.0) < 1.0e-12,
273 "joint angle wrapping takes the shortest rotational arc");
274 Check(std::abs(middle.translationMeters[2] + 0.015) < 1.0e-12 &&
275 std::abs(middle.cameraHeightOffsetMeters + 0.01) < 1.0e-12,
276 "grounding and first-person camera use the same blend as the skeleton");
277 double previous = 0.0;
278 for (int tick = 0; tick <= 1000; ++tick)
279 {
281 Check(value >= previous && value >= 0.0 && value <= 1.0, "blend remains bounded and monotonic");
282 previous = value;
283 }
285 Check(1.0 -
SmoothBlendProgress(0.349999, 0.35) < 1.0e-12,
"blend ends with a flat tangent");
287 "invalid elapsed time cannot contaminate a pose");
288}
289
291{
292 CheckInterrupts();
293 CheckNaturalHipExit();
294 CheckHipExitHostProtocol();
295 CheckTimingAndAvailability();
296 CheckCooldownAndVariation();
297 CheckDirectionalCooldowns();
298 CheckPoseBlends();
299 std::printf("PersonWaitingPolicy: %d checks passed.\n", checks);
300}
Command Update(const Input &input)
float Update(Component *components, std::size_t count, bool viewerInside)
double SmoothBlendProgress(double elapsedSeconds, double durationSeconds)
Pose BlendPose(const Pose &from, const Pose &to, double elapsedSeconds, double durationSeconds)
std::array< double, GestureCount > cooldownSeconds
double maxIntervalSeconds
double minInitialDelaySeconds
std::array< bool, GestureCount > available
double maxInitialDelaySeconds
double minIntervalSeconds
std::array< std::array< double, 3 >, 16 > anglesDegrees
double cameraHeightOffsetMeters
std::array< double, 3 > translationMeters