Skip to content

Commit

Permalink
bugfix: StateRecorder read methods lack the old values
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Sep 29, 2024
1 parent 392ec14 commit d569750
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 29 deletions.
24 changes: 12 additions & 12 deletions src/main/java/com/github/stephengold/joltjni/StateRecorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,39 +56,39 @@ public boolean isValidating() {
/**
* Read a boolean.
*
* @param b the value for validation
* @return the value that was read
*/
public boolean readBoolean() {
public boolean readBoolean(boolean b) {
long recorderVa = va();
boolean result = readBoolean(recorderVa);
boolean result = readBoolean(recorderVa, b);

return result;
}

/**
* Read a single-precision floating-point value.
*
* @param f the value for validation
* @return the value that was read
*/
public float readFloat() {
public float readFloat(float f) {
long recorderVa = va();
float result = readFloat(recorderVa);
float result = readFloat(recorderVa, f);

return result;
}

/**
* Read a vector.
*
* @return a new vector
* @param inOut the value for validation (not null, modified)
*/
public Vec3 readVec3() {
public void readVec3(Vec3 inOut) {
long recorderVa = va();
float[] storeFloats = new float[3];
float[] storeFloats = inOut.toArray();
readVec3(recorderVa, storeFloats);
Vec3 result = new Vec3(storeFloats[0], storeFloats[1], storeFloats[2]);

return result;
inOut.set(storeFloats[0], storeFloats[1], storeFloats[2]);
}

/**
Expand Down Expand Up @@ -138,9 +138,9 @@ public void write(Vec3Arg v) {

native private static boolean isValidating(long recorderVa);

native private static boolean readBoolean(long recorderVa);
native private static boolean readBoolean(long recorderVa, boolean b);

native private static float readFloat(long recorderVa);
native private static float readFloat(long recorderVa, float f);

native private static void readVec3(long recorderVa, float[] storeFloats);

Expand Down
16 changes: 8 additions & 8 deletions src/main/native/glue/s/StateRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,27 +45,27 @@ JNIEXPORT jboolean JNICALL Java_com_github_stephengold_joltjni_StateRecorder_isV
/*
* Class: com_github_stephengold_joltjni_StateRecorder
* Method: readBoolean
* Signature: (J)Z
* Signature: (JZ)Z
*/
JNIEXPORT jboolean JNICALL Java_com_github_stephengold_joltjni_StateRecorder_readBoolean
(JNIEnv *, jclass, jlong recorderVa) {
(JNIEnv *, jclass, jlong recorderVa, jboolean b) {
StateRecorder * const pRecorder
= reinterpret_cast<StateRecorder *> (recorderVa);
bool result;
bool result = b;
pRecorder->Read(result);
return result;
}

/*
* Class: com_github_stephengold_joltjni_StateRecorder
* Method: readFloat
* Signature: (J)F
* Signature: (JF)F
*/
JNIEXPORT jfloat JNICALL Java_com_github_stephengold_joltjni_StateRecorder_readFloat
(JNIEnv *, jclass, jlong recorderVa) {
(JNIEnv *, jclass, jlong recorderVa, jfloat f) {
StateRecorder * const pRecorder
= reinterpret_cast<StateRecorder *> (recorderVa);
float result;
float result = f;
pRecorder->Read(result);
return result;
}
Expand All @@ -79,11 +79,11 @@ JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_StateRecorder_readVec
(JNIEnv *pEnv, jclass, jlong recorderVa, jfloatArray storeFloats) {
StateRecorder * const pRecorder
= reinterpret_cast<StateRecorder *> (recorderVa);
Vec3 result;
pRecorder->Read(result);
jboolean isCopy;
jfloat * const pStoreFloats
= pEnv->GetFloatArrayElements(storeFloats, &isCopy);
Vec3 result(pStoreFloats[0], pStoreFloats[1], pStoreFloats[2]);
pRecorder->Read(result);
pStoreFloats[0] = result.GetX();
pStoreFloats[1] = result.GetY();
pStoreFloats[2] = result.GetZ();
Expand Down
12 changes: 6 additions & 6 deletions src/test/java/testjoltjni/app/samples/CharacterBaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -783,9 +783,9 @@ void SaveState(StateRecorder inStream)

void RestoreState(StateRecorder inStream)
{
mTime = inStream.readFloat();
mRampBlocksTimeLeft = inStream.readFloat();
mReversingVerticallyMovingVelocity = inStream.readFloat();
mTime = inStream.readFloat(mTime);
mRampBlocksTimeLeft = inStream.readFloat(mRampBlocksTimeLeft);
mReversingVerticallyMovingVelocity = inStream.readFloat(mReversingVerticallyMovingVelocity);

if (mAnimatedCharacterVirtual != null)
mAnimatedCharacterVirtual.getPtr().restoreState(inStream);
Expand All @@ -803,9 +803,9 @@ void SaveInputState(StateRecorder inStream)

void RestoreInputState(StateRecorder inStream)
{
mControlInput = inStream.readVec3();
mJump = inStream.readBoolean();
mSwitchStance = inStream.readBoolean();
inStream.readVec3(mControlInput);
mJump = inStream.readBoolean(mJump);
mSwitchStance = inStream.readBoolean(mSwitchStance);
}

void DrawCharacterState(ConstCharacterBase inCharacter, RMat44Arg inCharacterTransform, Vec3Arg inCharacterVelocity)
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/testjoltjni/app/samples/VehicleStressTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ void SaveInputState(StateRecorder inStream)

void RestoreInputState(StateRecorder inStream)
{
mForward = inStream.readFloat();
mRight = inStream.readFloat();
mHandBrake = inStream.readFloat();
mForward = inStream.readFloat(mForward);
mRight = inStream.readFloat(mRight);
mHandBrake = inStream.readFloat(mHandBrake);
}
}

0 comments on commit d569750

Please sign in to comment.