Skip to content

Commit

Permalink
PhysicsSceneRef: override targetVa() and refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Nov 8, 2024
1 parent 39adeb7 commit 5cb28a6
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions src/main/java/com/github/stephengold/joltjni/PhysicsSceneRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,7 @@ public PhysicsSceneRef() {
* @return {@code true} if successful, otherwise {@code false}
*/
public boolean fixInvalidScales() {
long refVa = va();
long sceneVa = getPtr(refVa);
long sceneVa = targetVa();
boolean result = PhysicsScene.fixInvalidScales(sceneVa);

return result;
Expand All @@ -76,8 +75,7 @@ public boolean fixInvalidScales() {
* objects assigned
*/
public BodyCreationSettings[] getBodies() {
long refVa = va();
long sceneVa = getPtr(refVa);
long sceneVa = targetVa();
int numBodies = PhysicsScene.getNumBodies(sceneVa);
BodyCreationSettings[] result = new BodyCreationSettings[numBodies];
for (int bodyIndex = 0; bodyIndex < numBodies; ++bodyIndex) {
Expand All @@ -95,8 +93,7 @@ public BodyCreationSettings[] getBodies() {
* @return {@code true} if successful, otherwise {@code false}
*/
public boolean createBodies(PhysicsSystem system) {
long refVa = va();
long sceneVa = getPtr(refVa);
long sceneVa = targetVa();
long systemVa = system.va();
boolean result = PhysicsScene.createBodies(sceneVa, systemVa);

Expand All @@ -112,13 +109,25 @@ public boolean createBodies(PhysicsSystem system) {
*/
@Override
public PhysicsScene getPtr() {
long refVa = va();
long sceneVa = getPtr(refVa);
long sceneVa = targetVa();
PhysicsScene result = new PhysicsScene(sceneVa);

return result;
}

/**
* Return the address of the target object. No objects are affected.
*
* @return a virtual address (not zero)
*/
@Override
public long targetVa() {
long refVa = va();
long result = getPtr(refVa);

return result;
}

/**
* Create another counted reference to the native {@code PhysicsScene}.
*
Expand Down

0 comments on commit 5cb28a6

Please sign in to comment.