mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-06 17:41:04 +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
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -103,5 +103,7 @@ private:
|
|||
v3f m_last_sent_rotation;
|
||||
float m_last_sent_position_timer = 0.0f;
|
||||
float m_last_sent_move_precision = 0.0f;
|
||||
std::string m_current_texture_modifier = "";
|
||||
|
||||
std::string m_texture_modifier;
|
||||
bool m_texture_modifier_sent = false;
|
||||
};
|
||||
|
|
|
@ -41,6 +41,8 @@ ServerActiveObject *UnitSAO::getParent() const
|
|||
|
||||
void UnitSAO::setArmorGroups(const ItemGroupList &armor_groups)
|
||||
{
|
||||
if (m_armor_groups == armor_groups)
|
||||
return;
|
||||
m_armor_groups = armor_groups;
|
||||
m_armor_groups_sent = false;
|
||||
}
|
||||
|
@ -53,7 +55,10 @@ const ItemGroupList &UnitSAO::getArmorGroups() const
|
|||
void UnitSAO::setAnimation(
|
||||
v2f frame_range, float frame_speed, float frame_blend, bool frame_loop)
|
||||
{
|
||||
// store these so they can be updated to clients
|
||||
if (std::tie(m_animation_range, m_animation_speed, m_animation_blend,
|
||||
m_animation_loop) ==
|
||||
std::tie(frame_range, frame_speed, frame_blend, frame_loop))
|
||||
return; // no change
|
||||
m_animation_range = frame_range;
|
||||
m_animation_speed = frame_speed;
|
||||
m_animation_blend = frame_blend;
|
||||
|
@ -72,6 +77,8 @@ void UnitSAO::getAnimation(v2f *frame_range, float *frame_speed, float *frame_bl
|
|||
|
||||
void UnitSAO::setAnimationSpeed(float frame_speed)
|
||||
{
|
||||
if (m_animation_speed == frame_speed)
|
||||
return;
|
||||
m_animation_speed = frame_speed;
|
||||
m_animation_speed_sent = false;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue