- moved Exhumed's engine state save code into the common part.

This needs to be save for all games and the discrepancies have already caused problems so engine state saving needs to be unified.
This commit is contained in:
Christoph Oelckers 2020-01-21 19:22:38 +01:00
parent cacbd7d8b6
commit acf7f29dbd
3 changed files with 78 additions and 65 deletions

View file

@ -351,3 +351,76 @@ FString G_BuildSaveName (const char *prefix)
return name;
}
#include "build.h"
#include "mmulti.h"
void SaveEngineState()
{
auto fw = WriteSavegameChunk("engine.bin");
fw->Write(&numsectors, sizeof(numsectors));
fw->Write(sector, sizeof(sectortype) * numsectors);
fw->Write(&numwalls, sizeof(numwalls));
fw->Write(wall, sizeof(walltype) * numwalls);
fw->Write(sprite, sizeof(spritetype) * MAXSPRITES);
fw->Write(headspritesect, sizeof(headspritesect));
fw->Write(prevspritesect, sizeof(prevspritesect));
fw->Write(nextspritesect, sizeof(nextspritesect));
fw->Write(headspritestat, sizeof(headspritestat));
fw->Write(prevspritestat, sizeof(prevspritestat));
fw->Write(nextspritestat, sizeof(nextspritestat));
fw->Write(&tailspritefree, sizeof(tailspritefree));
fw->Write(&myconnectindex, sizeof(myconnectindex));
fw->Write(&connecthead, sizeof(connecthead));
fw->Write(connectpoint2, sizeof(connectpoint2));
fw->Write(&numframes, sizeof(numframes));
fw->Write(&randomseed, sizeof(randomseed));
fw->Write(&numshades, sizeof(numshades));
fw->Write(&g_visibility, sizeof(g_visibility));
fw->Write(&parallaxtype, sizeof(parallaxtype));
fw->Write(&parallaxyoffs_override, sizeof(parallaxyoffs_override));
fw->Write(&parallaxyscale_override, sizeof(parallaxyscale_override));
fw->Write(&pskybits_override, sizeof(pskybits_override));
fw->Write(show2dwall, sizeof(show2dwall));
fw->Write(show2dsprite, sizeof(show2dsprite));
fw->Write(show2dsector, sizeof(show2dsector));
}
void LoadEngineState()
{
auto fr = ReadSavegameChunk("engine.bin");
if (fr.isOpen())
{
fr.Read(&numsectors, sizeof(numsectors));
fr.Read(sector, sizeof(sectortype) * numsectors);
fr.Read(&numwalls, sizeof(numwalls));
fr.Read(wall, sizeof(walltype) * numwalls);
fr.Read(sprite, sizeof(spritetype) * MAXSPRITES);
fr.Read(headspritesect, sizeof(headspritesect));
fr.Read(prevspritesect, sizeof(prevspritesect));
fr.Read(nextspritesect, sizeof(nextspritesect));
fr.Read(headspritestat, sizeof(headspritestat));
fr.Read(prevspritestat, sizeof(prevspritestat));
fr.Read(nextspritestat, sizeof(nextspritestat));
fr.Read(&tailspritefree, sizeof(tailspritefree));
fr.Read(&myconnectindex, sizeof(myconnectindex));
fr.Read(&connecthead, sizeof(connecthead));
fr.Read(connectpoint2, sizeof(connectpoint2));
fr.Read(&numframes, sizeof(numframes));
fr.Read(&randomseed, sizeof(randomseed));
fr.Read(&numshades, sizeof(numshades));
fr.Read(&g_visibility, sizeof(g_visibility));
fr.Read(&parallaxtype, sizeof(parallaxtype));
fr.Read(&parallaxyoffs_override, sizeof(parallaxyoffs_override));
fr.Read(&parallaxyscale_override, sizeof(parallaxyscale_override));
fr.Read(&pskybits_override, sizeof(pskybits_override));
fr.Read(show2dwall, sizeof(show2dwall));
fr.Read(show2dsprite, sizeof(show2dsprite));
fr.Read(show2dsector, sizeof(show2dsector));
fr.Close();
}
}

View file

@ -17,5 +17,8 @@ class FileReader;
FString G_BuildSaveName (const char *prefix);
int G_ValidateSavegame(FileReader &fr, FString *savetitle, bool formenu);
void SaveEngineState();
void LoadEngineState();
#define SAVEGAME_EXT ".dsave"

View file

@ -40,37 +40,7 @@ static TArray<SavegameHelper*> sghelpers(TArray<SavegameHelper*>::NoInit);
bool GameInterface::SaveGame(FSaveGameNode* sv)
{
auto fw = WriteSavegameChunk("engine");
fw->Write(&numsectors, sizeof(numsectors));
fw->Write(sector, sizeof(sectortype) * numsectors);
fw->Write(&numwalls, sizeof(numwalls));
fw->Write(wall, sizeof(walltype) * numwalls);
fw->Write(sprite, sizeof(spritetype) * kMaxSprites);
fw->Write(headspritesect, sizeof(headspritesect));
fw->Write(prevspritesect, sizeof(prevspritesect));
fw->Write(nextspritesect, sizeof(nextspritesect));
fw->Write(headspritestat, sizeof(headspritestat));
fw->Write(prevspritestat, sizeof(prevspritestat));
fw->Write(nextspritestat, sizeof(nextspritestat));
fw->Write(&tailspritefree, sizeof(tailspritefree));
fw->Write(&myconnectindex, sizeof(myconnectindex));
fw->Write(&connecthead, sizeof(connecthead));
fw->Write(connectpoint2, sizeof(connectpoint2));
fw->Write(&numframes, sizeof(numframes));
fw->Write(&randomseed, sizeof(randomseed));
fw->Write(&numshades, sizeof(numshades));
fw->Write(&g_visibility, sizeof(g_visibility));
fw->Write(&parallaxtype, sizeof(parallaxtype));
fw->Write(&parallaxyoffs_override, sizeof(parallaxyoffs_override));
fw->Write(&parallaxyscale_override, sizeof(parallaxyscale_override));
fw->Write(&pskybits_override, sizeof(pskybits_override));
fw->Write(show2dwall, sizeof(show2dwall));
fw->Write(show2dsprite, sizeof(show2dsprite));
fw->Write(show2dsector, sizeof(show2dsector));
SaveEngineState();
for (auto sgh : sghelpers) sgh->Save();
SaveTextureState();
FinishSavegameWrite();
@ -80,40 +50,7 @@ bool GameInterface::SaveGame(FSaveGameNode* sv)
bool GameInterface::LoadGame(FSaveGameNode* sv)
{
OpenSaveGameForRead(sv->Filename);
auto fr = ReadSavegameChunk("engine");
if (fr.isOpen())
{
fr.Read(&numsectors, sizeof(numsectors));
fr.Read(sector, sizeof(sectortype) * numsectors);
fr.Read(&numwalls, sizeof(numwalls));
fr.Read(wall, sizeof(walltype) * numwalls);
fr.Read(sprite, sizeof(spritetype) * kMaxSprites);
fr.Read(headspritesect, sizeof(headspritesect));
fr.Read(prevspritesect, sizeof(prevspritesect));
fr.Read(nextspritesect, sizeof(nextspritesect));
fr.Read(headspritestat, sizeof(headspritestat));
fr.Read(prevspritestat, sizeof(prevspritestat));
fr.Read(nextspritestat, sizeof(nextspritestat));
fr.Read(&tailspritefree, sizeof(tailspritefree));
fr.Read(&myconnectindex, sizeof(myconnectindex));
fr.Read(&connecthead, sizeof(connecthead));
fr.Read(connectpoint2, sizeof(connectpoint2));
fr.Read(&numframes, sizeof(numframes));
fr.Read(&randomseed, sizeof(randomseed));
fr.Read(&numshades, sizeof(numshades));
fr.Read(&g_visibility, sizeof(g_visibility));
fr.Read(&parallaxtype, sizeof(parallaxtype));
fr.Read(&parallaxyoffs_override, sizeof(parallaxyoffs_override));
fr.Read(&parallaxyscale_override, sizeof(parallaxyscale_override));
fr.Read(&pskybits_override, sizeof(pskybits_override));
fr.Read(show2dwall, sizeof(show2dwall));
fr.Read(show2dsprite, sizeof(show2dsprite));
fr.Read(show2dsector, sizeof(show2dsector));
fr.Close();
}
LoadEngineState();
for (auto sgh : sghelpers) sgh->Load();
LoadTextureState();