2014-03-15 16:59:03 +00:00
|
|
|
// SONIC ROBO BLAST 2
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Copyright (C) 1998-2000 by DooM Legacy Team.
|
2022-03-03 19:24:46 +00:00
|
|
|
// Copyright (C) 1999-2022 by Sonic Team Junior.
|
2014-03-15 16:59:03 +00:00
|
|
|
//
|
|
|
|
// This program is free software distributed under the
|
|
|
|
// terms of the GNU General Public License, version 2.
|
|
|
|
// See the 'LICENSE' file for more details.
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
/// \file g_input.h
|
2022-11-14 03:37:08 +00:00
|
|
|
/// \brief handle mouse/keyboard/gamepad inputs,
|
2014-03-15 16:59:03 +00:00
|
|
|
/// maps inputs to game controls (forward, spin, jump...)
|
|
|
|
|
|
|
|
#ifndef __G_INPUT__
|
|
|
|
#define __G_INPUT__
|
|
|
|
|
|
|
|
#include "d_event.h"
|
|
|
|
#include "keys.h"
|
|
|
|
#include "command.h"
|
2022-11-14 03:37:08 +00:00
|
|
|
#include "m_fixed.h"
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
// number of total 'button' inputs, include keyboard keys, plus virtual
|
|
|
|
// keys (mousebuttons and joybuttons becomes keys)
|
|
|
|
#define NUMKEYS 256
|
|
|
|
|
2022-11-14 03:37:08 +00:00
|
|
|
// Max gamepads that can be used by every player
|
|
|
|
#define NUM_GAMEPADS 2
|
|
|
|
|
|
|
|
// Max gamepads that can be detected
|
|
|
|
#define MAX_CONNECTED_GAMEPADS 4
|
|
|
|
|
|
|
|
// Max mouse buttons
|
2014-03-15 16:59:03 +00:00
|
|
|
#define MOUSEBUTTONS 8
|
2022-11-14 03:37:08 +00:00
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
GAMEPAD_TYPE_UNKNOWN,
|
|
|
|
|
|
|
|
GAMEPAD_TYPE_XBOX360,
|
|
|
|
GAMEPAD_TYPE_XBOXONE,
|
|
|
|
GAMEPAD_TYPE_XBOX_SERIES_XS,
|
|
|
|
GAMEPAD_TYPE_XBOX_ELITE,
|
|
|
|
|
|
|
|
GAMEPAD_TYPE_PS3,
|
|
|
|
GAMEPAD_TYPE_PS4,
|
|
|
|
GAMEPAD_TYPE_PS5,
|
|
|
|
|
|
|
|
GAMEPAD_TYPE_NINTENDO_SWITCH_PRO,
|
|
|
|
GAMEPAD_TYPE_NINTENDO_SWITCH_JOY_CON_GRIP,
|
|
|
|
GAMEPAD_TYPE_NINTENDO_SWITCH_JOY_CON_LEFT,
|
|
|
|
GAMEPAD_TYPE_NINTENDO_SWITCH_JOY_CON_RIGHT,
|
|
|
|
|
|
|
|
GAMEPAD_TYPE_GOOGLE_STADIA,
|
|
|
|
GAMEPAD_TYPE_AMAZON_LUNA,
|
|
|
|
GAMEPAD_TYPE_STEAM_CONTROLLER,
|
|
|
|
|
|
|
|
GAMEPAD_TYPE_VIRTUAL
|
|
|
|
} gamepadtype_e;
|
|
|
|
|
|
|
|
boolean G_GamepadTypeIsXbox(gamepadtype_e type);
|
|
|
|
boolean G_GamepadTypeIsPlayStation(gamepadtype_e type);
|
|
|
|
boolean G_GamepadTypeIsNintendoSwitch(gamepadtype_e type);
|
|
|
|
boolean G_GamepadTypeIsJoyCon(gamepadtype_e type);
|
|
|
|
|
|
|
|
const char *G_GamepadTypeToString(gamepadtype_e type);
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
GAMEPAD_BUTTON_A,
|
|
|
|
GAMEPAD_BUTTON_B,
|
|
|
|
GAMEPAD_BUTTON_X,
|
|
|
|
GAMEPAD_BUTTON_Y,
|
|
|
|
GAMEPAD_BUTTON_BACK,
|
|
|
|
GAMEPAD_BUTTON_GUIDE,
|
|
|
|
GAMEPAD_BUTTON_START,
|
|
|
|
GAMEPAD_BUTTON_LEFTSTICK,
|
|
|
|
GAMEPAD_BUTTON_RIGHTSTICK,
|
|
|
|
GAMEPAD_BUTTON_LEFTSHOULDER,
|
|
|
|
GAMEPAD_BUTTON_RIGHTSHOULDER,
|
|
|
|
GAMEPAD_BUTTON_DPAD_UP,
|
|
|
|
GAMEPAD_BUTTON_DPAD_DOWN,
|
|
|
|
GAMEPAD_BUTTON_DPAD_LEFT,
|
|
|
|
GAMEPAD_BUTTON_DPAD_RIGHT,
|
|
|
|
|
|
|
|
// According to SDL, this button can be:
|
|
|
|
// the Xbox Series X|S share button
|
|
|
|
// the PS5 microphone button
|
|
|
|
// the Nintendo Switch (Pro or Joy-Con) capture button
|
|
|
|
// the Amazon Luna microphone button
|
|
|
|
GAMEPAD_BUTTON_MISC1,
|
|
|
|
|
|
|
|
// Xbox Elite paddles
|
|
|
|
GAMEPAD_BUTTON_PADDLE1,
|
|
|
|
GAMEPAD_BUTTON_PADDLE2,
|
|
|
|
GAMEPAD_BUTTON_PADDLE3,
|
|
|
|
GAMEPAD_BUTTON_PADDLE4,
|
|
|
|
|
|
|
|
// PS4/PS5 touchpad button
|
|
|
|
GAMEPAD_BUTTON_TOUCHPAD,
|
|
|
|
|
|
|
|
NUM_GAMEPAD_BUTTONS
|
|
|
|
} gamepad_button_e;
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
GAMEPAD_AXIS_LEFTX,
|
|
|
|
GAMEPAD_AXIS_LEFTY,
|
|
|
|
GAMEPAD_AXIS_RIGHTX,
|
|
|
|
GAMEPAD_AXIS_RIGHTY,
|
|
|
|
GAMEPAD_AXIS_TRIGGERLEFT,
|
|
|
|
GAMEPAD_AXIS_TRIGGERRIGHT,
|
|
|
|
|
|
|
|
NUM_GAMEPAD_AXES
|
|
|
|
} gamepad_axis_e;
|
|
|
|
|
|
|
|
extern const char *const gamepad_button_names[NUM_GAMEPAD_BUTTONS + 1];
|
|
|
|
extern const char *const gamepad_axis_names[NUM_GAMEPAD_AXES + 1];
|
|
|
|
|
|
|
|
// Haptic effects
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
fixed_t large_magnitude; // Magnitude of the large motor
|
|
|
|
fixed_t small_magnitude; // Magnitude of the small motor
|
|
|
|
tic_t duration; // The total duration of the effect, in tics
|
|
|
|
} haptic_t;
|
|
|
|
|
|
|
|
// Gamepad info for each player on the system
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
// Gamepad index
|
|
|
|
UINT8 num;
|
|
|
|
|
|
|
|
// Gamepad is connected and being used by a player
|
|
|
|
boolean connected;
|
|
|
|
|
|
|
|
// What kind of controller this is (Xbox 360, DualShock, Joy-Con, etc.)
|
|
|
|
gamepadtype_e type;
|
|
|
|
|
|
|
|
// Treat this gamepad's axes as if it they were buttons
|
|
|
|
boolean digital;
|
|
|
|
|
|
|
|
struct {
|
|
|
|
boolean supported; // Gamepad can rumble
|
|
|
|
boolean active; // Rumble is active
|
|
|
|
boolean paused; // Rumble is paused
|
|
|
|
haptic_t data; // Current haptic effect status
|
|
|
|
} rumble;
|
|
|
|
|
|
|
|
UINT8 buttons[NUM_GAMEPAD_BUTTONS]; // Current state of all buttons
|
|
|
|
INT16 axes[NUM_GAMEPAD_AXES]; // Current state of all axes
|
|
|
|
} gamepad_t;
|
|
|
|
|
|
|
|
void G_InitGamepads(void);
|
|
|
|
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
GAMEPAD_STRING_DEFAULT, // A
|
|
|
|
GAMEPAD_STRING_MENU1, // A Button
|
|
|
|
GAMEPAD_STRING_MENU2 // the A Button
|
|
|
|
} gamepad_string_e;
|
|
|
|
|
|
|
|
const char *G_GetGamepadButtonString(gamepadtype_e type, gamepad_button_e button, gamepad_string_e strtype);
|
|
|
|
const char *G_GetGamepadAxisString(gamepadtype_e type, gamepad_axis_e button, gamepad_string_e strtype, boolean inv);
|
|
|
|
|
|
|
|
extern gamepad_t gamepads[NUM_GAMEPADS];
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
//
|
2022-11-14 03:37:08 +00:00
|
|
|
// mouse and gamepad buttons are handled as 'virtual' keys
|
2014-03-15 16:59:03 +00:00
|
|
|
//
|
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
KEY_MOUSE1 = NUMKEYS,
|
2022-11-14 03:37:08 +00:00
|
|
|
KEY_GAMEPAD = KEY_MOUSE1 + MOUSEBUTTONS,
|
|
|
|
KEY_AXES = KEY_GAMEPAD + NUM_GAMEPAD_BUTTONS, // Sure, why not.
|
|
|
|
KEY_INV_AXES = KEY_AXES + NUM_GAMEPAD_AXES,
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2022-11-14 03:37:08 +00:00
|
|
|
KEY_DBLMOUSE1 = KEY_INV_AXES + NUM_GAMEPAD_AXES, // double clicks
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2022-11-14 03:37:08 +00:00
|
|
|
KEY_2MOUSE1 = KEY_DBLMOUSE1 + MOUSEBUTTONS,
|
|
|
|
KEY_DBL2MOUSE1 = KEY_2MOUSE1 + MOUSEBUTTONS,
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2022-11-14 03:37:08 +00:00
|
|
|
KEY_MOUSEWHEELUP = KEY_DBL2MOUSE1 + MOUSEBUTTONS,
|
|
|
|
KEY_MOUSEWHEELDOWN,
|
|
|
|
KEY_2MOUSEWHEELUP,
|
|
|
|
KEY_2MOUSEWHEELDOWN,
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2022-11-14 03:37:08 +00:00
|
|
|
NUMINPUTS
|
2014-03-15 16:59:03 +00:00
|
|
|
} key_input_e;
|
|
|
|
|
2022-11-14 03:37:08 +00:00
|
|
|
#define GAMEPAD_KEY(key) (KEY_GAMEPAD + GAMEPAD_BUTTON_##key)
|
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
2021-08-15 14:15:28 +00:00
|
|
|
GC_NULL = 0, // a key/button mapped to GC_NULL has no effect
|
|
|
|
GC_FORWARD,
|
|
|
|
GC_BACKWARD,
|
|
|
|
GC_STRAFELEFT,
|
|
|
|
GC_STRAFERIGHT,
|
|
|
|
GC_TURNLEFT,
|
|
|
|
GC_TURNRIGHT,
|
|
|
|
GC_WEAPONNEXT,
|
|
|
|
GC_WEAPONPREV,
|
|
|
|
GC_WEPSLOT1,
|
|
|
|
GC_WEPSLOT2,
|
|
|
|
GC_WEPSLOT3,
|
|
|
|
GC_WEPSLOT4,
|
|
|
|
GC_WEPSLOT5,
|
|
|
|
GC_WEPSLOT6,
|
|
|
|
GC_WEPSLOT7,
|
|
|
|
GC_WEPSLOT8,
|
|
|
|
GC_WEPSLOT9,
|
|
|
|
GC_WEPSLOT10,
|
|
|
|
GC_FIRE,
|
|
|
|
GC_FIRENORMAL,
|
|
|
|
GC_TOSSFLAG,
|
|
|
|
GC_SPIN,
|
|
|
|
GC_CAMTOGGLE,
|
|
|
|
GC_CAMRESET,
|
|
|
|
GC_LOOKUP,
|
|
|
|
GC_LOOKDOWN,
|
|
|
|
GC_CENTERVIEW,
|
|
|
|
GC_MOUSEAIMING, // mouse aiming is momentary (toggleable in the menu)
|
|
|
|
GC_TALKKEY,
|
|
|
|
GC_TEAMKEY,
|
|
|
|
GC_SCORES,
|
|
|
|
GC_JUMP,
|
|
|
|
GC_CONSOLE,
|
|
|
|
GC_PAUSE,
|
|
|
|
GC_SYSTEMMENU,
|
|
|
|
GC_SCREENSHOT,
|
|
|
|
GC_RECORDGIF,
|
2022-11-23 17:35:51 +00:00
|
|
|
GC_VIEWPOINTNEXT,
|
|
|
|
GC_VIEWPOINTPREV,
|
2021-08-15 14:15:28 +00:00
|
|
|
GC_CUSTOM1, // Lua scriptable
|
|
|
|
GC_CUSTOM2, // Lua scriptable
|
|
|
|
GC_CUSTOM3, // Lua scriptable
|
|
|
|
NUM_GAMECONTROLS
|
2014-03-15 16:59:03 +00:00
|
|
|
} gamecontrols_e;
|
|
|
|
|
2018-11-10 22:06:35 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
gcs_custom,
|
|
|
|
gcs_fps,
|
2018-11-12 22:16:54 +00:00
|
|
|
gcs_platform,
|
2018-11-10 22:06:35 +00:00
|
|
|
num_gamecontrolschemes
|
|
|
|
} gamecontrolschemes_e;
|
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
// mouse values are used once
|
2015-01-01 19:50:31 +00:00
|
|
|
extern consvar_t cv_mousesens, cv_mouseysens;
|
2017-04-14 16:45:27 +00:00
|
|
|
extern consvar_t cv_mousesens2, cv_mouseysens2;
|
2023-01-27 01:24:21 +00:00
|
|
|
extern consvar_t cv_controlperkey;
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2021-03-23 05:02:49 +00:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
INT32 dx; // deltas with mousemove sensitivity
|
|
|
|
INT32 dy;
|
|
|
|
INT32 mlookdy; // dy with mouselook sensitivity
|
|
|
|
INT32 rdx; // deltas without sensitivity
|
|
|
|
INT32 rdy;
|
2021-03-26 02:14:59 +00:00
|
|
|
UINT16 buttons;
|
2021-03-23 05:02:49 +00:00
|
|
|
} mouse_t;
|
|
|
|
|
2021-03-26 02:14:59 +00:00
|
|
|
#define MB_BUTTON1 0x0001
|
|
|
|
#define MB_BUTTON2 0x0002
|
|
|
|
#define MB_BUTTON3 0x0004
|
|
|
|
#define MB_BUTTON4 0x0008
|
|
|
|
#define MB_BUTTON5 0x0010
|
|
|
|
#define MB_BUTTON6 0x0020
|
|
|
|
#define MB_BUTTON7 0x0040
|
|
|
|
#define MB_BUTTON8 0x0080
|
|
|
|
#define MB_SCROLLUP 0x0100
|
|
|
|
#define MB_SCROLLDOWN 0x0200
|
|
|
|
|
2021-03-23 05:02:49 +00:00
|
|
|
extern mouse_t mouse;
|
|
|
|
extern mouse_t mouse2;
|
2014-03-15 16:59:03 +00:00
|
|
|
|
|
|
|
// current state of the keys: true if pushed
|
|
|
|
extern UINT8 gamekeydown[NUMINPUTS];
|
|
|
|
|
|
|
|
// two key codes (or virtual key) per game control
|
2021-08-15 14:15:28 +00:00
|
|
|
extern INT32 gamecontrol[NUM_GAMECONTROLS][2];
|
|
|
|
extern INT32 gamecontrolbis[NUM_GAMECONTROLS][2]; // secondary splitscreen player
|
2022-11-14 03:37:08 +00:00
|
|
|
|
|
|
|
// default control storage, use 0 (gcs_custom) for memory retention
|
|
|
|
extern INT32 gamecontroldefault[num_gamecontrolschemes][NUM_GAMECONTROLS][2];
|
2021-08-15 14:15:28 +00:00
|
|
|
extern INT32 gamecontrolbisdefault[num_gamecontrolschemes][NUM_GAMECONTROLS][2];
|
2022-11-14 03:37:08 +00:00
|
|
|
|
|
|
|
boolean G_PlayerInputDown(UINT8 which, gamecontrols_e gc);
|
|
|
|
boolean G_CheckDigitalPlayerInput(UINT8 which, gamecontrols_e gc);
|
|
|
|
|
|
|
|
SINT8 G_PlayerInputIsAnalog(UINT8 which, gamecontrols_e gc, UINT8 settings);
|
|
|
|
INT16 G_GetAnalogPlayerInput(UINT8 which, gamecontrols_e gc, UINT8 settings);
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2018-11-13 04:23:39 +00:00
|
|
|
#define num_gcl_tutorial_check 6
|
|
|
|
#define num_gcl_tutorial_used 8
|
|
|
|
#define num_gcl_tutorial_full 13
|
|
|
|
#define num_gcl_movement 4
|
|
|
|
#define num_gcl_camera 2
|
|
|
|
#define num_gcl_movement_camera 6
|
|
|
|
#define num_gcl_jump 1
|
2020-06-06 10:52:29 +00:00
|
|
|
#define num_gcl_spin 1
|
|
|
|
#define num_gcl_jump_spin 2
|
2018-11-13 04:23:39 +00:00
|
|
|
|
|
|
|
extern const INT32 gcl_tutorial_check[num_gcl_tutorial_check];
|
|
|
|
extern const INT32 gcl_tutorial_used[num_gcl_tutorial_used];
|
|
|
|
extern const INT32 gcl_tutorial_full[num_gcl_tutorial_full];
|
|
|
|
extern const INT32 gcl_movement[num_gcl_movement];
|
|
|
|
extern const INT32 gcl_camera[num_gcl_camera];
|
|
|
|
extern const INT32 gcl_movement_camera[num_gcl_movement_camera];
|
|
|
|
extern const INT32 gcl_jump[num_gcl_jump];
|
2020-06-06 10:52:29 +00:00
|
|
|
extern const INT32 gcl_spin[num_gcl_spin];
|
|
|
|
extern const INT32 gcl_jump_spin[num_gcl_jump_spin];
|
2018-11-11 13:19:44 +00:00
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
// peace to my little coder fingers!
|
|
|
|
// check a gamecontrol being active or not
|
|
|
|
|
|
|
|
// remaps the input event to a game control.
|
|
|
|
void G_MapEventsToControls(event_t *ev);
|
|
|
|
|
2022-11-14 03:37:08 +00:00
|
|
|
boolean G_RumbleSupported(UINT8 which);
|
|
|
|
boolean G_RumbleGamepad(UINT8 which, fixed_t large_magnitude, fixed_t small_magnitude, tic_t duration);
|
|
|
|
void G_StopGamepadRumble(UINT8 which);
|
|
|
|
|
|
|
|
fixed_t G_GetLargeMotorFreq(UINT8 which);
|
|
|
|
fixed_t G_GetSmallMotorFreq(UINT8 which);
|
|
|
|
boolean G_GetGamepadRumblePaused(UINT8 which);
|
|
|
|
boolean G_SetLargeMotorFreq(UINT8 which, fixed_t freq);
|
|
|
|
boolean G_SetSmallMotorFreq(UINT8 which, fixed_t freq);
|
|
|
|
void G_SetGamepadRumblePaused(UINT8 which, boolean pause);
|
|
|
|
|
|
|
|
INT16 G_GamepadAxisEventValue(UINT8 which, INT16 value);
|
|
|
|
INT16 G_GetGamepadAxisValue(UINT8 which, gamepad_axis_e axis);
|
|
|
|
fixed_t G_GetAdjustedGamepadAxis(UINT8 which, gamepad_axis_e axis, boolean applyDeadzone);
|
|
|
|
|
|
|
|
UINT16 G_GetGamepadDeadZone(UINT8 which);
|
|
|
|
UINT16 G_GetGamepadDigitalDeadZone(UINT8 which);
|
|
|
|
INT32 G_BasicDeadZoneCalculation(INT32 magnitude, const UINT16 jdeadzone);
|
|
|
|
|
|
|
|
INT32 G_RemapGamepadEvent(event_t *event, INT32 *type);
|
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
// returns the name of a key
|
2021-08-15 13:24:23 +00:00
|
|
|
const char *G_KeyNumToName(INT32 keynum);
|
|
|
|
INT32 G_KeyNameToNum(const char *keystr);
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2022-11-14 03:37:08 +00:00
|
|
|
const char *G_GetDisplayNameForKey(INT32 keynum);
|
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
// detach any keys associated to the given game control
|
|
|
|
void G_ClearControlKeys(INT32 (*setupcontrols)[2], INT32 control);
|
2018-12-23 19:51:58 +00:00
|
|
|
void G_ClearAllControlKeys(void);
|
2022-11-14 03:37:08 +00:00
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
void Command_Setcontrol_f(void);
|
|
|
|
void Command_Setcontrol2_f(void);
|
2018-11-10 22:06:35 +00:00
|
|
|
void G_DefineDefaultControls(void);
|
2018-11-11 13:44:08 +00:00
|
|
|
INT32 G_GetControlScheme(INT32 (*fromcontrols)[2], const INT32 *gclist, INT32 gclen);
|
|
|
|
void G_CopyControls(INT32 (*setupcontrols)[2], INT32 (*fromcontrols)[2], const INT32 *gclist, INT32 gclen);
|
2018-11-10 22:06:35 +00:00
|
|
|
void G_SaveKeySetting(FILE *f, INT32 (*fromcontrols)[2], INT32 (*fromcontrolsbis)[2]);
|
2023-01-27 01:24:21 +00:00
|
|
|
INT32 G_CheckDoubleUsage(INT32 keynum, boolean modify);
|
2014-03-15 16:59:03 +00:00
|
|
|
|
2021-03-23 05:02:49 +00:00
|
|
|
// sets the members of a mouse_t given position deltas
|
2021-03-26 02:14:59 +00:00
|
|
|
void G_SetMouseDeltas(INT32 dx, INT32 dy, UINT8 ssplayer);
|
2021-03-23 05:02:49 +00:00
|
|
|
|
2014-03-15 16:59:03 +00:00
|
|
|
#endif
|