Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1672


Ignore:
Timestamp:
Aug 27, 2008, 10:21:39 PM (16 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
Location:
code/branches/gui
Files:
2 added
27 edited

Legend:

Unmodified
Added
Removed
  • code/branches/gui/src/core/CMakeLists.txt

    r1665 r1672  
    1010  OutputBuffer.cc
    1111  OutputHandler.cc
     12  RootGameState.cc
    1213  Script.cc
    1314  SignalHandler.cc
  • code/branches/gui/src/core/CorePrereqs.h

    r1663 r1672  
    161161  class XMLPortParamContainer;
    162162
     163  // game states
     164  class BaseGameState;
     165  class GameState;
     166  class RootGameState;
     167
    163168  // input
    164169  class BaseCommand;
  • code/branches/gui/src/core/GameState.cc

    r1670 r1672  
    4646    GameState::GameState(const std::string& name)
    4747        : name_(name)
    48         , bPauseParent_(false)
    49         //, bActive_(false)
    50         //, bSuspended_(false)
    51         //, bRunning_(false)
    52         , scheduledTransition_(0)
    5348        , parent_(0)
    5449        , activeChild_(0)
     50        //, bPauseParent_(false)
    5551    {
    5652        Operations temp = {false, false, false, false, false};
     
    6460    GameState::~GameState()
    6561    {
    66         if (this->operation_.active)
    67         {
    68             if (this->parent_)
    69                 this->requestState(this->parent_->getName());
    70             else
    71                 this->requestState("");
    72         }
     62        OrxAssert(!isInSubtree(getCurrentState()), "Deleting an active GameState is a very bad idea..");
    7363    }
    7464
     
    8878            it != state->allChildren_.end(); ++it)
    8979        {
    90             if (this->checkState(it->second->getName()))
     80            if (this->getState(it->second->getName()))
    9181            {
    9282                ThrowException(GameState, "Cannot add a GameState to the hierarchy twice.");
     
    9484            }
    9585        }
    96         if (this->checkState(state->name_))
     86        if (this->getState(state->name_))
    9787        {
    9888            ThrowException(GameState, "Cannot add a GameState to the hierarchy twice.");
     
    10999        for (std::map<std::string, GameState*>::const_iterator it = state->allChildren_.begin();
    110100            it != state->allChildren_.end(); ++it)
    111         {
    112             this->allChildren_[it->second->getName()] = it->second;
    113             this->grandchildrenToChildren_[it->second] = state;
    114             if (this->parent_)
    115                 this->parent_->grandchildAdded(this, it->second);
    116         }
     101            this->grandchildAdded(state, it->second);
    117102        // merge 'state' into this tree
    118         this->allChildren_[state->name_] = state;
    119         this->grandchildrenToChildren_[state] = state;
    120         if (this->parent_)
    121             this->parent_->grandchildAdded(this, state);
     103        this->grandchildAdded(state, state);
    122104
    123105        // mark us as parent
     
    137119        if (it != this->grandchildrenToChildren_.end())
    138120        {
    139             if (state->getOperation().active)
     121            if (state->isInSubtree(getCurrentState()))
    140122            {
    141                 ThrowException(GameState, "Cannot remove active game state child '"
     123                ThrowException(GameState, "Cannot remove an active game state child '"
    142124                    + state->getName() + "' from '" + name_ + "'.");
    143                 //COUT(2) << "Warning: Cannot remove active game state child '" << state->getName()
     125                //COUT(2) << "Warning: Cannot remove an active game state child '" << state->getName()
    144126                //    << "' from '" << name_ << "'." << std::endl;
    145127            }
     
    148130                for (std::map<GameState*, GameState*>::const_iterator it = state->grandchildrenToChildren_.begin();
    149131                    it != state->grandchildrenToChildren_.end(); ++it)
    150                 {
    151132                    this->grandchildRemoved(it->first);
    152                 }
    153133                this->grandchildRemoved(state);
    154134            }
     
    157137        {
    158138            ThrowException(GameState, "Game state '" + name_ + "' doesn't have a child named '"
    159                 + state->getName() + "'. Removal skipped.");
     139                + state->getName() + "'.");
    160140            //COUT(2) << "Warning: Game state '" << name_ << "' doesn't have a child named '"
    161141            //    << state->getName() << "'. Removal skipped." << std::endl;
     
    173153    void GameState::removeChild(const std::string& name)
    174154    {
    175         GameState* state = checkState(name);
     155        GameState* state = getState(name);
    176156        if (state)
    177157        {
     
    194174        The child that has been added.
    195175    */
    196     void GameState::grandchildAdded(GameState* child, GameState* grandchild)
     176    inline void GameState::grandchildAdded(GameState* child, GameState* grandchild)
    197177    {
    198178        // fill the two maps correctly.
     
    212192        The child that has been removed.
    213193    */
    214     void GameState::grandchildRemoved(GameState* grandchild)
     194    inline void GameState::grandchildRemoved(GameState* grandchild)
    215195    {
    216196        // adjust the two maps correctly.
     
    227207        Remember that the every node has a map with all its child nodes.
    228208    */
    229     GameState* GameState::checkState(const std::string& name)
     209    GameState* GameState::getState(const std::string& name)
    230210    {
    231211        if (this->parent_)
    232             return this->parent_->checkState(name);
     212            return this->parent_->getState(name);
    233213        else
    234214        {
     
    244224    /**
    245225    @brief
     226        Returns the root node of the tree.
     227    */
     228    GameState* GameState::getRoot()
     229    {
     230        if (this->parent_)
     231            return this->parent_->getRoot();
     232        else
     233            return this;
     234    }
     235
     236    /**
     237    @brief
    246238        Returns the current active state.
    247239    @remarks
     
    260252        else
    261253        {
    262             if (this->parent_)
    263                 return this->parent_->getCurrentState();
     254            if (this->getParent())
     255                return this->getParent()->getCurrentState();
    264256            else
    265257                return 0;
     
    269261    /**
    270262    @brief
    271         Returns the root node of the tree.
    272     */
    273     GameState* GameState::getRootNode()
    274     {
    275         if (this->parent_)
    276             return this->parent_->getRootNode();
    277         else
    278             return this;
     263        Determines whether 'state' is in this subtree, including this node.
     264    */
     265    bool GameState::isInSubtree(GameState* state) const
     266    {
     267        return (grandchildrenToChildren_.find(state) != grandchildrenToChildren_.end()
     268                || state == this);
    279269    }
    280270
     
    288278    void GameState::requestState(const std::string& name)
    289279    {
    290         GameState* current = getCurrentState();
    291         if (current != 0 && (current->getOperation().entering || current->getOperation().leaving))
    292         {
    293             ThrowException(GameState, "Making state transitions during enter()/leave() is forbidden.");
    294         }
    295         //if (name == "")
    296         //{
    297         //    // user would like to leave every state.
    298         //    if (current)
    299         //    {
    300         //        // Deactivate all states but root
    301         //        GameState* root = getRootNode();
    302         //        current->makeTransition(root);
    303         //        //// Kick root too
    304         //        //assert(!(root->getOperation().entering || root->getOperation().leaving));
    305         //        //if (root->operation_.running)
    306         //        //    root->scheduledTransition_ = 0;
    307         //        //else
    308         //        //    root->deactivate();
    309         //    }
    310         //}
    311         else
    312         {
    313             GameState* request = checkState(name);
    314             if (request)
    315             {
    316                 if (current)
    317                 {
    318                     // There is already an active state
    319                     current->makeTransition(request);
    320                 }
    321                 else
    322                 {
    323                     // no active state --> we have to activate the root node first.
    324                     GameState* root = getRootNode();
    325                     root->activate();
    326                     root->makeTransition(request);
    327                 }
    328             }
    329             else
    330             {
    331                 COUT(2) << "Warning: GameState '" << name << "' doesn't exist." << std::endl;
    332             }
    333         }
     280        assert(getRoot());
     281        getRoot()->requestState(name);
    334282    }
    335283
     
    339287        the method can assume certain things to be granted (like 'this' is always active).
    340288    */
    341     void GameState::makeTransition(GameState* state)
    342     {
    343         // we're always already active
    344         assert(this->operation_.active);
    345 
    346         if (state == this)
     289    void GameState::makeTransition(GameState* source, GameState* destination)
     290    {
     291        if (source == this->getParent())
     292        {
     293            // call is from the parent
     294            this->activate();
     295        }
     296        else if (source == 0)
     297        {
     298            // call was just started by root
     299            // don't do anyting yet
     300        }
     301        else
     302        {
     303            // call is from a child
     304            this->activeChild_ = 0;
     305        }
     306
     307        if (destination == this)
    347308            return;
    348309
    349         // Check for 'state' in the children map first
    350         std::map<GameState*, GameState*>::const_iterator it = this->grandchildrenToChildren_.find(state);
     310        // Check for 'destination' in the children map first
     311        std::map<GameState*, GameState*>::const_iterator it
     312            = this->grandchildrenToChildren_.find(destination);
    351313        if (it != this->grandchildrenToChildren_.end())
    352314        {
    353315            // child state. Don't use 'state', might be a grandchild!
    354             it->second->activate();
    355             it->second->makeTransition(state);
     316            this->activeChild_ = it->second;
     317            it->second->makeTransition(this, destination);
    356318        }
    357319        else
    358320        {
    359321            // parent. We can be sure of this.
    360             assert(this->parent_ != 0);
    361 
    362             // only do the transition if we're not currently running
    363             if (this->operation_.running)
    364             {
    365                 //this->bDeactivationScheduled_ = true;
    366                 this->scheduledTransition_ = state;
    367             }
    368             else
    369             {
    370                 this->deactivate();
    371                 this->parent_->makeTransition(state);
    372             }
    373 
     322            assert(this->getParent() != 0);
     323
     324            this->deactivate();
     325            this->getParent()->makeTransition(this, destination);
    374326        }
    375327    }
     
    381333    void GameState::activate()
    382334    {
    383         if (this->parent_)
    384             this->parent_->activeChild_ = this;
    385335        this->operation_.active = true;
    386336        this->operation_.entering = true;
     
    398348        this->operation_.leaving = false;
    399349        this->operation_.active = false;
    400         if (this->parent_)
    401             this->parent_->activeChild_ = 0;
    402350    }
    403351
     
    411359        This method is not virtual! You cannot override it therefore.
    412360    */
    413     void GameState::tick(float dt)
     361    void GameState::tick(float dt, uint64_t time)
    414362    {
    415363        this->operation_.running = true;
    416         this->ticked(dt);
     364        this->ticked(dt, time);
    417365        this->operation_.running = false;
    418 
    419         if (this->scheduledTransition_)
    420         {
    421             // state was requested to be deactivated when ticked.
    422             this->makeTransition(this->scheduledTransition_);
    423             this->scheduledTransition_ = 0;
    424             this->deactivate();
    425         }
    426     }
    427 
     366    }
    428367}
  • 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}
  • code/branches/gui/src/core/input/InputManager.cc

    r1670 r1672  
    640640
    641641        // check for states to leave
    642         for (std::set<InputState*>::reverse_iterator it = stateLeaveRequests_.rbegin();
    643             it != stateLeaveRequests_.rend(); ++it)
    644         {
    645             (*it)->onLeave();
     642        for (std::set<InputState*>::reverse_iterator rit = stateLeaveRequests_.rbegin();
     643            rit != stateLeaveRequests_.rend(); ++rit)
     644        {
     645            (*rit)->onLeave();
    646646            // just to be sure that the state actually is registered
    647             assert(inputStatesByName_.find((*it)->getName()) != inputStatesByName_.end());
    648 
    649             activeStates_.erase((*it)->getPriority());
     647            assert(inputStatesByName_.find((*rit)->getName()) != inputStatesByName_.end());
     648
     649            activeStates_.erase((*rit)->getPriority());
    650650            _updateActiveStates();
    651651        }
     
    653653
    654654        // check for states to enter
    655         for (std::set<InputState*>::reverse_iterator it = stateEnterRequests_.rbegin();
    656             it != stateEnterRequests_.rend(); ++it)
     655        for (std::set<InputState*>::reverse_iterator rit = stateEnterRequests_.rbegin();
     656            rit != stateEnterRequests_.rend(); ++rit)
    657657        {
    658658            // just to be sure that the state actually is registered
    659             assert(inputStatesByName_.find((*it)->getName()) != inputStatesByName_.end());
    660 
    661             activeStates_[(*it)->getPriority()] = (*it);
     659            assert(inputStatesByName_.find((*rit)->getName()) != inputStatesByName_.end());
     660
     661            activeStates_[(*rit)->getPriority()] = (*rit);
    662662            _updateActiveStates();
    663             (*it)->onEnter();
     663            (*rit)->onEnter();
    664664        }
    665665        stateEnterRequests_.clear();
    666666
    667667        // check for states to destroy
    668         for (std::set<InputState*>::reverse_iterator it = stateDestroyRequests_.rbegin();
    669             it != stateDestroyRequests_.rend(); ++it)
    670         {
    671             _destroyState((*it));
     668        for (std::set<InputState*>::reverse_iterator rit = stateDestroyRequests_.rbegin();
     669            rit != stateDestroyRequests_.rend(); ++rit)
     670        {
     671            _destroyState((*rit));
    672672        }
    673673
  • code/branches/gui/src/orxonox/CMakeLists.txt

    r1665 r1672  
    88  Settings.cc
    99
     10  gamestates/GSClient.cc
    1011  gamestates/GSGraphics.cc
    1112  gamestates/GSGUI.cc
     13  gamestates/GSIO.cc
     14  gamestates/GSIOConsole.cc
    1215  gamestates/GSLevel.cc
    1316  gamestates/GSRoot.cc
     17  gamestates/GSServer.cc
     18  gamestates/GSStandalone.cc
    1419
    1520  gui/GUIManager.cc
  • code/branches/gui/src/orxonox/Main.cc

    r1670 r1672  
    143143
    144144    root.feedCommandLine(argc, argv);
    145     root.requestState("ioConsole");
    146     while (!root.isGameFinished())
    147         root.tick(0.0f);
     145    root.start();
    148146
    149147    return 0;
  • code/branches/gui/src/orxonox/OrxonoxPrereqs.h

    r1663 r1672  
    7575    class GraphicsEngine;
    7676    class Orxonox;
     77    class RootGameState;
    7778    class Settings;
    7879
  • code/branches/gui/src/orxonox/gamestates/GSClient.cc

    r1670 r1672  
    7878    }
    7979
    80     void GSClient::ticked(float dt)
     80    void GSClient::ticked(float dt, uint64_t time)
    8181    {
    82         GSLevel::ticked(dt);
     82        GSLevel::ticked(dt, time);
    8383        client_->tick(dt);
    8484
    85         this->tickChild(dt);
     85        this->tickChild(dt, time);
    8686    }
    8787}
  • code/branches/gui/src/orxonox/gamestates/GSClient.h

    r1670 r1672  
    4646        void enter();
    4747        void leave();
    48         void ticked(float dt);
     48        void ticked(float dt, uint64_t time);
    4949
    5050        network::Client* client_;
  • code/branches/gui/src/orxonox/gamestates/GSGUI.cc

    r1670 r1672  
    5858    }
    5959
    60     void GSGUI::ticked(float dt)
     60    void GSGUI::ticked(float dt, uint64_t time)
    6161    {
    6262        // tick CEGUI
    6363        GUIManager::getInstance().tick(dt);
    6464
    65         this->tickChild(dt);
     65        this->tickChild(dt, time);
    6666    }
    6767}
  • code/branches/gui/src/orxonox/gamestates/GSGUI.h

    r1670 r1672  
    4444        void enter();
    4545        void leave();
    46         void ticked(float dt);
     46        void ticked(float dt, uint64_t time);
    4747
    4848    };
  • code/branches/gui/src/orxonox/gamestates/GSGraphics.cc

    r1670 r1672  
    3434#include <OgreTimer.h>
    3535#include <OgreWindowEventUtilities.h>
     36#include <OgreRenderWindow.h>
    3637
    3738#include "core/ConsoleCommand.h"
    3839#include "core/ConfigValueIncludes.h"
    3940#include "core/input/InputManager.h"
    40 #include "core/TclThreadManager.h"
    4141//#include "core/Core.h"
    4242#include "overlays/console/InGameConsole.h"
     
    4848    GSGraphics::GSGraphics()
    4949        : GameState("graphics")
    50         , timer_(0)
    5150        , debugRefreshTime_(0.0f)
    5251        , inputManager_(0)
    5352        , console_(0)
    5453        , guiManager_(0)
     54        , frameCount_(0)
    5555    {
    5656    }
     
    6767    void GSGraphics::enter()
    6868    {
     69        this->ogreRoot_ = Ogre::Root::getSingletonPtr();
    6970        this->graphicsEngine_ = GraphicsEngine::getInstancePtr();
    7071
     
    8788        guiManager_ = new GUIManager();
    8889        guiManager_->initialise();
    89 
    90         // use the ogre timer class to measure time.
    91         timer_ = new Ogre::Timer();
    9290    }
    9391
    9492    void GSGraphics::leave()
    9593    {
    96         delete this->timer_;
    97 
    9894        delete this->guiManager_;
    9995
     
    10298        delete this->inputManager_;
    10399
     100        this->ogreRoot_->detachRenderTarget(GraphicsEngine::getInstance().getRenderWindow());
     101        delete GraphicsEngine::getInstance().getRenderWindow();
     102        this->ogreRoot_->shutdown
    104103        // TODO: destroy render window
    105104    }
     
    118117        need the time. So we shouldn't run into problems.
    119118    */
    120     void GSGraphics::ticked(float dt)
     119    void GSGraphics::ticked(float dt, uint64_t time)
    121120    {
    122         // note: paramter 'dt' is of no meaning
     121        this->inputManager_->tick(dt);
    123122
    124         Ogre::Root& ogreRoot = Ogre::Root::getSingleton();
     123        this->tickChild(dt, time);
    125124
    126         unsigned long frameCount = 0;
     125        // tick console
     126        this->console_->tick(dt);
    127127
    128         const unsigned long refreshTime = (unsigned long)(debugRefreshTime_ * 1000000.0f);
    129         unsigned long refreshStartTime = 0;
    130         unsigned long tickTime = 0;
    131         unsigned long oldFrameCount = 0;
     128        //// get current time once again
     129        //timeAfterTick = timer_->getMicroseconds();
    132130
    133         unsigned long timeBeforeTick = 0;
    134         unsigned long timeBeforeTickOld = 0;
    135         unsigned long timeAfterTick = 0;
     131        //tickTime += timeAfterTick - timeBeforeTick;
     132        //if (timeAfterTick > refreshStartTime + refreshTime)
     133        //{
     134        //    GraphicsEngine::getInstance().setAverageTickTime(
     135        //        (float)tickTime * 0.001 / (frameCount - oldFrameCount));
     136        //    float avgFPS = (float)(frameCount - oldFrameCount) / (timeAfterTick - refreshStartTime) * 1000000.0;
     137        //    GraphicsEngine::getInstance().setAverageFramesPerSecond(avgFPS);
    136138
    137         // TODO: Update time in seconds every 7 seconds to avoid any overflow (7 secs is very tight)
     139        //    oldFrameCount = frameCount;
     140        //    tickTime = 0;
     141        //    refreshStartTime = timeAfterTick;
     142        //}
    138143
    139         COUT(3) << "Orxonox: Starting the main loop." << std::endl;
     144        // don't forget to call _fireFrameStarted in ogre to make sure
     145        // everything goes smoothly
     146        Ogre::FrameEvent evt;
     147        evt.timeSinceLastFrame = dt;
     148        evt.timeSinceLastEvent = dt; // note: same time, but shouldn't matter anyway
     149        ogreRoot_->_fireFrameStarted(evt);
    140150
    141         try
    142         {
    143             timer_->reset();
    144             while (!this->hasScheduledTransition())
    145             {
    146                 // get current time
    147                 timeBeforeTickOld = timeBeforeTick;
    148                 timeBeforeTick    = timer_->getMicroseconds();
    149                 float dt = (timeBeforeTick - timeBeforeTickOld) / 1000000.0;
     151        // Pump messages in all registered RenderWindows
     152        // This calls the WindowEventListener objects.
     153        Ogre::WindowEventUtilities::messagePump();
     154        // make sure the window stays active even when not focused
     155        // (probably only necessary on windows)
     156        GraphicsEngine::getInstance().setWindowActivity(true);
    150157
    151                 this->inputManager_->tick(dt);
    152                 TclThreadManager::getInstance().tick(dt);
     158        // render
     159        ogreRoot_->_updateAllRenderTargets();
    153160
    154                 this->tickChild(dt);
     161        // again, just to be sure ogre works fine
     162        ogreRoot_->_fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted
    155163
    156                 // tick console
    157                 this->console_->tick(dt);
     164        ++frameCount_;
    158165
    159                 // get current time once again
    160                 timeAfterTick = timer_->getMicroseconds();
    161 
    162                 tickTime += timeAfterTick - timeBeforeTick;
    163                 if (timeAfterTick > refreshStartTime + refreshTime)
    164                 {
    165                     GraphicsEngine::getInstance().setAverageTickTime(
    166                         (float)tickTime * 0.001 / (frameCount - oldFrameCount));
    167                     float avgFPS = (float)(frameCount - oldFrameCount) / (timeAfterTick - refreshStartTime) * 1000000.0;
    168                     GraphicsEngine::getInstance().setAverageFramesPerSecond(avgFPS);
    169 
    170                     oldFrameCount = frameCount;
    171                     tickTime = 0;
    172                     refreshStartTime = timeAfterTick;
    173                 }
    174 
    175                 // don't forget to call _fireFrameStarted in ogre to make sure
    176                 // everything goes smoothly
    177                 Ogre::FrameEvent evt;
    178                 evt.timeSinceLastFrame = dt;
    179                 evt.timeSinceLastEvent = dt; // note: same time, but shouldn't matter anyway
    180                 ogreRoot._fireFrameStarted(evt);
    181 
    182                 // Pump messages in all registered RenderWindows
    183                 // This calls the WindowEventListener objects.
    184                 Ogre::WindowEventUtilities::messagePump();
    185                 // make sure the window stays active even when not focused
    186                 // (probably only necessary on windows)
    187                 GraphicsEngine::getInstance().setWindowActivity(true);
    188 
    189                 // render
    190                 ogreRoot._updateAllRenderTargets();
    191 
    192                 // again, just to be sure ogre works fine
    193                 ogreRoot._fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted
    194 
    195                 ++frameCount;
    196             }
    197         }
    198         catch (std::exception& ex)
    199         {
    200             // something went wrong.
    201             COUT(1) << ex.what() << std::endl;
    202             COUT(1) << "Main loop was stopped by an unhandled exception. Shutting down." << std::endl;
    203         }
     166        //}
     167        //catch (std::exception& ex)
     168        //{
     169        //    // something went wrong.
     170        //    COUT(1) << ex.what() << std::endl;
     171        //    COUT(1) << "Main loop was stopped by an unhandled exception. Shutting down." << std::endl;
     172        //}
    204173    }
    205174}
  • code/branches/gui/src/orxonox/gamestates/GSGraphics.h

    r1670 r1672  
    4848        void enter();
    4949        void leave();
    50         void ticked(float dt);
    51 
    52         Ogre::Timer*          timer_;            //!< Main loop timer
     50        void ticked(float dt, uint64_t time);
    5351
    5452        // config values
    5553        float                 debugRefreshTime_;
    5654
     55        Ogre::Root*           ogreRoot_;
    5756        GraphicsEngine*       graphicsEngine_;   //!< our dearest graphics engine <3
    5857        InputManager*         inputManager_;
    5958        InGameConsole*        console_;
    6059        GUIManager*           guiManager_;
     60
     61
     62        // variables for time statistics
     63        unsigned long         frameCount_;
     64
     65        //const unsigned long refreshTime = (unsigned long)(debugRefreshTime_ * 1000000.0f);
     66        //unsigned long refreshStartTime;
     67        //unsigned long tickTime;
     68        //unsigned long oldFrameCount;
     69
     70        //unsigned long timeBeforeTick;
     71        //unsigned long timeBeforeTickOld;
     72        //unsigned long timeAfterTick;
    6173    };
    6274}
  • code/branches/gui/src/orxonox/gamestates/GSIO.cc

    r1670 r1672  
    5858    }
    5959
    60     void GSIO::ticked(float dt)
     60    void GSIO::ticked(float dt, uint64_t time)
    6161    {
    62         this->tickChild(dt);
     62        this->tickChild(dt, time);
    6363        //Ogre::Root& ogreRoot = Ogre::Root::getSingleton();
    6464
  • code/branches/gui/src/orxonox/gamestates/GSIO.h

    r1670 r1672  
    4545        void enter();
    4646        void leave();
    47         void ticked(float dt);
     47        void ticked(float dt, uint64_t time);
    4848
    4949        //Ogre::Timer*          timer_;            //!< Main loop timer
  • code/branches/gui/src/orxonox/gamestates/GSIOConsole.cc

    r1670 r1672  
    5858    }
    5959
    60     void GSIOConsole::ticked(float dt)
     60    void GSIOConsole::ticked(float dt, uint64_t time)
    6161    {
    62         while (!this->hasScheduledTransition())
    63         {
    64             std::string command;
    65             std::cin >> command;
    66             CommandExecutor::execute(command, true);
    67         }
     62        std::string command;
     63        std::getline(std::cin, command);
     64        CommandExecutor::execute(command, true);
     65       
     66        tickChild(dt, time);
    6867    }
    6968}
  • code/branches/gui/src/orxonox/gamestates/GSIOConsole.h

    r1670 r1672  
    4545        void enter();
    4646        void leave();
    47         void ticked(float dt);
     47        void ticked(float dt, uint64_t time);
    4848    };
    4949}
  • code/branches/gui/src/orxonox/gamestates/GSLevel.cc

    r1670 r1672  
    9696    }
    9797
    98     void GSLevel::ticked(float dt)
     98    void GSLevel::ticked(float dt, uint64_t time)
    9999    {
    100100        // Call those objects that need the real time
  • code/branches/gui/src/orxonox/gamestates/GSLevel.h

    r1670 r1672  
    4949        virtual void enter();
    5050        virtual void leave();
    51         virtual void ticked(float dt);
     51        virtual void ticked(float dt, uint64_t time);
    5252
    5353        void loadLevel();
  • code/branches/gui/src/orxonox/gamestates/GSRoot.cc

    r1670 r1672  
    4141#include "core/Core.h"
    4242#include "core/CommandLine.h"
     43#include "core/TclThreadManager.h"
    4344#include "GraphicsEngine.h"
    4445#include "Settings.h"
     
    4950
    5051    GSRoot::GSRoot()
    51         : GameState("root")
     52        : RootGameState("root")
    5253        , settings_(0)
    5354        , graphicsEngine_(0)
    54         , bExit_(false)
    5555    {
    5656    }
     
    113113        // initialise TCL
    114114        TclBind::getInstance().setDataPath(Settings::getDataPath());
     115        TclThreadManager::getInstance();
    115116
    116117        // initialise graphics engine. Doesn't load the render window yet!
     
    118119        graphicsEngine_->setup();       // creates ogre root and other essentials
    119120
    120         // console commands
    121         FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::loadGame);
    122         functor->setObject(this);
    123         CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "loadGame"));
     121        // add console commands
     122        FunctorMember<GSRoot>* functor1 = createFunctor(&GSRoot::exitGame);
     123        functor1->setObject(this);
     124        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "exit"));
    124125
    125126        // add console commands
    126         functor = createFunctor(&GSRoot::exitGame);
    127         functor->setObject(this);
    128         CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "exit"));
     127        FunctorMember01<GameState, const std::string&>* functor2 = createFunctor(&GameState::requestState);
     128        functor2->setObject(this);
     129        CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor2, "selectGameState"));
    129130    }
    130131
     
    137138    }
    138139
    139     void GSRoot::ticked(float dt)
     140    void GSRoot::ticked(float dt, uint64_t time)
    140141    {
    141         this->tickChild(dt);
    142     }
     142        TclThreadManager::getInstance().tick(dt);
    143143
    144     /**
    145     @brief
    146         Requests a state.
    147     */
    148     void GSRoot::loadGame(const std::string& name)
    149     {
    150         this->requestState(name);
     144        this->tickChild(dt, time);
    151145    }
    152146}
  • code/branches/gui/src/orxonox/gamestates/GSRoot.h

    r1670 r1672  
    3131
    3232#include "OrxonoxPrereqs.h"
    33 #include "core/GameState.h"
     33#include "core/RootGameState.h"
    3434
    3535namespace orxonox
    3636{
    37     class _OrxonoxExport GSRoot : public GameState
     37    class _OrxonoxExport GSRoot : public RootGameState
    3838    {
    3939    public:
     
    4242
    4343        void feedCommandLine(int argc, char** argv);
    44         void loadGame(const std::string& name);
    4544
    4645        void exitGame()
    4746        { requestState("root"); }
    48         bool isGameFinished() { return (this->getActiveChild() == 0); }
    4947
    5048    private:
    5149        void enter();
    5250        void leave();
    53         void ticked(float dt);
     51        void ticked(float dt, uint64_t time);
    5452
    5553        Settings*             settings_;
    56         GraphicsEngine*       graphicsEngine_;   //!< our dearest graphics engine <3
    57         bool                  bExit_;
     54        GraphicsEngine*       graphicsEngine_;   //!< Interface to Ogre
    5855    };
    5956}
    6057
    61 #endif /* _GSGraphics_H__ */
     58#endif /* _GSRoot_H__ */
  • code/branches/gui/src/orxonox/gamestates/GSServer.cc

    r1670 r1672  
    8383    }
    8484
    85     void GSServer::ticked(float dt)
     85    void GSServer::ticked(float dt, uint64_t time)
    8686    {
    87         GSLevel::ticked(dt);
     87        GSLevel::ticked(dt, time);
    8888        server_->tick(dt);
    89         this->tickChild(dt);
     89        this->tickChild(dt, time);
    9090    }
    9191}
  • code/branches/gui/src/orxonox/gamestates/GSServer.h

    r1670 r1672  
    4646        void enter();
    4747        void leave();
    48         void ticked(float dt);
     48        void ticked(float dt, uint64_t time);
    4949
    5050        network::Server*      server_;
  • code/branches/gui/src/orxonox/gamestates/GSStandalone.cc

    r1670 r1672  
    7070    }
    7171
    72     void GSStandalone::ticked(float dt)
     72    void GSStandalone::ticked(float dt, uint64_t time)
    7373    {
    74         GSLevel::ticked(dt);
     74        GSLevel::ticked(dt, time);
    7575
    76         this->tickChild(dt);
     76        this->tickChild(dt, time);
    7777    }
    7878}
  • code/branches/gui/src/orxonox/gamestates/GSStandalone.h

    r1670 r1672  
    4545        void enter();
    4646        void leave();
    47         void ticked(float dt);
     47        void ticked(float dt, uint64_t time);
    4848    };
    4949}
  • code/branches/gui/visual_studio/vc8/core.vcproj

    r1670 r1672  
    149149                        >
    150150                        <File
    151                                 RelativePath="..\..\src\core\BaseGameState.cc"
    152                                 >
    153                         </File>
    154                         <File
    155151                                RelativePath="..\..\src\core\ConfigFileManager.cc"
    156152                                >
     
    190186                        <File
    191187                                RelativePath="..\..\src\core\OutputHandler.cc"
     188                                >
     189                        </File>
     190                        <File
     191                                RelativePath="..\..\src\core\RootGameState.cc"
    192192                                >
    193193                        </File>
     
    380380                        >
    381381                        <File
    382                                 RelativePath="..\..\src\core\BaseGameState.h"
    383                                 >
    384                         </File>
    385                         <File
    386382                                RelativePath="..\..\src\core\ConfigFileManager.h"
    387383                                >
     
    433429                        <File
    434430                                RelativePath="..\..\src\core\OutputHandler.h"
     431                                >
     432                        </File>
     433                        <File
     434                                RelativePath="..\..\src\core\RootGameState.h"
    435435                                >
    436436                        </File>
Note: See TracChangeset for help on using the changeset viewer.