Improve engine error handling, add unload call, reset atoms
This commit is contained in:
parent
ac7385c498
commit
5b6fd432de
@ -18,14 +18,19 @@
|
||||
(println e))))
|
||||
|
||||
(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)}}]
|
||||
(rl/set-trace-log-level! rl/log-warning)
|
||||
(rl/init-window! width height title)
|
||||
(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})
|
||||
(try
|
||||
(reset! game-state (init config))
|
||||
(catch Throwable t
|
||||
(println t)))
|
||||
(while (not (rl/window-should-close?))
|
||||
(if @last-error
|
||||
(Thread/sleep 50)
|
||||
@ -40,4 +45,12 @@
|
||||
(println t)
|
||||
(reset! last-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)))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user