diff --git a/src/play_clj/core.clj b/src/play_clj/core.clj index 3b00363..a66b54b 100644 --- a/src/play_clj/core.clj +++ b/src/play_clj/core.clj @@ -7,6 +7,7 @@ PerspectiveCamera] [com.badlogic.gdx.graphics.g2d NinePatch ParticleEffect SpriteBatch TextureRegion] + [com.badlogic.gdx.graphics.g3d Environment ModelBatch ModelInstance] [com.badlogic.gdx.input GestureDetector GestureDetector$GestureListener] [com.badlogic.gdx.maps MapLayer MapLayers] diff --git a/src/play_clj/core_graphics.clj b/src/play_clj/core_graphics.clj index 723b055..78f34ea 100644 --- a/src/play_clj/core_graphics.clj +++ b/src/play_clj/core_graphics.clj @@ -186,21 +186,7 @@ with the tiled map file at `path` and `unit` scale `(let [^Stage object# (u/get-obj ~screen :renderer)] (u/call! object# ~k ~@options))) -; batch - -(defmulti batch - "Internal use only" - #(-> % :renderer class)) - -(defmethod batch BatchTiledMapRenderer - [{:keys [^BatchTiledMapRenderer renderer]}] - (.getSpriteBatch renderer)) - -(defmethod batch Stage - [{:keys [^Stage renderer]}] - (.getSpriteBatch renderer)) - -; rendering +; draw-entity (defmulti draw-entity! "Internal use only" @@ -210,7 +196,6 @@ with the tiled map file at `path` and `unit` scale (defmethod draw-entity! :texture [^SpriteBatch batch {:keys [^TextureRegion object x y width height]}] - (assert object) (let [x (float (or x 0)) y (float (or y 0)) width (float (or width (.getRegionWidth object))) @@ -219,7 +204,6 @@ with the tiled map file at `path` and `unit` scale (defmethod draw-entity! :nine-patch [^SpriteBatch batch {:keys [^NinePatch object x y width height]}] - (assert object) (let [x (float (or x 0)) y (float (or y 0)) width (float (or width (.getTotalWidth object))) @@ -228,7 +212,6 @@ with the tiled map file at `path` and `unit` scale (defmethod draw-entity! :particle-effect [^SpriteBatch batch {:keys [^ParticleEffect object x y delta-time]}] - (assert object) (let [x (float (or x 0)) y (float (or y 0)) delta-time (float (or delta-time (graphics! :get-delta-time)))] @@ -237,7 +220,6 @@ with the tiled map file at `path` and `unit` scale (defmethod draw-entity! :actor [^SpriteBatch batch {:keys [^Actor object] :as entity}] - (assert object) (doseq [[k v] entity] (case k :x (.setX object v) @@ -247,19 +229,45 @@ with the tiled map file at `path` and `unit` scale nil)) (.draw object batch 1)) -(defn draw! - "Draws the `entities` with the renderer from `screen` +(defmethod draw-entity! :model + [{:keys [^ModelBatch batch ^Environment attributes]} + {:keys [^ModelInstance object]}] + (.render batch object attributes)) - (draw! screen entities)" - [{:keys [renderer] :as screen} entities] - (assert renderer) - (let [^SpriteBatch batch (batch screen)] +; draw + +(defmulti draw! + "Internal use only" + (fn [screen _] (-> screen :renderer class))) + +(defmethod draw! BatchTiledMapRenderer + [{:keys [^BatchTiledMapRenderer renderer]} entities] + (let [^SpriteBatch batch (.getSpriteBatch renderer)] (.begin batch) (doseq [entity entities] (draw-entity! batch entity)) (.end batch)) entities) +(defmethod draw! Stage + [{:keys [^Stage renderer]} entities] + (let [^SpriteBatch batch (.getSpriteBatch renderer)] + (.begin batch) + (doseq [entity entities] + (draw-entity! batch entity)) + (.end batch)) + entities) + +(defmethod draw! ModelBatch + [{:keys [^ModelBatch renderer ^Camera camera] :as screen} entities] + (.begin renderer camera) + (doseq [entity entities] + (draw-entity! screen entity)) + (.end renderer) + entities) + +; render + (defn ^:private render-map! "Internal use only" [{:keys [^BatchTiledMapRenderer renderer ^Camera camera]}] diff --git a/src/play_clj/g3d.clj b/src/play_clj/g3d.clj new file mode 100644 index 0000000..d24c815 --- /dev/null +++ b/src/play_clj/g3d.clj @@ -0,0 +1,45 @@ +(ns play-clj.g3d + (:require [play-clj.utils :as u]) + (:import [com.badlogic.gdx.graphics.g3d Environment ModelBatch])) + +; environment + +(defn environment* + "The function version of `environment`" + [] + (Environment.)) + +(defmacro environment + "Returns an [Environment](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g3d/Environment.html) + + (environment)" + [& options] + `(let [^Environment object# (environment*)] + (u/calls! object# ~@options))) + +(defmacro environment! + "Calls a single method on an `environment`" + [screen k & options] + `(let [^Environment object# (u/get-obj ~screen :attributes)] + (u/call! object# ~k ~@options))) + +; model-batch + +(defn model-batch* + "The function version of `model-batch`" + [] + (ModelBatch.)) + +(defmacro model-batch + "Returns an [ModelBatch](http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/graphics/g3d/Environment.html) + + (model-batch)" + [& options] + `(let [^ModelBatch object# (model-batch*)] + (u/calls! object# ~@options))) + +(defmacro model-batch! + "Calls a single method on an `model-batch`" + [screen k & options] + `(let [^ModelBatch object# (u/get-obj ~screen :attributes)] + (u/call! object# ~k ~@options)))