Unload textures on the engine side, fix errors
This commit is contained in:
parent
6f3948d62e
commit
d6495103e1
@ -40,7 +40,6 @@
|
|||||||
(if (rl/window-ready?)
|
(if (rl/window-ready?)
|
||||||
(println "Warning: Existing raylib window open, ignoring!")
|
(println "Warning: Existing raylib window open, ignoring!")
|
||||||
(do
|
(do
|
||||||
(reset! texture-cache {})
|
|
||||||
(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! 30)
|
(rl/set-target-fps! 30)
|
||||||
@ -66,10 +65,13 @@
|
|||||||
(w/watch! (merge (watch-fn config @game-state) {:error t}))))))))
|
(w/watch! (merge (watch-fn config @game-state) {:error t}))))))))
|
||||||
(try
|
(try
|
||||||
(when unload
|
(when unload
|
||||||
|
(doseq [[_ tex] @texture-cache]
|
||||||
|
(rl/unload-texture! tex))
|
||||||
(unload @game-state))
|
(unload @game-state))
|
||||||
(catch Throwable t
|
(catch Throwable t
|
||||||
(report-exception! t)))
|
(report-exception! t)))
|
||||||
(rl/close-window!)
|
(rl/close-window!)
|
||||||
|
(reset! texture-cache {})
|
||||||
(reset! last-error nil)
|
(reset! last-error nil)
|
||||||
(reset! game-state nil)
|
(reset! game-state nil)
|
||||||
(reset! game-config nil)))))
|
(reset! game-config nil)))))
|
||||||
|
|||||||
@ -264,10 +264,7 @@
|
|||||||
(defn watch-game [config game]
|
(defn watch-game [config game]
|
||||||
{})
|
{})
|
||||||
|
|
||||||
(defn unload-game [game]
|
(defn unload-game [game])
|
||||||
(doseq [[_ tex] (:tilemaps game)]
|
|
||||||
(rl/unload-texture! tex))
|
|
||||||
(reset! texture-cache {}))
|
|
||||||
|
|
||||||
(defn -main [& _args]
|
(defn -main [& _args]
|
||||||
(e/run-game!
|
(e/run-game!
|
||||||
|
|||||||
@ -31,6 +31,13 @@
|
|||||||
:atlas-pos [0 0]
|
:atlas-pos [0 0]
|
||||||
:drag-delta [0 0]}))
|
:drag-delta [0 0]}))
|
||||||
|
|
||||||
|
(defn- get-selection-rect [{ax :x ay :y} {bx :x by :y}]
|
||||||
|
(let [start-x (min ax bx)
|
||||||
|
start-y (min ay by)
|
||||||
|
end-x (max ax bx)
|
||||||
|
end-y (max ay by)]
|
||||||
|
{:x start-x :y start-y :w (- end-x start-x) :h (- end-y start-y)}))
|
||||||
|
|
||||||
(defn handle-input [_ game]
|
(defn handle-input [_ game]
|
||||||
(update-as-> [g game]
|
(update-as-> [g game]
|
||||||
(when (rl/key-pressed? rl/key-r)
|
(when (rl/key-pressed? rl/key-r)
|
||||||
@ -50,11 +57,13 @@
|
|||||||
(assoc g :zoom (zoom-to-fit (:atlas g))))
|
(assoc g :zoom (zoom-to-fit (:atlas g))))
|
||||||
|
|
||||||
(when (rl/mouse-button-pressed? rl/mouse-button-left)
|
(when (rl/mouse-button-pressed? rl/mouse-button-left)
|
||||||
(assoc g
|
(cond-> (assoc g
|
||||||
:drag-start-pos (rl/get-mouse-position)
|
:drag-start-pos (rl/get-mouse-position)
|
||||||
:current-mouse-pos (rl/get-mouse-position)
|
:current-mouse-pos (rl/get-mouse-position)
|
||||||
:drag-mode :selecting
|
:drag-mode :selecting)
|
||||||
:selected-cells #{}))
|
|
||||||
|
(not (rl/key-down? rl/key-left-shift))
|
||||||
|
(assoc :selected-cells #{})))
|
||||||
(when (rl/mouse-button-released? rl/mouse-button-left)
|
(when (rl/mouse-button-released? rl/mouse-button-left)
|
||||||
(-> g
|
(-> g
|
||||||
(assoc :selected-sprite (get-selection-rect (:drag-start-pos g) (:current-mouse-pos g)))
|
(assoc :selected-sprite (get-selection-rect (:drag-start-pos g) (:current-mouse-pos g)))
|
||||||
@ -76,13 +85,6 @@
|
|||||||
(assoc g :zoom new-scale :atlas-pos [(- mx (* k (- mx ax)))
|
(assoc g :zoom new-scale :atlas-pos [(- mx (* k (- mx ax)))
|
||||||
(- my (* k (- my ay)))]))))))
|
(- my (* k (- my ay)))]))))))
|
||||||
|
|
||||||
(defn- get-selection-rect [{ax :x ay :y} {bx :x by :y}]
|
|
||||||
(let [start-x (min ax bx)
|
|
||||||
start-y (min ay by)
|
|
||||||
end-x (max ax bx)
|
|
||||||
end-y (max ay by)]
|
|
||||||
{:x start-x :y start-y :w (- end-x start-x) :h (- end-y start-y)}))
|
|
||||||
|
|
||||||
(defn update-sprite-atlas [_ game]
|
(defn update-sprite-atlas [_ game]
|
||||||
(update-as-> [g game]
|
(update-as-> [g game]
|
||||||
(handle-input {} g)
|
(handle-input {} g)
|
||||||
@ -169,8 +171,7 @@
|
|||||||
:atlas-pos (:atlas-pos game)
|
:atlas-pos (:atlas-pos game)
|
||||||
#_#_:drag-delta (:drag-delta game)})
|
#_#_:drag-delta (:drag-delta game)})
|
||||||
|
|
||||||
(defn unload-sprite-atlas [game]
|
(defn unload-sprite-atlas [game])
|
||||||
(rl/unload-texture! (:atlas game)))
|
|
||||||
|
|
||||||
(defn -main [& _args]
|
(defn -main [& _args]
|
||||||
(engine/run-game!
|
(engine/run-game!
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user