Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/gui/src/orxonox/gamestates/GSRoot.h @ 2805

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

Added new class: Game
It represents basic operation related to the running game like start and stop or managing the new GameStates.
And since only three lines were left in Main.cc I thought I could move that to the very beginning of 'Game'.

  • Property svn:eol-style set to native
File size: 3.4 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 "core/RootGameState.h"
36#include "core/OrxonoxClass.h"
37
38namespace orxonox
39{
40    class _OrxonoxExport GSRoot : public RootGameState, public OrxonoxClass
41    {
42        friend class ClassIdentifier<GSRoot>;
43
44    public:
45        struct statisticsTickInfo
46        {
47            uint64_t    tickTime;
48            uint32_t    tickLength;
49        };
50   
51    public:
52        GSRoot();
53        ~GSRoot();
54
55        // this has to be public because proteced triggers a bug in msvc
56        // when taking the function address.
57        void setTimeFactor(float factor);
58        void pause();
59        float getTimeFactor() { return this->timeFactor_; }
60
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
68    private:
69        void enter();
70        void leave();
71        void ticked(const Clock& time);
72
73        void setConfigValues();
74
75        float                 timeFactor_;       //!< A factor that sets the gamespeed. 1 is normal.
76        bool                  bPaused_;
77        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_;
90
91        // console commands
92        ConsoleCommand*       ccSelectGameState_;
93        ConsoleCommand*       ccSetTimeFactor_;
94        ConsoleCommand*       ccPause_;
95    };
96
97    class _OrxonoxExport TimeFactorListener : virtual public OrxonoxClass
98    {
99        friend class GSRoot;
100
101        public:
102            TimeFactorListener();
103            virtual ~TimeFactorListener() {}
104
105        protected:
106            virtual void changedTimeFactor(float factor_new, float factor_old) {}
107            inline float getTimeFactor() const
108                { return TimeFactorListener::timefactor_s; }
109
110        private:
111            static float timefactor_s;
112    };
113}
114
115#endif /* _GSRoot_H__ */
Note: See TracBrowser for help on using the repository browser.