aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorLoic Blot <loic.blot@unix-experience.fr>2016-10-08 10:38:04 +0200
committerNer'zhul <nerzhul@users.noreply.github.com>2016-10-08 11:36:28 +0200
commit8bcd10b872bc88c6f474913d6efb8d53c50c5ae1 (patch)
tree39a8af0048ed642eddc43c74ab9f736558663e9d /src/script
parent0264e38bff12a3c6b81231ac1f6cd281179df744 (diff)
downloadminetest-8bcd10b872bc88c6f474913d6efb8d53c50c5ae1.tar.gz
minetest-8bcd10b872bc88c6f474913d6efb8d53c50c5ae1.tar.bz2
minetest-8bcd10b872bc88c6f474913d6efb8d53c50c5ae1.zip
Player/LocalPlayer/RemotePlayer inheritance cleanup (part 1 on X)
* LocalPlayer take ownership of maxHudId as it's the only caller * RemotePlayer take ownership of day night ratio as it's the only user * Pass getPlayerControl as const reference to prevent object copy on each call (perf improvement in ObjectRef::l_get_player_control call) * getPlayerSAO is now only RemotePlayer call * get/setHotbarItemCount is now RemotePlayer owned * Server: Use RemotePlayer instead of Player object on concerned call to properly fix the object type * PlayerSAO now uses RemotePlayer instead of Player because it's only server side * ObjectRef::getplayer also returns RemotePlayer as it's linked with PlayerSAO
Diffstat (limited to 'src/script')
-rw-r--r--src/script/lua_api/l_env.cpp4
-rw-r--r--src/script/lua_api/l_object.cpp16
-rw-r--r--src/script/lua_api/l_object.h3
3 files changed, 12 insertions, 11 deletions
diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp
index ebdea09e4..f6ea23e95 100644
--- a/src/script/lua_api/l_env.cpp
+++ b/src/script/lua_api/l_env.cpp
@@ -494,8 +494,8 @@ int ModApiEnvMod::l_get_player_by_name(lua_State *L)
// Do it
const char *name = luaL_checkstring(L, 1);
- Player *player = env->getPlayer(name);
- if(player == NULL){
+ RemotePlayer *player = dynamic_cast<RemotePlayer *>(env->getPlayer(name));
+ if (player == NULL){
lua_pushnil(L);
return 1;
}
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp
index befae4253..4e1a1c159 100644
--- a/src/script/lua_api/l_object.cpp
+++ b/src/script/lua_api/l_object.cpp
@@ -107,7 +107,7 @@ PlayerSAO* ObjectRef::getplayersao(ObjectRef *ref)
return (PlayerSAO*)obj;
}
-Player* ObjectRef::getplayer(ObjectRef *ref)
+RemotePlayer* ObjectRef::getplayer(ObjectRef *ref)
{
PlayerSAO *playersao = getplayersao(ref);
if (playersao == NULL)
@@ -1212,8 +1212,8 @@ int ObjectRef::l_get_player_control(lua_State *L)
lua_pushlstring(L, "", 0);
return 1;
}
- // Do it
- PlayerControl control = player->getPlayerControl();
+
+ const PlayerControl &control = player->getPlayerControl();
lua_newtable(L);
lua_pushboolean(L, control.up);
lua_setfield(L, -2, "up");
@@ -1467,7 +1467,7 @@ int ObjectRef::l_hud_set_flags(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
- Player *player = getplayer(ref);
+ RemotePlayer *player = getplayer(ref);
if (player == NULL)
return 0;
@@ -1519,7 +1519,7 @@ int ObjectRef::l_hud_set_hotbar_itemcount(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
- Player *player = getplayer(ref);
+ RemotePlayer *player = getplayer(ref);
if (player == NULL)
return 0;
@@ -1537,7 +1537,7 @@ int ObjectRef::l_hud_get_hotbar_itemcount(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
- Player *player = getplayer(ref);
+ RemotePlayer *player = getplayer(ref);
if (player == NULL)
return 0;
@@ -1677,7 +1677,7 @@ int ObjectRef::l_override_day_night_ratio(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
- Player *player = getplayer(ref);
+ RemotePlayer *player = getplayer(ref);
if (player == NULL)
return 0;
@@ -1700,7 +1700,7 @@ int ObjectRef::l_get_day_night_ratio(lua_State *L)
{
NO_MAP_LOCK_REQUIRED;
ObjectRef *ref = checkobject(L, 1);
- Player *player = getplayer(ref);
+ RemotePlayer *player = getplayer(ref);
if (player == NULL)
return 0;
diff --git a/src/script/lua_api/l_object.h b/src/script/lua_api/l_object.h
index a37d29535..a7ac9dff9 100644
--- a/src/script/lua_api/l_object.h
+++ b/src/script/lua_api/l_object.h
@@ -27,6 +27,7 @@ class ServerActiveObject;
class LuaEntitySAO;
class PlayerSAO;
class Player;
+class RemotePlayer;
/*
ObjectRef
@@ -47,7 +48,7 @@ private:
static PlayerSAO* getplayersao(ObjectRef *ref);
- static Player* getplayer(ObjectRef *ref);
+ static RemotePlayer* getplayer(ObjectRef *ref);
// Exported functions