Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 24, 2009, 11:02:42 AM (15 years ago)
Author:
rgrieder
Message:

Reverted trunk again. We might want to find a way to delete these revisions again (x3n's changes are still available as diff in the commit mails).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/libraries/core/Game.cc

    r5774 r5781  
    4545#include "Clock.h"
    4646#include "CommandLine.h"
     47#include "ConsoleCommand.h"
    4748#include "Core.h"
    4849#include "CoreIncludes.h"
    4950#include "ConfigValueIncludes.h"
     51#include "GameMode.h"
    5052#include "GameState.h"
    5153
    5254namespace orxonox
    5355{
     56    static void stop_game()
     57        { Game::getInstance().stop(); }
     58    SetConsoleCommandShortcutExternAlias(stop_game, "exit");
     59
    5460    std::map<std::string, GameStateInfo> Game::gameStateDeclarations_s;
    5561    Game* Game::singletonPtr_s = 0;
     
    500506    void Game::loadGraphics()
    501507    {
     508        if (!GameMode::bShowsGraphics_s)
     509        {
     510            core_->loadGraphics();
     511            Loki::ScopeGuard graphicsUnloader = Loki::MakeObjGuard(*this, &Game::unloadGraphics);
     512            GameMode::bShowsGraphics_s = true;
     513
     514            // Construct all the GameStates that require graphics
     515            for (std::map<std::string, GameStateInfo>::const_iterator it = gameStateDeclarations_s.begin();
     516                it != gameStateDeclarations_s.end(); ++it)
     517            {
     518                if (it->second.bGraphicsMode)
     519                {
     520                    // Game state loading failure is serious --> don't catch
     521                    shared_ptr<GameState> gameState = GameStateFactory::fabricate(it->second);
     522                    if (!constructedStates_.insert(std::make_pair(
     523                        it->second.stateName, gameState)).second)
     524                        assert(false); // GameState was already created!
     525                }
     526            }
     527            graphicsUnloader.Dismiss();
     528        }
    502529    }
    503530
    504531    void Game::unloadGraphics()
    505532    {
     533        if (GameMode::bShowsGraphics_s)
     534        {
     535            // Destroy all the GameStates that require graphics
     536            for (GameStateMap::iterator it = constructedStates_.begin(); it != constructedStates_.end();)
     537            {
     538                if (it->second->getInfo().bGraphicsMode)
     539                    constructedStates_.erase(it++);
     540                else
     541                    ++it;
     542            }
     543
     544            core_->unloadGraphics();
     545            GameMode::bShowsGraphics_s = false;
     546        }
    506547    }
    507548
     
    522563        // If state requires graphics, load it
    523564        Loki::ScopeGuard graphicsUnloader = Loki::MakeObjGuard(*this, &Game::unloadGraphics);
    524         if (gameStateDeclarations_s[name].bGraphicsMode)
     565        if (gameStateDeclarations_s[name].bGraphicsMode && !GameMode::showsGraphics())
    525566            this->loadGraphics();
    526567        else
Note: See TracChangeset for help on using the changeset viewer.