]> git.lizzy.rs Git - dragonfireclient.git/blobdiff - src/content_cao.cpp
Prevent attached models from disappearing during parent reload (#4128)
[dragonfireclient.git] / src / content_cao.cpp
index f414b2b9beae7a4dc52464e6395df81fdbeb926c..207a630d7102ec824eb1c5bfd0d3cb1751913215 100644 (file)
@@ -51,7 +51,7 @@ struct ToolCapabilities;
 
 #define PP(x) "("<<(x).X<<","<<(x).Y<<","<<(x).Z<<")"
 
-std::map<u16, ClientActiveObject::Factory> ClientActiveObject::m_types;
+UNORDERED_MAP<u16, ClientActiveObject::Factory> ClientActiveObject::m_types;
 
 SmoothTranslator::SmoothTranslator():
        vect_old(0,0,0),
@@ -566,7 +566,7 @@ GenericCAO::GenericCAO(IGameDef *gamedef, ClientEnvironment *env):
                m_animation_speed(15),
                m_animation_blend(0),
                m_animation_loop(true),
-               m_bone_position(std::map<std::string, core::vector2d<v3f> >()),
+               m_bone_position(UNORDERED_MAP<std::string, core::vector2d<v3f> >()),
                m_attachment_bone(""),
                m_attachment_position(v3f(0,0,0)),
                m_attachment_rotation(v3f(0,0,0)),
@@ -1505,10 +1505,8 @@ void GenericCAO::updateBonePosition()
                return;
 
        m_animated_meshnode->setJointMode(irr::scene::EJUOR_CONTROL); // To write positions to the mesh on render
-       for(std::map<std::string,
-                       core::vector2d<v3f> >::const_iterator ii = m_bone_position.begin();
-                       ii != m_bone_position.end(); ++ii)
-       {
+       for(UNORDERED_MAP<std::string, core::vector2d<v3f> >::const_iterator
+                       ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) {
                std::string bone_name = (*ii).first;
                v3f bone_pos = (*ii).second.X;
                v3f bone_rot = (*ii).second.Y;
@@ -1569,8 +1567,7 @@ void GenericCAO::processMessage(const std::string &data)
        std::istringstream is(data, std::ios::binary);
        // command
        u8 cmd = readU8(is);
-       if(cmd == GENERIC_CMD_SET_PROPERTIES)
-       {
+       if (cmd == GENERIC_CMD_SET_PROPERTIES) {
                m_prop = gob_read_set_properties(is);
 
                m_selection_box = m_prop.collisionbox;
@@ -1589,9 +1586,7 @@ void GenericCAO::processMessage(const std::string &data)
                        m_prop.nametag = m_name;
 
                expireVisuals();
-       }
-       else if(cmd == GENERIC_CMD_UPDATE_POSITION)
-       {
+       } else if (cmd == GENERIC_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.
                m_position = readV3F1000(is);
@@ -1621,12 +1616,10 @@ void GenericCAO::processMessage(const std::string &data)
                        pos_translator.init(m_position);
                }
                updateNodePos();
-       }
-       else if(cmd == GENERIC_CMD_SET_TEXTURE_MOD) {
+       } else if (cmd == GENERIC_CMD_SET_TEXTURE_MOD) {
                std::string mod = deSerializeString(is);
                updateTextures(mod);
-       }
-       else if(cmd == GENERIC_CMD_SET_SPRITE) {
+       } else if (cmd == GENERIC_CMD_SET_SPRITE) {
                v2s16 p = readV2S16(is);
                int num_frames = readU16(is);
                float framelength = readF1000(is);
@@ -1638,8 +1631,7 @@ void GenericCAO::processMessage(const std::string &data)
                m_tx_select_horiz_by_yawpitch = select_horiz_by_yawpitch;
 
                updateTexturePos();
-       }
-       else if(cmd == GENERIC_CMD_SET_PHYSICS_OVERRIDE) {
+       } else if (cmd == GENERIC_CMD_SET_PHYSICS_OVERRIDE) {
                float override_speed = readF1000(is);
                float override_jump = readF1000(is);
                float override_gravity = readF1000(is);
@@ -1657,8 +1649,7 @@ void GenericCAO::processMessage(const std::string &data)
                        player->physics_override_sneak = sneak;
                        player->physics_override_sneak_glitch = sneak_glitch;
                }
-       }
-       else if(cmd == GENERIC_CMD_SET_ANIMATION) {
+       } else if (cmd == GENERIC_CMD_SET_ANIMATION) {
                // TODO: change frames send as v2s32 value
                v2f range = readV2F1000(is);
                if (!m_is_local_player) {
@@ -1692,8 +1683,7 @@ void GenericCAO::processMessage(const std::string &data)
                                        updateAnimation();
                        }
                }
-       }
-       else if(cmd == GENERIC_CMD_SET_BONE_POSITION) {
+       } else if (cmd == GENERIC_CMD_SET_BONE_POSITION) {
                std::string bone = deSerializeString(is);
                v3f position = readV3F1000(is);
                v3f rotation = readV3F1000(is);
@@ -1726,8 +1716,7 @@ void GenericCAO::processMessage(const std::string &data)
                }
 
                updateAttachments();
-       }
-       else if(cmd == GENERIC_CMD_PUNCHED) {
+       } else if (cmd == GENERIC_CMD_PUNCHED) {
                /*s16 damage =*/ readS16(is);
                s16 result_hp = readS16(is);
 
@@ -1755,8 +1744,7 @@ void GenericCAO::processMessage(const std::string &data)
                                updateTextures("^[brighten");
                        }
                }
-       }
-       else if(cmd == GENERIC_CMD_UPDATE_ARMOR_GROUPS) {
+       } else if (cmd == GENERIC_CMD_UPDATE_ARMOR_GROUPS) {
                m_armor_groups.clear();
                int armor_groups_size = readU16(is);
                for(int i=0; i<armor_groups_size; i++)
@@ -1772,6 +1760,19 @@ void GenericCAO::processMessage(const std::string &data)
                if (m_nametag != NULL) {
                        m_nametag->nametag_color = m_prop.nametag_color;
                }
+       } else if (cmd == GENERIC_CMD_SPAWN_INFANT) {
+               u16 child_id = readU16(is);
+               u8 type = readU8(is);
+
+               if (GenericCAO *childobj = m_env->getGenericCAO(child_id)) {
+                       childobj->initialize(deSerializeLongString(is));
+               } else {
+                       m_env->addActiveObject(child_id, type, deSerializeLongString(is));
+               }
+       } else {
+               warningstream << FUNCTION_NAME
+                       << ": unknown command or outdated client \""
+                       << cmd << std::endl;
        }
 }