Changeset 149


Ignore:
Timestamp:
Aug 21, 2010, 7:50:45 PM (10 years ago)
Author:
sam
Message:

Get the timer to talk milliseconds instead of seconds.

Location:
trunk/src
Files:
23 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/debugfps.cpp

    r147 r149  
    4444}
    4545
    46 void DebugFps::TickRender(float delta_time)
     46void DebugFps::TickRender(float deltams)
    4747{
    48     Entity::TickRender(delta_time);
     48    Entity::TickRender(deltams);
    4949
    5050    data->frame++;
     
    5353
    5454    sprintf(buf, "%2.2f fps (%i)",
    55             1.0f / Profiler::GetMean(Profiler::STAT_TICK_FRAME), data->frame);
     55            1e3f / Profiler::GetMean(Profiler::STAT_TICK_FRAME), data->frame);
    5656    data->font->PrintBold(10, 10, buf);
    5757
    5858    sprintf(buf, "Game   % 7.2f % 7.2f",
    59             1e3f * Profiler::GetMean(Profiler::STAT_TICK_GAME),
    60             1e3f * Profiler::GetMax(Profiler::STAT_TICK_GAME));
     59            Profiler::GetMean(Profiler::STAT_TICK_GAME),
     60            Profiler::GetMax(Profiler::STAT_TICK_GAME));
    6161    data->font->PrintBold(10, 34, buf);
    6262
    6363    sprintf(buf, "Render % 7.2f % 7.2f",
    64             1e3f * Profiler::GetMean(Profiler::STAT_TICK_RENDER),
    65             1e3f * Profiler::GetMax(Profiler::STAT_TICK_RENDER));
     64            Profiler::GetMean(Profiler::STAT_TICK_RENDER),
     65            Profiler::GetMax(Profiler::STAT_TICK_RENDER));
    6666    data->font->PrintBold(10, 50, buf);
    6767
    6868    sprintf(buf, "Blit   % 7.2f % 7.2f",
    69             1e3f * Profiler::GetMean(Profiler::STAT_TICK_BLIT),
    70             1e3f * Profiler::GetMax(Profiler::STAT_TICK_BLIT));
     69            Profiler::GetMean(Profiler::STAT_TICK_BLIT),
     70            Profiler::GetMax(Profiler::STAT_TICK_BLIT));
    7171    data->font->PrintBold(10, 66, buf);
    7272
    7373    sprintf(buf, "Frame  % 7.2f % 7.2f",
    74             1e3f * Profiler::GetMean(Profiler::STAT_TICK_FRAME),
    75             1e3f * Profiler::GetMax(Profiler::STAT_TICK_FRAME));
     74            Profiler::GetMean(Profiler::STAT_TICK_FRAME),
     75            Profiler::GetMax(Profiler::STAT_TICK_FRAME));
    7676    data->font->PrintBold(10, 82, buf);
    7777}
  • trunk/src/debugfps.h

    r147 r149  
    2424protected:
    2525    virtual Group GetGroup();
    26     virtual void TickRender(float delta_time);
     26    virtual void TickRender(float deltams);
    2727
    2828private:
  • trunk/src/debugrecord.cpp

    r147 r149  
    4848}
    4949
    50 void DebugRecord::TickGame(float delta_time)
     50void DebugRecord::TickGame(float deltams)
    5151{
    52     Entity::TickGame(delta_time);
     52    Entity::TickGame(deltams);
    5353}
    5454
    55 void DebugRecord::TickRender(float delta_time)
     55void DebugRecord::TickRender(float deltams)
    5656{
    57     Entity::TickRender(delta_time);
     57    Entity::TickRender(deltams);
    5858
    5959    int width = Video::GetWidth();
  • trunk/src/debugrecord.h

    r147 r149  
    2424protected:
    2525    virtual Group GetGroup();
    26     virtual void TickGame(float delta_time);
    27     virtual void TickRender(float delta_time);
     26    virtual void TickGame(float deltams);
     27    virtual void TickRender(float deltams);
    2828
    2929private:
  • trunk/src/debugsprite.cpp

    r147 r149  
    4444}
    4545
    46 void DebugSprite::TickGame(float delta_time)
     46void DebugSprite::TickGame(float deltams)
    4747{
    48     Entity::TickGame(delta_time);
     48    Entity::TickGame(deltams);
    4949}
    5050
    51 void DebugSprite::TickRender(float delta_time)
     51void DebugSprite::TickRender(float deltams)
    5252{
    53     Entity::TickRender(delta_time);
     53    Entity::TickRender(deltams);
    5454
    5555    data->game->GetScene()->AddTile((data->tiler << 16) | 15, 320, 240, 32, 1);
  • trunk/src/debugsprite.h

    r147 r149  
    2525protected:
    2626    virtual Group GetGroup();
    27     virtual void TickGame(float delta_time);
    28     virtual void TickRender(float delta_time);
     27    virtual void TickGame(float deltams);
     28    virtual void TickRender(float deltams);
    2929
    3030private:
  • trunk/src/entity.cpp

    r147 r149  
    4242}
    4343
    44 void Entity::TickGame(float delta_time)
     44void Entity::TickGame(float deltams)
    4545{
    4646#if !FINAL_RELEASE
     
    5151}
    5252
    53 void Entity::TickRender(float delta_time)
     53void Entity::TickRender(float deltams)
    5454{
    5555#if !FINAL_RELEASE
  • trunk/src/entity.h

    r147 r149  
    4343    virtual Group GetGroup();
    4444
    45     virtual void TickGame(float delta_time);
    46     virtual void TickRender(float delta_time);
     45    virtual void TickGame(float deltams);
     46    virtual void TickRender(float deltams);
    4747
    4848    Entity *next;
  • trunk/src/font.cpp

    r147 r149  
    8282}
    8383
    84 void Font::TickRender(float delta_time)
     84void Font::TickRender(float deltams)
    8585{
    86     Entity::TickRender(delta_time);
     86    Entity::TickRender(deltams);
    8787}
    8888
  • trunk/src/font.h

    r147 r149  
    2525    /* Inherited from Entity */
    2626    virtual Group GetGroup();
    27     virtual void TickRender(float delta_time);
     27    virtual void TickRender(float deltams);
    2828
    2929public:
  • trunk/src/game.cpp

    r147 r149  
    5454}
    5555
    56 void Game::TickGame(float delta_time)
     56void Game::TickGame(float deltams)
    5757{
    58     Entity::TickGame(delta_time);
     58    Entity::TickGame(deltams);
    5959}
    6060
    61 void Game::TickRender(float delta_time)
     61void Game::TickRender(float deltams)
    6262{
    63     Entity::TickRender(delta_time);
     63    Entity::TickRender(deltams);
    6464
    6565    GetScene();
  • trunk/src/game.h

    r147 r149  
    2626    /* Inherited from Entity */
    2727    virtual Group GetGroup();
    28     virtual void TickGame(float delta_time);
    29     virtual void TickRender(float delta_time);
     28    virtual void TickGame(float deltams);
     29    virtual void TickRender(float deltams);
    3030
    3131public:
  • trunk/src/gtk/editor.cpp

    r147 r149  
    8585        while (g_main_context_iteration(NULL, FALSE))
    8686            ;
    87         Ticker::ClampFps(1.0f / FPS);
     87        Ticker::ClampFps(1000.0f / FPS);
    8888    }
    8989
  • trunk/src/profiler.cpp

    r122 r149  
    4848void Profiler::Start(int id)
    4949{
    50     data[id].timer.GetSeconds();
     50    data[id].timer.GetMs();
    5151}
    5252
    5353void Profiler::Stop(int id)
    5454{
    55     float delta_time = data[id].timer.GetSeconds();
     55    float deltams = data[id].timer.GetMs();
    5656
    57     data[id].history[data->frame % ProfilerData::HISTORY] = delta_time;
     57    data[id].history[data->frame % ProfilerData::HISTORY] = deltams;
    5858    data[id].frame++;
    5959    data[id].mean = 0.0f;
  • trunk/src/sdlinput.cpp

    r147 r149  
    4141}
    4242
    43 void SdlInput::TickGame(float delta_time)
     43void SdlInput::TickGame(float deltams)
    4444{
    45     Entity::TickGame(delta_time);
     45    Entity::TickGame(deltams);
    4646
    4747    if (data->game->Finished())
  • trunk/src/sdlinput.h

    r147 r149  
    2525protected:
    2626    virtual Group GetGroup();
    27     virtual void TickGame(float delta_time);
     27    virtual void TickGame(float deltams);
    2828
    2929private:
  • trunk/src/test-map.cpp

    r145 r149  
    6767        Ticker::TickRender();
    6868        SDL_GL_SwapBuffers();
    69         Ticker::ClampFps(1.0f / FPS);
     69        Ticker::ClampFps(1000.0f / FPS);
    7070    }
    7171
  • trunk/src/ticker.cpp

    r147 r149  
    5151    /* Fixed framerate management */
    5252    Timer timer;
    53     float delta_time, bias;
     53    float deltams, bias;
    5454}
    5555tickerdata;
     
    7777    Profiler::Start(Profiler::STAT_TICK_GAME);
    7878
    79     data->delta_time = data->timer.GetSeconds();
    80     data->bias += data->delta_time;
     79    data->deltams = data->timer.GetMs();
     80    data->bias += data->deltams;
    8181
    8282    /* Garbage collect objects that can be destroyed. We can do this
     
    118118                a->state = Entity::STATE_PRETICK_GAME;
    119119#endif
    120                 a->TickGame(data->delta_time);
     120                a->TickGame(data->deltams);
    121121#if !FINAL_RELEASE
    122122                if (a->state != Entity::STATE_POSTTICK_GAME)
     
    143143                a->state = Entity::STATE_PRETICK_RENDER;
    144144#endif
    145                 a->TickRender(data->delta_time);
     145                a->TickRender(data->deltams);
    146146#if !FINAL_RELEASE
    147147                if (a->state != Entity::STATE_POSTTICK_RENDER)
     
    155155}
    156156
    157 void Ticker::ClampFps(float delta_time)
     157void Ticker::ClampFps(float deltams)
    158158{
    159159    Profiler::Stop(Profiler::STAT_TICK_BLIT);
    160160
    161     if (delta_time > data->bias + 0.2f)
    162         delta_time = data->bias + 0.2f; // Don't go below 5 fps
    163     if (delta_time > data->bias)
    164         data->timer.WaitSeconds(delta_time - data->bias);
    165     data->bias -= delta_time;
     161    if (deltams > data->bias + 200.0f)
     162        deltams = data->bias + 200.0f; // Don't go below 5 fps
     163    if (deltams > data->bias)
     164        data->timer.WaitMs(deltams - data->bias);
     165    data->bias -= deltams;
    166166}
    167167
  • trunk/src/ticker.h

    r147 r149  
    2424    static void TickGame();
    2525    static void TickRender();
    26     static void ClampFps(float delta_time);
     26    static void ClampFps(float deltams);
    2727};
    2828
  • trunk/src/tileset.cpp

    r147 r149  
    8080}
    8181
    82 void TileSet::TickRender(float delta_time)
     82void TileSet::TickRender(float deltams)
    8383{
    84     Entity::TickRender(delta_time);
     84    Entity::TickRender(deltams);
    8585
    8686    if (data->img)
  • trunk/src/tileset.h

    r147 r149  
    3030    /* Inherited from Entity */
    3131    virtual Group GetGroup();
    32     virtual void TickRender(float delta_time);
     32    virtual void TickRender(float deltams);
    3333
    3434public:
  • trunk/src/timer.cpp

    r128 r149  
    4141        LARGE_INTEGER tmp;
    4242        QueryPerformanceFrequency(&tmp);
    43         seconds_per_cycle = 1.0f / tmp.QuadPart;
     43        ms_per_cycle = 1e3f / tmp.QuadPart;
    4444        QueryPerformanceCounter(&cycles0);
    4545#else
     
    4949    }
    5050
    51     float GetOrWait(float seconds, bool update)
     51    float GetOrWait(float deltams, bool update)
    5252    {
    53         float ret, delta_time;
     53        float ret, towait;
    5454#if defined __linux__
    5555        struct timeval tv;
    5656        gettimeofday(&tv, NULL);
    57         ret = 1e-6f * (tv.tv_usec - tv0.tv_usec) + (tv.tv_sec - tv0.tv_sec);
     57        ret = 1e-3f * (tv.tv_usec - tv0.tv_usec)
     58            + 1e3f * (tv.tv_sec - tv0.tv_sec);
    5859        if (update)
    5960            tv0 = tv;
    60         delta_time = seconds - ret;
    61         if (delta_time > 0.0f)
    62             usleep((int)(delta_time * 1e6f));
     61        towait = deltams - ret;
     62        if (towait > 0.0f)
     63            usleep((int)(towait * 1e3f));
    6364#elif defined _WIN32
    6465        LARGE_INTEGER cycles;
    6566        QueryPerformanceCounter(&cycles);
    66         ret = seconds_per_cycle * (cycles.QuadPart - cycles0.QuadPart);
     67        ret = ms_per_cycle * (cycles.QuadPart - cycles0.QuadPart);
    6768        if (update)
    6869            cycles0 = cycles;
    69         delta_time = seconds - ret;
    70         if (delta_time > 5e-4f) // FIXME: use native Win32 stuff
    71             SDL_Delay((int)(delta_time * 1e3f + 0.5f));
     70        towait = deltams - ret;
     71        if (towait > 5e-4f) // FIXME: use native Win32 stuff
     72            SDL_Delay((int)(towait * 1e3f + 0.5f));
    7273#else
    7374        /* The crappy SDL fallback */
    7475        Uint32 ticks = SDL_GetTicks();
    75         ret = 1e-3f * (ticks - ticks0);
     76        ret = 1e-6f * (ticks - ticks0);
    7677        if (update)
    7778            ticks0 = ticks;
    78         delta_time = seconds - ret;
    79         if (delta_time > 5e-4f)
    80             SDL_Delay((int)(delta_time * 1e3f + 0.5f));
     79        towait = deltams - ret;
     80        if (towait > 0.5f)
     81            SDL_Delay((int)(towait + 0.5f));
    8182#endif
    8283        return ret;
     
    8687    struct timeval tv0;
    8788#elif defined _WIN32
    88     float seconds_per_cycle;
     89    float ms_per_cycle;
    8990    LARGE_INTEGER cycles0;
    9091#else
     
    107108}
    108109
    109 float Timer::GetSeconds()
     110float Timer::GetMs()
    110111{
    111112    return data->GetOrWait(0.0f, true);
    112113}
    113114
    114 float Timer::PollSeconds()
     115float Timer::PollMs()
    115116{
    116117    return data->GetOrWait(0.0f, false);
    117118}
    118119
    119 void Timer::WaitSeconds(float seconds)
     120void Timer::WaitMs(float deltams)
    120121{
    121     (void)data->GetOrWait(seconds, false);
     122    (void)data->GetOrWait(deltams, false);
    122123}
    123124
  • trunk/src/timer.h

    r128 r149  
    2020    ~Timer();
    2121
    22     float GetSeconds();
    23     float PollSeconds();
    24     void WaitSeconds(float milliseconds);
     22    float GetMs();
     23    float PollMs();
     24    void WaitMs(float deltams);
    2525
    2626private:
Note: See TracChangeset for help on using the changeset viewer.