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

Cleanup EditorNode, EditorHistory, EditorSelection and EditorData #58395

Merged
merged 1 commit into from
Mar 30, 2022

Conversation

Geometror
Copy link
Member

@Geometror Geometror commented Feb 21, 2022

This PR aims to tidy-up the EditorNode, EditorData, EditorSelection and EditorHistory classes (partially) with the following changes:

  • Remove unused enums (unused HISTORY_MAX constant)
  • Remove unused class attributes
  • Remove some old commented out code (reenabling it caused causes undesired behavior, so it seems fine to remove it)
  • Some renames of variables to be more descriptive/explicit (e.g., the term "history" was used ambiguously)
    • Rename EditorHistory to EditorSelectionHistory to better reflect what it does (this might require some discussion, as I am not quite sure with it)
  • Adjusted the comment style for consistency (// Begin with whitespace + uppercase letter and place a dot at the end.)
  • Removed some uninformative comments (e.g., //bye, //save after save();)
  • Restructure the EditorNode header to improve readability
    • Clearly separate class attributes and methods
    • Move enum and struct declarations
    • Group static methods
    • Group attributes/methods in a way that makes sense (I hope)
  • Reimplement rendering_driver check in EditorNode::_rendering_driver_selected (old commented out version)
  • Add TODO/FIXME in front of some comments which were (implicitly or explicitly) suggesting changes/marking hacks.
  • Remove an unnecessary visibility modifier since the GDCLASS macro includes "private:" at the end
  • Includes almost all changes in Refactored EditorHistory, removed unused code, added documentation. #44222 and Removed unused code from EditorSelection and added documentation. #44249 except the simplifications using the ERR_FAIL_INDEX macro, therefore co-authored by @EricEzaM.

@EricEzaM
Copy link
Contributor

You may be interested in having at a look at these PRs and seeing if there are any changes worth bringing into this one (I just never got around to updating them) #44222 #44249

@Geometror Geometror force-pushed the editor-node-data-cleanup branch 3 times, most recently from 7e47acd to 14d8e80 Compare March 29, 2022 23:59
@Geometror
Copy link
Member Author

Rebased and incorporated some of the changes made in #44222 and #44249 (basically all of it except the ERR_FAIL_INDEX macro additions/simplifications since they were used where negative values indicate a valid state, resulting in error spamming).

@Geometror Geometror changed the title Cleanup EditorNode and EditorData Cleanup EditorNode, EditorHistory, EditorSelection and EditorData Mar 30, 2022
Comment on lines 2970 to 2968
// case SET_VIDEO_DRIVER_SAVE_AND_RESTART: {
// ProjectSettings::get_singleton()->set("rendering/driver/driver_name", video_driver_request);
// save_all_scenes();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is dead code that can be removed.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

Copy link
Member

@akien-mga akien-mga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks pretty good to me. It makes variables and comments clearer, and the API renames and refactoring seems useful/clearer.

Comment on lines 1398 to 1399
scene->set_meta("__editor_run_settings__", Variant());
scene->set_meta("__editor_plugin_states__", Variant());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be changed to remove_meta()

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just did a quick search and it looks like this is actually the only place where these meta values are used, so I guess we could remove them completely.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed:

$ rg __editor_run_settings__
editor/editor_node.cpp
1396:   scene->set_meta("__editor_run_settings__", Variant()); // clear it (no point in keeping it)
$ rg __editor_plugin_states__
editor/editor_node.cpp
1397:   scene->set_meta("__editor_plugin_states__", Variant());

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed it.

@@ -2289,7 +2289,7 @@ void EditorNode::_edit_current(bool p_skip_foreign) {
InspectorDock::get_inspector_singleton()->set_use_folding(!disable_folding);
}

/* Take care of PLUGIN EDITOR */
// Take care of PLUGIN EDITOR.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment is odd. What is PLUGIN EDITOR?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, this is odd. We could change it to // Take care of the main editor plugin.

@@ -3366,14 +3365,14 @@ void EditorNode::set_addon_plugin_enabled(const String &p_addon, bool p_enabled,

EditorPlugin *ep = memnew(EditorPlugin);
ep->set_script(script);
plugin_addons[p_addon] = ep;
name_to_editor_plugin[p_addon] = ep;
Copy link
Member

@KoBeWi KoBeWi Mar 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

name_to_editor_plugin doesn't sound right. The original name is ok, not sure how it can be improved. Maybe addon_plugins? Or plugins_from_addons?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "addon_plugin" name in the method itself is a bit weird. Doesn't addon and plugin mean the same in this context? Or is there an API for non-plugin addons?

Since this stores editor plugins, it could just be editor_plugins.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point of this rename was that "addon" is inconsistent which the usual "plugin" naming, but just changing "addons" to "plugins" wont work since there is already Vector<EditorPlugin *> editor_plugins;
In addition, "plugin_addons" sound like it is just a list of all editor plugins/addons, which is not the case: It is actually of the type Map<String, EditorPlugin *>, so it maps the name of the editor plugin to the editor plugin object. In my opinion naming a map x_to_y makes it clearer since it directly tells you what is mapped to what.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand this variable correctly, it tracks which plugin was added from which user addon.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, this naming is indeed a bit weird. "Addon plugins" are basically editor plugins provided by the user, right? Should we then rename the corresponding methods/variables to use a "user_plugin" name scheme instead of a mix of plugin_addons and addon_plugins?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know tbh. It's rather established that installable plugins are called addons (their default folder is even called that). "addon plugins" could indeed be renamed to "user plugins", but the other usage of "addon" is probably fine.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I agree, we shouldn't do too much in this PR.
However, I still would rename plugin_addons to addon_name_to_plugin. What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addon_name_to_plugin is ok.

@@ -3933,7 +3932,7 @@ void EditorNode::register_editor_types() {

// FIXME: Is this stuff obsolete, or should it be ported to new APIs?
GDREGISTER_CLASS(EditorScenePostImport);
//ClassDB::register_type<EditorImportExport>();
// ClassDB::register_type<EditorImportExport>();
Copy link
Member

@KoBeWi KoBeWi Mar 30, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this type no longer exists. The code could be removed. (there is another commented-out instance in the code base if you search it)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we remove the dead code I guess we can also remove the FIXME comment above. I added this more than a year ago, if this didn't change since it's likely not relevant anymore.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it for EditorScenePostImport? Or was EditorScenePostImport just added between the comment and the commented out code?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, removed both comments.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In PR #10656

//ClassDB::register_type<EditorImporter>();
//ClassDB::register_type<EditorPostImport>();

was replaced with:

// FIXME: Is this stuff obsolete, or should it be ported to new APIs?
//ClassDB::register_class<EditorExportPlugin>();
//ClassDB::register_class<EditorScenePostImport>();
//ClassDB::register_type<EditorImportExport>();

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIRC EditorScenePostImport was ported recently. The only thing left would be EditorImportExport, but it's not clear what it's supposed to do. Also it's 5 years old...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did a quick research with git log, but couldn't find the exact commit where EditorImportExport was removed or renamed. But in the end it should be fine to remove this commented-out line.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to remove.

editor/editor_node.cpp Outdated Show resolved Hide resolved
@Geometror Geometror force-pushed the editor-node-data-cleanup branch 2 times, most recently from dfbcada to 988e61f Compare March 30, 2022 12:13
Comment on lines 250 to 271
EditorCommandPalette *command_palette;
EditorData editor_data;
EditorExport *editor_export;
EditorFolding editor_folding;
EditorInterface *editor_interface;
EditorLog *log;
EditorNativeShaderSourceVisualizer *native_shader_source_visualizer;
EditorPlugin *editor_plugin_screen;
EditorPluginList *editor_plugins_force_input_forwarding;
EditorPluginList *editor_plugins_force_over;
EditorPluginList *editor_plugins_over;
EditorQuickOpen *quick_open;
EditorQuickOpen *quick_run;
EditorResourcePreview *resource_preview;
EditorRun editor_run;
EditorRunNative *run_native;
EditorSelection *editor_selection;
EditorSelectionHistory editor_history;
EditorSettingsDialog *editor_settings_dialog;

ProjectExportDialog *project_export;
ProjectSettingsEditor *project_settings_editor;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These could be initialized to nullptr here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I changed it accordingly. But aren't there much more pointer member variables which are not initialized to nullptr (across the whole codebase)? So is there a general rule where to initialize to nullptr or should it ideally always be done?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, it should always be done. If it's not done somewhere, it's usually old code or someone missed it during review. We have occasional crashes caused by uninitialized pointers or variables.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We did a pass at initialization most member variables a while ago, but at the time we did not decide to initialize pointers to nullptr. So most of the codebase doesn't initialize them, but we can confirm with the other contributors that this should be done and then implement it with a regex.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you do if (pointer), the behavior is undefined when the pointer is not initialized and results in crashes that occur randomly (I've seen two of them recently). I don't know if there is anything against initializing them, but I'd say it's better to be safe.

@akien-mga akien-mga merged commit b7850bb into godotengine:master Mar 30, 2022
@akien-mga
Copy link
Member

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants