From 2266ae1cd6fc9ec0d080fb3200de9d0f9d58af1a Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 12 Sep 2022 00:17:09 +0200 Subject: [PATCH] - converted vel use in player_d.cpp's main movement functions Still using conversion factors until all code has been processed. --- source/games/duke/src/gameexec.cpp | 2 +- source/games/duke/src/input.cpp | 2 +- source/games/duke/src/player_d.cpp | 68 +++++++++++++++--------------- source/games/duke/src/player_r.cpp | 3 +- source/games/duke/src/savegame.cpp | 6 +-- source/games/duke/src/sectors.cpp | 2 +- 6 files changed, 41 insertions(+), 42 deletions(-) diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp index 8dca6202d..55bd8c59f 100644 --- a/source/games/duke/src/gameexec.cpp +++ b/source/games/duke/src/gameexec.cpp @@ -2388,7 +2388,7 @@ int ParseState::parse(void) // sigh.. this was yet another place where number literals were used as bit masks for every single value, making the code totally unreadable. if( (l& pducking) && ps[g_p].on_ground && PlayerInput(g_p, SB_CROUCH)) j = 1; - else if( (l& pfalling) && ps[g_p].jumping_counter == 0 && !ps[g_p].on_ground && ps[g_p].__vel.Z > 2048 ) + else if( (l& pfalling) && ps[g_p].jumping_counter == 0 && !ps[g_p].on_ground && ps[g_p].vel.Z > 8 * VELZ_FACTOR ) j = 1; else if( (l& pjumping) && ps[g_p].jumping_counter > 348 ) j = 1; diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 574f928fe..ab10ac81c 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -433,7 +433,7 @@ void hud_input(int plnum) else { p->hard_landing = 0; - p->__vel.Z = 0; + p->vel.Z = 0; S_PlayActorSound(DUKE_JETPACK_OFF, pact); S_StopSound(DUKE_JETPACK_IDLE, pact); S_StopSound(DUKE_JETPACK_ON, pact); diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index b96fdcddb..3fdf3fa13 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -1798,15 +1798,15 @@ static void movement(int snum, ESyncBits actions, sectortype* psect, int fz_, in { p->on_ground = 0; p->__vel.Z += (gs.gravity + 80); // (TICSPERFRAME<<6); - if (p->__vel.Z >= (4096 + 2048)) p->__vel.Z = (4096 + 2048); - if (p->__vel.Z > 2400 && p->falling_counter < 255) + if (p->vel.Z >= (16 + 8) * VELZ_FACTOR) p->vel.Z = (16 + 8) * VELZ_FACTOR; + if (p->vel.Z > 2400 / 256 * VELZ_FACTOR && p->falling_counter < 255) { p->falling_counter++; if (p->falling_counter == 38 && !S_CheckActorSoundPlaying(pact, DUKE_SCREAM)) S_PlayActorSound(DUKE_SCREAM, pact); } - if (p->pos.Z + p->__vel.Z * zinttoworld >= floorz - i) // hit the ground + if (p->pos.Z + p->vel.Z / VELZ_FACTOR >= floorz - i) // hit the ground { S_StopSound(DUKE_SCREAM, pact); if (!p->insector() || p->cursector->lotag != 1) @@ -1830,7 +1830,7 @@ static void movement(int snum, ESyncBits actions, sectortype* psect, int fz_, in SetPlayerPal(p, PalEntry(32, 16, 0, 0)); } - else if (p->__vel.Z > 2048) S_PlayActorSound(DUKE_LAND, pact); + else if (p->vel.Z > 8 * VELZ_FACTOR) S_PlayActorSound(DUKE_LAND, pact); } } } @@ -1841,8 +1841,8 @@ static void movement(int snum, ESyncBits actions, sectortype* psect, int fz_, in p->falling_counter = 0; S_StopSound(-1, pact, CHAN_VOICE); - if (psectlotag != ST_1_ABOVE_WATER && psectlotag != ST_2_UNDERWATER && p->on_ground == 0 && p->__vel.Z > (6144 >> 1)) - p->hard_landing = p->__vel.Z / 1024.; + if (psectlotag != ST_1_ABOVE_WATER && psectlotag != ST_2_UNDERWATER && p->on_ground == 0 && p->vel.Z > 12 * VELZ_FACTOR) + p->hard_landing = uint8_t(p->vel.Z / 4. / VELZ_FACTOR); p->on_ground = 1; @@ -1853,8 +1853,8 @@ static void movement(int snum, ESyncBits actions, sectortype* psect, int fz_, in double k = (floorz - i - p->pos.Z) * 0.5; if (abs(k) < 1) k = 0; p->pos.Z += k; - p->__vel.Z -= 768; - if (p->__vel.Z < 0) p->__vel.Z = 0; + p->vel.Z -= 3 * VELZ_FACTOR; + if (p->vel.Z < 0) p->vel.Z = 0; } else if (p->jumping_counter == 0) { @@ -1862,7 +1862,7 @@ static void movement(int snum, ESyncBits actions, sectortype* psect, int fz_, in if (p->on_warping_sector == 0 && p->pos.Z > floorz - 16) { p->pos.Z = floorz - 16; - p->__vel.Z *= 0.5; + p->vel.Z *= 0.5; } } @@ -1896,11 +1896,11 @@ static void movement(int snum, ESyncBits actions, sectortype* psect, int fz_, in if (psectlotag == 1 && p->jumping_counter > 768) { p->jumping_counter = 0; - p->__vel.Z = -512; + p->vel.Z = -2 * VELZ_FACTOR; } else { - p->__vel.Z -= bsin(2048 - 128 + p->jumping_counter) / 12; + p->vel.Z -= BobVal(2048 - 128 + p->jumping_counter) * (64. / 12) * VELZ_FACTOR; p->jumping_counter += 180; p->on_ground = 0; } @@ -1908,18 +1908,18 @@ static void movement(int snum, ESyncBits actions, sectortype* psect, int fz_, in else { p->jumping_counter = 0; - p->__vel.Z = 0; + p->vel.Z = 0; } } - p->pos.Z += p->__vel.Z * zinttoworld; + p->pos.Z += p->vel.Z / VELZ_FACTOR; if (p->pos.Z < ceilingz + 4) { p->jumping_counter = 0; - if (p->__vel.Z < 0) - p->__vel.X = p->__vel.Y = 0; - p->__vel.Z = 128; + if (p->vel.Z < 0) + p->vel.X = p->vel.Y = 0; + p->vel.Z = 0.5 * VELZ_FACTOR; p->pos.Z = ceilingz + 4; } } @@ -1950,38 +1950,38 @@ static void underwater(int snum, ESyncBits actions, int fz_, int cz_) if (actions & SB_JUMP) { // jump - if (p->__vel.Z > 0) p->__vel.Z = 0; - p->__vel.Z -= 348; - if (p->__vel.Z < -(256 * 6)) p->__vel.Z = -(256 * 6); + if (p->vel.Z > 0) p->vel.Z = 0; + p->vel.Z -= (348 / 256.) * VELZ_FACTOR; + if (p->vel.Z < -6 * VELZ_FACTOR) p->vel.Z = -6 * VELZ_FACTOR; } else if (actions & SB_CROUCH) { // crouch - if (p->__vel.Z < 0) p->__vel.Z = 0; - p->__vel.Z += 348; - if (p->__vel.Z > (256 * 6)) p->__vel.Z = (256 * 6); + if (p->vel.Z < 0) p->vel.Z = 0; + p->vel.Z += (348 / 256.) * VELZ_FACTOR; + if (p->vel.Z > 6 * VELZ_FACTOR) p->vel.Z = 6 * VELZ_FACTOR; } else { // normal view - if (p->__vel.Z < 0) + if (p->vel.Z < 0) { - p->__vel.Z += 256; - if (p->__vel.Z > 0) - p->__vel.Z = 0; + p->vel.Z += 1 * VELZ_FACTOR; + if (p->vel.Z > 0) + p->vel.Z = 0; } - if (p->__vel.Z > 0) + if (p->vel.Z > 0) { - p->__vel.Z -= 256; - if (p->__vel.Z < 0) - p->__vel.Z = 0; + p->vel.Z -= 1 * VELZ_FACTOR; + if (p->vel.Z < 0) + p->vel.Z = 0; } } - if (p->__vel.Z > 2048) - p->__vel.Z *= 0.5; + if (p->vel.Z > 8 * VELZ_FACTOR) + p->vel.Z *= 0.5; - p->pos.Z += p->__vel.Z * zinttoworld; + p->pos.Z += p->vel.Z / VELZ_FACTOR; if (p->pos.Z > floorz - 15) p->pos.Z += (((floorz - 15) - p->pos.Z) * 0.5); @@ -1989,7 +1989,7 @@ static void underwater(int snum, ESyncBits actions, int fz_, int cz_) if (p->pos.Z < ceilingz + 4) { p->pos.Z = ceilingz + 4; - p->__vel.Z = 0; + p->vel.Z = 0; } if (p->scuba_on && (krand() & 255) < 8) diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index 58ec8b3b0..5f284c50b 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -1319,8 +1319,7 @@ int doincrements_r(player_struct* p) { p->noise_radius = 16384; madenoise(screenpeek); - p->__vel.X += p->angle.ang.Cos() * (1 << 18); - p->__vel.Y += p->angle.ang.Sin() * (1 << 18); + p->vel.XY() += p->angle.ang.ToVector() * VEL_FACTOR; } p->eat -= 4; if (p->eat < 0) diff --git a/source/games/duke/src/savegame.cpp b/source/games/duke/src/savegame.cpp index 2dbe352f5..096717a70 100644 --- a/source/games/duke/src/savegame.cpp +++ b/source/games/duke/src/savegame.cpp @@ -122,9 +122,9 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, player_struct& w, ("bobposx", w.bobpos.X) ("bobposy", w.bobpos.Y) ("pyoff", w.pyoff) - ("posxv", w.__vel.X) - ("posyv", w.__vel.Y) - ("poszv", w.__vel.Z) + ("posxv", w.vel.X) + ("posyv", w.vel.Y) + ("poszv", w.vel.Z) ("last_pissed_time", w.last_pissed_time) ("truefz", w.truefz) ("truecz", w.truecz) diff --git a/source/games/duke/src/sectors.cpp b/source/games/duke/src/sectors.cpp index 844062a24..d3891205e 100644 --- a/source/games/duke/src/sectors.cpp +++ b/source/games/duke/src/sectors.cpp @@ -392,7 +392,7 @@ void doanimations(void) if (ps[p].GetActor()->GetOwner() != nullptr) { ps[p].player_add_int_z(v); - ps[p].__vel.Z = 0; + ps[p].vel.Z = 0; } DukeSectIterator it(dasectp);