Rise
The Vieneo Province
Loading...
Searching...
No Matches
OrbitDisplay.h
Go to the documentation of this file.
1#pragma once
2#include "OrbitState.h"
3#include <cwchar>
4
5// Shared, device-independent presentation: fixed 420x320 layout in every mode.
6// Cached by the instrument on snapshot/view changes, never solves during Draw.
7namespace Orbital
8{
9constexpr std::uint32_t Green=0xff00ff00,Cyan=0xff00ffff,Amber=0xffffcb4b,Red=0xffff3030,Gray=0xffaaaaaa,Dim=0xff466052;
10struct Point { double x=0,y=0; };
11struct Line { Point a,b; std::uint32_t color; };
12struct Label { int x,y; std::wstring text; std::uint32_t color; };
13struct Picture { std::vector<Line> lines; std::vector<Label> labels; };
14inline std::wstring Number(double n,int precision=0)
15{
16 if(!std::isfinite(n)) return L"---";
17 wchar_t text[64]; std::swprintf(text,64,L"%.*f",precision,n); return text;
18}
19inline std::wstring Clock(double seconds)
20{
21 if(!std::isfinite(seconds)||seconds<0) return L"PASSED";
22 int t=int((std::min)(seconds,359999.0)); wchar_t text[32];
23 std::swprintf(text,32,L"%02d:%02d",t/60,t%60); return text;
24}
25inline const wchar_t* ModeName(Mode m)
26{
27 switch(m) { case Mode::Adjust:return L"ADJUST ORBIT"; case Mode::Rendezvous:return L"RENDEZVOUS";
28 case Mode::Overfly:return L"OVERFLY"; case Mode::Return:return L"REENTRY";case Mode::Ascent:return L"PARKING ORBIT"; default:return L"TARGET"; }
29}
30inline const wchar_t* ViewName(View v)
31{
32 switch(v) { case View::Orbit:return L"ORBIT PLANE"; case View::Plane:return L"PLANE ORIENTATION";
33 case View::Edge:return L"PLANE EDGE-ON"; default:return L"GROUND TRACK"; }
34}
35inline bool AscentView(const Snapshot& s,View view)
36{
37 if(s.plan.ascent||s.mode==Mode::Ascent)return view==View::Orbit;
38 // Surface previews may inspect the whole proposed journey before takeoff.
39 // ORBIT retains the automatic local ascent detail below 100 km.
40 return s.ascentDetail&&(s.mode!=Mode::Return||view==View::Orbit);
41}
42inline std::wstring RowText(Row row,const Request& r,const Snapshot& s,double now)
43{
44 const auto contents=[&]() -> std::wstring {
45 switch(row) {
46 case Row::Mode:return std::wstring(L"MODE ")+(s.mode==Mode::Return?(s.plan.entry.active?L"REENTRY":L"SURFACE PLAN"):ModeName(Objective(r,s.targetKind)));
47 case Row::Route:return std::wstring(L"ROUTE ")+RouteName(r.route)+(r.route==Route::Auto&&s.plan.surface.available?L">"+std::wstring(RouteName(s.plan.surface.route)):L"");
48 case Row::Lock:return std::wstring(L"LOCK ")+(r.lock==Lock::None?L"NONE":(r.lock==Lock::Ap?L"AP ":L"PE ")+Number(r.heldRadiusKm-s.radius)+L"km");
49 case Row::Eccentricity:return L"e "+Number(r.eccentricity,4);
50 case Row::Size:return L"SIZE "+Number(r.sizeKm-s.radius,1)+L"km MSL";
51 case Row::Altitude:return L"ALT "+Number(r.altitudeKm)+L"km MSL";
52 case Row::AscentAltitude:return L"ORBIT "+Number(r.ascentAltitudeKm)+L"km MSL";
53 case Row::AscentSteering:return r.ascentOrbitSteering?L"STEER ORBIT":L"STEER AFCS";
54 case Row::AscentLaunch:return !s.onGround?L"LAUNCH AIRBORNE PICKUP":r.ascentWait?L"LAUNCH AUTO":L"LAUNCH NOW";
55 case Row::Arrival:return std::wstring(s.plan.entry.active?L"HANDOFF ":r.surfaceDurationHeld?L"TRIP ":s.mode==Mode::Overfly||s.mode==Mode::Return?L"PASS ":L"MEET ")+
56 (r.fastestMeet?std::wstring(L"FASTEST (AUTO)"):Clock(r.surfaceDurationHeld?r.arrivalSeconds:r.arrivalEpoch-now));
57 case Row::EntryHandoff:return r.automaticHandoff?L"TARGET AUTO":L"TARGET SET";
58 case Row::EntryAltitude:return L"H ALT "+(r.automaticHandoff?(s.plan.valid?Number(s.plan.entry.handoffAltitudeKm):L"---"):Number(r.entryAltitudeKm))+L"km MSL";
59 case Row::EntrySpeed:return L"H TAS "+(r.automaticHandoff?(s.plan.valid?Number(s.plan.entry.handoffSpeedKms,2):L"---"):Number(r.entrySpeedKms,2))+L"km/s";
60 case Row::Final:return std::wstring(L"FINAL ")+FinalName(r.final)+(r.final==Final::Vtol?L" (PLAN)":L"");
61 case Row::FinalDistance:return L"FINAL "+Number(r.finalDistanceKm)+L"km / 3deg";
62 case Row::Record:return !r.recordPreview?L"REC OFF":r.recordFlightOnly?L"REC ON (FLIGHT)":L"REC ON (REF)";
63 case Row::Exit:return std::wstring(L"EXIT ")+(r.circularizeAfter?L"CIRCULARIZE":L"COAST");
64 case Row::Start:return std::wstring(L"START ")+(r.start==Start::Now?L"NOW":r.start==Start::Auto?L"AUTO":L"AT TIME");
65 case Row::Delay:return L"IN "+Clock(r.departureEpoch-now);
66 case Row::View:return AscentView(s,r.view)?L"VIEW ASCENT (AUTO)":std::wstring(L"VIEW ")+(r.view==View::Plane?L"PLANE 3D":r.view==View::Orbit?L"ORBIT":r.view==View::Edge?L"EDGE-ON":L"TRACK");
67 }
68 return L"";
69 };
70 auto result=contents();
71 const size_t labelEnd=(row==Row::EntryAltitude||row==Row::EntrySpeed)?5:result.find(L' ');
72 if(labelEnd!=std::wstring::npos) {
73 const auto value=result.find_first_not_of(L' ',labelEnd);
74 if(value!=std::wstring::npos) result=result.substr(0,labelEnd)+
75 std::wstring((s.plan.entry.active?8:7)-labelEnd,L' ')+result.substr(value);
76 }
77 return result;
78}
79inline Picture Plot(const Snapshot& s,View view)
80{
81 Picture p;
82 auto orbitalFooter=[&]() {
83 if(s.mode==Mode::Ascent||s.plan.ascent) {
84 p.labels.push_back({7,285,s.onGround?L"LAUNCH EST / NO TERRAIN CHECK":L"PARKING ORBIT / GUIDANCE ONLY",Amber});return;
85 }
86 // This is the checked planned route, not the actual unpowered coast or
87 // the final orbit's PE. Keep it visible before engagement in every view.
88 const auto& c=s.plan.clearance;
89 const bool known=c.known&&std::isfinite(c.minimumKm)&&
91 const auto color=!known?Gray:c.minimumKm<OrbitalClearanceKm?Red:
93 p.labels.push_back({7,285,L"PLAN MIN ALT "+(known?Number(c.minimumKm,1)+L"km MSL":L"---"),color});
94 p.labels.push_back({165,285,L"OWN",Green});
95 p.labels.push_back({187,285,L"TARGET",Cyan});
96 p.labels.push_back({222,285,L"PLAN",Amber});
97 };
98 constexpr double left=12,right=239,top=43,bottom=270,cx=(left+right)/2,cy=(top+bottom)/2;
99 auto line=[&](Point a,Point b,std::uint32_t c) {
100 if(!std::isfinite(a.x)||!std::isfinite(a.y)||!std::isfinite(b.x)||!std::isfinite(b.y)) return;
101 // Liang-Barsky clipping avoids drawing false lines along the border when
102 // a local ascent trajectory or the surface extends beyond the viewport.
103 const double dx=b.x-a.x,dy=b.y-a.y; double first=0,last=1;
104 auto clip=[&](double direction,double distance) {
105 if(std::abs(direction)<1e-12) return distance>=0;
106 const double t=distance/direction;
107 if(direction<0) { if(t>last) return false; first=(std::max)(first,t); }
108 else { if(t<first) return false; last=(std::min)(last,t); }
109 return true;
110 };
111 if(!clip(-dx,a.x-5)||!clip(dx,247-a.x)||!clip(-dy,a.y-38)||!clip(dy,281-a.y)) return;
112 b={a.x+last*dx,a.y+last*dy}; a={a.x+first*dx,a.y+first*dy};
113 p.lines.push_back({a,b,c});
114 };
115 auto label=[&](Point at,const std::wstring& text,std::uint32_t c) {
116 p.labels.push_back({int((std::clamp)(at.x,6.0,246.0-5*text.size())),int((std::clamp)(at.y,38.0,268.0)),text,c});
117 };
118 auto mark=[&](Point at,const std::wstring& text,std::uint32_t c) {
119 line({at.x-3,at.y},{at.x,at.y-3},c); line({at.x,at.y-3},{at.x+3,at.y},c);
120 line({at.x+3,at.y},{at.x,at.y+3},c); line({at.x,at.y+3},{at.x-3,at.y},c);
121 if(!text.empty()) label({at.x+5,at.y-6},text,c);
122 };
123 if(AscentView(s,view)&&(s.plan.ascent||s.mode==Mode::Ascent)) {
124 const auto& profile=s.ascentProfile;
125 p.labels.push_back({7,22,L"ASCENT / ALTITUDE VS DISTANCE",Cyan});
126 p.labels.push_back({7,38,L"PLAN EST",Amber});
127 p.labels.push_back({72,38,L"ACTUAL",Green});
128 p.labels.push_back({7,53,L"ALT km MSL",Gray});
129 constexpr double x0=38,x1=237,y0=239,y1=73;
130 double distance=10,height=25;
131 for(const auto* path:{&profile.plan,&profile.actual})for(const auto& a:*path) {
132 if(std::isfinite(a.distanceKm))distance=(std::max)(distance,a.distanceKm);
133 if(std::isfinite(a.altitudeKm))height=(std::max)(height,a.altitudeKm);
134 }
135 auto scale=[](double maximum) {
136 const double power=std::pow(10.0,std::floor(std::log10(maximum)));
137 for(double step:{1.,2.,2.5,5.,10.})if(step*power>=maximum)return step*power;
138 return 10*power;
139 };
140 distance=scale(distance);height=scale(height);
141 for(int j=0;j<=4;++j) {
142 const double fraction=j/4.,x=x0+(x1-x0)*fraction,y=y0-(y0-y1)*fraction;
143 line({x,y1},{x,y0},Dim);line({x0,y},{x1,y},Dim);
144 const auto altitude=Number(height*fraction,height<100?1:0);
145 p.labels.push_back({int(x0)-int(altitude.size()*5)-4,int(y)-6,altitude,Gray});
146 const auto range=Number(distance*fraction,distance<100?1:0);
147 p.labels.push_back({int(x)-int(range.size()*5)/2,246,range,Gray});
148 }
149 p.labels.push_back({38,264,profile.pickup?L"DIST FROM PICKUP (km)":L"GROUND DISTANCE (km)",Gray});
150 auto project=[&](const AscentPoint& a) {
151 return Point{x0+(x1-x0)*a.distanceKm/distance,
152 y0-(y0-y1)*(std::max)(0.0,a.altitudeKm)/height};
153 };
154 auto draw=[&](const std::vector<AscentPoint>& path,std::uint32_t color) {
155 for(size_t j=1;j<path.size();++j)line(project(path[j-1]),project(path[j]),color);
156 };
157 draw(profile.plan,Amber);draw(profile.actual,Green);
158 if(!profile.actual.empty())mark(project(profile.actual.back()),L"",Green);
159 if(profile.plan.empty())p.labels.push_back({46,130,profile.pending?L"COMPUTING PLAN...":L"PLAN UNAVAILABLE",Amber});
160 else if(profile.planFromKm>0)p.labels.push_back({117,38,L"FROM "+Number(profile.planFromKm)+L"km",Amber});
161 p.labels.push_back({7,285,profile.pending?L"COMPUTING POWERED PLAN":profile.status,Amber});
162 return p;
163 }
164 if(AscentView(s,view)) {
165 // Local vertical detail, equal km/pixel axes. Surface profiles are
166 // explicit estimates; other objectives still show measured coast only.
167 p.labels.push_back({7,22,s.plan.localSurfaceTrip?L"LOCAL FLIGHT / NO PLAN":s.mode==Mode::Return?
168 (s.plan.valid?L"ASCENT / PLAN ONLY":s.plan.surface.available?L"ASCENT / INVALID PREVIEW":L"ASCENT / NO PLAN"):
169 s.plan.ascent?L"ASCENT / ACTUAL COAST":L"ASCENT DETAIL / COAST",Cyan});
170 const Vec up=Unit(s.ownState.r);
171 Vec horizontal=s.mode==Mode::Return?Unit(s.targetState.r-up*Dot(s.targetState.r,up)):
172 Unit(s.ownState.v-up*Dot(s.ownState.v,up));
173 if(Norm(horizontal)<.5) horizontal=Unit(Cross({0,0,1},up));
174 if(Norm(horizontal)<.5) horizontal={1,0,0};
175 constexpr double kmPerPixel=.6;
176 auto local=[&](Vec point) { return Point{55+Dot(point,horizontal)/kmPerPixel,254-(Dot(point,up)-s.radius)/kmPerPixel}; };
177 for(int i=-25;i<100;++i) {
178 const double x1=i*.001,x2=(i+1)*.001;
179 line(local((up*std::cos(x1)+horizontal*std::sin(x1))*s.radius),local((up*std::cos(x2)+horizontal*std::sin(x2))*s.radius),Dim);
180 }
181 for(double h:{0,25,50,75,100}) {
182 const double yy=254-h/kmPerPixel;
183 line({12,yy},{17,yy},Gray); label({18,yy-12},Number(h)+L"km",Gray);
184 }
185 if(s.own.valid) {
186 for(size_t i=1;i<s.ownPath.size();++i) {
187 const auto a=local(s.ownPath[i-1].r),b=local(s.ownPath[i].r);
188 if(a.x<12||a.x>239||a.y<43||a.y>254||b.x<12||b.x>239||b.y<43||b.y>254) continue;
189 line(a,b,Green);
190 }
191 }
192 // This local surface view rotates with the departure point; planetary
193 // rotation must not carry a vertical climb sideways out of the plot.
194 auto planned=[&](const Sample& point) { return local(Rotate(point.r,{0,0,1},-s.spin*point.seconds)); };
195 for(size_t i=1;i<s.plan.path.size();++i) line(planned(s.plan.path[i-1]),planned(s.plan.path[i]),Amber);
196 mark(local(s.ownState.r),L"OWN",Green);
197 if(s.mode==Mode::Return) p.labels.push_back({7,285,s.plan.localSurfaceTrip?L"LOCAL FLIGHT REQUIRED":
198 !s.plan.valid&&s.plan.surface.available?L"REJECTED PREVIEW":L"PREVIEW / ATM HANDOFF",Amber});
199 else orbitalFooter();
200 return p;
201 }
202 p.labels.push_back({7,22,ViewName(view),Cyan});
203 Vec u=s.own.valid?s.own.peri:Vec{1,0,0},v=s.own.valid?s.own.transverse:Vec{0,1,0};
204 if(s.mode==Mode::Return&&!s.own.valid) {
205 u=Unit(s.ownState.r); v=Unit(s.targetState.r-u*Dot(s.targetState.r,u));
206 if(Norm(v)<.5) v=Unit(Cross(std::abs(u.z)<.9?Vec{0,0,1}:Vec{0,1,0},u));
207 }
208 if(view==View::Edge) v=s.own.valid?s.own.normal:Vec{0,0,1};
209 if(view==View::Plane) { const double az=-10*Pi/180,el=25*Pi/180;
210 u={-std::sin(az),std::cos(az),0}; v={-std::sin(el)*std::cos(az),-std::sin(el)*std::sin(az),std::cos(el)}; }
211 double extent=s.radius*1.2;
212 auto include=[&](Vec a) { extent=(std::max)(extent,(std::max)(std::abs(Dot(a,u)),std::abs(Dot(a,v)))); };
213 for(const auto* points:{&s.ownPath,&s.targetPath,&s.plan.path,&s.plan.coast,&s.plan.goalPath}) for(const auto& a:*points) include(a.r);
214 const double scale=extent>0?103/extent:0;
215 auto project=[&](Vec a,double t=0.0) -> Point {
216 if(view==View::Track) {
217 a=Rotate(a,{0,0,1},-s.spin*t);
218 // Physical planet axes: -Y prime meridian, +X east, -Z north.
219 // Match the Player Portal's geographic coordinates and [-180,180]
220 // extent; the orbital math's X-axis azimuth is not longitude.
221 const double longitude=std::atan2(a.x,-a.y),latitude=-std::asin((std::clamp)(Unit(a).z,-1.0,1.0));
222 return {left+(longitude+Pi)/Tau*(right-left),bottom-(latitude+Pi/2)/Pi*(bottom-top)};
223 }
224 return {cx+Dot(a,u)*scale,cy-Dot(a,v)*scale};
225 };
226 if(view==View::Track) {
227 for(int i=0;i<=6;++i) { const double x=left+(right-left)*i/6; line({x,top},{x,bottom},Dim); }
228 for(int i=0;i<=4;++i) { const double y=top+(bottom-top)*i/4; line({left,y},{right,y},Dim); }
229 label({left,top},L"N",Gray); label({left,bottom-12},L"S",Gray);
230 } else {
231 const double radius=s.radius*scale;
232 for(int i=0;i<96;++i) { const double a=Tau*i/96,b=Tau*(i+1)/96;
233 line({cx+radius*std::cos(a),cy+radius*std::sin(a)},{cx+radius*std::cos(b),cy+radius*std::sin(b)},Dim); }
234 // Equatorial reference and the planet's north axis explain the 3D view.
235 if(view==View::Plane) {
236 for(int i=0;i<96;++i) line(project({s.radius*std::cos(Tau*i/96),s.radius*std::sin(Tau*i/96),0}),
237 project({s.radius*std::cos(Tau*(i+1)/96),s.radius*std::sin(Tau*(i+1)/96),0}),Dim);
238 line(project({}),project({0,0,s.radius*1.15}),Gray); label(project({0,0,s.radius*1.15}),L"N",Gray);
239 }
240 label({cx-15,cy-6},L"VIENEO",Dim);
241 }
242 auto path=[&](const std::vector<Sample>& points,std::uint32_t c,bool dashed) {
243 for(size_t i=1;i<points.size();++i) {
244 if(dashed&&(i/3)%2) continue;
245 const auto a=project(points[i-1].r,points[i-1].seconds),b=project(points[i].r,points[i].seconds);
246 if(view!=View::Track||std::abs(a.x-b.x)<(right-left)/2) line(a,b,c);
247 }
248 };
249 path(s.ownPath,Green,false); path(s.targetPath,Cyan,false);
250 if(view!=View::Track) path(s.plan.goalPath,0xff8c7130,true);
251 path(s.plan.coast,Gray,true); path(s.plan.path,Amber,true);
252 path(s.plan.arrival.path,Gray,true);
253 if(s.own.valid&&view!=View::Track) {
254 mark(project(s.own.peri*s.own.pe),L"PE",Green);
255 if(s.own.bound) mark(project(s.own.peri*(-s.own.ap)),L"AP",Green);
256 if(s.plan.valid&&!s.plan.planningOnly) {
257 mark(project(s.plan.goal.peri*s.plan.goal.pe),L"PE",Amber);
258 mark(project(s.plan.goal.peri*(-s.plan.goal.ap)),L"AP",Amber);
259 }
260 if(s.target.valid) {
261 const Vec nodes=Cross(s.own.normal,s.target.normal);
262 if(Norm(nodes)>1e-4) { const Vec n=Unit(nodes)*s.radius*1.05;
263 line(project(n),project(n*(-1)),Dim); label(project(n),L"NODE",Cyan); }
264 }
265 }
266 if(Norm(s.ownState.r)>1) mark(project(s.ownState.r),L"",Green);
267 if(s.targetKind!=TargetKind::None) mark(project(s.targetState.r),L"T",Cyan);
268 if(!s.plan.planningOnly) for(size_t i=0;i<s.plan.burns.size();++i) mark(project(s.plan.burns[i].position,s.plan.burns[i].at),Number(double(i+1)),Amber);
269 for(size_t i=0;i<s.plan.handoffs.size();++i) {
270 const auto& point=s.plan.handoffs[i];
271 const auto at=project(point.r,point.seconds);
272 mark(at,L"",Amber);
273 Point textAt{(std::clamp)(at.x+5,6.0,231.0),(std::clamp)(at.y-6,38.0,268.0)};
274 // Nearby phase boundaries need separate labels at this small resolution.
275 for(int attempt=0;attempt<20;++attempt) {
276 bool overlap=false;
277 for(const auto& other:p.labels)
278 overlap=overlap||(std::abs(textAt.y-other.y)<11&&textAt.x<other.x+other.text.size()*5+3&&textAt.x+8>other.x);
279 if(!overlap) break;
280 textAt.y+=12; if(textAt.y>268) textAt.y=38;
281 }
282 line(at,textAt,Dim);
283 label(textAt,s.plan.entry.active?(i==0?L"D":i+1==s.plan.handoffs.size()?L"H":L"E"):
284 i+1==s.plan.handoffs.size()?L"B":Number(double(i+1)),Amber);
285 }
286 if(s.mode!=Mode::Return) orbitalFooter();
287 else if(s.plan.entry.active) p.labels.push_back({7,285,s.plan.arrival.valid?
288 L"FINAL "+Number(s.plan.arrival.altitudeKm,2)+(s.plan.arrival.mode==Final::Ils?L"km MSL / ILS":L"km MSL / MANUAL"):L"D DEORBIT E 100km H HANDOFF",Amber});
289 else if(s.plan.handoffs.size()>1) p.labels.push_back({7,285,L"1 CLIMB 2 COAST 3 BRAKE 4 ENTRY",Amber});
290 else { p.labels.push_back({7,285,L"OWN",Green}); p.labels.push_back({47,285,L"TARGET",Cyan}); p.labels.push_back({102,285,L"PLAN",Amber}); }
291 return p;
292}
293inline std::vector<Label> Readouts(const BusState& data,const std::vector<Row>& rows,int uiRow,bool dorActive,bool showKeys=true)
294{
295 std::vector<Label> labels;
296 const auto& s=data.snapshot; const auto& r=data.request;
297 auto text=[&](const std::wstring& value,int xx,int yy,std::uint32_t color=Gray) {
298 labels.push_back({xx,yy,value,color});
299 };
300 // One second on / one second off, shared by EXEC and the active phase.
301 const bool executionVisible=std::fmod((std::max)(0.0,data.clock),2.0)<1.0;
302 const bool rejectedSurface=s.mode==Mode::Return&&!s.plan.entry.active&&s.plan.surface.available&&!s.plan.valid;
303 text(L"DOR",5,2,0xffff00ff);
304 text(s.targetName.substr(0,24),45,2,Cyan);
305 text(s.flightPhase,185,2,Gray);
306 if(!dorActive||executionVisible)
307 text(dorActive?(data.guidance.ascentWaiting?L"ARMED":L"EXEC"):data.approach.active?L"DESCENT":data.speedHoldValid?L"HOLD":rejectedSurface?L"INVALID":
308 !s.plan.valid?L"NO PLAN":s.plan.ascent?(data.launch.pending?L"SEARCH":
309 s.onGround&&(r.ascentWait||s.mode==Mode::Rendezvous)&&!data.launch.valid?L"NO FIT":
310 s.onGround&&data.launch.valid&&!data.launch.fuelEnough?L"FUEL":L"READY"):
311 s.plan.planningOnly?L"PLAN ONLY":s.plan.entry.active?L"READY":L"ESTIMATE",350,2,
312 !dorActive&&!data.speedHoldValid&&rejectedSurface?Red:Amber);
313 for(size_t i=0;i<rows.size();++i) {
314 const int yy=22+int(i)*12;
315 if(int(i)==uiRow) text(std::wstring(31,L'\x2592'),255,yy,0xff00a0a0);
316 text(rows[i]==Row::Arrival&&data.speedHoldValid?L"HANDOFF COMPLETE":rows[i]==Row::Record&&data.captureState>=2?
317 (data.captureState==2?L"REC FILE ERROR":L"REC FILE FULL"):RowText(rows[i],r,s,data.clock),255,yy,
318 rows[i]==Row::Record&&data.captureState>=2?Red:0xffdddddd);
319 }
320 const bool compact=rows.size()>=7;
321 const int dy=22+int(rows.size())*12+(compact?0:8);
322 if(s.mode==Mode::Ascent||s.plan.ascent) {
323 const auto& g=data.guidance;
324 if(s.mode==Mode::Rendezvous) text(L"STAGING "+Number(r.ascentAltitudeKm)+L"km MSL / AUTO",255,250,Gray);
325 if(s.onGround&&(!dorActive||g.ascentWaiting)) {
326 const auto& e=data.launch;
327 const bool now=e.valid&&e.launchEpoch-e.epoch<1&&data.clock-e.epoch<=30;
328 const bool current=e.valid&&e.launchEpoch>=data.clock;
329 const auto fuelText=[&](double fuel) {return fuel>=0?L"~"+Number(fuel)+L"kg":std::wstring(e.pending?L"---":L"NO FIT");};
330 text(g.ascentPlanning?L"ARMED / COMPARING LAUNCHES":g.ascentWaiting?L"ARMED / LAUNCH WAIT":e.pending?(e.fastest?L"FINDING FASTEST RENDEZVOUS":L"COMPARING LAUNCH TIMES..."):L"MEET / LAUNCH ESTIMATE",255,dy,Cyan);
331 text(e.pending?L"CANDIDATE / NOT COMMITTED":g.ascentWaiting?L"LIFTOFF IN "+Clock(g.ascentLaunchEpoch-data.clock):now?L"LAUNCH NOW":current?L"LAUNCH IN "+Clock(e.launchEpoch-data.clock):e.valid?L"LAUNCH PASSED / UPDATING":L"LAUNCH ---",255,dy+12,Amber);
332 text(e.valid?L"FACE "+Number(e.heading*180/Pi)+L"deg T / "+(r.ascentOrbitSteering?L"ORBIT":L"AFCS"):L"FACE ---",255,dy+24,0xffff00ff);
333 text(e.valid?L"INSERT IN ~"+Clock(e.insertionEpoch-data.clock):L"INSERT ---",255,dy+36,Gray);
334 text(e.valid?L"ASC ~"+Number(e.ascentFuel)+L"kg XFER ~"+Number(e.transferFuel)+L"kg":L"ASC --- XFER ---",255,dy+48,Gray);
335 text(e.valid?L"TOTAL ~"+Number(e.ascentFuel+e.transferFuel)+L"kg":L"TOTAL ---",255,dy+60,e.valid&&!e.fuelEnough?Red:Amber);
336 text(L"MEET -5m "+fuelText(e.earlierFuel),255,dy+72,Gray);
337 text(L"MEET +5m "+fuelText(e.laterFuel),255,dy+84,Gray);
338 text(e.status.substr(0,31),255,dy+96,e.valid?Amber:Gray);
339 text(L"CURRENT GEAR / FIXED WEATHER",255,dy+108,Gray);
340 text(L"EST / NO ATTITUDE-RCS FUEL",255,dy+120,Gray);
341 text(g.ascentWaiting?L"DOR OFF / INPUT CANCELS WAIT":r.ascentWait?L"DOR ARMS RECOMMENDED LAUNCH":L"DOR LIFTS IMMEDIATELY",255,dy+132,Cyan);
342 text((g.status.empty()?s.status:g.status).substr(0,31),255,266,Amber);
343 text(s.mode==Mode::Rendezvous?L"AUTO TRANSFER AFTER INSERTION":L"REPLAN RENDEZVOUS IN ORBIT",255,278,Amber);
344 text(L"GEAR RETRACTION: PILOT",255,290,Gray);
345 if(showKeys) {text(L"\x21e7+\x2190/\x2192 Change",5,304,0xff00a0a0);text(L"\x21e7+\x2191/\x2193 Select row",315,304,0xff00a0a0);}
346 return labels;
347 }
348 text(s.mode==Mode::Rendezvous?L"ASCENT / AUTO TRANSFER NEXT":L"PARKING ORBIT / NO ETA",255,dy,Cyan);
349 text(L"ALT "+Number(Norm(s.ownState.r)-s.radius,1)+L"km MSL",255,dy+14,Green);
350 text(L"AP "+(s.own.bound?Number(s.own.ap-s.radius,1):L"---")+L"km",255,dy+26,Green);
351 text(L"PE "+(s.own.valid?Number(s.own.pe-s.radius,1):L"---")+L"km",255,dy+38,Green);
352 text(L"ORBIT HDG "+Number(g.ascentOrbitHeading*180/Pi)+L"deg T",255,dy+54,0xffff00ff);
353 text(L"PITCH "+(g.ascentControl?Number(g.pitch*180/Pi,1):L"---")+L"deg",255,dy+66,Gray);
354 text(L"MAIN "+(g.ascentControl?Number(g.ascentMain*100):L"---")+L"% RCS "+
355 (g.ascentControl?Number(g.ascentNormal*100):L"---")+L"%",255,dy+78,Gray);
356 text(L"TGT TAS "+(g.ascentControl?Number(g.ascentTargetSpeed,2):L"---")+L"km/s",255,dy+90,Gray);
357 text(L"TGT VSI "+(g.ascentControl?Number(g.ascentTargetClimb*1000):L"---")+L"m/s",255,dy+102,Gray);
358 text(L"IAS "+(g.ascentControl?Number(g.entryForecastIasFraction*100):L"---")+L"% / 95% VNE",255,dy+116,g.entryLimited?Red:Gray);
359 text(L"AFT "+(g.ascentControl?Number(g.entryForecastAftC):L"---")+L"C / 200C",255,dy+128,g.entryLimited?Red:Gray);
360 text(L"USED "+Number(g.fuelUsedKg)+L"kg / NO BUDGET",255,dy+140,Amber);
361 if(!dorActive||executionVisible) text((g.status.empty()?s.status:g.status).substr(0,31),255,266,g.entryLimited?Red:Amber);
362 text(L"ALPHA / NO TERRAIN CHECK",255,278,Amber);
363 text(L"GEAR RETRACTION: PILOT",255,290,Gray);
364 if(showKeys) {text(L"\x21e7+\x2190/\x2192 Change",5,304,0xff00a0a0);text(L"\x21e7+\x2191/\x2193 Select row",315,304,0xff00a0a0);}
365 return labels;
366 }
367 if(s.mode==Mode::Return&&s.plan.entry.active) {
368 const auto& p=s.plan; const auto& e=p.entry;
369 const auto block=EntryEngagementBlock(s);
370 text(p.surface.reason.substr(0,31),255,dy,p.valid&&!p.planningOnly?Green:Amber);
371 const double age=(std::max)(0.0,data.clock-s.epoch);
372 text(L"DEORBIT "+(p.surface.available?Clock(e.coastSeconds-age):L"---"),255,dy+14,Cyan);
373 text(L"100km "+(p.surface.available?Clock(e.entrySeconds-age):L"---"),255,dy+26,Cyan);
374 text(L"ENTRY FUEL ~"+Number(p.fuel)+L"kg",255,dy+40,Amber);
375 text(L"PEAK REV "+Number(e.peakReverse*100)+L"% RCS "+Number(e.peakNormal*100)+L"%",255,dy+52,Gray);
376 text(L"PEAK IAS "+Number(e.peakIasFraction*100)+L"% / 95% VNE",255,dy+64,e.peakIasFraction>.95?Red:Gray);
377 text(L"PEAK AFT "+Number(e.peakAftC)+L"C / 200C",255,dy+76,e.peakAftC>200?Red:Gray);
378 text((p.arrival.valid&&(p.arrival.mode==Final::Ils||p.arrival.mode==Final::Visual)?L"DESC 20>3deg ~":L"GLIDE ~")+
379 Number(e.glideKm)+L"km TO "+(p.arrival.valid?L"FINAL":L"B"),255,dy+88,Gray);
380 text(L"LOAD "+Number(e.peakLoadFraction*100)+L"% / 95% LIMIT",255,dy+104,e.peakLoadFraction>.95?Red:Gray);
381 text(e.skipChecked?L"SKIP CHECKED / ENTRY":L"SKIP NOT CHECKED",255,dy+116,e.skipChecked?Gray:Amber);
382 text(e.transferCoastEnd<=e.transferCoastStart?L"CONTINUOUS ENTRY":
383 age>=e.transferCoastEnd?L"COAST COMPLETE":
384 age>=e.transferCoastStart?L"COAST END "+Clock(e.transferCoastEnd-age):
385 L"COAST "+Clock(e.transferCoastStart-age)+L" / "+Clock(e.transferCoastEnd-age),255,dy+128,Gray);
386 const bool aborted=data.guidance.phase==Phase::Abort;
387 text((dorActive||data.guidance.entryHandoff||aborted)?data.guidance.status.substr(0,31):
388 !block.empty()?block.substr(0,31):data.recordingAllowed&&data.captureState==1?L"REC ON / ARM DOR":L"ARM DOR TO EXECUTE",255,278,
389 data.guidance.entryLimited||aborted?Red:!block.empty()?Amber:Cyan);
390 text(p.arrival.valid?p.arrival.status:data.speedHoldValid?L"TAS HOLD / AFCS GUIDANCE":L"ALPHA / NO TERRAIN CHECK",255,290,Amber);
391 if(showKeys) {text(L"\x21e7+\x2190/\x2192 Change",5,304,0xff00a0a0);text(L"\x21e7+\x2191/\x2193 Select row",315,304,0xff00a0a0);}
392 return labels;
393 }
394 if(s.mode==Mode::Return) {
395 text(r.surfaceDurationHeld?L"ROUTES AT SELECTED TRIP":L"ROUTES AT SELECTED PASS",255,dy,Cyan);
396 for(int i=0;i<3;++i) {
397 const auto& option=s.plan.alternatives[i];
398 const std::wstring name=RouteName(Route(i+1));
399 text(name+(option.available?L" ~"+Number(option.fuel)+L"kg":L" ---"),255,dy+12+i*24,
400 option.fits?Green:Amber);
401 text(option.reason,255,dy+24+i*24,option.fits?Gray:Amber);
402 }
403 const auto& e=s.plan.surface;
404 const double range=Angle(s.ownState.r,s.targetState.r)*s.radius;
405 text(L"RANGE "+Number(range,range<10?1:0)+L"km",255,dy+90,Cyan);
406 text(L"TOP "+(e.available?Number(e.altitudeKm,1)+L"km MSL":L"---"),255,dy+102,Gray);
407 text(L"TOTAL "+(e.available?Number(e.deltaV*1000)+L"m/s":L"---"),255,dy+114,Amber);
408 text(L"FUEL "+(e.available?L"~"+Number(e.fuel)+L"kg":L"---"),255,dy+126,Amber);
409 text(L"THRUST "+(e.available?Number(e.peakThrust*100)+L"% peak":L"---"),255,dy+138,e.available&&e.peakThrust>1?Red:Gray);
410 text(L"MAX q "+(e.available?Number(e.peakQ/1000,1)+L"kPa":L"---"),255,dy+150,Gray);
411 if(e.available&&(s.plan.retrograde||s.plan.reversesOrbit))
412 text(s.plan.reversesOrbit?L"ORBIT REVERSAL":L"RETROGRADE ORBIT",120,22,Amber);
413 text(data.guidance.status.empty()?s.status:data.guidance.status,255,278,rejectedSurface?Red:Amber);
414 text(L"NO TERRAIN / HEAT CHECK",255,290,Gray);
415 if(showKeys&&!rows.empty()) {
416 text(L"\x21e7+\x2190/\x2192 Change",5,304,0xff00a0a0);
417 text(L"\x21e7+\x2191/\x2193 Select row",315,304,0xff00a0a0);
418 }
419 return labels;
420 }
421 const bool plan=s.plan.valid; auto goal=s.plan.goal;
422 // Dedicated steady caution beside the view title: execution blink and the
423 // atmospheric/fuel/finite-burn status lines must not hide orbital direction.
424 if((plan||s.plan.clearanceBlocked)&&(s.plan.reversesOrbit||s.plan.retrograde))
425 text(s.plan.reversesOrbit?(s.plan.retrograde?L"RETROGRADE / REVERSAL":L"ORBIT REVERSAL"):L"RETROGRADE ORBIT",120,22,Amber);
426 const bool draft=!plan&&s.mode==Mode::Adjust&&r.initialized;
427 if(draft) { goal.a=r.lock==Lock::None?r.sizeKm:r.heldRadiusKm/(r.lock==Lock::Ap?1+r.eccentricity:1-r.eccentricity);
428 goal.e=r.eccentricity; goal.ap=goal.a*(1+goal.e); goal.pe=goal.a*(1-goal.e); }
429 text(plan?L"CURRENT > FINAL":draft?L"CURRENT > REQUEST":L"CURRENT ORBIT",255,dy,Cyan);
430 auto comparison=[&](const wchar_t* name,double actual,double proposed,int decimals) {
431 return std::wstring(name)+Number(actual,decimals)+((plan||draft)?L">"+Number(proposed,decimals):L"");
432 };
433 text(!s.own.valid?L"AP ---":s.own.bound?comparison(L"AP ",s.own.ap-s.radius,goal.ap-s.radius,1)+L"km":L"AP UNBOUND",255,dy+12,Green);
434 text(s.own.valid?comparison(L"PE ",s.own.pe-s.radius,goal.pe-s.radius,1)+L"km":L"PE ---",255,dy+24,Green);
435 text(s.own.valid?comparison(L"e ",s.own.e,goal.e,4):L"e ---",255,dy+36,Green);
436 if(s.own.valid&&s.target.valid&&s.targetKind!=TargetKind::Surface)
437 text(L"PLANE DIF "+Number(Angle(s.own.normal,s.target.normal)*180/Pi,2)+L"deg",255,dy+48,Cyan);
438 else text(s.own.valid?L"i "+Number(s.own.inclination*180/Pi,2)+L"deg":L"i ---",255,dy+48,Green);
439 if(s.plan.poweredTransfer.valid) {
440 const auto& transfer=s.plan.poweredTransfer;
441 text(L"MAIN "+Number(transfer.peakMain*100)+L"% RCS "+Number(transfer.peakTrim*100)+L"% peak",255,dy+60,Gray);
442 } else text((s.own.bound?L"TP "+Number(s.own.period)+L"s":L"TP ---")+L" nu "+(s.own.valid?Number(s.own.anomaly*180/Pi,1):L"---"),255,dy+60,Gray);
443 int by=dy+(compact?72:78);
444 const double age=(std::max)(0.0,data.clock-s.epoch);
445 for(int i=0;i<2;++i) {
446 if(i<int(s.plan.burns.size())) {
447 const auto& b=s.plan.burns[i];
448 const auto phase=data.guidance.phase==Phase::Align?data.guidance.maneuverPhase:data.guidance.phase;
449 const bool done=dorActive&&i==0&&(phase==Phase::Coast||phase==Phase::Arrive);
450 const auto when=done?L"DONE":b.at<=.5?L"NOW":Clock((std::max)(0.0,b.at-age));
451 text(L"B"+Number(i+1)+L" "+when+L" "+Number(b.deltaV*1000)+L"m/s",255,by,Amber);
452 text(s.plan.performance?std::wstring(s.plan.poweredTransfer.valid?L"BURN ":L"IDEAL ")+Number(b.duration,1)+L"s / "+Number(b.fuel,1)+L"kg":L" PERFORMANCE ---",255,by+12,Gray);
453 } else text(i==0?L"B1 ---":L"B2 ---",255,by,Dim);
454 by+=24;
455 }
456 text(plan?L"TOTAL "+Number(s.plan.deltaV*1000)+L"m/s":L"TOTAL ---",255,by+4,Amber);
457 text(plan&&s.plan.performance?std::wstring(s.plan.poweredTransfer.valid?L"TOTAL FUEL ~":L"IDEAL FUEL ~")+Number(s.plan.fuel,1)+L"kg":L"FUEL ---",255,by+16,Amber);
458 // Fixed caution/status lines stay above the single-line action footer.
459 const auto& guidance=data.guidance;
460 const bool lowPass=s.lowAtmosphere||guidance.lowAtmosphere||
461 (s.plan.clearance.known&&s.plan.clearance.minimumKm<OrbitalClearanceKm);
462 const bool atmPass=lowPass||guidance.atmosphere||s.atmosphere||s.plan.atmosphere||s.plan.clearanceBlocked;
463 // Identify the trajectory: a clear committed plan can coexist with an
464 // unsafe unpowered orbit while B1/B2 are still needed. Never turn the
465 // normal execution phase red just because this independent warning is red.
466 const auto& correction=guidance.correctionClearance;
467 if(correction.known&&correction.minimumKm<OrbitalClearanceKm)
468 text(L"CORRECTION MIN "+Number(correction.minimumKm,1)+L"km",255,266,Red);
469 else if(s.plan.clearance.known&&s.plan.clearance.minimumKm<OrbitalClearanceKm)
470 text(L"PLAN MIN "+Number(s.plan.clearance.minimumKm,1)+L"km",255,266,Red);
471 else if(s.lowAtmosphere&&s.actualCoast.known)
472 text(L"COAST MIN "+Number(s.actualCoast.minimumKm,1)+L"km",255,266,Red);
473 else if(guidance.lowAtmosphere) text(L"EXEC PATH <100km",255,266,Red);
474 else if(correction.known&&correction.pressurePa>AtmosphereWarningPa) text(L"CORRECTION ATM q>10Pa",255,266,Amber);
475 else if(s.plan.atmosphere||s.plan.clearanceBlocked) text(L"PLAN ATM PASS",255,266,Amber);
476 else if(atmPass) text(s.actualCoast.known?L"COAST ATM q>10Pa":L"CURRENT ATM q>10Pa",255,266,Amber);
477 auto status=guidance.status.empty()?s.status:guidance.status;
478 if(status.compare(0,4,L"DOR ")==0) {
479 status.erase(0,4);
480 if(dorActive&&(guidance.phase==Phase::Depart||guidance.phase==Phase::Arrive))
481 status+=L" MECO "+(guidance.mecoSeconds>=0?L"~"+Clock(std::ceil(guidance.mecoSeconds)):L"---");
482 // Keep any appended atmospheric warning steady and in the same place.
483 if(dorActive&&!executionVisible) status.assign(status.size(),L' ');
484 }
485 if(dorActive&&s.status==L"ATMOSPHERIC TARGET") status+=L" / ATM TARGET";
486 text(status.substr(0,31),255,278,guidance.phase==Phase::Abort?Red:dorActive?Green:Amber);
487 if(dorActive) text(L"LEFT "+Number(guidance.remainingDeltaV*1000,1)+L"m/s ALL USED "+Number(guidance.fuelUsedKg)+L"kg",255,290,Amber);
488 else if(s.plan.clearanceBlocked&&s.plan.clearance.known)
489 text(L"MIN "+Number(s.plan.clearance.minimumKm,1)+L"km / BLOCKED",255,290,lowPass?Red:Amber);
490 else if(s.mode==Mode::Rendezvous) text(s.plan.poweredTransfer.valid?L"5km TRAIL / POWERED PROGRADE":s.plan.longBurn?L"5km TRAIL / FINITE BURN APPROX":L"5km TRAIL / COAST ASSUMED",255,290,Gray);
491 else if(s.plan.longBurn) text(L"FINITE BURN NOT CORRECTED",255,290,Gray);
492 else if(plan&&!s.plan.fuelEnough&&s.plan.performance) text(L"INSUFFICIENT FUEL",255,290,Amber);
493 if(showKeys&&!rows.empty()) {
494 std::wstring action=L"\x21e7+\x2190/\x2192 Change";
495 if(rows[uiRow]==Row::Mode) action+=L" objective";
496 else if(rows[uiRow]==Row::Eccentricity) action+=L" e \x21e7+C Circularize";
497 else if(rows[uiRow]==Row::View) action+=L" view";
498 text(action,5,304,0xff00a0a0);
499 text(L"\x21e7+\x2191/\x2193 Select row",315,304,0xff00a0a0);
500 }
501 return labels;
502}
503
504}
SCRIPT_CONTROL SCRIPT_STATE const void int
float fuel
Definition globals.cpp:90
float mark
Definition globals.cpp:45
constexpr double AtmosphereWarningPa
Definition OrbitState.h:10
double Angle(Vec a, Vec b)
Definition OrbitMath.h:21
constexpr std::uint32_t Gray
Definition OrbitDisplay.h:9
const wchar_t * ModeName(Mode m)
constexpr double Tau
Definition OrbitMath.h:10
std::wstring Number(double n, int precision=0)
const wchar_t * FinalName(Final f)
Definition OrbitState.h:20
std::wstring EntryEngagementBlock(const Snapshot &s)
Definition OrbitState.h:278
Vec Unit(Vec a)
Definition OrbitMath.h:20
std::wstring RowText(Row row, const Request &r, const Snapshot &s, double now)
Mode Objective(const Request &r, TargetKind target)
Definition OrbitState.h:368
constexpr double OrbitalClearanceKm
Definition OrbitState.h:38
constexpr std::uint32_t Red
Definition OrbitDisplay.h:9
Vec Rotate(Vec v, Vec axis, double angle)
Definition OrbitMath.h:22
bool AscentView(const Snapshot &s, View view)
double Dot(Vec a, Vec b)
Definition OrbitMath.h:16
constexpr std::uint32_t Cyan
Definition OrbitDisplay.h:9
constexpr std::uint32_t Green
Definition OrbitDisplay.h:9
constexpr std::uint32_t Amber
Definition OrbitDisplay.h:9
const wchar_t * RouteName(Route route)
Definition OrbitState.h:44
constexpr std::uint32_t Dim
Definition OrbitDisplay.h:9
constexpr double Pi
Definition OrbitMath.h:10
std::vector< Label > Readouts(const BusState &data, const std::vector< Row > &rows, int uiRow, bool dorActive, bool showKeys=true)
const wchar_t * ViewName(View v)
Picture Plot(const Snapshot &s, View view)
double Norm(Vec a)
Definition OrbitMath.h:18
Vec Cross(Vec a, Vec b)
Definition OrbitMath.h:17
std::wstring Clock(double seconds)
std::vector< Sample > path
Definition OrbitState.h:35
LaunchEstimate launch
Definition OrbitState.h:349
ApproachStatus approach
Definition OrbitState.h:349
double handoffAltitudeKm
Definition OrbitState.h:196
double handoffSpeedKms
Definition OrbitState.h:196
bool active
Definition OrbitState.h:194
std::wstring status
Definition OrbitState.h:315
std::uint32_t color
std::wstring text
std::uint32_t color
std::vector< Line > lines
std::vector< Label > labels
std::vector< Burn > burns
Definition OrbitState.h:241
Elements goal
Definition OrbitState.h:239
std::vector< Sample > handoffs
Definition OrbitState.h:237
Clearance clearance
Definition OrbitState.h:228
std::vector< Sample > goalPath
Definition OrbitState.h:240
RouteEstimate surface
Definition OrbitState.h:232
std::vector< Sample > coast
Definition OrbitState.h:240
EntryEstimate entry
Definition OrbitState.h:233
bool localSurfaceTrip
Definition OrbitState.h:231
std::vector< Sample > path
Definition OrbitState.h:240
ArrivalPreview arrival
Definition OrbitState.h:235
bool clearanceBlocked
Definition OrbitState.h:227
bool ascentOrbitSteering
Definition OrbitState.h:52
bool surfaceDurationHeld
Definition OrbitState.h:66
double entryAltitudeKm
Definition OrbitState.h:69
double arrivalEpoch
Definition OrbitState.h:74
double finalDistanceKm
Definition OrbitState.h:63
double departureEpoch
Definition OrbitState.h:74
double arrivalSeconds
Definition OrbitState.h:73
double ascentAltitudeKm
Definition OrbitState.h:55
double eccentricity
Definition OrbitState.h:72
double heldRadiusKm
Definition OrbitState.h:72
double entrySpeedKms
Definition OrbitState.h:69
std::vector< Sample > ownPath
Definition OrbitState.h:258
AscentProfile ascentProfile
Definition OrbitState.h:266
TargetKind targetKind
Definition OrbitState.h:255
std::vector< Sample > targetPath
Definition OrbitState.h:258