Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

merged output branch back to trunk.

Changes:

  • you have to include util/Output.h instead of util/Debug.h
  • COUT(x) is now called orxout(level)
  • output levels are now defined by an enum instead of numbers. see util/Output.h for the definition
  • it's possible to use output contexts with orxout(level, context). see util/Output.h for some common contexts. you can define more contexts
  • you must use 'endl' at the end of an output message, '\n' does not flush the message

Output levels:

  • instead of COUT(0) use orxout()
  • instead of COUT(1) use orxout(user_error) or orxout(internal_error)
  • instead of COUT(2) use orxout(user_warning) or orxout(internal_warning)
  • instead of COUT(3) use orxout(user_status/user_info) or orxout(internal_status/internal_info)
  • instead of COUT(4) use orxout(verbose)
  • instead of COUT(5) use orxout(verbose_more)
  • instead of COUT(6) use orxout(verbose_ultra)

Guidelines:

  • user_* levels are for the user, visible in the console and the log-file
  • internal_* levels are for developers, visible in the log-file
  • verbose_* levels are for debugging, only visible if the context of the output is activated

Usage in C++:

  • orxout() << "message" << endl;
  • orxout(level) << "message" << endl;
  • orxout(level, context) << "message" << endl;

Usage in Lua:

  • orxout("message")
  • orxout(orxonox.level.levelname, "message")
  • orxout(orxonox.level.levelname, "context", "message")

Usage in Tcl (and in the in-game-console):

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