perf improvements
This commit is contained in:
@@ -14,14 +14,14 @@
|
||||
(let [e (utils/get-entity entities id)]
|
||||
(if-let [[bx1 by1 bx2 by2] (:box e)]
|
||||
(zone/within bx1 by1 bx2 by2 x y)
|
||||
(let [{entity-x :x entity-y :y width :width scale-x :scale-x scale-y :scale-y origin-x :origin-x origin-y :origin-y height :height region :object} (get-in entities [:room :entities id])
|
||||
(let [{^float entity-x :x ^float entity-y :y width :width scale-x :scale-x scale-y :scale-y origin-x :origin-x origin-y :origin-y height :height region :object} (-> entities :room :entities id)
|
||||
|
||||
width (or width (if (instance? TextureRegion region ) (.getRegionWidth ^TextureRegion region) 0))
|
||||
height (or height (if (instance? TextureRegion region ) (.getRegionHeight ^TextureRegion region) 0))
|
||||
entity-x (unchecked-add (float entity-x) (unchecked-multiply (float (or origin-x 0))
|
||||
(float (or scale-x 1))))
|
||||
entity-y (unchecked-add (float entity-y) (unchecked-multiply (float (or origin-y 0))
|
||||
(float (or scale-y 1))))]
|
||||
entity-x (double (unchecked-add (float entity-x) (unchecked-multiply (float (or origin-x 0))
|
||||
(float (or scale-x 1)))))
|
||||
entity-y (double (unchecked-add (float entity-y) (unchecked-multiply (float (or origin-y 0))
|
||||
(float (or scale-y 1)))))]
|
||||
|
||||
(zone/within entity-x entity-y
|
||||
(unchecked-add (float entity-x) (unchecked-multiply (float width) (float (or scale-x 1))))
|
||||
|
||||
@@ -937,11 +937,12 @@
|
||||
|
||||
(defn play-key-sounds [screen entities]
|
||||
(if (= (get-in entities [:fade :opacity]) 0.0)
|
||||
(loop [entities entities
|
||||
[[target e] & rest] (seq (get-in entities [:room :entities]))]
|
||||
(if e
|
||||
(recur (play-sound-if-necessary screen entities target e) rest)
|
||||
entities))
|
||||
(reduce-kv (fn [entities target e]
|
||||
(if e
|
||||
(play-sound-if-necessary screen entities target e)
|
||||
entities))
|
||||
entities
|
||||
entities)
|
||||
entities))
|
||||
|
||||
(defn update-current-sound-vols! [entities]
|
||||
@@ -1013,7 +1014,7 @@
|
||||
(def nighttime-times #{:night :dawn})
|
||||
(defn get-rendered [entities {:keys [time ^double y ^double offset-y night-profile] :or {night-profile :default} :as e}]
|
||||
(as-> e e
|
||||
(if (or (get-in entities [:tweens :dawn-r])
|
||||
(if (or (-> entities :tweens :dawn-r)
|
||||
(and (not= time (-> entities :state :time))
|
||||
(nighttime-times (-> entities :state :time))))
|
||||
(-> e
|
||||
@@ -1074,30 +1075,30 @@
|
||||
#_(steam/update)
|
||||
(.apply viewport)
|
||||
|
||||
(if (get-in entities [:closing? :value])
|
||||
(if (-> entities :closing? :value)
|
||||
|
||||
(let [entities (utils/apply-tweens screen entities tweens)
|
||||
entities (update-current-sound-vols! entities)
|
||||
entities (remove-ended-sounds screen entities)
|
||||
get-rendered (partial get-rendered entities)
|
||||
entities (loop [entities entities
|
||||
[[k e] & rest] (seq (get-in entities [:room :entities]))]
|
||||
[[k e] & rest] (seq (-> entities :room :entities))]
|
||||
(if k
|
||||
(recur (update-in entities [:room :entities k] get-rendered) rest)
|
||||
entities))
|
||||
entities (grab-layers entities)
|
||||
layers (get-in entities [:room :current-layers])
|
||||
all-entities (-> layers (into (vals (get-in entities [:room :entities]))) (conj (:white-fade entities)))]
|
||||
(screen! fade-screen :update-fade {:opacity (get-in entities [:fade :opacity])})
|
||||
(doseq [m (vals (get-in entities [:musics]))]
|
||||
layers (-> entities :room :current-layers)
|
||||
all-entities (-> layers (into (vals (-> entities :room :entities))) (conj (:white-fade entities)))]
|
||||
(screen! fade-screen :update-fade {:opacity (-> entities :fade :opacity)})
|
||||
(utils/eager-loop (-> entities :musics-v :v) m
|
||||
(when m
|
||||
(music! m :set-volume (utils/current-music-volume (get-in entities [:volume :value])))))
|
||||
(music! m :set-volume (utils/current-music-volume (-> entities :volume :value)))))
|
||||
|
||||
(clear!)
|
||||
(doseq [e (sort-by :baseline all-entities)]
|
||||
(utils/eager-loop (vec (sort-by :baseline all-entities)) e
|
||||
(if (:parallax e)
|
||||
(render-parallax screen e)
|
||||
(render! screen [e])))
|
||||
(render-one screen e)))
|
||||
entities)
|
||||
(let [entities (fade-in-first-time-if-necessary screen entities)
|
||||
entities (utils/apply-tweens screen entities tweens)
|
||||
@@ -1112,14 +1113,14 @@
|
||||
last-pos-x (double last-pos-x)
|
||||
last-pos-y (double last-pos-y)
|
||||
entities (if (and (@utils/settings :camera-man? true)
|
||||
(not (get-in entities [:cam :paused?]))
|
||||
(nil? (get-in entities [:tweens :cam-x]))
|
||||
(not (-> entities :cam :paused?))
|
||||
(nil? (-> entities :tweens :cam-x))
|
||||
(= 1 (rand-int 20)))
|
||||
(if (= (rand-int 2) 1)
|
||||
(actions/pan-to screen entities
|
||||
(get-in entities [:room :entities :ego :x])
|
||||
(get-in entities [:room :entities :ego :y])
|
||||
(constantly (get-in entities [:room :entities :ego :scale-x]))
|
||||
(-> entities :room :entities :ego :x)
|
||||
(-> entities :room :entities :ego :y)
|
||||
(constantly (-> entities :room :entities :ego :scale-x))
|
||||
tween/ease-in-out-quadratic
|
||||
5.0)
|
||||
(actions/pan-to screen entities
|
||||
@@ -1127,7 +1128,7 @@
|
||||
(- 10 ^double (rand-int 20)))
|
||||
(+ ^double (get-in entities [:cam :y] 0)
|
||||
(- 10 ^double (rand-int 20)))
|
||||
(constantly (get-in entities [:room :entities :ego :scale-x]))
|
||||
(constantly (-> entities :room :entities :ego :scale-x))
|
||||
tween/ease-in-out-quadratic
|
||||
5.0))
|
||||
entities)
|
||||
@@ -1140,20 +1141,20 @@
|
||||
e)
|
||||
|
||||
e (if update-fn
|
||||
(update-fn screen (get-in entities [:room :entities]) e)
|
||||
(update-fn screen (-> entities :room :entities) e)
|
||||
e)
|
||||
e (get-rendered entities e)]
|
||||
e))
|
||||
entities (loop [room (transient (get-in entities [:room :entities]))
|
||||
[[k e] & rest] (doall (seq (get-in entities [:room :entities])))]
|
||||
entities (loop [room (transient (-> entities :room :entities))
|
||||
[[k e] & rest] (doall (seq (-> entities :room :entities)))]
|
||||
(if k
|
||||
(recur (assoc! room k (update-room e))
|
||||
rest)
|
||||
(assoc-in entities [:room :entities] (persistent! room))))
|
||||
layers (get-in entities [:room :current-layers])
|
||||
all-entities (-> layers (into (vals (get-in entities [:room :entities]))) (conj (:white-fade entities)))]
|
||||
layers (-> entities :room :current-layers)
|
||||
all-entities (-> layers (into (vals (-> entities :room :entities))) (conj (:white-fade entities)))]
|
||||
|
||||
(screen! tooltip-screen :on-hover-start {:hover-text (get-in entities [:label :text])
|
||||
(screen! tooltip-screen :on-hover-start {:hover-text (-> entities :label :text)
|
||||
:scene-viewport (:viewport screen)
|
||||
:cursor (:cursor entities)
|
||||
:x (unchecked-subtract last-pos-x
|
||||
@@ -1163,8 +1164,8 @@
|
||||
|
||||
(clear!)
|
||||
(screen! talking-screen :on-update-camera { :scene-viewport (:viewport screen) :scene-camera (:camera screen)})
|
||||
(screen! fade-screen :update-fade { :opacity (get-in entities [:fade :opacity])})
|
||||
(when true #_(not (get-in entities [:cam :paused?]))
|
||||
(screen! fade-screen :update-fade { :opacity (-> entities :fade :opacity)})
|
||||
(when true #_(not (-> entities :cam :paused?))
|
||||
(set! (. camera zoom) (:zoom (:cam entities)))
|
||||
(set! (.. camera position x) (:x (:cam entities) 160.0))
|
||||
(set! (.. camera position y) (:y (:cam entities) 120.0)))
|
||||
@@ -1174,13 +1175,13 @@
|
||||
entities (play-key-sounds screen entities)
|
||||
entities (update-current-sound-vols! entities)
|
||||
entities (remove-ended-sounds screen entities)]
|
||||
(doseq [m (vals (get-in entities [:musics]))]
|
||||
(utils/eager-loop (-> entities :musics-v :v) m
|
||||
(when m
|
||||
(music! m :set-volume (utils/current-music-volume (get-in entities [:volume :value])))))
|
||||
(doseq [e (doall (sort-by :baseline all-entities))]
|
||||
(music! m :set-volume (utils/current-music-volume (-> entities :volume :value)))))
|
||||
(utils/eager-loop (vec (doall (sort-by :baseline all-entities))) e
|
||||
(if (:parallax e)
|
||||
(render-parallax screen e)
|
||||
(render! screen [e])))
|
||||
(render-one screen e)))
|
||||
|
||||
entities))))
|
||||
|
||||
@@ -1304,11 +1305,13 @@
|
||||
((:scale-fn room)
|
||||
(if has-start-pos?
|
||||
start-pos
|
||||
(:start-pos room))))))}]
|
||||
(:start-pos room))))))}
|
||||
entities (assoc entities :musics-v {:v (vec (vals (get-in entities [:musics])))
|
||||
:object nil})]
|
||||
(log/info "assets so far", (.getDiagnostics *asset-manager*) )
|
||||
|
||||
|
||||
(doseq [[k [start time fn]] (get-in entities [:room :timers])]
|
||||
(doseq [[k [start time fn]] (-> entities :room :timers)]
|
||||
(add-timer! screen k start time))
|
||||
|
||||
(log/info "[done] Initializing scene.")
|
||||
@@ -1521,7 +1524,7 @@
|
||||
:on-render
|
||||
(fn [{:keys [^FitViewport viewport] :as screen} entities options]
|
||||
(.apply viewport)
|
||||
(render! screen [(:label entities)])
|
||||
(render-one screen (:label entities))
|
||||
entities)
|
||||
|
||||
:on-resize
|
||||
@@ -1921,15 +1924,14 @@
|
||||
|
||||
|
||||
|
||||
(render! screen [ (if (and hud-interactable? (not (:already-saved? entities)))
|
||||
(:save entities)
|
||||
(assoc (:save entities) :opacity 0.5))
|
||||
#_(:fps entities)
|
||||
(if hud-interactable?
|
||||
(:inventory entities)
|
||||
(assoc (:inventory entities) :opacity 0.5))
|
||||
(:selected-item entities)
|
||||
(:close entities)])
|
||||
(render-one screen (if (and hud-interactable? (not (:already-saved? entities)))
|
||||
(:save entities)
|
||||
(assoc (:save entities) :opacity 0.5)))
|
||||
(render-one screen (if hud-interactable?
|
||||
(:inventory entities)
|
||||
(assoc (:inventory entities) :opacity 0.5)))
|
||||
(render-one screen (:selected-item entities))
|
||||
(render-one screen (:close entities))
|
||||
entities))
|
||||
|
||||
:on-resize
|
||||
|
||||
@@ -128,16 +128,16 @@
|
||||
|
||||
(defonce selected-save (atom nil))
|
||||
|
||||
(defn current-music-volume
|
||||
([] (current-music-volume 1.0))
|
||||
([^double factor]
|
||||
(defn current-music-volume
|
||||
(^double [] (current-music-volume 1.0))
|
||||
(^double [^double factor]
|
||||
(-> (Math/pow (unchecked-multiply (:music-volume @settings) 0.01) 2)
|
||||
(unchecked-multiply 0.25)
|
||||
(unchecked-multiply (double factor)))))
|
||||
|
||||
(defn current-sound-volume
|
||||
([] (current-sound-volume 1.0))
|
||||
([^double factor]
|
||||
(^double [] (current-sound-volume 1.0))
|
||||
(^double [^double factor]
|
||||
(-> (Math/pow (unchecked-multiply (:sound-volume @settings) 0.01) 2)
|
||||
(unchecked-multiply 0.5)
|
||||
(unchecked-multiply (double factor)))))
|
||||
@@ -394,18 +394,18 @@
|
||||
(first (concat (filter #(and ((:mouse-in? %) entities x y)
|
||||
|
||||
(:override %))
|
||||
(get-in entities [:room :interactions]))
|
||||
(-> entities :room :interactions))
|
||||
(filter #(and (:mouse-in? %)
|
||||
((:mouse-in? %) entities x y)
|
||||
(not= "ego" (:id %))
|
||||
(:get-script %))
|
||||
(vals (get-in entities [:room :entities])))
|
||||
(vals (-> entities :room :entities)))
|
||||
(filter #(and ((:mouse-in? %) entities x y)
|
||||
(:get-script %))
|
||||
(get-in entities [:room :interactions])))))
|
||||
(-> entities :room :interactions)))))
|
||||
|
||||
(defn hovering-ego [entities [x y]]
|
||||
(when-let [mouse-in (get-in entities [:room :entities :ego :mouse-in?])]
|
||||
(when-let [mouse-in (-> entities :room :entities :ego :mouse-in?)]
|
||||
(mouse-in entities x y)))
|
||||
|
||||
(defn remove-interaction [entities id]
|
||||
@@ -506,14 +506,14 @@
|
||||
(not (#{:end :none-but-arrow} (or (get-in entities [:fg-actions :last-skip-type]) :end))))))
|
||||
|
||||
(defn update-override [{:keys [^FitViewport viewport] :as screen} entities options]
|
||||
(let [raw-pos (get-in entities [:cursor :last-pos])
|
||||
(let [raw-pos (-> entities :cursor :last-pos)
|
||||
last-pos (unproject screen options raw-pos)
|
||||
mouse-override (find-override entities last-pos)
|
||||
out-of-bounds (not (contains-point? (.getScreenX viewport) (.getScreenY viewport)
|
||||
(.getScreenWidth viewport) (.getScreenHeight viewport)
|
||||
(first raw-pos) (last raw-pos)))
|
||||
hovering-ego (hovering-ego entities last-pos)
|
||||
current (get-in entities [:cursor :current])
|
||||
current (-> entities :cursor :current)
|
||||
entities (assoc-in entities [:label :text] "")
|
||||
selected-inventory-item (@(resolve 'advent.screens.scene/get-selected-inventory-item))]
|
||||
|
||||
@@ -522,7 +522,7 @@
|
||||
(update-in entities [:cursor] assoc :override nil :active false )
|
||||
|
||||
|
||||
(not (get-in entities [:state :active?]))
|
||||
(not (-> entities :state :active?))
|
||||
(-> entities
|
||||
(assoc-in [:cursor :override] nil))
|
||||
|
||||
@@ -530,7 +530,7 @@
|
||||
(-> entities
|
||||
(assoc-in [:cursor :override] :hourglass))
|
||||
|
||||
(get-in entities [:state :hud-active?])
|
||||
(-> entities :state :hud-active?)
|
||||
(-> entities
|
||||
(assoc-in [:cursor :override] nil)
|
||||
(assoc-in [:label :text] ""))
|
||||
@@ -721,3 +721,20 @@
|
||||
|
||||
(defn get-entity [entities id]
|
||||
((:entities (:room entities)) id))
|
||||
|
||||
(defmacro eager-loop [xs n form]
|
||||
`(let [xs# ~xs]
|
||||
(if (instance? clojure.lang.Indexed xs#)
|
||||
(loop [x# 0]
|
||||
(if (< x# (count xs#))
|
||||
(let [~n (nth xs# x#)]
|
||||
~form
|
||||
(recur (inc x#)))))
|
||||
(do
|
||||
|
||||
(loop [[~n & r#] xs#]
|
||||
(if (seq r#)
|
||||
(do ~form
|
||||
nil)
|
||||
(do ~form
|
||||
(recur r#))))))))
|
||||
|
||||
Reference in New Issue
Block a user