Skip to content

Commit

Permalink
Scroller interpolation
Browse files Browse the repository at this point in the history
  • Loading branch information
dashodanger committed Sep 5, 2024
1 parent f209500 commit c362222
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 83 deletions.
25 changes: 7 additions & 18 deletions source_files/edge/p_setup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1651,8 +1651,10 @@ static void LoadUDMFSectors()
// granular offsets
ss->floor.offset.X += (fx/fx_sc);
ss->floor.offset.Y -= (fy/fy_sc);
ss->floor.old_offset = ss->floor.offset;
ss->ceiling.offset.X += (cx/cx_sc);
ss->ceiling.offset.Y -= (cy/cy_sc);
ss->ceiling.old_offset = ss->ceiling.offset;

ss->floor.image = ImageLookup(floor_tex, kImageNamespaceFlat);

Expand Down Expand Up @@ -1957,20 +1959,14 @@ static void LoadUDMFSideDefs()
sd->bottom.offset.Y += lowy/low_scy;
sd->middle.offset.Y += midy/mid_scy;
sd->top.offset.Y += highy/high_scy;
sd->top.old_offset = sd->top.offset;
sd->middle.old_offset = sd->middle.offset;
sd->bottom.old_offset = sd->bottom.offset;

// handle BOOM colormaps with [242] linetype
sd->top.boom_colormap = colormaps.Lookup(top_tex);
sd->middle.boom_colormap = colormaps.Lookup(middle_tex);
sd->bottom.boom_colormap = colormaps.Lookup(bottom_tex);

/*if (sd->top.image && fabs(sd->top.offset.Y) > sd->top.image->ScaledHeightActual())
sd->top.offset.Y = fmodf(sd->top.offset.Y, sd->top.image->ScaledHeightActual());
if (sd->middle.image && fabs(sd->middle.offset.Y) > sd->middle.image->ScaledHeightActual())
sd->middle.offset.Y = fmodf(sd->middle.offset.Y, sd->middle.image->ScaledHeightActual());
if (sd->bottom.image && fabs(sd->bottom.offset.Y) > sd->bottom.image->ScaledHeightActual())
sd->bottom.offset.Y = fmodf(sd->bottom.offset.Y, sd->bottom.image->ScaledHeightActual());*/
}
else // consume other blocks
{
Expand Down Expand Up @@ -2577,6 +2573,7 @@ static void TransferMapSideDef(const RawSidedef *msd, Side *sd, bool two_sided)
sd->top.translucency = 1.0f;
sd->top.offset.X = AlignedLittleEndianS16(msd->x_offset);
sd->top.offset.Y = AlignedLittleEndianS16(msd->y_offset);
sd->top.old_offset = sd->top.offset;
sd->top.x_matrix.X = 1;
sd->top.x_matrix.Y = 0;
sd->top.y_matrix.X = 0;
Expand Down Expand Up @@ -2618,16 +2615,8 @@ static void TransferMapSideDef(const RawSidedef *msd, Side *sd, bool two_sided)
{
sd->middle_mask_offset = sd->middle.offset.Y;
sd->middle.offset.Y = 0;
sd->middle.old_offset.Y = 0;
}

/*if (sd->top.image && fabs(sd->top.offset.Y) > sd->top.image->ScaledHeightActual())
sd->top.offset.Y = fmodf(sd->top.offset.Y, sd->top.image->ScaledHeightActual());
if (sd->middle.image && fabs(sd->middle.offset.Y) > sd->middle.image->ScaledHeightActual())
sd->middle.offset.Y = fmodf(sd->middle.offset.Y, sd->middle.image->ScaledHeightActual());
if (sd->bottom.image && fabs(sd->bottom.offset.Y) > sd->bottom.image->ScaledHeightActual())
sd->bottom.offset.Y = fmodf(sd->bottom.offset.Y, sd->bottom.image->ScaledHeightActual());*/
}

static void LoadSideDefs(int lump)
Expand Down
91 changes: 37 additions & 54 deletions source_files/edge/p_spec.cc
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,8 @@ static void P_LineEffect(Line *target, Line *source, const LineType *special)
{
source->side[0]->middle.offset.X = 0;
source->side[0]->bottom.offset.X = 0;
source->side[0]->middle.old_offset.X = 0;
source->side[0]->bottom.old_offset.X = 0;
}
}

Expand Down Expand Up @@ -920,6 +922,7 @@ static void SectorEffect(Sector *target, Line *source, const LineType *special)
target->floor.offset.X += source->side[0]->bottom.offset.X;
target->floor.offset.Y += source->side[0]->bottom.offset.Y;
}
target->floor.old_offset = target->floor.offset;
target->floor.rotation = angle;
}
if (special->sector_effect_ & kSectorEffectTypeAlignCeiling)
Expand All @@ -932,6 +935,7 @@ static void SectorEffect(Sector *target, Line *source, const LineType *special)
target->ceiling.offset.X += source->side[0]->bottom.offset.X;
target->ceiling.offset.Y += source->side[0]->bottom.offset.Y;
}
target->ceiling.old_offset = target->ceiling.offset;
target->ceiling.rotation = angle;
}

Expand Down Expand Up @@ -2272,36 +2276,27 @@ void UpdateSpecials()
{
if (ld->side[0]->top.image)
{
ld->side[0]->top.offset.X = fmod(
ld->side[0]->top.offset.X + (ld->side[0]->top.scroll.X + ld->side[0]->top.net_scroll.X) * factor,
ld->side[0]->top.image->actual_width_);
ld->side[0]->top.offset.Y = fmod(
ld->side[0]->top.offset.Y + (ld->side[0]->top.scroll.Y + ld->side[0]->top.net_scroll.Y) * factor,
ld->side[0]->top.image->actual_height_);
ld->side[0]->top.old_offset = ld->side[0]->top.offset;
ld->side[0]->top.offset.X = ld->side[0]->top.offset.X + (ld->side[0]->top.scroll.X + ld->side[0]->top.net_scroll.X) * factor;
ld->side[0]->top.offset.Y = ld->side[0]->top.offset.Y + (ld->side[0]->top.scroll.Y + ld->side[0]->top.net_scroll.Y) * factor;
ld->side[0]->top.net_scroll = {{0, 0}};
}
if (ld->side[0]->middle.image)
{
ld->side[0]->middle.offset.X =
fmod(ld->side[0]->middle.offset.X +
(ld->side[0]->middle.scroll.X + ld->side[0]->middle.net_scroll.X) * factor,
ld->side[0]->middle.image->actual_width_);
ld->side[0]->middle.offset.Y =
fmod(ld->side[0]->middle.offset.Y +
(ld->side[0]->middle.scroll.Y + ld->side[0]->middle.net_scroll.Y) * factor,
ld->side[0]->middle.image->actual_height_);
ld->side[0]->middle.old_offset = ld->side[0]->middle.offset;
ld->side[0]->middle.offset.X = ld->side[0]->middle.offset.X +
(ld->side[0]->middle.scroll.X + ld->side[0]->middle.net_scroll.X) * factor;
ld->side[0]->middle.offset.Y = ld->side[0]->middle.offset.Y +
(ld->side[0]->middle.scroll.Y + ld->side[0]->middle.net_scroll.Y) * factor;
ld->side[0]->middle.net_scroll = {{0, 0}};
}
if (ld->side[0]->bottom.image)
{
ld->side[0]->bottom.offset.X =
fmod(ld->side[0]->bottom.offset.X +
(ld->side[0]->bottom.scroll.X + ld->side[0]->bottom.net_scroll.X) * factor,
ld->side[0]->bottom.image->actual_width_);
ld->side[0]->bottom.offset.Y =
fmod(ld->side[0]->bottom.offset.Y +
(ld->side[0]->bottom.scroll.Y + ld->side[0]->bottom.net_scroll.Y) * factor,
ld->side[0]->bottom.image->actual_height_);
ld->side[0]->bottom.old_offset = ld->side[0]->bottom.offset;
ld->side[0]->bottom.offset.X = ld->side[0]->bottom.offset.X +
(ld->side[0]->bottom.scroll.X + ld->side[0]->bottom.net_scroll.X) * factor;
ld->side[0]->bottom.offset.Y = ld->side[0]->bottom.offset.Y +
(ld->side[0]->bottom.scroll.Y + ld->side[0]->bottom.net_scroll.Y) * factor;
ld->side[0]->bottom.net_scroll = {{0, 0}};
}
}
Expand All @@ -2310,36 +2305,27 @@ void UpdateSpecials()
{
if (ld->side[1]->top.image)
{
ld->side[1]->top.offset.X = fmod(
ld->side[1]->top.offset.X + (ld->side[1]->top.scroll.X + ld->side[1]->top.net_scroll.X) * factor,
ld->side[1]->top.image->actual_width_);
ld->side[1]->top.offset.Y = fmod(
ld->side[1]->top.offset.Y + (ld->side[1]->top.scroll.Y + ld->side[1]->top.net_scroll.Y) * factor,
ld->side[1]->top.image->actual_height_);
ld->side[1]->top.old_offset = ld->side[1]->top.offset;
ld->side[1]->top.offset.X = ld->side[1]->top.offset.X + (ld->side[1]->top.scroll.X + ld->side[1]->top.net_scroll.X) * factor;
ld->side[1]->top.offset.Y = ld->side[1]->top.offset.Y + (ld->side[1]->top.scroll.Y + ld->side[1]->top.net_scroll.Y) * factor;
ld->side[1]->top.net_scroll = {{0, 0}};
}
if (ld->side[1]->middle.image)
{
ld->side[1]->middle.offset.X =
fmod(ld->side[1]->middle.offset.X +
(ld->side[1]->middle.scroll.X + ld->side[1]->middle.net_scroll.X) * factor,
ld->side[1]->middle.image->actual_width_);
ld->side[1]->middle.offset.Y =
fmod(ld->side[1]->middle.offset.Y +
(ld->side[1]->middle.scroll.Y + ld->side[1]->middle.net_scroll.Y) * factor,
ld->side[1]->middle.image->actual_height_);
ld->side[1]->middle.old_offset = ld->side[1]->middle.offset;
ld->side[1]->middle.offset.X = ld->side[1]->middle.offset.X +
(ld->side[1]->middle.scroll.X + ld->side[1]->middle.net_scroll.X) * factor;
ld->side[1]->middle.offset.Y = ld->side[1]->middle.offset.Y +
(ld->side[1]->middle.scroll.Y + ld->side[1]->middle.net_scroll.Y) * factor;
ld->side[1]->middle.net_scroll = {{0, 0}};
}
if (ld->side[1]->bottom.image)
{
ld->side[1]->bottom.offset.X =
fmod(ld->side[1]->bottom.offset.X +
(ld->side[1]->bottom.scroll.X + ld->side[1]->bottom.net_scroll.X) * factor,
ld->side[1]->bottom.image->actual_width_);
ld->side[1]->bottom.offset.Y =
fmod(ld->side[1]->bottom.offset.Y +
(ld->side[1]->bottom.scroll.Y + ld->side[1]->bottom.net_scroll.Y) * factor,
ld->side[1]->bottom.image->actual_height_);
ld->side[1]->bottom.old_offset = ld->side[1]->bottom.offset;
ld->side[1]->bottom.offset.X = ld->side[1]->bottom.offset.X +
(ld->side[1]->bottom.scroll.X + ld->side[1]->bottom.net_scroll.X) * factor;
ld->side[1]->bottom.offset.Y = ld->side[1]->bottom.offset.Y +
(ld->side[1]->bottom.scroll.Y + ld->side[1]->bottom.net_scroll.Y) * factor;
ld->side[1]->bottom.net_scroll = {{0, 0}};
}
}
Expand Down Expand Up @@ -2426,16 +2412,13 @@ void UpdateSpecials()
sec->properties.push.Z = sec->properties.old_push.Z;
}

sec->floor.offset.X = fmod(sec->floor.offset.X + (sec->floor.scroll.X + sec->floor.net_scroll.X) * factor,
sec->floor.image->actual_width_);
sec->floor.offset.Y = fmod(sec->floor.offset.Y + (sec->floor.scroll.Y + sec->floor.net_scroll.Y) * factor,
sec->floor.image->actual_height_);
sec->ceiling.offset.X =
fmod(sec->ceiling.offset.X + (sec->ceiling.scroll.X + sec->ceiling.net_scroll.X) * factor,
sec->ceiling.image->actual_width_);
sec->ceiling.offset.Y =
fmod(sec->ceiling.offset.Y + (sec->ceiling.scroll.Y + sec->ceiling.net_scroll.Y) * factor,
sec->ceiling.image->actual_height_);
sec->floor.old_offset = sec->floor.offset;
sec->ceiling.old_offset = sec->ceiling.offset;

sec->floor.offset.X = sec->floor.offset.X + (sec->floor.scroll.X + sec->floor.net_scroll.X) * factor;
sec->floor.offset.Y = sec->floor.offset.Y + (sec->floor.scroll.Y + sec->floor.net_scroll.Y) * factor;
sec->ceiling.offset.X = sec->ceiling.offset.X + (sec->ceiling.scroll.X + sec->ceiling.net_scroll.X) * factor;
sec->ceiling.offset.Y = sec->ceiling.offset.Y + (sec->ceiling.scroll.Y + sec->ceiling.net_scroll.Y) * factor;
sec->properties.push.X = sec->properties.push.X + sec->properties.net_push.X;
sec->properties.push.Y = sec->properties.push.Y + sec->properties.net_push.Y;

Expand Down
1 change: 1 addition & 0 deletions source_files/edge/r_defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ struct MapSurface

// current offset and scrolling deltas (world coords)
HMM_Vec2 offset;
HMM_Vec2 old_offset;
HMM_Vec2 scroll;

HMM_Vec2 net_scroll = {{0, 0}};
Expand Down
37 changes: 26 additions & 11 deletions source_files/edge/r_render.cc
Original file line number Diff line number Diff line change
Expand Up @@ -819,9 +819,6 @@ static void DrawWallPart(DrawFloor *dfloor, float x1, float y1, float lz1, float

(void)opaque;

// if (! props)
// props = surf->override_properties ? surf->override_properties :
// dfloor->properties;
if (surf->override_properties)
props = surf->override_properties;

Expand Down Expand Up @@ -1000,8 +997,8 @@ static void DrawWallPart(DrawFloor *dfloor, float x1, float y1, float lz1, float

if (surf->image && surf->image->liquid_type_ > kLiquidImageNone && swirling_flats == kLiquidSwirlParallax)
{
data.tx0 = surf->offset.X + 25;
data.ty0 = surf->offset.Y + 25;
data.tx0 = data.tx0 + 25;
data.ty0 = data.ty0 + 25;
swirl_pass = 2;
int old_blend = data.blending;
float old_dt = data.trans;
Expand Down Expand Up @@ -1212,8 +1209,19 @@ static void DrawTile(Seg *seg, DrawFloor *dfloor, float lz1, float lz2, float rz
if (!image)
image = ImageForHomDetect();

float tex_top_h = tex_z + surf->offset.Y;
float x_offset = surf->offset.X;
float offx, offy;

if (uncapped_frames.d_ && !AlmostEquals(surf->old_offset.X, surf->offset.X) && !paused && !menu_active && !time_stop_active && !erraticism_active)
offx = fmod(HMM_Lerp(surf->old_offset.X, fractional_tic, surf->offset.X), surf->image->actual_width_);
else
offx = surf->offset.X;
if (uncapped_frames.d_ && !AlmostEquals(surf->old_offset.Y, surf->offset.Y) && !paused && !menu_active && !time_stop_active && !erraticism_active)
offy = fmod(HMM_Lerp(surf->old_offset.Y, fractional_tic, surf->offset.Y), surf->image->actual_height_);
else
offy = surf->offset.Y;

float tex_top_h = tex_z + offy;
float x_offset = offx;

if (flags & kWallTileExtraX)
{
Expand Down Expand Up @@ -1785,6 +1793,7 @@ static void EmulateFloodPlane(const DrawFloor *dfloor, const Sector *flood_ref,

data.plane_h = (face_dir > 0) ? h2 : h1;

// I don't think we need interpolation here...are there Boom scrollers which are also flat flooding hacks? - Dasho
data.tx0 = surf->offset.X;
data.ty0 = surf->offset.Y;
data.image_w = surf->image->ScaledWidthActual();
Expand Down Expand Up @@ -2501,8 +2510,14 @@ static void RenderPlane(DrawFloor *dfloor, float h, MapSurface *surf, int face_d
data.v_count = v_count;
data.vertices = vertices;
data.R = data.G = data.B = 1.0f;
data.tx0 = surf->offset.X;
data.ty0 = surf->offset.Y;
if (uncapped_frames.d_ && !AlmostEquals(surf->old_offset.X, surf->offset.X) && !paused && !menu_active && !time_stop_active && !erraticism_active)
data.tx0 = fmod(HMM_Lerp(surf->old_offset.X, fractional_tic, surf->offset.X), surf->image->actual_width_);
else
data.tx0 = surf->offset.X;
if (uncapped_frames.d_ && !AlmostEquals(surf->old_offset.Y, surf->offset.Y) && !paused && !menu_active && !time_stop_active && !erraticism_active)
data.ty0 = fmod(HMM_Lerp(surf->old_offset.Y, fractional_tic, surf->offset.Y), surf->image->actual_height_);
else
data.ty0 = surf->offset.Y;
data.image_w = surf->image->ScaledWidthActual();
data.image_h = surf->image->ScaledHeightActual();
data.x_mat = surf->x_matrix;
Expand Down Expand Up @@ -2544,8 +2559,8 @@ static void RenderPlane(DrawFloor *dfloor, float h, MapSurface *surf, int face_d
if (surf->image->liquid_type_ > kLiquidImageNone &&
swirling_flats == kLiquidSwirlParallax) // Kept as an example for future effects
{
data.tx0 = surf->offset.X + 25;
data.ty0 = surf->offset.Y + 25;
data.tx0 = data.tx0 + 25;
data.ty0 = data.ty0 + 25;
swirl_pass = 2;
int old_blend = data.blending;
float old_dt = data.trans;
Expand Down

0 comments on commit c362222

Please sign in to comment.