From 3af6ad697b84494efc19fa3eded9cbad3fabddfa Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Wed, 13 May 2020 14:57:33 +1000 Subject: [PATCH] Duke3D: Process q16rotscrnang and q16look_ang at frame-rate. Had to move lastInputTicks to the DukePlayer_t struct. When first running P_GetInput(), the initial value of elapsedInputTicks is the actual value of timerGetHiTicks(), which is into the thousands. This high initial value was affecting how scaleAdjustmentToInterval() scales as it was taking an initial q16look_ang value of 512 and overflowing the fix16_t type, making it -32,768. --- source/duke3d/src/game.cpp | 2 +- source/duke3d/src/player.cpp | 66 ++++++++++++++++++++++++++---------- source/duke3d/src/player.h | 6 +++- source/duke3d/src/premap.cpp | 1 + 4 files changed, 56 insertions(+), 19 deletions(-) diff --git a/source/duke3d/src/game.cpp b/source/duke3d/src/game.cpp index 5a1522878..33c679724 100644 --- a/source/duke3d/src/game.cpp +++ b/source/duke3d/src/game.cpp @@ -711,7 +711,7 @@ void G_DrawRooms(int32_t playerNum, int32_t smoothRatio) { if (ud.screen_tilting) { - renderSetRollAngle(fix16_to_float(pPlayer->oq16rotscrnang + mulscale16(((pPlayer->q16rotscrnang - pPlayer->oq16rotscrnang + fix16_from_int(1024))&0x7FFFFFF)-fix16_from_int(1024), smoothRatio))); + renderSetRollAngle(fix16_to_float(pPlayer->q16rotscrnang)); pPlayer->oq16rotscrnang = pPlayer->q16rotscrnang; } else diff --git a/source/duke3d/src/player.cpp b/source/duke3d/src/player.cpp index 87809199c..23801d4ec 100644 --- a/source/duke3d/src/player.cpp +++ b/source/duke3d/src/player.cpp @@ -3068,6 +3068,7 @@ void P_GetInput(int const playerNum) { auto &thisPlayer = g_player[playerNum]; auto const pPlayer = thisPlayer.ps; + auto const pSprite = &sprite[pPlayer->i]; ControlInfo info; if (g_cheatBufLen > 1 || (pPlayer->gm & (MODE_MENU|MODE_TYPE)) || (ud.pause_on && !inputState.GetKeyStatus(sc_Pause))) @@ -3131,11 +3132,13 @@ void P_GetInput(int const playerNum) input.svel -= info.dx * keyMove / analogExtent; input.fvel -= info.dz * keyMove / analogExtent; - static double lastInputTicks; auto const currentHiTicks = timerGetHiTicks(); - double const elapsedInputTicks = currentHiTicks - lastInputTicks; + double const elapsedInputTicks = currentHiTicks - pPlayer->lastInputTicks; - lastInputTicks = currentHiTicks; + pPlayer->lastInputTicks = currentHiTicks; + + if (elapsedInputTicks == currentHiTicks) + return; auto scaleAdjustmentToInterval = [=](double x) { return x * REALGAMETICSPERSEC / (1000.0 / elapsedInputTicks); }; @@ -3326,6 +3329,31 @@ void P_GetInput(int const playerNum) } } + // don't adjust rotscrnang and look_ang if dead. + if (pSprite->extra > 0) + { + pPlayer->q16rotscrnang = fix16_ssub(pPlayer->q16rotscrnang, fix16_from_dbl(scaleAdjustmentToInterval(fix16_to_dbl(fix16_sdiv(pPlayer->q16rotscrnang, fix16_from_int(2)))))); + + if (pPlayer->q16rotscrnang && !fix16_sdiv(pPlayer->q16rotscrnang, fix16_from_dbl(scaleAdjustmentToInterval(2)))) + pPlayer->q16rotscrnang = fix16_ssub(pPlayer->q16rotscrnang, fix16_from_dbl(scaleAdjustmentToInterval(ksgn(fix16_to_int(pPlayer->q16rotscrnang))))); + + pPlayer->q16look_ang = fix16_ssub(pPlayer->q16look_ang, fix16_from_dbl(scaleAdjustmentToInterval(fix16_to_dbl(fix16_sdiv(pPlayer->q16look_ang, fix16_from_int(4)))))); + + if (pPlayer->q16look_ang && !fix16_sdiv(pPlayer->q16look_ang, fix16_from_dbl(scaleAdjustmentToInterval(4)))) + pPlayer->q16look_ang = fix16_ssub(pPlayer->q16look_ang, fix16_from_dbl(scaleAdjustmentToInterval(ksgn(fix16_to_int(pPlayer->q16look_ang))))); + + if (thisPlayer.lookLeft) + { + pPlayer->q16look_ang = fix16_ssub(pPlayer->q16look_ang, fix16_from_dbl(scaleAdjustmentToInterval(152))); + pPlayer->q16rotscrnang = fix16_sadd(pPlayer->q16rotscrnang, fix16_from_dbl(scaleAdjustmentToInterval(24))); + } + if (thisPlayer.lookRight) + { + pPlayer->q16look_ang = fix16_sadd(pPlayer->q16look_ang, fix16_from_dbl(scaleAdjustmentToInterval(152))); + pPlayer->q16rotscrnang = fix16_ssub(pPlayer->q16rotscrnang, fix16_from_dbl(scaleAdjustmentToInterval(24))); + } + } + // A horiz diff of 128 equal 45 degrees, so we convert horiz to 1024 angle units if (thisPlayer.horizAngleAdjust) @@ -5103,24 +5131,21 @@ void P_ProcessInput(int playerNum) return; } - pPlayer->q16rotscrnang = fix16_ssub(pPlayer->q16rotscrnang, fix16_sdiv(pPlayer->q16rotscrnang, fix16_from_int(2))); - - if (pPlayer->q16rotscrnang && !fix16_sdiv(pPlayer->q16rotscrnang, fix16_from_int(2))) - pPlayer->q16rotscrnang = fix16_ssub(pPlayer->q16rotscrnang, fix16_from_int(ksgn(fix16_to_int(pPlayer->q16rotscrnang)))); - - pPlayer->q16look_ang = fix16_ssub(pPlayer->q16look_ang, fix16_sdiv(pPlayer->q16look_ang, fix16_from_int(4))); - - if (pPlayer->q16look_ang && !fix16_sdiv(pPlayer->q16look_ang, fix16_from_int(4))) - pPlayer->q16look_ang = fix16_ssub(pPlayer->q16look_ang, fix16_from_int(ksgn(fix16_to_int(pPlayer->q16look_ang)))); - if (TEST_SYNC_KEY(playerBits, SK_LOOK_LEFT)) { // look_left if (VM_OnEvent(EVENT_LOOKLEFT,pPlayer->i,playerNum) == 0) { - pPlayer->q16look_ang = fix16_ssub(pPlayer->q16look_ang, F16(152)); - pPlayer->q16rotscrnang = fix16_sadd(pPlayer->q16rotscrnang, fix16_from_int(24)); + thisPlayer.lookLeft = true; } + else + { + thisPlayer.lookLeft = false; + } + } + else + { + thisPlayer.lookLeft = false; } if (TEST_SYNC_KEY(playerBits, SK_LOOK_RIGHT)) @@ -5128,9 +5153,16 @@ void P_ProcessInput(int playerNum) // look_right if (VM_OnEvent(EVENT_LOOKRIGHT,pPlayer->i,playerNum) == 0) { - pPlayer->q16look_ang = fix16_sadd(pPlayer->q16look_ang, F16(152)); - pPlayer->q16rotscrnang = fix16_ssub(pPlayer->q16rotscrnang, fix16_from_int(24)); + thisPlayer.lookRight = true; } + else + { + thisPlayer.lookRight = false; + } + } + else + { + thisPlayer.lookRight = false; } int velocityModifier = TICSPERFRAME; diff --git a/source/duke3d/src/player.h b/source/duke3d/src/player.h index b6d1d1456..65930ca26 100644 --- a/source/duke3d/src/player.h +++ b/source/duke3d/src/player.h @@ -212,6 +212,8 @@ typedef struct { int8_t last_used_weapon; + double lastInputTicks; + #ifdef LUNATIC int8_t palsfadespeed, palsfadenext, palsfadeprio, padding2_; @@ -221,7 +223,7 @@ typedef struct { #endif int8_t crouch_toggle; - int8_t padding_[1]; + int8_t padding_[5]; } DukePlayer_t; // KEEPINSYNC lunatic/_defs_game.lua @@ -233,6 +235,8 @@ typedef struct bool horizRecenter; float horizAngleAdjust; int8_t horizSkew; + bool lookLeft; + bool lookRight; int32_t netsynctime; int16_t ping, filler; diff --git a/source/duke3d/src/premap.cpp b/source/duke3d/src/premap.cpp index 7f7e93db9..edef023f0 100644 --- a/source/duke3d/src/premap.cpp +++ b/source/duke3d/src/premap.cpp @@ -719,6 +719,7 @@ void P_ResetPlayer(int playerNum) p.jumping_toggle = 0; p.knee_incs = 0; p.knuckle_incs = 1; + p.lastInputTicks = 0; p.last_full_weapon = 0; p.last_pissed_time = 0; p.loogcnt = 0;