Rise
The Vieneo Province
Loading...
Searching...
No Matches
Tests/RejoinCountdownTests.cpp

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{
14 RejoinCountdown timer;
15 Check(!timer.Ready(100), "an uninitialized death screen cannot rejoin");
16 timer.Update(false, 100);
17 Check(!timer.Ready(100), "being alive does not enable rejoin");
18 timer.Update(true, 200);
19 Check(!timer.Ready(200) && timer.SecondsRemaining(200) == 15, "death starts the full 15-second wait");
20 timer.Update(true, 201);
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");
25 timer.Reset();
26 Check(!timer.Ready(900), "accepting rejoin prevents a second queued activation");
27 timer.Update(true, 900);
28 Check(!timer.Ready(900) && timer.SecondsRemaining(900) == 15, "a second death gets its own full wait");
29 timer.Update(false, 904); // Simulator, logout or server resurrection.
30 Check(!timer.Ready(999), "leaving a real death cancels the old deadline");
31 timer.Update(true, 1000);
32 Check(!timer.Ready(1014.999) && timer.Ready(1015), "new session cannot inherit a ready countdown");
33
34 // Different frame rates and a long render stall use the same real deadline.
35 for (int hz : {10, 30, 60, 144})
36 {
37 timer.Reset();
38 timer.Update(true, 2000);
39 for (int frame = 1; frame < 15 * hz; ++frame)
40 {
41 const double now = 2000.0 + double(frame) / hz;
42 timer.Update(true, now);
43 Check(!timer.Ready(now), "frame rate cannot shorten the wait");
44 }
45 timer.Update(true, 2015);
46 Check(timer.Ready(2015), "all frame rates expire at 15 real seconds");
47 }
48 timer.Reset();
49 timer.Update(true, 3000);
50 timer.Update(true, 3030);
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)