- Timestamp:
- Feb 14, 2006, 12:23:11 PM (19 years ago)
- Location:
- trunk/src/story_entities
- Files:
-
- 3 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); -
trunk/src/story_entities/game_world.h
r7004 r7131 11 11 #include "game_world_data.h" 12 12 13 class TiXmlElement;14 13 class Shell; 15 14 class WorldEntity; 16 class GameWorldData;17 15 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 18 21 19 22 //! The game world … … 82 85 83 86 /* world timing */ 84 Uint32 lastFrame; //!< last time of frame 87 Uint32 lastFrame; //!< last time of frame (in MiliSeconds) 85 88 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)87 89 float dtS; //!< The time needed for caluculations in seconds 88 90 float speed; //!< how fast the game flows 89 91 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 90 94 91 95 /* external modules interfaces */ -
trunk/src/story_entities/simple_game_menu.cc
r7063 r7131 296 296 GameWorld::tick(); 297 297 298 this->animateScene(this->dt );298 this->animateScene(this->dtS); 299 299 } 300 300 … … 314 314 void SimpleGameMenu::animateScene(float dt) 315 315 { 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)); 317 317 this->cameraVector = q.apply(this->cameraVector); 318 318 this->dataTank->localCamera->setRelCoor(this->cameraVector);
Note: See TracChangeset
for help on using the changeset viewer.