raze/source/exhumed/src/save.cpp

192 lines
5.1 KiB
C++
Raw Normal View History

//-------------------------------------------------------------------------
/*
Copyright (C) 2010-2019 EDuke32 developers and contributors
Copyright (C) 2019 sirlemonhead, Nuke.YKT
This file is part of PCExhumed.
PCExhumed is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
//-------------------------------------------------------------------------
#include "ns.h"
#include <stdio.h>
#include <stdarg.h>
#include "build.h"
2020-04-12 06:08:31 +00:00
#include "raze_music.h"
#include "engine.h"
#include "exhumed.h"
#include "mmulti.h"
#include "savegamehelp.h"
#include "sound.h"
#include "mapinfo.h"
BEGIN_PS_NS
2020-11-29 23:47:53 +00:00
void SerializeAnim(FSerializer& arc);
2020-11-30 00:07:14 +00:00
void SerializeBubbles(FSerializer& arc);
2020-11-30 00:10:52 +00:00
void SerializeBullet(FSerializer& arc);
void SerializeGrenade(FSerializer& arc);
2020-11-30 00:07:14 +00:00
void SerializeGun(FSerializer& arc);
2020-11-30 00:08:19 +00:00
void SerializeInit(FSerializer& arc);
2020-11-29 23:51:56 +00:00
void SerializeItems(FSerializer& arc);
void SerializeMove(FSerializer& arc);
2020-11-30 00:05:17 +00:00
void SerializeLighting(FSerializer& arc);
2020-11-29 23:49:25 +00:00
void SerializeObjects(FSerializer& arc);
2020-11-29 23:47:53 +00:00
void SerializePlayer(FSerializer& arc);
void SerializeRa(FSerializer& arc);
2020-11-29 23:23:57 +00:00
void SerializeRand(FSerializer& arc);
void SerializeRunList(FSerializer& arc);
void SerializeSequence(FSerializer& arc);
void SerializeSnake(FSerializer& arc);
void SerializeSwitch(FSerializer& arc);
void SerializeView(FSerializer& arc);
void SerializeAnubis(FSerializer& arc);
void SerializeFish(FSerializer& arc);
void SerializeLavadude(FSerializer& arc);
void SerializeLion(FSerializer& arc);
void SerializeMummy(FSerializer& arc);
2020-11-29 23:40:25 +00:00
void SerializeQueen(FSerializer& arc);
2020-11-29 19:39:27 +00:00
void SerializeRat(FSerializer& arc);
2020-11-29 19:43:35 +00:00
void SerializeRex(FSerializer& arc);
2020-11-29 19:47:55 +00:00
void SerializeRoach(FSerializer& arc);
2020-11-29 19:52:16 +00:00
void SerializeScorpion(FSerializer& arc);
2020-11-29 19:59:42 +00:00
void SerializeSet(FSerializer& arc);
void SerializeSpider(FSerializer& arc);
2020-11-29 20:09:41 +00:00
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
}
void GameInterface::SerializeGameState(FSerializer& arc)
{
if (arc.BeginObject("exhumed"))
{
2020-11-29 23:47:53 +00:00
SerializeAnim(arc);
2020-11-30 00:07:14 +00:00
SerializeBubbles(arc);
2020-11-30 00:10:52 +00:00
SerializeBullet(arc);
SerializeGrenade(arc);
2020-11-30 00:07:14 +00:00
SerializeGun(arc);
2020-11-30 00:08:19 +00:00
SerializeInit(arc);
2020-11-29 23:51:56 +00:00
SerializeItems(arc);
SerializeMove(arc);
2020-11-30 00:05:17 +00:00
SerializeLighting(arc);
2020-11-29 23:49:25 +00:00
SerializeObjects(arc);
2020-11-29 23:47:53 +00:00
SerializePlayer(arc);
SerializeRa(arc);
2020-11-29 23:23:57 +00:00
SerializeRand(arc);
SerializeRunList(arc);
SerializeSequence(arc);
SerializeSnake(arc);
SerializeSwitch(arc);
SerializeView(arc);
SerializeAnubis(arc);
SerializeFish(arc);
SerializeLavadude(arc);
SerializeLion(arc);
SerializeMummy(arc);
2020-11-29 23:40:25 +00:00
SerializeQueen(arc);
2020-11-29 19:39:27 +00:00
SerializeRat(arc);
2020-11-29 19:43:35 +00:00
SerializeRex(arc);
2020-11-29 19:47:55 +00:00
SerializeRoach(arc);
2020-11-29 19:52:16 +00:00
SerializeScorpion(arc);
2020-11-29 19:59:42 +00:00
SerializeSet(arc);
SerializeSpider(arc);
2020-11-29 20:09:41 +00:00
SerializeWasp(arc);
}
}
bool GameInterface::LoadGame()
{
for (auto sgh : sghelpers) sgh->Load();
LoadTextureState();
FinishSavegameRead();
// reset the sky in case it hasn't been done yet.
psky_t* pSky = tileSetupSky(DEFAULTPSKY);
pSky->tileofs[0] = 0;
pSky->tileofs[1] = 0;
pSky->tileofs[2] = 0;
pSky->tileofs[3] = 0;
pSky->yoffs = 256;
pSky->lognumtiles = 2;
pSky->horizfrac = 65536;
pSky->yscale = 65536;
parallaxtype = 2;
g_visibility = 2048;
if (currentLevel->levelNumber > 15)
{
nSwitchSound = 35;
nStoneSound = 23;
nElevSound = 51;
nStopSound = 35;
}
else
{
nSwitchSound = 33;
nStoneSound = 23;
nElevSound = 23;
nStopSound = 66;
}
Mus_ResumeSaved();
return 1; // CHECKME
}
SavegameHelper::SavegameHelper(const char* name, ...)
{
Name = name;
sghelpers.Push(this);
va_list ap;
va_start(ap, name);
for(;;)
{
void* addr = va_arg(ap, void*);
if (!addr) break;
size_t size = va_arg(ap, size_t);
Elements.Push(std::make_pair(addr, size));
}
}
void SavegameHelper::Load()
{
auto fr = ReadSavegameChunk(Name);
if (!fr.isOpen()) return;
for (auto& entry : Elements)
{
auto read = fr.Read(entry.first, entry.second);
if (read != entry.second) I_Error("Save game read error in %s", Name.GetChars());
}
}
void SavegameHelper::Save()
{
auto fw = WriteSavegameChunk(Name);
for (auto& entry : Elements)
{
auto write = fw->Write(entry.first, entry.second);
if (write != entry.second) I_Error("Save game write error in %s", Name.GetChars());
}
}
END_PS_NS