浏览代码

Added gamepad functions.

Brucey 5 年之前
父节点
当前提交
62013a7258
共有 2 个文件被更改,包括 60 次插入0 次删除
  1. 18 0
      glfwjoystick.mod/common.bmx
  2. 42 0
      glfwjoystick.mod/glfwjoystick.bmx

+ 18 - 0
glfwjoystick.mod/common.bmx

@@ -32,6 +32,10 @@ Extern
 	Function bmx_glfw_glfwGetJoystickGUID:Byte Ptr(id:Int)="glfwGetJoystickGUID"
 	Function bmx_glfw_glfwJoystickIsGamepad:Int(id:Int)="glfwJoystickIsGamepad"
 	Function bmx_glfw_glfwSetJoystickCallback(func(id:Int, event:Int))="glfwSetJoystickCallback"
+	
+	Function bmx_glfw_glfwGetGamepadState:Int(id:Int, state:GLFWgamepadstate Var)="glfwGetGamepadState"
+	Function bmx_glfw_glfwUpdateGamepadMappings:Int(txt:Byte Ptr)="glfwUpdateGamepadMappings"
+	Function bmx_glfw_glfwGetGamepadName:Byte Ptr(id:Int)="glfwGetGamepadName"
 End Extern
 
 Const GLFW_JOYSTICK_1:Int = 0
@@ -52,3 +56,17 @@ Const GLFW_JOYSTICK_15:Int = 14
 Const GLFW_JOYSTICK_16:Int = 15
 Const GLFW_JOYSTICK_LAST:Int = GLFW_JOYSTICK_16
 
+
+Rem
+bbdoc: Describes the input state of a gamepad.
+End Rem
+Struct GLFWgamepadstate
+	Rem
+	bbdoc: The states of each gamepad button, #GLFW_PRESS or #GLFW_RELEASE.
+	End Rem
+	Field StaticArray buttons:Byte[15]
+	Rem
+	bbdoc: The states of each gamepad axis, in the range -1.0 to 1.0 inclusive.
+	End Rem
+	Field StaticArray axes:Float[6]
+End Struct

+ 42 - 0
glfwjoystick.mod/glfwjoystick.bmx

@@ -130,3 +130,45 @@ End Rem
 Function SetJoystickCallback(func(id:Int, event:Int))
 	bmx_glfw_glfwSetJoystickCallback(func)
 End Function
+
+Rem
+bbdoc: Retrieves the state of the specified joystick remapped to an Xbox-like gamepad.
+about: If the specified joystick is not present or does not have a gamepad mapping this function will return #False
+but will not generate an error. Call #JoystickPresent to check whether it is present regardless of whether it has a mapping.
+
+The Guide button may not be available for input as it is often hooked by the system or the Steam client.
+
+Not all devices have all the buttons or axes provided by #GLFWgamepadstate. Unavailable buttons and axes will always report GLFW_RELEASE and 0.0 respectively.
+End Rem
+Function GetGamepadState:Int(id:Int, state:GLFWgamepadstate Var)
+	Return bmx_glfw_glfwGetGamepadState(id, state)
+End Function
+
+Rem
+bbdoc: parses the specified #String and updates the internal list with any gamepad mappings it finds.
+returns: #True if successful, or #False if an error occurred.
+about: This string may contain either a single gamepad mapping or many mappings separated by newlines. The parser supports the full format
+of the gamecontrollerdb.txt source file including empty lines and comments.
+
+See <a href="https://www.glfw.org/docs/latest/input_guide.html#gamepad_mapping">Gamepad mappings</a> for a description of the format.
+
+If there is already a gamepad mapping for a given GUID in the internal list, it will be replaced by the one passed to this function.
+If the library is terminated and re-initialized the internal list will revert to the built-in default.
+End Rem
+Function UpdateGamepadMappings:Int(txt:String)
+	Local t:Byte Ptr = txt.ToUTF8String()
+	Local res:Int = bmx_glfw_glfwUpdateGamepadMappings(t)
+	MemFree(t)
+End Function
+
+Rem
+bbdoc: Returns the human-readable name of the gamepad from the gamepad mapping assigned to the specified joystick.
+about: If the specified joystick is not present or does not have a gamepad mapping this function will return NULL but will not generate an error.
+Call #JoystickPresent to check whether it is present regardless of whether it has a mapping.
+End Rem
+Function GetGamepadName:String(id:Int)
+	Local n:Byte Ptr = bmx_glfw_glfwGetGamepadName(id)
+	If n Then
+		Return String.FromUTF8String(n)
+	End If
+End Function