1#include "NativeUiTest11.h"
2#include "../Instruments/Instrument.h"
3#include <iostream>
4
5
6
12{
if (level >=
Error)
throw std::runtime_error(text); }
18
19static void Check(bool pass, const char* message)
20{ if (!pass) throw std::runtime_error(message); }
21static bool Inside(
int x,
int y,
const RECT& rect)
22{ return x >= rect.left && x < rect.right && y >= rect.top && y < rect.bottom; }
23
24int main(
int argc,
char** argv)
25{
26 try {
27 Check(argc == 2, "usage: CdiReplayTests <output-directory>");
28 const std::filesystem::path
output = argv[1];
29 std::filesystem::create_directories(output);
30 NativeUiTest11 fixture(137,137);
Logger logger;
Bus bus(&logger);
32
34 Sprite surround(&logger,&device,
"Textures/Instruments/flatdelta.png",0,0,.9f,0,0,137,137,0xffffffff);
36 bus.TargetBearingDeg = 999;
37 auto render = [&](const char* name, float loc, float gs) {
40 attitude.FrameMove(1);
41 auto& d = fixture.device;
43 NativeUiTest11::HR(d.BeginScene());
46 RECT clip{0,0,137,137}; device.SetScissorRect(&clip);
49 surround.Draw(); attitude.Render();
50 NativeUiTest11::HR(device.pSprite->End());
51 NativeUiTest11::HR(d.EndScene()); fixture.DebugClean();
52 fixture.Save(output/(std::string(name)+".png"));
53 return fixture.Pixels();
54 };
55 const auto absent = render("a4-cdi-absent",999,999);
56 const auto centered = render("a4-cdi-centered",0,0);
57 const auto negative = render("a4-cdi-negative",-2.49f,-.69f);
58 const auto positive = render("a4-cdi-positive",2.49f,.69f);
59 const auto flagged = render("a4-cdi-flags",3,1);
60
61
62 const RECT localizer{51,105,82,111}, glideslope{94,54,100,87};
63 int locPixels=0, gsPixels=0;
64 for (const auto* pixels : {¢ered,&negative,&positive,&flagged}) {
65 for (int y=0;y<137;++y) for (int x=0;x<137;++x) {
66 const size_t i=size_t(y)*137+x;
67 if ((*pixels)[i]==absent[i]) continue;
68 const bool loc=
Inside(x,y,localizer), gs=
Inside(x,y,glideslope);
69 Check(loc || gs,"CDI rendering extends past its scale (stretched texture border)");
70 locPixels+=loc; gsPixels+=gs;
71 }
72 }
73 Check(locPixels>40 && gsPixels>40,"missing CDI scales");
74
75 for (const RECT& rect : {localizer,glideslope}) {
76 int leftChanges=0,rightChanges=0;
77 for (int y=rect.top;y<rect.bottom;++y) for (int x=rect.left;x<rect.right;++x) {
78 const size_t i=size_t(y)*137+x;
79 leftChanges+=negative[i]!=centered[i];
80 rightChanges+=positive[i]!=centered[i];
81 }
82 Check(leftChanges>3 && rightChanges>3,"CDI bug did not move with deviation");
83 }
84 Check(render("a4-cdi-signal-lost",999,999)==absent,"CDI remains after signal loss");
85 std::cout<<"PASS: A-4 CDI bounds, centered/negative/positive deviation, flags and signal loss; D3D11 debug layer clean\n";
86 return 0;
87 } catch (const std::exception& error) {
88 std::cerr<<"FAIL: "<<error.what()<<'\n'; return 1;
89 }
90}
void AddCommand(const Command &command, bool onlyOne)
std::vector< Command > commandStream
void Log(const char *msg, Level level=Info, int errorCode=0)
void AddToCallStack(const char *msg)
s_network_objects playerships[MAX_SCAN]
constexpr uint32_t TARGET
constexpr uint32_t SCISSORTESTENABLE
constexpr uint32_t ZENABLE
constexpr DWORD AlphaBlend
constexpr DWORD SortTexture
constexpr DWORD SortBackToFront
bool Inside(Vec p, const Triangle &t)