Only allow entities that implement the draw-entity! function

This commit is contained in:
oakes
2014-03-21 19:23:06 -04:00
parent 8dd9024fc7
commit bc0844310d
2 changed files with 10 additions and 8 deletions

View File

@@ -238,10 +238,6 @@ with the tiled map file at `path` and `unit` scale
; draw
(defn filter-entities
[entities]
(filter #(isa? (type %) Entity) entities))
(defmulti draw!
"Internal use only"
(fn [screen _] (-> screen :renderer class)))
@@ -250,7 +246,7 @@ with the tiled map file at `path` and `unit` scale
[{:keys [^BatchTiledMapRenderer renderer]} entities]
(let [^SpriteBatch batch (.getSpriteBatch renderer)]
(.begin batch)
(doseq [entity (filter-entities entities)]
(doseq [entity entities]
(u/draw-entity! entity batch))
(.end batch))
entities)
@@ -259,7 +255,7 @@ with the tiled map file at `path` and `unit` scale
[{:keys [^Stage renderer]} entities]
(let [^SpriteBatch batch (.getSpriteBatch renderer)]
(.begin batch)
(doseq [entity (filter-entities entities)]
(doseq [entity entities]
(u/draw-entity! entity batch))
(.end batch))
entities)
@@ -267,7 +263,7 @@ with the tiled map file at `path` and `unit` scale
(defmethod draw! ModelBatch
[{:keys [^ModelBatch renderer ^Camera camera] :as screen} entities]
(.begin renderer camera)
(doseq [entity (filter-entities entities)]
(doseq [entity entities]
(u/draw-entity! entity screen))
(.end renderer)
entities)
@@ -377,7 +373,7 @@ specify which layers to render with or without
(let [^SpriteBatch batch (.getSpriteBatch renderer)]
(.begin batch)
(doseq [entity (->> (map #(get-in screen [:layers %]) layer-names)
(apply concat (filter-entities entities))
(apply concat entities)
(sort-by :y #(compare %2 %1)))]
(if-let [layer (:layer entity)]
(.renderTileLayer renderer layer)

View File

@@ -179,6 +179,12 @@ new object to be created each time a field is set)
"Internal use only"
(draw-entity! [this batch] "Draws the entity"))
(extend-protocol Entity
clojure.lang.PersistentArrayMap
(draw-entity! [this batch])
clojure.lang.PersistentHashMap
(draw-entity! [this batch]))
(defrecord TextureEntity [object] Entity
(draw-entity! [{:keys [^TextureRegion object x y width height]} batch]
(let [x (float (or x 0))