mirror of
https://github.com/DrBeef/Raze.git
synced 2024-11-15 08:52:00 +00:00
- cleaned out the remains of the savegame compression hacks
This broke the savegame reader which still assumed it was working on compressed data. Everything will now take the uncompressed path. In-stream optional compression is not a good idea anyway, this can and should be done better. Also: Why is the savegame format architecture dependent???
This commit is contained in:
parent
f252eaffbc
commit
e87642e197
8 changed files with 63 additions and 163 deletions
|
@ -20,21 +20,6 @@ using buildvfs_kfd = int32_t;
|
|||
|
||||
extern int32_t pathsearchmode; // 0 = gamefs mode (default), 1 = localfs mode (editor's mode)
|
||||
|
||||
|
||||
// compression disabled pending a better process for saving. Per-block compression as done here was not that great.
|
||||
int32_t kdfread_LZ4(void* buffer, int dasizeof, int count, buildvfs_kfd fil) = delete;
|
||||
|
||||
inline int32_t kdfread_LZ4(void* buffer, int dasizeof, int count, FileReader& fil)
|
||||
{
|
||||
return fil.Read(buffer, dasizeof * count);
|
||||
}
|
||||
|
||||
inline void dfwrite_LZ4(const void* buffer, int dasizeof, int count, buildvfs_FILE fil)
|
||||
{
|
||||
fwrite(buffer, dasizeof, count, fil);
|
||||
}
|
||||
|
||||
|
||||
#include "filesystem/filesystem.h"
|
||||
|
||||
// Wrappers for the handle based API to get rid of the direct calls without any actual changes to the implementation.
|
||||
|
|
|
@ -113,7 +113,6 @@ bool G_CheckAutorun(bool button)
|
|||
// Demos
|
||||
|
||||
CVARD_NAMED(Bool, demorec_diffcompress, demorec_diffcompress_cvar, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG, "Compression for diffs")
|
||||
CVARD_NAMED(Bool, demorec_synccompress, demorec_synccompress_cvar, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG, "Compression for input")
|
||||
CVARD_NAMED(Bool, demorec_seeds, demorec_seeds_cvar, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG, "enable/disable recording of random seed for later sync checking")
|
||||
CVARD_NAMED(Bool, demorec_diffs, demorec_diffs_cvar, true, CVAR_ARCHIVE|CVAR_GLOBALCONFIG, "enable/disable diff recording in demos")
|
||||
CVARD_NAMED(Bool, demorec_force, demorec_force_cvar, false, CVAR_ARCHIVE|CVAR_GLOBALCONFIG, "enable/disable forced demo recording")
|
||||
|
|
|
@ -26,7 +26,6 @@ EXTERN_CVAR(Int, cl_weaponswitch)
|
|||
EXTERN_CVAR(Int, cl_crosshairscale)
|
||||
|
||||
EXTERN_CVAR(Bool, demorec_diffcompress_cvar)
|
||||
EXTERN_CVAR(Bool, demorec_synccompress_cvar)
|
||||
EXTERN_CVAR(Bool, demorec_seeds_cvar)
|
||||
EXTERN_CVAR(Bool, demoplay_diffs)
|
||||
EXTERN_CVAR(Bool, demoplay_showsync)
|
||||
|
|
|
@ -52,7 +52,7 @@ static int32_t g_demo_soundToggle;
|
|||
static int32_t demo_hasdiffs, demorec_diffs=1, demorec_difftics = 2*REALGAMETICSPERSEC;
|
||||
int32_t demoplay_diffs=1;
|
||||
|
||||
static int32_t demo_synccompress=1, demorec_seeds=1, demo_hasseeds;
|
||||
static int32_t demorec_seeds=1, demo_hasseeds;
|
||||
|
||||
static void Demo_RestoreModes(int32_t menu)
|
||||
{
|
||||
|
@ -112,10 +112,7 @@ static int32_t G_OpenDemoRead(int32_t g_whichDemo) // 0 = mine
|
|||
|
||||
demo_hasdiffs = saveh.recdiffsp;
|
||||
g_demo_totalCnt = saveh.reccnt;
|
||||
demo_synccompress = saveh.synccompress;
|
||||
|
||||
demo_hasseeds = demo_synccompress&2;
|
||||
demo_synccompress &= 1;
|
||||
demo_hasseeds = saveh.synccompress & 2;
|
||||
|
||||
i = g_demo_totalCnt/REALGAMETICSPERSEC;
|
||||
OSD_Printf("demo %d duration: %d min %d sec\n", g_whichDemo, i/60, i%60);
|
||||
|
@ -179,7 +176,7 @@ void G_OpenDemoWrite(void)
|
|||
return;
|
||||
|
||||
i=sv_saveandmakesnapshot(g_demo_filePtr, nullptr, -1, demorec_diffs_cvar, demorec_diffcompress_cvar,
|
||||
demorec_synccompress_cvar|(demorec_seeds_cvar<<1));
|
||||
(demorec_seeds_cvar<<1));
|
||||
if (i)
|
||||
{
|
||||
MAYBE_FCLOSE_AND_NULL(g_demo_filePtr);
|
||||
|
@ -192,7 +189,6 @@ error_wopen_demo:
|
|||
|
||||
demorec_seeds = demorec_seeds_cvar;
|
||||
demorec_diffs = demorec_diffs_cvar;
|
||||
demo_synccompress = demorec_synccompress_cvar;
|
||||
demorec_difftics = demorec_difftics_cvar;
|
||||
|
||||
Bsprintf(apStrings[QUOTE_RESERVED4], "DEMO %d RECORDING STARTED", demonum-1);
|
||||
|
@ -242,10 +238,7 @@ static void Demo_WriteSync()
|
|||
if (demorec_seeds)
|
||||
buildvfs_fwrite(g_demo_seedbuf, 1, ud.reccnt, g_demo_filePtr);
|
||||
|
||||
if (demo_synccompress)
|
||||
dfwrite_LZ4(recsync, sizeof(input_t), ud.reccnt, g_demo_filePtr);
|
||||
else //if (demo_synccompress==0)
|
||||
buildvfs_fwrite(recsync, sizeof(input_t), ud.reccnt, g_demo_filePtr);
|
||||
buildvfs_fwrite(recsync, sizeof(input_t), ud.reccnt, g_demo_filePtr);
|
||||
|
||||
ud.reccnt = 0;
|
||||
}
|
||||
|
@ -334,18 +327,11 @@ static int32_t Demo_ReadSync(int32_t errcode)
|
|||
return errcode;
|
||||
}
|
||||
|
||||
if (demo_synccompress)
|
||||
{
|
||||
if (kdfread_LZ4(recsync, sizeof(input_t), i, g_demo_recFilePtr) != i)
|
||||
return errcode+1;
|
||||
}
|
||||
else
|
||||
{
|
||||
int32_t bytes = sizeof(input_t)*i;
|
||||
|
||||
if (g_demo_recFilePtr.Read(recsync, bytes) != bytes)
|
||||
return errcode+2;
|
||||
}
|
||||
int32_t bytes = sizeof(input_t)*i;
|
||||
|
||||
if (g_demo_recFilePtr.Read(recsync, bytes) != bytes)
|
||||
return errcode+2;
|
||||
|
||||
ud.reccnt = i;
|
||||
return 0;
|
||||
|
@ -430,8 +416,7 @@ static void Demo_FinishProfile(void)
|
|||
dn, gms, (gms*1000.0)/nt);
|
||||
}
|
||||
|
||||
if (nf > 0)
|
||||
{
|
||||
if (nf > 0) {
|
||||
OSD_Printf("== demo %d: %d frames (%d frames/gametic)\n", dn, nf, g_demo_profile-1);
|
||||
OSD_Printf("== demo %d drawrooms times: %.03f s (%.03f ms/frame)\n",
|
||||
dn, dms1/1000.0, dms1/nf);
|
||||
|
|
|
@ -123,46 +123,46 @@ int Gv_ReadSave(FileReader &kFile)
|
|||
|
||||
Gv_Free(); // nuke 'em from orbit, it's the only way to be sure...
|
||||
|
||||
if (kdfread_LZ4(&g_gameVarCount,sizeof(g_gameVarCount),1,kFile) != 1) goto corrupt;
|
||||
if (kFile.Read(&g_gameVarCount,sizeof(g_gameVarCount)) != sizeof(g_gameVarCount)) goto corrupt;
|
||||
for (bssize_t i=0; i<g_gameVarCount; i++)
|
||||
{
|
||||
char *const olabel = aGameVars[i].szLabel;
|
||||
|
||||
if (kdfread_LZ4(&aGameVars[i], sizeof(gamevar_t), 1, kFile) != 1)
|
||||
if (kFile.Read(&aGameVars[i], sizeof(gamevar_t)) != sizeof(gamevar_t))
|
||||
goto corrupt;
|
||||
|
||||
aGameVars[i].szLabel = (char *)Xrealloc(olabel, MAXVARLABEL * sizeof(uint8_t));
|
||||
|
||||
if (kdfread_LZ4(aGameVars[i].szLabel, MAXVARLABEL, 1, kFile) != 1)
|
||||
if (kFile.Read(aGameVars[i].szLabel, MAXVARLABEL) != MAXVARLABEL)
|
||||
goto corrupt;
|
||||
hash_add(&h_gamevars, aGameVars[i].szLabel,i, 1);
|
||||
|
||||
if (aGameVars[i].flags & GAMEVAR_PERPLAYER)
|
||||
{
|
||||
aGameVars[i].pValues = (intptr_t*)Xaligned_alloc(PLAYER_VAR_ALIGNMENT, MAXPLAYERS * sizeof(intptr_t));
|
||||
if (kdfread_LZ4(aGameVars[i].pValues,sizeof(intptr_t) * MAXPLAYERS, 1, kFile) != 1) goto corrupt;
|
||||
if (kFile.Read(aGameVars[i].pValues,sizeof(intptr_t) * MAXPLAYERS) != sizeof(intptr_t) * MAXPLAYERS)) goto corrupt;
|
||||
}
|
||||
else if (aGameVars[i].flags & GAMEVAR_PERACTOR)
|
||||
{
|
||||
aGameVars[i].pValues = (intptr_t*)Xaligned_alloc(ACTOR_VAR_ALIGNMENT, MAXSPRITES * sizeof(intptr_t));
|
||||
if (kdfread_LZ4(aGameVars[i].pValues,sizeof(intptr_t) * MAXSPRITES, 1, kFile) != 1) goto corrupt;
|
||||
if (kFile.Read(aGameVars[i].pValues,sizeof(intptr_t) * MAXSPRITES) != sizeof(intptr_t) * MAXSPRITES) goto corrupt;
|
||||
}
|
||||
}
|
||||
|
||||
Gv_InitWeaponPointers();
|
||||
|
||||
if (kdfread_LZ4(&g_gameArrayCount,sizeof(g_gameArrayCount),1,kFile) != 1) goto corrupt;
|
||||
if (kFile.Read(&g_gameArrayCount,sizeof(g_gameArrayCount)) != sizeof(g_gameArrayCount)) goto corrupt;
|
||||
for (bssize_t i=0; i<g_gameArrayCount; i++)
|
||||
{
|
||||
char *const olabel = aGameArrays[i].szLabel;
|
||||
|
||||
// read for .size and .dwFlags (the rest are pointers):
|
||||
if (kdfread_LZ4(&aGameArrays[i], sizeof(gamearray_t), 1, kFile) != 1)
|
||||
if (kFile.Read(&aGameArrays[i], sizeof(gamearray_t)) != sizeof(gamearray_t))
|
||||
goto corrupt;
|
||||
|
||||
aGameArrays[i].szLabel = (char *) Xrealloc(olabel, MAXARRAYLABEL * sizeof(uint8_t));
|
||||
|
||||
if (kdfread_LZ4(aGameArrays[i].szLabel,sizeof(uint8_t) * MAXARRAYLABEL, 1, kFile) != 1)
|
||||
if (kFile.Read(aGameArrays[i].szLabel,sizeof(uint8_t) * MAXARRAYLABEL) != sizeof(uint8_t) * MAXARRAYLABEL)
|
||||
goto corrupt;
|
||||
|
||||
hash_add(&h_arrays, aGameArrays[i].szLabel, i, 1);
|
||||
|
@ -171,8 +171,9 @@ int Gv_ReadSave(FileReader &kFile)
|
|||
|
||||
if (asize != 0 && !(aGameArrays[i].flags & GAMEARRAY_SYSTEM))
|
||||
{
|
||||
aGameArrays[i].pValues = (intptr_t *)Xaligned_alloc(ARRAY_ALIGNMENT, Gv_GetArrayAllocSize(i));
|
||||
if (kdfread_LZ4(aGameArrays[i].pValues, Gv_GetArrayAllocSize(i), 1, kFile) < 1) goto corrupt;
|
||||
auto az = Gv_GetArrayAllocSize(i);
|
||||
aGameArrays[i].pValues = (intptr_t *)Xaligned_alloc(ARRAY_ALIGNMENT, az);
|
||||
if (kFile.Read(aGameArrays[i].pValues, az) < az) goto corrupt;
|
||||
}
|
||||
else
|
||||
aGameArrays[i].pValues = NULL;
|
||||
|
@ -183,7 +184,7 @@ int Gv_ReadSave(FileReader &kFile)
|
|||
uint8_t savedstate[MAXVOLUMES*MAXLEVELS];
|
||||
Bmemset(savedstate, 0, sizeof(savedstate));
|
||||
|
||||
if (kdfread_LZ4(savedstate, sizeof(savedstate), 1, kFile) != 1) goto corrupt;
|
||||
if (kFile.Read(savedstate, sizeof(savedstate)) != sizeof(savedstate)) goto corrupt;
|
||||
|
||||
for (bssize_t i = 0; i < (MAXVOLUMES * MAXLEVELS); i++)
|
||||
{
|
||||
|
@ -193,7 +194,7 @@ int Gv_ReadSave(FileReader &kFile)
|
|||
continue;
|
||||
|
||||
g_mapInfo[i].savedstate = (mapstate_t *)Xaligned_alloc(ACTOR_VAR_ALIGNMENT, sizeof(mapstate_t));
|
||||
if (kdfread_LZ4(g_mapInfo[i].savedstate, sizeof(mapstate_t), 1, kFile) != 1) return -8;
|
||||
if (kFile.Read(g_mapInfo[i].savedstate, sizeof(mapstate_t)) != sizeof(mapstate_t)) return -8;
|
||||
|
||||
mapstate_t &sv = *g_mapInfo[i].savedstate;
|
||||
|
||||
|
@ -203,16 +204,16 @@ int Gv_ReadSave(FileReader &kFile)
|
|||
if (aGameVars[j].flags & GAMEVAR_PERPLAYER)
|
||||
{
|
||||
sv.vars[j] = (intptr_t *) Xaligned_alloc(PLAYER_VAR_ALIGNMENT, MAXPLAYERS * sizeof(intptr_t));
|
||||
if (kdfread_LZ4(sv.vars[j], sizeof(intptr_t) * MAXPLAYERS, 1, kFile) != 1) return -9;
|
||||
if (kFile.Read(sv.vars[j], sizeof(intptr_t) * MAXPLAYERS) != sizeof(intptr_t) * MAXPLAYERS) return -9;
|
||||
}
|
||||
else if (aGameVars[j].flags & GAMEVAR_PERACTOR)
|
||||
{
|
||||
sv.vars[j] = (intptr_t *) Xaligned_alloc(ACTOR_VAR_ALIGNMENT, MAXSPRITES * sizeof(intptr_t));
|
||||
if (kdfread_LZ4(sv.vars[j], sizeof(intptr_t) * MAXSPRITES, 1, kFile) != 1) return -10;
|
||||
if (kFile.Read(sv.vars[j], sizeof(intptr_t) * MAXSPRITES) != sizeof(intptr_t) * MAXSPRITES) return -10;
|
||||
}
|
||||
}
|
||||
|
||||
if (kdfread_LZ4(sv.arraysiz, sizeof(sv.arraysiz), 1, kFile) < 1)
|
||||
if (kFile.Read(sv.arraysiz, sizeof(sv.arraysiz)) != sizeof(sv.arraysiz))
|
||||
return -11;
|
||||
|
||||
for (bssize_t j = 0; j < g_gameArrayCount; j++)
|
||||
|
@ -220,7 +221,7 @@ int Gv_ReadSave(FileReader &kFile)
|
|||
{
|
||||
size_t const siz = Gv_GetArrayAllocSizeForCount(j, sv.arraysiz[j]);
|
||||
sv.arrays[j] = (intptr_t *) Xaligned_alloc(ARRAY_ALIGNMENT, siz);
|
||||
if (kdfread_LZ4(sv.arrays[j], siz, 1, kFile) < 1) return -12;
|
||||
if (kFile.Read(sv.arrays[j], siz) != siz) return -12;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -238,29 +239,29 @@ void Gv_WriteSave(buildvfs_FILE fil)
|
|||
// AddLog("Saving Game Vars to File");
|
||||
buildvfs_fwrite("BEG: EDuke32", 12, 1, fil);
|
||||
|
||||
dfwrite_LZ4(&g_gameVarCount,sizeof(g_gameVarCount),1,fil);
|
||||
buildvfs_fwrite(&g_gameVarCount,sizeof(g_gameVarCount),1,fil);
|
||||
|
||||
for (bssize_t i = 0; i < g_gameVarCount; i++)
|
||||
{
|
||||
dfwrite_LZ4(&(aGameVars[i]), sizeof(gamevar_t), 1, fil);
|
||||
dfwrite_LZ4(aGameVars[i].szLabel, sizeof(uint8_t) * MAXVARLABEL, 1, fil);
|
||||
buildvfs_fwrite(&(aGameVars[i]), sizeof(gamevar_t), 1, fil);
|
||||
buildvfs_fwrite(aGameVars[i].szLabel, sizeof(uint8_t) * MAXVARLABEL, 1, fil);
|
||||
|
||||
if (aGameVars[i].flags & GAMEVAR_PERPLAYER)
|
||||
dfwrite_LZ4(aGameVars[i].pValues, sizeof(intptr_t) * MAXPLAYERS, 1, fil);
|
||||
buildvfs_fwrite(aGameVars[i].pValues, sizeof(intptr_t) * MAXPLAYERS, 1, fil);
|
||||
else if (aGameVars[i].flags & GAMEVAR_PERACTOR)
|
||||
dfwrite_LZ4(aGameVars[i].pValues, sizeof(intptr_t) * MAXSPRITES, 1, fil);
|
||||
buildvfs_fwrite(aGameVars[i].pValues, sizeof(intptr_t) * MAXSPRITES, 1, fil);
|
||||
}
|
||||
|
||||
dfwrite_LZ4(&g_gameArrayCount,sizeof(g_gameArrayCount),1,fil);
|
||||
buildvfs_fwrite(&g_gameArrayCount,sizeof(g_gameArrayCount),1,fil);
|
||||
|
||||
for (bssize_t i = 0; i < g_gameArrayCount; i++)
|
||||
{
|
||||
// write for .size and .dwFlags (the rest are pointers):
|
||||
dfwrite_LZ4(&aGameArrays[i], sizeof(gamearray_t), 1, fil);
|
||||
dfwrite_LZ4(aGameArrays[i].szLabel, sizeof(uint8_t) * MAXARRAYLABEL, 1, fil);
|
||||
buildvfs_fwrite(&aGameArrays[i], sizeof(gamearray_t), 1, fil);
|
||||
buildvfs_fwrite(aGameArrays[i].szLabel, sizeof(uint8_t) * MAXARRAYLABEL, 1, fil);
|
||||
|
||||
if ((aGameArrays[i].flags & GAMEARRAY_SYSTEM) != GAMEARRAY_SYSTEM)
|
||||
dfwrite_LZ4(aGameArrays[i].pValues, Gv_GetArrayAllocSize(i), 1, fil);
|
||||
buildvfs_fwrite(aGameArrays[i].pValues, Gv_GetArrayAllocSize(i), 1, fil);
|
||||
}
|
||||
|
||||
uint8_t savedstate[MAXVOLUMES * MAXLEVELS];
|
||||
|
@ -270,7 +271,7 @@ void Gv_WriteSave(buildvfs_FILE fil)
|
|||
if (g_mapInfo[i].savedstate != NULL)
|
||||
savedstate[i] = 1;
|
||||
|
||||
dfwrite_LZ4(savedstate, sizeof(savedstate), 1, fil);
|
||||
buildvfs_fwrite(savedstate, sizeof(savedstate), 1, fil);
|
||||
|
||||
for (bssize_t i = 0; i < (MAXVOLUMES * MAXLEVELS); i++)
|
||||
{
|
||||
|
@ -278,23 +279,23 @@ void Gv_WriteSave(buildvfs_FILE fil)
|
|||
|
||||
mapstate_t &sv = *g_mapInfo[i].savedstate;
|
||||
|
||||
dfwrite_LZ4(g_mapInfo[i].savedstate, sizeof(mapstate_t), 1, fil);
|
||||
buildvfs_fwrite(g_mapInfo[i].savedstate, sizeof(mapstate_t), 1, fil);
|
||||
|
||||
for (bssize_t j = 0; j < g_gameVarCount; j++)
|
||||
{
|
||||
if (aGameVars[j].flags & GAMEVAR_NORESET) continue;
|
||||
if (aGameVars[j].flags & GAMEVAR_PERPLAYER)
|
||||
dfwrite_LZ4(sv.vars[j], sizeof(intptr_t) * MAXPLAYERS, 1, fil);
|
||||
buildvfs_fwrite(sv.vars[j], sizeof(intptr_t) * MAXPLAYERS, 1, fil);
|
||||
else if (aGameVars[j].flags & GAMEVAR_PERACTOR)
|
||||
dfwrite_LZ4(sv.vars[j], sizeof(intptr_t) * MAXSPRITES, 1, fil);
|
||||
buildvfs_fwrite(sv.vars[j], sizeof(intptr_t) * MAXSPRITES, 1, fil);
|
||||
}
|
||||
|
||||
dfwrite_LZ4(sv.arraysiz, sizeof(sv.arraysiz), 1, fil);
|
||||
buildvfs_fwrite(sv.arraysiz, sizeof(sv.arraysiz), 1, fil);
|
||||
|
||||
for (bssize_t j = 0; j < g_gameArrayCount; j++)
|
||||
if (aGameArrays[j].flags & GAMEARRAY_RESTORE)
|
||||
{
|
||||
dfwrite_LZ4(sv.arrays[j], Gv_GetArrayAllocSizeForCount(j, sv.arraysiz[j]), 1, fil);
|
||||
buildvfs_fwrite(sv.arrays[j], Gv_GetArrayAllocSizeForCount(j, sv.arraysiz[j]), 1, fil);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -308,7 +308,7 @@ int32_t G_LoadSaveHeaderNew(char const *fn, savehead_t *saveh)
|
|||
TileFiles.tileCreate(TILE_LOADSHOT, 200, 320);
|
||||
if (screenshotofs)
|
||||
{
|
||||
if (kdfread_LZ4(tileData(TILE_LOADSHOT), 320, 200, fil) != 200)
|
||||
if (fil.Read(tileData(TILE_LOADSHOT), 320 * 200) != 320 * 200)
|
||||
{
|
||||
OSD_Printf("G_LoadSaveHeaderNew(): failed reading screenshot in \"%s\"\n", fn);
|
||||
goto corrupt;
|
||||
|
@ -963,10 +963,7 @@ static uint8_t *writespecdata(const dataspec_t *spec, buildvfs_FILE fil, uint8_t
|
|||
|
||||
if (fil)
|
||||
{
|
||||
if ((spec->flags & DS_CMP) || ((spec->flags & DS_CNTMASK) == 0 && spec->size * cnt <= savegame_comprthres))
|
||||
buildvfs_fwrite(ptr, spec->size, cnt, fil);
|
||||
else
|
||||
dfwrite_LZ4((void *)ptr, spec->size, cnt, fil);
|
||||
buildvfs_fwrite(ptr, spec->size, cnt, fil);
|
||||
}
|
||||
|
||||
if (dump && (spec->flags & (DS_NOCHK|DS_CMP)) == 0)
|
||||
|
@ -1036,9 +1033,8 @@ static int32_t readspecdata(const dataspec_t *spec, FileReader *fil, uint8_t **d
|
|||
if (fil != nullptr)
|
||||
{
|
||||
auto const mem = (dump && (spec->flags & DS_NOCHK) == 0) ? dump : (uint8_t *)ptr;
|
||||
bool const comp = !((spec->flags & DS_CNTMASK) == 0 && spec->size * cnt <= savegame_comprthres);
|
||||
int const siz = comp ? cnt : cnt * spec->size;
|
||||
int const ksiz = comp ? kdfread_LZ4(mem, spec->size, siz, *fil) : fil->Read(mem, siz);
|
||||
int const siz = cnt * spec->size;
|
||||
int const ksiz = fil->Read(mem, siz);
|
||||
|
||||
if (ksiz != siz)
|
||||
{
|
||||
|
@ -1724,7 +1720,7 @@ int32_t sv_saveandmakesnapshot(buildvfs_FILE fil, char const *name, int8_t spot,
|
|||
int32_t ofs;
|
||||
|
||||
// write the screenshot compressed
|
||||
dfwrite_LZ4(tileData(TILE_SAVESHOT), 320, 200, fil);
|
||||
buildvfs_fwrite(tileData(TILE_SAVESHOT), 320, 200, fil);
|
||||
|
||||
// write the current file offset right after the header
|
||||
ofs = buildvfs_ftell(fil);
|
||||
|
@ -1919,10 +1915,7 @@ uint32_t sv_writediff(buildvfs_FILE fil)
|
|||
buildvfs_fwrite("dIfF",4,1,fil);
|
||||
buildvfs_fwrite(&diffsiz, sizeof(diffsiz), 1, fil);
|
||||
|
||||
if (savegame_diffcompress)
|
||||
dfwrite_LZ4(svdiff, 1, diffsiz, fil); // cnt and sz swapped
|
||||
else
|
||||
buildvfs_fwrite(svdiff, 1, diffsiz, fil);
|
||||
buildvfs_fwrite(svdiff, 1, diffsiz, fil);
|
||||
|
||||
return diffsiz;
|
||||
}
|
||||
|
@ -1934,16 +1927,8 @@ int32_t sv_readdiff(FileReader &fil)
|
|||
if (fil.Read(&diffsiz, sizeof(uint32_t)) != sizeof(uint32_t))
|
||||
return -1;
|
||||
|
||||
if (savegame_diffcompress)
|
||||
{
|
||||
if (kdfread_LZ4(svdiff, 1, diffsiz, fil) != diffsiz) // cnt and sz swapped
|
||||
if (fil.Read(svdiff, diffsiz) != diffsiz)
|
||||
return -2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fil.Read(svdiff, diffsiz) != diffsiz)
|
||||
return -2;
|
||||
}
|
||||
|
||||
uint8_t *p = svsnapshot;
|
||||
uint8_t *d = svdiff;
|
||||
|
@ -2204,30 +2189,6 @@ static uint8_t *dosaveplayer2(buildvfs_FILE fil, uint8_t *mem)
|
|||
PRINTSIZE("ud");
|
||||
mem=writespecdata(svgm_secwsp, fil, mem); // sector, wall, sprite
|
||||
PRINTSIZE("sws");
|
||||
#ifdef LUNATIC
|
||||
{
|
||||
// Serialize Lunatic gamevars. When loading, the restoration code must
|
||||
// be present before Lua state creation in svgm_script, so save it
|
||||
// right before, too.
|
||||
int32_t slen, slen_ext;
|
||||
const char *svcode = El_SerializeGamevars(&slen, -1);
|
||||
|
||||
if (slen < 0)
|
||||
{
|
||||
// Serialization failed.
|
||||
g_savedOK = 0;
|
||||
g_failedVarname = svcode;
|
||||
return mem;
|
||||
}
|
||||
|
||||
buildvfs_fwrite("\0\1LunaGVAR\3\4", 12, 1, fil);
|
||||
slen_ext = B_LITTLE32(slen);
|
||||
buildvfs_fwrite(&slen_ext, sizeof(slen_ext), 1, fil);
|
||||
dfwrite_LZ4(svcode, 1, slen, fil); // cnt and sz swapped
|
||||
|
||||
g_savedOK = 1;
|
||||
}
|
||||
#endif
|
||||
mem=writespecdata(svgm_script, fil, mem); // script
|
||||
PRINTSIZE("script");
|
||||
mem=writespecdata(svgm_anmisc, fil, mem); // animates, quotes & misc.
|
||||
|
|
|
@ -51,11 +51,10 @@ static int32_t g_demo_soundToggle;
|
|||
static int32_t demo_hasdiffs, demorec_diffs=1, demorec_difftics = 2*REALGAMETICSPERSEC;
|
||||
int32_t demoplay_diffs=1;
|
||||
int32_t demorec_diffcompress_cvar=1;
|
||||
int32_t demorec_synccompress_cvar=1;
|
||||
int32_t demorec_seeds_cvar=1;
|
||||
int32_t demoplay_showsync=1;
|
||||
|
||||
static int32_t demo_synccompress=1, demorec_seeds=1, demo_hasseeds;
|
||||
static int32_t demorec_seeds=1, demo_hasseeds;
|
||||
|
||||
static void Demo_RestoreModes(int32_t menu)
|
||||
{
|
||||
|
@ -114,10 +113,7 @@ static int32_t G_OpenDemoRead(int32_t g_whichDemo) // 0 = mine
|
|||
|
||||
demo_hasdiffs = saveh.recdiffsp;
|
||||
g_demo_totalCnt = saveh.reccnt;
|
||||
demo_synccompress = saveh.synccompress;
|
||||
|
||||
demo_hasseeds = demo_synccompress&2;
|
||||
demo_synccompress &= 1;
|
||||
demo_hasseeds = saveh.synccompress&2;
|
||||
|
||||
i = g_demo_totalCnt/REALGAMETICSPERSEC;
|
||||
OSD_Printf("demo %d duration: %d min %d sec\n", g_whichDemo, i/60, i%60);
|
||||
|
@ -181,7 +177,7 @@ void G_OpenDemoWrite(void)
|
|||
return;
|
||||
|
||||
i=sv_saveandmakesnapshot(g_demo_filePtr, nullptr, -1, demorec_diffs_cvar, demorec_diffcompress_cvar,
|
||||
demorec_synccompress_cvar|(demorec_seeds_cvar<<1));
|
||||
(demorec_seeds_cvar<<1));
|
||||
if (i)
|
||||
{
|
||||
MAYBE_FCLOSE_AND_NULL(g_demo_filePtr);
|
||||
|
@ -194,7 +190,6 @@ error_wopen_demo:
|
|||
|
||||
demorec_seeds = demorec_seeds_cvar;
|
||||
demorec_diffs = demorec_diffs_cvar;
|
||||
demo_synccompress = demorec_synccompress_cvar;
|
||||
demorec_difftics = demorec_difftics_cvar;
|
||||
|
||||
Bsprintf(apStrings[QUOTE_RESERVED4], "DEMO %d RECORDING STARTED", demonum-1);
|
||||
|
@ -244,10 +239,7 @@ static void Demo_WriteSync()
|
|||
if (demorec_seeds)
|
||||
buildvfs_fwrite(g_demo_seedbuf, 1, ud.reccnt, g_demo_filePtr);
|
||||
|
||||
if (demo_synccompress)
|
||||
dfwrite_LZ4(recsync, sizeof(input_t), ud.reccnt, g_demo_filePtr);
|
||||
else //if (demo_synccompress==0)
|
||||
buildvfs_fwrite(recsync, sizeof(input_t), ud.reccnt, g_demo_filePtr);
|
||||
buildvfs_fwrite(recsync, sizeof(input_t), ud.reccnt, g_demo_filePtr);
|
||||
|
||||
ud.reccnt = 0;
|
||||
}
|
||||
|
@ -336,18 +328,11 @@ static int32_t Demo_ReadSync(int32_t errcode)
|
|||
return errcode;
|
||||
}
|
||||
|
||||
if (demo_synccompress)
|
||||
{
|
||||
if (kdfread_LZ4(recsync, sizeof(input_t), i, g_demo_recFilePtr) != i)
|
||||
return errcode+1;
|
||||
}
|
||||
else
|
||||
{
|
||||
int32_t bytes = sizeof(input_t)*i;
|
||||
|
||||
if (g_demo_recFilePtr.Read(recsync, bytes) != bytes)
|
||||
return errcode+2;
|
||||
}
|
||||
int32_t bytes = sizeof(input_t)*i;
|
||||
|
||||
if (g_demo_recFilePtr.Read(recsync, bytes) != bytes)
|
||||
return errcode+2;
|
||||
|
||||
ud.reccnt = i;
|
||||
return 0;
|
||||
|
|
|
@ -289,7 +289,7 @@ int32_t G_LoadSaveHeaderNew(char const *fn, savehead_t *saveh)
|
|||
TileFiles.tileCreate(TILE_LOADSHOT, 200, 320);
|
||||
if (screenshotofs)
|
||||
{
|
||||
if (kdfread_LZ4(tileData(TILE_LOADSHOT), 320, 200, fil) != 200)
|
||||
if (fil.Read(tileData(TILE_LOADSHOT), 320 * 200) != 320 * 200)
|
||||
{
|
||||
OSD_Printf("G_LoadSaveHeaderNew(): failed reading screenshot in \"%s\"\n", fn);
|
||||
goto corrupt;
|
||||
|
@ -672,10 +672,7 @@ static uint8_t *writespecdata(const dataspec_t *spec, FILE *fil, uint8_t *dump)
|
|||
|
||||
if (fil)
|
||||
{
|
||||
if ((spec->flags & DS_CMP) || ((spec->flags & DS_CNTMASK) == 0 && spec->size * cnt <= savegame_comprthres))
|
||||
fwrite(ptr, spec->size, cnt, fil);
|
||||
else
|
||||
dfwrite_LZ4((void *)ptr, spec->size, cnt, fil);
|
||||
fwrite(ptr, spec->size, cnt, fil);
|
||||
}
|
||||
|
||||
if (dump && (spec->flags & (DS_NOCHK|DS_CMP)) == 0)
|
||||
|
@ -745,9 +742,8 @@ static int32_t readspecdata(const dataspec_t *spec, FileReader *fil, uint8_t **d
|
|||
if (fil->isOpen())
|
||||
{
|
||||
auto const mem = (dump && (spec->flags & DS_NOCHK) == 0) ? dump : (uint8_t *)ptr;
|
||||
bool const comp = !((spec->flags & DS_CNTMASK) == 0 && spec->size * cnt <= savegame_comprthres);
|
||||
int const siz = comp ? cnt : cnt * spec->size;
|
||||
int const ksiz = comp ? kdfread_LZ4(mem, spec->size, siz, *fil) : fil->Read(mem, siz);
|
||||
int const siz = cnt * spec->size;
|
||||
int const ksiz = fil->Read(mem, siz);
|
||||
|
||||
if (ksiz != siz)
|
||||
{
|
||||
|
@ -1381,7 +1377,7 @@ int32_t sv_saveandmakesnapshot(FILE *fil, char const *name, int8_t spot, int8_t
|
|||
int32_t ofs;
|
||||
|
||||
// write the screenshot compressed
|
||||
dfwrite_LZ4(tileData(TILE_SAVESHOT), 320, 200, fil);
|
||||
fwrite(tileData(TILE_SAVESHOT), 320, 200, fil);
|
||||
|
||||
// write the current file offset right after the header
|
||||
ofs = ftell(fil);
|
||||
|
@ -1576,10 +1572,7 @@ uint32_t sv_writediff(FILE *fil)
|
|||
fwrite("dIfF",4,1,fil);
|
||||
fwrite(&diffsiz, sizeof(diffsiz), 1, fil);
|
||||
|
||||
if (savegame_diffcompress)
|
||||
dfwrite_LZ4(svdiff, 1, diffsiz, fil); // cnt and sz swapped
|
||||
else
|
||||
fwrite(svdiff, 1, diffsiz, fil);
|
||||
fwrite(svdiff, 1, diffsiz, fil);
|
||||
|
||||
return diffsiz;
|
||||
}
|
||||
|
@ -1591,16 +1584,8 @@ int32_t sv_readdiff(FileReader &fil)
|
|||
if (fil.Read(&diffsiz, sizeof(uint32_t)) != sizeof(uint32_t))
|
||||
return -1;
|
||||
|
||||
if (savegame_diffcompress)
|
||||
{
|
||||
if (kdfread_LZ4(svdiff, 1, diffsiz, fil) != diffsiz) // cnt and sz swapped
|
||||
if (fil.Read(svdiff, diffsiz) != diffsiz)
|
||||
return -2;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (fil.Read(svdiff, diffsiz) != diffsiz)
|
||||
return -2;
|
||||
}
|
||||
|
||||
uint8_t *p = svsnapshot;
|
||||
uint8_t *d = svdiff;
|
||||
|
|
Loading…
Reference in a new issue