From 7e4dccb3b5c4c3ec8a0ba89efece44266aa75ffe Mon Sep 17 00:00:00 2001 From: Desour Date: Tue, 22 Aug 2023 19:20:49 +0200 Subject: [PATCH] Revert "Get rid of global guienv variable" This reverts commit 16da954bd70b326f21cec9547237f55de18d4253. --- src/client/client.cpp | 12 +++++++----- src/client/clientlauncher.cpp | 3 ++- src/client/game.cpp | 23 ++++++++--------------- src/client/gameui.cpp | 11 ++++++++--- src/client/gameui.h | 7 +++++-- src/client/renderingengine.cpp | 4 ++-- src/client/renderingengine.h | 3 ++- src/gui/mainmenumanager.h | 3 +++ 8 files changed, 37 insertions(+), 29 deletions(-) diff --git a/src/client/client.cpp b/src/client/client.cpp index 122caa1fb2dd..744c5eb9084b 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -1776,6 +1776,7 @@ float Client::mediaReceiveProgress() } struct TextureUpdateArgs { + gui::IGUIEnvironment *guienv; u64 last_time_ms; u16 last_percent; std::wstring text_base; @@ -1801,7 +1802,7 @@ void Client::showUpdateProgressTexture(void *args, u32 progress, u32 max_progres targs->last_time_ms = time_ms; std::wostringstream strm; strm << targs->text_base << L" " << targs->last_percent << L"%..."; - m_rendering_engine->draw_load_screen(strm.str(), targs->tsrc, 0, + m_rendering_engine->draw_load_screen(strm.str(), targs->guienv, targs->tsrc, 0, 72 + (u16) ((18. / 100.) * (double) targs->last_percent)); } } @@ -1821,19 +1822,19 @@ void Client::afterContentReceived() // Rebuild inherited images and recreate textures infostream<<"- Rebuilding images and textures"<draw_load_screen(wstrgettext("Loading textures..."), - m_tsrc, 0, 70); + guienv, m_tsrc, 0, 70); m_tsrc->rebuildImagesAndTextures(); // Rebuild shaders infostream<<"- Rebuilding shaders"<draw_load_screen(wstrgettext("Rebuilding shaders..."), - m_tsrc, 0, 71); + guienv, m_tsrc, 0, 71); m_shsrc->rebuildShaders(); // Update node aliases infostream<<"- Updating node aliases"<draw_load_screen(wstrgettext("Initializing nodes..."), - m_tsrc, 0, 72); + guienv, m_tsrc, 0, 72); m_nodedef->updateAliases(m_itemdef); for (const auto &path : getTextureDirs()) { TextureOverrideSource override_source(path + DIR_DELIM + "override.txt"); @@ -1846,6 +1847,7 @@ void Client::afterContentReceived() // Update node textures and assign shaders to each tile infostream<<"- Updating node textures"<on_client_ready(m_env.getLocalPlayer()); - m_rendering_engine->draw_load_screen(wstrgettext("Done!"), m_tsrc, 0, 100); + m_rendering_engine->draw_load_screen(wstrgettext("Done!"), guienv, m_tsrc, 0, 100); infostream<<"Client::afterContentReceived() done"<get_scene_manager()->getParameters()-> setAttribute(scene::ALLOW_ZWRITE_ON_TRANSPARENT, true); - gui::IGUIEnvironment *guienv = m_rendering_engine->get_gui_env(); + guienv = m_rendering_engine->get_gui_env(); skin = guienv->getSkin(); skin->setColor(gui::EGDC_BUTTON_TEXT, video::SColor(255, 255, 255, 255)); skin->setColor(gui::EGDC_3D_LIGHT, video::SColor(0, 0, 0, 0)); diff --git a/src/client/game.cpp b/src/client/game.cpp index 280788603600..7b62015134e3 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -1530,9 +1530,7 @@ bool Game::createClient(const GameStartData &start_data) bool Game::initGui() { - auto guienv = m_rendering_engine->get_gui_env(); - - m_game_ui->init(guienv); + m_game_ui->init(); // Remove stale "recent" chat messages from previous connections chat_backend->clearRecentChat(); @@ -1727,11 +1725,11 @@ bool Game::getServerContent(bool *aborted) if (!client->itemdefReceived()) { progress = 25; m_rendering_engine->draw_load_screen(wstrgettext("Item definitions..."), - texture_src, dtime, progress); + guienv, texture_src, dtime, progress); } else if (!client->nodedefReceived()) { progress = 30; m_rendering_engine->draw_load_screen(wstrgettext("Node definitions..."), - texture_src, dtime, progress); + guienv, texture_src, dtime, progress); } else { std::ostringstream message; std::fixed(message); @@ -1756,7 +1754,7 @@ bool Game::getServerContent(bool *aborted) } progress = 30 + client->mediaReceiveProgress() * 35 + 0.5; - m_rendering_engine->draw_load_screen(utf8_to_wide(message.str()), + m_rendering_engine->draw_load_screen(utf8_to_wide(message.str()), guienv, texture_src, dtime, progress); } } @@ -1807,23 +1805,20 @@ inline bool Game::handleCallbacks() return false; } - auto guienv = m_rendering_engine->get_gui_env(); - auto guiroot = guienv->getRootGUIElement(); - if (g_gamecallback->changepassword_requested) { - (new GUIPasswordChange(guienv, guiroot, -1, + (new GUIPasswordChange(guienv, guienv->getRootGUIElement(), -1, &g_menumgr, client, texture_src))->drop(); g_gamecallback->changepassword_requested = false; } if (g_gamecallback->changevolume_requested) { - (new GUIVolumeChange(guienv, guiroot, -1, + (new GUIVolumeChange(guienv, guienv->getRootGUIElement(), -1, &g_menumgr, texture_src))->drop(); g_gamecallback->changevolume_requested = false; } if (g_gamecallback->keyconfig_requested) { - (new GUIKeyChangeMenu(guienv, guiroot, -1, + (new GUIKeyChangeMenu(guienv, guienv->getRootGUIElement(), -1, &g_menumgr, texture_src))->drop(); g_gamecallback->keyconfig_requested = false; } @@ -1954,8 +1949,6 @@ void Game::updateStats(RunStats *stats, const FpsControl &draw_times, void Game::processUserInput(f32 dtime) { - auto guienv = m_rendering_engine->get_gui_env(); - // Reset input if window not active or some menu is active if (!device->isWindowActive() || isMenuActive() || guienv->hasFocus(gui_chat_console)) { if(m_game_focused) { @@ -4297,7 +4290,7 @@ void FpsControl::limit(IrrlichtDevice *device, f32 *dtime) void Game::showOverlayMessage(const char *msg, float dtime, int percent, bool draw_sky) { - m_rendering_engine->draw_load_screen(wstrgettext(msg), texture_src, + m_rendering_engine->draw_load_screen(wstrgettext(msg), guienv, texture_src, dtime, percent, draw_sky); } diff --git a/src/client/gameui.cpp b/src/client/gameui.cpp index 17f4eb0c0331..4cc68fa10ce6 100644 --- a/src/client/gameui.cpp +++ b/src/client/gameui.cpp @@ -43,12 +43,17 @@ inline static const char *yawToDirectionString(int yaw) return direction[yaw]; } -void GameUI::init(gui::IGUIEnvironment *guienv) +GameUI::GameUI() { - if (guienv->getSkin()) + if (guienv && guienv->getSkin()) m_statustext_initial_color = guienv->getSkin()->getColor(gui::EGDC_BUTTON_TEXT); + else + m_statustext_initial_color = video::SColor(255, 0, 0, 0); - gui::IGUIElement *guiroot = guienv->getRootGUIElement(); +} +void GameUI::init() +{ + IGUIElement *guiroot = guienv->getRootGUIElement(); // First line of debug text m_guitext = gui::StaticText::add(guienv, utf8_to_wide(PROJECT_NAME_C).c_str(), diff --git a/src/client/gameui.h b/src/client/gameui.h index 2856feb7dab1..589328a286e0 100644 --- a/src/client/gameui.h +++ b/src/client/gameui.h @@ -49,6 +49,9 @@ class GameUI friend class TestGameUI; public: + GameUI(); + ~GameUI() = default; + // Flags that can, or may, change during main game loop struct Flags { @@ -60,7 +63,7 @@ class GameUI bool show_profiler_graph = false; }; - void init(gui::IGUIEnvironment *m_guienv); + void init(); void update(const RunStats &stats, Client *client, MapDrawControl *draw_control, const CameraOrientation &cam, const PointedThing &pointed_old, const GUIChatConsole *chat_console, float dtime); @@ -118,7 +121,7 @@ class GameUI gui::IGUIStaticText *m_guitext_status = nullptr; std::wstring m_statustext; float m_statustext_time = 0.0f; - video::SColor m_statustext_initial_color = video::SColor(255, 0, 0, 0); + video::SColor m_statustext_initial_color; gui::IGUIStaticText *m_guitext_chat = nullptr; // Chat text u32 m_recent_chat_count = 0; diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp index 7048f852542b..2c3ad4403143 100644 --- a/src/client/renderingengine.cpp +++ b/src/client/renderingengine.cpp @@ -226,9 +226,9 @@ bool RenderingEngine::setWindowIcon() Additionally, a progressbar can be drawn when percent is set between 0 and 100. */ void RenderingEngine::draw_load_screen(const std::wstring &text, - ITextureSource *tsrc, float dtime, int percent, bool sky) + gui::IGUIEnvironment *guienv, ITextureSource *tsrc, float dtime, + int percent, bool sky) { - gui::IGUIEnvironment *guienv = get_gui_env(); v2u32 screensize = getWindowSize(); v2s32 textsize(g_fontengine->getTextWidth(text), g_fontengine->getLineHeight()); diff --git a/src/client/renderingengine.h b/src/client/renderingengine.h index b5eac6da24ac..22b8a3946a96 100644 --- a/src/client/renderingengine.h +++ b/src/client/renderingengine.h @@ -110,7 +110,8 @@ class RenderingEngine return m_device->getGUIEnvironment(); } - void draw_load_screen(const std::wstring &text, ITextureSource *tsrc, + void draw_load_screen(const std::wstring &text, + gui::IGUIEnvironment *guienv, ITextureSource *tsrc, float dtime = 0, int percent = 0, bool sky = true); void draw_scene(video::SColor skycolor, bool show_hud, diff --git a/src/gui/mainmenumanager.h b/src/gui/mainmenumanager.h index 2fba04d44ede..b86d1892ac26 100644 --- a/src/gui/mainmenumanager.h +++ b/src/gui/mainmenumanager.h @@ -38,6 +38,9 @@ class IGameCallback virtual void signalKeyConfigChange() = 0; }; +// FIXME: do we really need this global variable? +extern gui::IGUIEnvironment *guienv; + // Handler for the modal menus class MainMenuManager : public IMenuManager