Fixes memory leak and input issue.
The input issue is caused by the fact that the previous screen is still rendered, even after .setScreen is called. Executing on the gl thread fixes this. The documentation says that old screens need to be disposed manually. This instantly freed up a lot of memory when running my game.
This commit is contained in:
@@ -515,11 +515,15 @@ keywords and functions in pairs."
|
|||||||
(let [run-fn! (fn [k & args]
|
(let [run-fn! (fn [k & args]
|
||||||
(doseq [screen screen-objects]
|
(doseq [screen screen-objects]
|
||||||
(apply (get screen k) args)))]
|
(apply (get screen k) args)))]
|
||||||
|
(when-let [old-screen (.getScreen game-object)]
|
||||||
|
(.dispose old-screen))
|
||||||
|
(on-gl
|
||||||
(.setScreen game-object
|
(.setScreen game-object
|
||||||
(reify Screen
|
(reify Screen
|
||||||
(show [this]
|
(show [this]
|
||||||
(input! :set-input-processor (InputMultiplexer.))
|
(input! :set-input-processor (InputMultiplexer.))
|
||||||
(run-fn! :show)
|
(run-fn! :show)
|
||||||
|
|
||||||
(doseq [{:keys [screen]} screen-objects]
|
(doseq [{:keys [screen]} screen-objects]
|
||||||
(doseq [[_ listener] (:input-listeners @screen)]
|
(doseq [[_ listener] (:input-listeners @screen)]
|
||||||
(add-input! listener))))
|
(add-input! listener))))
|
||||||
@@ -528,7 +532,7 @@ keywords and functions in pairs."
|
|||||||
(pause [this] (run-fn! :pause))
|
(pause [this] (run-fn! :pause))
|
||||||
(resize [this w h] (run-fn! :resize w h))
|
(resize [this w h] (run-fn! :resize w h))
|
||||||
(resume [this] (run-fn! :resume))
|
(resume [this] (run-fn! :resume))
|
||||||
(dispose [this])))))
|
(dispose [this]))))))
|
||||||
|
|
||||||
(defn set-screen-wrapper!
|
(defn set-screen-wrapper!
|
||||||
"Sets a function that wraps around all screen functions, allowing you to
|
"Sets a function that wraps around all screen functions, allowing you to
|
||||||
|
|||||||
Reference in New Issue
Block a user