Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy/src/orxonox/objects/worldentities/WorldEntity.cc @ 1940

Last change on this file since 1940 was 1940, checked in by landauf, 16 years ago

did some first (and very unfinished) steps to deal with different players on server and client

File size: 4.6 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Fabian 'x3n' Landau
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "WorldEntity.h"
30
31#include <OgreSceneManager.h>
32
33#include "core/CoreIncludes.h"
34#include "core/XMLPort.h"
35
36#include "GraphicsEngine.h"
37
38namespace orxonox
39{
40    WorldEntity::WorldEntity()
41    {
42        RegisterObject(WorldEntity);
43
44        this->node_ = GraphicsEngine::getInstance().getLevelSceneManager()->createSceneNode();
45        this->parent_ = 0;
46        this->parentID_ = (unsigned int)-1;
47
48        this->registerVariables();
49    }
50
51    WorldEntity::~WorldEntity()
52    {
53        if (this->isInitialized())
54        {
55            this->node_->detachAllObjects();
56            GraphicsEngine::getInstance().getLevelSceneManager()->destroySceneNode(this->node_->getName());
57        }
58    }
59
60
61    void WorldEntity::XMLPort(Element& xmlelement, XMLPort::Mode mode)
62    {
63        SUPER(WorldEntity, XMLPort, xmlelement, mode);
64
65        XMLPortParamTemplate(WorldEntity, "position", setPosition, getPosition, xmlelement, mode, const Vector3&);
66        XMLPortParamTemplate(WorldEntity, "orientation", setOrientation, getOrientation, xmlelement, mode, const Quaternion&);
67        XMLPortParamLoadOnly(WorldEntity, "lookat", lookAt_xmlport, xmlelement, mode);
68        XMLPortParamLoadOnly(WorldEntity, "direction", setDirection_xmlport, xmlelement, mode);
69        XMLPortParamLoadOnly(WorldEntity, "yaw", yaw_xmlport, xmlelement, mode);
70        XMLPortParamLoadOnly(WorldEntity, "pitch", pitch_xmlport, xmlelement, mode);
71        XMLPortParamLoadOnly(WorldEntity, "roll", roll_xmlport, xmlelement, mode);
72        XMLPortParamTemplate(WorldEntity, "scale3D", setScale3D, getScale3D, xmlelement, mode, const Vector3&);
73        XMLPortParam(WorldEntity, "scale", setScale, getScale, xmlelement, mode);
74
75        XMLPortObject(WorldEntity, WorldEntity, "attached", attach, getAttachedObject, xmlelement, mode);
76    }
77
78    void WorldEntity::registerVariables()
79    {
80        REGISTERDATA(this->bActive_,  network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::changedActivity));
81        REGISTERDATA(this->bVisible_, network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::changedVisibility));
82
83        REGISTERDATA(this->getScale3D().x, network::direction::toclient);
84        REGISTERDATA(this->getScale3D().y, network::direction::toclient);
85        REGISTERDATA(this->getScale3D().z, network::direction::toclient);
86
87        REGISTERDATA(this->parentID_, network::direction::toclient, new network::NetworkCallback<WorldEntity>(this, &WorldEntity::updateParent));
88    }
89
90    void WorldEntity::updateParent()
91    {
92        WorldEntity* parent = dynamic_cast<WorldEntity*>(Synchronisable::getSynchronisable(this->parentID_));
93        if (parent)
94            this->attachToParent(parent);
95    }
96
97    void WorldEntity::attach(WorldEntity* object)
98    {
99        if (object->getParent())
100            object->detachFromParent();
101
102        this->node_->addChild(object->node_);
103        this->children_.insert(object);
104        object->parent_ = this;
105        object->parentID_ = this->getObjectID();
106    }
107
108    void WorldEntity::detach(WorldEntity* object)
109    {
110        this->node_->removeChild(object->node_);
111        this->children_.erase(object);
112        object->parent_ = 0;
113        object->parentID_ = (unsigned int)-1;
114    }
115
116    WorldEntity* WorldEntity::getAttachedObject(unsigned int index) const
117    {
118        unsigned int i;
119        for (std::set<WorldEntity*>::const_iterator it = this->children_.begin(); it != this->children_.end(); ++it)
120        {
121            if (i == index)
122                return (*it);
123            ++i;
124        }
125        return 0;
126    }
127}
Note: See TracBrowser for help on using the repository browser.