diff --git a/lib/graphics_engine/src/ge_vulkan_texture.cpp b/lib/graphics_engine/src/ge_vulkan_texture.cpp index 611a24171..0d52c4f73 100644 --- a/lib/graphics_engine/src/ge_vulkan_texture.cpp +++ b/lib/graphics_engine/src/ge_vulkan_texture.cpp @@ -48,9 +48,11 @@ GEVulkanTexture::GEVulkanTexture(const std::string& path, } auto& paths = getGEConfig()->m_ondemand_load_texture_paths; - m_ondemand_load = (paths.find(m_full_path.c_str()) != paths.end()); + auto path_itr = paths.find(m_full_path.c_str()); + m_ondemand_load = (path_itr != paths.end()); if (m_ondemand_load) { + paths.erase(path_itr); video::IImageLoader* loader = NULL; io::IReadFile* file = io::createReadFile(m_full_path); getDriver()->createImageFromFile(file, &loader); diff --git a/src/graphics/irr_driver.cpp b/src/graphics/irr_driver.cpp index 7020af5f3..cf95fb38e 100644 --- a/src/graphics/irr_driver.cpp +++ b/src/graphics/irr_driver.cpp @@ -1173,6 +1173,7 @@ void IrrDriver::applyResolutionSettings(bool recreate_device) GUIEngine::addLoadingIcon(irr_driver->getTexture(banana) ); // No need to reload cached track data (track_manager->cleanAllCachedData // above) - this happens dynamically when the tracks are loaded. + track_manager->updateScreenshotCache(); GUIEngine::reshowCurrentScreen(); MessageQueue::updatePosition(); // Preload the explosion effects (explode.png) diff --git a/src/karts/kart_properties.cpp b/src/karts/kart_properties.cpp index bc65d6343..d7c1a68eb 100644 --- a/src/karts/kart_properties.cpp +++ b/src/karts/kart_properties.cpp @@ -129,18 +129,6 @@ KartProperties::~KartProperties() ShaderFilesManager::getInstance()->removeUnusedShaderFiles(); SP::SPTextureManager::get()->removeUnusedTextures(); } - - if (GE::getDriver()->getDriverType() != video::EDT_VULKAN) - return; - auto& paths = GE::getGEConfig()->m_ondemand_load_texture_paths; - auto it = paths.begin(); - while (it != paths.end()) - { - if (StringUtils::startsWith(*it, m_root_absolute_path)) - it = paths.erase(it); - else - it++; - } } #endif } // ~KartProperties @@ -383,6 +371,10 @@ void KartProperties::load(const std::string &filename, const std::string &node) file_manager->popTextureSearchPath(); file_manager->popModelSearchPath(); +#ifndef SERVER_ONLY + if (GE::getDriver()->getDriverType() == video::EDT_VULKAN) + GE::getGEConfig()->m_ondemand_load_texture_paths.clear(); +#endif } // load // ---------------------------------------------------------------------------- diff --git a/src/tracks/track.cpp b/src/tracks/track.cpp index 5dab4e5f3..750f278dc 100644 --- a/src/tracks/track.cpp +++ b/src/tracks/track.cpp @@ -194,11 +194,6 @@ Track::Track(const std::string &filename) /** Destructor, removes quad data structures etc. */ Track::~Track() { -#ifndef SERVER_ONLY - if (GE::getDriver()->getDriverType() == video::EDT_VULKAN) - GE::getGEConfig()->m_ondemand_load_texture_paths.erase(m_screenshot); -#endif - // Note that the music information in m_music is globally managed // by the music_manager, and is freed there. So no need to free it // here (esp. since various track might share the same music). @@ -432,13 +427,6 @@ void Track::cleanup() for(unsigned int i=0; igetDriverType() == video::EDT_VULKAN) - { - std::string fullpath = tex->getFullPath().c_str(); - GE::getGEConfig()->m_ondemand_load_texture_paths.erase(fullpath); - } -#endif tex->drop(); if (tex->getReferenceCount() == 1) irr_driver->removeTexture(tex); @@ -631,17 +619,7 @@ void Track::loadTrackInfo() // Set the correct paths if (m_screenshot.length() > 0) - { m_screenshot = m_root+m_screenshot; -#ifndef SERVER_ONLY - if (GE::getDriver()->getDriverType() == video::EDT_VULKAN) - { - m_screenshot = file_manager->getFileSystem() - ->getAbsolutePath(m_screenshot.c_str()).c_str(); - GE::getGEConfig()->m_ondemand_load_texture_paths.insert(m_screenshot); - } -#endif - } delete root; std::string dir = StringUtils::getPath(m_filename); diff --git a/src/tracks/track_manager.cpp b/src/tracks/track_manager.cpp index 4b81f1fd8..aae7cd80d 100644 --- a/src/tracks/track_manager.cpp +++ b/src/tracks/track_manager.cpp @@ -29,9 +29,14 @@ #include #include +#include #include #include +#ifndef SERVER_ONLY +#include +#endif + TrackManager* track_manager = 0; std::vector TrackManager::m_track_search_path; @@ -178,6 +183,7 @@ void TrackManager::loadTrackList() loadTrack(dir+*subdir+"/"); } // for dir in dirs } // for i isInternal()) - irr_driver->getTexture(track->getScreenshotFile()); - return true; } // loadTrack @@ -361,3 +361,25 @@ void TrackManager::onDemandLoadTrackScreenshots() screenshot->getTextureHandler(); } } // onDemandLoadTrackScreenshots + +// ---------------------------------------------------------------------------- +void TrackManager::updateScreenshotCache() +{ + for (unsigned i = 0; i < m_tracks.size(); i++) + { + // Populate the texture cache with track screenshots + // (internal tracks like end cutscene don't have screenshots) + Track* t = m_tracks[i]; + if (t->isInternal() || t->getScreenshotFile().empty()) + continue; + std::string full_path = file_manager->getFileSystem() + ->getAbsolutePath(t->getScreenshotFile().c_str()).c_str(); + if (!file_manager->fileExists(full_path)) + continue; +#ifndef SERVER_ONLY + if (GE::getDriver()->getDriverType() == video::EDT_VULKAN) + GE::getGEConfig()->m_ondemand_load_texture_paths.insert(full_path); +#endif + irr_driver->getTexture(t->getScreenshotFile()); + } +} // updateScreenshotCache diff --git a/src/tracks/track_manager.hpp b/src/tracks/track_manager.hpp index 524907e39..2328b0baa 100644 --- a/src/tracks/track_manager.hpp +++ b/src/tracks/track_manager.hpp @@ -138,7 +138,8 @@ public: } // getArenasInGroup // ------------------------------------------------------------------------ void onDemandLoadTrackScreenshots(); - + // ------------------------------------------------------------------------ + void updateScreenshotCache(); }; // TrackManager extern TrackManager* track_manager;