diff --git a/src/p_pspr.cpp b/src/p_pspr.cpp index 59399dd007..d7da8fa4cb 100644 --- a/src/p_pspr.cpp +++ b/src/p_pspr.cpp @@ -367,9 +367,10 @@ void P_DropWeapon (player_t *player) // //============================================================================ -void P_BobWeapon (player_t *player, pspdef_t *psp, float *x, float *y) +void P_BobWeapon (player_t *player, pspdef_t *psp, float *x, float *y, double ticfrac) { static float curbob; + double xx[2], yy[2]; AWeapon *weapon; float bobtarget; @@ -388,74 +389,79 @@ void P_BobWeapon (player_t *player, pspdef_t *psp, float *x, float *y) float Rangex = weapon->BobRangeX; float Rangey = weapon->BobRangeY; - // Bob the weapon based on movement speed. - FAngle angle = (BobSpeed * 35 / TICRATE*level.time) * (360.f / 8192.f); - - // [RH] Smooth transitions between bobbing and not-bobbing frames. - // This also fixes the bug where you can "stick" a weapon off-center by - // shooting it when it's at the peak of its swing. - bobtarget = float((player->WeaponState & WF_WEAPONBOBBING) ? player->bob : 0.); - if (curbob != bobtarget) + for (int i = 0; i < 2; i++) { - if (fabsf (bobtarget - curbob) <= 1) + // Bob the weapon based on movement speed. + FAngle angle = (BobSpeed * 35 / TICRATE*(level.time - 1 + i)) * (360.f / 8192.f); + + // [RH] Smooth transitions between bobbing and not-bobbing frames. + // This also fixes the bug where you can "stick" a weapon off-center by + // shooting it when it's at the peak of its swing. + bobtarget = float((player->WeaponState & WF_WEAPONBOBBING) ? player->bob : 0.); + if (curbob != bobtarget) { - curbob = bobtarget; - } - else - { - float zoom = MAX (1.f, fabsf (curbob - bobtarget) / 40); - if (curbob > bobtarget) + if (fabsf(bobtarget - curbob) <= 1) { - curbob -= zoom; + curbob = bobtarget; } else { - curbob += zoom; + float zoom = MAX(1.f, fabsf(curbob - bobtarget) / 40); + if (curbob > bobtarget) + { + curbob -= zoom; + } + else + { + curbob += zoom; + } } } - } - if (curbob != 0) - { - float bobx = float(player->bob * Rangex); - float boby = float(player->bob * Rangey); - switch (bobstyle) + if (curbob != 0) { - case AWeapon::BobNormal: - *x = bobx * angle.Cos(); - *y = boby * fabsf(angle.Sin()); - break; - - case AWeapon::BobInverse: - *x = bobx*angle.Cos(); - *y = boby * (1.f - fabsf(angle.Sin())); - break; - - case AWeapon::BobAlpha: - *x = bobx * angle.Sin(); - *y = boby * fabsf(angle.Sin()); - break; - - case AWeapon::BobInverseAlpha: - *x = bobx * angle.Sin(); - *y = boby * (1.f - fabsf(angle.Sin())); - break; - - case AWeapon::BobSmooth: - *x = bobx*angle.Cos(); - *y = 0.5f * (boby * (1.f - ((angle * 2).Cos()))); - break; + float bobx = float(player->bob * Rangex); + float boby = float(player->bob * Rangey); + switch (bobstyle) + { + case AWeapon::BobNormal: + xx[i] = bobx * angle.Cos(); + yy[i] = boby * fabsf(angle.Sin()); + break; - case AWeapon::BobInverseSmooth: - *x = bobx*angle.Cos(); - *y = 0.5f * (boby * (1.f + ((angle * 2).Cos()))); + case AWeapon::BobInverse: + xx[i] = bobx*angle.Cos(); + yy[i] = boby * (1.f - fabsf(angle.Sin())); + break; + + case AWeapon::BobAlpha: + xx[i] = bobx * angle.Sin(); + yy[i] = boby * fabsf(angle.Sin()); + break; + + case AWeapon::BobInverseAlpha: + xx[i] = bobx * angle.Sin(); + yy[i] = boby * (1.f - fabsf(angle.Sin())); + break; + + case AWeapon::BobSmooth: + xx[i] = bobx*angle.Cos(); + yy[i] = 0.5f * (boby * (1.f - ((angle * 2).Cos()))); + break; + + case AWeapon::BobInverseSmooth: + xx[i] = bobx*angle.Cos(); + yy[i] = 0.5f * (boby * (1.f + ((angle * 2).Cos()))); + } + } + else + { + xx[i] = 0; + yy[i] = 0; } } - else - { - *x = 0; - *y = 0; - } + *x = (float)(xx[0] * (1. - ticfrac) + xx[1] * ticfrac); + *y = (float)(yy[0] * (1. - ticfrac) + yy[1] * ticfrac); } //============================================================================ diff --git a/src/p_pspr.h b/src/p_pspr.h index 7045f96a5f..27f1778f37 100644 --- a/src/p_pspr.h +++ b/src/p_pspr.h @@ -87,7 +87,7 @@ void P_CalcSwing (player_t *player); void P_BringUpWeapon (player_t *player); void P_FireWeapon (player_t *player); void P_DropWeapon (player_t *player); -void P_BobWeapon (player_t *player, pspdef_t *psp, float *x, float *y); +void P_BobWeapon (player_t *player, pspdef_t *psp, float *x, float *y, double ticfrac); DAngle P_BulletSlope (AActor *mo, FTranslatedLineTarget *pLineTarget = NULL, int aimflags = 0); void P_GunShot (AActor *mo, bool accurate, PClassActor *pufftype, DAngle pitch); diff --git a/src/r_things.cpp b/src/r_things.cpp index 465b6c30fa..d2c0dcdb4e 100644 --- a/src/r_things.cpp +++ b/src/r_things.cpp @@ -1579,7 +1579,7 @@ void R_DrawPlayerSprites () centery = viewheight >> 1; centeryfrac = centery << FRACBITS; - P_BobWeapon (camera->player, &camera->player->psprites[ps_weapon], &ofsx, &ofsy); + P_BobWeapon (camera->player, &camera->player->psprites[ps_weapon], &ofsx, &ofsy, r_TicFracF); // add all active psprites for (i = 0, psp = camera->player->psprites;