tons of memory reducers.
This commit is contained in:
@@ -39,7 +39,7 @@
|
||||
[advent.screens.rooms.cat-tree :as rooms.cat-tree]
|
||||
[advent.screens.dialogue :refer [talking-screen toast-screen]]
|
||||
[advent.screens.inventory :refer [inventory-screen]]
|
||||
[clojure.core.async :refer [put! <! <!! >! chan go thread take! alts!! dropping-buffer]])
|
||||
[clojure.core.async :refer [put! <! <!! >! chan go thread take! alts!! poll! dropping-buffer]])
|
||||
(:import [com.badlogic.gdx.graphics Pixmap$Format Pixmap Pixmap$Filter Texture Texture$TextureFilter GL20 GL30]
|
||||
[com.badlogic.gdx.graphics.g2d TextureRegion Animation Batch]
|
||||
[com.badlogic.gdx.math Vector3 Matrix4]
|
||||
@@ -839,7 +839,7 @@ void main ()
|
||||
(let [{{:keys [script-running? script-chan]} key} entities]
|
||||
(if script-running?
|
||||
entities
|
||||
(let [[next-script] (alts!! [script-chan] :default nil)]
|
||||
(let [next-script (poll! script-chan)]
|
||||
(if next-script
|
||||
(do
|
||||
(next-script entities)
|
||||
@@ -861,7 +861,7 @@ void main ()
|
||||
(update-in terminated [key] assoc :current nil :started? false)
|
||||
key))
|
||||
(assoc-in entities [key :started?] true)))
|
||||
(let [[current _] (alts!! [channel] :default nil)]
|
||||
(let [current (poll! channel)]
|
||||
|
||||
(-> entities
|
||||
(assoc-in [key :started?] false)
|
||||
@@ -891,32 +891,39 @@ void main ()
|
||||
entities))
|
||||
|
||||
|
||||
(defn get-looped-animation-point [^Animation animation ^double total-time]
|
||||
(mod total-time (animation! animation :get-animation-duration)))
|
||||
(defn get-looped-animation-point ^double [^Animation animation ^double total-time]
|
||||
(let [t (double total-time)]
|
||||
(rem t (animation! animation :get-animation-duration))))
|
||||
|
||||
(defn animate [{:keys [anim anim-loop? anim-merges ^double anim-start] :or {anim-loop? true} :as entity} {:keys [^double delta-time ^double total-time] :or {^double delta-time 0} :as screen}]
|
||||
(let [current-frame-index (animation! ^Animation anim :get-key-frame-index
|
||||
(defn animate [{:keys [anim anim-loop? anim-merges anim-start] :or {anim-loop? true} :as entity} {:keys [delta-time total-time] :or {delta-time 0} :as screen}]
|
||||
(let [delta-time (double delta-time)
|
||||
total-time (double total-time)
|
||||
anim-start (double anim-start)
|
||||
animated-time (unchecked-subtract total-time anim-start)
|
||||
last-animated-time (unchecked-subtract animated-time delta-time)
|
||||
current-frame-index (animation! ^Animation anim :get-key-frame-index
|
||||
(if anim-loop?
|
||||
(get-looped-animation-point anim ^double (unchecked-subtract total-time anim-start))
|
||||
(unchecked-subtract total-time anim-start)))
|
||||
(get-looped-animation-point anim animated-time)
|
||||
animated-time))
|
||||
|
||||
previous-frame-index (animation! ^Animation anim :get-key-frame-index
|
||||
(if anim-loop?
|
||||
(get-looped-animation-point anim ^double (unchecked-subtract (unchecked-subtract total-time anim-start ) delta-time))
|
||||
(unchecked-subtract (unchecked-subtract total-time anim-start) delta-time)))]
|
||||
(get-looped-animation-point anim last-animated-time)
|
||||
last-animated-time))]
|
||||
(if (= current-frame-index (:current-frame-index entity) (:previous-frame-index entity))
|
||||
entity
|
||||
(merge (assoc entity
|
||||
:object (.getKeyFrame ^Animation anim (- total-time anim-start) anim-loop?)
|
||||
:current-frame-index current-frame-index
|
||||
:previous-frame-index previous-frame-index
|
||||
:origin-x (or (get-in entity [:anim-origins anim 0])
|
||||
:origin-x (or (-> entity :anim-origins (get anim) (nth 0))
|
||||
(:base-origin-x entity)
|
||||
(:origin-x entity))
|
||||
:origin-y (or (get-in entity [:anim-origins anim 1])
|
||||
:origin-y (or (-> entity :anim-origins (get anim) (nth 1))
|
||||
(:base-origin-y entity)
|
||||
(:origin-y entity)))
|
||||
(or (get-in entity [:anim-merges anim])
|
||||
(get-in entity [:anim-merges :default]))))))
|
||||
(or (-> entity :anim-merges (get anim))
|
||||
(-> entity :anim-merges :default))))))
|
||||
|
||||
|
||||
(defn get-layers [entities]
|
||||
@@ -1006,17 +1013,18 @@ void main ()
|
||||
(update-fn screen entities)
|
||||
entities))
|
||||
|
||||
(defn render-parallax [{:keys [^OrthographicCamera camera ^Stage renderer ^ShaderProgram shader] :as screen} {:keys [^double parallax ^float multiply-amount ^float hue-amount] :as e }]
|
||||
(defn render-parallax [{:keys [^OrthographicCamera camera ^Stage renderer ^ShaderProgram shader] :as screen} {:keys [parallax ^float multiply-amount ^float hue-amount] :as e }]
|
||||
|
||||
(let [tmp (Vector3.)
|
||||
tmp2 (Vector3.)
|
||||
parallax-view (Matrix4.)
|
||||
parallax-combined (Matrix4.)]
|
||||
parallax-combined (Matrix4.)
|
||||
p (float parallax)]
|
||||
(.update camera)
|
||||
|
||||
(.set tmp (.position camera))
|
||||
(set! (.x tmp) (double (* (.x tmp) parallax)))
|
||||
(set! (.y tmp) (double (* (.y tmp) parallax)))
|
||||
(set! (.x tmp) (float (* (.x tmp) p)))
|
||||
(set! (.y tmp) (float (* (.y tmp) p)))
|
||||
(.setToLookAt parallax-view tmp (-> tmp2
|
||||
(.set tmp)
|
||||
(.add (.direction camera)))
|
||||
@@ -1027,7 +1035,7 @@ void main ()
|
||||
|
||||
(let [^Batch batch (.getBatch renderer)]
|
||||
|
||||
(.begin batch)
|
||||
|
||||
(.setProjectionMatrix batch parallax-combined)
|
||||
(.setShader batch shader)
|
||||
(when shader
|
||||
@@ -1038,21 +1046,23 @@ void main ()
|
||||
|
||||
|
||||
(entities/draw! (assoc e :x (+ (/ ^double (:x e) (.zoom camera))
|
||||
(- (* 320 parallax 0.5)
|
||||
(- (* 320 p 0.5)
|
||||
(/ 160 (.zoom camera)) ))
|
||||
:y (+ (/ ^double (:y e) (.zoom camera))
|
||||
(- (* 240 parallax 0.5)
|
||||
(- (* 240 p 0.5)
|
||||
(/ 120 (.zoom camera))))) screen batch)
|
||||
(.setColor batch (color 1 1 1 1))
|
||||
(.end batch))))
|
||||
)))
|
||||
|
||||
(def nighttime-times #{:night :sunrise})
|
||||
(defn get-rendered [entities {:keys [time ^double y ^double offset-y night-profile] :or {night-profile :default} :as e}]
|
||||
(as-> e e
|
||||
(merge e
|
||||
(when (and (not= time (get-in entities [:state :time]))
|
||||
(#{:night :sunrise} (get-in entities [:state :time])))
|
||||
(assoc (get-in entities [:time-profiles night-profile])
|
||||
:time (get-in entities [:state :time]))))
|
||||
(if (and (not= time (-> entities :state :time))
|
||||
(nighttime-times (-> entities :state :time)))
|
||||
(-> e
|
||||
(merge (-> entities :time-profiles night-profile))
|
||||
(assoc :time (-> entities :state :time)))
|
||||
e)
|
||||
(if offset-y
|
||||
(assoc e :y (+ y offset-y))
|
||||
e)))
|
||||
@@ -1239,9 +1249,10 @@ void main ()
|
||||
nil)
|
||||
|
||||
:on-render
|
||||
(fn [{:keys [^OrthographicCamera camera ^FitViewport viewport] :as screen} entities options]
|
||||
(fn [{:keys [^OrthographicCamera camera ^FitViewport viewport ^Stage renderer] :as screen} entities options]
|
||||
(steam/update)
|
||||
(.apply viewport)
|
||||
|
||||
(if (get-in entities [:closing? :value])
|
||||
|
||||
(let [entities (utils/apply-tweens screen entities (:tweens entities))
|
||||
@@ -1265,7 +1276,8 @@ void main ()
|
||||
(doseq [e (sort-by :baseline all-entities)]
|
||||
(if (:parallax e)
|
||||
(render-parallax screen e)
|
||||
(render! screen [e]))))
|
||||
(render! screen [e])))
|
||||
entities)
|
||||
(let [entities (fade-in-first-time-if-necessary screen entities)
|
||||
entities (utils/apply-tweens screen entities (:tweens entities))
|
||||
entities (update-cursor screen entities)
|
||||
@@ -1310,12 +1322,12 @@ void main ()
|
||||
e)
|
||||
e (get-rendered entities e)]
|
||||
e))
|
||||
entities (loop [entities entities
|
||||
[[k e] & rest] (seq (get-in entities [:room :entities]))]
|
||||
entities (loop [room (transient (get-in entities [:room :entities]))
|
||||
[[k e] & rest] (doall (seq (get-in entities [:room :entities])))]
|
||||
(if k
|
||||
(recur (update-in entities [:room :entities k] update-room)
|
||||
(recur (assoc! room k (update-room e))
|
||||
rest)
|
||||
entities))
|
||||
(assoc-in entities [:room :entities] (persistent! room))))
|
||||
layers (get-in entities [:room :current-layers])
|
||||
all-entities (concat layers (vals (get-in entities [:room :entities])))]
|
||||
(clear!)
|
||||
@@ -1332,7 +1344,7 @@ void main ()
|
||||
(doseq [m (vals (get-in entities [:musics]))]
|
||||
(when m
|
||||
(music! m :set-volume (utils/current-music-volume (get-in entities [:volume :value])))))
|
||||
(doseq [e (sort-by :baseline all-entities)]
|
||||
(doseq [e (doall (sort-by :baseline all-entities))]
|
||||
(if (:parallax e)
|
||||
(render-parallax screen e)
|
||||
(render! screen [e])))
|
||||
@@ -1432,10 +1444,10 @@ void main ()
|
||||
(set-screen! @(resolve 'advent.core/advent) @(resolve 'advent.screens.title/title-screen))
|
||||
%))))))
|
||||
|
||||
:on-start-script (fn [{:keys [script]} entities options]
|
||||
:on-start-script (fn [screen entities {:keys [script]}]
|
||||
(script entities)
|
||||
entities)
|
||||
:hud-active? (fn [{:keys [hud-active?]} entities options]
|
||||
:hud-active? (fn [screen entities {:keys [hud-active?]}]
|
||||
(assoc-in entities [:state :hud-active?] hud-active?))) ()
|
||||
|
||||
|
||||
@@ -1856,7 +1868,7 @@ void main ()
|
||||
|
||||
|
||||
:on-start-script
|
||||
(fn [_ entities]
|
||||
(fn [_ entities _]
|
||||
(println "here")
|
||||
(-> entities
|
||||
(update-in [:inv-fsm :pending-states] conj [:none nil])
|
||||
|
||||
Reference in New Issue
Block a user