Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/core5/src/orxonox/LevelManager.cc @ 5836

Last change on this file since 5836 was 5836, checked in by rgrieder, 15 years ago

Extracted path related parts of Core into a new PathConfig class. This should decrease the mess in Core.cc a little bit.

  • Property svn:eol-style set to native
File size: 4.4 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 "LevelManager.h"
30
31#include <map>
32#include <OgreResourceGroupManager.h>
33
34#include "core/CommandLine.h"
35#include "core/ConfigValueIncludes.h"
36#include "core/CoreIncludes.h"
37#include "core/Loader.h"
38#include "PlayerManager.h"
39#include "Level.h"
40
41namespace orxonox
42{
43    SetCommandLineArgument(level, "").shortcut("l").information("Default level file (overrides LevelManager::defaultLevelName_ configValue)");
44
45    LevelManager* LevelManager::singletonPtr_s = 0;
46
47    LevelManager::LevelManager()
48    {
49        RegisterRootObject(LevelManager);
50        this->setConfigValues();
51
52        // check override
53        if (!CommandLine::getArgument("level")->hasDefaultValue())
54        {
55            ModifyConfigValue(defaultLevelName_, tset, CommandLine::getValue("level").getString());
56        }
57    }
58
59    LevelManager::~LevelManager()
60    {
61    }
62
63    void LevelManager::setConfigValues()
64    {
65        SetConfigValue(defaultLevelName_, "presentation_dm.oxw")
66            .description("Sets the preselection of the level in the main menu.");
67    }
68
69    void LevelManager::requestActivity(Level* level)
70    {
71        this->levels_s.push_back(level);
72        if (this->levels_s.size() == 1)
73            this->activateNextLevel();
74    }
75
76    void LevelManager::releaseActivity(Level* level)
77    {
78        if (this->levels_s.size() > 0)
79        {
80            if (this->levels_s.front() == level)
81            {
82                level->setActive(false);
83                this->levels_s.pop_front();
84                this->activateNextLevel();
85            }
86            else
87            {
88                for (std::list<Level*>::iterator it = this->levels_s.begin(); it != this->levels_s.end(); ++it)
89                    if ((*it) == level)
90                        this->levels_s.erase(it);
91            }
92        }
93    }
94
95    Level* LevelManager::getActiveLevel()
96    {
97        if (this->levels_s.size() > 0)
98            return this->levels_s.front();
99        else
100            return 0;
101    }
102
103    void LevelManager::activateNextLevel()
104    {
105        if (this->levels_s.size() > 0)
106        {
107            this->levels_s.front()->setActive(true);
108            for (std::map<unsigned int, PlayerInfo*>::const_iterator it = PlayerManager::getInstance().getClients().begin(); it != PlayerManager::getInstance().getClients().end(); ++it)
109                this->levels_s.front()->playerEntered(it->second);
110        }
111    }
112
113    void LevelManager::setDefaultLevel(const std::string& levelName)
114    {
115        ModifyConfigValue(defaultLevelName_, set, levelName);
116    }
117
118    const std::string& LevelManager::getDefaultLevel() const
119    {
120        return defaultLevelName_;
121    }
122
123    std::string LevelManager::getAvailableLevelListItem(unsigned int index) const
124    {
125        if (index >= availableLevels_.size())
126            return std::string();
127        else
128            return availableLevels_[index];
129    }
130
131    void LevelManager::compileAvailableLevelList()
132    {
133        availableLevels_.clear();
134
135        availableLevels_ = *Ogre::ResourceGroupManager::getSingleton().findResourceNames(
136            Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, "*.oxw");
137
138        for (std::vector<std::string>::iterator it = availableLevels_.begin(); it != availableLevels_.end();)
139            if (it->find("old/") == 0)
140                it = availableLevels_.erase(it);
141            else
142            {
143                size_t pos = it->find(".oxw");
144                *it = it->substr(0, pos);
145                ++it;
146            }
147    }
148}
Note: See TracBrowser for help on using the repository browser.