diff --git a/source/build/include/cache1d.h b/source/build/include/cache1d.h index 655a833a7..ae590dcb8 100644 --- a/source/build/include/cache1d.h +++ b/source/build/include/cache1d.h @@ -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. diff --git a/source/common/gamecvars.cpp b/source/common/gamecvars.cpp index af3c2b474..ed29b4cbf 100644 --- a/source/common/gamecvars.cpp +++ b/source/common/gamecvars.cpp @@ -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") diff --git a/source/common/gamecvars.h b/source/common/gamecvars.h index 4c1482c3b..12c3f6527 100644 --- a/source/common/gamecvars.h +++ b/source/common/gamecvars.h @@ -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) diff --git a/source/duke3d/src/demo.cpp b/source/duke3d/src/demo.cpp index 20a482d5b..37045ef45 100644 --- a/source/duke3d/src/demo.cpp +++ b/source/duke3d/src/demo.cpp @@ -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); diff --git a/source/duke3d/src/gamevars.cpp b/source/duke3d/src/gamevars.cpp index e27a7da4a..32986dbb7 100644 --- a/source/duke3d/src/gamevars.cpp +++ b/source/duke3d/src/gamevars.cpp @@ -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; iflags & 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. diff --git a/source/rr/src/demo.cpp b/source/rr/src/demo.cpp index 76c20d06e..9cf547c5d 100644 --- a/source/rr/src/demo.cpp +++ b/source/rr/src/demo.cpp @@ -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; diff --git a/source/rr/src/savegame.cpp b/source/rr/src/savegame.cpp index 73921033e..868f42f23 100644 --- a/source/rr/src/savegame.cpp +++ b/source/rr/src/savegame.cpp @@ -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;