Changeset 5781 for code/trunk/src/libraries/core/Game.cc
- Timestamp:
- Sep 24, 2009, 11:02:42 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/libraries/core/Game.cc
r5774 r5781 45 45 #include "Clock.h" 46 46 #include "CommandLine.h" 47 #include "ConsoleCommand.h" 47 48 #include "Core.h" 48 49 #include "CoreIncludes.h" 49 50 #include "ConfigValueIncludes.h" 51 #include "GameMode.h" 50 52 #include "GameState.h" 51 53 52 54 namespace orxonox 53 55 { 56 static void stop_game() 57 { Game::getInstance().stop(); } 58 SetConsoleCommandShortcutExternAlias(stop_game, "exit"); 59 54 60 std::map<std::string, GameStateInfo> Game::gameStateDeclarations_s; 55 61 Game* Game::singletonPtr_s = 0; … … 500 506 void Game::loadGraphics() 501 507 { 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 } 502 529 } 503 530 504 531 void Game::unloadGraphics() 505 532 { 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 } 506 547 } 507 548 … … 522 563 // If state requires graphics, load it 523 564 Loki::ScopeGuard graphicsUnloader = Loki::MakeObjGuard(*this, &Game::unloadGraphics); 524 if (gameStateDeclarations_s[name].bGraphicsMode )565 if (gameStateDeclarations_s[name].bGraphicsMode && !GameMode::showsGraphics()) 525 566 this->loadGraphics(); 526 567 else
Note: See TracChangeset
for help on using the changeset viewer.