Browse Source

Move C++ implementation to new module and start specializing to_jpc/to_jph

Lucien Greathouse 4 months ago
parent
commit
9cad13df67
4 changed files with 15 additions and 7 deletions
  1. 5 2
      CMakeLists.txt
  2. 6 5
      JoltCImpl/JoltC.cpp
  3. 0 0
      JoltCImpl/Test.cpp
  4. 4 0
      README.md

+ 5 - 2
CMakeLists.txt

@@ -29,11 +29,14 @@ project(JoltC VERSION 0.1
     LANGUAGES C CXX)
 
 add_library(joltc STATIC
+    # C Interface
     JoltC/JoltC.h
-    JoltC/JoltC.cpp
     JoltC/Enums.h
     JoltC/Functions.h
-    JoltC/Test.cpp
+
+    # C++ Implementation
+    JoltCImpl/Test.cpp
+    JoltCImpl/JoltC.cpp
 )
 
 target_compile_features(joltc PUBLIC cxx_std_17)

+ 6 - 5
JoltC/JoltC.cpp → JoltCImpl/JoltC.cpp

@@ -235,8 +235,8 @@ static JPC_RayCastResult to_jpc(JPH::RayCastResult in) {
 	return out;
 }
 
-static JPC_ShapeCastResult to_jpc(JPH::ShapeCastResult in) {
-	JPC_ShapeCastResult out{0};
+JPC_ShapeCastResult JPC_ShapeCastResult_to_jpc(JPH::ShapeCastResult in) {
+	JPC_ShapeCastResult out{};
 	// CollideShapeResult
 	out.ContactPointOn1 = to_jpc(in.mContactPointOn1);
 	out.ContactPointOn2 = to_jpc(in.mContactPointOn2);
@@ -255,8 +255,9 @@ static JPC_ShapeCastResult to_jpc(JPH::ShapeCastResult in) {
 	return out;
 }
 
-static JPH::ShapeCastSettings to_jph(JPC_ShapeCastSettings in) {
+JPH::ShapeCastSettings JPC_ShapeCastSettings_to_jph(JPC_ShapeCastSettings in) {
 	JPH::ShapeCastSettings out{};
+
 	// JPH::CollideSettingsBase
 	// EActiveEdgeMode ActiveEdgeMode;
 	// ECollectFacesMode CollectFacesMode;
@@ -662,7 +663,7 @@ public:
 	}
 
 	void AddHit(const ResultType &inResult) override {
-		JPC_ShapeCastResult result = to_jpc(inResult);
+		JPC_ShapeCastResult result = JPC_ShapeCastResult_to_jpc(inResult);
 		JPC_CastShapeCollector *base = to_jpc(this);
 
 		fns.AddHit(self, base, &result);
@@ -1929,7 +1930,7 @@ JPC_API void JPC_ShapeCastSettings_default(JPC_ShapeCastSettings* settings) {
 }
 
 JPC_API void JPC_NarrowPhaseQuery_CastShape(const JPC_NarrowPhaseQuery* self, JPC_NarrowPhaseQuery_CastShapeArgs* args) {
-	JPH::ShapeCastSettings settings = to_jph(args->Settings);
+	JPH::ShapeCastSettings settings = JPC_ShapeCastSettings_to_jph(args->Settings);
 
 	JPH::ClosestHitCollisionCollector<JPH::CastShapeCollector> defaultCollector{};
 	JPH::CastShapeCollector* collector = &defaultCollector;

+ 0 - 0
JoltC/Test.cpp → JoltCImpl/Test.cpp


+ 4 - 0
README.md

@@ -3,6 +3,10 @@ C wrapper for [Jolt Physics](https://github.com/jrouwe/JoltPhysics) 5.1.0.
 
 Currently a work in progress. Bindings contain functions that we've needed as part of our game or the Rust bindings we're working on in [jolt-rust](https://github.com/SecondHalfGames/jolt-rust).
 
+The [`JoltC`](./JoltC) directory contains headers for the C interface that you can bind to.
+
+The [`JoltCImpl`](./JoltCImpl) directory contains the C++ implementation of the C interface and serves as the glue between the C++ and C code.
+
 ## Goals
 1. Sound C wrapper around current version of Jolt Physics
 2. Headers suitable for usage in automatic binding generation tools (i.e. Rust `bindgen`, LuaJIT FFI)