3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2018 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 #include <irrlicht_changes/static_text.h>
23 #include "gui/mainmenumanager.h"
25 #include "fontengine.h"
26 #include "clientmap.h"
28 #include "renderingengine.h"
32 // First line of debug text
33 m_guitext = gui::StaticText::add(guienv, utf8_to_wide(PROJECT_NAME_C).c_str(),
34 core::rect<s32>(0, 0, 0, 0), false, false, guiroot);
37 void GameUI::update(const RunStats &stats, Client *client,
38 const MapDrawControl *draw_control)
40 if (m_flags.show_debug) {
41 static float drawtime_avg = 0;
42 drawtime_avg = drawtime_avg * 0.95 + stats.drawtime * 0.05;
43 u16 fps = 1.0 / stats.dtime_jitter.avg;
45 std::ostringstream os(std::ios_base::binary);
47 << PROJECT_NAME_C " " << g_version_hash
49 << std::setprecision(0)
50 << ", drawtime: " << drawtime_avg << "ms"
51 << std::setprecision(1)
53 << (stats.dtime_jitter.max_fraction * 100.0) << "%"
54 << std::setprecision(1)
56 << (draw_control->range_all ? "All" : itos(draw_control->wanted_range))
57 << std::setprecision(3)
58 << ", RTT: " << client->getRTT() << "s";
59 setStaticText(m_guitext, utf8_to_wide(os.str()).c_str());
60 m_guitext->setVisible(true);
62 m_guitext->setVisible(false);
65 if (m_guitext->isVisible()) {
66 v2u32 screensize = RenderingEngine::get_instance()->getWindowSize();
67 m_guitext->setRelativePosition(core::rect<s32>(5, 5, screensize.X,
68 5 + g_fontengine->getTextHeight()));
72 void GameUI::initFlags()
74 memset(&m_flags, 0, sizeof(GameUI::Flags));
75 m_flags.show_chat = true;
76 m_flags.show_hud = true;
77 m_flags.show_debug = g_settings->getBool("show_debug");
80 void GameUI::showMinimap(bool show)
82 m_flags.show_minimap = show;