Skip to content

Commit c3cc196

Browse files
committed
Make settings_changed signal less emitted
1 parent 99f5a3d commit c3cc196

File tree

4 files changed

+35
-14
lines changed

4 files changed

+35
-14
lines changed

core/config/project_settings.cpp

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) {
298298
}
299299

300300
_version++;
301-
_queue_changed();
301+
queue_changed();
302302
return true;
303303
}
304304

@@ -344,7 +344,7 @@ bool ProjectSettings::_set(const StringName &p_name, const Variant &p_value) {
344344
}
345345

346346
_version++;
347-
_queue_changed();
347+
queue_changed();
348348
return true;
349349
}
350350

@@ -501,8 +501,8 @@ void ProjectSettings::_get_property_list(List<PropertyInfo> *p_list) const {
501501
}
502502
}
503503

504-
void ProjectSettings::_queue_changed() {
505-
if (is_changed || !MessageQueue::get_singleton() || MessageQueue::get_singleton()->get_max_buffer_usage() == 0) {
504+
void ProjectSettings::queue_changed() {
505+
if (block_changed || is_changed || !MessageQueue::get_singleton() || MessageQueue::get_singleton()->get_max_buffer_usage() == 0) {
506506
return;
507507
}
508508
is_changed = true;
@@ -1119,7 +1119,9 @@ Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_cust
11191119
}
11201120
}
11211121
project_features = _trim_to_supported_features(project_features);
1122+
block_changed = true;
11221123
set_setting("application/config/features", project_features);
1124+
block_changed = false;
11231125
#endif // TOOLS_ENABLED
11241126

11251127
RBSet<_VCSort> vclist;
@@ -1199,18 +1201,22 @@ Error ProjectSettings::save_custom(const String &p_path, const CustomMap &p_cust
11991201
}
12001202

12011203
Variant _GLOBAL_DEF(const String &p_var, const Variant &p_default, bool p_restart_if_changed, bool p_ignore_value_in_docs, bool p_basic, bool p_internal) {
1204+
ProjectSettings *ps = ProjectSettings::get_singleton();
1205+
12021206
Variant ret;
1203-
if (!ProjectSettings::get_singleton()->has_setting(p_var)) {
1204-
ProjectSettings::get_singleton()->set(p_var, p_default);
1207+
if (!ps->has_setting(p_var)) {
1208+
ps->set_block_changed(true); // Prevents emitting change during initialization.
1209+
ps->set(p_var, p_default);
1210+
ps->set_block_changed(false);
12051211
}
12061212
ret = GLOBAL_GET(p_var);
12071213

1208-
ProjectSettings::get_singleton()->set_initial_value(p_var, p_default);
1209-
ProjectSettings::get_singleton()->set_builtin_order(p_var);
1210-
ProjectSettings::get_singleton()->set_as_basic(p_var, p_basic);
1211-
ProjectSettings::get_singleton()->set_restart_if_changed(p_var, p_restart_if_changed);
1212-
ProjectSettings::get_singleton()->set_ignore_value_in_docs(p_var, p_ignore_value_in_docs);
1213-
ProjectSettings::get_singleton()->set_as_internal(p_var, p_internal);
1214+
ps->set_initial_value(p_var, p_default);
1215+
ps->set_builtin_order(p_var);
1216+
ps->set_as_basic(p_var, p_basic);
1217+
ps->set_restart_if_changed(p_var, p_restart_if_changed);
1218+
ps->set_ignore_value_in_docs(p_var, p_ignore_value_in_docs);
1219+
ps->set_as_internal(p_var, p_internal);
12141220
return ret;
12151221
}
12161222

core/config/project_settings.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ class ProjectSettings : public Object {
9696
HashMap<StringName, PropertyInfo> custom_prop_info;
9797
bool using_datapack = false;
9898
bool project_loaded = false;
99+
bool block_changed = false;
99100
List<String> input_presets;
100101

101102
HashSet<String> custom_features;
@@ -117,7 +118,6 @@ class ProjectSettings : public Object {
117118
bool _property_can_revert(const StringName &p_name) const;
118119
bool _property_get_revert(const StringName &p_name, Variant &r_property) const;
119120

120-
void _queue_changed();
121121
void _emit_changed();
122122

123123
static inline ProjectSettings *singleton = nullptr;
@@ -160,6 +160,9 @@ class ProjectSettings : public Object {
160160
void store_global_class_list(const Array &p_classes);
161161
String get_global_class_list_path() const;
162162

163+
void queue_changed();
164+
void set_block_changed(bool p_block) { block_changed = p_block; }
165+
163166
bool has_setting(const String &p_var) const;
164167
String localize_path(const String &p_path) const;
165168
String globalize_path(const String &p_path) const;

editor/editor_sectioned_inspector.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
#include "editor_sectioned_inspector.h"
3232

33+
#include "core/config/project_settings.h"
3334
#include "editor/editor_inspector.h"
3435
#include "editor/editor_property_name_processor.h"
3536
#include "editor/editor_string_names.h"
@@ -69,8 +70,18 @@ class SectionedInspectorFilter : public Object {
6970
name = section + "/" + name;
7071
}
7172

73+
ProjectSettings *ps = ProjectSettings::get_singleton();
74+
if (ps) {
75+
// Small hack to block emitting of "settings_changed" signal unnecessarily.
76+
// It's handled by ProjectSettingsEditor.
77+
ps->set_block_changed(true);
78+
}
79+
7280
bool valid;
7381
edited->set(name, p_value, &valid);
82+
if (ps) {
83+
ps->set_block_changed(false);
84+
}
7485
return valid;
7586
}
7687

editor/project_settings_editor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ void ProjectSettingsEditor::_save() {
8282
settings_changed = false;
8383
if (ps) {
8484
ps->save();
85+
ps->queue_changed();
8586
}
8687
}
8788

@@ -792,7 +793,7 @@ ProjectSettingsEditor::ProjectSettingsEditor(EditorData *p_data) {
792793
tab_container->add_child(plugin_settings);
793794

794795
timer = memnew(Timer);
795-
timer->set_wait_time(1.5);
796+
timer->set_wait_time(1.0);
796797
timer->connect("timeout", callable_mp(this, &ProjectSettingsEditor::_save));
797798
timer->set_one_shot(true);
798799
add_child(timer);

0 commit comments

Comments
 (0)