2024-07-31 10:03:30 +01:00
|
|
|
structure EventLoop =
|
|
|
|
|
struct
|
|
|
|
|
open CML
|
2024-07-31 13:32:22 +01:00
|
|
|
open DrawMessage
|
2024-07-31 10:03:30 +01:00
|
|
|
|
2024-07-31 12:00:07 +01:00
|
|
|
local
|
2024-08-08 21:58:50 +01:00
|
|
|
fun loop (inputMailbox, drawMailbox, model) =
|
2024-07-31 12:30:12 +01:00
|
|
|
let
|
|
|
|
|
val inputMsg = Mailbox.recv inputMailbox
|
2024-08-08 21:58:50 +01:00
|
|
|
val (model, drawMsg) = AppUpdate.update (model, inputMsg)
|
2024-07-31 12:30:12 +01:00
|
|
|
val _ = Mailbox.send (drawMailbox, drawMsg)
|
|
|
|
|
in
|
2024-08-08 21:58:50 +01:00
|
|
|
loop (inputMailbox, drawMailbox, model)
|
2024-07-31 12:30:12 +01:00
|
|
|
end
|
2024-07-31 12:00:07 +01:00
|
|
|
in
|
2024-08-03 06:05:26 +01:00
|
|
|
fun update (inputMailbox, drawMailbox, initial) =
|
2024-08-08 21:58:50 +01:00
|
|
|
loop (inputMailbox, drawMailbox, initial)
|
2024-07-31 12:00:07 +01:00
|
|
|
end
|
2024-07-31 10:03:30 +01:00
|
|
|
|
2024-07-31 12:30:12 +01:00
|
|
|
fun draw
|
2024-07-31 22:25:15 +01:00
|
|
|
( drawMailbox
|
|
|
|
|
, window
|
|
|
|
|
, graphDrawObject
|
2024-08-03 04:40:53 +01:00
|
|
|
, drawGraphLength
|
2024-08-14 21:24:46 +01:00
|
|
|
, dotDrawObject
|
|
|
|
|
, dotDrawLength
|
2024-07-31 22:25:15 +01:00
|
|
|
, triangleDrawObject
|
|
|
|
|
, triangleDrawLength
|
|
|
|
|
) =
|
2024-07-31 10:03:30 +01:00
|
|
|
if not (Glfw.windowShouldClose window) then
|
2024-07-31 13:32:22 +01:00
|
|
|
case Mailbox.recvPoll drawMailbox of
|
|
|
|
|
NONE =>
|
|
|
|
|
let
|
|
|
|
|
val _ = Gles3.clearColor (1.0, 1.0, 1.0, 1.0)
|
|
|
|
|
val _ = Gles3.clear ()
|
2024-07-31 10:03:30 +01:00
|
|
|
|
2024-08-03 04:40:53 +01:00
|
|
|
val _ = AppDraw.drawGraphLines (graphDrawObject, drawGraphLength)
|
2024-08-01 21:39:09 +01:00
|
|
|
val _ =
|
|
|
|
|
AppDraw.drawTriangles (triangleDrawObject, triangleDrawLength)
|
2024-08-14 21:24:46 +01:00
|
|
|
val _ = AppDraw.drawDot (dotDrawObject, dotDrawLength)
|
2024-07-31 10:03:30 +01:00
|
|
|
|
2024-07-31 13:32:22 +01:00
|
|
|
val _ = Glfw.swapBuffers window
|
2024-08-14 02:00:07 +01:00
|
|
|
val _ = Glfw.pollEvents ()
|
2024-07-31 13:32:22 +01:00
|
|
|
in
|
|
|
|
|
draw
|
|
|
|
|
( drawMailbox
|
|
|
|
|
, window
|
|
|
|
|
, graphDrawObject
|
2024-08-03 04:40:53 +01:00
|
|
|
, drawGraphLength
|
2024-08-14 21:24:46 +01:00
|
|
|
, dotDrawObject
|
|
|
|
|
, dotDrawLength
|
2024-07-31 22:25:15 +01:00
|
|
|
, triangleDrawObject
|
|
|
|
|
, triangleDrawLength
|
2024-07-31 13:32:22 +01:00
|
|
|
)
|
|
|
|
|
end
|
|
|
|
|
| SOME drawMsg =>
|
|
|
|
|
(case drawMsg of
|
2024-08-14 21:24:46 +01:00
|
|
|
DRAW_DOT vec =>
|
2024-07-31 13:32:22 +01:00
|
|
|
let
|
2024-08-14 21:24:46 +01:00
|
|
|
val _ = AppDraw.uploadDotVector (dotDrawObject, vec)
|
|
|
|
|
val dotDrawLength = Vector.length vec div 5
|
2024-07-31 13:32:22 +01:00
|
|
|
in
|
|
|
|
|
draw
|
|
|
|
|
( drawMailbox
|
|
|
|
|
, window
|
|
|
|
|
, graphDrawObject
|
2024-08-03 04:40:53 +01:00
|
|
|
, drawGraphLength
|
2024-08-14 21:24:46 +01:00
|
|
|
, dotDrawObject
|
|
|
|
|
, dotDrawLength
|
2024-07-31 22:25:15 +01:00
|
|
|
, triangleDrawObject
|
|
|
|
|
, triangleDrawLength
|
|
|
|
|
)
|
|
|
|
|
end
|
2024-08-14 21:24:46 +01:00
|
|
|
| DRAW_TRIANGLES_AND_RESET_DOTS triangleVec =>
|
2024-07-31 22:25:15 +01:00
|
|
|
let
|
2024-08-01 21:39:09 +01:00
|
|
|
val _ =
|
|
|
|
|
AppDraw.uploadTrianglesVector
|
|
|
|
|
(triangleDrawObject, triangleVec)
|
2024-07-31 22:25:15 +01:00
|
|
|
val triangleDrawLength = Vector.length triangleVec div 2
|
2024-08-14 21:24:46 +01:00
|
|
|
(* dots are reset by setting dotDrawLength to 0 *)
|
2024-07-31 22:25:15 +01:00
|
|
|
in
|
|
|
|
|
draw
|
|
|
|
|
( drawMailbox
|
|
|
|
|
, window
|
|
|
|
|
, graphDrawObject
|
2024-08-03 04:40:53 +01:00
|
|
|
, drawGraphLength
|
2024-08-14 21:24:46 +01:00
|
|
|
, dotDrawObject
|
2024-08-03 04:40:53 +01:00
|
|
|
, 0
|
|
|
|
|
, triangleDrawObject
|
|
|
|
|
, triangleDrawLength
|
|
|
|
|
)
|
|
|
|
|
end
|
2024-08-14 21:24:46 +01:00
|
|
|
| DRAW_TRIANGLES_AND_DOTS {triangles = triangleVec, dots = dotsVec} =>
|
2024-08-08 21:35:48 +01:00
|
|
|
let
|
|
|
|
|
val _ =
|
|
|
|
|
AppDraw.uploadTrianglesVector
|
|
|
|
|
(triangleDrawObject, triangleVec)
|
|
|
|
|
val triangleDrawLength = Vector.length triangleVec div 2
|
|
|
|
|
|
2024-08-14 21:24:46 +01:00
|
|
|
val _ = AppDraw.uploadDotVector (dotDrawObject, dotsVec)
|
|
|
|
|
val dotDrawLength = Vector.length dotsVec div 5
|
2024-08-08 21:35:48 +01:00
|
|
|
in
|
|
|
|
|
draw
|
|
|
|
|
( drawMailbox
|
|
|
|
|
, window
|
|
|
|
|
, graphDrawObject
|
|
|
|
|
, drawGraphLength
|
2024-08-14 21:24:46 +01:00
|
|
|
, dotDrawObject
|
|
|
|
|
, dotDrawLength
|
2024-08-08 21:35:48 +01:00
|
|
|
, triangleDrawObject
|
|
|
|
|
, triangleDrawLength
|
|
|
|
|
)
|
|
|
|
|
end
|
2024-08-14 21:24:46 +01:00
|
|
|
| CLEAR_DOTS =>
|
2024-08-08 21:35:48 +01:00
|
|
|
let
|
2024-08-14 21:24:46 +01:00
|
|
|
val dotDrawLength = 0
|
2024-08-08 21:35:48 +01:00
|
|
|
in
|
|
|
|
|
draw
|
|
|
|
|
( drawMailbox
|
|
|
|
|
, window
|
|
|
|
|
, graphDrawObject
|
|
|
|
|
, drawGraphLength
|
2024-08-14 21:24:46 +01:00
|
|
|
, dotDrawObject
|
|
|
|
|
, dotDrawLength
|
2024-08-08 21:35:48 +01:00
|
|
|
, triangleDrawObject
|
|
|
|
|
, triangleDrawLength
|
|
|
|
|
)
|
|
|
|
|
end
|
2024-08-14 21:24:46 +01:00
|
|
|
| RESIZE_TRIANGLES_DOTS_AND_GRAPH {triangles, graphLines} =>
|
2024-08-03 04:40:53 +01:00
|
|
|
let
|
|
|
|
|
val _ =
|
2024-08-08 05:56:20 +01:00
|
|
|
AppDraw.uploadTrianglesVector (triangleDrawObject, triangles)
|
2024-08-03 04:40:53 +01:00
|
|
|
val triangleDrawLength = Vector.length triangles div 2
|
2024-08-08 05:56:20 +01:00
|
|
|
val _ = AppDraw.uploadGraphLines (graphDrawObject, graphLines)
|
|
|
|
|
val drawGraphLength = Vector.length graphLines div 2
|
2024-08-14 21:24:46 +01:00
|
|
|
(* to do: upload dots *)
|
2024-08-03 04:40:53 +01:00
|
|
|
in
|
|
|
|
|
draw
|
|
|
|
|
( drawMailbox
|
|
|
|
|
, window
|
|
|
|
|
, graphDrawObject
|
|
|
|
|
, drawGraphLength
|
2024-08-14 21:24:46 +01:00
|
|
|
, dotDrawObject
|
2024-07-31 22:25:15 +01:00
|
|
|
, 0
|
|
|
|
|
, triangleDrawObject
|
|
|
|
|
, triangleDrawLength
|
2024-07-31 13:32:22 +01:00
|
|
|
)
|
2024-07-31 14:52:12 +01:00
|
|
|
end
|
2024-08-14 02:35:44 +01:00
|
|
|
| DRAW_GRAPH graphLines =>
|
|
|
|
|
let
|
|
|
|
|
val _ = AppDraw.uploadGraphLines (graphDrawObject, graphLines)
|
|
|
|
|
val drawGraphLength = Vector.length graphLines div 2
|
|
|
|
|
in
|
|
|
|
|
draw
|
|
|
|
|
( drawMailbox
|
|
|
|
|
, window
|
|
|
|
|
, graphDrawObject
|
|
|
|
|
, drawGraphLength
|
2024-08-14 21:24:46 +01:00
|
|
|
, dotDrawObject
|
|
|
|
|
, dotDrawLength
|
2024-08-14 02:35:44 +01:00
|
|
|
, triangleDrawObject
|
|
|
|
|
, triangleDrawLength
|
|
|
|
|
)
|
|
|
|
|
end
|
2024-07-31 14:52:12 +01:00
|
|
|
| NO_DRAW =>
|
|
|
|
|
draw
|
|
|
|
|
( drawMailbox
|
|
|
|
|
, window
|
|
|
|
|
, graphDrawObject
|
2024-08-03 04:40:53 +01:00
|
|
|
, drawGraphLength
|
2024-08-14 21:24:46 +01:00
|
|
|
, dotDrawObject
|
|
|
|
|
, dotDrawLength
|
2024-07-31 22:25:15 +01:00
|
|
|
, triangleDrawObject
|
|
|
|
|
, triangleDrawLength
|
2024-07-31 14:52:12 +01:00
|
|
|
))
|
2024-07-31 10:03:30 +01:00
|
|
|
else
|
|
|
|
|
Glfw.terminate ()
|
|
|
|
|
end
|