From 989a355f8081958f8e2222b0497cd0fe99b7cb7a Mon Sep 17 00:00:00 2001 From: Boondorl Date: Sat, 14 Jun 2025 10:45:38 -0400 Subject: [PATCH] Moved BobTimer to playerinfo This was a bit too invasive for mods that used full PlayerThink overrides. --- src/playsim/d_player.h | 1 + src/playsim/p_user.cpp | 5 +++++ wadsrc/static/zscript/actors/player/player.zs | 9 ++++----- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/playsim/d_player.h b/src/playsim/d_player.h index 025355d95..536da4aed 100644 --- a/src/playsim/d_player.h +++ b/src/playsim/d_player.h @@ -335,6 +335,7 @@ public: double viewheight = 0; // base height above floor for viewz double deltaviewheight = 0; // squat speed. double bob = 0; // bounded/scaled total velocity + int BobTimer = 0; // killough 10/98: used for realistic bobbing (i.e. not simply overall speed) // mo->velx and mo->vely represent true velocity experienced by player. diff --git a/src/playsim/p_user.cpp b/src/playsim/p_user.cpp index 28dd271b7..ccc75998e 100644 --- a/src/playsim/p_user.cpp +++ b/src/playsim/p_user.cpp @@ -284,6 +284,7 @@ void player_t::CopyFrom(player_t &p, bool copyPSP) viewheight = p.viewheight; deltaviewheight = p.deltaviewheight; bob = p.bob; + BobTimer = p.BobTimer; Vel = p.Vel; centering = p.centering; turnticks = p.turnticks; @@ -1294,6 +1295,8 @@ void P_PlayerThink (player_t *player) player->LastSafePos = player->mo->Pos(); } + ++player->BobTimer; + // Bots do not think in freeze mode. if (player->mo->Level->isFrozen() && player->Bot != nullptr) { @@ -1710,6 +1713,7 @@ void player_t::Serialize(FSerializer &arc) ("viewheight", viewheight) ("deltaviewheight", deltaviewheight) ("bob", bob) + ("bobtimer", BobTimer) ("vel", Vel) ("centering", centering) ("health", health) @@ -1819,6 +1823,7 @@ DEFINE_FIELD_X(PlayerInfo, player_t, viewz) DEFINE_FIELD_X(PlayerInfo, player_t, viewheight) DEFINE_FIELD_X(PlayerInfo, player_t, deltaviewheight) DEFINE_FIELD_X(PlayerInfo, player_t, bob) +DEFINE_FIELD_X(PlayerInfo, player_t, BobTimer) DEFINE_FIELD_X(PlayerInfo, player_t, Vel) DEFINE_FIELD_X(PlayerInfo, player_t, centering) DEFINE_FIELD_X(PlayerInfo, player_t, turnticks) diff --git a/wadsrc/static/zscript/actors/player/player.zs b/wadsrc/static/zscript/actors/player/player.zs index 7eab28a19..f6d12a81e 100644 --- a/wadsrc/static/zscript/actors/player/player.zs +++ b/wadsrc/static/zscript/actors/player/player.zs @@ -18,7 +18,6 @@ class PlayerPawn : Actor // 16 pixels of bob const MAXBOB = 16.; - int BobTimer; // Use a local timer for this so it can be predicted correctly. int crouchsprite; int MaxHealth; int BonusHealth; @@ -634,7 +633,7 @@ class PlayerPawn : Actor { if (player.health > 0) { - angle = BobTimer / (120 * TICRATE / 35.) * 360.; + angle = player.BobTimer / (120 * TICRATE / 35.) * 360.; bob = player.GetStillBob() * sin(angle); } else @@ -644,7 +643,7 @@ class PlayerPawn : Actor } else { - angle = BobTimer / (ViewBobSpeed * TICRATE / 35.) * 360.; + angle = player.BobTimer / (ViewBobSpeed * TICRATE / 35.) * 360.; bob = player.bob * sin(angle) * (waterlevel > 1 ? 0.25f : 0.5f); } @@ -1668,7 +1667,6 @@ class PlayerPawn : Actor PlayerFlags |= PF_VOODOO_ZOMBIE; } - ++BobTimer; CheckFOV(); CheckCheats(); @@ -2543,7 +2541,7 @@ class PlayerPawn : Actor for (int i = 0; i < 2; i++) { // Bob the weapon based on movement speed. ([SP] And user's bob speed setting) - double angle = (BobSpeed * player.GetWBobSpeed() * 35 / TICRATE*(BobTimer - 1 + i)) * (360. / 8192.); + double angle = (BobSpeed * player.GetWBobSpeed() * 35 / TICRATE*(player.BobTimer - 1 + i)) * (360. / 8192.); // [RH] Smooth transitions between bobbing and not-bobbing frames. // This also fixes the bug where you can "stick" a weapon off-center by @@ -2894,6 +2892,7 @@ struct PlayerInfo native play // self is what internally is known as player_t native double viewheight; native double deltaviewheight; native double bob; + native int BobTimer; native vector2 vel; native bool centering; native uint8 turnticks;