Changeset 619


Ignore:
Timestamp:
Feb 9, 2011, 1:33:57 AM (11 years ago)
Author:
sam
Message:

Add a recording mode to Ticker that ensures fixed deltatime even when
lagging behind.

Location:
trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/debugrecord.cpp

    r615 r619  
    4646  : data(new DebugRecordData())
    4747{
     48    Ticker::StartRecording();
     49
    4850    data->path = strdup(path);
    4951    data->width = 0;
     
    9799DebugRecord::~DebugRecord()
    98100{
     101    Ticker::StopRecording();
     102
    99103    delete data;
    100104}
  • trunk/src/ticker.cpp

    r618 r619  
    3131        todolist(0), autolist(0),
    3232        nentities(0),
    33         frame(0), benchmark(0), deltams(0), bias(0), fps(0),
     33        frame(0), benchmark(0), recording(0), deltams(0), bias(0), fps(0),
    3434        quit(0), quitframe(0), quitdelay(20), panic(0)
    3535    {
     
    6262
    6363    /* Fixed framerate management */
    64     int frame, benchmark;
     64    int frame, benchmark, recording;
    6565    Timer timer;
    6666    float deltams, bias, fps;
     
    169169    data->frame++;
    170170
    171     if (data->benchmark && data->fps)
     171    if (data->recording && data->fps)
    172172    {
    173173        data->deltams = 1000.0f / data->fps;
     
    325325    Profiler::Stop(Profiler::STAT_TICK_BLIT);
    326326
    327     if (data->benchmark)
    328     {
    329         data->bias = 0.0f;
    330     }
    331     else
    332     {
    333         float deltams = data->fps ? 1000.0f / data->fps : 0.0f;
    334 
    335         if (deltams > data->bias + 200.0f)
    336             deltams = data->bias + 200.0f; // Don't go below 5 fps
    337         if (deltams > data->bias)
    338             data->timer.WaitMs(deltams - data->bias);
    339         data->bias -= deltams;
    340     }
     327    /* If benchmarking, set wait time to 0. If FPS are fixed, force wait
     328     * time to 1/FPS. Otherwise, set wait time to 0. */
     329    float framems = (!data->benchmark && data->fps) ? 1000.0f / data->fps
     330                                                    : 0.0f;
     331
     332    if (!data->benchmark)
     333    {
     334        if (framems > data->bias + 200.0f)
     335            framems = data->bias + 200.0f; // Don't go below 5 fps
     336        if (framems > data->bias)
     337            data->timer.WaitMs(framems - data->bias);
     338    }
     339
     340    if (!data->recording)
     341        data->bias -= framems;
    341342}
    342343
     
    349350{
    350351    data->benchmark--;
     352}
     353
     354void Ticker::StartRecording()
     355{
     356    data->recording++;
     357}
     358
     359void Ticker::StopRecording()
     360{
     361    data->recording--;
    351362}
    352363
  • trunk/src/ticker.h

    r618 r619  
    3535    static void StartBenchmark();
    3636    static void StopBenchmark();
     37    static void StartRecording();
     38    static void StopRecording();
    3739    static int GetFrameNum();
    3840
Note: See TracChangeset for help on using the changeset viewer.