1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-11 17:51:04 +00:00

Fix some common SAO methods to not generate useless update packets

This commit is contained in:
sfan5 2024-02-29 14:56:13 +01:00
parent 585ca90ae0
commit c524c52baa
11 changed files with 160 additions and 85 deletions

View file

@ -134,12 +134,16 @@ void LuaEntitySAO::dispatchScriptDeactivate(bool removal)
void LuaEntitySAO::step(float dtime, bool send_recommended)
{
if(!m_properties_sent)
{
if (!m_properties_sent) {
m_properties_sent = true;
std::string str = getPropertyPacket();
// create message and add to list
m_messages_out.emplace(getId(), true, str);
m_messages_out.emplace(getId(), true, std::move(str));
}
if (!m_texture_modifier_sent) {
m_texture_modifier_sent = true;
m_messages_out.emplace(getId(), true, generateSetTextureModCommand());
}
// If attached, check that our parent is still there. If it isn't, detach.
@ -444,24 +448,24 @@ v3f LuaEntitySAO::getAcceleration()
void LuaEntitySAO::setTextureMod(const std::string &mod)
{
m_current_texture_modifier = mod;
// create message and add to list
m_messages_out.emplace(getId(), true, generateSetTextureModCommand());
if (m_texture_modifier == mod)
return;
m_texture_modifier = mod;
m_texture_modifier_sent = false;
}
std::string LuaEntitySAO::getTextureMod() const
{
return m_current_texture_modifier;
return m_texture_modifier;
}
std::string LuaEntitySAO::generateSetTextureModCommand() const
{
std::ostringstream os(std::ios::binary);
// command
writeU8(os, AO_CMD_SET_TEXTURE_MOD);
// parameters
os << serializeString16(m_current_texture_modifier);
os << serializeString16(m_texture_modifier);
return os.str();
}