Skip to content

Commit

Permalink
BodyInterface: add accessors for user data
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Nov 26, 2024
1 parent ddf9626 commit 148813c
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/BodyInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,20 @@ public PhysicsSystem getSystem() {
return result;
}

/**
* Return the user data of the specified body.
*
* @param bodyId the ID of the body (not null, unaffected)
* @return the value
*/
public long getUserData(ConstBodyId bodyId) {
long bodyInterfaceVa = va();
long bodyIdVa = bodyId.targetVa();
long result = getUserData(bodyInterfaceVa, bodyIdVa);

return result;
}

/**
* Test whether the specified body is active.
*
Expand Down Expand Up @@ -818,6 +832,18 @@ public void setShape(ConstBodyId bodyId, ConstShape shape,
setShape(bodyInterfaceVa, bodyIdVa, shapeVa, updateMassProperties,
ordinal);
}

/**
* Alter the user data of the specified body.
*
* @param bodyId the ID of the body to modify (not null, unaffected)
* @param value the desired value
*/
public void setUserData(ConstBodyId bodyId, long value) {
long bodyInterfaceVa = va();
long bodyIdVa = bodyId.targetVa();
setUserData(bodyInterfaceVa, bodyIdVa, value);
}
// *************************************************************************
// native private methods

Expand Down Expand Up @@ -934,6 +960,7 @@ native private static float getRotationZ(

native private static long getShape(long bodyInterfaceVa, long bodyIdVa);

native private static long getUserData(long bodyInterfaceVa, long bodyIdVa);

native private static boolean isActive(long bodyInterfaceVa, long bodyIdVa);

Expand Down Expand Up @@ -986,4 +1013,7 @@ native private static void setRestitution(

native private static void setShape(long bodyInterfaceVa, long bodyIdVa,
long shapeVa, boolean updateMassProperties, int ordinal);

native private static void setUserData(
long bodyInterfaceVa, long bodyIdVa, long value);
}
27 changes: 27 additions & 0 deletions src/main/native/glue/bo/BodyInterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,20 @@ JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_BodyInterface_getSha
return reinterpret_cast<jlong> (pResult);
}

/*
* Class: com_github_stephengold_joltjni_BodyInterface
* Method: getUserData
* Signature: (JJ)J
*/
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_BodyInterface_getUserData
(JNIEnv *, jclass, jlong bodyInterfaceVa, jlong bodyIdVa) {
const BodyInterface * const pInterface
= reinterpret_cast<BodyInterface *> (bodyInterfaceVa);
const BodyID * const pBodyId = reinterpret_cast<BodyID *> (bodyIdVa);
const uint64 result = pInterface->GetUserData(*pBodyId);
return result;
}

/*
* Class: com_github_stephengold_joltjni_BodyInterface
* Method: isActive
Expand Down Expand Up @@ -825,4 +839,17 @@ JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_BodyInterface_setShap
const Shape * const pShape = reinterpret_cast<Shape *> (shapeVa);
const EActivation activation = (EActivation) ordinal;
pInterface->SetShape(*pBodyId, pShape, updateMassProperties, activation);
}

/*
* Class: com_github_stephengold_joltjni_BodyInterface
* Method: setUserData
* Signature: (JJJ)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_BodyInterface_setUserData
(JNIEnv *, jclass, jlong bodyInterfaceVa, jlong bodyIdVa, jlong value) {
BodyInterface * const pInterface
= reinterpret_cast<BodyInterface *> (bodyInterfaceVa);
const BodyID * const pBodyId = reinterpret_cast<BodyID *> (bodyIdVa);
pInterface->SetUserData(*pBodyId, value);
}

0 comments on commit 148813c

Please sign in to comment.