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

    Constructors
    Modifier
    Constructor
    Description
    protected
    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 Type
    Method
    Description
    void
    Free and unassign the native object if the JVM object owns it.
    int
    Compare (by virtual address) with another physics object.
    boolean
    equals(Object otherObject)
    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
    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
    Return the address of the native object, assuming this is not a counted reference.
    Represent the physics object as a String.
    final long
    va()
    Return the virtual address of the assigned native object, assuming one is assigned.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

    • JoltPhysicsObject

      protected JoltPhysicsObject()
      Instantiate with no containing object and no native object assigned.
    • JoltPhysicsObject

      protected JoltPhysicsObject(JoltPhysicsObject container, long virtualAddress)
      Instantiate with the specified container and native object.
      Parameters:
      container - the containing object, or null if none
      virtualAddress - 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

      protected final JoltPhysicsObject 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

      protected final void setVirtualAddress(long virtualAddress, Runnable action)
      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, or null if not responsible
    • close

      public void close()
      Free and unassign the native object if the JVM object owns it.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface ConstJoltPhysicsObject
    • compareTo

      public int compareTo(JoltPhysicsObject other)
      Compare (by virtual address) with another physics object. The current instance is unaffected.
      Specified by:
      compareTo in interface Comparable<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 interface ConstJoltPhysicsObject
      Returns:
      true if one is assigned, otherwise false
    • 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 interface ConstJoltPhysicsObject
      Returns:
      true if owner, otherwise false
    • 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 interface ConstJoltPhysicsObject
      Returns:
      a virtual address (not zero)
    • equals

      public boolean equals(Object otherObject)
      Test for type and virtual-address equality with another object. The current instance is unaffected.
      Overrides:
      equals in class Object
      Parameters:
      otherObject - the object to compare (unaffected) or null
      Returns:
      true if this and otherObject have the same type and virtual address, otherwise false
    • 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!

      Overrides:
      hashCode in class Object
      Returns:
      a 32-bit value for use in hashing
    • toString

      public String toString()
      Represent the physics object as a String. The physics object is unaffected.
      Overrides:
      toString in class Object
      Returns:
      a descriptive string of text (not null, not empty)