From f4118a4fdebe5c8a4a467afe5b3f49a0bd74c37a Mon Sep 17 00:00:00 2001 From: SmallJoker Date: Tue, 30 Mar 2021 21:49:15 +0200 Subject: Consistent title bar + render information in mainmenu (#10764) --- src/script/lua_api/l_mainmenu.cpp | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'src/script/lua_api/l_mainmenu.cpp') diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index ba7f708a4..6826ece05 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -856,14 +856,6 @@ int ModApiMainMenu::l_get_screen_info(lua_State *L) lua_pushnumber(L,RenderingEngine::getDisplayDensity()); lua_settable(L, top); - lua_pushstring(L,"display_width"); - lua_pushnumber(L,RenderingEngine::getDisplaySize().X); - lua_settable(L, top); - - lua_pushstring(L,"display_height"); - lua_pushnumber(L,RenderingEngine::getDisplaySize().Y); - lua_settable(L, top); - const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize(); lua_pushstring(L,"window_width"); lua_pushnumber(L, window_size.X); @@ -872,6 +864,10 @@ int ModApiMainMenu::l_get_screen_info(lua_State *L) lua_pushstring(L,"window_height"); lua_pushnumber(L, window_size.Y); lua_settable(L, top); + + lua_pushstring(L, "render_info"); + lua_pushstring(L, wide_to_utf8(RenderingEngine::get_video_driver()->getName()).c_str()); + lua_settable(L, top); return 1; } -- cgit v1.2.3 From 0abc1e98edb87b2e23eecccfd6b1393ac7fb4f56 Mon Sep 17 00:00:00 2001 From: sfan5 Date: Fri, 9 Apr 2021 22:36:10 +0200 Subject: Fix server favorites not saving when client/serverlist/ doesn't exist already (#11152) --- builtin/mainmenu/serverlistmgr.lua | 10 ++++++---- src/script/lua_api/l_mainmenu.cpp | 19 +++++++++++-------- src/script/lua_api/l_mainmenu.h | 2 +- 3 files changed, 18 insertions(+), 13 deletions(-) (limited to 'src/script/lua_api/l_mainmenu.cpp') diff --git a/builtin/mainmenu/serverlistmgr.lua b/builtin/mainmenu/serverlistmgr.lua index 9876d8ac5..964d0c584 100644 --- a/builtin/mainmenu/serverlistmgr.lua +++ b/builtin/mainmenu/serverlistmgr.lua @@ -90,8 +90,11 @@ function serverlistmgr.sync() end -------------------------------------------------------------------------------- -local function get_favorites_path() +local function get_favorites_path(folder) local base = core.get_user_path() .. DIR_DELIM .. "client" .. DIR_DELIM .. "serverlist" .. DIR_DELIM + if folder then + return base + end return base .. core.settings:get("serverlist_file") end @@ -103,9 +106,8 @@ local function save_favorites(favorites) core.settings:set("serverlist_file", filename:sub(1, #filename - 4) .. ".json") end - local path = get_favorites_path() - core.create_dir(path) - core.safe_file_write(path, core.write_json(favorites)) + assert(core.create_dir(get_favorites_path(true))) + core.safe_file_write(get_favorites_path(), core.write_json(favorites)) end -------------------------------------------------------------------------------- diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index 6826ece05..6488cd0fc 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -716,21 +716,24 @@ int ModApiMainMenu::l_get_mainmenu_path(lua_State *L) } /******************************************************************************/ -bool ModApiMainMenu::mayModifyPath(const std::string &path) +bool ModApiMainMenu::mayModifyPath(std::string path) { + path = fs::RemoveRelativePathComponents(path); + if (fs::PathStartsWith(path, fs::TempPath())) return true; - if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "games"))) - return true; + std::string path_user = fs::RemoveRelativePathComponents(porting::path_user); - if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "mods"))) + if (fs::PathStartsWith(path, path_user + DIR_DELIM "client")) return true; - - if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "textures"))) + if (fs::PathStartsWith(path, path_user + DIR_DELIM "games")) return true; - - if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "worlds"))) + if (fs::PathStartsWith(path, path_user + DIR_DELIM "mods")) + return true; + if (fs::PathStartsWith(path, path_user + DIR_DELIM "textures")) + return true; + if (fs::PathStartsWith(path, path_user + DIR_DELIM "worlds")) return true; if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_cache))) diff --git a/src/script/lua_api/l_mainmenu.h b/src/script/lua_api/l_mainmenu.h index 49ce7c251..33ac9e721 100644 --- a/src/script/lua_api/l_mainmenu.h +++ b/src/script/lua_api/l_mainmenu.h @@ -58,7 +58,7 @@ private: * @param path path to check * @return true if the path may be modified */ - static bool mayModifyPath(const std::string &path); + static bool mayModifyPath(std::string path); //api calls -- cgit v1.2.3 From e34d28af9f4b779b7a137f0e4017e499266e1931 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Wed, 28 Apr 2021 10:22:13 +0200 Subject: refacto: rendering engine singleton removal step 1 (filesystem) Make the RenderingEngine filesystem member non accessible from everywhere This permits also to determine that some lua code has directly a logic to extract zip file. Move this logic inside client, it's not the lua stack role to perform a such complex operation Found also another irrlicht <1.8 compat code to remove --- src/client/client.cpp | 84 ++++++++++++++++++++++++++++++++++----- src/client/client.h | 6 +++ src/client/game.cpp | 2 +- src/client/renderingengine.h | 5 +-- src/script/lua_api/l_mainmenu.cpp | 73 +--------------------------------- 5 files changed, 84 insertions(+), 86 deletions(-) (limited to 'src/script/lua_api/l_mainmenu.cpp') diff --git a/src/client/client.cpp b/src/client/client.cpp index 5db0b8f5d..d7e69f349 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -97,6 +97,7 @@ Client::Client( NodeDefManager *nodedef, ISoundManager *sound, MtEventManager *event, + RenderingEngine *rendering_engine, bool ipv6, GameUI *game_ui ): @@ -106,6 +107,7 @@ Client::Client( m_nodedef(nodedef), m_sound(sound), m_event(event), + m_rendering_engine(rendering_engine), m_mesh_update_thread(this), m_env( new ClientMap(this, control, 666), @@ -660,8 +662,8 @@ bool Client::loadMedia(const std::string &data, const std::string &filename, TRACESTREAM(<< "Client: Attempting to load image " << "file \"" << filename << "\"" << std::endl); - io::IFileSystem *irrfs = RenderingEngine::get_filesystem(); - video::IVideoDriver *vdrv = RenderingEngine::get_video_driver(); + io::IFileSystem *irrfs = m_rendering_engine->get_filesystem(); + video::IVideoDriver *vdrv = m_rendering_engine->get_video_driver(); io::IReadFile *rfile = irrfs->createMemoryReadFile( data.c_str(), data.size(), "_tempreadfile"); @@ -728,6 +730,72 @@ bool Client::loadMedia(const std::string &data, const std::string &filename, return false; } +bool Client::extractZipFile(const char *filename, const std::string &destination) +{ + auto fs = m_rendering_engine->get_filesystem(); + + if (!fs->addFileArchive(filename, false, false, io::EFAT_ZIP)) { + return false; + } + + sanity_check(fs->getFileArchiveCount() > 0); + + /**********************************************************************/ + /* WARNING this is not threadsafe!! */ + /**********************************************************************/ + io::IFileArchive* opened_zip = fs->getFileArchive(fs->getFileArchiveCount() - 1); + + const io::IFileList* files_in_zip = opened_zip->getFileList(); + + unsigned int number_of_files = files_in_zip->getFileCount(); + + for (unsigned int i=0; i < number_of_files; i++) { + std::string fullpath = destination; + fullpath += DIR_DELIM; + fullpath += files_in_zip->getFullFileName(i).c_str(); + std::string fullpath_dir = fs::RemoveLastPathComponent(fullpath); + + if (!files_in_zip->isDirectory(i)) { + if (!fs::PathExists(fullpath_dir) && !fs::CreateAllDirs(fullpath_dir)) { + fs->removeFileArchive(fs->getFileArchiveCount()-1); + return false; + } + + io::IReadFile* toread = opened_zip->createAndOpenFile(i); + + FILE *targetfile = fopen(fullpath.c_str(),"wb"); + + if (targetfile == NULL) { + fs->removeFileArchive(fs->getFileArchiveCount()-1); + return false; + } + + char read_buffer[1024]; + long total_read = 0; + + while (total_read < toread->getSize()) { + + unsigned int bytes_read = + toread->read(read_buffer,sizeof(read_buffer)); + if ((bytes_read == 0 ) || + (fwrite(read_buffer, 1, bytes_read, targetfile) != bytes_read)) + { + fclose(targetfile); + fs->removeFileArchive(fs->getFileArchiveCount() - 1); + return false; + } + total_read += bytes_read; + } + + fclose(targetfile); + } + + } + + fs->removeFileArchive(fs->getFileArchiveCount() - 1); + return true; +} + // Virtual methods from con::PeerHandler void Client::peerAdded(con::Peer *peer) { @@ -1910,23 +1978,17 @@ scene::IAnimatedMesh* Client::getMesh(const std::string &filename, bool cache) // Create the mesh, remove it from cache and return it // This allows unique vertex colors and other properties for each instance -#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR > 8 - io::IReadFile *rfile = RenderingEngine::get_filesystem()->createMemoryReadFile( + io::IReadFile *rfile = m_rendering_engine->get_filesystem()->createMemoryReadFile( data.c_str(), data.size(), filename.c_str()); -#else - Buffer data_rw(data.c_str(), data.size()); // Const-incorrect Irrlicht - io::IReadFile *rfile = RenderingEngine::get_filesystem()->createMemoryReadFile( - *data_rw, data_rw.getSize(), filename.c_str()); -#endif FATAL_ERROR_IF(!rfile, "Could not create/open RAM file"); - scene::IAnimatedMesh *mesh = RenderingEngine::get_scene_manager()->getMesh(rfile); + scene::IAnimatedMesh *mesh = m_rendering_engine->get_scene_manager()->getMesh(rfile); rfile->drop(); if (!mesh) return nullptr; mesh->grab(); if (!cache) - RenderingEngine::get_mesh_cache()->removeMesh(mesh); + m_rendering_engine->get_mesh_cache()->removeMesh(mesh); return mesh; } diff --git a/src/client/client.h b/src/client/client.h index 2dba1506e..bcb7d6b09 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -45,6 +45,7 @@ struct ClientEvent; struct MeshMakeData; struct ChatMessage; class MapBlockMesh; +class RenderingEngine; class IWritableTextureSource; class IWritableShaderSource; class IWritableItemDefManager; @@ -123,6 +124,7 @@ public: NodeDefManager *nodedef, ISoundManager *sound, MtEventManager *event, + RenderingEngine *rendering_engine, bool ipv6, GameUI *game_ui ); @@ -379,6 +381,9 @@ public: // Insert a media file appropriately into the appropriate manager bool loadMedia(const std::string &data, const std::string &filename, bool from_media_push = false); + + bool extractZipFile(const char *filename, const std::string &destination); + // Send a request for conventional media transfer void request_media(const std::vector &file_requests); @@ -469,6 +474,7 @@ private: NodeDefManager *m_nodedef; ISoundManager *m_sound; MtEventManager *m_event; + RenderingEngine *m_rendering_engine; MeshUpdateThread m_mesh_update_thread; diff --git a/src/client/game.cpp b/src/client/game.cpp index b092b95e2..612072136 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -1465,7 +1465,7 @@ bool Game::connectToServer(const GameStartData &start_data, start_data.password, start_data.address, *draw_control, texture_src, shader_src, itemdef_manager, nodedef_manager, sound, eventmgr, - connect_address.isIPv6(), m_game_ui.get()); + RenderingEngine::get_instance(), connect_address.isIPv6(), m_game_ui.get()); client->m_simple_singleplayer_mode = simple_singleplayer_mode; diff --git a/src/client/renderingengine.h b/src/client/renderingengine.h index 34cc60630..5807421ef 100644 --- a/src/client/renderingengine.h +++ b/src/client/renderingengine.h @@ -59,10 +59,9 @@ public: static RenderingEngine *get_instance() { return s_singleton; } - static io::IFileSystem *get_filesystem() + io::IFileSystem *get_filesystem() { - sanity_check(s_singleton && s_singleton->m_device); - return s_singleton->m_device->getFileSystem(); + return m_device->getFileSystem(); } static video::IVideoDriver *get_video_driver() diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index 6488cd0fc..1e8dea909 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -34,9 +34,7 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "serverlist.h" #include "mapgen/mapgen.h" #include "settings.h" - -#include -#include +#include "client/client.h" #include "client/renderingengine.h" #include "network/networkprotocol.h" @@ -630,74 +628,7 @@ int ModApiMainMenu::l_extract_zip(lua_State *L) if (ModApiMainMenu::mayModifyPath(absolute_destination)) { fs::CreateAllDirs(absolute_destination); - - io::IFileSystem *fs = RenderingEngine::get_filesystem(); - - if (!fs->addFileArchive(zipfile, false, false, io::EFAT_ZIP)) { - lua_pushboolean(L,false); - return 1; - } - - sanity_check(fs->getFileArchiveCount() > 0); - - /**********************************************************************/ - /* WARNING this is not threadsafe!! */ - /**********************************************************************/ - io::IFileArchive* opened_zip = - fs->getFileArchive(fs->getFileArchiveCount()-1); - - const io::IFileList* files_in_zip = opened_zip->getFileList(); - - unsigned int number_of_files = files_in_zip->getFileCount(); - - for (unsigned int i=0; i < number_of_files; i++) { - std::string fullpath = destination; - fullpath += DIR_DELIM; - fullpath += files_in_zip->getFullFileName(i).c_str(); - std::string fullpath_dir = fs::RemoveLastPathComponent(fullpath); - - if (!files_in_zip->isDirectory(i)) { - if (!fs::PathExists(fullpath_dir) && !fs::CreateAllDirs(fullpath_dir)) { - fs->removeFileArchive(fs->getFileArchiveCount()-1); - lua_pushboolean(L,false); - return 1; - } - - io::IReadFile* toread = opened_zip->createAndOpenFile(i); - - FILE *targetfile = fopen(fullpath.c_str(),"wb"); - - if (targetfile == NULL) { - fs->removeFileArchive(fs->getFileArchiveCount()-1); - lua_pushboolean(L,false); - return 1; - } - - char read_buffer[1024]; - long total_read = 0; - - while (total_read < toread->getSize()) { - - unsigned int bytes_read = - toread->read(read_buffer,sizeof(read_buffer)); - if ((bytes_read == 0 ) || - (fwrite(read_buffer, 1, bytes_read, targetfile) != bytes_read)) - { - fclose(targetfile); - fs->removeFileArchive(fs->getFileArchiveCount()-1); - lua_pushboolean(L,false); - return 1; - } - total_read += bytes_read; - } - - fclose(targetfile); - } - - } - - fs->removeFileArchive(fs->getFileArchiveCount()-1); - lua_pushboolean(L,true); + lua_pushboolean(L, getClient(L)->extractZipFile(zipfile, destination)); return 1; } -- cgit v1.2.3 From 258101a91031f3ff9ee01a974030b02529ffdac0 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Wed, 28 Apr 2021 12:48:13 +0200 Subject: refacto: RenderingEngine is now better hidden * No more access to the singleton instance from everywhere (RenderingEngine::get_instance dropped) * RenderingEngine::get_timer_time is now non static * RenderingEngine::draw_menu_scene is now non static * RenderingEngine::draw_scene is now non static * RenderingEngine::{initialize,finalize} are now non static * RenderingEngine::run is now non static * RenderingEngine::getWindowSize now have a static helper. It was mandatory to hide the global get_instance access --- src/client/camera.cpp | 2 +- src/client/clientlauncher.cpp | 57 ++++++++++++++++++++------------------- src/client/clientlauncher.h | 1 + src/client/game.cpp | 54 ++++++++++++++++++++----------------- src/client/game.h | 4 ++- src/client/gameui.cpp | 6 ++--- src/client/hud.cpp | 6 ++--- src/client/minimap.cpp | 2 +- src/client/renderingengine.cpp | 12 ++++----- src/client/renderingengine.h | 51 +++++++++++------------------------ src/gui/guiEngine.cpp | 30 +++++++++++---------- src/gui/guiEngine.h | 3 +++ src/main.cpp | 3 +-- src/script/lua_api/l_mainmenu.cpp | 2 +- 14 files changed, 112 insertions(+), 121 deletions(-) (limited to 'src/script/lua_api/l_mainmenu.cpp') diff --git a/src/client/camera.cpp b/src/client/camera.cpp index 5158d0dd1..f6892295b 100644 --- a/src/client/camera.cpp +++ b/src/client/camera.cpp @@ -541,7 +541,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime, f32 tool_r m_curr_fov_degrees = rangelim(m_curr_fov_degrees, 1.0f, 160.0f); // FOV and aspect ratio - const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize(); + const v2u32 &window_size = RenderingEngine::getWindowSize(); m_aspect = (f32) window_size.X / (f32) window_size.Y; m_fov_y = m_curr_fov_degrees * M_PI / 180.0; // Increase vertical FOV on lower aspect ratios (<16:10) diff --git a/src/client/clientlauncher.cpp b/src/client/clientlauncher.cpp index b1b801947..6db5f2e70 100644 --- a/src/client/clientlauncher.cpp +++ b/src/client/clientlauncher.cpp @@ -80,7 +80,7 @@ ClientLauncher::~ClientLauncher() delete g_fontengine; delete g_gamecallback; - delete RenderingEngine::get_instance(); + delete m_rendering_engine; #if USE_SOUND g_sound_manager_singleton.reset(); @@ -101,7 +101,7 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) // List video modes if requested if (list_video_modes) - return RenderingEngine::print_video_modes(); + return m_rendering_engine->print_video_modes(); #if USE_SOUND if (g_settings->getBool("enable_sound")) @@ -120,12 +120,12 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) return true; } - if (RenderingEngine::get_video_driver() == NULL) { + if (m_rendering_engine->get_video_driver() == NULL) { errorstream << "Could not initialize video driver." << std::endl; return false; } - RenderingEngine::get_instance()->setupTopLevelWindow(PROJECT_NAME_C); + m_rendering_engine->setupTopLevelWindow(PROJECT_NAME_C); /* This changes the minimum allowed number of vertices in a VBO. @@ -136,15 +136,15 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) // Create game callback for menus g_gamecallback = new MainGameCallback(); - RenderingEngine::get_instance()->setResizable(true); + m_rendering_engine->setResizable(true); init_input(); - RenderingEngine::get_scene_manager()->getParameters()-> + m_rendering_engine->get_scene_manager()->getParameters()-> setAttribute(scene::ALLOW_ZWRITE_ON_TRANSPARENT, true); - guienv = RenderingEngine::get_gui_env(); - skin = RenderingEngine::get_gui_env()->getSkin(); + 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)); skin->setColor(gui::EGDC_3D_HIGH_LIGHT, video::SColor(255, 30, 30, 30)); @@ -166,7 +166,7 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) sprite_path.append("checkbox_16.png"); // Texture dimensions should be a power of 2 gui::IGUISpriteBank *sprites = skin->getSpriteBank(); - video::IVideoDriver *driver = RenderingEngine::get_video_driver(); + video::IVideoDriver *driver = m_rendering_engine->get_video_driver(); video::ITexture *sprite_texture = driver->getTexture(sprite_path.c_str()); if (sprite_texture) { s32 sprite_id = sprites->addTextureAsSprite(sprite_texture); @@ -184,7 +184,7 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) // Create the menu clouds if (!g_menucloudsmgr) - g_menucloudsmgr = RenderingEngine::get_scene_manager()->createNewSceneManager(); + g_menucloudsmgr = m_rendering_engine->get_scene_manager()->createNewSceneManager(); if (!g_menuclouds) g_menuclouds = new Clouds(g_menucloudsmgr, -1, rand()); g_menuclouds->setHeight(100.0f); @@ -212,11 +212,11 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) bool retval = true; bool *kill = porting::signal_handler_killstatus(); - while (RenderingEngine::run() && !*kill && + while (m_rendering_engine->run() && !*kill && !g_gamecallback->shutdown_requested) { // Set the window caption const wchar_t *text = wgettext("Main Menu"); - RenderingEngine::get_raw_device()-> + m_rendering_engine->get_raw_device()-> setWindowCaption((utf8_to_wide(PROJECT_NAME_C) + L" " + utf8_to_wide(g_version_hash) + L" [" + text + L"]").c_str()); @@ -224,14 +224,14 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) try { // This is used for catching disconnects - RenderingEngine::get_gui_env()->clear(); + m_rendering_engine->get_gui_env()->clear(); /* We need some kind of a root node to be able to add custom gui elements directly on the screen. Otherwise they won't be automatically drawn. */ - guiroot = RenderingEngine::get_gui_env()->addStaticText(L"", + guiroot = m_rendering_engine->get_gui_env()->addStaticText(L"", core::rect(0, 0, 10000, 10000)); bool game_has_run = launch_game(error_message, reconnect_requested, @@ -254,29 +254,30 @@ bool ClientLauncher::run(GameStartData &start_data, const Settings &cmd_args) } // Break out of menu-game loop to shut down cleanly - if (!RenderingEngine::get_raw_device()->run() || *kill) { + if (!m_rendering_engine->run() || *kill) { if (!g_settings_path.empty()) g_settings->updateConfigFile(g_settings_path.c_str()); break; } - RenderingEngine::get_video_driver()->setTextureCreationFlag( + m_rendering_engine->get_video_driver()->setTextureCreationFlag( video::ETCF_CREATE_MIP_MAPS, g_settings->getBool("mip_map")); #ifdef HAVE_TOUCHSCREENGUI - receiver->m_touchscreengui = new TouchScreenGUI(RenderingEngine::get_raw_device(), receiver); + receiver->m_touchscreengui = new TouchScreenGUI(m_rendering_engine->get_raw_device(), receiver); g_touchscreengui = receiver->m_touchscreengui; #endif the_game( kill, input, + m_rendering_engine, start_data, error_message, chat_backend, &reconnect_requested ); - RenderingEngine::get_scene_manager()->clear(); + m_rendering_engine->get_scene_manager()->clear(); #ifdef HAVE_TOUCHSCREENGUI delete g_touchscreengui; @@ -344,8 +345,8 @@ void ClientLauncher::init_args(GameStartData &start_data, const Settings &cmd_ar bool ClientLauncher::init_engine() { receiver = new MyEventReceiver(); - new RenderingEngine(receiver); - return RenderingEngine::get_raw_device() != nullptr; + m_rendering_engine = new RenderingEngine(receiver); + return m_rendering_engine->get_raw_device() != nullptr; } void ClientLauncher::init_input() @@ -362,7 +363,7 @@ void ClientLauncher::init_input() // Make sure this is called maximum once per // irrlicht device, otherwise it will give you // multiple events for the same joystick. - if (RenderingEngine::get_raw_device()->activateJoysticks(infos)) { + if (m_rendering_engine->get_raw_device()->activateJoysticks(infos)) { infostream << "Joystick support enabled" << std::endl; joystick_infos.reserve(infos.size()); for (u32 i = 0; i < infos.size(); i++) { @@ -469,7 +470,7 @@ bool ClientLauncher::launch_game(std::string &error_message, start_data.address.empty() && !start_data.name.empty(); } - if (!RenderingEngine::run()) + if (!m_rendering_engine->run()) return false; if (!start_data.isSinglePlayer() && start_data.name.empty()) { @@ -541,14 +542,14 @@ bool ClientLauncher::launch_game(std::string &error_message, void ClientLauncher::main_menu(MainMenuData *menudata) { bool *kill = porting::signal_handler_killstatus(); - video::IVideoDriver *driver = RenderingEngine::get_video_driver(); + video::IVideoDriver *driver = m_rendering_engine->get_video_driver(); infostream << "Waiting for other menus" << std::endl; - while (RenderingEngine::get_raw_device()->run() && !*kill) { + while (m_rendering_engine->run() && !*kill) { if (!isMenuActive()) break; driver->beginScene(true, true, video::SColor(255, 128, 128, 128)); - RenderingEngine::get_gui_env()->drawAll(); + m_rendering_engine->get_gui_env()->drawAll(); driver->endScene(); // On some computers framerate doesn't seem to be automatically limited sleep_ms(25); @@ -557,14 +558,14 @@ void ClientLauncher::main_menu(MainMenuData *menudata) // Cursor can be non-visible when coming from the game #ifndef ANDROID - RenderingEngine::get_raw_device()->getCursorControl()->setVisible(true); + m_rendering_engine->get_raw_device()->getCursorControl()->setVisible(true); #endif /* show main menu */ - GUIEngine mymenu(&input->joystick, guiroot, &g_menumgr, menudata, *kill); + GUIEngine mymenu(&input->joystick, guiroot, m_rendering_engine, &g_menumgr, menudata, *kill); /* leave scene manager in a clean state */ - RenderingEngine::get_scene_manager()->clear(); + m_rendering_engine->get_scene_manager()->clear(); } void ClientLauncher::speed_tests() diff --git a/src/client/clientlauncher.h b/src/client/clientlauncher.h index b280d8e6b..79727e1fe 100644 --- a/src/client/clientlauncher.h +++ b/src/client/clientlauncher.h @@ -49,6 +49,7 @@ private: bool list_video_modes = false; bool skip_main_menu = false; bool random_input = false; + RenderingEngine *m_rendering_engine = nullptr; InputHandler *input = nullptr; MyEventReceiver *receiver = nullptr; gui::IGUISkin *skin = nullptr; diff --git a/src/client/game.cpp b/src/client/game.cpp index 8400d7639..33707df4a 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -642,6 +642,7 @@ public: bool startup(bool *kill, InputHandler *input, + RenderingEngine *rendering_engine, const GameStartData &game_params, std::string &error_message, bool *reconnect, @@ -853,6 +854,7 @@ private: these items (e.g. device) */ IrrlichtDevice *device; + RenderingEngine *m_rendering_engine; video::IVideoDriver *driver; scene::ISceneManager *smgr; bool *kill; @@ -994,6 +996,7 @@ Game::~Game() bool Game::startup(bool *kill, InputHandler *input, + RenderingEngine *rendering_engine, const GameStartData &start_data, std::string &error_message, bool *reconnect, @@ -1001,21 +1004,21 @@ bool Game::startup(bool *kill, { // "cache" - this->device = RenderingEngine::get_raw_device(); + m_rendering_engine = rendering_engine; + device = m_rendering_engine->get_raw_device(); this->kill = kill; this->error_message = &error_message; - this->reconnect_requested = reconnect; + reconnect_requested = reconnect; this->input = input; this->chat_backend = chat_backend; - this->simple_singleplayer_mode = start_data.isSinglePlayer(); + simple_singleplayer_mode = start_data.isSinglePlayer(); input->keycache.populate(); driver = device->getVideoDriver(); - smgr = RenderingEngine::get_scene_manager(); + smgr = m_rendering_engine->get_scene_manager(); - RenderingEngine::get_scene_manager()->getParameters()-> - setAttribute(scene::OBJ_LOADER_IGNORE_MATERIAL_FILES, true); + smgr->getParameters()->setAttribute(scene::OBJ_LOADER_IGNORE_MATERIAL_FILES, true); // Reinit runData runData = GameRunData(); @@ -1036,7 +1039,7 @@ bool Game::startup(bool *kill, if (!createClient(start_data)) return false; - RenderingEngine::initialize(client, hud); + m_rendering_engine->initialize(client, hud); return true; } @@ -1055,7 +1058,7 @@ void Game::run() Profiler::GraphValues dummyvalues; g_profiler->graphGet(dummyvalues); - draw_times.last_time = RenderingEngine::get_timer_time(); + draw_times.last_time = m_rendering_engine->get_timer_time(); set_light_table(g_settings->getFloat("display_gamma")); @@ -1067,12 +1070,12 @@ void Game::run() irr::core::dimension2d previous_screen_size(g_settings->getU16("screen_w"), g_settings->getU16("screen_h")); - while (RenderingEngine::run() + while (m_rendering_engine->run() && !(*kill || g_gamecallback->shutdown_requested || (server && server->isShutdownRequested()))) { const irr::core::dimension2d ¤t_screen_size = - RenderingEngine::get_video_driver()->getScreenSize(); + m_rendering_engine->get_video_driver()->getScreenSize(); // Verify if window size has changed and save it if it's the case // Ensure evaluating settings->getBool after verifying screensize // First condition is cheaper @@ -1085,7 +1088,7 @@ void Game::run() } // Calculate dtime = - // RenderingEngine::run() from this iteration + // m_rendering_engine->run() from this iteration // + Sleep time until the wanted FPS are reached limitFps(&draw_times, &dtime); @@ -1134,7 +1137,7 @@ void Game::run() void Game::shutdown() { - RenderingEngine::finalize(); + m_rendering_engine->finalize(); #if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR <= 8 if (g_settings->get("3d_mode") == "pageflip") { driver->setRenderTarget(irr::video::ERT_STEREO_BOTH_BUFFERS); @@ -1463,7 +1466,7 @@ bool Game::connectToServer(const GameStartData &start_data, start_data.password, start_data.address, *draw_control, texture_src, shader_src, itemdef_manager, nodedef_manager, sound, eventmgr, - RenderingEngine::get_instance(), connect_address.isIPv6(), m_game_ui.get()); + m_rendering_engine, connect_address.isIPv6(), m_game_ui.get()); client->m_simple_singleplayer_mode = simple_singleplayer_mode; @@ -1485,9 +1488,9 @@ bool Game::connectToServer(const GameStartData &start_data, f32 dtime; f32 wait_time = 0; // in seconds - fps_control.last_time = RenderingEngine::get_timer_time(); + fps_control.last_time = m_rendering_engine->get_timer_time(); - while (RenderingEngine::run()) { + while (m_rendering_engine->run()) { limitFps(&fps_control, &dtime); @@ -1524,7 +1527,7 @@ bool Game::connectToServer(const GameStartData &start_data, if (client->m_is_registration_confirmation_state) { if (registration_confirmation_shown) { // Keep drawing the GUI - RenderingEngine::draw_menu_scene(guienv, dtime, true); + m_rendering_engine->draw_menu_scene(guienv, dtime, true); } else { registration_confirmation_shown = true; (new GUIConfirmRegistration(guienv, guienv->getRootGUIElement(), -1, @@ -1560,9 +1563,9 @@ bool Game::getServerContent(bool *aborted) FpsControl fps_control = { 0 }; f32 dtime; // in seconds - fps_control.last_time = RenderingEngine::get_timer_time(); + fps_control.last_time = m_rendering_engine->get_timer_time(); - while (RenderingEngine::run()) { + while (m_rendering_engine->run()) { limitFps(&fps_control, &dtime); @@ -1600,13 +1603,13 @@ bool Game::getServerContent(bool *aborted) if (!client->itemdefReceived()) { const wchar_t *text = wgettext("Item definitions..."); progress = 25; - RenderingEngine::draw_load_screen(text, guienv, texture_src, + m_rendering_engine->draw_load_screen(text, guienv, texture_src, dtime, progress); delete[] text; } else if (!client->nodedefReceived()) { const wchar_t *text = wgettext("Node definitions..."); progress = 30; - RenderingEngine::draw_load_screen(text, guienv, texture_src, + m_rendering_engine->draw_load_screen(text, guienv, texture_src, dtime, progress); delete[] text; } else { @@ -1633,7 +1636,7 @@ bool Game::getServerContent(bool *aborted) } progress = 30 + client->mediaReceiveProgress() * 35 + 0.5; - RenderingEngine::draw_load_screen(utf8_to_wide(message.str()), guienv, + m_rendering_engine->draw_load_screen(utf8_to_wide(message.str()), guienv, texture_src, dtime, progress); } } @@ -3886,7 +3889,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, } catch (SettingNotFoundException) { } #endif - RenderingEngine::draw_scene(skycolor, m_game_ui->m_flags.show_hud, + m_rendering_engine->draw_scene(skycolor, m_game_ui->m_flags.show_hud, m_game_ui->m_flags.show_minimap, draw_wield_tool, draw_crosshair); /* @@ -4016,7 +4019,7 @@ inline void Game::limitFps(FpsControl *fps_timings, f32 *dtime) void Game::showOverlayMessage(const char *msg, float dtime, int percent, bool draw_clouds) { const wchar_t *wmsg = wgettext(msg); - RenderingEngine::draw_load_screen(wmsg, guienv, texture_src, dtime, percent, + m_rendering_engine->draw_load_screen(wmsg, guienv, texture_src, dtime, percent, draw_clouds); delete[] wmsg; } @@ -4229,6 +4232,7 @@ void Game::showPauseMenu() void the_game(bool *kill, InputHandler *input, + RenderingEngine *rendering_engine, const GameStartData &start_data, std::string &error_message, ChatBackend &chat_backend, @@ -4243,8 +4247,8 @@ void the_game(bool *kill, try { - if (game.startup(kill, input, start_data, error_message, - reconnect_requested, &chat_backend)) { + if (game.startup(kill, input, rendering_engine, start_data, + error_message, reconnect_requested, &chat_backend)) { game.run(); } diff --git a/src/client/game.h b/src/client/game.h index d04153271..fbbf106db 100644 --- a/src/client/game.h +++ b/src/client/game.h @@ -23,7 +23,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include class InputHandler; -class ChatBackend; /* to avoid having to include chat.h */ +class ChatBackend; +class RenderingEngine; struct SubgameSpec; struct GameStartData; @@ -45,6 +46,7 @@ struct CameraOrientation { void the_game(bool *kill, InputHandler *input, + RenderingEngine *rendering_engine, const GameStartData &start_data, std::string &error_message, ChatBackend &chat_backend, diff --git a/src/client/gameui.cpp b/src/client/gameui.cpp index 0c08efeb5..ebc6b108c 100644 --- a/src/client/gameui.cpp +++ b/src/client/gameui.cpp @@ -97,7 +97,7 @@ void GameUI::update(const RunStats &stats, Client *client, MapDrawControl *draw_ const CameraOrientation &cam, const PointedThing &pointed_old, const GUIChatConsole *chat_console, float dtime) { - v2u32 screensize = RenderingEngine::get_instance()->getWindowSize(); + v2u32 screensize = RenderingEngine::getWindowSize(); if (m_flags.show_debug) { static float drawtime_avg = 0; @@ -228,7 +228,7 @@ void GameUI::setChatText(const EnrichedString &chat_text, u32 recent_chat_count) if (m_flags.show_debug) chat_y += 2 * g_fontengine->getLineHeight(); - const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize(); + const v2u32 &window_size = RenderingEngine::getWindowSize(); core::rect chat_size(10, chat_y, window_size.X - 20, 0); @@ -260,7 +260,7 @@ void GameUI::updateProfiler() core::position2di upper_left(6, 50); core::position2di lower_right = upper_left; lower_right.X += size.Width + 10; - lower_right.Y += size.Height; + lower_right.Y += size.Height; m_guitext_profiler->setRelativePosition(core::rect(upper_left, lower_right)); } diff --git a/src/client/hud.cpp b/src/client/hud.cpp index c58c7e822..ceea96832 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -747,7 +747,7 @@ void Hud::drawHotbar(u16 playeritem) { s32 width = hotbar_itemcount * (m_hotbar_imagesize + m_padding * 2); v2s32 pos = centerlowerpos - v2s32(width / 2, m_hotbar_imagesize + m_padding * 3); - const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize(); + const v2u32 &window_size = RenderingEngine::getWindowSize(); if ((float) width / (float) window_size.X <= g_settings->getFloat("hud_hotbar_max_width")) { if (player->hud_flags & HUD_FLAG_HOTBAR_VISIBLE) { @@ -874,7 +874,7 @@ void Hud::toggleBlockBounds() void Hud::drawBlockBounds() { if (m_block_bounds_mode == BLOCK_BOUNDS_OFF) { - return; + return; } video::SMaterial old_material = driver->getMaterial2D(); @@ -956,7 +956,7 @@ void Hud::updateSelectionMesh(const v3s16 &camera_offset) } void Hud::resizeHotbar() { - const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize(); + const v2u32 &window_size = RenderingEngine::getWindowSize(); if (m_screensize != window_size) { m_hotbar_imagesize = floor(HOTBAR_IMAGE_SIZE * diff --git a/src/client/minimap.cpp b/src/client/minimap.cpp index 97977c366..f26aa1c70 100644 --- a/src/client/minimap.cpp +++ b/src/client/minimap.cpp @@ -577,7 +577,7 @@ scene::SMeshBuffer *Minimap::getMinimapMeshBuffer() void Minimap::drawMinimap() { // Non hud managed minimap drawing (legacy minimap) - v2u32 screensize = RenderingEngine::get_instance()->getWindowSize(); + v2u32 screensize = RenderingEngine::getWindowSize(); const u32 size = 0.25 * screensize.Y; drawMinimap(core::rect( diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp index da9022477..ec8f47576 100644 --- a/src/client/renderingengine.cpp +++ b/src/client/renderingengine.cpp @@ -159,7 +159,7 @@ RenderingEngine::~RenderingEngine() s_singleton = nullptr; } -v2u32 RenderingEngine::getWindowSize() const +v2u32 RenderingEngine::_getWindowSize() const { if (core) return core->getVirtualSize(); @@ -497,7 +497,7 @@ void RenderingEngine::_draw_load_screen(const std::wstring &text, gui::IGUIEnvironment *guienv, ITextureSource *tsrc, float dtime, int percent, bool clouds) { - v2u32 screensize = RenderingEngine::get_instance()->getWindowSize(); + v2u32 screensize = getWindowSize(); v2s32 textsize(g_fontengine->getTextWidth(text), g_fontengine->getLineHeight()); v2s32 center(screensize.X / 2, screensize.Y / 2); @@ -565,7 +565,7 @@ void RenderingEngine::_draw_load_screen(const std::wstring &text, /* Draws the menu scene including (optional) cloud background. */ -void RenderingEngine::_draw_menu_scene(gui::IGUIEnvironment *guienv, +void RenderingEngine::draw_menu_scene(gui::IGUIEnvironment *guienv, float dtime, bool clouds) { bool cloud_menu_background = clouds && g_settings->getBool("menu_clouds"); @@ -613,19 +613,19 @@ std::vector RenderingEngine::getSupportedVideoDrivers return drivers; } -void RenderingEngine::_initialize(Client *client, Hud *hud) +void RenderingEngine::initialize(Client *client, Hud *hud) { const std::string &draw_mode = g_settings->get("3d_mode"); core.reset(createRenderingCore(draw_mode, m_device, client, hud)); core->initialize(); } -void RenderingEngine::_finalize() +void RenderingEngine::finalize() { core.reset(); } -void RenderingEngine::_draw_scene(video::SColor skycolor, bool show_hud, +void RenderingEngine::draw_scene(video::SColor skycolor, bool show_hud, bool show_minimap, bool draw_wield_tool, bool draw_crosshair) { core->draw(skycolor, show_hud, show_minimap, draw_wield_tool, draw_crosshair); diff --git a/src/client/renderingengine.h b/src/client/renderingengine.h index 73b55229e..5462aa667 100644 --- a/src/client/renderingengine.h +++ b/src/client/renderingengine.h @@ -44,7 +44,6 @@ public: RenderingEngine(IEventReceiver *eventReceiver); ~RenderingEngine(); - v2u32 getWindowSize() const; void setResizable(bool resize); video::IVideoDriver *getVideoDriver() { return driver; } @@ -63,7 +62,11 @@ public: void removeMesh(const irr::scene::IMesh* mesh); - static RenderingEngine *get_instance() { return s_singleton; } + static v2u32 getWindowSize() + { + sanity_check(s_singleton); + return s_singleton->_getWindowSize(); + } io::IFileSystem *get_filesystem() { @@ -88,11 +91,9 @@ public: return s_singleton->m_device; } - static u32 get_timer_time() + u32 get_timer_time() { - sanity_check(s_singleton && s_singleton->m_device && - s_singleton->m_device->getTimer()); - return s_singleton->m_device->getTimer()->getTime(); + return m_device->getTimer()->getTime(); } static gui::IGUIEnvironment *get_gui_env() @@ -109,30 +110,16 @@ public: text, guienv, tsrc, dtime, percent, clouds); } - inline static void draw_menu_scene( - gui::IGUIEnvironment *guienv, float dtime, bool clouds) - { - s_singleton->_draw_menu_scene(guienv, dtime, clouds); - } + void draw_menu_scene(gui::IGUIEnvironment *guienv, float dtime, bool clouds); + void draw_scene(video::SColor skycolor, bool show_hud, + bool show_minimap, bool draw_wield_tool, bool draw_crosshair); - inline static void draw_scene(video::SColor skycolor, bool show_hud, - bool show_minimap, bool draw_wield_tool, bool draw_crosshair) - { - s_singleton->_draw_scene(skycolor, show_hud, show_minimap, - draw_wield_tool, draw_crosshair); - } + void initialize(Client *client, Hud *hud); + void finalize(); - inline static void initialize(Client *client, Hud *hud) + bool run() { - s_singleton->_initialize(client, hud); - } - - inline static void finalize() { s_singleton->_finalize(); } - - static bool run() - { - sanity_check(s_singleton && s_singleton->m_device); - return s_singleton->m_device->run(); + return m_device->run(); } static std::vector> getSupportedVideoModes(); @@ -143,15 +130,7 @@ private: ITextureSource *tsrc, float dtime = 0, int percent = 0, bool clouds = true); - void _draw_menu_scene(gui::IGUIEnvironment *guienv, float dtime = 0, - bool clouds = true); - - void _draw_scene(video::SColor skycolor, bool show_hud, bool show_minimap, - bool draw_wield_tool, bool draw_crosshair); - - void _initialize(Client *client, Hud *hud); - - void _finalize(); + v2u32 _getWindowSize() const; std::unique_ptr core; irr::IrrlichtDevice *m_device = nullptr; diff --git a/src/gui/guiEngine.cpp b/src/gui/guiEngine.cpp index 93463ad70..0c7b96492 100644 --- a/src/gui/guiEngine.cpp +++ b/src/gui/guiEngine.cpp @@ -121,12 +121,14 @@ void MenuMusicFetcher::fetchSounds(const std::string &name, /******************************************************************************/ GUIEngine::GUIEngine(JoystickController *joystick, gui::IGUIElement *parent, + RenderingEngine *rendering_engine, IMenuManager *menumgr, MainMenuData *data, bool &kill) : + m_rendering_engine(rendering_engine), m_parent(parent), m_menumanager(menumgr), - m_smgr(RenderingEngine::get_scene_manager()), + m_smgr(rendering_engine->get_scene_manager()), m_data(data), m_kill(kill) { @@ -138,7 +140,7 @@ GUIEngine::GUIEngine(JoystickController *joystick, m_buttonhandler = new TextDestGuiEngine(this); //create texture source - m_texture_source = new MenuTextureSource(RenderingEngine::get_video_driver()); + m_texture_source = new MenuTextureSource(rendering_engine->get_video_driver()); //create soundmanager MenuMusicFetcher soundfetcher; @@ -156,7 +158,7 @@ GUIEngine::GUIEngine(JoystickController *joystick, g_fontengine->getTextHeight()); rect += v2s32(4, 0); - m_irr_toplefttext = gui::StaticText::add(RenderingEngine::get_gui_env(), + m_irr_toplefttext = gui::StaticText::add(rendering_engine->get_gui_env(), m_toplefttext, rect, false, true, 0, -1); //create formspecsource @@ -232,7 +234,7 @@ void GUIEngine::run() { // Always create clouds because they may or may not be // needed based on the game selected - video::IVideoDriver *driver = RenderingEngine::get_video_driver(); + video::IVideoDriver *driver = m_rendering_engine->get_video_driver(); cloudInit(); @@ -259,10 +261,10 @@ void GUIEngine::run() fog_pixelfog, fog_rangefog); } - while (RenderingEngine::run() && (!m_startgame) && (!m_kill)) { + while (m_rendering_engine->run() && (!m_startgame) && (!m_kill)) { const irr::core::dimension2d ¤t_screen_size = - RenderingEngine::get_video_driver()->getScreenSize(); + m_rendering_engine->get_video_driver()->getScreenSize(); // Verify if window size has changed and save it if it's the case // Ensure evaluating settings->getBool after verifying screensize // First condition is cheaper @@ -293,11 +295,11 @@ void GUIEngine::run() drawHeader(driver); drawFooter(driver); - RenderingEngine::get_gui_env()->drawAll(); + m_rendering_engine->get_gui_env()->drawAll(); driver->endScene(); - IrrlichtDevice *device = RenderingEngine::get_raw_device(); + IrrlichtDevice *device = m_rendering_engine->get_raw_device(); u32 frametime_min = 1000 / (device->isWindowFocused() ? g_settings->getFloat("fps_max") : g_settings->getFloat("fps_max_unfocused")); @@ -330,7 +332,7 @@ GUIEngine::~GUIEngine() //clean up texture pointers for (image_definition &texture : m_textures) { if (texture.texture) - RenderingEngine::get_video_driver()->removeTexture(texture.texture); + m_rendering_engine->get_video_driver()->removeTexture(texture.texture); } delete m_texture_source; @@ -350,13 +352,13 @@ void GUIEngine::cloudInit() v3f(0,0,0), v3f(0, 60, 100)); m_cloud.camera->setFarValue(10000); - m_cloud.lasttime = RenderingEngine::get_timer_time(); + m_cloud.lasttime = m_rendering_engine->get_timer_time(); } /******************************************************************************/ void GUIEngine::cloudPreProcess() { - u32 time = RenderingEngine::get_timer_time(); + u32 time = m_rendering_engine->get_timer_time(); if(time > m_cloud.lasttime) m_cloud.dtime = (time - m_cloud.lasttime) / 1000.0; @@ -377,7 +379,7 @@ void GUIEngine::cloudPostProcess(u32 frametime_min, IrrlichtDevice *device) u32 busytime_u32; // not using getRealTime is necessary for wine - u32 time = RenderingEngine::get_timer_time(); + u32 time = m_rendering_engine->get_timer_time(); if(time > m_cloud.lasttime) busytime_u32 = time - m_cloud.lasttime; else @@ -528,7 +530,7 @@ void GUIEngine::drawFooter(video::IVideoDriver *driver) bool GUIEngine::setTexture(texture_layer layer, const std::string &texturepath, bool tile_image, unsigned int minsize) { - video::IVideoDriver *driver = RenderingEngine::get_video_driver(); + video::IVideoDriver *driver = m_rendering_engine->get_video_driver(); if (m_textures[layer].texture) { driver->removeTexture(m_textures[layer].texture); @@ -595,7 +597,7 @@ void GUIEngine::updateTopLeftTextSize() rect += v2s32(4, 0); m_irr_toplefttext->remove(); - m_irr_toplefttext = gui::StaticText::add(RenderingEngine::get_gui_env(), + m_irr_toplefttext = gui::StaticText::add(m_rendering_engine->get_gui_env(), m_toplefttext, rect, false, true, 0, -1); } diff --git a/src/gui/guiEngine.h b/src/gui/guiEngine.h index eef1ad8aa..70abce181 100644 --- a/src/gui/guiEngine.h +++ b/src/gui/guiEngine.h @@ -50,6 +50,7 @@ struct image_definition { /* forward declarations */ /******************************************************************************/ class GUIEngine; +class RenderingEngine; class MainMenuScripting; class Clouds; struct MainMenuData; @@ -150,6 +151,7 @@ public: */ GUIEngine(JoystickController *joystick, gui::IGUIElement *parent, + RenderingEngine *rendering_engine, IMenuManager *menumgr, MainMenuData *data, bool &kill); @@ -188,6 +190,7 @@ private: /** update size of topleftext element */ void updateTopLeftTextSize(); + RenderingEngine *m_rendering_engine = nullptr; /** parent gui element */ gui::IGUIElement *m_parent = nullptr; /** manager to add menus to */ diff --git a/src/main.cpp b/src/main.cpp index 39b441d2c..7f96836b5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -225,8 +225,7 @@ int main(int argc, char *argv[]) return run_dedicated_server(game_params, cmd_args) ? 0 : 1; #ifndef SERVER - ClientLauncher launcher; - retval = launcher.run(game_params, cmd_args) ? 0 : 1; + retval = ClientLauncher().run(game_params, cmd_args) ? 0 : 1; #else retval = 0; #endif diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index 1e8dea909..a5bb5f261 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -790,7 +790,7 @@ int ModApiMainMenu::l_get_screen_info(lua_State *L) lua_pushnumber(L,RenderingEngine::getDisplayDensity()); lua_settable(L, top); - const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize(); + const v2u32 &window_size = RenderingEngine::getWindowSize(); lua_pushstring(L,"window_width"); lua_pushnumber(L, window_size.X); lua_settable(L, top); -- cgit v1.2.3 From 48d5abd5bee7a3f956cb2b92745bed6313cf5d8a Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Thu, 29 Apr 2021 20:38:35 +0200 Subject: refacto: remove get_gui_env & draw_load_screen from RenderingEngine singleton --- src/client/client.cpp | 6 +++--- src/client/client.h | 1 + src/client/game.cpp | 24 ++++++++++++------------ src/client/renderingengine.cpp | 2 +- src/client/renderingengine.h | 17 ++++------------- src/gui/guiEngine.cpp | 1 + src/gui/guiFormSpecMenu.cpp | 12 ++++++------ src/gui/guiFormSpecMenu.h | 6 ++++-- src/nodedef.cpp | 6 ++---- src/nodedef.h | 4 +--- src/script/lua_api/l_mainmenu.cpp | 5 +++-- 11 files changed, 38 insertions(+), 46 deletions(-) (limited to 'src/script/lua_api/l_mainmenu.cpp') diff --git a/src/client/client.cpp b/src/client/client.cpp index 1a3a81378..c7aae1644 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -1731,7 +1731,7 @@ typedef struct TextureUpdateArgs { ITextureSource *tsrc; } TextureUpdateArgs; -void texture_update_progress(void *args, u32 progress, u32 max_progress) +void Client::showUpdateProgressTexture(void *args, u32 progress, u32 max_progress) { TextureUpdateArgs* targs = (TextureUpdateArgs*) args; u16 cur_percent = ceil(progress / (double) max_progress * 100.); @@ -1750,7 +1750,7 @@ void texture_update_progress(void *args, u32 progress, u32 max_progress) targs->last_time_ms = time_ms; std::basic_stringstream strm; strm << targs->text_base << " " << targs->last_percent << "%..."; - RenderingEngine::draw_load_screen(strm.str(), targs->guienv, targs->tsrc, 0, + m_rendering_engine->draw_load_screen(strm.str(), targs->guienv, targs->tsrc, 0, 72 + (u16) ((18. / 100.) * (double) targs->last_percent), true); } } @@ -1804,7 +1804,7 @@ void Client::afterContentReceived() tu_args.last_percent = 0; tu_args.text_base = wgettext("Initializing nodes"); tu_args.tsrc = m_tsrc; - m_nodedef->updateTextures(this, texture_update_progress, &tu_args); + m_nodedef->updateTextures(this, &tu_args); delete[] tu_args.text_base; // Start mesh update thread after setting up content definitions diff --git a/src/client/client.h b/src/client/client.h index be5970160..b819d4301 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -347,6 +347,7 @@ public: float mediaReceiveProgress(); void afterContentReceived(); + void showUpdateProgressTexture(void *args, u32 progress, u32 max_progress); float getRTT(); float getCurRate(); diff --git a/src/client/game.cpp b/src/client/game.cpp index 81508f5f4..2f0f50505 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -2047,8 +2047,8 @@ void Game::openInventory() || !client->getScript()->on_inventory_open(fs_src->m_client->getInventory(inventoryloc))) { TextDest *txt_dst = new TextDestPlayerInventory(client); auto *&formspec = m_game_ui->updateFormspec(""); - GUIFormSpecMenu::create(formspec, client, &input->joystick, fs_src, - txt_dst, client->getFormspecPrepend(), sound); + GUIFormSpecMenu::create(formspec, client, m_rendering_engine->get_gui_env(), + &input->joystick, fs_src, txt_dst, client->getFormspecPrepend(), sound); formspec->setFormSpec(fs_src->getForm(), inventoryloc); } @@ -2626,8 +2626,8 @@ void Game::handleClientEvent_ShowFormSpec(ClientEvent *event, CameraOrientation new TextDestPlayerInventory(client, *(event->show_formspec.formname)); auto *&formspec = m_game_ui->updateFormspec(*(event->show_formspec.formname)); - GUIFormSpecMenu::create(formspec, client, &input->joystick, - fs_src, txt_dst, client->getFormspecPrepend(), sound); + GUIFormSpecMenu::create(formspec, client, m_rendering_engine->get_gui_env(), + &input->joystick, fs_src, txt_dst, client->getFormspecPrepend(), sound); } delete event->show_formspec.formspec; @@ -2639,8 +2639,8 @@ void Game::handleClientEvent_ShowLocalFormSpec(ClientEvent *event, CameraOrienta FormspecFormSource *fs_src = new FormspecFormSource(*event->show_formspec.formspec); LocalFormspecHandler *txt_dst = new LocalFormspecHandler(*event->show_formspec.formname, client); - GUIFormSpecMenu::create(m_game_ui->getFormspecGUI(), client, &input->joystick, - fs_src, txt_dst, client->getFormspecPrepend(), sound); + GUIFormSpecMenu::create(m_game_ui->getFormspecGUI(), client, m_rendering_engine->get_gui_env(), + &input->joystick, fs_src, txt_dst, client->getFormspecPrepend(), sound); delete event->show_formspec.formspec; delete event->show_formspec.formname; @@ -3332,8 +3332,8 @@ bool Game::nodePlacement(const ItemDefinition &selected_def, TextDest *txt_dst = new TextDestNodeMetadata(nodepos, client); auto *&formspec = m_game_ui->updateFormspec(""); - GUIFormSpecMenu::create(formspec, client, &input->joystick, fs_src, - txt_dst, client->getFormspecPrepend(), sound); + GUIFormSpecMenu::create(formspec, client, m_rendering_engine->get_gui_env(), + &input->joystick, fs_src, txt_dst, client->getFormspecPrepend(), sound); formspec->setFormSpec(meta->getString("formspec"), inventoryloc); return false; @@ -4082,8 +4082,8 @@ void Game::showDeathFormspec() LocalFormspecHandler *txt_dst = new LocalFormspecHandler("MT_DEATH_SCREEN", client); auto *&formspec = m_game_ui->getFormspecGUI(); - GUIFormSpecMenu::create(formspec, client, &input->joystick, - fs_src, txt_dst, client->getFormspecPrepend(), sound); + GUIFormSpecMenu::create(formspec, client, m_rendering_engine->get_gui_env(), + &input->joystick, fs_src, txt_dst, client->getFormspecPrepend(), sound); formspec->setFocus("btn_respawn"); } @@ -4216,8 +4216,8 @@ void Game::showPauseMenu() LocalFormspecHandler *txt_dst = new LocalFormspecHandler("MT_PAUSE_MENU"); auto *&formspec = m_game_ui->getFormspecGUI(); - GUIFormSpecMenu::create(formspec, client, &input->joystick, - fs_src, txt_dst, client->getFormspecPrepend(), sound); + GUIFormSpecMenu::create(formspec, client, m_rendering_engine->get_gui_env(), + &input->joystick, fs_src, txt_dst, client->getFormspecPrepend(), sound); formspec->setFocus("btn_continue"); formspec->doPause = true; diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp index ec8f47576..e74446aeb 100644 --- a/src/client/renderingengine.cpp +++ b/src/client/renderingengine.cpp @@ -493,7 +493,7 @@ bool RenderingEngine::setXorgWindowIconFromPath(const std::string &icon_file) Text will be removed when the screen is drawn the next time. Additionally, a progressbar can be drawn when percent is set between 0 and 100. */ -void RenderingEngine::_draw_load_screen(const std::wstring &text, +void RenderingEngine::draw_load_screen(const std::wstring &text, gui::IGUIEnvironment *guienv, ITextureSource *tsrc, float dtime, int percent, bool clouds) { diff --git a/src/client/renderingengine.h b/src/client/renderingengine.h index 4d06baa23..1fd85f5ef 100644 --- a/src/client/renderingengine.h +++ b/src/client/renderingengine.h @@ -95,19 +95,14 @@ public: return m_device->getTimer()->getTime(); } - static gui::IGUIEnvironment *get_gui_env() + gui::IGUIEnvironment *get_gui_env() { - sanity_check(s_singleton && s_singleton->m_device); - return s_singleton->m_device->getGUIEnvironment(); + return m_device->getGUIEnvironment(); } - inline static void draw_load_screen(const std::wstring &text, + void draw_load_screen(const std::wstring &text, gui::IGUIEnvironment *guienv, ITextureSource *tsrc, - float dtime = 0, int percent = 0, bool clouds = true) - { - s_singleton->_draw_load_screen( - text, guienv, tsrc, dtime, percent, clouds); - } + float dtime = 0, int percent = 0, bool clouds = true); void draw_menu_scene(gui::IGUIEnvironment *guienv, float dtime, bool clouds); void draw_scene(video::SColor skycolor, bool show_hud, @@ -125,10 +120,6 @@ public: static std::vector getSupportedVideoDrivers(); private: - void _draw_load_screen(const std::wstring &text, gui::IGUIEnvironment *guienv, - ITextureSource *tsrc, float dtime = 0, int percent = 0, - bool clouds = true); - v2u32 _getWindowSize() const; std::unique_ptr core; diff --git a/src/gui/guiEngine.cpp b/src/gui/guiEngine.cpp index 0c7b96492..694baf482 100644 --- a/src/gui/guiEngine.cpp +++ b/src/gui/guiEngine.cpp @@ -170,6 +170,7 @@ GUIEngine::GUIEngine(JoystickController *joystick, -1, m_menumanager, NULL /* &client */, + m_rendering_engine->get_gui_env(), m_texture_source, m_sound_manager, m_formspecgui, diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index fdcf27a0a..c6435804f 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -96,10 +96,10 @@ inline u32 clamp_u8(s32 value) GUIFormSpecMenu::GUIFormSpecMenu(JoystickController *joystick, gui::IGUIElement *parent, s32 id, IMenuManager *menumgr, - Client *client, ISimpleTextureSource *tsrc, ISoundManager *sound_manager, - IFormSource *fsrc, TextDest *tdst, + Client *client, gui::IGUIEnvironment *guienv, ISimpleTextureSource *tsrc, + ISoundManager *sound_manager, IFormSource *fsrc, TextDest *tdst, const std::string &formspecPrepend, bool remap_dbl_click): - GUIModalMenu(RenderingEngine::get_gui_env(), parent, id, menumgr, remap_dbl_click), + GUIModalMenu(guienv, parent, id, menumgr, remap_dbl_click), m_invmgr(client), m_tsrc(tsrc), m_sound_manager(sound_manager), @@ -145,12 +145,12 @@ GUIFormSpecMenu::~GUIFormSpecMenu() } void GUIFormSpecMenu::create(GUIFormSpecMenu *&cur_formspec, Client *client, - JoystickController *joystick, IFormSource *fs_src, TextDest *txt_dest, - const std::string &formspecPrepend, ISoundManager *sound_manager) + gui::IGUIEnvironment *guienv, JoystickController *joystick, IFormSource *fs_src, + TextDest *txt_dest, const std::string &formspecPrepend, ISoundManager *sound_manager) { if (cur_formspec == nullptr) { cur_formspec = new GUIFormSpecMenu(joystick, guiroot, -1, &g_menumgr, - client, client->getTextureSource(), sound_manager, fs_src, + client, guienv, client->getTextureSource(), sound_manager, fs_src, txt_dest, formspecPrepend); cur_formspec->doPause = false; diff --git a/src/gui/guiFormSpecMenu.h b/src/gui/guiFormSpecMenu.h index d658aba7b..926de66d5 100644 --- a/src/gui/guiFormSpecMenu.h +++ b/src/gui/guiFormSpecMenu.h @@ -152,6 +152,7 @@ public: gui::IGUIElement* parent, s32 id, IMenuManager *menumgr, Client *client, + gui::IGUIEnvironment *guienv, ISimpleTextureSource *tsrc, ISoundManager *sound_manager, IFormSource* fs_src, @@ -162,8 +163,9 @@ public: ~GUIFormSpecMenu(); static void create(GUIFormSpecMenu *&cur_formspec, Client *client, - JoystickController *joystick, IFormSource *fs_src, TextDest *txt_dest, - const std::string &formspecPrepend, ISoundManager *sound_manager); + gui::IGUIEnvironment *guienv, JoystickController *joystick, IFormSource *fs_src, + TextDest *txt_dest, const std::string &formspecPrepend, + ISoundManager *sound_manager); void setFormSpec(const std::string &formspec_string, const InventoryLocation ¤t_inventory_location) diff --git a/src/nodedef.cpp b/src/nodedef.cpp index 65a76bcec..db4043aa1 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -1435,9 +1435,7 @@ void NodeDefManager::applyTextureOverrides(const std::vector &o } } -void NodeDefManager::updateTextures(IGameDef *gamedef, - void (*progress_callback)(void *progress_args, u32 progress, u32 max_progress), - void *progress_callback_args) +void NodeDefManager::updateTextures(IGameDef *gamedef, void *progress_callback_args) { #ifndef SERVER infostream << "NodeDefManager::updateTextures(): Updating " @@ -1456,7 +1454,7 @@ void NodeDefManager::updateTextures(IGameDef *gamedef, for (u32 i = 0; i < size; i++) { ContentFeatures *f = &(m_content_features[i]); f->updateTextures(tsrc, shdsrc, meshmanip, client, tsettings); - progress_callback(progress_callback_args, i, size); + client->showUpdateProgressTexture(progress_callback_args, i, size); } #endif } diff --git a/src/nodedef.h b/src/nodedef.h index 0de4dbc21..8a6d88071 100644 --- a/src/nodedef.h +++ b/src/nodedef.h @@ -660,9 +660,7 @@ public: * total ContentFeatures. * @param progress_cbk_args passed to the callback function */ - void updateTextures(IGameDef *gamedef, - void (*progress_cbk)(void *progress_args, u32 progress, u32 max_progress), - void *progress_cbk_args); + void updateTextures(IGameDef *gamedef, void *progress_cbk_args); /*! * Writes the content of this manager to the given output stream. diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index a5bb5f261..b13398539 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -397,7 +397,8 @@ int ModApiMainMenu::l_show_keys_menu(lua_State *L) GUIEngine* engine = getGuiEngine(L); sanity_check(engine != NULL); - GUIKeyChangeMenu *kmenu = new GUIKeyChangeMenu(RenderingEngine::get_gui_env(), + GUIKeyChangeMenu *kmenu = new GUIKeyChangeMenu( + engine->m_rendering_engine->get_gui_env(), engine->m_parent, -1, engine->m_menumanager, @@ -694,7 +695,7 @@ int ModApiMainMenu::l_show_path_select_dialog(lua_State *L) bool is_file_select = readParam(L, 3); GUIFileSelectMenu* fileOpenMenu = - new GUIFileSelectMenu(RenderingEngine::get_gui_env(), + new GUIFileSelectMenu(engine->m_rendering_engine->get_gui_env(), engine->m_parent, -1, engine->m_menumanager, -- cgit v1.2.3 From 225d4541ffb4d59001841747e0877a175da50c17 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Thu, 6 May 2021 09:02:11 +0200 Subject: fix: extractZipFile is not part of Client but more generic. This solve a crash from mainmenu while extracting the zip --- src/client/client.cpp | 66 --------------------------------------- src/client/client.h | 2 -- src/filesys.cpp | 64 +++++++++++++++++++++++++++++++++++++ src/filesys.h | 6 ++++ src/script/lua_api/l_mainmenu.cpp | 3 +- 5 files changed, 72 insertions(+), 69 deletions(-) (limited to 'src/script/lua_api/l_mainmenu.cpp') diff --git a/src/client/client.cpp b/src/client/client.cpp index c0da27e44..00ae8f6b8 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -725,72 +725,6 @@ bool Client::loadMedia(const std::string &data, const std::string &filename, return false; } -bool Client::extractZipFile(const char *filename, const std::string &destination) -{ - auto fs = m_rendering_engine->get_filesystem(); - - if (!fs->addFileArchive(filename, false, false, io::EFAT_ZIP)) { - return false; - } - - sanity_check(fs->getFileArchiveCount() > 0); - - /**********************************************************************/ - /* WARNING this is not threadsafe!! */ - /**********************************************************************/ - io::IFileArchive* opened_zip = fs->getFileArchive(fs->getFileArchiveCount() - 1); - - const io::IFileList* files_in_zip = opened_zip->getFileList(); - - unsigned int number_of_files = files_in_zip->getFileCount(); - - for (unsigned int i=0; i < number_of_files; i++) { - std::string fullpath = destination; - fullpath += DIR_DELIM; - fullpath += files_in_zip->getFullFileName(i).c_str(); - std::string fullpath_dir = fs::RemoveLastPathComponent(fullpath); - - if (!files_in_zip->isDirectory(i)) { - if (!fs::PathExists(fullpath_dir) && !fs::CreateAllDirs(fullpath_dir)) { - fs->removeFileArchive(fs->getFileArchiveCount()-1); - return false; - } - - io::IReadFile* toread = opened_zip->createAndOpenFile(i); - - FILE *targetfile = fopen(fullpath.c_str(),"wb"); - - if (targetfile == NULL) { - fs->removeFileArchive(fs->getFileArchiveCount()-1); - return false; - } - - char read_buffer[1024]; - long total_read = 0; - - while (total_read < toread->getSize()) { - - unsigned int bytes_read = - toread->read(read_buffer,sizeof(read_buffer)); - if ((bytes_read == 0 ) || - (fwrite(read_buffer, 1, bytes_read, targetfile) != bytes_read)) - { - fclose(targetfile); - fs->removeFileArchive(fs->getFileArchiveCount() - 1); - return false; - } - total_read += bytes_read; - } - - fclose(targetfile); - } - - } - - fs->removeFileArchive(fs->getFileArchiveCount() - 1); - return true; -} - // Virtual methods from con::PeerHandler void Client::peerAdded(con::Peer *peer) { diff --git a/src/client/client.h b/src/client/client.h index c9a72b1b3..85ca24049 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -384,8 +384,6 @@ public: bool loadMedia(const std::string &data, const std::string &filename, bool from_media_push = false); - bool extractZipFile(const char *filename, const std::string &destination); - // Send a request for conventional media transfer void request_media(const std::vector &file_requests); diff --git a/src/filesys.cpp b/src/filesys.cpp index 5ffb4506e..99b030624 100644 --- a/src/filesys.cpp +++ b/src/filesys.cpp @@ -727,6 +727,70 @@ bool safeWriteToFile(const std::string &path, const std::string &content) return true; } +bool extractZipFile(io::IFileSystem *fs, const char *filename, const std::string &destination) +{ + if (!fs->addFileArchive(filename, false, false, io::EFAT_ZIP)) { + return false; + } + + sanity_check(fs->getFileArchiveCount() > 0); + + /**********************************************************************/ + /* WARNING this is not threadsafe!! */ + /**********************************************************************/ + io::IFileArchive* opened_zip = fs->getFileArchive(fs->getFileArchiveCount() - 1); + + const io::IFileList* files_in_zip = opened_zip->getFileList(); + + unsigned int number_of_files = files_in_zip->getFileCount(); + + for (unsigned int i=0; i < number_of_files; i++) { + std::string fullpath = destination; + fullpath += DIR_DELIM; + fullpath += files_in_zip->getFullFileName(i).c_str(); + std::string fullpath_dir = fs::RemoveLastPathComponent(fullpath); + + if (!files_in_zip->isDirectory(i)) { + if (!fs::PathExists(fullpath_dir) && !fs::CreateAllDirs(fullpath_dir)) { + fs->removeFileArchive(fs->getFileArchiveCount()-1); + return false; + } + + io::IReadFile* toread = opened_zip->createAndOpenFile(i); + + FILE *targetfile = fopen(fullpath.c_str(),"wb"); + + if (targetfile == NULL) { + fs->removeFileArchive(fs->getFileArchiveCount()-1); + return false; + } + + char read_buffer[1024]; + long total_read = 0; + + while (total_read < toread->getSize()) { + + unsigned int bytes_read = + toread->read(read_buffer,sizeof(read_buffer)); + if ((bytes_read == 0 ) || + (fwrite(read_buffer, 1, bytes_read, targetfile) != bytes_read)) + { + fclose(targetfile); + fs->removeFileArchive(fs->getFileArchiveCount() - 1); + return false; + } + total_read += bytes_read; + } + + fclose(targetfile); + } + + } + + fs->removeFileArchive(fs->getFileArchiveCount() - 1); + return true; +} + bool ReadFile(const std::string &path, std::string &out) { std::ifstream is(path, std::ios::binary | std::ios::ate); diff --git a/src/filesys.h b/src/filesys.h index cfbfa02bf..a9584b036 100644 --- a/src/filesys.h +++ b/src/filesys.h @@ -36,6 +36,10 @@ with this program; if not, write to the Free Software Foundation, Inc., #define PATH_DELIM ":" #endif +namespace irr { namespace io { +class IFileSystem; +}} + namespace fs { @@ -125,6 +129,8 @@ const char *GetFilenameFromPath(const char *path); bool safeWriteToFile(const std::string &path, const std::string &content); +bool extractZipFile(irr::io::IFileSystem *fs, const char *filename, const std::string &destination); + bool ReadFile(const std::string &path, std::string &out); bool Rename(const std::string &from, const std::string &to); diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index b13398539..ee3e72dea 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -628,8 +628,9 @@ int ModApiMainMenu::l_extract_zip(lua_State *L) std::string absolute_destination = fs::RemoveRelativePathComponents(destination); if (ModApiMainMenu::mayModifyPath(absolute_destination)) { + auto rendering_engine = getGuiEngine(L)->m_rendering_engine; fs::CreateAllDirs(absolute_destination); - lua_pushboolean(L, getClient(L)->extractZipFile(zipfile, destination)); + lua_pushboolean(L, fs::extractZipFile(rendering_engine->get_filesystem(), zipfile, destination)); return 1; } -- cgit v1.2.3