2019-11-20 16:21:32 +00:00
|
|
|
//-------------------------------------------------------------------------
|
|
|
|
/*
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
//-------------------------------------------------------------------------
|
2019-11-22 23:11:37 +00:00
|
|
|
#include "ns.h"
|
2019-08-26 03:59:14 +00:00
|
|
|
#include <stdio.h>
|
2019-12-26 21:00:04 +00:00
|
|
|
#include <stdarg.h>
|
2020-08-18 08:28:19 +00:00
|
|
|
#include "build.h"
|
2020-04-12 06:08:31 +00:00
|
|
|
#include "raze_music.h"
|
2019-08-26 03:59:14 +00:00
|
|
|
#include "engine.h"
|
2019-12-26 21:00:04 +00:00
|
|
|
#include "exhumed.h"
|
2019-12-26 22:17:11 +00:00
|
|
|
#include "mmulti.h"
|
2019-12-26 21:00:04 +00:00
|
|
|
#include "savegamehelp.h"
|
2019-12-27 21:17:36 +00:00
|
|
|
#include "sound.h"
|
2020-08-23 14:24:54 +00:00
|
|
|
#include "mapinfo.h"
|
2019-08-26 03:59:14 +00:00
|
|
|
|
2019-11-22 23:11:37 +00:00
|
|
|
BEGIN_PS_NS
|
|
|
|
|
2020-11-29 18:15:59 +00:00
|
|
|
void SerializeAnubis(FSerializer& arc);
|
2020-11-29 19:16:58 +00:00
|
|
|
void SerializeFish(FSerializer& arc);
|
2020-11-29 19:34:55 +00:00
|
|
|
void SerializeLavadude(FSerializer& arc);
|
2020-11-29 19:26:54 +00:00
|
|
|
void SerializeLion(FSerializer& arc);
|
2020-11-29 19:34:55 +00:00
|
|
|
void SerializeMummy(FSerializer& arc);
|
2020-11-29 18:31:49 +00:00
|
|
|
void SerializeSpider(FSerializer& arc);
|
2020-11-29 18:15:59 +00:00
|
|
|
|
|
|
|
|
2019-12-27 09:52:40 +00:00
|
|
|
void SaveTextureState();
|
|
|
|
void LoadTextureState();
|
|
|
|
|
2019-12-26 22:17:11 +00:00
|
|
|
static TArray<SavegameHelper*> sghelpers(TArray<SavegameHelper*>::NoInit);
|
|
|
|
|
2020-10-07 16:32:57 +00:00
|
|
|
bool GameInterface::SaveGame()
|
2019-08-26 03:59:14 +00:00
|
|
|
{
|
2019-12-26 22:17:11 +00:00
|
|
|
for (auto sgh : sghelpers) sgh->Save();
|
2019-12-27 09:52:40 +00:00
|
|
|
SaveTextureState();
|
2019-08-31 07:47:15 +00:00
|
|
|
return 1; // CHECKME
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
2020-11-29 18:15:59 +00:00
|
|
|
void GameInterface::SerializeGameState(FSerializer& arc)
|
|
|
|
{
|
|
|
|
SerializeAnubis(arc);
|
2020-11-29 19:16:58 +00:00
|
|
|
SerializeFish(arc);
|
2020-11-29 19:34:55 +00:00
|
|
|
SerializeLavadude(arc);
|
2020-11-29 19:26:54 +00:00
|
|
|
SerializeLion(arc);
|
2020-11-29 19:34:55 +00:00
|
|
|
SerializeMummy(arc);
|
2020-11-29 18:31:49 +00:00
|
|
|
SerializeSpider(arc);
|
2020-11-29 18:15:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-10-07 16:32:57 +00:00
|
|
|
bool GameInterface::LoadGame()
|
2019-08-26 03:59:14 +00:00
|
|
|
{
|
|
|
|
|
2019-12-26 22:17:11 +00:00
|
|
|
for (auto sgh : sghelpers) sgh->Load();
|
2019-12-27 09:52:40 +00:00
|
|
|
LoadTextureState();
|
|
|
|
FinishSavegameRead();
|
2019-12-26 22:17:11 +00:00
|
|
|
|
|
|
|
// reset the sky in case it hasn't been done yet.
|
2020-07-14 22:06:19 +00:00
|
|
|
psky_t* pSky = tileSetupSky(DEFAULTPSKY);
|
2019-12-26 22:17:11 +00:00
|
|
|
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;
|
2019-12-27 21:17:36 +00:00
|
|
|
|
2020-08-23 14:24:54 +00:00
|
|
|
if (currentLevel->levelNumber > 15)
|
2019-12-27 21:17:36 +00:00
|
|
|
{
|
|
|
|
nSwitchSound = 35;
|
|
|
|
nStoneSound = 23;
|
|
|
|
nElevSound = 51;
|
|
|
|
nStopSound = 35;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
nSwitchSound = 33;
|
|
|
|
nStoneSound = 23;
|
|
|
|
nElevSound = 23;
|
|
|
|
nStopSound = 66;
|
|
|
|
}
|
|
|
|
|
2019-12-27 16:07:09 +00:00
|
|
|
Mus_ResumeSaved();
|
2019-08-31 07:47:15 +00:00
|
|
|
return 1; // CHECKME
|
2019-08-26 03:59:14 +00:00
|
|
|
}
|
|
|
|
|
2019-12-26 21:00:04 +00:00
|
|
|
|
|
|
|
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);
|
2020-09-04 21:31:41 +00:00
|
|
|
if (!fr.isOpen()) return;
|
2019-12-26 21:00:04 +00:00
|
|
|
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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-22 23:11:37 +00:00
|
|
|
END_PS_NS
|