Clean up execution function
This commit is contained in:
@@ -47,43 +47,32 @@
|
|||||||
:as options}]
|
:as options}]
|
||||||
(let [screen (atom {})
|
(let [screen (atom {})
|
||||||
entities (atom '())
|
entities (atom '())
|
||||||
execute-fn! (fn [func screen-map]
|
execute-fn! (fn [func & {:keys [] :as options}]
|
||||||
(let [entities-list @entities]
|
(let [entities-list @entities]
|
||||||
(some->> (func screen-map entities-list)
|
(some->> (func (merge @screen options) entities-list)
|
||||||
list
|
list
|
||||||
flatten
|
flatten
|
||||||
(remove nil?)
|
(remove nil?)
|
||||||
(compare-and-set! entities entities-list))))
|
(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 %))
|
create-renderer-fn! #(swap! screen assoc :renderer (renderer %))
|
||||||
update-fn! #(swap! screen merge %)]
|
update-fn! #(swap! screen merge %)]
|
||||||
{:screen screen
|
{:screen screen
|
||||||
:entities entities
|
:entities entities
|
||||||
:show (fn []
|
:show (fn []
|
||||||
(->> (swap! screen assoc
|
(swap! screen assoc
|
||||||
:total-time 0
|
:total-time 0
|
||||||
:delta-time 0
|
:create-renderer-fn! create-renderer-fn!
|
||||||
:create-renderer-fn! create-renderer-fn!
|
:update-fn! update-fn!)
|
||||||
:update-fn! update-fn!)
|
(execute-fn! on-show))
|
||||||
(execute-fn! on-show)))
|
:render (fn [d]
|
||||||
:render (fn [delta-time]
|
(swap! screen #(assoc % :total-time (+ (:total-time %) d)))
|
||||||
(->> (fn [screen-map]
|
(execute-fn! on-render :delta-time d))
|
||||||
(assoc screen-map
|
:hide #(execute-fn! on-hide)
|
||||||
:total-time (+ (:total-time screen-map) delta-time)
|
:pause #(execute-fn! on-pause)
|
||||||
:delta-time delta-time))
|
:resize #(execute-fn! on-resize)
|
||||||
(swap! screen)
|
:resume #(execute-fn! on-resume)
|
||||||
(execute-fn! on-render)))
|
:input (input* options execute-fn!)
|
||||||
:hide #(execute-fn! on-hide @screen)
|
:gesture (gesture* options execute-fn!)}))
|
||||||
: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!)}))
|
|
||||||
|
|
||||||
(defmacro defscreen
|
(defmacro defscreen
|
||||||
[n & {:keys [] :as options}]
|
[n & {:keys [] :as options}]
|
||||||
|
|||||||
@@ -51,28 +51,28 @@
|
|||||||
execute-fn!]
|
execute-fn!]
|
||||||
(reify InputProcessor
|
(reify InputProcessor
|
||||||
(keyDown [this k]
|
(keyDown [this k]
|
||||||
(execute-fn! key-down {:keycode k})
|
(execute-fn! key-down :keycode k)
|
||||||
false)
|
false)
|
||||||
(keyTyped [this c]
|
(keyTyped [this c]
|
||||||
(execute-fn! key-typed {:character c})
|
(execute-fn! key-typed :character c)
|
||||||
false)
|
false)
|
||||||
(keyUp [this k]
|
(keyUp [this k]
|
||||||
(execute-fn! key-up {:keycode k})
|
(execute-fn! key-up :keycode k)
|
||||||
false)
|
false)
|
||||||
(mouseMoved [this sx sy]
|
(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)
|
false)
|
||||||
(scrolled [this a]
|
(scrolled [this a]
|
||||||
(execute-fn! scrolled {:amount a})
|
(execute-fn! scrolled :amount a)
|
||||||
false)
|
false)
|
||||||
(touchDown [this sx sy p b]
|
(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)
|
false)
|
||||||
(touchDragged [this sx sy p]
|
(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)
|
false)
|
||||||
(touchUp [this sx sy p b]
|
(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)))
|
false)))
|
||||||
|
|
||||||
(defmacro input
|
(defmacro input
|
||||||
@@ -87,28 +87,29 @@
|
|||||||
(let [listener
|
(let [listener
|
||||||
(reify GestureDetector$GestureListener
|
(reify GestureDetector$GestureListener
|
||||||
(fling [this vx vy b]
|
(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)
|
false)
|
||||||
(longPress [this x y]
|
(longPress [this x y]
|
||||||
(execute-fn! long-press {:x x :y y})
|
(execute-fn! long-press :x x :y y)
|
||||||
false)
|
false)
|
||||||
(pan [this x y dx dy]
|
(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)
|
false)
|
||||||
(panStop [this x y p b]
|
(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)
|
false)
|
||||||
(pinch [this ip1 ip2 p1 p2]
|
(pinch [this ip1 ip2 p1 p2]
|
||||||
(execute-fn! pinch {:initial-pointer-1 ip1 :initial-pointer-2 ip2
|
(execute-fn! pinch
|
||||||
:pointer1 p1 :pointer2 p2})
|
:initial-pointer-1 ip1 :initial-pointer-2 ip2
|
||||||
|
:pointer1 p1 :pointer2 p2)
|
||||||
false)
|
false)
|
||||||
(tap [this x y c b]
|
(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)
|
false)
|
||||||
(touchDown [this x y p b]
|
(touchDown [this x y p b]
|
||||||
false)
|
false)
|
||||||
(zoom [this id d]
|
(zoom [this id d]
|
||||||
(execute-fn! zoom {:initial-distance id :distance d})
|
(execute-fn! zoom :initial-distance id :distance d)
|
||||||
false))]
|
false))]
|
||||||
(proxy [GestureDetector] [listener])))
|
(proxy [GestureDetector] [listener])))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user