Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
content_cao: Do not expire visuals when not necessary
fixes #6572
  • Loading branch information
sfan5 committed May 29, 2020
1 parent 34862a6 commit db7c262
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
42 changes: 32 additions & 10 deletions src/client/content_cao.cpp
Expand Up @@ -1457,13 +1457,23 @@ void GenericCAO::updateAttachments()
}
}

void GenericCAO::readAOMessageProperties(std::istream &is)
bool GenericCAO::visualExpiryRequired(const ObjectProperties &new_) const
{
// Reset object properties first
m_prop = ObjectProperties();

// Then read the whole new stream
m_prop.deSerialize(is);
const ObjectProperties &old = m_prop;
// Ordered to compare primitive types before std::vectors
return old.backface_culling != new_.backface_culling ||
old.initial_sprite_basepos != new_.initial_sprite_basepos ||
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)
Expand All @@ -1473,14 +1483,21 @@ void GenericCAO::processMessage(const std::string &data)
// command
u8 cmd = readU8(is);
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.MinEdge *= BS;
m_selection_box.MaxEdge *= BS;

m_tx_size.X = 1.0 / m_prop.spritediv.X;
m_tx_size.Y = 1.0 / m_prop.spritediv.Y;
m_tx_size.X = 1.0f / m_prop.spritediv.X;
m_tx_size.Y = 1.0f / m_prop.spritediv.Y;

if(!m_initial_tx_basepos_set){
m_initial_tx_basepos_set = true;
Expand All @@ -1500,7 +1517,12 @@ void GenericCAO::processMessage(const std::string &data)
if ((m_is_player && !m_is_local_player) && m_prop.nametag.empty())
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) {
// 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.
Expand Down
3 changes: 2 additions & 1 deletion src/client/content_cao.h
Expand Up @@ -68,7 +68,6 @@ struct SmoothTranslatorWrappedv3f : SmoothTranslator<v3f>
class GenericCAO : public ClientActiveObject
{
private:
void readAOMessageProperties(std::istream &is);
// Only set at initialization
std::string m_name = "";
bool m_is_player = false;
Expand Down Expand Up @@ -131,6 +130,8 @@ class GenericCAO : public ClientActiveObject
// Settings
bool m_enable_shaders = false;

bool visualExpiryRequired(const ObjectProperties &newprops) const;

public:
GenericCAO(Client *client, ClientEnvironment *env);

Expand Down

0 comments on commit db7c262

Please sign in to comment.