- savegame code cleanup.

This commit is contained in:
Christoph Oelckers 2021-04-18 23:55:33 +02:00
parent b85da221d7
commit 97d8aee2e8
4 changed files with 15 additions and 41 deletions

View file

@ -1380,20 +1380,24 @@ public:
{ {
Ptr = nullptr; Ptr = nullptr;
} }
TPointer(const T& other) TPointer(const T& other) = delete;
/*
{ {
Alloc(); Alloc();
*Ptr = other; *Ptr = other;
} }
*/
TPointer(T&& other) TPointer(T&& other)
{ {
Alloc(); Alloc();
*Ptr = other; *Ptr = other;
} }
TPointer(const TPointer<T>& other) TPointer(const TPointer<T>& other) = delete;
/*
{ {
DoCopy(other); DoCopy(other);
} }
*/
TPointer(TPointer<T>&& other) TPointer(TPointer<T>&& other)
{ {
Ptr = other.Ptr; Ptr = other.Ptr;

View file

@ -67,8 +67,6 @@ struct GameInterface
virtual bool StartGame(FNewGameStartup& gs) { return false; } virtual bool StartGame(FNewGameStartup& gs) { return false; }
virtual FSavegameInfo GetSaveSig() { return { "", 0, 0}; } virtual FSavegameInfo GetSaveSig() { return { "", 0, 0}; }
virtual double SmallFontScale() { return 1; } virtual double SmallFontScale() { return 1; }
virtual bool SaveGame() { return true; }
virtual bool LoadGame() { return true; }
virtual void SerializeGameState(FSerializer& arc) {} virtual void SerializeGameState(FSerializer& arc) {}
virtual void DrawPlayerSprite(const DVector2& origin, bool onteam) {} virtual void DrawPlayerSprite(const DVector2& origin, bool onteam) {}
virtual void QuitToTitle() {} virtual void QuitToTitle() {}

View file

@ -107,19 +107,11 @@ static void SerializeSession(FSerializer& arc)
//============================================================================= //=============================================================================
// //
// This is for keeping my sanity while working with the horrible mess
// that is the savegame code in Duke Nukem.
// Without handling this in global variables it is a losing proposition
// to save custom data along with the regular snapshot. :(
// With this the savegame code can mostly pretend to load from and write
// to files while really using a composite archive.
// //
// All global non-game dependent state is also saved right here for convenience.
// //
//============================================================================= //=============================================================================
bool ReadSavegame(const char *name)
bool OpenSaveGameForRead(const char *name)
{ {
if (savereader) delete savereader; if (savereader) delete savereader;
savereader = FResourceFile::OpenResourceFile(name, true, true); savereader = FResourceFile::OpenResourceFile(name, true, true);
@ -180,11 +172,6 @@ FileReader ReadSavegameChunk(const char *name)
return lump->NewReader(); return lump->NewReader();
} }
bool FinishSavegameWrite()
{
return savewriter.WriteToFile();
}
void FinishSavegameRead() void FinishSavegameRead()
{ {
delete savereader; delete savereader;
@ -199,7 +186,7 @@ CVAR(Bool, save_formatted, false, 0) // should be set to false once the conversi
// //
//============================================================================= //=============================================================================
bool OpenSaveGameForWrite(const char* filename, const char *name) bool WriteSavegame(const char* filename, const char *name)
{ {
savewriter.Clear(); savewriter.Clear();
savewriter.SetFileName(filename); savewriter.SetFileName(filename);
@ -262,8 +249,7 @@ bool OpenSaveGameForWrite(const char* filename, const char *name)
M_AppendPNGText(picfile, "Title", name); M_AppendPNGText(picfile, "Title", name);
M_AppendPNGText(picfile, "Current Map", lev->labelName); M_AppendPNGText(picfile, "Current Map", lev->labelName);
M_FinishPNG(picfile); M_FinishPNG(picfile);
return savewriter.WriteToFile();
return true;
} }
//============================================================================= //=============================================================================
@ -699,16 +685,9 @@ static int nextquicksave = -1;
void DoLoadGame(const char* name) void DoLoadGame(const char* name)
{ {
if (OpenSaveGameForRead(name)) if (ReadSavegame(name))
{ {
if (gi->LoadGame()) gameaction = ga_level;
{
gameaction = ga_level;
}
else
{
I_Error("%s: Failed to load savegame", name);
}
} }
else else
{ {
@ -727,14 +706,11 @@ static int nextquicksave = -1;
void G_SaveGame(const char *fn, const char *desc, bool ok4q, bool forceq) void G_SaveGame(const char *fn, const char *desc, bool ok4q, bool forceq)
{ {
if (OpenSaveGameForWrite(fn, desc)) if (WriteSavegame(fn, desc))
{ {
if (gi->SaveGame() && FinishSavegameWrite()) savegameManager.NotifyNewSave(fn, desc, ok4q, forceq);
{ Printf(PRINT_NOTIFY, "%s\n", GStrings("GAME SAVED"));
savegameManager.NotifyNewSave(fn, desc, ok4q, forceq); BackupSaveGame = fn;
Printf(PRINT_NOTIFY, "%s\n", GStrings("GAME SAVED"));
BackupSaveGame = fn;
}
} }
} }

View file

@ -5,13 +5,9 @@
extern FixedBitArray<MAXSPRITES> activeSprites; extern FixedBitArray<MAXSPRITES> activeSprites;
bool OpenSaveGameForWrite(const char *fname, const char *name);
bool OpenSaveGameForRead(const char *name);
FileWriter *WriteSavegameChunk(const char *name); FileWriter *WriteSavegameChunk(const char *name);
FileReader ReadSavegameChunk(const char *name); FileReader ReadSavegameChunk(const char *name);
bool FinishSavegameWrite();
void FinishSavegameRead(); void FinishSavegameRead();
// Savegame utilities // Savegame utilities