1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-06 17:41:04 +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

@ -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