Greatly improve editor performances by deferring tiles related updates

Solve few update problems
This commit is contained in:
Gilles Roudière 2021-10-13 14:49:28 +02:00
parent f86fd80f30
commit 0de2fce3e1
6 changed files with 51 additions and 23 deletions

View File

@ -38,8 +38,16 @@
#include "editor/editor_properties.h"
#include "editor/editor_scale.h"
void TileDataEditor::_call_tile_set_changed() {
_tile_set_changed();
void TileDataEditor::_tile_set_changed_plan_update() {
_tile_set_changed_update_needed = true;
call_deferred("_tile_set_changed_deferred_update");
}
void TileDataEditor::_tile_set_changed_deferred_update() {
if (_tile_set_changed_update_needed) {
_tile_set_changed();
_tile_set_changed_update_needed = false;
}
}
TileData *TileDataEditor::_get_tile_data(TileMapCell p_cell) {
@ -59,18 +67,20 @@ TileData *TileDataEditor::_get_tile_data(TileMapCell p_cell) {
}
void TileDataEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("_tile_set_changed_deferred_update"), &TileDataEditor::_tile_set_changed_deferred_update);
ADD_SIGNAL(MethodInfo("needs_redraw"));
}
void TileDataEditor::set_tile_set(Ref<TileSet> p_tile_set) {
if (tile_set.is_valid()) {
tile_set->disconnect("changed", callable_mp(this, &TileDataEditor::_call_tile_set_changed));
tile_set->disconnect("changed", callable_mp(this, &TileDataEditor::_tile_set_changed_plan_update));
}
tile_set = p_tile_set;
if (tile_set.is_valid()) {
tile_set->connect("changed", callable_mp(this, &TileDataEditor::_call_tile_set_changed));
tile_set->connect("changed", callable_mp(this, &TileDataEditor::_tile_set_changed_plan_update));
}
_call_tile_set_changed();
_tile_set_changed_plan_update();
}
bool DummyObject::_set(const StringName &p_name, const Variant &p_value) {

View File

@ -45,7 +45,9 @@ class TileDataEditor : public VBoxContainer {
GDCLASS(TileDataEditor, VBoxContainer);
private:
void _call_tile_set_changed();
bool _tile_set_changed_update_needed = false;
void _tile_set_changed_plan_update();
void _tile_set_changed_deferred_update();
protected:
Ref<TileSet> tile_set;

View File

@ -763,7 +763,11 @@ void TileSetAtlasSourceEditor::_update_tile_data_editors() {
// Update visibility.
bool is_visible = tools_button_group->get_pressed_button() == tool_paint_button;
tile_data_editor_dropdown_button->set_visible(is_visible);
tile_data_editor_dropdown_button->set_text(TTR("Select a property editor"));
if (tile_data_editors_tree->get_selected()) {
tile_data_editor_dropdown_button->set_text(tile_data_editors_tree->get_selected()->get_text(0));
} else {
tile_data_editor_dropdown_button->set_text(TTR("Select a property editor"));
}
tile_data_editors_label->set_visible(is_visible);
}
@ -959,7 +963,7 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_gui_input(const Ref<InputEven
current_tile_data_editor->forward_painting_atlas_gui_input(tile_atlas_view, tile_set_atlas_source, p_event);
}
// Update only what's needed.
tile_set_atlas_source_changed_needs_update = false;
tile_set_changed_needs_update = false;
tile_atlas_control->update();
tile_atlas_control_unscaled->update();
@ -1061,7 +1065,7 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_gui_input(const Ref<InputEven
drag_current_tile = coords;
// Update only what's needed.
tile_set_atlas_source_changed_needs_update = false;
tile_set_changed_needs_update = false;
_update_tile_inspector();
_update_atlas_view();
_update_tile_id_label();
@ -1101,7 +1105,7 @@ void TileSetAtlasSourceEditor::_tile_atlas_control_gui_input(const Ref<InputEven
drag_current_tile = new_rect.position;
// Update only what's needed.
tile_set_atlas_source_changed_needs_update = false;
tile_set_changed_needs_update = false;
_update_tile_inspector();
_update_atlas_view();
_update_tile_id_label();
@ -2012,12 +2016,12 @@ void TileSetAtlasSourceEditor::_tile_alternatives_control_unscaled_draw() {
}
}
void TileSetAtlasSourceEditor::_tile_set_atlas_source_changed() {
tile_set_atlas_source_changed_needs_update = true;
void TileSetAtlasSourceEditor::_tile_set_changed() {
tile_set_changed_needs_update = true;
}
void TileSetAtlasSourceEditor::_tile_proxy_object_changed(String p_what) {
tile_set_atlas_source_changed_needs_update = false; // Avoid updating too many things.
tile_set_changed_needs_update = false; // Avoid updating too many things.
_update_atlas_view();
}
@ -2073,8 +2077,8 @@ void TileSetAtlasSourceEditor::edit(Ref<TileSet> p_tile_set, TileSetAtlasSource
}
// Remove listener for old objects.
if (tile_set_atlas_source) {
tile_set_atlas_source->disconnect("changed", callable_mp(this, &TileSetAtlasSourceEditor::_tile_set_atlas_source_changed));
if (tile_set.is_valid()) {
tile_set->disconnect("changed", callable_mp(this, &TileSetAtlasSourceEditor::_tile_set_changed));
}
// Clear the selection.
@ -2086,8 +2090,8 @@ void TileSetAtlasSourceEditor::edit(Ref<TileSet> p_tile_set, TileSetAtlasSource
tile_set_atlas_source_id = p_source_id;
// Add the listener again.
if (tile_set_atlas_source) {
tile_set_atlas_source->connect("changed", callable_mp(this, &TileSetAtlasSourceEditor::_tile_set_atlas_source_changed));
if (tile_set.is_valid()) {
tile_set->connect("changed", callable_mp(this, &TileSetAtlasSourceEditor::_tile_set_changed));
}
// Update everything.
@ -2228,7 +2232,7 @@ void TileSetAtlasSourceEditor::_notification(int p_what) {
resize_handle_disabled = get_theme_icon(SNAME("EditorHandleDisabled"), SNAME("EditorIcons"));
break;
case NOTIFICATION_INTERNAL_PROCESS:
if (tile_set_atlas_source_changed_needs_update) {
if (tile_set_changed_needs_update) {
// Update everything.
_update_source_inspector();
@ -2241,7 +2245,7 @@ void TileSetAtlasSourceEditor::_notification(int p_what) {
_update_tile_data_editors();
_update_current_tile_data_editor();
tile_set_atlas_source_changed_needs_update = false;
tile_set_changed_needs_update = false;
}
break;
default:

View File

@ -112,7 +112,7 @@ private:
UndoRedo *undo_redo = EditorNode::get_undo_redo();
bool tile_set_atlas_source_changed_needs_update = false;
bool tile_set_changed_needs_update = false;
// -- Properties painting --
VBoxContainer *tile_data_painting_editor_container;
@ -263,7 +263,7 @@ private:
void _auto_remove_tiles();
AcceptDialog *confirm_auto_create_tiles;
void _tile_set_atlas_source_changed();
void _tile_set_changed();
void _tile_proxy_object_changed(String p_what);
void _atlas_source_proxy_object_changed(String p_what);

View File

@ -3094,6 +3094,8 @@ void TileMap::_bind_methods() {
ClassDB::bind_method(D_METHOD("_set_tile_data", "layer"), &TileMap::_set_tile_data);
ClassDB::bind_method(D_METHOD("_get_tile_data", "layer"), &TileMap::_get_tile_data);
ClassDB::bind_method(D_METHOD("_tile_set_changed_deferred_update"), &TileMap::_tile_set_changed_deferred_update);
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "tile_set", PROPERTY_HINT_RESOURCE_TYPE, "TileSet"), "set_tileset", "get_tileset");
ADD_PROPERTY(PropertyInfo(Variant::INT, "cell_quadrant_size", PROPERTY_HINT_RANGE, "1,128,1"), "set_quadrant_size", "get_quadrant_size");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collision_animatable"), "set_collision_animatable", "is_collision_animatable");
@ -3113,8 +3115,16 @@ void TileMap::_bind_methods() {
void TileMap::_tile_set_changed() {
emit_signal(SNAME("changed"));
_clear_internals();
_recreate_internals();
_tile_set_changed_deferred_update_needed = true;
call_deferred("_tile_set_changed_deferred_update");
}
void TileMap::_tile_set_changed_deferred_update() {
if (_tile_set_changed_deferred_update_needed) {
_clear_internals();
_recreate_internals();
_tile_set_changed_deferred_update_needed = false;
}
}
TileMap::TileMap() {

View File

@ -285,6 +285,8 @@ private:
Vector<int> _get_tile_data(int p_layer) const;
void _tile_set_changed();
bool _tile_set_changed_deferred_update_needed = false;
void _tile_set_changed_deferred_update();
protected:
bool _set(const StringName &p_name, const Variant &p_value);