diff options
Diffstat (limited to 'public/inputsystem')
| -rw-r--r-- | public/inputsystem/AnalogCode.h | 44 | ||||
| -rw-r--r-- | public/inputsystem/ButtonCode.h | 499 | ||||
| -rw-r--r-- | public/inputsystem/InputEnums.h | 195 | ||||
| -rw-r--r-- | public/inputsystem/iinputsystem.h | 162 |
4 files changed, 900 insertions, 0 deletions
diff --git a/public/inputsystem/AnalogCode.h b/public/inputsystem/AnalogCode.h new file mode 100644 index 0000000..51a8441 --- /dev/null +++ b/public/inputsystem/AnalogCode.h @@ -0,0 +1,44 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//===========================================================================// + +#ifndef ANALOGCODE_H +#define ANALOGCODE_H + +#ifdef _WIN32 +#pragma once +#endif + + +#include "inputsystem/InputEnums.h" + + +//----------------------------------------------------------------------------- +// Macro to get at joystick codes +//----------------------------------------------------------------------------- +#define JOYSTICK_AXIS_INTERNAL( _joystick, _axis ) ( JOYSTICK_FIRST_AXIS + ((_joystick) * MAX_JOYSTICK_AXES) + (_axis) ) +#define JOYSTICK_AXIS( _joystick, _axis ) ( (AnalogCode_t)JOYSTICK_AXIS_INTERNAL( _joystick, _axis ) ) + + +//----------------------------------------------------------------------------- +// Enumeration for analog input devices. Includes joysticks, mousewheel, mouse +//----------------------------------------------------------------------------- +enum AnalogCode_t +{ + ANALOG_CODE_INVALID = -1, + MOUSE_X = 0, + MOUSE_Y, + MOUSE_XY, // Invoked when either x or y changes + MOUSE_WHEEL, + + JOYSTICK_FIRST_AXIS, + JOYSTICK_LAST_AXIS = JOYSTICK_AXIS_INTERNAL( MAX_JOYSTICKS-1, MAX_JOYSTICK_AXES-1 ), + + ANALOG_CODE_LAST, +}; + + +#endif // ANALOGCODE_H diff --git a/public/inputsystem/ButtonCode.h b/public/inputsystem/ButtonCode.h new file mode 100644 index 0000000..ee6cb29 --- /dev/null +++ b/public/inputsystem/ButtonCode.h @@ -0,0 +1,499 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +// $NoKeywords: $ +//===========================================================================// + +#ifndef BUTTONCODE_H +#define BUTTONCODE_H + +#ifdef _WIN32 +#pragma once +#endif + +#include "inputsystem/InputEnums.h" +#include "mathlib/mathlib.h" + +//----------------------------------------------------------------------------- +// Button enum. "Buttons" are binary-state input devices (mouse buttons, keyboard keys) +//----------------------------------------------------------------------------- +enum +{ + JOYSTICK_MAX_BUTTON_COUNT = 32, + JOYSTICK_POV_BUTTON_COUNT = 4, + JOYSTICK_AXIS_BUTTON_COUNT = MAX_JOYSTICK_AXES * 2, +}; + +#define JOYSTICK_BUTTON_INTERNAL( _joystick, _button ) ( JOYSTICK_FIRST_BUTTON + ((_joystick) * JOYSTICK_MAX_BUTTON_COUNT) + (_button) ) +#define JOYSTICK_POV_BUTTON_INTERNAL( _joystick, _button ) ( JOYSTICK_FIRST_POV_BUTTON + ((_joystick) * JOYSTICK_POV_BUTTON_COUNT) + (_button) ) +#define JOYSTICK_AXIS_BUTTON_INTERNAL( _joystick, _button ) ( JOYSTICK_FIRST_AXIS_BUTTON + ((_joystick) * JOYSTICK_AXIS_BUTTON_COUNT) + (_button) ) + +#define JOYSTICK_BUTTON( _joystick, _button ) ( (ButtonCode_t)JOYSTICK_BUTTON_INTERNAL( _joystick, _button ) ) +#define JOYSTICK_POV_BUTTON( _joystick, _button ) ( (ButtonCode_t)JOYSTICK_POV_BUTTON_INTERNAL( _joystick, _button ) ) +#define JOYSTICK_AXIS_BUTTON( _joystick, _button ) ( (ButtonCode_t)JOYSTICK_AXIS_BUTTON_INTERNAL( _joystick, _button ) ) + +//----------------------------------------------------------------------------- +// Button enum. "Buttons" are binary-state input devices (mouse buttons, keyboard keys) +//----------------------------------------------------------------------------- +enum +{ + STEAMCONTROLLER_MAX_BUTTON_COUNT = SK_MAX_KEYS - 1, + STEAMCONTROLLER_AXIS_BUTTON_COUNT = MAX_STEAMPADAXIS * 2, +}; + +#define STEAMCONTROLLER_BUTTON_INTERNAL( _joystick, _button ) ( STEAMCONTROLLER_FIRST_BUTTON + ((_joystick) * STEAMCONTROLLER_MAX_BUTTON_COUNT) + (_button) ) +#define STEAMCONTROLLER_AXIS_BUTTON_INTERNAL( _joystick, _button ) ( STEAMCONTROLLER_FIRST_AXIS_BUTTON + ((_joystick) * STEAMCONTROLLER_AXIS_BUTTON_COUNT) + (_button) ) + +#define STEAMCONTROLLER_BUTTON( _joystick, _button ) ( (ButtonCode_t)STEAMCONTROLLER_BUTTON_INTERNAL( _joystick, _button ) ) +#define STEAMCONTROLLER_AXIS_BUTTON( _joystick, _button ) ( (ButtonCode_t)STEAMCONTROLLER_AXIS_BUTTON_INTERNAL( _joystick, _button ) ) + +enum ButtonCode_t +{ + BUTTON_CODE_INVALID = -1, + BUTTON_CODE_NONE = 0, + + KEY_FIRST = 0, + + KEY_NONE = KEY_FIRST, + KEY_0, + KEY_1, + KEY_2, + KEY_3, + KEY_4, + KEY_5, + KEY_6, + KEY_7, + KEY_8, + KEY_9, + KEY_A, + KEY_B, + KEY_C, + KEY_D, + KEY_E, + KEY_F, + KEY_G, + KEY_H, + KEY_I, + KEY_J, + KEY_K, + KEY_L, + KEY_M, + KEY_N, + KEY_O, + KEY_P, + KEY_Q, + KEY_R, + KEY_S, + KEY_T, + KEY_U, + KEY_V, + KEY_W, + KEY_X, + KEY_Y, + KEY_Z, + KEY_PAD_0, + KEY_PAD_1, + KEY_PAD_2, + KEY_PAD_3, + KEY_PAD_4, + KEY_PAD_5, + KEY_PAD_6, + KEY_PAD_7, + KEY_PAD_8, + KEY_PAD_9, + KEY_PAD_DIVIDE, + KEY_PAD_MULTIPLY, + KEY_PAD_MINUS, + KEY_PAD_PLUS, + KEY_PAD_ENTER, + KEY_PAD_DECIMAL, + KEY_LBRACKET, + KEY_RBRACKET, + KEY_SEMICOLON, + KEY_APOSTROPHE, + KEY_BACKQUOTE, + KEY_COMMA, + KEY_PERIOD, + KEY_SLASH, + KEY_BACKSLASH, + KEY_MINUS, + KEY_EQUAL, + KEY_ENTER, + KEY_SPACE, + KEY_BACKSPACE, + KEY_TAB, + KEY_CAPSLOCK, + KEY_NUMLOCK, + KEY_ESCAPE, + KEY_SCROLLLOCK, + KEY_INSERT, + KEY_DELETE, + KEY_HOME, + KEY_END, + KEY_PAGEUP, + KEY_PAGEDOWN, + KEY_BREAK, + KEY_LSHIFT, + KEY_RSHIFT, + KEY_LALT, + KEY_RALT, + KEY_LCONTROL, + KEY_RCONTROL, + KEY_LWIN, + KEY_RWIN, + KEY_APP, + KEY_UP, + KEY_LEFT, + KEY_DOWN, + KEY_RIGHT, + KEY_F1, + KEY_F2, + KEY_F3, + KEY_F4, + KEY_F5, + KEY_F6, + KEY_F7, + KEY_F8, + KEY_F9, + KEY_F10, + KEY_F11, + KEY_F12, + KEY_CAPSLOCKTOGGLE, + KEY_NUMLOCKTOGGLE, + KEY_SCROLLLOCKTOGGLE, + + KEY_LAST = KEY_SCROLLLOCKTOGGLE, + KEY_COUNT = KEY_LAST - KEY_FIRST + 1, + + // Mouse + MOUSE_FIRST = KEY_LAST + 1, + + MOUSE_LEFT = MOUSE_FIRST, + MOUSE_RIGHT, + MOUSE_MIDDLE, + MOUSE_4, + MOUSE_5, + MOUSE_WHEEL_UP, // A fake button which is 'pressed' and 'released' when the wheel is moved up + MOUSE_WHEEL_DOWN, // A fake button which is 'pressed' and 'released' when the wheel is moved down + + MOUSE_LAST = MOUSE_WHEEL_DOWN, + MOUSE_COUNT = MOUSE_LAST - MOUSE_FIRST + 1, + + // Joystick + JOYSTICK_FIRST = MOUSE_LAST + 1, + + JOYSTICK_FIRST_BUTTON = JOYSTICK_FIRST, + JOYSTICK_LAST_BUTTON = JOYSTICK_BUTTON_INTERNAL( MAX_JOYSTICKS-1, JOYSTICK_MAX_BUTTON_COUNT-1 ), + JOYSTICK_FIRST_POV_BUTTON, + JOYSTICK_LAST_POV_BUTTON = JOYSTICK_POV_BUTTON_INTERNAL( MAX_JOYSTICKS-1, JOYSTICK_POV_BUTTON_COUNT-1 ), + JOYSTICK_FIRST_AXIS_BUTTON, + JOYSTICK_LAST_AXIS_BUTTON = JOYSTICK_AXIS_BUTTON_INTERNAL( MAX_JOYSTICKS-1, JOYSTICK_AXIS_BUTTON_COUNT-1 ), + + JOYSTICK_LAST = JOYSTICK_LAST_AXIS_BUTTON, + +#if !defined ( _X360 ) + NOVINT_FIRST = JOYSTICK_LAST + 2, // plus 1 missing key. +1 seems to cause issues on the first button. + + NOVINT_LOGO_0 = NOVINT_FIRST, + NOVINT_TRIANGLE_0, + NOVINT_BOLT_0, + NOVINT_PLUS_0, + NOVINT_LOGO_1, + NOVINT_TRIANGLE_1, + NOVINT_BOLT_1, + NOVINT_PLUS_1, + + NOVINT_LAST = NOVINT_PLUS_1, + STEAMCONTROLLER_FIRST = NOVINT_LAST + 1, +#else + STEAMCONTROLLER_FIRST = JOYSTICK_LAST + 1 +#endif + + // Steam Controller + STEAMCONTROLLER_FIRST_BUTTON = STEAMCONTROLLER_FIRST, + STEAMCONTROLLER_LAST_BUTTON = STEAMCONTROLLER_BUTTON_INTERNAL( MAX_STEAM_CONTROLLERS - 1, STEAMCONTROLLER_MAX_BUTTON_COUNT - 1 ), + STEAMCONTROLLER_FIRST_AXIS_BUTTON, + STEAMCONTROLLER_LAST_AXIS_BUTTON = STEAMCONTROLLER_AXIS_BUTTON_INTERNAL( MAX_STEAM_CONTROLLERS - 1, STEAMCONTROLLER_AXIS_BUTTON_COUNT - 1 ), + STEAMCONTROLLER_LAST = STEAMCONTROLLER_LAST_AXIS_BUTTON, + + BUTTON_CODE_LAST, + BUTTON_CODE_COUNT = BUTTON_CODE_LAST - KEY_FIRST + 1, + + // Helpers for XBox 360 + KEY_XBUTTON_UP = JOYSTICK_FIRST_POV_BUTTON, // POV buttons + KEY_XBUTTON_RIGHT, + KEY_XBUTTON_DOWN, + KEY_XBUTTON_LEFT, + + KEY_XBUTTON_A = JOYSTICK_FIRST_BUTTON, // Buttons + KEY_XBUTTON_B, + KEY_XBUTTON_X, + KEY_XBUTTON_Y, + KEY_XBUTTON_LEFT_SHOULDER, + KEY_XBUTTON_RIGHT_SHOULDER, + KEY_XBUTTON_BACK, + KEY_XBUTTON_START, + KEY_XBUTTON_STICK1, + KEY_XBUTTON_STICK2, + + KEY_XSTICK1_RIGHT = JOYSTICK_FIRST_AXIS_BUTTON, // XAXIS POSITIVE + KEY_XSTICK1_LEFT, // XAXIS NEGATIVE + KEY_XSTICK1_DOWN, // YAXIS POSITIVE + KEY_XSTICK1_UP, // YAXIS NEGATIVE + KEY_XBUTTON_LTRIGGER, // ZAXIS POSITIVE + KEY_XBUTTON_RTRIGGER, // ZAXIS NEGATIVE + KEY_XSTICK2_RIGHT, // UAXIS POSITIVE + KEY_XSTICK2_LEFT, // UAXIS NEGATIVE + KEY_XSTICK2_DOWN, // VAXIS POSITIVE + KEY_XSTICK2_UP, // VAXIS NEGATIVE + + // Helpers for Steam Controller + STEAMCONTROLLER_A = STEAMCONTROLLER_FIRST_BUTTON, + STEAMCONTROLLER_B, + STEAMCONTROLLER_X, + STEAMCONTROLLER_Y, + STEAMCONTROLLER_DPAD_UP, + STEAMCONTROLLER_DPAD_RIGHT, + STEAMCONTROLLER_DPAD_DOWN, + STEAMCONTROLLER_DPAD_LEFT, + STEAMCONTROLLER_LEFT_BUMPER, + STEAMCONTROLLER_RIGHT_BUMPER, + STEAMCONTROLLER_LEFT_TRIGGER, + STEAMCONTROLLER_RIGHT_TRIGGER, + STEAMCONTROLLER_LEFT_GRIP, + STEAMCONTROLLER_RIGHT_GRIP, + STEAMCONTROLLER_LEFT_PAD_FINGERDOWN, + STEAMCONTROLLER_RIGHT_PAD_FINGERDOWN, + STEAMCONTROLLER_LEFT_PAD_CLICK, + STEAMCONTROLLER_RIGHT_PAD_CLICK, + STEAMCONTROLLER_LEFT_PAD_UP, + STEAMCONTROLLER_LEFT_PAD_RIGHT, + STEAMCONTROLLER_LEFT_PAD_DOWN, + STEAMCONTROLLER_LEFT_PAD_LEFT, + STEAMCONTROLLER_RIGHT_PAD_UP, + STEAMCONTROLLER_RIGHT_PAD_RIGHT, + STEAMCONTROLLER_RIGHT_PAD_DOWN, + STEAMCONTROLLER_RIGHT_PAD_LEFT, + STEAMCONTROLLER_SELECT, + STEAMCONTROLLER_START, + STEAMCONTROLLER_STEAM, + STEAMCONTROLLER_INACTIVE_START, + STEAMCONTROLLER_F1, + STEAMCONTROLLER_F2, + STEAMCONTROLLER_F3, + STEAMCONTROLLER_F4, + STEAMCONTROLLER_F5, + STEAMCONTROLLER_F6, + STEAMCONTROLLER_F7, + STEAMCONTROLLER_F8, + STEAMCONTROLLER_F9, + STEAMCONTROLLER_F10, + STEAMCONTROLLER_F11, + STEAMCONTROLLER_F12, +}; + +inline bool IsAlpha( ButtonCode_t code ) +{ + return ( code >= KEY_A ) && ( code <= KEY_Z ); +} + +inline bool IsAlphaNumeric( ButtonCode_t code ) +{ + return ( code >= KEY_0 ) && ( code <= KEY_Z ); +} + +inline bool IsSpace( ButtonCode_t code ) +{ + return ( code == KEY_ENTER ) || ( code == KEY_TAB ) || ( code == KEY_SPACE ); +} + +inline bool IsKeypad( ButtonCode_t code ) +{ + return ( code >= MOUSE_FIRST ) && ( code <= KEY_PAD_DECIMAL ); +} + +inline bool IsPunctuation( ButtonCode_t code ) +{ + return ( code >= KEY_0 ) && ( code <= KEY_SPACE ) && !IsAlphaNumeric( code ) && !IsSpace( code ) && !IsKeypad( code ); +} + +inline bool IsKeyCode( ButtonCode_t code ) +{ + return ( code >= KEY_FIRST ) && ( code <= KEY_LAST ); +} + +inline bool IsMouseCode( ButtonCode_t code ) +{ + return ( code >= MOUSE_FIRST ) && ( code <= MOUSE_LAST ); +} + +inline bool IsNovintCode( ButtonCode_t code ) +{ +#if !defined ( _X360 ) + return ( ( code >= NOVINT_FIRST ) && ( code <= NOVINT_LAST ) ); +#else + return false; +#endif +} + +inline bool IsNovintButtonCode( ButtonCode_t code ) +{ +#if !defined ( _X360 ) + return IsNovintCode( code ); +#else + return false; +#endif +} + +inline bool IsJoystickCode( ButtonCode_t code ) +{ + return ( (( code >= JOYSTICK_FIRST ) && ( code <= JOYSTICK_LAST )) || ((code >= STEAMCONTROLLER_FIRST_BUTTON) && (code <= STEAMCONTROLLER_LAST_BUTTON)) ); +} + +inline bool IsJoystickButtonCode( ButtonCode_t code ) +{ + return ( ( ( code >= JOYSTICK_FIRST_BUTTON ) && ( code <= JOYSTICK_LAST_BUTTON ) ) || IsNovintButtonCode( code ) ); +} + +inline bool IsJoystickPOVCode( ButtonCode_t code ) +{ + return ( code >= JOYSTICK_FIRST_POV_BUTTON ) && ( code <= JOYSTICK_LAST_POV_BUTTON ); +} + +inline bool IsJoystickAxisCode( ButtonCode_t code ) +{ + return ( code >= JOYSTICK_FIRST_AXIS_BUTTON ) && ( code <= JOYSTICK_LAST_AXIS_BUTTON ); +} + +inline bool IsSteamControllerCode( ButtonCode_t code ) +{ + return ( ( code >= STEAMCONTROLLER_FIRST ) && ( code <= STEAMCONTROLLER_LAST ) ); +} + +inline bool IsSteamControllerButtonCode( ButtonCode_t code ) +{ + return ( code >= STEAMCONTROLLER_FIRST_BUTTON ) && ( code <= STEAMCONTROLLER_LAST_BUTTON ); +} + +inline bool IsSteamControllerAxisCode( ButtonCode_t code ) +{ + return ( code >= STEAMCONTROLLER_FIRST_AXIS_BUTTON ) && ( code <= STEAMCONTROLLER_LAST_AXIS_BUTTON ); +} + +inline ButtonCode_t GetBaseButtonCode( ButtonCode_t code ) +{ + if ( IsJoystickButtonCode( code ) ) + { + int offset = ( code - JOYSTICK_FIRST_BUTTON ) % JOYSTICK_MAX_BUTTON_COUNT; + return (ButtonCode_t)( JOYSTICK_FIRST_BUTTON + offset ); + } + + if ( IsJoystickPOVCode( code ) ) + { + int offset = ( code - JOYSTICK_FIRST_POV_BUTTON ) % JOYSTICK_POV_BUTTON_COUNT; + return (ButtonCode_t)( JOYSTICK_FIRST_POV_BUTTON + offset ); + } + + if ( IsJoystickAxisCode( code ) ) + { + int offset = ( code - JOYSTICK_FIRST_AXIS_BUTTON ) % JOYSTICK_AXIS_BUTTON_COUNT; + return (ButtonCode_t)( JOYSTICK_FIRST_AXIS_BUTTON + offset ); + } + + if ( IsSteamControllerButtonCode( code ) ) + { + int offset = ( code - STEAMCONTROLLER_FIRST_BUTTON ) % STEAMCONTROLLER_MAX_BUTTON_COUNT; + return ( ButtonCode_t )( STEAMCONTROLLER_FIRST_BUTTON + offset ); + } + + if ( IsSteamControllerAxisCode( code ) ) + { + int offset = ( code - STEAMCONTROLLER_FIRST_AXIS_BUTTON ) % STEAMCONTROLLER_AXIS_BUTTON_COUNT; + return ( ButtonCode_t )( STEAMCONTROLLER_FIRST_AXIS_BUTTON + offset ); + } + + return code; +} + +inline int GetJoystickForCode( ButtonCode_t code ) +{ + if ( !IsJoystickCode( code ) ) + return 0; + + if ( IsJoystickButtonCode( code ) ) + { + int offset = ( code - JOYSTICK_FIRST_BUTTON ) / JOYSTICK_MAX_BUTTON_COUNT; + return offset; + } + if ( IsJoystickPOVCode( code ) ) + { + int offset = ( code - JOYSTICK_FIRST_POV_BUTTON ) / JOYSTICK_POV_BUTTON_COUNT; + return offset; + } + if ( IsJoystickAxisCode( code ) ) + { + int offset = ( code - JOYSTICK_FIRST_AXIS_BUTTON ) / JOYSTICK_AXIS_BUTTON_COUNT; + return offset; + } + if ( IsSteamControllerButtonCode( code ) ) + { + int offset = ( code - STEAMCONTROLLER_FIRST_BUTTON ) / STEAMCONTROLLER_MAX_BUTTON_COUNT; + return offset; + } + if ( IsSteamControllerAxisCode( code ) ) + { + int offset = ( code - STEAMCONTROLLER_FIRST_AXIS_BUTTON ) / STEAMCONTROLLER_AXIS_BUTTON_COUNT; + return offset; + } + + return 0; +} + +inline ButtonCode_t ButtonCodeToJoystickButtonCode( ButtonCode_t code, int nDesiredJoystick ) +{ + if ( ( !IsJoystickCode( code ) && !IsSteamControllerCode( code ) ) || nDesiredJoystick == 0 ) + return code; + + if ( IsJoystickCode( code ) && !IsSteamControllerCode( code ) ) + nDesiredJoystick = clamp( nDesiredJoystick, 0, MAX_JOYSTICKS - 1 ); + else + nDesiredJoystick = clamp( nDesiredJoystick, 0, MAX_STEAM_CONTROLLERS - 1 ); + + code = GetBaseButtonCode( code ); + + // Now upsample it + if ( IsJoystickButtonCode( code ) ) + { + int nOffset = code - JOYSTICK_FIRST_BUTTON; + return JOYSTICK_BUTTON( nDesiredJoystick, nOffset ); + } + + if ( IsJoystickPOVCode( code ) ) + { + int nOffset = code - JOYSTICK_FIRST_POV_BUTTON; + return JOYSTICK_POV_BUTTON( nDesiredJoystick, nOffset ); + } + + if ( IsJoystickAxisCode( code ) ) + { + int nOffset = code - JOYSTICK_FIRST_AXIS_BUTTON; + return JOYSTICK_AXIS_BUTTON( nDesiredJoystick, nOffset ); + } + + if ( IsSteamControllerButtonCode( code ) ) + { + int nOffset = code - STEAMCONTROLLER_FIRST_BUTTON; + return STEAMCONTROLLER_BUTTON( nDesiredJoystick, nOffset ); + } + + if ( IsJoystickAxisCode( code ) ) + { + int nOffset = code - STEAMCONTROLLER_FIRST_AXIS_BUTTON; + return STEAMCONTROLLER_AXIS_BUTTON( nDesiredJoystick, nOffset ); + } + + return code; +} + +#endif // BUTTONCODE_H diff --git a/public/inputsystem/InputEnums.h b/public/inputsystem/InputEnums.h new file mode 100644 index 0000000..ee460be --- /dev/null +++ b/public/inputsystem/InputEnums.h @@ -0,0 +1,195 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//===========================================================================// + +#ifndef INPUTENUMS_H +#define INPUTENUMS_H +#ifdef _WIN32 +#pragma once +#endif + +// Standard maximum +/- value of a joystick axis +#define MAX_BUTTONSAMPLE 32768 + +#if !defined( _X360 ) +#define INVALID_USER_ID -1 +#else +#define INVALID_USER_ID XBX_INVALID_USER_ID +#endif + +//----------------------------------------------------------------------------- +// Forward declarations: +//----------------------------------------------------------------------------- + +enum +{ + MAX_JOYSTICKS = 1, + MOUSE_BUTTON_COUNT = 5, + MAX_NOVINT_DEVICES = 2, +}; + +#if defined( LINUX ) +// Linux has a slightly different mapping order on the joystick axes +enum JoystickAxis_t +{ + JOY_AXIS_X = 0, + JOY_AXIS_Y, + JOY_AXIS_Z, + JOY_AXIS_U, + JOY_AXIS_R, + JOY_AXIS_V, + MAX_JOYSTICK_AXES, +}; +#else +enum JoystickAxis_t +{ + JOY_AXIS_X = 0, + JOY_AXIS_Y, + JOY_AXIS_Z, + JOY_AXIS_R, + JOY_AXIS_U, + JOY_AXIS_V, + MAX_JOYSTICK_AXES, +}; +#endif + +//----------------------------------------------------------------------------- +// Extra mouse codes +//----------------------------------------------------------------------------- +enum +{ + MS_WM_XBUTTONDOWN = 0x020B, + MS_WM_XBUTTONUP = 0x020C, + MS_WM_XBUTTONDBLCLK = 0x020D, + MS_MK_BUTTON4 = 0x0020, + MS_MK_BUTTON5 = 0x0040, +}; + +//----------------------------------------------------------------------------- +// Events +//----------------------------------------------------------------------------- +enum InputEventType_t +{ + IE_ButtonPressed = 0, // m_nData contains a ButtonCode_t + IE_ButtonReleased, // m_nData contains a ButtonCode_t + IE_ButtonDoubleClicked, // m_nData contains a ButtonCode_t + IE_AnalogValueChanged, // m_nData contains an AnalogCode_t, m_nData2 contains the value + + IE_FirstSystemEvent = 100, + IE_Quit = IE_FirstSystemEvent, + IE_ControllerInserted, // m_nData contains the controller ID + IE_ControllerUnplugged, // m_nData contains the controller ID + + IE_FirstVguiEvent = 1000, // Assign ranges for other systems that post user events here + IE_FirstAppEvent = 2000, +}; + +struct InputEvent_t +{ + int m_nType; // Type of the event (see InputEventType_t) + int m_nTick; // Tick on which the event occurred + int m_nData; // Generic 32-bit data, what it contains depends on the event + int m_nData2; // Generic 32-bit data, what it contains depends on the event + int m_nData3; // Generic 32-bit data, what it contains depends on the event +}; + +//----------------------------------------------------------------------------- +// Steam Controller Enums +//----------------------------------------------------------------------------- + +#define MAX_STEAM_CONTROLLERS 8 + +typedef enum +{ + SK_NULL, + SK_BUTTON_A, + SK_BUTTON_B, + SK_BUTTON_X, + SK_BUTTON_Y, + SK_BUTTON_UP, + SK_BUTTON_RIGHT, + SK_BUTTON_DOWN, + SK_BUTTON_LEFT, + SK_BUTTON_LEFT_BUMPER, + SK_BUTTON_RIGHT_BUMPER, + SK_BUTTON_LEFT_TRIGGER, + SK_BUTTON_RIGHT_TRIGGER, + SK_BUTTON_LEFT_GRIP, + SK_BUTTON_RIGHT_GRIP, + SK_BUTTON_LPAD_TOUCH, + SK_BUTTON_RPAD_TOUCH, + SK_BUTTON_LPAD_CLICK, + SK_BUTTON_RPAD_CLICK, + SK_BUTTON_LPAD_UP, + SK_BUTTON_LPAD_RIGHT, + SK_BUTTON_LPAD_DOWN, + SK_BUTTON_LPAD_LEFT, + SK_BUTTON_RPAD_UP, + SK_BUTTON_RPAD_RIGHT, + SK_BUTTON_RPAD_DOWN, + SK_BUTTON_RPAD_LEFT, + SK_BUTTON_SELECT, + SK_BUTTON_START, + SK_BUTTON_STEAM, + SK_BUTTON_INACTIVE_START, + SK_VBUTTON_F1, // These are "virtual" buttons. Useful if you want to have flow that maps an action to button code to be interpreted by some UI that accepts keystrokes, but you + SK_VBUTTON_F2, // don't want to map to real button (perhaps because it would be interpreted by UI in a way you don't like). + SK_VBUTTON_F3, + SK_VBUTTON_F4, + SK_VBUTTON_F5, + SK_VBUTTON_F6, + SK_VBUTTON_F7, + SK_VBUTTON_F8, + SK_VBUTTON_F9, + SK_VBUTTON_F10, + SK_VBUTTON_F11, + SK_VBUTTON_F12, + SK_MAX_KEYS +} sKey_t; + +enum ESteamPadAxis +{ + LEFTPAD_AXIS_X, + LEFTPAD_AXIS_Y, + RIGHTPAD_AXIS_X, + RIGHTPAD_AXIS_Y, + LEFT_TRIGGER_AXIS, + RIGHT_TRIGGER_AXIS, + GYRO_AXIS_PITCH, + GYRO_AXIS_ROLL, + GYRO_AXIS_YAW, + MAX_STEAMPADAXIS = GYRO_AXIS_YAW +}; + +enum +{ + LASTINPUT_KBMOUSE = 0, + LASTINPUT_CONTROLLER = 1, + LASTINPUT_STEAMCONTROLLER = 2 +}; + +enum GameActionSet_t +{ + GAME_ACTION_SET_NONE = -1, + GAME_ACTION_SET_MENUCONTROLS = 0, + GAME_ACTION_SET_FPSCONTROLS, + GAME_ACTION_SET_IN_GAME_HUD, + GAME_ACTION_SET_SPECTATOR, +}; + +enum GameActionSetFlags_t +{ + GAME_ACTION_SET_FLAGS_NONE = 0, + GAME_ACTION_SET_FLAGS_TAUNTING = (1<<0), +}; + +enum JoystickType_t +{ + INPUT_TYPE_GENERIC_JOYSTICK = 0, + INPUT_TYPE_X360, + INPUT_TYPE_STEAMCONTROLLER, +}; + +#endif // INPUTENUMS_H diff --git a/public/inputsystem/iinputsystem.h b/public/inputsystem/iinputsystem.h new file mode 100644 index 0000000..d53496e --- /dev/null +++ b/public/inputsystem/iinputsystem.h @@ -0,0 +1,162 @@ +//========= Copyright Valve Corporation, All rights reserved. ============// +// +// Purpose: +// +//===========================================================================// + +#ifndef IINPUTSYSTEM_H +#define IINPUTSYSTEM_H +#ifdef _WIN32 +#pragma once +#endif + +#include "tier0/platform.h" +#include "appframework/IAppSystem.h" + +#include "inputsystem/InputEnums.h" +#include "inputsystem/ButtonCode.h" +#include "inputsystem/AnalogCode.h" + +#include "steam/isteamcontroller.h" + +//----------------------------------------------------------------------------- +// Main interface for input. This is a low-level interface +//----------------------------------------------------------------------------- +#define INPUTSYSTEM_INTERFACE_VERSION "InputSystemVersion001" +abstract_class IInputSystem : public IAppSystem +{ +public: + // Attach, detach input system from a particular window + // This window should be the root window for the application + // Only 1 window should be attached at any given time. + virtual void AttachToWindow( void* hWnd ) = 0; + virtual void DetachFromWindow( ) = 0; + + // Enables/disables input. PollInputState will not update current + // button/analog states when it is called if the system is disabled. + virtual void EnableInput( bool bEnable ) = 0; + + // Enables/disables the windows message pump. PollInputState will not + // Peek/Dispatch messages if this is disabled + virtual void EnableMessagePump( bool bEnable ) = 0; + + // Polls the current input state + virtual void PollInputState() = 0; + + // Gets the time of the last polling in ms + virtual int GetPollTick() const = 0; + + // Is a button down? "Buttons" are binary-state input devices (mouse buttons, keyboard keys) + virtual bool IsButtonDown( ButtonCode_t code ) const = 0; + + // Returns the tick at which the button was pressed and released + virtual int GetButtonPressedTick( ButtonCode_t code ) const = 0; + virtual int GetButtonReleasedTick( ButtonCode_t code ) const = 0; + + // Gets the value of an analog input device this frame + // Includes joysticks, mousewheel, mouse + virtual int GetAnalogValue( AnalogCode_t code ) const = 0; + + // Gets the change in a particular analog input device this frame + // Includes joysticks, mousewheel, mouse + virtual int GetAnalogDelta( AnalogCode_t code ) const = 0; + + // Returns the input events since the last poll + virtual int GetEventCount() const = 0; + virtual const InputEvent_t* GetEventData( ) const = 0; + + // Posts a user-defined event into the event queue; this is expected + // to be called in overridden wndprocs connected to the root panel. + virtual void PostUserEvent( const InputEvent_t &event ) = 0; + + // Returns the number of joysticks + virtual int GetJoystickCount() const = 0; + + // Enable/disable joystick, it has perf costs + virtual void EnableJoystickInput( int nJoystick, bool bEnable ) = 0; + + // Enable/disable diagonal joystick POV (simultaneous POV buttons down) + virtual void EnableJoystickDiagonalPOV( int nJoystick, bool bEnable ) = 0; + + // Sample the joystick and append events to the input queue + virtual void SampleDevices( void ) = 0; + + // FIXME: Currently force-feedback is only supported on the Xbox 360 + virtual void SetRumble( float fLeftMotor, float fRightMotor, int userId = INVALID_USER_ID ) = 0; + virtual void StopRumble( void ) = 0; + + // Resets the input state + virtual void ResetInputState() = 0; + + // Sets a player as the primary user - all other controllers will be ignored. + virtual void SetPrimaryUserId( int userId ) = 0; + + // Convert back + forth between ButtonCode/AnalogCode + strings + virtual const char *ButtonCodeToString( ButtonCode_t code ) const = 0; + virtual const char *AnalogCodeToString( AnalogCode_t code ) const = 0; + virtual ButtonCode_t StringToButtonCode( const char *pString ) const = 0; + virtual AnalogCode_t StringToAnalogCode( const char *pString ) const = 0; + + // Sleeps until input happens. Pass a negative number to sleep infinitely + virtual void SleepUntilInput( int nMaxSleepTimeMS = -1 ) = 0; + + // Convert back + forth between virtual codes + button codes + // FIXME: This is a temporary piece of code + virtual ButtonCode_t VirtualKeyToButtonCode( int nVirtualKey ) const = 0; + virtual int ButtonCodeToVirtualKey( ButtonCode_t code ) const = 0; + virtual ButtonCode_t ScanCodeToButtonCode( int lParam ) const = 0; + + // How many times have we called PollInputState? + virtual int GetPollCount() const = 0; + + // Sets the cursor position + virtual void SetCursorPosition( int x, int y ) = 0; + + // NVNT get address to haptics interface + virtual void *GetHapticsInterfaceAddress() const = 0; + + virtual void SetNovintPure( bool bPure ) = 0; + + // read and clear accumulated raw input values + virtual bool GetRawMouseAccumulators( int& accumX, int& accumY ) = 0; + + // tell the input system that we're not a game, we're console text mode. + // this is used for dedicated servers to not initialize joystick system. + // this needs to be called before CInputSystem::Init (e.g. in PreInit of + // some system) if you want ot prevent the joystick system from ever + // being initialized. + virtual void SetConsoleTextMode( bool bConsoleTextMode ) = 0; + + virtual ISteamController* SteamControllerInterface() = 0; + virtual uint32 GetNumSteamControllersConnected() = 0; + virtual bool IsSteamControllerActive() = 0; + virtual bool IsSteamControllerConnected() = 0; + virtual int GetSteamControllerIndexForSlot( int nSlot ) = 0; + virtual bool GetRadialMenuStickValues( int nSlot, float &fX, float &fY ) = 0; + virtual void ActivateSteamControllerActionSetForSlot( uint64 nSlot, GameActionSet_t eActionSet ) = 0; + virtual ControllerActionSetHandle_t GetActionSetHandle( GameActionSet_t eActionSet ) = 0; + virtual ControllerActionSetHandle_t GetActionSetHandle( const char* szActionSet ) = 0; + + // Gets the action origin (i.e. which physical input) maps to the given action for the given action set + virtual EControllerActionOrigin GetSteamControllerActionOrigin( const char* action, GameActionSet_t action_set ) = 0; + virtual EControllerActionOrigin GetSteamControllerActionOrigin( const char* action, ControllerActionSetHandle_t action_set_handle ) = 0; + + // Maps a Steam Controller action origin to a string (consisting of a single character) in our SC icon font + virtual const wchar_t* GetSteamControllerFontCharacterForActionOrigin( EControllerActionOrigin origin ) = 0; + + // Maps a Steam Controller action origin to a short text string (e.g. "X", "LB", "LDOWN") describing the control. + // Prefer to actually use the icon font wherever possible. + virtual const wchar_t* GetSteamControllerDescriptionForActionOrigin( EControllerActionOrigin origin ) = 0; + + // This is called with "true" by dedicated server initialization (before calling Init) in order to + // force us to skip initialization of Steam (which messes up dedicated servers). + virtual void SetSkipControllerInitialization( bool bSkip ) = 0; + + // Helper - activate same action set for all controller slots. + void ActivateSteamControllerActionSet( GameActionSet_t eActionSet ) { + ActivateSteamControllerActionSetForSlot( 0xffffffffffffffff, eActionSet ); + } +}; + + +#endif // IINPUTSYSTEM_H |