Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2687 was 2558, checked in by scheusso, 16 years ago

Fixed that problems with statistical info of tick time/fps

  • 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              this->periodTickTime_+=length; }
71
72    private:
73        void enter();
74        void leave();
75        void ticked(const Clock& time);
76
77        void setConfigValues();
78        void setThreadAffinity(unsigned int limitToCPU);
79
80        float                 timeFactor_;       //!< A factor that sets the gamespeed. 1 is normal.
81        bool                  bPaused_;
82        float                 timeFactorPauseBackup_;
83        Settings*             settings_;
84        TclBind*              tclBind_;
85        TclThreadManager*     tclThreadManager_;
86        Shell*                shell_;
87        LuaBind*              luaBind_;
88
89        // variables for time statistics
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.