Skip to content

Commit

Permalink
BodyManager: add the 2 public methods
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Sep 20, 2024
1 parent 4016e6c commit 4dbbac7
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/BodyManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,21 @@ of this software and associated documentation files (the "Software"), to deal

import com.github.stephengold.joltjni.readonly.ConstBodyCreationSettings;
import com.github.stephengold.joltjni.readonly.ConstBodyId;
import com.github.stephengold.joltjni.readonly.ConstBroadPhaseLayerInterface;

/**
* A container for bodies.
*
* @author Stephen Gold [email protected]
*/
public class BodyManager extends NonCopyable {
// *************************************************************************
// fields

/**
* protect the BroadPhaseLayerInterface from garbage collection
*/
private ConstBroadPhaseLayerInterface layerMap;
// *************************************************************************
// constructors

Expand Down Expand Up @@ -173,6 +181,16 @@ public BodyVector getBodies() {
return result;
}

/**
* Access the (application-provided) interface for mapping object layers to
* broadphase layers.
*
* @return the pre-existing instance, or {@code null} if none
*/
public ConstBroadPhaseLayerInterface getBroadPhaseLayerInterface() {
return layerMap;
}

/**
* Return the maximum number of bodies the manager can support.
*
Expand All @@ -184,6 +202,24 @@ public int getMaxBodies() {

return result;
}

/**
* Initialize the manager.
*
* @param maxBodies the desired maximum number of rigid bodies that can be
* added
* @param numBodyMutexes the desired number of mutexes to allocate, or 0 for
* the default number
* @param map the desired map from object layers to broad-phase layers (not
* null, alias created)
*/
public void init(int maxBodies, int numBodyMutexes,
ConstBroadPhaseLayerInterface map) {
this.layerMap = map;
long managerVa = va();
long mapVa = map.va();
init(managerVa, maxBodies, numBodyMutexes, mapVa);
}
// *************************************************************************
// native private methods

Expand All @@ -205,4 +241,7 @@ native private static void draw(long managerVa, long drawSettingsVa,
native private static long getBodies(long managerVa);

native private static int getMaxBodies(long managerVa);

native private static void init(
long managerVa, int maxBodies, int numBodyMutexes, long mapVa);
}
13 changes: 13 additions & 0 deletions src/main/native/glue/b/BodyManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,4 +185,17 @@ JNIEXPORT jint JNICALL Java_com_github_stephengold_joltjni_BodyManager_getMaxBod
= reinterpret_cast<BodyManager *> (managerVa);
const uint result = pManager->GetMaxBodies();
return result;
}

/*
* Class: com_github_stephengold_joltjni_BodyManager
* Method: init
* Signature: (JIIJ)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_BodyManager_init
(JNIEnv *, jclass, jlong managerVa, jint maxBodies, jint numBodyMutexes, jlong mapVa) {
BodyManager * const pManager = reinterpret_cast<BodyManager *> (managerVa);
const BroadPhaseLayerInterface * const pMap
= reinterpret_cast<BroadPhaseLayerInterface *> (mapVa);
pManager->Init(maxBodies, numBodyMutexes, *pMap);
}

0 comments on commit 4dbbac7

Please sign in to comment.