Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy2/src/orxonox/objects/infos/HumanPlayer.cc @ 2662

Last change on this file since 2662 was 2428, checked in by landauf, 16 years ago
  • Moved some variables from Gametype to GametypeInfo (Gametype exists only on the Server while GametypeInfo is synchronized)
  • Created a new HUD-element, GametypeStatus, based on GametypeInfo (the same effect was formerly achieved by using a hack in Spectator and a TextOverlay)
  • HumanController creates a HUD (additionally to the SpaceShips HUD) which includes GametypeStatus and ChatOverlay and even more in the future
  • Property svn:eol-style set to native
File size: 4.8 KB
RevLine 
[2072]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 "HumanPlayer.h"
31
32#include "core/Core.h"
33#include "core/CoreIncludes.h"
34#include "core/ConfigValueIncludes.h"
35#include "network/ClientInformation.h"
36#include "network/Host.h"
37#include "objects/controllers/HumanController.h"
38#include "objects/gametypes/Gametype.h"
[2428]39#include "overlays/OverlayGroup.h"
[2072]40
41namespace orxonox
42{
43    CreateUnloadableFactory(HumanPlayer);
44
45    HumanPlayer::HumanPlayer(BaseObject* creator) : PlayerInfo(creator)
46    {
47        RegisterObject(HumanPlayer);
48
[2171]49        this->server_initialized_ = Core::isMaster();
50        this->client_initialized_ = false;
[2072]51
52        this->bHumanPlayer_ = true;
53        this->defaultController_ = Class(HumanController);
54
55        this->setConfigValues();
56        this->registerVariables();
57    }
58
59    HumanPlayer::~HumanPlayer()
60    {
61    }
62
63    void HumanPlayer::setConfigValues()
64    {
65        SetConfigValue(nick_, "Player").callback(this, &HumanPlayer::configvaluecallback_changednick);
[2428]66        SetConfigValue(hudtemplate_, "defaultHUD").callback(this, &HumanPlayer::configvaluecallback_changedHUDTemplate);
[2072]67    }
68
69    void HumanPlayer::registerVariables()
70    {
[2171]71        REGISTERSTRING(this->synchronize_nick_, direction::toserver, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_changednick));
[2072]72
[2428]73        REGISTERDATA(this->clientID_,           direction::toclient, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_clientIDchanged));
[2171]74        REGISTERDATA(this->server_initialized_, direction::toclient, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_server_initialized));
75        REGISTERDATA(this->client_initialized_, direction::toserver, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_client_initialized));
[2072]76    }
77
78    void HumanPlayer::configvaluecallback_changednick()
79    {
80        if (this->isLocalPlayer())
81        {
82            this->synchronize_nick_ = this->nick_;
83
84            if (Core::isMaster())
85                this->setName(this->nick_);
86        }
87    }
88
[2428]89    void HumanPlayer::configvaluecallback_changedHUDTemplate()
90    {
91        this->changedController();
92    }
93
[2072]94    void HumanPlayer::networkcallback_changednick()
95    {
96        this->setName(this->synchronize_nick_);
97    }
98
99    void HumanPlayer::networkcallback_clientIDchanged()
100    {
[2171]101        if (this->clientID_ == Host::getPlayerID())
[2072]102        {
103            this->bLocalPlayer_ = true;
104            this->synchronize_nick_ = this->nick_;
[2171]105            this->client_initialized_ = true;
[2072]106
107            if (!Core::isMaster())
[2171]108                this->setObjectMode(direction::bidirectional);
[2072]109            else
110                this->setName(this->nick_);
111
112            this->createController();
113        }
114    }
115
[2171]116    void HumanPlayer::networkcallback_server_initialized()
[2072]117    {
[2171]118        this->client_initialized_ = true;
[2072]119    }
120
[2171]121    void HumanPlayer::networkcallback_client_initialized()
[2072]122    {
123        if (this->getGametype())
124            this->getGametype()->playerEntered(this);
125    }
126
[2171]127    bool HumanPlayer::isInitialized() const
[2072]128    {
[2171]129        return (this->server_initialized_ && this->client_initialized_);
[2072]130    }
131
132    float HumanPlayer::getPing() const
133    {
[2171]134        return ClientInformation::findClient(this->getClientID())->getRTT();
[2072]135    }
136
137    float HumanPlayer::getPacketLossRatio() const
138    {
[2171]139        return ClientInformation::findClient(this->getClientID())->getPacketLoss();
[2072]140    }
141
142    void HumanPlayer::setClientID(unsigned int clientID)
143    {
144        this->clientID_ = clientID;
145        this->networkcallback_clientIDchanged();
146    }
[2428]147
148    void HumanPlayer::changedController()
149    {
150        if (this->getController())
151        {
152            this->getController()->setHUDTemplate(this->hudtemplate_);
153
154            if (this->getController() && this->getController()->getHUD())
155                this->getController()->getHUD()->setOwner(this->getControllableEntity());
156        }
157    }
[2072]158}
Note: See TracBrowser for help on using the repository browser.