[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" |
---|
[2908] | 33 | |
---|
| 34 | #include <list> |
---|
| 35 | #include <OgreLog.h> |
---|
| 36 | #include "core/RootGameState.h" |
---|
[1686] | 37 | #include "core/OrxonoxClass.h" |
---|
[1661] | 38 | |
---|
| 39 | namespace orxonox |
---|
| 40 | { |
---|
[2908] | 41 | class _OrxonoxExport GSRoot : public RootGameState, public OrxonoxClass |
---|
[1661] | 42 | { |
---|
[2908] | 43 | friend class ClassIdentifier<GSRoot>; |
---|
| 44 | |
---|
[1661] | 45 | public: |
---|
[2908] | 46 | struct statisticsTickInfo |
---|
| 47 | { |
---|
| 48 | uint64_t tickTime; |
---|
| 49 | uint32_t tickLength; |
---|
| 50 | }; |
---|
| 51 | |
---|
| 52 | public: |
---|
| 53 | GSRoot(); |
---|
[1661] | 54 | ~GSRoot(); |
---|
| 55 | |
---|
[2908] | 56 | void exitGame() |
---|
| 57 | { requestState("root"); } |
---|
[1670] | 58 | |
---|
[2662] | 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 | |
---|
[2908] | 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 | |
---|
[1661] | 72 | private: |
---|
[2908] | 73 | void enter(); |
---|
| 74 | void leave(); |
---|
| 75 | void ticked(const Clock& time); |
---|
| 76 | |
---|
| 77 | void setConfigValues(); |
---|
| 78 | void setThreadAffinity(unsigned int limitToCPU); |
---|
| 79 | |
---|
[2662] | 80 | float timeFactor_; //!< A factor that sets the gamespeed. 1 is normal. |
---|
| 81 | bool bPaused_; |
---|
| 82 | float timeFactorPauseBackup_; |
---|
[2908] | 83 | TclBind* tclBind_; |
---|
| 84 | TclThreadManager* tclThreadManager_; |
---|
| 85 | Shell* shell_; |
---|
| 86 | LuaBind* luaBind_; |
---|
[2662] | 87 | |
---|
[2908] | 88 | // variables for time statistics |
---|
| 89 | uint64_t statisticsStartTime_; |
---|
| 90 | std::list<statisticsTickInfo> |
---|
| 91 | statisticsTickTimes_; |
---|
| 92 | uint32_t periodTickTime_; |
---|
| 93 | float avgFPS_; |
---|
| 94 | float avgTickTime_; |
---|
| 95 | |
---|
| 96 | // config values |
---|
| 97 | unsigned int statisticsRefreshCycle_; |
---|
| 98 | unsigned int statisticsAvgLength_; |
---|
| 99 | |
---|
[2662] | 100 | // console commands |
---|
[2908] | 101 | ConsoleCommand* ccExit_; |
---|
| 102 | ConsoleCommand* ccSelectGameState_; |
---|
[2662] | 103 | ConsoleCommand* ccSetTimeFactor_; |
---|
| 104 | ConsoleCommand* ccPause_; |
---|
[1661] | 105 | }; |
---|
[2908] | 106 | |
---|
| 107 | class _OrxonoxExport TimeFactorListener : virtual public OrxonoxClass |
---|
| 108 | { |
---|
| 109 | friend class GSRoot; |
---|
| 110 | |
---|
| 111 | public: |
---|
| 112 | TimeFactorListener(); |
---|
| 113 | virtual ~TimeFactorListener() {} |
---|
| 114 | |
---|
| 115 | protected: |
---|
| 116 | virtual void changedTimeFactor(float factor_new, float factor_old) {} |
---|
| 117 | inline float getTimeFactor() const |
---|
| 118 | { return TimeFactorListener::timefactor_s; } |
---|
| 119 | |
---|
| 120 | private: |
---|
| 121 | static float timefactor_s; |
---|
| 122 | }; |
---|
[1661] | 123 | } |
---|
| 124 | |
---|
[1672] | 125 | #endif /* _GSRoot_H__ */ |
---|