source: trunk/src/debugfps.cpp @ 294

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

Rename Float3 to float3, Int3 to int3 etc. and add the 4-member versions.

  • 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    Text *lines[5];
30};
31
32/*
33 * Public DebugFps class
34 */
35
36DebugFps::DebugFps(int x, int y)
37  : data(new DebugFpsData())
38{
39    for (int i = 0; i < 5; i ++)
40    {
41        data->lines[i] = new Text(NULL, "gfx/font/ascii.png");
42        data->lines[i]->SetPos(int3(x, y + (i ? 8 : 0) + 16 * i, 0));
43        Ticker::Ref(data->lines[i]);
44    }
45}
46
47void DebugFps::TickGame(float deltams)
48{
49    Entity::TickGame(deltams);
50
51    char buf[1024];
52
53    sprintf(buf, "%2.2f fps (%i)",
54            1e3f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
55            Ticker::GetFrameNum());
56    data->lines[0]->SetText(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    data->lines[1]->SetText(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    data->lines[2]->SetText(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    data->lines[3]->SetText(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    data->lines[4]->SetText(buf);
77}
78
79DebugFps::~DebugFps()
80{
81    for (int i = 0; i < 5; i ++)
82        Ticker::Unref(data->lines[i]);
83    delete data;
84}
85
Note: See TracBrowser for help on using the repository browser.