MCPcopy Create free account
hub / github.com/GDRETools/gdsdecomp / custom_load

Method custom_load

compat/resource_loader_compat.cpp:228–272  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

226
227thread_local HashSet<String> currently_loading_paths;
228Ref<Resource> ResourceCompatLoader::custom_load(const String &p_path, const String &p_type_hint, ResourceInfo::LoadType p_type, Error *r_error, bool use_threads, ResourceFormatLoader::CacheMode p_cache_mode) {
229 String local_path = _validate_local_path(p_path);
230 String res_path = GDRESettings::get_singleton()->get_mapped_path(p_path);
231 bool is_real_load = p_type == ResourceInfo::LoadType::REAL_LOAD || p_type == ResourceInfo::LoadType::GLTF_LOAD;
232 if (p_cache_mode == ResourceFormatLoader::CACHE_MODE_REUSE) {
233 auto res = ResourceCache::get_ref(local_path);
234 if (res.is_valid()) {
235 return res;
236 }
237 }
238 ERR_FAIL_COND_V_MSG(currently_loading_paths.has(res_path), Ref<Resource>(), "Circular dependency detected: " + local_path);
239
240 auto loader = get_loader_for_path(res_path, p_type_hint);
241 if (loader.is_null() && is_real_load) {
242 currently_loading_paths.insert(res_path);
243 Ref<Resource> res = load_with_real_resource_loader(local_path, p_type_hint, r_error, use_threads, p_cache_mode);
244 currently_loading_paths.erase(res_path);
245 if (res.is_valid() && res->get_path() != local_path) {
246 if (is_real_load && p_cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE_DEEP && p_cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE) {
247 res->set_path(local_path, p_cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE || p_cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE_DEEP);
248 } else {
249 res->set_path_cache(local_path);
250 }
251 }
252 return res;
253 }
254 FAIL_LOADER_NOT_FOUND(loader);
255
256 if (!is_real_load) {
257 local_path = "";
258 }
259 currently_loading_paths.insert(res_path);
260 Ref<Resource> res = loader->custom_load(res_path, local_path, p_type, r_error, use_threads, p_cache_mode);
261 currently_loading_paths.erase(res_path);
262 if (res.is_valid()) {
263 if (res->get_path().is_empty()) {
264 if (is_real_load && p_cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE_DEEP && p_cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE) {
265 res->set_path(local_path, p_cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE || p_cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE_DEEP);
266 } else {
267 res->set_path_cache(local_path);
268 }
269 }
270 }
271 return res;
272}
273
274Ref<Resource> ResourceCompatLoader::load_with_real_resource_loader(const String &p_path, const String &p_type_hint, Error *r_error, bool use_threads, ResourceFormatLoader::CacheMode p_cache_mode) {
275 String local_path = _validate_local_path(p_path);

Callers 4

fake_loadMethod · 0.45
non_global_loadMethod · 0.45
to_binaryMethod · 0.45

Calls 8

_validate_local_pathFunction · 0.85
get_refFunction · 0.85
get_mapped_pathMethod · 0.80
set_pathMethod · 0.80
is_validMethod · 0.45
insertMethod · 0.45
eraseMethod · 0.45
get_pathMethod · 0.45

Tested by

no test coverage detected