4#include <unordered_map>
9 Instrument(prmX, prmY, prmXScale, prmYScale, prmBus, prmLogger, prmDevice, prmFonts)
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);
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);
26 assay =
new Sprite(
logger,
pDevice,
"Textures/Instruments/assayBox.png",
x,
y, 0.1f, 0, 0, 32, 32, 0xFFFFFFFF,
xScale,
yScale);
32 for (
unsigned density = 0; density < 2; ++density)
38 if (FAILED(texture->LockRect(0,&pixels,
nullptr,0))) { texture.Reset();
continue; }
39 for (
int py = 0; py < 32; ++py)
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;
45 texture->UnlockRect(0);
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);
89 for (UINT i = 0; i <
waypoints.size(); i++)
100 switch (waypoint.
type)
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);
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);
174 unsigned maxRare = 0, maxCommon = 0, maxFuel = 0;
184 const RECT rectangle = { 0, 0, 32, 32 };
199 maxRare = maxCommon = maxFuel = 255;
203 const int right =
static_cast<int>(530.f *
xScale) - 22;
205 const int textX = right - 62;
206 DrawTextW(L
"MAX SCANNED", textX, top + 2, 1.f, DT_RIGHT | DT_NOCLIP, 0xFFFFFFFF, 1,
"", 60);
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);
215 else if (relativeTerrain || surfaceMap)
217 const RECT rectangle = { 0, 0, 32, 32 };
245 for (UINT i = 0; i <
classGs.size(); i++)
319 if (i == 0 && waypoint.
location.x == 0.0f)
346 nextWaypoint.x =
static_cast<int>(nextWaypoint.x) - 14 *
xScale;
347 nextWaypoint.y =
static_cast<int>(nextWaypoint.y) - 14 *
yScale;
351 newWaypoint.
location.x = nextWaypoint.x +
x;
352 newWaypoint.
location.y = nextWaypoint.y +
y;
356 wcscpy_s(newWaypoint.
text, _countof(newWaypoint.
text), waypoint.
text);
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);
385 newWaypoint1.
location.x = nextWaypoint.x;
386 newWaypoint1.
location.y = nextWaypoint.y;
390 wcscpy_s(newWaypoint1.
text, _countof(newWaypoint1.
text), waypoint.
text);
392 classGs.emplace_back(newWaypoint1);
406 const float vertexWidth = 2.0f;
407 const float vertexHeight = 2.0f;
412 for (
int xx = 0; xx < 5; xx++)
414 for (
int yy = 0; yy < 5; yy++)
416 if ((xx == 0 && yy == 0) || (xx == 4 && yy == 0) || (xx == 0 && yy == 4) || (xx == 4 && yy == 4))
434 assayGrid[index].
u =
static_cast<short>(result.x);
435 assayGrid[index].
v =
static_cast<short>(result.y);
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); };
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;
466 for (
const auto& p : scan.cells)
if (p.valid) shiftedTerrain.emplace(plotKey(p.u,p.v),&p);
467 terrainIndexed =
true;
469 const auto it = shiftedTerrain.find(plotKey(tcp.u,tcp.v));
470 return it == shiftedTerrain.end() ? nullptr : it->second;
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;
479 for (
int u = 0; u < 63; ++u)
for (
int v = 0; v < 63; ++v)
481 const auto* cell = findCell(u,v);
489 const auto p = o.corners[0];
495 for (
int xx = 0; xx < 63; xx++)
497 for (
int yy = 0; yy < 63; yy++)
511 else if (
gridarray[xx][yy].elevation < 952)
513 else if (
gridarray[xx][yy].elevation < 1904)
515 else if (
gridarray[xx][yy].elevation < 2856)
517 else if (
gridarray[xx][yy].elevation < 3808)
519 else if (
gridarray[xx][yy].elevation < 4760)
521 else if (
gridarray[xx][yy].elevation < 5712)
523 else if (
gridarray[xx][yy].elevation < 6664)
525 else if (
gridarray[xx][yy].elevation < 7616)
527 else if (
gridarray[xx][yy].elevation < 8568)
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,
546 for (
const auto& obstacle : terrain.obstacles)
549 float left = FLT_MAX, top = FLT_MAX, right = -FLT_MAX, bottom = -FLT_MAX;
550 for (
const auto& p : obstacle.corners)
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);
557 if (!std::isfinite(left) || right < x || left >
x+530*
xScale || bottom < y || top >
y+530*
yScale)
continue;
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}};
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);
600 const RECT rectangle={0,0,32,32};
606 const auto& p=quad.corners[i];
618 for(
const auto& quad:radar.echoes) draw(quad);
629 const bool compact=
xScale<.4f;
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);
640 const auto& terrain = g.
terrain;
641 const RECT rectangle = {0,0,32,32};
643 const auto box = [&](
float left,
float top,
float width,
float height,
DWORD color) {
646 {cx+left+width,cy+top+height},{cx+left,cy+top+height}};
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);
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);
668 if (g.testPattern) message(L
"EGPWS SELF TEST",-39,0xffffffff);
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);
676 if (g.testLevel == 1)
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);
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);
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);
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);
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);
709 const bool high =
terrainMaximum < reference+(terrain.gearDown ? -.0762f : -.1524f);
711 const auto style = [&](
float height) {
return GpwsDisplay::Relative(height,terrain.altitudeKm,terrain.verticalKms,
716 box(-58,-115,116,13,0xf0000000);
721 swprintf_s(label,L
"%03d",
int(std::floor(minimum/.03048f)));
SCRIPT_CONTROL SCRIPT_STATE const void int
HRESULT(WINAPI *CUniBuffer::_ScriptApplyDigitSubstitution)(const SCRIPT_DIGITSUBSTITUTE *
SCRIPT_CONTROL SCRIPT_STATE const void DWORD
const RiseMath::Vector3 northpoleK
float MapScaleInnerRingKm
RiseMath::Vector3 lastWaypointLocation
std::vector< Swaypoint > waypoint
RiseMath::Vector3 BattleRoyaleRingCenter
float HeadingMagneticDegrees
WeatherRadarModel::Display weatherRadar
Rendering::RenderSprite * pSprite
Rendering::RenderTexture * GetTextureSRV(std::string pathAndFilename)
Rendering::RenderDevice * GetD3DDevice()
Instrument(int prmX, int prmY, float prmXScale, float prmYScale, Bus *prmBus, Logger *prmLogger, DeviceObject *prmDevice, std::vector< Font * > prmFonts)
void AddToCallStack(const char *msg)
bool WeatherRadarSelected() const
RiseMath::Matrix assayTransform[21]
Rendering::RenderTexture * assayTexture
DWORD colorColor[drawlistC]
std::vector< unsigned > obstacleDensity
std::vector< RiseMath::Matrix > obstacleGrid
std::vector< Swaypoint > waypoints
RiseMath::Vector2 relativeCenter
void FrameMove(float fElapsed) override
RiseMath::Matrix colorGrid[drawlistC]
Rendering::RenderTexture * terrainTexture
MovingMap(int prmX, int prmY, float prmXScale, float prmYScale, Bus *prmBus, Logger *prmLogger, DeviceObject *prmDevice, std::vector< Font * > prmFonts)
std::vector< Swaypoint > classGs
void RenderWeatherRadar()
std::vector< DWORD > obstacleColors
Microsoft::WRL::ComPtr< Rendering::RenderTexture > terrainStipple[2]
RiseMath::Matrix lookAtLH
unsigned terrainDensity[drawlistC]
DWORD terrainColors[drawlistC]
VECTOR2SHORT assayGrid[21]
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)
void SetLocation(int absoluteX, int absoluteY)
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)
void Draw(RiseMath::Color prmColor)
s_network_objects playerships[MAX_SCAN]
LOCALGRID2 gridarray[64][64]
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)
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)
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)
Vector3 * Vec3TransformCoord(Vector3 *out, const Vector3 *a, const Matrix *m)
float Vec2Length(const Vector2 *a)
Matrix * MatrixLookAtLH(Matrix *out, const Vector3 *eye, const Vector3 *at, const Vector3 *up)
Matrix * MatrixInverse(Matrix *out, float *determinant, const Matrix *a)
Vector3 * Vec3Normalize(Vector3 *out, const Vector3 *a)
Matrix * MatrixRotationZ(Matrix *out, float value)
constexpr auto Max(A first, B second)
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
bool TerrainDisplayActive() const
TerrainAwareness::State terrain
unsigned char pri_landform
SAssayVertex gridarray[5][5]
bool weatherRadarEquipped
RiseMath::Vector3 location