a little refactoring (different CML loops have their own files now)
This commit is contained in:
@@ -42,5 +42,8 @@ in
|
|||||||
end
|
end
|
||||||
|
|
||||||
imperative-shell/input-callbacks.sml
|
imperative-shell/input-callbacks.sml
|
||||||
imperative-shell/event-loop.sml
|
|
||||||
|
imperative-shell/update-thread.sml
|
||||||
|
imperative-shell/draw-thread.sml
|
||||||
|
|
||||||
imperative-shell/shell.sml
|
imperative-shell/shell.sml
|
||||||
|
|||||||
@@ -1,23 +1,9 @@
|
|||||||
structure EventLoop =
|
structure DrawThread =
|
||||||
struct
|
struct
|
||||||
open CML
|
open CML
|
||||||
open DrawMessage
|
open DrawMessage
|
||||||
|
|
||||||
local
|
fun run
|
||||||
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
|
|
||||||
( drawMailbox
|
( drawMailbox
|
||||||
, window
|
, window
|
||||||
, graphDrawObject
|
, graphDrawObject
|
||||||
@@ -42,7 +28,7 @@ struct
|
|||||||
val _ = Glfw.swapBuffers window
|
val _ = Glfw.swapBuffers window
|
||||||
val _ = Glfw.pollEvents ()
|
val _ = Glfw.pollEvents ()
|
||||||
in
|
in
|
||||||
draw
|
run
|
||||||
( drawMailbox
|
( drawMailbox
|
||||||
, window
|
, window
|
||||||
, graphDrawObject
|
, graphDrawObject
|
||||||
@@ -60,7 +46,7 @@ struct
|
|||||||
val _ = AppDraw.uploadDotVector (dotDrawObject, vec)
|
val _ = AppDraw.uploadDotVector (dotDrawObject, vec)
|
||||||
val dotDrawLength = Vector.length vec div 5
|
val dotDrawLength = Vector.length vec div 5
|
||||||
in
|
in
|
||||||
draw
|
run
|
||||||
( drawMailbox
|
( drawMailbox
|
||||||
, window
|
, window
|
||||||
, graphDrawObject
|
, graphDrawObject
|
||||||
@@ -79,7 +65,7 @@ struct
|
|||||||
val triangleDrawLength = Vector.length triangleVec div 2
|
val triangleDrawLength = Vector.length triangleVec div 2
|
||||||
(* dots are reset by setting dotDrawLength to 0 *)
|
(* dots are reset by setting dotDrawLength to 0 *)
|
||||||
in
|
in
|
||||||
draw
|
run
|
||||||
( drawMailbox
|
( drawMailbox
|
||||||
, window
|
, window
|
||||||
, graphDrawObject
|
, graphDrawObject
|
||||||
@@ -100,7 +86,7 @@ struct
|
|||||||
val _ = AppDraw.uploadDotVector (dotDrawObject, dotsVec)
|
val _ = AppDraw.uploadDotVector (dotDrawObject, dotsVec)
|
||||||
val dotDrawLength = Vector.length dotsVec div 5
|
val dotDrawLength = Vector.length dotsVec div 5
|
||||||
in
|
in
|
||||||
draw
|
run
|
||||||
( drawMailbox
|
( drawMailbox
|
||||||
, window
|
, window
|
||||||
, graphDrawObject
|
, graphDrawObject
|
||||||
@@ -115,7 +101,7 @@ struct
|
|||||||
let
|
let
|
||||||
val dotDrawLength = 0
|
val dotDrawLength = 0
|
||||||
in
|
in
|
||||||
draw
|
run
|
||||||
( drawMailbox
|
( drawMailbox
|
||||||
, window
|
, window
|
||||||
, graphDrawObject
|
, graphDrawObject
|
||||||
@@ -138,7 +124,7 @@ struct
|
|||||||
val _ = AppDraw.uploadDotVector (dotDrawObject, dots)
|
val _ = AppDraw.uploadDotVector (dotDrawObject, dots)
|
||||||
val dotDrawLength = Vector.length dots div 5
|
val dotDrawLength = Vector.length dots div 5
|
||||||
in
|
in
|
||||||
draw
|
run
|
||||||
( drawMailbox
|
( drawMailbox
|
||||||
, window
|
, window
|
||||||
, graphDrawObject
|
, graphDrawObject
|
||||||
@@ -154,7 +140,7 @@ struct
|
|||||||
val _ = AppDraw.uploadGraphLines (graphDrawObject, graphLines)
|
val _ = AppDraw.uploadGraphLines (graphDrawObject, graphLines)
|
||||||
val drawGraphLength = Vector.length graphLines div 2
|
val drawGraphLength = Vector.length graphLines div 2
|
||||||
in
|
in
|
||||||
draw
|
run
|
||||||
( drawMailbox
|
( drawMailbox
|
||||||
, window
|
, window
|
||||||
, graphDrawObject
|
, graphDrawObject
|
||||||
@@ -166,7 +152,7 @@ struct
|
|||||||
)
|
)
|
||||||
end
|
end
|
||||||
| NO_DRAW =>
|
| NO_DRAW =>
|
||||||
draw
|
run
|
||||||
( drawMailbox
|
( drawMailbox
|
||||||
, window
|
, window
|
||||||
, graphDrawObject
|
, graphDrawObject
|
||||||
@@ -32,9 +32,9 @@ struct
|
|||||||
val _ = CML.spawn (fn () =>
|
val _ = CML.spawn (fn () =>
|
||||||
InputCallbacks.registerCallbacks (window, inputMailbox))
|
InputCallbacks.registerCallbacks (window, inputMailbox))
|
||||||
val _ = CML.spawn (fn () =>
|
val _ = CML.spawn (fn () =>
|
||||||
EventLoop.update (inputMailbox, drawMailbox, initialModel))
|
UpdateThread.run (inputMailbox, drawMailbox, initialModel))
|
||||||
val _ = CML.spawn (fn () =>
|
val _ = CML.spawn (fn () =>
|
||||||
EventLoop.draw
|
DrawThread.run
|
||||||
( drawMailbox
|
( drawMailbox
|
||||||
, window
|
, window
|
||||||
, graphDrawObject
|
, 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