Changeset 1674 for code/branches/gui/src/orxonox/gamestates
- Timestamp:
- Aug 28, 2008, 8:30:25 PM (16 years ago)
- Location:
- code/branches/gui/src/orxonox/gamestates
- Files:
-
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/gui/src/orxonox/gamestates/GSClient.cc
r1672 r1674 78 78 } 79 79 80 void GSClient::ticked( float dt, uint64_ttime)80 void GSClient::ticked(const Clock& time) 81 81 { 82 GSLevel::ticked( dt,time);83 client_->tick( dt);82 GSLevel::ticked(time); 83 client_->tick(time.getDeltaTime()); 84 84 85 this->tickChild( dt,time);85 this->tickChild(time); 86 86 } 87 87 } -
code/branches/gui/src/orxonox/gamestates/GSClient.h
r1672 r1674 46 46 void enter(); 47 47 void leave(); 48 void ticked( float dt, uint64_ttime);48 void ticked(const Clock& time); 49 49 50 50 network::Client* client_; -
code/branches/gui/src/orxonox/gamestates/GSGUI.cc
r1672 r1674 58 58 } 59 59 60 void GSGUI::ticked( float dt, uint64_ttime)60 void GSGUI::ticked(const Clock& time) 61 61 { 62 62 // tick CEGUI 63 GUIManager::getInstance().tick( dt);63 GUIManager::getInstance().tick(time.getDeltaTime()); 64 64 65 this->tickChild( dt,time);65 this->tickChild(time); 66 66 } 67 67 } -
code/branches/gui/src/orxonox/gamestates/GSGUI.h
r1672 r1674 44 44 void enter(); 45 45 void leave(); 46 void ticked(float dt, uint64_t time); 47 46 void ticked(const Clock& time); 48 47 }; 49 48 } -
code/branches/gui/src/orxonox/gamestates/GSGraphics.cc
r1673 r1674 32 32 #include <OgreFrameListener.h> 33 33 #include <OgreRoot.h> 34 #include <OgreTimer.h>35 34 #include <OgreWindowEventUtilities.h> 36 35 #include <OgreRenderWindow.h> … … 39 38 #include "core/ConfigValueIncludes.h" 40 39 #include "core/input/InputManager.h" 41 //#include "core/Core.h"42 40 #include "overlays/console/InGameConsole.h" 43 41 #include "gui/GUIManager.h" … … 48 46 GSGraphics::GSGraphics() 49 47 : GameState("graphics") 50 , debugRefreshTime_(0.0f) 48 , ogreRoot_(0) 49 , graphicsEngine_(0) 51 50 , inputManager_(0) 52 51 , console_(0) 53 52 , guiManager_(0) 54 53 , frameCount_(0) 54 , statisticsRefreshCycle_(0) 55 , statisticsStartTime_(0) 56 , statisticsStartCount_(0) 57 , tickTime_(0) 55 58 { 56 59 } … … 62 65 void GSGraphics::setConfigValues() 63 66 { 64 SetConfigValue( debugRefreshTime_, 0.2).description("Sets the timeinterval at which average fps, etc. get updated.");67 SetConfigValue(statisticsRefreshCycle_, 200000).description("Sets the time in microseconds interval at which average fps, etc. get updated."); 65 68 } 66 69 67 70 void GSGraphics::enter() 68 71 { 72 setConfigValues(); 73 69 74 this->ogreRoot_ = Ogre::Root::getSingletonPtr(); 70 75 this->graphicsEngine_ = GraphicsEngine::getInstancePtr(); … … 88 93 guiManager_ = new GUIManager(); 89 94 guiManager_->initialise(); 95 96 // reset frame counter 97 this->frameCount_ = 0; 98 this->tickTime_ = 0; 99 statisticsStartTime_ = 0; 100 statisticsStartCount_ = 0; 90 101 } 91 102 … … 117 128 need the time. So we shouldn't run into problems. 118 129 */ 119 void GSGraphics::ticked( float dt, uint64_ttime)130 void GSGraphics::ticked(const Clock& time) 120 131 { 132 uint64_t timeBeforeTick = time.getRealMicroseconds(); 133 float dt = time.getDeltaTime(); 134 121 135 this->inputManager_->tick(dt); 122 123 this->tickChild(dt, time);124 125 136 // tick console 126 137 this->console_->tick(dt); 138 this->tickChild(time); 139 140 uint64_t timeAfterTick = time.getRealMicroseconds(); 127 141 128 //// get current time once again 129 //timeAfterTick = timer_->getMicroseconds(); 142 tickTime_ += (unsigned int)(timeAfterTick - timeBeforeTick); 143 if (timeAfterTick > statisticsStartTime_ + statisticsRefreshCycle_) 144 { 145 GraphicsEngine::getInstance().setAverageTickTime( 146 (float)tickTime_ * 0.001f / (frameCount_ - statisticsStartCount_)); 147 float avgFPS = (float)(frameCount_ - statisticsStartCount_) 148 / (timeAfterTick - statisticsStartTime_) * 1000000.0; 149 GraphicsEngine::getInstance().setAverageFramesPerSecond(avgFPS); 130 150 131 //tickTime += timeAfterTick - timeBeforeTick; 132 //if (timeAfterTick > refreshStartTime + refreshTime) 133 //{ 134 // GraphicsEngine::getInstance().setAverageTickTime( 135 // (float)tickTime * 0.001 / (frameCount - oldFrameCount)); 136 // float avgFPS = (float)(frameCount - oldFrameCount) / (timeAfterTick - refreshStartTime) * 1000000.0; 137 // GraphicsEngine::getInstance().setAverageFramesPerSecond(avgFPS); 138 139 // oldFrameCount = frameCount; 140 // tickTime = 0; 141 // refreshStartTime = timeAfterTick; 142 //} 151 tickTime_ = 0; 152 statisticsStartCount_ = frameCount_; 153 statisticsStartTime_ = timeAfterTick; 154 } 143 155 144 156 // don't forget to call _fireFrameStarted in ogre to make sure … … 163 175 164 176 ++frameCount_; 165 166 //}167 //catch (std::exception& ex)168 //{169 // // something went wrong.170 // COUT(1) << ex.what() << std::endl;171 // COUT(1) << "Main loop was stopped by an unhandled exception. Shutting down." << std::endl;172 //}173 177 } 174 178 } -
code/branches/gui/src/orxonox/gamestates/GSGraphics.h
r1672 r1674 48 48 void enter(); 49 49 void leave(); 50 void ticked(float dt, uint64_t time); 51 52 // config values 53 float debugRefreshTime_; 50 void ticked(const Clock& time); 54 51 55 52 Ogre::Root* ogreRoot_; 56 GraphicsEngine* graphicsEngine_; //!< our dearest graphics engine <353 GraphicsEngine* graphicsEngine_; //!< pointer to GraphicsEngine instance 57 54 InputManager* inputManager_; 58 55 InGameConsole* console_; 59 56 GUIManager* guiManager_; 60 57 61 62 58 // variables for time statistics 63 59 unsigned long frameCount_; 64 65 //const unsigned long refreshTime = (unsigned long)(debugRefreshTime_ * 1000000.0f); 66 //unsigned long refreshStartTime; 67 //unsigned long tickTime; 68 //unsigned long oldFrameCount; 69 70 //unsigned long timeBeforeTick; 71 //unsigned long timeBeforeTickOld; 72 //unsigned long timeAfterTick; 60 unsigned int statisticsRefreshCycle_; 61 uint64_t statisticsStartTime_; 62 unsigned long statisticsStartCount_; 63 unsigned int tickTime_; 73 64 }; 74 65 } -
code/branches/gui/src/orxonox/gamestates/GSIO.cc
r1672 r1674 30 30 #include "GSIO.h" 31 31 32 #include <OgreFrameListener.h>33 #include <OgreRoot.h>34 #include <OgreTimer.h>35 36 #include "core/ConsoleCommand.h"37 #include "core/TclThreadManager.h"38 #include "GraphicsEngine.h"39 40 32 namespace orxonox 41 33 { 42 34 GSIO::GSIO() 43 35 : GameState("io") 44 //, timer_(0)45 36 { 46 37 } … … 58 49 } 59 50 60 void GSIO::ticked( float dt, uint64_ttime)51 void GSIO::ticked(const Clock& time) 61 52 { 62 this->tickChild(dt, time); 63 //Ogre::Root& ogreRoot = Ogre::Root::getSingleton(); 64 65 //unsigned long frameCount = 0; 66 67 //const unsigned long refreshTime = (unsigned long)(debugRefreshTime_ * 1000000.0f); 68 //unsigned long refreshStartTime = 0; 69 //unsigned long tickTime = 0; 70 //unsigned long oldFrameCount = 0; 71 72 //unsigned long timeBeforeTick = 0; 73 //unsigned long timeBeforeTickOld = 0; 74 //unsigned long timeAfterTick = 0; 75 76 //// TODO: Update time in seconds every 7 seconds to avoid any overflow (7 secs is very tight) 77 78 //COUT(3) << "Orxonox: Starting the main loop." << std::endl; 79 80 //try 81 //{ 82 // timer_->reset(); 83 // while (!this->hasScheduledTransition()) 84 // { 85 // // get current time 86 // timeBeforeTickOld = timeBeforeTick; 87 // timeBeforeTick = timer_->getMicroseconds(); 88 // float dt = (timeBeforeTick - timeBeforeTickOld) / 1000000.0; 89 90 // TclThreadManager::getInstance().tick(dt); 91 92 // this->tickChild(dt); 93 94 // // get current time once again 95 // timeAfterTick = timer_->getMicroseconds(); 96 97 // tickTime += timeAfterTick - timeBeforeTick; 98 // if (timeAfterTick > refreshStartTime + refreshTime) 99 // { 100 // GraphicsEngine::getInstance().setAverageTickTime( 101 // (float)tickTime * 0.001 / (frameCount - oldFrameCount)); 102 // float avgFPS = (float)(frameCount - oldFrameCount) / (timeAfterTick - refreshStartTime) * 1000000.0; 103 // GraphicsEngine::getInstance().setAverageFramesPerSecond(avgFPS); 104 105 // oldFrameCount = frameCount; 106 // tickTime = 0; 107 // refreshStartTime = timeAfterTick; 108 // } 109 110 // // don't forget to call _fireFrameStarted in ogre to make sure 111 // // everything goes smoothly 112 // Ogre::FrameEvent evt; 113 // evt.timeSinceLastFrame = dt; 114 // evt.timeSinceLastEvent = dt; // note: same time, but shouldn't matter anyway 115 // ogreRoot._fireFrameStarted(evt); 116 117 // // again, just to be sure ogre works fine 118 // ogreRoot._fireFrameEnded(evt); // note: uses the same time as _fireFrameStarted 119 120 // ++frameCount; 121 // } 122 //} 123 //catch (std::exception& ex) 124 //{ 125 // // something went wrong. 126 // COUT(1) << ex.what() << std::endl; 127 // COUT(1) << "Main loop was stopped by an unhandled exception. Shutting down." << std::endl; 128 //} 53 this->tickChild(time); 129 54 } 130 55 } -
code/branches/gui/src/orxonox/gamestates/GSIO.h
r1672 r1674 31 31 32 32 #include "OrxonoxPrereqs.h" 33 #include <OgrePrerequisites.h>34 33 #include "core/GameState.h" 35 34 … … 45 44 void enter(); 46 45 void leave(); 47 void ticked(float dt, uint64_t time); 48 49 //Ogre::Timer* timer_; //!< Main loop timer 46 void ticked(const Clock& time); 50 47 }; 51 48 } -
code/branches/gui/src/orxonox/gamestates/GSIOConsole.cc
r1672 r1674 58 58 } 59 59 60 void GSIOConsole::ticked( float dt, uint64_ttime)60 void GSIOConsole::ticked(const Clock& time) 61 61 { 62 62 std::string command; … … 64 64 CommandExecutor::execute(command, true); 65 65 66 tickChild( dt,time);66 tickChild(time); 67 67 } 68 68 } -
code/branches/gui/src/orxonox/gamestates/GSIOConsole.h
r1672 r1674 45 45 void enter(); 46 46 void leave(); 47 void ticked( float dt, uint64_ttime);47 void ticked(const Clock& time); 48 48 }; 49 49 } -
code/branches/gui/src/orxonox/gamestates/GSLevel.cc
r1672 r1674 44 44 GSLevel::GSLevel(const std::string& name) 45 45 : GameState(name) 46 , time factor_(1.0f)46 , timeFactor_(1.0f) 47 47 , keyBinder_(0) 48 48 , inputState_(0) … … 74 74 hud_ = new Level(Settings::getDataPath() + "overlay/hud.oxo"); 75 75 Loader::load(hud_); 76 77 // reset game speed to normal 78 timeFactor_ = 1.0f; 76 79 } 77 80 … … 96 99 } 97 100 98 void GSLevel::ticked( float dt, uint64_ttime)101 void GSLevel::ticked(const Clock& time) 99 102 { 100 103 // Call those objects that need the real time 101 104 for (Iterator<TickableReal> it = ObjectList<TickableReal>::start(); it; ++it) 102 it->tick( dt);105 it->tick(time.getDeltaTime()); 103 106 // Call the scene objects 104 107 for (Iterator<Tickable> it = ObjectList<Tickable>::start(); it; ++it) 105 it->tick( dt * this->timefactor_);108 it->tick(time.getDeltaTime() * this->timeFactor_); 106 109 } 107 110 … … 112 115 void GSLevel::setTimeFactor(float factor) 113 116 { 114 float change = factor / this->time factor_;115 this->time factor_ = factor;117 float change = factor / this->timeFactor_; 118 this->timeFactor_ = factor; 116 119 for (Iterator<ParticleInterface> it = ObjectList<ParticleInterface>::begin(); it; ++it) 117 120 it->setSpeedFactor(it->getSpeedFactor() * change); 118 121 119 122 for (Iterator<Backlight> it = ObjectList<Backlight>::begin(); it; ++it) 120 it->setTimeFactor(time factor_);123 it->setTimeFactor(timeFactor_); 121 124 } 122 125 -
code/branches/gui/src/orxonox/gamestates/GSLevel.h
r1672 r1674 44 44 // when taking the function address. 45 45 void setTimeFactor(float factor); 46 float getTimeFactor() { return this->time factor_; }46 float getTimeFactor() { return this->timeFactor_; } 47 47 48 48 protected: 49 49 virtual void enter(); 50 50 virtual void leave(); 51 virtual void ticked( float dt, uint64_ttime);51 virtual void ticked(const Clock& time); 52 52 53 53 void loadLevel(); … … 56 56 private: 57 57 58 float time factor_; //!< A factor to change the gamespeed58 float timeFactor_; //!< A factor to change the gamespeed 59 59 60 60 KeyBinder* keyBinder_; //!< tool that loads and manages the input bindings -
code/branches/gui/src/orxonox/gamestates/GSRoot.cc
r1672 r1674 30 30 #include "GSRoot.h" 31 31 32 #include "util/SubString.h"32 //#include "util/SubString.h" 33 33 #include "core/Factory.h" 34 34 #include "core/ConfigFileManager.h" … … 39 39 #include "core/Exception.h" 40 40 #include "core/TclBind.h" 41 #include "core/Core.h"42 #include "core/CommandLine.h"43 41 #include "core/TclThreadManager.h" 44 42 #include "GraphicsEngine.h" 45 43 #include "Settings.h" 44 45 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 46 # ifndef WIN32_LEAN_AND_MEAN 47 # define WIN32_LEAN_AND_MEAN 48 # endif 49 # include "windows.h" 50 51 //Get around Windows hackery 52 # ifdef max 53 # undef max 54 # endif 55 # ifdef min 56 # undef min 57 # endif 58 #endif 46 59 47 60 namespace orxonox … … 119 132 graphicsEngine_->setup(); // creates ogre root and other essentials 120 133 134 // limit the main thread to the first core so that QueryPerformanceCounter doesn't jump 135 // do this after ogre has initialised. Somehow Ogre changes the settings again (not through 136 // the timer though). 137 setThreadAffinity(); 138 121 139 // add console commands 122 140 FunctorMember<GSRoot>* functor1 = createFunctor(&GSRoot::exitGame); … … 138 156 } 139 157 140 void GSRoot::ticked(float dt, uint64_t time) 141 { 142 TclThreadManager::getInstance().tick(dt); 143 144 this->tickChild(dt, time); 158 void GSRoot::ticked(const Clock& time) 159 { 160 TclThreadManager::getInstance().tick(time.getDeltaTime()); 161 162 this->tickChild(time); 163 } 164 165 /** 166 @note 167 The code of this function has been copied from OGRE, an open source graphics engine. 168 (Object-oriented Graphics Rendering Engine) 169 For the latest info, see http://www.ogre3d.org/ 170 171 Copyright (c) 2000-2008 Torus Knot Software Ltd 172 173 OGRE is licensed under the LGPL. For more info, see ogre license info. 174 */ 175 void GSRoot::setThreadAffinity() 176 { 177 #if ORXONOX_PLATFORM == ORXONOX_PLATFORM_WIN32 178 // Get the current process core mask 179 DWORD procMask; 180 DWORD sysMask; 181 #if _MSC_VER >= 1400 && defined (_M_X64) 182 GetProcessAffinityMask(GetCurrentProcess(), (PDWORD_PTR)&procMask, (PDWORD_PTR)&sysMask); 183 #else 184 GetProcessAffinityMask(GetCurrentProcess(), &procMask, &sysMask); 185 #endif 186 187 // If procMask is 0, consider there is only one core available 188 // (using 0 as procMask will cause an infinite loop below) 189 if (procMask == 0) 190 procMask = 1; 191 192 // Find the lowest core that this process uses 193 DWORD threadMask = 1; 194 while ((threadMask & procMask) == 0) 195 threadMask <<= 1; 196 197 // Set affinity to the first core 198 SetThreadAffinityMask(GetCurrentThread(), threadMask); 199 #endif 145 200 } 146 201 } -
code/branches/gui/src/orxonox/gamestates/GSRoot.h
r1672 r1674 49 49 void enter(); 50 50 void leave(); 51 void ticked(float dt, uint64_t time); 51 void ticked(const Clock& time); 52 53 void setThreadAffinity(); 52 54 53 55 Settings* settings_; -
code/branches/gui/src/orxonox/gamestates/GSServer.cc
r1672 r1674 83 83 } 84 84 85 void GSServer::ticked( float dt, uint64_ttime)85 void GSServer::ticked(const Clock& time) 86 86 { 87 GSLevel::ticked( dt,time);88 server_->tick( dt);89 this->tickChild( dt,time);87 GSLevel::ticked(time); 88 server_->tick(time.getDeltaTime()); 89 this->tickChild(time); 90 90 } 91 91 } -
code/branches/gui/src/orxonox/gamestates/GSServer.h
r1672 r1674 46 46 void enter(); 47 47 void leave(); 48 void ticked( float dt, uint64_ttime);48 void ticked(const Clock& time); 49 49 50 50 network::Server* server_; -
code/branches/gui/src/orxonox/gamestates/GSStandalone.cc
r1672 r1674 70 70 } 71 71 72 void GSStandalone::ticked( float dt, uint64_ttime)72 void GSStandalone::ticked(const Clock& time) 73 73 { 74 GSLevel::ticked(dt, time); 75 76 this->tickChild(dt, time); 74 GSLevel::ticked(time); 75 this->tickChild(time); 77 76 } 78 77 } -
code/branches/gui/src/orxonox/gamestates/GSStandalone.h
r1672 r1674 41 41 ~GSStandalone(); 42 42 43 44 43 private: 45 44 void enter(); 46 45 void leave(); 47 void ticked( float dt, uint64_ttime);46 void ticked(const Clock& time); 48 47 }; 49 48 }
Note: See TracChangeset
for help on using the changeset viewer.