summaryrefslogtreecommitdiff
path: root/src/script/lua_api
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2018-01-30 00:30:02 +0100
committerGitHub <noreply@github.com>2018-01-30 00:30:02 +0100
commit584d00a01c4bcd359cc3e585dbcab5cada662348 (patch)
tree4105f4d31e743ac808de40386271b9f331f1dcb5 /src/script/lua_api
parent3b4df956b171385f5c50be48718b900375f3040d (diff)
downloadminetest-584d00a01c4bcd359cc3e585dbcab5cada662348.tar.gz
minetest-584d00a01c4bcd359cc3e585dbcab5cada662348.tar.bz2
minetest-584d00a01c4bcd359cc3e585dbcab5cada662348.zip
Add minetest.bulk_set_node call + optimize Environment::set_node call (#6958)
* Add minetest.bulk_set_node call + experimental mod unittest * Optimize set_node function to prevent triple lookup on contentfeatures Do only one lookup for old, and try to merge old and new lookup if node is same than previous node * Add benchmark function + optimize vector population to have real results
Diffstat (limited to 'src/script/lua_api')
-rw-r--r--src/script/lua_api/l_env.cpp34
-rw-r--r--src/script/lua_api/l_env.h4
2 files changed, 38 insertions, 0 deletions
diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp
index 237d14ab3..684885341 100644
--- a/src/script/lua_api/l_env.cpp
+++ b/src/script/lua_api/l_env.cpp
@@ -273,6 +273,39 @@ int ModApiEnvMod::l_set_node(lua_State *L)
return 1;
}
+// bulk_set_node([pos1, pos2, ...], node)
+// pos = {x=num, y=num, z=num}
+int ModApiEnvMod::l_bulk_set_node(lua_State *L)
+{
+ GET_ENV_PTR;
+
+ INodeDefManager *ndef = env->getGameDef()->ndef();
+ // parameters
+ if (!lua_istable(L, 1)) {
+ return 0;
+ }
+
+ s32 len = lua_objlen(L, 1);
+ if (len == 0) {
+ lua_pushboolean(L, true);
+ return 1;
+ }
+
+ MapNode n = readnode(L, 2, ndef);
+
+ // Do it
+ bool succeeded = true;
+ for (s32 i = 1; i <= len; i++) {
+ lua_rawgeti(L, 1, i);
+ if (!env->setNode(read_v3s16(L, -1), n))
+ succeeded = false;
+ lua_pop(L, 1);
+ }
+
+ lua_pushboolean(L, succeeded);
+ return 1;
+}
+
int ModApiEnvMod::l_add_node(lua_State *L)
{
return l_set_node(L);
@@ -1232,6 +1265,7 @@ int ModApiEnvMod::l_forceload_free_block(lua_State *L)
void ModApiEnvMod::Initialize(lua_State *L, int top)
{
API_FCT(set_node);
+ API_FCT(bulk_set_node);
API_FCT(add_node);
API_FCT(swap_node);
API_FCT(add_item);
diff --git a/src/script/lua_api/l_env.h b/src/script/lua_api/l_env.h
index 1314456f8..4a8700f12 100644
--- a/src/script/lua_api/l_env.h
+++ b/src/script/lua_api/l_env.h
@@ -29,6 +29,10 @@ private:
// pos = {x=num, y=num, z=num}
static int l_set_node(lua_State *L);
+ // bulk_set_node([pos1, pos2, ...], node)
+ // pos = {x=num, y=num, z=num}
+ static int l_bulk_set_node(lua_State *L);
+
static int l_add_node(lua_State *L);
// remove_node(pos)