Changeset 10771 for code/branches/cpp11_v2/src/libraries/core/Game.cc
- Timestamp:
- Nov 7, 2015, 5:24:58 PM (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/cpp11_v2/src/libraries/core/Game.cc
r10769 r10771 36 36 37 37 #include <exception> 38 #include <boost/weak_ptr.hpp>39 38 #include <loki/ScopeGuard.h> 40 39 … … 72 71 { 73 72 std::string name_; 74 weak_ptr<GameStateTreeNode> parent_;75 std::vector<s hared_ptr<GameStateTreeNode>> children_;73 std::weak_ptr<GameStateTreeNode> parent_; 74 std::vector<std::shared_ptr<GameStateTreeNode>> children_; 76 75 }; 77 76 … … 124 123 125 124 // The empty root state is ALWAYS loaded! 126 this->rootStateNode_ = s hared_ptr<GameStateTreeNode>(new GameStateTreeNode());125 this->rootStateNode_ = std::shared_ptr<GameStateTreeNode>(new GameStateTreeNode()); 127 126 this->rootStateNode_->name_ = "emptyRootGameState"; 128 127 this->loadedTopStateNode_ = this->rootStateNode_; … … 137 136 138 137 assert(loadedStates_.size() <= 1); // Just empty root GameState 139 // Destroy all GameStates (s hared_ptrs take care of actual destruction)138 // Destroy all GameStates (std::shared_ptrs take care of actual destruction) 140 139 constructedStates_.clear(); 141 140 … … 235 234 while (this->requestedStateNodes_.size() > 0) 236 235 { 237 s hared_ptr<GameStateTreeNode> requestedStateNode = this->requestedStateNodes_.front();236 std::shared_ptr<GameStateTreeNode> requestedStateNode = this->requestedStateNodes_.front(); 238 237 assert(this->loadedTopStateNode_); 239 238 if (!this->loadedTopStateNode_->parent_.expired() && requestedStateNode == this->loadedTopStateNode_->parent_.lock()) … … 281 280 orxout(user_error) << "This should really never happen!" << endl; 282 281 orxout(user_error) << "Unloading all GameStates depending on the one that crashed." << endl; 283 s hared_ptr<GameStateTreeNode> current = this->loadedTopStateNode_;282 std::shared_ptr<GameStateTreeNode> current = this->loadedTopStateNode_; 284 283 while (current->name_ != (*it)->getName() && current) 285 284 current = current->parent_.lock(); … … 372 371 } 373 372 374 s hared_ptr<GameStateTreeNode> lastRequestedNode;373 std::shared_ptr<GameStateTreeNode> lastRequestedNode; 375 374 if (this->requestedStateNodes_.empty()) 376 375 lastRequestedNode = this->loadedTopStateNode_; … … 384 383 385 384 // Check children first 386 std::vector<s hared_ptr<GameStateTreeNode>> requestedNodes;385 std::vector<std::shared_ptr<GameStateTreeNode>> requestedNodes; 387 386 for (unsigned int i = 0; i < lastRequestedNode->children_.size(); ++i) 388 387 { … … 397 396 { 398 397 // Check parent and all its grand parents 399 s hared_ptr<GameStateTreeNode> currentNode = lastRequestedNode;398 std::shared_ptr<GameStateTreeNode> currentNode = lastRequestedNode; 400 399 while (currentNode != nullptr) 401 400 { … … 424 423 void Game::popState() 425 424 { 426 s hared_ptr<GameStateTreeNode> lastRequestedNode;425 std::shared_ptr<GameStateTreeNode> lastRequestedNode; 427 426 if (this->requestedStateNodes_.empty()) 428 427 lastRequestedNode = this->loadedTopStateNode_; … … 435 434 } 436 435 437 s hared_ptr<GameState> Game::getState(const std::string& name)436 std::shared_ptr<GameState> Game::getState(const std::string& name) 438 437 { 439 438 GameStateMap::const_iterator it = constructedStates_.find(name); … … 447 446 else 448 447 orxout(internal_error) << "Could not find GameState '" << name << "'." << endl; 449 return s hared_ptr<GameState>();448 return std::shared_ptr<GameState>(); 450 449 } 451 450 } … … 479 478 /*** Internal ***/ 480 479 481 void Game::parseStates(std::vector<std::pair<std::string, int>>::const_iterator& it, s hared_ptr<GameStateTreeNode> currentNode)480 void Game::parseStates(std::vector<std::pair<std::string, int>>::const_iterator& it, std::shared_ptr<GameStateTreeNode> currentNode) 482 481 { 483 482 SubString tokens(it->first, ","); … … 491 490 if (tokens[i] == this->rootStateNode_->name_) 492 491 ThrowException(GameState, "You shouldn't use 'emptyRootGameState' in the hierarchy..."); 493 s hared_ptr<GameStateTreeNode> node(new GameStateTreeNode());492 std::shared_ptr<GameStateTreeNode> node(new GameStateTreeNode()); 494 493 node->name_ = tokens[i]; 495 494 node->parent_ = currentNode; … … 527 526 { 528 527 // Game state loading failure is serious --> don't catch 529 s hared_ptr<GameState> gameState = GameStateFactory::fabricate(it->second);528 std::shared_ptr<GameState> gameState = GameStateFactory::fabricate(it->second); 530 529 if (!constructedStates_.insert(std::make_pair( 531 530 it->second.stateName, gameState)).second) … … 582 581 graphicsUnloader.Dismiss(); 583 582 584 s hared_ptr<GameState> state = this->getState(name);583 std::shared_ptr<GameState> state = this->getState(name); 585 584 state->activateInternal(); 586 585 if (!this->loadedStates_.empty()) … … 599 598 try 600 599 { 601 s hared_ptr<GameState> state = this->getState(name);600 std::shared_ptr<GameState> state = this->getState(name); 602 601 state->activity_.topState = false; 603 602 this->loadedStates_.pop_back(); … … 620 619 } 621 620 622 /*static*/ std::map<std::string, s hared_ptr<Game::GameStateFactory>>& Game::GameStateFactory::getFactories()623 { 624 static std::map<std::string, s hared_ptr<GameStateFactory>> factories;621 /*static*/ std::map<std::string, std::shared_ptr<Game::GameStateFactory>>& Game::GameStateFactory::getFactories() 622 { 623 static std::map<std::string, std::shared_ptr<GameStateFactory>> factories; 625 624 return factories; 626 625 } 627 626 628 /*static*/ s hared_ptr<GameState> Game::GameStateFactory::fabricate(const GameStateInfo& info)629 { 630 std::map<std::string, s hared_ptr<Game::GameStateFactory>>::const_iterator it = getFactories().find(info.className);627 /*static*/ std::shared_ptr<GameState> Game::GameStateFactory::fabricate(const GameStateInfo& info) 628 { 629 std::map<std::string, std::shared_ptr<Game::GameStateFactory>>::const_iterator it = getFactories().find(info.className); 631 630 assert(it != getFactories().end()); 632 631 return it->second->fabricateInternal(info);
Note: See TracChangeset
for help on using the changeset viewer.