Skip to content

Commit

Permalink
add the VehicleCollisionTesterCastCylinder class + its ref class
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Oct 14, 2024
1 parent f344cd0 commit 5aab91a
Show file tree
Hide file tree
Showing 3 changed files with 301 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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 [email protected]
*/
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);
}
Original file line number Diff line number Diff line change
@@ -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<VehicleCollisionTesterCastCylinder>})
*
* @author Stephen Gold [email protected]
*/
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 &rarr; make the current object the owner, false &rarr;
* 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);
}
93 changes: 93 additions & 0 deletions src/main/native/glue/v/VehicleCollisionTesterCastCylinder.cpp
Original file line number Diff line number Diff line change
@@ -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<jlong> (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<VehicleCollisionTesterCastCylinder *> (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<VehicleCollisionTesterCastCylinder *> (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<VehicleCollisionTesterCastCylinder *> (testerVa);
Ref<VehicleCollisionTesterCastCylinder> * const pResult
= new Ref<VehicleCollisionTesterCastCylinder>(pTester);
TRACE_NEW("Ref<VehicleCollisionTesterCastCylinder>", pResult)
return reinterpret_cast<jlong> (pResult);
}

0 comments on commit 5aab91a

Please sign in to comment.