mirror of
https://github.com/luanti-org/luanti.git
synced 2025-06-27 16:36:03 +00:00
Fix some common SAO methods to not generate useless update packets
This commit is contained in:
parent
585ca90ae0
commit
c524c52baa
11 changed files with 160 additions and 85 deletions
|
@ -804,13 +804,16 @@ int ObjectRef::l_set_properties(lua_State *L)
|
|||
if (sao == nullptr)
|
||||
return 0;
|
||||
|
||||
ObjectProperties *prop = sao->accessObjectProperties();
|
||||
auto *prop = sao->accessObjectProperties();
|
||||
if (prop == nullptr)
|
||||
return 0;
|
||||
|
||||
const auto old = *prop;
|
||||
read_object_properties(L, 2, sao, prop, getServer(L)->idef());
|
||||
prop->validate();
|
||||
sao->notifyObjectPropertiesModified();
|
||||
if (*prop != old) {
|
||||
prop->validate();
|
||||
sao->notifyObjectPropertiesModified();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1124,7 +1127,7 @@ int ObjectRef::l_get_entity_name(lua_State *L)
|
|||
NO_MAP_LOCK_REQUIRED;
|
||||
ObjectRef *ref = checkObject<ObjectRef>(L, 1);
|
||||
LuaEntitySAO *entitysao = getluaobject(ref);
|
||||
log_deprecated(L,"Deprecated call to \"get_entity_name");
|
||||
log_deprecated(L, "Deprecated call to \"get_entity_name\"");
|
||||
if (entitysao == nullptr)
|
||||
return 0;
|
||||
|
||||
|
@ -1323,13 +1326,14 @@ int ObjectRef::l_set_fov(lua_State *L)
|
|||
if (player == nullptr)
|
||||
return 0;
|
||||
|
||||
float degrees = static_cast<f32>(luaL_checknumber(L, 2));
|
||||
bool is_multiplier = readParam<bool>(L, 3, false);
|
||||
float transition_time = lua_isnumber(L, 4) ?
|
||||
static_cast<f32>(luaL_checknumber(L, 4)) : 0.0f;
|
||||
PlayerFovSpec s;
|
||||
s.fov = readParam<float>(L, 2);
|
||||
s.is_multiplier = readParam<bool>(L, 3, false);
|
||||
if (lua_isnumber(L, 4))
|
||||
s.transition_time = readParam<float>(L, 4);
|
||||
|
||||
player->setFov({degrees, is_multiplier, transition_time});
|
||||
getServer(L)->SendPlayerFov(player->getPeerId());
|
||||
if (player->setFov(s))
|
||||
getServer(L)->SendPlayerFov(player->getPeerId());
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1342,7 +1346,7 @@ int ObjectRef::l_get_fov(lua_State *L)
|
|||
if (player == nullptr)
|
||||
return 0;
|
||||
|
||||
PlayerFovSpec fov_spec = player->getFov();
|
||||
const auto &fov_spec = player->getFov();
|
||||
|
||||
lua_pushnumber(L, fov_spec.fov);
|
||||
lua_pushboolean(L, fov_spec.is_multiplier);
|
||||
|
@ -1446,10 +1450,12 @@ int ObjectRef::l_set_inventory_formspec(lua_State *L)
|
|||
if (player == nullptr)
|
||||
return 0;
|
||||
|
||||
std::string formspec = luaL_checkstring(L, 2);
|
||||
auto formspec = readParam<std::string_view>(L, 2);
|
||||
|
||||
player->inventory_formspec = formspec;
|
||||
getServer(L)->reportInventoryFormspecModified(player->getName());
|
||||
if (formspec != player->inventory_formspec) {
|
||||
player->inventory_formspec = formspec;
|
||||
getServer(L)->reportInventoryFormspecModified(player->getName());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1462,7 +1468,7 @@ int ObjectRef::l_get_inventory_formspec(lua_State *L)
|
|||
if (player == nullptr)
|
||||
return 0;
|
||||
|
||||
std::string formspec = player->inventory_formspec;
|
||||
auto &formspec = player->inventory_formspec;
|
||||
|
||||
lua_pushlstring(L, formspec.c_str(), formspec.size());
|
||||
return 1;
|
||||
|
@ -1477,10 +1483,12 @@ int ObjectRef::l_set_formspec_prepend(lua_State *L)
|
|||
if (player == nullptr)
|
||||
return 0;
|
||||
|
||||
std::string formspec = luaL_checkstring(L, 2);
|
||||
auto formspec = readParam<std::string_view>(L, 2);
|
||||
|
||||
player->formspec_prepend = formspec;
|
||||
getServer(L)->reportFormspecPrependModified(player->getName());
|
||||
if (player->formspec_prepend != formspec) {
|
||||
player->formspec_prepend = formspec;
|
||||
getServer(L)->reportFormspecPrependModified(player->getName());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1493,7 +1501,7 @@ int ObjectRef::l_get_formspec_prepend(lua_State *L)
|
|||
if (player == nullptr)
|
||||
return 0;
|
||||
|
||||
std::string formspec = player->formspec_prepend;
|
||||
auto &formspec = player->formspec_prepend;
|
||||
|
||||
lua_pushlstring(L, formspec.c_str(), formspec.size());
|
||||
return 1;
|
||||
|
@ -1506,7 +1514,7 @@ int ObjectRef::l_get_player_control(lua_State *L)
|
|||
ObjectRef *ref = checkObject<ObjectRef>(L, 1);
|
||||
RemotePlayer *player = getplayer(ref);
|
||||
|
||||
lua_newtable(L);
|
||||
lua_createtable(L, 0, 12);
|
||||
if (player == nullptr)
|
||||
return 1;
|
||||
|
||||
|
@ -1580,41 +1588,26 @@ int ObjectRef::l_set_physics_override(lua_State *L)
|
|||
RemotePlayer *player = playersao->getPlayer();
|
||||
auto &phys = player->physics_override;
|
||||
|
||||
if (lua_istable(L, 2)) {
|
||||
bool modified = false;
|
||||
modified |= getfloatfield(L, 2, "speed", phys.speed);
|
||||
modified |= getfloatfield(L, 2, "jump", phys.jump);
|
||||
modified |= getfloatfield(L, 2, "gravity", phys.gravity);
|
||||
modified |= getboolfield(L, 2, "sneak", phys.sneak);
|
||||
modified |= getboolfield(L, 2, "sneak_glitch", phys.sneak_glitch);
|
||||
modified |= getboolfield(L, 2, "new_move", phys.new_move);
|
||||
modified |= getfloatfield(L, 2, "speed_climb", phys.speed_climb);
|
||||
modified |= getfloatfield(L, 2, "speed_crouch", phys.speed_crouch);
|
||||
modified |= getfloatfield(L, 2, "liquid_fluidity", phys.liquid_fluidity);
|
||||
modified |= getfloatfield(L, 2, "liquid_fluidity_smooth", phys.liquid_fluidity_smooth);
|
||||
modified |= getfloatfield(L, 2, "liquid_sink", phys.liquid_sink);
|
||||
modified |= getfloatfield(L, 2, "acceleration_default", phys.acceleration_default);
|
||||
modified |= getfloatfield(L, 2, "acceleration_air", phys.acceleration_air);
|
||||
if (modified)
|
||||
playersao->m_physics_override_sent = false;
|
||||
} else {
|
||||
// old, non-table format
|
||||
// TODO: Remove this code after version 5.4.0
|
||||
log_deprecated(L, "Deprecated use of set_physics_override(num, num, num)");
|
||||
const PlayerPhysicsOverride old = phys;
|
||||
|
||||
if (!lua_isnil(L, 2)) {
|
||||
phys.speed = lua_tonumber(L, 2);
|
||||
playersao->m_physics_override_sent = false;
|
||||
}
|
||||
if (!lua_isnil(L, 3)) {
|
||||
phys.jump = lua_tonumber(L, 3);
|
||||
playersao->m_physics_override_sent = false;
|
||||
}
|
||||
if (!lua_isnil(L, 4)) {
|
||||
phys.gravity = lua_tonumber(L, 4);
|
||||
playersao->m_physics_override_sent = false;
|
||||
}
|
||||
}
|
||||
luaL_checktype(L, 2, LUA_TTABLE);
|
||||
|
||||
getfloatfield(L, 2, "speed", phys.speed);
|
||||
getfloatfield(L, 2, "jump", phys.jump);
|
||||
getfloatfield(L, 2, "gravity", phys.gravity);
|
||||
getboolfield(L, 2, "sneak", phys.sneak);
|
||||
getboolfield(L, 2, "sneak_glitch", phys.sneak_glitch);
|
||||
getboolfield(L, 2, "new_move", phys.new_move);
|
||||
getfloatfield(L, 2, "speed_climb", phys.speed_climb);
|
||||
getfloatfield(L, 2, "speed_crouch", phys.speed_crouch);
|
||||
getfloatfield(L, 2, "liquid_fluidity", phys.liquid_fluidity);
|
||||
getfloatfield(L, 2, "liquid_fluidity_smooth", phys.liquid_fluidity_smooth);
|
||||
getfloatfield(L, 2, "liquid_sink", phys.liquid_sink);
|
||||
getfloatfield(L, 2, "acceleration_default", phys.acceleration_default);
|
||||
getfloatfield(L, 2, "acceleration_air", phys.acceleration_air);
|
||||
|
||||
if (phys != old)
|
||||
playersao->m_physics_override_sent = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -1717,6 +1710,7 @@ int ObjectRef::l_hud_change(lua_State *L)
|
|||
void *value = nullptr;
|
||||
bool ok = read_hud_change(L, stat, elem, &value);
|
||||
|
||||
// FIXME: only send when actually changed
|
||||
if (ok)
|
||||
getServer(L)->hudChange(player, id, stat, value);
|
||||
|
||||
|
@ -1836,7 +1830,7 @@ int ObjectRef::l_hud_get_hotbar_itemcount(lua_State *L)
|
|||
if (player == nullptr)
|
||||
return 0;
|
||||
|
||||
lua_pushnumber(L, player->getHotbarItemcount());
|
||||
lua_pushinteger(L, player->getHotbarItemcount());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue