perf improvements, mobile working on i4s

This commit is contained in:
Bryce Covert
2017-05-24 06:15:28 -07:00
parent be916eb5f3
commit 2f6e0a4081
10 changed files with 262 additions and 186 deletions

View File

@@ -1,5 +1,6 @@
(ns advent.screens.rooms
(:require [advent.zone :as zone])
(:require [advent.zone :as zone]
[advent.utils :as utils])
(:import [com.badlogic.gdx.graphics Pixmap Pixmap$Filter Texture Texture$TextureFilter]
[com.badlogic.gdx.graphics.g2d TextureRegion]
[com.badlogic.gdx.utils.viewport FitViewport]
@@ -10,20 +11,21 @@
(merge entity
{:id id
:mouse-in? (fn [entities x y]
(if-let [box (get-in entities [:room :entities id :box])]
((apply zone/box box) x y)
(let [{entity-x :x entity-y :y width :width scale-x :scale-x scale-y :scale-y origin-x :origin-x origin-y :origin-y height :height region :object} (get-in entities [:room :entities id])
width (or width (if (instance? TextureRegion region ) (.getRegionWidth ^TextureRegion region) 0))
height (or height (if (instance? TextureRegion region ) (.getRegionHeight ^TextureRegion region) 0))
entity-x (- entity-x (* (or origin-x 0)
(or scale-x 1)))
entity-y (- entity-y (* (or origin-y 0)
(or scale-y 1)))]
((zone/box entity-x entity-y
(+ entity-x (* width (or scale-x 1)))
(+ entity-y (* height (or scale-y 1)))) x y))))}
(let [e (utils/get-entity entities id)]
(if-let [[bx1 by1 bx2 by2] (:box e)]
(zone/within bx1 by1 bx2 by2 x y)
(let [{entity-x :x entity-y :y width :width scale-x :scale-x scale-y :scale-y origin-x :origin-x origin-y :origin-y height :height region :object} (get-in entities [:room :entities id])
width (or width (if (instance? TextureRegion region ) (.getRegionWidth ^TextureRegion region) 0))
height (or height (if (instance? TextureRegion region ) (.getRegionHeight ^TextureRegion region) 0))
entity-x (unchecked-add (float entity-x) (unchecked-multiply (float (or origin-x 0))
(float (or scale-x 1))))
entity-y (unchecked-add (float entity-y) (unchecked-multiply (float (or origin-y 0))
(float (or scale-y 1))))]
(zone/within entity-x entity-y
(unchecked-add (float entity-x) (unchecked-multiply (float width) (float (or scale-x 1))))
(unchecked-add (float entity-y) (unchecked-multiply (float height) (float (or scale-y 1)))) x y)))))}
(when (or script scripts only-script)
{:get-script (fn [cursor [x y]]
(cond only-script
@@ -43,7 +45,8 @@
(merge spec
(when box
{:mouse-in? (fn [_ x y]
((apply zone/box box) x y))})
(let [[bx1 by1 bx2 by2] box]
(zone/within bx1 by1 bx2 by2 x y)))})
(when (or script scripts only-script)
{:get-script (fn [cursor [x y]]
(cond only-script
@@ -61,7 +64,6 @@
{:id id}))
entities (into {} (for [[id entity] entities]
[id (make-entity id entity)]))]
(println "MAKING")
(merge params {:collision (advent.pathfind/map-from-resource collision)
:interactions interactions-as-list
:entities entities})))