Changeset 1661 for code/branches/gui
- Timestamp:
- Aug 18, 2008, 9:17:30 PM (16 years ago)
- Location:
- code/branches/gui
- Files:
-
- 9 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gui/src/core/GameState.cc
r1660 r1661 56 56 /** 57 57 @brief 58 Destructor only checks that we don't delete an active state. 59 */ 60 GameState::~GameState() 61 { 62 if (this->bActive_) 63 { 64 if (this->parent_) 65 this->requestState(this->parent_->getName()); 66 else 67 this->requestState(""); 68 } 69 } 70 71 /** 72 @brief 58 73 Adds a child to the current tree. The Child can contain children of its own. 59 74 But you cannot a state tree that already has an active state. … … 104 119 // mark us as parent 105 120 state->parent_ = this; 121 } 122 123 /** 124 @brief 125 Removes a child by instance. This splits the tree in two parts, 126 each of them functional on its own. 127 @param state 128 GameState by instance pointer 129 */ 130 void GameState::removeChild(GameState* state) 131 { 132 std::map<GameState*, GameState*>::iterator it = this->grandchildrenToChildren_.find(state); 133 if (it != this->grandchildrenToChildren_.end()) 134 { 135 if (state->isActive()) 136 { 137 ThrowException(GameState, "Cannot remove active game state child '" 138 + state->getName() + "' from '" + name_ + "'."); 139 //COUT(2) << "Warning: Cannot remove active game state child '" << state->getName() 140 // << "' from '" << name_ << "'." << std::endl; 141 } 142 else 143 { 144 for (std::map<GameState*, GameState*>::const_iterator it = state->grandchildrenToChildren_.begin(); 145 it != state->grandchildrenToChildren_.end(); ++it) 146 { 147 this->grandchildRemoved(it->first); 148 } 149 this->grandchildRemoved(state); 150 } 151 } 152 else 153 { 154 ThrowException(GameState, "Game state '" + name_ + "' doesn't have a child named '" 155 + state->getName() + "'. Removal skipped."); 156 //COUT(2) << "Warning: Game state '" << name_ << "' doesn't have a child named '" 157 // << state->getName() << "'. Removal skipped." << std::endl; 158 } 159 } 160 161 /** 162 @brief 163 Removes a child by name. This splits the tree in two parts, 164 each of them functional on its own. 165 @param state 166 GameState by name 167 */ 168 169 void GameState::removeChild(const std::string& name) 170 { 171 GameState* state = checkState(name); 172 if (state) 173 { 174 removeChild(state); 175 } 176 else 177 { 178 ThrowException(GameState, "GameState '" + name + "' doesn't exist."); 179 //COUT(2) << "Warning: GameState '" << name << "' doesn't exist." << std::endl; 180 } 106 181 } 107 182 … … 126 201 /** 127 202 @brief 203 Tells a state that one of its children has removed a child. This is necessary 204 to fill the internal maps correctly. 205 @param child 206 The child who notices this state. 207 @param grandchild 208 The child that has been removed. 209 */ 210 void GameState::grandchildRemoved(GameState* grandchild) 211 { 212 // adjust the two maps correctly. 213 this->allChildren_.erase(grandchild->getName()); 214 this->grandchildrenToChildren_.erase(grandchild); 215 if (this->parent_) 216 this->parent_->grandchildRemoved(grandchild); 217 } 218 219 /** 220 @brief 128 221 Checks whether a specific game states exists in the hierarchy. 129 222 @remarks … … 191 284 void GameState::requestState(const std::string& name) 192 285 { 193 GameState* request = checkState(name);194 GameState* current = getCurrentState();195 if (request)196 {286 if (name == "") 287 { 288 // user would like to leave every state. 289 GameState* current = getCurrentState(); 197 290 if (current) 198 291 { 199 // There is already an active state 200 current->makeTransition(request); 201 } 202 else 203 { 204 // no active state --> we have to activate the root node first. 292 // Deactivate all states but root 205 293 GameState* root = getRootNode(); 206 root->activate(); 207 root->makeTransition(request); 208 } 209 } 210 else 211 { 212 COUT(2) << "Warning: GameState '" << name << "' doesn't exist." << std::endl; 294 current->makeTransition(root); 295 // Kick root too 296 root->deactivate(); 297 } 298 } 299 else 300 { 301 GameState* request = checkState(name); 302 GameState* current = getCurrentState(); 303 if (request) 304 { 305 if (current) 306 { 307 // There is already an active state 308 current->makeTransition(request); 309 } 310 else 311 { 312 // no active state --> we have to activate the root node first. 313 GameState* root = getRootNode(); 314 root->activate(); 315 root->makeTransition(request); 316 } 317 } 318 else 319 { 320 COUT(2) << "Warning: GameState '" << name << "' doesn't exist." << std::endl; 321 } 213 322 } 214 323 } -
code/branches/gui/src/core/GameState.h
r1660 r1661 62 62 public: 63 63 GameState(const std::string& name); 64 virtual ~GameState() { }64 virtual ~GameState(); 65 65 66 66 const std::string& getName() const { return name_; } 67 67 68 68 void addChild(GameState* state); 69 void removeChild(GameState* state); 70 void removeChild(const std::string& name); 69 71 void requestState(const std::string& name); 70 72 … … 76 78 bool isCurrentState() { return this->bActive_ && !this->activeChild_; } 77 79 80 virtual bool tick(float dt) { return true; } 81 78 82 protected: 83 //virtual void enter() = 0; 84 //virtual void leave() = 0; 85 //virtual void tick(float dt) = 0; 79 86 virtual void enter() { } 80 87 virtual void leave() { } 81 virtual void tick(float dt) { } 88 89 GameState* getActiveChild() { return this->activeChild_; } 82 90 83 91 private: … … 86 94 GameState* getRootNode(); 87 95 void grandchildAdded(GameState* child, GameState* grandchild); 96 void grandchildRemoved(GameState* grandchild); 88 97 void makeTransition(GameState* state); 89 98 void activate(); -
code/branches/gui/src/orxonox/Main.cc
r1660 r1661 45 45 #include "Settings.h" 46 46 #include "Orxonox.h" 47 48 #include "gamestates/GSRoot.h" 49 #include "gamestates/GSGraphics.h" 50 #include "gamestates/GSLevel.h" 51 #include "gamestates/GSGUI.h" 47 52 48 53 using namespace orxonox; … … 140 145 state2->addChild(state3); 141 146 state2->addChild(state5); 142 state3->addChild(state1);143 147 state6->addChild(state2); 148 149 state6->removeChild("state2"); 144 150 145 151 state5->requestState("state3"); … … 160 166 COUT(2) << std::endl;*/ 161 167 168 169 GSRoot root; 170 GSGraphics graphics; 171 GSLevel level; 172 GSGUI gui; 173 174 root.addChild(&graphics); 175 graphics.addChild(&level); 176 graphics.addChild(&gui); 177 178 root.requestState("gui"); 179 root.tick(0.0f); 180 root.requestState(""); 162 181 163 182 … … 169 188 orxonoxInstance.start(macBundlePath()); 170 189 #else 171 orxonoxInstance.start();190 //orxonoxInstance.start(); 172 191 #endif 173 192 } -
code/branches/gui/src/orxonox/Orxonox.cc
r1656 r1661 43 43 //****** OGRE ****** 44 44 #include <OgreFrameListener.h> 45 #include <OgreOverlay.h>46 #include <OgreOverlayManager.h>47 45 #include <OgreRoot.h> 48 46 #include <OgreTimer.h> -
code/branches/gui/src/orxonox/gui/GUIManager.cc
r1659 r1661 84 84 85 85 if (backgroundSceneManager_) 86 { 87 // We have to make sure the SceneManager is not anymore referenced. 88 // For the case that the target SceneManager was yet another one, it 89 // wouldn't matter anyway since this is the destructor. 90 guiRenderer_->setTargetSceneManager(0); 86 91 Ogre::Root::getSingleton().destroySceneManager(backgroundSceneManager_); 92 } 87 93 88 94 InputManager::getInstance().destroyState("gui"); … … 218 224 { 219 225 if (state_ == OnDisplay) 220 _hideGUI();226 hideGUI(); 221 227 222 228 COUT(3) << "Loading GUI " << name << std::endl; … … 264 270 } 265 271 266 void GUIManager:: _hideGUI()272 void GUIManager::hideGUI() 267 273 { 268 274 if (this->state_ != OnDisplay) -
code/branches/gui/src/orxonox/gui/GUIManager.h
r1653 r1661 71 71 } 72 72 void showGUI(const std::string& name, Ogre::SceneManager* sceneManager);// bool showBackground); // tolua_export 73 void _hideGUI(); // tolua_export73 void hideGUI(); // tolua_export 74 74 75 75 Ogre::Camera* getCamera() { return this->backgroundCamera_; } -
code/branches/gui/visual_studio/vc8/orxonox.vcproj
r1638 r1661 492 492 </File> 493 493 </Filter> 494 <Filter 495 Name="gamestates" 496 > 497 <File 498 RelativePath="..\..\src\orxonox\gamestates\GSGraphics.cc" 499 > 500 </File> 501 <File 502 RelativePath="..\..\src\orxonox\gamestates\GSGUI.cc" 503 > 504 </File> 505 <File 506 RelativePath="..\..\src\orxonox\gamestates\GSLevel.cc" 507 > 508 </File> 509 <File 510 RelativePath="..\..\src\orxonox\gamestates\GSRoot.cc" 511 > 512 </File> 513 </Filter> 494 514 </Filter> 495 515 <Filter … … 711 731 <File 712 732 RelativePath="..\..\src\orxonox\gui\OgreCEGUITexture.h" 733 > 734 </File> 735 </Filter> 736 <Filter 737 Name="gamestates" 738 > 739 <File 740 RelativePath="..\..\src\orxonox\gamestates\GSGraphics.h" 741 > 742 </File> 743 <File 744 RelativePath="..\..\src\orxonox\gamestates\GSGUI.h" 745 > 746 </File> 747 <File 748 RelativePath="..\..\src\orxonox\gamestates\GSLevel.h" 749 > 750 </File> 751 <File 752 RelativePath="..\..\src\orxonox\gamestates\GSRoot.h" 713 753 > 714 754 </File>
Note: See TracChangeset
for help on using the changeset viewer.