| 573 | } |
| 574 | |
| 575 | Ref<ResourceLoader::LoadToken> ResourceLoader::_load_start(const String &p_path, const String &p_type_hint, LoadThreadMode p_thread_mode, ResourceFormatLoader::CacheMode p_cache_mode, bool p_for_user) { |
| 576 | String local_path = _validate_local_path(p_path); |
| 577 | ERR_FAIL_COND_V(local_path.is_empty(), Ref<ResourceLoader::LoadToken>()); |
| 578 | |
| 579 | bool ignoring_cache = p_cache_mode == ResourceFormatLoader::CACHE_MODE_IGNORE || p_cache_mode == ResourceFormatLoader::CACHE_MODE_IGNORE_DEEP; |
| 580 | |
| 581 | Ref<LoadToken> load_token; |
| 582 | bool must_not_register = false; |
| 583 | ThreadLoadTask *load_task_ptr = nullptr; |
| 584 | { |
| 585 | MutexLock thread_load_lock(thread_load_mutex); |
| 586 | |
| 587 | if (p_for_user) { |
| 588 | LoadToken *existing_token = _load_threaded_request_reuse_user_token(p_path); |
| 589 | if (existing_token) { |
| 590 | return Ref<LoadToken>(existing_token); |
| 591 | } |
| 592 | } |
| 593 | |
| 594 | if (!ignoring_cache && thread_load_tasks.has(local_path)) { |
| 595 | load_token = Ref<LoadToken>(thread_load_tasks[local_path].load_token); |
| 596 | if (load_token.is_valid()) { |
| 597 | if (p_for_user) { |
| 598 | // Load task exists, with no user tokens at the moment. |
| 599 | // Let's "attach" to it. |
| 600 | _load_threaded_request_setup_user_token(load_token.ptr(), p_path); |
| 601 | } |
| 602 | return load_token; |
| 603 | } else { |
| 604 | // The token is dying (reached 0 on another thread). |
| 605 | // Ensure it's killed now so the path can be safely reused right away. |
| 606 | thread_load_tasks[local_path].load_token->clear(); |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | load_token.instantiate(); |
| 611 | load_token->local_path = local_path; |
| 612 | if (p_for_user) { |
| 613 | _load_threaded_request_setup_user_token(load_token.ptr(), p_path); |
| 614 | } |
| 615 | |
| 616 | //create load task |
| 617 | { |
| 618 | ThreadLoadTask load_task; |
| 619 | |
| 620 | load_task.load_token = load_token.ptr(); |
| 621 | load_task.local_path = local_path; |
| 622 | load_task.type_hint = p_type_hint; |
| 623 | load_task.cache_mode = p_cache_mode; |
| 624 | load_task.use_sub_threads = p_thread_mode == LOAD_THREAD_DISTRIBUTE; |
| 625 | if (p_cache_mode == ResourceFormatLoader::CACHE_MODE_REUSE) { |
| 626 | Ref<Resource> existing = ResourceCache::get_ref(local_path); |
| 627 | if (existing.is_valid()) { |
| 628 | //referencing is fine |
| 629 | load_task.resource = existing; |
| 630 | load_task.status = THREAD_LOAD_LOADED; |
| 631 | load_task.progress = 1.0; |
| 632 | DEV_ASSERT(!thread_load_tasks.has(local_path)); |
nothing calls this directly
no test coverage detected