Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/network/src/orxonox/objects/infos/HumanPlayer.cc @ 2518

Last change on this file since 2518 was 2245, checked in by scheusso, 16 years ago

most coding is done, still testing now
types should get transfered in platform independent formats now

  • 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_initialized_ = Core::isMaster();
49        this->client_initialized_ = 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        registerVariable(this->synchronize_nick_, variableDirection::toserver, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_changednick));
70
71        registerVariable(this->clientID_,     variableDirection::toclient, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_clientIDchanged));
72        registerVariable(this->server_initialized_, variableDirection::toclient, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_server_initialized));
73        registerVariable(this->client_initialized_, variableDirection::toserver, new NetworkCallback<HumanPlayer>(this, &HumanPlayer::networkcallback_client_initialized));
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_ == Host::getPlayerID())
95        {
96            this->bLocalPlayer_ = true;
97            this->synchronize_nick_ = this->nick_;
98            this->client_initialized_ = true;
99
100            if (!Core::isMaster())
101                this->setObjectMode(objectDirection::bidirectional);
102            else
103                this->setName(this->nick_);
104
105            this->createController();
106        }
107    }
108
109    void HumanPlayer::networkcallback_server_initialized()
110    {
111        this->client_initialized_ = true;
112    }
113
114    void HumanPlayer::networkcallback_client_initialized()
115    {
116        if (this->getGametype())
117            this->getGametype()->playerEntered(this);
118    }
119
120    bool HumanPlayer::isInitialized() const
121    {
122        return (this->server_initialized_ && this->client_initialized_);
123    }
124
125    float HumanPlayer::getPing() const
126    {
127        return ClientInformation::findClient(this->getClientID())->getRTT();
128    }
129
130    float HumanPlayer::getPacketLossRatio() const
131    {
132        return 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.