From 477120923ffffc79bc4364786493db8d15189153 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 12 Sep 2022 00:05:20 +0200 Subject: [PATCH] - made player.vel and gs.playerfriction floating point. No change in value range yet, but having them as floats now allows easier refactoring. --- source/games/duke/src/actors_d.cpp | 4 ++-- source/games/duke/src/actors_r.cpp | 4 ++-- source/games/duke/src/global.h | 2 +- source/games/duke/src/player_d.cpp | 24 +++++++++---------- source/games/duke/src/player_r.cpp | 38 +++++++++++++++--------------- source/games/duke/src/types.h | 2 +- 6 files changed, 37 insertions(+), 37 deletions(-) diff --git a/source/games/duke/src/actors_d.cpp b/source/games/duke/src/actors_d.cpp index 1458b9c72..8dcedfbc1 100644 --- a/source/games/duke/src/actors_d.cpp +++ b/source/games/duke/src/actors_d.cpp @@ -3642,8 +3642,8 @@ void move_d(DDukeActor *actor, int playernum, int xvel) } else { - ps[playernum].__vel.X = MulScale(ps[playernum].__vel.X, gs.playerfriction - 0x2000, 16); - ps[playernum].__vel.Y = MulScale(ps[playernum].__vel.Y, gs.playerfriction - 0x2000, 16); + ps[playernum].__vel.X = MulScaleF(ps[playernum].__vel.X, gs.playerfriction - 0x2000, 16); + ps[playernum].__vel.Y = MulScaleF(ps[playernum].__vel.Y, gs.playerfriction - 0x2000, 16); } } else if (actor->spr.picnum != DRONE && actor->spr.picnum != SHARK && actor->spr.picnum != COMMANDER) diff --git a/source/games/duke/src/actors_r.cpp b/source/games/duke/src/actors_r.cpp index ded9b03fd..476106cd1 100644 --- a/source/games/duke/src/actors_r.cpp +++ b/source/games/duke/src/actors_r.cpp @@ -3674,8 +3674,8 @@ void move_r(DDukeActor *actor, int pnum, int xvel) } else { - ps[pnum].__vel.X = MulScale(ps[pnum].__vel.X, gs.playerfriction - 0x2000, 16); - ps[pnum].__vel.Y = MulScale(ps[pnum].__vel.Y, gs.playerfriction - 0x2000, 16); + ps[pnum].__vel.X = MulScaleF(ps[pnum].__vel.X, gs.playerfriction - 0x2000, 16); + ps[pnum].__vel.Y = MulScaleF(ps[pnum].__vel.Y, gs.playerfriction - 0x2000, 16); } } else if ((isRRRA() && actor->spr.picnum != DRONE && actor->spr.picnum != SHARK && actor->spr.picnum != UFO1_RRRA) || diff --git a/source/games/duke/src/global.h b/source/games/duke/src/global.h index 3506920a6..75ab1ba76 100644 --- a/source/games/duke/src/global.h +++ b/source/games/duke/src/global.h @@ -22,7 +22,7 @@ struct DukeGameInfo int morterblastradius; int numfreezebounces; int pipebombblastradius; - int playerfriction; + double playerfriction; int rpgblastradius; int seenineblastradius; int shrinkerblastradius; diff --git a/source/games/duke/src/player_d.cpp b/source/games/duke/src/player_d.cpp index eec561803..e2b20eeb0 100644 --- a/source/games/duke/src/player_d.cpp +++ b/source/games/duke/src/player_d.cpp @@ -1842,7 +1842,7 @@ static void movement(int snum, ESyncBits actions, sectortype* psect, int fz_, in 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 >> 10; + p->hard_landing = p->__vel.Z / 1024.; p->on_ground = 1; @@ -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 >>= 1; + p->__vel.Z *= 0.5; } } @@ -1979,7 +1979,7 @@ static void underwater(int snum, ESyncBits actions, int fz_, int cz_) } if (p->__vel.Z > 2048) - p->__vel.Z >>= 1; + p->__vel.Z *= 0.5; p->pos.Z += p->__vel.Z * zinttoworld; @@ -2998,20 +2998,20 @@ void processinput_d(int snum) else check = ((aplWeaponWorksLike(p->curr_weapon, snum) == KNEE_WEAPON && p->kickback_pic > 10 && p->on_ground) || (p->on_ground && (actions & SB_CROUCH))); if (check) { - p->__vel.X = MulScale(p->__vel.X, gs.playerfriction - 0x2000, 16); - p->__vel.Y = MulScale(p->__vel.Y, gs.playerfriction - 0x2000, 16); + p->__vel.X = MulScaleF(p->__vel.X, gs.playerfriction - 0x2000, 16); + p->__vel.Y = MulScaleF(p->__vel.Y, gs.playerfriction - 0x2000, 16); } else { if (psectlotag == 2) { - p->__vel.X = MulScale(p->__vel.X, gs.playerfriction - 0x1400, 16); - p->__vel.Y = MulScale(p->__vel.Y, gs.playerfriction - 0x1400, 16); + p->__vel.X = MulScaleF(p->__vel.X, gs.playerfriction - 0x1400, 16); + p->__vel.Y = MulScaleF(p->__vel.Y, gs.playerfriction - 0x1400, 16); } else { - p->__vel.X = MulScale(p->__vel.X, gs.playerfriction, 16); - p->__vel.Y = MulScale(p->__vel.Y, gs.playerfriction, 16); + p->__vel.X = MulScaleF(p->__vel.X, gs.playerfriction, 16); + p->__vel.Y = MulScaleF(p->__vel.Y, gs.playerfriction, 16); } } @@ -3021,9 +3021,9 @@ void processinput_d(int snum) if (shrunk) { p->__vel.X = - MulScale(p->__vel.X, gs.playerfriction - (gs.playerfriction >> 1) + (gs.playerfriction >> 2), 16); + MulScaleF(p->__vel.X, gs.playerfriction * 0.75, 16); p->__vel.Y = - MulScale(p->__vel.Y, gs.playerfriction - (gs.playerfriction >> 1) + (gs.playerfriction >> 2), 16); + MulScaleF(p->__vel.Y, gs.playerfriction * 0.75, 16); } } @@ -3038,7 +3038,7 @@ HORIZONLY: Collision clip{}; if (ud.clipping) { - p->player_add_int_xy({ p->__vel.X >> 14, p->__vel.Y >> 14 }); + p->player_add_int_xy({ int(p->__vel.X / 16384), int(p->__vel.Y / 16384) }); updatesector(p->pos, &p->cursector); ChangeActorSect(pact, p->cursector); } diff --git a/source/games/duke/src/player_r.cpp b/source/games/duke/src/player_r.cpp index 8c777dc99..372db0d12 100644 --- a/source/games/duke/src/player_r.cpp +++ b/source/games/duke/src/player_r.cpp @@ -2205,7 +2205,7 @@ static void movement(int snum, ESyncBits actions, sectortype* psect, int fz_, in 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 >> 10; + p->hard_landing = p->__vel.Z /= 1024.; p->on_ground = 1; @@ -2225,7 +2225,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 >>= 1; + p->__vel.Z *= 0.5; } } @@ -2334,7 +2334,7 @@ static void underwater(int snum, ESyncBits actions, int fz_, int cz_) } if (p->__vel.Z > 2048) - p->__vel.Z >>= 1; + p->__vel.Z *= 0.5; p->pos.Z += p->__vel.Z * zinttoworld; @@ -3712,20 +3712,20 @@ void processinput_r(int snum) if (!isRRRA() && ((p->curr_weapon == KNEE_WEAPON && p->kickback_pic > 10 && p->on_ground) || (p->on_ground && (actions & SB_CROUCH)))) { - p->__vel.X = MulScale(p->__vel.X, gs.playerfriction - 0x2000, 16); - p->__vel.Y = MulScale(p->__vel.Y, gs.playerfriction - 0x2000, 16); + p->__vel.X = MulScaleF(p->__vel.X, gs.playerfriction - 0x2000, 16); + p->__vel.Y = MulScaleF(p->__vel.Y, gs.playerfriction - 0x2000, 16); } else { if (psectlotag == 2) { - p->__vel.X = MulScale(p->__vel.X, gs.playerfriction - 0x1400, 16); - p->__vel.Y = MulScale(p->__vel.Y, gs.playerfriction - 0x1400, 16); + p->__vel.X = MulScaleF(p->__vel.X, gs.playerfriction - 0x1400, 16); + p->__vel.Y = MulScaleF(p->__vel.Y, gs.playerfriction - 0x1400, 16); } else { - p->__vel.X = MulScale(p->__vel.X, gs.playerfriction, 16); - p->__vel.Y = MulScale(p->__vel.Y, gs.playerfriction, 16); + p->__vel.X = MulScaleF(p->__vel.X, gs.playerfriction, 16); + p->__vel.Y = MulScaleF(p->__vel.Y, gs.playerfriction, 16); } } @@ -3746,8 +3746,8 @@ void processinput_r(int snum) p->boot_amount--; else { - p->__vel.X = MulScale(p->__vel.X, gs.playerfriction, 16); - p->__vel.Y = MulScale(p->__vel.Y, gs.playerfriction, 16); + p->__vel.X = MulScaleF(p->__vel.X, gs.playerfriction, 16); + p->__vel.Y = MulScaleF(p->__vel.Y, gs.playerfriction, 16); } } else @@ -3758,8 +3758,8 @@ void processinput_r(int snum) { if (p->on_ground) { - p->__vel.X = MulScale(p->__vel.X, gs.playerfriction - 0x1800, 16); - p->__vel.Y = MulScale(p->__vel.Y, gs.playerfriction - 0x1800, 16); + p->__vel.X = MulScaleF(p->__vel.X, gs.playerfriction - 0x1800, 16); + p->__vel.Y = MulScaleF(p->__vel.Y, gs.playerfriction - 0x1800, 16); } } else @@ -3767,8 +3767,8 @@ void processinput_r(int snum) p->boot_amount--; else { - p->__vel.X = MulScale(p->__vel.X, gs.playerfriction - 0x1800, 16); - p->__vel.Y = MulScale(p->__vel.Y, gs.playerfriction - 0x1800, 16); + p->__vel.X = MulScaleF(p->__vel.X, gs.playerfriction - 0x1800, 16); + p->__vel.Y = MulScaleF(p->__vel.Y, gs.playerfriction - 0x1800, 16); } } @@ -3778,9 +3778,9 @@ void processinput_r(int snum) if (shrunk) { p->__vel.X = - MulScale(p->__vel.X, gs.playerfriction - (gs.playerfriction >> 1) + (gs.playerfriction >> 2), 16); + MulScaleF(p->__vel.X, gs.playerfriction * 0.75, 16); p->__vel.Y = - MulScale(p->__vel.Y, gs.playerfriction - (gs.playerfriction >> 1) + (gs.playerfriction >> 2), 16); + MulScaleF(p->__vel.Y, gs.playerfriction * 0.75, 16); } } @@ -3795,8 +3795,8 @@ HORIZONLY: Collision clip{}; if (ud.clipping) { - p->player_add_int_xy({ p->__vel.X >> 14, p->__vel.Y >> 14 }); - updatesector(p->player_int_pos().X, p->player_int_pos().Y, &p->cursector); + p->player_add_int_xy({ int(p->__vel.X / 16384), int(p->__vel.Y / 16384) }); + updatesector(p->pos, &p->cursector); ChangeActorSect(pact, p->cursector); } else diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index 3e28fdb14..3947eb5c3 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -201,7 +201,7 @@ struct CraneDef struct player_struct { - vec3_t __vel; + DVector3 __vel; DVector3 pos, opos; DVector2 bobpos;