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

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

1// Replay production CalculateAGLd plus the frame's independent grid publication.
2// No window, rendering device, physics controller, or network is needed.
3#include "../Rendering/ClientMath.h"
4namespace RoutePositionTest
5{
6struct Cell { short u=0, v=0; };
7struct MapBus { Cell tcp; float assayProgressU=0, assayProgressV=0; };
8struct Game { MapBus* bus; bool timeLapse=false; };
9struct Grid { Cell tcp; };
10struct Vertex { RiseMath::Vector3 position; Cell tcp; };
11static Vertex gridarray[33][33];
12static RiseMath::Vector3 insidearray[33][33][3];
13struct Logger {
14 enum Level { Warn };
15 void AddToCallStack(const char*) {}
16 void Log(const char*, Level) {}
17};
18struct Viewscreen {
19 Game* gameclass;
20 Grid* ptrGrid;
21 Logger* logger;
22 RiseMath::Vector3 leveler;
23 char area[3]{}, msg[999]{};
24 int zone=0;
25 float CalculateAGLd(RiseMath::Vector3, double, double, double,
26 double, double, double, RiseMath::Vector3, bool);
27 void BeginFrame() {
28#include "RoutePositionFrame.generated.h"
29 }
30};
31#include "RoutePosition.generated.h"
32
33struct Fixture {
34 MapBus bus;
35 Game game{&bus};
36 Grid grid;
37 Logger logger;
38 Viewscreen view{&game,&grid,&logger};
39 // Flat 2 km terrain tile, with the same eight triangles as the client.
40 // Center it on a downward radial ray; the supplied u/v are cell fractions.
41 bool Measure(Cell cell, float u, float v, bool terrainHit=true) {
42 grid.tcp=cell;
43 auto vertex=[&](float x,float y) {
44 return terrainHit ? RiseMath::Vector3((x-u)*2,(y-v)*2,-3000) : RiseMath::Vector3();
45 };
46 gridarray[31][31]={vertex(0,0),cell};
47 gridarray[32][31].position=vertex(1,0);
48 gridarray[31][32].position=vertex(0,1);
49 gridarray[32][32].position=vertex(1,1);
50 insidearray[31][31][0]=vertex(.5f,0);
51 insidearray[31][31][1]=vertex(0,.5f);
52 insidearray[31][31][2]=vertex(.5f,.5f);
53 insidearray[32][31][1]=vertex(1,.5f);
54 insidearray[31][32][0]=vertex(.5f,1);
55 // AGL ran late in the prior frame; displays read at the next frame's start.
56 const bool hit=view.CalculateAGLd({},0,0,0,0,0,3000,{0,0,-3000},false)!=-1;
57 view.BeginFrame();
58 return hit;
59 }
60 G::Point Position() const {
61 return {float(bus.tcp.u)+bus.assayProgressU,float(bus.tcp.v)+bus.assayProgressV};
62 }
63};
64
65static std::vector<G::Node> JaegerRoute() {
66 // Oct 16 server geometry. IDs stand in for incoming-edge identities; the
67 // log contains coordinates/names, not packet edge IDs. Float coordinates
68 // retain the actual ~4.88 m lane links and ~997.56 m straight segments.
69 return {
70 {{522.4988f,1102.501f},1,"Route 46"},
71 {{522.4988f,1103.f},2,"Route 46"},
72 {{522.4988f,1103.499f},3,"Route 46"},
73 {{522.f,1103.499f},4,"Route O"},
74 {{521.5012f,1103.499f},5,"Route O"},
75 {{521.4988f,1103.499f},6,"Route O"},
76 {{521.f,1103.499f},7,"Route O"},
77 {{520.5012f,1103.499f},8,"Route O"},
78 {{520.4988f,1103.499f},9,"Route O"},
79 {{520.f,1103.499f},10,"Route O"},
80 {{519.5012f,1103.499f},11,"Route O"},
81 {{519.5006f,1103.f},12,"CARMEL ST"}
82 };
83}
84
85static void CheckPositionPublication() {
86 for (const Cell step : {Cell{1,0},Cell{-1,0},Cell{0,1},Cell{0,-1}}) {
87 Fixture f;
88 const float u=step.u>0?.999f:step.u<0?.001f:.4993f;
89 const float v=step.v>0?.999f:step.v<0?.001f:.5f;
90 Check(f.Measure({522,1103},u,v),"initial terrain position is valid");
91 const auto before=f.Position();
92 const Cell next{short(522+step.u),short(1103+step.v)};
93 for(int frame=0;frame<4;++frame) {
94 Check(!f.Measure(next,0,0,false),"missing terrain intersection is reported");
95 Check(G::DistanceMeters(before,f.Position())<.01f,
96 "failed AGL at a cell boundary retains the entire previous map position");
97 }
98 Check(f.Measure(next,step.u?1-u:u,step.v?1-v:v),"position resumes after a valid terrain sample");
99 Check(G::DistanceMeters(before,f.Position())<5,
100 "resuming across a cell boundary moves meters instead of two kilometers");
101 }
102 // Every triangle quadrant and the actual sampled grid origin are covered.
103 Fixture f;
104 for(float u:{.1f,.4f,.6f,.9f}) for(float v:{.1f,.4f,.6f,.9f}) {
105 Check(f.Measure({522,1103},u,v),"terrain quadrant intersects");
106 Check(G::DistanceMeters(f.Position(),{522+u,1103+v})<.3f,
107 "map publication preserves terrain fractions in every quadrant");
108 }
109}
110
111static void CheckJaegerSeams() {
112 for (const int fps : {10,60,144}) {
113 Fixture f;
114 G guidance;
115 guidance.Reset(JaegerRoute());
116 auto update=[&](G::Point p) {
117 Cell cell{short(std::floor(p.x)),short(std::floor(p.y))};
118 Check(f.Measure(cell,p.x-cell.u,p.y-cell.v),"replay terrain sample intersects");
119 return guidance.Update(f.Position(),72,1.f/fps);
120 };
121 update({522.4993f,1102.999f});
122 // At v=1103 the new grid can miss AGL while the last fractions still
123 // describe v=1102.999. This formerly fabricated v=1103.999.
124 f.Measure({522,1103},0,0,false);
125 auto cues=guidance.Update(f.Position(),72,1.f/fps);
126 Check(guidance.NextNodeIndex()==2 && cues.empty(),
127 "Route 46 seam cannot skip the Route O junction or announce Continue Route O");
128 for(int frame=1;frame<=fps*4;++frame) {
129 cues=update({522.4993f,1103.f+frame*.01f/fps});
130 Check(!HasReroute(cues) && guidance.NextNodeIndex()==2,
131 "southbound Route 46 stays current after the seam without false recalculation");
132 }
133 // Match the reported origin (938 m short of the real junction).
134 Check(!HasReroute(update({522.4993f,1103.03f})),"logged Route 46 origin remains on route");
135 // Make the actual right turn and verify its warning, execution and reassurance.
136 cues=update({522.4993f,1103.35f});
137 Check(cues.size()==1 && cues[0].type==G::Approaching && cues[0].edgeId==4 && cues[0].direction==4,
138 "the actual Route O junction retains its right-turn warning");
139 cues=update({522.4993f,1103.48f});
140 Check(cues.size()==1 && cues[0].type==G::Execute && cues[0].edgeId==4,
141 "the actual Route O turn retains its execution cue");
142 cues=update({522.48f,1103.5f});
143 Check(cues.size()==1 && cues[0].type==G::Continue && cues[0].edgeId==4,
144 "Continue Route O occurs after the real turn");
145 // Keep the second symptom independent, including on a replay of the
146 // old code where the first seam has already requested a replacement.
147 guidance.Reset(JaegerRoute());
148 update({522.48f,1103.5f});
149 update({522.001f,1103.5f});
150 // Westbound x=522: stale near-zero u with the new cell used to fabricate
151 // x=521.001, poisoning progress by almost 2 km before the 10:42:22 request.
152 f.Measure({521,1103},0,0,false);
153 cues=guidance.Update(f.Position(),72,1.f/fps);
154 Check(!HasReroute(cues) && guidance.NextNodeIndex()==4,
155 "Route O seam cannot consume the next kilometer and lane link");
156 for(int frame=1;frame<=fps*4;++frame) {
157 cues=update({522.f-frame*.01f/fps,1103.5f});
158 Check(!HasReroute(cues) && guidance.NextNodeIndex()==4,
159 "normal Route O travel does not inherit a fictitious progress maximum");
160 }
161 Check(!HasReroute(update({521.9601f,1103.5f})),"logged Route O origin remains on route");
162 // Continue through kilometer edges and short lane links at 72 km/h.
163 for(int frame=1;frame<=fps*245;++frame) {
164 const float x=521.9601f-frame*.01f/fps;
165 cues=update({x,1103.5f});
166 Check(!HasReroute(cues),"continuous Route O driving through all short links does not reroute");
167 Check(guidance.NextNodeIndex()<=10,"the later Carmel junction remains ahead");
168 }
169 }
170}
171}
float CalculateAGLd(RiseMath::Vector3 terpos, double terprecisionx, double terprecisiony, double terprecisionz, double proposedx, double proposedy, double proposedz, RiseMath::Vector3 proposed, bool makeleveler)
char area[3]
Definition globals.cpp:87
RiseMath::Vector3 insidearray[63][63][3]
Definition globals.cpp:102
LOCALGRID2 gridarray[64][64]
Definition globals.cpp:100
Vector Position(int cube, int u, int v, float radius)
constexpr double G
Definition FlightLoads.h:13
float Level(float output, float limit)
Definition RcsAudio.h:12
std::function< void(const char *, bool warning)> Log
@ Game
Use the game audio system.
Definition discordpp.h:505
RiseMath::Vector3 position
Definition globals.h:273