From 5299a0625d6b5ad7e1f54f8fe8c60525ef327f56 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Wed, 13 May 2020 15:14:49 +1000 Subject: [PATCH] RR: 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/rr/src/game.cpp | 2 +- source/rr/src/player.cpp | 214 +++++++++++++++++++++++++++++---------- source/rr/src/player.h | 6 +- source/rr/src/premap.cpp | 1 + 4 files changed, 165 insertions(+), 58 deletions(-) diff --git a/source/rr/src/game.cpp b/source/rr/src/game.cpp index 4c791c7aa..eb9ffa065 100644 --- a/source/rr/src/game.cpp +++ b/source/rr/src/game.cpp @@ -916,7 +916,7 @@ void G_DrawRooms(int32_t playerNum, int32_t smoothRatio) )) { #ifdef USE_OPENGL - 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)); #endif pPlayer->oq16rotscrnang = pPlayer->q16rotscrnang; } diff --git a/source/rr/src/player.cpp b/source/rr/src/player.cpp index cfe0d477d..a9fbb2ba7 100644 --- a/source/rr/src/player.cpp +++ b/source/rr/src/player.cpp @@ -3205,6 +3205,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 ((pPlayer->gm & (MODE_MENU|MODE_TYPE)) || (ud.pause_on && !inputState.GetKeyStatus(sc_Pause))) @@ -3270,11 +3271,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); }; @@ -3509,6 +3512,48 @@ 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))); + } + + if (RRRA && pPlayer->sea_sick) + { + if (pPlayer->sea_sick < 250) + { + if (pPlayer->sea_sick >= 180) + pPlayer->q16rotscrnang = fix16_sadd(pPlayer->q16rotscrnang, fix16_from_dbl(scaleAdjustmentToInterval(24))); + else if (pPlayer->sea_sick >= 130) + pPlayer->q16rotscrnang = fix16_ssub(pPlayer->q16rotscrnang, fix16_from_dbl(scaleAdjustmentToInterval(24))); + else if (pPlayer->sea_sick >= 70) + pPlayer->q16rotscrnang = fix16_sadd(pPlayer->q16rotscrnang, fix16_from_dbl(scaleAdjustmentToInterval(24))); + else if (pPlayer->sea_sick >= 20) + pPlayer->q16rotscrnang = fix16_sadd(pPlayer->q16rotscrnang, fix16_from_dbl(scaleAdjustmentToInterval(24))); + } + if (pPlayer->sea_sick < 250) + pPlayer->q16look_ang = fix16_sadd(pPlayer->q16look_ang, fix16_from_dbl(scaleAdjustmentToInterval((krand2()&255)-128))); + } + } + // A horiz diff of 128 equal 45 degrees, so we convert horiz to 1024 angle units if (thisPlayer.horizAngleAdjust) @@ -3571,6 +3616,7 @@ void P_GetInputMotorcycle(int playerNum) { auto &thisPlayer = g_player[playerNum]; auto const pPlayer = thisPlayer.ps; + auto const pSprite = &sprite[pPlayer->i]; ControlInfo info; if ((pPlayer->gm & (MODE_MENU|MODE_TYPE)) || (ud.pause_on && !inputState.GetKeyStatus(sc_Pause))) @@ -3612,11 +3658,13 @@ void P_GetInputMotorcycle(int 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); }; @@ -3791,6 +3839,27 @@ void P_GetInputMotorcycle(int playerNum) } } + // don't adjust rotscrnang and look_ang if dead. + if (pSprite->extra > 0) + { + if (RRRA && pPlayer->sea_sick) + { + if (pPlayer->sea_sick < 250) + { + if (pPlayer->sea_sick >= 180) + pPlayer->q16rotscrnang = fix16_sadd(pPlayer->q16rotscrnang, fix16_from_dbl(scaleAdjustmentToInterval(24))); + else if (pPlayer->sea_sick >= 130) + pPlayer->q16rotscrnang = fix16_ssub(pPlayer->q16rotscrnang, fix16_from_dbl(scaleAdjustmentToInterval(24))); + else if (pPlayer->sea_sick >= 70) + pPlayer->q16rotscrnang = fix16_sadd(pPlayer->q16rotscrnang, fix16_from_dbl(scaleAdjustmentToInterval(24))); + else if (pPlayer->sea_sick >= 20) + pPlayer->q16rotscrnang = fix16_sadd(pPlayer->q16rotscrnang, fix16_from_dbl(scaleAdjustmentToInterval(24))); + } + if (pPlayer->sea_sick < 250) + pPlayer->q16look_ang = fix16_sadd(pPlayer->q16look_ang, fix16_from_dbl(scaleAdjustmentToInterval((krand2()&255)-128))); + } + } + if (TEST_SYNC_KEY(localInput.bits, SK_JUMP)) { localInput.bits |= 1; @@ -3801,6 +3870,7 @@ void P_GetInputBoat(int playerNum) { auto &thisPlayer = g_player[playerNum]; auto const pPlayer = thisPlayer.ps; + auto const pSprite = &sprite[pPlayer->i]; ControlInfo info; if ((pPlayer->gm & (MODE_MENU|MODE_TYPE)) || (ud.pause_on && !inputState.GetKeyStatus(sc_Pause))) @@ -3842,11 +3912,13 @@ void P_GetInputBoat(int 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); }; @@ -4001,6 +4073,27 @@ void P_GetInputBoat(int playerNum) pPlayer->q16ang = fix16_sadd(pPlayer->q16ang, input.q16avel) & 0x7FFFFFF; } } + + // don't adjust rotscrnang and look_ang if dead. + if (pSprite->extra > 0) + { + if (RRRA && pPlayer->sea_sick) + { + if (pPlayer->sea_sick < 250) + { + if (pPlayer->sea_sick >= 180) + pPlayer->q16rotscrnang = fix16_sadd(pPlayer->q16rotscrnang, fix16_from_dbl(scaleAdjustmentToInterval(24))); + else if (pPlayer->sea_sick >= 130) + pPlayer->q16rotscrnang = fix16_ssub(pPlayer->q16rotscrnang, fix16_from_dbl(scaleAdjustmentToInterval(24))); + else if (pPlayer->sea_sick >= 70) + pPlayer->q16rotscrnang = fix16_sadd(pPlayer->q16rotscrnang, fix16_from_dbl(scaleAdjustmentToInterval(24))); + else if (pPlayer->sea_sick >= 20) + pPlayer->q16rotscrnang = fix16_sadd(pPlayer->q16rotscrnang, fix16_from_dbl(scaleAdjustmentToInterval(24))); + } + if (pPlayer->sea_sick < 250) + pPlayer->q16look_ang = fix16_sadd(pPlayer->q16look_ang, fix16_from_dbl(scaleAdjustmentToInterval((krand2()&255)-128))); + } + } } int dword_A99D4, dword_A99D8, dword_A99DC, dword_A99E0; @@ -4026,6 +4119,7 @@ void P_DHGetInput(int const playerNum) { auto &thisPlayer = g_player[playerNum]; auto const pPlayer = thisPlayer.ps; + auto const pSprite = &sprite[pPlayer->i]; ControlInfo info; if ((pPlayer->gm & (MODE_MENU|MODE_TYPE)) || (ud.pause_on && !inputState.GetKeyStatus(sc_Pause))) @@ -4083,11 +4177,13 @@ void P_DHGetInput(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); }; @@ -4178,6 +4274,31 @@ void P_DHGetInput(int const playerNum) if (pPlayer->cursectnum >= 0 && sector[pPlayer->cursectnum].hitag == 2003) input.fvel >>= 1; + // 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) @@ -7816,24 +7937,21 @@ check_enemy_sprite: 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) && (!RRRA || !pPlayer->on_motorcycle)) { // look_left if (VM_OnEvent(EVENT_LOOKLEFT,pPlayer->i,playerNum) == 0) { - pPlayer->q16look_ang = fix16_ssub(pPlayer->q16look_ang, fix16_from_int(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) && (!RRRA || !pPlayer->on_motorcycle)) @@ -7841,26 +7959,16 @@ check_enemy_sprite: // look_right if (VM_OnEvent(EVENT_LOOKRIGHT,pPlayer->i,playerNum) == 0) { - pPlayer->q16look_ang = fix16_sadd(pPlayer->q16look_ang, fix16_from_int(152)); - pPlayer->q16rotscrnang = fix16_ssub(pPlayer->q16rotscrnang, fix16_from_int(24)); + thisPlayer.lookRight = true; + } + else + { + thisPlayer.lookRight = false; } } - - if (RRRA && pPlayer->sea_sick) + else { - if (pPlayer->sea_sick < 250) - { - if (pPlayer->sea_sick >= 180) - pPlayer->q16rotscrnang = fix16_sadd(pPlayer->q16rotscrnang, fix16_from_int(24)); - else if (pPlayer->sea_sick >= 130) - pPlayer->q16rotscrnang = fix16_ssub(pPlayer->q16rotscrnang, fix16_from_int(24)); - else if (pPlayer->sea_sick >= 70) - pPlayer->q16rotscrnang = fix16_sadd(pPlayer->q16rotscrnang, fix16_from_int(24)); - else if (pPlayer->sea_sick >= 20) - pPlayer->q16rotscrnang = fix16_sadd(pPlayer->q16rotscrnang, fix16_from_int(24)); - } - if (pPlayer->sea_sick < 250) - pPlayer->q16look_ang = fix16_sadd(pPlayer->q16look_ang, fix16_from_int((krand2()&255)-128)); + thisPlayer.lookRight = false; } int velocityModifier = TICSPERFRAME; @@ -9071,28 +9179,24 @@ void P_DHProcessInput(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) && !pPlayer->on_motorcycle) { // look_left - pPlayer->q16look_ang = fix16_ssub(pPlayer->q16look_ang, fix16_from_int(152)); - pPlayer->q16rotscrnang = fix16_sadd(pPlayer->q16rotscrnang, fix16_from_int(24)); + thisPlayer.lookLeft = true; + } + else + { + thisPlayer.lookLeft = false; } if (TEST_SYNC_KEY(playerBits, SK_LOOK_RIGHT) && !pPlayer->on_motorcycle) { // look_right - pPlayer->q16look_ang = fix16_sadd(pPlayer->q16look_ang, fix16_from_int(152)); - pPlayer->q16rotscrnang = fix16_ssub(pPlayer->q16rotscrnang, fix16_from_int(24)); + thisPlayer.lookRight = true; + } + else + { + thisPlayer.lookRight = false; } int velocityModifier = TICSPERFRAME; diff --git a/source/rr/src/player.h b/source/rr/src/player.h index fa65df9e4..5a77d2a96 100644 --- a/source/rr/src/player.h +++ b/source/rr/src/player.h @@ -222,12 +222,12 @@ typedef struct { int32_t drug_timer; int32_t sea_sick; uint8_t hurt_delay2, nocheat; - double tilt_status; + double tilt_status, lastInputTicks; int32_t dhat60f, dhat613, dhat617, dhat61b, dhat61f; int8_t crouch_toggle; - int8_t padding_[7]; + int8_t padding_[3]; } DukePlayer_t; // KEEPINSYNC lunatic/_defs_game.lua @@ -239,6 +239,8 @@ typedef struct bool horizRecenter; float horizAngleAdjust; int8_t horizSkew; + bool lookLeft; + bool lookRight; int32_t movefifoend, syncvalhead, myminlag; int32_t pcolor, pteam; diff --git a/source/rr/src/premap.cpp b/source/rr/src/premap.cpp index 249d44cf5..9731a1967 100644 --- a/source/rr/src/premap.cpp +++ b/source/rr/src/premap.cpp @@ -819,6 +819,7 @@ void P_ResetPlayer(int playerNum) if (!RR) pPlayer->q16rotscrnang = 0; pPlayer->runspeed = g_playerFriction; pPlayer->falling_counter = 0; + pPlayer->lastInputTicks = 0; P_ResetTintFade(pPlayer);