Changeset 2662 for code/trunk/src/orxonox/gamestates
- Timestamp:
- Feb 14, 2009, 10:17:35 PM (16 years ago)
- Location:
- code/trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
-
code/trunk/src/orxonox/gamestates/GSDedicated.cc
r2171 r2662 35 35 #include "network/Server.h" 36 36 #include "objects/Tickable.h" 37 #include "util/Sleep.h" 37 38 38 39 namespace orxonox … … 41 42 : GameState<GSRoot>("dedicated") 42 43 , server_(0) 44 , timeSinceLastUpdate_(0) 43 45 { 44 46 } … … 72 74 void GSDedicated::ticked(const Clock& time) 73 75 { 74 GSLevel::ticked(time); 75 server_->tick(time.getDeltaTime()); 76 this->tickChild(time); 76 // static float startTime = time.getSecondsPrecise(); 77 // static int nrOfTicks = 0; 78 timeSinceLastUpdate_ += time.getDeltaTime(); 79 if (timeSinceLastUpdate_ >= NETWORK_PERIOD) 80 { 81 // ++nrOfTicks; 82 // COUT(0) << "estimated ticks/sec: " << nrOfTicks/(time.getSecondsPrecise()-startTime) << endl; 83 timeSinceLastUpdate_ -= static_cast<unsigned int>(timeSinceLastUpdate_ / NETWORK_PERIOD) * NETWORK_PERIOD; 84 GSLevel::ticked(time); 85 server_->tick(time.getDeltaTime()); 86 this->tickChild(time); 87 } 88 else 89 { 90 usleep((int)((NETWORK_PERIOD - timeSinceLastUpdate_) * 1000 * 1000)); 91 // COUT(0) << "sleeping for " << (int)((NETWORK_PERIOD - timeSinceLastUpdate_) * 1000 * 1000) << " usec" << endl; 92 } 77 93 } 78 94 } -
code/trunk/src/orxonox/gamestates/GSDedicated.h
r2171 r2662 49 49 50 50 Server* server_; 51 float timeSinceLastUpdate_; 51 52 }; 52 53 } -
code/trunk/src/orxonox/gamestates/GSGraphics.cc
r2171 r2662 31 31 32 32 #include <fstream> 33 #include <OgreCompositorManager.h> 33 34 #include <OgreConfigFile.h> 34 35 #include <OgreFrameListener.h> … … 75 76 , graphicsEngine_(0) 76 77 , masterKeyBinder_(0) 77 , frameCount_(0)78 , statisticsRefreshCycle_(0)79 , statisticsStartTime_(0)80 , statisticsStartCount_(0)81 , tickTime_(0)82 78 , debugOverlay_(0) 83 79 { … … 106 102 SetConfigValue(ogreLogLevelCritical_, 2) 107 103 .description("Corresponding orxonox debug level for ogre Critical"); 108 SetConfigValue(statisticsRefreshCycle_, 200000)109 .description("Sets the time in microseconds interval at which average fps, etc. get updated.");110 104 SetConfigValue(defaultMasterKeybindings_, "def_masterKeybindings.ini") 111 105 .description("Filename of default master keybindings."); … … 155 149 guiManager_->initialise(this->renderWindow_); 156 150 157 // reset frame counter158 this->frameCount_ = 0;159 this->tickTime_ = 0;160 statisticsStartTime_ = 0;161 statisticsStartCount_ = 0;162 163 151 // add console commands 164 152 FunctorMember<GSGraphics>* functor1 = createFunctor(&GSGraphics::printScreen); 165 153 functor1->setObject(this); 166 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "printScreen")); 154 ccPrintScreen_ = createConsoleCommand(functor1, "printScreen"); 155 CommandExecutor::addConsoleCommandShortcut(ccPrintScreen_); 167 156 } 168 157 … … 170 159 { 171 160 using namespace Ogre; 161 162 delete this->ccPrintScreen_; 172 163 173 164 // remove our WindowEventListener first to avoid bad calls after the window has been destroyed … … 184 175 Loader::unload(this->debugOverlay_); 185 176 delete this->debugOverlay_; 177 178 // unload all compositors 179 Ogre::CompositorManager::getSingleton().removeAll(); 186 180 187 181 // destroy render window … … 206 200 delete this->ogreRoot_; 207 201 208 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32202 //#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 209 203 // delete the ogre log and the logManager (since we have created it). 210 204 this->ogreLogger_->getDefaultLog()->removeListener(this); 211 205 this->ogreLogger_->destroyLog(Ogre::LogManager::getSingleton().getDefaultLog()); 212 206 delete this->ogreLogger_; 213 #endif207 //#endif 214 208 215 209 delete graphicsEngine_; … … 219 213 220 214 /** 221 Main loop of the orxonox game. 222 We use the Ogre::Timer to measure time since it uses the most precise 223 method an a platform (however the windows timer lacks time when under 224 heavy kernel load!). 225 There is a simple mechanism to measure the average time spent in our 226 ticks as it may indicate performance issues. 215 @note 227 216 A note about the Ogre::FrameListener: Even though we don't use them, 228 217 they still get called. However, the delta times are not correct (except … … 233 222 void GSGraphics::ticked(const Clock& time) 234 223 { 235 unsigned long long timeBeforeTick = time.getRealMicroseconds(); 224 uint64_t timeBeforeTick = time.getRealMicroseconds(); 225 236 226 float dt = time.getDeltaTime(); 237 227 … … 248 238 } 249 239 250 unsigned long long timeAfterTick = time.getRealMicroseconds(); 251 252 tickTime_ += (unsigned int)(timeAfterTick - timeBeforeTick); 253 if (timeAfterTick > statisticsStartTime_ + statisticsRefreshCycle_) 254 { 255 GraphicsEngine::getInstance().setAverageTickTime( 256 (float)tickTime_ * 0.001f / (frameCount_ - statisticsStartCount_)); 257 float avgFPS = (float)(frameCount_ - statisticsStartCount_) 258 / (timeAfterTick - statisticsStartTime_) * 1000000.0; 259 GraphicsEngine::getInstance().setAverageFramesPerSecond(avgFPS); 260 261 tickTime_ = 0; 262 statisticsStartCount_ = frameCount_; 263 statisticsStartTime_ = timeAfterTick; 264 } 240 uint64_t timeAfterTick = time.getRealMicroseconds(); 241 242 // Also add our tick time to the list in GSRoot 243 this->getParent()->addTickTime(timeAfterTick - timeBeforeTick); 244 245 // Update statistics overlay. Note that the values only change periodically in GSRoot. 246 GraphicsEngine::getInstance().setAverageFramesPerSecond(this->getParent()->getAvgFPS()); 247 GraphicsEngine::getInstance().setAverageTickTime(this->getParent()->getAvgTickTime()); 265 248 266 249 // don't forget to call _fireFrameStarted in ogre to make sure … … 283 266 // again, just to be sure ogre works fine 284 267 ogreRoot_->_fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted 285 286 ++frameCount_;287 268 } 288 269 … … 296 277 297 278 // TODO: LogManager doesn't work on oli platform. The why is yet unknown. 298 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32279 //#if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 299 280 // create a new logManager 300 281 ogreLogger_ = new Ogre::LogManager(); … … 311 292 myLog->setLogDetail(Ogre::LL_BOREME); 312 293 myLog->addListener(this); 313 #endif294 //#endif 314 295 315 296 // Root will detect that we've already created a Log … … 430 411 // create a full screen default viewport 431 412 this->viewport_ = this->renderWindow_->addViewport(0, 0); 413 414 if (this->graphicsEngine_) 415 this->graphicsEngine_->setViewport(this->viewport_); 432 416 } 433 417 -
code/trunk/src/orxonox/gamestates/GSGraphics.h
r2103 r2662 93 93 94 94 KeyBinder* masterKeyBinder_; 95 96 // variables for time statistics97 unsigned long frameCount_;98 unsigned int statisticsRefreshCycle_;99 unsigned long long statisticsStartTime_;100 unsigned long statisticsStartCount_;101 unsigned int tickTime_;102 95 XMLFile* debugOverlay_; 103 96 … … 110 103 int ogreLogLevelNormal_; //!< Corresponding Orxonx debug level for LL_NORMAL 111 104 int ogreLogLevelCritical_; //!< Corresponding Orxonx debug level for LL_CRITICAL 112 unsigned int detailLevelParticle_; //!< Detail level of particle effects (0: off, 1: low, 2: normal, 3: high)113 105 std::string defaultMasterKeybindings_; //!< Filename of default master keybindings. 106 107 // console commands 108 ConsoleCommand* ccPrintScreen_; 114 109 }; 115 110 } -
code/trunk/src/orxonox/gamestates/GSLevel.cc
r2103 r2662 41 41 #include "core/CoreIncludes.h" 42 42 #include "core/Core.h" 43 //#include "objects/Backlight.h"44 43 #include "objects/Tickable.h" 45 44 #include "objects/Radar.h" 46 //#include "tools/ParticleInterface.h"47 45 #include "CameraManager.h" 48 46 #include "LevelManager.h" 47 #include "PlayerManager.h" 49 48 #include "Settings.h" 50 49 51 50 namespace orxonox 52 51 { 53 SetCommandLineArgument(level, " sample2.oxw").shortcut("l");52 SetCommandLineArgument(level, "presentation.oxw").shortcut("l"); 54 53 55 54 GSLevel::GSLevel() 56 55 // : GameState<GSGraphics>(name) 57 : timeFactor_(1.0f) 58 , keyBinder_(0) 56 : keyBinder_(0) 59 57 , inputState_(0) 60 58 , radar_(0) … … 64 62 { 65 63 RegisterObject(GSLevel); 64 65 this->ccKeybind_ = 0; 66 this->ccTkeybind_ = 0; 67 66 68 setConfigValues(); 67 69 } … … 95 97 } 96 98 99 this->playerManager_ = new PlayerManager(); 100 97 101 if (Core::isMaster()) 98 102 { 99 103 // create the global LevelManager 100 104 this->levelManager_ = new LevelManager(); 101 102 // reset game speed to normal103 timeFactor_ = 1.0f;104 105 105 106 this->loadLevel(); … … 114 115 FunctorMember<GSLevel>* functor1 = createFunctor(&GSLevel::keybind); 115 116 functor1->setObject(this); 116 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "keybind")); 117 ccKeybind_ = createConsoleCommand(functor1, "keybind"); 118 CommandExecutor::addConsoleCommandShortcut(ccKeybind_); 117 119 FunctorMember<GSLevel>* functor2 = createFunctor(&GSLevel::tkeybind); 118 120 functor2->setObject(this); 119 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor2, "tkeybind")); 121 ccTkeybind_ = createConsoleCommand(functor2, "tkeybind"); 122 CommandExecutor::addConsoleCommandShortcut(ccTkeybind_); 120 123 // set our console command as callback for the key detector 121 124 InputManager::getInstance().setKeyDetectorCallback(std::string("keybind ") + keyDetectorCallbackCode_); … … 124 127 InputManager::getInstance().requestEnterState("game"); 125 128 } 126 127 if (Core::isMaster())128 {129 // time factor console command130 FunctorMember<GSLevel>* functor = createFunctor(&GSLevel::setTimeFactor);131 functor->setObject(this);132 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor, "setTimeFactor")).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0);;133 }134 129 } 135 130 136 131 void GSLevel::leave() 137 132 { 133 // destroy console commands 134 if (this->ccKeybind_) 135 { 136 delete this->ccKeybind_; 137 this->ccKeybind_ = 0; 138 } 139 if (this->ccTkeybind_) 140 { 141 delete this->ccTkeybind_; 142 this->ccTkeybind_ = 0; 143 } 144 138 145 // this call will delete every BaseObject! 139 146 // But currently this will call methods of objects that exist no more … … 149 156 150 157 if (this->radar_) 158 { 151 159 delete this->radar_; 160 this->radar_ = 0; 161 } 152 162 153 163 if (this->cameraManager_) 164 { 154 165 delete this->cameraManager_; 166 this->cameraManager_ = 0; 167 } 155 168 156 169 if (this->levelManager_) 170 { 157 171 delete this->levelManager_; 172 this->levelManager_ = 0; 173 } 174 175 if (this->playerManager_) 176 { 177 delete this->playerManager_; 178 this->playerManager_ = 0; 179 } 158 180 159 181 if (Core::showsGraphics()) … … 162 184 InputManager::getInstance().requestDestroyState("game"); 163 185 if (this->keyBinder_) 186 { 164 187 delete this->keyBinder_; 188 this->keyBinder_ = 0; 189 } 165 190 } 166 191 } … … 172 197 //for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it) 173 198 // it->tick(time.getDeltaTime() * this->timeFactor_); 174 }175 176 /**177 @brief178 Changes the speed of Orxonox179 */180 void GSLevel::setTimeFactor(float factor)181 {182 /*183 float change = factor / this->timeFactor_;184 */185 this->timeFactor_ = factor;186 /*187 for (ObjectList<ParticleInterface>::iterator it = ObjectList<ParticleInterface>::begin(); it; ++it)188 it->setSpeedFactor(it->getSpeedFactor() * change);189 190 for (ObjectList<Backlight>::iterator it = ObjectList<Backlight>::begin(); it; ++it)191 it->setTimeFactor(timeFactor_);192 */193 199 } 194 200 -
code/trunk/src/orxonox/gamestates/GSLevel.h
r2103 r2662 32 32 #include "OrxonoxPrereqs.h" 33 33 #include <OgrePrerequisites.h> 34 #include "core/GameState.h" 35 #include "GSGraphics.h" 34 #include "core/OrxonoxClass.h" 36 35 37 36 namespace orxonox 38 37 { 39 class _OrxonoxExport GSLevel : public OrxonoxClass //,public GameState<GSGraphics>38 class _OrxonoxExport GSLevel : public OrxonoxClass 40 39 { 41 40 friend class ClassIdentifier<GSLevel>; … … 43 42 GSLevel(); 44 43 ~GSLevel(); 45 46 // this has to be public because proteced triggers a bug in msvc47 // when taking the function address.48 void setTimeFactor(float factor);49 float getTimeFactor() { return this->timeFactor_; }50 44 51 45 protected: … … 56 50 void loadLevel(); 57 51 void unloadLevel(); 58 59 float timeFactor_; //!< A factor that sets the gamespeed. 1 is normal.60 52 61 53 // console commands … … 70 62 CameraManager* cameraManager_; 71 63 LevelManager* levelManager_; 64 PlayerManager* playerManager_; 72 65 73 66 //##### ConfigValues ##### … … 75 68 //! Filename of default keybindings. 76 69 std::string defaultKeybindings_; 70 71 // console commands 72 ConsoleCommand* ccKeybind_; 73 ConsoleCommand* ccTkeybind_; 77 74 78 75 private: -
code/trunk/src/orxonox/gamestates/GSRoot.cc
r2171 r2662 32 32 #include "util/Exception.h" 33 33 #include "util/Debug.h" 34 #include "core/Core.h" 34 35 #include "core/Factory.h" 35 36 #include "core/ConfigValueIncludes.h" … … 40 41 #include "core/TclBind.h" 41 42 #include "core/TclThreadManager.h" 43 #include "core/LuaBind.h" 42 44 #include "tools/Timer.h" 43 45 #include "objects/Tickable.h" 44 46 #include "Settings.h" 45 47 46 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 48 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 47 49 # ifndef WIN32_LEAN_AND_MEAN 48 50 # define WIN32_LEAN_AND_MEAN … … 66 68 GSRoot::GSRoot() 67 69 : RootGameState("root") 70 , timeFactor_(1.0f) 71 , bPaused_(false) 72 , timeFactorPauseBackup_(1.0f) 68 73 , settings_(0) 69 74 , tclBind_(0) … … 73 78 RegisterRootObject(GSRoot); 74 79 setConfigValues(); 80 81 this->ccSetTimeFactor_ = 0; 82 this->ccPause_ = 0; 75 83 } 76 84 … … 81 89 void GSRoot::setConfigValues() 82 90 { 91 SetConfigValue(statisticsRefreshCycle_, 250000) 92 .description("Sets the time in microseconds interval at which average fps, etc. get updated."); 93 SetConfigValue(statisticsAvgLength_, 1000000) 94 .description("Sets the time in microseconds interval at which average fps, etc. gets calculated."); 83 95 } 84 96 … … 87 99 // creates the class hierarchy for all classes with factories 88 100 Factory::createClassHierarchy(); 101 102 // reset game speed to normal 103 timeFactor_ = 1.0f; 104 105 // reset frame counter 106 this->statisticsStartTime_ = 0; 107 this->statisticsTickTimes_.clear(); 108 this->periodTickTime_ = 0; 109 this->avgFPS_ = 0.0f; 110 this->avgTickTime_ = 0.0f; 111 112 // Create the lua interface 113 this->luaBind_ = new LuaBind(); 89 114 90 115 // instantiate Settings class … … 114 139 setThreadAffinity((unsigned int)(limitToCPU - 1)); 115 140 116 // add console commands 117 FunctorMember<GSRoot>* functor1 = createFunctor(&GSRoot::exitGame); 118 functor1->setObject(this); 119 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor1, "exit")); 120 121 // add console commands 122 FunctorMember01<GameStateBase, const std::string&>* functor2 = createFunctor(&GameStateBase::requestState); 123 functor2->setObject(this); 124 CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(functor2, "selectGameState")); 141 { 142 // add console commands 143 FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::exitGame); 144 functor->setObject(this); 145 this->ccExit_ = createConsoleCommand(functor, "exit"); 146 CommandExecutor::addConsoleCommandShortcut(this->ccExit_); 147 } 148 149 { 150 // add console commands 151 FunctorMember01<GameStateBase, const std::string&>* functor = createFunctor(&GameStateBase::requestState); 152 functor->setObject(this); 153 this->ccSelectGameState_ = createConsoleCommand(functor, "selectGameState"); 154 CommandExecutor::addConsoleCommandShortcut(this->ccSelectGameState_); 155 } 156 157 { 158 // time factor console command 159 FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::setTimeFactor); 160 functor->setObject(this); 161 this->ccSetTimeFactor_ = createConsoleCommand(functor, "setTimeFactor"); 162 CommandExecutor::addConsoleCommandShortcut(this->ccSetTimeFactor_).accessLevel(AccessLevel::Offline).defaultValue(0, 1.0); 163 } 164 165 { 166 // time factor console command 167 FunctorMember<GSRoot>* functor = createFunctor(&GSRoot::pause); 168 functor->setObject(this); 169 this->ccPause_ = createConsoleCommand(functor, "pause"); 170 CommandExecutor::addConsoleCommandShortcut(this->ccPause_).accessLevel(AccessLevel::Offline); 171 } 125 172 } 126 173 127 174 void GSRoot::leave() 128 175 { 129 // TODO: remove and destroy console commands 176 // destroy console commands 177 delete this->ccExit_; 178 delete this->ccSelectGameState_; 130 179 131 180 delete this->shell_; … … 133 182 delete this->tclBind_; 134 183 135 delete settings_; 136 184 delete this->settings_; 185 delete this->luaBind_; 186 187 if (this->ccSetTimeFactor_) 188 { 189 delete this->ccSetTimeFactor_; 190 this->ccSetTimeFactor_ = 0; 191 } 192 193 if (this->ccPause_) 194 { 195 delete this->ccPause_; 196 this->ccPause_ = 0; 197 } 137 198 } 138 199 139 200 void GSRoot::ticked(const Clock& time) 140 201 { 202 uint64_t timeBeforeTick = time.getRealMicroseconds(); 203 141 204 TclThreadManager::getInstance().tick(time.getDeltaTime()); 142 205 … … 146 209 /*** HACK *** HACK ***/ 147 210 // Call the Tickable objects 211 float leveldt = time.getDeltaTime(); 212 if (leveldt > 1.0f) 213 { 214 // just loaded 215 leveldt = 0.0f; 216 } 148 217 for (ObjectList<Tickable>::iterator it = ObjectList<Tickable>::begin(); it; ++it) 149 it->tick( time.getDeltaTime());218 it->tick(leveldt * this->timeFactor_); 150 219 /*** HACK *** HACK ***/ 151 220 221 uint64_t timeAfterTick = time.getRealMicroseconds(); 222 223 // STATISTICS 224 assert(timeAfterTick - timeBeforeTick >= 0 ); 225 statisticsTickInfo tickInfo = {timeAfterTick, timeAfterTick - timeBeforeTick}; 226 statisticsTickTimes_.push_back(tickInfo); 227 assert(statisticsTickTimes_.back().tickLength==tickInfo.tickLength); 228 this->periodTickTime_ += tickInfo.tickLength; 229 230 // Ticks GSGraphics or GSDedicated 152 231 this->tickChild(time); 232 233 if (timeAfterTick > statisticsStartTime_ + statisticsRefreshCycle_) 234 { 235 std::list<statisticsTickInfo>::iterator it = this->statisticsTickTimes_.begin(); 236 assert(it != this->statisticsTickTimes_.end()); 237 int64_t lastTime = timeAfterTick - statisticsAvgLength_; 238 if ((int64_t)it->tickTime < lastTime) 239 { 240 do 241 { 242 assert(this->periodTickTime_ > it->tickLength); 243 this->periodTickTime_ -= it->tickLength; 244 ++it; 245 assert(it != this->statisticsTickTimes_.end()); 246 } while ((int64_t)it->tickTime < lastTime); 247 this->statisticsTickTimes_.erase(this->statisticsTickTimes_.begin(), it); 248 } 249 250 uint32_t framesPerPeriod = this->statisticsTickTimes_.size(); 251 this->avgFPS_ = (float)framesPerPeriod / (timeAfterTick - this->statisticsTickTimes_.front().tickTime) * 1000000.0; 252 this->avgTickTime_ = (float)this->periodTickTime_ / framesPerPeriod / 1000.0; 253 254 statisticsStartTime_ = timeAfterTick; 255 } 256 153 257 } 154 258 … … 160 264 161 265 Copyright (c) 2000-2008 Torus Knot Software Ltd 162 266 163 267 OGRE is licensed under the LGPL. For more info, see OGRE license. 164 268 */ … … 167 271 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 168 272 // Get the current process core mask 169 170 273 DWORD procMask; 274 DWORD sysMask; 171 275 # if _MSC_VER >= 1400 && defined (_M_X64) 172 276 GetProcessAffinityMask(GetCurrentProcess(), (PDWORD_PTR)&procMask, (PDWORD_PTR)&sysMask); 173 277 # else 174 278 GetProcessAffinityMask(GetCurrentProcess(), &procMask, &sysMask); 175 279 # endif 176 280 177 178 179 180 281 // If procMask is 0, consider there is only one core available 282 // (using 0 as procMask will cause an infinite loop below) 283 if (procMask == 0) 284 procMask = 1; 181 285 182 286 // if the core specified with limitToCPU is not available, take the lowest one … … 184 288 limitToCPU = 0; 185 289 186 290 // Find the lowest core that this process uses and limitToCPU suggests 187 291 DWORD threadMask = 1; 188 189 190 191 192 292 while ((threadMask & procMask) == 0 || (threadMask < (1u << limitToCPU))) 293 threadMask <<= 1; 294 295 // Set affinity to the first core 296 SetThreadAffinityMask(GetCurrentThread(), threadMask); 193 297 #endif 194 298 } 299 300 /** 301 @brief 302 Changes the speed of Orxonox 303 */ 304 void GSRoot::setTimeFactor(float factor) 305 { 306 if (Core::isMaster()) 307 { 308 if (!this->bPaused_) 309 { 310 TimeFactorListener::timefactor_s = factor; 311 312 for (ObjectList<TimeFactorListener>::iterator it = ObjectList<TimeFactorListener>::begin(); it != ObjectList<TimeFactorListener>::end(); ++it) 313 it->changedTimeFactor(factor, this->timeFactor_); 314 315 this->timeFactor_ = factor; 316 } 317 else 318 this->timeFactorPauseBackup_ = factor; 319 } 320 } 321 322 void GSRoot::pause() 323 { 324 if (Core::isMaster()) 325 { 326 if (!this->bPaused_) 327 { 328 this->timeFactorPauseBackup_ = this->timeFactor_; 329 this->setTimeFactor(0.0f); 330 this->bPaused_ = true; 331 } 332 else 333 { 334 this->bPaused_ = false; 335 this->setTimeFactor(this->timeFactorPauseBackup_); 336 } 337 } 338 } 339 340 //////////////////////// 341 // TimeFactorListener // 342 //////////////////////// 343 float TimeFactorListener::timefactor_s = 1.0f; 344 345 TimeFactorListener::TimeFactorListener() 346 { 347 RegisterRootObject(TimeFactorListener); 348 } 195 349 } -
code/trunk/src/orxonox/gamestates/GSRoot.h
r1891 r2662 31 31 32 32 #include "OrxonoxPrereqs.h" 33 34 #include <list> 33 35 #include <OgreLog.h> 34 36 #include "core/RootGameState.h" … … 40 42 { 41 43 friend class ClassIdentifier<GSRoot>; 44 45 public: 46 struct statisticsTickInfo 47 { 48 uint64_t tickTime; 49 uint32_t tickLength; 50 }; 51 42 52 public: 43 53 GSRoot(); … … 46 56 void exitGame() 47 57 { requestState("root"); } 58 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 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; } 48 71 49 72 private: … … 55 78 void setThreadAffinity(unsigned int limitToCPU); 56 79 80 float timeFactor_; //!< A factor that sets the gamespeed. 1 is normal. 81 bool bPaused_; 82 float timeFactorPauseBackup_; 57 83 Settings* settings_; 58 84 TclBind* tclBind_; 59 85 TclThreadManager* tclThreadManager_; 60 86 Shell* shell_; 87 LuaBind* luaBind_; 88 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 101 // console commands 102 ConsoleCommand* ccExit_; 103 ConsoleCommand* ccSelectGameState_; 104 ConsoleCommand* ccSetTimeFactor_; 105 ConsoleCommand* ccPause_; 106 }; 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; 61 123 }; 62 124 }
Note: See TracChangeset
for help on using the changeset viewer.