content_cao: Do not expire visuals when not necessary

fixes #6572
This commit is contained in:
sfan5 2020-05-25 23:36:45 +02:00
parent 34862a6442
commit db7c262ee8
2 changed files with 34 additions and 11 deletions

View File

@ -1457,13 +1457,23 @@ void GenericCAO::updateAttachments()
} }
} }
void GenericCAO::readAOMessageProperties(std::istream &is) bool GenericCAO::visualExpiryRequired(const ObjectProperties &new_) const
{ {
// Reset object properties first const ObjectProperties &old = m_prop;
m_prop = ObjectProperties(); // Ordered to compare primitive types before std::vectors
return old.backface_culling != new_.backface_culling ||
// Then read the whole new stream old.initial_sprite_basepos != new_.initial_sprite_basepos ||
m_prop.deSerialize(is); old.is_visible != new_.is_visible ||
old.mesh != new_.mesh ||
old.nametag != new_.nametag ||
old.nametag_color != new_.nametag_color ||
old.spritediv != new_.spritediv ||
old.use_texture_alpha != new_.use_texture_alpha ||
old.visual != new_.visual ||
old.visual_size != new_.visual_size ||
old.wield_item != new_.wield_item ||
old.colors != new_.colors ||
old.textures != new_.textures;
} }
void GenericCAO::processMessage(const std::string &data) void GenericCAO::processMessage(const std::string &data)
@ -1473,14 +1483,21 @@ void GenericCAO::processMessage(const std::string &data)
// command // command
u8 cmd = readU8(is); u8 cmd = readU8(is);
if (cmd == AO_CMD_SET_PROPERTIES) { if (cmd == AO_CMD_SET_PROPERTIES) {
readAOMessageProperties(is); ObjectProperties newprops;
newprops.deSerialize(is);
// Check what exactly changed
bool expire_visuals = visualExpiryRequired(newprops);
// Apply changes
m_prop = std::move(newprops);
m_selection_box = m_prop.selectionbox; m_selection_box = m_prop.selectionbox;
m_selection_box.MinEdge *= BS; m_selection_box.MinEdge *= BS;
m_selection_box.MaxEdge *= BS; m_selection_box.MaxEdge *= BS;
m_tx_size.X = 1.0 / m_prop.spritediv.X; m_tx_size.X = 1.0f / m_prop.spritediv.X;
m_tx_size.Y = 1.0 / m_prop.spritediv.Y; m_tx_size.Y = 1.0f / m_prop.spritediv.Y;
if(!m_initial_tx_basepos_set){ if(!m_initial_tx_basepos_set){
m_initial_tx_basepos_set = true; m_initial_tx_basepos_set = true;
@ -1500,7 +1517,12 @@ void GenericCAO::processMessage(const std::string &data)
if ((m_is_player && !m_is_local_player) && m_prop.nametag.empty()) if ((m_is_player && !m_is_local_player) && m_prop.nametag.empty())
m_prop.nametag = m_name; m_prop.nametag = m_name;
expireVisuals(); if (expire_visuals) {
expireVisuals();
} else {
infostream << "GenericCAO: properties updated but expiring visuals"
<< " not necessary" << std::endl;
}
} else if (cmd == AO_CMD_UPDATE_POSITION) { } else if (cmd == AO_CMD_UPDATE_POSITION) {
// Not sent by the server if this object is an attachment. // Not sent by the server if this object is an attachment.
// We might however get here if the server notices the object being detached before the client. // We might however get here if the server notices the object being detached before the client.

View File

@ -68,7 +68,6 @@ struct SmoothTranslatorWrappedv3f : SmoothTranslator<v3f>
class GenericCAO : public ClientActiveObject class GenericCAO : public ClientActiveObject
{ {
private: private:
void readAOMessageProperties(std::istream &is);
// Only set at initialization // Only set at initialization
std::string m_name = ""; std::string m_name = "";
bool m_is_player = false; bool m_is_player = false;
@ -131,6 +130,8 @@ private:
// Settings // Settings
bool m_enable_shaders = false; bool m_enable_shaders = false;
bool visualExpiryRequired(const ObjectProperties &newprops) const;
public: public:
GenericCAO(Client *client, ClientEnvironment *env); GenericCAO(Client *client, ClientEnvironment *env);