Team Fortress 2 Source Code as on 22/4/2020
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.

210 lines
8.4 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 32
  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. };
  37. enum EControllerSourceMode
  38. {
  39. k_EControllerSourceMode_None,
  40. k_EControllerSourceMode_Dpad,
  41. k_EControllerSourceMode_Buttons,
  42. k_EControllerSourceMode_FourButtons,
  43. k_EControllerSourceMode_AbsoluteMouse,
  44. k_EControllerSourceMode_RelativeMouse,
  45. k_EControllerSourceMode_JoystickMove,
  46. k_EControllerSourceMode_JoystickCamera,
  47. k_EControllerSourceMode_ScrollWheel,
  48. k_EControllerSourceMode_Trigger,
  49. k_EControllerSourceMode_TouchMenu
  50. };
  51. enum EControllerActionOrigin
  52. {
  53. k_EControllerActionOrigin_None,
  54. k_EControllerActionOrigin_A,
  55. k_EControllerActionOrigin_B,
  56. k_EControllerActionOrigin_X,
  57. k_EControllerActionOrigin_Y,
  58. k_EControllerActionOrigin_LeftBumper,
  59. k_EControllerActionOrigin_RightBumper,
  60. k_EControllerActionOrigin_LeftGrip,
  61. k_EControllerActionOrigin_RightGrip,
  62. k_EControllerActionOrigin_Start,
  63. k_EControllerActionOrigin_Back,
  64. k_EControllerActionOrigin_LeftPad_Touch,
  65. k_EControllerActionOrigin_LeftPad_Swipe,
  66. k_EControllerActionOrigin_LeftPad_Click,
  67. k_EControllerActionOrigin_LeftPad_DPadNorth,
  68. k_EControllerActionOrigin_LeftPad_DPadSouth,
  69. k_EControllerActionOrigin_LeftPad_DPadWest,
  70. k_EControllerActionOrigin_LeftPad_DPadEast,
  71. k_EControllerActionOrigin_RightPad_Touch,
  72. k_EControllerActionOrigin_RightPad_Swipe,
  73. k_EControllerActionOrigin_RightPad_Click,
  74. k_EControllerActionOrigin_RightPad_DPadNorth,
  75. k_EControllerActionOrigin_RightPad_DPadSouth,
  76. k_EControllerActionOrigin_RightPad_DPadWest,
  77. k_EControllerActionOrigin_RightPad_DPadEast,
  78. k_EControllerActionOrigin_LeftTrigger_Pull,
  79. k_EControllerActionOrigin_LeftTrigger_Click,
  80. k_EControllerActionOrigin_RightTrigger_Pull,
  81. k_EControllerActionOrigin_RightTrigger_Click,
  82. k_EControllerActionOrigin_LeftStick_Move,
  83. k_EControllerActionOrigin_LeftStick_Click,
  84. k_EControllerActionOrigin_LeftStick_DPadNorth,
  85. k_EControllerActionOrigin_LeftStick_DPadSouth,
  86. k_EControllerActionOrigin_LeftStick_DPadWest,
  87. k_EControllerActionOrigin_LeftStick_DPadEast,
  88. k_EControllerActionOrigin_Gyro_Move,
  89. k_EControllerActionOrigin_Gyro_Pitch,
  90. k_EControllerActionOrigin_Gyro_Yaw,
  91. k_EControllerActionOrigin_Gyro_Roll,
  92. k_EControllerActionOrigin_Count
  93. };
  94. // ControllerHandle_t is used to refer to a specific controller.
  95. // This handle will consistently identify a controller, even if it is disconnected and re-connected
  96. typedef uint64 ControllerHandle_t;
  97. // These handles are used to refer to a specific in-game action or action set
  98. // All action handles should be queried during initialization for performance reasons
  99. typedef uint64 ControllerActionSetHandle_t;
  100. typedef uint64 ControllerDigitalActionHandle_t;
  101. typedef uint64 ControllerAnalogActionHandle_t;
  102. #pragma pack( push, 1 )
  103. struct ControllerAnalogActionData_t
  104. {
  105. // Type of data coming from this action, this will match what got specified in the action set
  106. EControllerSourceMode eMode;
  107. // The current state of this action; will be delta updates for mouse actions
  108. float x, y;
  109. // Whether or not this action is currently available to be bound in the active action set
  110. bool bActive;
  111. };
  112. struct ControllerDigitalActionData_t
  113. {
  114. // The current state of this action; will be true if currently pressed
  115. bool bState;
  116. // Whether or not this action is currently available to be bound in the active action set
  117. bool bActive;
  118. };
  119. #pragma pack( pop )
  120. //-----------------------------------------------------------------------------
  121. // Purpose: Native Steam controller support API
  122. //-----------------------------------------------------------------------------
  123. class ISteamController
  124. {
  125. public:
  126. // Init and Shutdown must be called when starting/ending use of this interface
  127. virtual bool Init() = 0;
  128. virtual bool Shutdown() = 0;
  129. // Pump callback/callresult events
  130. // Note: SteamAPI_RunCallbacks will do this for you, so you should never need to call this directly.
  131. virtual void RunFrame() = 0;
  132. // Enumerate currently connected controllers
  133. // handlesOut should point to a STEAM_CONTROLLER_MAX_COUNT sized array of ControllerHandle_t handles
  134. // Returns the number of handles written to handlesOut
  135. virtual int GetConnectedControllers( ControllerHandle_t *handlesOut ) = 0;
  136. // Invokes the Steam overlay and brings up the binding screen
  137. // Returns false is overlay is disabled / unavailable, or the user is not in Big Picture mode
  138. virtual bool ShowBindingPanel( ControllerHandle_t controllerHandle ) = 0;
  139. // ACTION SETS
  140. // Lookup the handle for an Action Set. Best to do this once on startup, and store the handles for all future API calls.
  141. virtual ControllerActionSetHandle_t GetActionSetHandle( const char *pszActionSetName ) = 0;
  142. // Reconfigure the controller to use the specified action set (ie 'Menu', 'Walk' or 'Drive')
  143. // This is cheap, and can be safely called repeatedly. It's often easier to repeatedly call it in
  144. // your state loops, instead of trying to place it in all of your state transitions.
  145. virtual void ActivateActionSet( ControllerHandle_t controllerHandle, ControllerActionSetHandle_t actionSetHandle ) = 0;
  146. virtual ControllerActionSetHandle_t GetCurrentActionSet( ControllerHandle_t controllerHandle ) = 0;
  147. // ACTIONS
  148. // Lookup the handle for a digital action. Best to do this once on startup, and store the handles for all future API calls.
  149. virtual ControllerDigitalActionHandle_t GetDigitalActionHandle( const char *pszActionName ) = 0;
  150. // Returns the current state of the supplied digital game action
  151. virtual ControllerDigitalActionData_t GetDigitalActionData( ControllerHandle_t controllerHandle, ControllerDigitalActionHandle_t digitalActionHandle ) = 0;
  152. // 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.
  153. // originsOut should point to a STEAM_CONTROLLER_MAX_ORIGINS sized array of EControllerActionOrigin handles
  154. virtual int GetDigitalActionOrigins( ControllerHandle_t controllerHandle, ControllerActionSetHandle_t actionSetHandle, ControllerDigitalActionHandle_t digitalActionHandle, EControllerActionOrigin *originsOut ) = 0;
  155. // Lookup the handle for an analog action. Best to do this once on startup, and store the handles for all future API calls.
  156. virtual ControllerAnalogActionHandle_t GetAnalogActionHandle( const char *pszActionName ) = 0;
  157. // Returns the current state of these supplied analog game action
  158. virtual ControllerAnalogActionData_t GetAnalogActionData( ControllerHandle_t controllerHandle, ControllerAnalogActionHandle_t analogActionHandle ) = 0;
  159. // 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.
  160. // originsOut should point to a STEAM_CONTROLLER_MAX_ORIGINS sized array of EControllerActionOrigin handles
  161. virtual int GetAnalogActionOrigins( ControllerHandle_t controllerHandle, ControllerActionSetHandle_t actionSetHandle, ControllerAnalogActionHandle_t analogActionHandle, EControllerActionOrigin *originsOut ) = 0;
  162. virtual void StopAnalogActionMomentum( ControllerHandle_t controllerHandle, ControllerAnalogActionHandle_t eAction ) = 0;
  163. // Trigger a haptic pulse on a controller
  164. virtual void TriggerHapticPulse( ControllerHandle_t controllerHandle, ESteamControllerPad eTargetPad, unsigned short usDurationMicroSec ) = 0;
  165. };
  166. #define STEAMCONTROLLER_INTERFACE_VERSION "SteamController003"
  167. #endif // ISTEAMCONTROLLER_H