Clean m_ondemand_load_texture_paths after texture loaded

This commit is contained in:
Benau 2023-03-04 10:26:31 +08:00
parent dcc7397668
commit 5e161f663d
6 changed files with 38 additions and 42 deletions

View File

@ -48,9 +48,11 @@ GEVulkanTexture::GEVulkanTexture(const std::string& path,
} }
auto& paths = getGEConfig()->m_ondemand_load_texture_paths; 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) if (m_ondemand_load)
{ {
paths.erase(path_itr);
video::IImageLoader* loader = NULL; video::IImageLoader* loader = NULL;
io::IReadFile* file = io::createReadFile(m_full_path); io::IReadFile* file = io::createReadFile(m_full_path);
getDriver()->createImageFromFile(file, &loader); getDriver()->createImageFromFile(file, &loader);

View File

@ -1173,6 +1173,7 @@ void IrrDriver::applyResolutionSettings(bool recreate_device)
GUIEngine::addLoadingIcon(irr_driver->getTexture(banana) ); GUIEngine::addLoadingIcon(irr_driver->getTexture(banana) );
// No need to reload cached track data (track_manager->cleanAllCachedData // No need to reload cached track data (track_manager->cleanAllCachedData
// above) - this happens dynamically when the tracks are loaded. // above) - this happens dynamically when the tracks are loaded.
track_manager->updateScreenshotCache();
GUIEngine::reshowCurrentScreen(); GUIEngine::reshowCurrentScreen();
MessageQueue::updatePosition(); MessageQueue::updatePosition();
// Preload the explosion effects (explode.png) // Preload the explosion effects (explode.png)

View File

@ -129,18 +129,6 @@ KartProperties::~KartProperties()
ShaderFilesManager::getInstance()->removeUnusedShaderFiles(); ShaderFilesManager::getInstance()->removeUnusedShaderFiles();
SP::SPTextureManager::get()->removeUnusedTextures(); 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 #endif
} // ~KartProperties } // ~KartProperties
@ -383,6 +371,10 @@ void KartProperties::load(const std::string &filename, const std::string &node)
file_manager->popTextureSearchPath(); file_manager->popTextureSearchPath();
file_manager->popModelSearchPath(); file_manager->popModelSearchPath();
#ifndef SERVER_ONLY
if (GE::getDriver()->getDriverType() == video::EDT_VULKAN)
GE::getGEConfig()->m_ondemand_load_texture_paths.clear();
#endif
} // load } // load
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------

View File

@ -194,11 +194,6 @@ Track::Track(const std::string &filename)
/** Destructor, removes quad data structures etc. */ /** Destructor, removes quad data structures etc. */
Track::~Track() 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 // 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 // by the music_manager, and is freed there. So no need to free it
// here (esp. since various track might share the same music). // here (esp. since various track might share the same music).
@ -432,13 +427,6 @@ void Track::cleanup()
for(unsigned int i=0; i<m_sky_textures.size(); i++) for(unsigned int i=0; i<m_sky_textures.size(); i++)
{ {
video::ITexture* tex = (video::ITexture*)m_sky_textures[i]; video::ITexture* tex = (video::ITexture*)m_sky_textures[i];
#ifndef SERVER_ONLY
if (GE::getDriver()->getDriverType() == video::EDT_VULKAN)
{
std::string fullpath = tex->getFullPath().c_str();
GE::getGEConfig()->m_ondemand_load_texture_paths.erase(fullpath);
}
#endif
tex->drop(); tex->drop();
if (tex->getReferenceCount() == 1) if (tex->getReferenceCount() == 1)
irr_driver->removeTexture(tex); irr_driver->removeTexture(tex);
@ -631,17 +619,7 @@ void Track::loadTrackInfo()
// Set the correct paths // Set the correct paths
if (m_screenshot.length() > 0) if (m_screenshot.length() > 0)
{
m_screenshot = m_root+m_screenshot; 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; delete root;
std::string dir = StringUtils::getPath(m_filename); std::string dir = StringUtils::getPath(m_filename);

View File

@ -29,9 +29,14 @@
#include <stdexcept> #include <stdexcept>
#include <stdio.h> #include <stdio.h>
#include <IFileSystem.h>
#include <ITexture.h> #include <ITexture.h>
#include <IVideoDriver.h> #include <IVideoDriver.h>
#ifndef SERVER_ONLY
#include <ge_main.hpp>
#endif
TrackManager* track_manager = 0; TrackManager* track_manager = 0;
std::vector<std::string> TrackManager::m_track_search_path; std::vector<std::string> TrackManager::m_track_search_path;
@ -178,6 +183,7 @@ void TrackManager::loadTrackList()
loadTrack(dir+*subdir+"/"); loadTrack(dir+*subdir+"/");
} // for dir in dirs } // for dir in dirs
} // for i <m_track_search_path.size() } // for i <m_track_search_path.size()
updateScreenshotCache();
onDemandLoadTrackScreenshots(); onDemandLoadTrackScreenshots();
} // loadTrackList } // loadTrackList
@ -221,12 +227,6 @@ bool TrackManager::loadTrack(const std::string& dirname)
m_tracks.push_back(track); m_tracks.push_back(track);
m_track_avail.push_back(true); m_track_avail.push_back(true);
updateGroups(track); updateGroups(track);
// Populate the texture cache with track screenshots
// (internal tracks like end cutscene don't have screenshots)
if (!track->isInternal())
irr_driver->getTexture(track->getScreenshotFile());
return true; return true;
} // loadTrack } // loadTrack
@ -361,3 +361,25 @@ void TrackManager::onDemandLoadTrackScreenshots()
screenshot->getTextureHandler(); screenshot->getTextureHandler();
} }
} // onDemandLoadTrackScreenshots } // 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

View File

@ -138,7 +138,8 @@ public:
} // getArenasInGroup } // getArenasInGroup
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
void onDemandLoadTrackScreenshots(); void onDemandLoadTrackScreenshots();
// ------------------------------------------------------------------------
void updateScreenshotCache();
}; // TrackManager }; // TrackManager
extern TrackManager* track_manager; extern TrackManager* track_manager;