Changeset 2817 for code/branches/gui/src/orxonox
- Timestamp:
- Mar 21, 2009, 10:17:59 PM (16 years ago)
- Location:
- code/branches/gui/src/orxonox
- Files:
-
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gui/src/orxonox/Game.cc
r2807 r2817 45 45 #include "core/Core.h" 46 46 #include "core/Identifier.h" 47 #include "core/CoreIncludes.h" 48 #include "core/ConfigValueIncludes.h" 47 49 48 50 #include "gamestates/GSRoot.h" … … 61 63 int main(int argc, char** argv) 62 64 { 63 orxonox::Game orxonox(argc, argv); 64 orxonox.run(); 65 { 66 orxonox::Game orxonox(argc, argv); 67 orxonox.run(); 68 // objects gets destroyed here! 69 } 70 71 // Clean up class hierarchy stuff (identifiers, xmlport, configvalue, consolecommand) 72 // Needs to be done after Game destructor because of ~OrxonoxClass 73 orxonox::Identifier::destroyAllIdentifiers(); 74 65 75 return 0; 66 76 } … … 89 99 this->abort_ = false; 90 100 101 // reset statistics 102 this->statisticsStartTime_ = 0; 103 this->statisticsTickTimes_.clear(); 104 this->periodTickTime_ = 0; 105 this->periodTime_ = 0; 106 this->avgFPS_ = 0.0f; 107 this->avgTickTime_ = 0.0f; 108 91 109 this->core_ = new orxonox::Core(); 92 110 this->gameClock_ = this->core_->initialise(argc, argv); 111 112 RegisterRootObject(Game); 113 this->setConfigValues(); 93 114 } 94 115 … … 101 122 delete this->core_; 102 123 103 // Clean up class hierarchy stuff (identifiers, xmlport, configvalue, consolecommand)104 // Needs to be done after 'delete core' because of ~OrxonoxClass105 orxonox::Identifier::destroyAllIdentifiers();106 107 124 assert(singletonRef_s); 108 125 singletonRef_s = 0; 126 } 127 128 void Game::setConfigValues() 129 { 130 SetConfigValue(statisticsRefreshCycle_, 250000) 131 .description("Sets the time in microseconds interval at which average fps, etc. get updated."); 132 SetConfigValue(statisticsAvgLength_, 1000000) 133 .description("Sets the time in microseconds interval at which average fps, etc. gets calculated."); 109 134 } 110 135 … … 143 168 root.gotoState(CommandLine::getValue("state")); 144 169 170 this->gameClock_->capture(); // first delta time should be about 0 seconds 145 171 while (!this->abort_) 146 172 { 147 173 this->gameClock_->capture(); 148 174 uint64_t currentTime = this->gameClock_->getMicroseconds(); 175 176 // STATISTICS 177 statisticsTickInfo tickInfo = {currentTime, 0}; 178 statisticsTickTimes_.push_back(tickInfo); 179 this->periodTime_ += this->gameClock_->getDeltaTimeMicroseconds(); 180 181 // UPDATE 149 182 root.tick(*this->gameClock_); 183 184 // STATISTICS 185 if (this->periodTime_ > statisticsRefreshCycle_) 186 { 187 std::list<statisticsTickInfo>::iterator it = this->statisticsTickTimes_.begin(); 188 assert(it != this->statisticsTickTimes_.end()); 189 int64_t lastTime = currentTime - this->statisticsAvgLength_; 190 if ((int64_t)it->tickTime < lastTime) 191 { 192 do 193 { 194 assert(this->periodTickTime_ > it->tickLength); 195 this->periodTickTime_ -= it->tickLength; 196 ++it; 197 assert(it != this->statisticsTickTimes_.end()); 198 } while ((int64_t)it->tickTime < lastTime); 199 this->statisticsTickTimes_.erase(this->statisticsTickTimes_.begin(), it); 200 } 201 202 uint32_t framesPerPeriod = this->statisticsTickTimes_.size(); 203 this->avgFPS_ = (float)framesPerPeriod / (currentTime - this->statisticsTickTimes_.front().tickTime) * 1000000.0; 204 this->avgTickTime_ = (float)this->periodTickTime_ / framesPerPeriod / 1000.0; 205 206 this->periodTime_ -= this->statisticsRefreshCycle_; 207 } 150 208 151 209 if (root.stateRequest_ != "") … … 161 219 this->abort_ = true; 162 220 } 221 222 void Game::addTickTime(uint32_t length) 223 { 224 assert(!this->statisticsTickTimes_.empty()); 225 this->statisticsTickTimes_.back().tickLength += length; 226 this->periodTickTime_+=length; 227 } 163 228 } -
code/branches/gui/src/orxonox/Game.h
r2807 r2817 38 38 #include "OrxonoxPrereqs.h" 39 39 #include <cassert> 40 #include "core/CorePrereqs.h" 40 #include <list> 41 #include "core/OrxonoxClass.h" 41 42 42 43 namespace orxonox … … 46 47 Main class responsible for running the game. 47 48 */ 48 class _OrxonoxExport Game 49 class _OrxonoxExport Game : public OrxonoxClass 49 50 { 50 51 public: 51 52 Game(int argc, char** argv); 52 53 ~Game(); 54 void setConfigValues(); 53 55 54 56 void run(); 55 57 void stop(); 56 58 59 float getAvgTickTime() { return this->avgTickTime_; } 60 float getAvgFPS() { return this->avgFPS_; } 61 62 void addTickTime(uint32_t length); 63 57 64 static Game& getInstance() { assert(singletonRef_s); return *singletonRef_s; } 58 65 59 66 private: 67 struct statisticsTickInfo 68 { 69 uint64_t tickTime; 70 uint32_t tickLength; 71 }; 72 60 73 Game(Game&); // don't mess with singletons 61 74 … … 65 78 bool abort_; 66 79 80 // variables for time statistics 81 uint64_t statisticsStartTime_; 82 std::list<statisticsTickInfo> 83 statisticsTickTimes_; 84 uint32_t periodTime_; 85 uint32_t periodTickTime_; 86 float avgFPS_; 87 float avgTickTime_; 88 89 // config values 90 unsigned int statisticsRefreshCycle_; 91 unsigned int statisticsAvgLength_; 92 67 93 static Game* singletonRef_s; //!< Pointer to the Singleton 68 94 }; -
code/branches/gui/src/orxonox/GraphicsManager.h
r2805 r2817 66 66 { return this->detailLevelParticle_; } 67 67 68 // <HACK>69 float getAverageFramesPerSecond() const { return this->avgFramesPerSecond_; }70 float getAverageTickTime() const { return this->avgTickTime_; }71 void setAverageTickTime(float tickTime) { this->avgTickTime_ = tickTime; }72 void setAverageFramesPerSecond(float fps) { this->avgFramesPerSecond_ = fps; }73 // </HACK>74 75 68 inline void setViewport(Ogre::Viewport* viewport) 76 69 { this->viewport_ = viewport; } -
code/branches/gui/src/orxonox/gamestates/GSClient.cc
r2807 r2817 41 41 42 42 GSClient::GSClient() 43 : GameState <GSGraphics>("client")43 : GameState("client") 44 44 , client_(0) 45 45 { -
code/branches/gui/src/orxonox/gamestates/GSClient.h
r2171 r2817 31 31 32 32 #include "OrxonoxPrereqs.h" 33 #include "core/GameState.h" 33 34 #include "network/NetworkPrereqs.h" 34 35 #include "GSLevel.h" 35 #include "GSGraphics.h"36 36 37 37 namespace orxonox 38 38 { 39 class _OrxonoxExport GSClient : public GameState <GSGraphics>, public GSLevel39 class _OrxonoxExport GSClient : public GameState, public GSLevel 40 40 { 41 41 public: -
code/branches/gui/src/orxonox/gamestates/GSDedicated.cc
r2801 r2817 41 41 { 42 42 GSDedicated::GSDedicated() 43 : GameState <GSRoot>("dedicated")43 : GameState("dedicated") 44 44 , server_(0) 45 45 , timeSinceLastUpdate_(0) -
code/branches/gui/src/orxonox/gamestates/GSDedicated.h
r2662 r2817 31 31 32 32 #include "OrxonoxPrereqs.h" 33 #include "core/GameState.h" 33 34 #include "network/NetworkPrereqs.h" 34 35 #include "GSLevel.h" 35 #include "GSRoot.h"36 36 37 37 namespace orxonox 38 38 { 39 class _OrxonoxExport GSDedicated : public GameState <GSRoot>, public GSLevel39 class _OrxonoxExport GSDedicated : public GameState, public GSLevel 40 40 { 41 41 public: -
code/branches/gui/src/orxonox/gamestates/GSGUI.cc
r2808 r2817 40 40 { 41 41 GSGUI::GSGUI() 42 : GameState <GSGraphics>("gui")42 : GameState("gui") 43 43 { 44 44 } -
code/branches/gui/src/orxonox/gamestates/GSGUI.h
r1755 r2817 32 32 #include "OrxonoxPrereqs.h" 33 33 #include "core/GameState.h" 34 #include "GSGraphics.h"35 34 36 35 namespace orxonox 37 36 { 38 class _OrxonoxExport GSGUI : public GameState <GSGraphics>37 class _OrxonoxExport GSGUI : public GameState 39 38 { 40 39 public: -
code/branches/gui/src/orxonox/gamestates/GSGraphics.cc
r2816 r2817 44 44 #include "overlays/console/InGameConsole.h" 45 45 #include "gui/GUIManager.h" 46 47 // for compatibility48 46 #include "GraphicsManager.h" 47 #include "Game.h" 49 48 50 49 namespace orxonox 51 50 { 52 51 GSGraphics::GSGraphics() 53 : GameState <GSRoot>("graphics")52 : GameState("graphics") 54 53 , inputManager_(0) 55 54 , console_(0) … … 157 156 uint64_t timeAfterTick = time.getRealMicroseconds(); 158 157 159 // Also add our tick time to the list in GSRoot 160 this->getParent()->addTickTime(timeAfterTick - timeBeforeTick); 161 162 // Update statistics overlay. Note that the values only change periodically in GSRoot. 163 GraphicsManager::getInstance().setAverageFramesPerSecond(this->getParent()->getAvgFPS()); 164 GraphicsManager::getInstance().setAverageTickTime(this->getParent()->getAvgTickTime()); 158 // Also add our tick time 159 Game::getInstance().addTickTime(timeAfterTick - timeBeforeTick); 165 160 166 161 this->graphicsManager_->update(time); -
code/branches/gui/src/orxonox/gamestates/GSGraphics.h
r2816 r2817 34 34 #include "core/OrxonoxClass.h" 35 35 #include "tools/WindowEventListener.h" 36 #include "GSRoot.h"37 36 38 37 namespace orxonox 39 38 { 40 class _OrxonoxExport GSGraphics : public GameState <GSRoot>, public WindowEventListener39 class _OrxonoxExport GSGraphics : public GameState, public WindowEventListener 41 40 { 42 41 friend class ClassIdentifier<GSGraphics>; -
code/branches/gui/src/orxonox/gamestates/GSIOConsole.cc
r2087 r2817 40 40 { 41 41 GSIOConsole::GSIOConsole() 42 : GameState <GSRoot>("ioConsole")42 : GameState("ioConsole") 43 43 { 44 44 } -
code/branches/gui/src/orxonox/gamestates/GSIOConsole.h
r1755 r2817 33 33 #include <OgrePrerequisites.h> 34 34 #include "core/GameState.h" 35 #include "GSRoot.h"36 35 37 36 namespace orxonox 38 37 { 39 class _OrxonoxExport GSIOConsole : public GameState <GSRoot>38 class _OrxonoxExport GSIOConsole : public GameState 40 39 { 41 40 public: -
code/branches/gui/src/orxonox/gamestates/GSLevel.cc
r2814 r2817 53 53 54 54 GSLevel::GSLevel() 55 // : GameState <GSGraphics>(name)55 // : GameState(name) 56 56 : keyBinder_(0) 57 57 , inputState_(0) -
code/branches/gui/src/orxonox/gamestates/GSLevel.h
r2801 r2817 31 31 32 32 #include "OrxonoxPrereqs.h" 33 #include "core/GameState.h" 33 34 #include "core/OrxonoxClass.h" 34 35 -
code/branches/gui/src/orxonox/gamestates/GSRoot.cc
r2805 r2817 33 33 #include "util/Debug.h" 34 34 #include "core/Core.h" 35 #include "core/ConfigValueIncludes.h"36 35 #include "core/CoreIncludes.h" 37 36 #include "core/ConsoleCommand.h" 38 37 #include "tools/Timer.h" 39 38 #include "objects/Tickable.h" 39 #include "Game.h" 40 40 41 41 namespace orxonox … … 47 47 , timeFactorPauseBackup_(1.0f) 48 48 { 49 RegisterRootObject(GSRoot);50 setConfigValues();51 52 49 this->ccSetTimeFactor_ = 0; 53 50 this->ccPause_ = 0; … … 58 55 } 59 56 60 void GSRoot::setConfigValues()61 {62 SetConfigValue(statisticsRefreshCycle_, 250000)63 .description("Sets the time in microseconds interval at which average fps, etc. get updated.");64 SetConfigValue(statisticsAvgLength_, 1000000)65 .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");66 }67 68 57 void GSRoot::enter() 69 58 { … … 71 60 timeFactor_ = 1.0f; 72 61 73 // reset frame counter74 this->statisticsStartTime_ = 0;75 this->statisticsTickTimes_.clear();76 this->periodTickTime_ = 0;77 this->avgFPS_ = 0.0f;78 this->avgTickTime_ = 0.0f;79 80 62 { 81 63 // add console commands 82 FunctorMember01<GameState Base, const std::string&>* functor = createFunctor(&GameStateBase::requestState);64 FunctorMember01<GameState, const std::string&>* functor = createFunctor(&GameState::requestState); 83 65 functor->setObject(this); 84 66 this->ccSelectGameState_ = createConsoleCommand(functor, "selectGameState"); … … 144 126 uint64_t timeAfterTick = time.getRealMicroseconds(); 145 127 146 // STATISTICS 147 assert(timeAfterTick - timeBeforeTick >= 0 ); 148 statisticsTickInfo tickInfo = {timeAfterTick, timeAfterTick - timeBeforeTick}; 149 statisticsTickTimes_.push_back(tickInfo); 150 assert(statisticsTickTimes_.back().tickLength==tickInfo.tickLength); 151 this->periodTickTime_ += tickInfo.tickLength; 128 // Also add our tick time to the list in GSRoot 129 Game::getInstance().addTickTime(timeAfterTick - timeBeforeTick); 152 130 153 // Ticks GSGraphics or GSDedicated154 131 this->tickChild(time); 155 156 if (timeAfterTick > statisticsStartTime_ + statisticsRefreshCycle_)157 {158 std::list<statisticsTickInfo>::iterator it = this->statisticsTickTimes_.begin();159 assert(it != this->statisticsTickTimes_.end());160 int64_t lastTime = timeAfterTick - statisticsAvgLength_;161 if ((int64_t)it->tickTime < lastTime)162 {163 do164 {165 assert(this->periodTickTime_ > it->tickLength);166 this->periodTickTime_ -= it->tickLength;167 ++it;168 assert(it != this->statisticsTickTimes_.end());169 } while ((int64_t)it->tickTime < lastTime);170 this->statisticsTickTimes_.erase(this->statisticsTickTimes_.begin(), it);171 }172 173 uint32_t framesPerPeriod = this->statisticsTickTimes_.size();174 this->avgFPS_ = (float)framesPerPeriod / (timeAfterTick - this->statisticsTickTimes_.front().tickTime) * 1000000.0;175 this->avgTickTime_ = (float)this->periodTickTime_ / framesPerPeriod / 1000.0;176 177 statisticsStartTime_ = timeAfterTick;178 }179 180 132 } 181 133 -
code/branches/gui/src/orxonox/gamestates/GSRoot.h
r2805 r2817 38 38 namespace orxonox 39 39 { 40 class _OrxonoxExport GSRoot : public RootGameState , public OrxonoxClass40 class _OrxonoxExport GSRoot : public RootGameState 41 41 { 42 42 friend class ClassIdentifier<GSRoot>; 43 43 44 44 public: 45 struct statisticsTickInfo46 {47 uint64_t tickTime;48 uint32_t tickLength;49 };50 45 51 46 public: … … 59 54 float getTimeFactor() { return this->timeFactor_; } 60 55 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 56 private: 69 57 void enter(); … … 71 59 void ticked(const Clock& time); 72 60 73 void setConfigValues();74 75 61 float timeFactor_; //!< A factor that sets the gamespeed. 1 is normal. 76 62 bool bPaused_; 77 63 float timeFactorPauseBackup_; 78 79 // variables for time statistics80 uint64_t statisticsStartTime_;81 std::list<statisticsTickInfo>82 statisticsTickTimes_;83 uint32_t periodTickTime_;84 float avgFPS_;85 float avgTickTime_;86 87 // config values88 unsigned int statisticsRefreshCycle_;89 unsigned int statisticsAvgLength_;90 64 91 65 // console commands -
code/branches/gui/src/orxonox/gamestates/GSServer.cc
r2801 r2817 39 39 40 40 GSServer::GSServer() 41 : GameState <GSGraphics>("server")41 : GameState("server") 42 42 , server_(0) 43 43 { -
code/branches/gui/src/orxonox/gamestates/GSServer.h
r2171 r2817 31 31 32 32 #include "OrxonoxPrereqs.h" 33 #include "core/GameState.h" 33 34 #include "network/NetworkPrereqs.h" 34 35 #include "GSLevel.h" 35 #include "GSGraphics.h"36 36 37 37 namespace orxonox 38 38 { 39 class _OrxonoxExport GSServer : public GameState <GSGraphics>, public GSLevel39 class _OrxonoxExport GSServer : public GameState, public GSLevel 40 40 { 41 41 public: -
code/branches/gui/src/orxonox/gamestates/GSStandalone.cc
r2808 r2817 40 40 { 41 41 GSStandalone::GSStandalone() 42 : GameState <GSGraphics>("standalone")42 : GameState("standalone") 43 43 { 44 44 } -
code/branches/gui/src/orxonox/gamestates/GSStandalone.h
r2808 r2817 31 31 32 32 #include "OrxonoxPrereqs.h" 33 #include "core/GameState.h" 33 34 #include "GSLevel.h" 34 #include "GSGraphics.h"35 35 36 36 namespace orxonox 37 37 { 38 class _OrxonoxExport GSStandalone : public GameState <GSGraphics>, public GSLevel38 class _OrxonoxExport GSStandalone : public GameState, public GSLevel 39 39 { 40 40 public: -
code/branches/gui/src/orxonox/overlays/debug/DebugFPSText.cc
r2801 r2817 30 30 #include "DebugFPSText.h" 31 31 #include <OgreTextAreaOverlayElement.h> 32 #include "util/Convert.h" 32 33 #include "core/CoreIncludes.h" 33 #include "GraphicsManager.h" 34 #include "util/Convert.h" 34 #include "Game.h" 35 35 36 36 namespace orxonox … … 51 51 SUPER(DebugFPSText, tick, dt); 52 52 53 float fps = G raphicsManager::getInstance().getAverageFramesPerSecond();53 float fps = Game::getInstance().getAvgFPS(); 54 54 this->setCaption(convertToString(fps)); 55 55 } -
code/branches/gui/src/orxonox/overlays/debug/DebugRTRText.cc
r2801 r2817 32 32 #include "core/CoreIncludes.h" 33 33 #include "util/Convert.h" 34 #include "G raphicsManager.h"34 #include "Game.h" 35 35 36 36 namespace orxonox … … 51 51 SUPER(DebugRTRText, tick, dt); 52 52 53 float rtr = G raphicsManager::getInstance().getAverageTickTime();53 float rtr = Game::getInstance().getAvgTickTime(); 54 54 this->setCaption(convertToString(rtr)); 55 55 }
Note: See TracChangeset
for help on using the changeset viewer.