Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Aug 27, 2008, 10:21:39 PM (17 years ago)
Author:
rgrieder
Message:
  • Changed GameState so that the new RootGameState can override 2 virtual methods
  • added RootGameState that takes care of state transitions (can only happen between ticks)
  • moved main loop to GSRoot instead of GSGraphics
  • network GameStates not yet finished
  • GraphicsEngine not yet merged into GSGraphics
File:
1 edited

Legend:

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

    r1670 r1672  
    4141#include <vector>
    4242#include <map>
     43#include "util/Integers.h"
    4344
    4445namespace orxonox
     
    6061    class _CoreExport GameState
    6162    {
     63        friend class RootGameState;
     64
    6265    public:
     66        /**
     67        @brief
     68            Gives information about what the GameState is currently doing
     69        */
    6370        struct Operations
    6471        {
     
    7077        };
    7178
     79    public:
    7280        GameState(const std::string& name);
    7381        virtual ~GameState();
    7482
    7583        const std::string& getName() const { return name_; }
     84        const Operations getOperation() const { return this->operation_; }
     85        bool isInSubtree(GameState* state) const;
     86
     87        GameState* getState(const std::string& name);
     88        GameState* getRoot();
     89        GameState* getParent() const { return this->parent_; }
     90        //! Returns the currently active game state
     91        virtual GameState* getCurrentState();
     92
     93        virtual void requestState(const std::string& name);
    7694
    7795        void addChild(GameState* state);
    7896        void removeChild(GameState* state);
    7997        void removeChild(const std::string& name);
    80         void requestState(const std::string& name);
    81 
    82         ////! Determines whether the state is active.
    83         //bool isActive()       { return this->bActive_; }
    84         ////! Determines whether the state is suspended.
    85         //bool isSuspended()    { return this->bSuspended_; }
    86         ////! Determines whether the state is the current
    87         //bool isCurrentState() { return this->bActive_ && !this->activeChild_; }
    88         const Operations getOperation() { return this->operation_; }
    89 
    90         void tick(float dt);
    91         void tickChild(float dt) { if (this->activeChild_) this->activeChild_->tick(dt); }
    9298
    9399    protected:
    94100        virtual void enter() = 0;
    95101        virtual void leave() = 0;
    96         virtual void ticked(float dt) = 0;
    97         //virtual void enter() { }
    98         //virtual void leave() { }
    99         //virtual void ticked(float dt) { }
     102        virtual void ticked(float dt, uint64_t time) = 0;
    100103
    101104        GameState* getActiveChild() { return this->activeChild_; }
    102         bool hasScheduledTransition() { return this->scheduledTransition_; }
     105
     106        void tickChild(float dt, uint64_t time) { if (this->getActiveChild()) this->getActiveChild()->tick(dt, time); }
    103107
    104108    private:
    105         GameState* checkState(const std::string& name);
    106         GameState* getCurrentState();
    107         GameState* getRootNode();
     109        //! Performs a transition to 'destination'
     110        virtual void makeTransition(GameState* source, GameState* destination);
     111
    108112        void grandchildAdded(GameState* child, GameState* grandchild);
    109113        void grandchildRemoved(GameState* grandchild);
    110         void makeTransition(GameState* state);
     114
     115        void tick(float dt, uint64_t time);
    111116        void activate();
    112117        void deactivate();
    113118
    114         const std::string                    name_;
    115         bool                                 bPauseParent_;
    116 
    117         Operations                           operation_;
    118 
    119         GameState*                           parent_;
    120         GameState*                           activeChild_;
    121         GameState*                           scheduledTransition_;
    122         std::map<std::string, GameState*>    allChildren_;
    123         std::map<GameState*, GameState*>     grandchildrenToChildren_;
     119        const std::string                          name_;
     120        Operations                                 operation_;
     121        GameState*                             parent_;
     122        GameState*                                 activeChild_;
     123        //bool                                       bPauseParent_;
     124        std::map<std::string, GameState*>      allChildren_;
     125        std::map<GameState*, GameState*>   grandchildrenToChildren_;
    124126    };
    125127}
Note: See TracChangeset for help on using the changeset viewer.