Mono: Fixes annotated signal loading in exported binaries

This commit is contained in:
= 2018-06-30 20:14:40 -05:00
parent 68c106d60d
commit 489c9adf03
2 changed files with 32 additions and 40 deletions

View file

@ -745,10 +745,9 @@ void CSharpLanguage::reload_assemblies_if_needed(bool p_soft_reload) {
for (Map<Ref<CSharpScript>, Map<ObjectID, List<Pair<StringName, Variant> > > >::Element *E = to_reload.front(); E; E = E->next()) {
Ref<CSharpScript> scr = E->key();
scr->signals_invalidated = true;
scr->exports_invalidated = true;
scr->signals_invalidated = true;
scr->reload(p_soft_reload);
scr->update_signals();
scr->update_exports();
//restore state if saved
@ -1579,37 +1578,33 @@ bool CSharpScript::_update_exports() {
return false;
}
bool CSharpScript::_update_signals() {
if (!valid)
return false;
void CSharpScript::load_script_signals(GDMonoClass *p_class, GDMonoClass *p_native_class) {
bool changed = false;
if (signals_invalidated) {
signals_invalidated = false;
GDMonoClass *top = script_class;
_signals.clear();
changed = true; // TODO Do a real check for change
while (top && top != native) {
const Vector<GDMonoClass *> &delegates = top->get_all_delegates();
for (int i = delegates.size() - 1; i >= 0; --i) {
Vector<Argument> parameters;
GDMonoClass *delegate = delegates[i];
if (_get_signal(top, delegate, parameters)) {
_signals[delegate->get_name()] = parameters;
}
}
top = top->get_parent_class();
}
// no need to load the script's signals more than once
if (!signals_invalidated) {
return;
}
return changed;
// make sure this classes signals are empty when loading for the first time
_signals.clear();
GDMonoClass *top = p_class;
while (top && top != p_native_class) {
const Vector<GDMonoClass *> &delegates = top->get_all_delegates();
for (int i = delegates.size() - 1; i >= 0; --i) {
Vector<Argument> parameters;
GDMonoClass *delegate = delegates[i];
if (_get_signal(top, delegate, parameters)) {
_signals[delegate->get_name()] = parameters;
}
}
top = top->get_parent_class();
}
signals_invalidated = false;
}
bool CSharpScript::_get_signal(GDMonoClass *p_class, GDMonoClass *p_delegate, Vector<Argument> &params) {
@ -1848,6 +1843,8 @@ Ref<CSharpScript> CSharpScript::create_for_managed_type(GDMonoClass *p_class) {
top = top->get_parent_class();
}
script->load_script_signals(script->script_class, script->native);
return script;
}
@ -1973,7 +1970,6 @@ ScriptInstance *CSharpScript::instance_create(Object *p_this) {
PlaceHolderScriptInstance *si = memnew(PlaceHolderScriptInstance(CSharpLanguage::get_singleton(), Ref<Script>(this), p_this));
placeholders.insert(si);
_update_exports();
_update_signals();
return si;
#else
return NULL;
@ -1992,8 +1988,6 @@ ScriptInstance *CSharpScript::instance_create(Object *p_this) {
ERR_FAIL_V(NULL);
}
update_signals();
if (native) {
String native_name = native->get_name();
if (!ClassDB::is_parent_class(p_this->get_class_name(), native_name)) {
@ -2114,6 +2108,8 @@ Error CSharpScript::reload(bool p_keep_state) {
top->fetch_methods_with_godot_api_checks(native);
top = top->get_parent_class();
}
load_script_signals(script_class, native);
}
return OK;
@ -2173,10 +2169,6 @@ void CSharpScript::get_script_signal_list(List<MethodInfo> *r_signals) const {
}
}
void CSharpScript::update_signals() {
_update_signals();
}
Ref<Script> CSharpScript::get_base_script() const {
// TODO search in metadata file once we have it, not important any way?
@ -2241,9 +2233,10 @@ CSharpScript::CSharpScript() :
#ifdef TOOLS_ENABLED
source_changed_cache = false;
exports_invalidated = true;
signals_invalidated = true;
#endif
signals_invalidated = true;
_resource_path_changed();
#ifdef DEBUG_ENABLED

View file

@ -111,7 +111,7 @@ class CSharpScript : public Script {
void _clear();
bool _update_signals();
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();
@ -149,7 +149,6 @@ public:
virtual bool has_script_signal(const StringName &p_signal) const;
virtual void get_script_signal_list(List<MethodInfo> *r_signals) const;
virtual void update_signals();
/* TODO */ virtual bool get_property_default_value(const StringName &p_property, Variant &r_value) const;
virtual void get_script_property_list(List<PropertyInfo> *p_list) const;