Changeset 3355 for code/branches/resource/src
- Timestamp:
- Jul 26, 2009, 2:15:08 PM (15 years ago)
- Location:
- code/branches/resource/src
- Files:
-
- 25 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/resource/src/core/Core.cc
r3349 r3355 364 364 guiManager_ = new GUIManager(renderWindow); 365 365 366 GameMode::setShowsGraphics(true);367 366 bGraphicsLoaded_ = true; 368 367 } … … 378 377 379 378 bGraphicsLoaded_ = false; 380 GameMode::setShowsGraphics(false);381 379 } 382 380 -
code/branches/resource/src/core/CorePrereqs.h
r3346 r3355 170 170 // game states 171 171 class Game; 172 struct GameStateConstrParams;173 172 class GameState; 173 struct GameStateInfo; 174 174 struct GameStateTreeNode; 175 175 -
code/branches/resource/src/core/Game.cc
r3352 r3355 48 48 #include "CoreIncludes.h" 49 49 #include "ConfigValueIncludes.h" 50 #include "GameMode.h" 50 51 #include "GameState.h" 51 52 … … 59 60 SetConsoleCommandShortcutExternAlias(stop_game, "exit"); 60 61 61 std::map<std::string, Game ::GameStateInfo> Game::gameStateDeclarations_s;62 std::map<std::string, GameStateInfo> Game::gameStateDeclarations_s; 62 63 Game* Game::singletonRef_s = 0; 63 64 … … 143 144 // Only create the states appropriate for the game mode 144 145 //if (GameMode::showsGraphics || !it->second.bGraphicsMode) 145 GameStateConstrParams params = { it->second.stateName, it->second.bIgnoreTickTime }; 146 gameStates_[getLowercase(it->second.stateName)] = GameStateFactory::fabricate(it->second.className, params); 146 gameStates_[getLowercase(it->second.stateName)] = GameStateFactory::fabricate(it->second); 147 147 } 148 148 … … 292 292 // Add tick time for most of the states 293 293 uint64_t timeBeforeTick; 294 if ((*it)-> ignoreTickTime())294 if ((*it)->getInfo().bIgnoreTickTime) 295 295 timeBeforeTick = this->gameClock_->getRealMicroseconds(); 296 296 (*it)->update(*this->gameClock_); 297 if ((*it)-> ignoreTickTime())297 if ((*it)->getInfo().bIgnoreTickTime) 298 298 this->subtractTickTime(static_cast<int32_t>(this->gameClock_->getRealMicroseconds() - timeBeforeTick)); 299 299 } … … 517 517 /*** Internal ***/ 518 518 519 void Game::loadGraphics() 520 { 521 if (!GameMode::bShowsGraphics_s) 522 { 523 core_->loadGraphics(); 524 GameMode::bShowsGraphics_s = true; 525 } 526 } 527 528 void Game::unloadGraphics() 529 { 530 if (GameMode::bShowsGraphics_s) 531 { 532 core_->unloadGraphics(); 533 GameMode::bShowsGraphics_s = false; 534 } 535 } 536 519 537 void Game::loadState(GameState* state) 520 538 { 521 539 this->bChangingState_ = true; 540 // If state requires graphics, load it 541 if (state->getInfo().bGraphicsMode) 542 this->loadGraphics(); 522 543 state->activate(); 523 544 if (!this->activeStates_.empty()) … … 538 559 { 539 560 state->deactivate(); 561 // Check if graphis is still required 562 bool graphicsRequired = false; 563 for (unsigned i = 0; i < activeStates_.size(); ++i) 564 graphicsRequired |= activeStates_[i]->getInfo().bGraphicsMode; 565 if (!graphicsRequired) 566 this->unloadGraphics(); 540 567 } 541 568 catch (const std::exception& ex) … … 549 576 std::map<std::string, Game::GameStateFactory*> Game::GameStateFactory::factories_s; 550 577 551 /*static*/ GameState* Game::GameStateFactory::fabricate(const std::string& className, const GameStateConstrParams& params)552 { 553 std::map<std::string, GameStateFactory*>::const_iterator it = factories_s.find( className);578 /*static*/ GameState* Game::GameStateFactory::fabricate(const GameStateInfo& info) 579 { 580 std::map<std::string, GameStateFactory*>::const_iterator it = factories_s.find(info.className); 554 581 assert(it != factories_s.end()); 555 return it->second->fabricate (params);582 return it->second->fabricateInternal(info); 556 583 } 557 584 -
code/branches/resource/src/core/Game.h
r3352 r3355 61 61 class GameConfiguration; 62 62 63 //! Helper object required before GameStates are being constructed 64 struct GameStateInfo 65 { 66 std::string stateName; 67 std::string className; 68 bool bIgnoreTickTime; 69 bool bGraphicsMode; 70 }; 71 63 72 /** 64 73 @brief … … 97 106 public: 98 107 virtual ~GameStateFactory() { } 99 static GameState* fabricate(const std::string& className, const GameStateConstrParams& params);108 static GameState* fabricate(const GameStateInfo& info); 100 109 template <class T> 101 110 static void createFactory(const std::string& className) … … 103 112 static void destroyFactories(); 104 113 private: 105 virtual GameState* fabricate (const GameStateConstrParams& params) = 0;114 virtual GameState* fabricateInternal(const GameStateInfo& info) = 0; 106 115 static std::map<std::string, GameStateFactory*> factories_s; 107 116 }; … … 110 119 { 111 120 public: 112 GameState* fabricate(const GameStateConstrParams& params) 113 { return new T(params); } 114 }; 115 116 struct GameStateInfo 117 { 118 std::string stateName; 119 std::string className; 120 bool bIgnoreTickTime; 121 bool bGraphicsMode; 121 GameState* fabricateInternal(const GameStateInfo& info) 122 { return new T(info); } 122 123 }; 123 124 … … 129 130 130 131 Game(Game&); // don't mess with singletons 132 133 void loadGraphics(); 134 void unloadGraphics(); 131 135 132 136 void loadState(GameState* state); -
code/branches/resource/src/core/GameMode.h
r3343 r3355 41 41 class _CoreExport GameMode 42 42 { 43 friend class Core;43 friend class Game; 44 44 45 45 public: … … 59 59 ~GameMode(); 60 60 61 static void setShowsGraphics(bool val) { bShowsGraphics_s = val; updateIsMaster(); } 62 static void updateIsMaster () { bIsMaster_s = (bHasServer_s || bIsStandalone_s); } 61 static void updateIsMaster() 62 { 63 bIsMaster_s = (bHasServer_s || bIsStandalone_s); 64 } 63 65 64 66 static bool bShowsGraphics_s; //!< global variable that tells whether to show graphics -
code/branches/resource/src/core/GameState.cc
r3280 r3355 38 38 #include "util/Exception.h" 39 39 #include "util/OrxAssert.h" 40 #include "Game.h" 40 41 41 42 namespace orxonox … … 45 46 Constructor only initialises variables and sets the name permanently. 46 47 */ 47 GameState::GameState(const GameStateConstrParams& params) 48 : name_(params.name) 49 , bIgnoreTickTime_(params.bIgnoreTickTime) 48 GameState::GameState(const GameStateInfo& info) 49 : info_(info) 50 50 , parent_(0) 51 51 { … … 65 65 { 66 66 OrxAssert(this->activity_.active == false, "Deleting an active GameState is a very bad idea.."); 67 } 68 69 const std::string& GameState::getName() const 70 { 71 return info_.stateName; 67 72 } 68 73 … … 107 112 else 108 113 { 109 ThrowException(GameState, "Game state '" + name_+ "' doesn't have a child named '"114 ThrowException(GameState, "Game state '" + this->getName() + "' doesn't have a child named '" 110 115 + state->getName() + "'."); 111 116 } -
code/branches/resource/src/core/GameState.h
r3280 r3355 45 45 /** 46 46 @brief 47 Helper class to group construction parameters for better genericity.48 */49 struct GameStateConstrParams50 {51 std::string name;52 bool bIgnoreTickTime;53 };54 55 /**56 @brief57 47 An implementation of a tree to manage game states. 58 48 This leads to a certain hierarchy that is created at runtime. … … 87 77 88 78 public: 89 GameState(const GameState ConstrParams& params);79 GameState(const GameStateInfo& info); 90 80 virtual ~GameState(); 91 81 92 const std::string& getName() const { return name_; } 93 State getActivity() const { return this->activity_; } 94 GameState* getParent() const { return this->parent_; } 95 96 bool ignoreTickTime() const { return this->bIgnoreTickTime_; } 82 const std::string& getName() const; 83 State getActivity() const { return activity_; } 84 GameState* getParent() const { return parent_; } 85 const GameStateInfo& getInfo() const { return info_; } 97 86 98 87 void addChild(GameState* state); … … 111 100 void updateInternal(const Clock& time); 112 101 113 const std::string name_;102 const GameStateInfo& info_; 114 103 State activity_; 115 const bool bIgnoreTickTime_;116 104 GameState* parent_; 117 105 std::map<std::string, GameState*> children_; -
code/branches/resource/src/orxonox/gamestates/GSClient.cc
r3280 r3355 42 42 SetCommandLineArgument(ip, "127.0.0.1").information("Sever IP as strin in the form #.#.#.#"); 43 43 44 GSClient::GSClient(const GameState ConstrParams& params)45 : GameState( params)44 GSClient::GSClient(const GameStateInfo& info) 45 : GameState(info) 46 46 , client_(0) 47 47 { -
code/branches/resource/src/orxonox/gamestates/GSClient.h
r3280 r3355 40 40 { 41 41 public: 42 GSClient(const GameState ConstrParams& params);42 GSClient(const GameStateInfo& info); 43 43 ~GSClient(); 44 44 -
code/branches/resource/src/orxonox/gamestates/GSDedicated.cc
r3304 r3355 55 55 termios* GSDedicated::originalTerminalSettings_; 56 56 57 GSDedicated::GSDedicated(const GameState ConstrParams& params)58 : GameState( params)57 GSDedicated::GSDedicated(const GameStateInfo& info) 58 : GameState(info) 59 59 , server_(0) 60 60 , closeThread_(false) -
code/branches/resource/src/orxonox/gamestates/GSDedicated.h
r3304 r3355 48 48 { 49 49 public: 50 GSDedicated(const GameState ConstrParams& params);50 GSDedicated(const GameStateInfo& info); 51 51 ~GSDedicated(); 52 52 -
code/branches/resource/src/orxonox/gamestates/GSGraphics.cc
r3349 r3355 57 57 DeclareGameState(GSGraphics, "graphics", false, true); 58 58 59 GSGraphics::GSGraphics(const GameState ConstrParams& params)60 : GameState( params)59 GSGraphics::GSGraphics(const GameStateInfo& info) 60 : GameState(info) 61 61 , console_(0) 62 62 , soundManager_(0) … … 88 88 void GSGraphics::activate() 89 89 { 90 // Load OGRE, CEGUI and OIS91 Core::getInstance().loadGraphics();92 93 90 // load debug overlay 94 91 COUT(3) << "Loading Debug Overlay..." << std::endl; … … 147 144 // HACK: (destroys a resource smart pointer) 148 145 Map::hackDestroyMap(); 149 150 // Unload OGRE, CEGUI and OIS151 Core::getInstance().loadGraphics();152 146 } 153 147 -
code/branches/resource/src/orxonox/gamestates/GSGraphics.h
r3349 r3355 50 50 { 51 51 public: 52 GSGraphics(const GameState ConstrParams& params);52 GSGraphics(const GameStateInfo& info); 53 53 ~GSGraphics(); 54 54 -
code/branches/resource/src/orxonox/gamestates/GSIOConsole.cc
r3280 r3355 38 38 DeclareGameState(GSIOConsole, "ioConsole", false, false); 39 39 40 GSIOConsole::GSIOConsole(const GameState ConstrParams& params)41 : GameState( params)40 GSIOConsole::GSIOConsole(const GameStateInfo& info) 41 : GameState(info) 42 42 { 43 43 } -
code/branches/resource/src/orxonox/gamestates/GSIOConsole.h
r3280 r3355 38 38 { 39 39 public: 40 GSIOConsole(const GameState ConstrParams& params);40 GSIOConsole(const GameStateInfo& info); 41 41 ~GSIOConsole(); 42 42 -
code/branches/resource/src/orxonox/gamestates/GSLevel.cc
r3346 r3355 60 60 XMLFile* GSLevel::startFile_s = NULL; 61 61 62 GSLevel::GSLevel(const GameState ConstrParams& params)63 : GameState( params)62 GSLevel::GSLevel(const GameStateInfo& info) 63 : GameState(info) 64 64 , keyBinder_(0) 65 65 , gameInputState_(0) -
code/branches/resource/src/orxonox/gamestates/GSLevel.h
r3327 r3355 41 41 { 42 42 public: 43 GSLevel(const GameState ConstrParams& params);43 GSLevel(const GameStateInfo& info); 44 44 ~GSLevel(); 45 45 void setConfigValues(); -
code/branches/resource/src/orxonox/gamestates/GSMainMenu.cc
r3346 r3355 45 45 DeclareGameState(GSMainMenu, "mainMenu", false, true); 46 46 47 GSMainMenu::GSMainMenu(const GameState ConstrParams& params)48 : GameState( params)47 GSMainMenu::GSMainMenu(const GameStateInfo& info) 48 : GameState(info) 49 49 , inputState_(0) 50 50 { -
code/branches/resource/src/orxonox/gamestates/GSMainMenu.h
r3327 r3355 40 40 { 41 41 public: 42 GSMainMenu(const GameState ConstrParams& params);42 GSMainMenu(const GameStateInfo& info); 43 43 ~GSMainMenu(); 44 44 -
code/branches/resource/src/orxonox/gamestates/GSRoot.cc
r3349 r3355 53 53 SetCommandLineSwitch(standalone).information("Start in standalone mode"); 54 54 55 GSRoot::GSRoot(const GameState ConstrParams& params)56 : GameState( params)55 GSRoot::GSRoot(const GameStateInfo& info) 56 : GameState(info) 57 57 , timeFactor_(1.0f) 58 58 , bPaused_(false) … … 174 174 @brief 175 175 Changes the speed of Orxonox 176 @remark 177 This function is a hack when placed here! 178 Timefactor should be related to the scene (level or so), not the game 176 179 */ 177 180 void GSRoot::setTimeFactor(float factor) -
code/branches/resource/src/orxonox/gamestates/GSRoot.h
r3280 r3355 38 38 { 39 39 public: 40 GSRoot(const GameState ConstrParams& params);40 GSRoot(const GameStateInfo& info); 41 41 ~GSRoot(); 42 42 -
code/branches/resource/src/orxonox/gamestates/GSServer.cc
r3280 r3355 41 41 SetCommandLineArgument(port, 55556).shortcut("p").information("Network communication port to be used 0-65535 (default: 55556)"); 42 42 43 GSServer::GSServer(const GameState ConstrParams& params)44 : GameState( params)43 GSServer::GSServer(const GameStateInfo& info) 44 : GameState(info) 45 45 , server_(0) 46 46 { -
code/branches/resource/src/orxonox/gamestates/GSServer.h
r3280 r3355 40 40 { 41 41 public: 42 GSServer(const GameState ConstrParams& params);42 GSServer(const GameStateInfo& info); 43 43 ~GSServer(); 44 44 -
code/branches/resource/src/orxonox/gamestates/GSStandalone.cc
r3280 r3355 36 36 DeclareGameState(GSStandalone, "standalone", false, true); 37 37 38 GSStandalone::GSStandalone(const GameState ConstrParams& params)39 : GameState( params)38 GSStandalone::GSStandalone(const GameStateInfo& info) 39 : GameState(info) 40 40 { 41 41 } -
code/branches/resource/src/orxonox/gamestates/GSStandalone.h
r3280 r3355 38 38 { 39 39 public: 40 GSStandalone(const GameState ConstrParams& params);40 GSStandalone(const GameStateInfo& info); 41 41 ~GSStandalone(); 42 42
Note: See TracChangeset
for help on using the changeset viewer.