Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 21, 2009, 10:17:59 PM (15 years ago)
Author:
rgrieder
Message:

Removed GameState template and renamed GameStateBase to GameState.
Moved statistics stuff (fps and tick time) to Game and removed the remaining hacks in GSGraphics and GSRoot.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gui/src/core/GameState.cc

    r2815 r2817  
    3030@file
    3131@brief
    32     Implementation of GameStateBase class.
     32    Implementation of GameState class.
    3333*/
    3434
     
    4343        Constructor only initialises variables and sets the name permanently.
    4444    */
    45     GameStateBase::GameStateBase(const std::string& name)
     45    GameState::GameState(const std::string& name)
    4646        : name_(name)
    47         //, parent_(0)
     47        , parent_(0)
    4848        , activeChild_(0)
    4949        //, bPausegetParent()(false)
     
    5757        Destructor only checks that we don't delete an active state.
    5858    */
    59     GameStateBase::~GameStateBase()
     59    GameState::~GameState()
    6060    {
    6161        OrxAssert(this->operation_.active == false, "Deleting an active GameState is a very bad idea..");
     
    6969        The state to be added.
    7070    */
    71     void GameStateBase::addChild(GameStateBase* state)
     71    void GameState::addChild(GameState* state)
    7272    {
    7373        if (!state)
    7474            return;
    7575        // check if the state/tree to be added has states in it that already exist in this tree.
    76         for (std::map<std::string, GameStateBase*>::const_iterator it = state->allChildren_.begin();
     76        for (std::map<std::string, GameState*>::const_iterator it = state->allChildren_.begin();
    7777            it != state->allChildren_.end(); ++it)
    7878        {
     
    9696
    9797        // merge the child's children into this tree
    98         for (std::map<std::string, GameStateBase*>::const_iterator it = state->allChildren_.begin();
     98        for (std::map<std::string, GameState*>::const_iterator it = state->allChildren_.begin();
    9999            it != state->allChildren_.end(); ++it)
    100100            this->grandchildAdded(state, it->second);
     
    113113        GameState by instance pointer
    114114    */
    115     void GameStateBase::removeChild(GameStateBase* state)
    116     {
    117         std::map<GameStateBase*, GameStateBase*>::iterator it = this->grandchildrenToChildren_.find(state);
     115    void GameState::removeChild(GameState* state)
     116    {
     117        std::map<GameState*, GameState*>::iterator it = this->grandchildrenToChildren_.find(state);
    118118        if (it != this->grandchildrenToChildren_.end())
    119119        {
     
    127127            else
    128128            {
    129                 for (std::map<GameStateBase*, GameStateBase*>::const_iterator it = state->grandchildrenToChildren_.begin();
     129                for (std::map<GameState*, GameState*>::const_iterator it = state->grandchildrenToChildren_.begin();
    130130                    it != state->grandchildrenToChildren_.end(); ++it)
    131131                    this->grandchildRemoved(it->first);
     
    150150    */
    151151
    152     void GameStateBase::removeChild(const std::string& name)
    153     {
    154         GameStateBase* state = getState(name);
     152    void GameState::removeChild(const std::string& name)
     153    {
     154        GameState* state = getState(name);
    155155        if (state)
    156156        {
     
    173173        The child that has been added.
    174174    */
    175     inline void GameStateBase::grandchildAdded(GameStateBase* child, GameStateBase* grandchild)
     175    inline void GameState::grandchildAdded(GameState* child, GameState* grandchild)
    176176    {
    177177        // fill the two maps correctly.
    178178        this->allChildren_[grandchild->getName()] = grandchild;
    179179        this->grandchildrenToChildren_[grandchild] = child;
    180         if (this->getParentAsBase())
    181             this->getParentAsBase()->grandchildAdded(this, grandchild);
     180        if (this->getParent())
     181            this->getParent()->grandchildAdded(this, grandchild);
    182182    }
    183183
     
    191191        The child that has been removed.
    192192    */
    193     inline void GameStateBase::grandchildRemoved(GameStateBase* grandchild)
     193    inline void GameState::grandchildRemoved(GameState* grandchild)
    194194    {
    195195        // adjust the two maps correctly.
    196196        this->allChildren_.erase(grandchild->getName());
    197197        this->grandchildrenToChildren_.erase(grandchild);
    198         if (this->getParentAsBase())
    199             this->getParentAsBase()->grandchildRemoved(grandchild);
     198        if (this->getParent())
     199            this->getParent()->grandchildRemoved(grandchild);
    200200    }
    201201
     
    206206        Remember that the every node has a map with all its child nodes.
    207207    */
    208     GameStateBase* GameStateBase::getState(const std::string& name)
    209     {
    210         if (this->getParentAsBase())
    211             return this->getParentAsBase()->getState(name);
     208    GameState* GameState::getState(const std::string& name)
     209    {
     210        if (this->getParent())
     211            return this->getParent()->getState(name);
    212212        else
    213213        {
     
    216216                return this;
    217217            // Search in the map. If there is no entry, we can be sure the state doesn't exist.
    218             std::map<std::string, GameStateBase*>::const_iterator it = this->allChildren_.find(name);
     218            std::map<std::string, GameState*>::const_iterator it = this->allChildren_.find(name);
    219219            return (it!= this->allChildren_.end() ? it->second : 0);
    220220        }
     
    225225        Returns the root node of the tree.
    226226    */
    227     GameStateBase* GameStateBase::getRoot()
    228     {
    229         if (this->getParentAsBase())
    230             return this->getParentAsBase()->getRoot();
     227    GameState* GameState::getRoot()
     228    {
     229        if (this->getParent())
     230            return this->getParent()->getRoot();
    231231        else
    232232            return this;
     
    240240        have active children itself. Many states can be active at once.
    241241    */
    242     GameStateBase* GameStateBase::getCurrentState()
     242    GameState* GameState::getCurrentState()
    243243    {
    244244        if (this->operation_.active)
     
    251251        else
    252252        {
    253             if (this->getParentAsBase())
    254                 return this->getParentAsBase()->getCurrentState();
     253            if (this->getParent())
     254                return this->getParent()->getCurrentState();
    255255            else
    256256                return 0;
     
    262262        Determines whether 'state' is in this subtree, including this node.
    263263    */
    264     bool GameStateBase::isInSubtree(GameStateBase* state) const
     264    bool GameState::isInSubtree(GameState* state) const
    265265    {
    266266        return (grandchildrenToChildren_.find(state) != grandchildrenToChildren_.end()
     
    275275        The state to be entered, has to exist in the tree.
    276276    */
    277     void GameStateBase::requestState(const std::string& name)
     277    void GameState::requestState(const std::string& name)
    278278    {
    279279        assert(getRoot());
     
    286286        the method can assume certain things to be granted (like 'this' is always active).
    287287    */
    288     void GameStateBase::makeTransition(GameStateBase* source, GameStateBase* destination)
    289     {
    290         if (source == this->getParentAsBase())
     288    void GameState::makeTransition(GameState* source, GameState* destination)
     289    {
     290        if (source == this->getParent())
    291291        {
    292292            // call is from the parent
     
    308308
    309309        // Check for 'destination' in the children map first
    310         std::map<GameStateBase*, GameStateBase*>::const_iterator it
     310        std::map<GameState*, GameState*>::const_iterator it
    311311            = this->grandchildrenToChildren_.find(destination);
    312312        if (it != this->grandchildrenToChildren_.end())
     
    319319        {
    320320            // parent. We can be sure of this.
    321             assert(this->getParentAsBase() != 0);
     321            assert(this->getParent() != 0);
    322322
    323323            this->deactivate();
    324             this->getParentAsBase()->makeTransition(this, destination);
     324            this->getParent()->makeTransition(this, destination);
    325325        }
    326326    }
     
    330330        Activates the state. Only sets bActive_ to true and notifies the parent.
    331331    */
    332     void GameStateBase::activate()
     332    void GameState::activate()
    333333    {
    334334        this->operation_.active = true;
     
    341341        Activates the state. Only sets bActive_ to false and notifies the parent.
    342342    */
    343     void GameStateBase::deactivate()
     343    void GameState::deactivate()
    344344    {
    345345        this->operation_.leaving = true;
     
    358358        This method is not virtual! You cannot override it therefore.
    359359    */
    360     void GameStateBase::tick(const Clock& time)
     360    void GameState::tick(const Clock& time)
    361361    {
    362362        this->operation_.running = true;
Note: See TracChangeset for help on using the changeset viewer.