Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 8770 was 8729, checked in by rgrieder, 13 years ago

Merged unity_build branch back to trunk.

Features:

  • Implemented fully automatic build units to speed up compilation if requested
  • Added DOUT macro for quick debug output
  • Activated text colouring in the POSIX IOConsole
  • DeclareToluaInterface is not necessary anymore

Improvements:

  • Output levels now change appropriately when switch back and forth from dev mode
  • Log level for the file output is now also correct during startup
  • Removed some header file dependencies in core and tools to speed up compilation

no more file for command line options

  • Improved util::tribool by adapting some concepts from boost::tribool

Regressions:

  • It is not possible anymore to specify command line arguments in an extra file because we've got config values for that purpose.
  • Property svn:eol-style set to native
File size: 6.9 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"
[8079]48#include "GSRoot.h"
[1661]49
50namespace orxonox
51{
[3370]52    DeclareGameState(GSLevel, "level", false, false);
[1934]53
[7876]54    static const std::string __CC_startMainMenu_name = "startMainMenu";
55    static const std::string __CC_changeGame_name = "changeGame";
56
57    SetConsoleCommand(__CC_startMainMenu_name, &GSLevel::startMainMenu).deactivate();
[8079]58    SetConsoleCommand(__CC_changeGame_name, &GSLevel::changeGame).defaultValues("").deactivate();
[7876]59
[3370]60    GSLevel::GSLevel(const GameStateInfo& info)
61        : GameState(info)
[2896]62        , gameInputState_(0)
63        , guiMouseOnlyInputState_(0)
64        , guiKeysOnlyInputState_(0)
[5876]65        , startFile_(0)
[6417]66        , bShowIngameGUI_(false)
[1661]67    {
68    }
69
70    GSLevel::~GSLevel()
71    {
72    }
73
[2896]74    void GSLevel::activate()
[1661]75    {
[2896]76        if (GameMode::showsGraphics())
[2087]77        {
[3327]78            gameInputState_ = InputManager::getInstance().createInputState("game");
[8729]79            gameInputState_->setMouseExclusive(true);
[5863]80            gameInputState_->setHandler(KeyBinderManager::getInstance().getDefaultAsHandler());
81            KeyBinderManager::getInstance().setToDefault();
[1661]82
[3327]83            guiMouseOnlyInputState_ = InputManager::getInstance().createInputState("guiMouseOnly");
[8729]84            guiMouseOnlyInputState_->setMouseExclusive(true);
[6746]85            guiMouseOnlyInputState_->setMouseHandler(&GUIManager::getInstance());
[2896]86
[3327]87            guiKeysOnlyInputState_ = InputManager::getInstance().createInputState("guiKeysOnly");
[6746]88            guiKeysOnlyInputState_->setKeyHandler(&GUIManager::getInstance());
[2087]89        }
[1662]90
[2896]91        if (GameMode::isMaster())
[2087]92        {
93            this->loadLevel();
94        }
[1755]95
[2896]96        if (GameMode::showsGraphics())
[2087]97        {
98            // level is loaded: we can start capturing the input
[3327]99            InputManager::getInstance().enterState("game");
[6417]100
[5820]101            // connect the HumanPlayer to the game
[5850]102            PlayerManager::getInstance().clientConnected(0);
[7876]103
104            ModifyConsoleCommand(__CC_startMainMenu_name).activate();
[2087]105        }
[7876]106
107        if (GameMode::isStandalone())
108            ModifyConsoleCommand(__CC_changeGame_name).activate();
[2662]109    }
[2087]110
[2896]111    void GSLevel::deactivate()
112    {
[5695]113        if (GameMode::showsGraphics())
[3327]114            InputManager::getInstance().leaveState("game");
[6417]115
[5966]116        // disconnect all HumanPlayers
117        PlayerManager::getInstance().disconnectAllClients();
[1662]118
[2896]119        if (GameMode::isMaster())
[2087]120            this->unloadLevel();
[1662]121
[2896]122        if (GameMode::showsGraphics())
[2087]123        {
[7879]124#if OGRE_VERSION < 0x010700
125            // unload all compositors (this is only necessary because we don't yet destroy all resources!)
126            Ogre::CompositorManager::getSingleton().removeAll();
127#endif
128
[2896]129            gameInputState_->setHandler(0);
130            guiMouseOnlyInputState_->setHandler(0);
131            guiKeysOnlyInputState_->setHandler(0);
[3327]132            InputManager::getInstance().destroyState("game");
[5818]133            InputManager::getInstance().destroyState("guiKeysOnly");
134            InputManager::getInstance().destroyState("guiMouseOnly");
[7876]135
136            ModifyConsoleCommand(__CC_startMainMenu_name  ).deactivate();
[2087]137        }
[7876]138
139        if (GameMode::isStandalone())
140            ModifyConsoleCommand(__CC_changeGame_name).deactivate();
[1661]141    }
142
[2896]143    void GSLevel::update(const Clock& time)
[1661]144    {
[5876]145        // Note: Temporarily moved to GSRoot.
[2087]146        //// Call the scene objects
147        //for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it)
148        //    it->tick(time.getDeltaTime() * this->timeFactor_);
[1661]149    }
150
[1670]151    void GSLevel::loadLevel()
152    {
[5922]153        for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ++it)
154            this->staticObjects_.insert(*it);
[6417]155
[1670]156        // call the loader
157        COUT(0) << "Loading level..." << std::endl;
[5876]158        startFile_ = new XMLFile(LevelManager::getInstance().getDefaultLevel());
[8079]159        bool loaded = Loader::open(startFile_);
[7870]160
161        Core::getInstance().updateLastLevelTimestamp();
[8079]162        if(!loaded)
163            GSRoot::delayedStartMainMenu();
[1670]164    }
165
166    void GSLevel::unloadLevel()
167    {
[5876]168        Loader::unload(startFile_);
169        delete startFile_;
[5922]170
171        COUT(3) << "Unloaded level. Remaining objects:" << std::endl;
172        unsigned int i = 0;
173        for (ObjectList<BaseObject>::iterator it = ObjectList<BaseObject>::begin(); it != ObjectList<BaseObject>::end(); ++it)
174        {
175            std::set<BaseObject*>::const_iterator find = this->staticObjects_.find(*it);
176            if (find == this->staticObjects_.end())
177            {
[7854]178                COUT(3) << ++i << ": " << it->getIdentifier()->getName() << " (" << *it << "), references: " << it->getReferenceCount() << std::endl;
[5922]179            }
180        }
181        COUT(3) << i << " objects remaining.";
182        if (i == 0)
183            COUT(3) << " Well done!" << std::endl;
184        else
185            COUT(3) << " Try harder!" << std::endl;
[1670]186    }
[7876]187
188    /**
189    @brief
190        Starts the MainMenu.
191    */
192    /*static*/ void GSLevel::startMainMenu(void)
193    {
194        // HACK
195        Game::getInstance().popState();
196        Game::getInstance().popState();
197    }
198
199    /**
200    @brief
201        Terminates the current game and starts a new game.
202    @param level
203        The filename of the level to be started.
204    */
205    /*static*/ void GSLevel::changeGame(const std::string& level)
206    {
[8079]207        if(level != "")
[7876]208            LevelManager::getInstance().setDefaultLevel(level);
209
210        // HACK
211        Game::getInstance().popState();
212        Game::getInstance().popState();
213        Game::getInstance().requestStates("standalone, level");
214    }
[1661]215}
Note: See TracBrowser for help on using the repository browser.