Package com.github.stephengold.joltjni
Class JoltPhysicsObject
java.lang.Object
com.github.stephengold.joltjni.JoltPhysicsObject
- All Implemented Interfaces:
ConstJoltPhysicsObject,AutoCloseable,Comparable<JoltPhysicsObject>
- Direct Known Subclasses:
AaBox,AaBoxCast,AddConvexRadiusSupport,AddConvexRadiusTab,AdditionalConstraint,Array,BodyActivationListener,BodyCreationSettings,BodyIdArray,BodyIdVector,BodyManagerDrawSettings,BroadPhaseCastResult,CastRayCollector,CastShapeBodyCollector,CastShapeCollector,CharacterBaseSettings,CharacterContactSettings,CharacterRefC,CharacterVirtualRefC,CollidePointCollector,CollidePointResult,CollideSettingsBase,CollideShapeBodyCollector,CollideShapeCollector,CollideShapeResult,CollisionEstimationResult,CollisionGroup,CombineFunction,Contact,ContactListener,ContactManifold,ContactSettings,ConvexHull,CustomCharacterContactListener,CustomPhysicsStepListener,Decomposer,DefaultRandomEngine,Edge,EpaPenetrationDepth,ExtendedUpdateSettings,Face,Geometry,GetTrianglesContext,GroupFilterToIdMap,IdToGroupFilterMap,IdToMaterialMap,IdToShapeMap,IdToSharedSettingsMap,Impulse,IndexedTriangleNoMaterial,InvBind,Joint,JointState,Lod,MassProperties,Mat44,Mat44Array,MaterialToIdMap,MotionProperties,MotorSettings,Mt19937,Mutex,NarrowPhaseStat,NonCopyable,OfStream,OrientedBox,Parameters,PhysicsMaterialRefC,PhysicsScene,PhysicsSettings,PhysicsStepListenerContext,PointConvexSupport,RagdollSettings,RayCast,RayCastBodyCollector,RayCastSettings,RayInvDirection,Ref,Result,RMat44,RodBendTwist,RodStretchShear,RRayCast,RShapeCast,Rtti,SerializableObject,ShapeRefC,ShapeSettingsRefC,ShapeToIdMap,SharedMutexBase,SharedSettingsToIdMap,SkeletalAnimation,Skeleton,SkeletonMapper,SkeletonPose,SkeletonPoseDrawSettings,Skinned,SkinWeight,SoftBodyContactListener,SoftBodyContactSettings,SoftBodyCreationSettings,SoftBodyManifold,SoftBodySharedSettings,SoftBodyVertex,Sphere,SpringSettings,StateRecorderFilter,Stats,StringStream,SubShape,SubShapeIdCreator,SubShapeIdPair,Support,SupportBuffer,TransformedConvexObject,TransformedShape,TransformedShapeCollector,Triangle,TriangleConvexSupport,UniformFloatDistribution,UniformIntDistribution,VehicleAntiRollBar,VehicleDifferentialSettings,VehicleEngineSettings,VehicleStepListener,VehicleTrackSettings,VehicleTransmissionSettings,Vertex,VertexArray,VertexAttributes,Volume
public abstract class JoltPhysicsObject
extends Object
implements AutoCloseable, ConstJoltPhysicsObject
An abstract class to represent a (native) Jolt Physics object.
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedInstantiate with no containing object and no native object assigned.protectedJoltPhysicsObject(JoltPhysicsObject container, long va) Instantiate with the specified container and native object. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Free and unassign the native object if the JVM object owns it.intcompareTo(JoltPhysicsObject other) Compare (by virtual address) with another physics object.booleanTest for type and virtual-address equality with another object.protected final JoltPhysicsObjectAccess the containing object, if any.final booleanTest whether a native object is assigned.inthashCode()Return the hash code of the physics object.static booleanTest whether a daemon thread to invoke freeing actions has been started.final booleanTest whether the JVM object owns (is responsible for freeing) its assigned native object.protected final voidsetVirtualAddress(long va) Assign a native object, assuming there's none already assigned.protected final voidsetVirtualAddress(long va, Runnable action) Assign a native object (assuming there's none already assigned) and a freeing action.static voidStart a daemon thread to process the phantom-reachable objects and invoke freeing actions, unless one has already been started.longtargetVa()Return the address of the native object, assuming this is not a counted reference.toString()Represent the physics object as a String.final longva()Return the virtual address of the assigned native object, assuming one is assigned.
-
Constructor Details
-
JoltPhysicsObject
protected JoltPhysicsObject()Instantiate with no containing object and no native object assigned. -
JoltPhysicsObject
Instantiate with the specified container and native object.- Parameters:
container- the containing object, ornullif noneva- the virtual address of the native object to assign (not zero)
-
-
Method Details
-
isCleanerStarted
public static boolean isCleanerStarted()Test whether a daemon thread to invoke freeing actions has been started.- Returns:
trueif a thread has been started, otherwisefalse
-
startCleaner
public static void startCleaner()Start a daemon thread to process the phantom-reachable objects and invoke freeing actions, unless one has already been started. -
va
public final long va()Return the virtual address of the assigned native object, assuming one is assigned. Both objects are unaffected.- Returns:
- the virtual address (not zero)
-
getContainingObject
Access the containing object, if any.- Returns:
- the pre-existing instance, or
nullif none
-
setVirtualAddress
protected final void setVirtualAddress(long va) Assign a native object, assuming there's none already assigned.- Parameters:
va- the virtual address of the native object to assign (not zero)
-
setVirtualAddress
Assign a native object (assuming there's none already assigned) and a freeing action.- Parameters:
va- the virtual address of the native object to assign (not zero)action- freeing action if the JVM object will own (be responsible for freeing) the native object, ornullif not responsible
-
close
public void close()Free and unassign the native object if the JVM object owns it. This can be invoked explicitly or by exiting a try-with-resources block.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceConstJoltPhysicsObject
-
compareTo
Compare (by virtual address) with another physics object. The current instance is unaffected.- Specified by:
compareToin interfaceComparable<JoltPhysicsObject>- Parameters:
other- (not null, unaffected)- Returns:
- 0 if the objects have the same virtual address; negative if this comes before other; positive if this comes after other
-
hasAssignedNativeObject
public final boolean hasAssignedNativeObject()Test whether a native object is assigned. Both objects are unaffected.- Specified by:
hasAssignedNativeObjectin interfaceConstJoltPhysicsObject- Returns:
trueif one is assigned, otherwisefalse
-
ownsNativeObject
public final boolean ownsNativeObject()Test whether the JVM object owns (is responsible for freeing) its assigned native object. Both objects are unaffected.- Specified by:
ownsNativeObjectin interfaceConstJoltPhysicsObject- Returns:
trueif owner, otherwisefalse
-
targetVa
public long targetVa()Return the address of the native object, assuming this is not a counted reference. No objects are affected.- Specified by:
targetVain interfaceConstJoltPhysicsObject- Returns:
- a virtual address (not zero)
-
equals
Test for type and virtual-address equality with another object. The current instance is unaffected. -
hashCode
public int hashCode()Return the hash code of the physics object. The object is unaffected.Note: operations that alter the virtual address are likely to affect the hash code as well!
-
toString
Represent the physics object as a String. The physics object is unaffected.
-