You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-12-02 16:48:55 +00:00
Show a warning toast when saving a large text-based scene
Text-based scenes that contain large amounts of binary data are slower to save and load. Their binary resources should be moved to separate files, or the binary `.scn` format should be used instead.
This commit is contained in:
@@ -206,6 +206,8 @@ static const String EDITOR_NODE_CONFIG_SECTION = "EditorNode";
|
||||
static const String REMOVE_ANDROID_BUILD_TEMPLATE_MESSAGE = TTRC("The Android build template is already installed in this project and it won't be overwritten.\nRemove the \"%s\" directory manually before attempting this operation again.");
|
||||
static const String INSTALL_ANDROID_BUILD_TEMPLATE_MESSAGE = TTRC("This will set up your project for gradle Android builds by installing the source template to \"%s\".\nNote that in order to make gradle builds instead of using pre-built APKs, the \"Use Gradle Build\" option should be enabled in the Android export preset.");
|
||||
|
||||
constexpr int LARGE_RESOURCE_WARNING_SIZE_THRESHOLD = 512'000; // 500 KB
|
||||
|
||||
bool EditorProgress::step(const String &p_state, int p_step, bool p_force_refresh) {
|
||||
if (!force_background && Thread::is_main_thread()) {
|
||||
return EditorNode::progress_task_step(task, p_state, p_step, p_force_refresh);
|
||||
@@ -1657,6 +1659,18 @@ void EditorNode::save_resource_in_path(const Ref<Resource> &p_resource, const St
|
||||
clear_node_reference(p_resource); // // Check if Resource is saved to disk to potentially remove it from resource_count
|
||||
emit_signal(SNAME("resource_saved"), p_resource);
|
||||
editor_data.notify_resource_saved(p_resource);
|
||||
|
||||
if (EDITOR_GET("filesystem/on_save/warn_on_saving_large_text_resources")) {
|
||||
if (p_path.ends_with(".tres")) {
|
||||
const int64_t file_size = FileAccess::get_size(p_path);
|
||||
if (file_size >= LARGE_RESOURCE_WARNING_SIZE_THRESHOLD) {
|
||||
// File is larger than 500 KiB, likely because it contains binary data serialized as Base64.
|
||||
// This is slow to save and load, so warn the user.
|
||||
EditorToaster::get_singleton()->popup_str(
|
||||
vformat(TTR("The text-based resource at path \"%s\" is large on disk (%s), likely because it has embedded binary data.\nThis slows down resource saving and loading.\nConsider saving its binary subresource(s) to a binary `.res` file or saving the resource as a binary `.res` file.\nThis warning can be disabled in the Editor Settings (FileSystem > On Save > Warn on Saving Large Text Resources)."), p_path, String::humanize_size(file_size)), EditorToaster::SEVERITY_WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void EditorNode::save_resource(const Ref<Resource> &p_resource) {
|
||||
@@ -2404,6 +2418,18 @@ void EditorNode::_save_scene(String p_file, int idx) {
|
||||
editor_data.set_scene_as_saved(idx);
|
||||
editor_data.set_scene_modified_time(idx, FileAccess::get_modified_time(p_file));
|
||||
|
||||
if (EDITOR_GET("filesystem/on_save/warn_on_saving_large_text_resources")) {
|
||||
if (p_file.ends_with(".tscn") || p_file.ends_with(".tres")) {
|
||||
const int64_t file_size = FileAccess::get_size(p_file);
|
||||
if (file_size >= LARGE_RESOURCE_WARNING_SIZE_THRESHOLD) {
|
||||
// File is larger than 500 KiB, likely because it contains binary data serialized as Base64.
|
||||
// This is slow to save and load, so warn the user.
|
||||
EditorToaster::get_singleton()->popup_str(
|
||||
vformat(TTR("The text-based scene at path \"%s\" is large on disk (%s), likely because it has embedded binary data.\nThis slows down scene saving and loading.\nConsider saving its binary subresource(s) to a binary `.res` file or saving the scene as a binary `.scn` file.\nThis warning can be disabled in the Editor Settings (FileSystem > On Save > Warn on Saving Large Text Resources)."), p_file, String::humanize_size(file_size)), EditorToaster::SEVERITY_WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
editor_folding.save_scene_folding(scene, p_file);
|
||||
|
||||
_update_title();
|
||||
|
||||
Reference in New Issue
Block a user