add 'newKeys' field (list of key codes pressed in frame) to frame input type, so we can change key bindings at runtime later

This commit is contained in:
2025-02-21 11:57:29 +00:00
parent 603d6fa139
commit 40fff7729f
4 changed files with 22 additions and 43 deletions

View File

@@ -8,5 +8,6 @@ struct
, attackHeld: bool , attackHeld: bool
, jumpHeld: bool , jumpHeld: bool
, escapeHeld: bool , escapeHeld: bool
, newKeys: CoreKey.key_code list
} }
end end

View File

@@ -190,7 +190,7 @@ struct
else else
helpGetMainAttackPatches (attackHeld, mainAttackPressed, charge, acc) helpGetMainAttackPatches (attackHeld, mainAttackPressed, charge, acc)
fun getInputPatches (player: player, input) = fun getInputPatches (player: player, input: FrameInputType.t) =
let let
val val
{ x { x
@@ -206,15 +206,8 @@ struct
, ... , ...
} = player } = player
val val {leftHeld, rightHeld, upHeld, downHeld, attackHeld, jumpHeld, ...} =
{ leftHeld input
, rightHeld
, upHeld
, downHeld
, attackHeld
, jumpHeld
, escapeHeld
} = input
val xAxis = getXAxis (leftHeld, rightHeld) val xAxis = getXAxis (leftHeld, rightHeld)
val facing = getFacing (facing, xAxis) val facing = getFacing (facing, xAxis)

22
oms.mlb
View File

@@ -13,15 +13,6 @@ vendored/brolib-sml/src/gap_map.sml
fcore/bin-search.sml fcore/bin-search.sml
fcore/bin-vec.sml fcore/bin-vec.sml
ann
"allowVectorExps true"
in
vendored/cozette-sml/fonts/cozette-ascii.mlb
fcore/block.sml
fcore/level/player/player-sprite.sml
fcore/field.sml
fcore/level/chain-edge.sml
end
fcore/make-text-vec.sml fcore/make-text-vec.sml
fcore/level/wall.sml fcore/level/wall.sml
@@ -69,19 +60,6 @@ fcore/game-update.sml
(* shell *) (* shell *)
$(SML_LIB)/basis/mlton.mlb $(SML_LIB)/basis/mlton.mlb
ann
"allowFFI true"
in
ffi/gles3-import.sml
ffi/glfw-import.sml
ffi/glfw-input.sml
end
ann
"allowVectorExps true"
in
shell/glfw-key-map.sml
end
shell/input-state.sml shell/input-state.sml
shell/parse-controls.sml shell/parse-controls.sml

View File

@@ -21,19 +21,27 @@ struct
, jumpHeld = ref false , jumpHeld = ref false
, attackHeld = ref false , attackHeld = ref false
, escapeHeld = ref false , escapeHeld = ref false
, newKeys = ref []
, width = ref (1920.0 : Real32.real) , width = ref (1920.0 : Real32.real)
, height = ref (1080.0 : Real32.real) , height = ref (1080.0 : Real32.real)
} }
fun getSnapshot () = fun getSnapshot () =
{ leftHeld = !(#leftHeld state) let
, rightHeld = !(#rightHeld state) val input =
, upHeld = !(#upHeld state) { leftHeld = !(#leftHeld state)
, downHeld = !(#downHeld state) , rightHeld = !(#rightHeld state)
, attackHeld = !(#attackHeld state) , upHeld = !(#upHeld state)
, jumpHeld = !(#jumpHeld state) , downHeld = !(#downHeld state)
, escapeHeld = !(#escapeHeld state) , attackHeld = !(#attackHeld state)
} , jumpHeld = !(#jumpHeld state)
, escapeHeld = !(#escapeHeld state)
, newKeys = !(#newKeys state)
}
val () = #newKeys state := []
in
input
end
(* there are three action states reported by OS: PRESS, REPEAT and RELEASE. (* there are three action states reported by OS: PRESS, REPEAT and RELEASE.
* If input is PRESS or REPEAT, then return true, or else return false. *) * If input is PRESS or REPEAT, then return true, or else return false. *)
@@ -43,6 +51,7 @@ struct
case GlfwKeyMap.codeFromKey key of case GlfwKeyMap.codeFromKey key of
SOME code => SOME code =>
let let
val () = #newKeys state := code :: !(#newKeys state)
val {left, right, down, up, attack, jump, escape} = !keyMappings val {left, right, down, up, attack, jump, escape} = !keyMappings
val action = actionToBool action val action = actionToBool action
in in
@@ -58,9 +67,7 @@ struct
| NONE => () | NONE => ()
fun keyCallback (key, scancode, action, mods) = fun keyCallback (key, scancode, action, mods) =
let open Input if mods = 0 then handleKey (key, action) else ()
in if mods = 0 then handleKey (key, action) else ()
end
fun getWidth () = fun getWidth () =
!(#width state) !(#width state)