diff --git a/src/main/java/com/github/stephengold/joltjni/WheelSettingsWv.java b/src/main/java/com/github/stephengold/joltjni/WheelSettingsWv.java new file mode 100644 index 00000000..77eaee3d --- /dev/null +++ b/src/main/java/com/github/stephengold/joltjni/WheelSettingsWv.java @@ -0,0 +1,163 @@ +/* +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.RefTarget; + +/** + * Settings used to construct a {@code WheelWv}. (native type: WheelSettingsWV) + * + * @author Stephen Gold sgold@sonic.net + */ +public class WheelSettingsWv extends WheelSettings implements RefTarget { + // ************************************************************************* + // constructors + + /** + * Instantiate default settings. + */ + public WheelSettingsWv() { + super(true); + long settingsVa = createDefault(); + setVirtualAddress(settingsVa, true); + } + + /** + * Instantiate with the specified native object assigned but not owned. + * + * @param settingsVa the virtual address of the native object to assign (not + * zero) + */ + WheelSettingsWv(long settingsVa) { + super(false); + setVirtualAddress(settingsVa, false); // not owner due to ref counting + } + // ************************************************************************* + // new methods exposed + + /** + * Return the maximum torque that the hand brake can exert on the wheel. The + * settings are unaffected. (native attribute: mMaxHandBrakeTorque) + * + * @return the maximum torque (in Newton.meters) + */ + public float getMaxHandBrakeTorque() { + long settingsVa = va(); + float result = getMaxHandBrakeTorque(settingsVa); + + return result; + } + + /** + * Return the maximum steering angle. The settings are unaffected. (native + * attribute: mMaxSteerAngle) + * + * @return the maximum steering angle (in radians) + */ + public float getMaxSteerAngle() { + long settingsVa = va(); + float result = getMaxSteerAngle(settingsVa); + + return result; + } + + /** + * Alter the maximum torque that the hand brake can exert on the wheel. + * (native attribute: mMaxHandBrakeTorque) + * + * @param torque the desired torque (in Newton.meters, default=4000) + */ + public void setMaxHandBrakeTorque(float torque) { + long settingsVa = va(); + setMaxHandBrakeTorque(settingsVa, torque); + } + + /** + * Alter the maximum steering angle. (native attribute: mMaxSteerAngle) + * + * @param angle the desired maximum steering angle (in radians, + * default=7*Pi/18) + */ + public void setMaxSteerAngle(float angle) { + long settingsVa = va(); + setMaxSteerAngle(settingsVa, angle); + } + // ************************************************************************* + // RefTarget methods + + /** + * Count the active references to the native {@code WheelSettingsWv}. The + * settings are unaffected. + * + * @return the count (≥0) + */ + @Override + public int getRefCount() { + long settingsVa = va(); + int result = getRefCount(settingsVa); + + return result; + } + + /** + * Mark the native {@code WheelSettingsWv} as embedded. + */ + @Override + public void setEmbedded() { + long settingsVa = va(); + setEmbedded(settingsVa); + } + + /** + * Create a counted reference to the native {@code WheelSettingsWv}. + * + * @return a new JVM object with a new native object assigned + */ + @Override + public WheelSettingsWvRef toRef() { + long settingsVa = va(); + long refVa = toRef(settingsVa); + WheelSettingsWvRef result + = new WheelSettingsWvRef(refVa, true); + + return result; + } + // ************************************************************************* + // native private methods + + native static private long createDefault(); + + native static private float getMaxHandBrakeTorque(long settingsVa); + + native static private float getMaxSteerAngle(long settingsVa); + + native private static int getRefCount(long settingsVa); + + native private static void setEmbedded(long settingsVa); + + native static private void setMaxHandBrakeTorque( + long settingsVa, float torque); + + native static private void setMaxSteerAngle(long settingsVa, float angle); + + native private static long toRef(long settingsVa); +} diff --git a/src/main/java/com/github/stephengold/joltjni/WheelSettingsWvRef.java b/src/main/java/com/github/stephengold/joltjni/WheelSettingsWvRef.java new file mode 100644 index 00000000..e1e40cb5 --- /dev/null +++ b/src/main/java/com/github/stephengold/joltjni/WheelSettingsWvRef.java @@ -0,0 +1,87 @@ +/* +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 WheelSettingsWv} object. (native + * type: {@code Ref}) + * + * @author Stephen Gold sgold@sonic.net + */ +final public class WheelSettingsWvRef 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 + */ + WheelSettingsWvRef(long refVa, boolean owner) { + Runnable freeingAction = owner ? () -> free(refVa) : null; + setVirtualAddress(refVa, freeingAction); + } + // ************************************************************************* + // Ref methods + + /** + * Temporarily access the referenced {@code WheelSettingsWv}. + * + * @return a new JVM object that refers to the pre-existing native object + */ + @Override + public WheelSettingsWv getPtr() { + long refVa = va(); + long settingsVa = getPtr(refVa); + WheelSettingsWv result = new WheelSettingsWv(settingsVa); + + return result; + } + + /** + * Create a counted reference to the native + * {@code WheelSettingsWv}. + * + * @return a new JVM object with a new native object assigned + */ + @Override + public WheelSettingsWvRef toRef() { + long refVa = va(); + long copyVa = copy(refVa); + WheelSettingsWvRef result = new WheelSettingsWvRef(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/w/WheelSettingsWv.cpp b/src/main/native/glue/w/WheelSettingsWv.cpp new file mode 100644 index 00000000..7956c9ff --- /dev/null +++ b/src/main/native/glue/w/WheelSettingsWv.cpp @@ -0,0 +1,139 @@ +/* +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/WheeledVehicleController.h" +#include "auto/com_github_stephengold_joltjni_WheelSettingsWv.h" +#include "auto/com_github_stephengold_joltjni_WheelSettingsWvRef.h" +#include "glue/glue.h" + +using namespace JPH; + +IMPLEMENT_REF(WheelSettingsWV, + Java_com_github_stephengold_joltjni_WheelSettingsWvRef_copy, + Java_com_github_stephengold_joltjni_WheelSettingsWvRef_createEmpty, + Java_com_github_stephengold_joltjni_WheelSettingsWvRef_free, + Java_com_github_stephengold_joltjni_WheelSettingsWvRef_getPtr) + +/* + * Class: com_github_stephengold_joltjni_WheelSettingsWv + * Method: createDefault + * Signature: ()J + */ +JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_WheelSettingsWv_createDefault + (JNIEnv *, jclass) { + const WheelSettingsWV * const pSettings = new WheelSettingsWV(); + TRACE_NEW("WheelSettingsWV", pSettings) + return reinterpret_cast (pSettings); +} + +/* + * Class: com_github_stephengold_joltjni_WheelSettingsWv + * Method: getMaxHandBrakeTorque + * Signature: (J)F + */ +JNIEXPORT jfloat JNICALL Java_com_github_stephengold_joltjni_WheelSettingsWv_getMaxHandBrakeTorque + (JNIEnv *, jclass, jlong settingsVa) { + const WheelSettingsWV * const pSettings + = reinterpret_cast (settingsVa); + const float result = pSettings->mMaxHandBrakeTorque; + return result; +} + +/* + * Class: com_github_stephengold_joltjni_WheelSettingsWv + * Method: getMaxSteerAngle + * Signature: (J)F + */ +JNIEXPORT jfloat JNICALL Java_com_github_stephengold_joltjni_WheelSettingsWv_getMaxSteerAngle + (JNIEnv *, jclass, jlong settingsVa) { + const WheelSettingsWV * const pSettings + = reinterpret_cast (settingsVa); + const float result = pSettings->mMaxSteerAngle; + return result; +} + +/* + * Class: com_github_stephengold_joltjni_WheelSettingsWv + * Method: getRefCount + * Signature: (J)I + */ +JNIEXPORT jint JNICALL Java_com_github_stephengold_joltjni_WheelSettingsWv_getRefCount + (JNIEnv *, jclass, jlong settingsVa) { + const WheelSettingsWV * const pSettings + = reinterpret_cast (settingsVa); + const uint32 result = pSettings->GetRefCount(); + return result; +} + +/* + * Class: com_github_stephengold_joltjni_WheelSettingsWv + * Method: setEmbedded + * Signature: (J)V + */ +JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_WheelSettingsWv_setEmbedded + (JNIEnv *, jclass, jlong settingsVa) { + WheelSettingsWV * const pSettings + = reinterpret_cast (settingsVa); + pSettings->SetEmbedded(); +} + +/* + * Class: com_github_stephengold_joltjni_WheelSettingsWv + * Method: setMaxHandBrakeTorque + * Signature: (JF)V + */ +JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_WheelSettingsWv_setMaxHandBrakeTorque + (JNIEnv *, jclass, jlong settingsVa, jfloat torque) { + WheelSettingsWV * const pSettings + = reinterpret_cast (settingsVa); + pSettings->mMaxHandBrakeTorque = torque; +} + +/* + * Class: com_github_stephengold_joltjni_WheelSettingsWv + * Method: setMaxSteerAngle + * Signature: (JF)V + */ +JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_WheelSettingsWv_setMaxSteerAngle + (JNIEnv *, jclass, jlong settingsVa, jfloat angle) { + WheelSettingsWV * const pSettings + = reinterpret_cast (settingsVa); + pSettings->mMaxSteerAngle = angle; +} + +/* + * Class: com_github_stephengold_joltjni_WheelSettingsWv + * Method: toRef + * Signature: (J)J + */ +JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_WheelSettingsWv_toRef + (JNIEnv *, jclass, jlong settingsVa) { + WheelSettingsWV * const pSettings + = reinterpret_cast (settingsVa); + Ref * const pResult = new Ref(pSettings); + TRACE_NEW("Ref", pResult) + return reinterpret_cast (pResult); +} \ No newline at end of file