Skip to content

Commit

Permalink
Save game when loading a new one (i.e. load different rom)
Browse files Browse the repository at this point in the history
  • Loading branch information
asveikau committed Dec 28, 2023
1 parent 974ea92 commit fa8f0bf
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 38 deletions.
21 changes: 5 additions & 16 deletions ParseCmdLine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ int stateToLoad = -1; //-1 since 0 will be slot 0
//3) add an entry in the switch statement in order to assign the variable
//4) add code under the "execute commands" section to handle the given commandline

extern MDFNGI *
MDFNI_LoadGame_Wrapper(const char *force_module, const char *name);

void ParseCmdLine(LPSTR lpCmdLine, HWND HWnd)
{
string argumentList; //Complete command line argument
Expand Down Expand Up @@ -99,14 +102,7 @@ void ParseCmdLine(LPSTR lpCmdLine, HWND HWnd)
//adelikat: for now assume ROM
if (FileToLoad[0])
{
//adelikat: This code is currently in LoadGame, Drag&Drop, Recent ROMs, and here, time for a function
pcejin.romLoaded = true;
pcejin.started = true;
if(!MDFNI_LoadGame(false, FileToLoad.c_str()))
{
pcejin.started = false;
pcejin.romLoaded = false;
}
MDFNI_LoadGame_Wrapper(nullptr, FileToLoad.c_str());
}
//{
// GensOpenFile(FileToLoad.c_str());
Expand All @@ -124,14 +120,7 @@ void ParseCmdLine(LPSTR lpCmdLine, HWND HWnd)
//ROM
if (RomToLoad[0])
{
//adelikat: This code is currently in LoadGame, Drag&Drop, Recent ROMs, and here, time for a function
pcejin.romLoaded = true;
pcejin.started = true;
if(!MDFNI_LoadGame(false, RomToLoad.c_str()))
{
pcejin.started = false;
pcejin.romLoaded = false;
}
MDFNI_LoadGame_Wrapper(nullptr, RomToLoad.c_str());
}

//Read+Write
Expand Down
37 changes: 22 additions & 15 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,25 @@ void vbjinInit() {
VTLineWidths[1] = (MDFN_Rect *)calloc(CurGame->fb_height, sizeof(MDFN_Rect));
}

MDFNGI *
MDFNI_LoadGame_Wrapper(const char *force_module, const char *name)
{
MDFNGI *r = nullptr;

if (pcejin.romLoaded) {
MDFNGameInfo->CloseGame();
}

pcejin.romLoaded = true;
pcejin.started = true;

if (!(r = MDFNI_LoadGame(force_module, name))) {
pcejin.started = false;
pcejin.romLoaded = false;
}

return r;
}

void MDFNI_Emulate(EmulateSpecStruct *espec) {
MDFNGameInfo->Emulate(espec);
Expand Down Expand Up @@ -405,14 +424,7 @@ void LoadGame(){
ofn.nMaxFile = MAX_PATH;
ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT;
if(GetOpenFileName(&ofn)) {
pcejin.romLoaded = true;
pcejin.started = true;

if(!MDFNI_LoadGame(NULL,szChoice)) {
pcejin.started = false;
pcejin.romLoaded = false;

}
MDFNI_LoadGame_Wrapper(NULL, szChoice);
if (AutoRWLoad)
{
//Open Ram Watch if its auto-load setting is checked
Expand Down Expand Up @@ -813,20 +825,15 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
//-------------------------------------------------------
//Else load it as a ROM
//-------------------------------------------------------
else if(MDFNI_LoadGame(NULL,filename))
else if(MDFNI_LoadGame_Wrapper(NULL,filename))
{
pcejin.romLoaded = true;
pcejin.started = true;
//TODO: adelikat: This code is copied directly from the LoadGame() function, it should be come a separate function and called in both places
////////////////////////////////
if (AutoRWLoad)
{
//Open Ram Watch if its auto-load setting is checked
OpenRWRecentFile(0);
RamWatchHWnd = CreateDialog(winClass.hInstance, MAKEINTRESOURCE(IDD_RAMWATCH), g_hWnd, (DLGPROC) RamWatchProc);
}
UpdateRecentRoms(filename);
////////////////////////////////
}
}
return 0;
Expand Down Expand Up @@ -1677,4 +1684,4 @@ std::string RemovePath(std::string filename)
std::string GetGameName()
{
return GameName;
}
}
11 changes: 4 additions & 7 deletions recentroms.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ HMENU recentromsmenu; //Handle to the recent ROMs submenu
extern char IniName[MAX_PATH];
extern HWND g_hWnd;

extern MDFNGI *
MDFNI_LoadGame_Wrapper(const char *force_module, const char *name);

void UpdateRecentRomsMenu()
{
//This function will be called to populate the Recent Menu
Expand Down Expand Up @@ -230,14 +233,8 @@ void OpenRecentROM(int listNum)
soundDriver->pause();
strcpy(filename, RecentRoms[listNum].c_str());

pcejin.romLoaded = true;
pcejin.started = true;

if(!MDFNI_LoadGame(NULL,filename))
if(!MDFNI_LoadGame_Wrapper(NULL,filename))
{
pcejin.started = false;
pcejin.romLoaded = false;

string str = "Could not open ";
str.append(filename);
str.append("\n\nRemove from list?");
Expand Down

0 comments on commit fa8f0bf

Please sign in to comment.