Changeset 3355 for code/branches/resource/src/core
- Timestamp:
- Jul 26, 2009, 2:15:08 PM (15 years ago)
- Location:
- code/branches/resource/src/core
- Files:
-
- 7 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_;
Note: See TracChangeset
for help on using the changeset viewer.