I believe this fixes the freezes.

This commit is contained in:
Bryce Covert
2015-08-14 21:01:55 -07:00
parent 6a5193e5dc
commit b8a97ad875
5 changed files with 45 additions and 29 deletions

View File

@@ -74,22 +74,31 @@
(terminate [this screen entities]
entities)
(skip-type [this screen entities]
:skip)))
:none-but-arrow)))
(defmacro get-script [entities & forms]
`(fn [starting-entities#]
(let [~entities (atom starting-entities#)]
(thread (do (change-script-state ~entities true)
~@forms
(change-script-state ~entities false)
(utils/save @~entities))))))
(put! (get-in starting-entities# [:actions :script-chan])
(fn [starting-entities#]
(let [~entities (atom starting-entities#)]
(thread (do
(try
~@forms
(finally
(change-script-state ~entities false)
(utils/save @~entities)
)))))))))
(defmacro get-unsaved-script [entities & forms]
`(fn [starting-entities#]
(let [~entities (atom starting-entities#)]
(thread (change-script-state ~entities true)
~@forms
(change-script-state ~entities false)))))
(put! (get-in starting-entities# [:actions :script-chan])
(fn [starting-entities#]
(let [~entities (atom starting-entities#)]
(thread (do
(try
~@forms
(finally
(change-script-state ~entities false))))))))))
(defn bound-to-camera [x length zoom]
(min (- length (* length 0.5 zoom ))

View File

@@ -164,9 +164,8 @@
(actions/has-item? entities :motivational-tapes) (do
(actions/remove-item entities :motivational-tapes)
(actions/do-dialogue entities
:frankie "And how about that? Some used earplugs."
:frankie "Wow! These are the choicest of earplugs!"
:frankie "They're great for tuning out your voice, Dipstick!"
:frankie "And how about that? Some motivational tapes"
:frankie "Wow! These are the choicest of motivational tapes!"
:frankie "But, I could fetch some real good dough for them."
:frankie "What would you say boys? ")
(actions/play-animation entities :frankie :glance)

View File

@@ -626,9 +626,11 @@
(actions/talk entities :ego "I guess her wool is shedding.")
(leave-sheep entities))
(do
(walk-to-sheep entities)
(actions/talk entities :ego "Come here mama sheep!")
(actions/play-animation entities :ego :sigh)
(actions/talk entities :ego "She's too far away for me to pet her.")))))
(actions/talk entities :ego "She's too far away for me to pet her.")
(leave-sheep entities)))))
:scripts #(condp = %
:wool (actions/get-script entities
(actions/talk entities :ego "She doesn't need it back."))

View File

@@ -35,7 +35,7 @@
[advent.screens.rooms.cat-tree :as rooms.cat-tree]
[advent.screens.dialogue :refer [talking-screen]]
[advent.screens.inventory :refer [inventory-screen]]
[clojure.core.async :refer [put! <! <!! >! chan go thread take! alts!!]])
[clojure.core.async :refer [put! <! <!! >! chan go thread take! alts!! dropping-buffer]])
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter GL20 GL30]
[com.badlogic.gdx.graphics.g2d TextureRegion Animation Batch]
[com.badlogic.gdx.math Vector3 Matrix4]
@@ -232,6 +232,7 @@ void main()
(= :end (actions/skip-type current-action screen entities))
(let [terminated-entities (actions/terminate current-action screen entities)]
(println "trying to end")
(do (put! (actions/get-channel current-action) :end)
(-> terminated-entities
(assoc-in [:actions :script-running?] false)
@@ -647,7 +648,18 @@ void main()
(merge (animation->texture screen (:stand (:right ego))) ego)
:stand)))
(defn update-from-script [screen {{:keys [current started? channel]} :actions :as entities}]
(defn start-script-if-necessary [screen {{:keys [script-running? script-chan]} :actions :as entities}]
(if script-running?
entities
(let [[next-script] (alts!! [script-chan] :default nil)]
(if next-script
(do
(next-script entities)
(println "starting script")
(assoc-in entities [:actions :script-running?] true))
entities))))
(defn update-from-script [screen {{:keys [current started? channel script-chan]} :actions :as entities}]
(if current
(let [entities (if started? entities (actions/begin current screen entities))
entities (actions/continue current screen entities)]
@@ -655,10 +667,10 @@ void main()
(let [terminated (actions/terminate current screen entities)]
(put! (actions/get-channel current) terminated)
(recur screen (assoc terminated
:actions {:channel channel :current nil :started? false :script-running? (get-in entities [:actions :script-running?]) :last-skip-type (get-in entities [:actions :last-skip-type])})))
:actions {:channel channel :script-chan (get-in entities [:actions :script-chan]) :current nil :started? false :script-running? (get-in entities [:actions :script-running?]) :last-skip-type (get-in entities [:actions :last-skip-type])})))
(assoc-in entities [:actions :started?] true)))
(let [[current _] (alts!! [channel] :default nil)]
(assoc entities :actions {:channel channel :current current :started? false :script-running? (get-in entities [:actions :script-running?]) :last-skip-type (if current
(assoc entities :actions {:script-chan (get-in entities [:actions :script-chan]) :channel channel :current current :started? false :script-running? (get-in entities [:actions :script-running?]) :last-skip-type (if current
(actions/skip-type current screen entities)
(get-in entities [:actions :last-skip-type]))}))))
@@ -898,7 +910,8 @@ void main()
:channel (chan)
:current nil
:script-running? false
:started? false}
:started? false
:script-chan (chan (dropping-buffer 1))}
:volume {:object nil
:value 0.0}
:music-override {:object nil
@@ -930,7 +943,6 @@ void main()
:on-render
(fn [{:keys [camera] :as screen} [entities]]
(if (get-in entities [:closing? :value])
(let [entities (utils/apply-tweens screen entities (:tweens entities))
@@ -944,6 +956,7 @@ void main()
(let [entities (fade-in-first-time-if-necessary screen entities)
entities (utils/apply-tweens screen entities (:tweens entities))
entities (update-cursor screen entities)
entities (start-script-if-necessary screen entities)
entities (update-from-script screen entities)
entities (update-from-room screen entities)
entities (update-from-hotspots screen entities)
@@ -1025,8 +1038,8 @@ void main()
:on-touch-up (fn [{:keys [input-x input-y viewport] :as screen} [entities]]
(when (utils/contains-point? (.getScreenX viewport) (.getScreenY viewport)
(.getScreenWidth viewport) (.getScreenHeight viewport)
input-x input-y)
(.getScreenWidth viewport) (.getScreenHeight viewport)
input-x input-y)
(if (= (button-code :right)
(:button screen))
(assoc-in entities [:cursor :current] :main)