mirror of
https://github.com/ZDoom/raze-gles.git
synced 2024-12-30 13:21:04 +00:00
- hooked up the new savegame code.
Not tested yet.
This commit is contained in:
parent
9ace06ad81
commit
1869a7930e
6 changed files with 41 additions and 33 deletions
|
@ -238,6 +238,12 @@ FSerializer &Serialize(FSerializer &arc, const char *key, TArray<T, TT> &value,
|
||||||
return arc;
|
return arc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template<int size>
|
||||||
|
FSerializer& Serialize(FSerializer& arc, const char* key, FixedBitArray<size>& value, FixedBitArray<size>* def)
|
||||||
|
{
|
||||||
|
return arc.Array(key, value.Storage(), def ? def->Storage() : nullptr, value.StorageSize());
|
||||||
|
}
|
||||||
|
|
||||||
template<> FSerializer& Serialize(FSerializer& arc, const char* key, PClass*& clst, PClass** def);
|
template<> FSerializer& Serialize(FSerializer& arc, const char* key, PClass*& clst, PClass** def);
|
||||||
template<> FSerializer& Serialize(FSerializer& arc, const char* key, FFont*& font, FFont** def);
|
template<> FSerializer& Serialize(FSerializer& arc, const char* key, FFont*& font, FFont** def);
|
||||||
template<> FSerializer &Serialize(FSerializer &arc, const char *key, Dictionary *&dict, Dictionary **def);
|
template<> FSerializer &Serialize(FSerializer &arc, const char *key, Dictionary *&dict, Dictionary **def);
|
||||||
|
|
|
@ -1527,6 +1527,16 @@ public:
|
||||||
{
|
{
|
||||||
memset(&bytes[0], on ? -1 : 0, sizeof(bytes));
|
memset(&bytes[0], on ? -1 : 0, sizeof(bytes));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// These are for utilities that need access to the raw storage. The serializer needs this to do its work, for example.
|
||||||
|
uint8_t* Storage()
|
||||||
|
{
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
unsigned StorageSize() const
|
||||||
|
{
|
||||||
|
return sizeof(bytes);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// A wrapper to externally stored data.
|
// A wrapper to externally stored data.
|
||||||
|
|
|
@ -77,8 +77,9 @@ struct GameInterface
|
||||||
virtual void DrawCenteredTextScreen(const DVector2& origin, const char* text, int position, bool withbg = true);
|
virtual void DrawCenteredTextScreen(const DVector2& origin, const char* text, int position, bool withbg = true);
|
||||||
virtual double SmallFontScale() { return 1; }
|
virtual double SmallFontScale() { return 1; }
|
||||||
virtual void DrawMenuCaption(const DVector2& origin, const char* text) {}
|
virtual void DrawMenuCaption(const DVector2& origin, const char* text) {}
|
||||||
virtual bool SaveGame(FSaveGameNode*) { return false; }
|
virtual bool SaveGame(FSaveGameNode*) { return true; }
|
||||||
virtual bool LoadGame(FSaveGameNode*) { return false; }
|
virtual bool LoadGame(FSaveGameNode*) { return true; }
|
||||||
|
virtual void SerializeGameState(FSerializer& arc) {}
|
||||||
virtual bool CleanupForLoad() { return true; }
|
virtual bool CleanupForLoad() { return true; }
|
||||||
virtual void DrawPlayerSprite(const DVector2& origin, bool onteam) {}
|
virtual void DrawPlayerSprite(const DVector2& origin, bool onteam) {}
|
||||||
virtual void QuitToTitle() {}
|
virtual void QuitToTitle() {}
|
||||||
|
|
|
@ -96,6 +96,20 @@ bool OpenSaveGameForRead(const char *name)
|
||||||
|
|
||||||
if (savereader != nullptr)
|
if (savereader != nullptr)
|
||||||
{
|
{
|
||||||
|
auto file = ReadSavegameChunk("info.json");
|
||||||
|
if (!file.isOpen())
|
||||||
|
{
|
||||||
|
FinishSavegameRead();
|
||||||
|
delete savereader;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (G_ValidateSavegame(file, nullptr, false) <= 0)
|
||||||
|
{
|
||||||
|
FinishSavegameRead();
|
||||||
|
delete savereader;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
FResourceLump* info = savereader->FindLump("session.json");
|
FResourceLump* info = savereader->FindLump("session.json");
|
||||||
if (info == nullptr)
|
if (info == nullptr)
|
||||||
{
|
{
|
||||||
|
@ -114,20 +128,7 @@ bool OpenSaveGameForRead(const char *name)
|
||||||
// Load system-side data from savegames.
|
// Load system-side data from savegames.
|
||||||
SerializeSession(arc);
|
SerializeSession(arc);
|
||||||
LoadEngineState();
|
LoadEngineState();
|
||||||
|
gi->SerializeGameState(arc);
|
||||||
auto file = ReadSavegameChunk("info.json");
|
|
||||||
if (!file.isOpen())
|
|
||||||
{
|
|
||||||
FinishSavegameRead();
|
|
||||||
delete savereader;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (G_ValidateSavegame(file, nullptr, false) <= 0)
|
|
||||||
{
|
|
||||||
FinishSavegameRead();
|
|
||||||
delete savereader;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return savereader != nullptr;
|
return savereader != nullptr;
|
||||||
}
|
}
|
||||||
|
@ -220,10 +221,11 @@ bool OpenSaveGameForWrite(const char* filename, const char *name)
|
||||||
// Handle system-side modules that need to persist data in savegames here, in a central place.
|
// Handle system-side modules that need to persist data in savegames here, in a central place.
|
||||||
savegamesession.OpenWriter(save_formatted);
|
savegamesession.OpenWriter(save_formatted);
|
||||||
SerializeSession(savegamesession);
|
SerializeSession(savegamesession);
|
||||||
|
SaveEngineState();
|
||||||
|
gi->SerializeGameState(savegamesession);
|
||||||
buff = savegamesession.GetCompressedOutput();
|
buff = savegamesession.GetCompressedOutput();
|
||||||
AddCompressedSavegameChunk("session.json", buff);
|
AddCompressedSavegameChunk("session.json", buff);
|
||||||
|
|
||||||
SaveEngineState();
|
|
||||||
auto picfile = WriteSavegameChunk("savepic.png");
|
auto picfile = WriteSavegameChunk("savepic.png");
|
||||||
WriteSavePic(picfile, 240, 180);
|
WriteSavePic(picfile, 240, 180);
|
||||||
return true;
|
return true;
|
||||||
|
@ -494,6 +496,7 @@ void SaveEngineState()
|
||||||
sv_prespriteextsave();
|
sv_prespriteextsave();
|
||||||
fw->Write(spriteext, sizeof(spriteext_t) * MAXSPRITES);
|
fw->Write(spriteext, sizeof(spriteext_t) * MAXSPRITES);
|
||||||
fw->Write(wallext, sizeof(wallext_t) * MAXWALLS);
|
fw->Write(wallext, sizeof(wallext_t) * MAXWALLS);
|
||||||
|
fw->Write(&randomseed, sizeof(randomseed));
|
||||||
sv_postspriteext();
|
sv_postspriteext();
|
||||||
WriteMagic(fw);
|
WriteMagic(fw);
|
||||||
|
|
||||||
|
@ -556,6 +559,7 @@ void LoadEngineState()
|
||||||
fr.Read(&Numsprites, sizeof(Numsprites));
|
fr.Read(&Numsprites, sizeof(Numsprites));
|
||||||
fr.Read(spriteext, sizeof(spriteext_t) * MAXSPRITES);
|
fr.Read(spriteext, sizeof(spriteext_t) * MAXSPRITES);
|
||||||
fr.Read(wallext, sizeof(wallext_t) * MAXWALLS);
|
fr.Read(wallext, sizeof(wallext_t) * MAXWALLS);
|
||||||
|
fr.Read(&randomseed, sizeof(randomseed));
|
||||||
sv_postspriteext();
|
sv_postspriteext();
|
||||||
CheckMagic(fr);
|
CheckMagic(fr);
|
||||||
|
|
||||||
|
|
|
@ -54,8 +54,7 @@ struct GameInterface : ::GameInterface
|
||||||
void DrawCenteredTextScreen(const DVector2& origin, const char* text, int position, bool bg) override;
|
void DrawCenteredTextScreen(const DVector2& origin, const char* text, int position, bool bg) override;
|
||||||
double SmallFontScale() override { return isRR() ? 0.5 : 1.; }
|
double SmallFontScale() override { return isRR() ? 0.5 : 1.; }
|
||||||
void DrawMenuCaption(const DVector2& origin, const char* text) override;
|
void DrawMenuCaption(const DVector2& origin, const char* text) override;
|
||||||
bool SaveGame(FSaveGameNode*) override;
|
void SerializeGameState(FSerializer& arc) override;
|
||||||
bool LoadGame(FSaveGameNode*) override;
|
|
||||||
void QuitToTitle() override;
|
void QuitToTitle() override;
|
||||||
FString GetCoordString() override;
|
FString GetCoordString() override;
|
||||||
bool CheatAllowed(bool printmsg) override;
|
bool CheatAllowed(bool printmsg) override;
|
||||||
|
|
|
@ -328,7 +328,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, weaponhit& w, weap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void SerializeGlobals(FSerializer& arc)
|
void GameInterface::SerializeGameState(FSerializer& arc)
|
||||||
{
|
{
|
||||||
if (arc.isReading())
|
if (arc.isReading())
|
||||||
{
|
{
|
||||||
|
@ -340,7 +340,7 @@ void SerializeGlobals(FSerializer& arc)
|
||||||
memset(ambienthitag, -1, sizeof(ambienthitag));
|
memset(ambienthitag, -1, sizeof(ambienthitag));
|
||||||
memset(ambientlotag, -1, sizeof(ambientlotag));
|
memset(ambientlotag, -1, sizeof(ambientlotag));
|
||||||
}
|
}
|
||||||
if (arc.BeginObject("globals"))
|
if (arc.BeginObject("duke.gamestate"))
|
||||||
{
|
{
|
||||||
arc("multimode", ud.multimode);
|
arc("multimode", ud.multimode);
|
||||||
if (ud.multimode > 1) arc.Array("frags", &frags[0][0], MAXPLAYERS * MAXPLAYERS);
|
if (ud.multimode > 1) arc.Array("frags", &frags[0][0], MAXPLAYERS * MAXPLAYERS);
|
||||||
|
@ -505,16 +505,4 @@ void SerializeGlobals(FSerializer& arc)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GameInterface::LoadGame(FSaveGameNode* sv)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool GameInterface::SaveGame(FSaveGameNode* sv)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
END_DUKE_NS
|
END_DUKE_NS
|
||||||
|
|
Loading…
Reference in a new issue