source: trunk/src/debug/fps.cpp @ 866

Last change on this file since 866 was 866, checked in by sam, 12 years ago

core: more vec?i -> ?veci renames.

  • Property svn:keywords set to Id
File size: 2.7 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 "loldebug.h"
19
20using namespace std;
21
22namespace lol
23{
24
25/*
26 * DebugFps implementation class
27 */
28
29class DebugFpsData
30{
31    friend class DebugFps;
32
33private:
34    Text *lines[5];
35};
36
37/*
38 * Public DebugFps class
39 */
40
41DebugFps::DebugFps(int x, int y)
42  : data(new DebugFpsData())
43{
44#if 0
45    for (int i = 0; i < 5; i ++)
46    {
47        data->lines[i] = new Text(NULL, "gfx/font/ascii.png");
48        data->lines[i]->SetPos(ivec3(x, y + (i ? 8 : 0) + 16 * i, 0));
49        Ticker::Ref(data->lines[i]);
50    }
51#else
52    data->lines[0] = new Text(NULL, "gfx/font/ascii.png");
53    data->lines[0]->SetPos(ivec3(x, y, 100));
54    Ticker::Ref(data->lines[0]);
55#endif
56}
57
58void DebugFps::TickGame(float deltams)
59{
60    Entity::TickGame(deltams);
61
62    char buf[1024];
63
64#if 0
65    sprintf(buf, "%2.2f fps (%i)",
66            1e3f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
67            Ticker::GetFrameNum());
68    data->lines[0]->SetText(buf);
69
70    sprintf(buf, "Game  % 7.2f % 7.2f",
71            Profiler::GetAvg(Profiler::STAT_TICK_GAME),
72            Profiler::GetMax(Profiler::STAT_TICK_GAME));
73    data->lines[1]->SetText(buf);
74
75    sprintf(buf, "Draw  % 7.2f % 7.2f",
76            Profiler::GetAvg(Profiler::STAT_TICK_DRAW),
77            Profiler::GetMax(Profiler::STAT_TICK_DRAW));
78    data->lines[2]->SetText(buf);
79
80    sprintf(buf, "Blit  % 7.2f % 7.2f",
81            Profiler::GetAvg(Profiler::STAT_TICK_BLIT),
82            Profiler::GetMax(Profiler::STAT_TICK_BLIT));
83    data->lines[3]->SetText(buf);
84
85    sprintf(buf, "Frame % 7.2f % 7.2f",
86            Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
87            Profiler::GetMax(Profiler::STAT_TICK_FRAME));
88    data->lines[4]->SetText(buf);
89#else
90    sprintf(buf, "%2.2f/%2.2f/%2.2f/%2.2f %2.2f fps (%i)",
91            Profiler::GetAvg(Profiler::STAT_TICK_GAME),
92            Profiler::GetAvg(Profiler::STAT_TICK_DRAW),
93            Profiler::GetAvg(Profiler::STAT_TICK_BLIT),
94            Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
95            1e3f / Profiler::GetAvg(Profiler::STAT_TICK_FRAME),
96            Ticker::GetFrameNum());
97    data->lines[0]->SetText(buf);
98#endif
99}
100
101DebugFps::~DebugFps()
102{
103#if 0
104    for (int i = 0; i < 5; i ++)
105        Ticker::Unref(data->lines[i]);
106#else
107    Ticker::Unref(data->lines[0]);
108#endif
109    delete data;
110}
111
112} /* namespace lol */
113
Note: See TracBrowser for help on using the repository browser.