source: trunk/src/debugfps.cpp @ 646

Last change on this file since 646 was 646, checked in by sam, 9 years ago

Ensure the DebugFps object is rendered in front of everything else.

  • Property svn:keywords set to Id
File size: 2.6 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#if 0
40    for (int i = 0; i < 5; i ++)
41    {
42        data->lines[i] = new Text(NULL, "gfx/font/ascii.png");
43        data->lines[i]->SetPos(int3(x, y + (i ? 8 : 0) + 16 * i, 0));
44        Ticker::Ref(data->lines[i]);
45    }
46#else
47    data->lines[0] = new Text(NULL, "gfx/font/ascii.png");
48    data->lines[0]->SetPos(int3(x, y, 100));
49    Ticker::Ref(data->lines[0]);
50#endif
51}
52
53void DebugFps::TickGame(float deltams)
54{
55    Entity::TickGame(deltams);
56
57    char buf[1024];
58
59#if 0
60    sprintf(buf, "%2.2f fps (%i)",
61            1e3f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
62            Ticker::GetFrameNum());
63    data->lines[0]->SetText(buf);
64
65    sprintf(buf, "Game  % 7.2f % 7.2f",
66            Profiler::GetAvg(Profiler::STAT_TICK_GAME),
67            Profiler::GetMax(Profiler::STAT_TICK_GAME));
68    data->lines[1]->SetText(buf);
69
70    sprintf(buf, "Draw  % 7.2f % 7.2f",
71            Profiler::GetAvg(Profiler::STAT_TICK_DRAW),
72            Profiler::GetMax(Profiler::STAT_TICK_DRAW));
73    data->lines[2]->SetText(buf);
74
75    sprintf(buf, "Blit  % 7.2f % 7.2f",
76            Profiler::GetAvg(Profiler::STAT_TICK_BLIT),
77            Profiler::GetMax(Profiler::STAT_TICK_BLIT));
78    data->lines[3]->SetText(buf);
79
80    sprintf(buf, "Frame % 7.2f % 7.2f",
81            Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
82            Profiler::GetMax(Profiler::STAT_TICK_FRAME));
83    data->lines[4]->SetText(buf);
84#else
85    sprintf(buf, "%2.2f/%2.2f/%2.2f/%2.2f %2.2f fps (%i)",
86            Profiler::GetAvg(Profiler::STAT_TICK_GAME),
87            Profiler::GetAvg(Profiler::STAT_TICK_DRAW),
88            Profiler::GetAvg(Profiler::STAT_TICK_BLIT),
89            Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
90            1e3f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
91            Ticker::GetFrameNum());
92    data->lines[0]->SetText(buf);
93#endif
94}
95
96DebugFps::~DebugFps()
97{
98#if 0
99    for (int i = 0; i < 5; i ++)
100        Ticker::Unref(data->lines[i]);
101#else
102    Ticker::Unref(data->lines[0]);
103#endif
104    delete data;
105}
106
Note: See TracBrowser for help on using the repository browser.