-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add the TrackedVehicleControllerSettings class
- Loading branch information
1 parent
4c7fc1e
commit 6433cb8
Showing
2 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
89 changes: 89 additions & 0 deletions
89
src/main/java/com/github/stephengold/joltjni/TrackedVehicleControllerSettings.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,89 @@ | ||
/* | ||
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; | ||
|
||
/** | ||
* Settings used to construct a {@code TrackedVehicleController}. | ||
* | ||
* @author Stephen Gold [email protected] | ||
*/ | ||
public class TrackedVehicleControllerSettings | ||
extends VehicleControllerSettings { | ||
// ************************************************************************* | ||
// constructors | ||
|
||
/** | ||
* Instantiate default settings. | ||
*/ | ||
public TrackedVehicleControllerSettings() { | ||
long settingsVa = createDefault(); | ||
setVirtualAddress(settingsVa, true); | ||
} | ||
|
||
/** | ||
* Instantiate settings with the specified native object assigned but not | ||
* owned. | ||
* | ||
* @param settingsVa the virtual address of the native object to assign (not | ||
* zero) | ||
*/ | ||
TrackedVehicleControllerSettings(long settingsVa) { | ||
super(settingsVa); | ||
} | ||
// ************************************************************************* | ||
// new methods exposed | ||
|
||
/** | ||
* Count how many tracks the vehicle will have. The settings are unaffected. | ||
* (native attribute: mTracks) | ||
* | ||
* @return the count (≥0) | ||
*/ | ||
public int getNumTracks() { | ||
long vehicleSettingsVa = va(); | ||
int result = getNumTracks(vehicleSettingsVa); | ||
|
||
return result; | ||
} | ||
|
||
/** | ||
* Access the settings for the specified track. (native field: mTracks) | ||
* | ||
* @param index the index of the track to access (≥0) | ||
* @return a new JVM object with the pre-existing native object assigned | ||
*/ | ||
public VehicleTrackSettings getTrack(int index) { | ||
long vehicleSettingsVa = va(); | ||
long trackVa = getTrack(vehicleSettingsVa, index); | ||
VehicleTrackSettings result = new VehicleTrackSettings(this, trackVa); | ||
|
||
return result; | ||
} | ||
// ************************************************************************* | ||
// native private methods | ||
|
||
native private static long createDefault(); | ||
|
||
native private static int getNumTracks(long vehicleSettingsVa); | ||
|
||
native private static long getTrack(long vehicleSettingsVa, int index); | ||
} |
69 changes: 69 additions & 0 deletions
69
src/main/native/glue/t/TrackedVehicleControllerSettings.cpp
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,69 @@ | ||
/* | ||
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/TrackedVehicleController.h" | ||
#include "auto/com_github_stephengold_joltjni_TrackedVehicleControllerSettings.h" | ||
#include "glue/glue.h" | ||
|
||
using namespace JPH; | ||
|
||
/* | ||
* Class: com_github_stephengold_joltjni_TrackedVehicleControllerSettings | ||
* Method: createDefault | ||
* Signature: ()J | ||
*/ | ||
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_TrackedVehicleControllerSettings_createDefault | ||
(JNIEnv *, jclass) { | ||
TrackedVehicleControllerSettings * const pSettings | ||
= new TrackedVehicleControllerSettings(); | ||
TRACE_NEW("TrackedVehicleControllerSettings", pSettings) | ||
return reinterpret_cast<jlong> (pSettings); | ||
} | ||
|
||
/* | ||
* Class: com_github_stephengold_joltjni_TrackedVehicleControllerSettings | ||
* Method: getNumTracks | ||
* Signature: (J)I | ||
*/ | ||
JNIEXPORT jint JNICALL Java_com_github_stephengold_joltjni_TrackedVehicleControllerSettings_getNumTracks | ||
(JNIEnv *, jclass, jlong) { | ||
const int result = (int) ETrackSide::Num; | ||
return result; | ||
} | ||
|
||
/* | ||
* Class: com_github_stephengold_joltjni_TrackedVehicleControllerSettings | ||
* Method: getTrack | ||
* Signature: (JI)J | ||
*/ | ||
JNIEXPORT jlong JNICALL Java_com_github_stephengold_joltjni_TrackedVehicleControllerSettings_getTrack | ||
(JNIEnv *, jclass, jlong settingsVa, jint trackIndex) { | ||
TrackedVehicleControllerSettings * const pVehicleSettings | ||
= reinterpret_cast<TrackedVehicleControllerSettings *> (settingsVa); | ||
VehicleTrackSettings * const pResult | ||
= &pVehicleSettings->mTracks[trackIndex]; | ||
return reinterpret_cast<jlong> (pResult); | ||
} |