# HG changeset patch # User Adam Kaminski # Date 1623472213 14400 # Sat Jun 12 00:30:13 2021 -0400 # Node ID 7ef22cb61f260d5f66c40414f7ab67845bd41eb4 # Parent 11d836e7dc0ad896337f08de3f202ec2fe54768e Added CVars from ZCC that customize how the weapon bobs, sways, and offsets based on the player's pitch, or whether or not to bob the screen itself while leaving the weapon bob unaffected. diff -r 11d836e7dc0a -r 7ef22cb61f26 src/g_shared/a_pickups.h --- a/src/g_shared/a_pickups.h Fri Jun 11 23:13:16 2021 -0400 +++ b/src/g_shared/a_pickups.h Sat Jun 12 00:30:13 2021 -0400 @@ -333,7 +333,9 @@ BobAlpha, BobInverseAlpha, BobSmooth, - BobInverseSmooth + BobInverseSmooth, + // [AK] Quake-styled bobbing originally made by Dark-Assassin. + BobQuake }; protected: diff -r 11d836e7dc0a -r 7ef22cb61f26 src/p_pspr.cpp --- a/src/p_pspr.cpp Fri Jun 11 23:13:16 2021 -0400 +++ b/src/p_pspr.cpp Sat Jun 12 00:30:13 2021 -0400 @@ -37,6 +37,7 @@ #include "sv_commands.h" #include "unlagged.h" #include "g_game.h" +#include "p_tick.h" // MACROS ------------------------------------------------------------------ @@ -78,6 +79,40 @@ } } +// [AK] CVars that control how the weapon bobs, sways, or offsets based on the player's pitch. +CVAR( Bool, cl_alwaysbob, false, CVAR_ARCHIVE ) +CVAR( Bool, cl_usecustombob, false, CVAR_ARCHIVE ) +CVAR( Float, cl_bobspeed, 1.0f, CVAR_ARCHIVE ) +CVAR( Float, cl_swayspeed, 0.0f, CVAR_ARCHIVE ) +CVAR( Float, cl_viewpitchoffset, 0.0f, CVAR_ARCHIVE ) + +// [AK] Allows a different bob style to be used than what the weapon uses. +CUSTOM_CVAR( Int, cl_bobstyle, AWeapon::BobNormal, CVAR_ARCHIVE ) +{ + if (self < AWeapon::BobNormal) + self = AWeapon::BobNormal; + else if ( self > AWeapon::BobQuake ) + self = AWeapon::BobQuake; +} + +// [AK] Specifies how to sway the weapon depending on how the player looks around. +CUSTOM_CVAR( Int, cl_swaystyle, WEAPON_SWAY_NORMAL, CVAR_ARCHIVE ) +{ + if (self < WEAPON_SWAY_NORMAL) + self = WEAPON_SWAY_NORMAL; + else if (self > WEAPON_SWAY_HORIZONTALONLY) + self = WEAPON_SWAY_HORIZONTALONLY; +} + +// [AK] Controls which parts of the player's pitch affect the offset of the weapon and how. +CUSTOM_CVAR( Int, cl_viewpitchstyle, WEAPON_PITCH_FULL, CVAR_ARCHIVE ) +{ + if (self < WEAPON_PITCH_FULL) + self = WEAPON_PITCH_FULL; + else if (self > WEAPON_PITCH_LOWERANDUPPER) + self = WEAPON_PITCH_LOWERANDUPPER; +} + // PRIVATE DATA DEFINITIONS ------------------------------------------------ static FRandom pr_wpnreadysnd ("WpnReadySnd"); @@ -447,6 +482,8 @@ void P_BobWeapon (player_t *player, pspdef_t *psp, fixed_t *x, fixed_t *y) { static fixed_t curbob; + // [AK] The position of the weapon while it's swaying (0 = x, 1 = y). + static fixed_t swaypos[2]; AWeapon *weapon; fixed_t bobtarget; @@ -464,8 +501,9 @@ } // [XA] Get the current weapon's bob properties. - int bobstyle = weapon->BobStyle; - int bobspeed = (weapon->BobSpeed * 128) >> 16; + // [AK] Adjust the bob style and speed to the client's preference if cl_usecustombob is enabled. + int bobstyle = cl_usecustombob ? cl_bobstyle : weapon->BobStyle; + int bobspeed = ((cl_usecustombob ? FLOAT2FIXED(cl_bobspeed) : weapon->BobSpeed) * 128) >> 16; fixed_t rangex = weapon->BobRangeX; fixed_t rangey = weapon->BobRangeY; @@ -475,7 +513,8 @@ // [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 = (player->WeaponState & WF_WEAPONBOBBING) ? player->bob : 0; + // [AK] Keep bobbing the weapon while firing if cl_alwaysbob is enabled. + bobtarget = ((player->WeaponState & WF_WEAPONBOBBING) || (cl_alwaysbob)) ? player->bob : 0; if (curbob != bobtarget) { if (abs (bobtarget - curbob) <= 1*FRACUNIT) @@ -530,6 +569,13 @@ case AWeapon::BobInverseSmooth: *x = FixedMul(bobx, finecosine[angle]); *y = (FixedMul(boby, finecosine[angle*2 & (FINEANGLES-1)]) + boby) / 2; + break; + + // [AK] Quake-styled bobbing originally made by Dark-Assassin. + case AWeapon::BobQuake: + *x = 0; + *y = FixedMul(boby, finesine[angle & (FINEANGLES/2-1)]); + break; } } else @@ -537,6 +583,76 @@ *x = 0; *y = 0; } + + // [AK] Sway the weapon if the multiplier is a non-zero value. + if (cl_swayspeed != 0.0f) + { + // [AK] Don't readjust the position of the sprite while the ticker is paused. + if ((paused == false) && (P_CheckTickerPaused() == false)) + { + fixed_t nswaypos[2]; + nswaypos[0] = FLOAT2FIXED(static_cast(player->cmd.ucmd.yaw) / 128.0f / cl_swayspeed); + nswaypos[1] = FLOAT2FIXED(static_cast(player->cmd.ucmd.pitch) / 128.0f / cl_swayspeed); + + for (int i = 0; i <= 1; i++) + { + if (abs(nswaypos[i] - swaypos[i]) <= 1024) + { + swaypos[i] = nswaypos[i]; + } + else + { + fixed_t zoom = MAX(1024, abs(swaypos[i] - nswaypos[i]) / 40); + swaypos[i] += zoom * (swaypos[i] > nswaypos[i] ? -1 : 1); + } + } + } + + *x += swaypos[0]; + + switch (cl_swaystyle) + { + case WEAPON_SWAY_NORMAL: + *y += swaypos[1]; + break; + + case WEAPON_SWAY_DOWNONLY: + *y += MAX(0, swaypos[1]); + break; + + case WEAPON_SWAY_UPONLY: + *y += MIN(0, swaypos[1]); + break; + } + } + + // [AK] Offset the weapon based on the player's pitch if the multiplier is a non-zero value. + if (cl_viewpitchoffset != 0.0f) + { + fixed_t halfmin = FIXED_MIN >> 1; + fixed_t value; + + switch (cl_viewpitchstyle) + { + case WEAPON_PITCH_FULL: + value = FixedDiv(halfmin + player->mo->pitch, FIXED_MIN); + break; + + case WEAPON_PITCH_LOWERONLY: + value = FixedDiv(MIN(0, player->mo->pitch), halfmin); + break; + + case WEAPON_PITCH_UPPERONLY: + value = -FixedDiv(MAX(0, player->mo->pitch), halfmin); + break; + + case WEAPON_PITCH_LOWERANDUPPER: + value = -FixedDiv(abs(player->mo->pitch), halfmin); + break; + } + + *y -= FixedMul(value, FLOAT2FIXED(cl_viewpitchoffset)) + MIN(0, FLOAT2FIXED(cl_viewpitchoffset)); + } } //============================================================================ diff -r 11d836e7dc0a -r 7ef22cb61f26 src/p_pspr.h --- a/src/p_pspr.h Fri Jun 11 23:13:16 2021 -0400 +++ b/src/p_pspr.h Sat Jun 12 00:30:13 2021 -0400 @@ -52,6 +52,24 @@ } psprnum_t; +// [AK] Enums for all weapon sway styles (used for cl_swaystyle). +enum +{ + WEAPON_SWAY_NORMAL, + WEAPON_SWAY_DOWNONLY, + WEAPON_SWAY_UPONLY, + WEAPON_SWAY_HORIZONTALONLY, +}; + +// [AK] Enums for all weapon pitch offset styles (used for cl_viewpitchstyle). +enum +{ + WEAPON_PITCH_FULL, + WEAPON_PITCH_LOWERONLY, + WEAPON_PITCH_UPPERONLY, + WEAPON_PITCH_LOWERANDUPPER, +}; + /* inline FArchive &operator<< (FArchive &arc, psprnum_t &i) { diff -r 11d836e7dc0a -r 7ef22cb61f26 src/p_user.cpp --- a/src/p_user.cpp Fri Jun 11 23:13:16 2021 -0400 +++ b/src/p_user.cpp Sat Jun 12 00:30:13 2021 -0400 @@ -92,6 +92,9 @@ static TArray PredictionSectorListBackup; static TArray PredictionSector_sprev_Backup; +// [Leo] Stops the screen from bobbing but not the weapon itself. +CVAR (Bool, cl_viewbob, true, CVAR_ARCHIVE) + // [Dusk] Determine speed spectators will move at CUSTOM_CVAR (Float, cl_spectatormove, 1.0, CVAR_ARCHIVE|CVAR_GLOBALCONFIG) { if (self > 100.0) @@ -2785,7 +2788,8 @@ { bob = 0; } - player->viewz = player->mo->z + player->viewheight + bob; + // [AK] Don't bob the screen if cl_viewbob is disabled. + player->viewz = player->mo->z + player->viewheight + (cl_viewbob ? bob : 0); if (player->mo->floorclip && player->playerstate != PST_DEAD && player->mo->z <= player->mo->floorz) { diff -r 11d836e7dc0a -r 7ef22cb61f26 wadsrc/static/menudef.za --- a/wadsrc/static/menudef.za Fri Jun 11 23:13:16 2021 -0400 +++ b/wadsrc/static/menudef.za Sat Jun 12 00:30:13 2021 -0400 @@ -448,6 +448,33 @@ 3, "Use PWO" } +OptionValue "ZA_WeaponBobStyle" +{ + 0, "Normal" + 1, "Inversed normal" + 2, "Alpha-style" + 3, "Inversed alpha-style" + 4, "Smooth" + 5, "Inversed smooth" + 6, "Quake-style" +} + +OptionValue "ZA_WeaponSwayStyle" +{ + 0, "Normal" + 1, "Down only" + 2, "Up only" + 3, "Horizontally only" +} + +OptionValue "ZA_WeaponPitchStyle" +{ + 0, "Full" + 1, "Lower-half only" + 2, "Upper-half only" + 3, "Both upper and lower" +} + OptionMenu ZA_WeaponSetup { Title "WEAPON SETUP" @@ -456,6 +483,18 @@ Option "Switch on pickup", "switchonpickup", "ZA_SwitchOnPickup" Option "Switch without ammo", "cl_noammoswitch", "YesNo" Option "Railgun color", "railcolor", "ZA_RailgunColors" + StaticText " " + Option "Always bob weapon", "cl_alwaysbob", "YesNo" + Option "Allow screen bob", "cl_viewbob", "YesNo" + Option "Use custom bob", "cl_usecustombob", "YesNo" + Option "Bob style", "cl_bobstyle", "ZA_WeaponBobStyle" + Slider "Bob speed", "cl_bobspeed", 0.0, 2.0, 0.1 + StaticText " " + Option "Sway weapon", "cl_swaystyle", "ZA_WeaponSwayStyle" + Slider "Sway multiplier", "cl_swayspeed", -5.0, 5.0, 0.5 + StaticText " " + Option "Offset weapon pitch", "cl_viewpitchstyle", "ZA_WeaponPitchStyle" + Slider "Offset multiplier", "cl_viewpitchoffset", -16.0, 16.0, 1.0 Class WeaponSetupMenu }