source: trunk/src/debugfps.cpp @ 259

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

Slightly change the ...Data initialisation in classes.

  • Property svn:keywords set to Id
File size: 2.0 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2011 Sam Hocevar <sam@hocevar.net>
5//   This program is free software; you can redistribute it and/or
6//   modify it under the terms of the Do What The Fuck You Want To
7//   Public License, Version 2, as published by Sam Hocevar. See
8//   http://sam.zoy.org/projects/COPYING.WTFPL for more details.
9//
10
11#if defined HAVE_CONFIG_H
12#   include "config.h"
13#endif
14
15#include <cstdio>
16
17#include "core.h"
18#include "debugfps.h"
19
20/*
21 * DebugFps implementation class
22 */
23
24class DebugFpsData
25{
26    friend class DebugFps;
27
28private:
29    int x, y;
30    int fontid;
31};
32
33/*
34 * Public DebugFps class
35 */
36
37DebugFps::DebugFps(int x, int y)
38  : data(new DebugFpsData())
39{
40    data->fontid = Forge::Register("gfx/font/ascii.png");
41    data->x = x;
42    data->y = y;
43
44    drawgroup = DRAWGROUP_HUD;
45}
46
47void DebugFps::TickDraw(float deltams)
48{
49    Entity::TickDraw(deltams);
50
51    char buf[1024];
52    Font *font = Forge::GetFont(data->fontid);
53
54    int x = data->x;
55    int y = data->y;
56
57    sprintf(buf, "%2.2f fps (%i)",
58            1e3f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
59            Ticker::GetFrameNum());
60    font->PrintBold(x, y, buf);
61
62    sprintf(buf, "Game  % 7.2f % 7.2f",
63            Profiler::GetAvg(Profiler::STAT_TICK_GAME),
64            Profiler::GetMax(Profiler::STAT_TICK_GAME));
65    font->PrintBold(x, y + 24, buf);
66
67    sprintf(buf, "Draw  % 7.2f % 7.2f",
68            Profiler::GetAvg(Profiler::STAT_TICK_DRAW),
69            Profiler::GetMax(Profiler::STAT_TICK_DRAW));
70    font->PrintBold(x, y + 40, buf);
71
72    sprintf(buf, "Blit  % 7.2f % 7.2f",
73            Profiler::GetAvg(Profiler::STAT_TICK_BLIT),
74            Profiler::GetMax(Profiler::STAT_TICK_BLIT));
75    font->PrintBold(x, y + 56, buf);
76
77    sprintf(buf, "Frame % 7.2f % 7.2f",
78            Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
79            Profiler::GetMax(Profiler::STAT_TICK_FRAME));
80    font->PrintBold(x, y + 72, buf);
81}
82
83DebugFps::~DebugFps()
84{
85    Forge::Deregister(data->fontid);
86    delete data;
87}
88
Note: See TracBrowser for help on using the repository browser.