Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1689


Ignore:
Timestamp:
Aug 31, 2008, 6:07:57 PM (16 years ago)
Author:
rgrieder
Message:
  • renamed:

GameState —> GameStateBase
GameStateTyped<T> —> GameState

  • moved command line parsing from GSRoot to RootGameState.
Location:
code/branches/gui/src
Files:
16 edited

Legend:

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

    r1688 r1689  
    162162
    163163  // game states
     164  class GameStateBase;
     165  template <class ParentType>
    164166  class GameState;
    165   template <class ParentType>
    166   class GameStateTyped;
    167167  class RootGameState;
    168168
  • code/branches/gui/src/core/GameState.cc

    r1688 r1689  
    3030@file
    3131@brief
    32     Implementation of GameState class.
     32    Implementation of GameStateBase class.
    3333*/
    3434
     
    4343        Constructor only initialises variables and sets the name permanently.
    4444    */
    45     GameState::GameState(const std::string& name)
     45    GameStateBase::GameStateBase(const std::string& name)
    4646        : name_(name)
    4747        //, parent_(0)
     
    5757        Destructor only checks that we don't delete an active state.
    5858    */
    59     GameState::~GameState()
     59    GameStateBase::~GameStateBase()
    6060    {
    6161        OrxAssert(!isInSubtree(getCurrentState()), "Deleting an active GameState is a very bad idea..");
     
    6969        The state to be added.
    7070    */
    71     void GameState::addChild(GameState* state)
     71    void GameStateBase::addChild(GameStateBase* 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, GameState*>::const_iterator it = state->allChildren_.begin();
     76        for (std::map<std::string, GameStateBase*>::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, GameState*>::const_iterator it = state->allChildren_.begin();
     98        for (std::map<std::string, GameStateBase*>::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 GameState::removeChild(GameState* state)
    116     {
    117         std::map<GameState*, GameState*>::iterator it = this->grandchildrenToChildren_.find(state);
     115    void GameStateBase::removeChild(GameStateBase* state)
     116    {
     117        std::map<GameStateBase*, GameStateBase*>::iterator it = this->grandchildrenToChildren_.find(state);
    118118        if (it != this->grandchildrenToChildren_.end())
    119119        {
     
    127127            else
    128128            {
    129                 for (std::map<GameState*, GameState*>::const_iterator it = state->grandchildrenToChildren_.begin();
     129                for (std::map<GameStateBase*, GameStateBase*>::const_iterator it = state->grandchildrenToChildren_.begin();
    130130                    it != state->grandchildrenToChildren_.end(); ++it)
    131131                    this->grandchildRemoved(it->first);
     
    150150    */
    151151
    152     void GameState::removeChild(const std::string& name)
    153     {
    154         GameState* state = getState(name);
     152    void GameStateBase::removeChild(const std::string& name)
     153    {
     154        GameStateBase* state = getState(name);
    155155        if (state)
    156156        {
     
    173173        The child that has been added.
    174174    */
    175     inline void GameState::grandchildAdded(GameState* child, GameState* grandchild)
     175    inline void GameStateBase::grandchildAdded(GameStateBase* child, GameStateBase* grandchild)
    176176    {
    177177        // fill the two maps correctly.
     
    191191        The child that has been removed.
    192192    */
    193     inline void GameState::grandchildRemoved(GameState* grandchild)
     193    inline void GameStateBase::grandchildRemoved(GameStateBase* grandchild)
    194194    {
    195195        // adjust the two maps correctly.
     
    206206        Remember that the every node has a map with all its child nodes.
    207207    */
    208     GameState* GameState::getState(const std::string& name)
     208    GameStateBase* GameStateBase::getState(const std::string& name)
    209209    {
    210210        if (this->getParent())
     
    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, GameState*>::const_iterator it = this->allChildren_.find(name);
     218            std::map<std::string, GameStateBase*>::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     GameState* GameState::getRoot()
     227    GameStateBase* GameStateBase::getRoot()
    228228    {
    229229        if (this->getParent())
     
    240240        have active children itself. Many states can be active at once.
    241241    */
    242     GameState* GameState::getCurrentState()
     242    GameStateBase* GameStateBase::getCurrentState()
    243243    {
    244244        if (this->operation_.active)
     
    262262        Determines whether 'state' is in this subtree, including this node.
    263263    */
    264     bool GameState::isInSubtree(GameState* state) const
     264    bool GameStateBase::isInSubtree(GameStateBase* 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 GameState::requestState(const std::string& name)
     277    void GameStateBase::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 GameState::makeTransition(GameState* source, GameState* destination)
     288    void GameStateBase::makeTransition(GameStateBase* source, GameStateBase* destination)
    289289    {
    290290        if (source == this->getParent())
     
    308308
    309309        // Check for 'destination' in the children map first
    310         std::map<GameState*, GameState*>::const_iterator it
     310        std::map<GameStateBase*, GameStateBase*>::const_iterator it
    311311            = this->grandchildrenToChildren_.find(destination);
    312312        if (it != this->grandchildrenToChildren_.end())
     
    330330        Activates the state. Only sets bActive_ to true and notifies the parent.
    331331    */
    332     void GameState::activate()
     332    void GameStateBase::activate()
    333333    {
    334334        this->operation_.active = true;
     
    341341        Activates the state. Only sets bActive_ to false and notifies the parent.
    342342    */
    343     void GameState::deactivate()
     343    void GameStateBase::deactivate()
    344344    {
    345345        this->operation_.leaving = true;
     
    358358        This method is not virtual! You cannot override it therefore.
    359359    */
    360     void GameState::tick(const Clock& time)
     360    void GameStateBase::tick(const Clock& time)
    361361    {
    362362        this->operation_.running = true;
  • code/branches/gui/src/core/GameState.h

    r1688 r1689  
    6161        Then Bar stores Foo in map by its name. The other one then maps Foo to Foofoo.
    6262    */
    63     class _CoreExport GameState
     63    class _CoreExport GameStateBase
    6464    {
    6565        friend class RootGameState;
    6666        template <class ParentType>
    67         friend class GameStateTyped;
     67        friend class GameState;
    6868
    6969    public:
     
    8282
    8383    public:
    84         virtual ~GameState();
     84        virtual ~GameStateBase();
    8585
    8686        const std::string& getName() const { return name_; }
    8787        const Operations getOperation() const { return this->operation_; }
    88         bool isInSubtree(GameState* state) const;
     88        bool isInSubtree(GameStateBase* state) const;
    8989
    90         GameState* getState(const std::string& name);
    91         GameState* getRoot();
     90        GameStateBase* getState(const std::string& name);
     91        GameStateBase* getRoot();
    9292        //! Returns the currently active game state
    93         virtual GameState* getCurrentState();
     93        virtual GameStateBase* getCurrentState();
    9494
    9595        virtual void requestState(const std::string& name);
    9696
    97         void addChild(GameState* state);
    98         void removeChild(GameState* state);
     97        void addChild(GameStateBase* state);
     98        void removeChild(GameStateBase* state);
    9999        void removeChild(const std::string& name);
    100100
     
    104104        virtual void ticked(const Clock& time) = 0;
    105105
    106         GameState* getActiveChild() { return this->activeChild_; }
     106        GameStateBase* getActiveChild() { return this->activeChild_; }
    107107
    108108        void tickChild(const Clock& time) { if (this->getActiveChild()) this->getActiveChild()->tick(time); }
    109109
    110         virtual GameState* getParent() const = 0;
    111         virtual void setParent(GameState* state) = 0;
     110        virtual GameStateBase* getParent() const = 0;
     111        virtual void setParent(GameStateBase* state) = 0;
    112112
    113113    private:
    114114        // Making the constructor private ensures that game states
    115         // are always derivates of GameStateTyped<T>. Note the friend declaration above.
    116         GameState(const std::string& name);
     115        // are always derivates of GameState<T>. Note the friend declaration above.
     116        GameStateBase(const std::string& name);
    117117
    118118        //! Performs a transition to 'destination'
    119         virtual void makeTransition(GameState* source, GameState* destination);
     119        virtual void makeTransition(GameStateBase* source, GameStateBase* destination);
    120120
    121         void grandchildAdded(GameState* child, GameState* grandchild);
    122         void grandchildRemoved(GameState* grandchild);
     121        void grandchildAdded(GameStateBase* child, GameStateBase* grandchild);
     122        void grandchildRemoved(GameStateBase* grandchild);
    123123
    124124        void tick(const Clock& time);
     
    126126        void deactivate();
    127127
    128         const std::string                   name_;
    129         Operations                          operation_;
    130         GameState*                          activeChild_;
    131         //bool                                bPauseParent_;
    132         std::map<std::string, GameState*>   allChildren_;
    133         std::map<GameState*, GameState*>    grandchildrenToChildren_;
     128        const std::string                        name_;
     129        Operations                               operation_;
     130        GameStateBase*                           activeChild_;
     131        //bool                                     bPauseParent_;
     132        std::map<std::string, GameStateBase*>    allChildren_;
     133        std::map<GameStateBase*, GameStateBase*> grandchildrenToChildren_;
    134134    };
    135135
     136
    136137    template <class ParentType>
    137     class GameStateTyped : public GameState
     138    class GameState : public GameStateBase
    138139    {
    139140    public:
    140         GameStateTyped(const std::string& name) : GameState(name) { }
    141         virtual ~GameStateTyped() { }
     141        GameState(const std::string& name) : GameStateBase(name) { }
     142        virtual ~GameState() { }
    142143
    143144        ParentType* getParent() const
     
    145146
    146147    protected:
    147         void setParent(GameState* state)
     148        void setParent(GameStateBase* state)
    148149        {
    149150            assert(dynamic_cast<ParentType*>(state) != 0);
  • code/branches/gui/src/core/RootGameState.cc

    r1688 r1689  
    3939
    4040    RootGameState::RootGameState(const std::string& name)
    41         : GameStateTyped<GameState>(name)
     41        : GameState<GameStateBase>(name)
    4242        , stateRequest_("")
    4343    {
     
    5353        the method can assume certain things to be granted (like 'this' is always active).
    5454    */
    55     void RootGameState::makeTransition(GameState* source, GameState* destination)
     55    void RootGameState::makeTransition(GameStateBase* source, GameStateBase* destination)
    5656    {
    5757        if (source != 0)
     
    6868
    6969        // Check for 'destination' in the children map first
    70         std::map<GameState*, GameState*>::const_iterator it
     70        std::map<GameStateBase*, GameStateBase*>::const_iterator it
    7171            = this->grandchildrenToChildren_.find(destination);
    7272        if (it != this->grandchildrenToChildren_.end())
    7373        {
    74             OrxAssert(dynamic_cast<GameState*>(it->second) != 0,
     74            OrxAssert(dynamic_cast<GameStateBase*>(it->second) != 0,
    7575                "There was a mix with RootGameState and GameState, could not cast.");
    76             GameState* child = static_cast<GameState*>(it->second);
     76            GameStateBase* child = static_cast<GameStateBase*>(it->second);
    7777            // child state. Don't use 'state', might be a grandchild!
    7878            this->activeChild_ = child;
     
    8888    void RootGameState::gotoState(const std::string& name)
    8989    {
    90         GameState* request = getState(name);
     90        GameStateBase* request = getState(name);
    9191        if (request)
    9292        {
    93             GameState* current = getCurrentState();
     93            GameStateBase* current = getCurrentState();
    9494            if (current)
    9595            {
     
    127127        State to start with (usually main menu or specified by command line)
    128128    */
    129     void RootGameState::start()
     129    void RootGameState::start(int argc, char** argv)
    130130    {
     131        parseCommandLine(argc, argv);
     132
    131133        this->activate();
    132134
     
    149151        this->deactivate();
    150152    }
     153
     154    void RootGameState::parseCommandLine(int argc, char** argv)
     155    {
     156        std::vector<std::string> args;
     157        for (int i = 1; i < argc; ++i)
     158            args.push_back(argv[i]);
     159
     160        try
     161        {
     162            orxonox::CommandLine::parse(args);
     163        }
     164        catch (orxonox::ArgumentException& ex)
     165        {
     166            COUT(1) << ex.what() << std::endl;
     167            COUT(0) << "Usage:" << std::endl << "orxonox " << CommandLine::getUsageInformation() << std::endl;
     168        }
     169    }
    151170}
  • code/branches/gui/src/core/RootGameState.h

    r1688 r1689  
    3535namespace orxonox
    3636{
    37     class _CoreExport RootGameState : public GameStateTyped<GameState>
     37    class _CoreExport RootGameState : public GameState<GameStateBase>
    3838    {
    3939    public:
     
    4242
    4343        void requestState(const std::string& name);
    44         void start();
     44        void start(int argc, char** argv);
    4545
    4646    private:
    47         void makeTransition(GameState* source, GameState* destination);
     47        void makeTransition(GameStateBase* source, GameStateBase* destination);
    4848        void gotoState(const std::string& name);
     49
     50        void parseCommandLine(int argc, char** argv);
    4951
    5052        std::string           stateRequest_;
  • code/branches/gui/src/orxonox/Main.cc

    r1688 r1689  
    4848#include "gamestates/GSClient.h"
    4949#include "gamestates/GSGUI.h"
    50 #include "gamestates/GSIO.h"
    5150#include "gamestates/GSIOConsole.h"
    5251
     
    9089    SignalHandler::getInstance()->doCatch(argv[0], "orxonox.log");
    9190
    92 
    93     /*GameState* state1 = new GameState("state1");
    94     GameState* state2 = new GameState("state2");
    95     GameState* state3 = new GameState("state3");
    96     GameState* state4 = new GameState("state4");
    97     GameState* state5 = new GameState("state5");
    98     GameState* state6 = new GameState("state6");
    99 
    100     state1->addChild(state4);
    101     state1->addChild(state6);
    102     state2->addChild(state3);
    103     state2->addChild(state5);
    104     state6->addChild(state2);
    105 
    106     state6->removeChild("state2");
    107 
    108     state5->requestState("state3");
    109     COUT(2) << std::endl;
    110     state2->requestState("state2");
    111     COUT(2) << std::endl;
    112     state2->requestState("state1");
    113     COUT(2) << std::endl;
    114     state4->requestState("state3");
    115     COUT(2) << std::endl;
    116     state1->requestState("state4");
    117     COUT(2) << std::endl;
    118     state1->requestState("state2");
    119     COUT(2) << std::endl;
    120     state1->requestState("stat");
    121     COUT(2) << std::endl;
    122     state1->requestState("state5");
    123     COUT(2) << std::endl;*/
    124 
    125 
    12691    GSRoot root;
    12792    GSGraphics graphics;
     
    140105    root.addChild(&ioConsole);
    141106
    142     root.feedCommandLine(argc, argv);
    143     root.start();
     107    root.start(argc, argv);
    144108
    145109    return 0;
  • code/branches/gui/src/orxonox/gamestates/GSGUI.cc

    r1688 r1689  
    3939{
    4040    GSGUI::GSGUI()
    41         : GameStateTyped<GSGraphics>("gui")
     41        : GameState<GSGraphics>("gui")
    4242    {
    4343    }
  • code/branches/gui/src/orxonox/gamestates/GSGUI.h

    r1688 r1689  
    3636namespace orxonox
    3737{
    38     class _OrxonoxExport GSGUI : public GameStateTyped<GSGraphics>
     38    class _OrxonoxExport GSGUI : public GameState<GSGraphics>
    3939    {
    4040    public:
  • code/branches/gui/src/orxonox/gamestates/GSGraphics.cc

    r1688 r1689  
    5757{
    5858    GSGraphics::GSGraphics()
    59         : GameStateTyped<GSRoot>("graphics")
     59        : GameState<GSRoot>("graphics")
    6060        , ogreRoot_(0)
    6161        , inputManager_(0)
  • code/branches/gui/src/orxonox/gamestates/GSGraphics.h

    r1688 r1689  
    3939namespace orxonox
    4040{
    41     class _OrxonoxExport GSGraphics : public GameStateTyped<GSRoot>, public OrxonoxClass, public Ogre::WindowEventListener
     41    class _OrxonoxExport GSGraphics : public GameState<GSRoot>, public OrxonoxClass, public Ogre::WindowEventListener
    4242    {
    4343        friend class ClassIdentifier<GSGraphics>;
  • code/branches/gui/src/orxonox/gamestates/GSIOConsole.cc

    r1688 r1689  
    4242{
    4343    GSIOConsole::GSIOConsole()
    44         : GameStateTyped<GSRoot>("ioConsole")
     44        : GameState<GSRoot>("ioConsole")
    4545    {
    4646    }
  • code/branches/gui/src/orxonox/gamestates/GSIOConsole.h

    r1688 r1689  
    3737namespace orxonox
    3838{
    39     class _OrxonoxExport GSIOConsole : public GameStateTyped<GSRoot>
     39    class _OrxonoxExport GSIOConsole : public GameState<GSRoot>
    4040    {
    4141    public:
  • code/branches/gui/src/orxonox/gamestates/GSLevel.cc

    r1688 r1689  
    4545{
    4646    GSLevel::GSLevel(const std::string& name)
    47         : GameStateTyped<GSGraphics>(name)
     47        : GameState<GSGraphics>(name)
    4848        , timeFactor_(1.0f)
    4949        , sceneManager_(0)
  • code/branches/gui/src/orxonox/gamestates/GSLevel.h

    r1688 r1689  
    3737namespace orxonox
    3838{
    39     class _OrxonoxExport GSLevel : public GameStateTyped<GSGraphics>
     39    class _OrxonoxExport GSLevel : public GameState<GSGraphics>
    4040    {
    4141    public:
  • code/branches/gui/src/orxonox/gamestates/GSRoot.cc

    r1686 r1689  
    9191    }
    9292
    93     //SetCommandLineArgument(asdf1, "haha").setShortcut("a").setUsageInformation("1|2|3");
    94     //SetCommandLineArgument(asdf2, 3).setShortcut("b");
    95     //SetCommandLineArgument(asdf3, Vector2()).setShortcut("c");
    96     //SetCommandLineArgument(adsf4, 1.4f).setShortcut("d");
    97     //SetCommandLineSwitch(showGraphics).setShortcut("g");
    98 
    99     void GSRoot::feedCommandLine(int argc, char** argv)
    100     {
    101         std::vector<std::string> args;
    102         for (int i = 1; i < argc; ++i)
    103             args.push_back(argv[i]);
    104 
    105         //std::string line = "-a --asdf3 (3,3) -d -5 -b - 5.4";
    106         //SubString tokens(line, " ", " ", false, 92, false, 34, true, 40, 41, false, 0);
    107 
    108         try
    109         {
    110             orxonox::CommandLine::parse(args);
    111             //CommandLine::parse(tokens.getAllStrings());
    112         }
    113         catch (orxonox::ArgumentException& ex)
    114         {
    115             COUT(1) << ex.what() << std::endl;
    116             COUT(0) << "Usage:" << std::endl << "orxonox " << CommandLine::getUsageInformation() << std::endl;
    117         }
    118     }
    119 
    12093    void GSRoot::enter()
    12194    {
     
    165138
    166139        // add console commands
    167         FunctorMember01<GameState, const std::string&>* functor2 = createFunctor(&GameState::requestState);
     140        FunctorMember01<GameStateBase, const std::string&>* functor2 = createFunctor(&GameStateBase::requestState);
    168141        functor2->setObject(this);
    169142        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor2, "selectGameState"));
  • code/branches/gui/src/orxonox/gamestates/GSRoot.h

    r1688 r1689  
    4444        ~GSRoot();
    4545
    46         void feedCommandLine(int argc, char** argv);
    47 
    4846        void exitGame()
    4947        { requestState("root"); }
Note: See TracChangeset for help on using the changeset viewer.