From 40fff7729fce65f21f78a83c89634b08b42268b3 Mon Sep 17 00:00:00 2001 From: Humza Shahid Date: Fri, 21 Feb 2025 11:57:29 +0000 Subject: [PATCH] add 'newKeys' field (list of key codes pressed in frame) to frame input type, so we can change key bindings at runtime later --- fcore/frame-input-type.sml | 1 + fcore/level/player/player.sml | 13 +++---------- oms.mlb | 22 ---------------------- shell/input-state.sml | 29 ++++++++++++++++++----------- 4 files changed, 22 insertions(+), 43 deletions(-) diff --git a/fcore/frame-input-type.sml b/fcore/frame-input-type.sml index e850cc4..401273a 100644 --- a/fcore/frame-input-type.sml +++ b/fcore/frame-input-type.sml @@ -8,5 +8,6 @@ struct , attackHeld: bool , jumpHeld: bool , escapeHeld: bool + , newKeys: CoreKey.key_code list } end diff --git a/fcore/level/player/player.sml b/fcore/level/player/player.sml index 4c5a350..d2cc357 100644 --- a/fcore/level/player/player.sml +++ b/fcore/level/player/player.sml @@ -190,7 +190,7 @@ struct else helpGetMainAttackPatches (attackHeld, mainAttackPressed, charge, acc) - fun getInputPatches (player: player, input) = + fun getInputPatches (player: player, input: FrameInputType.t) = let val { x @@ -206,15 +206,8 @@ struct , ... } = player - val - { leftHeld - , rightHeld - , upHeld - , downHeld - , attackHeld - , jumpHeld - , escapeHeld - } = input + val {leftHeld, rightHeld, upHeld, downHeld, attackHeld, jumpHeld, ...} = + input val xAxis = getXAxis (leftHeld, rightHeld) val facing = getFacing (facing, xAxis) diff --git a/oms.mlb b/oms.mlb index 33a7f1d..52b8bc9 100644 --- a/oms.mlb +++ b/oms.mlb @@ -13,15 +13,6 @@ vendored/brolib-sml/src/gap_map.sml fcore/bin-search.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/level/wall.sml @@ -69,19 +60,6 @@ fcore/game-update.sml (* shell *) $(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/parse-controls.sml diff --git a/shell/input-state.sml b/shell/input-state.sml index abbf34e..67d6e92 100644 --- a/shell/input-state.sml +++ b/shell/input-state.sml @@ -21,19 +21,27 @@ struct , jumpHeld = ref false , attackHeld = ref false , escapeHeld = ref false + , newKeys = ref [] , width = ref (1920.0 : Real32.real) , height = ref (1080.0 : Real32.real) } fun getSnapshot () = - { leftHeld = !(#leftHeld state) - , rightHeld = !(#rightHeld state) - , upHeld = !(#upHeld state) - , downHeld = !(#downHeld state) - , attackHeld = !(#attackHeld state) - , jumpHeld = !(#jumpHeld state) - , escapeHeld = !(#escapeHeld state) - } + let + val input = + { leftHeld = !(#leftHeld state) + , rightHeld = !(#rightHeld state) + , upHeld = !(#upHeld state) + , downHeld = !(#downHeld 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. * If input is PRESS or REPEAT, then return true, or else return false. *) @@ -43,6 +51,7 @@ struct case GlfwKeyMap.codeFromKey key of SOME code => let + val () = #newKeys state := code :: !(#newKeys state) val {left, right, down, up, attack, jump, escape} = !keyMappings val action = actionToBool action in @@ -58,9 +67,7 @@ struct | NONE => () fun keyCallback (key, scancode, action, mods) = - let open Input - in if mods = 0 then handleKey (key, action) else () - end + if mods = 0 then handleKey (key, action) else () fun getWidth () = !(#width state)