瀏覽代碼

Body interface, centralize wrapper definitions

Lucien Greathouse 1 年之前
父節點
當前提交
c849d6ee29
共有 4 個文件被更改,包括 36 次插入14 次删除
  1. 3 0
      CMakeLists.txt
  2. 2 0
      HelloWorld/main.cpp
  3. 7 0
      JoltC/Functions.h
  4. 24 14
      JoltC/JoltC.cpp

+ 3 - 0
CMakeLists.txt

@@ -20,6 +20,9 @@ target_link_libraries(joltc PUBLIC Jolt)
 
 if(MSVC)
   target_compile_options(joltc PRIVATE /W4)
+
+  # Ignore 'unreferenced function with internal linkage'
+  target_compile_options(joltc PRIVATE /wd4505)
 else()
   target_compile_options(joltc PRIVATE -Wall -Wextra -Wpedantic)
 endif()

+ 2 - 0
HelloWorld/main.cpp

@@ -121,6 +121,8 @@ int main() {
 
 	// TODO: register body activation listener
 	// TODO: register contact listener
+
+	const JPC_BodyInterface* body_interface = JPC_PhysicsSystem_GetBodyInterface(physics_system);
 	// TODO: body interface
 	// TODO: creating bodies
 	// TODO: PhysicsSystem::OptimizeBroadPhase

+ 7 - 0
JoltC/Functions.h

@@ -84,6 +84,11 @@ typedef struct JPC_ObjectLayerPairFilter {
 	JPC_ObjectLayerPairFilterFns fns;
 } JPC_ObjectLayerPairFilter;
 
+////////////////////////////////////////////////////////////////////////////////
+// BodyInterface
+
+typedef struct JPC_BodyInterface JPC_BodyInterface;
+
 ////////////////////////////////////////////////////////////////////////////////
 // PhysicsSystem
 
@@ -108,6 +113,8 @@ JPC_API JPC_PhysicsUpdateError JPC_PhysicsSystem_Update(
 	JPC_TempAllocatorImpl *inTempAllocator, // FIXME: un-specialize
 	JPC_JobSystemThreadPool *inJobSystem); // FIXME: un-specialize
 
+JPC_API const JPC_BodyInterface* JPC_PhysicsSystem_GetBodyInterface(JPC_PhysicsSystem* self);
+
 #ifdef __cplusplus
 }
 #endif

+ 24 - 14
JoltC/JoltC.cpp

@@ -11,8 +11,9 @@
 #include "JoltC/JoltC.h"
 
 #define OPAQUE_WRAPPER(c_type, cpp_type) \
-	static auto to_jpc(cpp_type *in) { return reinterpret_cast<c_type*>(in); } \
-	static auto to_jph(c_type *in) { return reinterpret_cast<cpp_type*>(in); }
+	static c_type* to_jpc(cpp_type *in) { return reinterpret_cast<c_type*>(in); } \
+	static const c_type* to_jpc(const cpp_type *in) { return reinterpret_cast<const c_type*>(in); } \
+	static cpp_type* to_jph(c_type *in) { return reinterpret_cast<cpp_type*>(in); }
 
 #define DESTRUCTOR(c_type) \
 	JPC_API void c_type##_delete(c_type* object) { \
@@ -25,6 +26,20 @@ constexpr auto to_integral(E e) -> typename std::underlying_type<E>::type
 	return static_cast<typename std::underlying_type<E>::type>(e);
 }
 
+OPAQUE_WRAPPER(JPC_PhysicsSystem, JPH::PhysicsSystem)
+DESTRUCTOR(JPC_PhysicsSystem)
+
+OPAQUE_WRAPPER(JPC_BodyInterface, JPH::BodyInterface)
+
+OPAQUE_WRAPPER(JPC_TempAllocatorImpl, JPH::TempAllocatorImpl)
+DESTRUCTOR(JPC_TempAllocatorImpl)
+
+OPAQUE_WRAPPER(JPC_JobSystemThreadPool, JPH::JobSystemThreadPool)
+DESTRUCTOR(JPC_JobSystemThreadPool)
+
+static auto to_jpc(JPH::BroadPhaseLayer in) { return in.GetValue(); }
+static auto to_jph(JPC_BroadPhaseLayer in) { return JPH::BroadPhaseLayer(in); }
+
 JPC_API void JPC_RegisterDefaultAllocator() {
 	JPH::RegisterDefaultAllocator();
 }
@@ -49,9 +64,6 @@ JPC_API void JPC_UnregisterTypes() {
 ////////////////////////////////////////////////////////////////////////////////
 // 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));
 }
@@ -59,9 +71,6 @@ JPC_API JPC_TempAllocatorImpl* JPC_TempAllocatorImpl_new(uint size) {
 ////////////////////////////////////////////////////////////////////////////////
 // JobSystemThreadPool
 
-OPAQUE_WRAPPER(JPC_JobSystemThreadPool, JPH::JobSystemThreadPool)
-DESTRUCTOR(JPC_JobSystemThreadPool)
-
 JPC_API JPC_JobSystemThreadPool* JPC_JobSystemThreadPool_new2(
 	uint inMaxJobs,
 	uint inMaxBarriers)
@@ -80,9 +89,6 @@ JPC_API JPC_JobSystemThreadPool* JPC_JobSystemThreadPool_new3(
 ////////////////////////////////////////////////////////////////////////////////
 // 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 final : public JPH::BroadPhaseLayerInterface {
 public:
 	explicit JPC_BroadPhaseLayerInterface_Impl(JPC_BroadPhaseLayerInterface in) : self(in.self), fns(in.fns) {}
@@ -151,10 +157,14 @@ static JPC_ObjectLayerPairFilter_Impl to_jph(JPC_ObjectLayerPairFilter in) {
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-// PhysicsSystem
+// BodyInterface
 
-OPAQUE_WRAPPER(JPC_PhysicsSystem, JPH::PhysicsSystem)
-DESTRUCTOR(JPC_PhysicsSystem)
+JPC_API const JPC_BodyInterface* JPC_PhysicsSystem_GetBodyInterface(JPC_PhysicsSystem* self) {
+	return to_jpc(&to_jph(self)->GetBodyInterface());
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// PhysicsSystem
 
 JPC_API JPC_PhysicsSystem* JPC_PhysicsSystem_new() {
 	return to_jpc(new JPH::PhysicsSystem());