a little refactoring (different CML loops have their own files now)

This commit is contained in:
2024-08-28 19:34:47 +01:00
parent 0a4de92862
commit fb9202248c
5 changed files with 34 additions and 27 deletions

BIN
dotscape

Binary file not shown.

View File

@@ -42,5 +42,8 @@ in
end
imperative-shell/input-callbacks.sml
imperative-shell/event-loop.sml
imperative-shell/update-thread.sml
imperative-shell/draw-thread.sml
imperative-shell/shell.sml

View File

@@ -1,23 +1,9 @@
structure EventLoop =
structure DrawThread =
struct
open CML
open DrawMessage
local
fun loop (inputMailbox, drawMailbox, model) =
let
val inputMsg = Mailbox.recv inputMailbox
val (model, drawMsg) = AppUpdate.update (model, inputMsg)
val _ = Mailbox.send (drawMailbox, drawMsg)
in
loop (inputMailbox, drawMailbox, model)
end
in
fun update (inputMailbox, drawMailbox, initial) =
loop (inputMailbox, drawMailbox, initial)
end
fun draw
fun run
( drawMailbox
, window
, graphDrawObject
@@ -42,7 +28,7 @@ struct
val _ = Glfw.swapBuffers window
val _ = Glfw.pollEvents ()
in
draw
run
( drawMailbox
, window
, graphDrawObject
@@ -60,7 +46,7 @@ struct
val _ = AppDraw.uploadDotVector (dotDrawObject, vec)
val dotDrawLength = Vector.length vec div 5
in
draw
run
( drawMailbox
, window
, graphDrawObject
@@ -79,7 +65,7 @@ struct
val triangleDrawLength = Vector.length triangleVec div 2
(* dots are reset by setting dotDrawLength to 0 *)
in
draw
run
( drawMailbox
, window
, graphDrawObject
@@ -100,7 +86,7 @@ struct
val _ = AppDraw.uploadDotVector (dotDrawObject, dotsVec)
val dotDrawLength = Vector.length dotsVec div 5
in
draw
run
( drawMailbox
, window
, graphDrawObject
@@ -115,7 +101,7 @@ struct
let
val dotDrawLength = 0
in
draw
run
( drawMailbox
, window
, graphDrawObject
@@ -138,7 +124,7 @@ struct
val _ = AppDraw.uploadDotVector (dotDrawObject, dots)
val dotDrawLength = Vector.length dots div 5
in
draw
run
( drawMailbox
, window
, graphDrawObject
@@ -154,7 +140,7 @@ struct
val _ = AppDraw.uploadGraphLines (graphDrawObject, graphLines)
val drawGraphLength = Vector.length graphLines div 2
in
draw
run
( drawMailbox
, window
, graphDrawObject
@@ -166,7 +152,7 @@ struct
)
end
| NO_DRAW =>
draw
run
( drawMailbox
, window
, graphDrawObject

View File

@@ -32,9 +32,9 @@ struct
val _ = CML.spawn (fn () =>
InputCallbacks.registerCallbacks (window, inputMailbox))
val _ = CML.spawn (fn () =>
EventLoop.update (inputMailbox, drawMailbox, initialModel))
UpdateThread.run (inputMailbox, drawMailbox, initialModel))
val _ = CML.spawn (fn () =>
EventLoop.draw
DrawThread.run
( drawMailbox
, window
, graphDrawObject

View File

@@ -0,0 +1,18 @@
structure UpdateThread =
struct
open CML
local
fun loop (inputMailbox, drawMailbox, model) =
let
val inputMsg = Mailbox.recv inputMailbox
val (model, drawMsg) = AppUpdate.update (model, inputMsg)
val _ = Mailbox.send (drawMailbox, drawMsg)
in
loop (inputMailbox, drawMailbox, model)
end
in
fun run (inputMailbox, drawMailbox, initial) =
loop (inputMailbox, drawMailbox, initial)
end
end