From 472cc85b62d997e27fed25b0102176a1171e9ee2 Mon Sep 17 00:00:00 2001 From: Roman Fomin Date: Mon, 24 Mar 2025 15:23:10 +0700 Subject: [PATCH] save floor/ceiling offsets, fix interpolation (#2226) --- src/g_game.c | 38 +++++++++++++++++++++++++------------- src/p_saveg.c | 17 +++++++++++++++++ src/p_saveg.h | 5 +++-- src/p_spec.c | 6 ------ src/r_bsp.c | 20 ++++++++++++++++++++ 5 files changed, 65 insertions(+), 21 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 9b761763..ffe33dd5 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -2199,7 +2199,16 @@ static void G_DoPlayDemo(void) // killough 2/22/98: version id string format for savegames #define VERSIONID "MBF %d" -#define CURRENT_SAVE_VERSION "Woof 15.0.0" +#define CURRENT_SAVE_VERSION "Woof 16.0.0" + +static const char *saveg_versions[] = +{ + [saveg_woof510] = "Woof 5.1.0", + [saveg_woof600] = "Woof 6.0.0", + [saveg_woof1300] = "Woof 13.0.0", + [saveg_woof1500] = "Woof 15.0.0", + [saveg_current] = CURRENT_SAVE_VERSION +}; static char *savename = NULL; @@ -2511,14 +2520,6 @@ static void G_DoSaveAutoSave(void) DoSaveGame(name); } -static void CheckSaveVersion(const char *str, saveg_compat_t ver) -{ - if (strncmp((char *) save_p, str, strlen(str)) == 0) - { - saveg_compat = ver; - } -} - static boolean DoLoadGame(boolean do_load_autosave) { int length, i; @@ -2549,10 +2550,21 @@ static boolean DoLoadGame(boolean do_load_autosave) // killough 2/22/98: "proprietary" version string :-) sprintf (vcheck,VERSIONID,MBFVERSION); - CheckSaveVersion(vcheck, saveg_mbf); - CheckSaveVersion("Woof 6.0.0", saveg_woof600); - CheckSaveVersion("Woof 13.0.0", saveg_woof1300); - CheckSaveVersion(CURRENT_SAVE_VERSION, saveg_current); + if (strncmp((char *)save_p, vcheck, VERSIONSIZE) == 0) + { + saveg_compat = saveg_mbf; + } + else + { + for (int i = saveg_woof510; i < arrlen(saveg_versions); ++i) + { + if (strncmp((char *)save_p, saveg_versions[i], VERSIONSIZE) == 0) + { + saveg_compat = i; + break; + } + } + } // killough 2/22/98: Friendly savegame version difference message if (!forced_loadgame && saveg_compat != saveg_mbf && saveg_compat < saveg_woof600) diff --git a/src/p_saveg.c b/src/p_saveg.c index bc9b90c2..de091d28 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -2119,6 +2119,11 @@ void P_ArchiveWorld (void) saveg_write16(sec->lightlevel); saveg_write16(sec->special); // needed? yes -- transfer types saveg_write16(sec->tag); // needed? need them -- killough + + saveg_write32(sec->floor_xoffs); + saveg_write32(sec->floor_yoffs); + saveg_write32(sec->ceiling_xoffs); + saveg_write32(sec->ceiling_yoffs); } // do lines @@ -2182,6 +2187,18 @@ void P_UnArchiveWorld (void) sec->lightingdata = 0; sec->soundtarget = 0; + if (saveg_compat > saveg_woof1500) + { + sec->floor_xoffs = saveg_read32(); + sec->floor_yoffs = saveg_read32(); + sec->ceiling_xoffs = saveg_read32(); + sec->ceiling_yoffs = saveg_read32(); + sec->base_floor_xoffs = sec->old_floor_xoffs = sec->floor_xoffs; + sec->base_floor_yoffs = sec->old_floor_yoffs = sec->floor_yoffs; + sec->base_ceiling_xoffs = sec->old_ceiling_xoffs = sec->ceiling_xoffs; + sec->base_ceiling_yoffs = sec->old_ceiling_yoffs = sec->ceiling_yoffs; + } + // [crispy] add overflow guard for the flattranslation[] array if (floorpic >= 0 && floorpic < numflats && W_LumpLength(firstflat + floorpic) >= 64*64) diff --git a/src/p_saveg.h b/src/p_saveg.h index 49649b25..6f08bdbb 100644 --- a/src/p_saveg.h +++ b/src/p_saveg.h @@ -51,13 +51,14 @@ void saveg_write32(int value); int64_t saveg_read64(void); void saveg_write64(int64_t value); -typedef enum saveg_compat_e +typedef enum { saveg_mbf, saveg_woof510, saveg_woof600, saveg_woof1300, - saveg_current, // saveg_woof1500 + saveg_woof1500, + saveg_current, // saveg_woof1600 } saveg_compat_t; extern saveg_compat_t saveg_compat; diff --git a/src/p_spec.c b/src/p_spec.c index 34be90c2..4708e8ef 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2696,8 +2696,6 @@ void T_Scroll(scroll_t *s) } side->basetextureoffset += dx; side->baserowoffset += dy; - side->textureoffset = side->basetextureoffset; - side->rowoffset = side->baserowoffset; break; case sc_floor: // killough 3/7/98: Scroll floor texture @@ -2710,8 +2708,6 @@ void T_Scroll(scroll_t *s) } sec->base_floor_xoffs += dx; sec->base_floor_yoffs += dy; - sec->floor_xoffs = sec->base_floor_xoffs; - sec->floor_yoffs = sec->base_floor_yoffs; break; case sc_ceiling: // killough 3/7/98: Scroll ceiling texture @@ -2724,8 +2720,6 @@ void T_Scroll(scroll_t *s) } sec->base_ceiling_xoffs += dx; sec->base_ceiling_yoffs += dy; - sec->ceiling_xoffs = sec->base_ceiling_xoffs; - sec->ceiling_yoffs = sec->base_ceiling_yoffs; break; case sc_carry: diff --git a/src/r_bsp.c b/src/r_bsp.c index 645e28e4..2878b73a 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -311,16 +311,31 @@ static void R_MaybeInterpolateSector(sector_t* sector) sector->floor_xoffs = LerpFixed(sector->old_floor_xoffs, sector->base_floor_xoffs); sector->floor_yoffs = LerpFixed(sector->old_floor_yoffs, sector->base_floor_yoffs); } + else + { + sector->floor_xoffs = sector->base_floor_xoffs; + sector->floor_yoffs = sector->base_floor_yoffs; + } + if (sector->old_ceil_offs_gametic == gametic - 1) { sector->ceiling_xoffs = LerpFixed(sector->old_ceiling_xoffs, sector->base_ceiling_xoffs); sector->ceiling_yoffs = LerpFixed(sector->old_ceiling_yoffs, sector->base_ceiling_yoffs); } + else + { + sector->ceiling_xoffs = sector->base_ceiling_xoffs; + sector->ceiling_yoffs = sector->base_ceiling_yoffs; + } } else { sector->interpfloorheight = sector->floorheight; sector->interpceilingheight = sector->ceilingheight; + sector->floor_xoffs = sector->base_floor_xoffs; + sector->floor_yoffs = sector->base_floor_yoffs; + sector->ceiling_xoffs = sector->base_ceiling_xoffs; + sector->ceiling_yoffs = sector->base_ceiling_yoffs; } } @@ -331,6 +346,11 @@ static void R_MaybeInterpolateTextureOffsets(side_t *side) side->textureoffset = LerpFixed(side->oldtextureoffset, side->basetextureoffset); side->rowoffset = LerpFixed(side->oldrowoffset, side->baserowoffset); } + else + { + side->textureoffset = side->basetextureoffset; + side->rowoffset = side->baserowoffset; + } } //