Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make attached objects visible in 3rd person view
  • Loading branch information
est31 committed Jun 20, 2015
1 parent 3b65a6a commit 40226e5
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 14 deletions.
42 changes: 28 additions & 14 deletions src/content_cao.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 2 additions & 0 deletions src/content_cao.h
Expand Up @@ -162,6 +162,8 @@ class GenericCAO : public ClientActiveObject
m_is_visible = toset;
}

void setChildrenVisible(bool toset);

void setAttachments();

void removeFromScene(bool permanent);
Expand Down
9 changes: 9 additions & 0 deletions src/environment.cpp
Expand Up @@ -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;
Expand Down
3 changes: 3 additions & 0 deletions src/environment.h
Expand Up @@ -405,6 +405,8 @@ class ServerEnvironment : public Environment
#ifndef SERVER

#include "clientobject.h"
#include "content_cao.h"

class ClientSimpleObject;

/*
Expand Down Expand Up @@ -467,6 +469,7 @@ class ClientEnvironment : public Environment
ActiveObjects
*/

GenericCAO* getGenericCAO(u16 id);
ClientActiveObject* getActiveObject(u16 id);

/*
Expand Down
1 change: 1 addition & 0 deletions src/game.cpp
Expand Up @@ -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;
Expand Down

0 comments on commit 40226e5

Please sign in to comment.