diff --git a/ffi/glfw-export.c b/ffi/glfw-export.c index 316c81f..6028a27 100644 --- a/ffi/glfw-export.c +++ b/ffi/glfw-export.c @@ -35,6 +35,10 @@ bool windowShouldClose(GLFWwindow *window) { glfwWindowShouldClose(window); } +void pollEvents() { + glfwPollEvents(); +} + void waitEvents() { glfwWaitEvents(); } diff --git a/ffi/glfw-import.sml b/ffi/glfw-import.sml index d05b29b..caabbb6 100644 --- a/ffi/glfw-import.sml +++ b/ffi/glfw-import.sml @@ -24,6 +24,7 @@ struct val terminate = _import "terminate" public : unit -> unit; val makeContextCurrent = _import "makeContextCurrent" public : window -> unit; val windowShouldClose = _import "windowShouldClose" public : window -> bool; + val pollEvents = _import "pollEvents" public reentrant : unit -> unit; val waitEvents = _import "waitEvents" public reentrant : unit -> unit; val swapBuffers = _import "swapBuffers" public : window -> unit; val setClipboardString = _import "setClipboardString" public : window * string -> unit; diff --git a/ffi/glfw-input.c b/ffi/glfw-input.c index dd873d5..fe03462 100644 --- a/ffi/glfw-input.c +++ b/ffi/glfw-input.c @@ -6,6 +6,14 @@ int PRESS = GLFW_PRESS; int RELEASE = GLFW_RELEASE; +int KEY_S = GLFW_KEY_S; +int KEY_D = GLFW_KEY_D; +int KEY_F = GLFW_KEY_F; + +int KEY_J = GLFW_KEY_J; +int KEY_K = GLFW_KEY_K; +int KEY_L = GLFW_KEY_L; + int ARROW_UP = GLFW_KEY_UP; int ARROW_DOWN = GLFW_KEY_DOWN; int ARROW_LEFT = GLFW_KEY_LEFT; diff --git a/ffi/glfw-input.sml b/ffi/glfw-input.sml index 5429f1c..8a96e78 100644 --- a/ffi/glfw-input.sml +++ b/ffi/glfw-input.sml @@ -27,6 +27,30 @@ struct _symbol "ARROW_RIGHT" public : ( unit -> int ) * ( int -> unit ); val ARROW_RIGHT = ARROW_RIGHT () + val (KEY_S, _) = + _symbol "KEY_S" public : ( unit -> int ) * ( int -> unit ); + val KEY_S = KEY_S () + + val (KEY_D, _) = + _symbol "KEY_D" public : ( unit -> int ) * ( int -> unit ); + val KEY_D = KEY_D () + + val (KEY_F, _) = + _symbol "KEY_F" public : ( unit -> int ) * ( int -> unit ); + val KEY_F = KEY_F () + + val (KEY_J, _) = + _symbol "KEY_J" public : ( unit -> int ) * ( int -> unit ); + val KEY_J = KEY_J () + + val (KEY_K, _) = + _symbol "KEY_K" public : ( unit -> int ) * ( int -> unit ); + val KEY_K = KEY_K () + + val (KEY_L, _) = + _symbol "KEY_L" public : ( unit -> int ) * ( int -> unit ); + val KEY_L = KEY_L () + val exportKeyCallback = _export "mltonKeyCallback" public : (int * int * int * int -> unit) -> unit; val setKeyCallback = diff --git a/shell/gl-draw.sml b/shell/gl-draw.sml index 0c36191..88fe137 100644 --- a/shell/gl-draw.sml +++ b/shell/gl-draw.sml @@ -173,7 +173,7 @@ struct val _ = draw shellState val _ = Glfw.swapBuffers window - val _ = Glfw.waitEvents () + val _ = Glfw.pollEvents () in helpLoop (shellState, game) end diff --git a/shell/input-state.sml b/shell/input-state.sml index aea37c6..ce62622 100644 --- a/shell/input-state.sml +++ b/shell/input-state.sml @@ -29,19 +29,19 @@ struct open Input fun handleKey (key, action) = - if key = ARROW_UP then + if key = KEY_K then if action = PRESS then (#upHeld state) := true else if action = RELEASE then (#upHeld state) := false else () - else if key = ARROW_DOWN then + else if key = KEY_D then if action = PRESS then (#downHeld state) := true else if action = RELEASE then (#downHeld state) := false else () - else if key = ARROW_LEFT then + else if key = KEY_S then if action = PRESS then (#leftHeld state) := true else if action = RELEASE then (#leftHeld state) := false else () - else if key = ARROW_RIGHT then + else if key = KEY_F then if action = PRESS then (#rightHeld state) := true else if action = RELEASE then (#rightHeld state) := false else ()