Skip to content

Commit

Permalink
ShapeSettings: add 2 public methods
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Jul 13, 2024
1 parent e8abc93 commit be68bf1
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/main/java/com/github/stephengold/joltjni/ShapeSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,31 @@ protected ShapeSettings() {
// new methods exposed

/**
* Generate a shape from these settings.
* Invoke this method after altering the settings but before generating any
* new shapes.
*/
public void clearCachedResult() {
long settingsVa = va();
clearCachedResult(settingsVa);
}

/**
* Generate a {@code ShapeResult} from these settings.
*
* @return a new instance
* @return a new JVM object with a new native object assigned
*/
public ShapeResult create() {
long settingsVa = va();
long resultVa = create(settingsVa);
ShapeResult result = new ShapeResult(resultVa, true);

return result;
}

/**
* Generate a {@code Shape} from these settings.
*
* @return a new JVM object
*/
abstract public Shape createShape();
// *************************************************************************
Expand All @@ -63,5 +85,9 @@ public int getRefCount() {
// *************************************************************************
// native private methods

native private static void clearCachedResult(long settingsVa);

native private static long create(long settingsVa);

native private static int getRefCount(long settingsVa);
}
25 changes: 25 additions & 0 deletions src/main/native/glue/ShapeSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,31 @@ SOFTWARE.

using namespace JPH;

/*
* Class: com_github_stephengold_joltjni_ShapeSettings
* Method: clearCachedResult
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_ShapeSettings_clearCachedResult
(JNIEnv *, jclass, jlong settingsVa) {
ShapeSettings * const pSettings = reinterpret_cast<ShapeSettings *> (settingsVa);
pSettings->ClearCachedResult();
}

/*
* Class: com_github_stephengold_joltjni_ShapeSettings
* Method: create
* Signature: (J)J
*/
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_ShapeSettings_create
(JNIEnv *, jclass, jlong settingsVa) {
const ShapeSettings * const pSettings
= reinterpret_cast<ShapeSettings *> (settingsVa);
ShapeSettings::ShapeResult *pResult = new ShapeSettings::ShapeResult();
*pResult = pSettings->Create();
return reinterpret_cast<jlong> (pResult);
}

/*
* Class: com_github_stephengold_joltjni_ShapeSettings
* Method: getRefCount
Expand Down

0 comments on commit be68bf1

Please sign in to comment.