Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jun 20, 2009, 9:20:47 AM (16 years ago)
Author:
rgrieder
Message:

Merged pch branch back to trunk.

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/core/Game.cc

    r3084 r3196  
    3636
    3737#include <exception>
    38 #include <cassert>
     38#include <boost/weak_ptr.hpp>
    3939
    4040#include "util/Debug.h"
     
    5151namespace orxonox
    5252{
     53    using boost::shared_ptr;
     54    using boost::weak_ptr;
     55
    5356    static void stop_game()
    5457        { Game::getInstance().stop(); }
     
    5760    struct _CoreExport GameStateTreeNode
    5861    {
    59         GameState*                      state_;
    60         GameStateTreeNode*              parent_;
    61         std::vector<GameStateTreeNode*> children_;
     62        GameState* state_;
     63        weak_ptr<GameStateTreeNode> parent_;
     64        std::vector<shared_ptr<GameStateTreeNode> > children_;
    6265    };
    6366
     
    7376        assert(singletonRef_s == 0);
    7477        singletonRef_s = this;
    75 
    76         this->rootStateNode_ = 0;
    77         this->activeStateNode_ = 0;
    7878
    7979        this->abort_ = false;
     
    105105        // Destroy pretty much everyhting left
    106106        delete this->core_;
    107 
    108         // Delete all the created nodes
    109         for (std::vector<GameStateTreeNode*>::const_iterator it = this->allStateNodes_.begin(); it != this->allStateNodes_.end(); ++it)
    110             delete *it;
    111107
    112108        delete this->gameClock_;
     
    172168            {
    173169                // 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())
    176172                    this->unloadState(this->activeStateNode_->state_);
    177173                else // has to be child
     
    194190
    195191                if ((*it)->getCountTickTime())
    196                     this->addTickTime(this->gameClock_->getRealMicroseconds() - timeBeforeTick);
     192                    this->addTickTime(static_cast<uint32_t>(this->gameClock_->getRealMicroseconds() - timeBeforeTick));
    197193            }
    198194
     
    216212
    217213                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;
    220216
    221217                this->periodTime_ -= this->statisticsRefreshCycle_;
     
    226222        while (!this->activeStates_.empty())
    227223            this->unloadState(this->activeStates_.back());
    228         this->activeStateNode_ = 0;
     224        this->activeStateNode_.reset();
    229225        this->requestedStateNodes_.clear();
    230226    }
     
    251247            return;
    252248
    253         GameStateTreeNode* requestedNode = 0;
     249        shared_ptr<GameStateTreeNode> requestedNode;
    254250
    255251        // this->requestedStateNodes_.back() is the currently active state
    256         GameStateTreeNode* lastRequestedNode = this->requestedStateNodes_.back();
     252        shared_ptr<GameStateTreeNode> lastRequestedNode = this->requestedStateNodes_.back();
    257253
    258254        // Already the active node?
     
    274270
    275271        // Check parent and all its grand parents
    276         GameStateTreeNode* currentNode = lastRequestedNode;
     272        shared_ptr<GameStateTreeNode> currentNode = lastRequestedNode;
    277273        while (requestedNode == NULL && currentNode != NULL)
    278274        {
    279275            if (currentNode->state_ == state)
    280276                requestedNode = currentNode;
    281             currentNode = currentNode->parent_;
     277            currentNode = currentNode->parent_.lock();
    282278        }
    283279
     
    297293    void Game::popState()
    298294    {
    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());
    301297        else
    302298            COUT(2) << "Warning: Could not pop GameState. Ignoring." << std::endl;
     
    333329        }
    334330        unsigned int currentLevel = 0;
    335         GameStateTreeNode* currentNode = 0;
     331        shared_ptr<GameStateTreeNode> currentNode;
    336332        for (std::vector<std::pair<std::string, unsigned> >::const_iterator it = stateStrings.begin(); it != stateStrings.end(); ++it)
    337333        {
     
    346342                if (this->rootStateNode_ != NULL)
    347343                    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);
    350345                newNode->state_ = newState;
    351                 newNode->parent_ = 0;
    352346                this->rootStateNode_ = newNode;
    353347                currentNode = this->rootStateNode_;
     
    355349            else if (currentNode)
    356350            {
    357                 GameStateTreeNode* newNode = new GameStateTreeNode;
    358                 this->allStateNodes_.push_back(newNode);
     351                shared_ptr<GameStateTreeNode> newNode(new GameStateTreeNode);
    359352                newNode->state_ = newState;
    360353                if (newLevel < currentLevel)
     
    362355                    // Get down the hierarchy
    363356                    do
    364                         currentNode = currentNode->parent_;
     357                        currentNode = currentNode->parent_.lock();
    365358                    while (newLevel < --currentLevel);
    366359                }
     
    369362                    // same level
    370363                    newNode->parent_ = currentNode->parent_;
    371                     newNode->parent_->children_.push_back(newNode);
     364                    newNode->parent_.lock()->children_.push_back(newNode);
    372365                }
    373366                else if (newLevel == currentLevel + 1)
Note: See TracChangeset for help on using the changeset viewer.