Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved weapon interpolation #2123

Merged
merged 4 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/am_map.c
Original file line number Diff line number Diff line change
Expand Up @@ -2312,10 +2312,7 @@ void AM_Drawer (void)
}

if (automapoverlay == AM_OVERLAY_OFF)
{
AM_clearFB(mapcolor_back); //jff 1/5/98 background default color
pspr_interp = false;
}
// [Alaux] Dark automap overlay
else if (automapoverlay == AM_OVERLAY_DARK && !MN_MenuIsShaded())
V_ShadeScreen();
Expand Down
2 changes: 0 additions & 2 deletions src/p_mobj.c
Original file line number Diff line number Diff line change
Expand Up @@ -1127,8 +1127,6 @@ void P_SpawnPlayer (mapthing_t* mthing)

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

pspr_interp = false;

// setup gun psprite

P_SetupPsprites (p);
Expand Down
12 changes: 10 additions & 2 deletions src/p_pspr.c
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,12 @@ static void P_BringUpWeapon(player_t *player)

player->pendingweapon = wp_nochange;

pspdef_t *psp = &player->psprites[ps_weapon];

// killough 12/98: prevent pistol from starting visibly at bottom of screen:
player->psprites[ps_weapon].sy = demo_version >= DV_MBF ?
WEAPONBOTTOM+FRACUNIT*2 : WEAPONBOTTOM;
psp->sy = demo_version >= DV_MBF ? WEAPONBOTTOM + FRACUNIT * 2 : WEAPONBOTTOM;

psp->sy2 = psp->oldsy2 = psp->sy;

P_SetPsprite(player, ps_weapon, newstate);
}
Expand Down Expand Up @@ -1118,6 +1121,9 @@ void P_MovePsprites(player_t *player)
const int center_weapon_strict = STRICTMODE(center_weapon);
int i;

psp[ps_weapon].oldsx2 = psp[ps_weapon].sx2;
psp[ps_weapon].oldsy2 = psp[ps_weapon].sy2;

// a null state means not active
// drop tic count and possibly change state
// a -1 tic count never changes
Expand Down Expand Up @@ -1176,6 +1182,8 @@ void P_MovePsprites(player_t *player)

player->psprites[ps_flash].sx2 = player->psprites[ps_weapon].sx2;
player->psprites[ps_flash].sy2 = player->psprites[ps_weapon].sy2;
player->psprites[ps_flash].oldsx2 = player->psprites[ps_weapon].oldsx2;
player->psprites[ps_flash].oldsy2 = player->psprites[ps_weapon].oldsy2;
}

//
Expand Down
2 changes: 2 additions & 0 deletions src/p_pspr.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ typedef struct pspdef_s
// [FG] centered weapon sprite
fixed_t sx2;
fixed_t sy2;
fixed_t oldsx2;
fixed_t oldsy2;
} pspdef_t;

extern int weapon_preferences[2][NUMWEAPONS+1]; // killough 5/2/98
Expand Down
3 changes: 3 additions & 0 deletions src/p_saveg.c
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,9 @@ static void saveg_read_pspdef_t(pspdef_t *str)
str->sx2 = str->sx;
str->sy2 = str->sy;
}

str->oldsx2 = str->sx2;
str->oldsy2 = str->sy2;
}

static void saveg_write_pspdef_t(pspdef_t *str)
Expand Down
2 changes: 0 additions & 2 deletions src/r_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -674,8 +674,6 @@ void R_ExecuteSetViewSize (void)
}

st_refresh_background = true;

pspr_interp = false;
}

//
Expand Down
55 changes: 15 additions & 40 deletions src/r_things.c
Original file line number Diff line number Diff line change
Expand Up @@ -787,8 +787,6 @@ void R_NearbySprites (void)
// R_DrawPSprite
//

boolean pspr_interp = true; // weapon bobbing interpolation

void R_DrawPSprite (pspdef_t *psp)
{
fixed_t tx;
Expand Down Expand Up @@ -821,8 +819,21 @@ void R_DrawPSprite (pspdef_t *psp)
lump = sprframe->lump[0];
flip = (boolean) sprframe->flip[0];

fixed_t sx2, sy2;

if (uncapped && oldleveltime < leveltime)
{
sx2 = LerpFixed(psp->oldsx2, psp->sx2);
sy2 = LerpFixed(psp->oldsy2, psp->sy2);
}
else
{
sx2 = psp->sx2;
sy2 = psp->sy2;
}

// calculate edges of the shape
tx = psp->sx2-160*FRACUNIT; // [FG] centered weapon sprite
tx = sx2 - 160*FRACUNIT; // [FG] centered weapon sprite

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

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

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

// interpolation for weapon bobbing
if (uncapped)
{
static int oldx1, x1_saved;
static fixed_t oldtexturemid, texturemid_saved;
static int oldlump = -1;
static int oldgametic = -1;

if (oldgametic < gametic)
{
oldx1 = x1_saved;
oldtexturemid = texturemid_saved;
oldgametic = gametic;
}

x1_saved = vis->x1;
texturemid_saved = vis->texturemid;

if (lump == oldlump && pspr_interp)
{
int deltax = x2 - vis->x1;
vis->x1 = LerpFixed(oldx1, vis->x1);
vis->x2 = vis->x1 + deltax;
if (vis->x2 >= viewwidth)
vis->x2 = viewwidth - 1;
vis->texturemid = LerpFixed(oldtexturemid, vis->texturemid);
}
else
{
oldx1 = vis->x1;
oldtexturemid = vis->texturemid;
oldlump = lump;
pspr_interp = true;
}
}

// [crispy] free look
vis->texturemid += (centery - viewheight/2) * pspriteiscale;

Expand Down
1 change: 0 additions & 1 deletion src/r_things.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ extern int64_t sprtopscreen; // [FG] 64-bit integer math
extern fixed_t pspritescale;
extern fixed_t pspriteiscale;

extern boolean pspr_interp; // weapon bobbing interpolation
extern boolean flipcorpses;

extern lighttable_t **spritelights;
Expand Down