2025-09-10 01:44:25 +01:00
|
|
|
structure Updater =
|
2024-10-06 09:32:56 +01:00
|
|
|
struct
|
|
|
|
|
open MailboxType
|
2025-08-04 09:29:37 +01:00
|
|
|
open InputMsg
|
2024-10-06 09:32:56 +01:00
|
|
|
|
2025-09-10 01:41:59 +01:00
|
|
|
fun sendMsg msg =
|
2025-10-17 23:08:16 +01:00
|
|
|
case msg of DRAW msg => DrawMailbox.append msg
|
2024-10-06 09:32:56 +01:00
|
|
|
|
2025-09-10 01:41:59 +01:00
|
|
|
fun sendMsgs msgList =
|
2024-10-06 09:32:56 +01:00
|
|
|
case msgList of
|
2025-09-10 01:41:59 +01:00
|
|
|
hd :: tl => let val () = sendMsg hd in sendMsgs tl end
|
2024-10-06 09:32:56 +01:00
|
|
|
| [] => ()
|
|
|
|
|
|
2026-01-23 10:55:43 +00:00
|
|
|
fun updateOne (app: AppType.app_type, inputMsg) =
|
2024-10-06 09:32:56 +01:00
|
|
|
let
|
2025-08-20 12:50:39 +01:00
|
|
|
val time = Time.now ()
|
2025-08-04 09:29:37 +01:00
|
|
|
|
2025-09-13 01:47:57 +01:00
|
|
|
val () =
|
|
|
|
|
case inputMsg of
|
|
|
|
|
CHAR_EVENT #"~" =>
|
|
|
|
|
ExceptionLogger.log (Fail "intentionally caused exception")
|
|
|
|
|
| _ => ()
|
|
|
|
|
|
2025-08-04 09:03:47 +01:00
|
|
|
val () = ExceptionLogger.addCommand inputMsg
|
2025-08-04 06:23:52 +01:00
|
|
|
|
2025-08-20 12:50:39 +01:00
|
|
|
val app = AppUpdate.update (app, inputMsg, time)
|
2025-08-06 00:16:50 +01:00
|
|
|
handle e => ExceptionLogger.log e
|
2025-08-03 13:14:28 +01:00
|
|
|
|
2025-09-10 01:41:59 +01:00
|
|
|
val () = sendMsgs (#msgs app)
|
2024-10-06 09:32:56 +01:00
|
|
|
in
|
2025-09-10 01:41:59 +01:00
|
|
|
app
|
2024-10-06 09:32:56 +01:00
|
|
|
end
|
2026-01-23 10:55:43 +00:00
|
|
|
|
|
|
|
|
fun updateLoop (pos, msgVec, app) =
|
|
|
|
|
if pos = Vector.length msgVec then
|
|
|
|
|
app
|
|
|
|
|
else
|
|
|
|
|
let
|
|
|
|
|
val msg = Vector.sub (msgVec, pos)
|
|
|
|
|
val app = updateOne (app, msg)
|
|
|
|
|
in
|
|
|
|
|
updateLoop (pos + 1, msgVec, app)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
fun update app =
|
|
|
|
|
updateLoop (0, InputMailbox.getMessagesAndClear (), app)
|
2024-10-06 09:32:56 +01:00
|
|
|
end
|