Don't draw an error, use watch system
This commit is contained in:
parent
02359b3799
commit
7834ff7356
@ -6,15 +6,10 @@
|
|||||||
|
|
||||||
(defonce ^:private last-error (atom nil))
|
(defonce ^:private last-error (atom nil))
|
||||||
|
|
||||||
(reset! last-error (ex-info "something bad happened" {:reason "why"}))
|
(defn clear-error!
|
||||||
(reset! last-error nil)
|
"Call from the REPL to resume the loop after an error froze it."
|
||||||
|
[]
|
||||||
(defn- draw-error! [err]
|
(reset! last-error nil))
|
||||||
(rl/clear-background!* rl/cornflower-blue)
|
|
||||||
(rl/draw-rectangle!* 10 10 300 30 (rl/color-seg 0xFF0000))
|
|
||||||
(rl/draw-text!* "Fix the code then left click anywhere with the mouse" 0 10 16 rl/white)
|
|
||||||
#_(rl/draw-text!* (str err) 50 100 20 rl/white)
|
|
||||||
(rl/draw-text!* "Error" 50 50 40 rl/white))
|
|
||||||
|
|
||||||
(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 watch-fn]
|
||||||
@ -24,19 +19,16 @@
|
|||||||
(rl/set-target-fps! 60)
|
(rl/set-target-fps! 60)
|
||||||
(let [state (atom (init (edn/read-string (slurp config-path))))]
|
(let [state (atom (init (edn/read-string (slurp config-path))))]
|
||||||
(while (not (rl/window-should-close?))
|
(while (not (rl/window-should-close?))
|
||||||
(rl/with-drawing!
|
(if @last-error
|
||||||
(if @last-error
|
(Thread/sleep 50)
|
||||||
(do
|
(rl/with-drawing!
|
||||||
(draw-error! @last-error)
|
|
||||||
(when (rl/mouse-button-released? rl/mouse-button-left)
|
|
||||||
(reset! last-error nil)))
|
|
||||||
(try
|
(try
|
||||||
(swap! state input)
|
(swap! state input)
|
||||||
(swap! state update)
|
(swap! state update)
|
||||||
(draw @state)
|
(draw @state)
|
||||||
(w/watch! (watch-fn @state))
|
(w/watch! (watch-fn @state))
|
||||||
;; TODO: Have Cider report this exception
|
|
||||||
(catch Throwable t
|
(catch Throwable t
|
||||||
(println t)
|
(println t)
|
||||||
(reset! last-error t))))))
|
(reset! last-error t)
|
||||||
|
(w/watch! (merge (watch-fn @state) {:error t})))))))
|
||||||
(rl/close-window!)))
|
(rl/close-window!)))
|
||||||
|
|||||||
@ -120,12 +120,14 @@
|
|||||||
|
|
||||||
;;; --------------------------------------------------- macros
|
;;; --------------------------------------------------- macros
|
||||||
|
|
||||||
(defmacro with-drawing! [& body]
|
(defmacro with-drawing!
|
||||||
|
[& body]
|
||||||
`(do
|
`(do
|
||||||
|
(begin-drawing!)
|
||||||
(try
|
(try
|
||||||
(begin-drawing!)
|
|
||||||
~@body
|
~@body
|
||||||
(end-drawing!))))
|
(finally
|
||||||
|
(end-drawing!)))))
|
||||||
|
|
||||||
;;; --------------------------------------------------- native value allocation
|
;;; --------------------------------------------------- native value allocation
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user