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

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

1// Render the production TCAS overlay, including the transponder-off ground test.
2#include "../TcasAudio.h"
3
4template<class Render> static void CheckTcasDisplayOnMap(Bus& bus, Render render)
5{
6 const bool transponder = playerships[0].transponder;
7 playerships[0].transponder = false;
8 const auto baseline = render("tcas-normal-map");
9 bus.TCASTestActive = true;
10 bus.TCASTestCallout = -1;
11 const auto symbols = render("tcas-display-check");
12 Check(symbols != baseline, "TCAS test must appear with transponder off");
13 auto previous = symbols;
14 for (int callout = 0; callout < TcasAudio::Count; ++callout)
15 {
16 bus.TCASTestCallout = callout;
17 const auto current = render("tcas-test-" + std::to_string(callout));
18 Check(current != previous, "every TCAS phrase must update the actual navigation display");
19 previous = current;
20 }
21 bus.TCASTestActive = false; // Even a stale phrase index must not retain test imagery.
22 Check(render("tcas-test-cancelled") == baseline, "TCAS cancellation must restore the original map exactly");
23 bus.TCASTestCallout = -1;
24 playerships[0].transponder = transponder;
25}
26
27static void CheckTcasMapDeclutter(NativeUiTest11& fixture, DeviceObject& device,
28 Bus& bus, Logger& logger, const std::vector<Font*>& fonts)
29{
30 const auto savedGpws=bus.GPWS;
31 const auto savedWaypoints=bus.waypoint;
32 const auto savedMode=bus.TCAS;
33 const bool savedTest=bus.TCASTestActive,savedArena=playerships[0].battleRoyale;
34 const bool savedAssay=ourcockpit.remoteAssayPower,savedEquipped=ourcockpit.remoteAssayEquipped;
35 const auto savedPower=ourcockpit.power;
36 const float savedAltitude=bus.PressureAltitudeKm,savedRange=bus.MapScaleInnerRingKm;
37 const auto savedCenter=bus.BattleRoyaleRingCenter;
38 const float savedRing=bus.BattleRoyaleRingKm;
39 bus.GPWS={};bus.waypoint.clear();bus.TCAS=Bus::Clear_Of_Conflict;bus.TCASTestActive=false;
42 MovingMap map(32,32,.468f,.468f,&bus,&logger,&device,fonts);
43 auto draw=[&] {
44 map.FrameMove(1);map.FrameMove(1);
45 NativeUiTest11::HR(fixture.device.Clear(0,nullptr,Rendering::ClearFlags::TARGET,0xff000000,1,0));
46 NativeUiTest11::HR(fixture.device.BeginScene());
47 fixture.device.SetRenderState(Rendering::RenderState::ZENABLE,FALSE);
48 fixture.device.SetRenderState(Rendering::RenderState::STENCILENABLE,FALSE);
49 fixture.device.SetRenderState(Rendering::RenderState::SCISSORTESTENABLE,FALSE);
50 NativeUiTest11::HR(device.pSprite->Begin(Rendering::SpriteFlags::AlphaBlend |
52 map.Render();NativeUiTest11::HR(device.pSprite->End());
53 NativeUiTest11::HR(fixture.device.EndScene());fixture.DebugClean();return fixture.Pixels();
54 };
55 // Altitude hides the surface fill independently of TCAS, giving a reference
56 // that can prove every other layer survives the test/advisory transitions.
57 const auto compassOnly=draw();
58 Check(std::any_of(compassOnly.begin(),compassOnly.end(),[](DWORD p){return p!=0xff000000;}),
59 "TCAS declutter reference must retain the compass and heading cues");
60 for(unsigned type=0;type<4;++type)
61 {
63 wp.uniqueid=type==1 ? 371 : 100+type;wcscpy_s(wp.text,L"AIRPORT LABEL");bus.waypoint.push_back(wp);
64 }
66 const auto navigationOnly=draw();
67 Check(navigationOnly!=compassOnly,"reference must contain waypoint symbols, labels, airspace and arena");
69 for(const bool assay : {false,true})
70 {
72 map.FrameMove(16); // Compare the steady assay display, past its own startup test.
74 const auto withoutSurface=draw();
75 Check(assay ? withoutSurface!=navigationOnly : withoutSurface==navigationOnly,
76 "reference must preserve the assay overlay when powered");
77 bus.PressureAltitudeKm=.4f;
78 const auto normal=draw();
79 Check(assay ? normal==withoutSurface : normal!=withoutSurface,
80 "normal surface fill must be visible unless replaced by assay");
81 for(int mode=-1;mode<=int(Bus::RA_Adjust);++mode)
82 {
83 if(mode==0)continue;
84 bus.TCASTestActive=mode==-1;
85 bus.TCAS=mode==-1 ? Bus::Clear_Of_Conflict : static_cast<Bus::TcasEnum>(mode);
86 Check(draw()==withoutSurface,
87 "TCAS test, TA and every RA must omit only surface fill, preserving all overlays");
88 }
90 Check(draw()==withoutSurface,"TCAS test over an RA must preserve overlays without surface fill");
91 bus.TCASTestActive=false;
92 Check(draw()==withoutSurface,"ending a test cannot restore surface fill during an RA");
94 Check(draw()==normal,"clear of conflict must restore surface fill without changing overlays");
95 }
98 Check(draw()!=navigationOnly,"TCAS declutter must preserve the GPWS warning annunciation");
100 auto& terrain=bus.GPWS.terrain;
101 terrain.enabled=terrain.terrainComplete=terrain.obstaclesComplete=true;
102 terrain.altitudeKm=.8f;terrain.terrain=TerrainAwareness::Severity::Caution;
103 for(int u=0;u<63;++u)for(int v=0;v<63;++v)
104 {
105 auto& cell=terrain.cells[u*63+v];
106 cell.valid=true;cell.u=gridarray[u][v].tcp.u;cell.v=gridarray[u][v].tcp.v;
107 cell.topKm=.1f+float((u+v)%8)*.2f;
108 }
109 const auto relative=draw();
110 Check(relative!=navigationOnly,"GPWS must display relative terrain when a hazard is active");
111 unsigned navigationInk=0;
112 for(size_t i=0;i<navigationOnly.size();++i)
113 if(navigationOnly[i]==0xffffffff && compassOnly[i]!=navigationOnly[i])
114 {
115 ++navigationInk;
116 Check(relative[i]==navigationOnly[i],"GPWS relative terrain must retain navigation glyphs");
117 }
118 Check(navigationInk>30,"GPWS overlay check needs visible navigation glyphs");
119 for(int mode=-1;mode<=int(Bus::RA_Adjust);++mode)
120 {
121 if(mode==0)continue;
122 bus.TCASTestActive=mode==-1;
123 bus.TCAS=mode==-1 ? Bus::Clear_Of_Conflict : static_cast<Bus::TcasEnum>(mode);
124 Check(draw()==relative,"TCAS must preserve GPWS relative terrain, peaks and navigation overlays");
125 }
126 terrain.terrain=TerrainAwareness::Severity::None;
127 Check(draw()==navigationOnly,"clearing GPWS during an RA leaves navigation with no surface fill");
129 Check(draw()!=navigationOnly,"clearing both hazards restores the surface map");
130 bus.GPWS=savedGpws;bus.waypoint=savedWaypoints;bus.TCAS=savedMode;bus.TCASTestActive=savedTest;
131 playerships[0].battleRoyale=savedArena;ourcockpit.remoteAssayPower=savedAssay;
132 ourcockpit.remoteAssayEquipped=savedEquipped;ourcockpit.power=savedPower;
133 bus.PressureAltitudeKm=savedAltitude;bus.MapScaleInnerRingKm=savedRange;
134 bus.BattleRoyaleRingCenter=savedCenter;bus.BattleRoyaleRingKm=savedRing;
135 std::cout<<"TCAS surface declutter: self-test, TA, all RAs, navigation/assay preservation, restoration and simultaneous GPWS terrain passed\n";
136}
137
138static void CheckTcasDisplayRendering(NativeUiTest11& fixture, DeviceObject& device,
139 Bus& bus, Logger& logger, const std::vector<Font*>& fonts)
140{
141 TCASOverlay overlay(32,32,.468f,.468f,&bus,&logger,&device,fonts);
142 const bool transponder = playerships[0].transponder;
143 playerships[0].transponder = false;
144 const float mapScale = bus.MapScaleInnerRingKm;
145 bus.MapScaleInnerRingKm = 0; // Test presentation must not depend on map projection/range.
146 auto begin = [&] {
147 NativeUiTest11::HR(fixture.device.Clear(0,nullptr,Rendering::ClearFlags::TARGET,0xff000000,1,0));
148 NativeUiTest11::HR(fixture.device.BeginScene());
149 fixture.device.SetRenderState(Rendering::RenderState::ZENABLE,FALSE);
150 fixture.device.SetRenderState(Rendering::RenderState::STENCILENABLE,FALSE);
151 fixture.device.SetRenderState(Rendering::RenderState::SCISSORTESTENABLE,FALSE);
152 NativeUiTest11::HR(device.pSprite->Begin(Rendering::SpriteFlags::AlphaBlend |
154 };
155 auto end = [&] {
156 NativeUiTest11::HR(device.pSprite->End());
157 NativeUiTest11::HR(fixture.device.EndScene());
158 fixture.DebugClean(); return fixture.Pixels();
159 };
160 const int cx = 32 + int(265*.468f), top = 32 + int(265*.468f) - 84;
161 auto compareText = [&](const std::vector<DWORD>& actual, const wchar_t* text, int atX, int atY, DWORD color, bool centered) {
162 begin(); RiseMath::Matrix identity; RiseMath::MatrixIdentity(&identity);
163 NativeUiTest11::HR(device.pSprite->SetTransform(&identity));
164 RECT rect = {atX,atY,atX,atY};
165 NativeUiTest11::HR(fonts[1]->pFont->DrawTextW(device.pSprite,text,-1,&rect,
166 DT_NOCLIP | (centered ? DT_CENTER : 0),color));
167 const auto expected = end(); int solid = 0;
168 for (int py = atY; py < atY+13; ++py) for (int px = cx-64; px < cx+64; ++px)
169 if (expected[size_t(py)*1024+px] == color)
170 {
171 ++solid;
172 Check(actual[size_t(py)*1024+px] == color, "TCAS test text, altitude or trend glyph is missing/obscured");
173 }
174 Check(solid > 0, "TCAS expected text produced no solid glyph pixels");
175 };
176 const wchar_t* instruction[] = {L"TRAFFIC",L"CLIMB",L"DESCEND",L"INCREASE CLIMB",L"INCREASE DESCENT",
177 L"REDUCE CLIMB",L"REDUCE DESCENT",L"CLIMB NOW",L"DESCEND NOW",L"MAINTAIN VERTICAL SPEED",
178 L"ADJUST VERTICAL SPEED",L"MONITOR VERTICAL SPEED",L"CROSSING",L"CLEAR OF CONFLICT",L"TCAS SYSTEM TEST OK"};
179 bus.TCASTestActive = true;
180 for (int callout = 0; callout < 15; ++callout)
181 {
182 bus.TCASTestCallout = callout;
183 // Deliberately omit FrameMove: opening a new page must show the current test immediately.
184 begin(); overlay.Render(); const auto actual = end();
185 compareText(actual,L"TCAS TEST",cx,top+7,0xffffffff,true);
186 compareText(actual,instruction[callout],cx,top+21,
187 callout == 0 ? 0xffffaa00 : callout < 13 ? 0xffff0000 : 0xffffffff,true);
188 compareText(actual,L"05",cx-51,top+54,0xff0088ff,false);
189 compareText(actual,L"01",cx-21,top+74,0xff0088ff,false);
190 compareText(actual,L"02\u2191",cx+9,top+54,0xffffaa00,false);
191 compareText(actual,L"02\u2193",cx+39,top+74,0xffff0000,false);
192 const int offsets[] = {-51,-21,9,39};
193 for (int symbol = 0; symbol < 4; ++symbol)
194 {
195 int ink = 0;
196 for (int py = top+64; py < top+73; ++py)
197 for (int px = cx+offsets[symbol]; px < cx+offsets[symbol]+13; ++px)
198 {
199 // The antialiased texture has gray source pixels; its tint is
200 // not necessarily a full-intensity label color after minification.
201 const DWORD pixel = actual[size_t(py)*1024+px];
202 const int r = (pixel >> 16)&255, g = (pixel >> 8)&255, b = pixel&255;
203 ink += symbol < 2 ? b > r+20 && b > g :
204 symbol == 2 ? r > g && g > b+20 : r > g+20 && r > b+20;
205 }
206 Check(ink > 0, "one of the four TCAS test symbols is absent or has the wrong color");
207 }
208 }
209 bus.TCASTestActive = false; bus.TCASTestCallout = -1;
210 overlay.FrameMove(.1f); begin(); overlay.Render(); const auto cleared = end();
211 Check(std::all_of(cleared.begin(),cleared.end(),[](DWORD p) { return p == 0xff000000; }),
212 "cancelled test leaves no symbols or text in the overlay");
213 const auto savedTarget = playerships[1];
214 const auto savedMode = bus.TCAS;
215 const auto savedOrdinal = bus.TCASTargetOrdinal;
216 auto& target = playerships[1]; target = {};
217 target.active = target.visible = target.isOnScanner = target.logolight = target.transponder = true;
218 target.reference = REF_ACLMODE; target.type = VehicleType::E10;
219 target.position = playerships[0].position * 1.00001f;
220 target.distance = .1f; target.altitudeDiffAbs = .1f;
221 playerships[0].transponder = true; bus.MapScaleInnerRingKm = 20;
223 overlay.FrameMove(1); begin(); overlay.Render(); const auto live = end();
224 Check(live != cleared, "live traffic must render outside test mode");
225 bus.TCASTestActive = true; bus.TCASTestCallout = 1;
226 overlay.FrameMove(1); begin(); overlay.Render(); end();
227 Check(target.active && bus.TCAS == Bus::Traffic_Advisory && bus.TCASTargetOrdinal == 1,
228 "test rendering cannot change scanner or advisory state");
229 bus.TCASTestActive = false; bus.TCASTestCallout = -1;
230 begin(); overlay.Render();
231 Check(end() == live, "test exit immediately restores the real target depiction");
232 bus.TCASTestActive = true;
233 target.active = false; overlay.FrameMove(1);
234 bus.TCASTestActive = false; begin(); overlay.Render();
235 Check(end() == cleared, "traffic lost during testing must not reappear when testing ends");
236 playerships[1] = savedTarget; bus.TCAS = savedMode; bus.TCASTargetOrdinal = savedOrdinal;
237 bus.MapScaleInnerRingKm = mapScale;
238 playerships[0].transponder = transponder;
239 CheckTcasMapDeclutter(fixture,device,bus,logger,fonts);
240 std::cout << "TCAS display: all phrases, four symbols, altitude/trend glyphs, page entry and cancellation passed\n";
241}
SCRIPT_CONTROL SCRIPT_STATE const void int
SCRIPT_CONTROL SCRIPT_STATE const void DWORD
@ E10
Definition ServerTypes.h:63
@ REF_ACLMODE
Definition ServerTypes.h:44
Definition Bus.h:20
float MapScaleInnerRingKm
Definition Bus.h:490
float PressureAltitudeKm
Definition Bus.h:31
short TCASTargetOrdinal
Definition Bus.h:339
int TCASTestCallout
Definition Bus.h:342
TcasEnum
Definition Bus.h:322
@ Clear_Of_Conflict
Definition Bus.h:323
@ Traffic_Advisory
Definition Bus.h:324
@ RA_Climb
Definition Bus.h:325
@ RA_Adjust
Definition Bus.h:337
struct Bus::Gpws GPWS
bool TCASTestActive
Definition Bus.h:341
std::vector< Swaypoint > waypoint
Definition Bus.h:500
float BattleRoyaleRingKm
Definition Bus.h:532
RiseMath::Vector3 BattleRoyaleRingCenter
Definition Bus.h:531
enum Bus::TcasEnum TCAS
Rendering::RenderSprite * pSprite
HRESULT Begin(DWORD flags)
HRESULT SetTransform(const RiseMath::Matrix *value)
s_network_objects playerships[MAX_SCAN]
Definition globals.cpp:112
Scockpit ourcockpit
Definition globals.cpp:114
LOCALGRID2 gridarray[64][64]
Definition globals.cpp:100
#define cloudBufferMslC
Definition globals.h:111
constexpr uint32_t TARGET
constexpr uint32_t STENCILENABLE
constexpr uint32_t SCISSORTESTENABLE
constexpr uint32_t ZENABLE
constexpr DWORD AlphaBlend
constexpr DWORD SortTexture
constexpr DWORD SortBackToFront
Matrix * MatrixIdentity(Matrix *out)
Definition ClientMath.h:115
constexpr int Count
Definition TcasAudio.h:36
type
Definition erin.py:143
bool warningLamp
Definition Bus.h:258
@ Mode1_Pull_Up
Definition Bus.h:194
@ NoAlert
Definition Bus.h:190
enum Bus::Gpws::GpwsEnum Alert
TerrainAwareness::State terrain
Definition Bus.h:264
VECTOR2SHORT tcp
Definition globals.h:290
bool remoteAssayPower
Definition globals.h:597
bool remoteAssayEquipped
Definition globals.h:669
float power
Definition globals.h:599
short heading
unsigned char type
float length
RiseMath::Vector3 location
WCHAR text[64]
RiseMath::Vector3 position
Definition globals.h:511