Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7131 in orxonox.OLD for trunk/src


Ignore:
Timestamp:
Feb 14, 2006, 12:23:11 PM (19 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.

Location:
trunk/src/story_entities
Files:
3 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);
  • trunk/src/story_entities/game_world.h

    r7004 r7131  
    1111#include "game_world_data.h"
    1212
    13 class TiXmlElement;
    1413class Shell;
    1514class WorldEntity;
    16 class GameWorldData;
    1715
     16/** How many frames time values to keep
     17 * The higher the value the smoother the result is...
     18 * Don't make it 0 or less :)
     19 */
     20#define TICK_SMOOTH_VALUE 10
    1821
    1922//! The game world
     
    8285
    8386    /* world timing */
    84     Uint32              lastFrame;                    //!< last time of frame
     87    Uint32              lastFrame;                    //!< last time of frame (in MiliSeconds)
    8588    Uint32              cycle;                        //!< The cycle we are in (starts with 0 and rises with every frame)
    86     Uint32              dt;                           //!< time needed to calculate this frame (in milliSeconds)
    8789    float               dtS;                          //!< The time needed for caluculations in seconds
    8890    float               speed;                        //!< how fast the game flows
    8991    double              gameTime;                     //!< this is where the game time is saved
     92    Uint32              frameTimes[TICK_SMOOTH_VALUE];//!< The time used for the last TICK_SMOOTH_VALUE's frames.
     93
    9094
    9195    /* external modules interfaces */
  • trunk/src/story_entities/simple_game_menu.cc

    r7063 r7131  
    296296  GameWorld::tick();
    297297
    298   this->animateScene(this->dt);
     298  this->animateScene(this->dtS);
    299299}
    300300
     
    314314void SimpleGameMenu::animateScene(float dt)
    315315{
    316   Quaternion q(/*0.00005*/ 0.0001* dt, Vector(0.0, 1.0, 0.0));
     316  Quaternion q(/*0.00005*/ dt * .1, Vector(0.0, 1.0, 0.0));
    317317  this->cameraVector = q.apply(this->cameraVector);
    318318  this->dataTank->localCamera->setRelCoor(this->cameraVector);
Note: See TracChangeset for help on using the changeset viewer.