diff options
author | SmallJoker <SmallJoker@users.noreply.github.com> | 2020-06-04 19:31:46 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-04 19:31:46 +0200 |
commit | c1e01bc638637efa788b5698238a465406bc3f5e (patch) | |
tree | b4e3abad6b2a51f41e28bc76cacc75002b37c324 /src/server/player_sao.cpp | |
parent | 0e698e63b3bc27551fda9bd4e66f72501413b4e6 (diff) | |
download | minetest-c1e01bc638637efa788b5698238a465406bc3f5e.tar.gz minetest-c1e01bc638637efa788b5698238a465406bc3f5e.tar.bz2 minetest-c1e01bc638637efa788b5698238a465406bc3f5e.zip |
Move shared parameters sending to UnitSAO (#9968)
Better header sorting by topic
Make UnitSAO-specific parameters private
Skip redundant recursive entity sending code (since ~5.2.0)
Diffstat (limited to 'src/server/player_sao.cpp')
-rw-r--r-- | src/server/player_sao.cpp | 57 |
1 files changed, 16 insertions, 41 deletions
diff --git a/src/server/player_sao.cpp b/src/server/player_sao.cpp index 9ea0743f7..67efed210 100644 --- a/src/server/player_sao.cpp +++ b/src/server/player_sao.cpp @@ -120,24 +120,26 @@ std::string PlayerSAO::getClientInitializationData(u16 protocol_version) msg_os << serializeLongString(getPropertyPacket()); // message 1 msg_os << serializeLongString(generateUpdateArmorGroupsCommand()); // 2 msg_os << serializeLongString(generateUpdateAnimationCommand()); // 3 - for (std::unordered_map<std::string, core::vector2d<v3f>>::const_iterator - ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) { - msg_os << serializeLongString(generateUpdateBonePositionCommand((*ii).first, - (*ii).second.X, (*ii).second.Y)); // m_bone_position.size + for (const auto &bone_pos : m_bone_position) { + msg_os << serializeLongString(generateUpdateBonePositionCommand( + bone_pos.first, bone_pos.second.X, bone_pos.second.Y)); // m_bone_position.size } msg_os << serializeLongString(generateUpdateAttachmentCommand()); // 4 msg_os << serializeLongString(generateUpdatePhysicsOverrideCommand()); // 5 + 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)) { + + for (const auto &id : getAttachmentChildIds()) { + if (ServerActiveObject *obj = m_env->getActiveObject(id)) { message_count++; - msg_os << serializeLongString(obj->generateUpdateInfantCommand(*ii, protocol_version)); + msg_os << serializeLongString(obj->generateUpdateInfantCommand( + id, protocol_version)); } } writeU8(os, message_count); - os.write(msg_os.str().c_str(), msg_os.str().size()); + std::string serialized = msg_os.str(); + os.write(serialized.c_str(), serialized.size()); // return result return os.str(); @@ -227,10 +229,10 @@ void PlayerSAO::step(float dtime, bool send_recommended) // If attached, check that our parent is still there. If it isn't, detach. if (m_attachment_parent_id && !isAttached()) { - m_attachment_parent_id = 0; - m_attachment_bone = ""; - m_attachment_position = v3f(0.0f, 0.0f, 0.0f); - m_attachment_rotation = v3f(0.0f, 0.0f, 0.0f); + // This is handled when objects are removed from the map + warningstream << "PlayerSAO::step() id=" << m_id << + " is attached to nonexistent parent. This is a bug." << std::endl; + clearParentAttachment(); setBasePosition(m_last_good_position); m_env->getGameDef()->SendMovePlayer(m_peer_id); } @@ -290,40 +292,13 @@ void PlayerSAO::step(float dtime, bool send_recommended) m_messages_out.emplace(getId(), false, str); } - if (!m_armor_groups_sent) { - m_armor_groups_sent = true; - // create message and add to list - m_messages_out.emplace(getId(), true, generateUpdateArmorGroupsCommand()); - } - if (!m_physics_override_sent) { m_physics_override_sent = true; // create message and add to list m_messages_out.emplace(getId(), true, generateUpdatePhysicsOverrideCommand()); } - if (!m_animation_sent) { - m_animation_sent = true; - // create message and add to list - m_messages_out.emplace(getId(), true, generateUpdateAnimationCommand()); - } - - if (!m_bone_position_sent) { - m_bone_position_sent = true; - for (std::unordered_map<std::string, core::vector2d<v3f>>::const_iterator - ii = m_bone_position.begin(); ii != m_bone_position.end(); ++ii) { - std::string str = generateUpdateBonePositionCommand((*ii).first, - (*ii).second.X, (*ii).second.Y); - // create message and add to list - m_messages_out.emplace(getId(), true, str); - } - } - - if (!m_attachment_sent) { - m_attachment_sent = true; - // create message and add to list - m_messages_out.emplace(getId(), true, generateUpdateAttachmentCommand()); - } + sendOutdatedData(); } std::string PlayerSAO::generateUpdatePhysicsOverrideCommand() const |