restructure a bit to make the GLFW-initialisation code its own separate structure/file, and so we can use shell.sml for running program in different ways

This commit is contained in:
2025-08-26 13:00:18 +01:00
parent 953eaefb88
commit 894cd50073
5 changed files with 68 additions and 61 deletions

BIN
dotscape

Binary file not shown.

View File

@@ -71,5 +71,6 @@ imperative-shell/input-callbacks.sml
imperative-shell/update-thread.sml
imperative-shell/file-thread.sml
imperative-shell/draw-thread.sml
imperative-shell/init-glfw.sml
imperative-shell/shell.sml

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,63 @@
structure InitGlfw =
struct
open CML
fun init () =
let
(* Set up GLFW. *)
val _ = Glfw.init ()
val _ = Glfw.windowHint (Glfw.CONTEXT_VERSION_MAJOR (), 3)
val _ = Glfw.windowHint (Glfw.DEPRECATED (), Glfw.FALSE ())
val _ = Glfw.windowHint (Glfw.SAMPLES (), 0)
val window =
Glfw.createWindow
(Constants.windowWidth, Constants.windowHeight, "Dotscape")
val _ = Glfw.makeContextCurrent window
val _ = Gles3.loadGlad ()
val initialModel = AppInit.fromWindowWidthAndHeight
( Constants.windowWidth
, Constants.windowHeight
, Constants.initialWidthClickPoints
, Constants.initialHeightClickPoints
)
val graphLines = GraphLines.generate initialModel
val graphDrawObject = AppDraw.initGraphLines ()
val _ = AppDraw.uploadGraphLines (graphDrawObject, graphLines)
val dotDrawObject = AppDraw.initDot ()
val squareDrawObject = AppDraw.initSquares ()
val modalTextDrawObject = AppDraw.initModalText ()
val inputMailbox = Mailbox.mailbox ()
val drawMailbox = Mailbox.mailbox ()
val fileMailbox = Mailbox.mailbox ()
val _ = InputCallbacks.registerCallbacks (window, inputMailbox)
val _ = CML.spawn (fn () =>
UpdateThread.run (inputMailbox, drawMailbox, fileMailbox, initialModel))
val _ = CML.spawn (fn () =>
DrawThread.run
( drawMailbox
, window
, graphDrawObject
, Vector.length graphLines div 2
, dotDrawObject
, 0
, squareDrawObject
, 0
, modalTextDrawObject
, 0
))
val _ = CML.spawn (fn () => FileThread.run (fileMailbox, inputMailbox))
in
()
end
fun main () = RunCML.doit (init, NONE)
end

View File

@@ -1,63 +1,6 @@
structure Shell =
struct
open CML
fun main () =
let
(* Set up GLFW. *)
val _ = Glfw.init ()
val _ = Glfw.windowHint (Glfw.CONTEXT_VERSION_MAJOR (), 3)
val _ = Glfw.windowHint (Glfw.DEPRECATED (), Glfw.FALSE ())
val _ = Glfw.windowHint (Glfw.SAMPLES (), 0)
val window =
Glfw.createWindow
(Constants.windowWidth, Constants.windowHeight, "Dotscape")
val _ = Glfw.makeContextCurrent window
val _ = Gles3.loadGlad ()
val initialModel = AppInit.fromWindowWidthAndHeight
( Constants.windowWidth
, Constants.windowHeight
, Constants.initialWidthClickPoints
, Constants.initialHeightClickPoints
)
val graphLines = GraphLines.generate initialModel
val graphDrawObject = AppDraw.initGraphLines ()
val _ = AppDraw.uploadGraphLines (graphDrawObject, graphLines)
val dotDrawObject = AppDraw.initDot ()
val squareDrawObject = AppDraw.initSquares ()
val modalTextDrawObject = AppDraw.initModalText ()
val inputMailbox = Mailbox.mailbox ()
val drawMailbox = Mailbox.mailbox ()
val fileMailbox = Mailbox.mailbox ()
val _ = InputCallbacks.registerCallbacks (window, inputMailbox)
val _ = CML.spawn (fn () =>
UpdateThread.run (inputMailbox, drawMailbox, fileMailbox, initialModel))
val _ = CML.spawn (fn () =>
DrawThread.run
( drawMailbox
, window
, graphDrawObject
, Vector.length graphLines div 2
, dotDrawObject
, 0
, squareDrawObject
, 0
, modalTextDrawObject
, 0
))
val _ = CML.spawn (fn () => FileThread.run (fileMailbox, inputMailbox))
in
()
end
fun main () = InitGlfw.main ()
end
val _ = RunCML.doit (Shell.main, NONE)
val _ = Shell.main ()