Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Mar 25, 2009, 5:23:00 PM (15 years ago)
Author:
rgrieder
Message:

Implemented new GameState concept. It doesn't differ that much from the old one, but there's still lots of changes.
The most important change is that one GameState can occur multiple times in the hierarchy.

Short log:

  • No RootGameState anymore. Simply the highest is root.
  • Game::requestGameState(name) can refer to the parent, grandparent, great-grandparent, etc. or one of the children.
  • Requested states are saved. So if you select "level", the next request (even right after the call) will be relative to "level"
  • Game::popState() will simply unload the current one
  • Re added Main.cc again because Game as well as GameState have been moved to the core
  • Adapted all GameStates to the new system

Things should already work, except for network support because standalone only works with a little hack.
We can now start creating a better hierarchy.

File:
1 edited

Legend:

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

    r2817 r2844  
    3939
    4040#include <string>
    41 #include <vector>
    4241#include <map>
    43 #include <cassert>
    44 #include "Clock.h"
     42#include "CorePrereqs.h"
    4543
    4644namespace orxonox
     
    6260    class _CoreExport GameState
    6361    {
    64         friend class RootGameState;
    65         // Hack
    6662        friend class Game;
    6763
     
    7167            Gives information about what the GameState is currently doing
    7268        */
    73         struct Operations
     69        struct State
    7470        {
    75             unsigned active    : 1;
    76             unsigned entering  : 1;
    77             unsigned leaving  : 1;
    78             unsigned running   : 1;
    79             unsigned suspended : 1;
     71            unsigned active       : 1;
     72            unsigned activating   : 1;
     73            unsigned deactivating : 1;
     74            unsigned updating     : 1;
     75            unsigned suspended    : 1;
    8076        };
    8177
     
    8581
    8682        const std::string& getName() const { return name_; }
    87         const Operations getOperation() const { return this->operation_; }
    88         bool isInSubtree(GameState* state) const;
    89 
    90         GameState* getState(const std::string& name);
    91         GameState* getRoot();
    92         //! Returns the currently active game state
    93         virtual GameState* getCurrentState();
    94 
    95         virtual void requestState(const std::string& name);
     83        const State getActivity() const    { return this->activity_; }
     84        GameState* getParent() const       { return this->parent_; }
    9685
    9786        void addChild(GameState* state);
    9887        void removeChild(GameState* state);
    99         void removeChild(const std::string& name);
    10088
    10189    protected:
    102         virtual void enter() = 0;
    103         virtual void leave() = 0;
    104         virtual void ticked(const Clock& time) = 0;
    105 
    106         GameState* getActiveChild() { return this->activeChild_; }
    107 
    108         void tickChild(const Clock& time) { if (this->getActiveChild()) this->getActiveChild()->tick(time); }
    109 
    110         GameState* getParent() const     { return this->parent_; }
    111         void setParent(GameState* state) { this->parent_ = state; }
     90        virtual void activate() = 0;
     91        virtual void deactivate() = 0;
     92        virtual void update(const Clock& time) = 0;
    11293
    11394    private:
    114         //! Performs a transition to 'destination'
    115         virtual void makeTransition(GameState* source, GameState* destination);
    116 
    117         void grandchildAdded(GameState* child, GameState* grandchild);
    118         void grandchildRemoved(GameState* grandchild);
    119 
    120         void tick(const Clock& time);
    121         void activate();
    122         void deactivate();
     95        void setParent(GameState* state) { this->parent_ = state; }
     96        void setActivity(State activity);
     97        void activateInternal();
     98        void deactivateInternal();
     99        void updateInternal(const Clock& time);
    123100
    124101        const std::string                        name_;
    125         Operations                               operation_;
     102        State                                    activity_;
    126103        GameState*                               parent_;
    127         GameState*                               activeChild_;
    128         //bool                                     bPauseParent_;
    129         std::map<std::string, GameState*>        allChildren_;
    130         std::map<GameState*, GameState*>         grandchildrenToChildren_;
     104        std::map<std::string, GameState*>        children_;
    131105    };
    132106}
Note: See TracChangeset for help on using the changeset viewer.