Daniele Bartolini 12 лет назад
Родитель
Сommit
4fc2e8bdcd
3 измененных файлов с 20 добавлено и 0 удалено
  1. 6 0
      engine/World.cpp
  2. 2 0
      engine/World.h
  3. 12 0
      engine/lua/LuaWorld.cpp

+ 6 - 0
engine/World.cpp

@@ -81,6 +81,12 @@ void World::destroy_unit(Unit* unit)
 	destroy_unit(unit->m_id);
 }
 
+//-----------------------------------------------------------------------------
+uint32_t World::num_units() const
+{
+	return m_units.size();
+}
+
 //-----------------------------------------------------------------------------
 void World::link_unit(UnitId child, UnitId parent, int32_t node)
 {

+ 2 - 0
engine/World.h

@@ -98,6 +98,8 @@ public:
 	void								destroy_unit(UnitId id);
 	void								destroy_unit(Unit* unit);
 
+	uint32_t							num_units() const;
+
 	void								link_unit(UnitId child, UnitId parent, int32_t node);
 	void								unlink_unit(UnitId unit);
 

+ 12 - 0
engine/lua/LuaWorld.cpp

@@ -61,6 +61,17 @@ CE_EXPORT int world_destroy_unit(lua_State* L)
 	return 0;
 }
 
+//-----------------------------------------------------------------------------
+CE_EXPORT int world_num_units(lua_State* L)
+{
+	LuaStack stack(L);
+
+	World* world = stack.get_world(1);
+
+	stack.push_uint32(world->num_units());
+	return 1;
+}
+
 //-----------------------------------------------------------------------------
 CE_EXPORT int world_play_sound(lua_State* L)
 {
@@ -166,6 +177,7 @@ void load_world(LuaEnvironment& env)
 {
 	env.load_module_function("World", "spawn_unit",			world_spawn_unit);
 	env.load_module_function("World", "destroy_unit",       world_destroy_unit);
+	env.load_module_function("World", "num_units",          world_num_units);
 
 	env.load_module_function("World", "play_sound",			world_play_sound);
 	env.load_module_function("World", "stop_sound", 		world_stop_sound);