Adds option to use a rotation of quicksaves instead of having one quicksave slot that needs to be manually created.

This commit is contained in:
Kevin Hutchins 2019-07-13 13:38:44 -07:00
commit 5cb59018e0
6 changed files with 58 additions and 9 deletions

View file

@ -95,8 +95,9 @@ void G_DoPlayDemo (void);
void G_DoCompleted (void);
void G_DoVictory (void);
void G_DoWorldDone (void);
void G_DoSaveGame (bool okForQuicksave, FString filename, const char *description);
void G_DoSaveGame (bool okForQuicksave, bool forceQuicksave, FString filename, const char *description);
void G_DoAutoSave ();
void G_DoQuickSave ();
void STAT_Serialize(FSerializer &file);
bool WriteZip(const char *filename, TArray<FString> &filenames, TArray<FCompressedBuffer> &content);
@ -1059,7 +1060,7 @@ void G_Ticker ()
G_DoLoadGame ();
break;
case ga_savegame:
G_DoSaveGame (true, savegamefile, savedescription);
G_DoSaveGame (true, false, savegamefile, savedescription);
gameaction = ga_nothing;
savegamefile = "";
savedescription = "";
@ -2028,6 +2029,14 @@ CUSTOM_CVAR (Int, autosavecount, 4, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
if (self < 0)
self = 0;
}
CVAR (Int, quicksavenum, -1, CVAR_NOSET|CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
static int lastquicksave = -1;
CVAR (Bool, quicksaverotation, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
CUSTOM_CVAR (Int, quicksaverotationcount, 4, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
{
if (self < 1)
self = 1;
}
void G_DoAutoSave ()
{
@ -2061,7 +2070,35 @@ void G_DoAutoSave ()
readableTime = myasctime ();
description.Format("Autosave %s", readableTime);
G_DoSaveGame (false, file, description);
G_DoSaveGame (false, false, file, description);
}
void G_DoQuickSave ()
{
FString description;
FString file;
// Keeps a rotating set of quicksaves
UCVarValue num;
const char *readableTime;
int count = quicksaverotationcount != 0 ? quicksaverotationcount : 1;
if (quicksavenum < 0)
{
lastquicksave = 0;
}
else
{
lastquicksave = (quicksavenum + 1) % count;
}
num.Int = lastquicksave;
quicksavenum.ForceSet (num, CVAR_Int);
file = G_BuildSaveName ("quick", lastquicksave);
readableTime = myasctime ();
description.Format("Quicksave %s", readableTime);
G_DoSaveGame (true, true, file, description);
}
@ -2166,7 +2203,7 @@ static void PutSavePic (FileWriter *file, int width, int height)
}
}
void G_DoSaveGame (bool okForQuicksave, FString filename, const char *description)
void G_DoSaveGame (bool okForQuicksave, bool forceQuicksave, FString filename, const char *description)
{
TArray<FCompressedBuffer> savegame_content;
TArray<FString> savegame_filenames;
@ -2282,7 +2319,7 @@ void G_DoSaveGame (bool okForQuicksave, FString filename, const char *descriptio
WriteZip(filename, savegame_filenames, savegame_content);
savegameManager.NotifyNewSave (filename, description, okForQuicksave);
savegameManager.NotifyNewSave (filename, description, okForQuicksave, forceQuicksave);
// delete the JSON buffers we created just above. Everything else will
// either still be needed or taken care of automatically.