Each platform supports multiple build targets
The Jolt headers don't include Jolt/Jolt.h. Always include Jolt/Jolt.h before including any other Jolt header. You can use Jolt/Jolt.h in your precompiled header to speed up compilation.
There are a number of user configurable defines that turn on/off certain features:
<summary>General Options (click to see more)</summary>
<ul>
<li>JPH_SHARED_LIBRARY - Use the Jolt library as a shared library. Use JPH_BUILD_SHARED_LIBRARY to build Jolt as a shared library.</li>
<li>JPH_PROFILE_ENABLED - Turns on the internal profiler.</li>
<li>JPH_EXTERNAL_PROFILE - Turns on the internal profiler but forwards the information to a user defined external system (see Profiler.h).</li>
<li>JPH_DEBUG_RENDERER - Adds support to draw lines and triangles, used to be able to debug draw the state of the world.</li>
<li>JPH_DISABLE_TEMP_ALLOCATOR - Disables the temporary memory allocator, used mainly to allow ASAN to do its job.</li>
<li>JPH_DISABLE_CUSTOM_ALLOCATOR - Disables the ability to override the memory allocator.</li>
<li>JPH_FLOATING_POINT_EXCEPTIONS_ENABLED - Turns on division by zero and invalid floating point exception support in order to detect bugs (Windows only).</li>
<li>JPH_CROSS_PLATFORM_DETERMINISTIC - Turns on behavior to attempt cross platform determinism. If this is set, JPH_USE_FMADD is ignored.</li>
<li>JPH_DET_LOG - Turn on a lot of extra logging to help debug determinism issues when JPH_CROSS_PLATFORM_DETERMINISTIC is turned on.</li>
<li>JPH_ENABLE_ASSERTS - Compiles the library so that it rises an assert in case of failures. The library ignores these failures otherwise.</li>
<li>JPH_DOUBLE_PRECISION - Compiles the library so that all positions are stored in doubles instead of floats. This makes larger worlds possible.</li>
<li>JPH_OBJECT_LAYER_BITS - Defines the size of ObjectLayer, must be 16 or 32 bits.</li>
<li>JPH_OBJECT_STREAM - Includes the code to serialize physics data in the ObjectStream format (mostly used by the examples).</li>
<li>JPH_NO_FORCE_INLINE - Don't use force inlining but fall back to a regular 'inline'.</li>
<li>JPH_USE_STD_VECTOR - Use std::vector instead of Jolt's own Array class.</li>
<li>CPP_RTTI_ENABLED - Enable C++ RTTI for the library. Disabled by default.</li>
</ul>
To override the default trace and assert mechanism install your own custom handlers in Trace and AssertFailed (see IssueReporting.h).
To implement your custom memory allocator override Allocate, Free, Reallocate, AlignedAllocate and AlignedFree (see Memory.h).
If you receive the following error when linking:
/usr/bin/ld: libJolt.a: error adding symbols: file format not recognized
Then you have not enabled interprocedural optimizations (link time optimizations) for your own application. See the INTERPROCEDURAL_OPTIMIZATION option in CMakeLists.txt.
If you receive a link error that looks like:
error LNK2001: unresolved external symbol "public: virtual void __cdecl JPH::ConvexShape::GetSubmergedVolume(...) const"
you have a mismatch in defines between your own code and the Jolt library. In this case the mismatch is in the define JPH_DEBUG_RENDERER
which is most likely defined in Jolt.lib
and not in your own project. In Debug
and Release
builds, Jolt by default has JPH_DEBUG_RENDERER
defined, in Distribution
it is not defined. The cmake options DEBUG_RENDERER_IN_DEBUG_AND_RELEASE
and DEBUG_RENDERER_IN_DISTRIBUTION
override this behavior.
The RegisterTypes
function (which you have to call to initialize the library) checks the other important defines and will trace and abort if there are more mismatches.
If you receive a link error that looks like:
error: undefined symbol: typeinfo for JPH::DebugRenderer
you have a mismatch between RTTI settings (MSVC: /GR
//GR-
, clang: -frtti
/-fno-rtti
). Jolt by default compiles without RTTI and if your project compiles with RTTI you can get this error. Either turn RTTI off for your project or turn it on for Jolt using the CPP_RTTI_ENABLED cmake option.
The samples use DirectX for the graphics implementation, when attempting to run the samples you may get a DirectX error pop-up which may say "The GPU device instance has been suspended", in your debugger you may see the message "Using the Redistributable D3D12 SDKLayers dll also requires that the latest SDKLayers for Windows 10 is installed.".
Fix this by enabling "Graphics Tools" which is an optional Windows settings. To enable it you have to press the windows key, search for "Manage Optional Features", and then click "Add a Feature", and install "Graphics Tools".
If your CPU doesn't support all of the instructions you'll get an Illegal instruction
exception.
On Linux to see what instructions your CPU supports run lscpu
and then look at the flags section, on Windows you can use a program like coreinfo
. Once you know what instructions your cpu supports you can configure the project through cmake and for example disable all special instructions:
./cmake_linux_clang_gcc.sh Release clang++ -DUSE_SSE4_1=OFF -DUSE_SSE4_2=OFF -DUSE_AVX=OFF -DUSE_AVX2=OFF -DUSE_AVX512=OFF -DUSE_LZCNT=OFF -DUSE_TZCNT=OFF -DUSE_F16C=OFF -DUSE_FMADD=OFF
Note that this example is for Linux but the cmake settings work on Windows too.
Documentation can be generated through doxygen: