Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7159 in orxonox.OLD for trunk/src/subprojects


Ignore:
Timestamp:
Feb 18, 2006, 1:50:59 AM (19 years ago)
Author:
bensch
Message:

better tick in framework

Location:
trunk/src/subprojects
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/subprojects/framework.cc

    r7158 r7159  
    6666{
    6767  Framework* framework = Framework::getInstance();
     68
     69  // initialize Timing
     70  framework->cycle = 0;
     71  for (unsigned int i = 0; i < TICK_SMOOTH_VALUE; i++)
     72    framework->frameTimes[i] = 100;
     73  framework->dtS = 0.0f;
     74  framework->lastFrame = SDL_GetTicks ();
     75
     76
    6877  while(!framework->isFinished)
    6978    {
     
    103112float Framework::tick()
    104113{
    105   currFrame = SDL_GetTicks();
    106   float dt = (float)(currFrame - lastFrame) / 1000.0;
    107   lastFrame = currFrame;
    108   this->camera->tick(dt);
    109 
    110   this->moduleTick(dt);
    111 
    112   return dt;
     114      // CALCULATE FRAMERATE
     115  Uint32 frameTimesIndex;
     116  Uint32 getTicks;
     117  Uint32 i;
     118
     119  frameTimesIndex = this->cycle % TICK_SMOOTH_VALUE;
     120  getTicks = SDL_GetTicks();
     121  this->frameTimes[frameTimesIndex] = getTicks - this->lastFrame;
     122  this->lastFrame = getTicks;
     123  ++this->cycle;
     124  this->dtS = 0;
     125  for (i = 0; i < TICK_SMOOTH_VALUE; i++)
     126    this->dtS += this->frameTimes[i];
     127  this->dtS = this->dtS / TICK_SMOOTH_VALUE / 1000.0f * speed;
     128
     129  this->camera->tick(dtS);
     130
     131  this->moduleTick(dtS);
     132
     133  return dtS;
    113134}
    114135
  • trunk/src/subprojects/framework.h

    r6981 r7159  
    1212
    1313#define MOUSE_BUTTON_COUNT 3
     14
     15#define TICK_SMOOTH_VALUE 10
    1416
    1517class Camera;
     
    5961    float                       backgroundColor[4];
    6062
    61     Uint32                      lastFrame;
    62     Uint32                      currFrame;
     63    /* world timing */
     64    Uint32              lastFrame;                    //!< last time of frame (in MiliSeconds)
     65    Uint32              cycle;                        //!< The cycle we are in (starts with 0 and rises with every frame)
     66    float               dtS;                          //!< The time needed for caluculations in seconds
     67    float               speed;                        //!< how fast the game flows
     68    double              gameTime;                     //!< this is where the game time is saved
     69    Uint32              frameTimes[TICK_SMOOTH_VALUE];//!< The time used for the last TICK_SMOOTH_VALUE's frames.
    6370
    6471    Uint8*                      keys;        // This variable will be used in the keyboard routine
Note: See TracChangeset for help on using the changeset viewer.