Skip to content

Commit

Permalink
hexen: Refactor savefile page handling
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeday0 committed Sep 16, 2024
1 parent b3430ef commit 05a92f4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 31 deletions.
6 changes: 4 additions & 2 deletions src/hexen/g_game.c
Original file line number Diff line number Diff line change
Expand Up @@ -2094,7 +2094,8 @@ void G_LoadGame(int slot)
void G_DoLoadGame(void)
{
gameaction = ga_nothing;
SV_LoadGame(GameLoadSlot);
// [crispy] support multiple pages of saves
SV_LoadGame(GameLoadSlot + savepage * 10);
if (!netgame)
{ // Copy the base slot to the reborn slot
SV_UpdateRebornSlot();
Expand Down Expand Up @@ -2127,7 +2128,8 @@ void G_SaveGame(int slot, char *description)

void G_DoSaveGame(void)
{
SV_SaveGame(savegameslot, savedescription);
// [crispy] support multiple pages of saves
SV_SaveGame(savegameslot + savepage * 10, savedescription);
gameaction = ga_nothing;
savedescription[0] = 0;
P_SetMessage(&players[consoleplayer], TXT_GAMESAVED, true);
Expand Down
4 changes: 3 additions & 1 deletion src/hexen/mn_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ int InfoType;
int messageson = true;
boolean mn_SuicideConsole;

int savepage; // [crispy] support 8 pages of savegames

// PRIVATE DATA DEFINITIONS ------------------------------------------------

static int FontABaseLump;
Expand Down Expand Up @@ -1263,7 +1265,7 @@ static void SCDeleteGame(int option)
return;
}

SV_ClearSaveSlot(option);
SV_ClearSaveSlot(option + savepage * 10);
CurrentMenu->oldItPos = CurrentItPos;
MN_LoadSlotText();
BorderNeedRefresh = true;
Expand Down
30 changes: 2 additions & 28 deletions src/hexen/sv_save.c
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ static void SV_WriteByte(byte val);
static void SV_WriteWord(unsigned short val);
static void SV_WriteLong(unsigned int val);
static void SV_WritePtr(void *ptr);
static void ClearSaveSlot(int slot); // [crispy]

// EXTERNAL DATA DECLARATIONS ----------------------------------------------

Expand All @@ -144,8 +143,6 @@ char *SavePath = DEFAULT_SAVEPATH;

int vanilla_savegame_limit = 1;

int savepage; // [crispy] support 8 pages of savegames

// PRIVATE DATA DEFINITIONS ------------------------------------------------

static int MobjCount;
Expand Down Expand Up @@ -1981,12 +1978,6 @@ void SV_SaveGame(int slot, const char *description)
char versionText[HXS_VERSION_TEXT_LENGTH];
unsigned int i;

// [crispy] get expanded save slot number
if (slot != BASE_SLOT && slot != REBORN_SLOT)
{
slot += savepage * 10;
}

// Open the output file
M_snprintf(fileName, sizeof(fileName), "%shex%d.hxs", SavePath, BASE_SLOT);
SV_OpenWrite(fileName);
Expand Down Expand Up @@ -2029,7 +2020,7 @@ void SV_SaveGame(int slot, const char *description)
SV_SaveMap(true); // true = save player info

// Clear all save files at destination slot
ClearSaveSlot(slot);
SV_ClearSaveSlot(slot);

// Copy base slot to destination slot
CopySaveSlot(BASE_SLOT, slot);
Expand Down Expand Up @@ -2093,12 +2084,6 @@ void SV_LoadGame(int slot)

p = &players[consoleplayer]; // [crispy]

// [crispy] get expanded save slot number
if (slot != BASE_SLOT && slot != REBORN_SLOT)
{
slot += savepage * 10;
}

// Copy all needed save files to the base slot
if (slot != BASE_SLOT)
{
Expand Down Expand Up @@ -3280,8 +3265,7 @@ static void AssertSegment(gameArchiveSegment_t segType)
//
//==========================================================================

// [crispy] Add wrapper to handle multiple save pages
static void ClearSaveSlot(int slot)
void SV_ClearSaveSlot(int slot)
{
int i;
char fileName[100];
Expand All @@ -3296,16 +3280,6 @@ static void ClearSaveSlot(int slot)
M_remove(fileName);
}

void SV_ClearSaveSlot(int slot)
{
if (slot != BASE_SLOT && slot != REBORN_SLOT)
{
slot += savepage * 10;
}

ClearSaveSlot(slot);
}

//==========================================================================
//
// CopySaveSlot
Expand Down

0 comments on commit 05a92f4

Please sign in to comment.