source: trunk/src/debugfps.cpp @ 167

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

Store the frame number in the Ticker instead of duplicating the information
in each class that uses it.

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