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?)
|
||||
(println "Warning: Existing raylib window open, ignoring!")
|
||||
(do
|
||||
(reset! texture-cache {})
|
||||
(rl/set-trace-log-level! rl/log-warning)
|
||||
(rl/init-window! width height title)
|
||||
(rl/set-target-fps! 30)
|
||||
@ -66,10 +65,13 @@
|
||||
(w/watch! (merge (watch-fn config @game-state) {:error t}))))))))
|
||||
(try
|
||||
(when unload
|
||||
(doseq [[_ tex] @texture-cache]
|
||||
(rl/unload-texture! tex))
|
||||
(unload @game-state))
|
||||
(catch Throwable t
|
||||
(report-exception! t)))
|
||||
(rl/close-window!)
|
||||
(reset! texture-cache {})
|
||||
(reset! last-error nil)
|
||||
(reset! game-state nil)
|
||||
(reset! game-config nil)))))
|
||||
|
||||
@ -264,10 +264,7 @@
|
||||
(defn watch-game [config game]
|
||||
{})
|
||||
|
||||
(defn unload-game [game]
|
||||
(doseq [[_ tex] (:tilemaps game)]
|
||||
(rl/unload-texture! tex))
|
||||
(reset! texture-cache {}))
|
||||
(defn unload-game [game])
|
||||
|
||||
(defn -main [& _args]
|
||||
(e/run-game!
|
||||
|
||||
@ -31,6 +31,13 @@
|
||||
:atlas-pos [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]
|
||||
(update-as-> [g game]
|
||||
(when (rl/key-pressed? rl/key-r)
|
||||
@ -50,11 +57,13 @@
|
||||
(assoc g :zoom (zoom-to-fit (:atlas g))))
|
||||
|
||||
(when (rl/mouse-button-pressed? rl/mouse-button-left)
|
||||
(assoc g
|
||||
(cond-> (assoc g
|
||||
:drag-start-pos (rl/get-mouse-position)
|
||||
:current-mouse-pos (rl/get-mouse-position)
|
||||
:drag-mode :selecting
|
||||
:selected-cells #{}))
|
||||
:drag-mode :selecting)
|
||||
|
||||
(not (rl/key-down? rl/key-left-shift))
|
||||
(assoc :selected-cells #{})))
|
||||
(when (rl/mouse-button-released? rl/mouse-button-left)
|
||||
(-> 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)))
|
||||
(- 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]
|
||||
(update-as-> [g game]
|
||||
(handle-input {} g)
|
||||
@ -169,8 +171,7 @@
|
||||
:atlas-pos (:atlas-pos game)
|
||||
#_#_:drag-delta (:drag-delta game)})
|
||||
|
||||
(defn unload-sprite-atlas [game]
|
||||
(rl/unload-texture! (:atlas game)))
|
||||
(defn unload-sprite-atlas [game])
|
||||
|
||||
(defn -main [& _args]
|
||||
(engine/run-game!
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user