- Exhumed: Serialize global state as JSON.

This was the last item to be converted.
This commit is contained in:
Christoph Oelckers 2020-11-30 01:13:40 +01:00
parent 487d62e264
commit 67dff2a863
3 changed files with 31 additions and 81 deletions

View file

@ -645,83 +645,43 @@ bool GameInterface::CanSave()
return new GameInterface;
}
// This is only the static global data.
static SavegameHelper sghexhumed("exhumed",
SV(besttarget),
SV(nCreaturesTotal),
SV(nCreaturesKilled),
SV(nFreeze),
SV(nSnakeCam),
SV(nLocalSpr),
SV(nClockVal), // kTile3603
SV(nRedTicks),
SV(nAlarmTicks),
SV(nButtonColor),
SV(nEnergyChan),
SV(lCountDown),
SV(nEnergyTowers),
SV(totalmoves),
SV(nCurBodyNum),
SV(nBodyTotal),
SV(bSnakeCam),
SV(bSlipMode),
SV(leveltime),
nullptr);
extern short cPupData[300];
extern uint8_t* Worktile;
extern int lHeadStartClock;
extern short* pPupData;
void SaveTextureState()
void SerializeState(FSerializer& arc)
{
auto fw = WriteSavegameChunk("texture");
int pupOffset = pPupData? int(pPupData - cPupData) : -1;
// There is really no good way to restore these tiles, so it's probably best to save them as well, so that they can be reloaded with the exact state they were left in
fw->Write(&pupOffset, 4);
uint8_t loaded = !!Worktile;
fw->Write(&loaded, 1);
if (Worktile) fw->Write(Worktile, WorktileSize);
auto pixels = TileFiles.tileMakeWritable(kTile3603);
fw->Write(pixels, tileWidth(kTile3603) * tileHeight(kTile3603));
pixels = TileFiles.tileMakeWritable(kEnergy1);
fw->Write(pixels, tileWidth(kEnergy1) * tileHeight(kEnergy1));
pixels = TileFiles.tileMakeWritable(kEnergy2);
fw->Write(pixels, tileWidth(kEnergy2) * tileHeight(kEnergy2));
}
void LoadTextureState()
{
auto fr = ReadSavegameChunk("texture");
int pofs;
fr.Read(&pofs, 4);
pPupData = pofs == -1 ? nullptr : cPupData + pofs;
uint8_t loaded;
fr.Read(&loaded, 1);
if (loaded)
int loaded = 0;
if (arc.BeginObject("state"))
{
Worktile = TileFiles.tileCreate(kTileRamsesWorkTile, kSpiritX * 2, kSpiritY * 2);
fr.Read(Worktile, WorktileSize);
if (arc.isReading() && currentLevel->levelNumber == 20)
{
InitEnergyTile();
}
arc ("besttarget", besttarget)
("creaturestotal", nCreaturesTotal)
("creatureskilled", nCreaturesKilled)
("freeze", nFreeze)
("snakecam", nSnakeCam)
("localspr", nLocalSpr)
("clockval", nClockVal) // kTile3603
("redticks", nRedTicks)
("alarmticks", nAlarmTicks)
("buttoncolor", nButtonColor)
("energychan", nEnergyChan)
("countdown", lCountDown)
("energytowers", nEnergyTowers)
("totalmoves", totalmoves)
("curbodynum", nCurBodyNum)
("bodytotal", nBodyTotal)
("snakecam", bSnakeCam)
("slipmode", bSlipMode)
("leveltime", leveltime)
("cinemaseen", nCinemaSeen)
.EndObject();
}
auto pixels = TileFiles.tileMakeWritable(kTile3603);
fr.Read(pixels, tileWidth(kTile3603) * tileHeight(kTile3603));
pixels = TileFiles.tileMakeWritable(kEnergy1);
fr.Read(pixels, tileWidth(kEnergy1) * tileHeight(kEnergy1));
pixels = TileFiles.tileMakeWritable(kEnergy2);
fr.Read(pixels, tileWidth(kEnergy2) * tileHeight(kEnergy2));
TileFiles.InvalidateTile(kTileRamsesWorkTile);
TileFiles.InvalidateTile(kTile3603);
TileFiles.InvalidateTile(kEnergy1);
TileFiles.InvalidateTile(kEnergy2);
}
CCMD(endit)
{
LevelFinished();
}
END_PS_NS

View file

@ -238,11 +238,4 @@ void DoEnergyTile()
}
}
static SavegameHelper sghmenu("menu",
SA(nCinemaSeen),
SA(energytile),
SV(nButtonColor),
SV(word_9AB5B),
nullptr);
END_PS_NS

View file

@ -29,6 +29,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
BEGIN_PS_NS
void SerializeState(FSerializer& arc);
void SerializeAnim(FSerializer& arc);
void SerializeBubbles(FSerializer& arc);
void SerializeBullet(FSerializer& arc);
@ -62,15 +63,11 @@ void SerializeSet(FSerializer& arc);
void SerializeSpider(FSerializer& arc);
void SerializeWasp(FSerializer& arc);
void SaveTextureState();
void LoadTextureState();
static TArray<SavegameHelper*> sghelpers(TArray<SavegameHelper*>::NoInit);
bool GameInterface::SaveGame()
{
for (auto sgh : sghelpers) sgh->Save();
SaveTextureState();
return 1; // CHECKME
}
@ -78,6 +75,7 @@ void GameInterface::SerializeGameState(FSerializer& arc)
{
if (arc.BeginObject("exhumed"))
{
SerializeState(arc);
SerializeAnim(arc);
SerializeBubbles(arc);
SerializeBullet(arc);
@ -117,7 +115,6 @@ bool GameInterface::LoadGame()
{
for (auto sgh : sghelpers) sgh->Load();
LoadTextureState();
FinishSavegameRead();
// reset the sky in case it hasn't been done yet.