Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/physics/src/orxonox/objects/worldentities/MovableEntity.cc @ 2408

Last change on this file since 2408 was 2408, checked in by rgrieder, 15 years ago

Renamed MovableEntity to MobileEntity and LinearEntity to MovableEntity.

  • Property svn:eol-style set to native
File size: 3.5 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 "OrxonoxStableHeaders.h"
30#include "MovableEntity.h"
31
32#include "core/CoreIncludes.h"
33#include "core/XMLPort.h"
34#include "core/Executor.h"
35#include "tools/Timer.h"
36
37namespace orxonox
38{
39    static const float MAX_RESYNCHRONIZE_TIME = 3.0f;
40
41    CreateFactory(MovableEntity);
42
43    MovableEntity::MovableEntity(BaseObject* creator) : MobileEntity(creator)
44    {
45        RegisterObject(MovableEntity);
46
47        this->overwrite_position_    = Vector3::ZERO;
48        this->overwrite_orientation_ = Quaternion::IDENTITY;
49
50        this->registerVariables();
51    }
52
53    MovableEntity::~MovableEntity()
54    {
55    }
56
57    void MovableEntity::XMLPort(Element& xmlelement, XMLPort::Mode mode)
58    {
59        SUPER(MovableEntity, XMLPort, xmlelement, mode);
60    }
61
62    void MovableEntity::registerVariables()
63    {
64        REGISTERDATA(this->linearVelocity_,        network::direction::toclient, new network::NetworkCallback<MovableEntity>(this, &MovableEntity::processLinearVelocity));
65        REGISTERDATA(this->angularVelocity_,       network::direction::toclient, new network::NetworkCallback<MovableEntity>(this, &MovableEntity::processAngularVelocity));
66
67        REGISTERDATA(this->overwrite_position_,    network::direction::toclient, new network::NetworkCallback<MovableEntity>(this, &MovableEntity::overwritePosition));
68        REGISTERDATA(this->overwrite_orientation_, network::direction::toclient, new network::NetworkCallback<MovableEntity>(this, &MovableEntity::overwriteOrientation));
69    }
70
71    void MovableEntity::tick(float dt)
72    {
73        MobileEntity::tick(dt);
74
75        if (this->isActive())
76        {
77        }
78    }
79
80    void MovableEntity::overwritePosition()
81    {
82        this->setPosition(this->overwrite_position_);
83    }
84
85    void MovableEntity::overwriteOrientation()
86    {
87        this->setOrientation(this->overwrite_orientation_);
88    }
89
90    void MovableEntity::clientConnected(unsigned int clientID)
91    {
92        resynchronize();
93        new Timer<MovableEntity>(rnd() * MAX_RESYNCHRONIZE_TIME, true, this, createExecutor(createFunctor(&MovableEntity::resynchronize)), false);
94    }
95
96    void MovableEntity::clientDisconnected(unsigned int clientID)
97    {
98    }
99
100    void MovableEntity::resynchronize()
101    {
102        positionChanged(false);
103        orientationChanged(false);
104    }
105
106    void MovableEntity::positionChanged(bool bContinuous)
107    {
108        if (!bContinuous)
109            this->overwrite_position_ = this->getPosition();
110    }
111
112    void MovableEntity::orientationChanged(bool bContinuous)
113    {
114        if (!bContinuous)
115            this->overwrite_orientation_ = this->getOrientation();
116    }
117}
Note: See TracBrowser for help on using the repository browser.