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

Source at documentation-generation time. See Test catalog for fixture associations.

1#include "../Rendering/ClientMath.h"
2#include <iostream>
3
4// Offline substitutes for world lookup and services. The generated code runs
5// the real command reset statements and production terrain/PFD decisions.
6struct Bus
7{
9 float RadioAltitudeKm = 0, DebugAglEye = -1;
10} busStorage;
11Bus* bus = &busStorage;
12struct Game { Bus* bus = &busStorage; } game;
13struct Gui { Game* game; } guiStorage{&game};
14Gui* gui = &guiStorage;
15struct Grid { bool dataReady = true; } grid;
16struct Camera { RiseMath::Vector3 position; } camera;
17struct Ship
18{
19 float mslKm = 0, bound = .001f;
20 bool groundvehicle = false;
21 double precisionx = 0, precisiony = 0, precisionz = 0;
22 RiseMath::Vector3 position;
23 RiseMath::Matrix matrixWorld;
24} playerships[1];
25struct Cockpit
26{
27 float strutsrettoCGKm = .002f, landingGearLengthKm = .001f;
28 float suspensionRideHeightKm = .0005f;
30struct City { float elevation = 0; } citystuff;
31float f_AGL = 0;
32bool g_bAboveClouds = false;
33struct Viewscreen
34{
35 Game* gameclass = &game;
36 Grid* ptrGrid = &grid;
37 Camera* cockpitCamera = &camera;
38 RiseMath::Vector3 terpos;
39 double terprecisionx = 0, terprecisiony = 0, terprecisionz = 0;
40 float result = -1;
41 int queries = 0;
42 float CalculateAGLd(RiseMath::Vector3, double, double, double,
43 double, double, double, RiseMath::Vector3, bool)
44 { ++queries; return result; }
45} view;
46Viewscreen* viewscreen = &view;
47
48#include "RepositionAltitude.generated.h"
49
50static int failures = 0, checks = 0;
51static void Check(bool pass, const char* message)
52{
53 ++checks;
54 if (!pass) { ++failures; std::cerr << "FAIL: " << message << '\n'; }
55}
56
57int main()
58{
59 // Ground -> dock and ground -> orbit, including the one frame in which
60 // weather still reports below clouds and the old terrain is still loaded.
61 for (auto reset : {ResetD0, ResetO0})
62 {
63 for (float staleResult : {-1.f, .003f})
64 {
65 f_AGL = .003f;
66 bus->RadioAltitudeKm = 0;
67 g_bAboveClouds = false;
68 grid.dataReady = true;
69 reset();
70 Check(f_AGL >= .442f, "reposition retained the old ground AGL");
71 Check(!GroundMarkerVisible(), "reposition did not hide the ground marker");
72 const float clearedAgl = f_AGL, clearedRadio = bus->RadioAltitudeKm;
73 playerships[0].mslKm = reset == ResetD0 ? 117.5f : 500.f;
74 view.result = staleResult;
75 view.queries = 0;
76 SampleTerrain();
77 Check(view.queries == 0, "old terrain queried before above-cloud flag caught up");
78 Check(f_AGL == clearedAgl && bus->RadioAltitudeKm == clearedRadio,
79 "old terrain overwrote the reposition clearance");
80 Check(!GroundMarkerVisible(), "false ground marker returned after reposition");
81 SampleContainedTerrain();
82 Check(view.queries == 0, "contained vehicle queried stale terrain in orbit");
83 g_bAboveClouds = true;
84 SampleTerrain();
85 Check(!GroundMarkerVisible(), "false ground marker persisted in orbit");
86 }
87 }
88
89 // Returning to the surface must restore normal gear-calibrated clearance.
90 playerships[0].mslKm = .103f;
91 g_bAboveClouds = false;
92 view.result = .003f;
93 view.queries = 0;
94 SampleTerrain();
95 Check(view.queries == 1 && std::fabs(bus->RadioAltitudeKm) < .000001f,
96 "landing did not restore near-zero radio altitude");
97 Check(GroundMarkerVisible(), "normal ground marker suppressed after return");
98 SampleContainedTerrain();
99 Check(view.queries == 2, "contained surface vehicle no longer refreshes its terrain position");
100 view.result = .5f;
101 SampleTerrain();
102 Check(!GroundMarkerVisible(), "ground marker did not clear during normal climb");
103
104 for (int invalid = 0; invalid < 3; ++invalid)
105 {
106 grid.dataReady = invalid != 0;
107 playerships[0].mslKm = invalid == 1 ? -1.f : .5f;
108 g_bAboveClouds = invalid == 2;
109 view.queries = 0;
110 SampleTerrain();
111 Check(view.queries == 0, "unavailable terrain was sampled");
112 }
113 std::cout << checks << " checks, " << failures << " failures\n";
114 return failures ? 1 : 0;
115}
Definition Bus.h:20
float StaticAirPressureMb
Definition Bus.h:406
float CabinPressureMb
Definition Bus.h:403
float DebugAglEye
Definition Bus.h:552
float RadioAltitudeKm
Definition Bus.h:157
GameClass * gameclass
Definition Viewscreen.h:439
std::unique_ptr< grid > ptrGrid
Definition Viewscreen.h:426
float CalculateAGLd(RiseMath::Vector3 terpos, double terprecisionx, double terprecisiony, double terprecisionz, double proposedx, double proposedy, double proposedz, RiseMath::Vector3 proposed, bool makeleveler)
double terprecisionz
Definition Viewscreen.h:370
double terprecisionx
Definition Viewscreen.h:370
RiseMath::Vector3 terpos
Definition Viewscreen.h:368
SCamera * cockpitCamera
Definition Viewscreen.h:138
double terprecisiony
Definition Viewscreen.h:370
SCamera * camera
Definition Viewscreen.h:137
Definition grid.h:14
bool dataReady
Definition grid.h:36
s_city_stuff citystuff
Definition globals.cpp:110
float f_AGL
Definition globals.cpp:9
s_network_objects playerships[MAX_SCAN]
Definition globals.cpp:112
Scockpit ourcockpit
Definition globals.cpp:114
bool g_bAboveClouds
Definition globals.cpp:16
@ Game
Use the game audio system.
Definition discordpp.h:505
gui(open_browser=True)
Definition erin.py:108