Changeset 7131 in orxonox.OLD for trunk/src/story_entities/game_world.cc
- Timestamp:
- Feb 14, 2006, 12:23:11 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/story_entities/game_world.cc
r7108 r7131 124 124 ErrorMessage GameWorld::init() 125 125 { 126 this->cycle = 0;127 126 /* init the world interface */ 128 127 this->shell = new Shell(); … … 248 247 this->dataTank->music->playback(); 249 248 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; 250 256 this->lastFrame = SDL_GetTicks (); 251 PRINTF(3)("GameWorld::mainLoop() - Entering main loop\n");252 257 253 258 while( this->isRunning) /* @todo implement pause */ … … 310 315 } 311 316 317 312 318 /** 313 319 * advance the timeline … … 323 329 if( !this->isPaused) 324 330 { 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 339 354 this->tick(this->dataTank->objectManager->getObjectList(OM_DEAD_TICK), this->dtS); 340 355 this->tick(this->dataTank->objectManager->getObjectList(OM_ENVIRON), this->dtS);
Note: See TracChangeset
for help on using the changeset viewer.