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
,AddConvexRadiusSupport
,AdditionalConstraint
,Array
,BodyActivationListener
,BodyCreationSettings
,BodyIdArray
,BodyIdVector
,BodyManagerDrawSettings
,BroadPhaseCastResult
,CastRayCollector
,CastShapeCollector
,CharacterBaseSettings
,CharacterContactSettings
,CharacterRefC
,CharacterVirtualRefC
,CollidePointCollector
,CollidePointResult
,CollideSettingsBase
,CollideShapeBodyCollector
,CollideShapeCollector
,CollideShapeResult
,CollisionGroup
,CombineFunction
,Contact
,ContactListener
,ContactManifold
,ContactSettings
,ConvexHull
,CustomCharacterContactListener
,CustomPhysicsStepListener
,Decomposer
,DefaultRandomEngine
,Edge
,ExtendedUpdateSettings
,Face
,GetTrianglesContext
,IndexedTriangleNoMaterial
,InvBind
,Joint
,JointState
,MassProperties
,Mat44
,Mat44Array
,MotionProperties
,MotorSettings
,Mt19937
,Mutex
,NarrowPhaseStat
,NonCopyable
,OrientedBox
,Parameters
,PhysicsMaterialRefC
,PhysicsScene
,PhysicsSceneResult
,PhysicsSettings
,PhysicsStepListenerContext
,RagdollResult
,RagdollSettings
,RayCast
,RayCastBodyCollector
,RayCastSettings
,Ref
,RMat44
,RRayCast
,RShapeCast
,ShapeRefC
,ShapeResult
,ShapeSettingsRefC
,SharedMutexBase
,SkeletalAnimation
,Skeleton
,SkeletonMapper
,SkeletonPose
,SkeletonPoseDrawSettings
,Skinned
,SkinWeight
,SoftBodyContactListener
,SoftBodyContactSettings
,SoftBodyCreationSettings
,SoftBodyManifold
,SoftBodySharedSettings
,SoftBodyVertex
,Sphere
,SpringSettings
,StateRecorderFilter
,Stats
,StringStream
,SubShape
,SubShapeIdCreator
,SubShapeIdPair
,Support
,SupportBuffer
,TransformedShape
,TransformedShapeCollector
,Triangle
,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
ConstructorsModifierConstructorDescriptionprotected
Instantiate with no containing object and no native object assigned.protected
JoltPhysicsObject
(JoltPhysicsObject container, long virtualAddress) Instantiate with the specified container and native object. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Free and unassign the native object if the JVM object owns it.int
compareTo
(JoltPhysicsObject other) Compare (by virtual address) with another physics object.boolean
Test for type and virtual-address equality with another object.protected final JoltPhysicsObject
Access the containing object, if any.final boolean
Test whether a native object is assigned.int
hashCode()
Return the hash code of the physics object.final boolean
Test whether the JVM object owns (is responsible for freeing) its assigned native object.protected final void
setVirtualAddress
(long virtualAddress) Assign a native object, assuming there's none already assigned.protected final void
setVirtualAddress
(long virtualAddress, Runnable action) Assign a native object (assuming there's none already assigned) and freeing action.static void
Start a daemon thread to process the phantom-reachable objects and invoke freeing actions, unless one has already been started.long
targetVa()
Return the address of the native object, assuming this is not a counted reference.toString()
Represent the physics object as a String.final long
va()
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, ornull
if nonevirtualAddress
- the virtual address of the native object to assign (not zero)
-
-
Method Details
-
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
null
if none
-
setVirtualAddress
protected final void setVirtualAddress(long virtualAddress) Assign a native object, assuming there's none already assigned.- Parameters:
virtualAddress
- the virtual address of the native object to assign (not zero)
-
setVirtualAddress
Assign a native object (assuming there's none already assigned) and freeing action.- Parameters:
virtualAddress
- 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, ornull
if not responsible
-
close
public void close()Free and unassign the native object if the JVM object owns it.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceConstJoltPhysicsObject
-
compareTo
Compare (by virtual address) with another physics object. The current instance is unaffected.- Specified by:
compareTo
in 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:
hasAssignedNativeObject
in interfaceConstJoltPhysicsObject
- Returns:
true
if 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:
ownsNativeObject
in interfaceConstJoltPhysicsObject
- Returns:
true
if 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:
targetVa
in 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.
-