- more savegame stuff.

Should be complete now. We'll see...
This commit is contained in:
Christoph Oelckers 2019-12-26 23:17:11 +01:00
parent 79d0818201
commit 3bd36bfb9d
3 changed files with 125 additions and 101 deletions

View file

@ -71,6 +71,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include <time.h> #include <time.h>
#include <assert.h> #include <assert.h>
#include "gamecvars.h" #include "gamecvars.h"
#include "savegamehelp.h"
BEGIN_PS_NS BEGIN_PS_NS
@ -3450,16 +3451,48 @@ static SavegameHelper sgh("exhumed",
SV(nBodyTotal), SV(nBodyTotal),
SV(bSnakeCam), SV(bSnakeCam),
SV(bSlipMode), SV(bSlipMode),
SV(lHeadStartClock),
SV(lNextStateChange),
SV(nHeadTimeStart),
SV(localclock),
SV(tclocks),
SV(tclocks2),
SV(totalclock),
nullptr); nullptr);
// These need to be saved as diffs.
//int lHeadStartClock; // Timer
//int lNextStateChange; // Timer
//int nHeadTimeStart; // Timer
//int localclock; // timer
//short* pPupData; void SaveTextureState()
//uint8_t* Worktile; {
auto fw = WriteSavegameChunk("texture");
int pupOffset = pPupData? int(pPupData - cPupData) : -1;
// There is really no good way to restore these two tiles, so it's probably best to save them as well, so that they can be reloaded with the saved data.
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, tilesiz[kTile3603].x * tilesiz[kTile3603].y);
}
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)
{
Worktile = TileFiles.tileCreate(kTileRamsesWorkTile, kSpiritX * 2, kSpiritY * 2);
fr.Read(Worktile, WorktileSize);
}
auto pixels = TileFiles.tileMakeWritable(kTile3603);
fr.Read(pixels, tilesiz[kTile3603].x * tilesiz[kTile3603].y);
TileFiles.InvalidateTile(kTileRamsesWorkTile);
TileFiles.InvalidateTile(kTile3603);
}
END_PS_NS END_PS_NS

View file

@ -19,114 +19,115 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#include "save.h" #include "save.h"
#include <stdio.h> #include <stdio.h>
#include <stdarg.h> #include <stdarg.h>
#include "init.h"
//#include <fcntl.h> //#include <fcntl.h>
//#include <sys/stat.h> //#include <sys/stat.h>
//#include <io.h> //#include <io.h>
#include "engine.h" #include "engine.h"
#include "exhumed.h" #include "exhumed.h"
#include "mmulti.h"
#include "savegamehelp.h" #include "savegamehelp.h"
BEGIN_PS_NS BEGIN_PS_NS
static TArray<SavegameHelper*> sghelpers(TArray<SavegameHelper*>::NoInit);
int savegame(int nSlot) int savegame(int nSlot)
{ {
char filename[92]; auto fw = WriteSavegameChunk("engine");
fw->Write(&numsectors, sizeof(numsectors));
fw->Write(sector, sizeof(sectortype) * numsectors);
fw->Write(&numwalls, sizeof(numwalls));
fw->Write(wall, sizeof(walltype) * numwalls);
fw->Write(sprite, sizeof(spritetype) * kMaxSprites);
fw->Write(headspritesect, sizeof(headspritesect));
fw->Write(prevspritesect, sizeof(prevspritesect));
fw->Write(nextspritesect, sizeof(nextspritesect));
fw->Write(headspritestat, sizeof(headspritestat));
fw->Write(prevspritestat, sizeof(prevspritestat));
fw->Write(nextspritestat, sizeof(nextspritestat));
if (nSlot < 0 || nSlot >= 10) { fw->Write(&tailspritefree, sizeof(tailspritefree));
return 0; fw->Write(&myconnectindex, sizeof(myconnectindex));
} fw->Write(&connecthead, sizeof(connecthead));
fw->Write(connectpoint2, sizeof(connectpoint2));
fw->Write(&numframes, sizeof(numframes));
fw->Write(&randomseed, sizeof(randomseed));
fw->Write(&numshades, sizeof(numshades));
sprintf(filename, "save%1d.gam", nSlot); fw->Write(&g_visibility, sizeof(g_visibility));
fw->Write(&parallaxtype, sizeof(parallaxtype));
fw->Write(&parallaxyoffs_override, sizeof(parallaxyoffs_override));
fw->Write(&parallaxyscale_override, sizeof(parallaxyscale_override));
fw->Write(&pskybits_override, sizeof(pskybits_override));
int hFile = open(filename, 609, 128); fw->Write(show2dwall, sizeof(show2dwall));
if (hFile != -1) fw->Write(show2dsprite, sizeof(show2dsprite));
{ fw->Write(show2dsector, sizeof(show2dsector));
#if 0 // TODO
write(hFile, &numsectors, sizeof(numsectors));
write(hFile, sector, sizeof(SECTOR) * numsectors);
write(hFile, &numwalls, sizeof(numwalls));
write(hFile, wall, sizeof(WALL) * numwalls);
write(hFile, sprite, sizeof(SPRITE) * kMaxSprites);
write(hFile, headspritesect, sizeof(headspritesect));
write(hFile, prevspritesect, sizeof(prevspritesect));
write(hFile, nextspritesect, sizeof(nextspritesect));
write(hFile, headspritestat, sizeof(headspritestat));
write(hFile, prevspritestat, sizeof(prevspritestat));
write(hFile, nextspritestat, sizeof(nextspritestat));
write(hFile, startumost, sizeof(startumost));
write(hFile, startdmost, sizeof(startdmost));
write(hFile, &brightness, 2);
write(hFile, &visibility, 4);
write(hFile, &parallaxtype, 1);
write(hFile, &parallaxyoffs, 4);
write(hFile, pskyoff, 512);
write(hFile, &pskybits, 2);
write(hFile, &inita, 2);
write(hFile, &initsect, 2);
write(hFile, &initx, 4);
write(hFile, &inity, 4);
write(hFile, &initz, 4);
write(hFile, &levelnum, 2);
#endif
close(hFile);
}
for (auto sgh : sghelpers) sgh->Save();
return 1; // CHECKME return 1; // CHECKME
} }
int loadgame(int nSlot) int loadgame(int nSlot)
{ {
char filename[92]; auto fr = ReadSavegameChunk("engine");
if (fr.isOpen())
if (nSlot < 0 || nSlot >= 10) {
return 0;
}
sprintf(filename, "save%1d.gam", nSlot);
int hFile = open(filename, 514, 256);
if (hFile != -1)
{ {
#if 0 // TODO fr.Read(&numsectors, sizeof(numsectors));
read(hFile, &numsectors, sizeof(numsectors)); fr.Read(sector, sizeof(sectortype) * numsectors);
read(hFile, sector, sizeof(SECTOR) * numsectors); fr.Read(&numwalls, sizeof(numwalls));
read(hFile, &numwalls, sizeof(numwalls)); fr.Read(wall, sizeof(walltype) * numwalls);
read(hFile, wall, sizeof(WALL) * numwalls); fr.Read(sprite, sizeof(spritetype) * kMaxSprites);
read(hFile, sprite, sizeof(SPRITE) * kMaxSprites); fr.Read(headspritesect, sizeof(headspritesect));
read(hFile, headspritesect, sizeof(headspritesect)); fr.Read(prevspritesect, sizeof(prevspritesect));
read(hFile, prevspritesect, sizeof(prevspritesect)); fr.Read(nextspritesect, sizeof(nextspritesect));
read(hFile, nextspritesect, sizeof(nextspritesect)); fr.Read(headspritestat, sizeof(headspritestat));
read(hFile, headspritestat, sizeof(headspritestat)); fr.Read(prevspritestat, sizeof(prevspritestat));
read(hFile, prevspritestat, sizeof(prevspritestat)); fr.Read(nextspritestat, sizeof(nextspritestat));
read(hFile, nextspritestat, sizeof(nextspritestat));
read(hFile, startumost, sizeof(startumost)); fr.Read(&tailspritefree, sizeof(tailspritefree));
read(hFile, startdmost, sizeof(startdmost)); fr.Read(&myconnectindex, sizeof(myconnectindex));
read(hFile, &brightness, 2); fr.Read(&connecthead, sizeof(connecthead));
read(hFile, &visibility, 4); fr.Read(connectpoint2, sizeof(connectpoint2));
read(hFile, &parallaxtype, 1); fr.Read(&numframes, sizeof(numframes));
read(hFile, &parallaxyoffs, 4); fr.Read(&randomseed, sizeof(randomseed));
read(hFile, pskyoff, 512); fr.Read(&numshades, sizeof(numshades));
read(hFile, &pskybits, 2);
read(hFile, &inita, 2); fr.Read(&g_visibility, sizeof(g_visibility));
read(hFile, &initsect, 2); fr.Read(&parallaxtype, sizeof(parallaxtype));
read(hFile, &initx, 4); fr.Read(&parallaxyoffs_override, sizeof(parallaxyoffs_override));
read(hFile, &inity, 4); fr.Read(&parallaxyscale_override, sizeof(parallaxyscale_override));
read(hFile, &initz, 4); fr.Read(&pskybits_override, sizeof(pskybits_override));
read(hFile, &levelnum, 2);
fr.Read(show2dwall, sizeof(show2dwall));
fr.Read(show2dsprite, sizeof(show2dsprite));
fr.Read(show2dsector, sizeof(show2dsector));
lPlayerXVel = 0;
lPlayerYVel = 0;
nPlayerDAng = 0;
#endif
close(hFile);
} }
for (auto sgh : sghelpers) sgh->Load();
// reset the sky in case it hasn't been done yet.
psky_t* pSky = tileSetupSky(0);
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;
ototalclock = totalclock;
return 1; // CHECKME return 1; // CHECKME
} }
static TArray<SavegameHelper*> sghelpers(TArray<SavegameHelper*>::NoInit);
SavegameHelper::SavegameHelper(const char* name, ...) SavegameHelper::SavegameHelper(const char* name, ...)
{ {
Name = name; Name = name;
@ -150,20 +151,6 @@ void SavegameHelper::Load()
auto read = fr.Read(entry.first, entry.second); auto read = fr.Read(entry.first, entry.second);
if (read != entry.second) I_Error("Save game read error in %s", Name.GetChars()); if (read != entry.second) I_Error("Save game read error in %s", Name.GetChars());
} }
// reset the sky in case it hasn't been done yet.
psky_t* pSky = tileSetupSky(0);
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;
} }
void SavegameHelper::Save() void SavegameHelper::Save()
{ {

View file

@ -675,6 +675,10 @@ static SavegameHelper sgh("view",
SA(dVertPan), SA(dVertPan),
SA(nVertPan), SA(nVertPan),
SA(nQuake), SA(nQuake),
SV(g_interpolationCnt),
SA(oldipos),
SA(curipos),
SA(bakipos),
nullptr); nullptr);
END_PS_NS END_PS_NS