Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/orxonox/gamestates/GSLevel.cc @ 7870

Last change on this file since 7870 was 7870, checked in by landauf, 13 years ago

added feature: ogre config dialog keeps showing up on startup until the user loads a level the first time.

the reason is: if the user closes the game (or it crashes) before loading a level, there was maybe a problem with the ogre config, so we show the menu again to modify it.
if the user manages to start a level, at least the menu shows correctly, hence he can change the config in the orxonox settings from now on if needed.

  • Property svn:eol-style set to native
File size: 5.4 KB
RevLine 
[1661]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 *      Reto Grieder
24 *   Co-authors:
[1662]25 *      Fabian 'x3n' Landau
[2896]26 *      Benjamin Knecht
[1661]27 *
28 */
29
30#include "GSLevel.h"
31
[5695]32#include <OgreCompositorManager.h>
33
[5855]34#include "util/Clock.h"
[1661]35#include "core/input/InputManager.h"
[3327]36#include "core/input/InputState.h"
[5863]37#include "core/input/KeyBinderManager.h"
[7870]38#include "core/Core.h"
[2896]39#include "core/Game.h"
40#include "core/GameMode.h"
[3370]41#include "core/GUIManager.h"
[3196]42#include "core/Loader.h"
43#include "core/XMLFile.h"
[7284]44#include "core/command/ConsoleCommand.h"
[3196]45
[2087]46#include "LevelManager.h"
[2662]47#include "PlayerManager.h"
[1661]48
49namespace orxonox
50{
[3370]51    DeclareGameState(GSLevel, "level", false, false);
[1934]52
[3370]53    GSLevel::GSLevel(const GameStateInfo& info)
54        : GameState(info)
[2896]55        , gameInputState_(0)
56        , guiMouseOnlyInputState_(0)
57        , guiKeysOnlyInputState_(0)
[5876]58        , startFile_(0)
[6417]59        , bShowIngameGUI_(false)
[1661]60    {
61    }
62
63    GSLevel::~GSLevel()
64    {
65    }
66
[2896]67    void GSLevel::activate()
[1661]68    {
[2896]69        if (GameMode::showsGraphics())
[2087]70        {
[3327]71            gameInputState_ = InputManager::getInstance().createInputState("game");
[6746]72            gameInputState_->setMouseExclusive(TriBool::True);
[5863]73            gameInputState_->setHandler(KeyBinderManager::getInstance().getDefaultAsHandler());
74            KeyBinderManager::getInstance().setToDefault();
[1661]75
[3327]76            guiMouseOnlyInputState_ = InputManager::getInstance().createInputState("guiMouseOnly");
[6746]77            guiMouseOnlyInputState_->setMouseExclusive(TriBool::True);
78            guiMouseOnlyInputState_->setMouseHandler(&GUIManager::getInstance());
[2896]79
[3327]80            guiKeysOnlyInputState_ = InputManager::getInstance().createInputState("guiKeysOnly");
[6746]81            guiKeysOnlyInputState_->setKeyHandler(&GUIManager::getInstance());
[2087]82        }
[1662]83
[2896]84        if (GameMode::isMaster())
[2087]85        {
86            this->loadLevel();
87        }
[1755]88
[2896]89        if (GameMode::showsGraphics())
[2087]90        {
91            // level is loaded: we can start capturing the input
[3327]92            InputManager::getInstance().enterState("game");
[6417]93
[5820]94            // connect the HumanPlayer to the game
[5850]95            PlayerManager::getInstance().clientConnected(0);
[2087]96        }
[2662]97    }
[2087]98
[2896]99    void GSLevel::deactivate()
100    {
[5695]101        if (GameMode::showsGraphics())
102        {
103            // unload all compositors (this is only necessary because we don't yet destroy all resources!)
104            Ogre::CompositorManager::getSingleton().removeAll();
[2896]105
[3327]106            InputManager::getInstance().leaveState("game");
[5820]107        }
[6417]108
[5966]109        // disconnect all HumanPlayers
110        PlayerManager::getInstance().disconnectAllClients();
[1662]111
[2896]112        if (GameMode::isMaster())
[2087]113            this->unloadLevel();
[1662]114
[2896]115        if (GameMode::showsGraphics())
[2087]116        {
[2896]117            gameInputState_->setHandler(0);
118            guiMouseOnlyInputState_->setHandler(0);
119            guiKeysOnlyInputState_->setHandler(0);
[3327]120            InputManager::getInstance().destroyState("game");
[5818]121            InputManager::getInstance().destroyState("guiKeysOnly");
122            InputManager::getInstance().destroyState("guiMouseOnly");
[2087]123        }
[1661]124    }
125
[2896]126    void GSLevel::update(const Clock& time)
[1661]127    {
[5876]128        // Note: Temporarily moved to GSRoot.
[2087]129        //// Call the scene objects
130        //for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it)
131        //    it->tick(time.getDeltaTime() * this->timeFactor_);
[1661]132    }
133
[1670]134    void GSLevel::loadLevel()
135    {
[5922]136        for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ++it)
137            this->staticObjects_.insert(*it);
[6417]138
[1670]139        // call the loader
140        COUT(0) << "Loading level..." << std::endl;
[5876]141        startFile_ = new XMLFile(LevelManager::getInstance().getDefaultLevel());
142        Loader::open(startFile_);
[7870]143
144        Core::getInstance().updateLastLevelTimestamp();
[1670]145    }
146
147    void GSLevel::unloadLevel()
148    {
[5876]149        Loader::unload(startFile_);
150        delete startFile_;
[5922]151
152        COUT(3) << "Unloaded level. Remaining objects:" << std::endl;
153        unsigned int i = 0;
154        for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ++it)
155        {
156            std::set<BaseObject*>::const_iterator find = this->staticObjects_.find(*it);
157            if (find == this->staticObjects_.end())
158            {
[7854]159                COUT(3) << ++i << ": " << it->getIdentifier()->getName() << " (" << *it << "), references: " << it->getReferenceCount() << std::endl;
[5922]160            }
161        }
162        COUT(3) << i << " objects remaining.";
163        if (i == 0)
164            COUT(3) << " Well done!" << std::endl;
165        else
166            COUT(3) << " Try harder!" << std::endl;
[1670]167    }
[1661]168}
Note: See TracBrowser for help on using the repository browser.