Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Changed the way setPosition, setVelocity, setOrientation and setAngularVelocity is handled in MobileEntity and upwards.
This allows to introduce a lost feature: Position of an enemy ship on the client can't be set anymore at all (local changes were allowed before).

  • Property svn:eol-style set to native
File size: 3.3 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 *      Reto Grieder
25 *   Co-authors:
26 *      ...
27 *
28 */
29
30#include "OrxonoxStableHeaders.h"
31#include "MovableEntity.h"
32
33#include "core/CoreIncludes.h"
34#include "core/XMLPort.h"
35#include "core/Executor.h"
36#include "tools/Timer.h"
37
38namespace orxonox
39{
40    static const float MAX_RESYNCHRONIZE_TIME = 3.0f;
41    static const float CONTINUOUS_SYNCHRONIZATION_TIME = 10.0f;
42
43    CreateFactory(MovableEntity);
44
45    MovableEntity::MovableEntity(BaseObject* creator) : MobileEntity(creator)
46    {
47        RegisterObject(MovableEntity);
48
49        this->overwrite_position_    = Vector3::ZERO;
50        this->overwrite_orientation_ = Quaternion::IDENTITY;
51
52        // Resynchronise every few seconds because we only work with velocities (no positions)
53        continuousResynchroTimer_ = new Timer<MovableEntity>(CONTINUOUS_SYNCHRONIZATION_TIME + rnd(-1, 1),
54                true, this, createExecutor(createFunctor(&MovableEntity::resynchronize)), false);
55
56        this->registerVariables();
57    }
58
59    MovableEntity::~MovableEntity()
60    {
61        if (this->isInitialized())
62            delete this->continuousResynchroTimer_;
63    }
64
65    void MovableEntity::XMLPort(Element& xmlelement, XMLPort::Mode mode)
66    {
67        SUPER(MovableEntity, XMLPort, xmlelement, mode);
68    }
69
70    void MovableEntity::registerVariables()
71    {
72        REGISTERDATA(this->linearVelocity_,        network::direction::toclient, new network::NetworkCallback<MovableEntity>(this, &MovableEntity::processLinearVelocity));
73        REGISTERDATA(this->angularVelocity_,       network::direction::toclient, new network::NetworkCallback<MovableEntity>(this, &MovableEntity::processAngularVelocity));
74
75        REGISTERDATA(this->overwrite_position_,    network::direction::toclient, new network::NetworkCallback<MovableEntity>(this, &MovableEntity::overwritePosition));
76        REGISTERDATA(this->overwrite_orientation_, network::direction::toclient, new network::NetworkCallback<MovableEntity>(this, &MovableEntity::overwriteOrientation));
77    }
78
79    void MovableEntity::clientConnected(unsigned int clientID)
80    {
81        new Timer<MovableEntity>(rnd() * MAX_RESYNCHRONIZE_TIME, false, this, createExecutor(createFunctor(&MovableEntity::resynchronize)), true);
82    }
83
84    void MovableEntity::clientDisconnected(unsigned int clientID)
85    {
86    }
87
88    void MovableEntity::resynchronize()
89    {
90        this->overwrite_position_ = this->getPosition();
91        this->overwrite_orientation_ = this->getOrientation();
92    }
93}
Note: See TracBrowser for help on using the repository browser.