Moved BobTimer to playerinfo

This was a bit too invasive for mods that used full PlayerThink overrides.
This commit is contained in:
Boondorl 2025-06-14 10:45:38 -04:00 committed by Ricardo Luís Vaz Silva
commit 989a355f80
3 changed files with 10 additions and 5 deletions

View file

@ -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.

View file

@ -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)

View file

@ -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;