Improve engine error handling, add unload call, reset atoms

This commit is contained in:
Joseph Ferano 2026-08-16 19:38:26 +07:00
parent ac7385c498
commit 5b6fd432de

View File

@ -18,14 +18,19 @@
(println e)))) (println e))))
(defn run-game! (defn run-game!
[{:keys [title width height config-path init input update draw watch-fn] [{:keys [title width height config-path init input update draw unload watch-fn]
:or {title "Untitled" width 1200 height 900 watch-fn (constantly nil)}}] :or {title "Untitled" width 1200 height 900 watch-fn (constantly nil)}}]
(rl/set-trace-log-level! rl/log-warning) (rl/set-trace-log-level! rl/log-warning)
(rl/init-window! width height title) (rl/init-window! width height title)
(rl/set-target-fps! 60) (rl/set-target-fps! 60)
(let [config (edn/read-string (slurp config-path))] (let [config (if config-path
(edn/read-string (slurp config-path))
{})]
(reset! game-config {:config-path config-path :config config}) (reset! game-config {:config-path config-path :config config})
(reset! game-state (init config)) (try
(reset! game-state (init config))
(catch Throwable t
(println t)))
(while (not (rl/window-should-close?)) (while (not (rl/window-should-close?))
(if @last-error (if @last-error
(Thread/sleep 50) (Thread/sleep 50)
@ -40,4 +45,12 @@
(println t) (println t)
(reset! last-error t) (reset! last-error t)
(w/watch! (merge (watch-fn config @game-state) {:error t})))))))) (w/watch! (merge (watch-fn config @game-state) {:error t}))))))))
(rl/close-window!))) (try
(when unload
(unload @game-state))
(catch Throwable t
(println t)))
(rl/close-window!)
(reset! last-error nil)
(reset! game-state nil)
(reset! game-config nil)))