1#include "../Viewscreen/WindshieldWipers.h"
2#include <cstdlib>
3#include <fstream>
4#include <iostream>
5#include <limits>
6#include <string>
7
8static void Check(bool ok, const char* message)
9{
10 if (!ok) { std::cerr << "FAIL: " << message << '\n'; std::exit(1); }
11}
12
13template<class T> static T Read(std::ifstream& file, std::streamoff offset)
14{
15 T value{};
16 file.seekg(offset);
17 file.read(reinterpret_cast<char*>(&value), sizeof(value));
18 Check(file.good(), "read shipped cockpit component");
19 return value;
20}
21
22static void CheckShippedBlades()
23{
24 struct Fixture { const char* vehicle; const char* mesh; int blades; };
25 for (const auto& fixture : {
26 Fixture{"C-2", "C-2 Dasher INT", 2}, {"C-2A", "C-2A Dasher INT", 2},
27 {"T-121", "2007 T-120 INT", 2}, {"T-27", "mammoth-int", 5},
28 {"C-98", "MuVERcockpit-construction", 0}, {"E-10", "e10cockpit1", 0},
29 {"E-11", "e11cockpit1", 0}, {"P-13", "p13-cockpit1", 0},
30 {"A-4", "T-8 Wanderer INT", 0}, {"T-120", "T-120 Steerhead-stock INT", 2},
31 {"T-19", "stratomaster_06-hex", 0}, {"W6 Manx", "manx-int-hex", 0}})
32 {
33 const std::string
path = std::string(
"Meshes/") + fixture.mesh +
".dix";
34 std::ifstream file(path, std::ios::binary);
35 Check(file.good(),
path.c_str());
36 const int components = Read<short>(file, 0);
37 int blades = 0;
38 for (int i = 0; i < components; ++i)
39 {
40 const int offset = 99 + i * 100;
41 const int type = Read<unsigned char>(file, offset + 58);
42 if (type != 47) continue;
43 const int primitives = Read<short>(file, offset + 2);
44 Check(primitives > 0, "authored blade has geometry");
45 float axisLengthSq = 0, travelLengthSq = 0;
46 for (int axis = 0; axis < 3; ++axis)
47 {
48 const float hinge = Read<float>(file, offset + 63 + axis * 4);
49 const float travel = Read<float>(file, offset + 32 + axis * 4);
50 axisLengthSq += hinge * hinge;
51 travelLengthSq += travel * travel;
52 }
53 const float extent = Read<float>(file, offset + 87);
55 (std::string(fixture.vehicle) + " blade must enable rain clearing and audio").c_str());
56 ++blades;
57 }
58 Check(blades == fixture.blades, (std::string(fixture.vehicle) + " shipped cockpit blade count: "
59 + std::to_string(blades) + ", expected " + std::to_string(fixture.blades)).c_str());
60 std::cout << "PASS: " << fixture.vehicle << ": " << blades << " movable cockpit blades\n";
61 }
62}
63
65{
67 CheckShippedBlades();
68 Check(
HasBladeMotion(47, 42, 1.f, -1.5f, 0.f),
"rotating blade enables audio");
69 Check(
HasBladeMotion(47, 42, 0.f, 0.f, .000002f * .000002f),
"two-millimetre sliding blade enables audio");
70 Check(!
HasBladeMotion(47, 42, 1.f, 0.f, 0.f),
"zero-travel blade stays silent");
71 Check(!
HasBladeMotion(47, 42, 0.f, 0.f, .0000005f * .0000005f),
"sub-millimetre authoring noise stays silent");
72 Check(!
HasBladeMotion(47, 0, 1.f, 1.f, 0.f),
"empty component stays silent");
73 Check(!
HasBladeMotion(5, 42, 1.f, 1.f, 0.f),
"glass without blades stays silent");
74 bool enabled = false;
75 Check(
SetEnabled(enabled, !enabled) && enabled,
"keybind ON changes state and requests an event");
76 Check(!
SetEnabled(enabled,
true) && enabled,
"crash cannot turn running wipers off or resend ON");
77 Check(
SetEnabled(enabled, !enabled) && !enabled,
"keybind OFF changes state and requests an event");
78 Check(
SetEnabled(enabled,
true) && enabled,
"crash activation uses the same state/event path");
79 for (int i = 0; i < 1000; ++i)
80 Check(!
SetEnabled(enabled,
true),
"repeated activation does not flood the wire");
81
82 for (int fps : {30, 60, 144})
83 {
86 Check(motion.
phase == 0 && !motion.
moving,
"OFF stays parked");
87 for (
int frame=0; frame<fps; ++frame) motion.
Update(1.f/fps,
true);
88 Check(std::abs(motion.
phase - .2f) < .00001f && motion.
moving,
"ON runs continuously at 1.2 Hz");
89 const float beforePause = motion.
phase;
90 motion.
Update(0,
true); Check(!motion.
moving && motion.
phase == beforePause,
"pause is silent and stationary");
91 motion.
Update(.1f,
true,
false); Check(!motion.
moving && motion.
phase == beforePause,
"power loss preserves pose");
92 motion.
Update(.1f,
false,
false); Check(!motion.
moving && motion.
phase == beforePause,
"OFF waits for power before parking");
93 motion.
Update(1.f/fps,
false);
94 Check(motion.
phase > beforePause && motion.
moving,
"OFF returns smoothly instead of snapping to park");
95 for (
int frame=0; frame<fps; ++frame) motion.
Update(1.f/fps,
false);
96 Check(motion.
phase == 0 && !motion.
moving,
"off completes return and parks");
97 for (
int frame=0; frame<fps; ++frame) motion.
Update(1.f/fps,
true);
98 Check(std::abs(motion.
phase - .2f) < .00001f,
"re-enabling resumes the same fixed rate");
99
101 for (int frame=0; frame<fps; ++frame)
102 {
103 vehicles[0].
Update(1.f/fps,
false);
104 vehicles[1].
Update(1.f/fps,
true);
105 vehicles[2].
Update(1.f/fps,
false);
106 }
107 Check(vehicles[0].phase == 0 && vehicles[1].moving && vehicles[2].phase == 0,
108 "each vehicle obeys its own on/off state, including slot zero");
109 for (int frame=0; frame<fps; ++frame)
110 {
111 vehicles[0].
Update(1.f/fps,
true);
112 vehicles[1].
Update(1.f/fps,
false);
113 }
114 Check(vehicles[0].moving && vehicles[1].phase == 0 && !vehicles[1].moving,
115 "one vehicle parking cannot stop another vehicle");
116 vehicles[0] = {};
117 Check(vehicles[0].phase == 0 && !vehicles[0].moving, "new slot occupant starts parked");
118 }
121 Check(stalled.
phase == bounded.
phase,
"stalls cannot jump across entire sweeps");
122 for (float elapsed : {-1.f, std::numeric_limits<float>::quiet_NaN(), std::numeric_limits<float>::infinity()})
123 {
124 const float before = bounded.
phase;
125 bounded.
Update(elapsed,
true);
126 Check(bounded.
phase == before && !bounded.
moving,
"invalid time cannot corrupt animation or play audio");
127 }
128 std::cout << "PASS: shared keybind/crash switch, fixed-rate per-vehicle motion, parking, pause/power, reset, and 30/60/144 FPS\n";
129}
bool SetEnabled(bool ¤t, bool enabled)
bool HasBladeMotion(int type, unsigned primitives, float axisLengthSq, float hingeExtent, float travelLengthSq)
void Update(float elapsed, bool enabled, bool powered=true)