Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy/src/orxonox/objects/infos/PlayerInfo.cc @ 1945

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

added option "forceCallback" to updateData(…) in Synchronisable to get a callback when synchronizing a variable for the first time (even if it didn't changed)

File size: 4.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 *   Co-authors:
25 *      ...
26 *
27 */
28
29#include "PlayerInfo.h"
30
31#include <OgreSceneManager.h>
32
33#include "core/CoreIncludes.h"
34#include "core/ConfigValueIncludes.h"
35#include "core/XMLPort.h"
36
37#include "network/Host.h"
38
39#include "Settings.h"
40#include "GraphicsEngine.h"
41#include "objects/gametypes/Gametype.h"
42
43namespace orxonox
44{
45    CreateUnloadableFactory(PlayerInfo);
46
47    PlayerInfo::PlayerInfo()
48    {
49        RegisterObject(PlayerInfo);
50
51        this->ping_ = -1;
52        this->bLocalPlayer_ = Settings::isStandalone();
53        this->bLocalPlayer_ = false;
54        this->bHumanPlayer_ = false;
55        this->bFinishedSetup_ = false;
56
57        this->setConfigValues();
58        this->registerVariables();
59
60        COUT(0) << "created PlayerInfo" << std::endl;
61    }
62
63    PlayerInfo::~PlayerInfo()
64    {
65        Gametype* gametype = Gametype::getCurrentGametype();
66        if (gametype)
67            gametype->removePlayer(this);
68    }
69
70    void PlayerInfo::setConfigValues()
71    {
72        SetConfigValue(playerName_, "Player").callback(this, &PlayerInfo::checkName);
73    }
74
75    void PlayerInfo::checkName()
76    {
77std::cout << "# PlayerInfo: checkName: " << this->bLocalPlayer_ << std::endl;
78        if (this->bLocalPlayer_)
79            this->setName(this->playerName_);
80    }
81
82    void PlayerInfo::registerVariables()
83    {
84        this->setObjectMode(network::direction::bidirectional);
85
86        REGISTERSTRING(name_,               network::direction::bidirectional, new network::NetworkCallback<PlayerInfo>(this, &PlayerInfo::changedName));
87        REGISTERDATA(clientID_,             network::direction::toclient,      new network::NetworkCallback<PlayerInfo>(this, &PlayerInfo::checkClientID));
88        REGISTERDATA(ping_,                 network::direction::toclient);
89        REGISTERDATA(bHumanPlayer_,         network::direction::toclient);
90        REGISTERDATA(bFinishedSetup_,       network::direction::bidirectional, new network::NetworkCallback<PlayerInfo>(this, &PlayerInfo::finishedSetup));
91    }
92
93    void PlayerInfo::checkClientID()
94    {
95std::cout << "# PlayerInfo: checkClientID" << std::endl;
96        this->bHumanPlayer_ = true;
97
98        if (this->clientID_ == network::Host::getPlayerID())
99        {
100std::cout << "#             it's the client's ID" << std::endl;
101            this->bLocalPlayer_ = true;
102            this->setName(this->playerName_);
103std::cout << "#             " << this->getName() << std::endl;
104
105            if (!Settings::isClient())
106            {
107std::cout << "#             not client: finish setup" << std::endl;
108                this->bFinishedSetup_ = true;
109                this->finishedSetup();
110            }
111        }
112    }
113
114    void PlayerInfo::finishedSetup()
115    {
116std::cout << "# PlayerInfo: finishedSetup: " << this->bFinishedSetup_ << std::endl;
117        if (Settings::isClient())
118        {
119std::cout << "#             client: set to true" << std::endl;
120            this->bFinishedSetup_ = true;
121        }
122        else if (this->bFinishedSetup_)
123        {
124std::cout << "#             not client but finished: add player" << std::endl;
125            Gametype* gametype = Gametype::getCurrentGametype();
126            if (gametype)
127                gametype->addPlayer(this);
128        }
129        else
130        {
131std::cout << "#             not client and not finished" << std::endl;
132        }
133    }
134}
Note: See TracBrowser for help on using the repository browser.