Clean up CAO nametag handling and remove deprecated AO_CMD
authorsfan5 <sfan5@live.de>
Tue, 26 May 2020 14:05:06 +0000 (16:05 +0200)
committersfan5 <sfan5@live.de>
Fri, 29 May 2020 20:54:50 +0000 (22:54 +0200)
AO_CMD_UPDATE_NAMETAG_ATTRIBUTES was deprecated in
9eee3c3f465c071bb9908749cf48be3c131a1bdf (0.4.14)

src/activeobject.h
src/client/content_cao.cpp
src/client/content_cao.h
src/server/player_sao.cpp
src/server/serveractiveobject.cpp

index c83243f865715a210a052a3a6fd07d259e975e47..85e160d100b7ef104dad3e0822ba59e7a2c3e55a 100644 (file)
@@ -66,7 +66,8 @@ enum ActiveObjectCommand {
        AO_CMD_SET_BONE_POSITION,
        AO_CMD_ATTACH_TO,
        AO_CMD_SET_PHYSICS_OVERRIDE,
-       AO_CMD_UPDATE_NAMETAG_ATTRIBUTES,
+       AO_CMD_OBSOLETE1,
+       // ^ UPDATE_NAMETAG_ATTRIBUTES deprecated since 0.4.14, removed in 5.3.0
        AO_CMD_SPAWN_INFANT,
        AO_CMD_SET_ANIMATION_SPEED
 };
index 947c1a279321c6ed7722b32a48b8eb5feb3f7206..dde31899b933e589d2aca80a5e0b888ee85ab81d 100644 (file)
@@ -776,15 +776,7 @@ void GenericCAO::addToScene(ITextureSource *tsrc)
        if (node && m_matrixnode)
                node->setParent(m_matrixnode);
 
-       if (node && !m_prop.nametag.empty() && !m_is_local_player) {
-               // Add nametag
-               v3f pos;
-               pos.Y = m_prop.selectionbox.MaxEdge.Y + 0.3f;
-               m_nametag = m_client->getCamera()->addNametag(node,
-                       m_prop.nametag, m_prop.nametag_color,
-                       pos);
-       }
-
+       updateNametag();
        updateNodePos();
        updateAnimation();
        updateBonePosition();
@@ -872,6 +864,38 @@ v3s16 GenericCAO::getLightPosition()
        return floatToInt(m_position, BS);
 }
 
+void GenericCAO::updateNametag()
+{
+       if (m_is_local_player) // No nametag for local player
+               return;
+
+       if (m_prop.nametag.empty()) {
+               // Delete nametag
+               if (m_nametag) {
+                       m_client->getCamera()->removeNametag(m_nametag);
+                       m_nametag = nullptr;
+               }
+               return;
+       }
+
+       scene::ISceneNode *node = getSceneNode();
+       if (!node)
+               return;
+
+       v3f pos;
+       pos.Y = m_prop.selectionbox.MaxEdge.Y + 0.3f;
+       if (!m_nametag) {
+               // Add nametag
+               m_nametag = m_client->getCamera()->addNametag(node,
+                       m_prop.nametag, m_prop.nametag_color, pos);
+       } else {
+               // Update nametag
+               m_nametag->nametag_text = m_prop.nametag;
+               m_nametag->nametag_color = m_prop.nametag_color;
+               m_nametag->nametag_pos = pos;
+       }
+}
+
 void GenericCAO::updateNodePos()
 {
        if (getParent() != NULL)
@@ -1465,8 +1489,6 @@ bool GenericCAO::visualExpiryRequired(const ObjectProperties &new_) const
                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 ||
@@ -1516,6 +1538,7 @@ void GenericCAO::processMessage(const std::string &data)
 
                if ((m_is_player && !m_is_local_player) && m_prop.nametag.empty())
                        m_prop.nametag = m_name;
+               updateNametag();
 
                if (expire_visuals) {
                        expireVisuals();
@@ -1694,22 +1717,14 @@ void GenericCAO::processMessage(const std::string &data)
                        int rating = readS16(is);
                        m_armor_groups[name] = rating;
                }
-       } else if (cmd == AO_CMD_UPDATE_NAMETAG_ATTRIBUTES) {
-               // Deprecated, for backwards compatibility only.
-               readU8(is); // version
-               m_prop.nametag_color = readARGB8(is);
-               if (m_nametag != NULL) {
-                       m_nametag->nametag_color = m_prop.nametag_color;
-                       v3f pos;
-                       pos.Y = m_prop.collisionbox.MaxEdge.Y + 0.3f;
-                       m_nametag->nametag_pos = pos;
-               }
        } else if (cmd == AO_CMD_SPAWN_INFANT) {
                u16 child_id = readU16(is);
                u8 type = readU8(is); // maybe this will be useful later
                (void)type;
 
                addAttachmentChild(child_id);
+       } else if (cmd == AO_CMD_OBSOLETE1) {
+               // Don't do anything and also don't log a warning
        } else {
                warningstream << FUNCTION_NAME
                        << ": unknown command or outdated client \""
index 03a3552048a7d14f30a845544d1a4c92218f0c7e..8e2a13ea8929d57a2235d7befd9fe2294d4a17d3 100644 (file)
@@ -244,6 +244,8 @@ public:
 
        v3s16 getLightPosition();
 
+       void updateNametag();
+
        void updateNodePos();
 
        void step(float dtime, ClientEnvironment *env);
index 3ea3536e25b54d8784d263a3a7edd23fde5a05d9..9ea0743f764604616b568884674161fc84ed085b 100644 (file)
@@ -127,9 +127,7 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version)
        }
        msg_os << serializeLongString(generateUpdateAttachmentCommand()); // 4
        msg_os << serializeLongString(generateUpdatePhysicsOverrideCommand()); // 5
-       // (AO_CMD_UPDATE_NAMETAG_ATTRIBUTES) : Deprecated, for backwards compatibility only.
-       msg_os << serializeLongString(generateUpdateNametagAttributesCommand(m_prop.nametag_color)); // 6
-       int message_count = 6 + m_bone_position.size();
+       int message_count = 5 + m_bone_position.size();
        for (std::unordered_set<int>::const_iterator ii = m_attachment_child_ids.begin();
                        ii != m_attachment_child_ids.end(); ++ii) {
                if (ServerActiveObject *obj = m_env->getActiveObject(*ii)) {
index fdcb13bd890605e9fa498e2a0cd4b5b152f8f025..dbf25e3bc5895a35d7a63d46b52fb0441f0a807e 100644 (file)
@@ -61,21 +61,10 @@ std::string ServerActiveObject::generateUpdateInfantCommand(u16 infant_id, u16 p
        return os.str();
 }
 
-std::string ServerActiveObject::generateUpdateNametagAttributesCommand(const video::SColor &color) const
-{
-       std::ostringstream os(std::ios::binary);
-       // command
-       writeU8(os, AO_CMD_UPDATE_NAMETAG_ATTRIBUTES);
-       // parameters
-       writeU8(os, 1); // version for forward compatibility
-       writeARGB8(os, color);
-       return os.str();
-}
-
 void ServerActiveObject::dumpAOMessagesToQueue(std::queue<ActiveObjectMessage> &queue)
 {
        while (!m_messages_out.empty()) {
                queue.push(std::move(m_messages_out.front()));
                m_messages_out.pop();
        }
-}
\ No newline at end of file
+}