- Inline the remainder of InputState methods.

This commit is contained in:
Mitchell Richters 2023-03-31 08:25:45 +11:00
parent ea4e850674
commit b9cf8a13c6
3 changed files with 26 additions and 60 deletions

View file

@ -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);

View file

@ -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.
}
//==========================================================================
//

View file

@ -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;