progrfess scaffolding rgfw (next: consume events and add callbacks for events)

This commit is contained in:
2026-01-23 10:55:43 +00:00
parent df20641af1
commit b4573441fb
6 changed files with 36 additions and 31 deletions

View File

@@ -37,20 +37,6 @@ struct
fun consumeEvents (drawState, window) =
consumeEventsLoop (0, DrawMailbox.getMessagesAndClear (), drawState, window)
fun updateLoop (pos, msgVec, app) =
if pos = Vector.length msgVec then
app
else
let
val msg = Vector.sub (msgVec, pos)
val app = Updater.update (app, msg)
in
updateLoop (pos + 1, msgVec, app)
end
fun update app =
updateLoop (0, InputMailbox.getMessagesAndClear (), app)
fun helpLoop (app, drawState, window, gamepad) =
case Glfw.windowShouldClose window of
false =>
@@ -62,10 +48,10 @@ struct
(* one update reacting to gamepad events *)
val (gamepad, actions) = GlfwGamepad.query gamepad
val app = updateLoop (0, Vector.fromList actions, app)
val app = Updater.updateLoop (0, Vector.fromList actions, app)
(* one update reacting to keyboard events *)
val app = update app
val app = Updater.update app
val _ = GlDraw.draw drawState
val _ = Glfw.swapBuffers window

View File

@@ -7,6 +7,9 @@ struct
let
val _ = Gles3.clearColor (0.89, 0.89, 0.89, 1.0)
val _ = Gles3.clear ()
val app = Updater.update app
val () = Rgfw.swapBuffers window
in
loop (window, app)

View File

@@ -11,7 +11,7 @@ struct
hd :: tl => let val () = sendMsg hd in sendMsgs tl end
| [] => ()
fun update (app: AppType.app_type, inputMsg) =
fun updateOne (app: AppType.app_type, inputMsg) =
let
val time = Time.now ()
@@ -30,4 +30,18 @@ struct
in
app
end
fun updateLoop (pos, msgVec, app) =
if pos = Vector.length msgVec then
app
else
let
val msg = Vector.sub (msgVec, pos)
val app = updateOne (app, msg)
in
updateLoop (pos + 1, msgVec, app)
end
fun update app =
updateLoop (0, InputMailbox.getMessagesAndClear (), app)
end