From b46b087e0c8d79d08c98ccdee289f08064675939 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Mon, 12 Sep 2022 00:14:31 +0200 Subject: [PATCH] - first round of vel refactoring. VEL_FACTOR is used as a marker that later can be quickly removed once the data type gets changed over. --- source/games/duke/src/actors_d.cpp | 12 ++++++------ source/games/duke/src/actors_r.cpp | 5 ++--- source/games/duke/src/gameexec.cpp | 20 +++++++++----------- source/games/duke/src/premap.cpp | 4 +--- source/games/duke/src/types.h | 3 ++- 5 files changed, 20 insertions(+), 24 deletions(-) diff --git a/source/games/duke/src/actors_d.cpp b/source/games/duke/src/actors_d.cpp index d5f82fb58..952a25132 100644 --- a/source/games/duke/src/actors_d.cpp +++ b/source/games/duke/src/actors_d.cpp @@ -1846,7 +1846,7 @@ void movetransports_d(void) int k = 0; - if (onfloorz && sectlotag == ST_1_ABOVE_WATER && ps[p].on_ground && ps[p].pos.Z > (sectp->floorz - 16) && (PlayerInput(p, SB_CROUCH) || ps[p].__vel.Z > 2048)) + if (onfloorz && sectlotag == ST_1_ABOVE_WATER && ps[p].on_ground && ps[p].pos.Z > (sectp->floorz - 16) && (PlayerInput(p, SB_CROUCH) || ps[p].vel.Z > 8 * VELZ_FACTOR)) // if( onfloorz && sectlotag == 1 && ps[p].pos.z > (sectp->floorz-(6<<8)) ) { k = 1; @@ -1859,8 +1859,9 @@ void movetransports_d(void) ps[p].pos.Z = Owner->sector()->ceilingz + 7; ps[p].backupz(); - ps[p].__vel.X = 4096 - (krand() & 8192); - ps[p].__vel.Y = 4096 - (krand() & 8192); + // this is actually below the precision óf the original Build coordinate system... + ps[p].vel.X = ((krand() & 8192) ? 1 / 64. : -1 / 64.) * VEL_FACTOR; + ps[p].vel.Y = ((krand() & 8192) ? 1 / 64. : -1 / 64.) * VEL_FACTOR; } @@ -3524,9 +3525,8 @@ void move_d(DDukeActor *actor, int playernum, int xvel) if (a & face_player_smart) { - double newx = ps[playernum].pos.X + (ps[playernum].__vel.X / 768) * inttoworld; - double newy = ps[playernum].pos.Y + (ps[playernum].__vel.Y / 768) * inttoworld; - goalang = getangle(newx - actor->spr.pos.X, newy - actor->spr.pos.Y); + DVector2 newpos = ps[playernum].pos.XY() + (ps[playernum].vel.XY() * (4. / 3.) / VEL_FACTOR); + goalang = getangle(newpos - actor->spr.pos.XY()); angdif = getincangle(actor->int_ang(), goalang) >> 2; if (angdif > -8 && angdif < 0) angdif = 0; actor->add_int_ang(angdif); diff --git a/source/games/duke/src/actors_r.cpp b/source/games/duke/src/actors_r.cpp index bf2f2bd9f..7a43a4777 100644 --- a/source/games/duke/src/actors_r.cpp +++ b/source/games/duke/src/actors_r.cpp @@ -3562,9 +3562,8 @@ void move_r(DDukeActor *actor, int pnum, int xvel) if (a & face_player_smart) { - double newx = ps[pnum].pos.X + (ps[pnum].__vel.X / 768) * inttoworld; - double newy = ps[pnum].pos.Y + (ps[pnum].__vel.Y / 768) * inttoworld; - goalang = getangle(newx - actor->spr.pos.X, newy - actor->spr.pos.Y); + DVector2 newpos = ps[pnum].pos.XY() + (ps[pnum].vel.XY() * (4. / 3.) / VEL_FACTOR); + goalang = getangle(newpos - actor->spr.pos.XY()); angdif = getincangle(actor->int_ang(), goalang) >> 2; if (angdif > -8 && angdif < 0) angdif = 0; actor->add_int_ang(angdif); diff --git a/source/games/duke/src/gameexec.cpp b/source/games/duke/src/gameexec.cpp index 71e57973c..8dca6202d 100644 --- a/source/games/duke/src/gameexec.cpp +++ b/source/games/duke/src/gameexec.cpp @@ -403,18 +403,18 @@ void DoPlayer(bool bSet, int lVar1, int lLabelID, int lVar2, DDukeActor* sActor, break; case PLAYER_POSXV: - if (bSet) ps[iPlayer].__vel.X = lValue; - else SetGameVarID(lVar2, ps[iPlayer].__vel.X, sActor, sPlayer); + if (bSet) ps[iPlayer].vel.X = FixedToFloat<18>(lValue); + else SetGameVarID(lVar2, FloatToFixed<18>(ps[iPlayer].vel.X), sActor, sPlayer); break; case PLAYER_POSYV: - if (bSet) ps[iPlayer].__vel.Y = lValue; - else SetGameVarID(lVar2, ps[iPlayer].__vel.Y, sActor, sPlayer); + if (bSet) ps[iPlayer].vel.Y = FixedToFloat<18>(lValue); + else SetGameVarID(lVar2, FloatToFixed<18>(ps[iPlayer].vel.Y), sActor, sPlayer); break; case PLAYER_POSZV: - if (bSet) ps[iPlayer].__vel.Z = lValue; - else SetGameVarID(lVar2, ps[iPlayer].__vel.Z, sActor, sPlayer); + if (bSet) ps[iPlayer].vel.Z = lValue * zmaptoworld; + else SetGameVarID(lVar2, ps[iPlayer].vel.Z / zmaptoworld, sActor, sPlayer); break; case PLAYER_LAST_PISSED_TIME: @@ -2250,7 +2250,7 @@ int ParseState::parse(void) ps[g_p].footprintcount = 0; ps[g_p].weapreccnt = 0; ps[g_p].ftq = 0; - ps[g_p].__vel.X = ps[g_p].__vel.Y = 0; + ps[g_p].vel.X = ps[g_p].vel.Y = 0; if (!isRR()) ps[g_p].angle.orotscrnang = ps[g_p].angle.rotscrnang = nullAngle; ps[g_p].falling_counter = 0; @@ -2447,8 +2447,7 @@ int ParseState::parse(void) case concmd_slapplayer: insptr++; forceplayerangle(g_p); - ps[g_p].__vel.X -= ps[g_p].angle.ang.Cos() * (1 << 21); - ps[g_p].__vel.Y -= ps[g_p].angle.ang.Sin() * (1 << 21); + ps[g_p].vel.XY() -= ps[g_p].angle.ang.ToVector() * 8 * VEL_FACTOR; return 0; case concmd_wackplayer: insptr++; @@ -2456,8 +2455,7 @@ int ParseState::parse(void) forceplayerangle(g_p); else { - ps[g_p].__vel.X -= ps[g_p].angle.ang.Cos() * (1 << 24); - ps[g_p].__vel.Y -= ps[g_p].angle.ang.Sin() * (1 << 24); + ps[g_p].vel.XY() -= ps[g_p].angle.ang.ToVector() * 64 * VEL_FACTOR; ps[g_p].jumping_counter = 767; ps[g_p].jumping_toggle = 1; } diff --git a/source/games/duke/src/premap.cpp b/source/games/duke/src/premap.cpp index fd4fc01cc..14d30c254 100644 --- a/source/games/duke/src/premap.cpp +++ b/source/games/duke/src/premap.cpp @@ -183,9 +183,7 @@ void resetplayerstats(int snum) p->newOwner =nullptr; p->jumping_counter = 0; p->hard_landing = 0; - p->__vel.X = 0; //!! - p->__vel.Y = 0; - p->__vel.Z = 0; + p->vel.Zero(); p->fric.X = 0; p->fric.Y = 0; p->somethingonplayer = nullptr; diff --git a/source/games/duke/src/types.h b/source/games/duke/src/types.h index 0dc4b46b1..78b46b304 100644 --- a/source/games/duke/src/types.h +++ b/source/games/duke/src/types.h @@ -201,7 +201,8 @@ struct CraneDef }; constexpr double VEL_FACTOR = FloatToFixed<18>(1); -struct player_struct +constexpr double VELZ_FACTOR = 256; +struct player_struct { union {