Browse Source

Expose a function to compare the JOLT_VERSION_ID with the version the library was compiled with

Allows multiple godot modules to verify that their jolt (ABI) is
compatible with the jolt library compiled by yet another module.
Andrea Catania 1 year ago
parent
commit
addff7c66c
3 changed files with 22 additions and 3 deletions
  1. 6 1
      Jolt/Core/Core.h
  2. 6 1
      Jolt/RegisterTypes.cpp
  3. 10 1
      Jolt/RegisterTypes.h

+ 6 - 1
Jolt/Core/Core.h

@@ -55,7 +55,12 @@
 #else
 #else
 	#define JPH_VERSION_FEATURE_BIT_9 0
 	#define JPH_VERSION_FEATURE_BIT_9 0
 #endif
 #endif
-#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))
+#ifdef JPH_ENABLE_ASSERTS
+	#define JPH_VERSION_FEATURE_BIT_10 1
+#else
+	#define JPH_VERSION_FEATURE_BIT_10 0
+#endif
+#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))
 
 
 // Combine the version and features in a single ID
 // Combine the version and features in a single ID
 #define JPH_VERSION_ID ((JPH_VERSION_FEATURES << 24) | (JPH_VERSION_MAJOR << 16) | (JPH_VERSION_MINOR << 8) | JPH_VERSION_PATCH)
 #define JPH_VERSION_ID ((JPH_VERSION_FEATURES << 24) | (JPH_VERSION_MAJOR << 16) | (JPH_VERSION_MINOR << 8) | JPH_VERSION_PATCH)

+ 6 - 1
Jolt/RegisterTypes.cpp

@@ -69,10 +69,15 @@ JPH_DECLARE_RTTI_WITH_NAMESPACE_FOR_FACTORY(JPH_EXPORT, JPH, SoftBodyCreationSet
 
 
 JPH_NAMESPACE_BEGIN
 JPH_NAMESPACE_BEGIN
 
 
+bool VerifyJoltVersionIDInternal(uint64 inVersionID)
+{
+	return inVersionID == JPH_VERSION_ID;
+}
+
 void RegisterTypesInternal(uint64 inVersionID)
 void RegisterTypesInternal(uint64 inVersionID)
 {
 {
 	// Version check
 	// Version check
-	if (inVersionID != JPH_VERSION_ID)
+	if (!VerifyJoltVersionIDInternal(inVersionID))
 	{
 	{
 		JPH_ASSERT(false, "Version mismatch, make sure you compile the client code with the same Jolt version and compiler definitions!");
 		JPH_ASSERT(false, "Version mismatch, make sure you compile the client code with the same Jolt version and compiler definitions!");
 		JPH_CRASH;
 		JPH_CRASH;

+ 10 - 1
Jolt/RegisterTypes.h

@@ -6,11 +6,20 @@
 
 
 JPH_NAMESPACE_BEGIN
 JPH_NAMESPACE_BEGIN
 
 
+/// Internal helper function
+JPH_EXPORT extern bool VerifyJoltVersionIDInternal(uint64 inVersionID);
+
+/// This function can be used to verify the library ABI is compatible with your
+/// application.
+/// Use it in this way: `assert(VerifyJoltVersionID());`.
+/// Returns `false` if the library used is not compatible with your app.
+JPH_INLINE bool VerifyJoltVersionID() { return VerifyJoltVersionIDInternal(JPH_VERSION_ID); }
+
 /// Internal helper function
 /// Internal helper function
 JPH_EXPORT extern void RegisterTypesInternal(uint64 inVersionID);
 JPH_EXPORT extern void RegisterTypesInternal(uint64 inVersionID);
 
 
 /// Register all physics types with the factory
 /// Register all physics types with the factory
-inline void RegisterTypes() { RegisterTypesInternal(JPH_VERSION_ID); }
+JPH_INLINE void RegisterTypes() { RegisterTypesInternal(JPH_VERSION_ID); }
 
 
 /// Unregisters all types with the factory and cleans up the default material
 /// Unregisters all types with the factory and cleans up the default material
 JPH_EXPORT extern void UnregisterTypes();
 JPH_EXPORT extern void UnregisterTypes();