summaryrefslogtreecommitdiff
path: root/scene/main
diff options
context:
space:
mode:
authorJuan Linietsky <juan@godotengine.org>2020-02-19 16:27:19 -0300
committerJuan Linietsky <reduzio@gmail.com>2020-02-20 08:24:50 +0100
commit69c95f4b4c128a22777af1e155bc24c7033decca (patch)
tree0add52fc270f808b4b2ad0bf7c970d72338c667e /scene/main
parent1a4be2cd8fdd9ba26f016f3e2d83febfe8ae141c (diff)
Reworked signal connection system, added support for Callable and Signal objects and made them default.
Diffstat (limited to 'scene/main')
-rw-r--r--scene/main/http_request.cpp2
-rw-r--r--scene/main/node.cpp50
-rw-r--r--scene/main/node.h8
-rw-r--r--scene/main/scene_tree.cpp30
-rw-r--r--scene/main/scene_tree.h4
-rw-r--r--scene/main/viewport.cpp12
6 files changed, 53 insertions, 53 deletions
diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp
index c4fb3335dc..85bde92851 100644
--- a/scene/main/http_request.cpp
+++ b/scene/main/http_request.cpp
@@ -589,7 +589,7 @@ HTTPRequest::HTTPRequest() {
timer = memnew(Timer);
timer->set_one_shot(true);
- timer->connect("timeout", this, "_timeout");
+ timer->connect_compat("timeout", this, "_timeout");
add_child(timer);
timeout = 0;
}
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index 8ceac74bb8..2c15ac6aae 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -592,16 +592,16 @@ void Node::rpc_unreliable_id(int p_peer_id, const StringName &p_method, VARIANT_
rpcp(p_peer_id, true, p_method, argptr, argc);
}
-Variant Node::_rpc_bind(const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
+Variant Node::_rpc_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
if (p_argcount < 1) {
- r_error.error = Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
+ r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
r_error.argument = 1;
return Variant();
}
if (p_args[0]->get_type() != Variant::STRING) {
- r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = 0;
r_error.expected = Variant::STRING;
return Variant();
@@ -611,27 +611,27 @@ Variant Node::_rpc_bind(const Variant **p_args, int p_argcount, Variant::CallErr
rpcp(0, false, method, &p_args[1], p_argcount - 1);
- r_error.error = Variant::CallError::CALL_OK;
+ r_error.error = Callable::CallError::CALL_OK;
return Variant();
}
-Variant Node::_rpc_id_bind(const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
+Variant Node::_rpc_id_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
if (p_argcount < 2) {
- r_error.error = Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
+ r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
r_error.argument = 2;
return Variant();
}
if (p_args[0]->get_type() != Variant::INT) {
- r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = 0;
r_error.expected = Variant::INT;
return Variant();
}
if (p_args[1]->get_type() != Variant::STRING) {
- r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = 1;
r_error.expected = Variant::STRING;
return Variant();
@@ -642,20 +642,20 @@ Variant Node::_rpc_id_bind(const Variant **p_args, int p_argcount, Variant::Call
rpcp(peer_id, false, method, &p_args[2], p_argcount - 2);
- r_error.error = Variant::CallError::CALL_OK;
+ r_error.error = Callable::CallError::CALL_OK;
return Variant();
}
-Variant Node::_rpc_unreliable_bind(const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
+Variant Node::_rpc_unreliable_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
if (p_argcount < 1) {
- r_error.error = Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
+ r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
r_error.argument = 1;
return Variant();
}
if (p_args[0]->get_type() != Variant::STRING) {
- r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = 0;
r_error.expected = Variant::STRING;
return Variant();
@@ -665,27 +665,27 @@ Variant Node::_rpc_unreliable_bind(const Variant **p_args, int p_argcount, Varia
rpcp(0, true, method, &p_args[1], p_argcount - 1);
- r_error.error = Variant::CallError::CALL_OK;
+ r_error.error = Callable::CallError::CALL_OK;
return Variant();
}
-Variant Node::_rpc_unreliable_id_bind(const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
+Variant Node::_rpc_unreliable_id_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
if (p_argcount < 2) {
- r_error.error = Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
+ r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
r_error.argument = 2;
return Variant();
}
if (p_args[0]->get_type() != Variant::INT) {
- r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = 0;
r_error.expected = Variant::INT;
return Variant();
}
if (p_args[1]->get_type() != Variant::STRING) {
- r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = 1;
r_error.expected = Variant::STRING;
return Variant();
@@ -696,7 +696,7 @@ Variant Node::_rpc_unreliable_id_bind(const Variant **p_args, int p_argcount, Va
rpcp(peer_id, true, method, &p_args[2], p_argcount - 2);
- r_error.error = Variant::CallError::CALL_OK;
+ r_error.error = Callable::CallError::CALL_OK;
return Variant();
}
@@ -2360,7 +2360,7 @@ void Node::_duplicate_signals(const Node *p_original, Node *p_copy) const {
NodePath p = p_original->get_path_to(this);
Node *copy = p_copy->get_node(p);
- Node *target = Object::cast_to<Node>(E->get().target);
+ Node *target = Object::cast_to<Node>(E->get().callable.get_object());
if (!target) {
continue;
}
@@ -2375,8 +2375,8 @@ void Node::_duplicate_signals(const Node *p_original, Node *p_copy) const {
if (p_copy->has_node(ptarget))
copytarget = p_copy->get_node(ptarget);
- if (copy && copytarget && !copy->is_connected(E->get().signal, copytarget, E->get().method)) {
- copy->connect(E->get().signal, copytarget, E->get().method, E->get().binds, E->get().flags);
+ if (copy && copytarget && !copy->is_connected_compat(E->get().signal.get_name(), copytarget, E->get().callable.get_method())) {
+ copy->connect_compat(E->get().signal.get_name(), copytarget, E->get().callable.get_method(), E->get().binds, E->get().flags);
}
}
}
@@ -2531,10 +2531,10 @@ void Node::_replace_connections_target(Node *p_new_target) {
Connection &c = E->get();
if (c.flags & CONNECT_PERSIST) {
- c.source->disconnect(c.signal, this, c.method);
- bool valid = p_new_target->has_method(c.method) || Ref<Script>(p_new_target->get_script()).is_null() || Ref<Script>(p_new_target->get_script())->has_method(c.method);
- ERR_CONTINUE_MSG(!valid, "Attempt to connect signal '" + c.source->get_class() + "." + c.signal + "' to nonexistent method '" + c.target->get_class() + "." + c.method + "'.");
- c.source->connect(c.signal, p_new_target, c.method, c.binds, c.flags);
+ c.signal.get_object()->disconnect_compat(c.signal.get_name(), this, c.callable.get_method());
+ bool valid = p_new_target->has_method(c.callable.get_method()) || Ref<Script>(p_new_target->get_script()).is_null() || Ref<Script>(p_new_target->get_script())->has_method(c.callable.get_method());
+ ERR_CONTINUE_MSG(!valid, "Attempt to connect signal '" + c.signal.get_object()->get_class() + "." + c.signal.get_name() + "' to nonexistent method '" + c.callable.get_object()->get_class() + "." + c.callable.get_method() + "'.");
+ c.signal.get_object()->connect_compat(c.signal.get_name(), p_new_target, c.callable.get_method(), c.binds, c.flags);
}
}
}
diff --git a/scene/main/node.h b/scene/main/node.h
index 02c828e8ff..d1f75b71ec 100644
--- a/scene/main/node.h
+++ b/scene/main/node.h
@@ -185,10 +185,10 @@ private:
Array _get_children() const;
Array _get_groups() const;
- Variant _rpc_bind(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
- Variant _rpc_unreliable_bind(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
- Variant _rpc_id_bind(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
- Variant _rpc_unreliable_id_bind(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
+ Variant _rpc_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error);
+ Variant _rpc_unreliable_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error);
+ Variant _rpc_id_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error);
+ Variant _rpc_unreliable_id_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error);
friend class SceneTree;
diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp
index 2a0825252d..f558670693 100644
--- a/scene/main/scene_tree.cpp
+++ b/scene/main/scene_tree.cpp
@@ -87,7 +87,7 @@ void SceneTreeTimer::release_connections() {
for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
Connection const &connection = E->get();
- disconnect(connection.signal, connection.target, connection.method);
+ disconnect_compat(connection.signal.get_name(), connection.callable.get_object(), connection.callable.get_method());
}
}
@@ -1004,9 +1004,9 @@ void SceneMainLoop::_update_listener_2d() {
}
*/
-Variant SceneTree::_call_group_flags(const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
+Variant SceneTree::_call_group_flags(const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
- r_error.error = Variant::CallError::CALL_OK;
+ r_error.error = Callable::CallError::CALL_OK;
ERR_FAIL_COND_V(p_argcount < 3, Variant());
ERR_FAIL_COND_V(!p_args[0]->is_num(), Variant());
@@ -1027,9 +1027,9 @@ Variant SceneTree::_call_group_flags(const Variant **p_args, int p_argcount, Var
return Variant();
}
-Variant SceneTree::_call_group(const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
+Variant SceneTree::_call_group(const Variant **p_args, int p_argcount, Callable::CallError &r_error) {
- r_error.error = Variant::CallError::CALL_OK;
+ r_error.error = Callable::CallError::CALL_OK;
ERR_FAIL_COND_V(p_argcount < 2, Variant());
ERR_FAIL_COND_V(p_args[0]->get_type() != Variant::STRING, Variant());
@@ -1766,21 +1766,21 @@ void SceneTree::set_multiplayer(Ref<MultiplayerAPI> p_multiplayer) {
ERR_FAIL_COND(!p_multiplayer.is_valid());
if (multiplayer.is_valid()) {
- multiplayer->disconnect("network_peer_connected", this, "_network_peer_connected");
- multiplayer->disconnect("network_peer_disconnected", this, "_network_peer_disconnected");
- multiplayer->disconnect("connected_to_server", this, "_connected_to_server");
- multiplayer->disconnect("connection_failed", this, "_connection_failed");
- multiplayer->disconnect("server_disconnected", this, "_server_disconnected");
+ multiplayer->disconnect_compat("network_peer_connected", this, "_network_peer_connected");
+ multiplayer->disconnect_compat("network_peer_disconnected", this, "_network_peer_disconnected");
+ multiplayer->disconnect_compat("connected_to_server", this, "_connected_to_server");
+ multiplayer->disconnect_compat("connection_failed", this, "_connection_failed");
+ multiplayer->disconnect_compat("server_disconnected", this, "_server_disconnected");
}
multiplayer = p_multiplayer;
multiplayer->set_root_node(root);
- multiplayer->connect("network_peer_connected", this, "_network_peer_connected");
- multiplayer->connect("network_peer_disconnected", this, "_network_peer_disconnected");
- multiplayer->connect("connected_to_server", this, "_connected_to_server");
- multiplayer->connect("connection_failed", this, "_connection_failed");
- multiplayer->connect("server_disconnected", this, "_server_disconnected");
+ multiplayer->connect_compat("network_peer_connected", this, "_network_peer_connected");
+ multiplayer->connect_compat("network_peer_disconnected", this, "_network_peer_disconnected");
+ multiplayer->connect_compat("connected_to_server", this, "_connected_to_server");
+ multiplayer->connect_compat("connection_failed", this, "_connection_failed");
+ multiplayer->connect_compat("server_disconnected", this, "_server_disconnected");
}
void SceneTree::set_network_peer(const Ref<NetworkedMultiplayerPeer> &p_network_peer) {
diff --git a/scene/main/scene_tree.h b/scene/main/scene_tree.h
index 565c58fac1..80f0da66e2 100644
--- a/scene/main/scene_tree.h
+++ b/scene/main/scene_tree.h
@@ -208,8 +208,8 @@ private:
void _notify_group_pause(const StringName &p_group, int p_notification);
void _call_input_pause(const StringName &p_group, const StringName &p_method, const Ref<InputEvent> &p_input);
- Variant _call_group_flags(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
- Variant _call_group(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
+ Variant _call_group_flags(const Variant **p_args, int p_argcount, Callable::CallError &r_error);
+ Variant _call_group(const Variant **p_args, int p_argcount, Callable::CallError &r_error);
void _flush_delete_queue();
//optimization
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index d9be77954b..d39bbed55b 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -1124,7 +1124,7 @@ void Viewport::set_world(const Ref<World> &p_world) {
_propagate_exit_world(this);
if (own_world.is_valid() && world.is_valid()) {
- world->disconnect(CoreStringNames::get_singleton()->changed, this, "_own_world_changed");
+ world->disconnect_compat(CoreStringNames::get_singleton()->changed, this, "_own_world_changed");
}
world = p_world;
@@ -1132,7 +1132,7 @@ void Viewport::set_world(const Ref<World> &p_world) {
if (own_world.is_valid()) {
if (world.is_valid()) {
own_world = world->duplicate();
- world->connect(CoreStringNames::get_singleton()->changed, this, "_own_world_changed");
+ world->connect_compat(CoreStringNames::get_singleton()->changed, this, "_own_world_changed");
} else {
own_world = Ref<World>(memnew(World));
}
@@ -2473,7 +2473,7 @@ List<Control *>::Element *Viewport::_gui_add_root_control(Control *p_control) {
List<Control *>::Element *Viewport::_gui_add_subwindow_control(Control *p_control) {
- p_control->connect("visibility_changed", this, "_subwindow_visibility_changed");
+ p_control->connect_compat("visibility_changed", this, "_subwindow_visibility_changed");
if (p_control->is_visible_in_tree()) {
gui.subwindow_order_dirty = true;
@@ -2568,7 +2568,7 @@ void Viewport::_gui_remove_subwindow_control(List<Control *>::Element *SI) {
Control *control = SI->get();
- control->disconnect("visibility_changed", this, "_subwindow_visibility_changed");
+ control->disconnect_compat("visibility_changed", this, "_subwindow_visibility_changed");
List<Control *>::Element *E = gui.subwindows.find(control);
if (E)
@@ -2850,12 +2850,12 @@ void Viewport::set_use_own_world(bool p_world) {
if (!p_world) {
own_world = Ref<World>();
if (world.is_valid()) {
- world->disconnect(CoreStringNames::get_singleton()->changed, this, "_own_world_changed");
+ world->disconnect_compat(CoreStringNames::get_singleton()->changed, this, "_own_world_changed");
}
} else {
if (world.is_valid()) {
own_world = world->duplicate();
- world->connect(CoreStringNames::get_singleton()->changed, this, "_own_world_changed");
+ world->connect_compat(CoreStringNames::get_singleton()->changed, this, "_own_world_changed");
} else {
own_world = Ref<World>(memnew(World));
}