From 81c2370c8b1a66a279a5ff450c78caf5dfef77bf Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Wed, 2 Oct 2019 19:11:27 +0200 Subject: Attachments: Fix attachments to temporary removed objects (#8989) Does not clear the parent's attachment information when the child is deleted locally. Either it was removed permanently, or just temporary - we don't know, but it's up to the server to send a *detach from child" packet for the parent. --- src/client/clientenvironment.cpp | 17 +++++++++++++++++ src/client/clientenvironment.h | 5 +---- src/client/content_cao.cpp | 19 ++++++++++++++----- src/client/content_cao.h | 5 +++++ 4 files changed, 37 insertions(+), 9 deletions(-) (limited to 'src/client') diff --git a/src/client/clientenvironment.cpp b/src/client/clientenvironment.cpp index e1b20ec84..5eb033302 100644 --- a/src/client/clientenvironment.cpp +++ b/src/client/clientenvironment.cpp @@ -402,6 +402,23 @@ void ClientEnvironment::addActiveObject(u16 id, u8 type, } } + +void ClientEnvironment::removeActiveObject(u16 id) +{ + // Get current attachment childs to detach them visually + std::unordered_set attachment_childs; + if (auto *obj = getActiveObject(id)) + attachment_childs = obj->getAttachmentChildIds(); + + m_ao_manager.removeObject(id); + + // Perform a proper detach in Irrlicht + for (auto c_id : attachment_childs) { + if (ClientActiveObject *child = getActiveObject(c_id)) + child->updateAttachments(); + } +} + void ClientEnvironment::processActiveObjectMessage(u16 id, const std::string &data) { ClientActiveObject *obj = getActiveObject(id); diff --git a/src/client/clientenvironment.h b/src/client/clientenvironment.h index f182b5951..864496a41 100644 --- a/src/client/clientenvironment.h +++ b/src/client/clientenvironment.h @@ -104,10 +104,7 @@ public: u16 addActiveObject(ClientActiveObject *object); void addActiveObject(u16 id, u8 type, const std::string &init_data); - void removeActiveObject(u16 id) - { - m_ao_manager.removeObject(id); - } + void removeActiveObject(u16 id); void processActiveObjectMessage(u16 id, const std::string &data); diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index d7ab8e945..716468402 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -523,7 +523,9 @@ void GenericCAO::removeFromScene(bool permanent) // Should be true when removing the object permanently // and false when refreshing (eg: updating visuals) if (m_env && permanent) { - clearChildAttachments(); + // The client does not know whether this object does re-appear to + // a later time, thus do not clear child attachments. + clearParentAttachment(); } @@ -1330,10 +1332,17 @@ void GenericCAO::updateAttachments() m_attached_to_local = parent && parent->isLocalPlayer(); - if (!parent && m_attachment_parent_id) { - //m_is_visible = false; maybe later. needs better handling - return; - } + /* + Following cases exist: + m_attachment_parent_id == 0 && !parent + This object is not attached + m_attachment_parent_id != 0 && parent + This object is attached + m_attachment_parent_id != 0 && !parent + This object will be attached as soon the parent is known + m_attachment_parent_id == 0 && parent + Impossible case + */ if (!parent) { // Detach or don't attach if (m_matrixnode) { diff --git a/src/client/content_cao.h b/src/client/content_cao.h index 3a071101f..2c2d11077 100644 --- a/src/client/content_cao.h +++ b/src/client/content_cao.h @@ -156,6 +156,11 @@ public: const v3f getPosition() const; + void setPosition(const v3f &pos) + { + pos_translator.val_current = pos; + } + inline const v3f &getRotation() const { return m_rotation; } const bool isImmortal(); -- cgit v1.2.3