]> git.lizzy.rs Git - dragonfireclient.git/blob - src/client/gameui.cpp
53d9f4a9cf5f3c15df138e2d7f1a0649c0e26869
[dragonfireclient.git] / src / client / gameui.cpp
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2018 nerzhul, Loic Blot <loic.blot@unix-experience.fr>
5
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.
10
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.
15
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.
19 */
20
21 #include "gameui.h"
22 #include <irrlicht_changes/static_text.h>
23 #include "gui/mainmenumanager.h"
24 #include "client.h"
25 #include "fontengine.h"
26 #include "clientmap.h"
27 #include "version.h"
28 #include "renderingengine.h"
29
30 void GameUI::init()
31 {
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);
35 }
36
37 void GameUI::update(const RunStats &stats, Client *client,
38         const MapDrawControl *draw_control)
39 {
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;
44
45                 std::ostringstream os(std::ios_base::binary);
46                 os << std::fixed
47                         << PROJECT_NAME_C " " << g_version_hash
48                         << ", FPS: " << fps
49                         << std::setprecision(0)
50                         << ", drawtime: " << drawtime_avg << "ms"
51                         << std::setprecision(1)
52                         << ", dtime jitter: "
53                         << (stats.dtime_jitter.max_fraction * 100.0) << "%"
54                         << std::setprecision(1)
55                         << ", view range: "
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);
61         } else {
62                 m_guitext->setVisible(false);
63         }
64
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()));
69         }
70 }
71
72 void GameUI::initFlags()
73 {
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");
78 }
79
80 void GameUI::showMinimap(bool show)
81 {
82         m_flags.show_minimap = show;
83 }