Skip to content

Commit

Permalink
refactor the Character{/Base/Virtual} classes
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Oct 31, 2024
1 parent 4923c46 commit ed2d3f5
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 114 deletions.
27 changes: 0 additions & 27 deletions src/main/java/com/github/stephengold/joltjni/Character.java
Original file line number Diff line number Diff line change
Expand Up @@ -484,29 +484,6 @@ public boolean setShape(
// *************************************************************************
// CharacterBase methods

/**
* Count the active references to the native {@code Character}. The
* character is unaffected.
*
* @return the count (≥0)
*/
@Override
public int getRefCount() {
long characterVa = va();
int result = getRefCount(characterVa);

return result;
}

/**
* Mark the native {@code Character} as embedded.
*/
@Override
public void setEmbedded() {
long characterVa = va();
setEmbedded(characterVa);
}

/**
* Create a counted reference to the native {@code Character}.
*
Expand Down Expand Up @@ -785,8 +762,6 @@ native static void getPosition(
native static void getPositionAndRotation(long characterVa,
double[] storeDoubles, float[] storeFloats, boolean lockBodies);

native private static int getRefCount(long characterVa);

native static void getRotation(
long characterVa, float[] toreFloats, boolean lockBodies);

Expand All @@ -799,8 +774,6 @@ native private static void postSimulation(
native private static void removeFromPhysicsSystem(
long characterVa, boolean lockBodies);

native private static void setEmbedded(long characterVa);

native private static void setLayer(
long characterVa, int layer, boolean lockBodies);

Expand Down
25 changes: 14 additions & 11 deletions src/main/java/com/github/stephengold/joltjni/CharacterBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ of this software and associated documentation files (the "Software"), to deal
import com.github.stephengold.joltjni.readonly.ConstPhysicsMaterial;
import com.github.stephengold.joltjni.readonly.ConstShape;
import com.github.stephengold.joltjni.readonly.Vec3Arg;
import com.github.stephengold.joltjni.template.Ref;
import com.github.stephengold.joltjni.template.RefTarget;

/**
Expand Down Expand Up @@ -323,21 +322,21 @@ public void saveState(StateRecorder recorder) {
* @return the count (≥0)
*/
@Override
abstract public int getRefCount();
public int getRefCount() {
long characterVa = va();
int result = getRefCount(characterVa);

/**
* Mark the native {@code CharacterBase} as embedded.
*/
@Override
abstract public void setEmbedded();
return result;
}

/**
* Create a counted reference to the native {@code CharacterBase}.
*
* @return a new JVM object with a new native object assigned
* Mark the native {@code CharacterBase} as embedded.
*/
@Override
abstract public Ref toRef();
public void setEmbedded() {
long characterVa = va();
setEmbedded(characterVa);
}
// *************************************************************************
// native methods

Expand Down Expand Up @@ -371,6 +370,8 @@ public void saveState(StateRecorder recorder) {

native static float getGroundVelocityZ(long characterVa);

native private static int getRefCount(long characterVa);

native static long getShape(long characterVa);

native static float getUpX(long characterVa);
Expand All @@ -388,6 +389,8 @@ native static boolean isSlopeTooSteep(

native static void saveState(long characterVa, long recorderVa);

native private static void setEmbedded(long characterVa);

native private static void setMaxSlopeAngle(long characterVa, float angle);

native private static void setUp(
Expand Down
27 changes: 0 additions & 27 deletions src/main/java/com/github/stephengold/joltjni/CharacterVirtual.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,29 +357,6 @@ public void updateGroundVelocity() {
// *************************************************************************
// CharacterBase methods

/**
* Count the active references to the native {@code CharacterVirtual}. The
* character is unaffected.
*
* @return the count (≥0)
*/
@Override
public int getRefCount() {
long characterVa = va();
int result = getRefCount(characterVa);

return result;
}

/**
* Mark the native {@code CharacterVirtual} as embedded.
*/
@Override
public void setEmbedded() {
long characterVa = va();
setEmbedded(characterVa);
}

/**
* Create a counted reference to the native {@code CharacterVirtual}.
*
Expand Down Expand Up @@ -795,8 +772,6 @@ native private static void extendedUpdate(long characterVa, float deltaTime,

native static double getPositionZ(long characterVa);

native private static int getRefCount(long characterVa);

native static float getRotationW(long characterVa);

native static float getRotationX(long characterVa);
Expand All @@ -823,8 +798,6 @@ native static boolean hasCollidedWithCharacter(
native private static void setCharacterVsCharacterCollision(
long characterVa, long interfaceVa);

native private static void setEmbedded(long characterVa);

native private static void setEnhancedInternalEdgeRemoval(
long characterVa, boolean enable);

Expand Down
24 changes: 0 additions & 24 deletions src/main/native/glue/c/Character.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,19 +218,6 @@ JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_Character_getPosition
pEnv->ReleaseFloatArrayElements(storeFloats, pStoreFloats, 0);
}

/*
* Class: com_github_stephengold_joltjni_Character
* Method: getRefCount
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_com_github_stephengold_joltjni_Character_getRefCount
(JNIEnv *, jclass, jlong characterVa) {
const Character * const pCharacter
= reinterpret_cast<Character *> (characterVa);
const uint32 result = pCharacter->GetRefCount();
return result;
}

/*
* Class: com_github_stephengold_joltjni_Character
* Method: getRotation
Expand Down Expand Up @@ -288,17 +275,6 @@ JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_Character_removeFromP
pCharacter->RemoveFromPhysicsSystem(lockBodies);
}

/*
* Class: com_github_stephengold_joltjni_Character
* Method: setEmbedded
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_Character_setEmbedded
(JNIEnv *, jclass, jlong characterVa) {
Character * const pCharacter = reinterpret_cast<Character *> (characterVa);
pCharacter->SetEmbedded();
}

/*
* Class: com_github_stephengold_joltjni_Character
* Method: setLayer
Expand Down
25 changes: 25 additions & 0 deletions src/main/native/glue/c/CharacterBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,19 @@ JNIEXPORT jfloat JNICALL Java_com_github_stephengold_joltjni_CharacterBase_getGr
return result;
}

/*
* Class: com_github_stephengold_joltjni_CharacterBase
* Method: getRefCount
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_com_github_stephengold_joltjni_CharacterBase_getRefCount
(JNIEnv *, jclass, jlong characterVa) {
const CharacterBase * const pCharacter
= reinterpret_cast<CharacterBase *> (characterVa);
const uint32 result = pCharacter->GetRefCount();
return result;
}

/*
* Class: com_github_stephengold_joltjni_CharacterBase
* Method: getShape
Expand Down Expand Up @@ -336,6 +349,18 @@ JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_CharacterBase_saveSta
pCharacter->SaveState(*pRecorder);
}

/*
* Class: com_github_stephengold_joltjni_CharacterBase
* Method: setEmbedded
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_CharacterBase_setEmbedded
(JNIEnv *, jclass, jlong characterVa) {
CharacterBase * const pCharacter
= reinterpret_cast<CharacterBase *> (characterVa);
pCharacter->SetEmbedded();
}

/*
* Class: com_github_stephengold_joltjni_CharacterBase
* Method: setMaxSlopeAngle
Expand Down
25 changes: 0 additions & 25 deletions src/main/native/glue/c/CharacterVirtual.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -384,19 +384,6 @@ JNIEXPORT jdouble JNICALL Java_com_github_stephengold_joltjni_CharacterVirtual_g
return result;
}

/*
* Class: com_github_stephengold_joltjni_CharacterVirtual
* Method: getRefCount
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_com_github_stephengold_joltjni_CharacterVirtual_getRefCount
(JNIEnv *, jclass, jlong characterVa) {
const CharacterVirtual * const pCharacter
= reinterpret_cast<CharacterVirtual *> (characterVa);
const uint32 result = pCharacter->GetRefCount();
return result;
}

/*
* Class: com_github_stephengold_joltjni_CharacterVirtual
* Method: getRotationW
Expand Down Expand Up @@ -559,18 +546,6 @@ JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_CharacterVirtual_setC
pCharacter->SetCharacterVsCharacterCollision(pInterface);
}

/*
* Class: com_github_stephengold_joltjni_CharacterVirtual
* Method: setEmbedded
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_CharacterVirtual_setEmbedded
(JNIEnv *, jclass, jlong characterVa) {
CharacterVirtual * const pCharacter
= reinterpret_cast<CharacterVirtual *> (characterVa);
pCharacter->SetEmbedded();
}

/*
* Class: com_github_stephengold_joltjni_CharacterVirtual
* Method: setEnhancedInternalEdgeRemoval
Expand Down

0 comments on commit ed2d3f5

Please sign in to comment.