-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1340bdf
commit 61da919
Showing
2 changed files
with
209 additions
and
0 deletions.
There are no files selected for viewing
109 changes: 109 additions & 0 deletions
109
src/main/java/com/github/stephengold/joltjni/RagdollResult.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
/* | ||
Copyright (c) 2024 Stephen Gold | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ | ||
package com.github.stephengold.joltjni; | ||
|
||
/** | ||
* Either an error or a {@code RagdollSettingsRef}. (native type: | ||
* {@code Result<Ref<RagdollSettings>>}) | ||
* | ||
* @author Stephen Gold [email protected] | ||
*/ | ||
final public class RagdollResult extends JoltPhysicsObject { | ||
// ************************************************************************* | ||
// constructors | ||
|
||
/** | ||
* Instantiate a result with the specified native object assigned. | ||
* | ||
* @param resultVa the virtual address of the native object to assign (not | ||
* zero) | ||
* @param owner {@code true} → make the JVM object the owner, | ||
* {@code false} → it isn't the owner | ||
*/ | ||
RagdollResult(long resultVa, boolean owner) { | ||
Runnable freeingAction = owner ? () -> free(resultVa) : null; | ||
setVirtualAddress(resultVa, freeingAction); | ||
} | ||
// ************************************************************************* | ||
// new methods exposed | ||
|
||
/** | ||
* Copy the {@code RagdollSettingsRef}. | ||
* | ||
* @return a new JVM object with a new native object assigned | ||
*/ | ||
public RagdollSettingsRef get() { | ||
long resultVa = va(); | ||
long settingsRefVa = get(resultVa); | ||
RagdollSettingsRef result = new RagdollSettingsRef(settingsRefVa, true); | ||
|
||
return result; | ||
} | ||
|
||
/** | ||
* Return the error string. | ||
* | ||
* @return the string | ||
*/ | ||
public String getError() { | ||
long resultVa = va(); | ||
String result = getError(resultVa); | ||
|
||
return result; | ||
} | ||
|
||
/** | ||
* Test whether there was an error. | ||
* | ||
* @return {@code true} if error, otherwise {@code false} | ||
*/ | ||
public boolean hasError() { | ||
long resultVa = va(); | ||
boolean result = hasError(resultVa); | ||
|
||
return result; | ||
} | ||
|
||
/** | ||
* Test whether the {@code RagdollSettingsRef} is valid. | ||
* | ||
* @return {@code true} if valid, otherwise {@code false} | ||
*/ | ||
public boolean isValid() { | ||
long resultVa = va(); | ||
boolean result = isValid(resultVa); | ||
|
||
return result; | ||
} | ||
// ************************************************************************* | ||
// native private methods | ||
|
||
native private static void free(long resultVa); | ||
|
||
native private static long get(long resultVa); | ||
|
||
native private static String getError(long resultVa); | ||
|
||
native private static boolean hasError(long resultVa); | ||
|
||
native private static boolean isValid(long resultVa); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
Copyright (c) 2024 Stephen Gold | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ | ||
|
||
/* | ||
* Author: Stephen Gold | ||
*/ | ||
#include "Jolt/Jolt.h" | ||
#include "Jolt/Physics/Ragdoll/Ragdoll.h" | ||
#include "auto/com_github_stephengold_joltjni_RagdollResult.h" | ||
#include "glue/glue.h" | ||
|
||
using namespace JPH; | ||
|
||
/* | ||
* Class: com_github_stephengold_joltjni_RagdollResult | ||
* Method: free | ||
* Signature: (J)V | ||
*/ | ||
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_RagdollResult_free | ||
(JNIEnv *, jclass, jlong resultVa) { | ||
RagdollSettings::RagdollResult * const pResult | ||
= reinterpret_cast<RagdollSettings::RagdollResult *> (resultVa); | ||
TRACE_DELETE("RagdollResult", pResult) | ||
delete pResult; | ||
} | ||
|
||
/* | ||
* Class: com_github_stephengold_joltjni_RagdollResult | ||
* Method: get | ||
* Signature: (J)J | ||
*/ | ||
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_RagdollResult_get | ||
(JNIEnv *, jclass, jlong resultVa) { | ||
const RagdollSettings::RagdollResult * const pResult | ||
= reinterpret_cast<RagdollSettings::RagdollResult *> (resultVa); | ||
Ref<RagdollSettings> * const pRef = new Ref<RagdollSettings>(); | ||
TRACE_NEW("RagdollSettingsRef", pRef) | ||
*pRef = pResult->Get(); | ||
return reinterpret_cast<jlong> (pRef); | ||
} | ||
|
||
/* | ||
* Class: com_github_stephengold_joltjni_RagdollResult | ||
* Method: getError | ||
* Signature: (J)Ljava/lang/String; | ||
*/ | ||
JNIEXPORT jstring JNICALL Java_com_github_stephengold_joltjni_RagdollResult_getError | ||
(JNIEnv *pEnv, jclass, jlong resultVa) { | ||
const RagdollSettings::RagdollResult * const pResult | ||
= reinterpret_cast<RagdollSettings::RagdollResult *> (resultVa); | ||
const String& message = pResult->GetError(); | ||
const char* const str = message.c_str(); | ||
const jstring result = pEnv->NewStringUTF(str); | ||
return result; | ||
} | ||
|
||
/* | ||
* Class: com_github_stephengold_joltjni_RagdollResult | ||
* Method: hasError | ||
* Signature: (J)Z | ||
*/ | ||
JNIEXPORT jboolean JNICALL Java_com_github_stephengold_joltjni_RagdollResult_hasError | ||
(JNIEnv *, jclass, jlong resultVa) { | ||
const RagdollSettings::RagdollResult * const pResult | ||
= reinterpret_cast<RagdollSettings::RagdollResult *> (resultVa); | ||
const bool result = pResult->HasError(); | ||
return result; | ||
} | ||
|
||
/* | ||
* Class: com_github_stephengold_joltjni_RagdollResult | ||
* Method: isValid | ||
* Signature: (J)Z | ||
*/ | ||
JNIEXPORT jboolean JNICALL Java_com_github_stephengold_joltjni_RagdollResult_isValid | ||
(JNIEnv *, jclass, jlong resultVa) { | ||
const RagdollSettings::RagdollResult * const pResult | ||
= reinterpret_cast<RagdollSettings::RagdollResult *> (resultVa); | ||
const bool result = pResult->IsValid(); | ||
return result; | ||
} |