diff options
author | Kahrl <kahrl@gmx.net> | 2017-09-11 15:51:40 +0200 |
---|---|---|
committer | sfan5 <sfan5@live.de> | 2017-09-12 19:31:46 +0200 |
commit | 17fd5fe9358615633a04d7a3941b444a8ce5f199 (patch) | |
tree | fc2862413a9fb3b022ae773498ef7d6d5c588eac /src/script/lua_api | |
parent | 5b3fbf9cf75f9f637c666d34e2489fef0cc035d9 (diff) | |
download | minetest-17fd5fe9358615633a04d7a3941b444a8ce5f199.tar.gz minetest-17fd5fe9358615633a04d7a3941b444a8ce5f199.tar.bz2 minetest-17fd5fe9358615633a04d7a3941b444a8ce5f199.zip |
Make INodeDefManager::getIds return a vector, not a set
Diffstat (limited to 'src/script/lua_api')
-rw-r--r-- | src/script/lua_api/l_env.cpp | 27 | ||||
-rw-r--r-- | src/script/lua_api/l_env.h | 12 |
2 files changed, 22 insertions, 17 deletions
diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index be92365ac..1d0716484 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -719,7 +719,7 @@ int ModApiEnvMod::l_find_node_near(lua_State *L) INodeDefManager *ndef = getGameDef(L)->ndef(); v3s16 pos = read_v3s16(L, 1); int radius = luaL_checkinteger(L, 2); - std::set<content_t> filter; + std::vector<content_t> filter; if (lua_istable(L, 3)) { lua_pushnil(L); while (lua_next(L, 3) != 0) { @@ -748,7 +748,7 @@ int ModApiEnvMod::l_find_node_near(lua_State *L) for (const v3s16 &i : list) { v3s16 p = pos + i; content_t c = env->getMap().getNodeNoEx(p).getContent(); - if (filter.count(c) != 0) { + if (CONTAINS(filter, c)) { push_v3s16(L, p); return 1; } @@ -780,7 +780,7 @@ int ModApiEnvMod::l_find_nodes_in_area(lua_State *L) return 0; } - std::set<content_t> filter; + std::vector<content_t> filter; if (lua_istable(L, 3)) { lua_pushnil(L); while (lua_next(L, 3) != 0) { @@ -794,7 +794,8 @@ int ModApiEnvMod::l_find_nodes_in_area(lua_State *L) ndef->getIds(lua_tostring(L, 3), filter); } - std::unordered_map<content_t, u32> individual_count; + std::vector<u32> individual_count; + individual_count.resize(filter.size()); lua_newtable(L); u64 i = 0; @@ -803,16 +804,20 @@ int ModApiEnvMod::l_find_nodes_in_area(lua_State *L) for (s16 z = minp.Z; z <= maxp.Z; z++) { v3s16 p(x, y, z); content_t c = env->getMap().getNodeNoEx(p).getContent(); - if (filter.count(c) != 0) { + + std::vector<content_t>::iterator it = std::find(filter.begin(), filter.end(), c); + if (it != filter.end()) { push_v3s16(L, p); lua_rawseti(L, -2, ++i); - individual_count[c]++; + + u32 filt_index = it - filter.begin(); + individual_count[filt_index]++; } } lua_newtable(L); - for (content_t it : filter) { - lua_pushnumber(L, individual_count[it]); - lua_setfield(L, -2, ndef->get(it).name.c_str()); + for (u32 i = 0; i < filter.size(); i++) { + lua_pushnumber(L, individual_count[i]); + lua_setfield(L, -2, ndef->get(filter[i]).name.c_str()); } return 2; } @@ -847,7 +852,7 @@ int ModApiEnvMod::l_find_nodes_in_area_under_air(lua_State *L) return 0; } - std::set<content_t> filter; + std::vector<content_t> filter; if (lua_istable(L, 3)) { lua_pushnil(L); @@ -873,7 +878,7 @@ int ModApiEnvMod::l_find_nodes_in_area_under_air(lua_State *L) v3s16 psurf(x, y + 1, z); content_t csurf = env->getMap().getNodeNoEx(psurf).getContent(); if (c != CONTENT_AIR && csurf == CONTENT_AIR && - filter.count(c) != 0) { + CONTAINS(filter, c)) { push_v3s16(L, v3s16(x, y, z)); lua_rawseti(L, -2, ++i); } diff --git a/src/script/lua_api/l_env.h b/src/script/lua_api/l_env.h index 4d295b6eb..6cfdc0f6d 100644 --- a/src/script/lua_api/l_env.h +++ b/src/script/lua_api/l_env.h @@ -188,15 +188,15 @@ class LuaABM : public ActiveBlockModifier { private: int m_id; - std::set<std::string> m_trigger_contents; - std::set<std::string> m_required_neighbors; + std::vector<std::string> m_trigger_contents; + std::vector<std::string> m_required_neighbors; float m_trigger_interval; u32 m_trigger_chance; bool m_simple_catch_up; public: LuaABM(lua_State *L, int id, - const std::set<std::string> &trigger_contents, - const std::set<std::string> &required_neighbors, + const std::vector<std::string> &trigger_contents, + const std::vector<std::string> &required_neighbors, float trigger_interval, u32 trigger_chance, bool simple_catch_up): m_id(id), m_trigger_contents(trigger_contents), @@ -206,11 +206,11 @@ public: m_simple_catch_up(simple_catch_up) { } - virtual const std::set<std::string> &getTriggerContents() const + virtual const std::vector<std::string> &getTriggerContents() const { return m_trigger_contents; } - virtual const std::set<std::string> &getRequiredNeighbors() const + virtual const std::vector<std::string> &getRequiredNeighbors() const { return m_required_neighbors; } |