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