From 6eda69a1b869ce096cf9af3b8068d7545585bd63 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Mon, 8 Aug 2016 13:20:25 -0700 Subject: [PATCH] hopefully less memory. --- desktop/project.clj | 2 +- desktop/src-common/advent/screens/scene.clj | 68 +++++++++++---------- 2 files changed, 37 insertions(+), 33 deletions(-) diff --git a/desktop/project.clj b/desktop/project.clj index d4bdf3bb..bba54845 100644 --- a/desktop/project.clj +++ b/desktop/project.clj @@ -33,7 +33,7 @@ [slamhound "1.5.5"] [org.clojure/data.csv "0.1.3"]] - :warn-on-reflection true} + #_#_:warn-on-reflection true} :app-store { :source-paths ["src" "src-common" "src-dev"] :jvm-opts ["-Dapp-store=true" "-Dno-steam=true"] diff --git a/desktop/src-common/advent/screens/scene.clj b/desktop/src-common/advent/screens/scene.clj index 38a7b28c..b6a986d6 100644 --- a/desktop/src-common/advent/screens/scene.clj +++ b/desktop/src-common/advent/screens/scene.clj @@ -53,6 +53,8 @@ VertexAttributes$Usage] [com.badlogic.gdx.scenes.scene2d Actor Stage])) +(set! *unchecked-math* :warn-on-boxed) + (declare hud) (declare get-selected-inventory-item) @@ -712,7 +714,7 @@ void main () :poke (utils/flip poke) :whistle (utils/flip whistle) } - :baseline (- 240 (last start-pos)) + :baseline (- 240 (double (last start-pos))) :facing :right :night-profile :sprite :origin-x 9 @@ -745,9 +747,9 @@ void main () :talk-color (color 0.6 1.0 1.0 1.0) :stand-override nil :mouse-in? (fn [entities x y] - (let [{entity-x :x entity-y :y ^TextureRegion region :object scale :scale-x} (get-in entities [:room :entities :ego]) - half-width (/ (* (.getRegionWidth region) (or scale 1.0)) 2) - height (* (.getRegionHeight region) (or scale 1.0))] + (let [{^double entity-x :x ^double entity-y :y ^TextureRegion region :object scale :scale-x} (get-in entities [:room :entities :ego]) + half-width (double (/ (* (.getRegionWidth region) (double (or scale 1.0))) 2)) + height (double (* (.getRegionHeight region) (double (or scale 1.0))))] ((zone/box (- entity-x half-width) entity-y (+ entity-x half-width) (+ entity-y height)) x y))) :get-script get-ego-script @@ -996,7 +998,7 @@ void main () (update-in entities [:current-sounds :value] (fn [sounds] (filter #(or (= :loop (:type %)) - (> (:ends-at %) (:total-time screen))) + (> ^double (:ends-at %) ^double (:total-time screen))) sounds)))) (defn update-from-room [screen entities] @@ -1004,7 +1006,7 @@ void main () (update-fn screen entities) entities)) -(defn render-parallax [{:keys [^OrthographicCamera camera ^Stage renderer ^ShaderProgram shader] :as screen} {:keys [parallax ^float multiply-amount ^float hue-amount] :as e }] +(defn render-parallax [{:keys [^OrthographicCamera camera ^Stage renderer ^ShaderProgram shader] :as screen} {:keys [^double parallax ^float multiply-amount ^float hue-amount] :as e }] (let [tmp (Vector3.) tmp2 (Vector3.) @@ -1013,8 +1015,8 @@ void main () (.update camera) (.set tmp (.position camera)) - (set! (.x tmp) (* (.x tmp) parallax)) - (set! (.y tmp) (* (.y tmp) parallax)) + (set! (.x tmp) (double (* (.x tmp) parallax))) + (set! (.y tmp) (double (* (.y tmp) parallax))) (.setToLookAt parallax-view tmp (-> tmp2 (.set tmp) (.add (.direction camera))) @@ -1035,24 +1037,24 @@ void main () (.setColor batch (color (:r e 1.0) (:g e 1.0) (:b e 1.0) (:opacity e 1.0))) - (entities/draw! (assoc e :x (+ (/ (:x e) (.zoom camera)) + (entities/draw! (assoc e :x (+ (/ ^double (:x e) (.zoom camera)) (- (* 320 parallax 0.5) (/ 160 (.zoom camera)) )) - :y (+ (/ (:y e) (.zoom camera)) + :y (+ (/ ^double (:y e) (.zoom camera)) (- (* 240 parallax 0.5) (/ 120 (.zoom camera))))) screen batch) (.setColor batch (color 1 1 1 1)) (.end batch)))) -(defn get-rendered [entities e] +(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 e) (get-in entities [:state :time])) + (when (and (not= time (get-in entities [:state :time])) (#{:night :sunrise} (get-in entities [:state :time]))) - (assoc (get-in entities [:time-profiles (:night-profile e :default)]) + (assoc (get-in entities [:time-profiles night-profile]) :time (get-in entities [:state :time])))) - (if (:offset-y e) - (assoc e :y (+ (:y e) (:offset-y e))) + (if offset-y + (assoc e :y (+ y offset-y)) e))) (defn mouse-moved [screen entities {:keys [input-x input-y] :as options}] @@ -1287,10 +1289,10 @@ void main () tween/ease-in-out-quadratic 5.0) (actions/pan-to screen entities - (+ (get-in entities [:cam :x] 0) - (- 10 (rand-int 20))) - (+ (get-in entities [:cam :y] 0) - (- 10 (rand-int 20))) + (+ ^double (get-in entities [:cam :x] 0) + (- 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])) tween/ease-in-out-quadratic 5.0)) @@ -1298,14 +1300,16 @@ void main () entities (grab-layers entities) - update-room (comp - #(if (:anim %) - (animate % screen) - %) - #(if (:update-fn %) - ((:update-fn %) screen entities %) - %) - (partial get-rendered entities)) + update-room (fn [{:keys [anim update-fn] :as e}] + (let [e (if (:anim e) + (animate e screen) + e) + + e (if update-fn + (update-fn screen entities e) + e) + e (get-rendered entities e)] + e)) entities (loop [entities entities [[k e] & rest] (seq (get-in entities [:room :entities]))] (if k @@ -1542,7 +1546,7 @@ void main () (transition-done? [this screen entities] (animation! (get-in entities [:inventory :anim]) :is-animation-finished - (- (:total-time screen) (get-in entities [:inventory :anim-start]))))) + (- ^double (:total-time screen) ^double (get-in entities [:inventory :anim-start]))))) (reify ITransition (start-transition [this screen entities] @@ -1566,7 +1570,7 @@ void main () (transition-done? [this screen entities] (animation! (get-in entities [:inventory :anim]) :is-animation-finished - (- (:total-time screen) (get-in entities [:inventory :anim-start]))))) + (- ^double (:total-time screen) ^double (get-in entities [:inventory :anim-start]))))) (reify ITransition (start-transition [this screen entities] @@ -1633,7 +1637,7 @@ void main () (transition-done? [this screen entities] (animation! (get-in entities [:inventory :anim]) :is-animation-finished - (- (:total-time screen) (get-in entities [:inventory :anim-start]))))) + (- ^double (:total-time screen) ^double (get-in entities [:inventory :anim-start]))))) (appear-transition state-data :show :out) (reify ITransition @@ -1656,7 +1660,7 @@ void main () (transition-done? [this screen entities] (animation! (get-in entities [:inventory :anim]) :is-animation-finished - (- (:total-time screen) (get-in entities [:inventory :anim-start]))))) + (- ^double (:total-time screen) ^double (get-in entities [:inventory :anim-start]))))) (reify ITransition (start-transition [this screen entities] @@ -1675,7 +1679,7 @@ void main () (transition-done? [this screen entities] (animation! (get-in entities [:inventory :anim]) :is-animation-finished - (- (:total-time screen) (get-in entities [:inventory :anim-start]))))) + (- ^double (:total-time screen) ^double (get-in entities [:inventory :anim-start]))))) (appear-transition state-data :show :none) (reify ITransition