mirror of
https://github.com/DrBeef/Raze.git
synced 2024-11-15 00:41:55 +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;
|
||||
}
|
||||
|
||||
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, FFont*& font, FFont** 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));
|
||||
}
|
||||
|
||||
// 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.
|
||||
|
|
|
@ -77,8 +77,9 @@ struct GameInterface
|
|||
virtual void DrawCenteredTextScreen(const DVector2& origin, const char* text, int position, bool withbg = true);
|
||||
virtual double SmallFontScale() { return 1; }
|
||||
virtual void DrawMenuCaption(const DVector2& origin, const char* text) {}
|
||||
virtual bool SaveGame(FSaveGameNode*) { return false; }
|
||||
virtual bool LoadGame(FSaveGameNode*) { return false; }
|
||||
virtual bool SaveGame(FSaveGameNode*) { return true; }
|
||||
virtual bool LoadGame(FSaveGameNode*) { return true; }
|
||||
virtual void SerializeGameState(FSerializer& arc) {}
|
||||
virtual bool CleanupForLoad() { return true; }
|
||||
virtual void DrawPlayerSprite(const DVector2& origin, bool onteam) {}
|
||||
virtual void QuitToTitle() {}
|
||||
|
|
|
@ -96,6 +96,20 @@ bool OpenSaveGameForRead(const char *name)
|
|||
|
||||
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");
|
||||
if (info == nullptr)
|
||||
{
|
||||
|
@ -114,20 +128,7 @@ bool OpenSaveGameForRead(const char *name)
|
|||
// Load system-side data from savegames.
|
||||
SerializeSession(arc);
|
||||
LoadEngineState();
|
||||
|
||||
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;
|
||||
}
|
||||
gi->SerializeGameState(arc);
|
||||
}
|
||||
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.
|
||||
savegamesession.OpenWriter(save_formatted);
|
||||
SerializeSession(savegamesession);
|
||||
SaveEngineState();
|
||||
gi->SerializeGameState(savegamesession);
|
||||
buff = savegamesession.GetCompressedOutput();
|
||||
AddCompressedSavegameChunk("session.json", buff);
|
||||
|
||||
SaveEngineState();
|
||||
auto picfile = WriteSavegameChunk("savepic.png");
|
||||
WriteSavePic(picfile, 240, 180);
|
||||
return true;
|
||||
|
@ -494,6 +496,7 @@ void SaveEngineState()
|
|||
sv_prespriteextsave();
|
||||
fw->Write(spriteext, sizeof(spriteext_t) * MAXSPRITES);
|
||||
fw->Write(wallext, sizeof(wallext_t) * MAXWALLS);
|
||||
fw->Write(&randomseed, sizeof(randomseed));
|
||||
sv_postspriteext();
|
||||
WriteMagic(fw);
|
||||
|
||||
|
@ -556,6 +559,7 @@ void LoadEngineState()
|
|||
fr.Read(&Numsprites, sizeof(Numsprites));
|
||||
fr.Read(spriteext, sizeof(spriteext_t) * MAXSPRITES);
|
||||
fr.Read(wallext, sizeof(wallext_t) * MAXWALLS);
|
||||
fr.Read(&randomseed, sizeof(randomseed));
|
||||
sv_postspriteext();
|
||||
CheckMagic(fr);
|
||||
|
||||
|
|
|
@ -54,8 +54,7 @@ struct GameInterface : ::GameInterface
|
|||
void DrawCenteredTextScreen(const DVector2& origin, const char* text, int position, bool bg) override;
|
||||
double SmallFontScale() override { return isRR() ? 0.5 : 1.; }
|
||||
void DrawMenuCaption(const DVector2& origin, const char* text) override;
|
||||
bool SaveGame(FSaveGameNode*) override;
|
||||
bool LoadGame(FSaveGameNode*) override;
|
||||
void SerializeGameState(FSerializer& arc) override;
|
||||
void QuitToTitle() override;
|
||||
FString GetCoordString() 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())
|
||||
{
|
||||
|
@ -340,7 +340,7 @@ void SerializeGlobals(FSerializer& arc)
|
|||
memset(ambienthitag, -1, sizeof(ambienthitag));
|
||||
memset(ambientlotag, -1, sizeof(ambientlotag));
|
||||
}
|
||||
if (arc.BeginObject("globals"))
|
||||
if (arc.BeginObject("duke.gamestate"))
|
||||
{
|
||||
arc("multimode", ud.multimode);
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue