|
47 | 47 | #include <stdexcept> |
48 | 48 | #include <string> |
49 | 49 |
|
| 50 | +#ifndef SERVER_ONLY |
| 51 | +#include <ge_main.hpp> |
| 52 | +#endif |
50 | 53 |
|
51 | 54 | float KartProperties::UNDEFINED = -99.9f; |
52 | 55 |
|
@@ -116,12 +119,27 @@ KartProperties::KartProperties(const std::string &filename) |
116 | 119 | KartProperties::~KartProperties() |
117 | 120 | { |
118 | 121 | #ifndef SERVER_ONLY |
119 | | - if (CVS->isGLSL() && m_kart_model.use_count() == 1) |
| 122 | + if (m_kart_model.use_count() == 1) |
120 | 123 | { |
121 | | - m_kart_model = nullptr; |
122 | | - SP::SPShaderManager::get()->removeUnusedShaders(); |
123 | | - ShaderFilesManager::getInstance()->removeUnusedShaderFiles(); |
124 | | - SP::SPTextureManager::get()->removeUnusedTextures(); |
| 124 | + if (CVS->isGLSL()) |
| 125 | + { |
| 126 | + m_kart_model = nullptr; |
| 127 | + SP::SPShaderManager::get()->removeUnusedShaders(); |
| 128 | + ShaderFilesManager::getInstance()->removeUnusedShaderFiles(); |
| 129 | + SP::SPTextureManager::get()->removeUnusedTextures(); |
| 130 | + } |
| 131 | + |
| 132 | + if (GE::getDriver()->getDriverType() != video::EDT_VULKAN) |
| 133 | + return; |
| 134 | + auto& paths = GE::getGEConfig()->m_ondemand_load_texture_paths; |
| 135 | + auto it = paths.begin(); |
| 136 | + while (it != paths.end()) |
| 137 | + { |
| 138 | + if (StringUtils::startsWith(*it, m_root_absolute_path)) |
| 139 | + it = paths.erase(it); |
| 140 | + else |
| 141 | + it++; |
| 142 | + } |
125 | 143 | } |
126 | 144 | #endif |
127 | 145 | } // ~KartProperties |
@@ -176,6 +194,33 @@ void KartProperties::copyFrom(const KartProperties *source) |
176 | 194 | } |
177 | 195 | } // copyFrom |
178 | 196 |
|
| 197 | +//----------------------------------------------------------------------------- |
| 198 | +void KartProperties::handleOnDemandLoadTexture() |
| 199 | +{ |
| 200 | +#ifndef SERVER_ONLY |
| 201 | + if (GE::getDriver()->getDriverType() != video::EDT_VULKAN) |
| 202 | + return; |
| 203 | + std::set<std::string> files; |
| 204 | + // Remove the last / |
| 205 | + m_root_absolute_path = StringUtils::getPath(m_root); |
| 206 | + m_root_absolute_path = file_manager->getFileSystem() |
| 207 | + ->getAbsolutePath(m_root_absolute_path.c_str()).c_str(); |
| 208 | + |
| 209 | + file_manager->listFiles(files, m_root_absolute_path, |
| 210 | + true/*make_full_path*/); |
| 211 | + std::set<std::string> image_extensions = |
| 212 | + { |
| 213 | + "png", "jpg", "jpeg", "jpe", "svg" |
| 214 | + }; |
| 215 | + for (const std::string& f : files) |
| 216 | + { |
| 217 | + if (image_extensions.find(StringUtils::getExtension(f)) != |
| 218 | + image_extensions.end()) |
| 219 | + GE::getGEConfig()->m_ondemand_load_texture_paths.insert(f); |
| 220 | + } |
| 221 | +#endif |
| 222 | +} // handleOnDemandLoadTexture |
| 223 | + |
179 | 224 | //----------------------------------------------------------------------------- |
180 | 225 | /** Loads the kart properties from a file. |
181 | 226 | * \param filename Filename to load. |
@@ -220,6 +265,7 @@ void KartProperties::load(const std::string &filename, const std::string &node) |
220 | 265 | m_is_addon = true; |
221 | 266 | } |
222 | 267 |
|
| 268 | + handleOnDemandLoadTexture(); |
223 | 269 | try |
224 | 270 | { |
225 | 271 | if(!root || root->getName()!="kart") |
|
0 commit comments