Rise
The Vieneo Province
Loading...
Searching...
No Matches
TerrainAlertStability.h
Go to the documentation of this file.
1#pragma once
2
3#include "TerrainAwareness.h"
4#include <map>
5
7{
8 // Rise annunciation tuning, not a Honeywell envelope or atmospheric constant.
9 // Never delay detection/escalation; require two seconds without a hazard
10 // before releasing it. Independent timers allow warning -> caution -> clear.
11 constexpr float AlertReleaseSeconds = 2.f;
12 struct AlertHold
13 {
15 Severity Update(Severity detected, float seconds)
16 {
18 (std::max)(0.f,cautionRemaining-seconds);
20 (std::max)(0.f,warningRemaining-seconds);
23 }
24 };
25
27 {
28 // TCP identities survive grid shifts. Absolute mesh bounds survive
29 // collector reordering; vector indices and ship-relative positions do not.
30 using CellKey = std::pair<int,int>;
31 using ObstacleKey = std::array<float,7>;
32 std::map<CellKey,AlertHold> cells;
33 std::map<ObstacleKey,AlertHold> obstacles;
34 public:
35 void Reset() { cells.clear(); obstacles.clear(); }
36 void Update(State& state, float seconds, bool active)
37 {
38 if (!active || !std::isfinite(seconds) || seconds <= 0)
39 {
40 Reset();
41 state.ClearThreats();
42 return;
43 }
44 std::map<CellKey,AlertHold> nextCells;
45 std::map<ObstacleKey,AlertHold> nextObstacles;
46 state.terrain = state.obstacle = Severity::None;
47 for (auto& cell : state.cells)
48 {
49 if (!cell.valid) continue;
50 const CellKey key{cell.u,cell.v};
51 const auto old = cells.find(key);
52 AlertHold hold = old == cells.end() ? AlertHold{} : old->second;
53 cell.severity = hold.Update(cell.severity,seconds);
54 if (cell.severity != Severity::None) nextCells.emplace(key,hold);
55 state.terrain = Max(state.terrain,cell.severity);
56 }
57 for (auto& obstacle : state.obstacles)
58 {
59 const auto low = obstacle.corners.front(), high = obstacle.corners.back();
60 if (!Finite(low) || !Finite(high) || !std::isfinite(obstacle.topKm))
61 { obstacle.severity = Severity::None; continue; }
62 const ObstacleKey key{low.x,low.y,low.z,high.x,high.y,high.z,obstacle.topKm};
63 const auto old = obstacles.find(key);
64 AlertHold hold = old == obstacles.end() ? AlertHold{} : old->second;
65 obstacle.severity = hold.Update(obstacle.severity,seconds);
66 if (obstacle.severity != Severity::None) nextObstacles.emplace(key,hold);
67 state.obstacle = Max(state.obstacle,obstacle.severity);
68 }
69 // Missing/invalid geometry is unknown, not a retained ghost hazard.
70 // Only current, valid geometry can keep an annunciation alive.
71 cells.swap(nextCells); obstacles.swap(nextObstacles);
72 }
73 };
74}
void Update(State &state, float seconds, bool active)
std::map< ObstacleKey, AlertHold > obstacles
std::map< CellKey, AlertHold > cells
constexpr float AlertReleaseSeconds
Severity Max(Severity a, Severity b)
bool Finite(Point p)
Severity Update(Severity detected, float seconds)
std::array< Cell, GridSize *GridSize > cells
std::vector< Obstacle > obstacles