Files
sml-projects/imperative-shell/event-loop.sml

37 lines
1.1 KiB
Standard ML
Raw Normal View History

2024-07-31 10:03:30 +01:00
structure EventLoop =
struct
open CML
open InputMessage
2024-07-31 12:00:07 +01:00
local
fun loop (inputMailbox, drawMailbox, mouseX, mouseY, model) =
2024-07-31 10:03:30 +01:00
let
2024-07-31 12:00:07 +01:00
val inputMsg = Mailbox.recv inputMailbox
val (model, drawMsg, mouseX, mouseY) = AppUpdate.update (model, mouseX, mouseY, inputMsg)
val _ = Mailbox.send (drawMailbox, drawMsg)
2024-07-31 10:03:30 +01:00
in
2024-07-31 12:00:07 +01:00
loop (inputMailbox, drawMailbox, mouseX, mouseY, model)
2024-07-31 10:03:30 +01:00
end
2024-07-31 12:00:07 +01:00
in
fun update (inputMailbox, drawMailbox) =
loop (inputMailbox, drawMailbox, 0, 0, AppType.initial)
end
2024-07-31 10:03:30 +01:00
2024-07-31 12:27:11 +01:00
fun draw (drawMailbox, window, graphDrawObject, buttonDrawObject, buttonDrawLength) =
2024-07-31 10:03:30 +01:00
if not (Glfw.windowShouldClose window) then
let
val _ = Gles3.clearColor (1.0, 1.0, 1.0, 1.0)
val _ = Gles3.clear ()
val _ = AppDraw.drawGraphLines graphDrawObject
val _ = AppDraw.drawButton (buttonDrawObject, buttonDrawLength)
val _ = Glfw.pollEvents ()
val _ = Glfw.swapBuffers window
in
2024-07-31 12:27:11 +01:00
draw (drawMailbox, window, graphDrawObject, buttonDrawObject, buttonDrawLength)
2024-07-31 10:03:30 +01:00
end
else
Glfw.terminate ()
end