Skip to content

Commit

Permalink
add the WheelSettingsWv and WheelSettingsWvRef classes
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Sep 27, 2024
1 parent bbcc630 commit a3008d9
Show file tree
Hide file tree
Showing 3 changed files with 389 additions and 0 deletions.
163 changes: 163 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/WheelSettingsWv.java
Original file line number Diff line number Diff line change
@@ -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 [email protected]
*/
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);
}
Original file line number Diff line number Diff line change
@@ -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<WheelSettingsWV>})
*
* @author Stephen Gold [email protected]
*/
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 &rarr; make the current object the owner, false &rarr;
* 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);
}
139 changes: 139 additions & 0 deletions src/main/native/glue/w/WheelSettingsWv.cpp
Original file line number Diff line number Diff line change
@@ -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<jlong> (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<WheelSettingsWV *> (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<WheelSettingsWV *> (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<WheelSettingsWV *> (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<WheelSettingsWV *> (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<WheelSettingsWV *> (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<WheelSettingsWV *> (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<WheelSettingsWV *> (settingsVa);
Ref<WheelSettingsWV> * const pResult = new Ref<WheelSettingsWV>(pSettings);
TRACE_NEW("Ref<WheelSettingsWV>", pResult)
return reinterpret_cast<jlong> (pResult);
}

0 comments on commit a3008d9

Please sign in to comment.