mikymod 12 лет назад
Родитель
Сommit
0eadc8ff2b
4 измененных файлов с 14 добавлено и 10 удалено
  1. 6 3
      engine/world/Unit.cpp
  2. 3 3
      engine/world/Unit.h
  3. 4 3
      engine/world/World.cpp
  4. 1 1
      engine/world/World.h

+ 6 - 3
engine/world/Unit.cpp

@@ -41,10 +41,10 @@ namespace crown
 {
 
 //-----------------------------------------------------------------------------
-Unit::Unit(World& w, const char* name, const UnitResource* ur, const Matrix4x4& pose)
+Unit::Unit(World& w, const ResourceId id, const UnitResource* ur, const Matrix4x4& pose)
 	: m_world(w)
-	, m_unit_name(name)
 	, m_scene_graph(*w.scene_graph_manager()->create_scene_graph())
+	, m_resource_id(id)
 	, m_resource(ur)
 	, m_num_cameras(0)
 	, m_num_meshes(0)
@@ -565,7 +565,10 @@ Material* Unit::material(uint32_t i)
 //-----------------------------------------------------------------------------
 bool Unit::is_a(const char* name)
 {
-	return string::strcmp(name, m_unit_name) == 0;
+	DynamicString unit(name);
+	unit += ".unit";
+
+	return m_resource_id.id == hash::murmur2_64(unit.c_str(), string::strlen(unit.c_str()), 0);
 }
 
 

+ 3 - 3
engine/world/Unit.h

@@ -75,7 +75,7 @@ struct UnitResource;
 
 struct Unit
 {
-						Unit(World& w, const char* name, const UnitResource* ur, const Matrix4x4& pose);
+						Unit(World& w, const ResourceId id, const UnitResource* ur, const Matrix4x4& pose);
 						~Unit();
 
 	void				set_id(const UnitId id);
@@ -136,6 +136,7 @@ struct Unit
 	Controller*			controller();
 
 	bool				is_a(const char* name);
+
 private:
 
 	void				create_objects(const Matrix4x4& pose);
@@ -149,6 +150,7 @@ public:
 
 	World&				m_world;
 	SceneGraph&			m_scene_graph;
+	const ResourceId	m_resource_id;
 	const UnitResource*	m_resource;
 	UnitId				m_id;
 
@@ -168,8 +170,6 @@ public:
 	Component			m_materials[CE_MAX_MATERIAL_COMPONENTS];
 
 	Component			m_controller;
-
-	const char* 		m_unit_name;
 };
 
 } // namespace crown

+ 4 - 3
engine/world/World.cpp

@@ -72,14 +72,15 @@ void World::set_id(WorldId id)
 UnitId World::spawn_unit(const char* name, const Vector3& pos, const Quaternion& rot)
 {
 	UnitResource* ur = (UnitResource*) device()->resource_manager()->lookup(UNIT_EXTENSION, name);
-	return spawn_unit(name, ur, pos, rot);
+	ResourceId id = device()->resource_manager()->resource_id(UNIT_EXTENSION, name);
+	return spawn_unit(id, ur, pos, rot);
 }
 
 //-----------------------------------------------------------------------------
-UnitId World::spawn_unit(const char* name, UnitResource* ur, const Vector3& pos, const Quaternion& rot)
+UnitId World::spawn_unit(const ResourceId id, UnitResource* ur, const Vector3& pos, const Quaternion& rot)
 {
 	// Allocate memory for unit
-	Unit* unit = CE_NEW(m_unit_pool, Unit)(*this, name, ur, Matrix4x4(rot, pos));
+	Unit* unit = CE_NEW(m_unit_pool, Unit)(*this, id, ur, Matrix4x4(rot, pos));
 
 	// Create Id for the unit
 	const UnitId unit_id = m_units.create(unit);

+ 1 - 1
engine/world/World.h

@@ -63,7 +63,7 @@ public:
 	void								set_id(WorldId id);
 
 	UnitId								spawn_unit(const char* name, const Vector3& pos = Vector3::ZERO, const Quaternion& rot = Quaternion::IDENTITY);
-	UnitId								spawn_unit(const char* name, UnitResource* ur, const Vector3& pos, const Quaternion& rot);
+	UnitId								spawn_unit(const ResourceId id, UnitResource* ur, const Vector3& pos, const Quaternion& rot);
 	void								destroy_unit(UnitId id);
 	void								reload_units(UnitResource* old_ur, UnitResource* new_ur);