Daniele Bartolini 10 лет назад
Родитель
Сommit
40431da306

+ 13 - 14
src/resource/physics_resource.cpp

@@ -200,11 +200,12 @@ namespace physics_resource
 			, type.c_str()
 			);
 
-		ColliderDesc sd;
-		sd.type        = st;
-		sd.shape_class = sjson::parse_string_id(obj["class"]);
-		sd.material    = sjson::parse_string_id(obj["material"]);
-		sd.local_tm    = MATRIX4X4_IDENTITY;
+		ColliderDesc cd;
+		cd.type        = st;
+		cd.shape_class = sjson::parse_string_id(obj["class"]);
+		cd.material    = sjson::parse_string_id(obj["material"]);
+		cd.local_tm    = MATRIX4X4_IDENTITY;
+		cd.size        = 0;
 
 		DynamicString scene(ta);
 		DynamicString name(ta);
@@ -221,11 +222,11 @@ namespace physics_resource
 
 		Array<Vector3> mesh_data(default_allocator());
 
-		switch (sd.type)
+		switch (cd.type)
 		{
-			case ColliderType::SPHERE:      compile_sphere(mesh, sd); break;
-			case ColliderType::CAPSULE:     compile_capsule(mesh, sd); break;
-			case ColliderType::BOX:         compile_box(mesh, sd); break;
+			case ColliderType::SPHERE:      compile_sphere(mesh, cd); break;
+			case ColliderType::CAPSULE:     compile_capsule(mesh, cd); break;
+			case ColliderType::BOX:         compile_box(mesh, cd); break;
 			case ColliderType::CONVEX_HULL: compile_convex_hull(mesh, mesh_data); break;
 			case ColliderType::MESH:
 			case ColliderType::HEIGHTFIELD:
@@ -235,15 +236,13 @@ namespace physics_resource
 			}
 		}
 
+		cd.size = sizeof(Vector3)*array::size(mesh_data);
+
 		Buffer buf(default_allocator());
-		array::push(buf, (char*)&sd, sizeof(sd));
+		array::push(buf, (char*)&cd, sizeof(cd));
 
 		if (array::size(mesh_data))
-		{
-			u32 num = array::size(mesh_data);
-			array::push(buf, (char*)&num, sizeof(num));
 			array::push(buf, (char*)array::begin(mesh_data), sizeof(Vector3)*array::size(mesh_data));
-		}
 
 		return buf;
 	}

+ 2 - 2
src/world/physics_world_bullet.cpp

@@ -224,8 +224,8 @@ public:
 				break;
 			case ColliderType::CONVEX_HULL:
 			{
-				const u32 num = *(const u32*)&sd[1];
-				const Vector3* points = (const Vector3*)((const char*)(&sd[1]) + sizeof(num));
+				const u32 num = sd->size / sizeof(Vector3);
+				const Vector3* points = (const Vector3*)&sd[1];
 
 				btConvexHullShape* convex = CE_NEW(*_allocator, btConvexHullShape);
 				for (u32 i = 0; i < num; ++i)

+ 3 - 3
src/world/world.cpp

@@ -107,11 +107,11 @@ UnitId World::spawn_unit(const UnitResource& ur, const Vector3& pos, const Quate
 
 		if (component->type == StringId32("collider")._id)
 		{
-			const ColliderDesc* sd = (const ColliderDesc*)data;
+			const ColliderDesc* cd = (const ColliderDesc*)data;
 			for (u32 i = 0; i < component->num_instances; ++i)
 			{
-				physics_world()->create_collider(unit_lookup[unit_index[i]], sd);
-				++sd;
+				physics_world()->create_collider(unit_lookup[unit_index[i]], cd);
+				cd = (ColliderDesc*)((char*)cd + sizeof(ColliderDesc) + cd->size);
 			}
 		}
 

+ 2 - 1
src/world/world_types.h

@@ -402,7 +402,8 @@ struct ColliderDesc
 	CapsuleShape capsule;
 	BoxShape box;
 	HeightfieldShape heightfield;
-	// dynamic data               ///< Mesh, Heightfield data.
+	u32 size;                     ///< Size of additional data.
+//	char data[size]               ///< Convex Hull, Mesh, Heightfield data.
 };
 
 struct HingeJoint