Skip to content

Commit

Permalink
Prevent the surface upgrade tool from running during export
Browse files Browse the repository at this point in the history
Also add an explicit way to trigger the tool manually
at user's will.
  • Loading branch information
YuriSizov committed Nov 20, 2023
1 parent 80de898 commit fdaee9e
Show file tree
Hide file tree
Showing 6 changed files with 88 additions and 18 deletions.
11 changes: 11 additions & 0 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3048,6 +3048,9 @@ void EditorNode::_tool_menu_option(int p_idx) {
case TOOLS_ORPHAN_RESOURCES: {
orphan_resources->show();
} break;
case TOOLS_SURFACE_UPGRADE: {
surface_upgrade_dialog->popup_centered(Size2(750 * EDSCALE, 0));
} break;
case TOOLS_CUSTOM: {
if (tool_menu->get_item_submenu(p_idx) == "") {
Callable callback = tool_menu->get_item_metadata(p_idx);
Expand Down Expand Up @@ -4671,6 +4674,10 @@ Error EditorNode::export_preset(const String &p_preset, const String &p_path, bo
return OK;
}

bool EditorNode::is_project_exporting() const {
return project_export && project_export->is_exporting();
}

void EditorNode::show_accept(const String &p_text, const String &p_title) {
current_menu_option = -1;
if (accept) {
Expand Down Expand Up @@ -7429,6 +7436,7 @@ EditorNode::EditorNode() {
project_menu->add_child(tool_menu);
project_menu->add_submenu_item(TTR("Tools"), "Tools");
tool_menu->add_item(TTR("Orphan Resource Explorer..."), TOOLS_ORPHAN_RESOURCES);
tool_menu->add_item(TTR("Upgrade Mesh Surfaces..."), TOOLS_SURFACE_UPGRADE);

project_menu->add_separator();
project_menu->add_shortcut(ED_SHORTCUT("editor/reload_current_project", TTR("Reload Current Project")), RELOAD_CURRENT_PROJECT);
Expand Down Expand Up @@ -7768,6 +7776,9 @@ EditorNode::EditorNode() {
orphan_resources = memnew(OrphanResourcesDialog);
gui_base->add_child(orphan_resources);

surface_upgrade_dialog = memnew(SurfaceUpgradeDialog);
gui_base->add_child(surface_upgrade_dialog);

confirmation = memnew(ConfirmationDialog);
gui_base->add_child(confirmation);
confirmation->connect("confirmed", callable_mp(this, &EditorNode::_menu_confirm_current));
Expand Down
4 changes: 4 additions & 0 deletions editor/editor_node.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ class RunSettingsDialog;
class SceneImportSettings;
class ScriptCreateDialog;
class SurfaceUpgradeTool;
class SurfaceUpgradeDialog;
class WindowWrapper;

class EditorNode : public Node {
Expand Down Expand Up @@ -192,6 +193,7 @@ class EditorNode : public Node {
EDIT_RELOAD_SAVED_SCENE,
TOOLS_ORPHAN_RESOURCES,
TOOLS_BUILD_PROFILE_MANAGER,
TOOLS_SURFACE_UPGRADE,
TOOLS_CUSTOM,
RESOURCE_SAVE,
RESOURCE_SAVE_AS,
Expand Down Expand Up @@ -496,6 +498,7 @@ class EditorNode : public Node {
HashMap<String, Ref<Texture2D>> icon_type_cache;

SurfaceUpgradeTool *surface_upgrade_tool = nullptr;
SurfaceUpgradeDialog *surface_upgrade_dialog = nullptr;
bool run_surface_upgrade_tool = false;

static EditorBuildCallback build_callbacks[MAX_BUILD_CALLBACKS];
Expand Down Expand Up @@ -875,6 +878,7 @@ class EditorNode : public Node {
void _copy_warning(const String &p_str);

Error export_preset(const String &p_preset, const String &p_path, bool p_debug, bool p_pack_only);
bool is_project_exporting() const;

Control *get_gui_base() { return gui_base; }

Expand Down
24 changes: 20 additions & 4 deletions editor/export/project_export.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1076,11 +1076,13 @@ void ProjectExportDialog::_export_project_to_path(const String &p_path) {
EditorSettings::get_singleton()->set_project_metadata("export_options", "default_filename", default_filename);

Ref<EditorExportPreset> current = get_current_preset();
ERR_FAIL_COND(current.is_null());
ERR_FAIL_COND_MSG(current.is_null(), "Failed to start the export: current preset is invalid.");
Ref<EditorExportPlatform> platform = current->get_platform();
ERR_FAIL_COND(platform.is_null());
ERR_FAIL_COND_MSG(platform.is_null(), "Failed to start the export: current preset has no valid platform.");
current->set_export_path(p_path);

exporting = true;

platform->clear_messages();
Error err = platform->export_project(current, export_debug->is_pressed(), current->get_export_path(), 0);
result_dialog_log->clear();
Expand All @@ -1089,6 +1091,8 @@ void ProjectExportDialog::_export_project_to_path(const String &p_path) {
result_dialog->popup_centered_ratio(0.5);
}
}

exporting = false;
}

void ProjectExportDialog::_export_all_dialog() {
Expand All @@ -1108,19 +1112,29 @@ void ProjectExportDialog::_export_all(bool p_debug) {
String export_target = p_debug ? TTR("Debug") : TTR("Release");
EditorProgress ep("exportall", TTR("Exporting All") + " " + export_target, EditorExport::get_singleton()->get_export_preset_count(), true);

exporting = true;

bool show_dialog = false;
result_dialog_log->clear();
for (int i = 0; i < EditorExport::get_singleton()->get_export_preset_count(); i++) {
Ref<EditorExportPreset> preset = EditorExport::get_singleton()->get_export_preset(i);
ERR_FAIL_COND(preset.is_null());
if (preset.is_null()) {
exporting = false;
ERR_FAIL_MSG("Failed to start the export: one of the presets is invalid.");
}

Ref<EditorExportPlatform> platform = preset->get_platform();
ERR_FAIL_COND(platform.is_null());
if (platform.is_null()) {
exporting = false;
ERR_FAIL_MSG("Failed to start the export: one of the presets has no valid platform.");
}

ep.step(preset->get_name(), i);

platform->clear_messages();
Error err = platform->export_project(preset, p_debug, preset->get_export_path(), 0);
if (err == ERR_SKIP) {
exporting = false;
return;
}
bool has_messages = platform->fill_log_messages(result_dialog_log, err);
Expand All @@ -1129,6 +1143,8 @@ void ProjectExportDialog::_export_all(bool p_debug) {
if (show_dialog) {
result_dialog->popup_centered_ratio(0.5);
}

exporting = false;
}

void ProjectExportDialog::_bind_methods() {
Expand Down
5 changes: 4 additions & 1 deletion editor/export/project_export.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class ProjectExportTextureFormatError : public HBoxContainer {
class ProjectExportDialog : public ConfirmationDialog {
GDCLASS(ProjectExportDialog, ConfirmationDialog);

private:
TabContainer *sections = nullptr;

MenuButton *add_preset = nullptr;
Expand Down Expand Up @@ -118,6 +117,8 @@ class ProjectExportDialog : public ConfirmationDialog {

String default_filename;

bool exporting = false;

void _runnable_pressed();
void _update_parameters(const String &p_edited_property);
void _name_changed(const String &p_string);
Expand Down Expand Up @@ -199,6 +200,8 @@ class ProjectExportDialog : public ConfirmationDialog {

Ref<EditorExportPreset> get_current_preset() const;

bool is_exporting() const { return exporting; };

ProjectExportDialog();
~ProjectExportDialog();
};
Expand Down
49 changes: 37 additions & 12 deletions editor/surface_upgrade_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#include "editor/editor_file_system.h"
#include "editor/editor_node.h"
#include "editor/editor_scale.h"
#include "editor/editor_settings.h"
#include "scene/scene_string_names.h"
#include "servers/rendering_server.h"
Expand Down Expand Up @@ -75,30 +76,38 @@ void SurfaceUpgradeTool::_try_show_popup() {

void SurfaceUpgradeTool::_show_popup() {
MutexLock lock(mutex);
if (EditorNode::get_singleton()->is_project_exporting()) {
return; // We suppress the tool during the export routine, because the immediate dialog breaks everything.
}
if (!show_requested || popped_up) {
return;
}
show_requested = false;
popped_up = true;

bool accepted = EditorNode::immediate_confirmation_dialog(TTR("This project uses meshes with an outdated mesh format from previous Godot versions. The engine needs to update the format in order to use those meshes.\n\nPress 'Restart & Upgrade' to run the surface upgrade tool which will update and re-save all meshes and scenes. This update will restart the editor and may take several minutes. Upgrading will make the meshes incompatible with previous versions of Godot.\n\nPress 'Upgrade Only' to continue opening the scene as normal. The engine will update each mesh in memory, but the update will not be saved. Choosing this option will lead to slower load times every time this project is loaded."), TTR("Restart & Upgrade"), TTR("Upgrade Only"), 500);
const String confirmation_message = TTR("This project uses meshes with an outdated mesh format from previous Godot versions. The engine needs to update the format in order to use those meshes.\n\nPress 'Restart & Upgrade' to run the surface upgrade tool which will update and re-save all meshes and scenes. This update will restart the editor and may take several minutes. Upgrading will make the meshes incompatible with previous versions of Godot.\n\nPress 'Upgrade Only' to continue opening the scene as normal. The engine will update each mesh in memory, but the update will not be saved. Choosing this option will lead to slower load times every time this project is loaded.");
bool accepted = EditorNode::immediate_confirmation_dialog(confirmation_message, TTR("Restart & Upgrade"), TTR("Upgrade Only"), 500);
if (accepted) {
EditorSettings::get_singleton()->set_project_metadata("surface_upgrade_tool", "run_on_restart", true);

Vector<String> reimport_paths;
Vector<String> resave_paths;
_add_files(EditorFileSystem::get_singleton()->get_filesystem(), reimport_paths, resave_paths);

EditorSettings::get_singleton()->set_project_metadata("surface_upgrade_tool", "reimport_paths", reimport_paths);
EditorSettings::get_singleton()->set_project_metadata("surface_upgrade_tool", "resave_paths", resave_paths);

// Delay to avoid deadlocks, since this dialog can be triggered by loading a scene.
MessageQueue::get_singleton()->push_callable(callable_mp(EditorNode::get_singleton(), &EditorNode::restart_editor));
prepare_upgrade();
} else {
RS::get_singleton()->set_warn_on_surface_upgrade(true);
}
}

void SurfaceUpgradeTool::prepare_upgrade() {
EditorSettings::get_singleton()->set_project_metadata("surface_upgrade_tool", "run_on_restart", true);

Vector<String> reimport_paths;
Vector<String> resave_paths;
_add_files(EditorFileSystem::get_singleton()->get_filesystem(), reimport_paths, resave_paths);

EditorSettings::get_singleton()->set_project_metadata("surface_upgrade_tool", "reimport_paths", reimport_paths);
EditorSettings::get_singleton()->set_project_metadata("surface_upgrade_tool", "resave_paths", resave_paths);

// Delay to avoid deadlocks, since this dialog can be triggered by loading a scene.
MessageQueue::get_singleton()->push_callable(callable_mp(EditorNode::get_singleton(), &EditorNode::restart_editor));
}

// Ensure that the warnings and popups are skipped.
void SurfaceUpgradeTool::begin_upgrade() {
EditorSettings::get_singleton()->set_project_metadata("surface_upgrade_tool", "run_on_restart", false);
Expand Down Expand Up @@ -162,3 +171,19 @@ SurfaceUpgradeTool::SurfaceUpgradeTool() {
}

SurfaceUpgradeTool::~SurfaceUpgradeTool() {}

void SurfaceUpgradeDialog::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_READY:
// Can't do it in the constructor because it doesn't know that the signal exists.
connect("confirmed", callable_mp(SurfaceUpgradeTool::get_singleton(), &SurfaceUpgradeTool::prepare_upgrade));
break;
}
}

SurfaceUpgradeDialog::SurfaceUpgradeDialog() {
const String confirmation_message = TTR("The mesh format has changed in Godot 4.2, which affects both imported meshes and meshes authored inside of Godot. The engine needs to update the format in order to use those meshes.\n\nIf your project predates Godot 4.2 and contains meshes we recommend you run this one time conversion tool. This update will restart the editor and may take several minutes. Upgrading will make the meshes incompatible with previous versions of Godot.\n\nYou can still use your existing meshes as is. The engine will update each mesh in memory, but the update will not be saved. Choosing this option will lead to slower load times every time this project is loaded.");
set_text(confirmation_message);
set_autowrap(true);
get_label()->set_custom_minimum_size(Size2(750 * EDSCALE, 0));
}
13 changes: 12 additions & 1 deletion editor/surface_upgrade_tool.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#ifndef SURFACE_UPGRADE_TOOL_H
#define SURFACE_UPGRADE_TOOL_H

#include "scene/main/node.h"
#include "scene/gui/dialogs.h"

class EditorFileSystemDirectory;

Expand All @@ -57,11 +57,22 @@ class SurfaceUpgradeTool : public Object {
bool is_show_requested() const { return show_requested; };
void show_popup() { _show_popup(); }

void prepare_upgrade();
void begin_upgrade();
void finish_upgrade();

SurfaceUpgradeTool();
~SurfaceUpgradeTool();
};

class SurfaceUpgradeDialog : public ConfirmationDialog {
GDCLASS(SurfaceUpgradeDialog, ConfirmationDialog);

protected:
void _notification(int p_what);

public:
SurfaceUpgradeDialog();
};

#endif // SURFACE_UPGRADE_TOOL_H

0 comments on commit fdaee9e

Please sign in to comment.