From 697b4a675e916c329c38f637a7374e2abcdff766 Mon Sep 17 00:00:00 2001 From: Stephen Gold Date: Fri, 28 Sep 2018 10:30:34 -0700 Subject: [PATCH] resolve issue #916 --- .../java/com/jme3/bullet/PhysicsSpace.java | 17 ++++++- .../java/com/jme3/bullet/PhysicsSpace.java | 44 +++++++++++++++++-- 2 files changed, 57 insertions(+), 4 deletions(-) diff --git a/jme3-bullet/src/main/java/com/jme3/bullet/PhysicsSpace.java b/jme3-bullet/src/main/java/com/jme3/bullet/PhysicsSpace.java index 873d080f7..ea5f74518 100644 --- a/jme3-bullet/src/main/java/com/jme3/bullet/PhysicsSpace.java +++ b/jme3-bullet/src/main/java/com/jme3/bullet/PhysicsSpace.java @@ -45,6 +45,7 @@ import com.jme3.math.Transform; import com.jme3.math.Vector3f; import com.jme3.scene.Node; import com.jme3.scene.Spatial; +import com.jme3.util.SafeArrayList; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Collection; @@ -54,6 +55,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Comparator; +import java.util.Deque; import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentLinkedQueue; @@ -122,9 +124,22 @@ public class PhysicsSpace { private Map physicsBodies = new ConcurrentHashMap(); private Map physicsJoints = new ConcurrentHashMap(); private Map physicsVehicles = new ConcurrentHashMap(); - private ArrayList collisionListeners = new ArrayList(); + /** + * list of registered collision listeners + */ + final private List collisionListeners + = new SafeArrayList<>(PhysicsCollisionListener.class); + /** + * queue of collision events not yet distributed to listeners + */ private ArrayDeque collisionEvents = new ArrayDeque(); + /** + * map from collision groups to registered group listeners + */ private Map collisionGroupListeners = new ConcurrentHashMap(); + /** + * queue of registered tick listeners + */ private ConcurrentLinkedQueue tickListeners = new ConcurrentLinkedQueue(); private PhysicsCollisionEventFactory eventFactory = new PhysicsCollisionEventFactory(); /** diff --git a/jme3-jbullet/src/main/java/com/jme3/bullet/PhysicsSpace.java b/jme3-jbullet/src/main/java/com/jme3/bullet/PhysicsSpace.java index fd934a162..9dd64be17 100644 --- a/jme3-jbullet/src/main/java/com/jme3/bullet/PhysicsSpace.java +++ b/jme3-jbullet/src/main/java/com/jme3/bullet/PhysicsSpace.java @@ -63,7 +63,6 @@ import com.bulletphysics.dynamics.constraintsolver.TypedConstraint; import com.bulletphysics.dynamics.vehicle.RaycastVehicle; import com.bulletphysics.extras.gimpact.GImpactCollisionAlgorithm; import com.jme3.app.AppTask; -import com.jme3.asset.AssetManager; import com.jme3.bullet.collision.PhysicsCollisionEvent; import com.jme3.bullet.collision.PhysicsCollisionEventFactory; import com.jme3.bullet.collision.PhysicsCollisionGroupListener; @@ -84,8 +83,8 @@ import com.jme3.math.Transform; import com.jme3.math.Vector3f; import com.jme3.scene.Node; import com.jme3.scene.Spatial; +import com.jme3.util.SafeArrayList; import java.util.ArrayDeque; -import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.LinkedList; @@ -104,9 +103,21 @@ import java.util.logging.Logger; */ public class PhysicsSpace { + /** + * message logger for this class + */ private static final Logger logger = Logger.getLogger(PhysicsSpace.class.getName()); + /** + * index of the X axis + */ public static final int AXIS_X = 0; + /** + * index of the Y axis + */ public static final int AXIS_Y = 1; + /** + * index of the Z axis + */ public static final int AXIS_Z = 2; private static ThreadLocal>> pQueueTL = new ThreadLocal>>() { @@ -129,14 +140,41 @@ public class PhysicsSpace { private Map physicsBodies = new ConcurrentHashMap(); private Map physicsJoints = new ConcurrentHashMap(); private Map physicsVehicles = new ConcurrentHashMap(); + /** + * map from collision groups to registered group listeners + */ private Map collisionGroupListeners = new ConcurrentHashMap(); + /** + * queue of registered tick listeners + */ private ConcurrentLinkedQueue tickListeners = new ConcurrentLinkedQueue(); - private ArrayList collisionListeners = new ArrayList(); + /** + * list of registered collision listeners + */ + final private List collisionListeners + = new SafeArrayList<>(PhysicsCollisionListener.class); + /** + * queue of collision events not yet distributed to listeners + */ private ArrayDeque collisionEvents = new ArrayDeque(); private PhysicsCollisionEventFactory eventFactory = new PhysicsCollisionEventFactory(); + /** + * copy of minimum coordinate values when using AXIS_SWEEP broadphase + * algorithms + */ private Vector3f worldMin = new Vector3f(-10000f, -10000f, -10000f); + /** + * copy of maximum coordinate values when using AXIS_SWEEP broadphase + * algorithms + */ private Vector3f worldMax = new Vector3f(10000f, 10000f, 10000f); + /** + * physics time step (in seconds, >0) + */ private float accuracy = 1f / 60f; + /** + * maximum number of physics steps per frame (≥0, default=4) + */ private int maxSubSteps = 4; private javax.vecmath.Vector3f rayVec1 = new javax.vecmath.Vector3f(); private javax.vecmath.Vector3f rayVec2 = new javax.vecmath.Vector3f();