Changeset 1028 for code/trunk/src
- Timestamp:
- Apr 10, 2008, 9:57:19 PM (17 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/Orxonox.cc
r1024 r1028 348 348 void Orxonox::startRenderLoop() 349 349 { 350 // Contains the times of recently fired events 351 // eventTimes[4] is the list for the times required for the fps counter 352 std::deque<unsigned long> eventTimes[4]; 353 // Clear event times 354 for (int i = 0; i < 4; ++i) 355 eventTimes[i].clear(); 356 // fill the fps time list with zeros 357 for (int i = 0; i < 20; i++) 358 eventTimes[3].push_back(0); 359 350 360 // use the ogre timer class to measure time. 351 361 if (!timer_) … … 353 363 timer_->reset(); 354 364 355 // Contains the times of recently fired events356 std::deque<unsigned long> eventTimes[3];357 // Clear event times358 for (int i = 0; i < 3; ++i)359 eventTimes[i].clear();360 361 365 while (!bAbort_) 362 366 { … … 366 370 // get current time 367 371 unsigned long now = timer_->getMilliseconds(); 372 eventTimes[3].push_back(now); 373 eventTimes[3].erase(eventTimes[3].begin()); 368 374 369 375 // create an event to pass to the frameStarted method in ogre … … 374 380 // show the current time in the HUD 375 381 orxonoxHUD_->setTime((int)now, 0); 382 if (eventTimes[3].back() - eventTimes[3].front() != 0) 383 orxonoxHUD_->setRocket1((int)(20000.0f/(eventTimes[3].back() - eventTimes[3].front()))); 376 384 377 385 // Iterate through all Tickables and call their tick(dt) function … … 383 391 ogre_->frameStarted(evt); 384 392 385 if (mode_ != SERVER) 386 ogre_->renderOneFrame(); // only render in non-server mode 393 // server still renders at the moment 394 //if (mode_ != SERVER) 395 ogre_->renderOneFrame(); // only render in non-server mode 387 396 388 397 // get current time … … 407 416 { 408 417 // Calculate the average time passed between events of the given type 409 // during the last mFrameSmoothingTimeseconds.418 // during the last frameSmoothingTime_ seconds. 410 419 411 420 times.push_back(now); … … 414 423 return 0; 415 424 416 // Times up to mFrameSmoothingTime seconds old should be kept 417 unsigned long discardThreshold = 418 static_cast<unsigned long>(frameSmoothingTime_ * 1000.0f); 425 // Times up to frameSmoothingTime_ seconds old should be kept 426 unsigned long discardThreshold = (unsigned long)frameSmoothingTime_ * 1000.0f; 419 427 420 428 // Find the oldest time to keep 421 std::deque<unsigned long>::iterator it = times.begin(), 422 end = times.end()-2; // We need at least two times 429 std::deque<unsigned long>::iterator it = times.begin(); 430 // We need at least two times 431 std::deque<unsigned long>::iterator end = times.end() - 2; 432 423 433 while(it != end) 424 434 { … … 432 442 times.erase(times.begin(), it); 433 443 434 return (float)(times.back() - times.front()) / ((times.size() -1) * 1000);444 return (float)(times.back() - times.front()) / ((times.size() - 1) * 1000); 435 445 } 436 446
Note: See TracChangeset
for help on using the changeset viewer.