From 1e4546a906db3b692f3db222d326625ceabd39c5 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Tue, 9 Aug 2016 21:39:01 -0700 Subject: [PATCH] tons of memory reducers. --- android/project.clj | 4 +- desktop/project.clj | 2 +- desktop/src-common/advent/actions.clj | 2 +- desktop/src-common/advent/core.clj | 7 +- desktop/src-common/advent/screens/scene.clj | 88 ++++++++++++--------- 5 files changed, 60 insertions(+), 43 deletions(-) diff --git a/android/project.clj b/android/project.clj index 3c755529..4e96edd0 100644 --- a/android/project.clj +++ b/android/project.clj @@ -18,7 +18,7 @@ [play-clj "0.4.5-BRYCE"] [org.clojure/data.priority-map "0.0.5"] - [org.clojure/core.async "0.1.346.0-17112a-alpha"]] + [org.clojure/core.async "0.2.371"]] :plugins [[lein-droid "0.4.4-SNAPSHOT"]] @@ -28,7 +28,7 @@ :rename-manifest-package "advent.core.debug" :manifest-options {:app-name "ticks tales (debug)"} - :aot-exclude-ns [cljs.core.async.macros cljs.core.impl-ioc-macros cljs.core.impl.ioc_macros]}} + :aot-exclude-ns ["clojure.core.memoize" "core.async"]}} :release {:android {;; Specify the path to your private ;; keystore and the the alias of the diff --git a/desktop/project.clj b/desktop/project.clj index bba54845..fd983606 100644 --- a/desktop/project.clj +++ b/desktop/project.clj @@ -12,7 +12,7 @@ [play-clj "0.4.6-BRYCE"] [log4j/log4j "1.2.16"] [org.clojure/data.priority-map "0.0.5"] - [org.clojure/core.async "0.1.338.0-5c5012-alpha"] + [org.clojure/core.async "0.2.385"] [org.clojure/tools.logging "0.3.1"] [org.im4java/im4java "1.4.0"]] :source-paths ["src" "src-common"] diff --git a/desktop/src-common/advent/actions.clj b/desktop/src-common/advent/actions.clj index fb7317ed..981eb445 100644 --- a/desktop/src-common/advent/actions.clj +++ b/desktop/src-common/advent/actions.clj @@ -726,7 +726,7 @@ entities (if apply-state (apply-state screen entities) entities) - entities (utils/update-override screen entities)] + #_#_entities (utils/update-override screen entities)] (when (and (not= new-music old-music) transition-music?) (doseq [[k v] (:musics entities) :when (and v (not= new-music k))] diff --git a/desktop/src-common/advent/core.clj b/desktop/src-common/advent/core.clj index d2daf7ed..892ec83c 100644 --- a/desktop/src-common/advent/core.clj +++ b/desktop/src-common/advent/core.clj @@ -3,6 +3,7 @@ [play-clj.ui :refer :all] [play-clj.utils :refer :all] [play-clj.g2d :refer :all] + [advent.utils :as utils] [advent.screens.scene :as scene] [advent.screens.dialogue :as dialogue] [clojure.tools.logging :as log] @@ -10,6 +11,8 @@ [advent.screens.splash :as splash] [advent.screens.credits :as credits] [advent.screens.inventory :as inventory] + [advent.screens.safe :as safe] + [advent.screens.fade :as fade] [advent.steam :as steam] [clojure.pprint] [advent.pathfind]) @@ -29,7 +32,9 @@ (log/log-capture! *ns* :warn :error) (log/info "Starting game on version v" (advent.version/version)) (steam/init) - (set-screen! this splash/splash-screen))) + (reset! utils/selected-save {:name "Autosave", :id "autosave", :screenshot "saves/screenshot-autosave.png", :state {:y 74.0, :active? true, :coaxed-sheep? true, :seen-bloodclot? true, :seen-frankie? true, :plaques-read #{:sword :shovel}, :knows-about-stash? true, :safe-listen-count 2, :convinced-wizard? true, :time :night, :broke-lock? true, :wool-count 2, :opened-bars? true, :opened-crack? true, :inventory [:flask-water-ash :money :camera :alarm-clock :charcoal :note-1 :flies :spear :crowbar :key :sword :kiss :cat-toy :tune :flask-1-strength :medal :trophy :slingshot], :has-met-gandarf? true, :seen-intro? true, :has-seen-love? true, :has-dropped-coin? true, :wizard-left? false, :dropped-ball? true, :wants-monocle? true, :clues #{:name}, :bubba-gone? false, :hud-active? nil, :allowed-to-keep-teddy? true, :warden-sleeping? true, :current-riddle :done, :owl-tried-strength? true, :opened-blinds? true, :x 239.3914592899382, :warden-fast-asleep? true, :last-room :cat-tree, :wants-toy true, :bent-bars? true, :knows-owl-trouble? true, :chest-contents [], :mints-eaten 0, :object nil, :talked-to-owl? true, :obtained-items #{:balloon :money :flask-2 :tune :flask-1-with-cream-of-mushroom :key :flask-water-ash :slingshot :teddy :flies :recipe :mushrooms :rope :flask-1-with-milk :kiss :wool :portrait :slobber :spear :medal :sword :frog-legs :flask-1 :flask-1-strength :dream-sword :mandrake :walkie-talkies :shovel :ash :cat-toy :grass :camera :sack-lunch :stick :charcoal :ladder :carrot :trophy :monocle :alarm-clock :crowbar :note-1 :flask-1-slobber :glass-eye :flask-water :ball-n-chain}}, :blurb "Autosave"}) + (set-screen! @(resolve 'advent.core/advent) scene/scene #_scene/demo scene/hud dialogue/talking-screen dialogue/choice-screen dialogue/toast-screen inventory/inventory-screen safe/safe-screen fade/fade-screen + ))) (defn reload [] (on-gl (set-screen! advent title/title-screen))) diff --git a/desktop/src-common/advent/screens/scene.clj b/desktop/src-common/advent/screens/scene.clj index b6a986d6..3480aaed 100644 --- a/desktop/src-common/advent/screens/scene.clj +++ b/desktop/src-common/advent/screens/scene.clj @@ -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])