a little refactoring (different CML loops have their own files now)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
18
imperative-shell/update-thread.sml
Normal file
18
imperative-shell/update-thread.sml
Normal 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
|
||||
Reference in New Issue
Block a user