[1661] | 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" |
---|
[2662] | 33 | |
---|
| 34 | #include <list> |
---|
[1672] | 35 | #include "core/RootGameState.h" |
---|
[1686] | 36 | #include "core/OrxonoxClass.h" |
---|
[1661] | 37 | |
---|
| 38 | namespace orxonox |
---|
| 39 | { |
---|
[1891] | 40 | class _OrxonoxExport GSRoot : public RootGameState, public OrxonoxClass |
---|
[1661] | 41 | { |
---|
[1686] | 42 | friend class ClassIdentifier<GSRoot>; |
---|
[2662] | 43 | |
---|
[1661] | 44 | public: |
---|
[2662] | 45 | struct statisticsTickInfo |
---|
| 46 | { |
---|
| 47 | uint64_t tickTime; |
---|
| 48 | uint32_t tickLength; |
---|
| 49 | }; |
---|
| 50 | |
---|
| 51 | public: |
---|
[1661] | 52 | GSRoot(); |
---|
| 53 | ~GSRoot(); |
---|
| 54 | |
---|
[1670] | 55 | void exitGame() |
---|
| 56 | { requestState("root"); } |
---|
| 57 | |
---|
[2662] | 58 | // this has to be public because proteced triggers a bug in msvc |
---|
| 59 | // when taking the function address. |
---|
| 60 | void setTimeFactor(float factor); |
---|
| 61 | void pause(); |
---|
| 62 | float getTimeFactor() { return this->timeFactor_; } |
---|
| 63 | |
---|
| 64 | float getAvgTickTime() { return this->avgTickTime_; } |
---|
| 65 | float getAvgFPS() { return this->avgFPS_; } |
---|
| 66 | |
---|
| 67 | inline void addTickTime(uint32_t length) |
---|
| 68 | { assert(!this->statisticsTickTimes_.empty()); this->statisticsTickTimes_.back().tickLength += length; |
---|
| 69 | this->periodTickTime_+=length; } |
---|
| 70 | |
---|
[1661] | 71 | private: |
---|
| 72 | void enter(); |
---|
| 73 | void leave(); |
---|
[1674] | 74 | void ticked(const Clock& time); |
---|
[1661] | 75 | |
---|
[1686] | 76 | void setConfigValues(); |
---|
[1674] | 77 | |
---|
[2662] | 78 | float timeFactor_; //!< A factor that sets the gamespeed. 1 is normal. |
---|
| 79 | bool bPaused_; |
---|
| 80 | float timeFactorPauseBackup_; |
---|
| 81 | |
---|
| 82 | // variables for time statistics |
---|
| 83 | uint64_t statisticsStartTime_; |
---|
| 84 | std::list<statisticsTickInfo> |
---|
| 85 | statisticsTickTimes_; |
---|
| 86 | uint32_t periodTickTime_; |
---|
| 87 | float avgFPS_; |
---|
| 88 | float avgTickTime_; |
---|
| 89 | |
---|
| 90 | // config values |
---|
| 91 | unsigned int statisticsRefreshCycle_; |
---|
| 92 | unsigned int statisticsAvgLength_; |
---|
| 93 | |
---|
| 94 | // console commands |
---|
| 95 | ConsoleCommand* ccExit_; |
---|
| 96 | ConsoleCommand* ccSelectGameState_; |
---|
| 97 | ConsoleCommand* ccSetTimeFactor_; |
---|
| 98 | ConsoleCommand* ccPause_; |
---|
[1661] | 99 | }; |
---|
[2662] | 100 | |
---|
| 101 | class _OrxonoxExport TimeFactorListener : virtual public OrxonoxClass |
---|
| 102 | { |
---|
| 103 | friend class GSRoot; |
---|
| 104 | |
---|
| 105 | public: |
---|
| 106 | TimeFactorListener(); |
---|
| 107 | virtual ~TimeFactorListener() {} |
---|
| 108 | |
---|
| 109 | protected: |
---|
| 110 | virtual void changedTimeFactor(float factor_new, float factor_old) {} |
---|
| 111 | inline float getTimeFactor() const |
---|
| 112 | { return TimeFactorListener::timefactor_s; } |
---|
| 113 | |
---|
| 114 | private: |
---|
| 115 | static float timefactor_s; |
---|
| 116 | }; |
---|
[1661] | 117 | } |
---|
| 118 | |
---|
[1672] | 119 | #endif /* _GSRoot_H__ */ |
---|