From 143c57afd1507d5f45c36fe9b0a55d79079a9ccf Mon Sep 17 00:00:00 2001 From: indy91 Date: Wed, 26 Jun 2024 20:12:59 +0200 Subject: [PATCH 1/2] Save and load the state of all RTCC MFD instances when switching panels (2D) or resizing the External MFD window (VC) --- .../src_rtccmfd/ApolloRTCCMFD.cpp | 82 +++++++++++++++---- .../ProjectApollo/src_rtccmfd/ApolloRTCCMFD.h | 20 +++-- 2 files changed, 81 insertions(+), 21 deletions(-) diff --git a/Orbitersdk/samples/ProjectApollo/src_rtccmfd/ApolloRTCCMFD.cpp b/Orbitersdk/samples/ProjectApollo/src_rtccmfd/ApolloRTCCMFD.cpp index 9465986436..0868414656 100644 --- a/Orbitersdk/samples/ProjectApollo/src_rtccmfd/ApolloRTCCMFD.cpp +++ b/Orbitersdk/samples/ProjectApollo/src_rtccmfd/ApolloRTCCMFD.cpp @@ -34,6 +34,7 @@ VESSEL *GCoreVessel[32]; AR_GCore *g_SC = NULL; // points to the static core, root of all persistence int nGutsUsed; bool initialised = false; +std::vector g_MFDData; // ============================================================== // MFD class implementation @@ -42,6 +43,7 @@ bool initialised = false; ApolloRTCCMFD::ApolloRTCCMFD (DWORD w, DWORD h, VESSEL *vessel, UINT im) : MFD2 (w, h, vessel) { + ID = im; screen = 0; subscreen = 0; @@ -85,6 +87,8 @@ ApolloRTCCMFD::ApolloRTCCMFD (DWORD w, DWORD h, VESSEL *vessel, UINT im) markermax = 0; IsCSM = true; ErrorMessage = false; + + LoadState(); } // Destructor @@ -100,6 +104,59 @@ ApolloRTCCMFD::~ApolloRTCCMFD () oapiReleaseFont(font5); oapiReleasePen(pen); oapiReleasePen(pen2); + + SaveState(); +} + +void ApolloRTCCMFD::SaveState() +{ + RTCCMFDData temp; + + temp.marker = marker; + temp.markermax = markermax; + temp.screen = screen; + temp.subscreen = subscreen; + temp.ID = ID; + temp.MEDCode = MEDInputData.MEDCode; + + bool found = false; + + //Search for existing MFD data + for (unsigned i = 0; i < g_MFDData.size(); i++) + { + if (g_MFDData[i].ID == ID) + { + //Found it, save in that place + g_MFDData[i] = temp; + found = true; + break; + } + } + + if (!found) + { + //Found in array yet, add it + g_MFDData.push_back(temp); + } +} + +void ApolloRTCCMFD::LoadState() +{ + //Load MFD data + + for (unsigned i = 0; i < g_MFDData.size(); i++) + { + if (g_MFDData[i].ID == ID) + { + //Found it, load data + marker = g_MFDData[i].marker; + markermax = g_MFDData[i].markermax; + screen = g_MFDData[i].screen; + subscreen = g_MFDData[i].subscreen; + MEDInputData.MEDCode = g_MFDData[i].MEDCode; + break; + } + } } // Return button labels @@ -6341,23 +6398,20 @@ void ApolloRTCCMFD::menuVECPOINTCalc() G->VecPointCalc(IsCSM); } -void ApolloRTCCMFD::StoreStatus(void) const -{ - screenData.screen = screen; - screenData.marker = marker; - screenData.markermax = markermax; - screenData.subscreen = subscreen; -} - void ApolloRTCCMFD::RecallStatus(void) { - SelectPage(screenData.screen); - subscreen = screenData.subscreen; - marker = screenData.marker; - markermax = screenData.markermax; -} + //MFD data got reloaded in LoadState from the constructor, but resetting the MFD buttons crashes there. Do it here instead -ApolloRTCCMFD::ScreenData ApolloRTCCMFD::screenData = { 0 }; + if (screen == 130) + { + //Special logic for MED input page + SetMEDInputPage(MEDInputData.MEDCode); + } + else + { + SelectPage(screen); + } +} void ApolloRTCCMFD::GetREFSMMATfromAGC() { diff --git a/Orbitersdk/samples/ProjectApollo/src_rtccmfd/ApolloRTCCMFD.h b/Orbitersdk/samples/ProjectApollo/src_rtccmfd/ApolloRTCCMFD.h index 3b7bd49a18..45d90b238e 100644 --- a/Orbitersdk/samples/ProjectApollo/src_rtccmfd/ApolloRTCCMFD.h +++ b/Orbitersdk/samples/ProjectApollo/src_rtccmfd/ApolloRTCCMFD.h @@ -53,6 +53,16 @@ struct MEDInputPage std::vector table; }; +struct RTCCMFDData +{ + int screen = 0; + int subscreen = 0; + int marker = 0; + int markermax = 0; + UINT ID = 0; + std::string MEDCode; +}; + class ApolloRTCCMFD: public MFD2 { public: ApolloRTCCMFD (DWORD w, DWORD h, VESSEL *vessel, UINT im); @@ -64,7 +74,6 @@ class ApolloRTCCMFD: public MFD2 { bool ConsumeKeyBuffered(DWORD key); void WriteStatus(FILEHANDLE scn) const; void ReadStatus(FILEHANDLE scn); - void StoreStatus(void) const; void RecallStatus(void); void Text(oapi::Sketchpad *skp, std::string message, int x, int y, int xmax = 1024, int ymax = 1024); @@ -872,14 +881,11 @@ class ApolloRTCCMFD: public MFD2 { int marker; int markermax; int status; //Page dependent status, reset to 0 when new page is entered - static struct ScreenData { - int screen; - int subscreen; - int marker; - int markermax; - } screenData; private: + void SaveState(); + void LoadState(); + UINT ID; ARCore* G; AR_GCore* GC; ApolloRTCCMFDButtons coreButtons; From dc04772399dbe26dc20e9a4608230b5bf5f547ed Mon Sep 17 00:00:00 2001 From: indy91 Date: Sun, 30 Jun 2024 12:56:31 +0200 Subject: [PATCH 2/2] RTCC MFD: Also save CSM vs LM bool --- Orbitersdk/samples/ProjectApollo/src_rtccmfd/ApolloRTCCMFD.cpp | 2 ++ Orbitersdk/samples/ProjectApollo/src_rtccmfd/ApolloRTCCMFD.h | 1 + 2 files changed, 3 insertions(+) diff --git a/Orbitersdk/samples/ProjectApollo/src_rtccmfd/ApolloRTCCMFD.cpp b/Orbitersdk/samples/ProjectApollo/src_rtccmfd/ApolloRTCCMFD.cpp index 0868414656..167bde8447 100644 --- a/Orbitersdk/samples/ProjectApollo/src_rtccmfd/ApolloRTCCMFD.cpp +++ b/Orbitersdk/samples/ProjectApollo/src_rtccmfd/ApolloRTCCMFD.cpp @@ -118,6 +118,7 @@ void ApolloRTCCMFD::SaveState() temp.subscreen = subscreen; temp.ID = ID; temp.MEDCode = MEDInputData.MEDCode; + temp.IsCSM = IsCSM; bool found = false; @@ -154,6 +155,7 @@ void ApolloRTCCMFD::LoadState() screen = g_MFDData[i].screen; subscreen = g_MFDData[i].subscreen; MEDInputData.MEDCode = g_MFDData[i].MEDCode; + IsCSM = g_MFDData[i].IsCSM; break; } } diff --git a/Orbitersdk/samples/ProjectApollo/src_rtccmfd/ApolloRTCCMFD.h b/Orbitersdk/samples/ProjectApollo/src_rtccmfd/ApolloRTCCMFD.h index 45d90b238e..f3fe9df3a1 100644 --- a/Orbitersdk/samples/ProjectApollo/src_rtccmfd/ApolloRTCCMFD.h +++ b/Orbitersdk/samples/ProjectApollo/src_rtccmfd/ApolloRTCCMFD.h @@ -61,6 +61,7 @@ struct RTCCMFDData int markermax = 0; UINT ID = 0; std::string MEDCode; + bool IsCSM = false; }; class ApolloRTCCMFD: public MFD2 {