From b9cf8a13c635a4ddccbc7fdf466f81ff0cea58e1 Mon Sep 17 00:00:00 2001 From: Mitchell Richters Date: Fri, 31 Mar 2023 08:25:45 +1100 Subject: [PATCH] - Inline the remainder of `InputState` methods. --- source/core/gameinput.h | 1 - source/core/inputstate.cpp | 57 -------------------------------------- source/core/inputstate.h | 28 +++++++++++++++++-- 3 files changed, 26 insertions(+), 60 deletions(-) diff --git a/source/core/gameinput.h b/source/core/gameinput.h index 85a4c4580..4dad5bd29 100644 --- a/source/core/gameinput.h +++ b/source/core/gameinput.h @@ -89,6 +89,5 @@ struct HIDInput FVector2 mouse; }; -void clearLocalInputBuffer(); void processVehicleInput(HIDInput* const hidInput, InputPacket* const currInput, const double scaleAdjust, const float baseVel, const float velScale, const bool canMove, const bool canTurn, const bool attenuate); void getInput(const double scaleAdjust, PlayerAngles* const plrAngles, InputPacket* packet = nullptr); diff --git a/source/core/inputstate.cpp b/source/core/inputstate.cpp index 0dd5e7646..6c2e36d40 100644 --- a/source/core/inputstate.cpp +++ b/source/core/inputstate.cpp @@ -34,66 +34,9 @@ #include "inputstate.h" #include "i_system.h" #include "v_draw.h" -#include "build.h" -#include "gamecvars.h" #include "v_video.h" #include "statusbar.h" -#include"packet.h" #include "gamecontrol.h" -#include "gamestruct.h" -#include "gamestate.h" -#include "gameinput.h" - -//========================================================================== -// -// -// -//========================================================================== - -static int exclKeys[] = { KEY_VOLUMEDOWN, KEY_VOLUMEUP }; - -void InputState::AddEvent(const event_t *ev) -{ - if (ev->type == EV_KeyDown || ev->type == EV_KeyUp) - { - int key = ev->data1; - bool state = ev->type == EV_KeyDown; - bool ignore = false; - KeyStatus[key] = (uint8_t)state; - - // Check if key is to be excluded from setting AnyKeyStatus. - for (int i = 0; i < 2; i++) - { - if (exclKeys[i] == key) - { - ignore = true; - break; - } - } - if (key > KEY_LASTJOYBUTTON && key < KEY_PAD_LTHUMB_RIGHT) - { - ignore = true; - } - - if (state && !ignore) - AnyKeyStatus = true; - } -} - -//========================================================================== -// -// -// -//========================================================================== - -void InputState::ClearAllInput() -{ - memset(KeyStatus, 0, sizeof(KeyStatus)); - AnyKeyStatus = false; - buttonMap.ResetButtonStates(); // this is important. If all input is cleared, the buttons must be cleared as well. - clearLocalInputBuffer(); // also clear game local input state. -} - //========================================================================== // diff --git a/source/core/inputstate.h b/source/core/inputstate.h index f4d094d10..5971815bd 100644 --- a/source/core/inputstate.h +++ b/source/core/inputstate.h @@ -13,6 +13,8 @@ #include "packet.h" #include "vectors.h" +void clearLocalInputBuffer(); + class InputState { uint8_t KeyStatus[NUM_KEYS]; @@ -26,7 +28,22 @@ public: return KeyStatus[sc_LeftShift] || KeyStatus[sc_RightShift]; } - void AddEvent(const event_t* ev); + void AddEvent(const event_t* ev) + { + if (ev->type != EV_KeyDown && ev->type != EV_KeyUp) + return; + + const int key = ev->data1; + const bool state = ev->type == EV_KeyDown; + KeyStatus[key] = (uint8_t)state; + + // Check if key is to be excluded from setting AnyKeyStatus. + const bool ignore = key == KEY_VOLUMEDOWN || key == KEY_VOLUMEUP || + (key > KEY_LASTJOYBUTTON && key < KEY_PAD_LTHUMB_RIGHT); + + if (state && !ignore) + AnyKeyStatus = true; + } void MouseAddToPos(float x, float y) { @@ -40,7 +57,14 @@ public: g_mousePos.Zero(); } - void ClearAllInput(); + void ClearAllInput() + { + memset(KeyStatus, 0, sizeof(KeyStatus)); + AnyKeyStatus = false; + buttonMap.ResetButtonStates(); // this is important. If all input is cleared, the buttons must be cleared as well. + clearLocalInputBuffer(); // also clear game local input state. + } + bool CheckAllInput() { bool res = AnyKeyStatus;