- removed unused compression records from savegame header

This commit is contained in:
Christoph Oelckers 2019-12-11 01:10:59 +01:00
parent 69fd6cf69d
commit cb051b44ea
7 changed files with 25 additions and 91 deletions

View File

@ -148,7 +148,7 @@ void G_WriteSaveHeader(const char *name)
sjson_put_string(ctx, root, "Map Label", currentLevel->labelName);
const char *fn = currentLevel->fileName;
if (*fn == '/') fn++;
if (!strncmp(fn, "file://", 7) != 0) // this only has meaning for non-usermaps
if (strncmp(fn, "file://", 7) != 0) // this only has meaning for non-usermaps
{
auto fileno = fileSystem.FindFile(fn);
auto mapfile = fileSystem.GetFileContainer(fileno);
@ -190,7 +190,7 @@ static bool CheckSingleFile (const char *name, bool &printRequires, bool printwa
{
return true;
}
if (!strncmp(name, "file://", 7) == 0)
if (strncmp(name, "file://", 7) == 0)
{
return FileExists(name + 7); // User maps must be present to be validated.
}
@ -274,7 +274,7 @@ int G_ValidateSavegame(FileReader &fr, FString *savetitle, bool formenu)
MapRecord *curLevel = nullptr;
if (!strncmp(filename, "file://", 7) != 0)
if (strncmp(filename, "file://", 7) != 0)
{
for (auto& mr : mapList)
{

View File

@ -109,7 +109,7 @@ static int32_t G_OpenDemoRead(int32_t g_whichDemo) // 0 = mine
demo_hasdiffs = saveh.recdiffsp;
g_demo_totalCnt = saveh.reccnt;
demo_hasseeds = saveh.synccompress & 2;
demo_hasseeds = 0;
i = g_demo_totalCnt/REALGAMETICSPERSEC;
OSD_Printf("demo %d duration: %d min %d sec\n", g_whichDemo, i/60, i%60);

View File

@ -184,10 +184,6 @@ corrupt:
static void sv_postudload();
// hack
static int different_user_map;
// XXX: keyboard input 'blocked' after load fail? (at least ESC?)
int32_t G_LoadPlayer(FSaveGameNode *sv)
{
@ -480,9 +476,7 @@ int32_t G_LoadPlayer(FSaveGameNode *sv)
ud.m_player_skill = h.skill;
// NOTE: Bmemcpy needed for SAVEGAME_MUSIC.
EDUKE32_STATIC_ASSERT(sizeof(boardfilename) == sizeof(h.boardfn));
different_user_map = Bstrcmp(boardfilename, h.boardfn);
Bmemcpy(boardfilename, h.boardfn, sizeof(boardfilename));
strcpy(boardfilename, currentLevel->fileName);
int const mapIdx = h.volnum*MAXLEVELS + h.levnum;
@ -655,11 +649,6 @@ typedef struct dataspec_gv_
intptr_t cnt;
} dataspec_gv_t;
#define SV_DEFAULTCOMPRTHRES 8
static uint8_t savegame_diffcompress; // 0:none, 1:Ken's LZW in cache1d.c
static uint8_t savegame_comprthres;
#define DS_DYNAMIC 1 // dereference .ptr one more time
#define DS_STRING 2
#define DS_CMP 4
@ -807,8 +796,8 @@ static int32_t readspecdata(const dataspec_t *spec, FileReader *fil, uint8_t **d
if (ksiz != siz)
{
OSD_Printf("rsd: spec=%s, idx=%d, mem=%p\n", (char *)sptr->ptr, (int32_t)(spec - sptr), mem);
OSD_Printf(" (%s): read %d, expected %d!\n",
((spec->flags & DS_CNTMASK) == 0 && spec->size * cnt <= savegame_comprthres) ? "uncompressed" : "compressed", ksiz, siz);
OSD_Printf(" : read %d, expected %d!\n",
ksiz, siz);
if (ksiz == -1)
OSD_Printf(" read: %s\n", strerror(errno));
@ -1379,14 +1368,10 @@ static void SV_AllocSnap(int32_t allocinit)
}
// make snapshot only if spot < 0 (demo)
int32_t sv_saveandmakesnapshot(FileWriter &fil, char const *name, int8_t spot, int8_t recdiffsp, int8_t diffcompress, int8_t synccompress)
int32_t sv_saveandmakesnapshot(FileWriter &fil, char const *name, int8_t spot, int8_t recdiffsp)
{
savehead_t h;
// set a few savegame system globals
savegame_comprthres = SV_DEFAULTCOMPRTHRES;
savegame_diffcompress = diffcompress;
// calculate total snapshot size
#if !defined LUNATIC
sv_makevarspec();
@ -1405,10 +1390,6 @@ int32_t sv_saveandmakesnapshot(FileWriter &fil, char const *name, int8_t spot, i
h.bytever = BYTEVERSION;
h.userbytever = ud.userbytever;
h.scriptcrc = g_scriptcrc;
h.comprthres = savegame_comprthres;
h.recdiffsp = recdiffsp;
h.diffcompress = savegame_diffcompress;
h.synccompress = synccompress;
h.reccnt = 0;
h.snapsiz = svsnapsiz;
@ -1424,7 +1405,6 @@ int32_t sv_saveandmakesnapshot(FileWriter &fil, char const *name, int8_t spot, i
if (spot >= 0)
{
// savegame
Bstrncpyz(h.savename, name, sizeof(h.savename));
auto fw = WriteSavegameChunk("header.dat");
fw->Write(&h, sizeof(savehead_t));
@ -1432,15 +1412,10 @@ int32_t sv_saveandmakesnapshot(FileWriter &fil, char const *name, int8_t spot, i
}
else
{
// demo
// demo (currently broken, needs a new format.)
const time_t t = time(NULL);
struct tm * st;
Bstrncpyz(h.savename, "EDuke32 demo", sizeof(h.savename));
if (t>=0 && (st = localtime(&t)))
Bsnprintf(h.savename, sizeof(h.savename), "Demo %04d%02d%02d %s",
st->tm_year+1900, st->tm_mon+1, st->tm_mday, GetGitDescription());
struct tm * st = localtime(&t);
FStringf demoname("Demo %04d%02d%02d %s", st->tm_year+1900, st->tm_mon+1, st->tm_mday, GetGitDescription());
fil.Write(&h, sizeof(savehead_t));
}
@ -1566,8 +1541,6 @@ int32_t sv_loadsnapshot(FileReader &fil, int32_t spot, savehead_t *h)
OSD_Printf("sv_loadsnapshot: snapshot size: %d bytes.\n", h->snapsiz);
#endif
savegame_comprthres = h->comprthres;
if (spot >= 0)
{
// savegame
@ -1580,9 +1553,6 @@ int32_t sv_loadsnapshot(FileReader &fil, int32_t spot, savehead_t *h)
}
else
{
// demo
savegame_diffcompress = h->diffcompress;
svsnapsiz = h->snapsiz;
SV_AllocSnap(1);

View File

@ -46,16 +46,13 @@ typedef struct
uint32_t userbytever;
uint32_t scriptcrc;
uint8_t comprthres;
uint8_t recdiffsp, diffcompress, synccompress;
uint8_t recdiffsp;
// 4 bytes
int32_t reccnt, snapsiz;
// 8 bytes
char savename[MAXSAVEGAMENAMESTRUCT];
uint8_t numplayers, volnum, levnum, skill;
char boardfn[BMAX_PATH];
// 286 bytes
uint8_t getPtrSize() const { return ptrsize; }
@ -71,7 +68,7 @@ int32_t sv_readdiff(FileReader& fil);
uint32_t sv_writediff(FileWriter *fil);
int32_t sv_loadheader(FileReader &fil, int32_t spot, savehead_t *h);
int32_t sv_loadsnapshot(FileReader &fil, int32_t spot, savehead_t *h);
int32_t sv_saveandmakesnapshot(FileWriter &fil, char const *name, int8_t spot, int8_t recdiffsp, int8_t diffcompress, int8_t synccompress);
int32_t sv_saveandmakesnapshot(FileWriter &fil, char const *name, int8_t spot, int8_t recdiffsp);
void sv_freemem();
int32_t G_LoadSaveHeaderNew(char const *fn, savehead_t *saveh);
void ReadSaveGameHeaders(void);

View File

@ -109,7 +109,7 @@ static int32_t G_OpenDemoRead(int32_t g_whichDemo) // 0 = mine
demo_hasdiffs = saveh.recdiffsp;
g_demo_totalCnt = saveh.reccnt;
demo_hasseeds = saveh.synccompress&2;
demo_hasseeds = 0;
i = g_demo_totalCnt/REALGAMETICSPERSEC;
OSD_Printf("demo %d duration: %d min %d sec\n", g_whichDemo, i/60, i%60);

View File

@ -184,8 +184,6 @@ corrupt:
static void sv_postudload();
// hack
static int different_user_map;
// XXX: keyboard input 'blocked' after load fail? (at least ESC?)
int32_t G_LoadPlayer(const char *path)
@ -240,16 +238,10 @@ int32_t G_LoadPlayer(const char *path)
ud.m_player_skill = h.skill;
// NOTE: Bmemcpy needed for SAVEGAME_MUSIC.
EDUKE32_STATIC_ASSERT(sizeof(boardfilename) == sizeof(h.boardfn));
different_user_map = Bstrcmp(boardfilename, h.boardfn);
Bmemcpy(boardfilename, h.boardfn, sizeof(boardfilename));
strcpy(boardfilename, currentLevel->fileName);
int const mapIdx = h.volnum*MAXLEVELS + h.levnum;
char workbuffer[BMAX_PATH];
if (boardfilename[0])
Bstrcpy(workbuffer, boardfilename);
else
Bstrcpy(workbuffer, mapList[mapIdx].fileName);
Bstrcpy(workbuffer, currentLevel->fileName);
if (workbuffer[0])
{
@ -393,11 +385,6 @@ typedef struct dataspec_
intptr_t cnt;
} dataspec_t;
#define SV_DEFAULTCOMPRTHRES 8
static uint8_t savegame_diffcompress; // 0:none, 1:Ken's LZW in cache1d.c
static uint8_t savegame_comprthres;
#define DS_DYNAMIC 1 // dereference .ptr one more time
#define DS_STRING 2
#define DS_CMP 4
@ -545,8 +532,8 @@ static int32_t readspecdata(const dataspec_t *spec, FileReader *fil, uint8_t **d
if (ksiz != siz)
{
OSD_Printf("rsd: spec=%s, idx=%d, mem=%p\n", (char *)sptr->ptr, (int32_t)(spec - sptr), mem);
OSD_Printf(" (%s): read %d, expected %d!\n",
((spec->flags & DS_CNTMASK) == 0 && spec->size * cnt <= savegame_comprthres) ? "uncompressed" : "compressed", ksiz, siz);
OSD_Printf(" : read %d, expected %d!\n",
ksiz, siz);
if (ksiz == -1)
OSD_Printf(" read: %s\n", strerror(errno));
@ -1086,14 +1073,10 @@ static void SV_AllocSnap(int32_t allocinit)
}
// make snapshot only if spot < 0 (demo)
int32_t sv_saveandmakesnapshot(FileWriter &fil, char const *name, int8_t spot, int8_t recdiffsp, int8_t diffcompress, int8_t synccompress, bool isAutoSave)
int32_t sv_saveandmakesnapshot(FileWriter &fil, char const *name, int8_t spot, int8_t recdiffsp, bool isAutoSave)
{
savehead_t h;
// set a few savegame system globals
savegame_comprthres = SV_DEFAULTCOMPRTHRES;
savegame_diffcompress = diffcompress;
// calculate total snapshot size
svsnapsiz = calcsz(svgm_udnetw) + calcsz(svgm_secwsp) + calcsz(svgm_script) + calcsz(svgm_anmisc);
@ -1110,10 +1093,6 @@ int32_t sv_saveandmakesnapshot(FileWriter &fil, char const *name, int8_t spot, i
h.bytever = BYTEVERSION;
h.userbytever = ud.userbytever;
h.scriptcrc = g_scriptcrc;
h.comprthres = savegame_comprthres;
h.recdiffsp = recdiffsp;
h.diffcompress = savegame_diffcompress;
h.synccompress = synccompress;
h.reccnt = 0;
h.snapsiz = svsnapsiz;
@ -1129,7 +1108,6 @@ int32_t sv_saveandmakesnapshot(FileWriter &fil, char const *name, int8_t spot, i
if (spot >= 0)
{
// savegame
Bstrncpyz(h.savename, name, sizeof(h.savename));
auto fw = WriteSavegameChunk("header.dat");
fw->Write(&h, sizeof(savehead_t));
G_WriteSaveHeader(name);
@ -1137,15 +1115,12 @@ int32_t sv_saveandmakesnapshot(FileWriter &fil, char const *name, int8_t spot, i
else
{
// demo
// demo (currently broken, needs a new format.)
const time_t t = time(NULL);
struct tm * st;
Bstrncpyz(h.savename, "EDuke32 demo", sizeof(h.savename));
if (t>=0 && (st = localtime(&t)))
Bsnprintf(h.savename, sizeof(h.savename), "Demo %04d%02d%02d %s",
st->tm_year+1900, st->tm_mon+1, st->tm_mday, GetGitDescription());
struct tm * st = localtime(&t);
FStringf demoname("Demo %04d%02d%02d %s", st->tm_year+1900, st->tm_mon+1, st->tm_mday, GetGitDescription());
fil.Write(&h, sizeof(savehead_t));
}
@ -1271,8 +1246,6 @@ int32_t sv_loadsnapshot(FileReader &fil, int32_t spot, savehead_t *h)
OSD_Printf("sv_loadsnapshot: snapshot size: %d bytes.\n", h->snapsiz);
#endif
savegame_comprthres = h->comprthres;
if (spot >= 0)
{
// savegame
@ -1285,9 +1258,6 @@ int32_t sv_loadsnapshot(FileReader &fil, int32_t spot, savehead_t *h)
}
else
{
// demo
savegame_diffcompress = h->diffcompress;
svsnapsiz = h->snapsiz;
SV_AllocSnap(1);

View File

@ -41,16 +41,13 @@ typedef struct
uint32_t userbytever;
uint32_t scriptcrc;
uint8_t comprthres;
uint8_t recdiffsp, diffcompress, synccompress;
uint8_t recdiffsp;
// 4 bytes
int32_t reccnt, snapsiz;
// 8 bytes
char savename[MAXSAVEGAMENAMESTRUCT];
uint8_t numplayers, volnum, levnum, skill;
char boardfn[BMAX_PATH];
// 286 bytes
uint8_t getPtrSize() const { return ptrsize; }
@ -62,7 +59,7 @@ int32_t sv_readdiff(FileReader& fil);
uint32_t sv_writediff(FileWriter *fil);
int32_t sv_loadheader(FileReader &fil, int32_t spot, savehead_t *h);
int32_t sv_loadsnapshot(FileReader &fil, int32_t spot, savehead_t *h);
int32_t sv_saveandmakesnapshot(FileWriter &fil, char const *name, int8_t spot, int8_t recdiffsp, int8_t diffcompress, int8_t synccompress, bool isAutoSave = false);
int32_t sv_saveandmakesnapshot(FileWriter &fil, char const *name, int8_t spot, int8_t recdiffsp, bool isAutoSave = false);
void sv_freemem();
int32_t G_LoadSaveHeaderNew(char const *fn, savehead_t *saveh);
void ReadSaveGameHeaders(void);