Skip to content

Commit

Permalink
HelloWorld: static import of Jolt.*
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Nov 10, 2024
1 parent 18adfa0 commit 05babd1
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/test/java/testjoltjni/app/helloworld/HelloWorld.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ of this software and associated documentation files (the "Software"), to deal
import com.github.stephengold.joltjni.enumerate.*;
import java.io.PrintStream;
import testjoltjni.TestUtils;
import static com.github.stephengold.joltjni.Jolt.*;

/**
* A line-for-line Java translation of the Jolt Physics "hello world" sample
Expand Down Expand Up @@ -148,20 +149,20 @@ public static void main(String[] argv)
TestUtils.loadNativeLibrary();
// Register allocation hook. In this example we'll just let Jolt use malloc / free but you can override these if you want (see Memory.h).
// This needs to be done before any other Jolt function is called.
Jolt.registerDefaultAllocator();
registerDefaultAllocator();

// Install trace and assert callbacks
Jolt.installDefaultTraceCallback();
Jolt.installDefaultAssertCallback( );
installDefaultTraceCallback( );
installDefaultAssertCallback( );

// Create a factory, this class is responsible for creating instances of classes based on their name or hash and is mainly used for deserialization of saved data.
// It is not directly used in this example but still required.
Jolt.newFactory();
newFactory();

// Register all physics types with the factory and install their collision handlers with the CollisionDispatch class.
// If you have your own custom shape types you probably need to register their handlers with the CollisionDispatch before calling this function.
// If you implement your own default material (PhysicsMaterial::sDefault) make sure to initialize it before this function or else this function will create one for you.
Jolt.registerTypes();
registerTypes();

// We need a temp allocator for temporary allocations during the physics update. We're
// pre-allocating 10 MB to avoid having to do allocations during the physics update.
Expand All @@ -173,7 +174,7 @@ public static void main(String[] argv)
// We need a job system that will execute physics jobs on multiple threads. Typically
// you would implement the JobSystem interface yourself and let Jolt Physics run on top
// of your own job scheduler. JobSystemThreadPool is an example implementation.
JobSystemThreadPool job_system=new JobSystemThreadPool(Jolt.cMaxPhysicsJobs, Jolt.cMaxPhysicsBarriers, TestUtils.numThreads());
JobSystemThreadPool job_system=new JobSystemThreadPool(cMaxPhysicsJobs, cMaxPhysicsBarriers, TestUtils.numThreads());

// This is the max amount of rigid bodies that you can add to the physics system. If you try to add more you'll get an error.
// Note: This value is low because this is a simple test. For a real project use something in the order of 65536.
Expand Down Expand Up @@ -294,10 +295,10 @@ public static void main(String[] argv)
body_interface.destroyBody(floor.getId());

// Unregisters all types with the factory and cleans up the default material
Jolt.unregisterTypes();
unregisterTypes();

// Destroy the factory
Jolt.destroyFactory();
destroyFactory();

}
}

0 comments on commit 05babd1

Please sign in to comment.