1#include "NativeUiTest11.h"
2#include "../Displays/Screen.h"
3#include <rapidxml.hpp>
4#include <cfloat>
5#include <codecvt>
6#include <fstream>
7#include <iostream>
8#include <locale>
9#include <regex>
10#include <unordered_map>
11
12
18{
if (level >=
Error)
throw std::runtime_error(text); }
29static int checks = 0;
30static void Check(bool pass, const char* message)
31{ ++checks; if (!pass) throw std::runtime_error(message); }
32
35{
36public:
37 std::vector<SClientPacket> requests;
39 { Check(size == sizeof(SClientPacket), "unexpected request"); requests.push_back(*static_cast<const SClientPacket*>(data)); }
40};
41struct Game { Bus* bus; Networking* networking; };
43{
44public:
48 VECTOR2SHORT
CalculateCGC(RiseMath::Vector3,
char)
const;
51 LOCALGRID2
CalculateSRV(
short,
short, VECTOR2SHORT,
char, SRenderVertex);
52};
54{
55public:
59 bool TryRadarSurface(
char face,
short u,
short v,
short& meters,
bool& water)
const;
61
62
63 bool TryElevation(
char face,
short u,
short v,
short& meters)
const;
67
76 void RemoveBuildZone(
short)
const {
throw std::runtime_error(
"fixture contains no buildings"); }
77};
78#include "ReplayGeometry.generated.h"
79#include "ReplayGrid.generated.h"
80struct RowReceiver
81{
82 struct HandlerGame { Viewscreen* viewscreen; } owner;
83 HandlerGame* game = &owner; char msg[999]{};
85 void Receive(const SRenderRow& row)
86 {
87 struct Packet { BYTE data[sizeof(SRenderRow)+1]; unsigned length = sizeof data; } storage;
88 memcpy(storage.data+1, &row, sizeof row); auto* packet = &storage;
89 switch (packet->length-1) {
90#include "ReplayRow.generated.h"
91 }
92 }
93};
95{
96public:
102};
103#include "E11Display.generated.h"
104
107static void FullGrid(
grid& terrain)
108{
109 auto packet = std::make_unique<SRenderGrid>(); packet->tcp = terrain.
requestedTcp;
110 for (
auto& column : packet->gridarray)
for (
auto& v : column) v =
Sample();
112
114}
115static void Respond(
const SClientPacket& request, RowReceiver& receiver)
116{
119 receiver.Receive(row);
120}
122{
125}
127{
130}
131struct Step { std::string time; int u, v; };
132static std::vector<Step> LoadSteps(const char* path, int& full, int& received)
133{
134 std::ifstream input(path); Check(bool(input), "player trace is unavailable");
135 std::regex moved(R"((\d\d:\d\d:\d\d\.\d+) GRID: Now \d,(-?\d+),(-?\d+))");
136 std::vector<Step> result; std::string line; std::smatch match;
137 while (std::getline(input,line)) {
138 full += line.find("GRID: Received SRenderGrid center") != std::string::npos;
139 received += line.find("NETWORK: Received 1.3 data edge") != std::string::npos;
140 if (std::regex_search(line,match,moved)) result.push_back({match[1],std::stoi(match[2]),std::stoi(match[3])});
141 }
142 return result;
143}
144static int ValidVertices()
145{
146 int count=0;
for (
const auto& column:
gridarray)
for (
const auto& v:column)
148 return count;
149}
150
151#include "RemoteAssayReplay.h"
152#include "TerrainHandoffReplay.h"
153#include "MovingMapLayerReplay.h"
154#include "TerrainAwarenessMapReplay.h"
155#include "TcasDisplayReplay.h"
156#include "GpwsMapPerformance.h"
157#include "WeatherRadarMapReplay.h"
158
159int main(
int argc,
char** argv)
160{
161 try {
162 Check(argc>=2,"usage: MovingMapReplayTests <output-directory> [player-trace] [--warp] [--benchmark]");
163 bool warp=false,benchmark=false;const char* trace=nullptr;
164 for(int i=2;i<argc;++i)if(!strcmp(argv[i],"--warp"))warp=true;else if(!strcmp(argv[i],"--benchmark"))benchmark=true;else {Check(!trace,"unexpected argument");trace=argv[i];}
165 const std::filesystem::path
output=argv[1]; std::filesystem::create_directories(output);
166 NativeUiTest11 fixture(1024,512,warp,!benchmark);
Logger logger;
167 auto busStorage = std::make_unique<Bus>(&logger); auto& bus = *busStorage;
169 Displays display{&logger,&bus,&device};
170 std::ifstream xml("Displays/E-11.xml"); Check(bool(xml),"E-11 layout is unavailable");
171 std::string text((std::istreambuf_iterator<char>(xml)),{}); rapidxml::xml_document<> doc; doc.parse<0>(text.data());
172 auto*
root=doc.first_node(
"Displays");
173 for(
auto* font=
root->first_node(
"Fonts")->first_node();font;font=font->next_sibling())
174 display.
fonts.push_back(
new Font(&logger,&fixture.device,atoi(font->first_attribute(
"width")->value()),atoi(font->first_attribute(
"height")->value()),font->first_attribute(
"name")->value(),font->value()));
175
176 auto* screens=
root->first_node(
"Screens");
177 for(auto* screen=screens->first_node();screen;) {
178 auto* next=screen->next_sibling();
179 if(std::string(screen->first_attribute("name")->value())!="MFD") screens->remove_node(screen);
180 else for(auto* page=screen->first_node();page;) {
181 auto* nextPage=page->next_sibling();
182 if(std::string(page->first_attribute("name")->value())!="Navigation") screen->remove_node(page);
183 page=nextPage;
184 }
185 screen=next;
186 }
188 auto& screen=display.
screens.front(); Check(screen.pages.front().instruments.size()==3,
"missing navigation instrument");
189 screen.bypassVdat=true;
190 bus.MapScaleInnerRingKm=20; bus.HeadingTrueDegrees=bus.HeadingTrackDegrees=167; bus.AFCS.DesiredHeadingRadians=
RiseMath::ToRadian(167);
191 bus.AFCS.DesiredRadians=
RiseMath::ToRadian(167); bus.PressureAltitudeKm=.406f; bus.RadioAltitudeKm=.3148f;
192 bus.LatitudeDeg=5.413f; bus.LongitudeDeg=-26.359f; bus.LinearVelocityKms=.389f; bus.NormalAcceleration.y=1.3f;
193 bus.AFCS.TvmCurrentClosingSpeed=.102f; bus.WindSpeedMs=2; bus.WindDirectionDegrees=136;
196 for(
int u=0;u<63;++u)
for(
int v=0;v<63;++v)
visiblegrid[u][v]=(u-31)*(u-31)+(v-31)*(v-31)<=1024;
198 if (benchmark)
199 {
200 Check(!trace,"benchmark does not consume a player trace");
201 BenchmarkGpwsMap(output,fixture,device,bus,logger,display.
fonts,view,terrain);
202 for(
auto* font:display.
fonts){font->OnDestroyDevice();
delete font;}
203 return 0;
204 }
205 RowReceiver receiver; receiver.owner.viewscreen=&view;
206 CheckTerrainHandoff(view,terrain,network,receiver);
208 std::cout<<
"Screenshot: face="<<
int(terrain.
cube)<<
" tcp="<<
target.u<<
','<<
target.v<<
" heading=167 inner-ring=20km\n";
209 std::vector<Step> steps; int full=0, received=0;
210 if(trace) steps=LoadSteps(trace,full,received);
211 else {
212 steps={{"synthetic",508,1107},{"synthetic",508,1108},{"synthetic",509,1108}};
213 int u=509;
214 for(int v=1109;v<=1135;++v) {
215 steps.push_back({"synthetic",u,v});
216 if(v==1111 || v==1115 || v==1118 || v==1122 || v==1126 || v==1130 || v==1134)
217 steps.push_back({"synthetic",++u,v});
218 }
219 }
220 Check(!steps.empty(),"no movement in replay");
221 std::ofstream metrics(output/"replay.csv"); metrics<<"case,time,u,v,pending,valid_vertices\n";
222 std::vector<DWORD> healthy,missing;
223 auto render=[&](const std::string& name,bool elements=true,bool hostileStencil=false) {
224
225 screen.FrameMove(1.f); screen.FrameMove(1.f); auto* d=&fixture.device;
230 std::vector<Element> saved; if(!elements) saved.swap(screen.pages.front().elements);
231 display.
Render();
if(!elements) saved.swap(screen.pages.front().elements);
232 NativeUiTest11::HR(d->EndScene()); fixture.DebugClean(); fixture.Save(output/(name+".png"),&screen.rect);
233 auto pixels=fixture.Pixels(); bool clipped=true;
234 for(int y=0;y<512;++y) for(int x=0;x<1024;++x)
235 if(x<screen.rect.left || x>=screen.rect.right || y<screen.rect.top || y>=screen.rect.bottom)
236 clipped &= pixels[size_t(y)*1024+x]==0;
237 Check(clipped,"MFD drawing escaped its authored screen rectangle"); return pixels;
238 };
239 auto initialize=[&] {
241 };
242 for(bool deliver:{false,true}) {
243 initialize(); bool captured=false;
244 for(const auto& step:steps) {
246 Check(terrain.
tcp.
u==step.u && terrain.
tcp.
v==step.v,
"coordinate replay mismatch");
247 Check(network.requests.size()==before+1,"movement failed to request an edge");
248 if(deliver) Respond(network.requests.back(),receiver);
249 metrics<<(deliver?
"delivered":
"withheld")<<
','<<step.time<<
','<<step.u<<
','<<step.v<<
','<<
int(terrain.
dataPending)<<
','<<ValidVertices()<<
'\n';
250 if(deliver) Check(ValidVertices()==4096,"on-time rows left terrain missing");
253 if(deliver) healthy=render("e11-rows-delivered"); else missing=render("e11-rows-withheld");
254 captured=true;
255 }
256 }
257 Check(captured,"route does not reach the screenshot's grid position");
258 render(deliver?"e11-session-end-delivered":"e11-session-end-withheld");
259 if(!deliver) Check(terrain.
dataPending==
int(steps.size()),
"outage did not accumulate all requests");
260 else Check(terrain.
dataPending==0,
"delivered sequence still pending");
261 }
262
264 auto complete=render("e11-complete-grid"); auto stencil=render("e11-inherited-stencil",true,true);
265 Check(complete==stencil,"inherited stencil changed MFD rendering"); render("e11-instrument-only",false);
266 if(!healthy.empty()) Check(healthy==complete,"streamed grid differs from fresh full grid");
267 if(!missing.empty()) {
268 unsigned lost=0;
269 for(int y=screen.y+35;y<screen.y+145;++y) for(int x=screen.x+25;x<screen.x+255;++x) {
270 auto a=complete[size_t(y)*1024+x],b=missing[size_t(y)*1024+x];
271 if((a&0xffffff)>0x303030 && (b&0xffffff)==0) ++lost;
272 }
273 std::cout<<"Screenshot comparison: "<<lost<<" terrain pixels become black when rows are withheld\n";
274 Check(lost>100,"withheld rows did not reproduce the forward gap");
275 }
276 if(trace) std::cout<<"Trace: "<<full<<" whole grids, "<<steps.size()<<" movement requests, "<<received<<" row receipts\n";
277 CheckTerrainAwarenessMap(bus,render);
278 CheckTcasDisplayOnMap(bus,render);
279 CheckWeatherRadarMap(bus,render);
280
282 bus.assayGrid={}; bus.assayGrid.tcp=
target; bus.assayGrid.gridarray[0][0].padding=0xA0;
283 for(auto& column:bus.assayGrid.gridarray) for(auto& cell:column) {cell.oreC=100;cell.oreD=12;}
284 bus.assayQuality=1; bus.RadioAltitudeKm=.65f; bus.MapScaleInnerRingKm=5;
285 render("e11-assay-self-test");
286 screen.FrameMove(16); render("e11-assay-max-scanned");
287
288
289 {
291 std::ifstream a4Xml("Displays/A-4.xml"); Check(bool(a4Xml),"A-4 layout is unavailable");
292 std::string a4Text((std::istreambuf_iterator<char>(a4Xml)),{});
293 rapidxml::xml_document<> a4Doc; a4Doc.parse<0>(a4Text.data());
294 auto* a4Screens=a4Doc.first_node("Displays")->first_node("Screens");
295 for(auto* item=a4Screens->first_node();item;) {
296 auto* next=item->next_sibling();
297 if(std::string(item->first_attribute("name")->value())!="EICAS2") a4Screens->remove_node(item);
298 item=next;
299 }
301 auto& a4Screen=a4.
screens.front(); a4Screen.bypassVdat=
true;
303 bus.TCASTestActive=true; bus.TCASTestCallout=9;
305 NativeUiTest11::HR(fixture.device.BeginScene());
306 a4.
Render(); NativeUiTest11::HR(fixture.device.EndScene()); fixture.DebugClean();
307 fixture.Save(output/"a4-tcas-display-test.png",&a4Screen.rect);
308 bus.TCASTestActive=false; bus.TCASTestCallout=-1;
309 for(bool testing:{true,false}) {
310 a4Screen.FrameMove(testing?1.f:16.f);
312 NativeUiTest11::HR(fixture.device.BeginScene());
313 a4.
Render(); NativeUiTest11::HR(fixture.device.EndScene()); fixture.DebugClean();
314 fixture.Save(output/(testing?"a4-assay-self-test.png":"a4-assay-max-scanned.png"),&a4Screen.rect);
315 }
316 auto renderA4Weather=[&](const std::string& name,bool elements=true,bool hostileStencil=false) {
317 a4Screen.FrameMove(1); a4Screen.FrameMove(1);
319 NativeUiTest11::HR(fixture.device.BeginScene());
323 a4.
Render(); NativeUiTest11::HR(fixture.device.EndScene()); fixture.DebugClean();
324 fixture.Save(output/("a4-"+name+".png"),&a4Screen.rect);
325 return fixture.Pixels();
326 };
327 CheckWeatherRadarMap(bus,renderA4Weather);
329 }
330 CheckRemoteAssayReadout(output,fixture,device,bus,logger,display.
fonts);
331 CheckRemoteAssay(output,fixture,device,bus,logger,display.
fonts);
332 CheckMapLayers(output,fixture,device,bus,logger,display.
fonts,view,terrain);
333 CheckTcasDisplayRendering(fixture,device,bus,logger,display.
fonts);
334 CheckGpwsPfdStatus(output,fixture,device,bus,logger,display.
fonts);
335 std::cout<<"PASS "<<checks<<" E-11 MovingMap/Screen checks; native D3D11 debug layer clean\n";
336 for(
auto* font:display.
fonts){font->OnDestroyDevice();
delete font;}
337 return 0;
338 } catch(const std::exception& error) {std::cerr<<"FAIL: "<<error.what()<<'\n';return 1;}
339}
SCRIPT_CONTROL SCRIPT_STATE const void int
void AddCommand(const Command &command, bool onlyOne)
std::vector< Command > commandStream
std::vector< Font * > fonts
std::vector< Screen > screens
unsigned int deviceGeneration
void ConfigureScreens(rapidxml::xml_node<> *xml_node)
Font(Logger *pLogger, Rendering::RenderDevice *pDevice, int width, int height, std::string name, std::string prmPathAndFilename)
void Log(const char *msg, Level level=Info, int errorCode=0)
void AddToCallStack(const char *msg)
void SendToServer(void *pData, DWORD dwSize, bool bGuaranteed, PacketOrdering order=ORDERING_NONE) const
std::unique_ptr< grid > ptrGrid
VECTOR2SHORT CalculateCGC(RiseMath::Vector3 position, char cube) const
VECTOR2SHORT CalculateWrap(short u, short v, char cube, char *rotate) const
LOCALGRID2 CalculateSRV(short t, short s, VECTOR2SHORT tcp, char cube, SRenderVertex sourcedata)
RiseMath::Vector3 CalculatePlanar(short u, short v)
char CalculateCube(RiseMath::Vector3 position) const
VECTOR2SHORT requestedTcp
uint64_t ElevationRevision() const
bool InterpolateElevation(char face, double u, double v, float &meters) const
grid(Viewscreen *ptrGame)
std::unordered_map< uint32_t, SurfacePoint > elevationByPlot
void ElevationChanged() const
void ReceiveWholeGrid(const SRenderGrid &datapacket)
void CalculateInsideArray(short t, short s) const
void CalculateCubeAndTcp()
uint64_t elevationRevision
void Trace(const char *msg, Logger::Level severity=Logger::Level::Info) const
bool TryElevation(char face, short u, short v, short &meters) const
bool TryRadarSurface(char face, short u, short v, short &meters, bool &water) const
void RemoveBuildZone(short ordinal) const
void PrepareForReposition()
bool resetWeatherOnNextGrid
bool InterpolateRadarSurface(char face, double u, double v, float &meters, float &waterFraction) const
uint64_t elevationIndexRevision
s_network_objects playerships[MAX_SCAN]
RiseMath::Vector3 insidearray[63][63][3]
LOCALGRID2 gridarray[64][64]
Vector Position(int cube, int u, int v, float radius)
SRenderWeather Sample(const unsigned char *p)
constexpr uint32_t TARGET
constexpr uint32_t ZBUFFER
constexpr uint32_t STENCIL
constexpr uint32_t STENCILFUNC
constexpr uint32_t STENCILENABLE
constexpr uint32_t ZENABLE
float Vec3LengthSq(const Vector3 *a)
Vector3 * Vec3Normalize(Vector3 *out, const Vector3 *a)
@ Game
Use the game audio system.
SRenderVertex gridarray[64]
unsigned char pri_landform
RiseMath::Vector3 position