Jolt Physics
A multi core friendly Game Physics Engine
Loading...
Searching...
No Matches
Core.h
Go to the documentation of this file.
1// Jolt Physics Library (https://github.com/jrouwe/JoltPhysics)
2// SPDX-FileCopyrightText: 2021 Jorrit Rouwe
3// SPDX-License-Identifier: MIT
4
5#pragma once
6
7// Jolt library version
8#define JPH_VERSION_MAJOR 5
9#define JPH_VERSION_MINOR 5
10#define JPH_VERSION_PATCH 1
11
12// Determine which features the library was compiled with
13#ifdef JPH_DOUBLE_PRECISION
14 #define JPH_VERSION_FEATURE_BIT_1 1
15#else
16 #define JPH_VERSION_FEATURE_BIT_1 0
17#endif
18#ifdef JPH_CROSS_PLATFORM_DETERMINISTIC
19 #define JPH_VERSION_FEATURE_BIT_2 1
20#else
21 #define JPH_VERSION_FEATURE_BIT_2 0
22#endif
23#ifdef JPH_FLOATING_POINT_EXCEPTIONS_ENABLED
24 #define JPH_VERSION_FEATURE_BIT_3 1
25#else
26 #define JPH_VERSION_FEATURE_BIT_3 0
27#endif
28#ifdef JPH_PROFILE_ENABLED
29 #define JPH_VERSION_FEATURE_BIT_4 1
30#else
31 #define JPH_VERSION_FEATURE_BIT_4 0
32#endif
33#ifdef JPH_EXTERNAL_PROFILE
34 #define JPH_VERSION_FEATURE_BIT_5 1
35#else
36 #define JPH_VERSION_FEATURE_BIT_5 0
37#endif
38#ifdef JPH_DEBUG_RENDERER
39 #define JPH_VERSION_FEATURE_BIT_6 1
40#else
41 #define JPH_VERSION_FEATURE_BIT_6 0
42#endif
43#ifdef JPH_DISABLE_TEMP_ALLOCATOR
44 #define JPH_VERSION_FEATURE_BIT_7 1
45#else
46 #define JPH_VERSION_FEATURE_BIT_7 0
47#endif
48#ifdef JPH_DISABLE_CUSTOM_ALLOCATOR
49 #define JPH_VERSION_FEATURE_BIT_8 1
50#else
51 #define JPH_VERSION_FEATURE_BIT_8 0
52#endif
53#if defined(JPH_OBJECT_LAYER_BITS) && JPH_OBJECT_LAYER_BITS == 32
54 #define JPH_VERSION_FEATURE_BIT_9 1
55#else
56 #define JPH_VERSION_FEATURE_BIT_9 0
57#endif
58#ifdef JPH_ENABLE_ASSERTS
59 #define JPH_VERSION_FEATURE_BIT_10 1
60#else
61 #define JPH_VERSION_FEATURE_BIT_10 0
62#endif
63#ifdef JPH_OBJECT_STREAM
64 #define JPH_VERSION_FEATURE_BIT_11 1
65#else
66 #define JPH_VERSION_FEATURE_BIT_11 0
67#endif
68#define JPH_VERSION_FEATURES (uint64(JPH_VERSION_FEATURE_BIT_1) | (JPH_VERSION_FEATURE_BIT_2 << 1) | (JPH_VERSION_FEATURE_BIT_3 << 2) | (JPH_VERSION_FEATURE_BIT_4 << 3) | (JPH_VERSION_FEATURE_BIT_5 << 4) | (JPH_VERSION_FEATURE_BIT_6 << 5) | (JPH_VERSION_FEATURE_BIT_7 << 6) | (JPH_VERSION_FEATURE_BIT_8 << 7) | (JPH_VERSION_FEATURE_BIT_9 << 8) | (JPH_VERSION_FEATURE_BIT_10 << 9) | (JPH_VERSION_FEATURE_BIT_11 << 10))
69
70// Combine the version and features in a single ID
71#define JPH_VERSION_ID ((JPH_VERSION_FEATURES << 24) | (JPH_VERSION_MAJOR << 16) | (JPH_VERSION_MINOR << 8) | JPH_VERSION_PATCH)
72
73// Determine platform
74#if defined(JPH_PLATFORM_BLUE)
75 // Correct define already defined, this overrides everything else
76#elif defined(_WIN32) || defined(_WIN64)
77 #include <winapifamily.h>
78 #if WINAPI_FAMILY == WINAPI_FAMILY_APP
79 #define JPH_PLATFORM_WINDOWS_UWP // Building for Universal Windows Platform
80 #endif
81 #define JPH_PLATFORM_WINDOWS
82#elif defined(__ANDROID__) // Android is linux too, so that's why we check it first
83 #define JPH_PLATFORM_ANDROID
84#elif defined(__linux__)
85 #define JPH_PLATFORM_LINUX
86#elif defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__)
87 #define JPH_PLATFORM_BSD
88#elif defined(__APPLE__)
89 #include <TargetConditionals.h>
90 #if defined(TARGET_OS_IPHONE) && !TARGET_OS_IPHONE
91 #define JPH_PLATFORM_MACOS
92 #else
93 #define JPH_PLATFORM_IOS
94 #endif
95#elif defined(__EMSCRIPTEN__)
96 #define JPH_PLATFORM_WASM
97#endif
98
99// Platform helper macros
100#ifdef JPH_PLATFORM_ANDROID
101 #define JPH_IF_NOT_ANDROID(x)
102#else
103 #define JPH_IF_NOT_ANDROID(x) x
104#endif
105
106// Determine compiler
107#if defined(__clang__)
108 #define JPH_COMPILER_CLANG
109#elif defined(__GNUC__)
110 #define JPH_COMPILER_GCC
111#elif defined(_MSC_VER)
112 #define JPH_COMPILER_MSVC
113#endif
114
115#if defined(__MINGW64__) || defined (__MINGW32__)
116 #define JPH_COMPILER_MINGW
117#endif
118
119// Detect CPU architecture
120#if defined(__aarch64__) || defined(_M_ARM64) || defined(__arm__) || defined(_M_ARM) || defined(_M_ARM64EC)
121 // ARM CPU architecture
122 #define JPH_CPU_ARM
123 #if defined(__aarch64__) || defined(_M_ARM64) || defined(_M_ARM64EC)
124 #define JPH_CPU_ARCH_BITS 64
125 #define JPH_USE_NEON
126 #define JPH_VECTOR_ALIGNMENT 16
127 #define JPH_DVECTOR_ALIGNMENT 32
128 #else
129 #define JPH_CPU_ARCH_BITS 32
130 #define JPH_VECTOR_ALIGNMENT 8 // 32-bit ARM does not support aligning on the stack on 16 byte boundaries
131 #define JPH_DVECTOR_ALIGNMENT 8
132 #endif
133 #ifndef JPH_CROSS_PLATFORM_DETERMINISTIC // FMA is not compatible with cross platform determinism
134 #if defined(__ARM_FEATURE_FMA) && !defined(JPH_USE_FMADD)
135 #define JPH_USE_FMADD
136 #endif
137 #endif
138#elif defined(__x86_64__) || defined(_M_X64) || defined(__i386__) || defined(_M_IX86)
139 // X86 CPU architecture
140 #define JPH_CPU_X86
141 #if defined(__x86_64__) || defined(_M_X64)
142 #define JPH_CPU_ARCH_BITS 64
143 #else
144 #define JPH_CPU_ARCH_BITS 32
145 #endif
146 #define JPH_USE_SSE
147 #define JPH_VECTOR_ALIGNMENT 16
148 #define JPH_DVECTOR_ALIGNMENT 32
149
150 // Detect enabled instruction sets
151 #if defined(__AVX512F__) && defined(__AVX512VL__) && defined(__AVX512DQ__) && !defined(JPH_USE_AVX512)
152 #define JPH_USE_AVX512
153 #endif
154 #if (defined(__AVX2__) || defined(JPH_USE_AVX512)) && !defined(JPH_USE_AVX2)
155 #define JPH_USE_AVX2
156 #endif
157 #if (defined(__AVX__) || defined(JPH_USE_AVX2)) && !defined(JPH_USE_AVX)
158 #define JPH_USE_AVX
159 #endif
160 #if (defined(__SSE4_2__) || defined(JPH_USE_AVX)) && !defined(JPH_USE_SSE4_2)
161 #define JPH_USE_SSE4_2
162 #endif
163 #if (defined(__SSE4_1__) || defined(JPH_USE_SSE4_2)) && !defined(JPH_USE_SSE4_1)
164 #define JPH_USE_SSE4_1
165 #endif
166 #if (defined(__F16C__) || defined(JPH_USE_AVX2)) && !defined(JPH_USE_F16C)
167 #define JPH_USE_F16C
168 #endif
169 #if (defined(__LZCNT__) || defined(JPH_USE_AVX2)) && !defined(JPH_USE_LZCNT)
170 #define JPH_USE_LZCNT
171 #endif
172 #if (defined(__BMI__) || defined(JPH_USE_AVX2)) && !defined(JPH_USE_TZCNT)
173 #define JPH_USE_TZCNT
174 #endif
175 #ifndef JPH_CROSS_PLATFORM_DETERMINISTIC // FMA is not compatible with cross platform determinism
176 #if defined(JPH_COMPILER_CLANG) || defined(JPH_COMPILER_GCC)
177 #if defined(__FMA__) && !defined(JPH_USE_FMADD)
178 #define JPH_USE_FMADD
179 #endif
180 #elif defined(JPH_COMPILER_MSVC)
181 #if defined(__AVX2__) && !defined(JPH_USE_FMADD) // AVX2 also enables fused multiply add
182 #define JPH_USE_FMADD
183 #endif
184 #else
185 #error Undefined compiler
186 #endif
187 #endif
188#elif defined(__riscv)
189 // RISC-V CPU architecture
190 #define JPH_CPU_RISCV
191 #if __riscv_xlen == 64
192 #define JPH_CPU_ARCH_BITS 64
193 #define JPH_VECTOR_ALIGNMENT 16
194 #define JPH_DVECTOR_ALIGNMENT 32
195 #else
196 #define JPH_CPU_ARCH_BITS 32
197 #define JPH_VECTOR_ALIGNMENT 16
198 #define JPH_DVECTOR_ALIGNMENT 8
199 #endif
200 #if defined(__riscv_vector)
201 #define JPH_USE_RVV
202 #endif
203#elif defined(JPH_PLATFORM_WASM)
204 // WebAssembly CPU architecture
205 #define JPH_CPU_WASM
206 #if defined(__wasm64__)
207 #define JPH_CPU_ARCH_BITS 64
208 #else
209 #define JPH_CPU_ARCH_BITS 32
210 #endif
211 #define JPH_VECTOR_ALIGNMENT 16
212 #define JPH_DVECTOR_ALIGNMENT 32
213 #ifdef __wasm_simd128__
214 #define JPH_USE_SSE
215 #define JPH_USE_SSE4_1
216 #define JPH_USE_SSE4_2
217 #endif
218#elif defined(__powerpc__) || defined(__powerpc64__)
219 // PowerPC CPU architecture
220 #define JPH_CPU_PPC
221 #if defined(__powerpc64__)
222 #define JPH_CPU_ARCH_BITS 64
223 #else
224 #define JPH_CPU_ARCH_BITS 32
225 #endif
226 #ifdef _BIG_ENDIAN
227 #define JPH_CPU_BIG_ENDIAN
228 #endif
229 #define JPH_VECTOR_ALIGNMENT 16
230 #define JPH_DVECTOR_ALIGNMENT 8
231#elif defined(__loongarch__)
232 // LoongArch CPU architecture
233 #define JPH_CPU_LOONGARCH
234 #if defined(__loongarch64)
235 #define JPH_CPU_ARCH_BITS 64
236 #else
237 #define JPH_CPU_ARCH_BITS 32
238 #endif
239 #define JPH_VECTOR_ALIGNMENT 16
240 #define JPH_DVECTOR_ALIGNMENT 8
241#elif defined(__e2k__)
242 // E2K CPU architecture (MCST Elbrus 2000)
243 #define JPH_CPU_E2K
244 #define JPH_CPU_ARCH_BITS 64
245 #define JPH_VECTOR_ALIGNMENT 16
246 #define JPH_DVECTOR_ALIGNMENT 32
247
248 // Compiler flags on e2k arch determine CPU features
249 #if defined(__SSE__) && !defined(JPH_USE_SSE)
250 #define JPH_USE_SSE
251 #endif
252#else
253 #error Unsupported CPU architecture
254#endif
255
256// If this define is set, Jolt is compiled as a shared library
257#ifdef JPH_SHARED_LIBRARY
258 #ifdef JPH_BUILD_SHARED_LIBRARY
259 // While building the shared library, we must export these symbols
260 #if defined(JPH_PLATFORM_WINDOWS) && !defined(JPH_COMPILER_MINGW)
261 #define JPH_EXPORT __declspec(dllexport)
262 #else
263 #define JPH_EXPORT __attribute__ ((visibility ("default")))
264 #if defined(JPH_COMPILER_GCC)
265 // Prevents an issue with GCC attribute parsing (see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69585)
266 #define JPH_EXPORT_GCC_BUG_WORKAROUND [[gnu::visibility("default")]]
267 #endif
268 #endif
269 #else
270 // When linking against Jolt, we must import these symbols
271 #if defined(JPH_PLATFORM_WINDOWS) && !defined(JPH_COMPILER_MINGW)
272 #define JPH_EXPORT __declspec(dllimport)
273 #else
274 #define JPH_EXPORT __attribute__ ((visibility ("default")))
275 #if defined(JPH_COMPILER_GCC)
276 // Prevents an issue with GCC attribute parsing (see https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69585)
277 #define JPH_EXPORT_GCC_BUG_WORKAROUND [[gnu::visibility("default")]]
278 #endif
279 #endif
280 #endif
281#else
282 // If the define is not set, we use static linking and symbols don't need to be imported or exported
283 #define JPH_EXPORT
284#endif
285
286#ifndef JPH_EXPORT_GCC_BUG_WORKAROUND
287 #define JPH_EXPORT_GCC_BUG_WORKAROUND JPH_EXPORT
288#endif
289
290// Macro used by the RTTI macros to not export a function
291#define JPH_NO_EXPORT
292
293// Pragmas to store / restore the warning state and to disable individual warnings
294#ifdef JPH_COMPILER_CLANG
295#define JPH_PRAGMA(x) _Pragma(#x)
296#define JPH_SUPPRESS_WARNING_PUSH JPH_PRAGMA(clang diagnostic push)
297#define JPH_SUPPRESS_WARNING_POP JPH_PRAGMA(clang diagnostic pop)
298#define JPH_CLANG_SUPPRESS_WARNING(w) JPH_PRAGMA(clang diagnostic ignored w)
299#if __clang_major__ >= 13
300 #define JPH_CLANG_13_PLUS_SUPPRESS_WARNING(w) JPH_CLANG_SUPPRESS_WARNING(w)
301#else
302 #define JPH_CLANG_13_PLUS_SUPPRESS_WARNING(w)
303#endif
304#if __clang_major__ >= 16
305 #define JPH_CLANG_16_PLUS_SUPPRESS_WARNING(w) JPH_CLANG_SUPPRESS_WARNING(w)
306#else
307 #define JPH_CLANG_16_PLUS_SUPPRESS_WARNING(w)
308#endif
309#else
310#define JPH_CLANG_SUPPRESS_WARNING(w)
311#define JPH_CLANG_13_PLUS_SUPPRESS_WARNING(w)
312#define JPH_CLANG_16_PLUS_SUPPRESS_WARNING(w)
313#endif
314#ifdef JPH_COMPILER_GCC
315#define JPH_PRAGMA(x) _Pragma(#x)
316#define JPH_SUPPRESS_WARNING_PUSH JPH_PRAGMA(GCC diagnostic push)
317#define JPH_SUPPRESS_WARNING_POP JPH_PRAGMA(GCC diagnostic pop)
318#define JPH_GCC_SUPPRESS_WARNING(w) JPH_PRAGMA(GCC diagnostic ignored w)
319#else
320#define JPH_GCC_SUPPRESS_WARNING(w)
321#endif
322#ifdef JPH_COMPILER_MSVC
323#define JPH_PRAGMA(x) __pragma(x)
324#define JPH_SUPPRESS_WARNING_PUSH JPH_PRAGMA(warning (push))
325#define JPH_SUPPRESS_WARNING_POP JPH_PRAGMA(warning (pop))
326#define JPH_MSVC_SUPPRESS_WARNING(w) JPH_PRAGMA(warning (disable : w))
327#if _MSC_VER >= 1920 && _MSC_VER < 1930
328 #define JPH_MSVC2019_SUPPRESS_WARNING(w) JPH_MSVC_SUPPRESS_WARNING(w)
329#else
330 #define JPH_MSVC2019_SUPPRESS_WARNING(w)
331#endif
332#if _MSC_VER >= 1950
333#define JPH_MSVC2026_PLUS_SUPPRESS_WARNING(w) JPH_MSVC_SUPPRESS_WARNING(w)
334#else
335#define JPH_MSVC2026_PLUS_SUPPRESS_WARNING(w)
336#endif
337#else
338#define JPH_MSVC_SUPPRESS_WARNING(w)
339#define JPH_MSVC2019_SUPPRESS_WARNING(w)
340#define JPH_MSVC2026_PLUS_SUPPRESS_WARNING(w)
341#endif
342
343// Disable common warnings triggered by Jolt when compiling with -Wall
344#define JPH_SUPPRESS_WARNINGS \
345 JPH_CLANG_SUPPRESS_WARNING("-Wc++98-compat") \
346 JPH_CLANG_SUPPRESS_WARNING("-Wc++98-compat-pedantic") \
347 JPH_CLANG_SUPPRESS_WARNING("-Wfloat-equal") \
348 JPH_CLANG_SUPPRESS_WARNING("-Wsign-conversion") \
349 JPH_CLANG_SUPPRESS_WARNING("-Wold-style-cast") \
350 JPH_CLANG_SUPPRESS_WARNING("-Wgnu-anonymous-struct") \
351 JPH_CLANG_SUPPRESS_WARNING("-Wnested-anon-types") \
352 JPH_CLANG_SUPPRESS_WARNING("-Wglobal-constructors") \
353 JPH_CLANG_SUPPRESS_WARNING("-Wexit-time-destructors") \
354 JPH_CLANG_SUPPRESS_WARNING("-Wnonportable-system-include-path") \
355 JPH_CLANG_SUPPRESS_WARNING("-Wlanguage-extension-token") \
356 JPH_CLANG_SUPPRESS_WARNING("-Wunused-parameter") \
357 JPH_CLANG_SUPPRESS_WARNING("-Wformat-nonliteral") \
358 JPH_CLANG_SUPPRESS_WARNING("-Wcovered-switch-default") \
359 JPH_CLANG_SUPPRESS_WARNING("-Wcast-align") \
360 JPH_CLANG_SUPPRESS_WARNING("-Winvalid-offsetof") \
361 JPH_CLANG_SUPPRESS_WARNING("-Wgnu-zero-variadic-macro-arguments") \
362 JPH_CLANG_SUPPRESS_WARNING("-Wdocumentation-unknown-command") \
363 JPH_CLANG_SUPPRESS_WARNING("-Wctad-maybe-unsupported") \
364 JPH_CLANG_SUPPRESS_WARNING("-Wswitch-default") \
365 JPH_CLANG_13_PLUS_SUPPRESS_WARNING("-Wdeprecated-copy") \
366 JPH_CLANG_13_PLUS_SUPPRESS_WARNING("-Wdeprecated-copy-with-dtor") \
367 JPH_CLANG_16_PLUS_SUPPRESS_WARNING("-Wunsafe-buffer-usage") \
368 JPH_IF_NOT_ANDROID(JPH_CLANG_SUPPRESS_WARNING("-Wimplicit-int-float-conversion")) \
369 \
370 JPH_GCC_SUPPRESS_WARNING("-Wcomment") \
371 JPH_GCC_SUPPRESS_WARNING("-Winvalid-offsetof") \
372 JPH_GCC_SUPPRESS_WARNING("-Wclass-memaccess") \
373 JPH_GCC_SUPPRESS_WARNING("-Wpedantic") \
374 JPH_GCC_SUPPRESS_WARNING("-Wunused-parameter") \
375 JPH_GCC_SUPPRESS_WARNING("-Wmaybe-uninitialized") \
376 \
377 JPH_MSVC_SUPPRESS_WARNING(4619) /* #pragma warning: there is no warning number 'XXXX' */ \
378 JPH_MSVC_SUPPRESS_WARNING(4514) /* 'X' : unreferenced inline function has been removed */ \
379 JPH_MSVC_SUPPRESS_WARNING(4710) /* 'X' : function not inlined */ \
380 JPH_MSVC_SUPPRESS_WARNING(4711) /* function 'X' selected for automatic inline expansion */ \
381 JPH_MSVC_SUPPRESS_WARNING(4714) /* function 'X' marked as __forceinline not inlined */ \
382 JPH_MSVC_SUPPRESS_WARNING(4820) /* 'X': 'Y' bytes padding added after data member 'Z' */ \
383 JPH_MSVC_SUPPRESS_WARNING(4100) /* 'X' : unreferenced formal parameter */ \
384 JPH_MSVC_SUPPRESS_WARNING(4626) /* 'X' : assignment operator was implicitly defined as deleted because a base class assignment operator is inaccessible or deleted */ \
385 JPH_MSVC_SUPPRESS_WARNING(5027) /* 'X' : move assignment operator was implicitly defined as deleted because a base class move assignment operator is inaccessible or deleted */ \
386 JPH_MSVC_SUPPRESS_WARNING(4365) /* 'argument' : conversion from 'X' to 'Y', signed / unsigned mismatch */ \
387 JPH_MSVC_SUPPRESS_WARNING(4324) /* 'X' : structure was padded due to alignment specifier */ \
388 JPH_MSVC_SUPPRESS_WARNING(4625) /* 'X' : copy constructor was implicitly defined as deleted because a base class copy constructor is inaccessible or deleted */ \
389 JPH_MSVC_SUPPRESS_WARNING(5026) /* 'X': move constructor was implicitly defined as deleted because a base class move constructor is inaccessible or deleted */ \
390 JPH_MSVC_SUPPRESS_WARNING(4623) /* 'X' : default constructor was implicitly defined as deleted */ \
391 JPH_MSVC_SUPPRESS_WARNING(4201) /* nonstandard extension used: nameless struct/union */ \
392 JPH_MSVC_SUPPRESS_WARNING(4371) /* 'X': layout of class may have changed from a previous version of the compiler due to better packing of member 'Y' */ \
393 JPH_MSVC_SUPPRESS_WARNING(5045) /* Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified */ \
394 JPH_MSVC_SUPPRESS_WARNING(4583) /* 'X': destructor is not implicitly called */ \
395 JPH_MSVC_SUPPRESS_WARNING(4582) /* 'X': constructor is not implicitly called */ \
396 JPH_MSVC_SUPPRESS_WARNING(5219) /* implicit conversion from 'X' to 'Y', possible loss of data */ \
397 JPH_MSVC_SUPPRESS_WARNING(4826) /* Conversion from 'X *' to 'JPH::uint64' is sign-extended. This may cause unexpected runtime behavior. (32-bit) */ \
398 JPH_MSVC_SUPPRESS_WARNING(5264) /* 'X': 'const' variable is not used */ \
399 JPH_MSVC_SUPPRESS_WARNING(4251) /* class 'X' needs to have DLL-interface to be used by clients of class 'Y' */ \
400 JPH_MSVC_SUPPRESS_WARNING(4738) /* storing 32-bit float result in memory, possible loss of performance */ \
401 JPH_MSVC2019_SUPPRESS_WARNING(5246) /* the initialization of a subobject should be wrapped in braces */ \
402 JPH_MSVC2026_PLUS_SUPPRESS_WARNING(5291) /* 'X': deriving from the base class 'Y' can cause potential runtime issues due to an ABI bug. Recommend adding a 4-byte data member to the base class for the padding at the end of it to work around this bug. */
403
404// OS-specific includes
405#if defined(JPH_PLATFORM_WINDOWS)
406 #define JPH_BREAKPOINT __debugbreak()
407#elif defined(JPH_PLATFORM_BLUE)
408 // Configuration for a popular game console.
409 // This file is not distributed because it would violate an NDA.
410 // Creating one should only be a couple of minutes of work if you have the documentation for the platform
411 // (you only need to define JPH_BREAKPOINT, JPH_PLATFORM_BLUE_GET_TICKS, JPH_PLATFORM_BLUE_MUTEX*, JPH_PLATFORM_BLUE_RWLOCK*, JPH_PLATFORM_BLUE_SEMAPHORE* and include the right header).
412 #include <Jolt/Core/PlatformBlue.h>
413#elif defined(JPH_PLATFORM_LINUX) || defined(JPH_PLATFORM_ANDROID) || defined(JPH_PLATFORM_MACOS) || defined(JPH_PLATFORM_IOS) || defined(JPH_PLATFORM_BSD)
414 #if defined(JPH_CPU_X86)
415 #define JPH_BREAKPOINT __asm volatile ("int $0x3")
416 #elif defined(JPH_CPU_ARM) || defined(JPH_CPU_RISCV) || defined(JPH_CPU_E2K) || defined(JPH_CPU_PPC) || defined(JPH_CPU_LOONGARCH)
417 #define JPH_BREAKPOINT __builtin_trap()
418 #else
419 #error Unknown CPU architecture
420 #endif
421#elif defined(JPH_PLATFORM_WASM)
422 #define JPH_BREAKPOINT do { } while (false) // Not supported
423#else
424 #error Unknown platform
425#endif
426
427// Begin the JPH namespace
428#define JPH_NAMESPACE_BEGIN \
429 JPH_SUPPRESS_WARNING_PUSH \
430 JPH_SUPPRESS_WARNINGS \
431 namespace JPH {
432
433// End the JPH namespace
434#define JPH_NAMESPACE_END \
435 } \
436 JPH_SUPPRESS_WARNING_POP
437
438// Suppress warnings generated by the standard template library
439#define JPH_SUPPRESS_WARNINGS_STD_BEGIN \
440 JPH_SUPPRESS_WARNING_PUSH \
441 JPH_MSVC_SUPPRESS_WARNING(4365) \
442 JPH_MSVC_SUPPRESS_WARNING(4619) \
443 JPH_MSVC_SUPPRESS_WARNING(4710) \
444 JPH_MSVC_SUPPRESS_WARNING(4711) \
445 JPH_MSVC_SUPPRESS_WARNING(4820) \
446 JPH_MSVC_SUPPRESS_WARNING(4514) \
447 JPH_MSVC_SUPPRESS_WARNING(5262) \
448 JPH_MSVC_SUPPRESS_WARNING(5264) \
449 JPH_MSVC_SUPPRESS_WARNING(4738) \
450 JPH_MSVC_SUPPRESS_WARNING(5045)
451
452#define JPH_SUPPRESS_WARNINGS_STD_END \
453 JPH_SUPPRESS_WARNING_POP
454
455// MSVC STL requires _HAS_EXCEPTIONS=0 if exceptions are turned off
456#if defined(JPH_COMPILER_MSVC) && (!defined(__cpp_exceptions) || !__cpp_exceptions) && !defined(_HAS_EXCEPTIONS)
457 #define _HAS_EXCEPTIONS 0
458#endif
459
460// Standard C++ includes
462#include <float.h>
463#include <limits.h>
464#include <string.h>
465#include <new>
466#include <utility>
467#include <cmath>
468#include <sstream>
469#include <functional>
470#include <algorithm>
471#include <cstdint>
472#include <type_traits>
473#if defined(JPH_COMPILER_MSVC) || (defined(JPH_COMPILER_CLANG) && defined(_MSC_VER)) // MSVC or clang-cl
474 #include <malloc.h> // for alloca
475#endif
476#if defined(JPH_USE_SSE)
477 #include <immintrin.h>
478#elif defined(JPH_USE_NEON)
479 #ifdef JPH_COMPILER_MSVC
480 #include <intrin.h>
481 #include <arm64_neon.h>
482 #else
483 #include <arm_neon.h>
484 #endif
485#elif defined(JPH_USE_RVV)
486 #include <riscv_vector.h>
487#endif
489
491
492// Commonly used STL types
493using std::min;
494using std::max;
495using std::abs;
496using std::ceil;
497using std::floor;
498using std::trunc;
499using std::round;
500using std::fmod;
501using std::string_view;
502using std::function;
503using std::numeric_limits;
504using std::isfinite;
505using std::isnan;
506using std::ostream;
507using std::istream;
508
509// Standard types
510using uint = unsigned int;
511using uint8 = std::uint8_t;
512using uint16 = std::uint16_t;
513using uint32 = std::uint32_t;
514using int32 = std::int32_t;
515using uint64 = std::uint64_t;
516using int64 = std::int64_t;
517
518// Assert sizes of types
519static_assert(sizeof(uint) >= 4, "Invalid size of uint");
520static_assert(sizeof(uint8) == 1, "Invalid size of uint8");
521static_assert(sizeof(uint16) == 2, "Invalid size of uint16");
522static_assert(sizeof(uint32) == 4, "Invalid size of uint32");
523static_assert(sizeof(uint64) == 8, "Invalid size of uint64");
524
525// Determine if we want extra debugging code to be active
526#if !defined(NDEBUG) && !defined(JPH_NO_DEBUG)
527 #define JPH_DEBUG
528#endif
529
530// Define inline macro
531#if defined(JPH_NO_FORCE_INLINE)
532 #define JPH_INLINE inline
533#elif defined(JPH_COMPILER_CLANG)
534 #define JPH_INLINE __inline__ __attribute__((always_inline))
535#elif defined(JPH_COMPILER_GCC)
536 // On gcc 14 using always_inline in debug mode causes error: "inlining failed in call to 'always_inline' 'XXX': function not considered for inlining"
537 // See: https://github.com/jrouwe/JoltPhysics/issues/1096
538 #if __GNUC__ >= 14 && defined(JPH_DEBUG)
539 #define JPH_INLINE inline
540 #else
541 #define JPH_INLINE __inline__ __attribute__((always_inline))
542 #endif
543#elif defined(JPH_COMPILER_MSVC)
544 #define JPH_INLINE __forceinline
545#else
546 #error Undefined
547#endif
548
549// Default memory allocation alignment.
550// This define can be overridden in case the user provides an Allocate function that has a different alignment than the platform default.
551#ifndef JPH_DEFAULT_ALLOCATE_ALIGNMENT
552 #define JPH_DEFAULT_ALLOCATE_ALIGNMENT __STDCPP_DEFAULT_NEW_ALIGNMENT__
553#endif
554
555// Cache line size (used for aligning to cache line)
556#ifndef JPH_CACHE_LINE_SIZE
557 #define JPH_CACHE_LINE_SIZE 64
558#endif
559
560// Define macro to get current function name
561#if defined(JPH_COMPILER_CLANG) || defined(JPH_COMPILER_GCC)
562 #define JPH_FUNCTION_NAME __PRETTY_FUNCTION__
563#elif defined(JPH_COMPILER_MSVC)
564 #define JPH_FUNCTION_NAME __FUNCTION__
565#else
566 #error Undefined
567#endif
568
569// Stack allocation
570#define JPH_STACK_ALLOC(n) alloca(n)
571
572// Shorthand for #ifdef JPH_DEBUG / #endif
573#ifdef JPH_DEBUG
574 #define JPH_IF_DEBUG(...) __VA_ARGS__
575 #define JPH_IF_NOT_DEBUG(...)
576#else
577 #define JPH_IF_DEBUG(...)
578 #define JPH_IF_NOT_DEBUG(...) __VA_ARGS__
579#endif
580
581// Shorthand for #ifdef JPH_FLOATING_POINT_EXCEPTIONS_ENABLED / #endif
582#ifdef JPH_FLOATING_POINT_EXCEPTIONS_ENABLED
583 #define JPH_IF_FLOATING_POINT_EXCEPTIONS_ENABLED(...) __VA_ARGS__
584#else
585 #define JPH_IF_FLOATING_POINT_EXCEPTIONS_ENABLED(...)
586#endif
587
588// Helper macros to detect if we're running in single or double precision mode
589#ifdef JPH_DOUBLE_PRECISION
590 #define JPH_IF_SINGLE_PRECISION(...)
591 #define JPH_IF_SINGLE_PRECISION_ELSE(s, d) d
592 #define JPH_IF_DOUBLE_PRECISION(...) __VA_ARGS__
593#else
594 #define JPH_IF_SINGLE_PRECISION(...) __VA_ARGS__
595 #define JPH_IF_SINGLE_PRECISION_ELSE(s, d) s
596 #define JPH_IF_DOUBLE_PRECISION(...)
597#endif
598
599// Helper macro to detect if the debug renderer is active
600#ifdef JPH_DEBUG_RENDERER
601 #define JPH_IF_DEBUG_RENDERER(...) __VA_ARGS__
602 #define JPH_IF_NOT_DEBUG_RENDERER(...)
603#else
604 #define JPH_IF_DEBUG_RENDERER(...)
605 #define JPH_IF_NOT_DEBUG_RENDERER(...) __VA_ARGS__
606#endif
607
608// Macro to indicate that a parameter / variable is unused
609#define JPH_UNUSED(x) (void)x
610
611// Check if Thread Sanitizer is enabled
612#ifdef __has_feature
613 #if __has_feature(thread_sanitizer)
614 #define JPH_TSAN_ENABLED
615 #endif
616#else
617 #ifdef __SANITIZE_THREAD__
618 #define JPH_TSAN_ENABLED
619 #endif
620#endif
621
622// Attribute to disable Thread Sanitizer for a particular function
623#ifdef JPH_TSAN_ENABLED
624 #define JPH_TSAN_NO_SANITIZE __attribute__((no_sanitize("thread")))
625#else
626 #define JPH_TSAN_NO_SANITIZE
627#endif
628
629// Check if Address Sanitizer is enabled
630#ifdef __has_feature
631 #if __has_feature(address_sanitizer)
632 #define JPH_ASAN_ENABLED
633 #endif
634#else
635 #ifdef __SANITIZE_ADDRESS__
636 #define JPH_ASAN_ENABLED
637 #endif
638#endif
639
640// DirectX 12 is only supported on Windows
641#if defined(JPH_USE_DX12) && !defined(JPH_PLATFORM_WINDOWS)
642 #undef JPH_USE_DX12
643#endif // JPH_PLATFORM_WINDOWS
644
645// Metal is only supported on Apple platforms
646#if defined(JPH_USE_MTL) && !defined(JPH_PLATFORM_MACOS) && !defined(JPH_PLATFORM_IOS)
647 #undef JPH_USE_MTL
648#endif // !JPH_PLATFORM_MACOS && !JPH_PLATFORM_IOS
649
std::uint8_t uint8
Definition Core.h:511
std::int32_t int32
Definition Core.h:514
#define JPH_SUPPRESS_WARNINGS_STD_BEGIN
Definition Core.h:439
std::int64_t int64
Definition Core.h:516
#define JPH_SUPPRESS_WARNINGS_STD_END
Definition Core.h:452
std::uint64_t uint64
Definition Core.h:515
unsigned int uint
Definition Core.h:510
#define JPH_NAMESPACE_END
Definition Core.h:434
std::uint32_t uint32
Definition Core.h:513
#define JPH_NAMESPACE_BEGIN
Definition Core.h:428
std::uint16_t uint16
Definition Core.h:512