From c561255018a29380286fa68653db9872399bbf18 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Tue, 3 Dec 2019 20:58:43 +0100 Subject: [PATCH] - moved the application of in_mousebias and in_mousedeadzone into the backend code. This piece was repeated 6x for each call to CONTROL_GetInput, creating quite a bit of redundancy. --- source/blood/src/controls.cpp | 21 ------------ source/common/gamecvars.h | 4 +-- source/common/inputstate.cpp | 21 ++++++++++++ source/duke3d/src/player.cpp | 21 ------------ source/rr/src/player.cpp | 62 ----------------------------------- source/sw/src/game.cpp | 21 ------------ 6 files changed, 23 insertions(+), 127 deletions(-) diff --git a/source/blood/src/controls.cpp b/source/blood/src/controls.cpp index 6a21564c9..508ece563 100644 --- a/source/blood/src/controls.cpp +++ b/source/blood/src/controls.cpp @@ -150,27 +150,6 @@ void ctrlGetInput(void) CONTROL_GetInput(&info); - if (in_mousedeadzone) - { - if (info.mousey > 0) - info.mousey = max(info.mousey - in_mousedeadzone, 0); - else if (info.mousey < 0) - info.mousey = min(info.mousey + in_mousedeadzone, 0); - - if (info.mousex > 0) - info.mousex = max(info.mousex - in_mousedeadzone, 0); - else if (info.mousex < 0) - info.mousex = min(info.mousex + in_mousedeadzone, 0); - } - - if (in_mousebias) - { - if (klabs(info.mousex) > klabs(info.mousey)) - info.mousey = tabledivide32_noinline(info.mousey, in_mousebias); - else - info.mousex = tabledivide32_noinline(info.mousex, in_mousebias); - } - if (gQuitRequest) gInput.keyFlags.quit = 1; diff --git a/source/common/gamecvars.h b/source/common/gamecvars.h index 1b9265c47..0a1ffcac1 100644 --- a/source/common/gamecvars.h +++ b/source/common/gamecvars.h @@ -97,8 +97,8 @@ EXTERN_CVAR(Bool, in_mouseflip) EXTERN_CVAR(Bool, in_mousemode) EXTERN_CVAR(Bool, in_mousesmoothing) EXTERN_CVAR(Float, in_mousesensitivity) -EXTERN_CVAR(Int, in_mousescalex) -EXTERN_CVAR(Int, in_mousescaley) +EXTERN_CVAR(Float, in_mousescalex) +EXTERN_CVAR(Float, in_mousescaley) extern int32_t g_MyAimMode; EXTERN_CVAR(Bool, in_mousemode) EXTERN_CVAR(String, wchoice) diff --git a/source/common/inputstate.cpp b/source/common/inputstate.cpp index 94353590d..f5a3e6ced 100644 --- a/source/common/inputstate.cpp +++ b/source/common/inputstate.cpp @@ -47,6 +47,27 @@ void InputState::GetMouseDelta(ControlInfo * info) //info->mousex = int(finput.x * (4.f) * in_mousesensitivity * in_mouseside); //info->mousey = int(finput.y * (4.f) * in_mousesensitivity * in_mouseforward); + if (in_mousedeadzone) + { + if (info->mousey > 0) + info->mousey = max(info->mousey - in_mousedeadzone, 0); + else if (info->mousey < 0) + info->mousey = min(info->mousey + in_mousedeadzone, 0); + + if (info->mousex > 0) + info->mousex = max(info->mousex - in_mousedeadzone, 0); + else if (info->mousex < 0) + info->mousex = min(info->mousex + in_mousedeadzone, 0); + } + + if (in_mousebias) + { + if (abs(info->mousex) > abs(info->mousey)) + info->mousey = tabledivide32_noinline(info->mousey, in_mousebias); + else + info->mousex = tabledivide32_noinline(info->mousex, in_mousebias); + } + } void InputState::AddEvent(const event_t *ev) diff --git a/source/duke3d/src/player.cpp b/source/duke3d/src/player.cpp index 9b354139e..5442cb8ed 100644 --- a/source/duke3d/src/player.cpp +++ b/source/duke3d/src/player.cpp @@ -2926,27 +2926,6 @@ void P_GetInput(int const playerNum) CONTROL_GetInput(&info); - if (in_mousedeadzone) - { - if (info.mousey > 0) - info.mousey = max(info.mousey - in_mousedeadzone, 0); - else if (info.mousey < 0) - info.mousey = min(info.mousey + in_mousedeadzone, 0); - - if (info.mousex > 0) - info.mousex = max(info.mousex - in_mousedeadzone, 0); - else if (info.mousex < 0) - info.mousex = min(info.mousex + in_mousedeadzone, 0); - } - - if (in_mousebias) - { - if (klabs(info.mousex) > klabs(info.mousey)) - info.mousey = tabledivide32_noinline(info.mousey, in_mousebias); - else - info.mousex = tabledivide32_noinline(info.mousex, in_mousebias); - } - // JBF: Run key behaviour is selectable int const playerRunning = G_CheckAutorun(buttonMap.ButtonDown(gamefunc_Run)); int const turnAmount = playerRunning ? (NORMALTURN << 1) : NORMALTURN; diff --git a/source/rr/src/player.cpp b/source/rr/src/player.cpp index 6cd9c4fdc..a9577925d 100644 --- a/source/rr/src/player.cpp +++ b/source/rr/src/player.cpp @@ -2774,26 +2774,6 @@ void P_GetInput(int playerNum) CONTROL_GetInput(&info); - if (in_mousedeadzone) - { - if (info.mousey > 0) - info.mousey = max(info.mousey - in_mousedeadzone, 0); - else if (info.mousey < 0) - info.mousey = min(info.mousey + in_mousedeadzone, 0); - - if (info.mousex > 0) - info.mousex = max(info.mousex - in_mousedeadzone, 0); - else if (info.mousex < 0) - info.mousex = min(info.mousex + in_mousedeadzone, 0); - } - - if (in_mousebias) - { - if (klabs(info.mousex) > klabs(info.mousey)) - info.mousey = tabledivide32_noinline(info.mousey, in_mousebias); - else - info.mousex = tabledivide32_noinline(info.mousex, in_mousebias); - } // JBF: Run key behaviour is selectable @@ -3080,27 +3060,6 @@ void P_GetInputMotorcycle(int playerNum) CONTROL_GetInput(&info); - if (in_mousedeadzone) - { - if (info.mousey > 0) - info.mousey = max(info.mousey - in_mousedeadzone, 0); - else if (info.mousey < 0) - info.mousey = min(info.mousey + in_mousedeadzone, 0); - - if (info.mousex > 0) - info.mousex = max(info.mousex - in_mousedeadzone, 0); - else if (info.mousex < 0) - info.mousex = min(info.mousex + in_mousedeadzone, 0); - } - - if (in_mousebias) - { - if (klabs(info.mousex) > klabs(info.mousey)) - info.mousey = tabledivide32_noinline(info.mousey, in_mousebias); - else - info.mousex = tabledivide32_noinline(info.mousex, in_mousebias); - } - // JBF: Run key behaviour is selectable int const playerRunning = G_CheckAutorun(buttonMap.ButtonDown(gamefunc_Run)); constexpr int const analogTurnAmount = (NORMALTURN << 1); @@ -3378,27 +3337,6 @@ void P_GetInputBoat(int playerNum) CONTROL_GetInput(&info); - if (in_mousedeadzone) - { - if (info.mousey > 0) - info.mousey = max(info.mousey - in_mousedeadzone, 0); - else if (info.mousey < 0) - info.mousey = min(info.mousey + in_mousedeadzone, 0); - - if (info.mousex > 0) - info.mousex = max(info.mousex - in_mousedeadzone, 0); - else if (info.mousex < 0) - info.mousex = min(info.mousex + in_mousedeadzone, 0); - } - - if (in_mousebias) - { - if (klabs(info.mousex) > klabs(info.mousey)) - info.mousey = tabledivide32_noinline(info.mousey, in_mousebias); - else - info.mousex = tabledivide32_noinline(info.mousex, in_mousebias); - } - // JBF: Run key behaviour is selectable int const playerRunning = G_CheckAutorun(buttonMap.ButtonDown(gamefunc_Run)); constexpr int const analogTurnAmount = (NORMALTURN << 1); diff --git a/source/sw/src/game.cpp b/source/sw/src/game.cpp index e29909bb9..f9a0d98ad 100644 --- a/source/sw/src/game.cpp +++ b/source/sw/src/game.cpp @@ -3545,27 +3545,6 @@ void getinput(SW_PACKET *loc) ControlInfo info; CONTROL_GetInput(&info); - if (in_mousedeadzone) - { - if (info.mousey > 0) - info.mousey = max(info.mousey - in_mousedeadzone, 0); - else if (info.mousey < 0) - info.mousey = min(info.mousey + in_mousedeadzone, 0); - - if (info.mousex > 0) - info.mousex = max(info.mousex - in_mousedeadzone, 0); - else if (info.mousex < 0) - info.mousex = min(info.mousex + in_mousedeadzone, 0); - } - - if (in_mousebias) - { - if (klabs(info.mousex) > klabs(info.mousey)) - info.mousey = tabledivide32_noinline(info.mousey, in_mousebias); - else - info.mousex = tabledivide32_noinline(info.mousex, in_mousebias); - } - //info.dz = (info.dz * move_scale)>>8; //info.dyaw = (info.dyaw * turn_scale)>>8;