Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/presentation/src/orxonox/gamestates/GSRoot.h @ 2553

Last change on this file since 2553 was 2549, checked in by rgrieder, 15 years ago

Moved tick time measurement to GSRoot. The values get combined with the one from GSGraphics.

  • Property svn:eol-style set to native
File size: 3.8 KB
Line 
1/*
2 *   ORXONOX - the hottest 3D action shooter ever to exist
3 *                    > www.orxonox.net <
4 *
5 *
6 *   License notice:
7 *
8 *   This program is free software; you can redistribute it and/or
9 *   modify it under the terms of the GNU General Public License
10 *   as published by the Free Software Foundation; either version 2
11 *   of the License, or (at your option) any later version.
12 *
13 *   This program is distributed in the hope that it will be useful,
14 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
15 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 *   GNU General Public License for more details.
17 *
18 *   You should have received a copy of the GNU General Public License
19 *   along with this program; if not, write to the Free Software
20 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
21 *
22 *   Author:
23 *      Reto Grieder
24 *   Co-authors:
25 *      ...
26 *
27 */
28
29#ifndef _GSRoot_H__
30#define _GSRoot_H__
31
32#include "OrxonoxPrereqs.h"
33
34#include <list>
35#include <OgreLog.h>
36#include "core/RootGameState.h"
37#include "core/OrxonoxClass.h"
38
39namespace orxonox
40{
41    class _OrxonoxExport GSRoot : public RootGameState, public OrxonoxClass
42    {
43        friend class ClassIdentifier<GSRoot>;
44
45    public:
46        struct statisticsTickInfo
47        {
48            uint64_t    tickTime;
49            uint32_t    tickLength;
50        };
51   
52    public:
53        GSRoot();
54        ~GSRoot();
55
56        void exitGame()
57        { requestState("root"); }
58
59        // this has to be public because proteced triggers a bug in msvc
60        // when taking the function address.
61        void setTimeFactor(float factor);
62        void pause();
63        float getTimeFactor() { return this->timeFactor_; }
64
65        float getAvgTickTime() { return this->avgTickTime_; }
66        float getAvgFPS()      { return this->avgFPS_; }
67
68        inline void addTickTime(uint32_t length)
69            { assert(!this->statisticsTickTimes_.empty()); this->statisticsTickTimes_.back().tickLength += length; }
70
71    private:
72        void enter();
73        void leave();
74        void ticked(const Clock& time);
75
76        void setConfigValues();
77        void setThreadAffinity(unsigned int limitToCPU);
78
79        float                 timeFactor_;       //!< A factor that sets the gamespeed. 1 is normal.
80        bool                  bPaused_;
81        float                 timeFactorPauseBackup_;
82        Settings*             settings_;
83        TclBind*              tclBind_;
84        TclThreadManager*     tclThreadManager_;
85        Shell*                shell_;
86        LuaBind*              luaBind_;
87
88        // variables for time statistics
89        uint32_t              frameCount_;
90        uint64_t              statisticsStartTime_;
91        std::list<statisticsTickInfo>
92                              statisticsTickTimes_;
93        uint32_t              periodTickTime_;
94        float                 avgFPS_;
95        float                 avgTickTime_;
96
97        // config values
98        unsigned int          statisticsRefreshCycle_;
99        unsigned int          statisticsAvgLength_;
100
101        // console commands
102        ConsoleCommand*       ccExit_;
103        ConsoleCommand*       ccSelectGameState_;
104        ConsoleCommand*       ccSetTimeFactor_;
105        ConsoleCommand*       ccPause_;
106    };
107
108    class _OrxonoxExport TimeFactorListener : virtual public OrxonoxClass
109    {
110        friend class GSRoot;
111
112        public:
113            TimeFactorListener();
114            virtual ~TimeFactorListener() {}
115
116        protected:
117            virtual void changedTimeFactor(float factor_new, float factor_old) {}
118            inline float getTimeFactor() const
119                { return TimeFactorListener::timefactor_s; }
120
121        private:
122            static float timefactor_s;
123    };
124}
125
126#endif /* _GSRoot_H__ */
Note: See TracBrowser for help on using the repository browser.