Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/pickups2/src/orxonox/objects/infos/HumanPlayer.cc @ 2293

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

merged objecthierarchy branch back to trunk

  • Property svn:eol-style set to native
File size: 4.2 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 "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
48        this->server_ready_ = Core::isMaster();
49        this->client_ready_ = false;
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    {
69        REGISTERSTRING(this->synchronize_nick_, network::direction::toserver, new network::NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_changednick));
70
71        REGISTERDATA(this->clientID_,     network::direction::toclient, new network::NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_clientIDchanged));
72        REGISTERDATA(this->server_ready_, network::direction::toclient, new network::NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_server_ready));
73        REGISTERDATA(this->client_ready_, network::direction::toserver, new network::NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_client_ready));
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    {
94        if (this->clientID_ == network::Host::getPlayerID())
95        {
96            this->bLocalPlayer_ = true;
97            this->synchronize_nick_ = this->nick_;
98            this->client_ready_ = true;
99
100            if (!Core::isMaster())
101                this->setObjectMode(network::direction::bidirectional);
102            else
103                this->setName(this->nick_);
104
105            this->createController();
106        }
107    }
108
109    void HumanPlayer::networkcallback_server_ready()
110    {
111        this->client_ready_ = true;
112    }
113
114    void HumanPlayer::networkcallback_client_ready()
115    {
116        if (this->getGametype())
117            this->getGametype()->playerEntered(this);
118    }
119
120    bool HumanPlayer::isReady() const
121    {
122        return (this->server_ready_ && this->client_ready_);
123    }
124
125    float HumanPlayer::getPing() const
126    {
127        return network::ClientInformation::findClient(this->getClientID())->getRTT();
128    }
129
130    float HumanPlayer::getPacketLossRatio() const
131    {
132        return network::ClientInformation::findClient(this->getClientID())->getPacketLoss();
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.