Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/LevelManager.cc @ 5726

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

Merged resource2 branch back to trunk.

IMPORTANT NOTE:
Upon this merge you need to specifically call your data directory "data_extern" when checking it out (when you don't provide a name, it will be just called 'trunk').
The new CMake variable is EXTERNAL_DATA_DIRECTORY. DATA_DIRECTORY now points to the one the source part of the repository.
UPDATE YOUR DATA DIRECTORY AS WELL!!!

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