progress reimplementing gamepad support

This commit is contained in:
2026-01-21 21:03:20 +00:00
parent 50868b830b
commit 2d1bcf28f7

View File

@@ -2,6 +2,8 @@ structure GlfwGamepad =
struct struct
datatype mode = datatype mode =
PENDING PENDING
(* we need to wait for all keys to be released after pressing a button *)
| WAIT_FOR_KEY_RELEASE
| TRIANGLE | TRIANGLE
| TRIANGLE_CIRCLE | TRIANGLE_CIRCLE
| CIRCLE | CIRCLE
@@ -23,7 +25,7 @@ struct
, squarePressed: bool , squarePressed: bool
} }
fun setToPendingAndUnshifted (gamepadState: gamepad_state) = fun releaseKeysAndUnshift (gamepadState: gamepad_state) =
let let
val val
{ mode = _ { mode = _
@@ -34,7 +36,7 @@ struct
, squarePressed , squarePressed
} = gamepadState } = gamepadState
in in
{ mode = PENDING { mode = WAIT_FOR_KEY_RELEASE
, shiftChr = false , shiftChr = false
, trianglePressed = false , trianglePressed = false
, circlePressed = false , circlePressed = false
@@ -43,6 +45,33 @@ struct
} }
end end
fun onWaitForKeyRelease
( gamepadState: gamepad_state
, trianglePressed
, circlePressed
, crossPressed
, squarePressed
, actions
) =
if
trianglePressed orelse circlePressed orelse crossPressed
orelse squarePressed
then
(gamepadState, actions)
else
let
val newState =
{ mode = PENDING
, shiftChr = #shiftChr gamepadState
, trianglePressed = false
, circlePressed = false
, crossPressed = false
, squarePressed = false
}
in
(newState, actions)
end
fun onPendingMode fun onPendingMode
( state: gamepad_state ( state: gamepad_state
, trianglePressed , trianglePressed
@@ -125,28 +154,28 @@ struct
) = ) =
if trianglePressed then if trianglePressed then
let let
val newState = setToPendingAndUnshifted gamepadState val newState = releaseKeysAndUnshift gamepadState
val actions = IM.CHAR_EVENT #"a" :: actions val actions = IM.CHAR_EVENT #"a" :: actions
in in
(newState, actions) (newState, actions)
end end
else if circlePressed then else if circlePressed then
let let
val newState = setToPendingAndUnshifted gamepadState val newState = releaseKeysAndUnshift gamepadState
val actions = IM.CHAR_EVENT #"b" :: actions val actions = IM.CHAR_EVENT #"b" :: actions
in in
(newState, actions) (newState, actions)
end end
else if crossPressed then else if crossPressed then
let let
val newState = setToPendingAndUnshifted gamepadState val newState = releaseKeysAndUnshift gamepadState
val actions = IM.CHAR_EVENT #"c" :: actions val actions = IM.CHAR_EVENT #"c" :: actions
in in
(newState, actions) (newState, actions)
end end
else if squarePressed then else if squarePressed then
let let
val newState = setToPendingAndUnshifted gamepadState val newState = releaseKeysAndUnshift gamepadState
val actions = IM.CHAR_EVENT #"d" :: actions val actions = IM.CHAR_EVENT #"d" :: actions
in in
(newState, actions) (newState, actions)
@@ -178,6 +207,15 @@ struct
, squarePressed , squarePressed
, actions , actions
) )
| WAIT_FOR_KEY_RELEASE =>
onWaitForKeyRelease
( gamepadState
, trianglePressed
, circlePressed
, crossPressed
, squarePressed
, actions
)
| TRIANGLE => | TRIANGLE =>
onTriangleMode onTriangleMode
( gamepadState ( gamepadState
@@ -208,7 +246,7 @@ struct
val crossPressed = Input.isCrossButtonPressed () <> 0 val crossPressed = Input.isCrossButtonPressed () <> 0
val squarePressed = Input.isSquareButtonPressed () <> 0 val squarePressed = Input.isSquareButtonPressed () <> 0
val l1Pressed = Input.isL1ButtonPressed () <> 0 val l1Pressed = Input.isL1ButtonPressed () <> 0
val r1Pressed = Input.isL1ButtonPressed () <> 0 val r1Pressed = Input.isR1ButtonPressed () <> 0
in in
handleButtons handleButtons
( gamepadState ( gamepadState