CSharpScript should not own base script signals

This commit is contained in:
Paul Joannon 2024-05-09 13:46:25 +02:00
parent c313312ff5
commit 1d7085571e
No known key found for this signature in database
GPG key ID: C12F69B0AD0390DD
3 changed files with 34 additions and 27 deletions

View file

@ -1764,16 +1764,19 @@ void CSharpInstance::mono_object_disposed_baseref(GCHandleIntPtr p_gchandle_to_f
}
void CSharpInstance::connect_event_signals() {
// The script signals list includes the signals declared in base scripts.
for (CSharpScript::EventSignalInfo &signal : script->get_script_event_signals()) {
String signal_name = signal.name;
const CSharpScript *top = script.ptr();
while (top != nullptr && top->valid) {
for (const CSharpScript::EventSignalInfo &signal : top->event_signals) {
String signal_name = signal.name;
// TODO: Use pooling for ManagedCallable instances.
EventSignalCallable *event_signal_callable = memnew(EventSignalCallable(owner, signal_name));
// TODO: Use pooling for ManagedCallable instances.
EventSignalCallable *event_signal_callable = memnew(EventSignalCallable(owner, signal_name));
Callable callable(event_signal_callable);
connected_event_signals.push_back(callable);
owner->connect(signal_name, callable);
Callable callable(event_signal_callable);
connected_event_signals.push_back(callable);
owner->connect(signal_name, callable);
}
top = top->base_script.ptr();
}
}
@ -2617,25 +2620,33 @@ bool CSharpScript::has_script_signal(const StringName &p_signal) const {
}
}
if (base_script.is_valid()) {
return base_script->has_script_signal(p_signal);
}
return false;
}
void CSharpScript::get_script_signal_list(List<MethodInfo> *r_signals) const {
void CSharpScript::_get_script_signal_list(List<MethodInfo> *r_signals, bool p_include_base) const {
if (!valid) {
return;
}
for (const EventSignalInfo &signal : get_script_event_signals()) {
for (const EventSignalInfo &signal : event_signals) {
r_signals->push_back(signal.method_info);
}
if (!p_include_base) {
return;
}
if (base_script.is_valid()) {
base_script->get_script_signal_list(r_signals);
}
}
Vector<CSharpScript::EventSignalInfo> CSharpScript::get_script_event_signals() const {
if (!valid) {
return Vector<EventSignalInfo>();
}
return event_signals;
void CSharpScript::get_script_signal_list(List<MethodInfo> *r_signals) const {
_get_script_signal_list(r_signals, true);
}
bool CSharpScript::inherits_script(const Ref<Script> &p_script) const {

View file

@ -215,6 +215,8 @@ private:
// Do not use unless you know what you are doing
static void update_script_class_info(Ref<CSharpScript> p_script);
void _get_script_signal_list(List<MethodInfo> *r_signals, bool p_include_base) const;
protected:
static void _bind_methods();
@ -251,8 +253,6 @@ public:
bool has_script_signal(const StringName &p_signal) const override;
void get_script_signal_list(List<MethodInfo> *r_signals) const override;
Vector<EventSignalInfo> get_script_event_signals() const;
bool get_property_default_value(const StringName &p_property, Variant &r_value) const override;
void get_script_property_list(List<PropertyInfo> *r_list) const override;
void update_exports() override;

View file

@ -798,15 +798,15 @@ namespace Godot.Bridge
GetScriptTypeInfo(scriptType, outTypeInfo);
Type native = GodotObject.InternalGetClassNativeBase(scriptType);
// Methods
// Performance is not critical here as this will be replaced with source generators.
using var methods = new Collections.Array();
Type? top = scriptType;
Type native = GodotObject.InternalGetClassNativeBase(scriptType);
if (scriptType != null && scriptType != native)
if (scriptType != native)
{
var methodList = GetMethodListForType(scriptType);
@ -910,11 +910,9 @@ namespace Godot.Bridge
// Performance is not critical here as this will be replaced with source generators.
using var signals = new Collections.Dictionary();
top = scriptType;
while (top != null && top != native)
if (scriptType != native)
{
var signalList = GetSignalListForType(top);
var signalList = GetSignalListForType(scriptType);
if (signalList != null)
{
@ -949,8 +947,6 @@ namespace Godot.Bridge
signals.Add(signalName, signalParams);
}
}
top = top.BaseType;
}
*outEventSignalsDest = NativeFuncs.godotsharp_dictionary_new_copy(