Skip to content

Commit

Permalink
StateRecorder: add 4 public methods
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Oct 29, 2024
1 parent 0d0448b commit 7c5d0d3
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 0 deletions.
58 changes: 58 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/StateRecorder.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ of this software and associated documentation files (the "Software"), to deal
*/
package com.github.stephengold.joltjni;

import com.github.stephengold.joltjni.readonly.RMat44Arg;
import com.github.stephengold.joltjni.readonly.RVec3Arg;
import com.github.stephengold.joltjni.readonly.Vec3Arg;

/**
Expand Down Expand Up @@ -103,6 +105,29 @@ public int readInt(int i) {
return result;
}

/**
* Read a matrix.
*
* @param inOut the value for validation (not null, modified)
*/
public void readRMat44(RMat44 inOut) {
long recorderVa = va();
long matrixVa = inOut.va();
readRMat44(recorderVa, matrixVa);
}

/**
* Read a location vector.
*
* @param inOut the value for validation (not null, modified)
*/
public void readRVec3(RVec3 inOut) {
long recorderVa = va();
double[] tmpDoubles = inOut.toArray();
readRVec3(recorderVa, tmpDoubles);
inOut.set(tmpDoubles[0], tmpDoubles[1], tmpDoubles[2]);
}

/**
* Read a vector.
*
Expand Down Expand Up @@ -166,6 +191,30 @@ public void write(int i) {
writeInt(recorderVa, i);
}

/**
* Write the value of the specified matrix.
*
* @param matrix the matrix to write (not null, unaffected)
*/
public void write(RMat44Arg matrix) {
long recorderVa = va();
long matrixVa = matrix.va();
writeRMat44(recorderVa, matrixVa);
}

/**
* Write the value of the specified vector.
*
* @param v the vector to write (not null, unaffected)
*/
public void write(RVec3Arg v) {
long recorderVa = va();
double xx = v.xx();
double yy = v.yy();
double zz = v.zz();
writeRVec3(recorderVa, xx, yy, zz);
}

/**
* Write the value of the specified vector.
*
Expand All @@ -191,6 +240,10 @@ public void write(Vec3Arg v) {

native private static int readInt(long recorderVa, int i);

native private static void readRMat44(long recorderVa, long matrixVa);

native private static void readRVec3(long recorderVa, double[] tmpDoubles);

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

native private static void setValidating(long recorderVa, boolean setting);
Expand All @@ -204,6 +257,11 @@ native private static void writeBodyIdVector(

native private static void writeInt(long recorderVa, int i);

native private static void writeRMat44(long recorderVa, long matrixVa);

native private static void writeRVec3(
long recorderVa, double xx, double yy, double zz);

native private static void writeVec3(
long recorderVa, float x, float y, float z);
}
59 changes: 59 additions & 0 deletions src/main/native/glue/s/StateRecorder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,39 @@ JNIEXPORT jint JNICALL Java_com_github_stephengold_joltjni_StateRecorder_readInt
return i;
}

/*
* Class: com_github_stephengold_joltjni_StateRecorder
* Method: readRMat44
* Signature: (JJ)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_StateRecorder_readRMat44
(JNIEnv *, jclass, jlong recorderVa, jlong matrixVa) {
StateRecorder * const pRecorder
= reinterpret_cast<StateRecorder *> (recorderVa);
RMat44 * const pMatrix = reinterpret_cast<RMat44 *> (matrixVa);
pRecorder->Read(*pMatrix);
}

/*
* Class: com_github_stephengold_joltjni_StateRecorder
* Method: readRVec3
* Signature: (J[D)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_StateRecorder_readRVec3
(JNIEnv *pEnv, jclass, jlong recorderVa, jdoubleArray tmpDoubles) {
StateRecorder * const pRecorder
= reinterpret_cast<StateRecorder *> (recorderVa);
jboolean isCopy;
jdouble * const pTmpDoubles
= pEnv->GetDoubleArrayElements(tmpDoubles, &isCopy);
RVec3 rvec3(pTmpDoubles[0], pTmpDoubles[1], pTmpDoubles[2]);
pRecorder->Read(rvec3);
pTmpDoubles[0] = rvec3.GetX();
pTmpDoubles[1] = rvec3.GetY();
pTmpDoubles[2] = rvec3.GetZ();
pEnv->ReleaseDoubleArrayElements(tmpDoubles, pTmpDoubles, 0);
}

/*
* Class: com_github_stephengold_joltjni_StateRecorder
* Method: readVec3
Expand Down Expand Up @@ -181,6 +214,32 @@ JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_StateRecorder_writeIn
pRecorder->Write(i);
}

/*
* Class: com_github_stephengold_joltjni_StateRecorder
* Method: writeRMat44
* Signature: (JJ)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_StateRecorder_writeRMat44
(JNIEnv *, jclass, jlong recorderVa, jlong matrixVa) {
StateRecorder * const pRecorder
= reinterpret_cast<StateRecorder *> (recorderVa);
const RMat44 * const pMatrix = reinterpret_cast<RMat44 *> (matrixVa);
pRecorder->Write(*pMatrix);
}

/*
* Class: com_github_stephengold_joltjni_StateRecorder
* Method: writeRVec3
* Signature: (JDDD)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_StateRecorder_writeRVec3
(JNIEnv *, jclass, jlong recorderVa, jdouble xx, jdouble yy, jdouble zz) {
StateRecorder * const pRecorder
= reinterpret_cast<StateRecorder *> (recorderVa);
const RVec3 rvec3(xx, yy, zz);
pRecorder->Write(rvec3);
}

/*
* Class: com_github_stephengold_joltjni_StateRecorder
* Method: writeVec3
Expand Down

0 comments on commit 7c5d0d3

Please sign in to comment.