Просмотр исходного кода

Add support to Material to UnitResource

Daniele Bartolini 12 лет назад
Родитель
Сommit
bc0496e645
2 измененных файлов с 26 добавлено и 3 удалено
  1. 19 3
      engine/resource/UnitResource.cpp
  2. 7 0
      engine/resource/UnitResource.h

+ 19 - 3
engine/resource/UnitResource.cpp

@@ -229,6 +229,7 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 	JSONElement root = json.root();
 	JSONElement root = json.root();
 
 
 	ResourceId				m_physics_resource;
 	ResourceId				m_physics_resource;
+	ResourceId				m_material_resource;
 	List<GraphNode>			m_nodes(default_allocator());
 	List<GraphNode>			m_nodes(default_allocator());
 	List<GraphNodeDepth>	m_node_depths(default_allocator());
 	List<GraphNodeDepth>	m_node_depths(default_allocator());
 	List<UnitCamera>		m_cameras(default_allocator());
 	List<UnitCamera>		m_cameras(default_allocator());
@@ -293,18 +294,33 @@ void compile(Filesystem& fs, const char* resource_path, File* out_file)
 	// Check if the unit has a .physics resource
 	// Check if the unit has a .physics resource
 	DynamicString unit_name(resource_path);
 	DynamicString unit_name(resource_path);
 	unit_name.strip_trailing("unit");
 	unit_name.strip_trailing("unit");
-	unit_name += "physics";
-	if (fs.is_file(unit_name.c_str()))
+	DynamicString physics_name = unit_name;
+	physics_name += "physics";
+	if (fs.is_file(physics_name.c_str()))
 	{
 	{
-		m_physics_resource.id = hash::murmur2_64(unit_name.c_str(), string::strlen(unit_name.c_str()), 0);
+		m_physics_resource.id = hash::murmur2_64(physics_name.c_str(), string::strlen(physics_name.c_str()), 0);
 	}
 	}
 	else
 	else
 	{
 	{
 		m_physics_resource.id = 0;
 		m_physics_resource.id = 0;
 	}
 	}
 
 
+	// Check if the unit has a .material resource
+	DynamicString material_name = unit_name;
+	material_name += "material";
+	if (fs.is_file(material_name.c_str()))
+	{
+		m_material_resource.id = hash::murmur2_64(material_name.c_str(), string::strlen(material_name.c_str()), 0);
+	}
+	else
+	{
+		m_material_resource.id = 0;
+	}
+
+
 	UnitHeader h;
 	UnitHeader h;
 	h.physics_resource = m_physics_resource;
 	h.physics_resource = m_physics_resource;
+	h.material_resource = m_material_resource;
 	h.num_renderables = m_renderables.size();
 	h.num_renderables = m_renderables.size();
 	h.num_cameras = m_cameras.size();
 	h.num_cameras = m_cameras.size();
 	h.num_actors = m_actors.size();
 	h.num_actors = m_actors.size();

+ 7 - 0
engine/resource/UnitResource.h

@@ -41,6 +41,7 @@ namespace crown
 struct UnitHeader
 struct UnitHeader
 {
 {
 	ResourceId physics_resource;
 	ResourceId physics_resource;
+	ResourceId material_resource;
 	uint32_t num_renderables;
 	uint32_t num_renderables;
 	uint32_t renderables_offset;
 	uint32_t renderables_offset;
 	uint32_t num_cameras;
 	uint32_t num_cameras;
@@ -116,6 +117,12 @@ struct UnitResource
 		return ((UnitHeader*) this)->physics_resource;
 		return ((UnitHeader*) this)->physics_resource;
 	}
 	}
 
 
+	//-----------------------------------------------------------------------------
+	ResourceId material_resource() const
+	{
+		return ((UnitHeader*) this)->material_resource;
+	}
+
 	//-----------------------------------------------------------------------------
 	//-----------------------------------------------------------------------------
 	uint32_t num_renderables() const
 	uint32_t num_renderables() const
 	{
 	{