From 1c5cdd2d393538f0d7f75a2634a628c05bba2cd7 Mon Sep 17 00:00:00 2001 From: Garry Newman Date: Wed, 19 Jun 2019 16:18:12 +0100 Subject: [PATCH] Controller tests --- Facepunch.Steamworks.Test/InputTest.cs | 7 +- .../controller_config/game_actions_252490.vdf | 74 +++++++++++++++++++ .../controller_config/game_actions_252490.vdf | 74 +++++++++++++++++++ .../Generated/Interfaces/ISteamInput.cs | 8 +- Facepunch.Steamworks/Generated/SteamEnums.cs | 2 +- Facepunch.Steamworks/SteamInput.cs | 13 ++-- Facepunch.Steamworks/Structs/Controller.cs | 4 + Generator/Cleanup.cs | 2 + 8 files changed, 171 insertions(+), 13 deletions(-) create mode 100644 Facepunch.Steamworks.Test/bin/Debug/controller_config/game_actions_252490.vdf create mode 100644 Facepunch.Steamworks.Test/bin/Release/controller_config/game_actions_252490.vdf diff --git a/Facepunch.Steamworks.Test/InputTest.cs b/Facepunch.Steamworks.Test/InputTest.cs index 8eef654..ad108e3 100644 --- a/Facepunch.Steamworks.Test/InputTest.cs +++ b/Facepunch.Steamworks.Test/InputTest.cs @@ -11,17 +11,18 @@ namespace Steamworks { [TestClass] [DeploymentItem( "steam_api64.dll" )] + [DeploymentItem( "controller_config/game_actions_252490.vdf" )] public class InputTest { - [TestMethod] public void ControllerList() { - foreach ( var c in SteamInput.Controllers ) + foreach ( var controller in SteamInput.Controllers ) { - Console.WriteLine( "Got Contorller!" ); + Console.Write( $"Controller: {controller}" ); } } } } + \ No newline at end of file diff --git a/Facepunch.Steamworks.Test/bin/Debug/controller_config/game_actions_252490.vdf b/Facepunch.Steamworks.Test/bin/Debug/controller_config/game_actions_252490.vdf new file mode 100644 index 0000000..b0672eb --- /dev/null +++ b/Facepunch.Steamworks.Test/bin/Debug/controller_config/game_actions_252490.vdf @@ -0,0 +1,74 @@ +"In Game Actions" +{ + "actions" + { + "InGameControls" + { + "title" "#Set_Ingame" + "StickPadGyro" + { + "Move" + { + "title" "#Action_Move" + "input_mode" "joystick_move" + } + "Camera" + { + "title" "#Action_Camera" + "input_mode" "absolute_mouse" + } + } + "AnalogTrigger" + { + "Throttle" "#Action_Throttle" + } + "Button" + { + "fire" "#Action_Fire" + "Jump" "#Action_Jump" + "pause_menu" "#Action_Menu" + } + } + "MenuControls" + { + "title" "#Set_Menu" + "StickPadGyro" + { + } + "AnalogTrigger" + { + } + "Button" + { + "menu_up" "#Menu_Up" + "menu_down" "#Menu_Down" + "menu_left" "#Menu_Left" + "menu_right" "#Menu_Right" + "menu_select" "#Menu_Select" + "menu_cancel" "#Menu_Cancel" + "pause_menu" "#Action_ReturnToGame" + } + } + } + "localization" + { + "english" + { + "Set_Ingame" "In-Game Controls" + "Set_Menu" "Menu Controls" + "Action_Move" "Movement" + "Action_Camera" "Camera" + "Action_Throttle" "Throttle" + "Action_Fire" "Fire Weapon" + "Action_Jump" "Jump" + "Action_Menu" "Pause Menu" + "Action_ReturnToGame" "Return To Game" + "Menu_Up" "Up" + "Menu_Down" "Down" + "Menu_Left" "Left" + "Menu_Right" "Right" + "Menu_Select" "Select" + "Menu_Cancel" "Cancel" + } + } +} \ No newline at end of file diff --git a/Facepunch.Steamworks.Test/bin/Release/controller_config/game_actions_252490.vdf b/Facepunch.Steamworks.Test/bin/Release/controller_config/game_actions_252490.vdf new file mode 100644 index 0000000..b0672eb --- /dev/null +++ b/Facepunch.Steamworks.Test/bin/Release/controller_config/game_actions_252490.vdf @@ -0,0 +1,74 @@ +"In Game Actions" +{ + "actions" + { + "InGameControls" + { + "title" "#Set_Ingame" + "StickPadGyro" + { + "Move" + { + "title" "#Action_Move" + "input_mode" "joystick_move" + } + "Camera" + { + "title" "#Action_Camera" + "input_mode" "absolute_mouse" + } + } + "AnalogTrigger" + { + "Throttle" "#Action_Throttle" + } + "Button" + { + "fire" "#Action_Fire" + "Jump" "#Action_Jump" + "pause_menu" "#Action_Menu" + } + } + "MenuControls" + { + "title" "#Set_Menu" + "StickPadGyro" + { + } + "AnalogTrigger" + { + } + "Button" + { + "menu_up" "#Menu_Up" + "menu_down" "#Menu_Down" + "menu_left" "#Menu_Left" + "menu_right" "#Menu_Right" + "menu_select" "#Menu_Select" + "menu_cancel" "#Menu_Cancel" + "pause_menu" "#Action_ReturnToGame" + } + } + } + "localization" + { + "english" + { + "Set_Ingame" "In-Game Controls" + "Set_Menu" "Menu Controls" + "Action_Move" "Movement" + "Action_Camera" "Camera" + "Action_Throttle" "Throttle" + "Action_Fire" "Fire Weapon" + "Action_Jump" "Jump" + "Action_Menu" "Pause Menu" + "Action_ReturnToGame" "Return To Game" + "Menu_Up" "Up" + "Menu_Down" "Down" + "Menu_Left" "Left" + "Menu_Right" "Right" + "Menu_Select" "Select" + "Menu_Cancel" "Cancel" + } + } +} \ No newline at end of file diff --git a/Facepunch.Steamworks/Generated/Interfaces/ISteamInput.cs b/Facepunch.Steamworks/Generated/Interfaces/ISteamInput.cs index b329417..f66238d 100644 --- a/Facepunch.Steamworks/Generated/Interfaces/ISteamInput.cs +++ b/Facepunch.Steamworks/Generated/Interfaces/ISteamInput.cs @@ -410,11 +410,11 @@ namespace Steamworks #region FunctionMeta [UnmanagedFunctionPointer( CallingConvention.ThisCall )] - private delegate SteamInputType FGetInputTypeForHandle( IntPtr self, InputHandle_t inputHandle ); + private delegate InputType FGetInputTypeForHandle( IntPtr self, InputHandle_t inputHandle ); private FGetInputTypeForHandle _GetInputTypeForHandle; #endregion - internal SteamInputType GetInputTypeForHandle( InputHandle_t inputHandle ) + internal InputType GetInputTypeForHandle( InputHandle_t inputHandle ) { return _GetInputTypeForHandle( Self, inputHandle ); } @@ -476,11 +476,11 @@ namespace Steamworks #region FunctionMeta [UnmanagedFunctionPointer( CallingConvention.ThisCall )] - private delegate InputActionOrigin FTranslateActionOrigin( IntPtr self, SteamInputType eDestinationInputType, InputActionOrigin eSourceOrigin ); + private delegate InputActionOrigin FTranslateActionOrigin( IntPtr self, InputType eDestinationInputType, InputActionOrigin eSourceOrigin ); private FTranslateActionOrigin _TranslateActionOrigin; #endregion - internal InputActionOrigin TranslateActionOrigin( SteamInputType eDestinationInputType, InputActionOrigin eSourceOrigin ) + internal InputActionOrigin TranslateActionOrigin( InputType eDestinationInputType, InputActionOrigin eSourceOrigin ) { return _TranslateActionOrigin( Self, eDestinationInputType, eSourceOrigin ); } diff --git a/Facepunch.Steamworks/Generated/SteamEnums.cs b/Facepunch.Steamworks/Generated/SteamEnums.cs index 4b73942..0cb5b89 100644 --- a/Facepunch.Steamworks/Generated/SteamEnums.cs +++ b/Facepunch.Steamworks/Generated/SteamEnums.cs @@ -1436,7 +1436,7 @@ namespace Steamworks // // ESteamInputType // - internal enum SteamInputType : int + public enum InputType : int { Unknown = 0, SteamController = 1, diff --git a/Facepunch.Steamworks/SteamInput.cs b/Facepunch.Steamworks/SteamInput.cs index cd4e552..764b89f 100644 --- a/Facepunch.Steamworks/SteamInput.cs +++ b/Facepunch.Steamworks/SteamInput.cs @@ -20,8 +20,6 @@ namespace Steamworks { _internal = new ISteamInput(); _internal.Init(); - - _internal.DoInit(); } return _internal; @@ -36,9 +34,15 @@ namespace Steamworks internal static void InstallEvents() { + Internal.DoInit(); + Internal.RunFrame(); + // None? } + + static InputHandle_t[] queryArray = new InputHandle_t[STEAM_CONTROLLER_MAX_COUNT]; + /// /// Return a list of connected controllers. Will return null if none found. /// @@ -46,12 +50,11 @@ namespace Steamworks { get { - var array = new InputHandle_t[STEAM_CONTROLLER_MAX_COUNT]; - var num = Internal.GetConnectedControllers( array ); + var num = Internal.GetConnectedControllers( queryArray ); for ( int i = 0; i < num; i++ ) { - yield return new Controller( array[num] ); + yield return new Controller( queryArray[i] ); } } diff --git a/Facepunch.Steamworks/Structs/Controller.cs b/Facepunch.Steamworks/Structs/Controller.cs index 155edd3..35bcbf8 100644 --- a/Facepunch.Steamworks/Structs/Controller.cs +++ b/Facepunch.Steamworks/Structs/Controller.cs @@ -10,5 +10,9 @@ namespace Steamworks { this.inputHandle = inputHandle_t; } + + public InputType InputType => SteamInput.Internal.GetInputTypeForHandle( inputHandle ); + + public override string ToString() => $"{InputType}.{inputHandle.Value}"; } } \ No newline at end of file diff --git a/Generator/Cleanup.cs b/Generator/Cleanup.cs index 21d32c5..f16a88a 100644 --- a/Generator/Cleanup.cs +++ b/Generator/Cleanup.cs @@ -39,6 +39,7 @@ public static class Cleanup type = type.Replace( "SteamNetworkingMicroseconds", "long" ); type = type.Replace( "SteamNetworkingSocketsDebugOutputType", "DebugOutputType" ); type = type.Replace( "SteamNetworkingGetConfigValueResult", "NetConfigResult" ); + type = type.Replace( "SteamInputType", "InputType" ); return type; } @@ -75,6 +76,7 @@ public static class Cleanup if ( name == "P2PSend" ) return "public"; if ( name == "RoomEnter" ) return "public"; if ( name == "P2PSessionError" ) return "public"; + if ( name == "InputType" ) return "public"; return "internal"; }