Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2023 was 2023, checked in by rgrieder, 16 years ago
  • Added support for dedicated server. Could not network test it yet, client still segfaults me.
  • Also kicked GraphicsEngine::levelSceneManager_, there are only the statistic methods left.
  • GSDedicated also derives from GSLevel, but GSLevel is not anymore a real GameState.
  • CameraHandler and LevelManager get created in GSLevel now.
File size: 3.9 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::singletonRef_s = 0;
41
42    LevelManager::LevelManager()
43    {
44        RegisterRootObject(LevelManager);
45
46        assert(singletonRef_s == 0);
47        singletonRef_s = this;
48
49        this->getConnectedClients();
50    }
51
52    LevelManager::~LevelManager()
53    {
54        assert(singletonRef_s != 0);
55        singletonRef_s = 0;
56    }
57
58    void LevelManager::requestActivity(Level* level)
59    {
60        this->levels_s.push_back(level);
61        if (this->levels_s.size() == 1)
62            this->activateNextLevel();
63    }
64
65    void LevelManager::releaseActivity(Level* level)
66    {
67        if (this->levels_s.size() > 0)
68        {
69            if (this->levels_s.front() == level)
70            {
71                level->setActive(false);
72                this->levels_s.pop_front();
73                this->activateNextLevel();
74            }
75            else
76            {
77                for (std::list<Level*>::iterator it = this->levels_s.begin(); it != this->levels_s.end(); ++it)
78                    if ((*it) == level)
79                        this->levels_s.erase(it);
80            }
81        }
82    }
83
84    Level* LevelManager::getActiveLevel()
85    {
86        if (this->levels_s.size() > 0)
87            return this->levels_s.front();
88        else
89            return 0;
90    }
91
92    void LevelManager::activateNextLevel()
93    {
94        if (this->levels_s.size() > 0)
95        {
96            this->levels_s.front()->setActive(true);
97            for (std::map<unsigned int, PlayerInfo*>::iterator it = this->clients_.begin(); it != this->clients_.end(); ++it)
98                this->levels_s.front()->playerEntered(it->second);
99        }
100    }
101
102
103    void LevelManager::clientConnected(unsigned int clientID)
104    {
105        COUT(0) << "client connected" << std::endl;
106
107        // create new HumanPlayer instance
108        HumanPlayer* player = new HumanPlayer(0);
109        player->setClientID(clientID);
110
111        // add to clients-map
112        assert(!this->clients_[clientID]);
113        this->clients_[clientID] = player;
114    }
115
116    void LevelManager::clientDisconnected(unsigned int clientID)
117    {
118        COUT(0) << "client disconnected" << std::endl;
119
120        // remove from clients-map
121        PlayerInfo* player = this->clients_[clientID];
122        this->clients_.erase(clientID);
123
124        // delete PlayerInfo instance
125        if (player)
126            delete player;
127    }
128
129
130    PlayerInfo* LevelManager::getClient(unsigned int clientID) const
131    {
132        std::map<unsigned int, PlayerInfo*>::const_iterator it = this->clients_.find(clientID);
133        if (it != this->clients_.end())
134            return it->second;
135        else
136            return 0;
137    }
138}
Note: See TracBrowser for help on using the repository browser.