Skip to content

Commit

Permalink
PhysicsSpace: add 7 public methods from Minie
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Jun 19, 2024
1 parent f8516df commit 94edc6b
Showing 1 changed file with 87 additions and 0 deletions.
87 changes: 87 additions & 0 deletions library/src/main/java/com/jme3/bullet/PhysicsSpace.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,24 @@ public void addCollisionObject(PhysicsRigidBody pco) {
pco.setAddedToSpaceInternal(this);
}

/**
* Register the specified tick listener with the space.
* <p>
* Tick listeners are notified before and after each simulation step. A
* simulation step is not necessarily the same as a frame; it is more
* influenced by the accuracy of the PhysicsSpace.
*
* @see #setAccuracy(float)
*
* @param listener the listener to register (not null, alias created)
*/
public void addTickListener(PhysicsTickListener listener) {
Validate.nonNull(listener, "listener");
assert !tickListeners.contains(listener);

tickListeners.add(listener);
}

/**
* Return the number of active bodies.
*
Expand All @@ -243,6 +261,25 @@ public int countActiveBodies() {
return result;
}

/**
* Count how many tick listeners are registered with the space.
*
* @return the count (&ge;0)
*/
public int countTickListeners() {
int count = tickListeners.size();
return count;
}

/**
* Return the simulation accuracy: the time step used when maxSubSteps&gt;0.
*
* @return the time step (in seconds, &gt;0)
*/
public float getAccuracy() {
return accuracy;
}

/**
* Access the jolt-java BodyInterface.
*
Expand All @@ -263,6 +300,16 @@ public int maxSubSteps() {
return maxSubSteps;
}

/**
* Return the maximum time step (imposed when maxSubSteps=0).
*
* @return the maximum time step (in seconds, &gt;0, default=0.1)
*/
public float maxTimeStep() {
assert maxTimeStep > 0f : maxTimeStep;
return maxTimeStep;
}

/**
* Remove the specified collision object from this space.
*
Expand All @@ -276,6 +323,32 @@ public void removeCollisionObject(PhysicsRigidBody rbc) {
rbc.setAddedToSpaceInternal(null);
}

/**
* De-register the specified tick listener.
*
* @see #addTickListener(com.jme3.bullet.PhysicsTickListener)
* @param listener the listener to de-register (not null, unaffected)
*/
public void removeTickListener(PhysicsTickListener listener) {
Validate.nonNull(listener, "listener");

boolean success = tickListeners.remove(listener);
assert success;
}

/**
* Alter the accuracy (time step used when maxSubSteps&gt;0).
* <p>
* In general, the smaller the time step, the more accurate (and
* compute-intensive) the simulation will be.
*
* @param accuracy the desired time step (in seconds, &gt;0, default=1/60)
*/
public void setAccuracy(float accuracy) {
Validate.positive(accuracy, "accuracy");
this.accuracy = accuracy;
}

/**
* Alter the gravitational acceleration acting on newly-added bodies.
* <p>
Expand Down Expand Up @@ -307,6 +380,20 @@ public void setMaxSubSteps(int steps) {
this.maxSubSteps = steps;
}

/**
* Alter the maximum time step (imposed when maxSubSteps=0).
* <p>
* In general, the smaller the time step, the more accurate (and
* compute-intensive) the simulation will be.
*
* @param maxTimeStep the desired maximum time step (in seconds, &gt;0,
* default=0.1)
*/
public void setMaxTimeStep(float maxTimeStep) {
Validate.positive(maxTimeStep, "max time step");
this.maxTimeStep = maxTimeStep;
}

/**
* Update this space. Can be used to single-step the physics simulation, if
* maxSubSteps is set to 0 or 1. This method should be invoked on the thread
Expand Down

0 comments on commit 94edc6b

Please sign in to comment.