Remove joints whose bodies no longer exist

This commit is contained in:
oakes
2014-01-18 18:51:23 -05:00
parent 7497b33eca
commit a1a6066c99
3 changed files with 13 additions and 6 deletions

View File

@@ -19,7 +19,7 @@
IsometricStaggeredTiledMapRenderer
IsometricTiledMapRenderer
OrthogonalTiledMapRenderer]
[com.badlogic.gdx.physics.box2d World]
[com.badlogic.gdx.physics.box2d Joint World]
[com.badlogic.gdx.scenes.scene2d Actor Stage]))
(load "core_global")

View File

@@ -15,11 +15,18 @@
(defn ^:private update-box-2d!
[{:keys [^World world]} entities]
(when-not (.isLocked world)
(let [bodies (u/gdx-array [])]
(.getBodies world bodies)
(doseq [body bodies]
(let [arr (u/gdx-array [])]
; remove bodies that no longer exist
(.getBodies world arr)
(doseq [body arr]
(when-not (some #(= body (:body %)) entities)
(.destroyBody world body))))))
(.destroyBody world body)))
; remove joints whose bodies no longer exist
(.getJoints world arr)
(doseq [^Joint joint arr]
(when (and (not (some #(= (.getBodyA joint) (:body %)) entities))
(not (some #(= (.getBodyB joint) (:body %)) entities)))
(.destroyJoint world joint))))))
(defn ^:private update-screen!
([{:keys [world g2dp-listener]}]

View File

@@ -88,7 +88,7 @@
(defn create-field-setters
[obj {:keys [] :as args}]
(map (fn [[k v]]
`(set! (. ~obj ~(symbol (key->camel k))) (eval ~v)))
`(set! (. ~obj ~(symbol (key->camel k))) ~v))
args))
(defmacro fields!