Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/objects/infos/HumanPlayer.cc @ 2604

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

merged revisions 2111-2170 from objecthierarchy branch back to trunk.

  • Property svn:eol-style set to native
File size: 4.2 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"
39
40namespace orxonox
41{
42    CreateUnloadableFactory(HumanPlayer);
43
44    HumanPlayer::HumanPlayer(BaseObject* creator) : PlayerInfo(creator)
45    {
46        RegisterObject(HumanPlayer);
47
[2171]48        this->server_initialized_ = Core::isMaster();
49        this->client_initialized_ = false;
[2072]50
51        this->bHumanPlayer_ = true;
52        this->defaultController_ = Class(HumanController);
53
54        this->setConfigValues();
55        this->registerVariables();
56    }
57
58    HumanPlayer::~HumanPlayer()
59    {
60    }
61
62    void HumanPlayer::setConfigValues()
63    {
64        SetConfigValue(nick_, "Player").callback(this, &HumanPlayer::configvaluecallback_changednick);
65    }
66
67    void HumanPlayer::registerVariables()
68    {
[2171]69        REGISTERSTRING(this->synchronize_nick_, direction::toserver, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_changednick));
[2072]70
[2171]71        REGISTERDATA(this->clientID_,     direction::toclient, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_clientIDchanged));
72        REGISTERDATA(this->server_initialized_, direction::toclient, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_server_initialized));
73        REGISTERDATA(this->client_initialized_, direction::toserver, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_client_initialized));
[2072]74    }
75
76    void HumanPlayer::configvaluecallback_changednick()
77    {
78        if (this->isLocalPlayer())
79        {
80            this->synchronize_nick_ = this->nick_;
81
82            if (Core::isMaster())
83                this->setName(this->nick_);
84        }
85    }
86
87    void HumanPlayer::networkcallback_changednick()
88    {
89        this->setName(this->synchronize_nick_);
90    }
91
92    void HumanPlayer::networkcallback_clientIDchanged()
93    {
[2171]94        if (this->clientID_ == Host::getPlayerID())
[2072]95        {
96            this->bLocalPlayer_ = true;
97            this->synchronize_nick_ = this->nick_;
[2171]98            this->client_initialized_ = true;
[2072]99
100            if (!Core::isMaster())
[2171]101                this->setObjectMode(direction::bidirectional);
[2072]102            else
103                this->setName(this->nick_);
104
105            this->createController();
106        }
107    }
108
[2171]109    void HumanPlayer::networkcallback_server_initialized()
[2072]110    {
[2171]111        this->client_initialized_ = true;
[2072]112    }
113
[2171]114    void HumanPlayer::networkcallback_client_initialized()
[2072]115    {
116        if (this->getGametype())
117            this->getGametype()->playerEntered(this);
118    }
119
[2171]120    bool HumanPlayer::isInitialized() const
[2072]121    {
[2171]122        return (this->server_initialized_ && this->client_initialized_);
[2072]123    }
124
125    float HumanPlayer::getPing() const
126    {
[2171]127        return ClientInformation::findClient(this->getClientID())->getRTT();
[2072]128    }
129
130    float HumanPlayer::getPacketLossRatio() const
131    {
[2171]132        return ClientInformation::findClient(this->getClientID())->getPacketLoss();
[2072]133    }
134
135    void HumanPlayer::setClientID(unsigned int clientID)
136    {
137        this->clientID_ = clientID;
138        this->networkcallback_clientIDchanged();
139    }
140}
Note: See TracBrowser for help on using the repository browser.