From f2a107816758430fb56ace15ff71d30299f2e3b7 Mon Sep 17 00:00:00 2001 From: oakes Date: Fri, 10 Jan 2014 14:21:37 -0500 Subject: [PATCH] Clean up execution function --- src/play_clj/core.clj | 43 ++++++++++++++---------------------- src/play_clj/core_global.clj | 33 +++++++++++++-------------- 2 files changed, 33 insertions(+), 43 deletions(-) diff --git a/src/play_clj/core.clj b/src/play_clj/core.clj index a5d110a..de77267 100644 --- a/src/play_clj/core.clj +++ b/src/play_clj/core.clj @@ -47,43 +47,32 @@ :as options}] (let [screen (atom {}) entities (atom '()) - execute-fn! (fn [func screen-map] + execute-fn! (fn [func & {:keys [] :as options}] (let [entities-list @entities] - (some->> (func screen-map entities-list) + (some->> (func (merge @screen options) entities-list) list flatten (remove nil?) (compare-and-set! entities entities-list)))) - execute-priority-fn! (fn [func options] - (some->> (func (merge @screen options) @entities) - list - flatten - (remove nil?) - (reset! entities))) create-renderer-fn! #(swap! screen assoc :renderer (renderer %)) update-fn! #(swap! screen merge %)] {:screen screen :entities entities :show (fn [] - (->> (swap! screen assoc - :total-time 0 - :delta-time 0 - :create-renderer-fn! create-renderer-fn! - :update-fn! update-fn!) - (execute-fn! on-show))) - :render (fn [delta-time] - (->> (fn [screen-map] - (assoc screen-map - :total-time (+ (:total-time screen-map) delta-time) - :delta-time delta-time)) - (swap! screen) - (execute-fn! on-render))) - :hide #(execute-fn! on-hide @screen) - :pause #(execute-fn! on-pause @screen) - :resize #(execute-fn! on-resize @screen) - :resume #(execute-fn! on-resume @screen) - :input (input* options execute-priority-fn!) - :gesture (gesture* options execute-priority-fn!)})) + (swap! screen assoc + :total-time 0 + :create-renderer-fn! create-renderer-fn! + :update-fn! update-fn!) + (execute-fn! on-show)) + :render (fn [d] + (swap! screen #(assoc % :total-time (+ (:total-time %) d))) + (execute-fn! on-render :delta-time d)) + :hide #(execute-fn! on-hide) + :pause #(execute-fn! on-pause) + :resize #(execute-fn! on-resize) + :resume #(execute-fn! on-resume) + :input (input* options execute-fn!) + :gesture (gesture* options execute-fn!)})) (defmacro defscreen [n & {:keys [] :as options}] diff --git a/src/play_clj/core_global.clj b/src/play_clj/core_global.clj index ecfa4d0..05778b9 100644 --- a/src/play_clj/core_global.clj +++ b/src/play_clj/core_global.clj @@ -51,28 +51,28 @@ execute-fn!] (reify InputProcessor (keyDown [this k] - (execute-fn! key-down {:keycode k}) + (execute-fn! key-down :keycode k) false) (keyTyped [this c] - (execute-fn! key-typed {:character c}) + (execute-fn! key-typed :character c) false) (keyUp [this k] - (execute-fn! key-up {:keycode k}) + (execute-fn! key-up :keycode k) false) (mouseMoved [this sx sy] - (execute-fn! mouse-moved {:screen-x sx :screen-y sy}) + (execute-fn! mouse-moved :screen-x sx :screen-y sy) false) (scrolled [this a] - (execute-fn! scrolled {:amount a}) + (execute-fn! scrolled :amount a) false) (touchDown [this sx sy p b] - (execute-fn! touch-down {:screen-x sx :screen-y sy :pointer p :button b}) + (execute-fn! touch-down :screen-x sx :screen-y sy :pointer p :button b) false) (touchDragged [this sx sy p] - (execute-fn! touch-dragged {:screen-x sx :screen-y sy :pointer p}) + (execute-fn! touch-dragged :screen-x sx :screen-y sy :pointer p) false) (touchUp [this sx sy p b] - (execute-fn! touch-up {:screen-x sx :screen-y sy :pointer p :button b}) + (execute-fn! touch-up :screen-x sx :screen-y sy :pointer p :button b) false))) (defmacro input @@ -87,28 +87,29 @@ (let [listener (reify GestureDetector$GestureListener (fling [this vx vy b] - (execute-fn! fling {:velocity-x vx :velocity-y vy :button b}) + (execute-fn! fling :velocity-x vx :velocity-y vy :button b) false) (longPress [this x y] - (execute-fn! long-press {:x x :y y}) + (execute-fn! long-press :x x :y y) false) (pan [this x y dx dy] - (execute-fn! pan {:x x :y y :delta-x dx :delta-y dy}) + (execute-fn! pan :x x :y y :delta-x dx :delta-y dy) false) (panStop [this x y p b] - (execute-fn! pan-stop {:x x :y y :pointer p :button b}) + (execute-fn! pan-stop :x x :y y :pointer p :button b) false) (pinch [this ip1 ip2 p1 p2] - (execute-fn! pinch {:initial-pointer-1 ip1 :initial-pointer-2 ip2 - :pointer1 p1 :pointer2 p2}) + (execute-fn! pinch + :initial-pointer-1 ip1 :initial-pointer-2 ip2 + :pointer1 p1 :pointer2 p2) false) (tap [this x y c b] - (execute-fn! tap {:x x :y y :count c :button b}) + (execute-fn! tap :x x :y y :count c :button b) false) (touchDown [this x y p b] false) (zoom [this id d] - (execute-fn! zoom {:initial-distance id :distance d}) + (execute-fn! zoom :initial-distance id :distance d) false))] (proxy [GestureDetector] [listener])))