- fix deprecation message and javadoc cleanups in PhysicsSpace

git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@10345 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
nor..67 12 years ago
parent 9f7b273517
commit 2f100c79fb
  1. 158
      engine/src/bullet/com/jme3/bullet/PhysicsSpace.java
  2. 6
      engine/src/jbullet/com/jme3/bullet/PhysicsSpace.java

@ -60,10 +60,11 @@ import java.util.logging.Logger;
/** /**
* <p>PhysicsSpace - The central jbullet-jme physics space</p> * <p>PhysicsSpace - The central jbullet-jme physics space</p>
*
* @author normenhansen * @author normenhansen
*/ */
public class PhysicsSpace { public class PhysicsSpace {
private static final Logger logger = Logger.getLogger(PhysicsSpace.class.getName()); private static final Logger logger = Logger.getLogger(PhysicsSpace.class.getName());
public static final int AXIS_X = 0; public static final int AXIS_X = 0;
public static final int AXIS_Y = 1; public static final int AXIS_Y = 1;
@ -71,7 +72,6 @@ public class PhysicsSpace {
private long physicsSpaceId = 0; private long physicsSpaceId = 0;
private static ThreadLocal<ConcurrentLinkedQueue<AppTask<?>>> pQueueTL = private static ThreadLocal<ConcurrentLinkedQueue<AppTask<?>>> pQueueTL =
new ThreadLocal<ConcurrentLinkedQueue<AppTask<?>>>() { new ThreadLocal<ConcurrentLinkedQueue<AppTask<?>>>() {
@Override @Override
protected ConcurrentLinkedQueue<AppTask<?>> initialValue() { protected ConcurrentLinkedQueue<AppTask<?>> initialValue() {
return new ConcurrentLinkedQueue<AppTask<?>>(); return new ConcurrentLinkedQueue<AppTask<?>>();
@ -86,13 +86,11 @@ public class PhysicsSpace {
// private ConstraintSolver solver; // private ConstraintSolver solver;
// private DefaultCollisionConfiguration collisionConfiguration; // private DefaultCollisionConfiguration collisionConfiguration;
// private Map<GhostObject, PhysicsGhostObject> physicsGhostNodes = new ConcurrentHashMap<GhostObject, PhysicsGhostObject>(); // private Map<GhostObject, PhysicsGhostObject> physicsGhostNodes = new ConcurrentHashMap<GhostObject, PhysicsGhostObject>();
private Map<Long, PhysicsGhostObject> physicsGhostObjects = new ConcurrentHashMap<Long, PhysicsGhostObject>();
private Map<Long, PhysicsGhostObject> physicsGhostObjects = new ConcurrentHashMap<Long, PhysicsGhostObject>(); private Map<Long, PhysicsCharacter> physicsCharacters = new ConcurrentHashMap<Long, PhysicsCharacter>();
private Map<Long, PhysicsCharacter> physicsCharacters = new ConcurrentHashMap<Long, PhysicsCharacter>(); private Map<Long, PhysicsRigidBody> physicsBodies = new ConcurrentHashMap<Long, PhysicsRigidBody>();
private Map<Long, PhysicsRigidBody> physicsBodies = new ConcurrentHashMap<Long, PhysicsRigidBody>();
private Map<Long, PhysicsJoint> physicsJoints = new ConcurrentHashMap<Long, PhysicsJoint>(); private Map<Long, PhysicsJoint> physicsJoints = new ConcurrentHashMap<Long, PhysicsJoint>();
private Map<Long, PhysicsVehicle> physicsVehicles = new ConcurrentHashMap<Long, PhysicsVehicle>(); private Map<Long, PhysicsVehicle> physicsVehicles = new ConcurrentHashMap<Long, PhysicsVehicle>();
private List<PhysicsCollisionListener> collisionListeners = new LinkedList<PhysicsCollisionListener>(); private List<PhysicsCollisionListener> collisionListeners = new LinkedList<PhysicsCollisionListener>();
private List<PhysicsCollisionEvent> collisionEvents = new LinkedList<PhysicsCollisionEvent>(); private List<PhysicsCollisionEvent> collisionEvents = new LinkedList<PhysicsCollisionEvent>();
private Map<Integer, PhysicsCollisionGroupListener> collisionGroupListeners = new ConcurrentHashMap<Integer, PhysicsCollisionGroupListener>(); private Map<Integer, PhysicsCollisionGroupListener> collisionGroupListeners = new ConcurrentHashMap<Integer, PhysicsCollisionGroupListener>();
@ -110,8 +108,10 @@ public class PhysicsSpace {
} }
/** /**
* Get the current PhysicsSpace <b>running on this thread</b><br/> * Get the current PhysicsSpace <b>running on this thread</b><br/> For
* For parallel physics, this can also be called from the OpenGL thread to receive the PhysicsSpace * parallel physics, this can also be called from the OpenGL thread to
* receive the PhysicsSpace
*
* @return the PhysicsSpace running on this thread * @return the PhysicsSpace running on this thread
*/ */
public static PhysicsSpace getPhysicsSpace() { public static PhysicsSpace getPhysicsSpace() {
@ -120,6 +120,7 @@ public class PhysicsSpace {
/** /**
* Used internally * Used internally
*
* @param space * @param space
*/ */
public static void setLocalThreadPhysicsSpace(PhysicsSpace space) { public static void setLocalThreadPhysicsSpace(PhysicsSpace space) {
@ -336,6 +337,7 @@ public class PhysicsSpace {
/** /**
* updates the physics space * updates the physics space
*
* @param time the current time value * @param time the current time value
*/ */
public void update(float time) { public void update(float time) {
@ -344,6 +346,7 @@ public class PhysicsSpace {
/** /**
* updates the physics space, uses maxSteps<br> * updates the physics space, uses maxSteps<br>
*
* @param time the current time value * @param time the current time value
* @param maxSteps * @param maxSteps
*/ */
@ -360,15 +363,15 @@ public class PhysicsSpace {
public void distributeEvents() { public void distributeEvents() {
//add collision callbacks //add collision callbacks
// synchronized (collisionEvents) { // synchronized (collisionEvents) {
for (Iterator<PhysicsCollisionEvent> it = collisionEvents.iterator(); it.hasNext();) { for (Iterator<PhysicsCollisionEvent> it = collisionEvents.iterator(); it.hasNext();) {
PhysicsCollisionEvent physicsCollisionEvent = it.next(); PhysicsCollisionEvent physicsCollisionEvent = it.next();
for (PhysicsCollisionListener listener : collisionListeners) { for (PhysicsCollisionListener listener : collisionListeners) {
listener.collision(physicsCollisionEvent); listener.collision(physicsCollisionEvent);
}
//recycle events
eventFactory.recycle(physicsCollisionEvent);
it.remove();
} }
//recycle events
eventFactory.recycle(physicsCollisionEvent);
it.remove();
}
// } // }
} }
@ -380,7 +383,9 @@ public class PhysicsSpace {
} }
/** /**
* calls the callable on the next physics tick (ensuring e.g. force applying) * calls the callable on the next physics tick (ensuring e.g. force
* applying)
*
* @param <V> * @param <V>
* @param callable * @param callable
* @return Future object * @return Future object
@ -393,6 +398,7 @@ public class PhysicsSpace {
/** /**
* adds an object to the physics space * adds an object to the physics space
*
* @param obj the PhysicsControl or Spatial with PhysicsControl to add * @param obj the PhysicsControl or Spatial with PhysicsControl to add
*/ */
public void add(Object obj) { public void add(Object obj) {
@ -425,6 +431,7 @@ public class PhysicsSpace {
/** /**
* removes an object from the physics space * removes an object from the physics space
*
* @param obj the PhysicsControl or Spatial with PhysicsControl to remove * @param obj the PhysicsControl or Spatial with PhysicsControl to remove
*/ */
public void remove(Object obj) { public void remove(Object obj) {
@ -454,8 +461,9 @@ public class PhysicsSpace {
} }
/** /**
* adds all physics controls and joints in the given spatial node to the physics space * adds all physics controls and joints in the given spatial node to the
* (e.g. after loading from disk) - recursive if node * physics space (e.g. after loading from disk) - recursive if node
*
* @param spatial the rootnode containing the physics objects * @param spatial the rootnode containing the physics objects
*/ */
public void addAll(Spatial spatial) { public void addAll(Spatial spatial) {
@ -493,8 +501,9 @@ public class PhysicsSpace {
} }
/** /**
* Removes all physics controls and joints in the given spatial from the physics space * Removes all physics controls and joints in the given spatial from the
* (e.g. before saving to disk) - recursive if node * physics space (e.g. before saving to disk) - recursive if node
*
* @param spatial the rootnode containing the physics objects * @param spatial the rootnode containing the physics objects
*/ */
public void removeAll(Spatial spatial) { public void removeAll(Spatial spatial) {
@ -552,13 +561,13 @@ public class PhysicsSpace {
private native void removeVehicle(long space, long id); private native void removeVehicle(long space, long id);
private native void addConstraint(long space, long id); private native void addConstraint(long space, long id);
private native void addConstraintC(long space, long id, boolean collision); private native void addConstraintC(long space, long id, boolean collision);
private native void removeConstraint(long space, long id); private native void removeConstraint(long space, long id);
private void addGhostObject(PhysicsGhostObject node) { private void addGhostObject(PhysicsGhostObject node) {
if(physicsGhostObjects.containsKey(node.getObjectId())){ if (physicsGhostObjects.containsKey(node.getObjectId())) {
logger.log(Level.WARNING, "GhostObject {0} already exists in PhysicsSpace, cannot add.", node); logger.log(Level.WARNING, "GhostObject {0} already exists in PhysicsSpace, cannot add.", node);
return; return;
} }
@ -568,7 +577,7 @@ public class PhysicsSpace {
} }
private void removeGhostObject(PhysicsGhostObject node) { private void removeGhostObject(PhysicsGhostObject node) {
if(!physicsGhostObjects.containsKey(node.getObjectId())){ if (!physicsGhostObjects.containsKey(node.getObjectId())) {
logger.log(Level.WARNING, "GhostObject {0} does not exist in PhysicsSpace, cannot remove.", node); logger.log(Level.WARNING, "GhostObject {0} does not exist in PhysicsSpace, cannot remove.", node);
return; return;
} }
@ -578,7 +587,7 @@ public class PhysicsSpace {
} }
private void addCharacter(PhysicsCharacter node) { private void addCharacter(PhysicsCharacter node) {
if(physicsCharacters.containsKey(node.getObjectId())){ if (physicsCharacters.containsKey(node.getObjectId())) {
logger.log(Level.WARNING, "Character {0} already exists in PhysicsSpace, cannot add.", node); logger.log(Level.WARNING, "Character {0} already exists in PhysicsSpace, cannot add.", node);
return; return;
} }
@ -591,7 +600,7 @@ public class PhysicsSpace {
} }
private void removeCharacter(PhysicsCharacter node) { private void removeCharacter(PhysicsCharacter node) {
if(!physicsCharacters.containsKey(node.getObjectId())){ if (!physicsCharacters.containsKey(node.getObjectId())) {
logger.log(Level.WARNING, "Character {0} does not exist in PhysicsSpace, cannot remove.", node); logger.log(Level.WARNING, "Character {0} does not exist in PhysicsSpace, cannot remove.", node);
return; return;
} }
@ -604,7 +613,7 @@ public class PhysicsSpace {
} }
private void addRigidBody(PhysicsRigidBody node) { private void addRigidBody(PhysicsRigidBody node) {
if(physicsBodies.containsKey(node.getObjectId())){ if (physicsBodies.containsKey(node.getObjectId())) {
logger.log(Level.WARNING, "RigidBody {0} already exists in PhysicsSpace, cannot add.", node); logger.log(Level.WARNING, "RigidBody {0} already exists in PhysicsSpace, cannot add.", node);
return; return;
} }
@ -626,13 +635,13 @@ public class PhysicsSpace {
logger.log(Level.FINE, "Adding RigidBody {0} to physics space.", node.getObjectId()); logger.log(Level.FINE, "Adding RigidBody {0} to physics space.", node.getObjectId());
if (node instanceof PhysicsVehicle) { if (node instanceof PhysicsVehicle) {
logger.log(Level.FINE, "Adding vehicle constraint {0} to physics space.", Long.toHexString(((PhysicsVehicle) node).getVehicleId())); logger.log(Level.FINE, "Adding vehicle constraint {0} to physics space.", Long.toHexString(((PhysicsVehicle) node).getVehicleId()));
physicsVehicles.put(((PhysicsVehicle) node).getVehicleId(), (PhysicsVehicle)node); physicsVehicles.put(((PhysicsVehicle) node).getVehicleId(), (PhysicsVehicle) node);
addVehicle(physicsSpaceId, ((PhysicsVehicle) node).getVehicleId()); addVehicle(physicsSpaceId, ((PhysicsVehicle) node).getVehicleId());
} }
} }
private void removeRigidBody(PhysicsRigidBody node) { private void removeRigidBody(PhysicsRigidBody node) {
if(!physicsBodies.containsKey(node.getObjectId())){ if (!physicsBodies.containsKey(node.getObjectId())) {
logger.log(Level.WARNING, "RigidBody {0} does not exist in PhysicsSpace, cannot remove.", node); logger.log(Level.WARNING, "RigidBody {0} does not exist in PhysicsSpace, cannot remove.", node);
return; return;
} }
@ -647,7 +656,7 @@ public class PhysicsSpace {
} }
private void addJoint(PhysicsJoint joint) { private void addJoint(PhysicsJoint joint) {
if(physicsJoints.containsKey(joint.getObjectId())){ if (physicsJoints.containsKey(joint.getObjectId())) {
logger.log(Level.WARNING, "Joint {0} already exists in PhysicsSpace, cannot add.", joint); logger.log(Level.WARNING, "Joint {0} already exists in PhysicsSpace, cannot add.", joint);
return; return;
} }
@ -658,7 +667,7 @@ public class PhysicsSpace {
} }
private void removeJoint(PhysicsJoint joint) { private void removeJoint(PhysicsJoint joint) {
if(!physicsJoints.containsKey(joint.getObjectId())){ if (!physicsJoints.containsKey(joint.getObjectId())) {
logger.log(Level.WARNING, "Joint {0} does not exist in PhysicsSpace, cannot remove.", joint); logger.log(Level.WARNING, "Joint {0} does not exist in PhysicsSpace, cannot remove.", joint);
return; return;
} }
@ -668,28 +677,29 @@ public class PhysicsSpace {
// dynamicsWorld.removeConstraint(joint.getObjectId()); // dynamicsWorld.removeConstraint(joint.getObjectId());
} }
public Collection<PhysicsRigidBody> getRigidBodyList(){ public Collection<PhysicsRigidBody> getRigidBodyList() {
return new LinkedList<PhysicsRigidBody>(physicsBodies.values()); return new LinkedList<PhysicsRigidBody>(physicsBodies.values());
} }
public Collection<PhysicsGhostObject> getGhostObjectList(){ public Collection<PhysicsGhostObject> getGhostObjectList() {
return new LinkedList<PhysicsGhostObject>(physicsGhostObjects.values()); return new LinkedList<PhysicsGhostObject>(physicsGhostObjects.values());
} }
public Collection<PhysicsCharacter> getCharacterList(){ public Collection<PhysicsCharacter> getCharacterList() {
return new LinkedList<PhysicsCharacter>(physicsCharacters.values()); return new LinkedList<PhysicsCharacter>(physicsCharacters.values());
} }
public Collection<PhysicsJoint> getJointList(){ public Collection<PhysicsJoint> getJointList() {
return new LinkedList<PhysicsJoint>(physicsJoints.values()); return new LinkedList<PhysicsJoint>(physicsJoints.values());
} }
public Collection<PhysicsVehicle> getVehicleList(){ public Collection<PhysicsVehicle> getVehicleList() {
return new LinkedList<PhysicsVehicle>(physicsVehicles.values()); return new LinkedList<PhysicsVehicle>(physicsVehicles.values());
} }
/** /**
* Sets the gravity of the PhysicsSpace, set before adding physics objects! * Sets the gravity of the PhysicsSpace, set before adding physics objects!
*
* @param gravity * @param gravity
*/ */
public void setGravity(Vector3f gravity) { public void setGravity(Vector3f gravity) {
@ -714,9 +724,10 @@ public class PhysicsSpace {
// } // }
// //
/** /**
* Adds the specified listener to the physics tick listeners. * Adds the specified listener to the physics tick listeners. The listeners
* The listeners are called on each physics step, which is not necessarily * are called on each physics step, which is not necessarily each frame but
* each frame but is determined by the accuracy of the physics space. * is determined by the accuracy of the physics space.
*
* @param listener * @param listener
*/ */
public void addTickListener(PhysicsTickListener listener) { public void addTickListener(PhysicsTickListener listener) {
@ -729,6 +740,7 @@ public class PhysicsSpace {
/** /**
* Adds a CollisionListener that will be informed about collision events * Adds a CollisionListener that will be informed about collision events
*
* @param listener the CollisionListener to add * @param listener the CollisionListener to add
*/ */
public void addCollisionListener(PhysicsCollisionListener listener) { public void addCollisionListener(PhysicsCollisionListener listener) {
@ -737,6 +749,7 @@ public class PhysicsSpace {
/** /**
* Removes a CollisionListener from the list * Removes a CollisionListener from the list
*
* @param listener the CollisionListener to remove * @param listener the CollisionListener to remove
*/ */
public void removeCollisionListener(PhysicsCollisionListener listener) { public void removeCollisionListener(PhysicsCollisionListener listener) {
@ -744,8 +757,10 @@ public class PhysicsSpace {
} }
/** /**
* Adds a listener for a specific collision group, such a listener can disable collisions when they happen.<br> * Adds a listener for a specific collision group, such a listener can
* There can be only one listener per collision group. * disable collisions when they happen.<br> There can be only one listener
* per collision group.
*
* @param listener * @param listener
* @param collisionGroup * @param collisionGroup
*/ */
@ -758,7 +773,8 @@ public class PhysicsSpace {
} }
/** /**
* Performs a ray collision test and returns the results as a list of PhysicsRayTestResults * Performs a ray collision test and returns the results as a list of
* PhysicsRayTestResults
*/ */
public List rayTest(Vector3f from, Vector3f to) { public List rayTest(Vector3f from, Vector3f to) {
List results = new LinkedList(); List results = new LinkedList();
@ -767,7 +783,8 @@ public class PhysicsSpace {
} }
/** /**
* Performs a ray collision test and returns the results as a list of PhysicsRayTestResults * Performs a ray collision test and returns the results as a list of
* PhysicsRayTestResults
*/ */
public List<PhysicsRayTestResult> rayTest(Vector3f from, Vector3f to, List<PhysicsRayTestResult> results) { public List<PhysicsRayTestResult> rayTest(Vector3f from, Vector3f to, List<PhysicsRayTestResult> results) {
results.clear(); results.clear();
@ -793,9 +810,11 @@ public class PhysicsSpace {
// } // }
// } // }
/** /**
* Performs a sweep collision test and returns the results as a list of PhysicsSweepTestResults<br/> * Performs a sweep collision test and returns the results as a list of
* You have to use different Transforms for start and end (at least distance > 0.4f). * PhysicsSweepTestResults<br/> You have to use different Transforms for
* SweepTest will not see a collision if it starts INSIDE an object and is moving AWAY from its center. * start and end (at least distance > 0.4f). SweepTest will not see a
* collision if it starts INSIDE an object and is moving AWAY from its
* center.
*/ */
public List<PhysicsSweepTestResult> sweepTest(CollisionShape shape, Transform start, Transform end) { public List<PhysicsSweepTestResult> sweepTest(CollisionShape shape, Transform start, Transform end) {
List<PhysicsSweepTestResult> results = new LinkedList<PhysicsSweepTestResult>(); List<PhysicsSweepTestResult> results = new LinkedList<PhysicsSweepTestResult>();
@ -809,9 +828,11 @@ public class PhysicsSpace {
} }
/** /**
* Performs a sweep collision test and returns the results as a list of PhysicsSweepTestResults<br/> * Performs a sweep collision test and returns the results as a list of
* You have to use different Transforms for start and end (at least distance > 0.4f). * PhysicsSweepTestResults<br/> You have to use different Transforms for
* SweepTest will not see a collision if it starts INSIDE an object and is moving AWAY from its center. * start and end (at least distance > 0.4f). SweepTest will not see a
* collision if it starts INSIDE an object and is moving AWAY from its
* center.
*/ */
public List<PhysicsSweepTestResult> sweepTest(CollisionShape shape, Transform start, Transform end, List<PhysicsSweepTestResult> results) { public List<PhysicsSweepTestResult> sweepTest(CollisionShape shape, Transform start, Transform end, List<PhysicsSweepTestResult> results) {
results.clear(); results.clear();
@ -850,9 +871,10 @@ public class PhysicsSpace {
} }
/** /**
// * used internally * // * used internally //
// * @return the dynamicsWorld *
// */ * @return the dynamicsWorld //
*/
public long getSpaceId() { public long getSpaceId() {
return physicsSpaceId; return physicsSpaceId;
} }
@ -866,11 +888,13 @@ public class PhysicsSpace {
} }
/** /**
* Sets the maximum amount of extra steps that will be used to step the physics * Sets the maximum amount of extra steps that will be used to step the
* when the fps is below the physics fps. Doing this maintains determinism in physics. * physics when the fps is below the physics fps. Doing this maintains
* For example a maximum number of 2 can compensate for framerates as low as 30fps * determinism in physics. For example a maximum number of 2 can compensate
* when the physics has the default accuracy of 60 fps. Note that setting this * for framerates as low as 30fps when the physics has the default accuracy
* value too high can make the physics drive down its own fps in case its overloaded. * of 60 fps. Note that setting this value too high can make the physics
* drive down its own fps in case its overloaded.
*
* @param steps The maximum number of extra steps, default is 4. * @param steps The maximum number of extra steps, default is 4.
*/ */
public void setMaxSubSteps(int steps) { public void setMaxSubSteps(int steps) {
@ -879,6 +903,7 @@ public class PhysicsSpace {
/** /**
* get the current accuracy of the physics computation * get the current accuracy of the physics computation
*
* @return the current accuracy * @return the current accuracy
*/ */
public float getAccuracy() { public float getAccuracy() {
@ -887,6 +912,7 @@ public class PhysicsSpace {
/** /**
* sets the accuracy of the physics computation, default=1/60s<br> * sets the accuracy of the physics computation, default=1/60s<br>
*
* @param accuracy * @param accuracy
*/ */
public void setAccuracy(float accuracy) { public void setAccuracy(float accuracy) {
@ -899,6 +925,7 @@ public class PhysicsSpace {
/** /**
* only applies for AXIS_SWEEP broadphase * only applies for AXIS_SWEEP broadphase
*
* @param worldMin * @param worldMin
*/ */
public void setWorldMin(Vector3f worldMin) { public void setWorldMin(Vector3f worldMin) {
@ -911,6 +938,7 @@ public class PhysicsSpace {
/** /**
* only applies for AXIS_SWEEP broadphase * only applies for AXIS_SWEEP broadphase
*
* @param worldMax * @param worldMax
*/ */
public void setWorldMax(Vector3f worldMax) { public void setWorldMax(Vector3f worldMax) {
@ -918,9 +946,11 @@ public class PhysicsSpace {
} }
/** /**
* Enable debug display for physics * Enable debug display for physics.
*
* @deprecated in favor of BulletDebugAppState, use
* <code>BulletAppState.setDebugEnabled(boolean)</code> to add automatically
* @param manager AssetManager to use to create debug materials * @param manager AssetManager to use to create debug materials
* @Deprecated in favor of BulletDebugAppState, use BulletAppState.setDebugEnabled(boolean) to add automatically
*/ */
@Deprecated @Deprecated
public void enableDebug(AssetManager manager) { public void enableDebug(AssetManager manager) {

@ -857,9 +857,11 @@ public class PhysicsSpace {
} }
/** /**
* Enable debug display for physics * Enable debug display for physics.
*
* @deprecated in favor of BulletDebugAppState, use
* <code>BulletAppState.setDebugEnabled(boolean)</code> to add automatically
* @param manager AssetManager to use to create debug materials * @param manager AssetManager to use to create debug materials
* @Deprecated in favor of BulletDebugAppState, use BulletAppState.setDebugEnabled(boolean) to add automatically
*/ */
@Deprecated @Deprecated
public void enableDebug(AssetManager manager) { public void enableDebug(AssetManager manager) {

Loading…
Cancel
Save