aboutsummaryrefslogtreecommitdiff
path: root/src/script/lua_api
diff options
context:
space:
mode:
authorLoïc Blot <nerzhul@users.noreply.github.com>2020-04-11 19:59:43 +0200
committerGitHub <noreply@github.com>2020-04-11 19:59:43 +0200
commit5cc06e4748a82acb36310fee89e72f30b2b35a36 (patch)
treebf99c5498f491c831c8494c064f2be5502f4bdf0 /src/script/lua_api
parent5146086a64d5eeb480948d612a008a2ec81455d4 (diff)
downloadminetest-5cc06e4748a82acb36310fee89e72f30b2b35a36.tar.gz
minetest-5cc06e4748a82acb36310fee89e72f30b2b35a36.tar.bz2
minetest-5cc06e4748a82acb36310fee89e72f30b2b35a36.zip
Reduce ServerEnvironment propagation (#9642)
ServerEnvironment is a huge class with many accessors. In various places it's not needed Remove it to reduce the ServerEnvironment view. Idea here is to reduce size of some of our objects to transport lightweight managers and permit easier testing Pathfinder is now tied to a generic map, not a ServerMap, it can be ported to client
Diffstat (limited to 'src/script/lua_api')
-rw-r--r--src/script/lua_api/l_env.cpp7
-rw-r--r--src/script/lua_api/l_nodetimer.cpp44
-rw-r--r--src/script/lua_api/l_nodetimer.h10
3 files changed, 16 insertions, 45 deletions
diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp
index 40e50e64a..e3afe1862 100644
--- a/src/script/lua_api/l_env.cpp
+++ b/src/script/lua_api/l_env.cpp
@@ -577,7 +577,7 @@ int ModApiEnvMod::l_get_node_timer(lua_State *L)
// Do it
v3s16 p = read_v3s16(L, 1);
- NodeTimerRef::create(L, p, env);
+ NodeTimerRef::create(L, p, &env->getServerMap());
return 1;
}
@@ -1193,7 +1193,7 @@ int ModApiEnvMod::l_find_path(lua_State *L)
algo = PA_DIJKSTRA;
}
- std::vector<v3s16> path = get_path(env, pos1, pos2,
+ std::vector<v3s16> path = get_path(&env->getServerMap(), env->getGameDef()->ndef(), pos1, pos2,
searchdistance, max_jump, max_drop, algo);
if (!path.empty()) {
@@ -1257,8 +1257,9 @@ int ModApiEnvMod::l_spawn_tree(lua_State *L)
else
return 0;
+ ServerMap *map = &env->getServerMap();
treegen::error e;
- if ((e = treegen::spawn_ltree (env, p0, ndef, tree_def)) != treegen::SUCCESS) {
+ if ((e = treegen::spawn_ltree (map, p0, ndef, tree_def)) != treegen::SUCCESS) {
if (e == treegen::UNBALANCED_BRACKETS) {
luaL_error(L, "spawn_tree(): closing ']' has no matching opening bracket");
} else {
diff --git a/src/script/lua_api/l_nodetimer.cpp b/src/script/lua_api/l_nodetimer.cpp
index 15a59744f..c2df52c05 100644
--- a/src/script/lua_api/l_nodetimer.cpp
+++ b/src/script/lua_api/l_nodetimer.cpp
@@ -41,11 +41,9 @@ int NodeTimerRef::l_set(lua_State *L)
{
MAP_LOCK_REQUIRED;
NodeTimerRef *o = checkobject(L, 1);
- ServerEnvironment *env = o->m_env;
- if(env == NULL) return 0;
f32 t = readParam<float>(L,2);
f32 e = readParam<float>(L,3);
- env->getMap().setNodeTimer(NodeTimer(t, e, o->m_p));
+ o->m_map->setNodeTimer(NodeTimer(t, e, o->m_p));
return 0;
}
@@ -53,10 +51,8 @@ int NodeTimerRef::l_start(lua_State *L)
{
MAP_LOCK_REQUIRED;
NodeTimerRef *o = checkobject(L, 1);
- ServerEnvironment *env = o->m_env;
- if(env == NULL) return 0;
f32 t = readParam<float>(L,2);
- env->getMap().setNodeTimer(NodeTimer(t, 0, o->m_p));
+ o->m_map->setNodeTimer(NodeTimer(t, 0, o->m_p));
return 0;
}
@@ -64,9 +60,7 @@ int NodeTimerRef::l_stop(lua_State *L)
{
MAP_LOCK_REQUIRED;
NodeTimerRef *o = checkobject(L, 1);
- ServerEnvironment *env = o->m_env;
- if(env == NULL) return 0;
- env->getMap().removeNodeTimer(o->m_p);
+ o->m_map->removeNodeTimer(o->m_p);
return 0;
}
@@ -74,10 +68,7 @@ int NodeTimerRef::l_is_started(lua_State *L)
{
MAP_LOCK_REQUIRED;
NodeTimerRef *o = checkobject(L, 1);
- ServerEnvironment *env = o->m_env;
- if(env == NULL) return 0;
-
- NodeTimer t = env->getMap().getNodeTimer(o->m_p);
+ NodeTimer t = o->m_map->getNodeTimer(o->m_p);
lua_pushboolean(L,(t.timeout != 0));
return 1;
}
@@ -86,10 +77,7 @@ int NodeTimerRef::l_get_timeout(lua_State *L)
{
MAP_LOCK_REQUIRED;
NodeTimerRef *o = checkobject(L, 1);
- ServerEnvironment *env = o->m_env;
- if(env == NULL) return 0;
-
- NodeTimer t = env->getMap().getNodeTimer(o->m_p);
+ NodeTimer t = o->m_map->getNodeTimer(o->m_p);
lua_pushnumber(L,t.timeout);
return 1;
}
@@ -98,37 +86,21 @@ int NodeTimerRef::l_get_elapsed(lua_State *L)
{
MAP_LOCK_REQUIRED;
NodeTimerRef *o = checkobject(L, 1);
- ServerEnvironment *env = o->m_env;
- if(env == NULL) return 0;
-
- NodeTimer t = env->getMap().getNodeTimer(o->m_p);
+ NodeTimer t = o->m_map->getNodeTimer(o->m_p);
lua_pushnumber(L,t.elapsed);
return 1;
}
-
-NodeTimerRef::NodeTimerRef(v3s16 p, ServerEnvironment *env):
- m_p(p),
- m_env(env)
-{
-}
-
// Creates an NodeTimerRef and leaves it on top of stack
// Not callable from Lua; all references are created on the C side.
-void NodeTimerRef::create(lua_State *L, v3s16 p, ServerEnvironment *env)
+void NodeTimerRef::create(lua_State *L, v3s16 p, ServerMap *map)
{
- NodeTimerRef *o = new NodeTimerRef(p, env);
+ NodeTimerRef *o = new NodeTimerRef(p, map);
*(void **)(lua_newuserdata(L, sizeof(void *))) = o;
luaL_getmetatable(L, className);
lua_setmetatable(L, -2);
}
-void NodeTimerRef::set_null(lua_State *L)
-{
- NodeTimerRef *o = checkobject(L, -1);
- o->m_env = NULL;
-}
-
void NodeTimerRef::Register(lua_State *L)
{
lua_newtable(L);
diff --git a/src/script/lua_api/l_nodetimer.h b/src/script/lua_api/l_nodetimer.h
index b894c5c8c..bbc975fd2 100644
--- a/src/script/lua_api/l_nodetimer.h
+++ b/src/script/lua_api/l_nodetimer.h
@@ -22,13 +22,13 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irr_v3d.h"
#include "lua_api/l_base.h"
-class ServerEnvironment;
+class ServerMap;
class NodeTimerRef : public ModApiBase
{
private:
v3s16 m_p;
- ServerEnvironment *m_env = nullptr;
+ ServerMap *m_map;
static const char className[];
static const luaL_Reg methods[];
@@ -50,14 +50,12 @@ private:
static int l_get_elapsed(lua_State *L);
public:
- NodeTimerRef(v3s16 p, ServerEnvironment *env);
+ NodeTimerRef(v3s16 p, ServerMap *map) : m_p(p), m_map(map) {}
~NodeTimerRef() = default;
// Creates an NodeTimerRef and leaves it on top of stack
// Not callable from Lua; all references are created on the C side.
- static void create(lua_State *L, v3s16 p, ServerEnvironment *env);
-
- static void set_null(lua_State *L);
+ static void create(lua_State *L, v3s16 p, ServerMap *map);
static void Register(lua_State *L);
};