Skip to content

Commit af76ea9

Browse files
MrAlauxrfomin
andauthored
Improved weapon interpolation (#2123)
* Improved weapon interpolation This approach, similar to that of mobj interpolation, eliminates some issues from the old approach, namely interpolation having to be reset upon sprite changes and view-size changes. * rfomin's patch: remove `pspr_interp` Co-Authored-By: Roman Fomin <[email protected]> * Assign `s#2` to `olds#2` when loading savegames * Assign to `olds#2` properly --------- Co-authored-by: Roman Fomin <[email protected]>
1 parent 501a54c commit af76ea9

File tree

8 files changed

+30
-50
lines changed

8 files changed

+30
-50
lines changed

src/am_map.c

-3
Original file line numberDiff line numberDiff line change
@@ -2312,10 +2312,7 @@ void AM_Drawer (void)
23122312
}
23132313

23142314
if (automapoverlay == AM_OVERLAY_OFF)
2315-
{
23162315
AM_clearFB(mapcolor_back); //jff 1/5/98 background default color
2317-
pspr_interp = false;
2318-
}
23192316
// [Alaux] Dark automap overlay
23202317
else if (automapoverlay == AM_OVERLAY_DARK && !MN_MenuIsShaded())
23212318
V_ShadeScreen();

src/p_mobj.c

-2
Original file line numberDiff line numberDiff line change
@@ -1127,8 +1127,6 @@ void P_SpawnPlayer (mapthing_t* mthing)
11271127

11281128
p->momx = p->momy = 0; // killough 10/98: initialize bobbing to 0.
11291129

1130-
pspr_interp = false;
1131-
11321130
// setup gun psprite
11331131

11341132
P_SetupPsprites (p);

src/p_pspr.c

+10-2
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,12 @@ static void P_BringUpWeapon(player_t *player)
167167

168168
player->pendingweapon = wp_nochange;
169169

170+
pspdef_t *psp = &player->psprites[ps_weapon];
171+
170172
// killough 12/98: prevent pistol from starting visibly at bottom of screen:
171-
player->psprites[ps_weapon].sy = demo_version >= DV_MBF ?
172-
WEAPONBOTTOM+FRACUNIT*2 : WEAPONBOTTOM;
173+
psp->sy = demo_version >= DV_MBF ? WEAPONBOTTOM + FRACUNIT * 2 : WEAPONBOTTOM;
174+
175+
psp->sy2 = psp->oldsy2 = psp->sy;
173176

174177
P_SetPsprite(player, ps_weapon, newstate);
175178
}
@@ -1118,6 +1121,9 @@ void P_MovePsprites(player_t *player)
11181121
const int center_weapon_strict = STRICTMODE(center_weapon);
11191122
int i;
11201123

1124+
psp[ps_weapon].oldsx2 = psp[ps_weapon].sx2;
1125+
psp[ps_weapon].oldsy2 = psp[ps_weapon].sy2;
1126+
11211127
// a null state means not active
11221128
// drop tic count and possibly change state
11231129
// a -1 tic count never changes
@@ -1176,6 +1182,8 @@ void P_MovePsprites(player_t *player)
11761182

11771183
player->psprites[ps_flash].sx2 = player->psprites[ps_weapon].sx2;
11781184
player->psprites[ps_flash].sy2 = player->psprites[ps_weapon].sy2;
1185+
player->psprites[ps_flash].oldsx2 = player->psprites[ps_weapon].oldsx2;
1186+
player->psprites[ps_flash].oldsy2 = player->psprites[ps_weapon].oldsy2;
11791187
}
11801188

11811189
//

src/p_pspr.h

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ typedef struct pspdef_s
6060
// [FG] centered weapon sprite
6161
fixed_t sx2;
6262
fixed_t sy2;
63+
fixed_t oldsx2;
64+
fixed_t oldsy2;
6365
} pspdef_t;
6466

6567
extern int weapon_preferences[2][NUMWEAPONS+1]; // killough 5/2/98

src/p_saveg.c

+3
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,9 @@ static void saveg_read_pspdef_t(pspdef_t *str)
771771
str->sx2 = str->sx;
772772
str->sy2 = str->sy;
773773
}
774+
775+
str->oldsx2 = str->sx2;
776+
str->oldsy2 = str->sy2;
774777
}
775778

776779
static void saveg_write_pspdef_t(pspdef_t *str)

src/r_main.c

-2
Original file line numberDiff line numberDiff line change
@@ -674,8 +674,6 @@ void R_ExecuteSetViewSize (void)
674674
}
675675

676676
st_refresh_background = true;
677-
678-
pspr_interp = false;
679677
}
680678

681679
//

src/r_things.c

+15-40
Original file line numberDiff line numberDiff line change
@@ -787,8 +787,6 @@ void R_NearbySprites (void)
787787
// R_DrawPSprite
788788
//
789789

790-
boolean pspr_interp = true; // weapon bobbing interpolation
791-
792790
void R_DrawPSprite (pspdef_t *psp)
793791
{
794792
fixed_t tx;
@@ -821,8 +819,21 @@ void R_DrawPSprite (pspdef_t *psp)
821819
lump = sprframe->lump[0];
822820
flip = (boolean) sprframe->flip[0];
823821

822+
fixed_t sx2, sy2;
823+
824+
if (uncapped && oldleveltime < leveltime)
825+
{
826+
sx2 = LerpFixed(psp->oldsx2, psp->sx2);
827+
sy2 = LerpFixed(psp->oldsy2, psp->sy2);
828+
}
829+
else
830+
{
831+
sx2 = psp->sx2;
832+
sy2 = psp->sy2;
833+
}
834+
824835
// calculate edges of the shape
825-
tx = psp->sx2-160*FRACUNIT; // [FG] centered weapon sprite
836+
tx = sx2 - 160*FRACUNIT; // [FG] centered weapon sprite
826837

827838
tx -= spriteoffset[lump];
828839
x1 = (centerxfrac + FixedMul (tx,pspritescale))>>FRACBITS;
@@ -845,7 +856,7 @@ void R_DrawPSprite (pspdef_t *psp)
845856

846857
// killough 12/98: fix psprite positioning problem
847858
vis->texturemid = (BASEYCENTER<<FRACBITS) /* + FRACUNIT/2 */ -
848-
(psp->sy2-spritetopoffset[lump]); // [FG] centered weapon sprite
859+
(sy2 - spritetopoffset[lump]); // [FG] centered weapon sprite
849860

850861
vis->x1 = x1 < 0 ? 0 : x1;
851862
vis->x2 = x2 >= viewwidth ? viewwidth-1 : x2;
@@ -883,42 +894,6 @@ void R_DrawPSprite (pspdef_t *psp)
883894
}
884895
vis->brightmap = R_BrightmapForState(psp->state - states);
885896

886-
// interpolation for weapon bobbing
887-
if (uncapped)
888-
{
889-
static int oldx1, x1_saved;
890-
static fixed_t oldtexturemid, texturemid_saved;
891-
static int oldlump = -1;
892-
static int oldgametic = -1;
893-
894-
if (oldgametic < gametic)
895-
{
896-
oldx1 = x1_saved;
897-
oldtexturemid = texturemid_saved;
898-
oldgametic = gametic;
899-
}
900-
901-
x1_saved = vis->x1;
902-
texturemid_saved = vis->texturemid;
903-
904-
if (lump == oldlump && pspr_interp)
905-
{
906-
int deltax = x2 - vis->x1;
907-
vis->x1 = LerpFixed(oldx1, vis->x1);
908-
vis->x2 = vis->x1 + deltax;
909-
if (vis->x2 >= viewwidth)
910-
vis->x2 = viewwidth - 1;
911-
vis->texturemid = LerpFixed(oldtexturemid, vis->texturemid);
912-
}
913-
else
914-
{
915-
oldx1 = vis->x1;
916-
oldtexturemid = vis->texturemid;
917-
oldlump = lump;
918-
pspr_interp = true;
919-
}
920-
}
921-
922897
// [crispy] free look
923898
vis->texturemid += (centery - viewheight/2) * pspriteiscale;
924899

src/r_things.h

-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ extern int64_t sprtopscreen; // [FG] 64-bit integer math
3939
extern fixed_t pspritescale;
4040
extern fixed_t pspriteiscale;
4141

42-
extern boolean pspr_interp; // weapon bobbing interpolation
4342
extern boolean flipcorpses;
4443

4544
extern lighttable_t **spritelights;

0 commit comments

Comments
 (0)