Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1028


Ignore:
Timestamp:
Apr 10, 2008, 9:57:19 PM (17 years ago)
Author:
rgrieder
Message:
  • added cheap fps counter
  • trunk should work so far
File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/src/orxonox/Orxonox.cc

    r1024 r1028  
    348348  void Orxonox::startRenderLoop()
    349349  {
     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
    350360    // use the ogre timer class to measure time.
    351361    if (!timer_)
     
    353363    timer_->reset();
    354364
    355     // Contains the times of recently fired events
    356     std::deque<unsigned long> eventTimes[3];
    357     // Clear event times
    358     for (int i = 0; i < 3; ++i)
    359       eventTimes[i].clear();
    360 
    361365          while (!bAbort_)
    362366          {
     
    366370      // get current time
    367371      unsigned long now = timer_->getMilliseconds();
     372      eventTimes[3].push_back(now);
     373      eventTimes[3].erase(eventTimes[3].begin());
    368374
    369375      // create an event to pass to the frameStarted method in ogre
     
    374380      // show the current time in the HUD
    375381      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())));
    376384
    377385      // Iterate through all Tickables and call their tick(dt) function
     
    383391      ogre_->frameStarted(evt);
    384392
    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
    387396
    388397      // get current time
     
    407416  {
    408417    // Calculate the average time passed between events of the given type
    409     // during the last mFrameSmoothingTime seconds.
     418    // during the last frameSmoothingTime_ seconds.
    410419
    411420    times.push_back(now);
     
    414423      return 0;
    415424
    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;
    419427
    420428    // 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
    423433    while(it != end)
    424434    {
     
    432442    times.erase(times.begin(), it);
    433443
    434     return (float)(times.back() - times.front()) / ((times.size()-1) * 1000);
     444    return (float)(times.back() - times.front()) / ((times.size() - 1) * 1000);
    435445  }
    436446
Note: See TracChangeset for help on using the changeset viewer.