Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2817 for code/branches


Ignore:
Timestamp:
Mar 21, 2009, 10:17:59 PM (16 years ago)
Author:
rgrieder
Message:

Removed GameState template and renamed GameStateBase to GameState.
Moved statistics stuff (fps and tick time) to Game and removed the remaining hacks in GSGraphics and GSRoot.

Location:
code/branches/gui/src
Files:
28 edited

Legend:

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

    r2710 r2817  
    166166
    167167  // game states
    168   class GameStateBase;
    169   template <class ParentType>
    170168  class GameState;
    171169  class RootGameState;
  • code/branches/gui/src/core/GameState.cc

    r2815 r2817  
    3030@file
    3131@brief
    32     Implementation of GameStateBase class.
     32    Implementation of GameState class.
    3333*/
    3434
     
    4343        Constructor only initialises variables and sets the name permanently.
    4444    */
    45     GameStateBase::GameStateBase(const std::string& name)
     45    GameState::GameState(const std::string& name)
    4646        : name_(name)
    47         //, parent_(0)
     47        , parent_(0)
    4848        , activeChild_(0)
    4949        //, bPausegetParent()(false)
     
    5757        Destructor only checks that we don't delete an active state.
    5858    */
    59     GameStateBase::~GameStateBase()
     59    GameState::~GameState()
    6060    {
    6161        OrxAssert(this->operation_.active == false, "Deleting an active GameState is a very bad idea..");
     
    6969        The state to be added.
    7070    */
    71     void GameStateBase::addChild(GameStateBase* state)
     71    void GameState::addChild(GameState* 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, GameStateBase*>::const_iterator it = state->allChildren_.begin();
     76        for (std::map<std::string, GameState*>::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, GameStateBase*>::const_iterator it = state->allChildren_.begin();
     98        for (std::map<std::string, GameState*>::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 GameStateBase::removeChild(GameStateBase* state)
    116     {
    117         std::map<GameStateBase*, GameStateBase*>::iterator it = this->grandchildrenToChildren_.find(state);
     115    void GameState::removeChild(GameState* state)
     116    {
     117        std::map<GameState*, GameState*>::iterator it = this->grandchildrenToChildren_.find(state);
    118118        if (it != this->grandchildrenToChildren_.end())
    119119        {
     
    127127            else
    128128            {
    129                 for (std::map<GameStateBase*, GameStateBase*>::const_iterator it = state->grandchildrenToChildren_.begin();
     129                for (std::map<GameState*, GameState*>::const_iterator it = state->grandchildrenToChildren_.begin();
    130130                    it != state->grandchildrenToChildren_.end(); ++it)
    131131                    this->grandchildRemoved(it->first);
     
    150150    */
    151151
    152     void GameStateBase::removeChild(const std::string& name)
    153     {
    154         GameStateBase* state = getState(name);
     152    void GameState::removeChild(const std::string& name)
     153    {
     154        GameState* state = getState(name);
    155155        if (state)
    156156        {
     
    173173        The child that has been added.
    174174    */
    175     inline void GameStateBase::grandchildAdded(GameStateBase* child, GameStateBase* grandchild)
     175    inline void GameState::grandchildAdded(GameState* child, GameState* grandchild)
    176176    {
    177177        // fill the two maps correctly.
    178178        this->allChildren_[grandchild->getName()] = grandchild;
    179179        this->grandchildrenToChildren_[grandchild] = child;
    180         if (this->getParentAsBase())
    181             this->getParentAsBase()->grandchildAdded(this, grandchild);
     180        if (this->getParent())
     181            this->getParent()->grandchildAdded(this, grandchild);
    182182    }
    183183
     
    191191        The child that has been removed.
    192192    */
    193     inline void GameStateBase::grandchildRemoved(GameStateBase* grandchild)
     193    inline void GameState::grandchildRemoved(GameState* grandchild)
    194194    {
    195195        // adjust the two maps correctly.
    196196        this->allChildren_.erase(grandchild->getName());
    197197        this->grandchildrenToChildren_.erase(grandchild);
    198         if (this->getParentAsBase())
    199             this->getParentAsBase()->grandchildRemoved(grandchild);
     198        if (this->getParent())
     199            this->getParent()->grandchildRemoved(grandchild);
    200200    }
    201201
     
    206206        Remember that the every node has a map with all its child nodes.
    207207    */
    208     GameStateBase* GameStateBase::getState(const std::string& name)
    209     {
    210         if (this->getParentAsBase())
    211             return this->getParentAsBase()->getState(name);
     208    GameState* GameState::getState(const std::string& name)
     209    {
     210        if (this->getParent())
     211            return this->getParent()->getState(name);
    212212        else
    213213        {
     
    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, GameStateBase*>::const_iterator it = this->allChildren_.find(name);
     218            std::map<std::string, GameState*>::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     GameStateBase* GameStateBase::getRoot()
    228     {
    229         if (this->getParentAsBase())
    230             return this->getParentAsBase()->getRoot();
     227    GameState* GameState::getRoot()
     228    {
     229        if (this->getParent())
     230            return this->getParent()->getRoot();
    231231        else
    232232            return this;
     
    240240        have active children itself. Many states can be active at once.
    241241    */
    242     GameStateBase* GameStateBase::getCurrentState()
     242    GameState* GameState::getCurrentState()
    243243    {
    244244        if (this->operation_.active)
     
    251251        else
    252252        {
    253             if (this->getParentAsBase())
    254                 return this->getParentAsBase()->getCurrentState();
     253            if (this->getParent())
     254                return this->getParent()->getCurrentState();
    255255            else
    256256                return 0;
     
    262262        Determines whether 'state' is in this subtree, including this node.
    263263    */
    264     bool GameStateBase::isInSubtree(GameStateBase* state) const
     264    bool GameState::isInSubtree(GameState* 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 GameStateBase::requestState(const std::string& name)
     277    void GameState::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 GameStateBase::makeTransition(GameStateBase* source, GameStateBase* destination)
    289     {
    290         if (source == this->getParentAsBase())
     288    void GameState::makeTransition(GameState* source, GameState* destination)
     289    {
     290        if (source == this->getParent())
    291291        {
    292292            // call is from the parent
     
    308308
    309309        // Check for 'destination' in the children map first
    310         std::map<GameStateBase*, GameStateBase*>::const_iterator it
     310        std::map<GameState*, GameState*>::const_iterator it
    311311            = this->grandchildrenToChildren_.find(destination);
    312312        if (it != this->grandchildrenToChildren_.end())
     
    319319        {
    320320            // parent. We can be sure of this.
    321             assert(this->getParentAsBase() != 0);
     321            assert(this->getParent() != 0);
    322322
    323323            this->deactivate();
    324             this->getParentAsBase()->makeTransition(this, destination);
     324            this->getParent()->makeTransition(this, destination);
    325325        }
    326326    }
     
    330330        Activates the state. Only sets bActive_ to true and notifies the parent.
    331331    */
    332     void GameStateBase::activate()
     332    void GameState::activate()
    333333    {
    334334        this->operation_.active = true;
     
    341341        Activates the state. Only sets bActive_ to false and notifies the parent.
    342342    */
    343     void GameStateBase::deactivate()
     343    void GameState::deactivate()
    344344    {
    345345        this->operation_.leaving = true;
     
    358358        This method is not virtual! You cannot override it therefore.
    359359    */
    360     void GameStateBase::tick(const Clock& time)
     360    void GameState::tick(const Clock& time)
    361361    {
    362362        this->operation_.running = true;
  • code/branches/gui/src/core/GameState.h

    r2815 r2817  
    6060        Then Bar stores Foo in map by its name. The other one then maps Foo to Foofoo.
    6161    */
    62     class _CoreExport GameStateBase
     62    class _CoreExport GameState
    6363    {
    6464        friend class RootGameState;
    65         template <class ParentType>
    66         friend class GameState;
    6765        // Hack
    6866        friend class Game;
     
    8381
    8482    public:
    85         virtual ~GameStateBase();
     83        GameState(const std::string& name);
     84        virtual ~GameState();
    8685
    8786        const std::string& getName() const { return name_; }
    8887        const Operations getOperation() const { return this->operation_; }
    89         bool isInSubtree(GameStateBase* state) const;
     88        bool isInSubtree(GameState* state) const;
    9089
    91         GameStateBase* getState(const std::string& name);
    92         GameStateBase* getRoot();
     90        GameState* getState(const std::string& name);
     91        GameState* getRoot();
    9392        //! Returns the currently active game state
    94         virtual GameStateBase* getCurrentState();
     93        virtual GameState* getCurrentState();
    9594
    9695        virtual void requestState(const std::string& name);
    9796
    98         void addChild(GameStateBase* state);
    99         void removeChild(GameStateBase* state);
     97        void addChild(GameState* state);
     98        void removeChild(GameState* state);
    10099        void removeChild(const std::string& name);
    101100
     
    105104        virtual void ticked(const Clock& time) = 0;
    106105
    107         GameStateBase* getActiveChild() { return this->activeChild_; }
     106        GameState* getActiveChild() { return this->activeChild_; }
    108107
    109108        void tickChild(const Clock& time) { if (this->getActiveChild()) this->getActiveChild()->tick(time); }
    110109
    111         virtual GameStateBase* getParentAsBase() const = 0;
    112         virtual void setParent(GameStateBase* state) = 0;
     110        GameState* getParent() const     { return this->parent_; }
     111        void setParent(GameState* state) { this->parent_ = state; }
    113112
    114113    private:
    115         // Making the constructor private ensures that game states
    116         // are always derivates of GameState<T>. Note the friend declaration above.
    117         GameStateBase(const std::string& name);
     114        //! Performs a transition to 'destination'
     115        virtual void makeTransition(GameState* source, GameState* destination);
    118116
    119         //! Performs a transition to 'destination'
    120         virtual void makeTransition(GameStateBase* source, GameStateBase* destination);
    121 
    122         void grandchildAdded(GameStateBase* child, GameStateBase* grandchild);
    123         void grandchildRemoved(GameStateBase* grandchild);
     117        void grandchildAdded(GameState* child, GameState* grandchild);
     118        void grandchildRemoved(GameState* grandchild);
    124119
    125120        void tick(const Clock& time);
     
    129124        const std::string                        name_;
    130125        Operations                               operation_;
    131         GameStateBase*                           activeChild_;
     126        GameState*                               parent_;
     127        GameState*                               activeChild_;
    132128        //bool                                     bPauseParent_;
    133         std::map<std::string, GameStateBase*>    allChildren_;
    134         std::map<GameStateBase*, GameStateBase*> grandchildrenToChildren_;
    135     };
    136 
    137 
    138     template <class ParentType>
    139     class GameState : public GameStateBase
    140     {
    141     public:
    142         GameState(const std::string& name)
    143             : GameStateBase(name)
    144             , parent_(0)
    145         { }
    146         virtual ~GameState() { }
    147 
    148         GameStateBase* getParentAsBase() const
    149             { return parent_; }
    150 
    151         ParentType* getParent() const
    152             { return parent_; }
    153 
    154     protected:
    155         void setParent(GameStateBase* state)
    156         {
    157             assert(dynamic_cast<ParentType*>(state) != 0);
    158             this->parent_ = dynamic_cast<ParentType*>(state);
    159         }
    160 
    161     private:
    162         ParentType* parent_;
     129        std::map<std::string, GameState*>        allChildren_;
     130        std::map<GameState*, GameState*>         grandchildrenToChildren_;
    163131    };
    164132}
  • code/branches/gui/src/core/RootGameState.cc

    r2815 r2817  
    3636{
    3737    RootGameState::RootGameState(const std::string& name)
    38         : GameState<GameStateBase>(name)
     38        : GameState(name)
    3939        , stateRequest_("")
    4040    {
     
    5050        the method can assume certain things to be granted (like 'this' is always active).
    5151    */
    52     void RootGameState::makeTransition(GameStateBase* source, GameStateBase* destination)
     52    void RootGameState::makeTransition(GameState* source, GameState* destination)
    5353    {
    5454        if (source != 0)
     
    6565
    6666        // Check for 'destination' in the children map first
    67         std::map<GameStateBase*, GameStateBase*>::const_iterator it
     67        std::map<GameState*, GameState*>::const_iterator it
    6868            = this->grandchildrenToChildren_.find(destination);
    6969        if (it != this->grandchildrenToChildren_.end())
    7070        {
    71             OrxAssert(static_cast<GameStateBase*>(it->second) != 0,
     71            OrxAssert(static_cast<GameState*>(it->second) != 0,
    7272                "There was a mix with RootGameState and GameState, could not cast.");
    73             GameStateBase* child = static_cast<GameStateBase*>(it->second);
     73            GameState* child = static_cast<GameState*>(it->second);
    7474            // child state. Don't use 'state', might be a grandchild!
    7575            this->activeChild_ = child;
     
    8585    void RootGameState::gotoState(const std::string& name)
    8686    {
    87         GameStateBase* request = getState(name);
     87        GameState* request = getState(name);
    8888        if (request)
    8989        {
    90             GameStateBase* current = getCurrentState();
     90            GameState* current = getCurrentState();
    9191            if (current)
    9292            {
  • code/branches/gui/src/core/RootGameState.h

    r2805 r2817  
    3535namespace orxonox
    3636{
    37     class _CoreExport RootGameState : public GameState<GameStateBase>
     37    class _CoreExport RootGameState : public GameState
    3838    {
    3939        // Hack!
     
    4747
    4848    private:
    49         void makeTransition(GameStateBase* source, GameStateBase* destination);
     49        void makeTransition(GameState* source, GameState* destination);
    5050        void gotoState(const std::string& name);
    5151
  • code/branches/gui/src/orxonox/Game.cc

    r2807 r2817  
    4545#include "core/Core.h"
    4646#include "core/Identifier.h"
     47#include "core/CoreIncludes.h"
     48#include "core/ConfigValueIncludes.h"
    4749
    4850#include "gamestates/GSRoot.h"
     
    6163int main(int argc, char** argv)
    6264{
    63     orxonox::Game orxonox(argc, argv);
    64     orxonox.run();
     65    {
     66        orxonox::Game orxonox(argc, argv);
     67        orxonox.run();
     68        // objects gets destroyed here!
     69    }
     70
     71    // Clean up class hierarchy stuff (identifiers, xmlport, configvalue, consolecommand)
     72    // Needs to be done after Game destructor because of ~OrxonoxClass
     73    orxonox::Identifier::destroyAllIdentifiers();
     74
    6575    return 0;
    6676}
     
    8999        this->abort_ = false;
    90100
     101        // reset statistics
     102        this->statisticsStartTime_ = 0;
     103        this->statisticsTickTimes_.clear();
     104        this->periodTickTime_ = 0;
     105        this->periodTime_ = 0;
     106        this->avgFPS_ = 0.0f;
     107        this->avgTickTime_ = 0.0f;
     108
    91109        this->core_ = new orxonox::Core();
    92110        this->gameClock_ = this->core_->initialise(argc, argv);
     111
     112        RegisterRootObject(Game);
     113        this->setConfigValues();
    93114    }
    94115
     
    101122        delete this->core_;
    102123
    103         // Clean up class hierarchy stuff (identifiers, xmlport, configvalue, consolecommand)
    104         // Needs to be done after 'delete core' because of ~OrxonoxClass
    105         orxonox::Identifier::destroyAllIdentifiers();
    106 
    107124        assert(singletonRef_s);
    108125        singletonRef_s = 0;
     126    }
     127
     128    void Game::setConfigValues()
     129    {
     130        SetConfigValue(statisticsRefreshCycle_, 250000)
     131            .description("Sets the time in microseconds interval at which average fps, etc. get updated.");
     132        SetConfigValue(statisticsAvgLength_, 1000000)
     133            .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");
    109134    }
    110135
     
    143168        root.gotoState(CommandLine::getValue("state"));
    144169
     170        this->gameClock_->capture(); // first delta time should be about 0 seconds
    145171        while (!this->abort_)
    146172        {
    147173            this->gameClock_->capture();
    148 
     174            uint64_t currentTime = this->gameClock_->getMicroseconds();
     175
     176            // STATISTICS
     177            statisticsTickInfo tickInfo = {currentTime, 0};
     178            statisticsTickTimes_.push_back(tickInfo);
     179            this->periodTime_ += this->gameClock_->getDeltaTimeMicroseconds();
     180
     181            // UPDATE
    149182            root.tick(*this->gameClock_);
     183
     184            // STATISTICS
     185            if (this->periodTime_ > statisticsRefreshCycle_)
     186            {
     187                std::list<statisticsTickInfo>::iterator it = this->statisticsTickTimes_.begin();
     188                assert(it != this->statisticsTickTimes_.end());
     189                int64_t lastTime = currentTime - this->statisticsAvgLength_;
     190                if ((int64_t)it->tickTime < lastTime)
     191                {
     192                    do
     193                    {
     194                        assert(this->periodTickTime_ > it->tickLength);
     195                        this->periodTickTime_ -= it->tickLength;
     196                        ++it;
     197                        assert(it != this->statisticsTickTimes_.end());
     198                    } while ((int64_t)it->tickTime < lastTime);
     199                    this->statisticsTickTimes_.erase(this->statisticsTickTimes_.begin(), it);
     200                }
     201
     202                uint32_t framesPerPeriod = this->statisticsTickTimes_.size();
     203                this->avgFPS_ = (float)framesPerPeriod / (currentTime - this->statisticsTickTimes_.front().tickTime) * 1000000.0;
     204                this->avgTickTime_ = (float)this->periodTickTime_ / framesPerPeriod / 1000.0;
     205
     206                this->periodTime_ -= this->statisticsRefreshCycle_;
     207            }
    150208
    151209            if (root.stateRequest_ != "")
     
    161219        this->abort_ = true;
    162220    }
     221
     222    void Game::addTickTime(uint32_t length)
     223    {
     224        assert(!this->statisticsTickTimes_.empty());
     225        this->statisticsTickTimes_.back().tickLength += length;
     226        this->periodTickTime_+=length;
     227    }
    163228}
  • code/branches/gui/src/orxonox/Game.h

    r2807 r2817  
    3838#include "OrxonoxPrereqs.h"
    3939#include <cassert>
    40 #include "core/CorePrereqs.h"
     40#include <list>
     41#include "core/OrxonoxClass.h"
    4142
    4243namespace orxonox
     
    4647        Main class responsible for running the game.
    4748    */
    48     class _OrxonoxExport Game
     49    class _OrxonoxExport Game : public OrxonoxClass
    4950    {
    5051    public:
    5152        Game(int argc, char** argv);
    5253        ~Game();
     54        void setConfigValues();
    5355
    5456        void run();
    5557        void stop();
    5658
     59        float getAvgTickTime() { return this->avgTickTime_; }
     60        float getAvgFPS()      { return this->avgFPS_; }
     61
     62        void addTickTime(uint32_t length);
     63
    5764        static Game& getInstance() { assert(singletonRef_s); return *singletonRef_s; }
    5865
    5966    private:
     67        struct statisticsTickInfo
     68        {
     69            uint64_t    tickTime;
     70            uint32_t    tickLength;
     71        };
     72
    6073        Game(Game&); // don't mess with singletons
    6174
     
    6578        bool abort_;
    6679
     80        // variables for time statistics
     81        uint64_t              statisticsStartTime_;
     82        std::list<statisticsTickInfo>
     83                              statisticsTickTimes_;
     84        uint32_t              periodTime_;
     85        uint32_t              periodTickTime_;
     86        float                 avgFPS_;
     87        float                 avgTickTime_;
     88
     89        // config values
     90        unsigned int          statisticsRefreshCycle_;
     91        unsigned int          statisticsAvgLength_;
     92
    6793        static Game* singletonRef_s;        //!< Pointer to the Singleton
    6894    };
  • code/branches/gui/src/orxonox/GraphicsManager.h

    r2805 r2817  
    6666            { return this->detailLevelParticle_; }
    6767
    68         // <HACK>
    69         float getAverageFramesPerSecond() const   { return this->avgFramesPerSecond_; }
    70         float getAverageTickTime() const          { return this->avgTickTime_; }
    71         void setAverageTickTime(float tickTime)   { this->avgTickTime_ = tickTime; }
    72         void setAverageFramesPerSecond(float fps) { this->avgFramesPerSecond_ = fps; }
    73         // </HACK>
    74 
    7568        inline void setViewport(Ogre::Viewport* viewport)
    7669            { this->viewport_ = viewport; }
  • code/branches/gui/src/orxonox/gamestates/GSClient.cc

    r2807 r2817  
    4141
    4242    GSClient::GSClient()
    43         : GameState<GSGraphics>("client")
     43        : GameState("client")
    4444        , client_(0)
    4545    {
  • code/branches/gui/src/orxonox/gamestates/GSClient.h

    r2171 r2817  
    3131
    3232#include "OrxonoxPrereqs.h"
     33#include "core/GameState.h"
    3334#include "network/NetworkPrereqs.h"
    3435#include "GSLevel.h"
    35 #include "GSGraphics.h"
    3636
    3737namespace orxonox
    3838{
    39     class _OrxonoxExport GSClient : public GameState<GSGraphics>, public GSLevel
     39    class _OrxonoxExport GSClient : public GameState, public GSLevel
    4040    {
    4141    public:
  • code/branches/gui/src/orxonox/gamestates/GSDedicated.cc

    r2801 r2817  
    4141{
    4242    GSDedicated::GSDedicated()
    43         : GameState<GSRoot>("dedicated")
     43        : GameState("dedicated")
    4444        , server_(0)
    4545        , timeSinceLastUpdate_(0)
  • code/branches/gui/src/orxonox/gamestates/GSDedicated.h

    r2662 r2817  
    3131
    3232#include "OrxonoxPrereqs.h"
     33#include "core/GameState.h"
    3334#include "network/NetworkPrereqs.h"
    3435#include "GSLevel.h"
    35 #include "GSRoot.h"
    3636
    3737namespace orxonox
    3838{
    39     class _OrxonoxExport GSDedicated : public GameState<GSRoot>, public GSLevel
     39    class _OrxonoxExport GSDedicated : public GameState, public GSLevel
    4040    {
    4141    public:
  • code/branches/gui/src/orxonox/gamestates/GSGUI.cc

    r2808 r2817  
    4040{
    4141    GSGUI::GSGUI()
    42         : GameState<GSGraphics>("gui")
     42        : GameState("gui")
    4343    {
    4444    }
  • code/branches/gui/src/orxonox/gamestates/GSGUI.h

    r1755 r2817  
    3232#include "OrxonoxPrereqs.h"
    3333#include "core/GameState.h"
    34 #include "GSGraphics.h"
    3534
    3635namespace orxonox
    3736{
    38     class _OrxonoxExport GSGUI : public GameState<GSGraphics>
     37    class _OrxonoxExport GSGUI : public GameState
    3938    {
    4039    public:
  • code/branches/gui/src/orxonox/gamestates/GSGraphics.cc

    r2816 r2817  
    4444#include "overlays/console/InGameConsole.h"
    4545#include "gui/GUIManager.h"
    46 
    47 // for compatibility
    4846#include "GraphicsManager.h"
     47#include "Game.h"
    4948
    5049namespace orxonox
    5150{
    5251    GSGraphics::GSGraphics()
    53         : GameState<GSRoot>("graphics")
     52        : GameState("graphics")
    5453        , inputManager_(0)
    5554        , console_(0)
     
    157156        uint64_t timeAfterTick = time.getRealMicroseconds();
    158157
    159         // Also add our tick time to the list in GSRoot
    160         this->getParent()->addTickTime(timeAfterTick - timeBeforeTick);
    161 
    162         // Update statistics overlay. Note that the values only change periodically in GSRoot.
    163         GraphicsManager::getInstance().setAverageFramesPerSecond(this->getParent()->getAvgFPS());
    164         GraphicsManager::getInstance().setAverageTickTime(this->getParent()->getAvgTickTime());
     158        // Also add our tick time
     159        Game::getInstance().addTickTime(timeAfterTick - timeBeforeTick);
    165160
    166161        this->graphicsManager_->update(time);
  • code/branches/gui/src/orxonox/gamestates/GSGraphics.h

    r2816 r2817  
    3434#include "core/OrxonoxClass.h"
    3535#include "tools/WindowEventListener.h"
    36 #include "GSRoot.h"
    3736
    3837namespace orxonox
    3938{
    40     class _OrxonoxExport GSGraphics : public GameState<GSRoot>, public WindowEventListener
     39    class _OrxonoxExport GSGraphics : public GameState, public WindowEventListener
    4140    {
    4241        friend class ClassIdentifier<GSGraphics>;
  • code/branches/gui/src/orxonox/gamestates/GSIOConsole.cc

    r2087 r2817  
    4040{
    4141    GSIOConsole::GSIOConsole()
    42         : GameState<GSRoot>("ioConsole")
     42        : GameState("ioConsole")
    4343    {
    4444    }
  • code/branches/gui/src/orxonox/gamestates/GSIOConsole.h

    r1755 r2817  
    3333#include <OgrePrerequisites.h>
    3434#include "core/GameState.h"
    35 #include "GSRoot.h"
    3635
    3736namespace orxonox
    3837{
    39     class _OrxonoxExport GSIOConsole : public GameState<GSRoot>
     38    class _OrxonoxExport GSIOConsole : public GameState
    4039    {
    4140    public:
  • code/branches/gui/src/orxonox/gamestates/GSLevel.cc

    r2814 r2817  
    5353
    5454    GSLevel::GSLevel()
    55 //        : GameState<GSGraphics>(name)
     55//        : GameState(name)
    5656        : keyBinder_(0)
    5757        , inputState_(0)
  • code/branches/gui/src/orxonox/gamestates/GSLevel.h

    r2801 r2817  
    3131
    3232#include "OrxonoxPrereqs.h"
     33#include "core/GameState.h"
    3334#include "core/OrxonoxClass.h"
    3435
  • code/branches/gui/src/orxonox/gamestates/GSRoot.cc

    r2805 r2817  
    3333#include "util/Debug.h"
    3434#include "core/Core.h"
    35 #include "core/ConfigValueIncludes.h"
    3635#include "core/CoreIncludes.h"
    3736#include "core/ConsoleCommand.h"
    3837#include "tools/Timer.h"
    3938#include "objects/Tickable.h"
     39#include "Game.h"
    4040
    4141namespace orxonox
     
    4747        , timeFactorPauseBackup_(1.0f)
    4848    {
    49         RegisterRootObject(GSRoot);
    50         setConfigValues();
    51 
    5249        this->ccSetTimeFactor_ = 0;
    5350        this->ccPause_ = 0;
     
    5855    }
    5956
    60     void GSRoot::setConfigValues()
    61     {
    62         SetConfigValue(statisticsRefreshCycle_, 250000)
    63             .description("Sets the time in microseconds interval at which average fps, etc. get updated.");
    64         SetConfigValue(statisticsAvgLength_, 1000000)
    65             .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");
    66     }
    67 
    6857    void GSRoot::enter()
    6958    {
     
    7160        timeFactor_ = 1.0f;
    7261
    73         // reset frame counter
    74         this->statisticsStartTime_ = 0;
    75         this->statisticsTickTimes_.clear();
    76         this->periodTickTime_ = 0;
    77         this->avgFPS_ = 0.0f;
    78         this->avgTickTime_ = 0.0f;
    79 
    8062        {
    8163            // add console commands
    82             FunctorMember01<GameStateBase, const std::string&>* functor = createFunctor(&GameStateBase::requestState);
     64            FunctorMember01<GameState, const std::string&>* functor = createFunctor(&GameState::requestState);
    8365            functor->setObject(this);
    8466            this->ccSelectGameState_ = createConsoleCommand(functor, "selectGameState");
     
    144126        uint64_t timeAfterTick = time.getRealMicroseconds();
    145127
    146         // STATISTICS
    147         assert(timeAfterTick - timeBeforeTick >= 0 );
    148         statisticsTickInfo tickInfo = {timeAfterTick, timeAfterTick - timeBeforeTick};
    149         statisticsTickTimes_.push_back(tickInfo);
    150         assert(statisticsTickTimes_.back().tickLength==tickInfo.tickLength);
    151         this->periodTickTime_ += tickInfo.tickLength;
     128        // Also add our tick time to the list in GSRoot
     129        Game::getInstance().addTickTime(timeAfterTick - timeBeforeTick);
    152130
    153         // Ticks GSGraphics or GSDedicated
    154131        this->tickChild(time);
    155 
    156         if (timeAfterTick > statisticsStartTime_ + statisticsRefreshCycle_)
    157         {
    158             std::list<statisticsTickInfo>::iterator it = this->statisticsTickTimes_.begin();
    159             assert(it != this->statisticsTickTimes_.end());
    160             int64_t lastTime = timeAfterTick - statisticsAvgLength_;
    161             if ((int64_t)it->tickTime < lastTime)
    162             {
    163                 do
    164                 {
    165                     assert(this->periodTickTime_ > it->tickLength);
    166                     this->periodTickTime_ -= it->tickLength;
    167                     ++it;
    168                     assert(it != this->statisticsTickTimes_.end());
    169                 } while ((int64_t)it->tickTime < lastTime);
    170                 this->statisticsTickTimes_.erase(this->statisticsTickTimes_.begin(), it);
    171             }
    172 
    173             uint32_t framesPerPeriod = this->statisticsTickTimes_.size();
    174             this->avgFPS_ = (float)framesPerPeriod / (timeAfterTick - this->statisticsTickTimes_.front().tickTime) * 1000000.0;
    175             this->avgTickTime_ = (float)this->periodTickTime_ / framesPerPeriod / 1000.0;
    176 
    177             statisticsStartTime_ = timeAfterTick;
    178         }
    179 
    180132    }
    181133
  • code/branches/gui/src/orxonox/gamestates/GSRoot.h

    r2805 r2817  
    3838namespace orxonox
    3939{
    40     class _OrxonoxExport GSRoot : public RootGameState, public OrxonoxClass
     40    class _OrxonoxExport GSRoot : public RootGameState
    4141    {
    4242        friend class ClassIdentifier<GSRoot>;
    4343
    4444    public:
    45         struct statisticsTickInfo
    46         {
    47             uint64_t    tickTime;
    48             uint32_t    tickLength;
    49         };
    5045   
    5146    public:
     
    5954        float getTimeFactor() { return this->timeFactor_; }
    6055
    61         float getAvgTickTime() { return this->avgTickTime_; }
    62         float getAvgFPS()      { return this->avgFPS_; }
    63 
    64         inline void addTickTime(uint32_t length)
    65             { assert(!this->statisticsTickTimes_.empty()); this->statisticsTickTimes_.back().tickLength += length;
    66               this->periodTickTime_+=length; }
    67 
    6856    private:
    6957        void enter();
     
    7159        void ticked(const Clock& time);
    7260
    73         void setConfigValues();
    74 
    7561        float                 timeFactor_;       //!< A factor that sets the gamespeed. 1 is normal.
    7662        bool                  bPaused_;
    7763        float                 timeFactorPauseBackup_;
    78 
    79         // variables for time statistics
    80         uint64_t              statisticsStartTime_;
    81         std::list<statisticsTickInfo>
    82                               statisticsTickTimes_;
    83         uint32_t              periodTickTime_;
    84         float                 avgFPS_;
    85         float                 avgTickTime_;
    86 
    87         // config values
    88         unsigned int          statisticsRefreshCycle_;
    89         unsigned int          statisticsAvgLength_;
    9064
    9165        // console commands
  • code/branches/gui/src/orxonox/gamestates/GSServer.cc

    r2801 r2817  
    3939
    4040    GSServer::GSServer()
    41         : GameState<GSGraphics>("server")
     41        : GameState("server")
    4242        , server_(0)
    4343    {
  • code/branches/gui/src/orxonox/gamestates/GSServer.h

    r2171 r2817  
    3131
    3232#include "OrxonoxPrereqs.h"
     33#include "core/GameState.h"
    3334#include "network/NetworkPrereqs.h"
    3435#include "GSLevel.h"
    35 #include "GSGraphics.h"
    3636
    3737namespace orxonox
    3838{
    39     class _OrxonoxExport GSServer : public GameState<GSGraphics>, public GSLevel
     39    class _OrxonoxExport GSServer : public GameState, public GSLevel
    4040    {
    4141    public:
  • code/branches/gui/src/orxonox/gamestates/GSStandalone.cc

    r2808 r2817  
    4040{
    4141    GSStandalone::GSStandalone()
    42         : GameState<GSGraphics>("standalone")
     42        : GameState("standalone")
    4343    {
    4444    }
  • code/branches/gui/src/orxonox/gamestates/GSStandalone.h

    r2808 r2817  
    3131
    3232#include "OrxonoxPrereqs.h"
     33#include "core/GameState.h"
    3334#include "GSLevel.h"
    34 #include "GSGraphics.h"
    3535
    3636namespace orxonox
    3737{
    38     class _OrxonoxExport GSStandalone : public GameState<GSGraphics>, public GSLevel
     38    class _OrxonoxExport GSStandalone : public GameState, public GSLevel
    3939    {
    4040    public:
  • code/branches/gui/src/orxonox/overlays/debug/DebugFPSText.cc

    r2801 r2817  
    3030#include "DebugFPSText.h"
    3131#include <OgreTextAreaOverlayElement.h>
     32#include "util/Convert.h"
    3233#include "core/CoreIncludes.h"
    33 #include "GraphicsManager.h"
    34 #include "util/Convert.h"
     34#include "Game.h"
    3535
    3636namespace orxonox
     
    5151        SUPER(DebugFPSText, tick, dt);
    5252
    53         float fps = GraphicsManager::getInstance().getAverageFramesPerSecond();
     53        float fps = Game::getInstance().getAvgFPS();
    5454        this->setCaption(convertToString(fps));
    5555    }
  • code/branches/gui/src/orxonox/overlays/debug/DebugRTRText.cc

    r2801 r2817  
    3232#include "core/CoreIncludes.h"
    3333#include "util/Convert.h"
    34 #include "GraphicsManager.h"
     34#include "Game.h"
    3535
    3636namespace orxonox
     
    5151        SUPER(DebugRTRText, tick, dt);
    5252
    53         float rtr = GraphicsManager::getInstance().getAverageTickTime();
     53        float rtr = Game::getInstance().getAvgTickTime();
    5454        this->setCaption(convertToString(rtr));
    5555    }
Note: See TracChangeset for help on using the changeset viewer.