瀏覽代碼

save unit name in Unit

mikymod 12 年之前
父節點
當前提交
e69415d311
共有 4 個文件被更改,包括 17 次插入6 次删除
  1. 9 1
      engine/world/Unit.cpp
  2. 4 1
      engine/world/Unit.h
  3. 3 3
      engine/world/World.cpp
  4. 1 1
      engine/world/World.h

+ 9 - 1
engine/world/Unit.cpp

@@ -41,8 +41,9 @@ namespace crown
 {
 
 //-----------------------------------------------------------------------------
-Unit::Unit(World& w, const UnitResource* ur, const Matrix4x4& pose)
+Unit::Unit(World& w, const char* name, 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(ur)
 	, m_num_cameras(0)
@@ -561,4 +562,11 @@ Material* Unit::material(uint32_t i)
 	return m_world.render_world()->lookup_material(material);
 }
 
+//-----------------------------------------------------------------------------
+bool Unit::is_a(const char* name)
+{
+	return string::strcmp(name, m_unit_name) == 0;
+}
+
+
 } // namespace crown

+ 4 - 1
engine/world/Unit.h

@@ -75,7 +75,7 @@ struct UnitResource;
 
 struct Unit
 {
-						Unit(World& w, const UnitResource* ur, const Matrix4x4& pose);
+						Unit(World& w, const char* name, const UnitResource* ur, const Matrix4x4& pose);
 						~Unit();
 
 	void				set_id(const UnitId id);
@@ -135,6 +135,7 @@ struct Unit
 
 	Controller*			controller();
 
+	bool				is_a(const char* name);
 private:
 
 	void				create_objects(const Matrix4x4& pose);
@@ -167,6 +168,8 @@ public:
 	Component			m_materials[CE_MAX_MATERIAL_COMPONENTS];
 
 	Component			m_controller;
+
+	const char* 		m_unit_name;
 };
 
 } // namespace crown

+ 3 - 3
engine/world/World.cpp

@@ -72,14 +72,14 @@ 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(ur, pos, rot);
+	return spawn_unit(name, ur, pos, rot);
 }
 
 //-----------------------------------------------------------------------------
-UnitId World::spawn_unit(UnitResource* ur, const Vector3& pos, const Quaternion& rot)
+UnitId World::spawn_unit(const char* name, UnitResource* ur, const Vector3& pos, const Quaternion& rot)
 {
 	// Allocate memory for unit
-	Unit* unit = CE_NEW(m_unit_pool, Unit)(*this, ur, Matrix4x4(rot, pos));
+	Unit* unit = CE_NEW(m_unit_pool, Unit)(*this, name, 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(UnitResource* ur, const Vector3& pos, const Quaternion& rot);
+	UnitId								spawn_unit(const char* name, UnitResource* ur, const Vector3& pos, const Quaternion& rot);
 	void								destroy_unit(UnitId id);
 	void								reload_units(UnitResource* old_ur, UnitResource* new_ur);