Browse Source

Progress towards PhysicsSystem

Lucien Greathouse 1 year ago
parent
commit
7c0ff0a5bb
6 changed files with 119 additions and 14 deletions
  1. 2 2
      CMakeLists.txt
  2. 0 7
      JoltC/Enums.h
  3. 36 0
      JoltC/Functions.h
  4. 70 3
      JoltC/JoltC.cpp
  5. 7 0
      JoltC/JoltC.h
  6. 4 2
      JoltC/Test.cpp

+ 2 - 2
CMakeLists.txt

@@ -19,9 +19,9 @@ target_include_directories(joltc PUBLIC . JoltPhysics)
 target_link_libraries(joltc PUBLIC Jolt)
 
 if(MSVC)
-  target_compile_options(joltc PRIVATE /W4 /WX)
+  target_compile_options(joltc PRIVATE /W4)
 else()
-  target_compile_options(joltc PRIVATE -Wall -Wextra -Wpedantic -Werror)
+  target_compile_options(joltc PRIVATE -Wall -Wextra -Wpedantic)
 endif()
 
 add_executable(HelloWorld

+ 0 - 7
JoltC/Enums.h

@@ -2,13 +2,6 @@
 
 #include <stdint.h>
 
-#ifndef ENSURE_TESTS
-    #define ENSURE_EQUAL(a, b)
-    #define ENSURE_ENUM_EQ(a, b)
-    #define ENSURE_SIZE_ALIGN(a, b)
-    #define ENSURE_FIELD(a, b, c, d)
-#endif
-
 const int JPC_MAX_PHYSICS_JOBS = 2048;
 const int JPC_MAX_PHYSICS_BARRIERS = 8;
 

+ 36 - 0
JoltC/Functions.h

@@ -13,11 +13,17 @@ JPC_API void JPC_RegisterDefaultAllocator();
 JPC_API void JPC_FactoryInit();
 JPC_API void JPC_RegisterTypes();
 
+////////////////////////////////////////////////////////////////////////////////
+// TempAllocatorImpl
+
 typedef struct JPC_TempAllocatorImpl JPC_TempAllocatorImpl;
 
 JPC_API JPC_TempAllocatorImpl* JPC_TempAllocatorImpl_new(uint size);
 JPC_API void JPC_TempAllocatorImpl_delete(JPC_TempAllocatorImpl* object);
 
+////////////////////////////////////////////////////////////////////////////////
+// JobSystemThreadPool
+
 typedef struct JPC_JobSystemThreadPool JPC_JobSystemThreadPool;
 
 JPC_API JPC_JobSystemThreadPool* JPC_JobSystemThreadPool_new2(
@@ -30,10 +36,40 @@ JPC_API JPC_JobSystemThreadPool* JPC_JobSystemThreadPool_new3(
 
 JPC_API void JPC_JobSystemThreadPool_delete(JPC_JobSystemThreadPool* object);
 
+////////////////////////////////////////////////////////////////////////////////
+// BroadPhaseLayerInterface
+
+typedef uint8_t JPC_BroadPhaseLayer;
+ENSURE_SIZE_ALIGN(JPC_BroadPhaseLayer, JPH::BroadPhaseLayer)
+
+typedef uint16_t JPC_ObjectLayer; // FIXME: Branch on JPH_OBJECT_LAYER_BITS?
+ENSURE_SIZE_ALIGN(JPC_ObjectLayer, JPH::ObjectLayer)
+
+typedef struct JPC_BroadPhaseLayerInterfaceFns {
+	uint (*GetNumBroadPhaseLayers)(void *self);
+	JPC_BroadPhaseLayer (*GetBroadPhaseLayer)(void *self, JPC_ObjectLayer inLayer);
+} JPC_BroadPhaseLayerInterfaceFns;
+
+typedef struct JPC_BroadPhaseLayerInterface {
+	JPC_BroadPhaseLayerInterfaceFns *fns;
+	void *self;
+} JPC_BroadPhaseLayerInterface;
+
+////////////////////////////////////////////////////////////////////////////////
+// PhysicsSystem
+
 typedef struct JPC_PhysicsSystem JPC_PhysicsSystem;
 
 JPC_API JPC_PhysicsSystem* JPC_PhysicsSystem_new();
 JPC_API void JPC_PhysicsSystem_delete(JPC_PhysicsSystem* object);
+JPC_API void JPC_PhysicsSystem_Init(
+	uint inMaxBodies,
+	uint inNumBodyMutexes,
+	uint inMaxBodyPairs,
+	uint inMaxContactConstraints,
+	JPC_BroadPhaseLayerInterface inBroadPhaseLayerInterface);
+	// const ObjectVsBroadPhaseLayerFilter &inObjectVsBroadPhaseLayerFilter,
+	// const ObjectLayerPairFilter &inObjectLayerPairFilter);
 
 #ifdef __cplusplus
 }

+ 70 - 3
JoltC/JoltC.cpp

@@ -19,9 +19,6 @@
 		delete to_jph(object); \
 	}
 
-OPAQUE_WRAPPER(JPC_TempAllocatorImpl, JPH::TempAllocatorImpl)
-DESTRUCTOR(JPC_TempAllocatorImpl)
-
 JPC_API void JPC_RegisterDefaultAllocator() {
 	JPH::RegisterDefaultAllocator();
 }
@@ -34,10 +31,19 @@ JPC_API void JPC_RegisterTypes() {
 	JPH::RegisterTypes();
 }
 
+////////////////////////////////////////////////////////////////////////////////
+// TempAllocatorImpl
+
+OPAQUE_WRAPPER(JPC_TempAllocatorImpl, JPH::TempAllocatorImpl)
+DESTRUCTOR(JPC_TempAllocatorImpl)
+
 JPC_API JPC_TempAllocatorImpl* JPC_TempAllocatorImpl_new(uint size) {
 	return to_jpc(new JPH::TempAllocatorImpl(size));
 }
 
+////////////////////////////////////////////////////////////////////////////////
+// JobSystemThreadPool
+
 OPAQUE_WRAPPER(JPC_JobSystemThreadPool, JPH::JobSystemThreadPool)
 DESTRUCTOR(JPC_JobSystemThreadPool)
 
@@ -56,9 +62,70 @@ JPC_API JPC_JobSystemThreadPool* JPC_JobSystemThreadPool_new3(
 	return to_jpc(new JPH::JobSystemThreadPool(inMaxJobs, inMaxBarriers, inNumThreads));
 }
 
+////////////////////////////////////////////////////////////////////////////////
+// BroadPhaseLayerInterface
+
+static auto to_jpc(JPH::BroadPhaseLayer in) { return in.GetValue(); }
+static auto to_jph(JPC_BroadPhaseLayer in) { return JPH::BroadPhaseLayer(in); }
+
+class JPC_BroadPhaseLayerInterface_Impl : public JPH::BroadPhaseLayerInterface {
+public:
+	explicit JPC_BroadPhaseLayerInterface_Impl(JPC_BroadPhaseLayerInterface in) : fns(*in.fns), self(in.self) {}
+
+	uint GetNumBroadPhaseLayers() const override {
+		return fns.GetNumBroadPhaseLayers(self);
+	}
+
+	JPH::BroadPhaseLayer GetBroadPhaseLayer(JPH::ObjectLayer inLayer) const override {
+		return to_jph(fns.GetBroadPhaseLayer(self, inLayer));
+	}
+
+#if defined(JPH_EXTERNAL_PROFILE) || defined(JPH_PROFILE_ENABLED)
+	const char * GetBroadPhaseLayerName(JPH::BroadPhaseLayer inLayer) const override {
+		return "FIXME";
+	}
+#endif
+
+private:
+	JPC_BroadPhaseLayerInterfaceFns fns;
+	void* self;
+};
+
+static JPC_BroadPhaseLayerInterface_Impl to_jph(JPC_BroadPhaseLayerInterface in) {
+	return JPC_BroadPhaseLayerInterface_Impl(in);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// PhysicsSystem
+
 OPAQUE_WRAPPER(JPC_PhysicsSystem, JPH::PhysicsSystem)
 DESTRUCTOR(JPC_PhysicsSystem)
 
 JPC_API JPC_PhysicsSystem* JPC_PhysicsSystem_new() {
 	return to_jpc(new JPH::PhysicsSystem());
+}
+
+JPC_API void JPC_PhysicsSystem_Init(
+	JPC_PhysicsSystem* self,
+	uint inMaxBodies,
+	uint inNumBodyMutexes,
+	uint inMaxBodyPairs,
+	uint inMaxContactConstraints,
+	JPC_BroadPhaseLayerInterface inBroadPhaseLayerInterface)
+	// const ObjectVsBroadPhaseLayerFilter &inObjectVsBroadPhaseLayerFilter,
+	// const ObjectLayerPairFilter &inObjectLayerPairFilter);
+{
+	auto impl_inBroadPhaseLayerInterface = to_jph(inBroadPhaseLayerInterface);
+
+	JPH::ObjectVsBroadPhaseLayerFilter impl_inObjectVsBroadPhaseLayerFilter;
+	JPH::ObjectLayerPairFilter impl_inObjectLayerPairFilter;
+
+	to_jph(self)->Init(
+		inMaxBodies,
+		inNumBodyMutexes,
+		inMaxBodyPairs,
+		inMaxContactConstraints,
+		impl_inBroadPhaseLayerInterface,
+		impl_inObjectVsBroadPhaseLayerFilter,
+		impl_inObjectLayerPairFilter);
 }

+ 7 - 0
JoltC/JoltC.h

@@ -1,4 +1,11 @@
 #pragma once
 
+#ifndef ENSURE_TESTS
+    #define ENSURE_EQUAL(a, b)
+    #define ENSURE_ENUM_EQ(a, b)
+    #define ENSURE_SIZE_ALIGN(a, b)
+    #define ENSURE_FIELD(a, b, c, d)
+#endif
+
 #include "JoltC/Enums.h"
 #include "JoltC/Functions.h"

+ 4 - 2
JoltC/Test.cpp

@@ -16,6 +16,8 @@
 #include "Jolt/Physics/EPhysicsUpdateError.h"
 #include "Jolt/Physics/PhysicsSettings.h"
 #include "Jolt/Physics/Body/AllowedDOFs.h"
+#include "Jolt/Physics/Collision/BroadPhase/BroadPhaseLayer.h"
+#include "Jolt/Physics/Collision/ObjectLayer.h"
 
 template<typename E>
 constexpr auto to_integral(E e) -> typename std::underlying_type<E>::type 
@@ -34,8 +36,8 @@ constexpr auto to_integral(E e) -> typename std::underlying_type<E>::type
     static_assert(sizeof(c_const) == sizeof(cpp_enum), #c_const " did not have same size as " #cpp_enum);
 
 #define ENSURE_SIZE_ALIGN(type0, type1) \
-    static_assert(sizeof(type0) == sizeof(type1)); \
-    static_assert(alignof(type0) == alignof(type1));
+    static_assert(sizeof(type0) == sizeof(type1), "size of " #type0 " did not match size of " #type1); \
+    static_assert(alignof(type0) == alignof(type1), "align of " #type0 " did not match align of " #type1);
 
 #define unsafe_offsetof(st, m) ((size_t) ( (char *)&((st *)(0))->m - (char *)0 ))
 #define unsafe_fieldtype(st, m) decltype((st *)(0)->m)