Make attached objects visible in 3rd person view
authorest31 <MTest31@outlook.com>
Fri, 19 Jun 2015 22:30:38 +0000 (00:30 +0200)
committerest31 <MTest31@outlook.com>
Sat, 20 Jun 2015 00:59:53 +0000 (02:59 +0200)
src/content_cao.cpp
src/content_cao.h
src/environment.cpp
src/environment.h
src/game.cpp

index 9ee81e63f9dd01df5687d742d0fd1e822b5bdf10..4f1336d281b58ff1b55f4d63da3ba060e029ee15 100644 (file)
@@ -727,6 +727,17 @@ scene::IBillboardSceneNode* GenericCAO::getSpriteSceneNode()
        return m_spritenode;
 }
 
+void GenericCAO::setChildrenVisible(bool toset)
+{
+       for (std::vector<u16>::iterator ci = m_children.begin();
+                       ci != m_children.end(); ci++) {
+               GenericCAO *obj = m_env->getGenericCAO(*ci);
+               if (obj) {
+                       obj->setVisible(toset);
+               }
+       }
+}
+
 void GenericCAO::setAttachments()
 {
        updateAttachments();
@@ -1489,16 +1500,7 @@ void GenericCAO::updateBonePosition()
 void GenericCAO::updateAttachments()
 {
 
-       // localplayer itself can't be attached to localplayer
-       if (!m_is_local_player)
-       {
-               m_attached_to_local = getParent() != NULL && getParent()->isLocalPlayer();
-               // Objects attached to the local player should always be hidden
-               m_is_visible = !m_attached_to_local;
-       }
-
-       if(getParent() == NULL || m_attached_to_local) // Detach or don't attach
-       {
+       if (getParent() == NULL) { // Detach or don't attach
                scene::ISceneNode *node = getSceneNode();
                if (node) {
                        v3f old_position = node->getAbsolutePosition();
@@ -1667,14 +1669,26 @@ void GenericCAO::processMessage(const std::string &data)
                m_bone_position[bone] = core::vector2d<v3f>(position, rotation);
 
                updateBonePosition();
-       }
-       else if(cmd == GENERIC_CMD_SET_ATTACHMENT) {
-               m_env->m_attachements[getId()] = readS16(is);
-               m_children.push_back(m_env->m_attachements[getId()]);
+       } else if (cmd == GENERIC_CMD_SET_ATTACHMENT) {
+               u16 parentID = readS16(is);
+               m_env->m_attachements[getId()] = parentID;
+               GenericCAO *parentobj = m_env->getGenericCAO(parentID);
+
+               if (parentobj) {
+                       parentobj->m_children.push_back(getId());
+               }
+
                m_attachment_bone = deSerializeString(is);
                m_attachment_position = readV3F1000(is);
                m_attachment_rotation = readV3F1000(is);
 
+               // localplayer itself can't be attached to localplayer
+               if (!m_is_local_player) {
+                       m_attached_to_local = getParent() != NULL && getParent()->isLocalPlayer();
+                       // Objects attached to the local player should be hidden by default
+                       m_is_visible = !m_attached_to_local;
+               }
+
                updateAttachments();
        }
        else if(cmd == GENERIC_CMD_PUNCHED) {
index 36245bd3b0cfa74e2bed8aea9fac1a610889c171..813a4125930adec8d0e95cfd0647ad03b178751d 100644 (file)
@@ -162,6 +162,8 @@ public:
                m_is_visible = toset;
        }
 
+       void setChildrenVisible(bool toset);
+
        void setAttachments();
 
        void removeFromScene(bool permanent);
index dc18fd58f8857a2734be3b78ea6a5cc4af06e3bc..7d80619bc4e96bc06503f4c4c7d939e9699efca5 100644 (file)
@@ -2400,6 +2400,15 @@ void ClientEnvironment::addSimpleObject(ClientSimpleObject *simple)
        m_simple_objects.push_back(simple);
 }
 
+GenericCAO* ClientEnvironment::getGenericCAO(u16 id)
+{
+       ClientActiveObject *obj = getActiveObject(id);
+       if (obj && obj->getType() == ACTIVEOBJECT_TYPE_GENERIC)
+               return (GenericCAO*) obj;
+       else
+               return NULL;
+}
+
 ClientActiveObject* ClientEnvironment::getActiveObject(u16 id)
 {
        std::map<u16, ClientActiveObject*>::iterator n;
index a25a12db37c9b3aba4b1e861eb086619841abc8d..983f094092a21188326bbcbba75a0a148d8ff076 100644 (file)
@@ -405,6 +405,8 @@ private:
 #ifndef SERVER
 
 #include "clientobject.h"
+#include "content_cao.h"
+
 class ClientSimpleObject;
 
 /*
@@ -467,6 +469,7 @@ public:
                ActiveObjects
        */
 
+       GenericCAO* getGenericCAO(u16 id);
        ClientActiveObject* getActiveObject(u16 id);
 
        /*
index 903e4f85c58cf5cafd3ffce27454326e993a8459..be4897d756b4e32edd800312e10abd4cb0a6c21a 100644 (file)
@@ -3298,6 +3298,7 @@ void Game::updateCamera(VolatileRunFlags *flags, u32 busy_time,
                camera->toggleCameraMode();
 
                playercao->setVisible(camera->getCameraMode() > CAMERA_MODE_FIRST);
+               playercao->setChildrenVisible(camera->getCameraMode() > CAMERA_MODE_FIRST);
        }
 
        float full_punch_interval = playeritem_toolcap.full_punch_interval;