1
0
mirror of https://github.com/luanti-org/luanti.git synced 2025-10-12 16:15:20 +02:00

Rework object attachment handling to fix bugs (#14825)

This commit is contained in:
sfan5
2024-08-12 15:32:18 +02:00
committed by GitHub
parent a0e33ba9ea
commit 85e717fcd1
17 changed files with 245 additions and 172 deletions

View File

@@ -465,7 +465,7 @@ scene::IAnimatedMeshSceneNode *GenericCAO::getAnimatedMeshSceneNode() const
void GenericCAO::setChildrenVisible(bool toset)
{
for (u16 cao_id : m_attachment_child_ids) {
for (object_t cao_id : m_attachment_child_ids) {
GenericCAO *obj = m_env->getGenericCAO(cao_id);
if (obj) {
// Check if the entity is forced to appear in first person.
@@ -474,10 +474,10 @@ void GenericCAO::setChildrenVisible(bool toset)
}
}
void GenericCAO::setAttachment(int parent_id, const std::string &bone,
void GenericCAO::setAttachment(object_t parent_id, const std::string &bone,
v3f position, v3f rotation, bool force_visible)
{
int old_parent = m_attachment_parent_id;
const auto old_parent = m_attachment_parent_id;
m_attachment_parent_id = parent_id;
m_attachment_bone = bone;
m_attachment_position = position;
@@ -509,7 +509,7 @@ void GenericCAO::setAttachment(int parent_id, const std::string &bone,
}
}
void GenericCAO::getAttachment(int *parent_id, std::string *bone, v3f *position,
void GenericCAO::getAttachment(object_t *parent_id, std::string *bone, v3f *position,
v3f *rotation, bool *force_visible) const
{
*parent_id = m_attachment_parent_id;
@@ -523,29 +523,21 @@ void GenericCAO::clearChildAttachments()
{
// Cannot use for-loop here: setAttachment() modifies 'm_attachment_child_ids'!
while (!m_attachment_child_ids.empty()) {
int child_id = *m_attachment_child_ids.begin();
const auto child_id = *m_attachment_child_ids.begin();
if (ClientActiveObject *child = m_env->getActiveObject(child_id))
child->setAttachment(0, "", v3f(), v3f(), false);
removeAttachmentChild(child_id);
if (auto *child = m_env->getActiveObject(child_id))
child->clearParentAttachment();
else
removeAttachmentChild(child_id);
}
}
void GenericCAO::clearParentAttachment()
{
if (m_attachment_parent_id)
setAttachment(0, "", m_attachment_position, m_attachment_rotation, false);
else
setAttachment(0, "", v3f(), v3f(), false);
}
void GenericCAO::addAttachmentChild(int child_id)
void GenericCAO::addAttachmentChild(object_t child_id)
{
m_attachment_child_ids.insert(child_id);
}
void GenericCAO::removeAttachmentChild(int child_id)
void GenericCAO::removeAttachmentChild(object_t child_id)
{
m_attachment_child_ids.erase(child_id);
}