Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/objecthierarchy/src/orxonox/LevelManager.cc @ 2019

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

many changes, most important: BaseObject takes now a pointer to it's creator which is needed to build a level hierarchy (with different scenes)

File size: 3.7 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
31#include "LevelManager.h"
32
33#include "core/CoreIncludes.h"
34
35#include "objects/infos/Level.h"
36#include "objects/infos/HumanPlayer.h"
37
38namespace orxonox
39{
40    LevelManager::LevelManager()
41    {
42        RegisterRootObject(LevelManager);
43
44        this->getConnectedClients();
45    }
46
47    LevelManager& LevelManager::getInstance()
48    {
49        static LevelManager instance;
50        return instance;
51    }
52
53    void LevelManager::requestActivity(Level* level)
54    {
55        this->levels_s.push_back(level);
56        if (this->levels_s.size() == 1)
57            this->activateNextLevel();
58    }
59
60    void LevelManager::releaseActivity(Level* level)
61    {
62        if (this->levels_s.size() > 0)
63        {
64            if (this->levels_s.front() == level)
65            {
66                level->setActive(false);
67                this->levels_s.pop_front();
68                this->activateNextLevel();
69            }
70            else
71            {
72                for (std::list<Level*>::iterator it = this->levels_s.begin(); it != this->levels_s.end(); ++it)
73                    if ((*it) == level)
74                        this->levels_s.erase(it);
75            }
76        }
77    }
78
79    Level* LevelManager::getActiveLevel()
80    {
81        if (this->levels_s.size() > 0)
82            return this->levels_s.front();
83        else
84            return 0;
85    }
86
87    void LevelManager::activateNextLevel()
88    {
89        if (this->levels_s.size() > 0)
90        {
91            this->levels_s.front()->setActive(true);
92            for (std::map<unsigned int, PlayerInfo*>::iterator it = this->clients_.begin(); it != this->clients_.end(); ++it)
93                this->levels_s.front()->playerEntered(it->second);
94        }
95    }
96
97
98    void LevelManager::clientConnected(unsigned int clientID)
99    {
100        COUT(0) << "client connected" << std::endl;
101
102        // create new HumanPlayer instance
103        HumanPlayer* player = new HumanPlayer(0);
104        player->setClientID(clientID);
105
106        // add to clients-map
107        assert(!this->clients_[clientID]);
108        this->clients_[clientID] = player;
109    }
110
111    void LevelManager::clientDisconnected(unsigned int clientID)
112    {
113        COUT(0) << "client disconnected" << std::endl;
114
115        // remove from clients-map
116        PlayerInfo* player = this->clients_[clientID];
117        this->clients_.erase(clientID);
118
119        // delete PlayerInfo instance
120        if (player)
121            delete player;
122    }
123
124
125    PlayerInfo* LevelManager::getClient(unsigned int clientID) const
126    {
127        std::map<unsigned int, PlayerInfo*>::const_iterator it = this->clients_.find(clientID);
128        if (it != this->clients_.end())
129            return it->second;
130        else
131            return 0;
132    }
133}
Note: See TracBrowser for help on using the repository browser.