Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assign temporary path to preloaded resources #80281

Merged
merged 1 commit into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/io/resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ String Resource::get_path() const {
return path_cache;
}

void Resource::set_path_cache(const String &p_path) {
path_cache = p_path;
}

String Resource::generate_scene_unique_id() {
// Generate a unique enough hash, but still user-readable.
// If it's not unique it does not matter because the saver will try again.
Expand Down
1 change: 1 addition & 0 deletions core/io/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class Resource : public RefCounted {

virtual void set_path(const String &p_path, bool p_take_over = false);
String get_path() const;
void set_path_cache(const String &p_path); // Set raw path without involving resource cache.
_FORCE_INLINE_ bool is_built_in() const { return path_cache.is_empty() || path_cache.contains("::") || path_cache.begins_with("local://"); }

static String generate_scene_unique_id();
Expand Down
2 changes: 2 additions & 0 deletions core/io/resource_format_binary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,8 @@ Error ResourceLoaderBinary::load() {
res = Ref<Resource>(r);
if (!path.is_empty() && cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE) {
r->set_path(path, cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE); //if got here because the resource with same path has different type, replace it
} else if (!path.is_resource_file()) {
r->set_path_cache(path);
}
r->set_scene_unique_id(id);
}
Expand Down
2 changes: 2 additions & 0 deletions core/io/resource_loader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,8 @@ void ResourceLoader::_thread_load_function(void *p_userdata) {
if (load_task.resource.is_valid()) {
if (load_task.cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE) {
load_task.resource->set_path(load_task.local_path);
} else if (!load_task.local_path.is_resource_file()) {
load_task.resource->set_path_cache(load_task.local_path);
}

if (load_task.xl_remapped) {
Expand Down
5 changes: 5 additions & 0 deletions modules/gdscript/gdscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -992,6 +992,7 @@ void GDScript::set_path(const String &p_path, bool p_take_over) {

String old_path = path;
path = p_path;
path_valid = true;
GDScriptCache::move_script(old_path, p_path);

for (KeyValue<StringName, Ref<GDScript>> &kv : subclasses) {
Expand All @@ -1000,6 +1001,9 @@ void GDScript::set_path(const String &p_path, bool p_take_over) {
}

String GDScript::get_script_path() const {
if (!path_valid && !get_path().is_empty()) {
return get_path();
}
return path;
}

Expand Down Expand Up @@ -1035,6 +1039,7 @@ Error GDScript::load_source_code(const String &p_path) {

source = s;
path = p_path;
path_valid = true;
#ifdef TOOLS_ENABLED
source_changed_cache = true;
set_edited(false);
Expand Down
1 change: 1 addition & 0 deletions modules/gdscript/gdscript.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ class GDScript : public Script {
//exported members
String source;
String path;
bool path_valid = false; // False if using default path.
StringName local_name; // Inner class identifier or `class_name`.
StringName global_name; // `class_name`.
String fully_qualified_name;
Expand Down
2 changes: 2 additions & 0 deletions scene/resources/resource_format_text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,8 @@ Error ResourceLoaderText::load() {
if (do_assign) {
if (cache_mode != ResourceFormatLoader::CACHE_MODE_IGNORE) {
res->set_path(path, cache_mode == ResourceFormatLoader::CACHE_MODE_REPLACE);
} else if (!path.is_resource_file()) {
res->set_path_cache(path);
}
res->set_scene_unique_id(id);
}
Expand Down
Loading