diff --git a/dotscape b/dotscape index 71ec9d3..ef0bc3d 100755 Binary files a/dotscape and b/dotscape differ diff --git a/dotscape.mlb b/dotscape.mlb index d389734..43b2e0a 100644 --- a/dotscape.mlb +++ b/dotscape.mlb @@ -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 diff --git a/imperative-shell/event-loop.sml b/imperative-shell/draw-thread.sml similarity index 89% rename from imperative-shell/event-loop.sml rename to imperative-shell/draw-thread.sml index 560611d..7a04a2f 100644 --- a/imperative-shell/event-loop.sml +++ b/imperative-shell/draw-thread.sml @@ -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 diff --git a/imperative-shell/shell.sml b/imperative-shell/shell.sml index 1e31145..f6fd18c 100644 --- a/imperative-shell/shell.sml +++ b/imperative-shell/shell.sml @@ -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 diff --git a/imperative-shell/update-thread.sml b/imperative-shell/update-thread.sml new file mode 100644 index 0000000..e86fd22 --- /dev/null +++ b/imperative-shell/update-thread.sml @@ -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