Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 27, 2006, 1:09:35 PM (19 years ago)
Author:
bensch
Message:

gui: implemented the timer right here. now we calc in microseconds

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/gui/src/story_entities/game_world.cc

    r7840 r7900  
    2525
    2626#include "util/loading/game_loader.h"
     27#include "util/timer.h"
    2728
    2829#include "player.h"
     
    259260  this->cycle = 0;
    260261  for (unsigned int i = 0; i < TICK_SMOOTH_VALUE; i++)
    261     this->frameTimes[i] = 100;
     262    this->frameTimes[i] = 0.01f;
    262263  this->dtS = 0.0f;
    263   this->lastFrame = SDL_GetTicks ();
     264  this->lastFrame = Timer::getNow();
    264265
    265266  if (this->dataTank->music != NULL)
     
    356357void GameWorld::tick ()
    357358{
    358   Uint32 currentFrame = SDL_GetTicks();
    359 
    360359  if( !this->bPaused)
    361360  {
    362361    // CALCULATE FRAMERATE
    363362    Uint32 frameTimesIndex;
    364     Uint32 getTicks;
    365363    Uint32 i;
     364    double currentFrame = Timer::getNow();
    366365
    367366    frameTimesIndex = this->cycle % TICK_SMOOTH_VALUE;
    368     getTicks = SDL_GetTicks();
    369     this->frameTimes[frameTimesIndex] = getTicks - this->lastFrame;
    370     this->lastFrame = getTicks;
     367    this->frameTimes[frameTimesIndex] = currentFrame - this->lastFrame;
     368    this->lastFrame = currentFrame;
    371369    ++this->cycle;
    372     this->dtS = 0;
     370    this->dtS = 0.0;
    373371    for (i = 0; i < TICK_SMOOTH_VALUE; i++)
    374372      this->dtS += this->frameTimes[i];
    375     this->dtS = this->dtS / TICK_SMOOTH_VALUE / 1000.0f * speed;
     373    this->dtS = this->dtS / TICK_SMOOTH_VALUE * speed;
    376374
    377375    // TICK everything
     
    390388      this->dataTank->gameRule->tick(this->dtS);
    391389  }
    392   this->lastFrame = currentFrame;
    393390}
    394391
Note: See TracChangeset for help on using the changeset viewer.