Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7900 in orxonox.OLD for branches/gui/src


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

Location:
branches/gui/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/gui/src/lib/gui/gl_gui/glgui_inputline.cc

    r7896 r7900  
    4848
    4949    this->setFocusable(true);
    50     this->setClickable(true);
    5150
    5251    this->text.setParent2D(this);
  • branches/gui/src/lib/util/timer.cc

    r7899 r7900  
    1212#include <sys/time.h>
    1313
    14 
     14/**
     15 * @returns the current time in Second exact to the micro-second
     16 */
    1517double Timer::getNow() {
    1618
  • branches/gui/src/lib/util/timer.h

    r7899 r7900  
    1313class Timer
    1414{
     15public:
    1516  static double getNow();
    1617
  • 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
  • branches/gui/src/story_entities/game_world.h

    r7785 r7900  
    9393
    9494    /* world timing */
    95     Uint32              lastFrame;                    //!< last time of frame (in MiliSeconds)
     95    double              lastFrame;                    //!< last time of frame (in MiliSeconds)
    9696    Uint32              cycle;                        //!< The cycle we are in (starts with 0 and rises with every frame)
    9797    float               dtS;                          //!< The time needed for caluculations in seconds
    9898    float               speed;                        //!< how fast the game flows
    9999    double              gameTime;                     //!< this is where the game time is saved
    100     Uint32              frameTimes[TICK_SMOOTH_VALUE];//!< The time used for the last TICK_SMOOTH_VALUE's frames.
     100    double              frameTimes[TICK_SMOOTH_VALUE];//!< The time used for the last TICK_SMOOTH_VALUE's frames.
    101101
    102102    GameRules*          gameRules;                    //!< Pointer to the data structure containig the game rules
Note: See TracChangeset for help on using the changeset viewer.