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.h

    r2815 r2817  
    6060        Then Bar stores Foo in map by its name. The other one then maps Foo to Foofoo.
    6161    */
    62     class _CoreExport GameStateBase
     62    class _CoreExport GameState
    6363    {
    6464        friend class RootGameState;
    65         template <class ParentType>
    66         friend class GameState;
    6765        // Hack
    6866        friend class Game;
     
    8381
    8482    public:
    85         virtual ~GameStateBase();
     83        GameState(const std::string& name);
     84        virtual ~GameState();
    8685
    8786        const std::string& getName() const { return name_; }
    8887        const Operations getOperation() const { return this->operation_; }
    89         bool isInSubtree(GameStateBase* state) const;
     88        bool isInSubtree(GameState* state) const;
    9089
    91         GameStateBase* getState(const std::string& name);
    92         GameStateBase* getRoot();
     90        GameState* getState(const std::string& name);
     91        GameState* getRoot();
    9392        //! Returns the currently active game state
    94         virtual GameStateBase* getCurrentState();
     93        virtual GameState* getCurrentState();
    9594
    9695        virtual void requestState(const std::string& name);
    9796
    98         void addChild(GameStateBase* state);
    99         void removeChild(GameStateBase* state);
     97        void addChild(GameState* state);
     98        void removeChild(GameState* state);
    10099        void removeChild(const std::string& name);
    101100
     
    105104        virtual void ticked(const Clock& time) = 0;
    106105
    107         GameStateBase* getActiveChild() { return this->activeChild_; }
     106        GameState* getActiveChild() { return this->activeChild_; }
    108107
    109108        void tickChild(const Clock& time) { if (this->getActiveChild()) this->getActiveChild()->tick(time); }
    110109
    111         virtual GameStateBase* getParentAsBase() const = 0;
    112         virtual void setParent(GameStateBase* state) = 0;
     110        GameState* getParent() const     { return this->parent_; }
     111        void setParent(GameState* state) { this->parent_ = state; }
    113112
    114113    private:
    115         // Making the constructor private ensures that game states
    116         // are always derivates of GameState<T>. Note the friend declaration above.
    117         GameStateBase(const std::string& name);
     114        //! Performs a transition to 'destination'
     115        virtual void makeTransition(GameState* source, GameState* destination);
    118116
    119         //! Performs a transition to 'destination'
    120         virtual void makeTransition(GameStateBase* source, GameStateBase* destination);
    121 
    122         void grandchildAdded(GameStateBase* child, GameStateBase* grandchild);
    123         void grandchildRemoved(GameStateBase* grandchild);
     117        void grandchildAdded(GameState* child, GameState* grandchild);
     118        void grandchildRemoved(GameState* grandchild);
    124119
    125120        void tick(const Clock& time);
     
    129124        const std::string                        name_;
    130125        Operations                               operation_;
    131         GameStateBase*                           activeChild_;
     126        GameState*                               parent_;
     127        GameState*                               activeChild_;
    132128        //bool                                     bPauseParent_;
    133         std::map<std::string, GameStateBase*>    allChildren_;
    134         std::map<GameStateBase*, GameStateBase*> grandchildrenToChildren_;
    135     };
    136 
    137 
    138     template <class ParentType>
    139     class GameState : public GameStateBase
    140     {
    141     public:
    142         GameState(const std::string& name)
    143             : GameStateBase(name)
    144             , parent_(0)
    145         { }
    146         virtual ~GameState() { }
    147 
    148         GameStateBase* getParentAsBase() const
    149             { return parent_; }
    150 
    151         ParentType* getParent() const
    152             { return parent_; }
    153 
    154     protected:
    155         void setParent(GameStateBase* state)
    156         {
    157             assert(dynamic_cast<ParentType*>(state) != 0);
    158             this->parent_ = dynamic_cast<ParentType*>(state);
    159         }
    160 
    161     private:
    162         ParentType* parent_;
     129        std::map<std::string, GameState*>        allChildren_;
     130        std::map<GameState*, GameState*>         grandchildrenToChildren_;
    163131    };
    164132}
Note: See TracChangeset for help on using the changeset viewer.