diff --git a/source/blood/src/blood.h b/source/blood/src/blood.h index 2f8e81afd..e7300f64d 100644 --- a/source/blood/src/blood.h +++ b/source/blood/src/blood.h @@ -102,6 +102,7 @@ struct GameInterface : ::GameInterface void SetTileProps(int til, int surf, int vox, int shade) override; fixed_t playerHorizMin() override { return IntToFixed(-80); } fixed_t playerHorizMax() override { return IntToFixed(220); } + int playerKeyMove() override { return 1024; } GameStats getStats() override; }; diff --git a/source/blood/src/controls.cpp b/source/blood/src/controls.cpp index 41c2d59e5..c6a6a507b 100644 --- a/source/blood/src/controls.cpp +++ b/source/blood/src/controls.cpp @@ -30,128 +30,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. BEGIN_BLD_NS -static const double gTurnSpeed = 92.; static InputPacket gInput; -static double turnHeldTime; - -enum -{ - MAXFVEL = 2048, - MAXSVEL = 2048, - MAXHORIZVEL = 128 -}; void UpdatePlayerSpriteAngle(PLAYER* pPlayer); -//--------------------------------------------------------------------------- -// -// handles movement -// -//--------------------------------------------------------------------------- - -static void processMovement(ControlInfo* const hidInput) -{ - double const scaleAdjust = InputScale(); - int const run = !!(gInput.actions & SB_RUN); - int const keyMove = (1 + run) << 10; - InputPacket input = {}; - - if (buttonMap.ButtonDown(gamefunc_Strafe)) - { - input.svel -= xs_CRoundToInt((hidInput->mousex * 32.) + (scaleAdjust * (hidInput->dyaw * keyMove))); - } - else - { - input.q16avel += FloatToFixed(hidInput->mousex + (scaleAdjust * hidInput->dyaw)); - } - - if (!(gInput.actions & SB_AIMMODE)) - { - input.q16horz += FloatToFixed(hidInput->mousey); - } - else - { - input.fvel -= xs_CRoundToInt(hidInput->mousey * 64.); - } - - if (!in_mouseflip) - input.q16horz = -input.q16horz; - - input.q16horz -= FloatToFixed(scaleAdjust * hidInput->dpitch); - input.svel -= xs_CRoundToInt(scaleAdjust * (hidInput->dx * keyMove)); - input.fvel -= xs_CRoundToInt(scaleAdjust * (hidInput->dz * keyMove)); - - if (buttonMap.ButtonDown(gamefunc_Strafe)) - { - if (gInput.svel < keyMove && gInput.svel > -keyMove) - { - if (buttonMap.ButtonDown(gamefunc_Turn_Left)) - input.svel += keyMove; - - if (buttonMap.ButtonDown(gamefunc_Turn_Right)) - input.svel -= keyMove; - } - } - else - { - if (buttonMap.ButtonDown(gamefunc_Turn_Left)) - { - turnHeldTime += scaleAdjust * kTicsPerFrame; - input.q16avel -= FloatToFixed(scaleAdjust * (min(12. * turnHeldTime, gTurnSpeed) / 4.)); - } - else if (buttonMap.ButtonDown(gamefunc_Turn_Right)) - { - turnHeldTime += scaleAdjust * kTicsPerFrame; - input.q16avel += FloatToFixed(scaleAdjust * (min(12. * turnHeldTime, gTurnSpeed) / 4.)); - } - else - { - turnHeldTime = 0; - } - } - - if (run && turnHeldTime > 24.) - input.q16avel <<= 1; - - if (abs(gInput.fvel) < keyMove) - { - if (buttonMap.ButtonDown(gamefunc_Move_Forward)) - input.fvel += keyMove; - - if (buttonMap.ButtonDown(gamefunc_Move_Backward)) - input.fvel -= keyMove; - } - - if (abs(gInput.svel) < keyMove) - { - if (buttonMap.ButtonDown(gamefunc_Strafe_Left)) - input.svel += keyMove; - - if (buttonMap.ButtonDown(gamefunc_Strafe_Right)) - input.svel -= keyMove; - } - - if (!cl_syncinput && gamestate == GS_LEVEL) - { - PLAYER* pPlayer = &gPlayer[myconnectindex]; - - // Perform unsynchronised angle/horizon if not dead. - if (gView->pXSprite->health != 0) - { - applylook(&pPlayer->q16ang, &pPlayer->q16look_ang, &pPlayer->q16rotscrnang, &pPlayer->spin, input.q16avel, &pPlayer->input.actions, scaleAdjust, pPlayer->posture != 0); - UpdatePlayerSpriteAngle(pPlayer); - sethorizon(&pPlayer->q16horiz, input.q16horz, &pPlayer->input.actions, scaleAdjust); - } - - playerProcessHelpers(&pPlayer->q16ang, &pPlayer->angAdjust, &pPlayer->angTarget, &pPlayer->q16horiz, &pPlayer->horizAdjust, &pPlayer->horizTarget, scaleAdjust); - } - - gInput.fvel = clamp(gInput.fvel + input.fvel, -MAXFVEL, MAXFVEL); - gInput.svel = clamp(gInput.svel + input.svel, -MAXSVEL, MAXSVEL); - gInput.q16avel += input.q16avel; - gInput.q16horz = clamp(gInput.q16horz + input.q16horz, -IntToFixed(MAXHORIZVEL), IntToFixed(MAXHORIZVEL)); -} - void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput) { if (paused || M_Active()) @@ -160,8 +42,26 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput) return; } + double const scaleAdjust = InputScale(); + InputPacket input {}; + ApplyGlobalInput(gInput, hidInput); - processMovement(hidInput); + processMovement(&input, &gInput, hidInput, true, scaleAdjust); + + if (!cl_syncinput && gamestate == GS_LEVEL) + { + PLAYER* pPlayer = &gPlayer[myconnectindex]; + + // Perform unsynchronised angle/horizon if not dead. + if (gView->pXSprite->health != 0) + { + applylook(&pPlayer->q16ang, &pPlayer->q16look_ang, &pPlayer->q16rotscrnang, &pPlayer->spin, input.q16avel, &pPlayer->input.actions, scaleAdjust, pPlayer->posture != 0); + sethorizon(&pPlayer->q16horiz, input.q16horz, &pPlayer->input.actions, scaleAdjust); + } + + playerProcessHelpers(&pPlayer->q16ang, &pPlayer->angAdjust, &pPlayer->angTarget, &pPlayer->q16horiz, &pPlayer->horizAdjust, &pPlayer->horizTarget, scaleAdjust); + UpdatePlayerSpriteAngle(pPlayer); + } if (packet) { @@ -179,7 +79,6 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput) void GameInterface::clearlocalinputstate() { gInput = {}; - turnHeldTime = 0; } END_BLD_NS diff --git a/source/core/gamecontrol.cpp b/source/core/gamecontrol.cpp index cf89415e5..7fb6d4f27 100644 --- a/source/core/gamecontrol.cpp +++ b/source/core/gamecontrol.cpp @@ -1488,6 +1488,130 @@ fixed_t getincangleq16(fixed_t a, fixed_t na) } } +//--------------------------------------------------------------------------- +// +// Player's movement function, called from game's ticker or from gi->GetInput() as required. +// +//--------------------------------------------------------------------------- + +void processMovement(InputPacket* currInput, InputPacket* inputBuffer, ControlInfo* const hidInput, bool const allowstrafe, double const scaleAdjust, int const turnscale, short const drink_amt) +{ + // set up variables + bool const mouseaim = !(inputBuffer->actions & SB_AIMMODE); + int const running = !!(inputBuffer->actions & SB_RUN); + int const keymove = gi->playerKeyMove() << running; + int const mousevelscale = g_gameType & GAMEFLAG_BLOOD ? 32 : 4; + + // process mouse and initial controller input. + if (buttonMap.ButtonDown(gamefunc_Strafe) && allowstrafe) + currInput->svel -= xs_CRoundToInt((hidInput->mousex * mousevelscale) + (scaleAdjust * (hidInput->dyaw * keymove))); + else + currInput->q16avel += FloatToFixed(hidInput->mousex + (scaleAdjust * hidInput->dyaw)); + + if (mouseaim) + currInput->q16horz -= FloatToFixed(hidInput->mousey); + else + currInput->fvel -= xs_CRoundToInt(hidInput->mousey * mousevelscale * 2); + + if (in_mouseflip) + currInput->q16horz = -currInput->q16horz; + + // process remaining controller input. + currInput->q16horz -= FloatToFixed(scaleAdjust * hidInput->dpitch); + currInput->svel -= xs_CRoundToInt(scaleAdjust * (hidInput->dx * keymove)); + currInput->fvel -= xs_CRoundToInt(scaleAdjust * (hidInput->dz * keymove)); + + // process keyboard turning keys. + if (buttonMap.ButtonDown(gamefunc_Strafe) && allowstrafe) + { + if (abs(inputBuffer->svel) < keymove) + { + if (buttonMap.ButtonDown(gamefunc_Turn_Left)) + currInput->svel += keymove; + + if (buttonMap.ButtonDown(gamefunc_Turn_Right)) + currInput->svel -= keymove; + } + } + else + { + static double turnheldtime; + int const turnheldamt = 120 / GameTicRate; + double const turboturntime = 590. / GameTicRate; + double turnamount = ((running ? 1735. : 867.5) / GameTicRate) * turnscale; + double preambleturn = turnamount / 3.; + + // allow Exhumed to use its legacy values given the drastic difference from the other games. + if ((g_gameType & GAMEFLAG_PSEXHUMED) && cl_exhumedoldturn) + { + turnamount = running ? 12 : 8; + preambleturn = turnamount; + } + + if (buttonMap.ButtonDown(gamefunc_Turn_Left) || (buttonMap.ButtonDown(gamefunc_Strafe_Left) && !allowstrafe)) + { + turnheldtime += scaleAdjust * turnheldamt; + currInput->q16avel -= FloatToFixed(scaleAdjust * (turnheldtime >= turboturntime ? turnamount : preambleturn)); + } + else if (buttonMap.ButtonDown(gamefunc_Turn_Right) || (buttonMap.ButtonDown(gamefunc_Strafe_Right) && !allowstrafe)) + { + turnheldtime += scaleAdjust * turnheldamt; + currInput->q16avel += FloatToFixed(scaleAdjust * (turnheldtime >= turboturntime ? turnamount : preambleturn)); + } + else + { + turnheldtime = 0; + } + } + + // process keyboard forward/side velocity keys. + if (abs(inputBuffer->svel) < keymove) + { + if (buttonMap.ButtonDown(gamefunc_Strafe_Left) && allowstrafe) + currInput->svel += keymove; + + if (buttonMap.ButtonDown(gamefunc_Strafe_Right) && allowstrafe) + currInput->svel -= keymove; + } + if (abs(inputBuffer->fvel) < keymove) + { + if (isRR() && drink_amt >= 66 && drink_amt <= 87) + { + if (buttonMap.ButtonDown(gamefunc_Move_Forward)) + { + currInput->fvel += keymove; + if (drink_amt & 1) + currInput->svel += keymove; + else + currInput->svel -= keymove; + } + + if (buttonMap.ButtonDown(gamefunc_Move_Backward)) + { + currInput->fvel -= keymove; + if (drink_amt & 1) + currInput->svel -= keymove; + else + currInput->svel += keymove; + } + } + else + { + if (buttonMap.ButtonDown(gamefunc_Move_Forward)) + currInput->fvel += keymove; + + if (buttonMap.ButtonDown(gamefunc_Move_Backward)) + currInput->fvel -= keymove; + } + } + + // add collected input to game's local input accumulation packet. + inputBuffer->fvel = clamp(inputBuffer->fvel + currInput->fvel, -keymove, keymove); + inputBuffer->svel = clamp(inputBuffer->svel + currInput->svel, -keymove, keymove); + inputBuffer->q16avel += currInput->q16avel; + inputBuffer->q16horz += currInput->q16horz; +} + //--------------------------------------------------------------------------- // // Player's horizon function, called from game's ticker or from gi->GetInput() as required. diff --git a/source/core/gamecontrol.h b/source/core/gamecontrol.h index fc92a6f1b..e11ab1fd3 100644 --- a/source/core/gamecontrol.h +++ b/source/core/gamecontrol.h @@ -67,6 +67,7 @@ void CompleteLevel(MapRecord* map); int getincangle(int c, int n); fixed_t getincangleq16(fixed_t c, fixed_t n); +void processMovement(InputPacket* currInput, InputPacket* inputBuffer, ControlInfo* const hidInput, bool const allowstrafe, double const scaleAdjust, int const turnscale = 1, short const drink_amt = 0); void sethorizon(fixed_t* q16horiz, fixed_t const q16horz, ESyncBits* actions, double const scaleAdjust); void applylook(fixed_t* q16ang, fixed_t* q16look_ang, fixed_t* q16rotscrnang, fixed_t* spin, fixed_t const q16avel, ESyncBits* actions, double const scaleAdjust, bool const crouching); void playerAddAngle(fixed_t* q16ang, double* helper, double adjustment); diff --git a/source/core/gamecvars.cpp b/source/core/gamecvars.cpp index c7c4548f7..d4c5be0c5 100644 --- a/source/core/gamecvars.cpp +++ b/source/core/gamecvars.cpp @@ -82,6 +82,7 @@ CVARD(Bool, cl_dukefixrpgrecoil, false, CVAR_ARCHIVE, "soften recoil of Duke 3D' CVARD(Bool, cl_smoothsway, false, CVAR_ARCHIVE, "move SW weapon left and right smoothly while bobbing") CVARD(Bool, cl_showmagamt, false, CVAR_ARCHIVE, "show the amount of rounds left in the magazine of your weapon on the modern HUD") CVARD(Bool, cl_nomeleeblur, false, CVAR_ARCHIVE, "enable/disable blur effect with melee weapons in SW") +CVARD(Bool, cl_exhumedoldturn, false, CVAR_ARCHIVE, "enable/disable legacy turning speed for Powerslave/Exhumed") CUSTOM_CVARD(Int, cl_crosshairscale, 50, CVAR_ARCHIVE, "changes the size of the crosshair") { if (self < 1) self = 1; diff --git a/source/core/gamecvars.h b/source/core/gamecvars.h index bcc11b94d..e89f97bfd 100644 --- a/source/core/gamecvars.h +++ b/source/core/gamecvars.h @@ -27,6 +27,7 @@ EXTERN_CVAR(Bool, cl_dukefixrpgrecoil) EXTERN_CVAR(Bool, cl_smoothsway) EXTERN_CVAR(Bool, cl_showmagamt) EXTERN_CVAR(Bool, cl_nomeleeblur) +EXTERN_CVAR(Bool, cl_exhumedoldturn) EXTERN_CVAR(Bool, demorec_seeds_cvar) EXTERN_CVAR(Bool, demoplay_diffs) diff --git a/source/core/gamestruct.h b/source/core/gamestruct.h index e4d442be0..62edcee70 100644 --- a/source/core/gamestruct.h +++ b/source/core/gamestruct.h @@ -110,6 +110,7 @@ struct GameInterface virtual void SetTileProps(int tile, int surf, int vox, int shade) {} virtual fixed_t playerHorizMin() { return IntToFixed(-99); } virtual fixed_t playerHorizMax() { return IntToFixed(299); } + virtual int playerKeyMove() { return 0; } virtual FString statFPS() { diff --git a/source/exhumed/src/exhumed.h b/source/exhumed/src/exhumed.h index d9aa19767..c4d669ba4 100644 --- a/source/exhumed/src/exhumed.h +++ b/source/exhumed/src/exhumed.h @@ -263,6 +263,7 @@ struct GameInterface : ::GameInterface bool DrawAutomapPlayer(int x, int y, int z, int a) override; fixed_t playerHorizMin() override { return IntToFixed(-50); } fixed_t playerHorizMax() override { return IntToFixed(250); } + int playerKeyMove() override { return 6; } ::GameStats getStats() override; }; diff --git a/source/exhumed/src/input.cpp b/source/exhumed/src/input.cpp index bef919f6f..43fe9e6d5 100644 --- a/source/exhumed/src/input.cpp +++ b/source/exhumed/src/input.cpp @@ -94,118 +94,6 @@ void CheckKeys2() } -static void processMovement(ControlInfo* const hidInput) -{ - // JBF: Run key behaviour is selectable - int const playerRunning = !!(localInput.actions & SB_RUN); - int const turnAmount = playerRunning ? 12 : 8; - int const keyMove = playerRunning ? 12 : 6; - bool const mouseaim = !(localInput.actions & SB_AIMMODE); - double const scaleAdjust = InputScale(); - InputPacket tempinput {}; - - if (buttonMap.ButtonDown(gamefunc_Strafe)) - { - tempinput.svel -= xs_CRoundToInt((hidInput->mousex * 32.) + (scaleAdjust * (hidInput->dyaw * keyMove))); - } - else - { - tempinput.q16avel += FloatToFixed(hidInput->mousex + (scaleAdjust * hidInput->dyaw)); - } - - if (mouseaim) - { - tempinput.q16horz += FloatToFixed(hidInput->mousey); - } - else - { - tempinput.fvel -= xs_CRoundToInt(hidInput->mousey * 8.); - } - - if (!in_mouseflip) - tempinput.q16horz = -tempinput.q16horz; - - tempinput.q16horz -= FloatToFixed(scaleAdjust * hidInput->dpitch); - tempinput.svel -= xs_CRoundToInt(scaleAdjust * (hidInput->dx * keyMove)); - tempinput.fvel -= xs_CRoundToInt(scaleAdjust * (hidInput->dz * keyMove)); - - if (buttonMap.ButtonDown(gamefunc_Strafe)) - { - if (buttonMap.ButtonDown(gamefunc_Turn_Left)) - tempinput.svel -= -keyMove; - - if (buttonMap.ButtonDown(gamefunc_Turn_Right)) - tempinput.svel -= keyMove; - } - else - { - if (buttonMap.ButtonDown(gamefunc_Turn_Left)) - { - turn -= 2; - - if (turn < -turnAmount) - turn = -turnAmount; - } - else if (buttonMap.ButtonDown(gamefunc_Turn_Right)) - { - turn += 2; - - if (turn > turnAmount) - turn = turnAmount; - } - - if (turn < 0) - { - turn++; - if (turn > 0) - turn = 0; - } - - if (turn > 0) - { - turn--; - if (turn < 0) - turn = 0; - } - - //if ((counter++) % 4 == 0) // what was this for??? - tempinput.q16avel += FloatToFixed(scaleAdjust * (turn * 2)); - - } - - if (buttonMap.ButtonDown(gamefunc_Strafe_Left)) - tempinput.svel += keyMove; - - if (buttonMap.ButtonDown(gamefunc_Strafe_Right)) - tempinput.svel += -keyMove; - - if (buttonMap.ButtonDown(gamefunc_Move_Forward)) - tempinput.fvel += keyMove; - - if (buttonMap.ButtonDown(gamefunc_Move_Backward)) - tempinput.fvel += -keyMove; - - localInput.fvel = clamp(localInput.fvel + tempinput.fvel, -12, 12); - localInput.svel = clamp(localInput.svel + tempinput.svel, -12, 12); - localInput.q16avel += tempinput.q16avel; - localInput.q16horz += tempinput.q16horz; - - if (!cl_syncinput) - { - Player* pPlayer = &PlayerList[nLocalPlayer]; - - if (!nFreeze) - { - applylook(&pPlayer->q16angle, &pPlayer->q16look_ang, &pPlayer->q16rotscrnang, &pPlayer->spin, tempinput.q16avel, &sPlayerInput[nLocalPlayer].actions, scaleAdjust, eyelevel[nLocalPlayer] > -14080); - sethorizon(&pPlayer->q16horiz, tempinput.q16horz, &sPlayerInput[nLocalPlayer].actions, scaleAdjust); - UpdatePlayerSpriteAngle(pPlayer); - } - - playerProcessHelpers(&pPlayer->q16angle, &pPlayer->angAdjust, &pPlayer->angTarget, &pPlayer->q16horiz, &pPlayer->horizAdjust, &pPlayer->horizTarget, scaleAdjust); - } -} - - void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput) { if (paused || M_Active()) @@ -228,8 +116,29 @@ void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput) return; } - processMovement(hidInput); - if (packet) *packet = localInput; + double const scaleAdjust = InputScale(); + InputPacket input {}; + + processMovement(&input, &localInput, hidInput, true, scaleAdjust); + + if (!cl_syncinput) + { + Player* pPlayer = &PlayerList[nLocalPlayer]; + + if (!nFreeze) + { + applylook(&pPlayer->q16angle, &pPlayer->q16look_ang, &pPlayer->q16rotscrnang, &pPlayer->spin, input.q16avel, &sPlayerInput[nLocalPlayer].actions, scaleAdjust, eyelevel[nLocalPlayer] > -14080); + sethorizon(&pPlayer->q16horiz, input.q16horz, &sPlayerInput[nLocalPlayer].actions, scaleAdjust); + } + + playerProcessHelpers(&pPlayer->q16angle, &pPlayer->angAdjust, &pPlayer->angTarget, &pPlayer->q16horiz, &pPlayer->horizAdjust, &pPlayer->horizTarget, scaleAdjust); + UpdatePlayerSpriteAngle(pPlayer); + } + + if (packet) + { + *packet = localInput; + } } //--------------------------------------------------------------------------- diff --git a/source/games/duke/src/duke3d.h b/source/games/duke/src/duke3d.h index 1dbd230e8..d5b079606 100644 --- a/source/games/duke/src/duke3d.h +++ b/source/games/duke/src/duke3d.h @@ -62,6 +62,7 @@ struct GameInterface : public ::GameInterface void NewGame(MapRecord* map, int skill) override; void LevelCompleted(MapRecord* map, int skill) override; bool DrawAutomapPlayer(int x, int y, int z, int a) override; + int playerKeyMove() override { return 40; } }; diff --git a/source/games/duke/src/input.cpp b/source/games/duke/src/input.cpp index 6ed72818e..89e2dff50 100644 --- a/source/games/duke/src/input.cpp +++ b/source/games/duke/src/input.cpp @@ -580,112 +580,6 @@ int getticssincelastupdate() return tics; } -//--------------------------------------------------------------------------- -// -// handles movement -// -//--------------------------------------------------------------------------- - -static void processMovement(player_struct *p, InputPacket &input, ControlInfo* const hidInput, double scaleFactor) -{ - bool mouseaim = !(loc.actions & SB_AIMMODE); - - // JBF: Run key behaviour is selectable - int running = !!(loc.actions & SB_RUN); - int turnamount = NORMALTURN << running; - int keymove = NORMALKEYMOVE << running; - - if (buttonMap.ButtonDown(gamefunc_Strafe)) - input.svel -= hidInput->mousex * 4.f + scaleFactor * hidInput->dyaw * keymove; - else - input.q16avel += FloatToFixed(hidInput->mousex + scaleFactor * hidInput->dyaw); - - if (mouseaim) - input.q16horz += FloatToFixed(hidInput->mousey); - else - input.fvel -= hidInput->mousey * 8.f; - - if (!in_mouseflip) input.q16horz = -input.q16horz; - - input.q16horz -= FloatToFixed(scaleFactor * (hidInput->dpitch)); - input.svel -= scaleFactor * (hidInput->dx * keymove); - input.fvel -= scaleFactor * (hidInput->dz * keymove); - - if (buttonMap.ButtonDown(gamefunc_Strafe)) - { - if (!loc.svel) - { - if (buttonMap.ButtonDown(gamefunc_Turn_Left)) - input.svel = keymove; - - if (buttonMap.ButtonDown(gamefunc_Turn_Right)) - input.svel = -keymove; - } - } - else - { - int tics = getticssincelastupdate(); - - if (buttonMap.ButtonDown(gamefunc_Turn_Left)) - { - turnheldtime += tics; - input.q16avel -= FloatToFixed(2 * scaleFactor * (turnheldtime >= TURBOTURNTIME ? turnamount : PREAMBLETURN)); - } - else if (buttonMap.ButtonDown(gamefunc_Turn_Right)) - { - turnheldtime += tics; - input.q16avel += FloatToFixed(2 * scaleFactor * (turnheldtime >= TURBOTURNTIME ? turnamount : PREAMBLETURN)); - } - else - { - turnheldtime = 0; - lastcontroltime = 0; - } - - } - - if (abs(loc.svel) < keymove) - { - if (buttonMap.ButtonDown(gamefunc_Strafe_Left)) - input.svel += keymove; - - if (buttonMap.ButtonDown(gamefunc_Strafe_Right)) - input.svel += -keymove; - } - - if (abs(loc.fvel) < keymove) - { - if (isRR() && p->drink_amt >= 66 && p->drink_amt <= 87) - { - if (buttonMap.ButtonDown(gamefunc_Move_Forward)) - { - input.fvel += keymove; - if (p->drink_amt & 1) - input.svel += keymove; - else - input.svel -= keymove; - } - - if (buttonMap.ButtonDown(gamefunc_Move_Backward)) - { - input.fvel += -keymove; - if (p->drink_amt & 1) - input.svel -= keymove; - else - input.svel += keymove; - } - } - else - { - if (buttonMap.ButtonDown(gamefunc_Move_Forward)) - input.fvel += keymove; - - if (buttonMap.ButtonDown(gamefunc_Move_Backward)) - input.fvel += -keymove; - } - } -} - //--------------------------------------------------------------------------- // // split out for readability @@ -952,7 +846,8 @@ static void FinalizeInput(int playerNum, InputPacket& input, bool vehicle) if (p->on_crane < 0 && p->newowner == -1) { - loc.q16avel = clamp(loc.q16avel + input.q16avel, IntToFixed(-MAXANGVEL), IntToFixed(MAXANGVEL)); + // input.q16avel already added to loc in processMovement() + loc.q16avel = clamp(loc.q16avel, IntToFixed(-MAXANGVEL), IntToFixed(MAXANGVEL)); if (!cl_syncinput && input.q16avel) { p->one_eighty_count = 0; @@ -965,7 +860,8 @@ static void FinalizeInput(int playerNum, InputPacket& input, bool vehicle) if (p->newowner == -1 && !(ps[playerNum].sync.actions & SB_CENTERVIEW)) { - loc.q16horz = clamp(loc.q16horz + input.q16horz, IntToFixed(-MAXHORIZVEL), IntToFixed(MAXHORIZVEL)); + // input.q16horz already added to loc in processMovement() + loc.q16horz = clamp(loc.q16horz, IntToFixed(-MAXHORIZVEL), IntToFixed(MAXHORIZVEL)); } else { @@ -974,22 +870,23 @@ static void FinalizeInput(int playerNum, InputPacket& input, bool vehicle) } } + //--------------------------------------------------------------------------- // -// main input handler routine +// External entry point // //--------------------------------------------------------------------------- -static void GetInputInternal(InputPacket &locInput, ControlInfo* const hidInput) +void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput) { - auto const p = &ps[myconnectindex]; - if (paused) { loc = {}; return; } + auto const p = &ps[myconnectindex]; + if (numplayers == 1) { setlocalplayerinput(p); @@ -1013,7 +910,7 @@ static void GetInputInternal(InputPacket &locInput, ControlInfo* const hidInput) else { processInputBits(p, hidInput); - processMovement(p, input, hidInput, scaleAdjust); + processMovement(&input, &loc, hidInput, true, scaleAdjust, 1, p->drink_amt); checkCrouchToggle(p); FinalizeInput(myconnectindex, input, false); } @@ -1031,17 +928,7 @@ static void GetInputInternal(InputPacket &locInput, ControlInfo* const hidInput) playerProcessHelpers(&p->q16ang, &p->angAdjust, &p->angTarget, &p->q16horiz, &p->horizAdjust, &p->horizTarget, scaleAdjust); } -} -//--------------------------------------------------------------------------- -// -// External entry point -// -//--------------------------------------------------------------------------- - -void GameInterface::GetInput(InputPacket* packet, ControlInfo* const hidInput) -{ - GetInputInternal(loc, hidInput); if (packet) { auto const pPlayer = &ps[myconnectindex]; diff --git a/source/sw/src/game.h b/source/sw/src/game.h index dedcf503b..e5197eb3e 100644 --- a/source/sw/src/game.h +++ b/source/sw/src/game.h @@ -2213,6 +2213,7 @@ struct GameInterface : ::GameInterface void NextLevel(MapRecord *map, int skill) override; void NewGame(MapRecord *map, int skill) override; bool DrawAutomapPlayer(int x, int y, int z, int a) override; + int playerKeyMove() override { return 35; } GameStats getStats() override; diff --git a/source/sw/src/input.cpp b/source/sw/src/input.cpp index 348758ce2..f3291dd54 100644 --- a/source/sw/src/input.cpp +++ b/source/sw/src/input.cpp @@ -78,17 +78,16 @@ enum // //--------------------------------------------------------------------------- -static void processInputBits(PLAYERp const pp, ControlInfo* const hidInput, bool* mouseaim) +static void processInputBits(PLAYERp const pp, ControlInfo* const hidInput) { ApplyGlobalInput(loc, hidInput); - *mouseaim = !(loc.actions & SB_AIMMODE); if (!CommEnabled) { // Go back to the source to set this - the old code here was catastrophically bad. // this needs to be fixed properly - as it is this can never be compatible with demo playback. - if (mouseaim) + if (!(loc.actions & SB_AIMMODE)) SET(Player[myconnectindex].Flags, PF_MOUSE_AIMING_ON); else RESET(Player[myconnectindex].Flags, PF_MOUSE_AIMING_ON); @@ -193,129 +192,6 @@ static void processWeapon(PLAYERp const pp) } } -//--------------------------------------------------------------------------- -// -// handles movement -// -//--------------------------------------------------------------------------- - -static void processMovement(PLAYERp const pp, ControlInfo* const hidInput, bool const mouseaim) -{ - double const scaleAdjust = InputScale(); - bool const strafeKey = buttonMap.ButtonDown(gamefunc_Strafe) && !pp->sop; - int32_t turnamount, keymove; - int32_t fvel = 0, svel = 0; - fixed_t q16avel = 0, q16horz = 0; - - if (loc.actions & SB_RUN) - { - turnamount = pp->sop_control ? RUNTURN * 3 : RUNTURN; - keymove = NORMALKEYMOVE << 1; - } - else - { - turnamount = pp->sop_control ? NORMALTURN * 3 : NORMALTURN; - keymove = NORMALKEYMOVE; - } - - if (strafeKey) - { - svel -= xs_CRoundToInt((hidInput->mousex * 4.) + (scaleAdjust * (hidInput->dyaw * keymove))); - } - else - { - q16avel += FloatToFixed(hidInput->mousex + (scaleAdjust * hidInput->dyaw)); - } - - if (mouseaim) - q16horz -= FloatToFixed(hidInput->mousey); - else - fvel -= xs_CRoundToInt(hidInput->mousey * 8.); - - if (in_mouseflip) - q16horz = -q16horz; - - q16horz -= FloatToFixed(scaleAdjust * hidInput->dpitch); - svel -= xs_CRoundToInt(scaleAdjust * (hidInput->dx * keymove)); - fvel -= xs_CRoundToInt(scaleAdjust * (hidInput->dz * keymove)); - - if (strafeKey) - { - if (abs(svel) < keymove) - { - if (buttonMap.ButtonDown(gamefunc_Turn_Left)) - svel += keymove; - if (buttonMap.ButtonDown(gamefunc_Turn_Right)) - svel -= keymove; - } - } - else - { - if (buttonMap.ButtonDown(gamefunc_Turn_Left) || (buttonMap.ButtonDown(gamefunc_Strafe_Left) && pp->sop)) - { - turnheldtime += synctics; - q16avel -= FloatToFixed(scaleAdjust * (turnheldtime >= TURBOTURNTIME ? turnamount : PREAMBLETURN)); - } - else if (buttonMap.ButtonDown(gamefunc_Turn_Right) || (buttonMap.ButtonDown(gamefunc_Strafe_Right) && pp->sop)) - { - turnheldtime += synctics; - q16avel += FloatToFixed(scaleAdjust * (turnheldtime >= TURBOTURNTIME ? turnamount : PREAMBLETURN)); - } - else - { - turnheldtime = 0; - } - } - - if (abs(loc.svel) < keymove) - { - if (buttonMap.ButtonDown(gamefunc_Strafe_Left) && !pp->sop) - svel += keymove; - - if (buttonMap.ButtonDown(gamefunc_Strafe_Right) && !pp->sop) - svel -= keymove; - } - if (abs(loc.fvel) < keymove) - { - if (buttonMap.ButtonDown(gamefunc_Move_Forward)) - fvel += keymove; - - if (buttonMap.ButtonDown(gamefunc_Move_Backward)) - fvel -= keymove; - } - - if (!cl_syncinput) - { - if (TEST(pp->Flags2, PF2_INPUT_CAN_AIM)) - { - DoPlayerHorizon(pp, q16horz, scaleAdjust); - } - - if (TEST(pp->Flags2, PF2_INPUT_CAN_TURN_GENERAL)) - { - DoPlayerTurn(pp, q16avel, scaleAdjust); - } - - if (TEST(pp->Flags2, PF2_INPUT_CAN_TURN_VEHICLE)) - { - DoPlayerTurnVehicle(pp, q16avel, pp->posz + Z(10), labs(pp->posz + Z(10) - pp->sop->floor_loz)); - } - - if (TEST(pp->Flags2, PF2_INPUT_CAN_TURN_TURRET)) - { - DoPlayerTurnTurret(pp, q16avel); - } - - playerProcessHelpers(&pp->q16ang, &pp->angAdjust, &pp->angTarget, &pp->q16horiz, &pp->horizAdjust, &pp->horizTarget, scaleAdjust); - } - - loc.fvel = clamp(loc.fvel + fvel, -MAXFVEL, MAXFVEL); - loc.svel = clamp(loc.svel + svel, -MAXSVEL, MAXSVEL); - - loc.q16avel = clamp(loc.q16avel + q16avel, -IntToFixed(MAXANGVEL), IntToFixed(MAXANGVEL)); - loc.q16horz = clamp(loc.q16horz + q16horz, -IntToFixed(MAXHORIZVEL), IntToFixed(MAXHORIZVEL)); -} - void GameInterface::GetInput(InputPacket *packet, ControlInfo* const hidInput) { if (paused || M_Active()) @@ -324,13 +200,39 @@ void GameInterface::GetInput(InputPacket *packet, ControlInfo* const hidInput) return; } + double const scaleAdjust = InputScale(); + InputPacket input {}; PLAYERp pp = &Player[myconnectindex]; - bool mouseaim; - processInputBits(pp, hidInput, &mouseaim); - processMovement(pp, hidInput, mouseaim); + processInputBits(pp, hidInput); + processMovement(&input, &loc, hidInput, true, scaleAdjust, pp->sop_control ? 3 : 1); processWeapon(pp); + if (!cl_syncinput) + { + if (TEST(pp->Flags2, PF2_INPUT_CAN_AIM)) + { + DoPlayerHorizon(pp, input.q16horz, scaleAdjust); + } + + if (TEST(pp->Flags2, PF2_INPUT_CAN_TURN_GENERAL)) + { + DoPlayerTurn(pp, input.q16avel, scaleAdjust); + } + + if (TEST(pp->Flags2, PF2_INPUT_CAN_TURN_VEHICLE)) + { + DoPlayerTurnVehicle(pp, input.q16avel, pp->posz + Z(10), labs(pp->posz + Z(10) - pp->sop->floor_loz)); + } + + if (TEST(pp->Flags2, PF2_INPUT_CAN_TURN_TURRET)) + { + DoPlayerTurnTurret(pp, input.q16avel); + } + + playerProcessHelpers(&pp->q16ang, &pp->angAdjust, &pp->angTarget, &pp->q16horiz, &pp->horizAdjust, &pp->horizTarget, scaleAdjust); + } + if (packet) { auto const ang = FixedToInt(pp->q16ang);