Rise
The Vieneo Province
Loading...
Searching...
No Matches
Tests/TerrainAwarenessMapReplay.h

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

1// Exercise the actual MovingMap renderer inside the authored cockpit screen.
2template<class Render> static void CheckTerrainAwarenessMap(Bus& bus, Render render)
3{
4 using namespace TerrainAwareness;
5 auto& state = bus.GPWS.terrain;
7 const auto baseline = render("gpws-sectional-baseline");
8 state.Clear(); state.enabled = true; state.terrainComplete = state.obstaclesComplete = true;
9 state.altitudeKm = .8f; state.verticalKms = 0; state.gearDown = false;
10 for (int u = 0; u < 63; ++u) for (int v = 0; v < 63; ++v)
11 {
12 auto& cell = state.cells[u*63+v];
13 cell.valid = true; cell.u = gridarray[u][v].tcp.u; cell.v = gridarray[u][v].tcp.v;
14 cell.topKm = .1f+float((u+v)%8)*.2f;
15 }
16 Check(render("gpws-normal-with-terrain-data")==baseline,"available terrain data alone never selects terrain view");
17 state.terrain=Severity::Caution;
18 const auto relative = render("gpws-relative-terrain");
19 Check(relative != baseline,"relative terrain must change the cockpit map");
20 state.onGround = true; state.displayRunwayKm = .8f;
21 const auto parked = render("gpws-ground-mountains");
22 Check(parked == baseline,"parked aircraft retains normal map even with stale threat data");
23 state.onGround = false; state.displayRunwayKm = -100;
24 const auto originalCells = state.cells;
25 std::rotate(state.cells.begin(),state.cells.begin()+63,state.cells.end());
26 Check(render("gpws-grid-shift-handoff") == relative,"plot identity preserves map colors before prediction catches a grid shift");
27 state.cells = originalCells;
28 for (int u = 28; u <= 34; ++u) for (int v = 28; v <= 34; ++v)
29 state.cells[u*63+v].severity = Severity::Caution;
30 state.terrain = Severity::Caution;
31 const auto caution = render("gpws-terrain-caution");
32 Check(caution != relative,"terrain caution must highlight its cells and label");
33 for (auto& cell : state.cells) if (cell.severity == Severity::Caution) cell.severity = Severity::Warning;
34 state.terrain = Severity::Warning;
35 const auto warning = render("gpws-terrain-warning");
36 Check(warning != caution,"terrain warning must replace yellow with red");
37
38 for (auto& cell : state.cells) cell.severity = Severity::None;
39 Obstacle tower; tower.topKm = 1; tower.severity = Severity::Warning;
40 const auto p = (gridarray[31][31].position+gridarray[32][32].position)*.5f;
41 for (int i = 0; i < 8; ++i) tower.corners[i] = {p.x+((i&1)?.01f:-.01f),p.y+((i&2)?.01f:-.01f),p.z+((i&4)?.01f:-.01f)};
42 state.obstacles.push_back(tower); state.terrain = Severity::None; state.obstacle = Severity::Warning;
43 const auto obstacle = render("gpws-obstacle-warning");
44 Check(obstacle != relative,"obstacle warning must render a distinct marker and label");
45 state.terrain = Severity::Warning; state.terrainTime = 20; state.obstacleTime = 19.999f;
46 const auto simultaneous = render("gpws-simultaneous-guide-priority");
47 Check(simultaneous != obstacle,"equal-severity terrain takes the guide-priority map label");
48 state.obstacleTime = 20.001f;
49 Check(render("gpws-simultaneous-time-jitter") == simultaneous,"predicted-time jitter cannot change the map label");
50 state.terrain = Severity::None;
52 Check(render("gpws-obstacle-over-assay") == obstacle,"active threat must override the assay map");
54 state.terrainComplete = false;
55 Check(render("gpws-data-limited") != obstacle,"unavailable coverage must be visible");
56 state.obstacle = Severity::None; state.obstacles.clear(); state.terrain = Severity::Caution;
57 for (auto& cell : state.cells) cell.topKm = .3f;
58 const auto terrainLimited = render("gpws-terrain-limited-no-backing");
59 state.terrainComplete = true; state.obstaclesComplete = false;
60 Check(render("gpws-obstacle-limited-with-backing") != terrainLimited,"only terrain-data status omits its black backing");
61 state.terrainComplete = state.obstaclesComplete = true;
62 state.altitudeKm = 5;
63 const auto peaks = render("gpws-peaks-high");
64 bus.GPWS.peaks = false;
65 const auto nonPeaks = render("gpws-nonpeaks-high");
66 Check(peaks != nonPeaks,"Peaks retains green terrain at high relative altitude");
67 bus.GPWS.peaks = true;
68 state.terrain = Severity::None;
69 Check(render("gpws-hazard-clear-restores-map") == baseline,"hazard clear restores ordinary map automatically");
70 state.terrain = Severity::Caution;
71 Check(render("gpws-popup") != baseline,"caution automatically selects terrain view");
72 bus.GPWS.inhibited = true;
73 Check(render("gpws-master-inhibit-normal-map") == baseline,"inhibit restores normal map and its status belongs to CAS");
74 bus.GPWS.inhibited = false; state.terrain = Severity::None;
75 bus.GPWS.mode5cancelled = true;
76 Check(render("gpws-gs-cancel-no-map-banner") == baseline,"GS cancel is CAS-only");
77 bus.GPWS.mode5cancelled = false;
79 const auto simultaneousTcas=render("gpws-popup-with-tcas");
81 Check(render("gpws-popup-after-tcas")==simultaneousTcas,"TCAS preserves relative terrain while its hazard is active");
82 state.terrain=Severity::None;
83 Check(render("gpws-both-hazards-clear")==baseline,"clearing both hazards restores ordinary map");
85 Check(render("gpws-mode6-no-warning-lamp") == baseline,"bank advisory does not light terrain warning display");
87 Check(render("gpws-reactive-pull-up") != baseline,"reactive warning label works without terrain selected");
88 bus.GPWS.Alert = Bus::Gpws::NoAlert; bus.GPWS.warningLamp = false;
89 bus.GPWS.faults = 1|4;
90 Check(render("gpws-input-faults") != baseline,"input failures are shown independently of terrain page");
91 bus.GPWS.faults = 0;
92 bus.GPWS.testLevel = 1; bus.GPWS.testPattern = bus.GPWS.warningLamp = true;
93 bus.GPWS.testLines = {L"EGPWS SELF TEST"};
94 Check(render("gpws-self-test-pattern") != baseline,"ground functional pattern and warning lamps render");
95 bus.GPWS.testPattern=bus.GPWS.warningLamp=false;
96 const auto testWithoutGs=render("gpws-self-test-no-gs-banner");
97 bus.GPWS.testStep=4;
98 Check(render("gpws-self-test-gs-step")==testWithoutGs,"self-test does not put GS CANCEL on the map");
99 bus.GPWS.testStep=0;
100 bus.GPWS.testLevel = 2; bus.GPWS.testPattern = bus.GPWS.warningLamp = false;
101 bus.GPWS.testLines = {L"RADIO ALTITUDE INOP",L"TERR DATA LIMITED"};
102 Check(render("gpws-fault-test") != baseline,"maintenance test renders detected fault list");
103 bus.GPWS.testLevel = 0; bus.GPWS.testLines.clear();
104 state.terrain = Severity::Warning;
105 playerships[0].isSimulator = true;
106 Check(render("gpws-simulator-baseline") == baseline,"simulator must retain baseline map despite stale awareness state");
107 playerships[0].isSimulator = false; state.Clear();
108}
109
110// Compare the authored PFD crop with an expanded crop of the same instrument.
111// Every new yellow glyph pixel must survive the actual screen's clipping.
112static void CheckGpwsPfdStatus(const std::filesystem::path& output, NativeUiTest11& fixture,
113 DeviceObject& device, Bus& bus, Logger& logger, const std::vector<Font*>& fonts)
114{
115 Displays display{&logger,&bus,&device}; display.fonts=fonts;
116 std::ifstream xml("Displays/E-11.xml"); Check(bool(xml),"E-11 PFD layout is unavailable");
117 std::string text((std::istreambuf_iterator<char>(xml)),{});
118 rapidxml::xml_document<> doc; doc.parse<0>(text.data());
119 auto* screens=doc.first_node("Displays")->first_node("Screens");
120 for (auto* screen=screens->first_node(); screen;)
121 {
122 auto* next=screen->next_sibling();
123 if (std::string(screen->first_attribute("name")->value())!="PFD") screens->remove_node(screen);
124 screen=next;
125 }
126 display.ConfigureScreens(screens); Check(display.screens.size()==1,"expected one authored PFD");
127 auto& screen=display.screens.front(); screen.bypassVdat=true;
128 const RECT crop=screen.rect;
129 const auto saved=bus.GPWS;
131 bus.MapScaleInnerRingKm=20;
132 screen.FrameMove(1); screen.FrameMove(1);
133 auto render=[&](bool clipped) {
134 screen.rect=crop; if (!clipped) screen.rect.bottom=512;
135 NativeUiTest11::HR(fixture.device.Clear(0,nullptr,Rendering::ClearFlags::TARGET,0,1,0));
136 NativeUiTest11::HR(fixture.device.BeginScene());
137 fixture.device.SetRenderState(Rendering::RenderState::ZENABLE,FALSE);
138 fixture.device.SetRenderState(Rendering::RenderState::STENCILENABLE,FALSE);
139 display.Render(); NativeUiTest11::HR(fixture.device.EndScene()); fixture.DebugClean();
140 return fixture.Pixels();
141 };
142 const auto baseline=render(false);
143 const char* cases[]={"gpws-inop","flap-override","steep-approach"};
144 for (int status=0; status<3; ++status)
145 {
146 bus.GPWS={};
147 bus.GPWS.faults=status==0 ? 1 : 0;
148 bus.GPWS.flapOverride=status==1;
149 bus.GPWS.steepApproach=status==2;
150 const auto expanded=render(false);
151 const auto actual=render(true);
152 fixture.Save(output/(std::string("e11-pfd-")+cases[status]+".png"),&crop);
153 int ink=0;
154 for (int y=0; y<512; ++y) for (int x=crop.left; x<crop.right; ++x)
155 {
156 const auto i=size_t(y)*1024+x;
157 if (expanded[i]==0xffffff00 && baseline[i]!=expanded[i])
158 {
159 ++ink;
160 Check(y>=crop.top && y<crop.bottom && actual[i]==expanded[i],
161 "GPWS status glyph is clipped by the authored PFD screen");
162 }
163 }
164 Check(ink>30,"GPWS status produced too few visible yellow glyph pixels");
165 }
166 bus.GPWS=saved;
167 std::cout<<"GPWS PFD: all three status labels fit the authored screen crop\n";
168}
Definition Bus.h:20
float MapScaleInnerRingKm
Definition Bus.h:490
@ Clear_Of_Conflict
Definition Bus.h:323
@ Traffic_Advisory
Definition Bus.h:324
struct Bus::Gpws GPWS
enum Bus::TcasEnum TCAS
std::vector< Font * > fonts
Definition Displays.h:25
std::vector< Screen > screens
Definition Displays.h:24
void Render()
Definition Displays.cpp:570
void ConfigureScreens(rapidxml::xml_node<> *xml_node)
Definition Displays.cpp:10
s_network_objects playerships[MAX_SCAN]
Definition globals.cpp:112
Scockpit ourcockpit
Definition globals.cpp:114
LOCALGRID2 gridarray[64][64]
Definition globals.cpp:100
constexpr uint32_t TARGET
constexpr uint32_t STENCILENABLE
constexpr uint32_t ZENABLE
bool inhibited
Definition Bus.h:250
bool warningLamp
Definition Bus.h:258
bool flapOverride
Definition Bus.h:250
int testStep
Definition Bus.h:260
@ Mode1_Pull_Up
Definition Bus.h:194
@ NoAlert
Definition Bus.h:190
@ Mode6_Bank_Angle
Definition Bus.h:228
bool peaks
Definition Bus.h:251
bool steepApproach
Definition Bus.h:250
unsigned faults
Definition Bus.h:259
std::vector< std::wstring > testLines
Definition Bus.h:263
bool mode5cancelled
Definition Bus.h:249
enum Bus::Gpws::GpwsEnum Alert
int testLevel
Definition Bus.h:260
bool testPattern
Definition Bus.h:261
TerrainAwareness::State terrain
Definition Bus.h:264
RiseMath::Vector3 position
Definition globals.h:273
VECTOR2SHORT tcp
Definition globals.h:290
bool remoteAssayPower
Definition globals.h:597
bool remoteAssayEquipped
Definition globals.h:669
float power
Definition globals.h:599
std::array< Point, 8 > corners