diff --git a/src/main/java/com/github/stephengold/joltjni/BodyManager.java b/src/main/java/com/github/stephengold/joltjni/BodyManager.java index 59f8f52d..9a0d6f66 100644 --- a/src/main/java/com/github/stephengold/joltjni/BodyManager.java +++ b/src/main/java/com/github/stephengold/joltjni/BodyManager.java @@ -23,6 +23,7 @@ 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. @@ -30,6 +31,13 @@ of this software and associated documentation files (the "Software"), to deal * @author Stephen Gold sgold@sonic.net */ public class BodyManager extends NonCopyable { + // ************************************************************************* + // fields + + /** + * protect the BroadPhaseLayerInterface from garbage collection + */ + private ConstBroadPhaseLayerInterface layerMap; // ************************************************************************* // constructors @@ -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. * @@ -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 @@ -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); } diff --git a/src/main/native/glue/b/BodyManager.cpp b/src/main/native/glue/b/BodyManager.cpp index df5e22fe..7ceb98a4 100644 --- a/src/main/native/glue/b/BodyManager.cpp +++ b/src/main/native/glue/b/BodyManager.cpp @@ -185,4 +185,17 @@ JNIEXPORT jint JNICALL Java_com_github_stephengold_joltjni_BodyManager_getMaxBod = reinterpret_cast (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 (managerVa); + const BroadPhaseLayerInterface * const pMap + = reinterpret_cast (mapVa); + pManager->Init(maxBodies, numBodyMutexes, *pMap); } \ No newline at end of file