瀏覽代碼

the forward march of time never relents

Lucien Greathouse 1 年之前
父節點
當前提交
cd17b167e5
共有 4 個文件被更改,包括 149 次插入26 次删除
  1. 20 0
      HelloWorld/main.cpp
  2. 39 0
      JoltC/Functions.h
  3. 78 10
      JoltC/JoltC.cpp
  4. 12 16
      JoltC/Test.cpp

+ 20 - 0
HelloWorld/main.cpp

@@ -1,5 +1,6 @@
 #include <stdio.h>
 #include <stdio.h>
 #include <stdint.h>
 #include <stdint.h>
+#include <stdlib.h>
 
 
 #include "JoltC/JoltC.h"
 #include "JoltC/JoltC.h"
 
 
@@ -124,6 +125,25 @@ int main() {
 
 
 	const JPC_BodyInterface* body_interface = JPC_PhysicsSystem_GetBodyInterface(physics_system);
 	const JPC_BodyInterface* body_interface = JPC_PhysicsSystem_GetBodyInterface(physics_system);
 
 
+	JPC_BoxShapeSettings* floor_shape_settings = JPC_BoxShapeSettings_new(JPC_Vec3{100.0f, 100.0f, 100.0f});
+	JPC_ConvexShapeSettings_SetDensity((JPC_ConvexShapeSettings*)floor_shape_settings, 1000.0f);
+
+	JPC_Shape* shape;
+	JPC_String* err;
+	if (!JPC_ShapeSettings_Create((JPC_ShapeSettings*)floor_shape_settings, &shape, &err)) {
+		printf("fatal error: %s\n", JPC_String_c_str(err));
+
+		// the world is ending, but I guess we can still free memory
+		JPC_String_delete(err);
+
+		exit(1);
+	}
+
+	// BodyCreationSettings floor_settings(floor_shape, RVec3(0.0_r, -1.0_r, 0.0_r), Quat::sIdentity(), EMotionType::Static, Layers::NON_MOVING);
+
+	// Body *floor = body_interface.CreateBody(floor_settings);
+	// body_interface.AddBody(floor->GetID(), EActivation::DontActivate);
+
 	// TODO: creating bodies
 	// TODO: creating bodies
 	// TODO: PhysicsSystem::OptimizeBroadPhase
 	// TODO: PhysicsSystem::OptimizeBroadPhase
 
 

+ 39 - 0
JoltC/Functions.h

@@ -138,6 +138,45 @@ typedef struct JPC_ObjectLayerPairFilter {
 	JPC_ObjectLayerPairFilterFns fns;
 	JPC_ObjectLayerPairFilterFns fns;
 } JPC_ObjectLayerPairFilter;
 } JPC_ObjectLayerPairFilter;
 
 
+////////////////////////////////////////////////////////////////////////////////
+// String
+
+typedef struct JPC_String JPC_String;
+
+JPC_API void JPC_String_delete(JPC_String* self);
+JPC_API const char* JPC_String_c_str(JPC_String* self);
+
+////////////////////////////////////////////////////////////////////////////////
+// Shapes
+
+typedef struct JPC_Shape JPC_Shape;
+
+////////////////////////////////////////////////////////////////////////////////
+// ShapeSettings
+
+typedef struct JPC_ShapeSettings JPC_ShapeSettings;
+
+JPC_API bool JPC_ShapeSettings_Create(
+	JPC_ShapeSettings* self,
+	JPC_Shape** outShape,
+	JPC_String** outError);
+
+////////////////////////////////////////////////////////////////////////////////
+// ConvexShapeSettings
+
+typedef struct JPC_ConvexShapeSettings JPC_ConvexShapeSettings;
+
+JPC_API float JPC_ConvexShapeSettings_GetDensity(JPC_ConvexShapeSettings* self);
+JPC_API void JPC_ConvexShapeSettings_SetDensity(JPC_ConvexShapeSettings* self, float inDensity);
+
+////////////////////////////////////////////////////////////////////////////////
+// BoxShapeSettings
+
+typedef struct JPC_BoxShapeSettings JPC_BoxShapeSettings;
+
+JPC_API JPC_BoxShapeSettings* JPC_BoxShapeSettings_new(JPC_Vec3 inHalfExtent);
+JPC_API void JPC_BoxShapeSettings_delete(JPC_BoxShapeSettings* object);
+
 ////////////////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////////////
 // BodyInterface
 // BodyInterface
 
 

+ 78 - 10
JoltC/JoltC.cpp

@@ -1,19 +1,23 @@
-#include "Jolt/Jolt.h"
+#include <Jolt/Jolt.h>
 
 
-#include "Jolt/Core/Core.h"
-#include "Jolt/Core/Factory.h"
-#include "Jolt/Core/JobSystemThreadPool.h"
-#include "Jolt/Core/Memory.h"
-#include "Jolt/Core/TempAllocator.h"
-#include "Jolt/Physics/PhysicsSystem.h"
-#include "Jolt/RegisterTypes.h"
+#include <Jolt/RegisterTypes.h>
+#include <Jolt/Core/Factory.h>
+#include <Jolt/Core/TempAllocator.h>
+#include <Jolt/Core/JobSystemThreadPool.h>
+#include <Jolt/Physics/PhysicsSettings.h>
+#include <Jolt/Physics/PhysicsSystem.h>
+#include <Jolt/Physics/Collision/Shape/BoxShape.h>
+#include <Jolt/Physics/Collision/Shape/SphereShape.h>
+#include <Jolt/Physics/Body/BodyCreationSettings.h>
+#include <Jolt/Physics/Body/BodyActivationListener.h>
 
 
-#include "JoltC/JoltC.h"
+#include <JoltC/JoltC.h>
 
 
 #define OPAQUE_WRAPPER(c_type, cpp_type) \
 #define OPAQUE_WRAPPER(c_type, cpp_type) \
 	static c_type* to_jpc(cpp_type *in) { return reinterpret_cast<c_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 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); }
+	static cpp_type* to_jph(c_type *in) { return reinterpret_cast<cpp_type*>(in); } \
+	static const cpp_type* to_jph(const c_type *in) { return reinterpret_cast<const cpp_type*>(in); }
 
 
 #define DESTRUCTOR(c_type) \
 #define DESTRUCTOR(c_type) \
 	JPC_API void c_type##_delete(c_type* object) { \
 	JPC_API void c_type##_delete(c_type* object) { \
@@ -37,9 +41,26 @@ DESTRUCTOR(JPC_TempAllocatorImpl)
 OPAQUE_WRAPPER(JPC_JobSystemThreadPool, JPH::JobSystemThreadPool)
 OPAQUE_WRAPPER(JPC_JobSystemThreadPool, JPH::JobSystemThreadPool)
 DESTRUCTOR(JPC_JobSystemThreadPool)
 DESTRUCTOR(JPC_JobSystemThreadPool)
 
 
+OPAQUE_WRAPPER(JPC_ConvexShapeSettings, JPH::ConvexShapeSettings)
+OPAQUE_WRAPPER(JPC_ShapeSettings, JPH::ShapeSettings)
+OPAQUE_WRAPPER(JPC_Shape, JPH::Shape)
+
+OPAQUE_WRAPPER(JPC_String, JPH::String)
+DESTRUCTOR(JPC_String)
+
+OPAQUE_WRAPPER(JPC_BoxShapeSettings, JPH::BoxShapeSettings)
+DESTRUCTOR(JPC_BoxShapeSettings)
+
 static auto to_jpc(JPH::BroadPhaseLayer in) { return in.GetValue(); }
 static auto to_jpc(JPH::BroadPhaseLayer in) { return in.GetValue(); }
 static auto to_jph(JPC_BroadPhaseLayer in) { return JPH::BroadPhaseLayer(in); }
 static auto to_jph(JPC_BroadPhaseLayer in) { return JPH::BroadPhaseLayer(in); }
 
 
+static JPC_Vec3 to_jpc(JPH::Vec3 in) {
+	return JPC_Vec3{in.GetX(), in.GetY(), in.GetZ(), in.GetZ()};
+}
+static JPH::Vec3 to_jph(JPC_Vec3 in) {
+	return JPH::Vec3(in.x, in.y, in.z);
+}
+
 JPC_API void JPC_RegisterDefaultAllocator() {
 JPC_API void JPC_RegisterDefaultAllocator() {
 	JPH::RegisterDefaultAllocator();
 	JPH::RegisterDefaultAllocator();
 }
 }
@@ -156,6 +177,53 @@ static JPC_ObjectLayerPairFilter_Impl to_jph(JPC_ObjectLayerPairFilter in) {
 	return JPC_ObjectLayerPairFilter_Impl(in);
 	return JPC_ObjectLayerPairFilter_Impl(in);
 }
 }
 
 
+////////////////////////////////////////////////////////////////////////////////
+// String
+
+JPC_API const char* JPC_String_c_str(JPC_String* self) {
+	return to_jph(self)->c_str();
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// ShapeSettings
+
+JPC_API bool JPC_ShapeSettings_Create(
+	JPC_ShapeSettings* self,
+	JPC_Shape** outShape,
+	JPC_String** outError)
+{
+	auto res = to_jph(self)->Create();
+
+	if (res.HasError()) {
+		JPH::String* created = new JPH::String(std::move(res.GetError()));
+		*outError = to_jpc(created);
+
+		return false;
+	} else {
+		*outShape = to_jpc(res.Get());
+
+		return true;
+	}
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// ConvexShapeSettings
+
+JPC_API float JPC_ConvexShapeSettings_GetDensity(JPC_ConvexShapeSettings* self) {
+	return to_jph(self)->mDensity;
+}
+
+JPC_API void JPC_ConvexShapeSettings_SetDensity(JPC_ConvexShapeSettings* self, float inDensity) {
+	to_jph(self)->SetDensity(inDensity);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// BoxShapeSettings
+
+JPC_API JPC_BoxShapeSettings* JPC_BoxShapeSettings_new(JPC_Vec3 inHalfExtent) {
+	return to_jpc(new JPH::BoxShapeSettings(to_jph(inHalfExtent)));
+}
+
 ////////////////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////////////////
 // BodyInterface
 // BodyInterface
 
 

+ 12 - 16
JoltC/Test.cpp

@@ -2,22 +2,18 @@
 #include <stddef.h>
 #include <stddef.h>
 #include <type_traits>
 #include <type_traits>
 
 
-#include "Jolt/Jolt.h"
-#include "Jolt/Physics/Body/BodyCreationSettings.h"
-#include "Jolt/Physics/Body/BodyType.h"
-#include "Jolt/Physics/Body/MotionQuality.h"
-#include "Jolt/Physics/Body/MotionType.h"
-#include "Jolt/Physics/Character/CharacterBase.h"
-#include "Jolt/Physics/Collision/BackFaceMode.h"
-#include "Jolt/Physics/Collision/ContactListener.h"
-#include "Jolt/Physics/Collision/Shape/Shape.h"
-#include "Jolt/Physics/Constraints/Constraint.h"
-#include "Jolt/Physics/EActivation.h"
-#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"
+#include <Jolt/Jolt.h>
+
+#include <Jolt/RegisterTypes.h>
+#include <Jolt/Core/Factory.h>
+#include <Jolt/Core/TempAllocator.h>
+#include <Jolt/Core/JobSystemThreadPool.h>
+#include <Jolt/Physics/PhysicsSettings.h>
+#include <Jolt/Physics/PhysicsSystem.h>
+#include <Jolt/Physics/Collision/Shape/BoxShape.h>
+#include <Jolt/Physics/Collision/Shape/SphereShape.h>
+#include <Jolt/Physics/Body/BodyCreationSettings.h>
+#include <Jolt/Physics/Body/BodyActivationListener.h>
 
 
 template<typename E>
 template<typename E>
 constexpr auto to_integral(E e) -> typename std::underlying_type<E>::type 
 constexpr auto to_integral(E e) -> typename std::underlying_type<E>::type