From 6aecd46dbcacc84d5b1aa627d1d9a12cbb7c77b4 Mon Sep 17 00:00:00 2001 From: NY00123 Date: Sat, 18 Apr 2020 00:10:55 +0300 Subject: [PATCH] SW - Hopefully a better way to decide if getinput should call DoPlayerTurn/DoPlayerHorizon while input is tied to the frame rate: Introduce the new player flags PF2_INPUT_CAN_TURN and PF2_INPUT_CAN_AIM. Set PF2_INPUT_CAN_TURN if DoPlayerTurn can be called outside of getinput. Similarly set PF2_INPUT_CAN_AIM if DoPlayerHorizon can be called in this manner. getinput will only call DoPlayerTurn/DoPlayerHorizon if PF2_INPUT_CAN_TURN/PF2_INPUT_CAN_AIM is set. These flags are reset right before the call to the player's current DoPlayerAction function. For one example in which this assists, it's not always the case that DoPlayerDeathFollowKiller may call DoPlayerTurn, even if we assume that pp->input.q16angvel is never zero. --- source/sw/src/game.cpp | 7 ++++--- source/sw/src/game.h | 2 ++ source/sw/src/player.cpp | 7 +++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/source/sw/src/game.cpp b/source/sw/src/game.cpp index 5a72a6fa9..522fec5dd 100644 --- a/source/sw/src/game.cpp +++ b/source/sw/src/game.cpp @@ -3283,11 +3283,12 @@ getinput(SW_PACKET *loc, SWBOOL tied) q16angvel = fix16_floor(q16angvel); q16aimvel = fix16_floor(q16aimvel); } - else if (!TEST(pp->Flags, PF_DEAD) && (pp->DoPlayerAction != DoPlayerTeleportPause)) + else { - if (!TEST(pp->Flags, PF_CLIMBING) && !pp->sop_control) + if (TEST(pp->Flags2, PF2_INPUT_CAN_TURN)) DoPlayerTurn(pp, &pp->camq16ang, q16angvel); - DoPlayerHorizon(pp, &pp->camq16horiz, q16aimvel); + if (TEST(pp->Flags2, PF2_INPUT_CAN_AIM)) + DoPlayerHorizon(pp, &pp->camq16horiz, q16aimvel); } loc->vel += vel; diff --git a/source/sw/src/game.h b/source/sw/src/game.h index f299112e2..083a30b9f 100644 --- a/source/sw/src/game.h +++ b/source/sw/src/game.h @@ -1357,6 +1357,8 @@ extern PLAYER Player[MAX_SW_PLAYERS_REG+1]; #define PF_WEAPON_DOWN (BIT(31)) #define PF2_TELEPORTED (BIT(0)) +#define PF2_INPUT_CAN_TURN (BIT(1)) // Allow calling DoPlayerTurn from getinput +#define PF2_INPUT_CAN_AIM (BIT(2)) // Allow calling DoPlayerHorizon from getinput /////////////////////////////////////////////////////////////////////////////////////////// // diff --git a/source/sw/src/player.cpp b/source/sw/src/player.cpp index b9d99b1fb..b27035b15 100644 --- a/source/sw/src/player.cpp +++ b/source/sw/src/player.cpp @@ -1545,6 +1545,7 @@ DoPlayerTurn(PLAYERp pp, fix16_t *pq16ang, fix16_t q16angvel) if (!PedanticMode && (pq16ang == &pp->q16ang)) { + SET(pp->Flags2, PF2_INPUT_CAN_TURN); pp->q16ang = pp->oq16ang = pp->input.q16ang; sprite[pp->PlayerSprite].ang = fix16_to_int(*pq16ang); if (!Prediction) @@ -1914,6 +1915,7 @@ DoPlayerHorizon(PLAYERp pp, fix16_t *pq16horiz, fix16_t q16aimvel) if (!PedanticMode && (pq16horiz == &pp->q16horiz)) { + SET(pp->Flags2, PF2_INPUT_CAN_AIM); pp->q16horiz = pp->oq16horiz = pp->input.q16horiz; return; } @@ -6779,6 +6781,9 @@ void DoPlayerDeathFollowKiller(PLAYERp pp) //DoPlayerDeathTilt(pp, pp->tilt_dest, 4 * synctics); // allow turning + if (TEST(pp->Flags, PF_DEAD_HEAD|PF_HEAD_CONTROL)) + SET(pp->Flags2, PF2_INPUT_CAN_TURN); + if ((TEST(pp->Flags, PF_DEAD_HEAD) && pp->input.q16angvel != 0) || TEST(pp->Flags, PF_HEAD_CONTROL)) { DoPlayerTurn(pp, &pp->q16ang, pp->input.q16angvel); @@ -8021,6 +8026,8 @@ domovethings(void) DoPlayerSectorUpdatePreMove(pp); ChopsCheck(pp); + // Reset flags used while tying input to framerate + RESET(pp->Flags2, PF2_INPUT_CAN_TURN|PF2_INPUT_CAN_AIM); // extern SWBOOL ScrollMode2D; //if (!ScrollMode2D) if (pp->DoPlayerAction) pp->DoPlayerAction(pp);