Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7131 in orxonox.OLD for trunk/src/story_entities/game_world.cc


Ignore:
Timestamp:
Feb 14, 2006, 12:23:11 PM (18 years ago)
Author:
bensch
Message:

orxonox/trunk: framerate calculation is much more 'accurate' meaning, if it is falling from one value into another one, the rate will be averanged to the middle.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/story_entities/game_world.cc

    r7108 r7131  
    124124ErrorMessage GameWorld::init()
    125125{
    126   this->cycle = 0;
    127126  /* init the world interface */
    128127  this->shell = new Shell();
     
    248247    this->dataTank->music->playback();
    249248
     249  PRINTF(3)("GameWorld::mainLoop() - Entering main loop\n");
     250
     251  // initialize Timing
     252  this->cycle = 0;
     253  for (unsigned int i = 0; i < TICK_SMOOTH_VALUE; i++)
     254    this->frameTimes[i] = 0;
     255  this->dtS = 0.0f;
    250256  this->lastFrame = SDL_GetTicks ();
    251   PRINTF(3)("GameWorld::mainLoop() - Entering main loop\n");
    252257
    253258  while( this->isRunning) /* @todo implement pause */
     
    310315}
    311316
     317
    312318/**
    313319 *  advance the timeline
     
    323329  if( !this->isPaused)
    324330  {
    325     this->dt = currentFrame - this->lastFrame;
    326 
    327     /* limit the the frame rate to 100 frames per second (fps) */
    328     if( this->dt < 10)
    329     {
    330       /* the frame-rate is limited to 100 frames per second, all other things are for nothing. */
    331       //PRINTF(0)("fps = 1000 - frame rate is adjusted\n");
    332       SDL_Delay(10 - dt);
    333       this->dt = 10;
    334     }
    335 
    336     this->dtS = (float)this->dt / 1000.0f * this->speed;
    337     this->gameTime += this->dtS;
    338 
     331    // CALCULATE FRAMERATE
     332    Uint32 frameTimesIndex;
     333    Uint32 getTicks;
     334    Uint32 count;
     335    Uint32 i;
     336
     337    frameTimesIndex = this->cycle % TICK_SMOOTH_VALUE;
     338    getTicks = SDL_GetTicks();
     339    this->frameTimes[frameTimesIndex] = getTicks - this->lastFrame;
     340    this->lastFrame = getTicks;
     341    //this->cycle++;
     342  // Work out the current framerate
     343    if (this->cycle < TICK_SMOOTH_VALUE)
     344      count = this->cycle;
     345    else
     346      count = TICK_SMOOTH_VALUE;
     347        // add up all the values and divide to get the average frame time.
     348    this->dtS = 0;
     349    for (i = 0; i < count; i++)
     350      this->dtS += this->frameTimes[i];
     351    this->dtS = this->dtS / count / 1000.0f * speed;
     352
     353    // TICK everything
    339354    this->tick(this->dataTank->objectManager->getObjectList(OM_DEAD_TICK), this->dtS);
    340355    this->tick(this->dataTank->objectManager->getObjectList(OM_ENVIRON), this->dtS);
Note: See TracChangeset for help on using the changeset viewer.