Stephen Gold 11 years ago
commit 1a68fc9c30
  1. 18
      jme3-bullet/src/main/java/com/jme3/bullet/PhysicsSpace.java
  2. 26
      jme3-jbullet/src/main/java/com/jme3/bullet/PhysicsSpace.java

@ -46,6 +46,8 @@ import com.jme3.math.Transform;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
@ -91,8 +93,8 @@ public class PhysicsSpace {
private Map<Long, PhysicsRigidBody> physicsBodies = new ConcurrentHashMap<Long, PhysicsRigidBody>();
private Map<Long, PhysicsJoint> physicsJoints = new ConcurrentHashMap<Long, PhysicsJoint>();
private Map<Long, PhysicsVehicle> physicsVehicles = new ConcurrentHashMap<Long, PhysicsVehicle>();
private List<PhysicsCollisionListener> collisionListeners = new LinkedList<PhysicsCollisionListener>();
private List<PhysicsCollisionEvent> collisionEvents = new LinkedList<PhysicsCollisionEvent>();
private ArrayList<PhysicsCollisionListener> collisionListeners = new ArrayList<PhysicsCollisionListener>();
private ArrayDeque<PhysicsCollisionEvent> collisionEvents = new ArrayDeque<PhysicsCollisionEvent>();
private Map<Integer, PhysicsCollisionGroupListener> collisionGroupListeners = new ConcurrentHashMap<Integer, PhysicsCollisionGroupListener>();
private ConcurrentLinkedQueue<PhysicsTickListener> tickListeners = new ConcurrentLinkedQueue<PhysicsTickListener>();
private PhysicsCollisionEventFactory eventFactory = new PhysicsCollisionEventFactory();
@ -361,17 +363,15 @@ public class PhysicsSpace {
public void distributeEvents() {
//add collision callbacks
// synchronized (collisionEvents) {
for (Iterator<PhysicsCollisionEvent> it = collisionEvents.iterator(); it.hasNext();) {
PhysicsCollisionEvent physicsCollisionEvent = it.next();
for (PhysicsCollisionListener listener : collisionListeners) {
listener.collision(physicsCollisionEvent);
int clistsize = collisionListeners.size();
while( collisionEvents.isEmpty() == false ) {
PhysicsCollisionEvent physicsCollisionEvent = collisionEvents.pop();
for(int i=0;i<clistsize;i++) {
collisionListeners.get(i).collision(physicsCollisionEvent);
}
//recycle events
eventFactory.recycle(physicsCollisionEvent);
it.remove();
}
// }
}
public static <V> Future<V> enqueueOnThisThread(Callable<V> callable) {

@ -66,6 +66,8 @@ import com.jme3.math.Transform;
import com.jme3.math.Vector3f;
import com.jme3.scene.Node;
import com.jme3.scene.Spatial;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
@ -111,8 +113,8 @@ public class PhysicsSpace {
private Map<RaycastVehicle, PhysicsVehicle> physicsVehicles = new ConcurrentHashMap<RaycastVehicle, PhysicsVehicle>();
private Map<Integer, PhysicsCollisionGroupListener> collisionGroupListeners = new ConcurrentHashMap<Integer, PhysicsCollisionGroupListener>();
private ConcurrentLinkedQueue<PhysicsTickListener> tickListeners = new ConcurrentLinkedQueue<PhysicsTickListener>();
private List<PhysicsCollisionListener> collisionListeners = new LinkedList<PhysicsCollisionListener>();
private List<PhysicsCollisionEvent> collisionEvents = new LinkedList<PhysicsCollisionEvent>();
private ArrayList<PhysicsCollisionListener> collisionListeners = new ArrayList<PhysicsCollisionListener>();
private ArrayDeque<PhysicsCollisionEvent> collisionEvents = new ArrayDeque<PhysicsCollisionEvent>();
private PhysicsCollisionEventFactory eventFactory = new PhysicsCollisionEventFactory();
private Vector3f worldMin = new Vector3f(-10000f, -10000f, -10000f);
private Vector3f worldMax = new Vector3f(10000f, 10000f, 10000f);
@ -332,19 +334,17 @@ public class PhysicsSpace {
public void distributeEvents() {
//add collision callbacks
// synchronized (collisionEvents) {
for (Iterator<PhysicsCollisionEvent> it = collisionEvents.iterator(); it.hasNext();) {
PhysicsCollisionEvent physicsCollisionEvent = it.next();
for (PhysicsCollisionListener listener : collisionListeners) {
listener.collision(physicsCollisionEvent);
}
//recycle events
eventFactory.recycle(physicsCollisionEvent);
it.remove();
int clistsize = collisionListeners.size();
while( collisionEvents.isEmpty() == false ) {
PhysicsCollisionEvent physicsCollisionEvent = collisionEvents.pop();
for(int i=0;i<clistsize;i++) {
collisionListeners.get(i).collision(physicsCollisionEvent);
}
// }
//recycle events
eventFactory.recycle(physicsCollisionEvent);
}
}
public static <V> Future<V> enqueueOnThisThread(Callable<V> callable) {
AppTask<V> task = new AppTask<V>(callable);
System.out.println("created apptask");

Loading…
Cancel
Save