2024-08-28 20:42:52 +01:00
|
|
|
signature FILE_THREAD =
|
|
|
|
|
sig
|
2024-08-29 05:38:58 +01:00
|
|
|
val run: FileMessage.t Mailbox.mbox * InputMessage.t Mailbox.mbox -> unit
|
2024-08-28 20:42:52 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
structure FileThread :> FILE_THREAD =
|
|
|
|
|
struct
|
|
|
|
|
open FileMessage
|
2024-08-29 05:38:58 +01:00
|
|
|
open InputMessage
|
2024-08-28 20:42:52 +01:00
|
|
|
|
2025-07-06 15:06:00 +01:00
|
|
|
datatype parse_result = OK of unit | PARSE_ERROR
|
2024-08-29 04:39:23 +01:00
|
|
|
|
2024-12-29 20:18:29 +00:00
|
|
|
val structureName = "Green"
|
|
|
|
|
val filename = "green.dsc"
|
|
|
|
|
val exportFilename = "green.sml"
|
2024-08-30 02:22:02 +01:00
|
|
|
|
2024-08-30 03:46:05 +01:00
|
|
|
fun ndcToLerpX num =
|
|
|
|
|
let
|
|
|
|
|
val num = (num + 1.0) / 2.0
|
|
|
|
|
val num = Real32.toString num
|
2024-09-25 08:08:15 +01:00
|
|
|
val num =
|
2024-08-30 11:13:08 +01:00
|
|
|
(* Problem: It seems that Real32.toString may sometimes return a string
|
|
|
|
|
* that is recognised as an integer, like "1" instead of "1.0".
|
|
|
|
|
* If that happens, we just add a ".0" to the end
|
|
|
|
|
* so it's recognised as a real. *)
|
2024-09-25 08:08:15 +01:00
|
|
|
if String.isSubstring "." num then num
|
2024-08-30 11:13:08 +01:00
|
|
|
else num ^ ".0"
|
2024-08-30 03:46:05 +01:00
|
|
|
in
|
2024-09-25 08:08:15 +01:00
|
|
|
" (((startX * (1.0 - " ^ num ^ ")) + (endX * " ^ num
|
|
|
|
|
^ ")) / windowWidth) - 1.0"
|
2024-08-30 03:46:05 +01:00
|
|
|
end
|
2024-08-30 02:22:02 +01:00
|
|
|
|
2024-08-30 03:46:05 +01:00
|
|
|
fun ndcToLerpY num =
|
2024-08-30 02:22:02 +01:00
|
|
|
let
|
|
|
|
|
val num = (num + 1.0) / 2.0
|
|
|
|
|
val num = Real32.toString num
|
2024-09-25 08:08:15 +01:00
|
|
|
val num = if String.isSubstring "." num then num else num ^ ".0"
|
2024-08-30 02:22:02 +01:00
|
|
|
in
|
2024-09-25 08:08:15 +01:00
|
|
|
" (((startY * (1.0 - " ^ num ^ ")) + (endY * " ^ num
|
|
|
|
|
^ ")) / windowHeight) - 1.0"
|
2024-08-30 02:22:02 +01:00
|
|
|
end
|
|
|
|
|
|
2024-12-29 20:18:29 +00:00
|
|
|
fun colToString col =
|
|
|
|
|
let val col = Real32.toString col
|
|
|
|
|
in if String.isSubstring "." col then col else col ^ ".0"
|
|
|
|
|
end
|
|
|
|
|
|
2025-07-06 15:06:00 +01:00
|
|
|
fun exportSquares squares = ()
|
2024-08-30 02:22:02 +01:00
|
|
|
|
2025-07-06 15:06:00 +01:00
|
|
|
fun parse (io, acc) = ()
|
2024-08-30 02:22:02 +01:00
|
|
|
|
2025-07-06 15:06:00 +01:00
|
|
|
fun loadSquares (path, inputMailbox) = ()
|
2024-08-30 02:22:02 +01:00
|
|
|
|
2025-07-06 15:06:00 +01:00
|
|
|
fun saveSquares squares = ()
|
2024-08-29 00:05:30 +01:00
|
|
|
|
2024-09-29 22:26:07 +01:00
|
|
|
fun getDirList (dir, acc, rootPath) =
|
2024-09-25 08:08:15 +01:00
|
|
|
case OS.FileSys.readDir dir of
|
|
|
|
|
SOME path =>
|
2024-09-29 22:26:07 +01:00
|
|
|
let
|
|
|
|
|
val folderPath = String.concat [rootPath, "/", path]
|
|
|
|
|
in
|
|
|
|
|
if OS.FileSys.isDir folderPath then
|
|
|
|
|
getDirList (dir, AppType.IS_FOLDER path :: acc, rootPath)
|
|
|
|
|
else if OS.FileSys.isLink folderPath then
|
|
|
|
|
getDirList (dir, acc, rootPath)
|
|
|
|
|
else
|
|
|
|
|
getDirList (dir, AppType.IS_FILE path :: acc, rootPath)
|
|
|
|
|
end
|
2024-09-25 08:08:15 +01:00
|
|
|
| NONE => let val acc = List.rev acc in Vector.fromList acc end
|
|
|
|
|
|
|
|
|
|
fun loadFiles (path, inputMailbox) =
|
|
|
|
|
let
|
|
|
|
|
val path = if String.size path = 0 then OS.FileSys.getDir () else path
|
|
|
|
|
val dir = OS.FileSys.openDir path
|
2024-09-29 22:26:07 +01:00
|
|
|
val dirList = getDirList (dir, [], path)
|
2024-09-25 08:08:15 +01:00
|
|
|
val _ = OS.FileSys.closeDir dir
|
2024-09-27 10:06:21 +01:00
|
|
|
val inputMsg = FILE_BROWSER_AND_PATH {fileBrowser = dirList, path = path}
|
2024-09-25 08:08:15 +01:00
|
|
|
in
|
2024-09-27 10:06:21 +01:00
|
|
|
Mailbox.send (inputMailbox, inputMsg)
|
2024-09-25 08:08:15 +01:00
|
|
|
end
|
|
|
|
|
|
2024-09-29 22:26:07 +01:00
|
|
|
fun selectPath (path, inputMailbox) =
|
|
|
|
|
if OS.FileSys.isDir path then loadFiles (path, inputMailbox)
|
2025-07-06 15:06:00 +01:00
|
|
|
else loadSquares (path, inputMailbox)
|
2024-09-29 22:26:07 +01:00
|
|
|
|
2024-08-29 05:38:58 +01:00
|
|
|
fun run (fileMailbox, inputMailbox) =
|
2024-08-28 20:42:52 +01:00
|
|
|
let
|
|
|
|
|
val _ =
|
|
|
|
|
case Mailbox.recv fileMailbox of
|
2025-07-06 15:06:00 +01:00
|
|
|
SAVE_SQUARES triangles => saveSquares triangles
|
|
|
|
|
| LOAD_SQUARES => loadSquares (filename, inputMailbox)
|
|
|
|
|
| EXPORT_SQUARES triangles => exportSquares triangles
|
2024-09-25 08:08:15 +01:00
|
|
|
| LOAD_FILES path => loadFiles (path, inputMailbox)
|
2024-09-29 22:26:07 +01:00
|
|
|
| SELECT_PATH path => selectPath (path, inputMailbox)
|
2024-08-28 20:42:52 +01:00
|
|
|
in
|
2024-08-29 05:38:58 +01:00
|
|
|
run (fileMailbox, inputMailbox)
|
2024-08-28 20:42:52 +01:00
|
|
|
end
|
|
|
|
|
end
|