Rise
The Vieneo Province
Loading...
Searching...
No Matches
MovingMap.cpp
Go to the documentation of this file.
1#include "../Instrument.h"
3#include "../../GpwsDisplay.h"
4#include <unordered_map>
7
8MovingMap::MovingMap(int prmX, int prmY, float prmXScale, float prmYScale, Bus* prmBus, Logger* prmLogger, DeviceObject* prmDevice, std::vector<Font*> prmFonts) :
9 Instrument(prmX, prmY, prmXScale, prmYScale, prmBus, prmLogger, prmDevice, prmFonts)
10{
11 logger->AddToCallStack("MovingMap::ctor");
12 defaultFont = 1;
13
14 // @todo could break compass and heading bug stuff into it's own instrument like TCAS
15 headingBug = new Sprite(logger, pDevice, "Textures/Instruments/HeadingBug.png", x - 6, y - 6, 0.8f, 0, 0, 556, 556, 0xFFFF00FF, xScale, yScale);
16 bearingBug = new Sprite(logger, pDevice, "Textures/Instruments/HeadingBug.png", x - 6, y - 6, 0.8f, 0, 0, 556, 556, 0xFF00FF00, xScale, yScale);
17 lastBug = new Sprite(logger, pDevice, "Textures/Instruments/HeadingBug.png", x - 6, y - 6, 0.8f, 0, 0, 556, 556, 0xFFFFFF00, xScale, yScale);
18 compass = new Sprite(logger, pDevice, "Textures/Instruments/CompassLarge.png", x, y, 0.2f, 0, 0, 530, 530, 0xFFFFFFFF, xScale, yScale);
19
20 flyoverFix = new Sprite(logger, pDevice, "Textures/Instruments/Waypoints.png", x, y, 0.42f, 0, 0, 28, 28, 0xFFFFFFFF, xScale, yScale);
21 malteseFix = new Sprite(logger, pDevice, "Textures/Instruments/Waypoints.png", x, y, 0.43f, 28, 0, 28, 28, 0xFFFFFFFF, xScale, yScale);
22 touchdown = new Sprite(logger, pDevice, "Textures/Instruments/Waypoints.png", x, y, 0.40f, 56, 0, 28, 28, 0xFFFFFFFF, xScale, yScale);
23 userPin = new Sprite(logger, pDevice, "Textures/Instruments/Waypoints.png", x, y, 0.41f, 84, 0, 28, 28, 0xFFFFFFFF, xScale, yScale);
24
25 // @todo could break assay overlay stuff into it's own instrument like TCAS
26 assay = new Sprite(logger, pDevice, "Textures/Instruments/assayBox.png", x, y, 0.1f, 0, 0, 32, 32, 0xFFFFFFFF, xScale, yScale);
28 assayTexture = pDevice->GetTextureSRV("Textures/Instruments/assayBox.png");
29
30 terrainTexture = pDevice->GetTextureSRV("Textures/Instruments/colorBox.png");
31 // Build instrument stipples in memory: no new installed bitmap is required.
32 for (unsigned density = 0; density < 2; ++density)
33 {
34 auto& texture = terrainStipple[density];
35 if (FAILED(Rendering::CreateTexture(pDevice->GetD3DDevice(),32,32,1,0,
38 if (FAILED(texture->LockRect(0,&pixels,nullptr,0))) { texture.Reset(); continue; }
39 for (int py = 0; py < 32; ++py)
40 {
41 auto row = reinterpret_cast<DWORD*>(static_cast<BYTE*>(pixels.pBits)+py*pixels.Pitch);
42 for (int px = 0; px < 32; ++px)
43 row[px] = (density ? (px+py)%2 == 0 : px%2 == 0 && py%2 == 0) ? 0xffffffff : 0xff000000;
44 }
45 texture->UnlockRect(0);
46 }
47
48 arena = new Sprite(logger, pDevice, "Textures/Instruments/arena.png", x, y, 0.33f, 0, 0, 512, 512, 0xFFFFFFFF, xScale, yScale);
49 classB = new Sprite(logger, pDevice, "Textures/Instruments/arena.png", x, y, 0.32f, 0, 0, 512, 512, 0xFFFFFFFF, xScale, yScale);
50 classG = new Sprite(logger, pDevice, "Textures/Instruments/arena_grad.png", x, y, 0.31f, 0, 0, 128, 128, 0xFFFFFFFF, xScale, yScale);
51
52 relativeCenter = RiseMath::Vector2(530.0f * 0.5f * xScale, 530.0f * 0.5f * yScale);
53
54 remoteAssayPower = 0.0f;
55}
56
58{
59 compass->Draw();
60
62 {
65 lastBug->Draw();
66 }
67
68 // The surface map is the ordinary land/water fill. TCAS suppresses only
69 // that fill for the whole test/advisory, including gaps between phrases.
70 // GPWS relative terrain replaces that fill independently; navigation
71 // symbols, labels, compass and airspace remain visible in either case.
72 const bool relativeTerrain = terrainMode && bus->GPWS.terrain.enabled && !playerships[0].isSimulator;
73 const bool surfaceMap = !bus->TCASTestActive && bus->TCAS < Bus::Traffic_Advisory &&
75
76 /*RiseMath::Matrix matRot;
77 RiseMath::MatrixRotationZ(&matRot, -compass->rotate);*/
78
79 //RiseMath::Vector2 lastWaypoint;
80 //lastWaypoint.x = 265;
81 //lastWaypoint.y = 265;
82 //RiseMath::Vector2 nextWaypoint;
83
85 // first one (temporary waypoint) is skipped if it isn't set
86 // if distance is beyond 2x scale then skip
87
88
89 for (UINT i = 0; i < waypoints.size(); i++)
90 {
91 const Swaypoint waypoint = waypoints.at(i);
92
93 DWORD color;
94 if (waypoint.id == bus->WPtargetC)
95 color = 0xFFFF00FF;
96 else
97 color = 0xFFFFFFFF;
98
99 // ReSharper disable once CppDefaultCaseNotHandledInSwitchStatement
100 switch (waypoint.type)
101 {
102 case 0: // User Pin
103 userPin->SetLocation(static_cast<int>(waypoint.location.x), static_cast<int>(waypoint.location.y));
104 userPin->Update();
105 userPin->Draw(color);
106 break;
107 case 1: // LOM/FAF
108 {
109 malteseFix->SetLocation(static_cast<int>(waypoint.location.x), static_cast<int>(waypoint.location.y));
111 malteseFix->Draw(color);
112
113 WCHAR msg[99];
114 wcscpy_s(msg, _countof(msg), waypoint.text);
115 DrawTextW(msg, static_cast<int>(waypoint.location.x + 20) - x, static_cast<int>(waypoint.location.y) - y, 0.3f, DT_NOCLIP, color);
116 }
117 break;
118 case 2: // threshold
119 {
120 touchdown->SetLocation(static_cast<int>(waypoint.location.x + 7.5f), static_cast<int>(waypoint.location.y));
121 touchdown->mag = RiseMath::Max(1.0f, waypoint.length / bus->MapScaleInnerRingKm * 5.0f);
122 touchdown->rotate = 3.141f + headingTrueRad - RiseMath::ToRadian(static_cast<float>(waypoint.heading));
123 touchdown->Update();
124 touchdown->Draw(color);
125 }
126 break;
127 case 3: // flyover fix
128 {
129 flyoverFix->SetLocation(static_cast<int>(waypoint.location.x), static_cast<int>(waypoint.location.y));
131 flyoverFix->Draw(color);
132
133 WCHAR msg[99];
134 wcscpy_s(msg, _countof(msg), waypoint.text);
135 DrawTextW(msg, static_cast<int>(waypoint.location.x + 20) - x, static_cast<int>(waypoint.location.y) - y, 0.3f, DT_NOCLIP, color);
136 }
137 break;
138 //case 4: // MM (not displayed)
139 //break;
140 }
141
142
143 //course.height = static_cast<int>(sqrtf(powf(nextWaypoint.x - lastWaypoint.x, 2.0f) + powf(nextWaypoint.y - lastWaypoint.y, 2.0f)));
144 //course.x = static_cast<int>((nextWaypoint.x + lastWaypoint.x)*0.5f);
145 //course.y = static_cast<int>(RiseMath::Min(nextWaypoint.y, lastWaypoint.y) - (course.height - fabsf(nextWaypoint.y - lastWaypoint.y))*0.5f);
146 //if (i == 0)
147 // course.color = 0xFFFF00FF; // first one only
148 //else
149 // course.color = 0xFFFFFFFF;
150
151 //course.rotate = -atan2f(lastWaypoint.y - nextWaypoint.y, lastWaypoint.x - nextWaypoint.x) + RiseMath::HalfPi;
152 //course.Update();
153 //course.Draw();
154
155 //lastWaypoint = nextWaypoint;
156 }
157
162 {
163 if (remoteAssayPower > 15.0f)
164 {
166 DrawTextW(L"ALT", (int)(relativeCenter.x - 7.0f), (int)(relativeCenter.y + 8.0f), 1.0f, DT_NOCLIP, 0xFFFFAA00);
167 else
168 DrawTextW(L"SCN", (int)(relativeCenter.x - 7.0f), (int)(relativeCenter.y + 8.0f), 1.0f, DT_NOCLIP, 0xFF00FF00);
169
170 }
171 else
172 DrawTextW(L"TST", (int)(relativeCenter.x - 7.0f), (int)(relativeCenter.y + 8.0f), 1.0f, DT_NOCLIP, 0xFFFFFFFF);
173
174 unsigned maxRare = 0, maxCommon = 0, maxFuel = 0;
175 for (int i = 0; i < assayTileCount; i++)
176 {
177 // Use only the current rendered cells (no omitted corners or seam voids).
178 maxRare = RiseMath::Max(maxRare, (assayColor[i] >> 16) & 255U);
179 maxCommon = RiseMath::Max(maxCommon, (assayColor[i] >> 8) & 255U);
180 maxFuel = RiseMath::Max(maxFuel, assayColor[i] & 255U);
181 const DWORD color = remoteAssayPower > 15.0f ? assayColor[i] : Rendering::ColorARGB(255, i * 10, i * 10, i * 10);
183 {
184 const RECT rectangle = { 0, 0, 32, 32 };
185 const RiseMath::Vector3 position(0, 0, .1f);
186 HRESULT hr;
188 V(pDevice->pSprite->Draw(assayTexture, &rectangle, nullptr, &position, color));
189 }
190 else
191 {
192 assay->SetLocation(assayGrid[i].u + x, assayGrid[i].v + y);
193 assay->Update();
194 assay->Draw(color);
195 }
196 }
197
198 if (remoteAssayPower <= 15.0f)
199 maxRare = maxCommon = maxFuel = 255;
200 // Upper right of the scan, beneath the navigation page's weather readings.
201 // Fixed font metrics keep the readout legible on the smaller MFDs as well.
202 // Inset from the arc to fit the A-4's narrower screen; finish at arc height.
203 const int right = static_cast<int>(530.f * xScale) - 22;
204 const int top = static_cast<int>(relativeCenter.y) - 50;
205 const int textX = right - 62;
206 DrawTextW(L"MAX SCANNED", textX, top + 2, 1.f, DT_RIGHT | DT_NOCLIP, 0xFFFFFFFF, 1, "", 60);
207 wchar_t value[20];
208 swprintf_s(value, L"Rare: %3u", maxRare);
209 DrawTextW(value, textX, top + 15, 1.f, DT_RIGHT | DT_NOCLIP, 0xFFFF4040, 1, "", 60);
210 swprintf_s(value, L"Common: %3u", maxCommon);
211 DrawTextW(value, textX, top + 28, 1.f, DT_RIGHT | DT_NOCLIP, 0xFF00FF00, 1, "", 60);
212 swprintf_s(value, L"Fuel: %3u", maxFuel);
213 DrawTextW(value, textX, top + 41, 1.f, DT_RIGHT | DT_NOCLIP, 0xFF4488FF, 1, "", 60);
214 }
215 else if (relativeTerrain || surfaceMap)
216 {
217 const RECT rectangle = { 0, 0, 32, 32 };
218 const RiseMath::Vector3 position(0, 0, 0.1f);
219 HRESULT hr;
220 for (int i = 0; i < terrainTileCount; i++)
221 {
223 const unsigned density = relativeTerrain ? terrainDensity[i] : 0;
224 auto texture = density && terrainStipple[density-1] ? terrainStipple[density-1].Get() : terrainTexture;
225 V(pDevice->pSprite->Draw(texture, &rectangle, nullptr, &position, relativeTerrain ? terrainColors[i] : colorColor[i]));
226 }
227 if (relativeTerrain)
228 {
229 for (size_t i = 0; i < obstacleGrid.size(); ++i)
230 {
232 const unsigned density = obstacleDensity[i];
233 auto texture = density && terrainStipple[density-1] ? terrainStipple[density-1].Get() : terrainTexture;
234 V(pDevice->pSprite->Draw(texture, &rectangle, nullptr, &position, obstacleColors[i]));
235 }
236 }
237 }
238
239 if (playerships[0].battleRoyale)
240 arena->Draw(0x77FF7700);
241
242 if (hasAirspace)
243 classB->Draw(0x770080FF);
244
245 for (UINT i = 0; i < classGs.size(); i++)
246 {
247 const Swaypoint waypoint = classGs.at(i);
248
249 classG->SetLocation(static_cast<int>(waypoint.location.x), static_cast<int>(waypoint.location.y));
250 classG->Update();
251 classG->Draw(0x778A2254);
252 }
253 RenderGpws();
254}
255
256void MovingMap::FrameMove(float fElapsed)
257{
259 obstacleGrid.clear(); obstacleColors.clear(); obstacleDensity.clear();
260 terrainMinimum = FLT_MAX; terrainMaximum = -FLT_MAX;
262 assayTileCount = 0;
264
265 // so if heading went from 0 to 360 ... and we are on 0 for the compass rotation
266 // 360-0 = 360 diff ... we want 0
267
268 float diff = headingTrueRad - compass->rotate; // turning left, 360 - 0 = 360
269 if (diff > RiseMath::Pi)
270 {
272 diff -= RiseMath::Tau;
273 }
274 else if (diff < -RiseMath::Pi)
275 {
277 diff += RiseMath::Tau;
278 }
279
280 compass->rotate += diff * fElapsed;
281 compass->Update();
282
284 if (diff > RiseMath::Pi)
285 diff -= RiseMath::Tau;
286 else if (diff < -RiseMath::Pi)
287 diff += RiseMath::Tau;
288
289 headingBug->rotate = diff;
291
294
295 if (bus->lastWaypointLocation.x != 0.0f)
296 {
298 lastBug->Update();
299 }
300
301 pixelPerKmX = 530.0f * 0.25f / bus->MapScaleInnerRingKm * xScale;
302 pixelPerKmY = 530.0f * 0.25f / bus->MapScaleInnerRingKm * yScale;
303
304 RiseMath::Vector3 posnorml;
305 RiseMath::Vec3Normalize(&posnorml, &playerships[0].position);
306 RiseMath::MatrixLookAtLH(&lookAtLH, &playerships[0].position, &northpoleK, &posnorml);
307 RiseMath::Matrix matrixRot;
309 lookAtLH = lookAtLH * matrixRot;
310
311 waypoints.clear();
312 classGs.clear();
313 hasAirspace = false;
314 for (UINT i = 0; i < bus->waypoint.size(); i++)
315 {
316 const Swaypoint waypoint = bus->waypoint.at(i);
317
318 // first one (temporary waypoint) is skipped if it isn't set
319 if (i == 0 && waypoint.location.x == 0.0f)
320 continue;
321
322 // if we are in the control tower then we don't show user waypoints
324 continue;
325
326 RiseMath::Vector3 result1;
327 RiseMath::Vec3TransformCoord(&result1, &waypoint.location, &lookAtLH);
328
329 // don't show stuff on other side of planet
330 if (fabsf(result1.z) > (playerships[0].mslKm + radiusC))
331 continue;
332
333 // if distance is beyond 2x scale then skip
334 RiseMath::Vector2 result2 = RiseMath::Vector2(result1.x, result1.y);
335 const float dist = RiseMath::Vec2Length(&result2);
336 float bias = 0.0f;
337 if (waypoint.uniqueid == 371 && !playerships[0].groundvehicle) // Deois Control Tower
338 bias = 37.0f;
339 if (waypoint.type == 2 && !playerships[0].groundvehicle) // Class G
340 bias = 9.26f;
341 if ((dist - bias) > bus->MapScaleInnerRingKm * 2.0f)
342 continue;
343
344 const RiseMath::Vector2 diff2d = RiseMath::Vector2(-result2.x * pixelPerKmX, result2.y * pixelPerKmY);
345 RiseMath::Vector2 nextWaypoint = relativeCenter + diff2d;
346 nextWaypoint.x = static_cast<int>(nextWaypoint.x) - 14 * xScale;
347 nextWaypoint.y = static_cast<int>(nextWaypoint.y) - 14 * yScale;
348
349 Swaypoint newWaypoint;
350 newWaypoint.type = waypoint.type;
351 newWaypoint.location.x = nextWaypoint.x + x;
352 newWaypoint.location.y = nextWaypoint.y + y;
353 newWaypoint.id = i;
354 newWaypoint.heading = waypoint.heading;
355 newWaypoint.length = waypoint.length;
356 wcscpy_s(newWaypoint.text, _countof(newWaypoint.text), waypoint.text);
357
358 waypoints.emplace_back(newWaypoint);
359
360 if (waypoint.uniqueid == 371 && !playerships[0].groundvehicle) // Deois Control Tower
361 {
362 hasAirspace = true;
363
364 // 37km is the outer class B ring
365 classB->mag = 37.0f / bus->MapScaleInnerRingKm * 0.53f;
366
367 nextWaypoint = relativeCenter + diff2d;
368 const int x1 = static_cast<int>(nextWaypoint.x + x - 256.0f * xScale * classB->mag);
369 const int y1 = static_cast<int>(nextWaypoint.y + y - 256.0f * yScale * classB->mag);
370
371 classB->SetLocation(x1, y1);
372 classB->Update();
373 }
374 else if (waypoint.type == 2 && !playerships[0].groundvehicle && waypoint.uniqueid != 3) // Deois TDZ
375 {
376 // 9.26km is the outer class G ring
377 classG->mag = 9.26f / bus->MapScaleInnerRingKm * 0.53f * 4.0f; // 0.53 is the scale for 512 map ... 2.12 for 128 ... 1.06 for 256
378
379 nextWaypoint = relativeCenter + diff2d;
380 nextWaypoint.x = nextWaypoint.x + x - 64.0f * xScale * classG->mag;
381 nextWaypoint.y = nextWaypoint.y + y - 64.0f * yScale * classG->mag;
382
383 Swaypoint newWaypoint1;
384 newWaypoint1.type = waypoint.type;
385 newWaypoint1.location.x = nextWaypoint.x;
386 newWaypoint1.location.y = nextWaypoint.y;
387 newWaypoint1.id = i;
388 newWaypoint1.heading = waypoint.heading;
389 newWaypoint1.length = waypoint.length;
390 wcscpy_s(newWaypoint1.text, _countof(newWaypoint1.text), waypoint.text);
391
392 classGs.emplace_back(newWaypoint1);
393 }
394 }
395
396 // Keep ordinary map geometry ready when a module raises a new priority alert.
399 {
400 const int assayFace = AssayMapProjection::PacketFace(bus->assayGrid.gridarray[0][0].padding);
401 assayUsesProjection = assayFace >= 0;
402 // Untagged packets retain the legacy display during a rolling server upgrade.
404 assay->mag = 8.0f / bus->MapScaleInnerRingKm;
405
406 const float vertexWidth = 2.0f;
407 const float vertexHeight = 2.0f;
409 RiseMath::MatrixInverse(&matrixRot, nullptr, &matrixRot);
410 RiseMath::Vector3 test, result;
411 test.z = 0.0f; // UL
412 for (int xx = 0; xx < 5; xx++)
413 {
414 for (int yy = 0; yy < 5; yy++)
415 {
416 if ((xx == 0 && yy == 0) || (xx == 4 && yy == 0) || (xx == 0 && yy == 4) || (xx == 4 && yy == 4))
417 continue;
418 const int index = assayTileCount;
420 {
422 bus->assayGrid.tcp.v + yy - 2, assayFace, radiusC, lookAtLH,
424 assayTransform[index]))
425 continue;
426 }
427 else
428 {
429 test.x = (xx - 2.0f - bus->assayProgressU - static_cast<float>(bus->tcp.u - bus->assayGrid.tcp.u)) * vertexWidth * pixelPerKmX;
430 test.y = (yy - 2.0f - bus->assayProgressV - static_cast<float>(bus->tcp.v - bus->assayGrid.tcp.v)) * vertexHeight * pixelPerKmY;
431 RiseMath::Vec3TransformCoord(&result, &test, &matrixRot);
432 result.x += relativeCenter.x;
433 result.y += relativeCenter.y;
434 assayGrid[index].u = static_cast<short>(result.x);
435 assayGrid[index].v = static_cast<short>(result.y);
436 }
437
438 assayColor[index] = Rendering::ColorARGB(static_cast<int>(bus->assayQuality * 255.0f),
439 bus->assayGrid.gridarray[xx][yy].oreA,
440 bus->assayGrid.gridarray[xx][yy].oreC,
441 bus->assayGrid.gridarray[xx][yy].oreD);
442
444 }
445 }
446 remoteAssayPower += fElapsed;
447 }
448 else // otherwise show sectional chart
449 {
450 remoteAssayPower = 0.0f;
452 bus->assayGrid.tcp = bus->tcp;
453
454 // A grid shift can occur between the predictor and display updates. Match
455 // the previous snapshot by plot identity until GPWS scans the new revision.
456 // Build the lookup only on a mismatch; normal frames use the direct index.
457 std::unordered_map<uint32_t,const TerrainAwareness::Cell*> shiftedTerrain;
458 bool terrainIndexed = false;
459 const auto plotKey = [](int u, int v) { return (uint32_t(uint16_t(u)) << 16) | uint16_t(v); };
460 const auto& scan = bus->GPWS.terrain;
461 const auto findCell = [&](int u, int v) -> const TerrainAwareness::Cell* {
462 const auto& c = scan.cells[u*63+v]; const auto tcp = gridarray[u][v].tcp;
463 if (c.u == tcp.u && c.v == tcp.v) return &c;
464 if (!terrainIndexed)
465 {
466 for (const auto& p : scan.cells) if (p.valid) shiftedTerrain.emplace(plotKey(p.u,p.v),&p);
467 terrainIndexed = true;
468 }
469 const auto it = shiftedTerrain.find(plotKey(tcp.u,tcp.v));
470 return it == shiftedTerrain.end() ? nullptr : it->second;
471 };
472 const auto inRange = [&](RiseMath::Vector3 p) {
474 const float dx = xy.x/(265*xScale), dy = xy.y/(265*yScale);
475 return std::isfinite(dx) && std::isfinite(dy) && dy <= 0 && dx*dx+dy*dy <= 1;
476 };
477 if (terrainMode)
478 {
479 for (int u = 0; u < 63; ++u) for (int v = 0; v < 63; ++v)
480 {
481 const auto* cell = findCell(u,v);
482 if (!cell || !cell->valid || !visiblegrid[u][v] ||
483 !inRange((gridarray[u][v].position+gridarray[u+1][v+1].position)*.5f)) continue;
484 terrainMinimum = (std::min)(terrainMinimum,cell->topKm);
485 terrainMaximum = (std::max)(terrainMaximum,cell->topKm);
486 }
487 if (bus->GPWS.obstaclesEnabled) for (const auto& o : scan.obstacles)
488 {
489 const auto p = o.corners[0];
490 if (inRange({p.x,p.y,p.z})) { terrainMinimum = (std::min)(terrainMinimum,o.topKm); terrainMaximum = (std::max)(terrainMaximum,o.topKm); }
491 }
492 }
493 // Use the entire received patch, independent of the world camera cull.
494
495 for (int xx = 0; xx < 63; xx++)
496 {
497 for (int yy = 0; yy < 63; yy++)
498 {
499 if (!visiblegrid[xx][yy])
500 continue;
501 // Never color a cube-net void or an unloaded tile as low terrain.
505 colorGrid[terrainTileCount], terrainMode && findCell(xx,yy) && findCell(xx,yy)->severity != TerrainAwareness::Severity::None ? 6.f : 0.f))
506 continue;
507 const int index = terrainTileCount++;
508
509 if (gridarray[xx][yy].pri_landform == 1)
510 colorColor[index] = 0xff010f94;
511 else if (gridarray[xx][yy].elevation < 952)
512 colorColor[index] = 0xffd8e7ca;
513 else if (gridarray[xx][yy].elevation < 1904)
514 colorColor[index] = 0xffbec8a9;
515 else if (gridarray[xx][yy].elevation < 2856)
516 colorColor[index] = 0xfff5f0cb;
517 else if (gridarray[xx][yy].elevation < 3808)
518 colorColor[index] = 0xfff0eaa8;
519 else if (gridarray[xx][yy].elevation < 4760)
520 colorColor[index] = 0xffe9d79a;
521 else if (gridarray[xx][yy].elevation < 5712)
522 colorColor[index] = 0xffe8d798;
523 else if (gridarray[xx][yy].elevation < 6664)
524 colorColor[index] = 0xffe8b968;
525 else if (gridarray[xx][yy].elevation < 7616)
526 colorColor[index] = 0xffc58838;
527 else if (gridarray[xx][yy].elevation < 8568)
528 colorColor[index] = 0xff71573e;
529 else
530 colorColor[index] = 0xfffefefe;
531 const auto& terrain = bus->GPWS.terrain;
532 const auto* cell = findCell(xx,yy);
533 const bool known = cell && cell->valid;
534 const auto style = GpwsDisplay::Relative(known ? cell->topKm : 0,terrain.altitudeKm,terrain.verticalKms,
535 terrain.gearDown,known ? cell->severity : TerrainAwareness::Severity::None,known,terrain.displayRunwayKm,
536 terrain.onGround,bus->GPWS.peaks,terrainMinimum,terrainMaximum,gridarray[xx][yy].pri_landform == 1);
537 terrainColors[index] = style.color; terrainDensity[index] = style.density;
538 }
539 }
540
541 }
542
543 if (terrainMode)
544 {
545 const auto& terrain = bus->GPWS.terrain;
546 for (const auto& obstacle : terrain.obstacles)
547 {
548 if (!bus->GPWS.obstaclesEnabled) break;
549 float left = FLT_MAX, top = FLT_MAX, right = -FLT_MAX, bottom = -FLT_MAX;
550 for (const auto& p : obstacle.corners)
551 {
552 const auto point = TerrainMapProjection::Project({p.x,p.y,p.z},radiusC,lookAtLH,
554 left = (std::min)(left,point.x); right = (std::max)(right,point.x);
555 top = (std::min)(top,point.y); bottom = (std::max)(bottom,point.y);
556 }
557 if (!std::isfinite(left) || right < x || left > x+530*xScale || bottom < y || top > y+530*yScale) continue;
558 const float minimum = obstacle.severity == TerrainAwareness::Severity::None ? 2.f : 6.f;
559 const float width = (std::max)(minimum,right-left), height = (std::max)(minimum,bottom-top);
560 const float cx = (left+right)*.5f, cy = (top+bottom)*.5f;
561 RiseMath::Vector2 corners[] = {{cx-width*.5f,cy-height*.5f},{cx+width*.5f,cy-height*.5f},
562 {cx+width*.5f,cy+height*.5f},{cx-width*.5f,cy+height*.5f}};
563 RiseMath::Matrix transform;
564 if (!TerrainMapProjection::QuadTransform(corners,32,32,.09f,transform)) continue;
565 obstacleGrid.push_back(transform);
566 const auto style = GpwsDisplay::Relative(obstacle.topKm,terrain.altitudeKm,terrain.verticalKms,
567 terrain.gearDown,obstacle.severity,true,terrain.displayRunwayKm,terrain.onGround,bus->GPWS.peaks,terrainMinimum,terrainMaximum);
568 obstacleColors.push_back(style.color); obstacleDensity.push_back(style.density);
569 }
570 }
571
572 if (playerships[0].battleRoyale)
573 {
575
576 RiseMath::Vector3 result1;
578 const RiseMath::Vector2 result2 = RiseMath::Vector2(result1.x, result1.y);
579 const RiseMath::Vector2 diff2d = RiseMath::Vector2(-result2.x * pixelPerKmX, result2.y * pixelPerKmY);
580 const RiseMath::Vector2 nextWaypoint = relativeCenter + diff2d;
581 const int x1 = static_cast<int>(nextWaypoint.x) + x - static_cast<int>(256 * xScale * arena->mag);
582 const int y1 = static_cast<int>(nextWaypoint.y) + y - static_cast<int>(256 * yScale * arena->mag);
583
584 arena->SetLocation(x1, y1);
585 arena->Update();
586 }
587}
588
596
598{
599 const auto& radar=bus->weatherRadar;
600 const RECT rectangle={0,0,32,32};
601 const RiseMath::Vector3 position(0,0,.1f);
602 const auto draw=[&](const WeatherRadarModel::Quad& quad) {
603 RiseMath::Vector2 points[4];
604 for(int i=0;i<4;++i)
605 {
606 const auto& p=quad.corners[i];
607 // Preserve sub-meter wedge edges at a ~2940 km planet radius.
608 // Corners are already on the surface in render coordinates.
609 const double px=-p.x*lookAtLH._11-p.y*lookAtLH._21-p.z*lookAtLH._31+lookAtLH._41;
610 const double py=-p.x*lookAtLH._12-p.y*lookAtLH._22-p.z*lookAtLH._32+lookAtLH._42;
611 points[i]={float(x+relativeCenter.x-px*pixelPerKmX),float(y+relativeCenter.y+py*pixelPerKmY)};
612 }
613 RiseMath::Matrix transform;
614 if(!TerrainMapProjection::QuadTransform(points,32,32,.1f,transform)) return;
615 pDevice->pSprite->SetTransform(&transform);
616 pDevice->pSprite->Draw(terrainTexture,&rectangle,nullptr,&position,quad.color);
617 };
618 for(const auto& quad:radar.echoes) draw(quad);
619 if(WeatherRadarModel::SweepVisible(radar)) draw(radar.sweep);
620 // Fixed operational annunciations, not GUI/localization entries.
621 const wchar_t* status=WeatherRadarModel::StatusText(radar);
622 DrawTextW(status,int(relativeCenter.x),int(relativeCenter.y*.24f),1,DT_CENTER|DT_NOCLIP,
623 WeatherRadarModel::SweepVisible(radar) && !radar.limited ? 0xff80d0e0 : 0xffffc040,1);
624 if(radar.attenuated)
625 DrawTextW(L"WX ATTEN",int(relativeCenter.x),int(relativeCenter.y*.24f)+13,1,DT_CENTER|DT_NOCLIP,0xffffc040,1);
626 // Stack AUTO over the signed angle beside the inner-range label, clear of
627 // the range arc and ownship. Small MFDs put their scale below the arc.
628 const auto tilt=WeatherRadarModel::TiltText(radar);
629 const bool compact=xScale<.4f;
630 const int tiltX=int(relativeCenter.x*.48f)+(compact ? 16 : 22);
631 const int tiltY=int(relativeCenter.y)+(compact ? 13 : 0);
632 DrawTextW(L"AUTO",tiltX,tiltY-13,1,DT_NOCLIP,0xff80d0e0,1);
633 DrawTextW(tilt.c_str()+5,tiltX,tiltY,1,DT_NOCLIP,0xff80d0e0,1);
634}
635
637{
638 if (playerships[0].groundvehicle || ourcockpit.power < .5f) return;
639 const auto& g = bus->GPWS;
640 const auto& terrain = g.terrain;
641 const RECT rectangle = {0,0,32,32};
642 const RiseMath::Vector3 position(0,0,.9f);
643 const auto box = [&](float left, float top, float width, float height, DWORD color) {
644 const float cx = x+relativeCenter.x, cy = y+relativeCenter.y;
645 const RiseMath::Vector2 p[] = {{cx+left,cy+top},{cx+left+width,cy+top},
646 {cx+left+width,cy+top+height},{cx+left,cy+top+height}};
648 if (!TerrainMapProjection::QuadTransform(p,32,32,.9f,m)) return;
650 pDevice->pSprite->Draw(terrainTexture,&rectangle,nullptr,&position,color);
651 };
652 const auto message = [&](const wchar_t* text, int offset, DWORD color, bool backing = true) {
653 if (backing) box(-58,float(offset-2),116,13,0xf0000000);
654 DrawTextW(text,int(relativeCenter.x),int(relativeCenter.y)+offset,1,DT_CENTER|DT_NOCLIP,color,1);
655 };
656 if (g.testLevel)
657 {
658 if (g.testPattern)
659 {
660 // Same category arrangement as the guide's functional pattern;
661 // database identity reports the actual source, not a fictitious TDB.
662 const DWORD colors[] = {0xffff3030,0xffffff00,g.peaks ? 0xff00d8ffu : 0xff000000u,
663 0xffb030b0,0xff20d040,0xff000000};
664 for (int row = 0; row < 2; ++row) for (int col = 0; col < 3; ++col)
665 box(-54+col*36.f,-91+row*25.f,34,23,colors[row*3+col]);
666 message(L"TDB LIVE VIENEO",-105,0xffffffff);
667 }
668 if (g.testPattern) message(L"EGPWS SELF TEST",-39,0xffffffff);
669 else
670 {
671 const size_t pages = (std::max)(size_t(1),(g.testLines.size()+4)/5);
672 const size_t first = g.testLevel == 1 ? 0 : size_t(g.testStep)%pages*5;
673 for (size_t i = first; i < (std::min)(g.testLines.size(),first+5); ++i)
674 message(g.testLines[i].c_str(),-85+int(i-first)*13,0xffffffff);
675 }
676 if (g.testLevel == 1)
677 {
678 message(L"GPWS INOP / TERR INOP",-20,0xffffff00);
679 if (g.testStep == 1) message(L"FLAP OVRD",-7,0xffffff00);
680 if (g.cautionLamp) message(L"GPWS CAUTION",-7,0xffffff00);
681 if (g.warningLamp) message(L"PULL UP",-7,0xffff3030);
682 }
683 return;
684 }
685 if (g.testMessageSeconds > 0 && !g.testLines.empty()) message(g.testLines[0].c_str(),-85,0xffffffff);
686 if (*g.AlertText()) message(g.AlertText(),-55,g.warningLamp ? 0xffff3030 : 0xffffff00);
687 else if (g.mode2Latch) message(L"TERRAIN",-55,0xffffff00);
688 else if (terrainMode && terrain.Alert() != TerrainAwareness::Severity::None)
689 {
690 const bool warning = terrain.Alert() == TerrainAwareness::Severity::Warning;
691 message(terrain.ObstacleAlert() ? (warning ? L"OBSTACLE - PULL UP" : L"CAUTION OBSTACLE") :
692 (warning ? L"TERRAIN - PULL UP" : L"CAUTION TERRAIN"),-55,warning ? 0xffff3030 : 0xffffff00);
693 }
694 // Keep the entire status glyph row inside the compact PFD screen crop.
695 if (g.faults&3) message(L"GPWS INOP",-42,0xffffff00);
696 else if (g.flapOverride) message(L"FLAP OVRD",-42,0xffffff00);
697 else if (g.steepApproach) message(L"STEEP APPROACH",-42,0xffffff00);
698 else if (g.predictiveWindshear.enabled && !g.predictiveWindshear.complete)
699 message(L"PWS DATA LIMITED",-42,0xffffc040);
700 if (g.faults&4) message(L"TERR INOP",-21,0xffffff00);
701 else if (terrainMode && TerrainAwareness::NeedsPrediction(terrain.altitudeKm,terrain.verticalKms,true))
702 {
703 if (!terrain.terrainComplete) message(L"TERR DATA LIMITED",-21,0xffff60ff,false);
704 else if (g.obstaclesEnabled && !terrain.obstaclesComplete) message(L"OBST DATA LIMITED",-21,0xffff60ff);
705 }
706 if (terrainMode && g.peaks && terrainMinimum <= terrainMaximum)
707 {
708 const float reference = GpwsDisplay::Reference(terrain.altitudeKm,terrain.verticalKms);
709 const bool high = terrainMaximum < reference+(terrain.gearDown ? -.0762f : -.1524f);
710 const float minimum = high ? terrainMinimum : (std::max)(terrainMinimum,reference-.6096f);
711 const auto style = [&](float height) { return GpwsDisplay::Relative(height,terrain.altitudeKm,terrain.verticalKms,
712 terrain.gearDown,TerrainAwareness::Severity::None,true,-100,false,true,terrainMinimum,terrainMaximum); };
713 wchar_t label[64];
714 // The guide's numeric labels are hundreds of feet MSL. Include the unit
715 // explicitly because Rise's other cockpit altitude readouts use km.
716 box(-58,-115,116,13,0xf0000000);
717 swprintf_s(label,L"%03d",int(std::ceil(terrainMaximum/.03048f)));
718 DrawTextW(label,int(relativeCenter.x)-43,int(relativeCenter.y)-113,1,DT_CENTER|DT_NOCLIP,style(terrainMaximum).color,1);
719 if (minimum < terrainMaximum-.0001f)
720 {
721 swprintf_s(label,L"%03d",int(std::floor(minimum/.03048f)));
722 DrawTextW(label,int(relativeCenter.x)-12,int(relativeCenter.y)-113,1,DT_CENTER|DT_NOCLIP,style(minimum).color,1);
723 }
724 DrawTextW(L"x100 FT",int(relativeCenter.x)+27,int(relativeCenter.y)-113,1,DT_CENTER|DT_NOCLIP,0xffffffff,1);
725 }
726}
#define V(expression)
SCRIPT_CONTROL SCRIPT_STATE const void int
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
SCRIPT_CONTROL SCRIPT_STATE const void DWORD
@ ControlTower
Definition ServerTypes.h:86
const RiseMath::Vector3 northpoleK
Definition Bus.h:20
VECTOR2SHORT tcp
Definition Bus.h:314
float MapScaleInnerRingKm
Definition Bus.h:490
float assayQuality
Definition Bus.h:495
float PressureAltitudeKm
Definition Bus.h:31
@ Traffic_Advisory
Definition Bus.h:324
struct Bus::Gpws GPWS
float LastBearingDeg
Definition Bus.h:504
bool TCASTestActive
Definition Bus.h:341
RiseMath::Vector3 lastWaypointLocation
Definition Bus.h:501
struct Bus::Afcs AFCS
float HeadingTrueDegrees
Definition Bus.h:41
std::vector< Swaypoint > waypoint
Definition Bus.h:500
float assayProgressV
Definition Bus.h:496
float BattleRoyaleRingKm
Definition Bus.h:532
SAssayGrid assayGrid
Definition Bus.h:494
float RadioAltitudeKm
Definition Bus.h:157
RiseMath::Vector3 BattleRoyaleRingCenter
Definition Bus.h:531
int WPtargetC
Definition Bus.h:499
float HeadingMagneticDegrees
Definition Bus.h:42
float TargetBearingDeg
Definition Bus.h:503
enum Bus::TcasEnum TCAS
float assayProgressU
Definition Bus.h:496
WeatherRadarModel::Display weatherRadar
Definition Bus.h:25
Rendering::RenderSprite * pSprite
Rendering::RenderTexture * GetTextureSRV(std::string pathAndFilename)
Rendering::RenderDevice * GetD3DDevice()
Bus * bus
Definition Instrument.h:22
float xScale
Definition Instrument.h:19
float yScale
Definition Instrument.h:20
Instrument(int prmX, int prmY, float prmXScale, float prmYScale, Bus *prmBus, Logger *prmLogger, DeviceObject *prmDevice, std::vector< Font * > prmFonts)
Definition Instrument.h:36
Logger * logger
Definition Instrument.h:23
DeviceObject * pDevice
Definition Instrument.h:21
UINT defaultFont
Definition Instrument.h:24
void AddToCallStack(const char *msg)
Definition Logger.cpp:355
Sprite * arena
Definition Instrument.h:310
bool WeatherRadarSelected() const
float pixelPerKmX
Definition Instrument.h:314
RiseMath::Matrix assayTransform[21]
Definition Instrument.h:320
Rendering::RenderTexture * assayTexture
Definition Instrument.h:302
Sprite * compass
Definition Instrument.h:289
DWORD assayColor[21]
Definition Instrument.h:323
DWORD colorColor[drawlistC]
Definition Instrument.h:326
std::vector< unsigned > obstacleDensity
Definition Instrument.h:306
int assayTileCount
Definition Instrument.h:321
bool hasAirspace
Definition Instrument.h:333
std::vector< RiseMath::Matrix > obstacleGrid
Definition Instrument.h:329
std::vector< Swaypoint > waypoints
Definition Instrument.h:316
Sprite * touchdown
Definition Instrument.h:297
float terrainMinimum
Definition Instrument.h:307
bool terrainMode
Definition Instrument.h:328
RiseMath::Vector2 relativeCenter
Definition Instrument.h:331
Sprite * classB
Definition Instrument.h:311
void RenderGpws()
Sprite * classG
Definition Instrument.h:312
int terrainTileCount
Definition Instrument.h:325
void FrameMove(float fElapsed) override
RiseMath::Matrix colorGrid[drawlistC]
Definition Instrument.h:324
float remoteAssayPower
Definition Instrument.h:332
Rendering::RenderTexture * terrainTexture
Definition Instrument.h:303
Sprite * assay
Definition Instrument.h:301
bool assayUsesProjection
Definition Instrument.h:322
MovingMap(int prmX, int prmY, float prmXScale, float prmYScale, Bus *prmBus, Logger *prmLogger, DeviceObject *prmDevice, std::vector< Font * > prmFonts)
Definition MovingMap.cpp:8
Sprite * userPin
Definition Instrument.h:298
Sprite * bearingBug
Definition Instrument.h:291
std::vector< Swaypoint > classGs
Definition Instrument.h:317
Sprite * lastBug
Definition Instrument.h:292
void RenderWeatherRadar()
std::vector< DWORD > obstacleColors
Definition Instrument.h:330
Sprite * flyoverFix
Definition Instrument.h:295
Microsoft::WRL::ComPtr< Rendering::RenderTexture > terrainStipple[2]
Definition Instrument.h:304
RiseMath::Matrix lookAtLH
Definition Instrument.h:334
float terrainMaximum
Definition Instrument.h:307
float pixelPerKmY
Definition Instrument.h:315
unsigned terrainDensity[drawlistC]
Definition Instrument.h:305
Sprite * malteseFix
Definition Instrument.h:296
float headingTrueRad
Definition Instrument.h:318
DWORD terrainColors[drawlistC]
Definition Instrument.h:327
VECTOR2SHORT assayGrid[21]
Definition Instrument.h:319
void Render() override
Definition MovingMap.cpp:57
Sprite * headingBug
Definition Instrument.h:290
HRESULT SetTransform(const RiseMath::Matrix *value)
HRESULT Draw(RenderTexture *image, const RECT *rectangle, const RiseMath::Vector3 *center, const RiseMath::Vector3 *position, PackedColor color)
void SetRotationCenter(RiseMath::Vector2 rotationCenter)
Definition Sprite.h:52
void SetLocation(int absoluteX, int absoluteY)
Definition Sprite.cpp:99
float rotate
Definition Sprite.h:35
Sprite(Logger *prmLogger, DeviceObject *prmpDevice, std::string prmPathAndFilename, int prmX, int prmY, float prmZ, int prmTop, int prmLeft, int prmWidth, int prmHeight, DWORD prmColor, float scaleX=1.0f, float scaleY=1.0f)
Definition Sprite.cpp:5
void Draw(RiseMath::Color prmColor)
Definition Sprite.cpp:75
void Update()
Definition Sprite.cpp:50
float mag
Definition Sprite.h:36
s_network_objects playerships[MAX_SCAN]
Definition globals.cpp:112
bool visiblegrid[63][63]
Definition globals.cpp:101
Scockpit ourcockpit
Definition globals.cpp:114
LOCALGRID2 gridarray[64][64]
Definition globals.cpp:100
#define drawlistC
Definition globals.h:65
#define radiusC
Definition globals.h:87
#define cloudBufferMslC
Definition globals.h:111
int PacketFace(unsigned char tag)
bool CellTransform(int u, int v, int face, float radius, const RiseMath::Matrix &mapView, float pixelsPerKmX, float pixelsPerKmY, RiseMath::Vector2 center, RiseMath::Matrix &transform)
float Reference(float altitude, float vertical)
Definition GpwsDisplay.h:10
Style Relative(float height, float altitude, float vertical, bool gear, TerrainAwareness::Severity threat, bool known, float runway, bool ground, bool peaks, float lowest, float highest, bool water=false)
Definition GpwsDisplay.h:12
bool InAltitudeBand(float altitudeKm)
constexpr PackedColor ColorARGB(unsigned a, unsigned r, unsigned g, unsigned b)
HRESULT CreateTexture(RenderDevice *owner, UINT width, UINT height, UINT levels, DWORD usage, ImageFormat format, ResourcePool pool, RenderTexture **result)
auto ToRadian(T value)
Definition ClientMath.h:13
constexpr float Pi
Definition ClientMath.h:12
Vector3 * Vec3TransformCoord(Vector3 *out, const Vector3 *a, const Matrix *m)
Definition ClientMath.h:109
float Vec2Length(const Vector2 *a)
Definition ClientMath.h:92
Matrix * MatrixLookAtLH(Matrix *out, const Vector3 *eye, const Vector3 *at, const Vector3 *up)
Definition ClientMath.h:139
Matrix * MatrixInverse(Matrix *out, float *determinant, const Matrix *a)
Definition ClientMath.h:118
constexpr float Tau
Definition ClientMath.h:12
Vector3 * Vec3Normalize(Vector3 *out, const Vector3 *a)
Definition ClientMath.h:103
Matrix * MatrixRotationZ(Matrix *out, float value)
Definition ClientMath.h:128
constexpr auto Max(A first, B second)
Definition ClientMath.h:16
bool NeedsPrediction(float altitudeKm, float verticalKms, bool active)
RiseMath::Vector2 Project(const RiseMath::Vector3 &terrainPosition, float radius, const RiseMath::Matrix &mapView, float pixelsPerKmX, float pixelsPerKmY, RiseMath::Vector2 center)
bool QuadTransform(const RiseMath::Vector2(&p)[4], float width, float height, float depth, RiseMath::Matrix &transform)
bool CellTransform(const Vertex(&grid)[64][64], int u, int v, float radius, const RiseMath::Matrix &mapView, float pixelsPerKmX, float pixelsPerKmY, RiseMath::Vector2 center, RiseMath::Matrix &transform, float minimumPixels=0)
bool DisplaySelected(bool equipped, bool power, bool simulator, bool terrainPriority, bool tcasPriority)
bool SweepVisible(const Display &display)
std::wstring TiltText(const Display &display)
const wchar_t * StatusText(const Display &display)
float DesiredHeadingRadians
Definition Bus.h:133
bool TerrainDisplayActive() const
Definition Bus.h:271
bool peaks
Definition Bus.h:251
int testLevel
Definition Bus.h:260
TerrainAwareness::State terrain
Definition Bus.h:264
bool obstaclesEnabled
Definition Bus.h:252
unsigned char pri_landform
Definition globals.h:278
VECTOR2SHORT tcp
Definition globals.h:290
SAssayVertex gridarray[5][5]
VECTOR2SHORT tcp
unsigned char oreA
unsigned char oreD
unsigned char oreC
unsigned char padding
bool remoteAssayPower
Definition globals.h:597
short texturelib
Definition globals.h:602
bool remoteAssayEquipped
Definition globals.h:669
float power
Definition globals.h:599
bool weatherRadarEquipped
Definition globals.h:669
bool weatherRadarPower
Definition globals.h:597
short heading
unsigned char type
float length
RiseMath::Vector3 location
WCHAR text[64]