Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1688 for code/branches/gui/src


Ignore:
Timestamp:
Aug 31, 2008, 5:50:42 PM (16 years ago)
Author:
rgrieder
Message:

Modified the GameState hierarchy so that you can get the parent with the actual type by calling getParent().

Location:
code/branches/gui/src
Files:
2 deleted
16 edited

Legend:

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

    r1674 r1688  
    163163  // game states
    164164  class GameState;
     165  template <class ParentType>
     166  class GameStateTyped;
    165167  class RootGameState;
    166168
  • code/branches/gui/src/core/GameState.cc

    r1674 r1688  
    4545    GameState::GameState(const std::string& name)
    4646        : name_(name)
    47         , parent_(0)
     47        //, parent_(0)
    4848        , activeChild_(0)
    49         //, bPauseParent_(false)
     49        //, bPausegetParent()(false)
    5050    {
    5151        Operations temp = {false, false, false, false, false};
     
    103103
    104104        // mark us as parent
    105         state->parent_ = this;
     105        state->setParent(this);
    106106    }
    107107
     
    178178        this->allChildren_[grandchild->getName()] = grandchild;
    179179        this->grandchildrenToChildren_[grandchild] = child;
    180         if (this->parent_)
    181             this->parent_->grandchildAdded(this, grandchild);
     180        if (this->getParent())
     181            this->getParent()->grandchildAdded(this, grandchild);
    182182    }
    183183
     
    196196        this->allChildren_.erase(grandchild->getName());
    197197        this->grandchildrenToChildren_.erase(grandchild);
    198         if (this->parent_)
    199             this->parent_->grandchildRemoved(grandchild);
     198        if (this->getParent())
     199            this->getParent()->grandchildRemoved(grandchild);
    200200    }
    201201
     
    208208    GameState* GameState::getState(const std::string& name)
    209209    {
    210         if (this->parent_)
    211             return this->parent_->getState(name);
     210        if (this->getParent())
     211            return this->getParent()->getState(name);
    212212        else
    213213        {
     
    227227    GameState* GameState::getRoot()
    228228    {
    229         if (this->parent_)
    230             return this->parent_->getRoot();
     229        if (this->getParent())
     230            return this->getParent()->getRoot();
    231231        else
    232232            return this;
  • code/branches/gui/src/core/GameState.h

    r1686 r1688  
    4141#include <vector>
    4242#include <map>
     43#include <cassert>
    4344#include "util/Integers.h"
    4445#include "Clock.h"
     
    6364    {
    6465        friend class RootGameState;
     66        template <class ParentType>
     67        friend class GameStateTyped;
    6568
    6669    public:
     
    7982
    8083    public:
    81         GameState(const std::string& name);
    8284        virtual ~GameState();
    8385
     
    8890        GameState* getState(const std::string& name);
    8991        GameState* getRoot();
    90         GameState* getParent() const { return this->parent_; }
    9192        //! Returns the currently active game state
    9293        virtual GameState* getCurrentState();
     
    107108        void tickChild(const Clock& time) { if (this->getActiveChild()) this->getActiveChild()->tick(time); }
    108109
     110        virtual GameState* getParent() const = 0;
     111        virtual void setParent(GameState* state) = 0;
     112
    109113    private:
     114        // 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);
     117
    110118        //! Performs a transition to 'destination'
    111119        virtual void makeTransition(GameState* source, GameState* destination);
     
    120128        const std::string                   name_;
    121129        Operations                          operation_;
    122         GameState*                          parent_;
    123130        GameState*                          activeChild_;
    124131        //bool                                bPauseParent_;
     
    126133        std::map<GameState*, GameState*>    grandchildrenToChildren_;
    127134    };
     135
     136    template <class ParentType>
     137    class GameStateTyped : public GameState
     138    {
     139    public:
     140        GameStateTyped(const std::string& name) : GameState(name) { }
     141        virtual ~GameStateTyped() { }
     142
     143        ParentType* getParent() const
     144            { return parent_; }
     145
     146    protected:
     147        void setParent(GameState* state)
     148        {
     149            assert(dynamic_cast<ParentType*>(state) != 0);
     150            this->parent_ = dynamic_cast<ParentType*>(state);
     151        }
     152
     153    private:
     154        ParentType* parent_;
     155    };
    128156}
    129157
  • code/branches/gui/src/core/RootGameState.cc

    r1674 r1688  
    3939
    4040    RootGameState::RootGameState(const std::string& name)
    41         : GameState(name)
     41        : GameStateTyped<GameState>(name)
    4242        , stateRequest_("")
    4343    {
  • code/branches/gui/src/core/RootGameState.h

    r1674 r1688  
    3535namespace orxonox
    3636{
    37     class _CoreExport RootGameState : public GameState
     37    class _CoreExport RootGameState : public GameStateTyped<GameState>
    3838    {
    3939    public:
  • code/branches/gui/src/orxonox/Main.cc

    r1672 r1688  
    130130    GSClient client;
    131131    GSGUI gui;
    132     GSIO io;
    133132    GSIOConsole ioConsole;
    134133
     
    139138    graphics.addChild(&gui);
    140139
    141     root.addChild(&io);
    142     io.addChild(&ioConsole);
     140    root.addChild(&ioConsole);
    143141
    144142    root.feedCommandLine(argc, argv);
  • code/branches/gui/src/orxonox/OrxonoxPrereqs.h

    r1674 r1688  
    120120    //gui
    121121    class GUIManager;
     122
     123    // game states
     124    class GSRoot;
     125    class GSGraphics;
     126    class GSIO;
     127    class GSIOConsole;
     128    class GSLevel;
     129    class GSStandalone;
     130    class GSServer;
     131    class GSClient;
     132    class GSGUI;
    122133}
    123134
  • code/branches/gui/src/orxonox/gamestates/GSGUI.cc

    r1686 r1688  
    3939{
    4040    GSGUI::GSGUI()
    41         : GameState("gui")
     41        : GameStateTyped<GSGraphics>("gui")
    4242    {
    4343    }
     
    4949    void GSGUI::enter()
    5050    {
     51        guiManager_ = getParent()->getGUIManager();
     52
    5153        // show main menu
    52         GUIManager::getInstance().showGUI("MainMenu", 0);
    53         GraphicsEngine::getInstance().getViewport()->setCamera(GUIManager::getInstance().getCamera());
     54        guiManager_->showGUI("MainMenu", 0);
     55        getParent()->getViewport()->setCamera(guiManager_->getCamera());
    5456    }
    5557
    5658    void GSGUI::leave()
    5759    {
    58         GUIManager::getInstance().hideGUI();
     60        guiManager_->hideGUI();
    5961    }
    6062
     
    6264    {
    6365        // tick CEGUI
    64         GUIManager::getInstance().tick(time.getDeltaTime());
     66        guiManager_->tick(time.getDeltaTime());
    6567
    6668        this->tickChild(time);
  • code/branches/gui/src/orxonox/gamestates/GSGUI.h

    r1674 r1688  
    3232#include "OrxonoxPrereqs.h"
    3333#include "core/GameState.h"
     34#include "GSGraphics.h"
    3435
    3536namespace orxonox
    3637{
    37     class _OrxonoxExport GSGUI : public GameState
     38    class _OrxonoxExport GSGUI : public GameStateTyped<GSGraphics>
    3839    {
    3940    public:
     
    4546        void leave();
    4647        void ticked(const Clock& time);
     48
     49        GUIManager* guiManager_;
    4750    };
    4851}
  • code/branches/gui/src/orxonox/gamestates/GSGraphics.cc

    r1686 r1688  
    5757{
    5858    GSGraphics::GSGraphics()
    59         : GameState("graphics")
     59        : GameStateTyped<GSRoot>("graphics")
    6060        , ogreRoot_(0)
    6161        , inputManager_(0)
     
    7777    void GSGraphics::setConfigValues()
    7878    {
    79         SetConfigValue(resourceFile_,    "resources.cfg").description("Location of the resources file in the data path.");
     79        SetConfigValue(resourceFile_, "resources.cfg").description("Location of the resources file in the data path.");
    8080        SetConfigValue(statisticsRefreshCycle_, 200000).description("Sets the time in microseconds interval at which average fps, etc. get updated.");
    8181    }
     
    8585        setConfigValues();
    8686
    87         this->ogreRoot_ = Ogre::Root::getSingletonPtr();
     87        this->ogreRoot_ = getParent()->getOgreRoot();
    8888
    8989        this->declareResources();
     
    9494
    9595        // HACK: temporary:
    96         GraphicsEngine& graphicsEngine = GraphicsEngine::getInstance();
    97         graphicsEngine.renderWindow_ = this->renderWindow_;
    98         graphicsEngine.root_ = this->ogreRoot_;
    99         graphicsEngine.viewport_ = this->viewport_;
     96        GraphicsEngine* graphicsEngine = getParent()->getGraphicsEngine();
     97        graphicsEngine->renderWindow_ = this->renderWindow_;
     98        graphicsEngine->root_          = this->ogreRoot_;
     99        graphicsEngine->viewport_      = this->viewport_;
    100100
    101101
  • code/branches/gui/src/orxonox/gamestates/GSGraphics.h

    r1686 r1688  
    3535#include "core/GameState.h"
    3636#include "core/OrxonoxClass.h"
     37#include "GSRoot.h"
    3738
    3839namespace orxonox
    3940{
    40     class _OrxonoxExport GSGraphics : public GameState, public OrxonoxClass, public Ogre::WindowEventListener
     41    class _OrxonoxExport GSGraphics : public GameStateTyped<GSRoot>, public OrxonoxClass, public Ogre::WindowEventListener
    4142    {
    4243        friend class ClassIdentifier<GSGraphics>;
     
    4445        GSGraphics();
    4546        ~GSGraphics();
     47
     48        Ogre::Viewport* getViewport() { return this->viewport_; }
     49        GUIManager* getGUIManager() { return this->guiManager_; }
    4650
    4751    private:
  • code/branches/gui/src/orxonox/gamestates/GSIOConsole.cc

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

    r1674 r1688  
    3333#include <OgrePrerequisites.h>
    3434#include "core/GameState.h"
     35#include "GSRoot.h"
    3536
    3637namespace orxonox
    3738{
    38     class _OrxonoxExport GSIOConsole : public GameState
     39    class _OrxonoxExport GSIOConsole : public GameStateTyped<GSRoot>
    3940    {
    4041    public:
  • code/branches/gui/src/orxonox/gamestates/GSLevel.cc

    r1686 r1688  
    4545{
    4646    GSLevel::GSLevel(const std::string& name)
    47         : GameState(name)
     47        : GameStateTyped<GSGraphics>(name)
    4848        , timeFactor_(1.0f)
    4949        , sceneManager_(0)
     
    6868
    6969        // create Ogre SceneManager for the level
    70         this->sceneManager_ = GraphicsEngine::getInstance().getOgreRoot()->
    71             createSceneManager(Ogre::ST_GENERIC, "LevelSceneManager");
     70        this->sceneManager_ = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC, "LevelSceneManager");
    7271        COUT(4) << "Created SceneManager: " << sceneManager_->getName() << std::endl;
     72
     73        // temporary hack
    7374        GraphicsEngine::getInstance().setLevelSceneManager(this->sceneManager_);
    7475
     
    9899        delete this->radar_;
    99100
    100         GraphicsEngine::getInstance().getOgreRoot()->destroySceneManager(this->sceneManager_);
     101        Ogre::Root::getSingleton().destroySceneManager(this->sceneManager_);
    101102
    102103        inputState_->setHandler(0);
  • code/branches/gui/src/orxonox/gamestates/GSLevel.h

    r1686 r1688  
    3333#include <OgrePrerequisites.h>
    3434#include "core/GameState.h"
     35#include "GSGraphics.h"
    3536
    3637namespace orxonox
    3738{
    38     class _OrxonoxExport GSLevel : public GameState
     39    class _OrxonoxExport GSLevel : public GameStateTyped<GSGraphics>
    3940    {
    4041    public:
  • code/branches/gui/src/orxonox/gamestates/GSRoot.h

    r1686 r1688  
    4949        { requestState("root"); }
    5050
     51        Ogre::Root* getOgreRoot() { return this->ogreRoot_; }
     52        GraphicsEngine* getGraphicsEngine() { return this->graphicsEngine_; }
     53
    5154    private:
    5255        void enter();
Note: See TracChangeset for help on using the changeset viewer.