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
282 #define JPH_IF_SHARED_LIBRARY(x) x
283 #define JPH_IF_NOT_SHARED_LIBRARY(x)
284#else
285 // If the define is not set, we use static linking and symbols don't need to be imported or exported
286 #define JPH_EXPORT
287
288 #define JPH_IF_SHARED_LIBRARY(x)
289 #define JPH_IF_NOT_SHARED_LIBRARY(x) x
290#endif
291
292#ifndef JPH_EXPORT_GCC_BUG_WORKAROUND
293 #define JPH_EXPORT_GCC_BUG_WORKAROUND JPH_EXPORT
294#endif
295
296// Macro used by the RTTI macros to not export a function
297#define JPH_NO_EXPORT
298
299// Pragmas to store / restore the warning state and to disable individual warnings
300#ifdef JPH_COMPILER_CLANG
301 #define JPH_PRAGMA(x) _Pragma(#x)
302 #define JPH_SUPPRESS_WARNING_PUSH JPH_PRAGMA(clang diagnostic push)
303 #define JPH_SUPPRESS_WARNING_POP JPH_PRAGMA(clang diagnostic pop)
304 #define JPH_CLANG_SUPPRESS_WARNING(w) JPH_PRAGMA(clang diagnostic ignored w)
305 #if __has_warning("-Wdeprecated-copy")
306 #define JPH_CLANG_SUPPRESS_DEPRECATED_COPY_WARNING JPH_CLANG_SUPPRESS_WARNING("-Wdeprecated-copy")
307 #endif
308 #if __has_warning("-Wdeprecated-copy-with-dtor")
309 #define JPH_CLANG_SUPPRESS_DEPRECATED_COPY_WITH_DTOR_WARNING JPH_CLANG_SUPPRESS_WARNING("-Wdeprecated-copy-with-dtor")
310 #endif
311 #if __has_warning("-Wunsafe-buffer-usage")
312 #define JPH_CLANG_SUPPRESS_UNSAFE_BUFFER_USAGE_WARNING JPH_CLANG_SUPPRESS_WARNING("-Wunsafe-buffer-usage")
313 #endif
314 #if __has_warning("-Wimplicit-int-float-conversion")
315 #define JPH_CLANG_SUPPRESS_IMPLICIT_INT_FLOAT_CONVERSION_WARNING JPH_CLANG_SUPPRESS_WARNING("-Wimplicit-int-float-conversion")
316 #endif
317 #if __has_warning("-Wunique-object-duplication")
318 #define JPH_CLANG_SUPPRESS_UNIQUE_OBJECT_DUPLICATION_WARNING JPH_CLANG_SUPPRESS_WARNING("-Wunique-object-duplication")
319 #endif
320 #if __has_warning("-Wnrvo")
321 #define JPH_CLANG_SUPPRESS_NRVO_WARNING JPH_CLANG_SUPPRESS_WARNING("-Wnrvo")
322 #endif
323#else
324 #define JPH_CLANG_SUPPRESS_WARNING(w)
325#endif
326#ifndef JPH_CLANG_SUPPRESS_DEPRECATED_COPY_WARNING
327 #define JPH_CLANG_SUPPRESS_DEPRECATED_COPY_WARNING
328#endif
329#ifndef JPH_CLANG_SUPPRESS_DEPRECATED_COPY_WITH_DTOR_WARNING
330 #define JPH_CLANG_SUPPRESS_DEPRECATED_COPY_WITH_DTOR_WARNING
331#endif
332#ifndef JPH_CLANG_SUPPRESS_UNSAFE_BUFFER_USAGE_WARNING
333 #define JPH_CLANG_SUPPRESS_UNSAFE_BUFFER_USAGE_WARNING
334#endif
335#ifndef JPH_CLANG_SUPPRESS_IMPLICIT_INT_FLOAT_CONVERSION_WARNING
336 #define JPH_CLANG_SUPPRESS_IMPLICIT_INT_FLOAT_CONVERSION_WARNING
337#endif
338#ifndef JPH_CLANG_SUPPRESS_UNIQUE_OBJECT_DUPLICATION_WARNING
339 #define JPH_CLANG_SUPPRESS_UNIQUE_OBJECT_DUPLICATION_WARNING
340#endif
341#ifndef JPH_CLANG_SUPPRESS_NRVO_WARNING
342 #define JPH_CLANG_SUPPRESS_NRVO_WARNING
343#endif
344
345#ifdef JPH_COMPILER_GCC
346 #define JPH_PRAGMA(x) _Pragma(#x)
347 #define JPH_SUPPRESS_WARNING_PUSH JPH_PRAGMA(GCC diagnostic push)
348 #define JPH_SUPPRESS_WARNING_POP JPH_PRAGMA(GCC diagnostic pop)
349 #define JPH_GCC_SUPPRESS_WARNING(w) JPH_PRAGMA(GCC diagnostic ignored w)
350#else
351 #define JPH_GCC_SUPPRESS_WARNING(w)
352#endif
353
354#ifdef JPH_COMPILER_MSVC
355 #define JPH_PRAGMA(x) __pragma(x)
356 #define JPH_SUPPRESS_WARNING_PUSH JPH_PRAGMA(warning (push))
357 #define JPH_SUPPRESS_WARNING_POP JPH_PRAGMA(warning (pop))
358 #define JPH_MSVC_SUPPRESS_WARNING(w) JPH_PRAGMA(warning (disable : w))
359 #if _MSC_VER >= 1920 && _MSC_VER < 1930
360 #define JPH_MSVC2019_SUPPRESS_WARNING(w) JPH_MSVC_SUPPRESS_WARNING(w)
361 #else
362 #define JPH_MSVC2019_SUPPRESS_WARNING(w)
363 #endif
364 #if _MSC_VER >= 1950
365 #define JPH_MSVC2026_PLUS_SUPPRESS_WARNING(w) JPH_MSVC_SUPPRESS_WARNING(w)
366 #else
367 #define JPH_MSVC2026_PLUS_SUPPRESS_WARNING(w)
368 #endif
369#else
370 #define JPH_MSVC_SUPPRESS_WARNING(w)
371 #define JPH_MSVC2019_SUPPRESS_WARNING(w)
372 #define JPH_MSVC2026_PLUS_SUPPRESS_WARNING(w)
373#endif
374
375// Disable common warnings triggered by Jolt when compiling with -Wall
376#define JPH_SUPPRESS_WARNINGS \
377 JPH_CLANG_SUPPRESS_WARNING("-Wc++98-compat") \
378 JPH_CLANG_SUPPRESS_WARNING("-Wc++98-compat-pedantic") \
379 JPH_CLANG_SUPPRESS_WARNING("-Wfloat-equal") \
380 JPH_CLANG_SUPPRESS_WARNING("-Wsign-conversion") \
381 JPH_CLANG_SUPPRESS_WARNING("-Wold-style-cast") \
382 JPH_CLANG_SUPPRESS_WARNING("-Wgnu-anonymous-struct") \
383 JPH_CLANG_SUPPRESS_WARNING("-Wnested-anon-types") \
384 JPH_CLANG_SUPPRESS_WARNING("-Wglobal-constructors") \
385 JPH_CLANG_SUPPRESS_WARNING("-Wexit-time-destructors") \
386 JPH_CLANG_SUPPRESS_WARNING("-Wnonportable-system-include-path") \
387 JPH_CLANG_SUPPRESS_WARNING("-Wlanguage-extension-token") \
388 JPH_CLANG_SUPPRESS_WARNING("-Wunused-parameter") \
389 JPH_CLANG_SUPPRESS_WARNING("-Wformat-nonliteral") \
390 JPH_CLANG_SUPPRESS_WARNING("-Wcovered-switch-default") \
391 JPH_CLANG_SUPPRESS_WARNING("-Wcast-align") \
392 JPH_CLANG_SUPPRESS_WARNING("-Winvalid-offsetof") \
393 JPH_CLANG_SUPPRESS_WARNING("-Wgnu-zero-variadic-macro-arguments") \
394 JPH_CLANG_SUPPRESS_WARNING("-Wdocumentation-unknown-command") \
395 JPH_CLANG_SUPPRESS_WARNING("-Wctad-maybe-unsupported") \
396 JPH_CLANG_SUPPRESS_WARNING("-Wswitch-default") \
397 JPH_CLANG_SUPPRESS_DEPRECATED_COPY_WARNING \
398 JPH_CLANG_SUPPRESS_DEPRECATED_COPY_WITH_DTOR_WARNING \
399 JPH_CLANG_SUPPRESS_UNSAFE_BUFFER_USAGE_WARNING \
400 JPH_CLANG_SUPPRESS_IMPLICIT_INT_FLOAT_CONVERSION_WARNING \
401 JPH_CLANG_SUPPRESS_WARNING("-Wpadded") \
402 JPH_IF_NOT_SHARED_LIBRARY(JPH_CLANG_SUPPRESS_UNIQUE_OBJECT_DUPLICATION_WARNING) \
403 JPH_CLANG_SUPPRESS_NRVO_WARNING \
404 \
405 JPH_GCC_SUPPRESS_WARNING("-Wcomment") \
406 JPH_GCC_SUPPRESS_WARNING("-Winvalid-offsetof") \
407 JPH_GCC_SUPPRESS_WARNING("-Wclass-memaccess") \
408 JPH_GCC_SUPPRESS_WARNING("-Wpedantic") \
409 JPH_GCC_SUPPRESS_WARNING("-Wunused-parameter") \
410 JPH_GCC_SUPPRESS_WARNING("-Wmaybe-uninitialized") \
411 \
412 JPH_MSVC_SUPPRESS_WARNING(4619) /* #pragma warning: there is no warning number 'XXXX' */ \
413 JPH_MSVC_SUPPRESS_WARNING(4514) /* 'X' : unreferenced inline function has been removed */ \
414 JPH_MSVC_SUPPRESS_WARNING(4710) /* 'X' : function not inlined */ \
415 JPH_MSVC_SUPPRESS_WARNING(4711) /* function 'X' selected for automatic inline expansion */ \
416 JPH_MSVC_SUPPRESS_WARNING(4714) /* function 'X' marked as __forceinline not inlined */ \
417 JPH_MSVC_SUPPRESS_WARNING(4820) /* 'X': 'Y' bytes padding added after data member 'Z' */ \
418 JPH_MSVC_SUPPRESS_WARNING(4100) /* 'X' : unreferenced formal parameter */ \
419 JPH_MSVC_SUPPRESS_WARNING(4626) /* 'X' : assignment operator was implicitly defined as deleted because a base class assignment operator is inaccessible or deleted */ \
420 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 */ \
421 JPH_MSVC_SUPPRESS_WARNING(4365) /* 'argument' : conversion from 'X' to 'Y', signed / unsigned mismatch */ \
422 JPH_MSVC_SUPPRESS_WARNING(4324) /* 'X' : structure was padded due to alignment specifier */ \
423 JPH_MSVC_SUPPRESS_WARNING(4625) /* 'X' : copy constructor was implicitly defined as deleted because a base class copy constructor is inaccessible or deleted */ \
424 JPH_MSVC_SUPPRESS_WARNING(5026) /* 'X': move constructor was implicitly defined as deleted because a base class move constructor is inaccessible or deleted */ \
425 JPH_MSVC_SUPPRESS_WARNING(4623) /* 'X' : default constructor was implicitly defined as deleted */ \
426 JPH_MSVC_SUPPRESS_WARNING(4201) /* nonstandard extension used: nameless struct/union */ \
427 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' */ \
428 JPH_MSVC_SUPPRESS_WARNING(5045) /* Compiler will insert Spectre mitigation for memory load if /Qspectre switch specified */ \
429 JPH_MSVC_SUPPRESS_WARNING(4583) /* 'X': destructor is not implicitly called */ \
430 JPH_MSVC_SUPPRESS_WARNING(4582) /* 'X': constructor is not implicitly called */ \
431 JPH_MSVC_SUPPRESS_WARNING(5219) /* implicit conversion from 'X' to 'Y', possible loss of data */ \
432 JPH_MSVC_SUPPRESS_WARNING(4826) /* Conversion from 'X *' to 'JPH::uint64' is sign-extended. This may cause unexpected runtime behavior. (32-bit) */ \
433 JPH_MSVC_SUPPRESS_WARNING(5264) /* 'X': 'const' variable is not used */ \
434 JPH_MSVC_SUPPRESS_WARNING(4251) /* class 'X' needs to have DLL-interface to be used by clients of class 'Y' */ \
435 JPH_MSVC_SUPPRESS_WARNING(4738) /* storing 32-bit float result in memory, possible loss of performance */ \
436 JPH_MSVC2019_SUPPRESS_WARNING(5246) /* the initialization of a subobject should be wrapped in braces */ \
437 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. */
438
439// OS-specific includes
440#if defined(JPH_PLATFORM_WINDOWS)
441 #define JPH_BREAKPOINT __debugbreak()
442#elif defined(JPH_PLATFORM_BLUE)
443 // Configuration for a popular game console.
444 // This file is not distributed because it would violate an NDA.
445 // Creating one should only be a couple of minutes of work if you have the documentation for the platform
446 // (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).
447 #include <Jolt/Core/PlatformBlue.h>
448#elif defined(JPH_PLATFORM_LINUX) || defined(JPH_PLATFORM_ANDROID) || defined(JPH_PLATFORM_MACOS) || defined(JPH_PLATFORM_IOS) || defined(JPH_PLATFORM_BSD)
449 #if defined(JPH_CPU_X86)
450 #define JPH_BREAKPOINT __asm volatile ("int $0x3")
451 #elif defined(JPH_CPU_ARM) || defined(JPH_CPU_RISCV) || defined(JPH_CPU_E2K) || defined(JPH_CPU_PPC) || defined(JPH_CPU_LOONGARCH)
452 #define JPH_BREAKPOINT __builtin_trap()
453 #else
454 #error Unknown CPU architecture
455 #endif
456#elif defined(JPH_PLATFORM_WASM)
457 #define JPH_BREAKPOINT do { } while (false) // Not supported
458#else
459 #error Unknown platform
460#endif
461
462// Begin the JPH namespace
463#define JPH_NAMESPACE_BEGIN \
464 JPH_SUPPRESS_WARNING_PUSH \
465 JPH_SUPPRESS_WARNINGS \
466 namespace JPH {
467
468// End the JPH namespace
469#define JPH_NAMESPACE_END \
470 } \
471 JPH_SUPPRESS_WARNING_POP
472
473// Suppress warnings generated by the standard template library
474#define JPH_SUPPRESS_WARNINGS_STD_BEGIN \
475 JPH_SUPPRESS_WARNING_PUSH \
476 JPH_CLANG_SUPPRESS_WARNING("-Wpadded") \
477 JPH_MSVC_SUPPRESS_WARNING(4365) \
478 JPH_MSVC_SUPPRESS_WARNING(4619) \
479 JPH_MSVC_SUPPRESS_WARNING(4710) \
480 JPH_MSVC_SUPPRESS_WARNING(4711) \
481 JPH_MSVC_SUPPRESS_WARNING(4820) \
482 JPH_MSVC_SUPPRESS_WARNING(4514) \
483 JPH_MSVC_SUPPRESS_WARNING(5262) \
484 JPH_MSVC_SUPPRESS_WARNING(5264) \
485 JPH_MSVC_SUPPRESS_WARNING(4738) \
486 JPH_MSVC_SUPPRESS_WARNING(5045)
487
488#define JPH_SUPPRESS_WARNINGS_STD_END \
489 JPH_SUPPRESS_WARNING_POP
490
491// MSVC STL requires _HAS_EXCEPTIONS=0 if exceptions are turned off
492#if defined(JPH_COMPILER_MSVC) && (!defined(__cpp_exceptions) || !__cpp_exceptions) && !defined(_HAS_EXCEPTIONS)
493 #define _HAS_EXCEPTIONS 0
494#endif
495
496// Standard C++ includes
498#include <float.h>
499#include <limits.h>
500#include <string.h>
501#include <new>
502#include <utility>
503#include <cmath>
504#include <sstream>
505#include <functional>
506#include <algorithm>
507#include <cstdint>
508#include <type_traits>
509#if defined(JPH_COMPILER_MSVC) || (defined(JPH_COMPILER_CLANG) && defined(_MSC_VER)) // MSVC or clang-cl
510 #include <malloc.h> // for alloca
511#endif
512#if defined(JPH_USE_SSE)
513 #include <immintrin.h>
514#elif defined(JPH_USE_NEON)
515 #ifdef JPH_COMPILER_MSVC
516 #include <intrin.h>
517 #include <arm64_neon.h>
518 #else
519 #include <arm_neon.h>
520 #endif
521#elif defined(JPH_USE_RVV)
522 #include <riscv_vector.h>
523#endif
525
527
528// Commonly used STL types
529using std::min;
530using std::max;
531using std::abs;
532using std::ceil;
533using std::floor;
534using std::trunc;
535using std::round;
536using std::fmod;
537using std::string_view;
538using std::function;
539using std::numeric_limits;
540using std::isfinite;
541using std::isnan;
542using std::ostream;
543using std::istream;
544
545// Standard types
546using uint = unsigned int;
547using uint8 = std::uint8_t;
548using uint16 = std::uint16_t;
549using uint32 = std::uint32_t;
550using int32 = std::int32_t;
551using uint64 = std::uint64_t;
552using int64 = std::int64_t;
553
554// Assert sizes of types
555static_assert(sizeof(uint) >= 4, "Invalid size of uint");
556static_assert(sizeof(uint8) == 1, "Invalid size of uint8");
557static_assert(sizeof(uint16) == 2, "Invalid size of uint16");
558static_assert(sizeof(uint32) == 4, "Invalid size of uint32");
559static_assert(sizeof(uint64) == 8, "Invalid size of uint64");
560
561// Determine if we want extra debugging code to be active
562#if !defined(NDEBUG) && !defined(JPH_NO_DEBUG)
563 #define JPH_DEBUG
564#endif
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 #define JPH_DEFAULT_ALLOCATE_ALIGNMENT __STDCPP_DEFAULT_NEW_ALIGNMENT__
589#endif
590
591// Cache line size (used for aligning to cache line)
592#ifndef JPH_CACHE_LINE_SIZE
593 #define JPH_CACHE_LINE_SIZE 64
594#endif
595
596// Define macro to get current function name
597#if defined(JPH_COMPILER_CLANG) || defined(JPH_COMPILER_GCC)
598 #define JPH_FUNCTION_NAME __PRETTY_FUNCTION__
599#elif defined(JPH_COMPILER_MSVC)
600 #define JPH_FUNCTION_NAME __FUNCTION__
601#else
602 #error Undefined
603#endif
604
605// Stack allocation
606#define JPH_STACK_ALLOC(n) alloca(n)
607
608// Shorthand for #ifdef JPH_DEBUG / #endif
609#ifdef JPH_DEBUG
610 #define JPH_IF_DEBUG(...) __VA_ARGS__
611 #define JPH_IF_NOT_DEBUG(...)
612#else
613 #define JPH_IF_DEBUG(...)
614 #define JPH_IF_NOT_DEBUG(...) __VA_ARGS__
615#endif
616
617// Shorthand for #ifdef JPH_FLOATING_POINT_EXCEPTIONS_ENABLED / #endif
618#ifdef JPH_FLOATING_POINT_EXCEPTIONS_ENABLED
619 #define JPH_IF_FLOATING_POINT_EXCEPTIONS_ENABLED(...) __VA_ARGS__
620#else
621 #define JPH_IF_FLOATING_POINT_EXCEPTIONS_ENABLED(...)
622#endif
623
624// Helper macros to detect if we're running in single or double precision mode
625#ifdef JPH_DOUBLE_PRECISION
626 #define JPH_IF_SINGLE_PRECISION(...)
627 #define JPH_IF_SINGLE_PRECISION_ELSE(s, d) d
628 #define JPH_IF_DOUBLE_PRECISION(...) __VA_ARGS__
629#else
630 #define JPH_IF_SINGLE_PRECISION(...) __VA_ARGS__
631 #define JPH_IF_SINGLE_PRECISION_ELSE(s, d) s
632 #define JPH_IF_DOUBLE_PRECISION(...)
633#endif
634
635// Helper macro to detect if the debug renderer is active
636#ifdef JPH_DEBUG_RENDERER
637 #define JPH_IF_DEBUG_RENDERER(...) __VA_ARGS__
638 #define JPH_IF_NOT_DEBUG_RENDERER(...)
639#else
640 #define JPH_IF_DEBUG_RENDERER(...)
641 #define JPH_IF_NOT_DEBUG_RENDERER(...) __VA_ARGS__
642#endif
643
644// Macro to indicate that a parameter / variable is unused
645#define JPH_UNUSED(x) (void)x
646
647// Macro to enable floating point precise mode
648#if defined(JPH_COMPILER_CLANG)
649 #define JPH_PRECISE_MATH_ON \
650 _Pragma("clang diagnostic push") \
651 _Pragma("clang diagnostic ignored \"-Wignored-pragmas\"") \
652 _Pragma("float_control(precise, on, push)") \
653 _Pragma("clang diagnostic pop")
654 #define JPH_PRECISE_MATH_OFF \
655 _Pragma("clang diagnostic push") \
656 _Pragma("clang diagnostic ignored \"-Wignored-pragmas\"") \
657 _Pragma("float_control(pop)") \
658 _Pragma("clang diagnostic pop")
659#elif defined(JPH_COMPILER_MSVC)
660 #define JPH_PRECISE_MATH_ON \
661 __pragma(float_control(precise, on, push))
662 #define JPH_PRECISE_MATH_OFF \
663 __pragma(float_control(pop))
664#else
665 #define JPH_PRECISE_MATH_ON
666 #define JPH_PRECISE_MATH_OFF
667#endif
668
669// Check if Thread Sanitizer is enabled
670#ifdef __has_feature
671 #if __has_feature(thread_sanitizer)
672 #define JPH_TSAN_ENABLED
673 #endif
674#else
675 #ifdef __SANITIZE_THREAD__
676 #define JPH_TSAN_ENABLED
677 #endif
678#endif
679
680// Attribute to disable Thread Sanitizer for a particular function
681#ifdef JPH_TSAN_ENABLED
682 #define JPH_TSAN_NO_SANITIZE __attribute__((no_sanitize("thread")))
683#else
684 #define JPH_TSAN_NO_SANITIZE
685#endif
686
687// Check if Address Sanitizer is enabled
688#ifdef __has_feature
689 #if __has_feature(address_sanitizer)
690 #define JPH_ASAN_ENABLED
691 #endif
692#else
693 #ifdef __SANITIZE_ADDRESS__
694 #define JPH_ASAN_ENABLED
695 #endif
696#endif
697
698// DirectX 12 is only supported on Windows
699#if defined(JPH_USE_DX12) && !defined(JPH_PLATFORM_WINDOWS)
700 #undef JPH_USE_DX12
701#endif // JPH_PLATFORM_WINDOWS
702
703// Metal is only supported on Apple platforms
704#if defined(JPH_USE_MTL) && !defined(JPH_PLATFORM_MACOS) && !defined(JPH_PLATFORM_IOS)
705 #undef JPH_USE_MTL
706#endif // !JPH_PLATFORM_MACOS && !JPH_PLATFORM_IOS
707
std::uint8_t uint8
Definition Core.h:547
std::int32_t int32
Definition Core.h:550
#define JPH_SUPPRESS_WARNINGS_STD_BEGIN
Definition Core.h:474
std::int64_t int64
Definition Core.h:552
#define JPH_SUPPRESS_WARNINGS_STD_END
Definition Core.h:488
std::uint64_t uint64
Definition Core.h:551
unsigned int uint
Definition Core.h:546
#define JPH_NAMESPACE_END
Definition Core.h:469
std::uint32_t uint32
Definition Core.h:549
#define JPH_NAMESPACE_BEGIN
Definition Core.h:463
std::uint16_t uint16
Definition Core.h:548