From 2b1e4ae81799cb19ecc215fa8310c11db2caa692 Mon Sep 17 00:00:00 2001 From: Bryce Covert Date: Tue, 23 Jan 2018 20:38:55 -0800 Subject: [PATCH] working on changes to support mobile with performance. --- src/play_clj/core_graphics.clj | 26 +++++++++++++++----------- src/play_clj/core_listeners.clj | 5 ++--- src/play_clj/core_utils.clj | 2 +- 3 files changed, 18 insertions(+), 15 deletions(-) diff --git a/src/play_clj/core_graphics.clj b/src/play_clj/core_graphics.clj index 480853f..d5d46aa 100755 --- a/src/play_clj/core_graphics.clj +++ b/src/play_clj/core_graphics.clj @@ -485,14 +485,12 @@ with the tiled map file at `path` and `unit` scale. (.end batch)) entities) -(defmethod draw! Stage - [{:keys [^Stage renderer ^Camera camera ^ShaderProgram shader] :as screen} entities] +(def reset-color ^Color (color 1 1 1 1)) + +(defn render-one [{:keys [^Stage renderer ^Camera camera ^ShaderProgram shader] :as screen} {:keys [additive? opacity ^float r ^float g ^float b ^float hue-amount ^float multiply-amount] :as entity :or {opacity 1.0}}] (let [^Batch batch (.getBatch renderer)] - (.setProjectionMatrix batch (.combined camera)) - #_(.begin batch) - - (doseq [{:keys [additive? opacity ^float r ^float g ^float b ^float hue-amount ^float multiply-amount] :as entity :or {opacity 1.0}} entities - :when (> opacity 0.0)] + (.setProjectionMatrix batch (.combined camera)) + (when (> opacity 0.0) (when shader (.setShader batch shader) (.setUniformf shader "multiply_amount" (float (or multiply-amount 1.0))) @@ -500,15 +498,21 @@ with the tiled map file at `path` and `unit` scale. (when additive? (.setBlendFunction ^Batch batch (gl :gl-src-alpha) (gl :gl-one))) - (do (.setColor batch (color (or r 1.0) (or g 1.0) (or b 1.0) opacity)) + (do (.setColor batch (float (or r 1.0)) (float (or g 1.0)) (float (or b 1.0)) (float opacity)) (e/draw! entity screen batch) - (.setColor batch (color 1 1 1 1))) + (.setColor batch ^Color reset-color)) (when (or additive?) - (.setBlendFunction ^Batch batch (gl :gl-src-alpha) (gl :gl-one-minus-src-alpha)))) - #_(.end batch)) + (.setBlendFunction ^Batch batch (gl :gl-src-alpha) (gl :gl-one-minus-src-alpha)))))) + +(defmethod draw! Stage + [screen entities] + (doseq [entity entities] + (render-one screen entity)) entities) + + (defmethod draw! ModelBatch [{:keys [^ModelBatch renderer ^Camera camera] :as screen} entities] (.begin renderer camera) diff --git a/src/play_clj/core_listeners.clj b/src/play_clj/core_listeners.clj index 2ba23aa..5f881a9 100755 --- a/src/play_clj/core_listeners.clj +++ b/src/play_clj/core_listeners.clj @@ -221,10 +221,9 @@ in the `screen`." (defn ^:private update-screen! ([{:keys [renderer world] :as screen}] (when (instance? Stage renderer) - (update-stage! screen)) - (update-physics! screen)) + (update-stage! screen))) ([{:keys [renderer world] :as screen} entities] (when (instance? Stage renderer) (update-stage! screen entities)) - (update-physics! screen entities) + entities)) diff --git a/src/play_clj/core_utils.clj b/src/play_clj/core_utils.clj index 30b8024..7787b5b 100755 --- a/src/play_clj/core_utils.clj +++ b/src/play_clj/core_utils.clj @@ -175,7 +175,7 @@ found." (set-loaders! am (InternalFileHandleResolver.))) ([^AssetManager am res] (.setLoader am TiledMap (TmxMapLoader. res)) - (.setLoader am ParticleEffect (proxy [ParticleEffectLoader] [res] + #_(.setLoader am ParticleEffect (proxy [ParticleEffectLoader] [res] (load [am file-name fh param] (doto (ParticleEffect.) (.load fh (.parent fh))))))))