-
-
Notifications
You must be signed in to change notification settings - Fork 21.1k
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
Cleanup EditorNode, EditorHistory, EditorSelection and EditorData #58395
Conversation
7e47acd
to
14d8e80
Compare
editor/editor_node.cpp
Outdated
// case SET_VIDEO_DRIVER_SAVE_AND_RESTART: { | ||
// ProjectSettings::get_singleton()->set("rendering/driver/driver_name", video_driver_request); | ||
// save_all_scenes(); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this 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.
editor/editor_node.cpp
Outdated
scene->set_meta("__editor_run_settings__", Variant()); | ||
scene->set_meta("__editor_plugin_states__", Variant()); |
There was a problem hiding this comment.
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()
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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());
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed it.
editor/editor_node.cpp
Outdated
@@ -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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
editor/editor_node.cpp
Outdated
@@ -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; |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
editor/editor_node.cpp
Outdated
@@ -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>(); |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, removed both comments.
There was a problem hiding this comment.
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>();
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to remove.
dfbcada
to
988e61f
Compare
editor/editor_node.h
Outdated
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; |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
988e61f
to
843a898
Compare
Co-authored-by: Eric M <[email protected]>
843a898
to
314430b
Compare
Thanks! |
This PR aims to tidy-up the EditorNode, EditorData, EditorSelection and EditorHistory classes (partially) with the following changes:
//bye
,//save
after save();)