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"
24 #include "util/pointedthing.h"
26 #include "clientmap.h"
27 #include "fontengine.h"
29 #include "renderingengine.h"
32 inline static const char *yawToDirectionString(int yaw)
34 static const char *direction[4] = {"N +Z", "W -X", "S -Z", "E +X"};
36 yaw = wrapDegrees_0_360(yaw);
37 yaw = (yaw + 45) % 360 / 90;
39 return direction[yaw];
44 // First line of debug text
45 m_guitext = gui::StaticText::add(guienv, utf8_to_wide(PROJECT_NAME_C).c_str(),
46 core::rect<s32>(0, 0, 0, 0), false, false, guiroot);
48 // Second line of debug text
49 m_guitext2 = gui::StaticText::add(guienv, L"", core::rect<s32>(0, 0, 0, 0), false,
52 // At the middle of the screen
53 // Object infos are shown in this
54 m_guitext_info = gui::StaticText::add(guienv, L"",
55 core::rect<s32>(0, 0, 400, g_fontengine->getTextHeight() * 5 + 5)
56 + v2s32(100, 200), false, true, guiroot);
59 void GameUI::update(const RunStats &stats, Client *client, MapDrawControl *draw_control,
60 const CameraOrientation &cam, const PointedThing &pointed_old)
62 v2u32 screensize = RenderingEngine::get_instance()->getWindowSize();
64 if (m_flags.show_debug) {
65 static float drawtime_avg = 0;
66 drawtime_avg = drawtime_avg * 0.95 + stats.drawtime * 0.05;
67 u16 fps = 1.0 / stats.dtime_jitter.avg;
69 std::ostringstream os(std::ios_base::binary);
71 << PROJECT_NAME_C " " << g_version_hash
73 << std::setprecision(0)
74 << ", drawtime: " << drawtime_avg << "ms"
75 << std::setprecision(1)
77 << (stats.dtime_jitter.max_fraction * 100.0) << "%"
78 << std::setprecision(1)
80 << (draw_control->range_all ? "All" : itos(draw_control->wanted_range))
81 << std::setprecision(3)
82 << ", RTT: " << client->getRTT() << "s";
83 setStaticText(m_guitext, utf8_to_wide(os.str()).c_str());
85 m_guitext->setRelativePosition(core::rect<s32>(5, 5, screensize.X,
86 5 + g_fontengine->getTextHeight()));
89 // Finally set the guitext visible depending on the flag
90 m_guitext->setVisible(m_flags.show_debug);
92 if (m_flags.show_debug) {
93 LocalPlayer *player = client->getEnv().getLocalPlayer();
94 v3f player_position = player->getPosition();
96 std::ostringstream os(std::ios_base::binary);
97 os << std::setprecision(1) << std::fixed
98 << "pos: (" << (player_position.X / BS)
99 << ", " << (player_position.Y / BS)
100 << ", " << (player_position.Z / BS)
101 << "), yaw: " << (wrapDegrees_0_360(cam.camera_yaw)) << "° "
102 << yawToDirectionString(cam.camera_yaw)
103 << ", seed: " << ((u64)client->getMapSeed());
105 if (pointed_old.type == POINTEDTHING_NODE) {
106 ClientMap &map = client->getEnv().getClientMap();
107 const INodeDefManager *nodedef = client->getNodeDefManager();
108 MapNode n = map.getNodeNoEx(pointed_old.node_undersurface);
110 if (n.getContent() != CONTENT_IGNORE && nodedef->get(n).name != "unknown") {
111 os << ", pointed: " << nodedef->get(n).name
112 << ", param2: " << (u64) n.getParam2();
116 setStaticText(m_guitext2, utf8_to_wide(os.str()).c_str());
118 m_guitext2->setRelativePosition(core::rect<s32>(5,
119 5 + g_fontengine->getTextHeight(), screensize.X,
120 5 + g_fontengine->getTextHeight() * 2
124 m_guitext2->setVisible(m_flags.show_debug);
126 setStaticText(m_guitext_info, translate_string(m_infotext).c_str());
127 m_guitext_info->setVisible(m_flags.show_hud && g_menumgr.menuCount() == 0);
130 void GameUI::initFlags()
132 memset(&m_flags, 0, sizeof(GameUI::Flags));
133 m_flags.show_chat = true;
134 m_flags.show_hud = true;
135 m_flags.show_debug = g_settings->getBool("show_debug");
138 void GameUI::showMinimap(bool show)
140 m_flags.show_minimap = show;