Fix slow load/save of scenes with many instances of the same script

(cherry picked from commit 2ca6b9c610)
This commit is contained in:
Pedro J. Estébanez 2021-06-13 13:32:44 +02:00 committed by Rémi Verschelde
parent 6c07784dba
commit 2d1943b8d1
No known key found for this signature in database
GPG Key ID: C3336907360768E1
4 changed files with 21 additions and 12 deletions

View File

@ -310,7 +310,7 @@ PlaceHolderScriptInstance *GDScript::placeholder_instance_create(Object *p_this)
#ifdef TOOLS_ENABLED
PlaceHolderScriptInstance *si = memnew(PlaceHolderScriptInstance(GDScriptLanguage::get_singleton(), Ref<Script>(this), p_this));
placeholders.insert(si);
_update_exports();
_update_exports(nullptr, false, si);
return si;
#else
return NULL;
@ -357,7 +357,7 @@ void GDScript::_update_exports_values(Map<StringName, Variant> &values, List<Pro
}
#endif
bool GDScript::_update_exports(bool *r_err, bool p_recursive_call) {
bool GDScript::_update_exports(bool *r_err, bool p_recursive_call, PlaceHolderScriptInstance *p_instance_to_update) {
#ifdef TOOLS_ENABLED
static Vector<GDScript *> base_caches;
@ -480,15 +480,19 @@ bool GDScript::_update_exports(bool *r_err, bool p_recursive_call) {
}
}
if (placeholders.size()) { //hm :(
if ((changed || p_instance_to_update) && placeholders.size()) { //hm :(
// update placeholders if any
Map<StringName, Variant> values;
List<PropertyInfo> propnames;
_update_exports_values(values, propnames);
for (Set<PlaceHolderScriptInstance *>::Element *E = placeholders.front(); E; E = E->next()) {
E->get()->update(propnames, values);
if (changed) {
for (Set<PlaceHolderScriptInstance *>::Element *E = placeholders.front(); E; E = E->next()) {
E->get()->update(propnames, values);
}
} else {
p_instance_to_update->update(propnames, values);
}
}

View File

@ -129,7 +129,7 @@ class GDScript : public Script {
#endif
bool _update_exports(bool *r_err = nullptr, bool p_recursive_call = false);
bool _update_exports(bool *r_err = nullptr, bool p_recursive_call = false, PlaceHolderScriptInstance *p_instance_to_update = nullptr);
void _save_orphaned_subclasses();

View File

@ -2214,7 +2214,7 @@ void CSharpScript::_update_member_info_no_exports() {
}
#endif
bool CSharpScript::_update_exports() {
bool CSharpScript::_update_exports(PlaceHolderScriptInstance *p_instance_to_update) {
#ifdef TOOLS_ENABLED
bool is_editor = Engine::get_singleton()->is_editor_hint();
if (is_editor)
@ -2385,14 +2385,18 @@ bool CSharpScript::_update_exports() {
if (is_editor) {
placeholder_fallback_enabled = false;
if (placeholders.size()) {
if ((changed || p_instance_to_update) && placeholders.size()) {
// Update placeholders if any
Map<StringName, Variant> values;
List<PropertyInfo> propnames;
_update_exports_values(values, propnames);
for (Set<PlaceHolderScriptInstance *>::Element *E = placeholders.front(); E; E = E->next()) {
E->get()->update(propnames, values);
if (changed) {
for (Set<PlaceHolderScriptInstance *>::Element *E = placeholders.front(); E; E = E->next()) {
E->get()->update(propnames, values);
}
} else {
p_instance_to_update->update(propnames, values);
}
}
}
@ -2989,7 +2993,7 @@ PlaceHolderScriptInstance *CSharpScript::placeholder_instance_create(Object *p_t
#ifdef TOOLS_ENABLED
PlaceHolderScriptInstance *si = memnew(PlaceHolderScriptInstance(CSharpLanguage::get_singleton(), Ref<Script>(this), p_this));
placeholders.insert(si);
_update_exports();
_update_exports(si);
return si;
#else
return NULL;

View File

@ -135,7 +135,8 @@ class CSharpScript : public Script {
void load_script_signals(GDMonoClass *p_class, GDMonoClass *p_native_class);
bool _get_signal(GDMonoClass *p_class, GDMonoClass *p_delegate, Vector<Argument> &params);
bool _update_exports();
bool _update_exports(PlaceHolderScriptInstance *p_instance_to_update = nullptr);
bool _get_member_export(IMonoClassMember *p_member, bool p_inspect_export, PropertyInfo &r_prop_info, bool &r_exported);
#ifdef TOOLS_ENABLED
static int _try_get_member_export_hint(IMonoClassMember *p_member, ManagedType p_type, Variant::Type p_variant_type, bool p_allow_generics, PropertyHint &r_hint, String &r_hint_string);