Skip to content

Commit

Permalink
Interpolate scrolling textures
Browse files Browse the repository at this point in the history
  • Loading branch information
bradharding committed Oct 24, 2024
1 parent 50f1aba commit fc11fd8
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 8 deletions.
3 changes: 3 additions & 0 deletions src/p_saveg.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 4 additions & 2 deletions src/p_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
39 changes: 33 additions & 6 deletions src/p_spec.c
Original file line number Diff line number Diff line change
Expand Up @@ -2801,26 +2801,53 @@ 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;
}

case sc_floor: // killough 03/07/98: Scroll floor texture
{
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;
}

case sc_ceiling: // killough 03/07/98: Scroll ceiling texture
{
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;
}

Expand Down
29 changes: 29 additions & 0 deletions src/r_bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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.
//
Expand Down Expand Up @@ -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))
{
Expand Down
13 changes: 13 additions & 0 deletions src/r_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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;

//
Expand Down

0 comments on commit fc11fd8

Please sign in to comment.