From bc1888ff21d50eb21c8f4d381e5dcc8049f7e36c Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Wed, 28 Apr 2021 09:55:51 +0200 Subject: fix: drop old irrlicht <1.8 compat on Client::loadMedia --- src/client/client.cpp | 7 ------- 1 file changed, 7 deletions(-) (limited to 'src/client/client.cpp') diff --git a/src/client/client.cpp b/src/client/client.cpp index 0486bc0a9..5db0b8f5d 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -663,15 +663,8 @@ bool Client::loadMedia(const std::string &data, const std::string &filename, io::IFileSystem *irrfs = RenderingEngine::get_filesystem(); video::IVideoDriver *vdrv = RenderingEngine::get_video_driver(); -#if IRRLICHT_VERSION_MAJOR == 1 && IRRLICHT_VERSION_MINOR > 8 io::IReadFile *rfile = irrfs->createMemoryReadFile( data.c_str(), data.size(), "_tempreadfile"); -#else - // Silly irrlicht's const-incorrectness - Buffer data_rw(data.c_str(), data.size()); - io::IReadFile *rfile = irrfs->createMemoryReadFile( - *data_rw, data_rw.getSize(), "_tempreadfile"); -#endif FATAL_ERROR_IF(!rfile, "Could not create irrlicht memory file."); -- 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/client/client.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 e0716384d6c7abfa228b039056f1e872ca7bb8cf Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Wed, 28 Apr 2021 10:53:36 +0200 Subject: refacto: add RenderingEngine::cleanupMeshCache This permits to prevent client to own the mesh cache cleanup logic. It's better in RenderingEngine --- src/client/client.cpp | 7 +------ src/client/renderingengine.cpp | 9 +++++++++ src/client/renderingengine.h | 1 + 3 files changed, 11 insertions(+), 6 deletions(-) (limited to 'src/client/client.cpp') diff --git a/src/client/client.cpp b/src/client/client.cpp index d7e69f349..48097be2e 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -300,12 +300,7 @@ Client::~Client() } // cleanup 3d model meshes on client shutdown - while (RenderingEngine::get_mesh_cache()->getMeshCount() != 0) { - scene::IAnimatedMesh *mesh = RenderingEngine::get_mesh_cache()->getMeshByIndex(0); - - if (mesh) - RenderingEngine::get_mesh_cache()->removeMesh(mesh); - } + m_rendering_engine->cleanupMeshCache(); delete m_minimap; m_minimap = nullptr; diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp index d2d136a61..970bcf95b 100644 --- a/src/client/renderingengine.cpp +++ b/src/client/renderingengine.cpp @@ -225,6 +225,15 @@ bool RenderingEngine::print_video_modes() return videomode_list != NULL; } +void RenderingEngine::cleanupMeshCache() +{ + auto mesh_cache = m_device->getSceneManager()->getMeshCache(); + while (mesh_cache->getMeshCount() != 0) { + if (scene::IAnimatedMesh *mesh = mesh_cache->getMeshByIndex(0)) + m_rendering_engine->get_mesh_cache()->removeMesh(mesh); + } +} + bool RenderingEngine::setupTopLevelWindow(const std::string &name) { // FIXME: It would make more sense for there to be a switch of some diff --git a/src/client/renderingengine.h b/src/client/renderingengine.h index 5807421ef..fae431f1f 100644 --- a/src/client/renderingengine.h +++ b/src/client/renderingengine.h @@ -56,6 +56,7 @@ public: bool setWindowIcon(); bool setXorgWindowIconFromPath(const std::string &icon_file); static bool print_video_modes(); + void cleanupMeshCache(); static RenderingEngine *get_instance() { return s_singleton; } -- cgit v1.2.3 From 74125a74d34e9b1a003107d4ef6b95b8483d2464 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Wed, 28 Apr 2021 11:07:28 +0200 Subject: refacto: hide mesh_cache inside the rendering engine This permit cleaner access to meshCache and ensure we don't access to it from all the code --- src/client/client.cpp | 2 +- src/client/game.cpp | 25 +------------------------ src/client/renderingengine.cpp | 7 ++++++- src/client/renderingengine.h | 11 +++++------ 4 files changed, 13 insertions(+), 32 deletions(-) (limited to 'src/client/client.cpp') diff --git a/src/client/client.cpp b/src/client/client.cpp index 48097be2e..15979df02 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -1983,7 +1983,7 @@ scene::IAnimatedMesh* Client::getMesh(const std::string &filename, bool cache) return nullptr; mesh->grab(); if (!cache) - m_rendering_engine->get_mesh_cache()->removeMesh(mesh); + m_rendering_engine->removeMesh(mesh); return mesh; } diff --git a/src/client/game.cpp b/src/client/game.cpp index 612072136..8400d7639 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -652,8 +652,6 @@ public: protected: - void extendedResourceCleanup(); - // Basic initialisation bool init(const std::string &map_dir, const std::string &address, u16 port, const SubgameSpec &gamespec); @@ -968,7 +966,7 @@ Game::~Game() delete itemdef_manager; delete draw_control; - extendedResourceCleanup(); + clearTextureNameCache(); g_settings->deregisterChangedCallback("doubletap_jump", &settingChangedCallback, this); @@ -4063,27 +4061,6 @@ void Game::readSettings() ****************************************************************************/ /****************************************************************************/ -void Game::extendedResourceCleanup() -{ - // Extended resource accounting - infostream << "Irrlicht resources after cleanup:" << std::endl; - infostream << "\tRemaining meshes : " - << RenderingEngine::get_mesh_cache()->getMeshCount() << std::endl; - infostream << "\tRemaining textures : " - << driver->getTextureCount() << std::endl; - - for (unsigned int i = 0; i < driver->getTextureCount(); i++) { - irr::video::ITexture *texture = driver->getTextureByIndex(i); - infostream << "\t\t" << i << ":" << texture->getName().getPath().c_str() - << std::endl; - } - - clearTextureNameCache(); - infostream << "\tRemaining materials: " - << driver-> getMaterialRendererCount() - << " (note: irrlicht doesn't support removing renderers)" << std::endl; -} - void Game::showDeathFormspec() { static std::string formspec_str = diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp index 970bcf95b..da9022477 100644 --- a/src/client/renderingengine.cpp +++ b/src/client/renderingengine.cpp @@ -225,12 +225,17 @@ bool RenderingEngine::print_video_modes() return videomode_list != NULL; } +void RenderingEngine::removeMesh(const irr::scene::IMesh* mesh) +{ + m_device->getSceneManager()->getMeshCache()->removeMesh(mesh); +} + void RenderingEngine::cleanupMeshCache() { auto mesh_cache = m_device->getSceneManager()->getMeshCache(); while (mesh_cache->getMeshCount() != 0) { if (scene::IAnimatedMesh *mesh = mesh_cache->getMeshByIndex(0)) - m_rendering_engine->get_mesh_cache()->removeMesh(mesh); + mesh_cache->removeMesh(mesh); } } diff --git a/src/client/renderingengine.h b/src/client/renderingengine.h index fae431f1f..73b55229e 100644 --- a/src/client/renderingengine.h +++ b/src/client/renderingengine.h @@ -26,6 +26,9 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "irrlichttypes_extrabloated.h" #include "debug.h" +namespace irr { namespace scene { +class IMesh; +}} class ITextureSource; class Camera; class Client; @@ -58,6 +61,8 @@ public: static bool print_video_modes(); void cleanupMeshCache(); + void removeMesh(const irr::scene::IMesh* mesh); + static RenderingEngine *get_instance() { return s_singleton; } io::IFileSystem *get_filesystem() @@ -71,12 +76,6 @@ public: return s_singleton->m_device->getVideoDriver(); } - static scene::IMeshCache *get_mesh_cache() - { - sanity_check(s_singleton && s_singleton->m_device); - return s_singleton->m_device->getSceneManager()->getMeshCache(); - } - static scene::ISceneManager *get_scene_manager() { sanity_check(s_singleton && s_singleton->m_device); -- cgit v1.2.3 From 1bc855646e2c920c1df55bb73416f72295c020f4 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Thu, 29 Apr 2021 08:51:17 +0200 Subject: refacto: protect some RenderingEngine::get_scene_manager * protect it from Camera, Sky, ClientMap object calls * rename Game::sky to Game::m_sky --- src/client/camera.cpp | 4 +-- src/client/camera.h | 3 +- src/client/client.cpp | 2 +- src/client/clientmap.cpp | 7 ++-- src/client/clientmap.h | 1 + src/client/game.cpp | 83 ++++++++++++++++++++++++------------------------ src/client/sky.cpp | 6 ++-- src/client/sky.h | 2 +- 8 files changed, 56 insertions(+), 52 deletions(-) (limited to 'src/client/client.cpp') diff --git a/src/client/camera.cpp b/src/client/camera.cpp index f6892295b..2629a6359 100644 --- a/src/client/camera.cpp +++ b/src/client/camera.cpp @@ -43,11 +43,11 @@ with this program; if not, write to the Free Software Foundation, Inc., #define WIELDMESH_AMPLITUDE_X 7.0f #define WIELDMESH_AMPLITUDE_Y 10.0f -Camera::Camera(MapDrawControl &draw_control, Client *client): +Camera::Camera(MapDrawControl &draw_control, Client *client, RenderingEngine *rendering_engine): m_draw_control(draw_control), m_client(client) { - scene::ISceneManager *smgr = RenderingEngine::get_scene_manager(); + auto smgr = rendering_engine->get_scene_manager(); // note: making the camera node a child of the player node // would lead to unexpected behaviour, so we don't do that. m_playernode = smgr->addEmptySceneNode(smgr->getRootSceneNode()); diff --git a/src/client/camera.h b/src/client/camera.h index 6fd8d9aa7..593a97d80 100644 --- a/src/client/camera.h +++ b/src/client/camera.h @@ -30,6 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc., class LocalPlayer; struct MapDrawControl; class Client; +class RenderingEngine; class WieldMeshSceneNode; struct Nametag @@ -78,7 +79,7 @@ enum CameraMode {CAMERA_MODE_FIRST, CAMERA_MODE_THIRD, CAMERA_MODE_THIRD_FRONT}; class Camera { public: - Camera(MapDrawControl &draw_control, Client *client); + Camera(MapDrawControl &draw_control, Client *client, RenderingEngine *rendering_engine); ~Camera(); // Get camera scene node. diff --git a/src/client/client.cpp b/src/client/client.cpp index 15979df02..d1c5cd948 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -110,7 +110,7 @@ Client::Client( m_rendering_engine(rendering_engine), m_mesh_update_thread(this), m_env( - new ClientMap(this, control, 666), + new ClientMap(this, rendering_engine, control, 666), tsrc, this ), m_particle_manager(&m_env), diff --git a/src/client/clientmap.cpp b/src/client/clientmap.cpp index c5b47532c..6dc535898 100644 --- a/src/client/clientmap.cpp +++ b/src/client/clientmap.cpp @@ -64,12 +64,13 @@ void MeshBufListList::add(scene::IMeshBuffer *buf, v3s16 position, u8 layer) ClientMap::ClientMap( Client *client, + RenderingEngine *rendering_engine, MapDrawControl &control, s32 id ): Map(client), - scene::ISceneNode(RenderingEngine::get_scene_manager()->getRootSceneNode(), - RenderingEngine::get_scene_manager(), id), + scene::ISceneNode(rendering_engine->get_scene_manager()->getRootSceneNode(), + rendering_engine->get_scene_manager(), id), m_client(client), m_control(control) { @@ -317,7 +318,7 @@ void ClientMap::renderMap(video::IVideoDriver* driver, s32 pass) v3f block_pos_r = intToFloat(block->getPosRelative() + MAP_BLOCKSIZE / 2, BS); float d = camera_position.getDistanceFrom(block_pos_r); d = MYMAX(0,d - BLOCK_MAX_RADIUS); - + // Mesh animation if (pass == scene::ESNRP_SOLID) { //MutexAutoLock lock(block->mesh_mutex); diff --git a/src/client/clientmap.h b/src/client/clientmap.h index 57cc4427e..80add4a44 100644 --- a/src/client/clientmap.h +++ b/src/client/clientmap.h @@ -68,6 +68,7 @@ class ClientMap : public Map, public scene::ISceneNode public: ClientMap( Client *client, + RenderingEngine *rendering_engine, MapDrawControl &control, s32 id ); diff --git a/src/client/game.cpp b/src/client/game.cpp index 33707df4a..aa794a755 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -839,7 +839,7 @@ private: MapDrawControl *draw_control = nullptr; Camera *camera = nullptr; Clouds *clouds = nullptr; // Free using ->Drop() - Sky *sky = nullptr; // Free using ->Drop() + Sky *m_sky = nullptr; // Free using ->Drop() Hud *hud = nullptr; Minimap *mapper = nullptr; @@ -1159,8 +1159,8 @@ void Game::shutdown() if (gui_chat_console) gui_chat_console->drop(); - if (sky) - sky->drop(); + if (m_sky) + m_sky->drop(); /* cleanup menus */ while (g_menumgr.menuCount() > 0) { @@ -1293,7 +1293,7 @@ bool Game::createClient(const GameStartData &start_data) { showOverlayMessage(N_("Creating client..."), 0, 10); - draw_control = new MapDrawControl; + draw_control = new MapDrawControl(); if (!draw_control) return false; @@ -1334,7 +1334,7 @@ bool Game::createClient(const GameStartData &start_data) /* Camera */ - camera = new Camera(*draw_control, client); + camera = new Camera(*draw_control, client, m_rendering_engine); if (!camera->successfullyCreated(*error_message)) return false; client->setCamera(camera); @@ -1346,8 +1346,8 @@ bool Game::createClient(const GameStartData &start_data) /* Skybox */ - sky = new Sky(-1, texture_src, shader_src); - scsf->setSky(sky); + m_sky = new Sky(-1, m_rendering_engine, texture_src, shader_src); + scsf->setSky(m_sky); skybox = NULL; // This is used/set later on in the main run loop /* Pre-calculated values @@ -2754,23 +2754,23 @@ void Game::handleClientEvent_HudChange(ClientEvent *event, CameraOrientation *ca void Game::handleClientEvent_SetSky(ClientEvent *event, CameraOrientation *cam) { - sky->setVisible(false); + m_sky->setVisible(false); // Whether clouds are visible in front of a custom skybox. - sky->setCloudsEnabled(event->set_sky->clouds); + m_sky->setCloudsEnabled(event->set_sky->clouds); if (skybox) { skybox->remove(); skybox = NULL; } // Clear the old textures out in case we switch rendering type. - sky->clearSkyboxTextures(); + m_sky->clearSkyboxTextures(); // Handle according to type if (event->set_sky->type == "regular") { // Shows the mesh skybox - sky->setVisible(true); + m_sky->setVisible(true); // Update mesh based skybox colours if applicable. - sky->setSkyColors(event->set_sky->sky_color); - sky->setHorizonTint( + m_sky->setSkyColors(event->set_sky->sky_color); + m_sky->setHorizonTint( event->set_sky->fog_sun_tint, event->set_sky->fog_moon_tint, event->set_sky->fog_tint_type @@ -2778,61 +2778,62 @@ void Game::handleClientEvent_SetSky(ClientEvent *event, CameraOrientation *cam) } else if (event->set_sky->type == "skybox" && event->set_sky->textures.size() == 6) { // Disable the dyanmic mesh skybox: - sky->setVisible(false); + m_sky->setVisible(false); // Set fog colors: - sky->setFallbackBgColor(event->set_sky->bgcolor); + m_sky->setFallbackBgColor(event->set_sky->bgcolor); // Set sunrise and sunset fog tinting: - sky->setHorizonTint( + m_sky->setHorizonTint( event->set_sky->fog_sun_tint, event->set_sky->fog_moon_tint, event->set_sky->fog_tint_type ); // Add textures to skybox. for (int i = 0; i < 6; i++) - sky->addTextureToSkybox(event->set_sky->textures[i], i, texture_src); + m_sky->addTextureToSkybox(event->set_sky->textures[i], i, texture_src); } else { // Handle everything else as plain color. if (event->set_sky->type != "plain") infostream << "Unknown sky type: " << (event->set_sky->type) << std::endl; - sky->setVisible(false); - sky->setFallbackBgColor(event->set_sky->bgcolor); + m_sky->setVisible(false); + m_sky->setFallbackBgColor(event->set_sky->bgcolor); // Disable directional sun/moon tinting on plain or invalid skyboxes. - sky->setHorizonTint( + m_sky->setHorizonTint( event->set_sky->bgcolor, event->set_sky->bgcolor, "custom" ); } + delete event->set_sky; } void Game::handleClientEvent_SetSun(ClientEvent *event, CameraOrientation *cam) { - sky->setSunVisible(event->sun_params->visible); - sky->setSunTexture(event->sun_params->texture, + m_sky->setSunVisible(event->sun_params->visible); + m_sky->setSunTexture(event->sun_params->texture, event->sun_params->tonemap, texture_src); - sky->setSunScale(event->sun_params->scale); - sky->setSunriseVisible(event->sun_params->sunrise_visible); - sky->setSunriseTexture(event->sun_params->sunrise, texture_src); + m_sky->setSunScale(event->sun_params->scale); + m_sky->setSunriseVisible(event->sun_params->sunrise_visible); + m_sky->setSunriseTexture(event->sun_params->sunrise, texture_src); delete event->sun_params; } void Game::handleClientEvent_SetMoon(ClientEvent *event, CameraOrientation *cam) { - sky->setMoonVisible(event->moon_params->visible); - sky->setMoonTexture(event->moon_params->texture, + m_sky->setMoonVisible(event->moon_params->visible); + m_sky->setMoonTexture(event->moon_params->texture, event->moon_params->tonemap, texture_src); - sky->setMoonScale(event->moon_params->scale); + m_sky->setMoonScale(event->moon_params->scale); delete event->moon_params; } void Game::handleClientEvent_SetStars(ClientEvent *event, CameraOrientation *cam) { - sky->setStarsVisible(event->star_params->visible); - sky->setStarCount(event->star_params->count, false); - sky->setStarColor(event->star_params->starcolor); - sky->setStarScale(event->star_params->scale); + m_sky->setStarsVisible(event->star_params->visible); + m_sky->setStarCount(event->star_params->count, false); + m_sky->setStarColor(event->star_params->starcolor); + m_sky->setStarScale(event->star_params->scale); delete event->star_params; } @@ -3709,7 +3710,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, direct_brightness = time_brightness; sunlight_seen = true; } else { - float old_brightness = sky->getBrightness(); + float old_brightness = m_sky->getBrightness(); direct_brightness = client->getEnv().getClientMap() .getBackgroundBrightness(MYMIN(runData.fog_range * 1.2, 60 * BS), daynight_ratio, (int)(old_brightness * 255.5), &sunlight_seen) @@ -3736,7 +3737,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, runData.time_of_day_smooth = time_of_day_smooth; - sky->update(time_of_day_smooth, time_brightness, direct_brightness, + m_sky->update(time_of_day_smooth, time_brightness, direct_brightness, sunlight_seen, camera->getCameraMode(), player->getYaw(), player->getPitch()); @@ -3744,7 +3745,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, Update clouds */ if (clouds) { - if (sky->getCloudsVisible()) { + if (m_sky->getCloudsVisible()) { clouds->setVisible(true); clouds->step(dtime); // camera->getPosition is not enough for 3rd person views @@ -3754,14 +3755,14 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, camera_node_position.Y = camera_node_position.Y + camera_offset.Y * BS; camera_node_position.Z = camera_node_position.Z + camera_offset.Z * BS; clouds->update(camera_node_position, - sky->getCloudColor()); + m_sky->getCloudColor()); if (clouds->isCameraInsideCloud() && m_cache_enable_fog) { // if inside clouds, and fog enabled, use that as sky // color(s) video::SColor clouds_dark = clouds->getColor() .getInterpolated(video::SColor(255, 0, 0, 0), 0.9); - sky->overrideColors(clouds_dark, clouds->getColor()); - sky->setInClouds(true); + m_sky->overrideColors(clouds_dark, clouds->getColor()); + m_sky->setInClouds(true); runData.fog_range = std::fmin(runData.fog_range * 0.5f, 32.0f * BS); // do not draw clouds after all clouds->setVisible(false); @@ -3782,7 +3783,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, if (m_cache_enable_fog) { driver->setFog( - sky->getBgColor(), + m_sky->getBgColor(), video::EFT_FOG_LINEAR, runData.fog_range * m_cache_fog_start, runData.fog_range * 1.0, @@ -3792,7 +3793,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, ); } else { driver->setFog( - sky->getBgColor(), + m_sky->getBgColor(), video::EFT_FOG_LINEAR, 100000 * BS, 110000 * BS, @@ -3872,7 +3873,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, /* Drawing begins */ - const video::SColor &skycolor = sky->getSkyColor(); + const video::SColor &skycolor = m_sky->getSkyColor(); TimeTaker tt_draw("Draw scene"); driver->beginScene(true, true, skycolor); diff --git a/src/client/sky.cpp b/src/client/sky.cpp index 46a3f2621..47296a7a5 100644 --- a/src/client/sky.cpp +++ b/src/client/sky.cpp @@ -53,9 +53,9 @@ static video::SMaterial baseMaterial() return mat; }; -Sky::Sky(s32 id, ITextureSource *tsrc, IShaderSource *ssrc) : - scene::ISceneNode(RenderingEngine::get_scene_manager()->getRootSceneNode(), - RenderingEngine::get_scene_manager(), id) +Sky::Sky(s32 id, RenderingEngine *rendering_engine, ITextureSource *tsrc, IShaderSource *ssrc) : + scene::ISceneNode(rendering_engine->get_scene_manager()->getRootSceneNode(), + rendering_engine->get_scene_manager(), id) { m_seed = (u64)myrand() << 32 | myrand(); diff --git a/src/client/sky.h b/src/client/sky.h index dc7da5021..121a16bb7 100644 --- a/src/client/sky.h +++ b/src/client/sky.h @@ -36,7 +36,7 @@ class Sky : public scene::ISceneNode { public: //! constructor - Sky(s32 id, ITextureSource *tsrc, IShaderSource *ssrc); + Sky(s32 id, RenderingEngine *rendering_engine, ITextureSource *tsrc, IShaderSource *ssrc); virtual void OnRegisterSceneNode(); -- cgit v1.2.3 From 5a02c376ea5f2e7f1dd0a2bd4f08bf953ed4bfc8 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Thu, 29 Apr 2021 09:40:56 +0200 Subject: refacto: RenderingEngine::get_scene_manager() is now not callable from singleton This permits to make evidence that we have some bad object passing on various code parts. I fixed majority of them to reduce the scope of passed objects Unfortunately, for some edge cases i should have to expose ISceneManager from client, this should be fixed in the future when our POO will be cleaner client side (we have a mix of rendering and processing in majority of the client objects, it works but it's not clean) --- src/client/client.cpp | 5 +++++ src/client/client.h | 1 + src/client/clientenvironment.cpp | 2 +- src/client/content_mapblock.cpp | 16 +++++++--------- src/client/content_mapblock.h | 3 ++- src/client/mapblock_mesh.cpp | 4 ++-- src/client/particles.cpp | 4 ++-- src/client/renderingengine.h | 5 ++--- src/client/wieldmesh.cpp | 5 +++-- src/gui/guiFormSpecMenu.cpp | 2 +- src/nodedef.cpp | 4 ++-- 11 files changed, 28 insertions(+), 23 deletions(-) (limited to 'src/client/client.cpp') diff --git a/src/client/client.cpp b/src/client/client.cpp index d1c5cd948..2f4f2aac5 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -1475,6 +1475,11 @@ bool Client::updateWieldedItem() return true; } +irr::scene::ISceneManager* Client::getSceneManager() +{ + return m_rendering_engine->get_scene_manager(); +} + Inventory* Client::getInventory(const InventoryLocation &loc) { switch(loc.type){ diff --git a/src/client/client.h b/src/client/client.h index bcb7d6b09..be5970160 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -355,6 +355,7 @@ public: void setCamera(Camera* camera) { m_camera = camera; } Camera* getCamera () { return m_camera; } + irr::scene::ISceneManager *getSceneManager(); bool shouldShowMinimap() const; diff --git a/src/client/clientenvironment.cpp b/src/client/clientenvironment.cpp index 9c40484bf..7e3867537 100644 --- a/src/client/clientenvironment.cpp +++ b/src/client/clientenvironment.cpp @@ -352,7 +352,7 @@ u16 ClientEnvironment::addActiveObject(ClientActiveObject *object) if (!m_ao_manager.registerObject(object)) return 0; - object->addToScene(m_texturesource, RenderingEngine::get_scene_manager()); + object->addToScene(m_texturesource, m_client->getSceneManager()); // Update lighting immediately object->updateLight(getDayNightRatio()); diff --git a/src/client/content_mapblock.cpp b/src/client/content_mapblock.cpp index ce7235bca..e530f3d7f 100644 --- a/src/client/content_mapblock.cpp +++ b/src/client/content_mapblock.cpp @@ -60,18 +60,16 @@ static constexpr u16 quad_indices[] = {0, 1, 2, 2, 3, 0}; const std::string MapblockMeshGenerator::raillike_groupname = "connect_to_raillike"; -MapblockMeshGenerator::MapblockMeshGenerator(MeshMakeData *input, MeshCollector *output) +MapblockMeshGenerator::MapblockMeshGenerator(MeshMakeData *input, MeshCollector *output, + irr::scene::IMeshManipulator *mm): + data(input), + collector(output), + nodedef(data->m_client->ndef()), + meshmanip(mm), + blockpos_nodes(data->m_blockpos * MAP_BLOCKSIZE) { - data = input; - collector = output; - - nodedef = data->m_client->ndef(); - meshmanip = RenderingEngine::get_scene_manager()->getMeshManipulator(); - enable_mesh_cache = g_settings->getBool("enable_mesh_cache") && !data->m_smooth_lighting; // Mesh cache is not supported with smooth lighting - - blockpos_nodes = data->m_blockpos * MAP_BLOCKSIZE; } void MapblockMeshGenerator::useTile(int index, u8 set_flags, u8 reset_flags, bool special) diff --git a/src/client/content_mapblock.h b/src/client/content_mapblock.h index a6c450d1f..cbee49021 100644 --- a/src/client/content_mapblock.h +++ b/src/client/content_mapblock.h @@ -172,7 +172,8 @@ public: void drawNode(); public: - MapblockMeshGenerator(MeshMakeData *input, MeshCollector *output); + MapblockMeshGenerator(MeshMakeData *input, MeshCollector *output, + irr::scene::IMeshManipulator *mm); void generate(); void renderSingle(content_t node, u8 param2 = 0x00); }; diff --git a/src/client/mapblock_mesh.cpp b/src/client/mapblock_mesh.cpp index 167e1e3ec..72e68fe97 100644 --- a/src/client/mapblock_mesh.cpp +++ b/src/client/mapblock_mesh.cpp @@ -1072,8 +1072,8 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset): */ { - MapblockMeshGenerator generator(data, &collector); - generator.generate(); + MapblockMeshGenerator(data, &collector, + data->m_client->getSceneManager()->getMeshManipulator()).generate(); } /* diff --git a/src/client/particles.cpp b/src/client/particles.cpp index 7acd996dc..288826a5f 100644 --- a/src/client/particles.cpp +++ b/src/client/particles.cpp @@ -64,8 +64,8 @@ Particle::Particle( v2f texsize, video::SColor color ): - scene::ISceneNode(RenderingEngine::get_scene_manager()->getRootSceneNode(), - RenderingEngine::get_scene_manager()) + scene::ISceneNode(((Client *)gamedef)->getSceneManager()->getRootSceneNode(), + ((Client *)gamedef)->getSceneManager()) { // Misc m_gamedef = gamedef; diff --git a/src/client/renderingengine.h b/src/client/renderingengine.h index 5462aa667..4d06baa23 100644 --- a/src/client/renderingengine.h +++ b/src/client/renderingengine.h @@ -79,10 +79,9 @@ public: return s_singleton->m_device->getVideoDriver(); } - static scene::ISceneManager *get_scene_manager() + scene::ISceneManager *get_scene_manager() { - sanity_check(s_singleton && s_singleton->m_device); - return s_singleton->m_device->getSceneManager(); + return m_device->getSceneManager(); } static irr::IrrlichtDevice *get_raw_device() diff --git a/src/client/wieldmesh.cpp b/src/client/wieldmesh.cpp index d9d5e57cd..08fd49fc0 100644 --- a/src/client/wieldmesh.cpp +++ b/src/client/wieldmesh.cpp @@ -307,7 +307,8 @@ static scene::SMesh *createSpecialNodeMesh(Client *client, MapNode n, MeshMakeData mesh_make_data(client, false); MeshCollector collector; mesh_make_data.setSmoothLighting(false); - MapblockMeshGenerator gen(&mesh_make_data, &collector); + MapblockMeshGenerator gen(&mesh_make_data, &collector, + client->getSceneManager()->getMeshManipulator()); if (n.getParam2()) { // keep it @@ -538,7 +539,7 @@ void getItemMesh(Client *client, const ItemStack &item, ItemMesh *result) content_t id = ndef->getId(def.name); FATAL_ERROR_IF(!g_extrusion_mesh_cache, "Extrusion mesh cache is not yet initialized"); - + scene::SMesh *mesh = nullptr; // Shading is on by default diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index fd35f2d84..fdcf27a0a 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -2794,7 +2794,7 @@ void GUIFormSpecMenu::parseModel(parserData *data, const std::string &element) core::rect rect(pos, pos + geom); - GUIScene *e = new GUIScene(Environment, RenderingEngine::get_scene_manager(), + GUIScene *e = new GUIScene(Environment, m_client->getSceneManager(), data->current_parent, rect, spec.fid); auto meshnode = e->setMesh(mesh); diff --git a/src/nodedef.cpp b/src/nodedef.cpp index dd862e606..65a76bcec 100644 --- a/src/nodedef.cpp +++ b/src/nodedef.cpp @@ -1446,8 +1446,8 @@ void NodeDefManager::updateTextures(IGameDef *gamedef, Client *client = (Client *)gamedef; ITextureSource *tsrc = client->tsrc(); IShaderSource *shdsrc = client->getShaderSource(); - scene::IMeshManipulator *meshmanip = - RenderingEngine::get_scene_manager()->getMeshManipulator(); + auto smgr = client->getSceneManager(); + scene::IMeshManipulator *meshmanip = smgr->getMeshManipulator(); TextureSettings tsettings; tsettings.readSettings(); -- cgit v1.2.3 From a93712458b2f8914fdb43ec436c5caf908ba93b8 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Thu, 29 Apr 2021 09:45:49 +0200 Subject: fix: don't use RenderingEngine singleton when it's possible --- src/client/client.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/client/client.cpp') diff --git a/src/client/client.cpp b/src/client/client.cpp index 2f4f2aac5..1a3a81378 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -1771,21 +1771,21 @@ void Client::afterContentReceived() // Rebuild inherited images and recreate textures infostream<<"- Rebuilding images and textures"<draw_load_screen(text, guienv, m_tsrc, 0, 70); m_tsrc->rebuildImagesAndTextures(); delete[] text; // Rebuild shaders infostream<<"- Rebuilding shaders"<draw_load_screen(text, guienv, m_tsrc, 0, 71); m_shsrc->rebuildShaders(); delete[] text; // Update node aliases infostream<<"- Updating node aliases"<draw_load_screen(text, guienv, m_tsrc, 0, 72); m_nodedef->updateAliases(m_itemdef); for (const auto &path : getTextureDirs()) { TextureOverrideSource override_source(path + DIR_DELIM + "override.txt"); @@ -1818,7 +1818,7 @@ void Client::afterContentReceived() m_script->on_client_ready(m_env.getLocalPlayer()); text = wgettext("Done!"); - RenderingEngine::draw_load_screen(text, guienv, m_tsrc, 0, 100); + m_rendering_engine->draw_load_screen(text, guienv, m_tsrc, 0, 100); infostream<<"Client::afterContentReceived() done"<get_video_driver(); irr::video::IImage* const raw_image = driver->createScreenShot(); if (!raw_image) -- 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/client/client.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 de85bc9227ef0db01854fa0eef89256646b4d578 Mon Sep 17 00:00:00 2001 From: Loic Blot Date: Mon, 3 May 2021 10:27:00 +0200 Subject: fix: some code tidy about includes & irr namespaces --- src/client/client.cpp | 2 +- src/client/client.h | 2 +- src/client/clientobject.h | 6 +-- src/client/clouds.cpp | 2 +- src/client/clouds.h | 3 +- src/client/content_cao.cpp | 14 +++--- src/client/content_cao.h | 2 +- src/client/content_mapblock.cpp | 2 +- src/client/content_mapblock.h | 2 +- src/client/game.cpp | 78 ++++++++++++++--------------- src/client/renderingengine.cpp | 2 +- src/client/renderingengine.h | 5 +- src/script/common/c_content.h | 2 + src/unittest/test_clientactiveobjectmgr.cpp | 2 +- 14 files changed, 59 insertions(+), 65 deletions(-) (limited to 'src/client/client.cpp') diff --git a/src/client/client.cpp b/src/client/client.cpp index c7aae1644..c0da27e44 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -1475,7 +1475,7 @@ bool Client::updateWieldedItem() return true; } -irr::scene::ISceneManager* Client::getSceneManager() +scene::ISceneManager* Client::getSceneManager() { return m_rendering_engine->get_scene_manager(); } diff --git a/src/client/client.h b/src/client/client.h index b819d4301..c9a72b1b3 100644 --- a/src/client/client.h +++ b/src/client/client.h @@ -356,7 +356,7 @@ public: void setCamera(Camera* camera) { m_camera = camera; } Camera* getCamera () { return m_camera; } - irr::scene::ISceneManager *getSceneManager(); + scene::ISceneManager *getSceneManager(); bool shouldShowMinimap() const; diff --git a/src/client/clientobject.h b/src/client/clientobject.h index dbc2f22cf..b192f0dcd 100644 --- a/src/client/clientobject.h +++ b/src/client/clientobject.h @@ -33,17 +33,13 @@ class LocalPlayer; struct ItemStack; class WieldMeshSceneNode; -namespace irr { namespace scene { - class ISceneManager; -}} - class ClientActiveObject : public ActiveObject { public: ClientActiveObject(u16 id, Client *client, ClientEnvironment *env); virtual ~ClientActiveObject(); - virtual void addToScene(ITextureSource *tsrc, irr::scene::ISceneManager *smgr) = 0; + virtual void addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr) = 0; virtual void removeFromScene(bool permanent) {} virtual void updateLight(u32 day_night_ratio) {} diff --git a/src/client/clouds.cpp b/src/client/clouds.cpp index 5a075aaf0..5008047af 100644 --- a/src/client/clouds.cpp +++ b/src/client/clouds.cpp @@ -30,7 +30,7 @@ with this program; if not, write to the Free Software Foundation, Inc., // Menu clouds are created later class Clouds; Clouds *g_menuclouds = NULL; -irr::scene::ISceneManager *g_menucloudsmgr = NULL; +scene::ISceneManager *g_menucloudsmgr = NULL; // Constant for now static constexpr const float cloud_size = BS * 64.0f; diff --git a/src/client/clouds.h b/src/client/clouds.h index a4d810faa..c009a05b7 100644 --- a/src/client/clouds.h +++ b/src/client/clouds.h @@ -29,8 +29,7 @@ class Clouds; extern Clouds *g_menuclouds; // Scene manager used for menu clouds -namespace irr{namespace scene{class ISceneManager;}} -extern irr::scene::ISceneManager *g_menucloudsmgr; +extern scene::ISceneManager *g_menucloudsmgr; class Clouds : public scene::ISceneNode { diff --git a/src/client/content_cao.cpp b/src/client/content_cao.cpp index a2fbbf001..6c7559364 100644 --- a/src/client/content_cao.cpp +++ b/src/client/content_cao.cpp @@ -188,7 +188,7 @@ public: static ClientActiveObject* create(Client *client, ClientEnvironment *env); - void addToScene(ITextureSource *tsrc, irr::scene::ISceneManager *smgr); + void addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr); void removeFromScene(bool permanent); void updateLight(u32 day_night_ratio); void updateNodePos(); @@ -219,7 +219,7 @@ ClientActiveObject* TestCAO::create(Client *client, ClientEnvironment *env) return new TestCAO(client, env); } -void TestCAO::addToScene(ITextureSource *tsrc, irr::scene::ISceneManager *smgr) +void TestCAO::addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr) { if(m_node != NULL) return; @@ -590,7 +590,7 @@ void GenericCAO::removeFromScene(bool permanent) m_client->getMinimap()->removeMarker(&m_marker); } -void GenericCAO::addToScene(ITextureSource *tsrc, irr::scene::ISceneManager *smgr) +void GenericCAO::addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr) { m_smgr = smgr; @@ -1484,10 +1484,10 @@ void GenericCAO::updateBonePosition() if (m_bone_position.empty() || !m_animated_meshnode) return; - m_animated_meshnode->setJointMode(irr::scene::EJUOR_CONTROL); // To write positions to the mesh on render + m_animated_meshnode->setJointMode(scene::EJUOR_CONTROL); // To write positions to the mesh on render for (auto &it : m_bone_position) { std::string bone_name = it.first; - irr::scene::IBoneSceneNode* bone = m_animated_meshnode->getJointNode(bone_name.c_str()); + scene::IBoneSceneNode* bone = m_animated_meshnode->getJointNode(bone_name.c_str()); if (bone) { bone->setPosition(it.second.X); bone->setRotation(it.second.Y); @@ -1496,7 +1496,7 @@ void GenericCAO::updateBonePosition() // search through bones to find mistakenly rotated bones due to bug in Irrlicht for (u32 i = 0; i < m_animated_meshnode->getJointCount(); ++i) { - irr::scene::IBoneSceneNode *bone = m_animated_meshnode->getJointNode(i); + scene::IBoneSceneNode *bone = m_animated_meshnode->getJointNode(i); if (!bone) continue; @@ -1924,7 +1924,7 @@ void GenericCAO::updateMeshCulling() return; } - irr::scene::ISceneNode *node = getSceneNode(); + scene::ISceneNode *node = getSceneNode(); if (!node) return; diff --git a/src/client/content_cao.h b/src/client/content_cao.h index 32ec9c1c3..4bbba9134 100644 --- a/src/client/content_cao.h +++ b/src/client/content_cao.h @@ -236,7 +236,7 @@ public: void removeFromScene(bool permanent); - void addToScene(ITextureSource *tsrc, irr::scene::ISceneManager *smgr); + void addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr); inline void expireVisuals() { diff --git a/src/client/content_mapblock.cpp b/src/client/content_mapblock.cpp index e530f3d7f..810c57138 100644 --- a/src/client/content_mapblock.cpp +++ b/src/client/content_mapblock.cpp @@ -61,7 +61,7 @@ static constexpr u16 quad_indices[] = {0, 1, 2, 2, 3, 0}; const std::string MapblockMeshGenerator::raillike_groupname = "connect_to_raillike"; MapblockMeshGenerator::MapblockMeshGenerator(MeshMakeData *input, MeshCollector *output, - irr::scene::IMeshManipulator *mm): + scene::IMeshManipulator *mm): data(input), collector(output), nodedef(data->m_client->ndef()), diff --git a/src/client/content_mapblock.h b/src/client/content_mapblock.h index cbee49021..237cc7847 100644 --- a/src/client/content_mapblock.h +++ b/src/client/content_mapblock.h @@ -173,7 +173,7 @@ public: public: MapblockMeshGenerator(MeshMakeData *input, MeshCollector *output, - irr::scene::IMeshManipulator *mm); + scene::IMeshManipulator *mm); void generate(); void renderSingle(content_t node, u8 param2 = 0x00); }; diff --git a/src/client/game.cpp b/src/client/game.cpp index 2f0f50505..eb1dbb5a3 100644 --- a/src/client/game.cpp +++ b/src/client/game.cpp @@ -839,7 +839,7 @@ private: MapDrawControl *draw_control = nullptr; Camera *camera = nullptr; Clouds *clouds = nullptr; // Free using ->Drop() - Sky *m_sky = nullptr; // Free using ->Drop() + Sky *sky = nullptr; // Free using ->Drop() Hud *hud = nullptr; Minimap *mapper = nullptr; @@ -1159,8 +1159,8 @@ void Game::shutdown() if (gui_chat_console) gui_chat_console->drop(); - if (m_sky) - m_sky->drop(); + if (sky) + sky->drop(); /* cleanup menus */ while (g_menumgr.menuCount() > 0) { @@ -1346,8 +1346,8 @@ bool Game::createClient(const GameStartData &start_data) /* Skybox */ - m_sky = new Sky(-1, m_rendering_engine, texture_src, shader_src); - scsf->setSky(m_sky); + sky = new Sky(-1, m_rendering_engine, texture_src, shader_src); + scsf->setSky(sky); skybox = NULL; // This is used/set later on in the main run loop /* Pre-calculated values @@ -2754,23 +2754,23 @@ void Game::handleClientEvent_HudChange(ClientEvent *event, CameraOrientation *ca void Game::handleClientEvent_SetSky(ClientEvent *event, CameraOrientation *cam) { - m_sky->setVisible(false); + sky->setVisible(false); // Whether clouds are visible in front of a custom skybox. - m_sky->setCloudsEnabled(event->set_sky->clouds); + sky->setCloudsEnabled(event->set_sky->clouds); if (skybox) { skybox->remove(); skybox = NULL; } // Clear the old textures out in case we switch rendering type. - m_sky->clearSkyboxTextures(); + sky->clearSkyboxTextures(); // Handle according to type if (event->set_sky->type == "regular") { // Shows the mesh skybox - m_sky->setVisible(true); + sky->setVisible(true); // Update mesh based skybox colours if applicable. - m_sky->setSkyColors(event->set_sky->sky_color); - m_sky->setHorizonTint( + sky->setSkyColors(event->set_sky->sky_color); + sky->setHorizonTint( event->set_sky->fog_sun_tint, event->set_sky->fog_moon_tint, event->set_sky->fog_tint_type @@ -2778,27 +2778,27 @@ void Game::handleClientEvent_SetSky(ClientEvent *event, CameraOrientation *cam) } else if (event->set_sky->type == "skybox" && event->set_sky->textures.size() == 6) { // Disable the dyanmic mesh skybox: - m_sky->setVisible(false); + sky->setVisible(false); // Set fog colors: - m_sky->setFallbackBgColor(event->set_sky->bgcolor); + sky->setFallbackBgColor(event->set_sky->bgcolor); // Set sunrise and sunset fog tinting: - m_sky->setHorizonTint( + sky->setHorizonTint( event->set_sky->fog_sun_tint, event->set_sky->fog_moon_tint, event->set_sky->fog_tint_type ); // Add textures to skybox. for (int i = 0; i < 6; i++) - m_sky->addTextureToSkybox(event->set_sky->textures[i], i, texture_src); + sky->addTextureToSkybox(event->set_sky->textures[i], i, texture_src); } else { // Handle everything else as plain color. if (event->set_sky->type != "plain") infostream << "Unknown sky type: " << (event->set_sky->type) << std::endl; - m_sky->setVisible(false); - m_sky->setFallbackBgColor(event->set_sky->bgcolor); + sky->setVisible(false); + sky->setFallbackBgColor(event->set_sky->bgcolor); // Disable directional sun/moon tinting on plain or invalid skyboxes. - m_sky->setHorizonTint( + sky->setHorizonTint( event->set_sky->bgcolor, event->set_sky->bgcolor, "custom" @@ -2810,30 +2810,30 @@ void Game::handleClientEvent_SetSky(ClientEvent *event, CameraOrientation *cam) void Game::handleClientEvent_SetSun(ClientEvent *event, CameraOrientation *cam) { - m_sky->setSunVisible(event->sun_params->visible); - m_sky->setSunTexture(event->sun_params->texture, + sky->setSunVisible(event->sun_params->visible); + sky->setSunTexture(event->sun_params->texture, event->sun_params->tonemap, texture_src); - m_sky->setSunScale(event->sun_params->scale); - m_sky->setSunriseVisible(event->sun_params->sunrise_visible); - m_sky->setSunriseTexture(event->sun_params->sunrise, texture_src); + sky->setSunScale(event->sun_params->scale); + sky->setSunriseVisible(event->sun_params->sunrise_visible); + sky->setSunriseTexture(event->sun_params->sunrise, texture_src); delete event->sun_params; } void Game::handleClientEvent_SetMoon(ClientEvent *event, CameraOrientation *cam) { - m_sky->setMoonVisible(event->moon_params->visible); - m_sky->setMoonTexture(event->moon_params->texture, + sky->setMoonVisible(event->moon_params->visible); + sky->setMoonTexture(event->moon_params->texture, event->moon_params->tonemap, texture_src); - m_sky->setMoonScale(event->moon_params->scale); + sky->setMoonScale(event->moon_params->scale); delete event->moon_params; } void Game::handleClientEvent_SetStars(ClientEvent *event, CameraOrientation *cam) { - m_sky->setStarsVisible(event->star_params->visible); - m_sky->setStarCount(event->star_params->count, false); - m_sky->setStarColor(event->star_params->starcolor); - m_sky->setStarScale(event->star_params->scale); + sky->setStarsVisible(event->star_params->visible); + sky->setStarCount(event->star_params->count, false); + sky->setStarColor(event->star_params->starcolor); + sky->setStarScale(event->star_params->scale); delete event->star_params; } @@ -3710,7 +3710,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, direct_brightness = time_brightness; sunlight_seen = true; } else { - float old_brightness = m_sky->getBrightness(); + float old_brightness = sky->getBrightness(); direct_brightness = client->getEnv().getClientMap() .getBackgroundBrightness(MYMIN(runData.fog_range * 1.2, 60 * BS), daynight_ratio, (int)(old_brightness * 255.5), &sunlight_seen) @@ -3737,7 +3737,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, runData.time_of_day_smooth = time_of_day_smooth; - m_sky->update(time_of_day_smooth, time_brightness, direct_brightness, + sky->update(time_of_day_smooth, time_brightness, direct_brightness, sunlight_seen, camera->getCameraMode(), player->getYaw(), player->getPitch()); @@ -3745,7 +3745,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, Update clouds */ if (clouds) { - if (m_sky->getCloudsVisible()) { + if (sky->getCloudsVisible()) { clouds->setVisible(true); clouds->step(dtime); // camera->getPosition is not enough for 3rd person views @@ -3755,14 +3755,14 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, camera_node_position.Y = camera_node_position.Y + camera_offset.Y * BS; camera_node_position.Z = camera_node_position.Z + camera_offset.Z * BS; clouds->update(camera_node_position, - m_sky->getCloudColor()); + sky->getCloudColor()); if (clouds->isCameraInsideCloud() && m_cache_enable_fog) { // if inside clouds, and fog enabled, use that as sky // color(s) video::SColor clouds_dark = clouds->getColor() .getInterpolated(video::SColor(255, 0, 0, 0), 0.9); - m_sky->overrideColors(clouds_dark, clouds->getColor()); - m_sky->setInClouds(true); + sky->overrideColors(clouds_dark, clouds->getColor()); + sky->setInClouds(true); runData.fog_range = std::fmin(runData.fog_range * 0.5f, 32.0f * BS); // do not draw clouds after all clouds->setVisible(false); @@ -3783,7 +3783,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, if (m_cache_enable_fog) { driver->setFog( - m_sky->getBgColor(), + sky->getBgColor(), video::EFT_FOG_LINEAR, runData.fog_range * m_cache_fog_start, runData.fog_range * 1.0, @@ -3793,7 +3793,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, ); } else { driver->setFog( - m_sky->getBgColor(), + sky->getBgColor(), video::EFT_FOG_LINEAR, 100000 * BS, 110000 * BS, @@ -3873,7 +3873,7 @@ void Game::updateFrame(ProfilerGraph *graph, RunStats *stats, f32 dtime, /* Drawing begins */ - const video::SColor &skycolor = m_sky->getSkyColor(); + const video::SColor &skycolor = sky->getSkyColor(); TimeTaker tt_draw("Draw scene"); driver->beginScene(true, true, skycolor); diff --git a/src/client/renderingengine.cpp b/src/client/renderingengine.cpp index e74446aeb..4f96a6e37 100644 --- a/src/client/renderingengine.cpp +++ b/src/client/renderingengine.cpp @@ -225,7 +225,7 @@ bool RenderingEngine::print_video_modes() return videomode_list != NULL; } -void RenderingEngine::removeMesh(const irr::scene::IMesh* mesh) +void RenderingEngine::removeMesh(const scene::IMesh* mesh) { m_device->getSceneManager()->getMeshCache()->removeMesh(mesh); } diff --git a/src/client/renderingengine.h b/src/client/renderingengine.h index 1fd85f5ef..28ddc8652 100644 --- a/src/client/renderingengine.h +++ b/src/client/renderingengine.h @@ -26,9 +26,6 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "irrlichttypes_extrabloated.h" #include "debug.h" -namespace irr { namespace scene { -class IMesh; -}} class ITextureSource; class Camera; class Client; @@ -60,7 +57,7 @@ public: static bool print_video_modes(); void cleanupMeshCache(); - void removeMesh(const irr::scene::IMesh* mesh); + void removeMesh(const scene::IMesh* mesh); static v2u32 getWindowSize() { diff --git a/src/script/common/c_content.h b/src/script/common/c_content.h index f54490e3a..4dc614706 100644 --- a/src/script/common/c_content.h +++ b/src/script/common/c_content.h @@ -39,6 +39,8 @@ extern "C" { #include "itemgroup.h" #include "itemdef.h" #include "c_types.h" +// We do a explicit path include because by default c_content.h include src/client/hud.h +// prior to the src/hud.h, which is not good on server only build #include "../../hud.h" namespace Json { class Value; } diff --git a/src/unittest/test_clientactiveobjectmgr.cpp b/src/unittest/test_clientactiveobjectmgr.cpp index a43855c19..2d508cf32 100644 --- a/src/unittest/test_clientactiveobjectmgr.cpp +++ b/src/unittest/test_clientactiveobjectmgr.cpp @@ -29,7 +29,7 @@ public: TestClientActiveObject() : ClientActiveObject(0, nullptr, nullptr) {} ~TestClientActiveObject() = default; ActiveObjectType getType() const { return ACTIVEOBJECT_TYPE_TEST; } - virtual void addToScene(ITextureSource *tsrc, irr::scene::ISceneManager *smgr) {} + virtual void addToScene(ITextureSource *tsrc, scene::ISceneManager *smgr) {} }; class TestClientActiveObjectMgr : public TestBase -- 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/client/client.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