Changeset 3196 for code/trunk/src/core/Game.cc
- Timestamp:
- Jun 20, 2009, 9:20:47 AM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/pch (added) merged: 3114-3118,3124-3125,3127-3131,3133,3138-3194
- Property svn:mergeinfo changed
-
code/trunk/src/core/Game.cc
r3084 r3196 36 36 37 37 #include <exception> 38 #include < cassert>38 #include <boost/weak_ptr.hpp> 39 39 40 40 #include "util/Debug.h" … … 51 51 namespace orxonox 52 52 { 53 using boost::shared_ptr; 54 using boost::weak_ptr; 55 53 56 static void stop_game() 54 57 { Game::getInstance().stop(); } … … 57 60 struct _CoreExport GameStateTreeNode 58 61 { 59 GameState* 60 GameStateTreeNode*parent_;61 std::vector< GameStateTreeNode*> children_;62 GameState* state_; 63 weak_ptr<GameStateTreeNode> parent_; 64 std::vector<shared_ptr<GameStateTreeNode> > children_; 62 65 }; 63 66 … … 73 76 assert(singletonRef_s == 0); 74 77 singletonRef_s = this; 75 76 this->rootStateNode_ = 0;77 this->activeStateNode_ = 0;78 78 79 79 this->abort_ = false; … … 105 105 // Destroy pretty much everyhting left 106 106 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 107 112 108 delete this->gameClock_; … … 172 168 { 173 169 // 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_ )170 std::vector<shared_ptr<GameStateTreeNode> >::iterator it = this->requestedStateNodes_.begin() + 1; 171 if (*it == this->activeStateNode_->parent_.lock()) 176 172 this->unloadState(this->activeStateNode_->state_); 177 173 else // has to be child … … 194 190 195 191 if ((*it)->getCountTickTime()) 196 this->addTickTime( this->gameClock_->getRealMicroseconds() - timeBeforeTick);192 this->addTickTime(static_cast<uint32_t>(this->gameClock_->getRealMicroseconds() - timeBeforeTick)); 197 193 } 198 194 … … 216 212 217 213 uint32_t framesPerPeriod = this->statisticsTickTimes_.size(); 218 this->avgFPS_ = (float)framesPerPeriod / (currentTime - this->statisticsTickTimes_.front().tickTime) * 1000000.0;219 this->avgTickTime_ = (float)this->periodTickTime_ / framesPerPeriod / 1000.0;214 this->avgFPS_ = static_cast<float>(framesPerPeriod) / (currentTime - this->statisticsTickTimes_.front().tickTime) * 1000000.0f; 215 this->avgTickTime_ = static_cast<float>(this->periodTickTime_) / framesPerPeriod / 1000.0f; 220 216 221 217 this->periodTime_ -= this->statisticsRefreshCycle_; … … 226 222 while (!this->activeStates_.empty()) 227 223 this->unloadState(this->activeStates_.back()); 228 this->activeStateNode_ = 0;224 this->activeStateNode_.reset(); 229 225 this->requestedStateNodes_.clear(); 230 226 } … … 251 247 return; 252 248 253 GameStateTreeNode* requestedNode = 0;249 shared_ptr<GameStateTreeNode> requestedNode; 254 250 255 251 // this->requestedStateNodes_.back() is the currently active state 256 GameStateTreeNode*lastRequestedNode = this->requestedStateNodes_.back();252 shared_ptr<GameStateTreeNode> lastRequestedNode = this->requestedStateNodes_.back(); 257 253 258 254 // Already the active node? … … 274 270 275 271 // Check parent and all its grand parents 276 GameStateTreeNode*currentNode = lastRequestedNode;272 shared_ptr<GameStateTreeNode> currentNode = lastRequestedNode; 277 273 while (requestedNode == NULL && currentNode != NULL) 278 274 { 279 275 if (currentNode->state_ == state) 280 276 requestedNode = currentNode; 281 currentNode = currentNode->parent_ ;277 currentNode = currentNode->parent_.lock(); 282 278 } 283 279 … … 297 293 void Game::popState() 298 294 { 299 if (this->activeStateNode_ != NULL && this->requestedStateNodes_.back()->parent_ )300 this->requestState(this->requestedStateNodes_.back()->parent_ ->state_->getName());295 if (this->activeStateNode_ != NULL && this->requestedStateNodes_.back()->parent_.lock()) 296 this->requestState(this->requestedStateNodes_.back()->parent_.lock()->state_->getName()); 301 297 else 302 298 COUT(2) << "Warning: Could not pop GameState. Ignoring." << std::endl; … … 333 329 } 334 330 unsigned int currentLevel = 0; 335 GameStateTreeNode* currentNode = 0;331 shared_ptr<GameStateTreeNode> currentNode; 336 332 for (std::vector<std::pair<std::string, unsigned> >::const_iterator it = stateStrings.begin(); it != stateStrings.end(); ++it) 337 333 { … … 346 342 if (this->rootStateNode_ != NULL) 347 343 ThrowException(GameState, "No two root GameStates are allowed!"); 348 GameStateTreeNode* newNode = new GameStateTreeNode; 349 this->allStateNodes_.push_back(newNode); 344 shared_ptr<GameStateTreeNode> newNode(new GameStateTreeNode); 350 345 newNode->state_ = newState; 351 newNode->parent_ = 0;352 346 this->rootStateNode_ = newNode; 353 347 currentNode = this->rootStateNode_; … … 355 349 else if (currentNode) 356 350 { 357 GameStateTreeNode* newNode = new GameStateTreeNode; 358 this->allStateNodes_.push_back(newNode); 351 shared_ptr<GameStateTreeNode> newNode(new GameStateTreeNode); 359 352 newNode->state_ = newState; 360 353 if (newLevel < currentLevel) … … 362 355 // Get down the hierarchy 363 356 do 364 currentNode = currentNode->parent_ ;357 currentNode = currentNode->parent_.lock(); 365 358 while (newLevel < --currentLevel); 366 359 } … … 369 362 // same level 370 363 newNode->parent_ = currentNode->parent_; 371 newNode->parent_ ->children_.push_back(newNode);364 newNode->parent_.lock()->children_.push_back(newNode); 372 365 } 373 366 else if (newLevel == currentLevel + 1)
Note: See TracChangeset
for help on using the changeset viewer.