1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

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)
This commit is contained in:
SmallJoker 2020-06-04 19:31:46 +02:00 committed by GitHub
parent 0e698e63b3
commit c1e01bc638
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 110 additions and 115 deletions

View file

@ -123,12 +123,11 @@ void LuaEntitySAO::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,0,0);
m_attachment_rotation = v3f(0,0,0);
if (m_attachment_parent_id && !isAttached()) {
// This is handled when objects are removed from the map
warningstream << "LuaEntitySAO::step() id=" << m_id <<
" is attached to nonexistent parent. This is a bug." << std::endl;
clearParentAttachment();
sendPosition(false, true);
}
@ -217,43 +216,7 @@ void LuaEntitySAO::step(float dtime, bool send_recommended)
}
}
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_animation_sent) {
m_animation_sent = true;
std::string str = generateUpdateAnimationCommand();
// create message and add to list
m_messages_out.emplace(getId(), true, str);
}
if (!m_animation_speed_sent) {
m_animation_speed_sent = true;
std::string str = generateUpdateAnimationSpeedCommand();
// create message and add to list
m_messages_out.emplace(getId(), true, str);
}
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;
std::string str = generateUpdateAttachmentCommand();
// create message and add to list
m_messages_out.emplace(getId(), true, str);
}
sendOutdatedData();
}
std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version)
@ -273,20 +236,19 @@ std::string LuaEntitySAO::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
int message_count = 4 + 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++;
// TODO after a protocol bump: only send the object initialization data
// to older clients (superfluous since this message exists)
msg_os << serializeLongString(obj->generateUpdateInfantCommand(*ii, protocol_version));
msg_os << serializeLongString(obj->generateUpdateInfantCommand(
id, protocol_version));
}
}
@ -294,7 +256,8 @@ std::string LuaEntitySAO::getClientInitializationData(u16 protocol_version)
message_count++;
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();