source: trunk/src/debugfps.cpp @ 130

Last change on this file since 130 was 130, checked in by sam, 11 years ago

Try to detect assets not calling their super tick methods. Already spotted
one bug thanks to that.

  • Property svn:keywords set to Id
File size: 1.8 KB
Line 
1//
2// Deus Hax (working title)
3// Copyright (c) 2010 Sam Hocevar <sam@hocevar.net>
4//
5
6#if defined HAVE_CONFIG_H
7#   include "config.h"
8#endif
9
10#include <cstdio>
11
12#include "debugfps.h"
13#include "forge.h"
14#include "profiler.h"
15
16/*
17 * DebugFps implementation class
18 */
19
20class DebugFpsData
21{
22    friend class DebugFps;
23
24private:
25    Font *font;
26    int frame;
27};
28
29/*
30 * Public DebugFps class
31 */
32
33DebugFps::DebugFps()
34{
35    data = new DebugFpsData();
36
37    data->font = Forge::GetFont("gfx/font/ascii.png");
38    data->frame = 0;
39}
40
41Asset::Group DebugFps::GetGroup()
42{
43    return GROUP_AFTER;
44}
45
46void DebugFps::TickRender(float delta_time)
47{
48    Asset::TickRender(delta_time);
49
50    data->frame++;
51
52    char buf[1024];
53
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, 34, 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, 50, 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, 66, 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);
77}
78
79DebugFps::~DebugFps()
80{
81    Forge::ReleaseFont(data->font);
82    delete data;
83}
84
Note: See TracBrowser for help on using the repository browser.