Skip to content

Commit

Permalink
redo interpolation of scrollers animation (#1219)
Browse files Browse the repository at this point in the history
* add old* fields

* remove R_InterpolateTextureOffets() function, move code to r_bsp.c
  • Loading branch information
rfomin authored Oct 13, 2023
1 parent 51ccc03 commit 54eb621
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 101 deletions.
4 changes: 0 additions & 4 deletions src/p_saveg.c
Original file line number Diff line number Diff line change
Expand Up @@ -2568,8 +2568,6 @@ void P_UnArchiveSpecials (void)
{
byte tclass;

P_FreeScrollers();

// read in saved thinkers
while ((tclass = saveg_read8()) != tc_endspecials) // killough 2/14/98
switch (tclass)
Expand Down Expand Up @@ -2689,8 +2687,6 @@ void P_UnArchiveSpecials (void)
saveg_read_scroll_t(scroll);
scroll->thinker.function.p1 = (actionf_p1)T_Scroll;
P_AddThinker(&scroll->thinker);
if (scroll->type >= sc_side && scroll->type <= sc_ceiling)
P_AddScroller(scroll);
break;
}

Expand Down
8 changes: 8 additions & 0 deletions src/p_setup.c
Original file line number Diff line number Diff line change
Expand Up @@ -304,8 +304,12 @@ void P_LoadSectors (int lump)
// killough 3/7/98:
ss->floor_xoffs = 0;
ss->floor_yoffs = 0; // floor and ceiling flats offsets
ss->old_floor_xoffs = ss->base_floor_xoffs = 0;
ss->old_floor_yoffs = ss->base_floor_yoffs = 0;
ss->ceiling_xoffs = 0;
ss->ceiling_yoffs = 0;
ss->old_ceiling_xoffs = ss->base_ceiling_xoffs = 0;
ss->old_ceiling_yoffs = ss->base_ceiling_yoffs = 0;
ss->heightsec = -1; // sector used to get floor and ceiling height
ss->floorlightsec = -1; // sector used to get floor lighting
// killough 3/7/98: end changes
Expand All @@ -329,6 +333,7 @@ void P_LoadSectors (int lump)
// [FG] inhibit sector interpolation during the 0th gametic
ss->oldceilgametic = -1;
ss->oldfloorgametic = -1;
ss->oldscrollgametic = -1;
}

Z_Free (data);
Expand Down Expand Up @@ -579,8 +584,11 @@ void P_LoadSideDefs2(int lump)
sd->textureoffset = SHORT(msd->textureoffset)<<FRACBITS;
sd->rowoffset = SHORT(msd->rowoffset)<<FRACBITS;
// [crispy] smooth texture scrolling
sd->oldtextureoffset = sd->textureoffset;
sd->oldrowoffset = sd->rowoffset;
sd->basetextureoffset = sd->textureoffset;
sd->baserowoffset = sd->rowoffset;
sd->oldgametic = -1;

// killough 4/4/98: allow sidedef texture names to be overloaded
// killough 4/11/98: refined to allow colormaps to work as wall
Expand Down
108 changes: 18 additions & 90 deletions src/p_spec.c
Original file line number Diff line number Diff line change
Expand Up @@ -2642,6 +2642,12 @@ void T_Scroll(scroll_t *s)

case sc_side: // killough 3/7/98: Scroll wall texture
side = sides + s->affectee;
if (side->oldgametic != gametic)
{
side->oldtextureoffset = side->basetextureoffset;
side->oldrowoffset = side->baserowoffset;
side->oldgametic = gametic;
}
side->basetextureoffset += dx;
side->baserowoffset += dy;
side->textureoffset = side->basetextureoffset;
Expand All @@ -2650,6 +2656,12 @@ void T_Scroll(scroll_t *s)

case sc_floor: // killough 3/7/98: Scroll floor texture
sec = sectors + s->affectee;
if (sec->oldscrollgametic != gametic)
{
sec->old_floor_xoffs = sec->base_floor_xoffs;
sec->old_floor_yoffs = sec->base_floor_yoffs;
sec->oldscrollgametic = gametic;
}
sec->base_floor_xoffs += dx;
sec->base_floor_yoffs += dy;
sec->floor_xoffs = sec->base_floor_xoffs;
Expand All @@ -2658,6 +2670,12 @@ void T_Scroll(scroll_t *s)

case sc_ceiling: // killough 3/7/98: Scroll ceiling texture
sec = sectors + s->affectee;
if (sec->oldscrollgametic != gametic)
{
sec->old_ceiling_xoffs = sec->base_ceiling_xoffs;
sec->old_ceiling_yoffs = sec->base_ceiling_yoffs;
sec->oldscrollgametic = gametic;
}
sec->base_ceiling_xoffs += dx;
sec->base_ceiling_yoffs += dy;
sec->ceiling_xoffs = sec->base_ceiling_xoffs;
Expand Down Expand Up @@ -2695,91 +2713,6 @@ void T_Scroll(scroll_t *s)
}
}

// [crispy] smooth texture scrolling

static int maxscrollers, numscrollers;
static scroll_t **scrollers;

void P_AddScroller (scroll_t *s)
{
if (numscrollers == maxscrollers)
{
maxscrollers = maxscrollers ? 2 * maxscrollers : 32;
scrollers = I_Realloc(scrollers, maxscrollers * sizeof(*scrollers));
}
scrollers[numscrollers++] = s;
}

void P_FreeScrollers (void)
{
maxscrollers = 0;
numscrollers = 0;
if (scrollers)
free(scrollers);
scrollers = NULL;
}

void R_InterpolateTextureOffsets (void)
{
if (uncapped && leveltime > oldleveltime && !frozen_mode)
{
int i;

for (i = 0; i < numscrollers; i++)
{
scroll_t *s = scrollers[i];
int dx, dy;

if (s->accel)
{
dx = s->vdx;
dy = s->vdy;
}
else
{
dx = s->dx;
dy = s->dy;

if (s->control != -1)
{ // compute scroll amounts based on a sector's height changes
fixed_t height = sectors[s->control].floorheight +
sectors[s->control].ceilingheight;
fixed_t delta = height - s->last_height;
dx = FixedMul(dx, delta);
dy = FixedMul(dy, delta);
}
}

if (!dx && !dy)
continue;

switch(s->type)
{
side_t *side;
sector_t *sec;

case sc_side:
side = sides + s->affectee;
side->textureoffset = side->basetextureoffset + FixedMul(dx, fractionaltic);
side->rowoffset = side->baserowoffset + FixedMul(dy, fractionaltic);
break;
case sc_floor:
sec = sectors + s->affectee;
sec->floor_xoffs = sec->base_floor_xoffs + FixedMul(dx, fractionaltic);
sec->floor_yoffs = sec->base_floor_yoffs + FixedMul(dy, fractionaltic);
break;
case sc_ceiling:
sec = sectors + s->affectee;
sec->ceiling_xoffs = sec->base_ceiling_xoffs + FixedMul(dx, fractionaltic);
sec->ceiling_yoffs = sec->base_ceiling_yoffs + FixedMul(dy, fractionaltic);
break;
default:
break;
}
}
}
}

//
// Add_Scroller()
//
Expand Down Expand Up @@ -2813,9 +2746,6 @@ static void Add_Scroller(int type, fixed_t dx, fixed_t dy,
sectors[control].floorheight + sectors[control].ceilingheight;
s->affectee = affectee;
P_AddThinker(&s->thinker);

if (type >= sc_side && type <= sc_ceiling)
P_AddScroller(s);
}

// Adds wall scroller. Scroll amount is rotated with respect to wall's
Expand Down Expand Up @@ -2855,8 +2785,6 @@ static void P_SpawnScrollers(void)
int i;
line_t *l = lines;

P_FreeScrollers();

for (i=0;i<numlines;i++,l++)
{
fixed_t dx = l->dx >> SCROLL_SHIFT; // direction and speed of scrolling
Expand Down
4 changes: 0 additions & 4 deletions src/p_spec.h
Original file line number Diff line number Diff line change
Expand Up @@ -810,10 +810,6 @@ boolean P_WasSecret(sector_t *sec);

void P_ChangeSwitchTexture(line_t *line, int useAgain);

void P_FreeScrollers(void);

void P_AddScroller(scroll_t *s);

////////////////////////////////////////////////////////////////
//
// Linedef and sector special action function prototypes
Expand Down
25 changes: 25 additions & 0 deletions src/r_bsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,18 @@ static void R_MaybeInterpolateSector(sector_t* sector)
{
sector->interpceilingheight = sector->ceilingheight;
}

if (sector->oldscrollgametic == gametic - 1)
{
sector->floor_xoffs = sector->old_floor_xoffs +
FixedMul(sector->base_floor_xoffs - sector->old_floor_xoffs, fractionaltic);
sector->floor_yoffs = sector->old_floor_yoffs +
FixedMul(sector->base_floor_yoffs - sector->old_floor_yoffs, fractionaltic);
sector->ceiling_xoffs = sector->old_ceiling_xoffs +
FixedMul(sector->base_ceiling_xoffs - sector->old_ceiling_xoffs, fractionaltic);
sector->ceiling_yoffs = sector->old_ceiling_yoffs +
FixedMul(sector->base_ceiling_yoffs - sector->old_ceiling_yoffs, fractionaltic);
}
}
else
{
Expand All @@ -302,6 +314,17 @@ static void R_MaybeInterpolateSector(sector_t* sector)
}
}

static void R_MaybeInterpolateTextureOffsets(side_t *side)
{
if (uncapped && side->oldgametic == gametic - 1)
{
side->textureoffset = side->oldtextureoffset +
FixedMul(side->basetextureoffset - side->oldtextureoffset, fractionaltic);
side->rowoffset = side->oldrowoffset +
FixedMul(side->baserowoffset - side->oldrowoffset, fractionaltic);
}
}

//
// R_AddLine
// Clips the given segment
Expand Down Expand Up @@ -372,6 +395,8 @@ static void R_AddLine (seg_t *line)
if (x1 >= x2) // killough 1/31/98 -- change == to >= for robustness
return;

R_MaybeInterpolateTextureOffsets(line->sidedef);

backsector = line->backsector;

// Single sided line?
Expand Down
8 changes: 8 additions & 0 deletions src/r_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ typedef struct
// if old values were not updated recently.
int oldceilgametic;
int oldfloorgametic;
int oldscrollgametic;

// [AM] Interpolated floor and ceiling height.
// Calculated once per tic and used inside
Expand All @@ -162,8 +163,12 @@ typedef struct

fixed_t base_floor_xoffs;
fixed_t base_floor_yoffs;
fixed_t old_floor_xoffs;
fixed_t old_floor_yoffs;
fixed_t base_ceiling_xoffs;
fixed_t base_ceiling_yoffs;
fixed_t old_ceiling_xoffs;
fixed_t old_ceiling_yoffs;
} sector_t;

//
Expand All @@ -186,8 +191,11 @@ typedef struct
int special;

// [crispy] smooth texture scrolling
fixed_t oldtextureoffset;
fixed_t oldrowoffset;
fixed_t basetextureoffset;
fixed_t baserowoffset;
int oldgametic;

} side_t;

Expand Down
3 changes: 0 additions & 3 deletions src/r_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -816,9 +816,6 @@ void R_RenderPlayerView (player_t* player)
// check for new console commands.
NetUpdate ();

// [crispy] smooth texture scrolling
R_InterpolateTextureOffsets();

// The head node is the last node output.
R_RenderBSPNode (numnodes-1);

Expand Down

0 comments on commit 54eb621

Please sign in to comment.