Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/doc/src/orxonox/LevelManager.cc @ 7346

Last change on this file since 7346 was 7335, checked in by rgrieder, 14 years ago

Added separate page for a commandline argument reference.
It's not too useful, but better than nothing.

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