[Orxonox-commit 761] r3289 - in branches/netp6/src: core orxonox/gamestates

scheusso at orxonox.net scheusso at orxonox.net
Tue Jul 14 10:09:12 CEST 2009


Author: scheusso
Date: 2009-07-14 10:09:12 +0200 (Tue, 14 Jul 2009)
New Revision: 3289

Modified:
   branches/netp6/src/core/Clock.cc
   branches/netp6/src/core/Game.cc
   branches/netp6/src/core/Game.h
   branches/netp6/src/orxonox/gamestates/GSDedicated.cc
   branches/netp6/src/orxonox/gamestates/GSDedicated.h
Log:
a fix in Clock (more ogre-overflow safe now)
moved framerate control from gsdedicated to game
desired framerate can be controlled by config value FPSLimit_ (in the Game class) now


Modified: branches/netp6/src/core/Clock.cc
===================================================================
--- branches/netp6/src/core/Clock.cc	2009-07-13 20:43:59 UTC (rev 3288)
+++ branches/netp6/src/core/Clock.cc	2009-07-14 08:09:12 UTC (rev 3289)
@@ -58,7 +58,7 @@
         tickDt_ = timersTime - lastTimersTime_;
         tickDtFloat_ = static_cast<float>(tickDt_) / 1000000.0f;
 
-        if (timersTime > 0x7FFFFFF0)
+        if (timersTime > 0xFFFFFFFF/4)
         {
             // Ogre timer will overflow at 2^32 microseconds if unsigned long is 32 bit
             storedTime_ += timersTime;
@@ -73,6 +73,6 @@
 
     unsigned long long Clock::getRealMicroseconds() const
     {
-        return this->timer_->getMicroseconds();
+        return this->timer_->getMicroseconds() + this->storedTime_;
     }
 }

Modified: branches/netp6/src/core/Game.cc
===================================================================
--- branches/netp6/src/core/Game.cc	2009-07-13 20:43:59 UTC (rev 3288)
+++ branches/netp6/src/core/Game.cc	2009-07-14 08:09:12 UTC (rev 3289)
@@ -39,6 +39,7 @@
 
 #include "util/Debug.h"
 #include "util/Exception.h"
+#include "util/Sleep.h"
 #include "util/SubString.h"
 #include "Clock.h"
 #include "CommandLine.h"
@@ -119,6 +120,8 @@
             .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");
         SetConfigValue(levelName_, "presentation_dm.oxw")
             .description("Sets the preselection of the level in the main menu.");
+      SetConfigValue(FPSLimit_, 50)
+            .description("Sets the desired framerate (0 for no limit).");
     }
 
     void Game::setLevel(std::string levelName)
@@ -155,8 +158,15 @@
         this->gameClock_->capture(); // first delta time should be about 0 seconds
         while (!this->abort_ && !this->activeStates_.empty())
         {
+            uint64_t currentTime = this->gameClock_->getRealMicroseconds();
+
+            uint64_t nextTickTime = statisticsTickTimes_.back().tickTime + 1000000.f/this->FPSLimit_;
+            if( currentTime < nextTickTime )
+            {
+                usleep( nextTickTime - currentTime );
+                continue;
+            }
             this->gameClock_->capture();
-            uint64_t currentTime = this->gameClock_->getMicroseconds();
 
             // STATISTICS
             statisticsTickInfo tickInfo = {currentTime, 0};

Modified: branches/netp6/src/core/Game.h
===================================================================
--- branches/netp6/src/core/Game.h	2009-07-13 20:43:59 UTC (rev 3288)
+++ branches/netp6/src/core/Game.h	2009-07-14 08:09:12 UTC (rev 3289)
@@ -130,6 +130,7 @@
         // config values
         unsigned int                    statisticsRefreshCycle_;
         unsigned int                    statisticsAvgLength_;
+        unsigned int                    FPSLimit_;
         std::string                     levelName_;
 
         static std::map<std::string, GameState*> allStates_s;

Modified: branches/netp6/src/orxonox/gamestates/GSDedicated.cc
===================================================================
--- branches/netp6/src/orxonox/gamestates/GSDedicated.cc	2009-07-13 20:43:59 UTC (rev 3288)
+++ branches/netp6/src/orxonox/gamestates/GSDedicated.cc	2009-07-14 08:09:12 UTC (rev 3289)
@@ -57,7 +57,6 @@
     GSDedicated::GSDedicated(const std::string& name)
         : GameState(name)
         , server_(0)
-        , timeSinceLastUpdate_(0)
         , closeThread_(false)
         , cleanLine_(true)
         , inputIterator_(0)
@@ -108,18 +107,7 @@
 
     void GSDedicated::update(const Clock& time)
     {
-        timeSinceLastUpdate_ += time.getDeltaTime();
-        //if (timeSinceLastUpdate_ >= NETWORK_PERIOD)
-        {
-            timeSinceLastUpdate_ -= static_cast<unsigned int>(timeSinceLastUpdate_ / NETWORK_PERIOD) * NETWORK_PERIOD;
-            server_->update(time);
-        }
-        /*else
-        {
-            msleep(static_cast<unsigned int>((NETWORK_PERIOD - timeSinceLastUpdate_)*1000));
-            msleep(static_cast<unsigned int>(NETWORK_PERIOD*1000)); // NOTE: this is to throttle the non-network framerate
-//            COUT(0) << "sleeping for " << (int)((NETWORK_PERIOD - timeSinceLastUpdate_) * 1000 * 1000) << " usec" << endl;
-        }*/
+        server_->update(time);
         processQueue();
         printLine();
     }

Modified: branches/netp6/src/orxonox/gamestates/GSDedicated.h
===================================================================
--- branches/netp6/src/orxonox/gamestates/GSDedicated.h	2009-07-13 20:43:59 UTC (rev 3288)
+++ branches/netp6/src/orxonox/gamestates/GSDedicated.h	2009-07-14 08:09:12 UTC (rev 3289)
@@ -65,7 +65,6 @@
         void deleteCharacter( unsigned int position );
         
         Server*                 server_;
-        float                   timeSinceLastUpdate_;
         
         boost::thread           *inputThread_;
         boost::recursive_mutex  inputLineMutex_;




More information about the Orxonox-commit mailing list