making stuff a tiny bit faster.
This commit is contained in:
@@ -46,11 +46,7 @@
|
|||||||
|
|
||||||
(defn ^:private normalize
|
(defn ^:private normalize
|
||||||
[entities]
|
[entities]
|
||||||
(some->> entities
|
entities)
|
||||||
list
|
|
||||||
flatten
|
|
||||||
(remove nil?)
|
|
||||||
vec))
|
|
||||||
|
|
||||||
(defn ^:private wrapper
|
(defn ^:private wrapper
|
||||||
[screen-atom screen-fn]
|
[screen-atom screen-fn]
|
||||||
@@ -76,16 +72,19 @@
|
|||||||
[screen entities
|
[screen entities
|
||||||
{:keys [on-show on-render on-hide on-pause on-resize on-resume on-timer]
|
{:keys [on-show on-render on-hide on-pause on-resize on-resume on-timer]
|
||||||
:as options}]
|
:as options}]
|
||||||
(let [execute-fn! (fn [func & {:keys [] :as options}]
|
(let [execute-fn! (fn exec
|
||||||
(when func
|
([func]
|
||||||
(let [screen-map (merge @screen options)
|
(exec func {}))
|
||||||
old-entities @entities]
|
([func options]
|
||||||
(some->> (with-meta
|
(when func
|
||||||
#(normalize (func screen-map old-entities))
|
(let [screen-map (merge @screen options)
|
||||||
(meta func))
|
old-entities @entities]
|
||||||
(wrapper screen)
|
(some->> (with-meta
|
||||||
(reset-changed! entities old-entities)
|
#(normalize (func screen-map old-entities))
|
||||||
(update-screen! @screen)))))
|
(meta func))
|
||||||
|
(wrapper screen)
|
||||||
|
(reset-changed! entities old-entities)
|
||||||
|
(update-screen! @screen))))))
|
||||||
execute-fn-on-gl! (fn [& args]
|
execute-fn-on-gl! (fn [& args]
|
||||||
(on-gl (apply execute-fn! args)))
|
(on-gl (apply execute-fn! args)))
|
||||||
update-fn! (fn [func & args]
|
update-fn! (fn [func & args]
|
||||||
@@ -118,12 +117,11 @@
|
|||||||
update-screen!))
|
update-screen!))
|
||||||
:render (fn [d]
|
:render (fn [d]
|
||||||
(swap! screen update-in [:total-time] #(+ (or %1 0) %2) d)
|
(swap! screen update-in [:total-time] #(+ (or %1 0) %2) d)
|
||||||
(some->> (execute-fn! on-render :delta-time d)
|
(execute-fn! on-render (assoc @screen :delta-time d)))
|
||||||
(add-to-timeline! screen)))
|
|
||||||
:hide #(execute-fn! on-hide)
|
:hide #(execute-fn! on-hide)
|
||||||
:pause #(execute-fn! on-pause)
|
:pause #(execute-fn! on-pause)
|
||||||
:resize (fn [w h]
|
:resize (fn [w h]
|
||||||
(execute-fn! on-resize :width w :height h)
|
(execute-fn! on-resize {:width w :height h})
|
||||||
(update-screen! @screen))
|
(update-screen! @screen))
|
||||||
:resume #(execute-fn! on-resume)}))
|
:resume #(execute-fn! on-resume)}))
|
||||||
|
|
||||||
@@ -488,7 +486,7 @@ keywords and functions in pairs."
|
|||||||
(intern *ns* map-sym# (atom {}))))
|
(intern *ns* map-sym# (atom {}))))
|
||||||
entities-sym# (symbol (str '~n "-entities"))
|
entities-sym# (symbol (str '~n "-entities"))
|
||||||
entities# (deref (or (resolve entities-sym#)
|
entities# (deref (or (resolve entities-sym#)
|
||||||
(intern *ns* entities-sym# (atom []))))]
|
(intern *ns* entities-sym# (atom {}))))]
|
||||||
(def ~n (defscreen* screen# entities# fn-syms#))))
|
(def ~n (defscreen* screen# entities# fn-syms#))))
|
||||||
|
|
||||||
(defn defgame*
|
(defn defgame*
|
||||||
@@ -559,6 +557,7 @@ is the atom storing the screen map behind the scenes. Returns the updated
|
|||||||
|
|
||||||
(update! screen :renderer (stage))"
|
(update! screen :renderer (stage))"
|
||||||
[screen & args]
|
[screen & args]
|
||||||
|
(println screen)
|
||||||
(doto (apply (:update-fn! screen) assoc args)
|
(doto (apply (:update-fn! screen) assoc args)
|
||||||
update-screen!))
|
update-screen!))
|
||||||
|
|
||||||
@@ -568,8 +567,8 @@ of key-value pairs, which will be given to the function via its screen map.
|
|||||||
|
|
||||||
(screen! my-other-screen :on-show)
|
(screen! my-other-screen :on-show)
|
||||||
(screen! my-other-screen :on-change-color :color :blue)"
|
(screen! my-other-screen :on-change-color :color :blue)"
|
||||||
[screen-object fn-name & options]
|
[screen-object fn-name options]
|
||||||
(let [execute-fn! (:execute-fn! screen-object)
|
(let [execute-fn! (:execute-fn! screen-object)
|
||||||
screen-fn (-> screen-object :options (get fn-name))]
|
screen-fn (-> screen-object :options (get fn-name))]
|
||||||
(apply execute-fn! screen-fn options)
|
(execute-fn! screen-fn options)
|
||||||
nil))
|
nil))
|
||||||
|
|||||||
@@ -8,28 +8,28 @@
|
|||||||
execute-fn!]
|
execute-fn!]
|
||||||
(reify InputProcessor
|
(reify InputProcessor
|
||||||
(keyDown [this k]
|
(keyDown [this k]
|
||||||
(execute-fn! on-key-down :key k)
|
(execute-fn! on-key-down {:key k})
|
||||||
false)
|
false)
|
||||||
(keyTyped [this c]
|
(keyTyped [this c]
|
||||||
(execute-fn! on-key-typed :character c)
|
(execute-fn! on-key-typed {:character c})
|
||||||
false)
|
false)
|
||||||
(keyUp [this k]
|
(keyUp [this k]
|
||||||
(execute-fn! on-key-up :key k)
|
(execute-fn! on-key-up {:key k})
|
||||||
false)
|
false)
|
||||||
(mouseMoved [this sx sy]
|
(mouseMoved [this sx sy]
|
||||||
(execute-fn! on-mouse-moved :input-x sx :input-y sy)
|
(execute-fn! on-mouse-moved {:input-x sx :input-y sy})
|
||||||
false)
|
false)
|
||||||
(scrolled [this a]
|
(scrolled [this a]
|
||||||
(execute-fn! on-scrolled :amount a)
|
(execute-fn! on-scrolled {:amount a})
|
||||||
false)
|
false)
|
||||||
(touchDown [this sx sy p b]
|
(touchDown [this sx sy p b]
|
||||||
(execute-fn! on-touch-down :input-x sx :input-y sy :pointer p :button b)
|
(execute-fn! on-touch-down {:input-x sx :input-y sy :pointer p :button b})
|
||||||
false)
|
false)
|
||||||
(touchDragged [this sx sy p]
|
(touchDragged [this sx sy p]
|
||||||
(execute-fn! on-touch-dragged :input-x sx :input-y sy :pointer p)
|
(execute-fn! on-touch-dragged {:input-x sx :input-y sy :pointer p})
|
||||||
false)
|
false)
|
||||||
(touchUp [this sx sy p b]
|
(touchUp [this sx sy p b]
|
||||||
(execute-fn! on-touch-up :input-x sx :input-y sy :pointer p :button b)
|
(execute-fn! on-touch-up {:input-x sx :input-y sy :pointer p :button b})
|
||||||
false)))
|
false)))
|
||||||
|
|
||||||
(defmacro input-processor!
|
(defmacro input-processor!
|
||||||
@@ -45,29 +45,29 @@ in the `screen`."
|
|||||||
execute-fn!]
|
execute-fn!]
|
||||||
(reify GestureDetector$GestureListener
|
(reify GestureDetector$GestureListener
|
||||||
(fling [this vx vy b]
|
(fling [this vx vy b]
|
||||||
(execute-fn! on-fling :velocity-x vx :velocity-y vy :button b)
|
(execute-fn! on-fling {:velocity-x vx :velocity-y vy :button b})
|
||||||
(some? on-fling))
|
(some? on-fling))
|
||||||
(longPress [this x y]
|
(longPress [this x y]
|
||||||
(execute-fn! on-long-press :input-x x :input-y y)
|
(execute-fn! on-long-press {:input-x x :input-y y})
|
||||||
(some? on-long-press))
|
(some? on-long-press))
|
||||||
(pan [this x y dx dy]
|
(pan [this x y dx dy]
|
||||||
(execute-fn! on-pan :input-x x :input-y y :delta-x dx :delta-y dy)
|
(execute-fn! on-pan {:input-x x :input-y y :delta-x dx :delta-y dy})
|
||||||
(some? on-pan))
|
(some? on-pan))
|
||||||
(panStop [this x y p b]
|
(panStop [this x y p b]
|
||||||
(execute-fn! on-pan-stop :input-x x :input-y y :pointer p :button b)
|
(execute-fn! on-pan-stop {:input-x x :input-y y :pointer p :button b})
|
||||||
(some? on-pan-stop))
|
(some? on-pan-stop))
|
||||||
(pinch [this ip1 ip2 p1 p2]
|
(pinch [this ip1 ip2 p1 p2]
|
||||||
(execute-fn! on-pinch
|
(execute-fn! on-pinch
|
||||||
:initial-pointer-1 ip1 :initial-pointer-2 ip2
|
{:initial-pointer-1 ip1 :initial-pointer-2 ip2
|
||||||
:pointer-1 p1 :pointer-2 p2)
|
:pointer-1 p1 :pointer-2 p2})
|
||||||
(some? on-pinch))
|
(some? on-pinch))
|
||||||
(tap [this x y c b]
|
(tap [this x y c b]
|
||||||
(execute-fn! on-tap :input-x x :input-y y :count c :button b)
|
(execute-fn! on-tap {:input-x x :input-y y :count c :button b})
|
||||||
(some? on-tap))
|
(some? on-tap))
|
||||||
(touchDown [this x y p b]
|
(touchDown [this x y p b]
|
||||||
false)
|
false)
|
||||||
(zoom [this id d]
|
(zoom [this id d]
|
||||||
(execute-fn! on-zoom :initial-distance id :distance d)
|
(execute-fn! on-zoom {:initial-distance id :distance d})
|
||||||
(some? on-zoom))))
|
(some? on-zoom))))
|
||||||
|
|
||||||
(defn ^:private gesture-detector
|
(defn ^:private gesture-detector
|
||||||
@@ -96,30 +96,30 @@ in the `screen`."
|
|||||||
(proxy [ActorGestureListener] []
|
(proxy [ActorGestureListener] []
|
||||||
(fling [e vx vy b]
|
(fling [e vx vy b]
|
||||||
(execute-fn! on-ui-fling
|
(execute-fn! on-ui-fling
|
||||||
:event e :velocity-x vx :velocity-y vy :button b))
|
{:event e :velocity-x vx :velocity-y vy :button b}))
|
||||||
(longPress [a x y]
|
(longPress [a x y]
|
||||||
(execute-fn! on-ui-long-press :actor a :input-x x :input-y y)
|
(execute-fn! on-ui-long-press {:actor a :input-x x :input-y y})
|
||||||
(some? on-ui-long-press))
|
(some? on-ui-long-press))
|
||||||
(pan [e x y dx dy]
|
(pan [e x y dx dy]
|
||||||
(execute-fn! on-ui-pan
|
(execute-fn! on-ui-pan
|
||||||
:event e :input-x x :input-y y :delta-x dx :delta-y dy))
|
{ :event e :input-x x :input-y y :delta-x dx :delta-y dy}))
|
||||||
(pinch [e ip1 ip2 p1 p2]
|
(pinch [e ip1 ip2 p1 p2]
|
||||||
(execute-fn! on-ui-pinch
|
(execute-fn! on-ui-pinch
|
||||||
:event e :initial-pointer-1 ip1 :initial-pointer-2 ip2
|
{ :event e :initial-pointer-1 ip1 :initial-pointer-2 ip2
|
||||||
:pointer1 p1 :pointer2 p2))
|
:pointer1 p1 :pointer2 p2}))
|
||||||
(tap [e x y p b]
|
(tap [e x y p b]
|
||||||
(execute-fn! on-ui-tap
|
(execute-fn! on-ui-tap
|
||||||
:event e :input-x x :input-y y :pointer p :button b))
|
{ :event e :input-x x :input-y y :pointer p :button b}))
|
||||||
;(touchDown [e x y p b])
|
;(touchDown [e x y p b])
|
||||||
;(touchUp [e x y p b])
|
;(touchUp [e x y p b])
|
||||||
(zoom [e id d]
|
(zoom [e id d]
|
||||||
(execute-fn! on-ui-zoom :event e :initial-distance id :distance d))))
|
(execute-fn! on-ui-zoom { :event e :initial-distance id :distance d}))))
|
||||||
|
|
||||||
(defn ^:private change-listener
|
(defn ^:private change-listener
|
||||||
[{:keys [on-ui-changed]} execute-fn!]
|
[{:keys [on-ui-changed]} execute-fn!]
|
||||||
(proxy [ChangeListener] []
|
(proxy [ChangeListener] []
|
||||||
(changed [e a]
|
(changed [e a]
|
||||||
(execute-fn! on-ui-changed :event e :actor a))))
|
(execute-fn! on-ui-changed { :event e :actor a}))))
|
||||||
|
|
||||||
(defn ^:private click-listener
|
(defn ^:private click-listener
|
||||||
[{:keys [on-ui-clicked on-ui-enter on-ui-exit
|
[{:keys [on-ui-clicked on-ui-enter on-ui-exit
|
||||||
@@ -127,23 +127,23 @@ in the `screen`."
|
|||||||
execute-fn!]
|
execute-fn!]
|
||||||
(proxy [ClickListener] []
|
(proxy [ClickListener] []
|
||||||
(clicked [e x y]
|
(clicked [e x y]
|
||||||
(execute-fn! on-ui-clicked :event e :input-x x :input-y y))
|
(execute-fn! on-ui-clicked { :event e :input-x x :input-y y}))
|
||||||
(enter [e x y p a]
|
(enter [e x y p a]
|
||||||
(execute-fn! on-ui-enter
|
(execute-fn! on-ui-enter
|
||||||
:event e :input-x x :input-y y :pointer p :actor a))
|
{ :event e :input-x x :input-y y :pointer p :actor a}))
|
||||||
(exit [e x y p a]
|
(exit [e x y p a]
|
||||||
(execute-fn! on-ui-exit
|
(execute-fn! on-ui-exit
|
||||||
:event e :input-x x :input-y y :pointer p :actor a))
|
{ :event e :input-x x :input-y y :pointer p :actor a}))
|
||||||
(touchDown [e x y p b]
|
(touchDown [e x y p b]
|
||||||
(execute-fn! on-ui-touch-down
|
(execute-fn! on-ui-touch-down
|
||||||
:event e :input-x x :input-y y :pointer p :button b)
|
{ :event e :input-x x :input-y y :pointer p :button b})
|
||||||
(some? on-ui-touch-down))
|
(some? on-ui-touch-down))
|
||||||
(touchDragged [e x y p]
|
(touchDragged [e x y p]
|
||||||
(execute-fn! on-ui-touch-dragged
|
(execute-fn! on-ui-touch-dragged
|
||||||
:event e :input-x x :input-y y :pointer p))
|
{ :event e :input-x x :input-y y :pointer p}))
|
||||||
(touchUp [e x y p b]
|
(touchUp [e x y p b]
|
||||||
(execute-fn! on-ui-touch-up
|
(execute-fn! on-ui-touch-up
|
||||||
:event e :input-x x :input-y y :pointer p :button b))))
|
{ :event e :input-x x :input-y y :pointer p :button b}))))
|
||||||
|
|
||||||
(defn ^:private drag-listener
|
(defn ^:private drag-listener
|
||||||
[{:keys [on-ui-drag on-ui-drag-start on-ui-drag-stop]}
|
[{:keys [on-ui-drag on-ui-drag-start on-ui-drag-stop]}
|
||||||
@@ -153,20 +153,20 @@ in the `screen`."
|
|||||||
;(touchDragged [e x y p])
|
;(touchDragged [e x y p])
|
||||||
;(touchUp [e x y p b])
|
;(touchUp [e x y p b])
|
||||||
(drag [e x y p]
|
(drag [e x y p]
|
||||||
(execute-fn! on-ui-drag :event e :input-x x :input-y y :pointer p))
|
(execute-fn! on-ui-drag { :event e :input-x x :input-y y :pointer p}))
|
||||||
(dragStart [e x y p]
|
(dragStart [e x y p]
|
||||||
(execute-fn! on-ui-drag-start :event e :input-x x :input-y y :pointer p))
|
(execute-fn! on-ui-drag-start { :event e :input-x x :input-y y :pointer p}))
|
||||||
(dragStop [e x y p]
|
(dragStop [e x y p]
|
||||||
(execute-fn! on-ui-drag-stop :event e :input-x x :input-y y :pointer p))))
|
(execute-fn! on-ui-drag-stop { :event e :input-x x :input-y y :pointer p}))))
|
||||||
|
|
||||||
(defn ^:private focus-listener
|
(defn ^:private focus-listener
|
||||||
[{:keys [on-ui-keyboard-focus-changed on-ui-scroll-focus-changed]}
|
[{:keys [on-ui-keyboard-focus-changed on-ui-scroll-focus-changed]}
|
||||||
execute-fn!]
|
execute-fn!]
|
||||||
(proxy [FocusListener] []
|
(proxy [FocusListener] []
|
||||||
(keyboardFocusChanged [e a f]
|
(keyboardFocusChanged [e a f]
|
||||||
(execute-fn! on-ui-keyboard-focus-changed :event e :actor a :focused? f))
|
(execute-fn! on-ui-keyboard-focus-changed { :event e :actor a :focused? f}))
|
||||||
(scrollFocusChanged [e a f]
|
(scrollFocusChanged [e a f]
|
||||||
(execute-fn! on-ui-scroll-focus-changed :event e :actor a :focused? f))))
|
(execute-fn! on-ui-scroll-focus-changed { :event e :actor a :focused? f}))))
|
||||||
|
|
||||||
(defn ^:private ui-listeners
|
(defn ^:private ui-listeners
|
||||||
[options execute-fn!]
|
[options execute-fn!]
|
||||||
@@ -190,7 +190,7 @@ in the `screen`."
|
|||||||
(doto (.getViewport renderer)
|
(doto (.getViewport renderer)
|
||||||
(.setCamera camera)
|
(.setCamera camera)
|
||||||
(.setWorldSize (. camera viewportWidth) (. camera viewportHeight)))))
|
(.setWorldSize (. camera viewportWidth) (. camera viewportHeight)))))
|
||||||
([{:keys [^Stage renderer ui-listeners]} [entities]]
|
([{:keys [^Stage renderer ui-listeners]} entities]
|
||||||
(let [actor-set (->> entities
|
(let [actor-set (->> entities
|
||||||
vals
|
vals
|
||||||
(map :object)
|
(map :object)
|
||||||
@@ -206,7 +206,7 @@ in the `screen`."
|
|||||||
(add-input! renderer))))
|
(add-input! renderer))))
|
||||||
|
|
||||||
(defmulti update-physics!
|
(defmulti update-physics!
|
||||||
(fn [screen & [entities]] (some-> screen :world class .getName))
|
(fn [screen & entities] (some-> screen :world class .getName))
|
||||||
:default nil)
|
:default nil)
|
||||||
|
|
||||||
(defmethod update-physics! nil [_ & _])
|
(defmethod update-physics! nil [_ & _])
|
||||||
|
|||||||
@@ -116,7 +116,7 @@ entities vector."
|
|||||||
[{:keys [execute-fn! on-timer]} id]
|
[{:keys [execute-fn! on-timer]} id]
|
||||||
(proxy [Timer$Task] []
|
(proxy [Timer$Task] []
|
||||||
(run []
|
(run []
|
||||||
(execute-fn! on-timer :id id))))
|
(execute-fn! on-timer {:id id}))))
|
||||||
|
|
||||||
(defn ^:private timer*
|
(defn ^:private timer*
|
||||||
[]
|
[]
|
||||||
|
|||||||
@@ -44,7 +44,7 @@
|
|||||||
(-> ^Pixmap arg Texture. TextureRegion.)
|
(-> ^Pixmap arg Texture. TextureRegion.)
|
||||||
(instance? Texture arg)
|
(instance? Texture arg)
|
||||||
(-> ^Texture arg TextureRegion.)
|
(-> ^Texture arg TextureRegion.)
|
||||||
(instance? TextureEntity )
|
(instance? TextureEntity arg)
|
||||||
(-> ^TextureRegion (:object arg) TextureRegion.)
|
(-> ^TextureRegion (:object arg) TextureRegion.)
|
||||||
:else
|
:else
|
||||||
arg)))
|
arg)))
|
||||||
|
|||||||
@@ -228,13 +228,13 @@ such as :on-begin-contact."
|
|||||||
execute-fn!]
|
execute-fn!]
|
||||||
(reify ContactListener
|
(reify ContactListener
|
||||||
(beginContact [this c]
|
(beginContact [this c]
|
||||||
(execute-fn! on-begin-contact :contact c))
|
(execute-fn! on-begin-contact { :contact c}))
|
||||||
(endContact [this c]
|
(endContact [this c]
|
||||||
(execute-fn! on-end-contact :contact c))
|
(execute-fn! on-end-contact { :contact c}))
|
||||||
(postSolve [this c i]
|
(postSolve [this c i]
|
||||||
(execute-fn! on-post-solve :contact c :impulse i))
|
(execute-fn! on-post-solve { :contact c :impulse i}))
|
||||||
(preSolve [this c m]
|
(preSolve [this c m]
|
||||||
(execute-fn! on-pre-solve :contact c :old-manifold m))))
|
(execute-fn! on-pre-solve { :contact c :old-manifold m}))))
|
||||||
|
|
||||||
(defmethod c/update-physics!
|
(defmethod c/update-physics!
|
||||||
"com.badlogic.gdx.physics.box2d.World"
|
"com.badlogic.gdx.physics.box2d.World"
|
||||||
|
|||||||
@@ -273,9 +273,9 @@ such as :on-begin-contact."
|
|||||||
execute-fn!]
|
execute-fn!]
|
||||||
(ContactListener3D.
|
(ContactListener3D.
|
||||||
(fn [a b]
|
(fn [a b]
|
||||||
(execute-fn! on-begin-contact :first-body a :second-body b))
|
(execute-fn! on-begin-contact { :first-body a :second-body b}))
|
||||||
(fn [a b]
|
(fn [a b]
|
||||||
(execute-fn! on-end-contact :first-body a :second-body b))))
|
(execute-fn! on-end-contact { :first-body a :second-body b}))))
|
||||||
|
|
||||||
(defn ^:private get-bodies
|
(defn ^:private get-bodies
|
||||||
[screen]
|
[screen]
|
||||||
|
|||||||
Reference in New Issue
Block a user