tons of memory reducers.

This commit is contained in:
Bryce Covert
2016-08-09 21:39:01 -07:00
parent 6eda69a1b8
commit 1e4546a906
5 changed files with 60 additions and 43 deletions

View File

@@ -18,7 +18,7 @@
[play-clj "0.4.5-BRYCE"] [play-clj "0.4.5-BRYCE"]
[org.clojure/data.priority-map "0.0.5"] [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"]] :plugins [[lein-droid "0.4.4-SNAPSHOT"]]
@@ -28,7 +28,7 @@
:rename-manifest-package "advent.core.debug" :rename-manifest-package "advent.core.debug"
:manifest-options {:app-name "ticks tales (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 :release {:android
{;; Specify the path to your private {;; Specify the path to your private
;; keystore and the the alias of the ;; keystore and the the alias of the

View File

@@ -12,7 +12,7 @@
[play-clj "0.4.6-BRYCE"] [play-clj "0.4.6-BRYCE"]
[log4j/log4j "1.2.16"] [log4j/log4j "1.2.16"]
[org.clojure/data.priority-map "0.0.5"] [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.clojure/tools.logging "0.3.1"]
[org.im4java/im4java "1.4.0"]] [org.im4java/im4java "1.4.0"]]
:source-paths ["src" "src-common"] :source-paths ["src" "src-common"]

View File

@@ -726,7 +726,7 @@
entities (if apply-state entities (if apply-state
(apply-state screen entities) (apply-state screen entities)
entities) entities)
entities (utils/update-override screen entities)] #_#_entities (utils/update-override screen entities)]
(when (and (not= new-music old-music) transition-music?) (when (and (not= new-music old-music) transition-music?)
(doseq [[k v] (:musics entities) (doseq [[k v] (:musics entities)
:when (and v (not= new-music k))] :when (and v (not= new-music k))]

View File

@@ -3,6 +3,7 @@
[play-clj.ui :refer :all] [play-clj.ui :refer :all]
[play-clj.utils :refer :all] [play-clj.utils :refer :all]
[play-clj.g2d :refer :all] [play-clj.g2d :refer :all]
[advent.utils :as utils]
[advent.screens.scene :as scene] [advent.screens.scene :as scene]
[advent.screens.dialogue :as dialogue] [advent.screens.dialogue :as dialogue]
[clojure.tools.logging :as log] [clojure.tools.logging :as log]
@@ -10,6 +11,8 @@
[advent.screens.splash :as splash] [advent.screens.splash :as splash]
[advent.screens.credits :as credits] [advent.screens.credits :as credits]
[advent.screens.inventory :as inventory] [advent.screens.inventory :as inventory]
[advent.screens.safe :as safe]
[advent.screens.fade :as fade]
[advent.steam :as steam] [advent.steam :as steam]
[clojure.pprint] [clojure.pprint]
[advent.pathfind]) [advent.pathfind])
@@ -29,7 +32,9 @@
(log/log-capture! *ns* :warn :error) (log/log-capture! *ns* :warn :error)
(log/info "Starting game on version v" (advent.version/version)) (log/info "Starting game on version v" (advent.version/version))
(steam/init) (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 [] (defn reload []
(on-gl (set-screen! advent title/title-screen))) (on-gl (set-screen! advent title/title-screen)))

View File

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