Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3289


Ignore:
Timestamp:
Jul 14, 2009, 10:09:12 AM (15 years ago)
Author:
scheusso
Message:

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

Location:
code/branches/netp6/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/netp6/src/core/Clock.cc

    r3196 r3289  
    5959        tickDtFloat_ = static_cast<float>(tickDt_) / 1000000.0f;
    6060
    61         if (timersTime > 0x7FFFFFF0)
     61        if (timersTime > 0xFFFFFFFF/4)
    6262        {
    6363            // Ogre timer will overflow at 2^32 microseconds if unsigned long is 32 bit
     
    7474    unsigned long long Clock::getRealMicroseconds() const
    7575    {
    76         return this->timer_->getMicroseconds();
     76        return this->timer_->getMicroseconds() + this->storedTime_;
    7777    }
    7878}
  • code/branches/netp6/src/core/Game.cc

    r3196 r3289  
    4040#include "util/Debug.h"
    4141#include "util/Exception.h"
     42#include "util/Sleep.h"
    4243#include "util/SubString.h"
    4344#include "Clock.h"
     
    120121        SetConfigValue(levelName_, "presentation_dm.oxw")
    121122            .description("Sets the preselection of the level in the main menu.");
     123      SetConfigValue(FPSLimit_, 50)
     124            .description("Sets the desired framerate (0 for no limit).");
    122125    }
    123126
     
    156159        while (!this->abort_ && !this->activeStates_.empty())
    157160        {
     161            uint64_t currentTime = this->gameClock_->getRealMicroseconds();
     162
     163            uint64_t nextTickTime = statisticsTickTimes_.back().tickTime + 1000000.f/this->FPSLimit_;
     164            if( currentTime < nextTickTime )
     165            {
     166                usleep( nextTickTime - currentTime );
     167                continue;
     168            }
    158169            this->gameClock_->capture();
    159             uint64_t currentTime = this->gameClock_->getMicroseconds();
    160170
    161171            // STATISTICS
  • code/branches/netp6/src/core/Game.h

    r3196 r3289  
    131131        unsigned int                    statisticsRefreshCycle_;
    132132        unsigned int                    statisticsAvgLength_;
     133        unsigned int                    FPSLimit_;
    133134        std::string                     levelName_;
    134135
  • code/branches/netp6/src/orxonox/gamestates/GSDedicated.cc

    r3284 r3289  
    5858        : GameState(name)
    5959        , server_(0)
    60         , timeSinceLastUpdate_(0)
    6160        , closeThread_(false)
    6261        , cleanLine_(true)
     
    109108    void GSDedicated::update(const Clock& time)
    110109    {
    111         timeSinceLastUpdate_ += time.getDeltaTime();
    112         //if (timeSinceLastUpdate_ >= NETWORK_PERIOD)
    113         {
    114             timeSinceLastUpdate_ -= static_cast<unsigned int>(timeSinceLastUpdate_ / NETWORK_PERIOD) * NETWORK_PERIOD;
    115             server_->update(time);
    116         }
    117         /*else
    118         {
    119             msleep(static_cast<unsigned int>((NETWORK_PERIOD - timeSinceLastUpdate_)*1000));
    120             msleep(static_cast<unsigned int>(NETWORK_PERIOD*1000)); // NOTE: this is to throttle the non-network framerate
    121 //            COUT(0) << "sleeping for " << (int)((NETWORK_PERIOD - timeSinceLastUpdate_) * 1000 * 1000) << " usec" << endl;
    122         }*/
     110        server_->update(time);
    123111        processQueue();
    124112        printLine();
  • code/branches/netp6/src/orxonox/gamestates/GSDedicated.h

    r3198 r3289  
    6666       
    6767        Server*                 server_;
    68         float                   timeSinceLastUpdate_;
    6968       
    7069        boost::thread           *inputThread_;
Note: See TracChangeset for help on using the changeset viewer.