Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7284 was 7284, checked in by landauf, 14 years ago

merged consolecommands3 branch back to trunk.

note: the console command interface has changed completely, but the documentation is not yet up to date. just copy an existing command and change it to your needs, it's pretty self-explanatory. also the include files related to console commands are now located in core/command/. in the game it should work exactly like before, except for some changes in the auto-completion.

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