Skip to content

Commit bcd9c62

Browse files
committed
Fix merge bs
2 parents af904e7 + a278685 commit bcd9c62

318 files changed

Lines changed: 13984 additions & 2555 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎JoltPhysicsC/CMakeLists.txt‎

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,22 @@ option(CROSS_PLATFORM_DETERMINISTIC "Cross platform deterministic" OFF)
1818
# When turning this option on, the library will be compiled for ARM (aarch64-linux-gnu), requires compiling with clang
1919
option(CROSS_COMPILE_ARM "Cross compile to aarch64-linux-gnu" OFF)
2020

21+
# When turning this option on, Jolt will be compiled as a shared library and public symbols will be exported.
22+
option(COMPILE_AS_SHARED_LIBRARY "Compile Jolt as a shared library" OFF)
23+
2124
# When turning this option on, the library will be compiled with interprocedural optimizations enabled, also known as link-time optimizations or link-time code generation.
2225
# Note that if you turn this on you need to use SET_INTERPROCEDURAL_OPTIMIZATION() or set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON) to enable LTO specificly for your own project as well.
2326
# If you don't do this you may get an error: /usr/bin/ld: libJolt.a: error adding symbols: file format not recognized
2427
option(INTERPROCEDURAL_OPTIMIZATION "Enable interprocedural optimizations" ON)
2528

26-
# When turning this on, in Debug and Release mode, the library will emit extra code to ensure that the 4th component of a 3-vector is kept the same as the 3rd component
27-
# and will enable floating point exceptions during simulation to detect divisions by zero.
29+
# When turning this on, in Debug and Release mode, the library will emit extra code to ensure that the 4th component of a 3-vector is kept the same as the 3rd component
30+
# and will enable floating point exceptions during simulation to detect divisions by zero.
2831
# Note that this currently only works using MSVC. Clang turns Float2 into a SIMD vector sometimes causing floating point exceptions (the option is ignored).
2932
option(FLOATING_POINT_EXCEPTIONS_ENABLED "Enable floating point exceptions" ON)
3033

34+
# Number of bits to use in ObjectLayer. Can be 16 or 32.
35+
option(OBJECT_LAYER_BITS "Number of bits in ObjectLayer" 16)
36+
3137
# Select X86 processor features to use (if everything is off it will be SSE2 compatible)
3238
option(USE_SSE4_1 "Enable SSE4.1" $ENV{JPJ_USE_SSE4_1})
3339
option(USE_SSE4_2 "Enable SSE4.2" $ENV{JPJ_USE_SSE4_2})
@@ -39,6 +45,9 @@ option(USE_TZCNT "Enable TZCNT" $ENV{JPJ_USE_TZCNT})
3945
option(USE_F16C "Enable F16C" $ENV{JPJ_USE_F16C})
4046
option(USE_FMADD "Enable FMADD" $ENV{JPJ_USE_FMADD})
4147

48+
# Enable all warnings
49+
option(ENABLE_ALL_WARNINGS "Enable all warnings and warnings as errors" ON)
50+
4251
include(CMakeDependentOption)
4352

4453
# Ability to toggle between the static and DLL versions of the MSVC runtime library
@@ -55,19 +64,22 @@ endif()
5564
if (("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "WindowsStore") AND NOT MINGW)
5665
# Fill in the path to the asan libraries
5766
set(CLANG_LIB_PATH "\"$(VSInstallDir)\\VC\\Tools\\Llvm\\x64\\lib\\clang\\${CMAKE_CXX_COMPILER_VERSION}\\lib\\windows\"")
58-
67+
5968
# 64 bit architecture
6069
set(CMAKE_VS_PLATFORM_TOOLSET_HOST_ARCHITECTURE "x64")
6170

6271
# Set runtime library
6372
if (USE_STATIC_MSVC_RUNTIME_LIBRARY)
6473
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
65-
else()
66-
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
6774
endif()
6875

6976
# Set general compiler flags
70-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:__cplusplus /Gm- /Wall /WX /MP /nologo /diagnostics:classic /FC /fp:except- /Zc:inline")
77+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Zc:__cplusplus /Gm- /MP /nologo /diagnostics:classic /FC /fp:except- /Zc:inline")
78+
79+
# Enable warnings
80+
if (ENABLE_ALL_WARNINGS)
81+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /Wall /WX")
82+
endif()
7183

7284
# Optionally generate debug symbols
7385
if (GENERATE_DEBUG_SYMBOLS)
@@ -110,7 +122,12 @@ if (("${CMAKE_SYSTEM_NAME}" STREQUAL "Windows" OR "${CMAKE_SYSTEM_NAME}" STREQUA
110122
endif()
111123
elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "Darwin" OR "${CMAKE_SYSTEM_NAME}" STREQUAL "iOS" OR MINGW OR EMSCRIPTEN)
112124
# Set general compiler flags
113-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I. -Wall -Wno-unused-function -Werror -fPIC") # JoltJava: add -fPIC, change some warning flags
125+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -I. -fPIC") # JoltJava: add -fPIC
126+
127+
# Enable warnings
128+
if (ENABLE_ALL_WARNINGS)
129+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wno-unused-function -Wno-unused-variable") # JoltJava: add flags
130+
endif()
114131

115132
# Optionally generate debug symbols
116133
if (GENERATE_DEBUG_SYMBOLS)
@@ -121,7 +138,7 @@ elseif ("${CMAKE_SYSTEM_NAME}" STREQUAL "Linux" OR "${CMAKE_SYSTEM_NAME}" STREQU
121138
# Somehow -Wcomment doesn't want to be turned off from code and we need this because Doxygen MathJax uses it
122139
# Also disable -Wstringop-overflow or it will generate false positives that can't be disabled from code when link-time optimizations are enabled
123140
# Also turn off automatic fused multiply add contractions, there doesn't seem to be a way to do this selectively through the macro JPH_PRECISE_MATH_OFF
124-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-comment -Wno-stringop-overflow -ffp-contract=off -Wno-unused-function -Wno-unused-variable") # JoltJava: add -Wno-unused-function -Wno-unused-variable
141+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-comment -Wno-stringop-overflow -ffp-contract=off")
125142
else()
126143
# Do not use -ffast-math since it cannot be turned off in a single compilation unit under clang, see Core.h
127144
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -ffp-model=precise")
@@ -179,7 +196,7 @@ set(PHYSICS_REPO_ROOT ${CMAKE_CURRENT_SOURCE_DIR}/)
179196
include(${PHYSICS_REPO_ROOT}/Jolt/Jolt.cmake)
180197
if (IOS)
181198
# Ensure that we enable SSE4.2 for the x86_64 build, CMAKE_SYSTEM_PROCESSOR is not set for iOS
182-
set_property(TARGET Jolt PROPERTY XCODE_ATTRIBUTE_OTHER_CPLUSPLUSFLAGS[arch=x86_64] "$(inherited) -msse4.2 -mpopcnt")
199+
set_property(TARGET Jolt PROPERTY XCODE_ATTRIBUTE_OTHER_CPLUSPLUSFLAGS[arch=x86_64] "$(inherited) -msse4.2 -mpopcnt")
183200
endif()
184201

185202
# JoltJava: source JoltPhysicsC

‎JoltPhysicsC/Jolt/AABBTree/AABBTreeBuilder.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ struct AABBTreeBuilderStats
3232
};
3333

3434
/// Helper class to build an AABB tree
35-
class AABBTreeBuilder
35+
class JPH_EXPORT AABBTreeBuilder
3636
{
3737
public:
3838
/// A node in the tree, contains the AABox for the tree and any child nodes or triangles

‎JoltPhysicsC/Jolt/Core/Color.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Color;
1212
using ColorArg = Color;
1313

1414
/// Class that holds an RGBA color with 8-bits per component
15-
class [[nodiscard]] Color
15+
class [[nodiscard]] JPH_EXPORT Color
1616
{
1717
public:
1818
/// Constructors

‎JoltPhysicsC/Jolt/Core/Core.h‎

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,45 @@
123123
#error Unsupported CPU architecture
124124
#endif
125125

126+
// If this define is set, Jolt is compiled as a shared library
127+
#ifdef JPH_SHARED_LIBRARY
128+
#ifdef JPH_BUILD_SHARED_LIBRARY
129+
// While building the shared library, we must export these symbols
130+
#ifdef JPH_PLATFORM_WINDOWS
131+
#define JPH_EXPORT __declspec(dllexport)
132+
#else
133+
#define JPH_EXPORT __attribute__ ((visibility ("default")))
134+
#endif
135+
#else
136+
// When linking against Jolt, we must import these symbols
137+
#ifdef JPH_PLATFORM_WINDOWS
138+
#define JPH_EXPORT __declspec(dllimport)
139+
#else
140+
#define JPH_EXPORT __attribute__ ((visibility ("default")))
141+
#endif
142+
#endif
143+
#else
144+
// If the define is not set, we use static linking and symbols don't need to be imported or exported
145+
#define JPH_EXPORT
146+
#endif
147+
148+
// Macro used by the RTTI macros to not export a function
149+
#define JPH_NO_EXPORT
150+
126151
// Pragmas to store / restore the warning state and to disable individual warnings
127152
#ifdef JPH_COMPILER_CLANG
128153
#define JPH_PRAGMA(x) _Pragma(#x)
129154
#define JPH_SUPPRESS_WARNING_PUSH JPH_PRAGMA(clang diagnostic push)
130155
#define JPH_SUPPRESS_WARNING_POP JPH_PRAGMA(clang diagnostic pop)
131156
#define JPH_CLANG_SUPPRESS_WARNING(w) JPH_PRAGMA(clang diagnostic ignored w)
157+
#if __clang_major__ >= 13
158+
#define JPH_CLANG_13_PLUS_SUPPRESS_WARNING(w) JPH_CLANG_SUPPRESS_WARNING(w)
159+
#else
160+
#define JPH_CLANG_13_PLUS_SUPPRESS_WARNING(w)
161+
#endif
132162
#else
133163
#define JPH_CLANG_SUPPRESS_WARNING(w)
164+
#define JPH_CLANG_13_PLUS_SUPPRESS_WARNING(w)
134165
#endif
135166
#ifdef JPH_COMPILER_GCC
136167
#define JPH_PRAGMA(x) _Pragma(#x)
@@ -145,8 +176,14 @@
145176
#define JPH_SUPPRESS_WARNING_PUSH JPH_PRAGMA(warning (push))
146177
#define JPH_SUPPRESS_WARNING_POP JPH_PRAGMA(warning (pop))
147178
#define JPH_MSVC_SUPPRESS_WARNING(w) JPH_PRAGMA(warning (disable : w))
179+
#if _MSC_VER >= 1920 && _MSC_VER < 1930
180+
#define JPH_MSVC2019_SUPPRESS_WARNING(w) JPH_MSVC_SUPPRESS_WARNING(w)
181+
#else
182+
#define JPH_MSVC2019_SUPPRESS_WARNING(w)
183+
#endif
148184
#else
149185
#define JPH_MSVC_SUPPRESS_WARNING(w)
186+
#define JPH_MSVC2019_SUPPRESS_WARNING(w)
150187
#endif
151188

152189
// Disable common warnings triggered by Jolt when compiling with -Wall
@@ -171,6 +208,7 @@
171208
JPH_CLANG_SUPPRESS_WARNING("-Wdocumentation-unknown-command") \
172209
JPH_CLANG_SUPPRESS_WARNING("-Wctad-maybe-unsupported") \
173210
JPH_CLANG_SUPPRESS_WARNING("-Wdeprecated-copy") \
211+
JPH_CLANG_13_PLUS_SUPPRESS_WARNING("-Wdeprecated-copy-with-dtor") \
174212
JPH_IF_NOT_ANDROID(JPH_CLANG_SUPPRESS_WARNING("-Wimplicit-int-float-conversion")) \
175213
\
176214
JPH_GCC_SUPPRESS_WARNING("-Wcomment") \
@@ -197,7 +235,9 @@
197235
JPH_MSVC_SUPPRESS_WARNING(4582) /* 'X': constructor is not implicitly called */ \
198236
JPH_MSVC_SUPPRESS_WARNING(5219) /* implicit conversion from 'X' to 'Y', possible loss of data */ \
199237
JPH_MSVC_SUPPRESS_WARNING(4826) /* Conversion from 'X *' to 'JPH::uint64' is sign-extended. This may cause unexpected runtime behavior. (32-bit) */ \
200-
JPH_MSVC_SUPPRESS_WARNING(5264) /* 'X': 'const' variable is not used */
238+
JPH_MSVC_SUPPRESS_WARNING(5264) /* 'X': 'const' variable is not used */ \
239+
JPH_MSVC_SUPPRESS_WARNING(4251) /* class 'X' needs to have DLL-interface to be used by clients of class 'Y' */ \
240+
JPH_MSVC2019_SUPPRESS_WARNING(5246) /* the initialization of a subobject should be wrapped in braces */
201241

202242
// OS-specific includes
203243
#if defined(JPH_PLATFORM_WINDOWS)

‎JoltPhysicsC/Jolt/Core/FPControlWord.h‎

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class FPControlWord : public NonCopyable
6060
unsigned int mPrevState;
6161
};
6262

63-
#elif defined(JPH_CPU_ARM)
63+
#elif defined(JPH_CPU_ARM) && defined(JPH_USE_NEON)
6464

6565
/// Helper class that needs to be put on the stack to update the state of the floating point control word.
6666
/// This state is kept per thread.
@@ -91,6 +91,37 @@ class FPControlWord : public NonCopyable
9191
uint64 mPrevState;
9292
};
9393

94+
#elif defined(JPH_CPU_ARM)
95+
96+
/// Helper class that needs to be put on the stack to update the state of the floating point control word.
97+
/// This state is kept per thread.
98+
template <uint32 Value, uint32 Mask>
99+
class FPControlWord : public NonCopyable
100+
{
101+
public:
102+
FPControlWord()
103+
{
104+
uint32 val;
105+
asm volatile("vmrs %0, fpscr" : "=r" (val));
106+
mPrevState = val;
107+
val &= ~Mask;
108+
val |= Value;
109+
asm volatile("vmsr fpscr, %0" : /* no output */ : "r" (val));
110+
}
111+
112+
~FPControlWord()
113+
{
114+
uint32 val;
115+
asm volatile("vmrs %0, fpscr" : "=r" (val));
116+
val &= ~Mask;
117+
val |= mPrevState & Mask;
118+
asm volatile("vmsr fpscr, %0" : /* no output */ : "r" (val));
119+
}
120+
121+
private:
122+
uint32 mPrevState;
123+
};
124+
94125
#elif defined(JPH_CPU_WASM)
95126

96127
// Not supported

‎JoltPhysicsC/Jolt/Core/Factory.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
JPH_NAMESPACE_BEGIN
1111

1212
/// Factory, to create RTTI objects
13-
class Factory
13+
class JPH_EXPORT Factory
1414
{
1515
public:
1616
JPH_OVERRIDE_NEW_DELETE

‎JoltPhysicsC/Jolt/Core/FixedSizeFreeList.inl‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,18 @@ JPH_NAMESPACE_BEGIN
77
template <typename Object>
88
FixedSizeFreeList<Object>::~FixedSizeFreeList()
99
{
10-
// Ensure everything is freed before the freelist is destructed
11-
JPH_ASSERT(mNumFreeObjects.load(memory_order_relaxed) == mNumPages * mPageSize);
12-
13-
// Free memory for pages
14-
uint32 num_pages = mNumObjectsAllocated / mPageSize;
15-
for (uint32 page = 0; page < num_pages; ++page)
16-
AlignedFree(mPages[page]);
17-
Free(mPages);
10+
// Check if we got our Init call
11+
if (mPages != nullptr)
12+
{
13+
// Ensure everything is freed before the freelist is destructed
14+
JPH_ASSERT(mNumFreeObjects.load(memory_order_relaxed) == mNumPages * mPageSize);
15+
16+
// Free memory for pages
17+
uint32 num_pages = mNumObjectsAllocated / mPageSize;
18+
for (uint32 page = 0; page < num_pages; ++page)
19+
AlignedFree(mPages[page]);
20+
Free(mPages);
21+
}
1822
}
1923

2024
template <typename Object>

‎JoltPhysicsC/Jolt/Core/HashCombine.h‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@ inline uint64 HashBytes(const void *inData, uint inSize, uint64 inSeed = 0xcbf29
2323
return hash;
2424
}
2525

26+
/// A 64 bit hash function by Thomas Wang, Jan 1997
27+
/// See: http://web.archive.org/web/20071223173210/http://www.concentric.net/~Ttwang/tech/inthash.htm
28+
/// @param inValue Value to hash
29+
/// @return Hash
30+
inline uint64 Hash64(uint64 inValue)
31+
{
32+
uint64 hash = inValue;
33+
hash = (~hash) + (hash << 21); // hash = (hash << 21) - hash - 1;
34+
hash = hash ^ (hash >> 24);
35+
hash = (hash + (hash << 3)) + (hash << 8); // hash * 265
36+
hash = hash ^ (hash >> 14);
37+
hash = (hash + (hash << 2)) + (hash << 4); // hash * 21
38+
hash = hash ^ (hash >> 28);
39+
hash = hash + (hash << 31);
40+
return hash;
41+
}
42+
2643
/// @brief Helper function that hashes a single value into ioSeed
2744
/// Taken from: https://stackoverflow.com/questions/2590677/how-do-i-combine-hash-values-in-c0x
2845
template <typename T>

‎JoltPhysicsC/Jolt/Core/IssueReporting.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ JPH_NAMESPACE_BEGIN
88

99
/// Trace function, needs to be overridden by application. This should output a line of text to the log / TTY.
1010
using TraceFunction = void (*)(const char *inFMT, ...);
11-
extern TraceFunction Trace;
11+
JPH_EXPORT extern TraceFunction Trace;
1212

1313
// Always turn on asserts in Debug mode
1414
#if defined(_DEBUG) && !defined(JPH_ENABLE_ASSERTS)
@@ -18,7 +18,7 @@ extern TraceFunction Trace;
1818
#ifdef JPH_ENABLE_ASSERTS
1919
/// Function called when an assertion fails. This function should return true if a breakpoint needs to be triggered
2020
using AssertFailedFunction = bool(*)(const char *inExpression, const char *inMessage, const char *inFile, uint inLine);
21-
extern AssertFailedFunction AssertFailed;
21+
JPH_EXPORT extern AssertFailedFunction AssertFailed;
2222

2323
// Helper functions to pass message on to failed function
2424
struct AssertLastParam { };

‎JoltPhysicsC/Jolt/Core/JobSystem.h‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ JPH_NAMESPACE_BEGIN
6666
/// to wait for these in this function after the barrier is finished waiting.
6767
///
6868
/// An example implementation is JobSystemThreadPool. If you don't want to write the Barrier class you can also inherit from JobSystemWithBarrier.
69-
class JobSystem : public NonCopyable
69+
class JPH_EXPORT JobSystem : public NonCopyable
7070
{
7171
protected:
7272
class Job;
@@ -80,16 +80,16 @@ class JobSystem : public NonCopyable
8080
{
8181
public:
8282
/// Constructor
83-
inline JobHandle() = default;
84-
inline JobHandle(const JobHandle &inHandle) = default;
83+
inline JobHandle() = default;
84+
inline JobHandle(const JobHandle &inHandle) = default;
8585
inline JobHandle(JobHandle &&inHandle) noexcept : Ref<Job>(std::move(inHandle)) { }
8686

8787
/// Constructor, only to be used by JobSystem
8888
inline explicit JobHandle(Job *inJob) : Ref<Job>(inJob) { }
8989

9090
/// Assignment
91-
inline JobHandle & operator = (const JobHandle &inHandle) { Ref<Job>::operator = (inHandle); return *this; }
92-
inline JobHandle & operator = (JobHandle &&inHandle) noexcept { Ref<Job>::operator = (std::move(inHandle)); return *this; }
91+
inline JobHandle & operator = (const JobHandle &inHandle) = default;
92+
inline JobHandle & operator = (JobHandle &&inHandle) noexcept = default;
9393

9494
/// Check if this handle contains a job
9595
inline bool IsValid() const { return GetPtr() != nullptr; }

0 commit comments

Comments
 (0)