source: trunk/src/debugfps.cpp @ 227

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

Spawn several pieces in Monsterz now that we can.

  • 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{
39    data = new DebugFpsData();
40
41    data->fontid = Forge::Register("gfx/font/ascii.png");
42    data->x = x;
43    data->y = y;
44
45    drawgroup = DRAWGROUP_HUD;
46}
47
48void DebugFps::TickDraw(float deltams)
49{
50    Entity::TickDraw(deltams);
51
52    char buf[1024];
53    Font *font = Forge::GetFont(data->fontid);
54
55    int x = data->x;
56    int y = data->y;
57
58    sprintf(buf, "%2.2f fps (%i)",
59            1e3f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
60            Ticker::GetFrameNum());
61    font->PrintBold(x, y, buf);
62
63    sprintf(buf, "Game  % 7.2f % 7.2f",
64            Profiler::GetAvg(Profiler::STAT_TICK_GAME),
65            Profiler::GetMax(Profiler::STAT_TICK_GAME));
66    font->PrintBold(x, y + 24, buf);
67
68    sprintf(buf, "Draw  % 7.2f % 7.2f",
69            Profiler::GetAvg(Profiler::STAT_TICK_DRAW),
70            Profiler::GetMax(Profiler::STAT_TICK_DRAW));
71    font->PrintBold(x, y + 40, buf);
72
73    sprintf(buf, "Blit  % 7.2f % 7.2f",
74            Profiler::GetAvg(Profiler::STAT_TICK_BLIT),
75            Profiler::GetMax(Profiler::STAT_TICK_BLIT));
76    font->PrintBold(x, y + 56, buf);
77
78    sprintf(buf, "Frame % 7.2f % 7.2f",
79            Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
80            Profiler::GetMax(Profiler::STAT_TICK_FRAME));
81    font->PrintBold(x, y + 72, buf);
82}
83
84DebugFps::~DebugFps()
85{
86    Forge::Deregister(data->fontid);
87    delete data;
88}
89
Note: See TracBrowser for help on using the repository browser.