Skip to content

Commit

Permalink
add the (abstract) CollideShapeBodyCollector class
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Sep 9, 2024
1 parent dc69280 commit 23e74fb
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
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;

/**
* Collect body IDs from a broad-phase collision test.
*
* @author Stephen Gold [email protected]
*/
abstract public class CollideShapeBodyCollector extends JoltPhysicsObject {
// *************************************************************************
// constructors

/**
* Instantiate a collector with no native object assigned.
*/
CollideShapeBodyCollector() {
}
// *************************************************************************
// new protected methods

/**
* Assign a native object, assuming there's none already assigned.
*
* @param collectorVa the virtual address of the native object to assign
* (not zero)
* @param owner true → make the JVM object the owner, false → it
* isn't the owner
*/
void setVirtualAddress(long collectorVa, boolean owner) {
Runnable freeingAction = owner ? () -> free(collectorVa) : null;
setVirtualAddress(collectorVa, freeingAction);
}
// *************************************************************************
// native private methods

native private static void free(long collectorVa);
}
44 changes: 44 additions & 0 deletions src/main/native/glue/co/CollideShapeBodyCollector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
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/Collision/BroadPhase/BroadPhaseQuery.h>
#include "auto/com_github_stephengold_joltjni_RayCastBodyCollector.h"
#include "glue/glue.h"

using namespace JPH;

/*
* Class: com_github_stephengold_joltjni_CollideShapeBodyCollector
* Method: free
* Signature: (J)V
*/
JNIEXPORT void JNICALL Java_com_github_stephengold_joltjni_CollideShapeBodyCollector_free
(JNIEnv *, jclass, jlong collectorVa) {
CollideShapeBodyCollector * const pCollector
= reinterpret_cast<CollideShapeBodyCollector *> (collectorVa);
TRACE_DELETE("CollideShapeBodyCollector", pCollector)
delete pCollector;
}

0 comments on commit 23e74fb

Please sign in to comment.