Skip to content

Commit

Permalink
WheeledVehicleControllerSettings: add 4 public methods
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Oct 13, 2024
1 parent 1d9ed68 commit 8bd8b33
Show file tree
Hide file tree
Showing 2 changed files with 199 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,62 @@ public WheeledVehicleControllerSettings() {
// *************************************************************************
// new methods exposed

/**
* Access the settings of the specified differential.
*
* @param index the index of differential to access (≥0)
* @return a new JVM object with the pre-existing native object assigned
*/
public VehicleDifferentialSettings getDifferential(int index) {
long vehicleSettingsVa = va();
long differentialVa = getDifferential(vehicleSettingsVa, index);
VehicleDifferentialSettings result
= new VehicleDifferentialSettings(this, differentialVa);

return result;
}

/**
* Access the engine settings.
*
* @return a new JVM object with the pre-existing native object assigned
*/
public VehicleEngineSettings getEngine() {
long vehicleSettingsVa = va();
long engineVa = getEngine(vehicleSettingsVa);
VehicleEngineSettings result
= new VehicleEngineSettings(this, engineVa);

return result;
}

/**
* Count how many differentials the vehicle will have. (native attribute:
* mDifferentials)
*
* @return the count (≥0)
*/
public int getNumDifferentials() {
long vehicleSettingsVa = va();
int result = countDifferentials(vehicleSettingsVa);

return result;
}

/**
* Access the transmission (gearbox) settings.
*
* @return a new JVM object with the pre-existing native object assigned
*/
public VehicleTransmissionSettings getTransmission() {
long vehicleSettingsVa = va();
long transmissionVa = getTransmission(vehicleSettingsVa);
VehicleTransmissionSettings result
= new VehicleTransmissionSettings(this, transmissionVa);

return result;
}

/**
* Alter the left wheel assigned to the specified differential.
*
Expand Down Expand Up @@ -86,8 +142,17 @@ public void setNumDifferentials(int count) {
// *************************************************************************
// native private methods

native private static int countDifferentials(long vehicleSettingsVa);

native private static long createDefault();

native private static long getDifferential(
long vehicleSettingsVa, int diffIndex);

native private static long getEngine(long vehicleSettingsVa);

native private static long getTransmission(long vehicleSettingsVa);

native private static void setDifferentialsLeftWheel(
long settingsVa, int diffIndex, int wheelIndex);

Expand Down
134 changes: 134 additions & 0 deletions src/main/native/glue/w/WheeledVehicleControllerSettings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
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_WheeledVehicleControllerSettings.h"
#include "glue/glue.h"

using namespace JPH;

/*
* Class: com_github_stephengold_joltjni_WheeledVehicleControllerSettings
* Method: countDifferentials
* Signature: (J)I
*/
JNIEXPORT jint JNICALL Java_com_github_stephengold_joltjni_WheeledVehicleControllerSettings_countDifferentials
(JNIEnv *, jclass, jlong settingsVa) {
const WheeledVehicleControllerSettings * const pSettings
= reinterpret_cast<WheeledVehicleControllerSettings *> (settingsVa);
const Array<VehicleDifferentialSettings>::size_type result
= pSettings->mDifferentials.size();
return result;
}

/*
* Class: com_github_stephengold_joltjni_WheeledVehicleControllerSettings
* Method: createDefault
* Signature: ()J
*/
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_WheeledVehicleControllerSettings_createDefault
(JNIEnv *, jclass) {
WheeledVehicleControllerSettings * const pSettings
= new WheeledVehicleControllerSettings();
TRACE_NEW("WheeledVehicleControllerSettings", pSettings)
return reinterpret_cast<jlong> (pSettings);
}

/*
* Class: com_github_stephengold_joltjni_WheeledVehicleControllerSettings
* Method: getDifferential
* Signature: (JI)J
*/
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_WheeledVehicleControllerSettings_getDifferential
(JNIEnv *, jclass, jlong settingsVa, jint index) {
WheeledVehicleControllerSettings * const pSettings
= reinterpret_cast<WheeledVehicleControllerSettings *> (settingsVa);
VehicleDifferentialSettings * const pResult
= &pSettings->mDifferentials[index];
return reinterpret_cast<jlong> (pResult);
}

/*
* Class: com_github_stephengold_joltjni_WheeledVehicleControllerSettings
* Method: getEngine
* Signature: (J)J
*/
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_WheeledVehicleControllerSettings_getEngine
(JNIEnv *, jclass, jlong settingsVa) {
WheeledVehicleControllerSettings * const pSettings
= reinterpret_cast<WheeledVehicleControllerSettings *> (settingsVa);
VehicleEngineSettings * const pResult = &pSettings->mEngine;
return reinterpret_cast<jlong> (pResult);
}

/*
* Class: com_github_stephengold_joltjni_WheeledVehicleControllerSettings
* Method: getTransmission
* Signature: (J)J
*/
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_WheeledVehicleControllerSettings_getTransmission
(JNIEnv *, jclass, jlong settingsVa) {
WheeledVehicleControllerSettings * const pSettings
= reinterpret_cast<WheeledVehicleControllerSettings *> (settingsVa);
VehicleTransmissionSettings * const pResult = &pSettings->mTransmission;
return reinterpret_cast<jlong> (pResult);
}

/*
* Class: com_github_stephengold_joltjni_WheeledVehicleControllerSettings
* Method: setDifferentialsLeftWheel
* Signature: (JII)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_WheeledVehicleControllerSettings_setDifferentialsLeftWheel
(JNIEnv *, jclass, jlong settingsVa, jint diffIndex, jint wheelIndex) {
WheeledVehicleControllerSettings * const pSettings
= reinterpret_cast<WheeledVehicleControllerSettings *> (settingsVa);
pSettings->mDifferentials[diffIndex].mLeftWheel = wheelIndex;
}

/*
* Class: com_github_stephengold_joltjni_WheeledVehicleControllerSettings
* Method: setDifferentialsLRightWheel
* Signature: (JII)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_WheeledVehicleControllerSettings_setDifferentialsLRightWheel
(JNIEnv *, jclass, jlong settingsVa, jint diffIndex, jint wheelIndex) {
WheeledVehicleControllerSettings * const pSettings
= reinterpret_cast<WheeledVehicleControllerSettings *> (settingsVa);
pSettings->mDifferentials[diffIndex].mRightWheel = wheelIndex;
}

/*
* Class: com_github_stephengold_joltjni_WheeledVehicleControllerSettings
* Method: setNumDifferentials
* Signature: (JI)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_WheeledVehicleControllerSettings_setNumDifferentials
(JNIEnv *, jclass, jlong settingsVa, jint count) {
WheeledVehicleControllerSettings * const pSettings
= reinterpret_cast<WheeledVehicleControllerSettings *> (settingsVa);
pSettings->mDifferentials.resize(count);
}

0 comments on commit 8bd8b33

Please sign in to comment.