2019-10-27 23:24:09 +00:00
|
|
|
#pragma once
|
|
|
|
|
2019-10-28 05:47:49 +00:00
|
|
|
#include <stdint.h>
|
2020-07-14 12:00:27 +00:00
|
|
|
#include "printf.h"
|
|
|
|
#include "c_dispatch.h"
|
2019-10-28 05:47:49 +00:00
|
|
|
#include "tarray.h"
|
2019-10-28 00:12:31 +00:00
|
|
|
#include "scancodes.h"
|
2019-11-03 19:24:50 +00:00
|
|
|
#include "c_bind.h"
|
2019-11-04 22:01:50 +00:00
|
|
|
#include "c_buttons.h"
|
2019-11-03 23:53:55 +00:00
|
|
|
#include "d_event.h"
|
2019-12-14 19:15:15 +00:00
|
|
|
#include "m_joy.h"
|
|
|
|
#include "gamecvars.h"
|
2020-08-26 22:53:35 +00:00
|
|
|
#include "packet.h"
|
2021-12-14 10:57:24 +00:00
|
|
|
#include "vectors.h"
|
2019-11-04 16:58:18 +00:00
|
|
|
|
2019-10-27 23:24:09 +00:00
|
|
|
class InputState
|
|
|
|
{
|
2023-04-05 02:57:48 +00:00
|
|
|
FixedBitArray<NUM_KEYS> KeyStatus;
|
2020-08-24 18:34:18 +00:00
|
|
|
bool AnyKeyStatus;
|
2019-11-10 14:15:14 +00:00
|
|
|
|
2019-10-27 23:24:09 +00:00
|
|
|
public:
|
|
|
|
|
2019-10-28 00:12:31 +00:00
|
|
|
bool ShiftPressed()
|
|
|
|
{
|
|
|
|
return KeyStatus[sc_LeftShift] || KeyStatus[sc_RightShift];
|
|
|
|
}
|
2019-11-03 23:53:55 +00:00
|
|
|
|
2023-03-30 21:25:45 +00:00
|
|
|
void AddEvent(const event_t* ev)
|
|
|
|
{
|
|
|
|
if (ev->type != EV_KeyDown && ev->type != EV_KeyUp)
|
|
|
|
return;
|
|
|
|
|
|
|
|
const int key = ev->data1;
|
2023-04-05 02:57:48 +00:00
|
|
|
KeyStatus.Set(key, ev->type == EV_KeyDown);
|
2023-03-30 21:25:45 +00:00
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2023-04-05 02:57:48 +00:00
|
|
|
if (KeyStatus[key] && !ignore)
|
2023-03-30 21:25:45 +00:00
|
|
|
AnyKeyStatus = true;
|
|
|
|
}
|
2019-11-03 23:53:55 +00:00
|
|
|
|
2023-03-30 21:25:45 +00:00
|
|
|
void ClearAllInput()
|
|
|
|
{
|
2023-04-05 02:57:48 +00:00
|
|
|
KeyStatus.Zero();
|
2023-03-30 21:25:45 +00:00
|
|
|
AnyKeyStatus = false;
|
|
|
|
buttonMap.ResetButtonStates(); // this is important. If all input is cleared, the buttons must be cleared as well.
|
|
|
|
}
|
|
|
|
|
2019-12-24 11:59:26 +00:00
|
|
|
bool CheckAllInput()
|
2019-12-14 19:15:15 +00:00
|
|
|
{
|
2020-08-24 18:34:18 +00:00
|
|
|
bool res = AnyKeyStatus;
|
|
|
|
AnyKeyStatus = false;
|
2019-12-24 11:59:26 +00:00
|
|
|
return res;
|
2019-11-28 18:35:35 +00:00
|
|
|
}
|
2019-10-27 23:24:09 +00:00
|
|
|
};
|
2019-12-14 19:15:15 +00:00
|
|
|
|
|
|
|
extern InputState inputState;
|
2019-11-06 18:22:14 +00:00
|
|
|
|
2019-12-24 12:54:50 +00:00
|
|
|
int32_t handleevents(void);
|
2020-08-26 22:25:59 +00:00
|
|
|
|
|
|
|
enum GameFunction_t
|
|
|
|
{
|
2020-08-27 22:03:35 +00:00
|
|
|
gamefunc_Move_Forward, //
|
|
|
|
gamefunc_Move_Backward, //
|
|
|
|
gamefunc_Turn_Left, //
|
|
|
|
gamefunc_Turn_Right, //
|
|
|
|
gamefunc_Strafe, //
|
2020-08-26 22:25:59 +00:00
|
|
|
gamefunc_Fire,
|
|
|
|
gamefunc_Open,
|
|
|
|
gamefunc_Run,
|
|
|
|
gamefunc_Alt_Fire,
|
|
|
|
gamefunc_Jump,
|
|
|
|
gamefunc_Crouch,
|
|
|
|
gamefunc_Look_Up,
|
|
|
|
gamefunc_Look_Down,
|
|
|
|
gamefunc_Look_Left,
|
|
|
|
gamefunc_Look_Right,
|
2020-08-27 22:03:35 +00:00
|
|
|
gamefunc_Strafe_Left, //
|
|
|
|
gamefunc_Strafe_Right, //
|
2020-08-26 22:25:59 +00:00
|
|
|
gamefunc_Aim_Up,
|
|
|
|
gamefunc_Aim_Down,
|
|
|
|
gamefunc_Shrink_Screen, // Automap only
|
|
|
|
gamefunc_Enlarge_Screen, // Automap only
|
|
|
|
gamefunc_Mouse_Aiming,
|
|
|
|
gamefunc_Dpad_Select,
|
|
|
|
gamefunc_Dpad_Aiming,
|
|
|
|
gamefunc_Toggle_Crouch,
|
|
|
|
gamefunc_Quick_Kick,
|
2023-04-23 09:34:59 +00:00
|
|
|
gamefunc_Move_Up,
|
|
|
|
gamefunc_Move_Down,
|
2020-09-06 18:49:43 +00:00
|
|
|
gamefunc_AM_PanLeft,
|
|
|
|
gamefunc_AM_PanRight,
|
|
|
|
gamefunc_AM_PanUp,
|
|
|
|
gamefunc_AM_PanDown,
|
2020-08-26 22:25:59 +00:00
|
|
|
NUM_ACTIONS
|
|
|
|
};
|
|
|
|
|
|
|
|
void SetupGameButtons();
|