Changeset 122


Ignore:
Timestamp:
Aug 15, 2010, 6:56:09 PM (10 years ago)
Author:
sam
Message:

Implement the profiling system.

Location:
trunk/src
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/Makefile.am

    r116 r122  
    99    joystick.cpp joystick.h asset.cpp asset.h ticker.cpp ticker.h \
    1010    forge.cpp forge.h video.cpp video.h timer.cpp timer.h \
    11     debugfps.cpp debugfps.h
     11    profiler.cpp profiler.h debugfps.cpp debugfps.h
    1212libcommon_a_CXXFLAGS = `pkg-config --cflags sdl gl SDL_image`
    1313
  • trunk/src/debugfps.cpp

    r116 r122  
    1212#include "debugfps.h"
    1313#include "forge.h"
     14#include "profiler.h"
    1415
    1516/*
     
    2122    friend class DebugFps;
    2223
    23     static int const HISTORY = 30;
    24 
    2524private:
    26     float history[HISTORY];
    2725    Font *font;
    2826    int frame;
     
    3735    data = new DebugFpsData();
    3836
    39     for (int i = 0; i < DebugFpsData::HISTORY; i++)
    40         data->history[i] = 0.0f;
    4137    data->font = Forge::GetFont("gfx/font/ascii.png");
    4238    data->frame = 0;
     
    5248    Asset::TickGame(delta_time);
    5349
    54     data->history[data->frame % DebugFpsData::HISTORY] = delta_time;
    5550    data->frame++;
    5651
    57     float mean = 0.0f, max = 0.0f;
    58     for (int i = 0; i < DebugFpsData::HISTORY; i++)
    59     {
    60         mean += data->history[i];
    61         if (data->history[i] > max)
    62             max = data->history[i];
    63     }
    64     mean /= DebugFpsData::HISTORY;
     52    char buf[1024];
    6553
    66     char buf[1024];
    67     sprintf(buf, "%3.2f ms (%3.2f fps) -- max %3.2f ms -- #%i",
    68             1000.0f * mean, 1.0f / mean, 1000.0f * max, data->frame);
    69     data->font->Print(10, 10, buf);
    70     data->font->Print(11, 10, buf);
    71     data->font->Print(10, 11, buf);
     54    sprintf(buf, "%2.2f fps (%i)",
     55            1.0f / Profiler::GetMean(Profiler::STAT_TICK_FRAME), data->frame);
     56    data->font->PrintBold(10, 10, buf);
     57
     58    sprintf(buf, "Game   % 7.2f % 7.2f",
     59            1e3f * Profiler::GetMean(Profiler::STAT_TICK_GAME),
     60            1e3f * Profiler::GetMax(Profiler::STAT_TICK_GAME));
     61    data->font->PrintBold(10, 28, buf);
     62
     63    sprintf(buf, "Render % 7.2f % 7.2f",
     64            1e3f * Profiler::GetMean(Profiler::STAT_TICK_RENDER),
     65            1e3f * Profiler::GetMax(Profiler::STAT_TICK_RENDER));
     66    data->font->PrintBold(10, 46, buf);
     67
     68    sprintf(buf, "Blit   % 7.2f % 7.2f",
     69            1e3f * Profiler::GetMean(Profiler::STAT_TICK_BLIT),
     70            1e3f * Profiler::GetMax(Profiler::STAT_TICK_BLIT));
     71    data->font->PrintBold(10, 64, buf);
     72
     73    sprintf(buf, "Frame  % 7.2f % 7.2f",
     74            1e3f * Profiler::GetMean(Profiler::STAT_TICK_FRAME),
     75            1e3f * Profiler::GetMax(Profiler::STAT_TICK_FRAME));
     76    data->font->PrintBold(10, 82, buf);
    7277}
    7378
  • trunk/src/gtk/editor.cpp

    r116 r122  
    7878        ticking = 0;
    7979
    80         /* Clear the screen, tick the renderer, and show the frame */
     80        /* Clear the screen, tick the renderer, show the frame and
     81         * clamp to desired framerate. */
    8182        Video::Clear();
    8283        Ticker::TickRender();
  • trunk/src/test-map.cpp

    r118 r122  
    1717#include "game.h"
    1818#include "ticker.h"
     19#include "profiler.h"
    1920#include "video.h"
    2021
     
    5758        Ticker::TickGame();
    5859
    59         /* Clear the screen, tick the renderer, and show the frame */
     60        /* Clear the screen, tick the renderer, show the frame and
     61         * clamp to desired framerate. */
    6062        Video::Clear();
    6163        Ticker::TickRender();
    6264        SDL_GL_SwapBuffers();
    63 
    64         /* Clamp to desired framerate */
    6565        Ticker::ClampFps(FPS);
    6666    }
  • trunk/src/ticker.cpp

    r116 r122  
    1212#include <stdint.h>
    1313
     14#include "profiler.h"
    1415#include "ticker.h"
    1516#include "asset.h"
     
    3132        for (int i = 0; i < Asset::GROUP_COUNT; i++)
    3233            list[i] = NULL;
    33         timer = new Timer();
    3434        bias = 0.0f;
    3535    }
     
    4141            fprintf(stderr, "ERROR: still %i assets in ticker\n", nassets);
    4242#endif
    43         delete timer;
    4443    }
    4544
     
    5049    int nassets;
    5150
    52     /* FPS management */
    53     float delta_time;
    54     Timer *timer;
    55     float bias;
     51    /* Fixed framerate management */
     52    Timer timer;
     53    float delta_time, bias;
    5654}
    5755tickerdata;
     
    7472void Ticker::TickGame()
    7573{
    76     data->delta_time = data->timer->GetSeconds();
     74    Profiler::Stop(Profiler::STAT_TICK_FRAME);
     75    Profiler::Start(Profiler::STAT_TICK_FRAME);
     76    Profiler::Start(Profiler::STAT_TICK_GAME);
     77
     78    data->delta_time = data->timer.GetSeconds();
    7779    data->bias += data->delta_time;
    7880
     
    108110            if (!a->destroy)
    109111                a->TickGame(data->delta_time);
     112
     113    Profiler::Stop(Profiler::STAT_TICK_GAME);
    110114}
    111115
    112116void Ticker::TickRender()
    113117{
     118    Profiler::Start(Profiler::STAT_TICK_RENDER);
     119
    114120    /* Tick objects for the render loop */
    115121    for (int i = 0; i < Asset::GROUP_COUNT; i++)
     
    117123            if (!a->destroy)
    118124                a->TickRender(data->delta_time);
     125
     126    Profiler::Stop(Profiler::STAT_TICK_RENDER);
     127    Profiler::Start(Profiler::STAT_TICK_BLIT);
    119128}
    120129
    121130void Ticker::ClampFps(float fps)
    122131{
     132    Profiler::Stop(Profiler::STAT_TICK_BLIT);
     133
    123134    float ideal_time = 1.0f / fps;
    124 
    125     data->timer->WaitSeconds(ideal_time - data->bias);
     135    if (ideal_time > data->bias)
     136        data->timer.WaitSeconds(ideal_time - data->bias);
    126137    data->bias -= ideal_time;
    127138}
Note: See TracChangeset for help on using the changeset viewer.