소스 검색

Commit to the new binding strategy for ShapeSettings types

Lucien Greathouse 1 년 전
부모
커밋
6f54d7e9a2
3개의 변경된 파일186개의 추가작업 그리고 73개의 파일을 삭제
  1. 9 5
      HelloWorld/main.cpp
  2. 70 24
      JoltC/Functions.h
  3. 107 44
      JoltC/JoltC.cpp

+ 9 - 5
HelloWorld/main.cpp

@@ -122,12 +122,14 @@ int main() {
 
 	JPC_BodyInterface* body_interface = JPC_PhysicsSystem_GetBodyInterface(physics_system);
 
-	JPC_BoxShapeSettings* floor_shape_settings = JPC_BoxShapeSettings_new(JPC_Vec3{100.0f, 1.0f, 100.0f});
-	JPC_ConvexShapeSettings_SetDensity((JPC_ConvexShapeSettings*)floor_shape_settings, 1000.0f);
+	JPC_BoxShapeSettings floor_shape_settings;
+	JPC_BoxShapeSettings_default(&floor_shape_settings);
+	floor_shape_settings.HalfExtent = JPC_Vec3{100.0f, 1.0f, 100.0f};
+	floor_shape_settings.Density = 500.0;
 
 	JPC_Shape* floor_shape;
 	JPC_String* err;
-	if (!JPC_ShapeSettings_Create((JPC_ShapeSettings*)floor_shape_settings, &floor_shape, &err)) {
+	if (!JPC_BoxShapeSettings_Create(&floor_shape_settings, &floor_shape, &err)) {
 		printf("fatal error: %s\n", JPC_String_c_str(err));
 
 		// the world is ending, but I guess we can still free memory
@@ -146,10 +148,12 @@ int main() {
 	JPC_Body* floor = JPC_BodyInterface_CreateBody(body_interface, &floor_settings);
 	JPC_BodyInterface_AddBody(body_interface, JPC_Body_GetID(floor), JPC_ACTIVATION_DONT_ACTIVATE);
 
-	JPC_SphereShapeSettings* sphere_shape_settings = JPC_SphereShapeSettings_new(0.5);
+	JPC_SphereShapeSettings sphere_shape_settings;
+	JPC_SphereShapeSettings_default(&sphere_shape_settings);
+	sphere_shape_settings.Radius = 0.5;
 
 	JPC_Shape* sphere_shape;
-	if (!JPC_ShapeSettings_Create((JPC_ShapeSettings*)sphere_shape_settings, &sphere_shape, &err)) {
+	if (!JPC_SphereShapeSettings_Create(&sphere_shape_settings, &sphere_shape, &err)) {
 		printf("fatal error: %s\n", JPC_String_c_str(err));
 
 		// the world is ending, but I guess we can still free memory

+ 70 - 24
JoltC/Functions.h

@@ -308,53 +308,99 @@ JPC_API void JPC_ConvexShapeSettings_SetDensity(JPC_ConvexShapeSettings* self, f
 ////////////////////////////////////////////////////////////////////////////////
 // TriangleShapeSettings
 
-typedef struct JPC_TriangleShapeSettings JPC_TriangleShapeSettings;
+typedef struct JPC_TriangleShapeSettings {
+	// ShapeSettings
+	uint64_t UserData;
+
+	// ConvexShapeSettings
+	// TODO: Material
+	float Density;
+
+	// TriangleShapeSettings
+	JPC_Vec3 V1;
+	JPC_Vec3 V2;
+	JPC_Vec3 V3;
+	float ConvexRadius;
+} JPC_TriangleShapeSettings;
 
-JPC_API JPC_TriangleShapeSettings* JPC_TriangleShapeSettings_new(JPC_Vec3 inV1, JPC_Vec3 inV2, JPC_Vec3 inV3);
-JPC_API void JPC_TriangleShapeSettings_delete(JPC_TriangleShapeSettings* object);
+JPC_API void JPC_TriangleShapeSettings_default(JPC_TriangleShapeSettings* object);
+JPC_API bool JPC_TriangleShapeSettings_Create(const JPC_TriangleShapeSettings* self, JPC_Shape** outShape, JPC_String** outError);
 
 ////////////////////////////////////////////////////////////////////////////////
-// BoxShapeSettings
+// BoxShapeSettings -> ConvexShapeSettings -> ShapeSettings
 
-typedef struct JPC_BoxShapeSettings2 {
+typedef struct JPC_BoxShapeSettings {
+	// ShapeSettings
 	uint64_t UserData;
+
+	// ConvexShapeSettings
 	// TODO: Material
 	float Density;
+
+	// BoxShapeSettings
 	JPC_Vec3 HalfExtent;
 	float ConvexRadius;
-} JPC_BoxShapeSettings2;
+} JPC_BoxShapeSettings;
 
-JPC_API void JPC_BoxShapeSettings2_default(JPC_BoxShapeSettings2* object);
-JPC_API bool JPC_BoxShapeSettings2_Create(const JPC_BoxShapeSettings2* self, JPC_Shape** outShape, JPC_String** outError);
+JPC_API void JPC_BoxShapeSettings_default(JPC_BoxShapeSettings* object);
+JPC_API bool JPC_BoxShapeSettings_Create(const JPC_BoxShapeSettings* self, JPC_Shape** outShape, JPC_String** outError);
 
-typedef struct JPC_BoxShapeSettings JPC_BoxShapeSettings;
+////////////////////////////////////////////////////////////////////////////////
+// SphereShapeSettings -> ConvexShapeSettings -> ShapeSettings
 
-JPC_API JPC_BoxShapeSettings* JPC_BoxShapeSettings_new(JPC_Vec3 inHalfExtent);
-JPC_API void JPC_BoxShapeSettings_delete(JPC_BoxShapeSettings* object);
+typedef struct JPC_SphereShapeSettings {
+	// ShapeSettings
+	uint64_t UserData;
 
-////////////////////////////////////////////////////////////////////////////////
-// SphereShapeSettings
+	// ConvexShapeSettings
+	// TODO: Material
+	float Density;
 
-typedef struct JPC_SphereShapeSettings JPC_SphereShapeSettings;
+	// SphereShapeSettings
+	float Radius;
+} JPC_SphereShapeSettings;
 
-JPC_API JPC_SphereShapeSettings* JPC_SphereShapeSettings_new(float inRadius);
-JPC_API void JPC_SphereShapeSettings_delete(JPC_SphereShapeSettings* object);
+JPC_API void JPC_SphereShapeSettings_default(JPC_SphereShapeSettings* object);
+JPC_API bool JPC_SphereShapeSettings_Create(const JPC_SphereShapeSettings* self, JPC_Shape** outShape, JPC_String** outError);
 
 ////////////////////////////////////////////////////////////////////////////////
-// CapsuleShapeSettings
+// CapsuleShapeSettings -> ConvexShapeSettings -> ShapeSettings
+
+typedef struct JPC_CapsuleShapeSettings {
+	// ShapeSettings
+	uint64_t UserData;
+
+	// ConvexShapeSettings
+	// TODO: Material
+	float Density;
 
-typedef struct JPC_CapsuleShapeSettings JPC_CapsuleShapeSettings;
+	// CapsuleShapeSettings
+	float Radius;
+	float HalfHeightOfCylinder;
+} JPC_CapsuleShapeSettings;
 
-JPC_API JPC_CapsuleShapeSettings* JPC_CapsuleShapeSettings_new(float inHalfHeightOfCylinder, float inRadius);
-JPC_API void JPC_CapsuleShapeSettings_delete(JPC_CapsuleShapeSettings* object);
+JPC_API void JPC_CapsuleShapeSettings_default(JPC_CapsuleShapeSettings* object);
+JPC_API bool JPC_CapsuleShapeSettings_Create(const JPC_CapsuleShapeSettings* self, JPC_Shape** outShape, JPC_String** outError);
 
 ////////////////////////////////////////////////////////////////////////////////
-// CylinderShapeSettings
+// CylinderShapeSettings -> ConvexShapeSettings -> ShapeSettings
 
-typedef struct JPC_CylinderShapeSettings JPC_CylinderShapeSettings;
+typedef struct JPC_CylinderShapeSettings {
+	// ShapeSettings
+	uint64_t UserData;
+
+	// ConvexShapeSettings
+	// TODO: Material
+	float Density;
+
+	// CylinderShapeSettings
+	float HalfHeight;
+	float Radius;
+	float ConvexRadius;
+} JPC_CylinderShapeSettings;
 
-JPC_API JPC_CylinderShapeSettings* JPC_CylinderShapeSettings_new(float inHalfHeight, float inRadius);
-JPC_API void JPC_CylinderShapeSettings_delete(JPC_CapsuleShapeSettings* object);
+JPC_API void JPC_CylinderShapeSettings_default(JPC_CylinderShapeSettings* object);
+JPC_API bool JPC_CylinderShapeSettings_Create(const JPC_CylinderShapeSettings* self, JPC_Shape** outShape, JPC_String** outError);
 
 ////////////////////////////////////////////////////////////////////////////////
 // BodyCreationSettings

+ 107 - 44
JoltC/JoltC.cpp

@@ -99,21 +99,6 @@ DESTRUCTOR(JPC_IndexedTriangleList)
 OPAQUE_WRAPPER(JPC_String, JPH::String)
 DESTRUCTOR(JPC_String)
 
-OPAQUE_WRAPPER(JPC_TriangleShapeSettings, JPH::TriangleShapeSettings)
-DESTRUCTOR(JPC_TriangleShapeSettings)
-
-OPAQUE_WRAPPER(JPC_BoxShapeSettings, JPH::BoxShapeSettings)
-DESTRUCTOR(JPC_BoxShapeSettings)
-
-OPAQUE_WRAPPER(JPC_SphereShapeSettings, JPH::SphereShapeSettings)
-DESTRUCTOR(JPC_SphereShapeSettings)
-
-OPAQUE_WRAPPER(JPC_CapsuleShapeSettings, JPH::CapsuleShapeSettings)
-DESTRUCTOR(JPC_CapsuleShapeSettings)
-
-OPAQUE_WRAPPER(JPC_CylinderShapeSettings, JPH::CylinderShapeSettings)
-DESTRUCTOR(JPC_CylinderShapeSettings)
-
 LAYOUT_COMPATIBLE(JPC_BodyManager_DrawSettings, JPH::BodyManager::DrawSettings)
 
 LAYOUT_COMPATIBLE(JPC_BodyID, JPH::BodyID)
@@ -422,77 +407,155 @@ JPC_API void JPC_ConvexShapeSettings_SetDensity(JPC_ConvexShapeSettings* self, f
 ////////////////////////////////////////////////////////////////////////////////
 // TriangleShapeSettings
 
-JPC_API JPC_TriangleShapeSettings* JPC_TriangleShapeSettings_new(JPC_Vec3 inV1, JPC_Vec3 inV2, JPC_Vec3 inV3) {
-	auto settings = new JPH::TriangleShapeSettings{
-		to_jph(inV1),
-		to_jph(inV2),
-		to_jph(inV3),
-	};
+static void to_jph(const JPC_TriangleShapeSettings* input, JPH::TriangleShapeSettings* output) {
+	output->mUserData = input->UserData;
+
+	// TODO: Material
+	output->mDensity = input->Density;
+
+	output->mV1 = to_jph(input->V1);
+	output->mV2 = to_jph(input->V2);
+	output->mV3 = to_jph(input->V3);
+	output->mConvexRadius = input->ConvexRadius;
+}
+
+JPC_API void JPC_TriangleShapeSettings_default(JPC_TriangleShapeSettings* object) {
+	object->UserData = 0;
+
+	// TODO: Material
+	object->Density = 1000.0;
+
+	object->V1 = {0};
+	object->V2 = {0};
+	object->V3 = {0};
+	object->ConvexRadius = 0.0;
+}
+
+JPC_API bool JPC_TriangleShapeSettings_Create(const JPC_TriangleShapeSettings* self, JPC_Shape** outShape, JPC_String** outError) {
+	JPH::TriangleShapeSettings settings;
+	to_jph(self, &settings);
 
-	return to_jpc(settings);
+	return HandleShapeResult(settings.Create(), outShape, outError);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // BoxShapeSettings
 
-static void to_jph(const JPC_BoxShapeSettings2* input, JPH::BoxShapeSettings* output) {
+static void to_jph(const JPC_BoxShapeSettings* input, JPH::BoxShapeSettings* output) {
 	output->mUserData = input->UserData;
+
 	// TODO: Material
 	output->mDensity = input->Density;
+
 	output->mHalfExtent = to_jph(input->HalfExtent);
 	output->mConvexRadius = input->ConvexRadius;
 }
 
-JPC_API void JPC_BoxShapeSettings2_default(JPC_BoxShapeSettings2* object) {
+JPC_API void JPC_BoxShapeSettings_default(JPC_BoxShapeSettings* object) {
 	object->UserData = 0;
+
 	// TODO: Material
 	object->Density = 1000.0;
+
 	object->HalfExtent = JPC_Vec3{0};
 	object->ConvexRadius = 0.0;
 }
 
-JPC_API bool JPC_BoxShapeSettings2_Create(const JPC_BoxShapeSettings2* self, JPC_Shape** outShape, JPC_String** outError) {
+JPC_API bool JPC_BoxShapeSettings_Create(const JPC_BoxShapeSettings* self, JPC_Shape** outShape, JPC_String** outError) {
 	JPH::BoxShapeSettings settings;
 	to_jph(self, &settings);
 
 	return HandleShapeResult(settings.Create(), outShape, outError);
 }
 
-JPC_API JPC_BoxShapeSettings* JPC_BoxShapeSettings_new(JPC_Vec3 inHalfExtent) {
-	return to_jpc(new JPH::BoxShapeSettings(to_jph(inHalfExtent)));
-}
-
 ////////////////////////////////////////////////////////////////////////////////
 // SphereShapeSettings
 
-JPC_API JPC_SphereShapeSettings* JPC_SphereShapeSettings_new(float inRadius) {
-	auto settings = new JPH::SphereShapeSettings{};
-	settings->mRadius = inRadius;
+static void to_jph(const JPC_SphereShapeSettings* input, JPH::SphereShapeSettings* output) {
+	output->mUserData = input->UserData;
+
+	// TODO: Material
+	output->mDensity = input->Density;
+
+	output->mRadius = input->Radius;
+}
+
+JPC_API void JPC_SphereShapeSettings_default(JPC_SphereShapeSettings* object) {
+	object->UserData = 0;
+
+	// TODO: Material
+	object->Density = 1000.0;
 
-	return to_jpc(settings);
+	object->Radius = 0.0;
+}
+
+JPC_API bool JPC_SphereShapeSettings_Create(const JPC_SphereShapeSettings* self, JPC_Shape** outShape, JPC_String** outError) {
+	JPH::SphereShapeSettings settings;
+	to_jph(self, &settings);
+
+	return HandleShapeResult(settings.Create(), outShape, outError);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // CapsuleShapeSettings
 
-JPC_API JPC_CapsuleShapeSettings* JPC_CapsuleShapeSettings_new(float inHalfHeightOfCylinder, float inRadius) {
-	auto settings = new JPH::CapsuleShapeSettings{};
-	settings->mHalfHeightOfCylinder = inHalfHeightOfCylinder;
-	settings->mRadius = inRadius;
+static void to_jph(const JPC_CapsuleShapeSettings* input, JPH::CapsuleShapeSettings* output) {
+	output->mUserData = input->UserData;
+
+	// TODO: Material
+	output->mDensity = input->Density;
+
+	output->mRadius = input->Radius;
+	output->mHalfHeightOfCylinder = input->HalfHeightOfCylinder;
+}
+
+JPC_API void JPC_CapsuleShapeSettings_default(JPC_CapsuleShapeSettings* object) {
+	object->UserData = 0;
+
+	// TODO: Material
+	object->Density = 1000.0;
 
-	return to_jpc(settings);
+	object->Radius = 0.0;
+	object->HalfHeightOfCylinder = 0.0;
+}
+
+JPC_API bool JPC_CapsuleShapeSettings_Create(const JPC_CapsuleShapeSettings* self, JPC_Shape** outShape, JPC_String** outError) {
+	JPH::CapsuleShapeSettings settings;
+	to_jph(self, &settings);
+
+	return HandleShapeResult(settings.Create(), outShape, outError);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 // CylinderShapeSettings
 
-JPC_API JPC_CylinderShapeSettings* JPC_CylinderShapeSettings_new(float inHalfHeight, float inRadius) {
-	auto settings = new JPH::CylinderShapeSettings{};
-	settings->mHalfHeight = inHalfHeight;
-	settings->mRadius = inRadius;
-	settings->mConvexRadius = JPH::cDefaultConvexRadius;
+static void to_jph(const JPC_CylinderShapeSettings* input, JPH::CylinderShapeSettings* output) {
+	output->mUserData = input->UserData;
+
+	// TODO: Material
+	output->mDensity = input->Density;
+
+	output->mHalfHeight = input->HalfHeight;
+	output->mRadius = input->Radius;
+	output->mConvexRadius = input->ConvexRadius;
+}
+
+JPC_API void JPC_CylinderShapeSettings_default(JPC_CylinderShapeSettings* object) {
+	object->UserData = 0;
 
-	return to_jpc(settings);
+	// TODO: Material
+	object->Density = 1000.0;
+
+	object->HalfHeight = 0.0;
+	object->Radius = 0.0;
+	object->ConvexRadius = 0.0;
+}
+
+JPC_API bool JPC_CylinderShapeSettings_Create(const JPC_CylinderShapeSettings* self, JPC_Shape** outShape, JPC_String** outError) {
+	JPH::CylinderShapeSettings settings;
+	to_jph(self, &settings);
+
+	return HandleShapeResult(settings.Create(), outShape, outError);
 }
 
 ////////////////////////////////////////////////////////////////////////////////