source: trunk/src/debugfps.cpp @ 154

Last change on this file since 154 was 154, checked in by sam, 10 years ago

Refactor stuff.

  • Property svn:keywords set to Id
File size: 1.7 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 "core.h"
13#include "debugfps.h"
14
15/*
16 * DebugFps implementation class
17 */
18
19class DebugFpsData
20{
21    friend class DebugFps;
22
23private:
24    int fontid;
25    int frame;
26};
27
28/*
29 * Public DebugFps class
30 */
31
32DebugFps::DebugFps()
33{
34    data = new DebugFpsData();
35
36    data->fontid = Forge::Register("gfx/font/ascii.png");
37    data->frame = 0;
38}
39
40Entity::Group DebugFps::GetGroup()
41{
42    return GROUP_AFTER;
43}
44
45void DebugFps::TickDraw(float deltams)
46{
47    Entity::TickDraw(deltams);
48
49    data->frame++;
50
51    char buf[1024];
52    Font *font = Forge::GetFont(data->fontid);
53
54    sprintf(buf, "%2.2f fps (%i)",
55            1e3f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME), data->frame);
56    font->PrintBold(10, 10, buf);
57
58    sprintf(buf, "Game  % 7.2f % 7.2f",
59            Profiler::GetAvg(Profiler::STAT_TICK_GAME),
60            Profiler::GetMax(Profiler::STAT_TICK_GAME));
61    font->PrintBold(10, 34, buf);
62
63    sprintf(buf, "Draw  % 7.2f % 7.2f",
64            Profiler::GetAvg(Profiler::STAT_TICK_DRAW),
65            Profiler::GetMax(Profiler::STAT_TICK_DRAW));
66    font->PrintBold(10, 50, buf);
67
68    sprintf(buf, "Blit  % 7.2f % 7.2f",
69            Profiler::GetAvg(Profiler::STAT_TICK_BLIT),
70            Profiler::GetMax(Profiler::STAT_TICK_BLIT));
71    font->PrintBold(10, 66, buf);
72
73    sprintf(buf, "Frame % 7.2f % 7.2f",
74            Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
75            Profiler::GetMax(Profiler::STAT_TICK_FRAME));
76    font->PrintBold(10, 82, buf);
77}
78
79DebugFps::~DebugFps()
80{
81    Forge::Deregister(data->fontid);
82    delete data;
83}
84
Note: See TracBrowser for help on using the repository browser.