Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Jul 18, 2009, 6:23:31 PM (15 years ago)
Author:
rgrieder
Message:

Merged netp6 branch back to the trunk.

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/core/Game.cc

    r3300 r3304  
    4040#include "util/Debug.h"
    4141#include "util/Exception.h"
     42#include "util/Sleep.h"
    4243#include "util/SubString.h"
    4344#include "Clock.h"
     
    9596            SetConfigValue(statisticsAvgLength_, 1000000)
    9697                .description("Sets the time in microseconds interval at which average fps, etc. gets calculated.");
     98            SetConfigValue(fpsLimit_, 50)
     99                .description("Sets the desired framerate (0 for no limit).");
    97100        }
    98101
    99102        unsigned int statisticsRefreshCycle_;
    100103        unsigned int statisticsAvgLength_;
     104        unsigned int fpsLimit_;
    101105    };
    102106
     
    192196
    193197        // START GAME
    194         this->gameClock_->capture(); // first delta time should be about 0 seconds
     198        // first delta time should be about 0 seconds
     199        this->gameClock_->capture();
     200        // A first item is required for the fps limiter
     201        StatisticsTickInfo tickInfo = {0, 0};
     202        statisticsTickTimes_.push_back(tickInfo);
    195203        while (!this->bAbort_ && (!this->activeStates_.empty() || this->requestedStateNodes_.size() > 0))
    196204        {
     205            uint64_t currentTime = this->gameClock_->getRealMicroseconds();
     206
     207            uint64_t nextTickTime = statisticsTickTimes_.back().tickTime + static_cast<uint64_t>(1000000.0f / configuration_->fpsLimit_);
     208            if (currentTime < nextTickTime)
     209            {
     210                usleep(nextTickTime - currentTime);
     211                continue;
     212            }
    197213            this->gameClock_->capture();
    198             uint64_t currentTime = this->gameClock_->getMicroseconds();
    199214
    200215            // STATISTICS
Note: See TracChangeset for help on using the changeset viewer.