2024-10-06 09:32:56 +01:00
|
|
|
structure UpdateThread =
|
|
|
|
|
struct
|
|
|
|
|
open CML
|
|
|
|
|
open MailboxType
|
2025-08-04 09:29:37 +01:00
|
|
|
open InputMsg
|
2024-10-06 09:32:56 +01:00
|
|
|
|
|
|
|
|
fun sendMsg (msg, drawMailbox) =
|
|
|
|
|
case msg of DRAW msg => Mailbox.send (drawMailbox, msg)
|
|
|
|
|
|
|
|
|
|
fun sendMsgs (msgList, drawMailbox) =
|
|
|
|
|
case msgList of
|
|
|
|
|
hd :: tl =>
|
|
|
|
|
let val _ = sendMsg (hd, drawMailbox)
|
|
|
|
|
in sendMsgs (tl, drawMailbox)
|
|
|
|
|
end
|
|
|
|
|
| [] => ()
|
|
|
|
|
|
|
|
|
|
fun loop (app: AppType.app_type, inputMailbox, drawMailbox) =
|
|
|
|
|
let
|
|
|
|
|
val inputMsg = Mailbox.recv inputMailbox
|
2025-08-04 09:29:37 +01:00
|
|
|
val () =
|
|
|
|
|
(* if a certain CHAR_EVENT is sent,
|
|
|
|
|
* we trigger an exception and log the command history.
|
|
|
|
|
* This is helpful for manually triggering logs when,
|
|
|
|
|
* for example, we encounter a bug and would like to see
|
|
|
|
|
* the history of events that caused it. *)
|
|
|
|
|
case inputMsg of
|
|
|
|
|
CHAR_EVENT #"~" => ExceptionLogger.log (Fail "")
|
|
|
|
|
| _ => ()
|
|
|
|
|
|
2025-08-04 09:03:47 +01:00
|
|
|
val () = ExceptionLogger.addCommand inputMsg
|
2025-08-04 06:23:52 +01:00
|
|
|
|
2025-08-06 00:16:50 +01:00
|
|
|
val app = AppUpdate.update (app, inputMsg)
|
|
|
|
|
handle e => ExceptionLogger.log e
|
2025-08-03 13:14:28 +01:00
|
|
|
|
2024-12-17 10:40:06 +00:00
|
|
|
val () = sendMsgs (#msgs app, drawMailbox)
|
2024-10-06 09:32:56 +01:00
|
|
|
in
|
|
|
|
|
loop (app, inputMailbox, drawMailbox)
|
|
|
|
|
end
|
|
|
|
|
end
|