aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorKahrl <kahrl@gmx.net>2017-09-11 15:51:40 +0200
committersfan5 <sfan5@live.de>2017-09-12 19:31:46 +0200
commit17fd5fe9358615633a04d7a3941b444a8ce5f199 (patch)
treefc2862413a9fb3b022ae773498ef7d6d5c588eac /src/script
parent5b3fbf9cf75f9f637c666d34e2489fef0cc035d9 (diff)
downloadminetest-17fd5fe9358615633a04d7a3941b444a8ce5f199.tar.gz
minetest-17fd5fe9358615633a04d7a3941b444a8ce5f199.tar.bz2
minetest-17fd5fe9358615633a04d7a3941b444a8ce5f199.zip
Make INodeDefManager::getIds return a vector, not a set
Diffstat (limited to 'src/script')
-rw-r--r--src/script/cpp_api/s_env.cpp12
-rw-r--r--src/script/lua_api/l_env.cpp27
-rw-r--r--src/script/lua_api/l_env.h12
3 files changed, 28 insertions, 23 deletions
diff --git a/src/script/cpp_api/s_env.cpp b/src/script/cpp_api/s_env.cpp
index b1404bf22..517892b03 100644
--- a/src/script/cpp_api/s_env.cpp
+++ b/src/script/cpp_api/s_env.cpp
@@ -108,7 +108,7 @@ void ScriptApiEnv::initializeEnvironment(ServerEnvironment *env)
int id = lua_tonumber(L, -2);
int current_abm = lua_gettop(L);
- std::set<std::string> trigger_contents;
+ std::vector<std::string> trigger_contents;
lua_getfield(L, current_abm, "nodenames");
if (lua_istable(L, -1)) {
int table = lua_gettop(L);
@@ -116,16 +116,16 @@ void ScriptApiEnv::initializeEnvironment(ServerEnvironment *env)
while (lua_next(L, table)) {
// key at index -2 and value at index -1
luaL_checktype(L, -1, LUA_TSTRING);
- trigger_contents.insert(lua_tostring(L, -1));
+ trigger_contents.push_back(lua_tostring(L, -1));
// removes value, keeps key for next iteration
lua_pop(L, 1);
}
} else if (lua_isstring(L, -1)) {
- trigger_contents.insert(lua_tostring(L, -1));
+ trigger_contents.push_back(lua_tostring(L, -1));
}
lua_pop(L, 1);
- std::set<std::string> required_neighbors;
+ std::vector<std::string> required_neighbors;
lua_getfield(L, current_abm, "neighbors");
if (lua_istable(L, -1)) {
int table = lua_gettop(L);
@@ -133,12 +133,12 @@ void ScriptApiEnv::initializeEnvironment(ServerEnvironment *env)
while (lua_next(L, table)) {
// key at index -2 and value at index -1
luaL_checktype(L, -1, LUA_TSTRING);
- required_neighbors.insert(lua_tostring(L, -1));
+ required_neighbors.push_back(lua_tostring(L, -1));
// removes value, keeps key for next iteration
lua_pop(L, 1);
}
} else if (lua_isstring(L, -1)) {
- required_neighbors.insert(lua_tostring(L, -1));
+ required_neighbors.push_back(lua_tostring(L, -1));
}
lua_pop(L, 1);
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;
}