java.lang.Object
com.github.stephengold.joltjni.Jolt

public final class Jolt extends Object
Utility methods providing JNI access to Jolt Physics.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final float
    default rounding of corners in convex shapes (in meters)
    static final int
    empty sub-shape ID
    static final int
    invalid body ID
    static final int
    invalid character ID
    static final int
    standard 2nd argument to the JobSystemThreadPool constructor
    static final int
    standard first argument to the JobSystemThreadPool constructor
    static final Object
    generic null pointer (to expedite porting of C++ code)
    static final int
    index of the X component, for swizzling
    static final int
    index of the Y component, for swizzling
    static final int
    index of the Z component, for swizzling
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    Return the Jolt-JNI build-type string that's hard-coded in the native library.
    static int
    Return the cumulative number of delete operations in glue code, in Debug native libraries.
    static int
    Return the cumulative number of new operations in glue code, in Debug native libraries, excluding ref targets.
    static void
    Destroy the factory used for collision dispatch and object-stream serialization.
    static void
    detLog(String message)
    Append a message to the determinism log.
    static long
    Return the installed assert callback.
    static String
    Return a string describing some important configuration settings of the native library.
    static boolean
    Test whether the native library implements CPU-based compute systems, which are intended mainly for debugging.
    static boolean
    Test whether the native library implements compute systems based on Microsoft's DirectX 12 API.
    static boolean
    Test whether the native library implements compute systems based on Apple's Metal API.
    static boolean
    Test whether the native library implements compute systems based on Khronos's Vulkan API.
    static boolean
    Test whether the native library implements debug rendering.
    static boolean
    Test whether the native library implements extra logging to help debug determinism issues.
    static void
    installAndroidTraceCallback(int priority, String tag)
    Install an alternative trace callback that sends to the Android log with the specified priority and tag.
    static void
    installAssertCallback(long callbackVa)
    Install the specified assert callback.
    static void
    Install an alternative trace callback that writes to cerr.
    static void
    Install an alternative assert callback that crashes the JVM with an EXCEPTION_ACCESS_VIOLATION or SIGILL.
    static void
    Install the default assert callback, which writes to cout and triggers a native breakpoint.
    static void
    Install the default trace callback, which writes to cout.
    static void
    Install an alternative assert callback that silently ignores assertions.
    static void
    Install an alternative trace callback that writes to the specified PrintStream.
    static boolean
    Test whether the native library uses double-precision location vectors.
    static ByteBuffer
    Load raw bytes from the named classpath resource.
    static ByteBuffer
    newDirectByteBuffer(int numBytes)
    Create a direct ByteBuffer with native byte order and the specified capacity.
    newDirectDoubleBuffer(int numDoubles)
    Create a direct DoubleBuffer with native byte order and the specified capacity.
    newDirectFloatBuffer(int numFloats)
    Create a direct FloatBuffer with native byte order and the specified capacity.
    static IntBuffer
    newDirectIntBuffer(int numInts)
    Create a direct IntBuffer with native byte order and the specified capacity.
    static LongBuffer
    newDirectLongBuffer(int numLongs)
    Create a direct LongBuffer with native byte order and the specified capacity.
    newDirectShortBuffer(int numShorts)
    Create a direct ShortBuffer with native byte order and the specified capacity.
    static boolean
    Create a factory for collision dispatch and object-stream serialization.
    static void
    Dump profiler data.
    static void
    Terminate the profiler.
    static void
    Increment the profiler's frame counter.
    static void
    Start an instrumented code section.
    static void
    registerCustomAllocator(long allocateVa, long reallocateVa, long freeVa, long alignedAllocateVa, long alignedFreeVa)
    Register the allocation hook to use the specified functions.
    static void
    Register the allocation hook to use malloc/free.
    static void
    Register HairSettings with the factory.
    static void
    Register all physics types except HairSettings with the factory and install their collision handlers.
    static void
    setTraceAllocations(boolean setting)
    Enable or disable allocation tracing in Debug native libraries.
    static boolean
    Test whether the native library supports the ObjectStream format.
    static void
    test000(String... args)
    Execute a test written in native code.
    static void
    Unregister all physics types with the factory.
    static String
    Return the Jolt-JNI version string that's hard-coded into the native library.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • cDefaultConvexRadius

      public static final float cDefaultConvexRadius
      default rounding of corners in convex shapes (in meters)

      value should match Jolt/Physics/PhysicsSettings.h

      See Also:
    • cEmptySubShapeId

      public static final int cEmptySubShapeId
      empty sub-shape ID

      value should match Jolt/Physics/Collision/Shape/SubShapeID.h

      See Also:
    • cInvalidBodyId

      public static final int cInvalidBodyId
      invalid body ID

      value should match Jolt/Physics/Body/BodyID.h

      See Also:
    • cInvalidCharacterId

      public static final int cInvalidCharacterId
      invalid character ID

      value should match Jolt/Physics/Character/CharacterID.h

      See Also:
    • cMaxPhysicsBarriers

      public static final int cMaxPhysicsBarriers
      standard 2nd argument to the JobSystemThreadPool constructor

      value should match Jolt/Physics/PhysicsSettings.h

      See Also:
    • cMaxPhysicsJobs

      public static final int cMaxPhysicsJobs
      standard first argument to the JobSystemThreadPool constructor

      value should match Jolt/Physics/PhysicsSettings.h

      See Also:
    • SWIZZLE_X

      public static final int SWIZZLE_X
      index of the X component, for swizzling
      See Also:
    • SWIZZLE_Y

      public static final int SWIZZLE_Y
      index of the Y component, for swizzling
      See Also:
    • SWIZZLE_Z

      public static final int SWIZZLE_Z
      index of the Z component, for swizzling
      See Also:
    • nullptr

      public static final Object nullptr
      generic null pointer (to expedite porting of C++ code)
  • Method Details

    • buildType

      public static String buildType()
      Return the Jolt-JNI build-type string that's hard-coded in the native library.
      Returns:
      either "Debug" or "Release"
    • countDeletes

      public static int countDeletes()
      Return the cumulative number of delete operations in glue code, in Debug native libraries.
      Returns:
      the count (≥0)
    • countNews

      public static int countNews()
      Return the cumulative number of new operations in glue code, in Debug native libraries, excluding ref targets.
      Returns:
      the count (≥0)
    • destroyFactory

      public static void destroyFactory()
      Destroy the factory used for collision dispatch and object-stream serialization.
      See Also:
    • detLog

      public static void detLog(String message)
      Append a message to the determinism log. (native macro: JPH_DET_LOG)
      Parameters:
      message - (not null)
    • getAssertCallback

      public static long getAssertCallback()
      Return the installed assert callback.
      Returns:
      the virtual address of the callback, or zero if none
      See Also:
    • getConfigurationString

      public static String getConfigurationString()
      Return a string describing some important configuration settings of the native library. (see Jolt/ConfigurationString.h)
      Returns:
      the string value
    • implementsComputeCpu

      public static boolean implementsComputeCpu()
      Test whether the native library implements CPU-based compute systems, which are intended mainly for debugging. (native macro: JPH_USE_CPU_COMPUTE)
      Returns:
      true if implemented, otherwise false
    • implementsComputeDx12

      public static boolean implementsComputeDx12()
      Test whether the native library implements compute systems based on Microsoft's DirectX 12 API. (native macro: JPH_USE_DX12)
      Returns:
      true if implemented, otherwise false
    • implementsComputeMtl

      public static boolean implementsComputeMtl()
      Test whether the native library implements compute systems based on Apple's Metal API. (native macro: JPH_USE_MTL)
      Returns:
      true if implemented, otherwise false
    • implementsComputeVk

      public static boolean implementsComputeVk()
      Test whether the native library implements compute systems based on Khronos's Vulkan API. (native macro: JPH_USE_VK)
      Returns:
      true if implemented, otherwise false
    • implementsDebugRendering

      public static boolean implementsDebugRendering()
      Test whether the native library implements debug rendering. (native macro: JPH_DEBUG_RENDERER)
      Returns:
      true if implemented, otherwise false
    • implementsDeterminismLog

      public static boolean implementsDeterminismLog()
      Test whether the native library implements extra logging to help debug determinism issues. (native macro: JPH_ENABLE_DETERMINISM_LOG)
      Returns:
      true if implemented, otherwise false
    • installAndroidTraceCallback

      public static void installAndroidTraceCallback(int priority, String tag)
      Install an alternative trace callback that sends to the Android log with the specified priority and tag.
      Parameters:
      priority - the desired priority of trace output in the log
      tag - the log tag to identify trace output (may be null)
    • installAssertCallback

      public static void installAssertCallback(long callbackVa)
      Install the specified assert callback.
      Parameters:
      callbackVa - the virtual address of the desired callback
      See Also:
    • installCerrTraceCallback

      public static void installCerrTraceCallback()
      Install an alternative trace callback that writes to cerr.
    • installCrashAssertCallback

      public static void installCrashAssertCallback()
      Install an alternative assert callback that crashes the JVM with an EXCEPTION_ACCESS_VIOLATION or SIGILL. Intended for testing only!
    • installDefaultAssertCallback

      public static void installDefaultAssertCallback()
      Install the default assert callback, which writes to cout and triggers a native breakpoint.
    • installDefaultTraceCallback

      public static void installDefaultTraceCallback()
      Install the default trace callback, which writes to cout.
    • installIgnoreAssertCallback

      public static void installIgnoreAssertCallback()
      Install an alternative assert callback that silently ignores assertions.
    • installJavaTraceCallback

      public static void installJavaTraceCallback(PrintStream stream)
      Install an alternative trace callback that writes to the specified PrintStream.
      Parameters:
      stream - where to send trace output (not null)
    • isDoublePrecision

      public static boolean isDoublePrecision()
      Test whether the native library uses double-precision location vectors. (native macro: JPH_DOUBLE_PRECISION)
      Returns:
      true if double-precision, otherwise false
    • loadResourceAsBytes

      public static ByteBuffer loadResourceAsBytes(String resourceName)
      Load raw bytes from the named classpath resource.
      Parameters:
      resourceName - the name of the resource (not null)
      Returns:
      a new direct buffer
    • newDirectByteBuffer

      public static ByteBuffer newDirectByteBuffer(int numBytes)
      Create a direct ByteBuffer with native byte order and the specified capacity.
      Parameters:
      numBytes - the desired capacity (in bytes)
      Returns:
      a new direct buffer, zeroed and rewound but not flipped
    • newDirectDoubleBuffer

      public static DoubleBuffer newDirectDoubleBuffer(int numDoubles)
      Create a direct DoubleBuffer with native byte order and the specified capacity.
      Parameters:
      numDoubles - the desired capacity (in doubles)
      Returns:
      a new direct buffer, zeroed and rewound but not flipped
    • newDirectFloatBuffer

      public static FloatBuffer newDirectFloatBuffer(int numFloats)
      Create a direct FloatBuffer with native byte order and the specified capacity.
      Parameters:
      numFloats - the desired capacity (in floats)
      Returns:
      a new direct buffer, zeroed and rewound but not flipped
    • newDirectIntBuffer

      public static IntBuffer newDirectIntBuffer(int numInts)
      Create a direct IntBuffer with native byte order and the specified capacity.
      Parameters:
      numInts - the desired capacity (in ints)
      Returns:
      a new direct buffer, zeroed and rewound but not flipped
    • newDirectLongBuffer

      public static LongBuffer newDirectLongBuffer(int numLongs)
      Create a direct LongBuffer with native byte order and the specified capacity.
      Parameters:
      numLongs - the desired capacity (in longs)
      Returns:
      a new direct buffer, zeroed and rewound but not flipped
    • newDirectShortBuffer

      public static ShortBuffer newDirectShortBuffer(int numShorts)
      Create a direct ShortBuffer with native byte order and the specified capacity.
      Parameters:
      numShorts - the desired capacity (in shorts)
      Returns:
      a new direct buffer, zeroed and rewound but not flipped
    • newFactory

      public static boolean newFactory()
      Create a factory for collision dispatch and object-stream serialization.
      Returns:
      true if successful, otherwise false
      See Also:
    • profileDump

      public static void profileDump(String message)
      Dump profiler data. (native macro: JPH_PROFILE_DUMP)
      Parameters:
      message - (not null)
    • profileEnd

      public static void profileEnd()
      Terminate the profiler. (native macro: JPH_PROFILE_END)
    • profileNextFrame

      public static void profileNextFrame()
      Increment the profiler's frame counter. (native macro: JPH_PROFILE_NEXTFRAME)
    • profileStart

      public static void profileStart(String name)
      Start an instrumented code section. (native macro: JPH_PROFILE_START)
      Parameters:
      name - the section name (not null)
    • registerCustomAllocator

      public static void registerCustomAllocator(long allocateVa, long reallocateVa, long freeVa, long alignedAllocateVa, long alignedFreeVa)
      Register the allocation hook to use the specified functions. This must be done before any other Jolt function is called.
      Parameters:
      allocateVa - the virtual address of the desired Allocate function
      reallocateVa - the virtual address of the desired Reallocate function
      freeVa - the virtual address of the desired Free function
      alignedAllocateVa - the virtual address of the desired AlignedAllocate function
      alignedFreeVa - the virtual address of the desired AlignedFree function
    • registerDefaultAllocator

      public static void registerDefaultAllocator()
      Register the allocation hook to use malloc/free. This must be done before any other Jolt function is called. (see Jolt/Core/Memory.cpp)
    • registerHair

      public static void registerHair()
      Register HairSettings with the factory. (see Jolt/RegisterTypes.h)
      See Also:
    • registerTypes

      public static void registerTypes()
      Register all physics types except HairSettings with the factory and install their collision handlers. (see Jolt/RegisterTypes.h)
      See Also:
    • setTraceAllocations

      public static void setTraceAllocations(boolean setting)
      Enable or disable allocation tracing in Debug native libraries.
      Parameters:
      setting - true to enable tracing, false to disable it (default=false)
    • supportsObjectStream

      public static boolean supportsObjectStream()
      Test whether the native library supports the ObjectStream format. (native macro: JPH_OBJECT_STREAM)
      Returns:
      true if supported, otherwise false
    • test000

      public static void test000(String... args)
      Execute a test written in native code. Intended for testing only.
      Parameters:
      args - command-line arguments
    • unregisterTypes

      public static void unregisterTypes()
      Unregister all physics types with the factory. (see Jolt/RegisterTypes.h)
      See Also:
    • versionString

      public static String versionString()
      Return the Jolt-JNI version string that's hard-coded into the native library.
      Returns:
      the version string (not null, not empty)