Daniele Bartolini 10 rokov pred
rodič
commit
c6061e7634

+ 27 - 27
src/resource/physics_resource.cpp

@@ -20,22 +20,22 @@ namespace crown
 {
 {
 namespace physics_resource
 namespace physics_resource
 {
 {
-	struct ShapeInfo
+	struct ColliderInfo
 	{
 	{
 		const char* name;
 		const char* name;
-		ShapeType::Enum type;
+		ColliderType::Enum type;
 	};
 	};
 
 
-	static const ShapeInfo s_shape[] =
+	static const ColliderInfo s_collider[] =
 	{
 	{
-		{ "sphere",      ShapeType::SPHERE      },
-		{ "capsule",     ShapeType::CAPSULE     },
-		{ "box",         ShapeType::BOX         },
-		{ "convex_hull", ShapeType::CONVEX_HULL },
-		{ "mesh",        ShapeType::MESH        },
-		{ "heightfield", ShapeType::HEIGHTFIELD }
+		{ "sphere",      ColliderType::SPHERE      },
+		{ "capsule",     ColliderType::CAPSULE     },
+		{ "box",         ColliderType::BOX         },
+		{ "convex_hull", ColliderType::CONVEX_HULL },
+		{ "mesh",        ColliderType::MESH        },
+		{ "heightfield", ColliderType::HEIGHTFIELD }
 	};
 	};
-	CE_STATIC_ASSERT(CE_COUNTOF(s_shape) == ShapeType::COUNT);
+	CE_STATIC_ASSERT(CE_COUNTOF(s_collider) == ColliderType::COUNT);
 
 
 	struct JointInfo
 	struct JointInfo
 	{
 	{
@@ -51,15 +51,15 @@ namespace physics_resource
 	};
 	};
 	CE_STATIC_ASSERT(CE_COUNTOF(s_joint) == JointType::COUNT);
 	CE_STATIC_ASSERT(CE_COUNTOF(s_joint) == JointType::COUNT);
 
 
-	static ShapeType::Enum shape_type_to_enum(const char* type)
+	static ColliderType::Enum shape_type_to_enum(const char* type)
 	{
 	{
-		for (u32 i = 0; i < CE_COUNTOF(s_shape); ++i)
+		for (u32 i = 0; i < CE_COUNTOF(s_collider); ++i)
 		{
 		{
-			if (strcmp(type, s_shape[i].name) == 0)
-				return s_shape[i].type;
+			if (strcmp(type, s_collider[i].name) == 0)
+				return s_collider[i].type;
 		}
 		}
 
 
-		return ShapeType::COUNT;
+		return ColliderType::COUNT;
 	}
 	}
 
 
 	static JointType::Enum joint_type_to_enum(const char* type)
 	static JointType::Enum joint_type_to_enum(const char* type)
@@ -92,7 +92,7 @@ namespace physics_resource
 		return buf;
 		return buf;
 	}
 	}
 
 
-	void compile_sphere(const char* mesh, ShapeDesc& sd)
+	void compile_sphere(const char* mesh, ColliderDesc& sd)
 	{
 	{
 		TempAllocator4096 ta;
 		TempAllocator4096 ta;
 		JsonObject obj(ta);
 		JsonObject obj(ta);
@@ -115,7 +115,7 @@ namespace physics_resource
 		sd.sphere.radius = sphere.r;
 		sd.sphere.radius = sphere.r;
 	}
 	}
 
 
-	void compile_capsule(const char* mesh, ShapeDesc& sd)
+	void compile_capsule(const char* mesh, ColliderDesc& sd)
 	{
 	{
 		TempAllocator4096 ta;
 		TempAllocator4096 ta;
 		JsonObject obj(ta);
 		JsonObject obj(ta);
@@ -139,7 +139,7 @@ namespace physics_resource
 		sd.capsule.height = (aabb.max.y - aabb.min.y) / 2.0f;
 		sd.capsule.height = (aabb.max.y - aabb.min.y) / 2.0f;
 	}
 	}
 
 
-	void compile_box(const char* mesh, ShapeDesc& sd)
+	void compile_box(const char* mesh, ColliderDesc& sd)
 	{
 	{
 		TempAllocator4096 ta;
 		TempAllocator4096 ta;
 		JsonObject obj(ta);
 		JsonObject obj(ta);
@@ -193,14 +193,14 @@ namespace physics_resource
 		DynamicString type(ta);
 		DynamicString type(ta);
 		sjson::parse_string(obj["shape"], type);
 		sjson::parse_string(obj["shape"], type);
 
 
-		ShapeType::Enum st = shape_type_to_enum(type.c_str());
-		RESOURCE_COMPILER_ASSERT(st != ShapeType::COUNT
+		ColliderType::Enum st = shape_type_to_enum(type.c_str());
+		RESOURCE_COMPILER_ASSERT(st != ColliderType::COUNT
 			, opts
 			, opts
 			, "Unknown shape type: '%s'"
 			, "Unknown shape type: '%s'"
 			, type.c_str()
 			, type.c_str()
 			);
 			);
 
 
-		ShapeDesc sd;
+		ColliderDesc sd;
 		sd.type        = st;
 		sd.type        = st;
 		sd.shape_class = sjson::parse_string_id(obj["class"]);
 		sd.shape_class = sjson::parse_string_id(obj["class"]);
 		sd.material    = sjson::parse_string_id(obj["material"]);
 		sd.material    = sjson::parse_string_id(obj["material"]);
@@ -223,12 +223,12 @@ namespace physics_resource
 
 
 		switch (sd.type)
 		switch (sd.type)
 		{
 		{
-			case ShapeType::SPHERE:      compile_sphere(mesh, sd); break;
-			case ShapeType::CAPSULE:     compile_capsule(mesh, sd); break;
-			case ShapeType::BOX:         compile_box(mesh, sd); break;
-			case ShapeType::CONVEX_HULL: compile_convex_hull(mesh, mesh_data); break;
-			case ShapeType::MESH:
-			case ShapeType::HEIGHTFIELD:
+			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::CONVEX_HULL: compile_convex_hull(mesh, mesh_data); break;
+			case ColliderType::MESH:
+			case ColliderType::HEIGHTFIELD:
 			{
 			{
 				RESOURCE_COMPILER_ASSERT(false, opts, "Not implemented yet");
 				RESOURCE_COMPILER_ASSERT(false, opts, "Not implemented yet");
 				break;
 				break;

+ 1 - 1
src/world/physics_world.h

@@ -22,7 +22,7 @@ public:
 	PhysicsWorld() {}
 	PhysicsWorld() {}
 	virtual ~PhysicsWorld() {}
 	virtual ~PhysicsWorld() {}
 
 
-	virtual ColliderInstance create_collider(UnitId id, const ShapeDesc* sd) = 0;
+	virtual ColliderInstance create_collider(UnitId id, const ColliderDesc* sd) = 0;
 	virtual ColliderInstance first_collider(UnitId id) = 0;
 	virtual ColliderInstance first_collider(UnitId id) = 0;
 	virtual ColliderInstance next_collider(ColliderInstance i) = 0;
 	virtual ColliderInstance next_collider(ColliderInstance i) = 0;
 
 

+ 7 - 7
src/world/physics_world_bullet.cpp

@@ -204,22 +204,22 @@ public:
 		CE_DELETE(*_allocator, _scene);
 		CE_DELETE(*_allocator, _scene);
 	}
 	}
 
 
-	ColliderInstance create_collider(UnitId id, const ShapeDesc* sd)
+	ColliderInstance create_collider(UnitId id, const ColliderDesc* sd)
 	{
 	{
 		btCollisionShape* child_shape = NULL;
 		btCollisionShape* child_shape = NULL;
 
 
 		switch(sd->type)
 		switch(sd->type)
 		{
 		{
-			case ShapeType::SPHERE:
+			case ColliderType::SPHERE:
 				child_shape = CE_NEW(*_allocator, btSphereShape)(sd->sphere.radius);
 				child_shape = CE_NEW(*_allocator, btSphereShape)(sd->sphere.radius);
 				break;
 				break;
-			case ShapeType::CAPSULE:
+			case ColliderType::CAPSULE:
 				child_shape = CE_NEW(*_allocator, btCapsuleShape)(sd->capsule.radius, sd->capsule.height);
 				child_shape = CE_NEW(*_allocator, btCapsuleShape)(sd->capsule.radius, sd->capsule.height);
 				break;
 				break;
-			case ShapeType::BOX:
+			case ColliderType::BOX:
 				child_shape = CE_NEW(*_allocator, btBoxShape)(to_btVector3(sd->box.half_size));
 				child_shape = CE_NEW(*_allocator, btBoxShape)(to_btVector3(sd->box.half_size));
 				break;
 				break;
-			case ShapeType::CONVEX_HULL:
+			case ColliderType::CONVEX_HULL:
 			{
 			{
 				const u32 num = *(const u32*)&sd[1];
 				const u32 num = *(const u32*)&sd[1];
 				const Vector3* points = (const Vector3*)((const char*)(&sd[1]) + sizeof(num));
 				const Vector3* points = (const Vector3*)((const char*)(&sd[1]) + sizeof(num));
@@ -234,8 +234,8 @@ public:
 				child_shape = convex;
 				child_shape = convex;
 				break;
 				break;
 			}
 			}
-			case ShapeType::MESH:
-			case ShapeType::HEIGHTFIELD:
+			case ColliderType::MESH:
+			case ColliderType::HEIGHTFIELD:
 			{
 			{
 				CE_FATAL("Not implemented yet");
 				CE_FATAL("Not implemented yet");
 				break;
 				break;

+ 1 - 1
src/world/world.cpp

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

+ 3 - 3
src/world/world_types.h

@@ -87,10 +87,10 @@ struct ActorFlags
 	};
 	};
 };
 };
 
 
-/// Enumerates shape types.
+/// Enumerates collider types.
 ///
 ///
 /// @ingroup World
 /// @ingroup World
-struct ShapeType
+struct ColliderType
 {
 {
 	enum Enum
 	enum Enum
 	{
 	{
@@ -387,7 +387,7 @@ struct HeightfieldShape
 	f32 max_height;
 	f32 max_height;
 };
 };
 
 
-struct ShapeDesc
+struct ColliderDesc
 {
 {
 	StringId32 shape_class;       ///< Name of shape in global.physics_config resource.
 	StringId32 shape_class;       ///< Name of shape in global.physics_config resource.
 	u32 type;                     ///< ShapeType::Enum
 	u32 type;                     ///< ShapeType::Enum