Skip to content

Commit

Permalink
ObjVsBpFilter: add the disableBp() and disableObj() methods
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Sep 23, 2024
1 parent 9c6b2e3 commit 8ff1650
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/ObjVsBpFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,32 @@ public ObjVsBpFilter(int numObjectLayers, int numBpLayers) {
// *************************************************************************
// new methods exposed

/**
* Disable interactions with the specified layer.
*
* @param bpLayer the index of the broad-phase layer (< numBpLayers)
* @return the modified filter (for chaining)
*/
public ObjVsBpFilter disableBp(int bpLayer) {
long filterVa = va();
disableBp(filterVa, bpLayer);

return this;
}

/**
* Disable interactions with the specified layer.
*
* @param objLayer the index of the object layer (< numObjectLayers)
* @return the modified filter (for chaining)
*/
public ObjVsBpFilter disableObj(int objLayer) {
long filterVa = va();
disableObj(filterVa, objLayer);

return this;
}

/**
* Disable interactions between the specified layers.
*
Expand All @@ -61,6 +87,10 @@ public ObjVsBpFilter disablePair(int objLayer, int bpLayer) {
native private static long createObjVsBpFilter(
int numObjectLayers, int numBpLayers);

native private static void disableBp(long filterVa, int bpLayer);

native private static void disableObj(long filterVa, int objLayer);

native private static void disablePair(
long filterVa, int objLayer, int bpLayer);

Expand Down
38 changes: 38 additions & 0 deletions src/main/native/glue/o/ObjVsBpFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ class ObjVsBpFilter final : public ObjectVsBroadPhaseLayerFilter {
return result;
}

void DisableBp(BroadPhaseLayer inBpLayer) {
JPH_ASSERT(inBpLayer.GetValue() < mNumBpLayers);
for (ObjectLayer i = 0; i < mNumObjectLayers; ++i) {
mppEnable[i][inBpLayer.GetValue()] = false;
}
}

void DisableObj(ObjectLayer inObjectLayer) {
JPH_ASSERT(inObjectLayer < mNumObjectLayers);
for (uint j = 0; j < mNumBpLayers; ++j) {
mppEnable[inObjectLayer][j] = false;
}
}

void DisablePair(ObjectLayer inObjectLayer, BroadPhaseLayer inBpLayer) {
JPH_ASSERT(inObjectLayer < mNumObjectLayers);
JPH_ASSERT(inBpLayer.GetValue() < mNumBpLayers);
Expand Down Expand Up @@ -87,6 +101,30 @@ JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_ObjVsBpFilter_create
return reinterpret_cast<jlong> (pFilter);
}

/*
* Class: com_github_stephengold_joltjni_ObjVsBpFilter
* Method: disableBp
* Signature: (JI)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_ObjVsBpFilter_disableBp
(JNIEnv *, jclass, jlong filterVa, jint bpLayer) {
ObjVsBpFilter * const pFilter
= reinterpret_cast<ObjVsBpFilter *> (filterVa);
pFilter->DisableBp(BroadPhaseLayer(bpLayer));
}

/*
* Class: com_github_stephengold_joltjni_ObjVsBpFilter
* Method: disableObj
* Signature: (JI)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_ObjVsBpFilter_disableObj
(JNIEnv *, jclass, jlong filterVa, jint objLayer) {
ObjVsBpFilter * const pFilter
= reinterpret_cast<ObjVsBpFilter *> (filterVa);
pFilter->DisableObj(objLayer);
}

/*
* Class: com_github_stephengold_joltjni_ObjVsBpFilter
* Method: disablePair
Expand Down

0 comments on commit 8ff1650

Please sign in to comment.