[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" |
---|
[2549] | 33 | |
---|
| 34 | #include <list> |
---|
[1686] | 35 | #include <OgreLog.h> |
---|
[1672] | 36 | #include "core/RootGameState.h" |
---|
[1686] | 37 | #include "core/OrxonoxClass.h" |
---|
[1661] | 38 | |
---|
| 39 | namespace orxonox |
---|
| 40 | { |
---|
[1891] | 41 | class _OrxonoxExport GSRoot : public RootGameState, public OrxonoxClass |
---|
[1661] | 42 | { |
---|
[1686] | 43 | friend class ClassIdentifier<GSRoot>; |
---|
[2549] | 44 | |
---|
[1661] | 45 | public: |
---|
[2549] | 46 | struct statisticsTickInfo |
---|
| 47 | { |
---|
| 48 | uint64_t tickTime; |
---|
| 49 | uint32_t tickLength; |
---|
| 50 | }; |
---|
| 51 | |
---|
| 52 | public: |
---|
[1661] | 53 | GSRoot(); |
---|
| 54 | ~GSRoot(); |
---|
| 55 | |
---|
[1670] | 56 | void exitGame() |
---|
| 57 | { requestState("root"); } |
---|
| 58 | |
---|
[2485] | 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 | |
---|
[2549] | 65 | float getAvgTickTime() { return this->avgTickTime_; } |
---|
| 66 | float getAvgFPS() { return this->avgFPS_; } |
---|
| 67 | |
---|
| 68 | inline void addTickTime(uint32_t length) |
---|
[2558] | 69 | { assert(!this->statisticsTickTimes_.empty()); this->statisticsTickTimes_.back().tickLength += length; |
---|
| 70 | this->periodTickTime_+=length; } |
---|
[2549] | 71 | |
---|
[1661] | 72 | private: |
---|
| 73 | void enter(); |
---|
| 74 | void leave(); |
---|
[1674] | 75 | void ticked(const Clock& time); |
---|
[1661] | 76 | |
---|
[1686] | 77 | void setConfigValues(); |
---|
[1691] | 78 | void setThreadAffinity(unsigned int limitToCPU); |
---|
[1674] | 79 | |
---|
[2485] | 80 | float timeFactor_; //!< A factor that sets the gamespeed. 1 is normal. |
---|
| 81 | bool bPaused_; |
---|
| 82 | float timeFactorPauseBackup_; |
---|
[1663] | 83 | Settings* settings_; |
---|
[1792] | 84 | TclBind* tclBind_; |
---|
| 85 | TclThreadManager* tclThreadManager_; |
---|
| 86 | Shell* shell_; |
---|
[2485] | 87 | LuaBind* luaBind_; |
---|
| 88 | |
---|
[2549] | 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 | |
---|
[2485] | 101 | // console commands |
---|
| 102 | ConsoleCommand* ccExit_; |
---|
| 103 | ConsoleCommand* ccSelectGameState_; |
---|
| 104 | ConsoleCommand* ccSetTimeFactor_; |
---|
| 105 | ConsoleCommand* ccPause_; |
---|
[1661] | 106 | }; |
---|
[2485] | 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 | }; |
---|
[1661] | 124 | } |
---|
| 125 | |
---|
[1672] | 126 | #endif /* _GSRoot_H__ */ |
---|