Changeset 603


Ignore:
Timestamp:
May 8, 2011, 5:32:24 PM (6 years ago)
Author:
Sam Hocevar
Message:

game: refactor the framerate logic so that it predicts framerate based
on time averages rather than frames per second averages.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • abuse/trunk/src/game.cpp

    r578 r603  
    15091509
    15101510time_marker *led_last_time = NULL;
    1511 static float avg_fps = 15.0f, possible_fps = 15.0f;
     1511static float avg_ms = 1000.0f / 15, possible_ms = 1000.0f / 15;
    15121512
    15131513void Game::toggle_delay()
     
    15151515    no_delay = !no_delay;
    15161516    show_help(symbol_str(no_delay ? "delay_off" : "delay_on"));
    1517     avg_fps = possible_fps = 15.0f;
     1517    avg_ms = possible_ms = 1000.0f / 15;
    15181518}
    15191519
     
    15241524
    15251525    char str[16];
    1526     sprintf(str, "%ld", (long)(avg_fps * 10.0));
     1526    sprintf(str, "%ld", (long)(10000.0f / avg_ms));
    15271527    console_font->put_string(screen, first_view->cx1, first_view->cy1, str);
    15281528
     
    16061606
    16071607    // Find average fps for last 10 frames
    1608     float fps = 1000.0f / Max(1.0f, frame_timer.PollMs());
    1609 
    1610     avg_fps = 0.9f * avg_fps + 0.1f * fps;
    1611     possible_fps = 0.9f * possible_fps + 0.1f * fps;
    1612 
    1613     if (avg_fps > 14)
     1608    float deltams = Max(1.0f, frame_timer.PollMs());
     1609
     1610    avg_ms = 0.9f * avg_ms + 0.1f * deltams;
     1611    possible_ms = 0.9f * possible_ms + 0.1f * deltams;
     1612
     1613    if (avg_ms < 1000.0f / 14)
    16141614        massive_frame_panic = Max(0, Min(20, massive_frame_panic - 1));
    16151615
     
    16221622        frame_timer.WaitMs(33);
    16231623    }
    1624     else if (avg_fps > 15 && need_delay)
     1624    else if (avg_ms < 1000.0f / 15 && need_delay)
    16251625    {
    16261626        frame_panic = 0;
     
    16281628        {
    16291629            frame_timer.WaitMs(1000.0f / 15);
    1630             avg_fps -= 0.1f * fps;
    1631             avg_fps += 0.1f * 15.0f;
     1630            avg_ms -= 0.1f * deltams;
     1631            avg_ms += 0.1f * 1000.0f / 15;
    16321632        }
    16331633    }
    1634     else if (avg_fps < 14)
    1635     {
    1636         if(avg_fps < 10)
     1634    else if (avg_ms > 1000.0f / 14)
     1635    {
     1636        if(avg_ms > 1000.0f / 10)
    16371637            massive_frame_panic++;
    16381638        frame_panic++;
Note: See TracChangeset for help on using the changeset viewer.