From 5aab91a0302aab348ca27529f4586cde0603dfdf Mon Sep 17 00:00:00 2001 From: stephengold Date: Sun, 13 Oct 2024 17:48:23 -0700 Subject: [PATCH] add the VehicleCollisionTesterCastCylinder class + its ref class --- .../VehicleCollisionTesterCastCylinder.java | 118 ++++++++++++++++++ ...VehicleCollisionTesterCastCylinderRef.java | 90 +++++++++++++ .../v/VehicleCollisionTesterCastCylinder.cpp | 93 ++++++++++++++ 3 files changed, 301 insertions(+) create mode 100644 src/main/java/com/github/stephengold/joltjni/VehicleCollisionTesterCastCylinder.java create mode 100644 src/main/java/com/github/stephengold/joltjni/VehicleCollisionTesterCastCylinderRef.java create mode 100644 src/main/native/glue/v/VehicleCollisionTesterCastCylinder.cpp diff --git a/src/main/java/com/github/stephengold/joltjni/VehicleCollisionTesterCastCylinder.java b/src/main/java/com/github/stephengold/joltjni/VehicleCollisionTesterCastCylinder.java new file mode 100644 index 0000000..6b3bc92 --- /dev/null +++ b/src/main/java/com/github/stephengold/joltjni/VehicleCollisionTesterCastCylinder.java @@ -0,0 +1,118 @@ +/* +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; + +/** + * A {@code VehicleCollisionTester} that casts a cylindrical shape. + * + * @author Stephen Gold sgold@sonic.net + */ +public class VehicleCollisionTesterCastCylinder extends VehicleCollisionTester { + // ************************************************************************* + // constructors + + /** + * Instantiate a tester for the specified layer. + * + * @param objectLayer the index of the desired object layer for collisions + * (≥0) + */ + public VehicleCollisionTesterCastCylinder(int objectLayer) { + this(objectLayer, 0.1f); + } + + /** + * Instantiate a tester with the specified properties. + * + * @param objectLayer the index of the desired object layer for collisions + * (≥0) + * @param convexRadiusFraction (default=0.1) + */ + public VehicleCollisionTesterCastCylinder( + int objectLayer, float convexRadiusFraction) { + long testerVa = createTester(objectLayer, convexRadiusFraction); + setVirtualAddress(testerVa, true); + } + + /** + * Instantiate a tester with the specified native object assigned but not + * owned. + * + * @param testerVa the virtual address of the native object to assign (not + * zero) + */ + VehicleCollisionTesterCastCylinder(long testerVa) { + setVirtualAddress(testerVa, null); + } + // ************************************************************************* + // VehicleCollisionTester methods + + /** + * Count the active references to the native {@code VehicleCollisionTester}. + * The tester is unaffected. + * + * @return the count (≥0) + */ + @Override + public int getRefCount() { + long testerVa = va(); + int result = getRefCount(testerVa); + + return result; + } + + /** + * Mark the native {@code VehicleCollisionTesterCastCylinder} as embedded. + */ + @Override + public void setEmbedded() { + long testerVa = va(); + setEmbedded(testerVa); + } + + /** + * Create a counted reference to the native + * {@code VehicleCollisionTesterCastCylinder}. + * + * @return a new JVM object with a new native object assigned + */ + @Override + public VehicleCollisionTesterCastCylinderRef toRef() { + long testerVa = va(); + long refVa = toRef(testerVa); + VehicleCollisionTesterCastCylinderRef result + = new VehicleCollisionTesterCastCylinderRef(refVa, true); + + return result; + } + // ************************************************************************* + // native private methods + + native private static long createTester( + int objectLayer, float convexRadiusFraction); + + native private static int getRefCount(long settingsVa); + + native private static void setEmbedded(long settingsVa); + + native private static long toRef(long settingsVa); +} diff --git a/src/main/java/com/github/stephengold/joltjni/VehicleCollisionTesterCastCylinderRef.java b/src/main/java/com/github/stephengold/joltjni/VehicleCollisionTesterCastCylinderRef.java new file mode 100644 index 0000000..ca0a939 --- /dev/null +++ b/src/main/java/com/github/stephengold/joltjni/VehicleCollisionTesterCastCylinderRef.java @@ -0,0 +1,90 @@ +/* +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; + +import com.github.stephengold.joltjni.template.Ref; + +/** + * A counted reference to a {@code VehicleCollisionTesterCastCylinder}. (native + * type: {@code Ref}) + * + * @author Stephen Gold sgold@sonic.net + */ +final public class VehicleCollisionTesterCastCylinderRef extends Ref { + // ************************************************************************* + // constructors + + /** + * Instantiate a reference with the specified native object assigned. + * + * @param refVa the virtual address of the native object to assign (not + * zero) + * @param owner true → make the current object the owner, false → + * the current object isn't the owner + */ + VehicleCollisionTesterCastCylinderRef(long refVa, boolean owner) { + Runnable freeingAction = owner ? () -> free(refVa) : null; + setVirtualAddress(refVa, freeingAction); + } + // ************************************************************************* + // Ref methods + + /** + * Temporarily access the referenced + * {@code VehicleCollisionTesterCastCylinder}. + * + * @return a new JVM object that refers to the pre-existing native object + */ + @Override + public VehicleCollisionTesterCastCylinder getPtr() { + long refVa = va(); + long controllerVa = getPtr(refVa); + VehicleCollisionTesterCastCylinder result + = new VehicleCollisionTesterCastCylinder(controllerVa); + + return result; + } + + /** + * Create a counted reference to the native + * {@code VehicleCollisionTesterCastCylinder}. + * + * @return a new JVM object with a new native object assigned + */ + @Override + public VehicleCollisionTesterCastCylinderRef toRef() { + long refVa = va(); + long copyVa = copy(refVa); + VehicleCollisionTesterCastCylinderRef result + = new VehicleCollisionTesterCastCylinderRef(copyVa, true); + + return result; + } + // ************************************************************************* + // native private methods + + native private static long copy(long refVa); + + native private static void free(long refVa); + + native private static long getPtr(long refVa); +} diff --git a/src/main/native/glue/v/VehicleCollisionTesterCastCylinder.cpp b/src/main/native/glue/v/VehicleCollisionTesterCastCylinder.cpp new file mode 100644 index 0000000..d400f81 --- /dev/null +++ b/src/main/native/glue/v/VehicleCollisionTesterCastCylinder.cpp @@ -0,0 +1,93 @@ +/* +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/Vehicle/VehicleCollisionTester.h" + +#include "auto/com_github_stephengold_joltjni_VehicleCollisionTesterCastCylinder.h" +#include "auto/com_github_stephengold_joltjni_VehicleCollisionTesterCastCylinderRef.h" +#include "glue/glue.h" + +using namespace JPH; + +IMPLEMENT_REF(VehicleCollisionTesterCastCylinder, + Java_com_github_stephengold_joltjni_VehicleCollisionTesterCastCylinderRef_copy, + Java_com_github_stephengold_joltjni_VehicleCollisionTesterCastCylinderRef_createEmpty, + Java_com_github_stephengold_joltjni_VehicleCollisionTesterCastCylinderRef_free, + Java_com_github_stephengold_joltjni_VehicleCollisionTesterCastCylinderRef_getPtr) + +/* + * Class: com_github_stephengold_joltjni_VehicleCollisionTesterCastCylinder + * Method: createTester + * Signature: (IF)J + */ +JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_VehicleCollisionTesterCastCylinder_createTester + (JNIEnv *, jclass, jint layer, jfloat convexRadiusFraction) { + const ObjectLayer objLayer = (ObjectLayer) layer; + VehicleCollisionTesterCastCylinder * const pTester + = new VehicleCollisionTesterCastCylinder(objLayer, convexRadiusFraction); + TRACE_NEW("VehicleCollisionTesterCastCylinder", pTester) + return reinterpret_cast (pTester); +} + +/* + * Class: com_github_stephengold_joltjni_VehicleCollisionTesterCastCylinder + * Method: getRefCount + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_com_github_stephengold_joltjni_VehicleCollisionTesterCastCylinder_getRefCount + (JNIEnv *, jclass, jlong testerVa) { + const VehicleCollisionTesterCastCylinder * const pTester + = reinterpret_cast (testerVa); + const uint32 result = pTester->GetRefCount(); + return result; +} + +/* + * Class: com_github_stephengold_joltjni_VehicleCollisionTesterCastCylinder + * Method: setEmbedded + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_VehicleCollisionTesterCastCylinder_setEmbedded + (JNIEnv *, jclass, jlong testerVa) { + VehicleCollisionTesterCastCylinder * const pTester + = reinterpret_cast (testerVa); + pTester->SetEmbedded(); +} + +/* + * Class: com_github_stephengold_joltjni_VehicleCollisionTesterCastCylinder + * Method: toRef + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_VehicleCollisionTesterCastCylinder_toRef + (JNIEnv *, jclass, jlong testerVa) { + VehicleCollisionTesterCastCylinder * const pTester + = reinterpret_cast (testerVa); + Ref * const pResult + = new Ref(pTester); + TRACE_NEW("Ref", pResult) + return reinterpret_cast (pResult); +} \ No newline at end of file