From aa5cb1f2f7736669d965db536330904467ff03c5 Mon Sep 17 00:00:00 2001 From: = Date: Fri, 12 Sep 2014 17:54:41 -0700 Subject: [PATCH] performance enhancement. --- desktop/src-common/advent/actions.clj | 16 ++++++++++------ desktop/src-common/advent/pathfind.clj | 1 + 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/desktop/src-common/advent/actions.clj b/desktop/src-common/advent/actions.clj index c799c3b2..c0fc2358 100644 --- a/desktop/src-common/advent/actions.clj +++ b/desktop/src-common/advent/actions.clj @@ -66,9 +66,12 @@ ;; function for an action (let [initial-time (atom nil)] (fn [screen entities] - (swap! initial-time #(or % (:total-time screen))) - (let [target-y (get-in entities [target-id :y]) + + (let [ + begin? (not@initial-time) + _ (swap! initial-time #(or % (:total-time screen))) + target-y (get-in entities [target-id :y]) scale-fn (get-in entities [:background :scale-fn]) scale (scale-fn target-y) height (* scale 36) @@ -80,8 +83,9 @@ (run! dialogue/talking-screen :stop-talk :target-id target-id) (update-in entities [target-id :actions] rest)) (do - (run! dialogue/talking-screen :on-talk :text text - :x (get-in entities [target-id :x]) :y (+ (get-in entities [target-id :y]) height) - :target-id target-id - :scale scale) + (when begin? + (run! dialogue/talking-screen :on-talk :text text + :x (get-in entities [target-id :x]) :y (+ (get-in entities [target-id :y]) height) + :target-id target-id + :scale scale)) (assoc-in entities [target-id :anim] (get-in entities [target-id :talk])))))))) diff --git a/desktop/src-common/advent/pathfind.clj b/desktop/src-common/advent/pathfind.clj index de06495d..4979bca2 100644 --- a/desktop/src-common/advent/pathfind.clj +++ b/desktop/src-common/advent/pathfind.clj @@ -65,6 +65,7 @@ (conj path (from-scale current-node)) (came-from (vec current-node)))))))) + (def d2 ^double (- (Math/sqrt 2) 2)) (defn heuristic ^long [^long goal-x ^long goal-y ^long current-x ^long current-y] (let [dist-x (if (< goal-x current-x)