From a5c9a702e9f8ebb66ff3622e762d65e0bd8f89d5 Mon Sep 17 00:00:00 2001 From: "Richard C. Gobeille" Date: Mon, 8 Jun 2020 12:21:48 -0700 Subject: [PATCH] Duke3d: fix jittery view on moving sectors This also fixes the interpolation for gamefunc_TurnAround and stomping on enemies. Fixes terminx/eduke32#60. # Conflicts: # source/duke3d/src/actors.cpp # source/duke3d/src/game.cpp # source/duke3d/src/premap.cpp --- source/duke3d/src/actors.cpp | 35 ++++++++++++++++++++++++++++++----- source/duke3d/src/game.cpp | 7 ++++--- source/duke3d/src/player.cpp | 5 ----- source/duke3d/src/player.h | 4 ++-- source/duke3d/src/premap.cpp | 10 ++++++---- 5 files changed, 42 insertions(+), 19 deletions(-) diff --git a/source/duke3d/src/actors.cpp b/source/duke3d/src/actors.cpp index 9e730d051..bb7292b0a 100644 --- a/source/duke3d/src/actors.cpp +++ b/source/duke3d/src/actors.cpp @@ -1341,7 +1341,9 @@ ACTOR_STATIC void G_MovePlayers(void) { int const nextSprite = nextspritestat[spriteNum]; auto const pSprite = &sprite[spriteNum]; - auto const pPlayer = g_player[P_GetP(pSprite)].ps; + int const playerNum = P_GetP(pSprite); + auto & thisPlayer = g_player[playerNum]; + auto const pPlayer = thisPlayer.ps; if (pSprite->owner >= 0) { @@ -1386,11 +1388,19 @@ ACTOR_STATIC void G_MovePlayers(void) if (G_TileHasActor(sprite[spriteNum].picnum)) A_Execute(spriteNum, P_GetP(pSprite), otherPlayerDist); + thisPlayer.smoothcamera = false; pPlayer->q16angvel = G_GetQ16AngleDelta(pPlayer->oq16ang, pPlayer->q16ang); pPlayer->oq16ang = pPlayer->q16ang; pPlayer->oq16horiz = pPlayer->q16horiz; pPlayer->oq16horizoff = pPlayer->q16horizoff; + if (pPlayer->one_eighty_count < 0) + { + thisPlayer.smoothcamera = true; + pPlayer->one_eighty_count += 128; + pPlayer->q16ang += F16(128); + } + if (g_netServer || ud.multimode > 1) { if (sprite[g_player[otherp].ps->i].extra > 0) @@ -1414,6 +1424,14 @@ ACTOR_STATIC void G_MovePlayers(void) } } + if (pPlayer->actorsqu >= 0) + { + thisPlayer.smoothcamera = true; + pPlayer->q16ang += fix16_from_int( + G_GetAngleDelta(fix16_to_int(pPlayer->q16ang), getangle(sprite[pPlayer->actorsqu].x - pPlayer->pos.x, sprite[pPlayer->actorsqu].y - pPlayer->pos.y)) + >> 2); + } + if (ud.god) { pSprite->extra = pPlayer->max_player_health; @@ -1448,6 +1466,7 @@ ACTOR_STATIC void G_MovePlayers(void) if (pPlayer->wackedbyactor >= 0 && sprite[pPlayer->wackedbyactor].statnum < MAXSTATUS) { + thisPlayer.smoothcamera = true; pPlayer->q16ang += fix16_from_int(G_GetAngleDelta(fix16_to_int(pPlayer->q16ang), getangle(sprite[pPlayer->wackedbyactor].x - pPlayer->pos.x, sprite[pPlayer->wackedbyactor].y - pPlayer->pos.y)) @@ -1846,6 +1865,7 @@ ACTOR_STATIC void G_MoveStandables(void) pSprite->owner = -2; g_player[p].ps->on_crane = spriteNum; A_PlaySound(DUKE_GRUNT,g_player[p].ps->i); + g_player[p].smoothcamera = true; g_player[p].ps->q16ang = fix16_from_int(pSprite->ang+1024); } else @@ -3686,7 +3706,8 @@ ACTOR_STATIC void G_MoveTransports(void) if (sprite[sectSprite].owner != -1) { int const playerNum = P_Get(sectSprite); - auto const pPlayer = g_player[playerNum].ps; + auto & thisPlayer = g_player[playerNum]; + auto const pPlayer = thisPlayer.ps; pPlayer->on_warping_sector = 1; @@ -3710,6 +3731,7 @@ ACTOR_STATIC void G_MoveTransports(void) } } + thisPlayer.smoothcamera = true; pPlayer->q16ang = fix16_from_int(sprite[OW(spriteNum)].ang); if (sprite[OW(spriteNum)].owner != OW(spriteNum)) @@ -3738,12 +3760,12 @@ ACTOR_STATIC void G_MoveTransports(void) } if (onFloor == 0 && klabs(SZ(spriteNum) - pPlayer->pos.z) < 6144) - if (!pPlayer->jetpack_on || TEST_SYNC_KEY(g_player[playerNum].input->bits, SK_JUMP) - || TEST_SYNC_KEY(g_player[playerNum].input->bits, SK_CROUCH)) + if (!pPlayer->jetpack_on || TEST_SYNC_KEY(thisPlayer.input->bits, SK_JUMP) + || TEST_SYNC_KEY(thisPlayer.input->bits, SK_CROUCH)) { pPlayer->pos.x += sprite[OW(spriteNum)].x - SX(spriteNum); pPlayer->pos.y += sprite[OW(spriteNum)].y - SY(spriteNum); - pPlayer->pos.z = (pPlayer->jetpack_on && (TEST_SYNC_KEY(g_player[playerNum].input->bits, SK_JUMP) + pPlayer->pos.z = (pPlayer->jetpack_on && (TEST_SYNC_KEY(thisPlayer.input->bits, SK_JUMP) || pPlayer->jetpack_on < 11)) ? sprite[OW(spriteNum)].z - 6144 : sprite[OW(spriteNum)].z + 6144; @@ -6257,6 +6279,7 @@ ACTOR_STATIC void G_MoveEffectors(void) //STATNUM 3 if (pPlayer->cursectnum == pSprite->sectnum && pPlayer->on_ground == 1) { + g_player[playerNum].smoothcamera = true; pPlayer->q16ang += fix16_from_int(l*q); pPlayer->q16ang &= 0x7FFFFFF; @@ -6480,6 +6503,8 @@ ACTOR_STATIC void G_MoveEffectors(void) //STATNUM 3 pPlayer->bobpos.x += m; pPlayer->bobpos.y += x; + g_player[playerNum].smoothcamera = true; + pPlayer->q16ang += fix16_from_int(q); pPlayer->q16ang &= 0x7FFFFFF; diff --git a/source/duke3d/src/game.cpp b/source/duke3d/src/game.cpp index 6b029638a..062429b42 100644 --- a/source/duke3d/src/game.cpp +++ b/source/duke3d/src/game.cpp @@ -616,7 +616,8 @@ static void G_ClearGotMirror() void G_DrawRooms(int32_t playerNum, int32_t smoothRatio) { - auto const pPlayer = g_player[playerNum].ps; + auto const &thisPlayer = g_player[playerNum]; + auto const pPlayer = thisPlayer.ps; int const viewingRange = viewingrange; @@ -726,8 +727,8 @@ void G_DrawRooms(int32_t playerNum, int32_t smoothRatio) pPlayer->opos.z + mulscale16(pPlayer->pos.z - pPlayer->opos.z, smoothRatio) }; CAMERA(pos) = camVect; - - if (pPlayer->wackedbyactor >= 0) + + if (thisPlayer.smoothcamera) { CAMERA(q16ang) = pPlayer->oq16ang + mulscale16(((pPlayer->q16ang + F16(1024) - pPlayer->oq16ang) & 0x7FFFFFF) - F16(1024), smoothRatio) diff --git a/source/duke3d/src/player.cpp b/source/duke3d/src/player.cpp index ad5484927..021376c26 100644 --- a/source/duke3d/src/player.cpp +++ b/source/duke3d/src/player.cpp @@ -5803,11 +5803,6 @@ RECHECK: } pPlayer->actorsqu = -1; } - else if (pPlayer->actorsqu >= 0) - pPlayer->q16ang += fix16_from_int( - G_GetAngleDelta(fix16_to_int(pPlayer->q16ang), - getangle(sprite[pPlayer->actorsqu].x - pPlayer->pos.x, sprite[pPlayer->actorsqu].y - pPlayer->pos.y)) - >> 2); } #endif diff --git a/source/duke3d/src/player.h b/source/duke3d/src/player.h index e95d14069..22547507d 100644 --- a/source/duke3d/src/player.h +++ b/source/duke3d/src/player.h @@ -222,12 +222,12 @@ typedef struct double lastInputTicks; int32_t netsynctime; - int16_t ping, filler; int32_t pcolor, pteam; + int16_t ping; // NOTE: wchoice[HANDREMOTE_WEAPON .. MAX_WEAPONS-1] unused uint8_t frags[MAXPLAYERS], wchoice[MAX_WEAPONS]; - + char smoothcamera; char vote, gotvote, pingcnt, playerquitflag, ready; // currently unused. May be used later to indicate that a player has pressed use on intermission to indicate they are ready to go on to the next map char user_name[32]; diff --git a/source/duke3d/src/premap.cpp b/source/duke3d/src/premap.cpp index 996830bb0..21f6893b8 100644 --- a/source/duke3d/src/premap.cpp +++ b/source/duke3d/src/premap.cpp @@ -675,7 +675,8 @@ void P_ResetMultiPlayer(int playerNum) void P_ResetPlayer(int playerNum) { - auto &p = *g_player[playerNum].ps; + auto &thisPlayer = g_player[playerNum]; + auto &p = *thisPlayer.ps; gFullMap = 0; @@ -774,9 +775,10 @@ void P_ResetPlayer(int playerNum) ? PWEAPON(playerNum, p.curr_weapon, TotalTime) : 0; - g_player[playerNum].horizRecenter = 0; - g_player[playerNum].horizSkew = 0; - g_player[playerNum].horizAngleAdjust = 0; + thisPlayer.smoothcamera = false; + thisPlayer.horizRecenter = false; + thisPlayer.horizSkew = 0; + thisPlayer.horizAngleAdjust = 0; g_player[playerNum].lastInputTicks = 0; P_UpdateScreenPal(&p);