begin binding gamepad functions from GLFW to SML

This commit is contained in:
2026-01-19 13:23:47 +00:00
parent c6dee6e9f9
commit 6f89fbc89c
4 changed files with 64 additions and 0 deletions

View File

@@ -40,3 +40,29 @@ void setKeyCallback(GLFWwindow *window) {
glfwSetKeyCallback(window, keyCallback);
}
// gamepad code
GLFWgamepadstate state;
float* axes;
int axesCount = -1;
void getGamepadState(int joystickID) {
if (glfwGetGamepadState(joystickID, &state)) {
axes = glfwGetJoystickAxes(joystickID, &axesCount);
}
}
float getLeftJoystickXAxisState() {
if (axesCount >= 2) {
return axes[0];
} else {
return 99.0;
}
}
float getLeftJoystickYAxisState() {
if (axesCount >= 2) {
return axes[1];
} else {
return 99.0;
}
}

View File

@@ -52,4 +52,12 @@ struct
val (KEY_ARROW_DOWN, _) =
_symbol "KEY_ARROW_DOWN" public : ( unit -> int ) * ( int -> unit );
val KEY_ARROW_DOWN = KEY_ARROW_DOWN ()
val getGamepadState =
_import "getGamepadState" public : int -> unit;
val getLeftJoystickXAxisState =
_import "getLeftJoystickXAxisState" public : unit -> Real32.real;
val getLeftJoystickYAxisState =
_import "getLeftJoystickYAxisState" public : unit -> Real32.real;
end

View File

@@ -145,6 +145,28 @@ struct
updateLoop (0, InputMailbox.getMessagesAndClear (), app)
end
fun getGamepadState () =
let
val () = Input.getGamepadState 0
val () = Input.getGamepadState 1
val () = Input.getGamepadState 2
val () = Input.getGamepadState 3
val () = Input.getGamepadState 4
val () = Input.getGamepadState 5
val () = Input.getGamepadState 6
val () = Input.getGamepadState 7
val () = Input.getGamepadState 8
val () = Input.getGamepadState 9
val () = Input.getGamepadState 10
val () = Input.getGamepadState 11
val () = Input.getGamepadState 12
val () = Input.getGamepadState 13
val () = Input.getGamepadState 14
val () = Input.getGamepadState 15
in
()
end
fun helpLoop (app, shellState as {window, ...}: t) =
case Glfw.windowShouldClose window of
false =>
@@ -154,6 +176,13 @@ struct
val _ = Gles3.clearColor (0.89, 0.89, 0.89, 1.0)
val _ = Gles3.clear ()
val () = getGamepadState ()
val xAxis = Input.getLeftJoystickXAxisState ()
val yAxis = Input.getLeftJoystickYAxisState ()
val () = print ("x axis = " ^ Real32.toString xAxis ^ "\n")
val () = print ("y axis = " ^ Real32.toString yAxis ^ "\n")
val () = print "\n"
val app = update app
val _ = draw shellState

View File

@@ -1,3 +1,4 @@
# To-do list
- Bind gamepad functions from GLFW
- Modify deletion functions to use `PersistentVector.delete`
- Implement 'yj' motion and add tests for it