Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

214 lines
8.8 KiB

  1. //====== Copyright 1996-2013, Valve Corporation, All rights reserved. =======
  2. //
  3. // Purpose: interface to valve controller
  4. //
  5. //=============================================================================
  6. #ifndef ISTEAMCONTROLLER_H
  7. #define ISTEAMCONTROLLER_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "isteamclient.h"
  12. #define STEAM_CONTROLLER_MAX_COUNT 16
  13. #define STEAM_CONTROLLER_MAX_ANALOG_ACTIONS 16
  14. #define STEAM_CONTROLLER_MAX_DIGITAL_ACTIONS 128
  15. #define STEAM_CONTROLLER_MAX_ORIGINS 8
  16. // When sending an option to a specific controller handle, you can send to all controllers via this command
  17. #define STEAM_CONTROLLER_HANDLE_ALL_CONTROLLERS UINT64_MAX
  18. #define STEAM_CONTROLLER_MIN_ANALOG_ACTION_DATA -1.0f
  19. #define STEAM_CONTROLLER_MAX_ANALOG_ACTION_DATA 1.0f
  20. enum ESteamControllerPad
  21. {
  22. k_ESteamControllerPad_Left,
  23. k_ESteamControllerPad_Right
  24. };
  25. enum EControllerSource
  26. {
  27. k_EControllerSource_None,
  28. k_EControllerSource_LeftTrackpad,
  29. k_EControllerSource_RightTrackpad,
  30. k_EControllerSource_Joystick,
  31. k_EControllerSource_ABXY,
  32. k_EControllerSource_Switch,
  33. k_EControllerSource_LeftTrigger,
  34. k_EControllerSource_RightTrigger,
  35. k_EControllerSource_Gyro,
  36. k_EControllerSource_Count
  37. };
  38. enum EControllerSourceMode
  39. {
  40. k_EControllerSourceMode_None,
  41. k_EControllerSourceMode_Dpad,
  42. k_EControllerSourceMode_Buttons,
  43. k_EControllerSourceMode_FourButtons,
  44. k_EControllerSourceMode_AbsoluteMouse,
  45. k_EControllerSourceMode_RelativeMouse,
  46. k_EControllerSourceMode_JoystickMove,
  47. k_EControllerSourceMode_JoystickCamera,
  48. k_EControllerSourceMode_ScrollWheel,
  49. k_EControllerSourceMode_Trigger,
  50. k_EControllerSourceMode_TouchMenu,
  51. k_EControllerSourceMode_MouseJoystick,
  52. k_EControllerSourceMode_MouseRegion
  53. };
  54. enum EControllerActionOrigin
  55. {
  56. k_EControllerActionOrigin_None,
  57. k_EControllerActionOrigin_A,
  58. k_EControllerActionOrigin_B,
  59. k_EControllerActionOrigin_X,
  60. k_EControllerActionOrigin_Y,
  61. k_EControllerActionOrigin_LeftBumper,
  62. k_EControllerActionOrigin_RightBumper,
  63. k_EControllerActionOrigin_LeftGrip,
  64. k_EControllerActionOrigin_RightGrip,
  65. k_EControllerActionOrigin_Start,
  66. k_EControllerActionOrigin_Back,
  67. k_EControllerActionOrigin_LeftPad_Touch,
  68. k_EControllerActionOrigin_LeftPad_Swipe,
  69. k_EControllerActionOrigin_LeftPad_Click,
  70. k_EControllerActionOrigin_LeftPad_DPadNorth,
  71. k_EControllerActionOrigin_LeftPad_DPadSouth,
  72. k_EControllerActionOrigin_LeftPad_DPadWest,
  73. k_EControllerActionOrigin_LeftPad_DPadEast,
  74. k_EControllerActionOrigin_RightPad_Touch,
  75. k_EControllerActionOrigin_RightPad_Swipe,
  76. k_EControllerActionOrigin_RightPad_Click,
  77. k_EControllerActionOrigin_RightPad_DPadNorth,
  78. k_EControllerActionOrigin_RightPad_DPadSouth,
  79. k_EControllerActionOrigin_RightPad_DPadWest,
  80. k_EControllerActionOrigin_RightPad_DPadEast,
  81. k_EControllerActionOrigin_LeftTrigger_Pull,
  82. k_EControllerActionOrigin_LeftTrigger_Click,
  83. k_EControllerActionOrigin_RightTrigger_Pull,
  84. k_EControllerActionOrigin_RightTrigger_Click,
  85. k_EControllerActionOrigin_LeftStick_Move,
  86. k_EControllerActionOrigin_LeftStick_Click,
  87. k_EControllerActionOrigin_LeftStick_DPadNorth,
  88. k_EControllerActionOrigin_LeftStick_DPadSouth,
  89. k_EControllerActionOrigin_LeftStick_DPadWest,
  90. k_EControllerActionOrigin_LeftStick_DPadEast,
  91. k_EControllerActionOrigin_Gyro_Move,
  92. k_EControllerActionOrigin_Gyro_Pitch,
  93. k_EControllerActionOrigin_Gyro_Yaw,
  94. k_EControllerActionOrigin_Gyro_Roll,
  95. k_EControllerActionOrigin_Count
  96. };
  97. // ControllerHandle_t is used to refer to a specific controller.
  98. // This handle will consistently identify a controller, even if it is disconnected and re-connected
  99. typedef uint64 ControllerHandle_t;
  100. // These handles are used to refer to a specific in-game action or action set
  101. // All action handles should be queried during initialization for performance reasons
  102. typedef uint64 ControllerActionSetHandle_t;
  103. typedef uint64 ControllerDigitalActionHandle_t;
  104. typedef uint64 ControllerAnalogActionHandle_t;
  105. #pragma pack( push, 1 )
  106. struct ControllerAnalogActionData_t
  107. {
  108. // Type of data coming from this action, this will match what got specified in the action set
  109. EControllerSourceMode eMode;
  110. // The current state of this action; will be delta updates for mouse actions
  111. float x, y;
  112. // Whether or not this action is currently available to be bound in the active action set
  113. bool bActive;
  114. };
  115. struct ControllerDigitalActionData_t
  116. {
  117. // The current state of this action; will be true if currently pressed
  118. bool bState;
  119. // Whether or not this action is currently available to be bound in the active action set
  120. bool bActive;
  121. };
  122. #pragma pack( pop )
  123. //-----------------------------------------------------------------------------
  124. // Purpose: Native Steam controller support API
  125. //-----------------------------------------------------------------------------
  126. class ISteamController
  127. {
  128. public:
  129. // Init and Shutdown must be called when starting/ending use of this interface
  130. virtual bool Init() = 0;
  131. virtual bool Shutdown() = 0;
  132. // Synchronize API state with the latest Steam Controller inputs available. This
  133. // is performed automatically by SteamAPI_RunCallbacks, but for the absolute lowest
  134. // possible latency, you call this directly before reading controller state.
  135. virtual void RunFrame() = 0;
  136. // Enumerate currently connected controllers
  137. // handlesOut should point to a STEAM_CONTROLLER_MAX_COUNT sized array of ControllerHandle_t handles
  138. // Returns the number of handles written to handlesOut
  139. virtual int GetConnectedControllers( ControllerHandle_t *handlesOut ) = 0;
  140. // Invokes the Steam overlay and brings up the binding screen
  141. // Returns false is overlay is disabled / unavailable, or the user is not in Big Picture mode
  142. virtual bool ShowBindingPanel( ControllerHandle_t controllerHandle ) = 0;
  143. // ACTION SETS
  144. // Lookup the handle for an Action Set. Best to do this once on startup, and store the handles for all future API calls.
  145. virtual ControllerActionSetHandle_t GetActionSetHandle( const char *pszActionSetName ) = 0;
  146. // Reconfigure the controller to use the specified action set (ie 'Menu', 'Walk' or 'Drive')
  147. // This is cheap, and can be safely called repeatedly. It's often easier to repeatedly call it in
  148. // your state loops, instead of trying to place it in all of your state transitions.
  149. virtual void ActivateActionSet( ControllerHandle_t controllerHandle, ControllerActionSetHandle_t actionSetHandle ) = 0;
  150. virtual ControllerActionSetHandle_t GetCurrentActionSet( ControllerHandle_t controllerHandle ) = 0;
  151. // ACTIONS
  152. // Lookup the handle for a digital action. Best to do this once on startup, and store the handles for all future API calls.
  153. virtual ControllerDigitalActionHandle_t GetDigitalActionHandle( const char *pszActionName ) = 0;
  154. // Returns the current state of the supplied digital game action
  155. virtual ControllerDigitalActionData_t GetDigitalActionData( ControllerHandle_t controllerHandle, ControllerDigitalActionHandle_t digitalActionHandle ) = 0;
  156. // Get the origin(s) for a digital action within an action set. Returns the number of origins supplied in originsOut. Use this to display the appropriate on-screen prompt for the action.
  157. // originsOut should point to a STEAM_CONTROLLER_MAX_ORIGINS sized array of EControllerActionOrigin handles
  158. virtual int GetDigitalActionOrigins( ControllerHandle_t controllerHandle, ControllerActionSetHandle_t actionSetHandle, ControllerDigitalActionHandle_t digitalActionHandle, EControllerActionOrigin *originsOut ) = 0;
  159. // Lookup the handle for an analog action. Best to do this once on startup, and store the handles for all future API calls.
  160. virtual ControllerAnalogActionHandle_t GetAnalogActionHandle( const char *pszActionName ) = 0;
  161. // Returns the current state of these supplied analog game action
  162. virtual ControllerAnalogActionData_t GetAnalogActionData( ControllerHandle_t controllerHandle, ControllerAnalogActionHandle_t analogActionHandle ) = 0;
  163. // Get the origin(s) for an analog action within an action set. Returns the number of origins supplied in originsOut. Use this to display the appropriate on-screen prompt for the action.
  164. // originsOut should point to a STEAM_CONTROLLER_MAX_ORIGINS sized array of EControllerActionOrigin handles
  165. virtual int GetAnalogActionOrigins( ControllerHandle_t controllerHandle, ControllerActionSetHandle_t actionSetHandle, ControllerAnalogActionHandle_t analogActionHandle, EControllerActionOrigin *originsOut ) = 0;
  166. virtual void StopAnalogActionMomentum( ControllerHandle_t controllerHandle, ControllerAnalogActionHandle_t eAction ) = 0;
  167. // Trigger a haptic pulse on a controller
  168. virtual void TriggerHapticPulse( ControllerHandle_t controllerHandle, ESteamControllerPad eTargetPad, unsigned short usDurationMicroSec ) = 0;
  169. virtual void TriggerRepeatedHapticPulse( ControllerHandle_t controllerHandle, ESteamControllerPad eTargetPad, unsigned short usDurationMicroSec, unsigned short usOffMicroSec, unsigned short unRepeat, unsigned int nFlags ) = 0;
  170. };
  171. #define STEAMCONTROLLER_INTERFACE_VERSION "SteamController003"
  172. #endif // ISTEAMCONTROLLER_H