Source at documentation-generation time. See Test catalog for fixture associations.
1#include "../RejoinCountdown.h"
2#include <cstdlib>
3#include <iostream>
4
5static int checks = 0;
6static void Check(bool condition, const char* message)
7{
8 ++checks;
9 if (!condition) { std::cerr << "FAIL: " << message << '\n'; std::exit(1); }
10}
11
12int main()
13{
15 Check(!timer.
Ready(100),
"an uninitialized death screen cannot rejoin");
17 Check(!timer.
Ready(100),
"being alive does not enable rejoin");
19 Check(!timer.
Ready(200) && timer.
SecondsRemaining(200) == 15,
"death starts the full 15-second wait");
21 Check(timer.
SecondsRemaining(201) == 14,
"repeated death updates do not restart the countdown");
22 Check(timer.
SecondsRemaining(214.999) == 1 && !timer.
Ready(214.999),
"last fraction remains locked and displays one second");
23 Check(timer.
Ready(215) && timer.
SecondsRemaining(215) == 0,
"deadline enables rejoin exactly at 15 seconds");
24 Check(timer.
Ready(900) && timer.
SecondsRemaining(900) == 0,
"an expired countdown never becomes negative");
26 Check(!timer.
Ready(900),
"accepting rejoin prevents a second queued activation");
28 Check(!timer.
Ready(900) && timer.
SecondsRemaining(900) == 15,
"a second death gets its own full wait");
30 Check(!timer.
Ready(999),
"leaving a real death cancels the old deadline");
32 Check(!timer.
Ready(1014.999) && timer.
Ready(1015),
"new session cannot inherit a ready countdown");
33
34
35 for (int hz : {10, 30, 60, 144})
36 {
39 for (int frame = 1; frame < 15 * hz; ++frame)
40 {
41 const double now = 2000.0 + double(frame) / hz;
43 Check(!timer.
Ready(now),
"frame rate cannot shorten the wait");
44 }
46 Check(timer.
Ready(2015),
"all frame rates expire at 15 real seconds");
47 }
51 Check(timer.
Ready(3030),
"render stalls do not stretch the wait via clamped physics time");
52 std::cout << "PASS " << checks << " countdown checks\n";
53}
bool Ready(double now) const
double SecondsRemaining(double now) const
void Update(bool realDeath, double now)