Skip to content

Commit 4b94bd1

Browse files
committed
Add a flag to make the connection automatically emit the source object.
Mainly used to improve the connection dialog.
1 parent 2582793 commit 4b94bd1

File tree

5 files changed

+252
-172
lines changed

5 files changed

+252
-172
lines changed

core/object/object.cpp

+14
Original file line numberDiff line numberDiff line change
@@ -1177,6 +1177,7 @@ Error Object::emit_signalp(const StringName &p_name, const Variant **p_args, int
11771177
OBJ_DEBUG_LOCK
11781178

11791179
Error err = OK;
1180+
Variant appended_self;
11801181

11811182
for (uint32_t i = 0; i < slot_count; ++i) {
11821183
const Callable &callable = slot_callables[i];
@@ -1190,6 +1191,18 @@ Error Object::emit_signalp(const StringName &p_name, const Variant **p_args, int
11901191
const Variant **args = p_args;
11911192
int argc = p_argcount;
11921193

1194+
if (flags & CONNECT_APPEND_SOURCE_OBJECT) {
1195+
argc += 1;
1196+
args = (const Variant **)alloca(sizeof(Variant *) * argc);
1197+
for (int j = 0; j < p_argcount; j++) {
1198+
args[j] = (const Variant *)p_args[j];
1199+
}
1200+
if (unlikely(appended_self.get_type() == Variant::NIL)) {
1201+
appended_self = this;
1202+
}
1203+
args[p_argcount] = &appended_self;
1204+
}
1205+
11931206
if (flags & CONNECT_DEFERRED) {
11941207
MessageQueue::get_singleton()->push_callablep(callable, args, argc, true);
11951208
} else {
@@ -1806,6 +1819,7 @@ void Object::_bind_methods() {
18061819
BIND_ENUM_CONSTANT(CONNECT_PERSIST);
18071820
BIND_ENUM_CONSTANT(CONNECT_ONE_SHOT);
18081821
BIND_ENUM_CONSTANT(CONNECT_REFERENCE_COUNTED);
1822+
BIND_ENUM_CONSTANT(CONNECT_APPEND_SOURCE_OBJECT);
18091823
}
18101824

18111825
void Object::set_deferred(const StringName &p_property, const Variant &p_value) {

0 commit comments

Comments
 (0)