Changeset 3124 for code/branches/pch/src
- Timestamp:
- Jun 9, 2009, 2:42:19 PM (15 years ago)
- Location:
- code/branches/pch/src/core
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pch/src/core/Game.cc
r3084 r3124 37 37 #include <exception> 38 38 #include <cassert> 39 #include <boost/weak_ptr.hpp> 39 40 40 41 #include "util/Debug.h" … … 51 52 namespace orxonox 52 53 { 54 using boost::shared_ptr; 55 using boost::weak_ptr; 56 53 57 static void stop_game() 54 58 { Game::getInstance().stop(); } … … 57 61 struct _CoreExport GameStateTreeNode 58 62 { 59 GameState* 60 GameStateTreeNode*parent_;61 std::vector< GameStateTreeNode*> children_;63 GameState* state_; 64 weak_ptr<GameStateTreeNode> parent_; 65 std::vector<shared_ptr<GameStateTreeNode> > children_; 62 66 }; 63 67 … … 73 77 assert(singletonRef_s == 0); 74 78 singletonRef_s = this; 75 76 this->rootStateNode_ = 0;77 this->activeStateNode_ = 0;78 79 79 80 this->abort_ = false; … … 105 106 // Destroy pretty much everyhting left 106 107 delete this->core_; 107 108 // Delete all the created nodes109 for (std::vector<GameStateTreeNode*>::const_iterator it = this->allStateNodes_.begin(); it != this->allStateNodes_.end(); ++it)110 delete *it;111 108 112 109 delete this->gameClock_; … … 172 169 { 173 170 // Note: this->requestedStateNodes_.front() is the currently active state node 174 std::vector< GameStateTreeNode*>::iterator it = this->requestedStateNodes_.begin() + 1;175 if (*it == this->activeStateNode_->parent_ )171 std::vector<shared_ptr<GameStateTreeNode> >::iterator it = this->requestedStateNodes_.begin() + 1; 172 if (*it == this->activeStateNode_->parent_.lock()) 176 173 this->unloadState(this->activeStateNode_->state_); 177 174 else // has to be child … … 226 223 while (!this->activeStates_.empty()) 227 224 this->unloadState(this->activeStates_.back()); 228 this->activeStateNode_ = 0;225 this->activeStateNode_.reset(); 229 226 this->requestedStateNodes_.clear(); 230 227 } … … 251 248 return; 252 249 253 GameStateTreeNode* requestedNode = 0;250 shared_ptr<GameStateTreeNode> requestedNode; 254 251 255 252 // this->requestedStateNodes_.back() is the currently active state 256 GameStateTreeNode*lastRequestedNode = this->requestedStateNodes_.back();253 shared_ptr<GameStateTreeNode> lastRequestedNode = this->requestedStateNodes_.back(); 257 254 258 255 // Already the active node? … … 274 271 275 272 // Check parent and all its grand parents 276 GameStateTreeNode*currentNode = lastRequestedNode;273 shared_ptr<GameStateTreeNode> currentNode = lastRequestedNode; 277 274 while (requestedNode == NULL && currentNode != NULL) 278 275 { 279 276 if (currentNode->state_ == state) 280 277 requestedNode = currentNode; 281 currentNode = currentNode->parent_ ;278 currentNode = currentNode->parent_.lock(); 282 279 } 283 280 … … 297 294 void Game::popState() 298 295 { 299 if (this->activeStateNode_ != NULL && this->requestedStateNodes_.back()->parent_ )300 this->requestState(this->requestedStateNodes_.back()->parent_ ->state_->getName());296 if (this->activeStateNode_ != NULL && this->requestedStateNodes_.back()->parent_.lock()) 297 this->requestState(this->requestedStateNodes_.back()->parent_.lock()->state_->getName()); 301 298 else 302 299 COUT(2) << "Warning: Could not pop GameState. Ignoring." << std::endl; … … 333 330 } 334 331 unsigned int currentLevel = 0; 335 GameStateTreeNode* currentNode = 0;332 shared_ptr<GameStateTreeNode> currentNode; 336 333 for (std::vector<std::pair<std::string, unsigned> >::const_iterator it = stateStrings.begin(); it != stateStrings.end(); ++it) 337 334 { … … 346 343 if (this->rootStateNode_ != NULL) 347 344 ThrowException(GameState, "No two root GameStates are allowed!"); 348 GameStateTreeNode* newNode = new GameStateTreeNode; 349 this->allStateNodes_.push_back(newNode); 345 shared_ptr<GameStateTreeNode> newNode(new GameStateTreeNode); 350 346 newNode->state_ = newState; 351 newNode->parent_ = 0;352 347 this->rootStateNode_ = newNode; 353 348 currentNode = this->rootStateNode_; … … 355 350 else if (currentNode) 356 351 { 357 GameStateTreeNode* newNode = new GameStateTreeNode; 358 this->allStateNodes_.push_back(newNode); 352 shared_ptr<GameStateTreeNode> newNode(new GameStateTreeNode); 359 353 newNode->state_ = newState; 360 354 if (newLevel < currentLevel) … … 362 356 // Get down the hierarchy 363 357 do 364 currentNode = currentNode->parent_ ;358 currentNode = currentNode->parent_.lock(); 365 359 while (newLevel < --currentLevel); 366 360 } … … 369 363 // same level 370 364 newNode->parent_ = currentNode->parent_; 371 newNode->parent_ ->children_.push_back(newNode);365 newNode->parent_.lock()->children_.push_back(newNode); 372 366 } 373 367 else if (newLevel == currentLevel + 1) -
code/branches/pch/src/core/Game.h
r3084 r3124 41 41 #include <map> 42 42 #include <vector> 43 #include <boost/shared_ptr.hpp> 43 44 #include "OrxonoxClass.h" 44 45 … … 106 107 107 108 std::vector<GameState*> activeStates_; 108 GameStateTreeNode* rootStateNode_; 109 GameStateTreeNode* activeStateNode_; 110 std::vector<GameStateTreeNode*> requestedStateNodes_; 111 std::vector<GameStateTreeNode*> allStateNodes_; 109 boost::shared_ptr<GameStateTreeNode> rootStateNode_; 110 boost::shared_ptr<GameStateTreeNode> activeStateNode_; 111 std::vector<boost::shared_ptr<GameStateTreeNode> > requestedStateNodes_; 112 112 113 113 Core* core_;
Note: See TracChangeset
for help on using the changeset viewer.