Skip to content

Commit

Permalink
Merge pull request #1262 from indy91/RTCCMFDSaving
Browse files Browse the repository at this point in the history
Save and load the state of all RTCC MFD instances when switching panels (2D) or resizing the External MFD window (VC)
  • Loading branch information
indy91 authored Jun 30, 2024
2 parents 915f79d + dc04772 commit 0a33b2d
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 21 deletions.
84 changes: 70 additions & 14 deletions Orbitersdk/samples/ProjectApollo/src_rtccmfd/ApolloRTCCMFD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<RTCCMFDData> g_MFDData;

// ==============================================================
// MFD class implementation
Expand All @@ -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;

Expand Down Expand Up @@ -85,6 +87,8 @@ ApolloRTCCMFD::ApolloRTCCMFD (DWORD w, DWORD h, VESSEL *vessel, UINT im)
markermax = 0;
IsCSM = true;
ErrorMessage = false;

LoadState();
}

// Destructor
Expand All @@ -100,6 +104,61 @@ 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;
temp.IsCSM = IsCSM;

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;
IsCSM = g_MFDData[i].IsCSM;
break;
}
}
}

// Return button labels
Expand Down Expand Up @@ -6368,23 +6427,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()
{
Expand Down
21 changes: 14 additions & 7 deletions Orbitersdk/samples/ProjectApollo/src_rtccmfd/ApolloRTCCMFD.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,17 @@ struct MEDInputPage
std::vector<MEDInput> table;
};

struct RTCCMFDData
{
int screen = 0;
int subscreen = 0;
int marker = 0;
int markermax = 0;
UINT ID = 0;
std::string MEDCode;
bool IsCSM = false;
};

class ApolloRTCCMFD: public MFD2 {
public:
ApolloRTCCMFD (DWORD w, DWORD h, VESSEL *vessel, UINT im);
Expand All @@ -64,7 +75,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);
Expand Down Expand Up @@ -873,14 +883,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;
Expand Down

0 comments on commit 0a33b2d

Please sign in to comment.