From fc11fd82d68b3582ad8e293ecaa4876c334b6732 Mon Sep 17 00:00:00 2001 From: Brad Harding Date: Thu, 24 Oct 2024 17:52:44 +1100 Subject: [PATCH] Interpolate scrolling textures --- src/p_saveg.c | 3 +++ src/p_setup.c | 6 ++++-- src/p_spec.c | 39 +++++++++++++++++++++++++++++++++------ src/r_bsp.c | 29 +++++++++++++++++++++++++++++ src/r_defs.h | 13 +++++++++++++ 5 files changed, 82 insertions(+), 8 deletions(-) diff --git a/src/p_saveg.c b/src/p_saveg.c index 248ff17a6..95d1063d9 100644 --- a/src/p_saveg.c +++ b/src/p_saveg.c @@ -1266,6 +1266,9 @@ void P_UnarchiveWorld(void) if (ABS((side->rowoffset = saveg_read32())) < FRACUNIT) side->rowoffset <<= FRACBITS; + side->basetextureoffset = side->textureoffset; + side->baserowoffset = side->rowoffset; + side->toptexture = saveg_read16(); side->bottomtexture = saveg_read16(); side->midtexture = saveg_read16(); diff --git a/src/p_setup.c b/src/p_setup.c index 68e8b4901..8b73927bc 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -1388,6 +1388,8 @@ static void P_LoadSectors(int lump) ss->oldceilinggametime = -1; ss->oldfloorgametime = -1; + ss->oldceilingoffsetgametime = -1; + ss->oldflooroffsetgametime = -1; // [BH] Apply any level-specific fixes. if (canmodify && r_fixmaperrors && gamemode != shareware) @@ -2201,8 +2203,8 @@ static void P_LoadSideDefs2(int lump) sector_t *sec; unsigned short sector_num = SHORT(msd->sector); - sd->textureoffset = SHORT(msd->textureoffset) << FRACBITS; - sd->rowoffset = SHORT(msd->rowoffset) << FRACBITS; + sd->textureoffset = sd->basetextureoffset = sd->oldtextureoffset = SHORT(msd->textureoffset) << FRACBITS; + sd->rowoffset = sd->baserowoffset = SHORT(msd->rowoffset) << FRACBITS; // cph 09/30/06: catch out-of-range sector numbers; use sector 0 instead if (sector_num >= numsectors) diff --git a/src/p_spec.c b/src/p_spec.c index 5668a4a80..dca26c575 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2801,8 +2801,17 @@ void T_Scroll(scroll_t *scroller) { side_t *side = sides + scroller->affectee; - side->textureoffset += dx; - side->rowoffset += dy; + if (side->oldgametime != gametime) + { + side->oldtextureoffset = side->basetextureoffset; + side->oldrowoffset = side->baserowoffset; + side->oldgametime = gametime; + } + + side->basetextureoffset += dx; + side->baserowoffset += dy; + side->textureoffset = side->basetextureoffset; + side->rowoffset = side->baserowoffset; break; } @@ -2810,8 +2819,17 @@ void T_Scroll(scroll_t *scroller) { sector_t *sec = sectors + scroller->affectee; - sec->floorxoffset += dx; - sec->flooryoffset += dy; + if (sec->oldflooroffsetgametime != gametime) + { + sec->oldfloorxoffset = sec->basefloorxoffset; + sec->oldflooryoffset = sec->baseflooryoffset; + sec->oldflooroffsetgametime = gametime; + } + + sec->basefloorxoffset += dx; + sec->baseflooryoffset += dy; + sec->floorxoffset = sec->basefloorxoffset; + sec->flooryoffset = sec->baseflooryoffset; break; } @@ -2819,8 +2837,17 @@ void T_Scroll(scroll_t *scroller) { sector_t *sec = sectors + scroller->affectee; - sec->ceilingxoffset += dx; - sec->ceilingyoffset += dy; + if (sec->oldceilingoffsetgametime != gametime) + { + sec->oldceilingxoffset = sec->baseceilingxoffset; + sec->oldceilingyoffset = sec->baseceilingyoffset; + sec->oldceilingoffsetgametime = gametime; + } + + sec->baseceilingxoffset += dx; + sec->baseceilingyoffset += dy; + sec->ceilingxoffset = sec->baseceilingxoffset; + sec->ceilingyoffset = sec->baseceilingyoffset; break; } diff --git a/src/r_bsp.c b/src/r_bsp.c index 7bb3243c1..f3fea17cd 100644 --- a/src/r_bsp.c +++ b/src/r_bsp.c @@ -215,6 +215,22 @@ static void R_InterpolateSector(sector_t *sector) else heightsec->interpceilingheight = heightsec->ceilingheight; } + + if (sector->oldflooroffsetgametime == gametime - 1) + { + sector->floorxoffset = sector->oldfloorxoffset + + FixedMul(sector->basefloorxoffset - sector->oldfloorxoffset, fractionaltic); + sector->flooryoffset = sector->oldflooryoffset + + FixedMul(sector->baseflooryoffset - sector->oldflooryoffset, fractionaltic); + } + + if (sector->oldceilingoffsetgametime == gametime - 1) + { + sector->ceilingxoffset = sector->oldceilingxoffset + + FixedMul(sector->baseceilingxoffset - sector->oldceilingxoffset, fractionaltic); + sector->ceilingyoffset = sector->oldceilingyoffset + + FixedMul(sector->baseceilingyoffset - sector->oldceilingyoffset, fractionaltic); + } } else { @@ -229,6 +245,17 @@ static void R_InterpolateSector(sector_t *sector) } } +static void R_InterpolateTextureOffsets(side_t *side) +{ + if (vid_capfps != TICRATE && side->oldgametime == gametime - 1) + { + side->textureoffset = side->oldtextureoffset + + FixedMul(side->basetextureoffset - side->oldtextureoffset, fractionaltic); + side->rowoffset = side->oldrowoffset + + FixedMul(side->baserowoffset - side->oldrowoffset, fractionaltic); + } +} + // // killough 03/07/98: Hack floor/ceiling heights for deep water etc. // @@ -388,6 +415,8 @@ static void R_AddLine(seg_t *line) if (x1 >= x2) return; + R_InterpolateTextureOffsets(line->sidedef); + // Single sided line? if ((backsector = line->backsector)) { diff --git a/src/r_defs.h b/src/r_defs.h index fda7a1328..d926ec996 100644 --- a/src/r_defs.h +++ b/src/r_defs.h @@ -152,6 +152,8 @@ typedef struct sector_s // if old values were not updated recently. int oldfloorgametime; int oldceilinggametime; + int oldceilingoffsetgametime; + int oldflooroffsetgametime; // [AM] Interpolated floor and ceiling height. // Calculated once per tic and used inside @@ -168,6 +170,11 @@ typedef struct sector_s fixed_t floorxoffset, flooryoffset; fixed_t ceilingxoffset, ceilingyoffset; + fixed_t basefloorxoffset, baseflooryoffset; + fixed_t oldfloorxoffset, oldflooryoffset; + fixed_t baseceilingxoffset, baseceilingyoffset; + fixed_t oldceilingxoffset, oldceilingyoffset; + // killough 04/11/98: support for lightlevels coming from another sector struct sector_s *floorlightsec; struct sector_s *ceilinglightsec; @@ -233,6 +240,12 @@ typedef struct bool missingtoptexture; bool missingmidtexture; bool missingbottomtexture; + + fixed_t oldtextureoffset; + fixed_t oldrowoffset; + fixed_t basetextureoffset; + fixed_t baserowoffset; + int oldgametime; } side_t; //