summaryrefslogtreecommitdiff
path: root/scene/main/node.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/main/node.cpp')
-rwxr-xr-xscene/main/node.cpp171
1 files changed, 51 insertions, 120 deletions
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index 0474c6fd26..c3d9d97c5a 100755
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -3,7 +3,7 @@
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
-/* http://www.godotengine.org */
+/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2017 Godot Engine contributors (cf. AUTHORS.md) */
@@ -28,6 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "node.h"
+
#include "instance_placeholder.h"
#include "io/resource_loader.h"
#include "message_queue.h"
@@ -194,7 +195,7 @@ void Node::_propagate_enter_tree() {
data.depth = 1;
}
- data.viewport = cast_to<Viewport>();
+ data.viewport = Object::cast_to<Viewport>(this);
if (!data.viewport)
data.viewport = data.parent->data.viewport;
@@ -360,18 +361,6 @@ void Node::add_child_notify(Node *p_child) {
// to be used when not wanted
}
-/*
-void Node::remove_and_delete_child(Node *p_child) {
-
- ERR_FAIL_NULL( p_child );
- ERR_FAIL_COND( p_child->get_parent()!=this );
-
- remove_child(p_child);
- memdelete(p_child);
-
-}
-*/
-
void Node::remove_child_notify(Node *p_child) {
// to be used when not wanted
@@ -675,31 +664,6 @@ Variant Node::_rpc_unreliable_id_bind(const Variant **p_args, int p_argcount, Va
return Variant();
}
-#if 0
-Variant Node::_rpc_bind(const Variant** p_args, int p_argcount, Variant::CallError& r_error) {
-
- if (p_argcount<1) {
- r_error.error=Variant::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.argument=0;
- r_error.expected=Variant::STRING;
- return Variant();
- }
-
- StringName method = *p_args[0];
-
- rpcp(method,&p_args[1],p_argcount-1);
-
- r_error.error=Variant::CallError::CALL_OK;
- return Variant();
-}
-
-#endif
void Node::rpcp(int p_peer_id, bool p_unreliable, const StringName &p_method, const Variant **p_arg, int p_argcount) {
ERR_FAIL_COND(!is_inside_tree());
@@ -1353,20 +1317,24 @@ void Node::_add_child_nocheck(Node *p_child, const StringName &p_name) {
void Node::add_child(Node *p_child, bool p_legible_unique_name) {
ERR_FAIL_NULL(p_child);
- /* Fail if node has a parent */
+
if (p_child == this) {
- ERR_EXPLAIN("Can't add child " + p_child->get_name() + " to itself.")
+ ERR_EXPLAIN("Can't add child '" + p_child->get_name() + "' to itself.")
ERR_FAIL_COND(p_child == this); // adding to itself!
}
- ERR_EXPLAIN("Can't add child, already has a parent");
- ERR_FAIL_COND(p_child->data.parent);
+
+ /* Fail if node has a parent */
+ if (p_child->data.parent) {
+ ERR_EXPLAIN("Can't add child '" + p_child->get_name() + "' to '" + get_name() + "', already has a parent '" + p_child->data.parent->get_name() + "'.");
+ ERR_FAIL_COND(p_child->data.parent);
+ }
if (data.blocked > 0) {
- ERR_EXPLAIN("Parent node is busy setting up children, add_node() failed. Consider using call_deferred(\"add_child\",child) instead.");
+ ERR_EXPLAIN("Parent node is busy setting up children, add_node() failed. Consider using call_deferred(\"add_child\", child) instead.");
ERR_FAIL_COND(data.blocked > 0);
}
- ERR_EXPLAIN("Can't add child while a notification is happening");
+ ERR_EXPLAIN("Can't add child while a notification is happening.");
ERR_FAIL_COND(data.blocked > 0);
/* Validate name */
@@ -1381,7 +1349,7 @@ void Node::add_child_below_node(Node *p_node, Node *p_child, bool p_legible_uniq
if (is_a_parent_of(p_node)) {
move_child(p_child, p_node->get_position_in_parent() + 1);
} else {
- WARN_PRINTS("Cannot move under node " + p_node->get_name() + " as " + p_child->get_name() + " does not share a parent")
+ WARN_PRINTS("Cannot move under node " + p_node->get_name() + " as " + p_child->get_name() + " does not share a parent.")
}
}
@@ -1954,6 +1922,23 @@ void Node::propagate_notification(int p_notification) {
data.blocked--;
}
+void Node::propagate_call(const StringName &p_method, const Array &p_args, const bool p_parent_first) {
+
+ data.blocked++;
+
+ if (p_parent_first && has_method(p_method))
+ callv(p_method, p_args);
+
+ for (int i = 0; i < data.children.size(); i++) {
+ data.children[i]->propagate_call(p_method, p_args, p_parent_first);
+ }
+
+ if (!p_parent_first && has_method(p_method))
+ callv(p_method, p_args);
+
+ data.blocked--;
+}
+
void Node::_propagate_replace_owner(Node *p_owner, Node *p_by_owner) {
if (get_owner() == p_owner)
set_owner(p_by_owner);
@@ -2049,59 +2034,6 @@ HashMap<NodePath, int> Node::get_editable_instances() const {
return data.editable_instances;
}
-#if 0
-
-void Node::generate_instance_state() {
-
- List<PropertyInfo> properties;
- get_property_list(&properties);
-
- data.instance_state.clear();
-
- for( List<PropertyInfo>::Element *E=properties.front();E;E=E->next() ) {
-
- PropertyInfo &pi=E->get();
- if ((pi.usage&PROPERTY_USAGE_NO_INSTANCE_STATE) || !(pi.usage&PROPERTY_USAGE_EDITOR) || !(pi.usage&PROPERTY_USAGE_STORAGE))
- continue;
-
- data.instance_state[pi.name]=get(pi.name);
- }
-
- List<GroupInfo> groups;
- get_groups(&groups);
- for(List<GroupInfo>::Element *E=groups.front();E;E=E->next()) {
-
- if (!E->get().persistent)
- continue;
- data.instance_groups.push_back(E->get().name);
- }
-
- List<MethodInfo> signal_list;
-
- get_signal_list(&signal_list);
-
- for(List<MethodInfo>::Element *E=signal_list.front();E;E=E->next()) {
-
- StringName name = E->get().name;
- List<Connection> connections;
- get_signal_connection_list(name,&connections);
-
- for(List<Connection>::Element *F=connections.front();F;F=F->next()) {
-
- if (F->get().flags&CONNECT_PERSIST)
- data.instance_connections.push_back(F->get());
- }
-
- }
-}
-
-Dictionary Node::get_instance_state() const {
-
- return data.instance_state;
-}
-
-#endif
-
void Node::set_scene_instance_state(const Ref<SceneState> &p_state) {
data.instance_state = p_state;
@@ -2143,9 +2075,9 @@ Node *Node::_duplicate(int p_flags) const {
bool instanced = false;
- if (cast_to<InstancePlaceholder>()) {
+ if (Object::cast_to<InstancePlaceholder>(this)) {
- const InstancePlaceholder *ip = cast_to<const InstancePlaceholder>();
+ const InstancePlaceholder *ip = Object::cast_to<const InstancePlaceholder>(this);
InstancePlaceholder *nip = memnew(InstancePlaceholder);
nip->set_instance_path(ip->get_instance_path());
node = nip;
@@ -2163,7 +2095,7 @@ Node *Node::_duplicate(int p_flags) const {
Object *obj = ClassDB::instance(get_class());
ERR_FAIL_COND_V(!obj, NULL);
- node = obj->cast_to<Node>();
+ node = Object::cast_to<Node>(obj);
if (!node)
memdelete(obj);
ERR_FAIL_COND_V(!node, NULL);
@@ -2253,7 +2185,7 @@ void Node::_duplicate_and_reown(Node *p_new_parent, const Map<Node *, Node *> &p
print_line("could not duplicate: " + String(get_class()));
}
ERR_FAIL_COND(!obj);
- node = obj->cast_to<Node>();
+ node = Object::cast_to<Node>(obj);
if (!node)
memdelete(obj);
}
@@ -2309,7 +2241,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 = E->get().target->cast_to<Node>();
+ Node *target = Object::cast_to<Node>(E->get().target);
if (!target) {
continue;
}
@@ -2338,7 +2270,7 @@ Node *Node::duplicate_and_reown(const Map<Node *, Node *> &p_reown_map) const {
print_line("could not duplicate: " + String(get_class()));
}
ERR_FAIL_COND_V(!obj, NULL);
- node = obj->cast_to<Node>();
+ node = Object::cast_to<Node>(obj);
if (!node)
memdelete(obj);
ERR_FAIL_COND_V(!node, NULL);
@@ -2593,7 +2525,7 @@ void Node::_set_tree(SceneTree *p_tree) {
static void _Node_debug_sn(Object *p_obj) {
- Node *n = p_obj->cast_to<Node>();
+ Node *n = Object::cast_to<Node>(p_obj);
if (!n)
return;
@@ -2731,7 +2663,6 @@ void Node::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_name"), &Node::get_name);
ClassDB::bind_method(D_METHOD("add_child", "node", "legible_unique_name"), &Node::add_child, DEFVAL(false));
ClassDB::bind_method(D_METHOD("remove_child", "node"), &Node::remove_child);
- //ClassDB::bind_method(D_METHOD("remove_and_delete_child","node"),&Node::remove_and_delete_child);
ClassDB::bind_method(D_METHOD("get_child_count"), &Node::get_child_count);
ClassDB::bind_method(D_METHOD("get_children"), &Node::_get_children);
ClassDB::bind_method(D_METHOD("get_child", "idx"), &Node::get_child);
@@ -2761,6 +2692,7 @@ void Node::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_filename", "filename"), &Node::set_filename);
ClassDB::bind_method(D_METHOD("get_filename"), &Node::get_filename);
ClassDB::bind_method(D_METHOD("propagate_notification", "what"), &Node::propagate_notification);
+ ClassDB::bind_method(D_METHOD("propagate_call", "method", "args", "parent_first"), &Node::propagate_call, DEFVAL(Array()), DEFVAL(false));
ClassDB::bind_method(D_METHOD("set_fixed_process", "enable"), &Node::set_fixed_process);
ClassDB::bind_method(D_METHOD("get_fixed_process_delta_time"), &Node::get_fixed_process_delta_time);
ClassDB::bind_method(D_METHOD("is_fixed_processing"), &Node::is_fixed_processing);
@@ -2842,7 +2774,6 @@ void Node::_bind_methods() {
BIND_CONSTANT(NOTIFICATION_ENTER_TREE);
BIND_CONSTANT(NOTIFICATION_EXIT_TREE);
BIND_CONSTANT(NOTIFICATION_MOVED_IN_PARENT);
- //BIND_CONSTANT( NOTIFICATION_PARENT_DECONFIGURED );
BIND_CONSTANT(NOTIFICATION_READY);
BIND_CONSTANT(NOTIFICATION_FIXED_PROCESS);
BIND_CONSTANT(NOTIFICATION_PROCESS);
@@ -2858,20 +2789,20 @@ void Node::_bind_methods() {
BIND_CONSTANT(NOTIFICATION_INTERNAL_PROCESS);
BIND_CONSTANT(NOTIFICATION_INTERNAL_FIXED_PROCESS);
- BIND_CONSTANT(RPC_MODE_DISABLED);
- BIND_CONSTANT(RPC_MODE_REMOTE);
- BIND_CONSTANT(RPC_MODE_SYNC);
- BIND_CONSTANT(RPC_MODE_MASTER);
- BIND_CONSTANT(RPC_MODE_SLAVE);
+ BIND_ENUM_CONSTANT(RPC_MODE_DISABLED);
+ BIND_ENUM_CONSTANT(RPC_MODE_REMOTE);
+ BIND_ENUM_CONSTANT(RPC_MODE_SYNC);
+ BIND_ENUM_CONSTANT(RPC_MODE_MASTER);
+ BIND_ENUM_CONSTANT(RPC_MODE_SLAVE);
- BIND_CONSTANT(PAUSE_MODE_INHERIT);
- BIND_CONSTANT(PAUSE_MODE_STOP);
- BIND_CONSTANT(PAUSE_MODE_PROCESS);
+ BIND_ENUM_CONSTANT(PAUSE_MODE_INHERIT);
+ BIND_ENUM_CONSTANT(PAUSE_MODE_STOP);
+ BIND_ENUM_CONSTANT(PAUSE_MODE_PROCESS);
- BIND_CONSTANT(DUPLICATE_SIGNALS);
- BIND_CONSTANT(DUPLICATE_GROUPS);
- BIND_CONSTANT(DUPLICATE_SCRIPTS);
- BIND_CONSTANT(DUPLICATE_USE_INSTANCING);
+ BIND_ENUM_CONSTANT(DUPLICATE_SIGNALS);
+ BIND_ENUM_CONSTANT(DUPLICATE_GROUPS);
+ BIND_ENUM_CONSTANT(DUPLICATE_SCRIPTS);
+ BIND_ENUM_CONSTANT(DUPLICATE_USE_INSTANCING);
ADD_SIGNAL(MethodInfo("renamed"));
ADD_SIGNAL(MethodInfo("tree_entered"));