Skip to content

Commit 40226e5

Browse files
committedJun 20, 2015
Make attached objects visible in 3rd person view
1 parent 3b65a6a commit 40226e5

File tree

5 files changed

+43
-14
lines changed

5 files changed

+43
-14
lines changed
 

‎src/content_cao.cpp

+28-14
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,17 @@ scene::IBillboardSceneNode* GenericCAO::getSpriteSceneNode()
727727
return m_spritenode;
728728
}
729729

730+
void GenericCAO::setChildrenVisible(bool toset)
731+
{
732+
for (std::vector<u16>::iterator ci = m_children.begin();
733+
ci != m_children.end(); ci++) {
734+
GenericCAO *obj = m_env->getGenericCAO(*ci);
735+
if (obj) {
736+
obj->setVisible(toset);
737+
}
738+
}
739+
}
740+
730741
void GenericCAO::setAttachments()
731742
{
732743
updateAttachments();
@@ -1489,16 +1500,7 @@ void GenericCAO::updateBonePosition()
14891500
void GenericCAO::updateAttachments()
14901501
{
14911502

1492-
// localplayer itself can't be attached to localplayer
1493-
if (!m_is_local_player)
1494-
{
1495-
m_attached_to_local = getParent() != NULL && getParent()->isLocalPlayer();
1496-
// Objects attached to the local player should always be hidden
1497-
m_is_visible = !m_attached_to_local;
1498-
}
1499-
1500-
if(getParent() == NULL || m_attached_to_local) // Detach or don't attach
1501-
{
1503+
if (getParent() == NULL) { // Detach or don't attach
15021504
scene::ISceneNode *node = getSceneNode();
15031505
if (node) {
15041506
v3f old_position = node->getAbsolutePosition();
@@ -1667,14 +1669,26 @@ void GenericCAO::processMessage(const std::string &data)
16671669
m_bone_position[bone] = core::vector2d<v3f>(position, rotation);
16681670

16691671
updateBonePosition();
1670-
}
1671-
else if(cmd == GENERIC_CMD_SET_ATTACHMENT) {
1672-
m_env->m_attachements[getId()] = readS16(is);
1673-
m_children.push_back(m_env->m_attachements[getId()]);
1672+
} else if (cmd == GENERIC_CMD_SET_ATTACHMENT) {
1673+
u16 parentID = readS16(is);
1674+
m_env->m_attachements[getId()] = parentID;
1675+
GenericCAO *parentobj = m_env->getGenericCAO(parentID);
1676+
1677+
if (parentobj) {
1678+
parentobj->m_children.push_back(getId());
1679+
}
1680+
16741681
m_attachment_bone = deSerializeString(is);
16751682
m_attachment_position = readV3F1000(is);
16761683
m_attachment_rotation = readV3F1000(is);
16771684

1685+
// localplayer itself can't be attached to localplayer
1686+
if (!m_is_local_player) {
1687+
m_attached_to_local = getParent() != NULL && getParent()->isLocalPlayer();
1688+
// Objects attached to the local player should be hidden by default
1689+
m_is_visible = !m_attached_to_local;
1690+
}
1691+
16781692
updateAttachments();
16791693
}
16801694
else if(cmd == GENERIC_CMD_PUNCHED) {

‎src/content_cao.h

+2
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,8 @@ class GenericCAO : public ClientActiveObject
162162
m_is_visible = toset;
163163
}
164164

165+
void setChildrenVisible(bool toset);
166+
165167
void setAttachments();
166168

167169
void removeFromScene(bool permanent);

‎src/environment.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -2400,6 +2400,15 @@ void ClientEnvironment::addSimpleObject(ClientSimpleObject *simple)
24002400
m_simple_objects.push_back(simple);
24012401
}
24022402

2403+
GenericCAO* ClientEnvironment::getGenericCAO(u16 id)
2404+
{
2405+
ClientActiveObject *obj = getActiveObject(id);
2406+
if (obj && obj->getType() == ACTIVEOBJECT_TYPE_GENERIC)
2407+
return (GenericCAO*) obj;
2408+
else
2409+
return NULL;
2410+
}
2411+
24032412
ClientActiveObject* ClientEnvironment::getActiveObject(u16 id)
24042413
{
24052414
std::map<u16, ClientActiveObject*>::iterator n;

‎src/environment.h

+3
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,8 @@ class ServerEnvironment : public Environment
405405
#ifndef SERVER
406406

407407
#include "clientobject.h"
408+
#include "content_cao.h"
409+
408410
class ClientSimpleObject;
409411

410412
/*
@@ -467,6 +469,7 @@ class ClientEnvironment : public Environment
467469
ActiveObjects
468470
*/
469471

472+
GenericCAO* getGenericCAO(u16 id);
470473
ClientActiveObject* getActiveObject(u16 id);
471474

472475
/*

‎src/game.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -3298,6 +3298,7 @@ void Game::updateCamera(VolatileRunFlags *flags, u32 busy_time,
32983298
camera->toggleCameraMode();
32993299

33003300
playercao->setVisible(camera->getCameraMode() > CAMERA_MODE_FIRST);
3301+
playercao->setChildrenVisible(camera->getCameraMode() > CAMERA_MODE_FIRST);
33013302
}
33023303

33033304
float full_punch_interval = playeritem_toolcap.full_punch_interval;

0 commit comments

Comments
 (0)
Please sign in to comment.