Class JoltPhysicsObject

java.lang.Object
com.github.stephengold.joltjni.JoltPhysicsObject
All Implemented Interfaces:
ConstJoltPhysicsObject, AutoCloseable, Comparable<ConstJoltPhysicsObject>
Direct Known Subclasses:
AaBox, Array, BodyActivationListener, BodyCreationSettings, BodyId, BodyManagerDrawSettings, BroadPhaseCastResult, CastRayCollector, CastShapeCollector, CharacterBaseSettings, CharacterContactSettings, CollidePointCollector, CollidePointResult, CollideSettingsBase, CollideShapeBodyCollector, CollideShapeCollector, CollideShapeResult, CollisionGroup, CombineFunction, Contact, ContactListener, ContactManifold, ContactSettings, CustomCharacterContactListener, CustomPhysicsStepListener, DefaultRandomEngine, ExtendedUpdateSettings, IndexedTriangleNoMaterial, JointState, MassProperties, Mat44, MotionProperties, MotorSettings, Mt19937, NarrowPhaseStat, NonCopyable, PhysicsScene, PhysicsSettings, PhysicsStepListenerContext, RagdollSettings, RayCast, RayCastBodyCollector, RayCastSettings, Ref, RMat44, RRayCast, RShapeCast, ShapeRefC, ShapeResult, SharedMutexBase, SkeletalAnimation, Skeleton, SkeletonPose, SkeletonPoseDrawSettings, SpringSettings, StateRecorderFilter, SubShape, SubShapeId, SubShapeIdPair, Triangle, UniformIntDistribution, UniformRealDistribution

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 native object assigned.
  • 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.
    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, Runnable action)
    Assign a native object, assuming there's none already assigned.
    static void
    Start a daemon thread to process the phantom reachable objects and invoke freeing actions.
    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 native object assigned.
  • Method Details

    • startCleaner

      public static void startCleaner()
      Start a daemon thread to process the phantom reachable objects and invoke freeing actions.
    • setVirtualAddress

      protected final void setVirtualAddress(long virtualAddress, Runnable action)
      Assign a native object, assuming there's none already assigned.
      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 none
    • 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(ConstJoltPhysicsObject other)
      Compare (by virtual address) with another physics object. The current instance is unaffected.
      Specified by:
      compareTo in interface Comparable<ConstJoltPhysicsObject>
      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
    • va

      public final long va()
      Return the virtual address of the assigned native object, assuming one is assigned. Both objects are unaffected.
      Specified by:
      va in interface ConstJoltPhysicsObject
      Returns:
      the 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 (may be null, unaffected)
      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)