summaryrefslogtreecommitdiff
path: root/scene/main
diff options
context:
space:
mode:
Diffstat (limited to 'scene/main')
-rw-r--r--scene/main/canvas_layer.cpp4
-rw-r--r--scene/main/canvas_layer.h2
-rw-r--r--scene/main/http_request.cpp28
-rw-r--r--scene/main/http_request.h4
-rw-r--r--scene/main/instance_placeholder.cpp2
-rw-r--r--scene/main/instance_placeholder.h2
-rwxr-xr-xscene/main/node.cpp171
-rw-r--r--scene/main/node.h8
-rw-r--r--scene/main/resource_preloader.cpp2
-rw-r--r--scene/main/resource_preloader.h2
-rw-r--r--scene/main/scene_tree.cpp180
-rw-r--r--scene/main/scene_tree.h15
-rwxr-xr-xscene/main/timer.cpp10
-rwxr-xr-xscene/main/timer.h2
-rw-r--r--scene/main/viewport.cpp249
-rw-r--r--scene/main/viewport.h2
16 files changed, 244 insertions, 439 deletions
diff --git a/scene/main/canvas_layer.cpp b/scene/main/canvas_layer.cpp
index 77407fdde7..ce8714e574 100644
--- a/scene/main/canvas_layer.cpp
+++ b/scene/main/canvas_layer.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) */
@@ -201,7 +201,7 @@ void CanvasLayer::set_custom_viewport(Node *p_viewport) {
viewport = RID();
}
- custom_viewport = p_viewport->cast_to<Viewport>();
+ custom_viewport = Object::cast_to<Viewport>(p_viewport);
if (custom_viewport) {
custom_viewport_id = custom_viewport->get_instance_id();
diff --git a/scene/main/canvas_layer.h b/scene/main/canvas_layer.h
index b14a915fe8..fbee87f487 100644
--- a/scene/main/canvas_layer.h
+++ b/scene/main/canvas_layer.h
@@ -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) */
diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp
index a9b2dba186..1e1e4f2d5f 100644
--- a/scene/main/http_request.cpp
+++ b/scene/main/http_request.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) */
@@ -547,19 +547,19 @@ void HTTPRequest::_bind_methods() {
ADD_SIGNAL(MethodInfo("request_completed", PropertyInfo(Variant::INT, "result"), PropertyInfo(Variant::INT, "response_code"), PropertyInfo(Variant::POOL_STRING_ARRAY, "headers"), PropertyInfo(Variant::POOL_BYTE_ARRAY, "body")));
- BIND_CONSTANT(RESULT_SUCCESS);
- //BIND_CONSTANT( RESULT_NO_BODY );
- BIND_CONSTANT(RESULT_CHUNKED_BODY_SIZE_MISMATCH);
- BIND_CONSTANT(RESULT_CANT_CONNECT);
- BIND_CONSTANT(RESULT_CANT_RESOLVE);
- BIND_CONSTANT(RESULT_CONNECTION_ERROR);
- BIND_CONSTANT(RESULT_SSL_HANDSHAKE_ERROR);
- BIND_CONSTANT(RESULT_NO_RESPONSE);
- BIND_CONSTANT(RESULT_BODY_SIZE_LIMIT_EXCEEDED);
- BIND_CONSTANT(RESULT_REQUEST_FAILED);
- BIND_CONSTANT(RESULT_DOWNLOAD_FILE_CANT_OPEN);
- BIND_CONSTANT(RESULT_DOWNLOAD_FILE_WRITE_ERROR);
- BIND_CONSTANT(RESULT_REDIRECT_LIMIT_REACHED);
+ BIND_ENUM_CONSTANT(RESULT_SUCCESS);
+ //BIND_ENUM_CONSTANT( RESULT_NO_BODY );
+ BIND_ENUM_CONSTANT(RESULT_CHUNKED_BODY_SIZE_MISMATCH);
+ BIND_ENUM_CONSTANT(RESULT_CANT_CONNECT);
+ BIND_ENUM_CONSTANT(RESULT_CANT_RESOLVE);
+ BIND_ENUM_CONSTANT(RESULT_CONNECTION_ERROR);
+ BIND_ENUM_CONSTANT(RESULT_SSL_HANDSHAKE_ERROR);
+ BIND_ENUM_CONSTANT(RESULT_NO_RESPONSE);
+ BIND_ENUM_CONSTANT(RESULT_BODY_SIZE_LIMIT_EXCEEDED);
+ BIND_ENUM_CONSTANT(RESULT_REQUEST_FAILED);
+ BIND_ENUM_CONSTANT(RESULT_DOWNLOAD_FILE_CANT_OPEN);
+ BIND_ENUM_CONSTANT(RESULT_DOWNLOAD_FILE_WRITE_ERROR);
+ BIND_ENUM_CONSTANT(RESULT_REDIRECT_LIMIT_REACHED);
}
HTTPRequest::HTTPRequest() {
diff --git a/scene/main/http_request.h b/scene/main/http_request.h
index 6099d4e9bf..790ff5f7ef 100644
--- a/scene/main/http_request.h
+++ b/scene/main/http_request.h
@@ -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) */
@@ -137,4 +137,6 @@ public:
~HTTPRequest();
};
+VARIANT_ENUM_CAST(HTTPRequest::Result);
+
#endif // HTTPREQUEST_H
diff --git a/scene/main/instance_placeholder.cpp b/scene/main/instance_placeholder.cpp
index 5580ef486e..cbe30e05dd 100644
--- a/scene/main/instance_placeholder.cpp
+++ b/scene/main/instance_placeholder.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) */
diff --git a/scene/main/instance_placeholder.h b/scene/main/instance_placeholder.h
index ec4520e1c8..375c87a035 100644
--- a/scene/main/instance_placeholder.h
+++ b/scene/main/instance_placeholder.h
@@ -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) */
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"));
diff --git a/scene/main/node.h b/scene/main/node.h
index bb8d80a0c8..12d6310062 100644
--- a/scene/main/node.h
+++ b/scene/main/node.h
@@ -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) */
@@ -192,7 +192,6 @@ protected:
virtual void add_child_notify(Node *p_child);
virtual void remove_child_notify(Node *p_child);
virtual void move_child_notify(Node *p_child);
- //void remove_and_delete_child(Node *p_child);
void _propagate_replace_owner(Node *p_owner, Node *p_by_owner);
@@ -212,7 +211,6 @@ public:
NOTIFICATION_EXIT_TREE = 11,
NOTIFICATION_MOVED_IN_PARENT = 12,
NOTIFICATION_READY = 13,
- //NOTIFICATION_PARENT_DECONFIGURED =15, - it's confusing, it's going away
NOTIFICATION_PAUSED = 14,
NOTIFICATION_UNPAUSED = 15,
NOTIFICATION_FIXED_PROCESS = 16,
@@ -298,6 +296,8 @@ public:
void propagate_notification(int p_notification);
+ void propagate_call(const StringName &p_method, const Array &p_args = Array(), const bool p_parent_first = false);
+
/* PROCESSING */
void set_fixed_process(bool p_process);
float get_fixed_process_delta_time() const;
@@ -412,6 +412,8 @@ public:
~Node();
};
+VARIANT_ENUM_CAST(Node::DuplicateFlags);
+
typedef Set<Node *, Node::Comparator> NodeSet;
#endif
diff --git a/scene/main/resource_preloader.cpp b/scene/main/resource_preloader.cpp
index ae323ba021..35bb6ef7e8 100644
--- a/scene/main/resource_preloader.cpp
+++ b/scene/main/resource_preloader.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) */
diff --git a/scene/main/resource_preloader.h b/scene/main/resource_preloader.h
index a54781dc81..40e900a492 100644
--- a/scene/main/resource_preloader.h
+++ b/scene/main/resource_preloader.h
@@ -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) */
diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp
index 66eafa1070..65aeb23609 100644
--- a/scene/main/scene_tree.cpp
+++ b/scene/main/scene_tree.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) */
@@ -29,17 +29,15 @@
/*************************************************************************/
#include "scene_tree.h"
+#include "editor/editor_node.h"
+#include "io/marshalls.h"
+#include "io/resource_loader.h"
#include "message_queue.h"
#include "node.h"
#include "os/keyboard.h"
#include "os/os.h"
#include "print_string.h"
#include "project_settings.h"
-#include <stdio.h>
-//#include "servers/spatial_sound_2d_server.h"
-
-#include "io/marshalls.h"
-#include "io/resource_loader.h"
#include "scene/resources/material.h"
#include "scene/resources/mesh.h"
#include "scene/resources/packed_scene.h"
@@ -48,6 +46,8 @@
#include "servers/physics_server.h"
#include "viewport.h"
+#include <stdio.h>
+
void SceneTreeTimer::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_time_left", "time"), &SceneTreeTimer::set_time_left);
@@ -382,7 +382,7 @@ bool SceneTree::is_input_handled() {
void SceneTree::input_event(const Ref<InputEvent> &p_event) {
- if (is_editor_hint() && (p_event->cast_to<InputEventJoypadButton>() || p_event->cast_to<InputEventJoypadMotion>()))
+ if (Engine::get_singleton()->is_editor_hint() && (Object::cast_to<InputEventJoypadButton>(p_event.ptr()) || Object::cast_to<InputEventJoypadMotion>(*p_event)))
return; //avoid joy input on editor
root_lock++;
@@ -392,86 +392,11 @@ void SceneTree::input_event(const Ref<InputEvent> &p_event) {
Ref<InputEvent> ev = p_event;
ev->set_id(++last_id); //this should work better
-#if 0
- switch(ev.type) {
-
- case InputEvent::MOUSE_BUTTON: {
-
- Matrix32 ai = root->get_final_transform().affine_inverse();
- Vector2 g = ai.xform(Vector2(ev.mouse_button.global_x,ev.mouse_button.global_y));
- Vector2 l = ai.xform(Vector2(ev->get_pos().x,ev->get_pos().y));
- ev->get_pos().x=l.x;
- ev->get_pos().y=l.y;
- ev.mouse_button.global_x=g.x;
- ev.mouse_button.global_y=g.y;
-
- } break;
- case InputEvent::MOUSE_MOTION: {
-
- Matrix32 ai = root->get_final_transform().affine_inverse();
- Vector2 g = ai.xform(Vector2(ev.mouse_motion.global_x,ev.mouse_motion.global_y));
- Vector2 l = ai.xform(Vector2(ev.mouse_motion.x,ev.mouse_motion.y));
- Vector2 r = ai.xform(Vector2(ev->get_relative().x,ev->get_relative().y));
- ev.mouse_motion.x=l.x;
- ev.mouse_motion.y=l.y;
- ev.mouse_motion.global_x=g.x;
- ev.mouse_motion.global_y=g.y;
- ev->get_relative().x=r.x;
- ev->get_relative().y=r.y;
-
- } break;
- case InputEvent::SCREEN_TOUCH: {
-
- Matrix32 ai = root->get_final_transform().affine_inverse();
- Vector2 t = ai.xform(Vector2(ev.screen_touch.x,ev.screen_touch.y));
- ev.screen_touch.x=t.x;
- ev.screen_touch.y=t.y;
-
- } break;
- case InputEvent::SCREEN_DRAG: {
-
- Matrix32 ai = root->get_final_transform().affine_inverse();
- Vector2 t = ai.xform(Vector2(ev.screen_drag.x,ev.screen_drag.y));
- Vector2 r = ai.xform(Vector2(ev.screen_drag.relative_x,ev.screen_drag.relative_y));
- Vector2 s = ai.xform(Vector2(ev.screen_drag.speed_x,ev.screen_drag.speed_y));
- ev.screen_drag.x=t.x;
- ev.screen_drag.y=t.y;
- ev.screen_drag.relative_x=r.x;
- ev.screen_drag.relative_y=r.y;
- ev.screen_drag.speed_x=s.x;
- ev.screen_drag.speed_y=s.y;
- } break;
- }
-
-#endif
MainLoop::input_event(ev);
-#if 0
- _call_input_pause("input","_input",ev);
-
- call_group(GROUP_CALL_REVERSE|GROUP_CALL_REALTIME|GROUP_CALL_MULIILEVEL,"_gui_input","_gui_input",p_event); //special one for GUI, as controls use their own process check
-
- //call_group(GROUP_CALL_REVERSE|GROUP_CALL_REALTIME|GROUP_CALL_MULIILEVEL,"input","_input",ev);
-
- /*
- if (ev.type==InputEvent::KEY && ev->is_pressed() && !ev->is_echo() && ev->get_scancode()==KEY_F12) {
-
- print_line("RAM: "+itos(Memory::get_static_mem_usage()));
- print_line("DRAM: "+itos(Memory::get_dynamic_mem_usage()));
- }
- if (ev.type==InputEvent::KEY && ev->is_pressed() && !ev->is_echo() && ev->get_scancode()==KEY_F11) {
-
- Memory::dump_static_mem_to_file("memdump.txt");
- }
- */
-
- //transform for the rest
-#else
call_group_flags(GROUP_CALL_REALTIME, "_viewports", "_vp_input", ev); //special one for GUI, as controls use their own process check
-#endif
-
if (ScriptDebugger::get_singleton() && ScriptDebugger::get_singleton()->is_remote()) {
//quit from game window using F8
Ref<InputEventKey> k = ev;
@@ -482,28 +407,16 @@ void SceneTree::input_event(const Ref<InputEvent> &p_event) {
_flush_ugc();
root_lock--;
- MessageQueue::get_singleton()->flush(); //small little hack
+ //MessageQueue::get_singleton()->flush(); //flushing here causes UI and other places slowness
root_lock++;
if (!input_handled) {
-
-#if 0
- _call_input_pause("unhandled_input","_unhandled_input",ev);
- //call_group(GROUP_CALL_REVERSE|GROUP_CALL_REALTIME|GROUP_CALL_MULIILEVEL,"unhandled_input","_unhandled_input",ev);
- if (!input_handled && ev.type==InputEvent::KEY) {
- _call_input_pause("unhandled_key_input","_unhandled_key_input",ev);
- //call_group(GROUP_CALL_REVERSE|GROUP_CALL_REALTIME|GROUP_CALL_MULIILEVEL,"unhandled_key_input","_unhandled_key_input",ev);
- }
-#else
-
call_group_flags(GROUP_CALL_REALTIME, "_viewports", "_vp_unhandled_input", ev); //special one for GUI, as controls use their own process check
-
-#endif
input_handled = true;
_flush_ugc();
root_lock--;
- MessageQueue::get_singleton()->flush(); //small little hack
+ //MessageQueue::get_singleton()->flush(); //flushing here causes UI and other places slowness
} else {
input_handled = true;
root_lock--;
@@ -616,7 +529,7 @@ bool SceneTree::idle(float p_time) {
#ifdef TOOLS_ENABLED
- if (is_editor_hint()) {
+ if (Engine::get_singleton()->is_editor_hint()) {
//simple hack to reload fallback environment if it changed from editor
String env_path = ProjectSettings::get_singleton()->get("rendering/environment/default_environment");
env_path = env_path.strip_edges(); //user may have added a space or two
@@ -691,7 +604,7 @@ void SceneTree::_notification(int p_notification) {
get_root()->propagate_notification(p_notification);
} break;
case NOTIFICATION_TRANSLATION_CHANGED: {
- if (!is_editor_hint()) {
+ if (!Engine::get_singleton()->is_editor_hint()) {
get_root()->propagate_notification(Node::NOTIFICATION_TRANSLATION_CHANGED);
}
} break;
@@ -701,6 +614,19 @@ void SceneTree::_notification(int p_notification) {
} break;
+ case NOTIFICATION_WM_ABOUT: {
+
+#ifdef TOOLS_ENABLED
+ if (EditorNode::get_singleton()) {
+ EditorNode::get_singleton()->show_about();
+ } else {
+#endif
+ get_root()->propagate_notification(p_notification);
+#ifdef TOOLS_ENABLED
+ }
+#endif
+ } break;
+
default:
break;
};
@@ -717,19 +643,10 @@ void SceneTree::set_quit_on_go_back(bool p_enable) {
}
#ifdef TOOLS_ENABLED
-void SceneTree::set_editor_hint(bool p_enabled) {
-
- editor_hint = p_enabled;
-}
bool SceneTree::is_node_being_edited(const Node *p_node) const {
- return editor_hint && edited_scene_root && edited_scene_root->is_a_parent_of(p_node);
-}
-
-bool SceneTree::is_editor_hint() const {
-
- return editor_hint;
+ return Engine::get_singleton()->is_editor_hint() && edited_scene_root && edited_scene_root->is_a_parent_of(p_node);
}
#endif
@@ -1470,12 +1387,12 @@ void SceneTree::_live_edit_create_node_func(const NodePath &p_parent, const Stri
continue;
Node *n2 = n->get_node(p_parent);
- Object *o = ClassDB::instance(p_type);
- if (!o)
+ Node *no = Object::cast_to<Node>(ClassDB::instance(p_type));
+ if (!no) {
continue;
- Node *no = o->cast_to<Node>();
- no->set_name(p_name);
+ }
+ no->set_name(p_name);
n2->add_child(no);
}
}
@@ -1778,6 +1695,11 @@ Vector<int> SceneTree::get_network_connected_peers() const {
return ret;
}
+
+int SceneTree::get_rpc_sender_id() const {
+ return rpc_sender_id;
+}
+
void SceneTree::set_refuse_new_network_connections(bool p_refuse) {
ERR_FAIL_COND(!network_peer.is_valid());
network_peer->set_refuse_new_connections(p_refuse);
@@ -2172,7 +2094,9 @@ void SceneTree::_network_poll() {
ERR_PRINT("Error getting packet!");
}
+ rpc_sender_id = sender;
_network_process_packet(sender, packet, len);
+ rpc_sender_id = 0;
if (!network_peer.is_valid()) {
break; //it's also possible that a packet or RPC caused a disconnection, so also check here
@@ -2189,8 +2113,6 @@ void SceneTree::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_auto_accept_quit", "enabled"), &SceneTree::set_auto_accept_quit);
- ClassDB::bind_method(D_METHOD("set_editor_hint", "enable"), &SceneTree::set_editor_hint);
- ClassDB::bind_method(D_METHOD("is_editor_hint"), &SceneTree::is_editor_hint);
ClassDB::bind_method(D_METHOD("set_debug_collisions_hint", "enable"), &SceneTree::set_debug_collisions_hint);
ClassDB::bind_method(D_METHOD("is_debugging_collisions_hint"), &SceneTree::is_debugging_collisions_hint);
ClassDB::bind_method(D_METHOD("set_debug_navigation_hint", "enable"), &SceneTree::set_debug_navigation_hint);
@@ -2254,6 +2176,7 @@ void SceneTree::_bind_methods() {
ClassDB::bind_method(D_METHOD("has_network_peer"), &SceneTree::has_network_peer);
ClassDB::bind_method(D_METHOD("get_network_connected_peers"), &SceneTree::get_network_connected_peers);
ClassDB::bind_method(D_METHOD("get_network_unique_id"), &SceneTree::get_network_unique_id);
+ ClassDB::bind_method(D_METHOD("get_rpc_sender_id"), &SceneTree::get_rpc_sender_id);
ClassDB::bind_method(D_METHOD("set_refuse_new_network_connections", "refuse"), &SceneTree::set_refuse_new_network_connections);
ClassDB::bind_method(D_METHOD("is_refusing_new_network_connections"), &SceneTree::is_refusing_new_network_connections);
ClassDB::bind_method(D_METHOD("_network_peer_connected"), &SceneTree::_network_peer_connected);
@@ -2277,18 +2200,19 @@ void SceneTree::_bind_methods() {
ADD_SIGNAL(MethodInfo("connection_failed"));
ADD_SIGNAL(MethodInfo("server_disconnected"));
- BIND_CONSTANT(GROUP_CALL_DEFAULT);
- BIND_CONSTANT(GROUP_CALL_REVERSE);
- BIND_CONSTANT(GROUP_CALL_REALTIME);
- BIND_CONSTANT(GROUP_CALL_UNIQUE);
+ BIND_ENUM_CONSTANT(GROUP_CALL_DEFAULT);
+ BIND_ENUM_CONSTANT(GROUP_CALL_REVERSE);
+ BIND_ENUM_CONSTANT(GROUP_CALL_REALTIME);
+ BIND_ENUM_CONSTANT(GROUP_CALL_UNIQUE);
- BIND_CONSTANT(STRETCH_MODE_DISABLED);
- BIND_CONSTANT(STRETCH_MODE_2D);
- BIND_CONSTANT(STRETCH_MODE_VIEWPORT);
- BIND_CONSTANT(STRETCH_ASPECT_IGNORE);
- BIND_CONSTANT(STRETCH_ASPECT_KEEP);
- BIND_CONSTANT(STRETCH_ASPECT_KEEP_WIDTH);
- BIND_CONSTANT(STRETCH_ASPECT_KEEP_HEIGHT);
+ BIND_ENUM_CONSTANT(STRETCH_MODE_DISABLED);
+ BIND_ENUM_CONSTANT(STRETCH_MODE_2D);
+ BIND_ENUM_CONSTANT(STRETCH_MODE_VIEWPORT);
+
+ BIND_ENUM_CONSTANT(STRETCH_ASPECT_IGNORE);
+ BIND_ENUM_CONSTANT(STRETCH_ASPECT_KEEP);
+ BIND_ENUM_CONSTANT(STRETCH_ASPECT_KEEP_WIDTH);
+ BIND_ENUM_CONSTANT(STRETCH_ASPECT_KEEP_HEIGHT);
}
SceneTree *SceneTree::singleton = NULL;
@@ -2315,9 +2239,6 @@ SceneTree::SceneTree() {
accept_quit = true;
quit_on_go_back = true;
initialized = false;
-#ifdef TOOLS_ENABLED
- editor_hint = false;
-#endif
#ifdef DEBUG_ENABLED
debug_collisions_hint = false;
debug_navigation_hint = false;
@@ -2340,6 +2261,7 @@ SceneTree::SceneTree() {
call_lock = 0;
root_lock = 0;
node_count = 0;
+ rpc_sender_id = 0;
//create with mainloop
@@ -2387,7 +2309,7 @@ SceneTree::SceneTree() {
if (env.is_valid()) {
root->get_world()->set_fallback_environment(env);
} else {
- if (is_editor_hint()) {
+ if (Engine::get_singleton()->is_editor_hint()) {
//file was erased, clear the field.
ProjectSettings::get_singleton()->set("rendering/environment/default_environment", "");
} else {
diff --git a/scene/main/scene_tree.h b/scene/main/scene_tree.h
index 3543ebee90..594b806cef 100644
--- a/scene/main/scene_tree.h
+++ b/scene/main/scene_tree.h
@@ -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) */
@@ -111,9 +111,6 @@ private:
bool quit_on_go_back;
uint32_t last_id;
-#ifdef TOOLS_ENABLED
- bool editor_hint;
-#endif
#ifdef DEBUG_ENABLED
bool debug_collisions_hint;
bool debug_navigation_hint;
@@ -202,6 +199,8 @@ private:
void _connection_failed();
void _server_disconnected();
+ int rpc_sender_id;
+
//path sent caches
struct PathSentCache {
Map<int, bool> confirmed_peers;
@@ -363,14 +362,8 @@ public:
_FORCE_INLINE_ float get_idle_process_time() const { return idle_process_time; }
#ifdef TOOLS_ENABLED
- void set_editor_hint(bool p_enabled);
-
- bool is_editor_hint() const;
bool is_node_being_edited(const Node *p_node) const;
#else
- void set_editor_hint(bool p_enabled) {}
-
- bool is_editor_hint() const { return false; }
bool is_node_being_edited(const Node *p_node) const { return false; }
#endif
@@ -454,6 +447,7 @@ public:
bool has_network_peer() const;
int get_network_unique_id() const;
Vector<int> get_network_connected_peers() const;
+ int get_rpc_sender_id() const;
void set_refuse_new_network_connections(bool p_refuse);
bool is_refusing_new_network_connections() const;
@@ -465,5 +459,6 @@ public:
VARIANT_ENUM_CAST(SceneTree::StretchMode);
VARIANT_ENUM_CAST(SceneTree::StretchAspect);
+VARIANT_ENUM_CAST(SceneTree::CallGroupFlags);
#endif
diff --git a/scene/main/timer.cpp b/scene/main/timer.cpp
index a61d1100e6..df7d609ac0 100755
--- a/scene/main/timer.cpp
+++ b/scene/main/timer.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) */
@@ -29,6 +29,8 @@
/*************************************************************************/
#include "timer.h"
+#include "engine.h"
+
void Timer::_notification(int p_what) {
switch (p_what) {
@@ -37,7 +39,7 @@ void Timer::_notification(int p_what) {
if (autostart) {
#ifdef TOOLS_ENABLED
- if (get_tree()->is_editor_hint() && get_tree()->get_edited_scene_root() && (get_tree()->get_edited_scene_root() == this || get_tree()->get_edited_scene_root()->is_a_parent_of(this)))
+ if (Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && (get_tree()->get_edited_scene_root() == this || get_tree()->get_edited_scene_root()->is_a_parent_of(this)))
break;
#endif
start();
@@ -202,8 +204,8 @@ void Timer::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "one_shot"), "set_one_shot", "is_one_shot");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "autostart"), "set_autostart", "has_autostart");
- BIND_CONSTANT(TIMER_PROCESS_FIXED);
- BIND_CONSTANT(TIMER_PROCESS_IDLE);
+ BIND_ENUM_CONSTANT(TIMER_PROCESS_FIXED);
+ BIND_ENUM_CONSTANT(TIMER_PROCESS_IDLE);
}
Timer::Timer() {
diff --git a/scene/main/timer.h b/scene/main/timer.h
index dd4711ec37..0cd92f12de 100755
--- a/scene/main/timer.h
+++ b/scene/main/timer.h
@@ -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) */
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index a22d897669..02da926e50 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.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,28 +28,23 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "viewport.h"
+
#include "os/input.h"
#include "os/os.h"
-#include "scene/3d/spatial.h"
-#include "servers/physics_2d_server.h"
-//#include "scene/3d/camera.h"
-
+#include "project_settings.h"
+#include "scene/2d/collision_object_2d.h"
#include "scene/3d/camera.h"
#include "scene/3d/collision_object.h"
#include "scene/3d/listener.h"
-#include "scene/3d/spatial_indexer.h"
+#include "scene/3d/scenario_fx.h"
+#include "scene/3d/spatial.h"
#include "scene/gui/control.h"
-#include "scene/resources/mesh.h"
-
-#include "scene/2d/collision_object_2d.h"
-
#include "scene/gui/label.h"
#include "scene/gui/panel.h"
#include "scene/main/timer.h"
+#include "scene/resources/mesh.h"
#include "scene/scene_string_names.h"
-
-#include "project_settings.h"
-#include "scene/3d/scenario_fx.h"
+#include "servers/physics_2d_server.h"
void ViewportTexture::setup_local_to_scene() {
@@ -68,7 +63,7 @@ void ViewportTexture::setup_local_to_scene() {
ERR_EXPLAIN("ViewportTexture: Path to node is invalid");
ERR_FAIL_COND(!vpn);
- vp = vpn->cast_to<Viewport>();
+ vp = Object::cast_to<Viewport>(vpn);
ERR_EXPLAIN("ViewportTexture: Path to node does not point to a viewport");
ERR_FAIL_COND(!vp);
@@ -337,22 +332,18 @@ void Viewport::_test_new_mouseover(ObjectID new_collider) {
if (new_collider != physics_object_over) {
if (physics_object_over) {
- Object *obj = ObjectDB::get_instance(physics_object_over);
- if (obj) {
- CollisionObject *co = obj->cast_to<CollisionObject>();
- if (co) {
- co->_mouse_exit();
- }
+
+ CollisionObject *co = Object::cast_to<CollisionObject>(ObjectDB::get_instance(physics_object_over));
+ if (co) {
+ co->_mouse_exit();
}
}
if (new_collider) {
- Object *obj = ObjectDB::get_instance(new_collider);
- if (obj) {
- CollisionObject *co = obj->cast_to<CollisionObject>();
- if (co) {
- co->_mouse_enter();
- }
+
+ CollisionObject *co = Object::cast_to<CollisionObject>(ObjectDB::get_instance(new_collider));
+ if (co) {
+ co->_mouse_enter();
}
}
@@ -399,7 +390,7 @@ void Viewport::_notification(int p_what) {
contact_3d_debug_instance = VisualServer::get_singleton()->instance_create();
VisualServer::get_singleton()->instance_set_base(contact_3d_debug_instance, contact_3d_debug_multimesh);
VisualServer::get_singleton()->instance_set_scenario(contact_3d_debug_instance, find_world()->get_scenario());
- VisualServer::get_singleton()->instance_geometry_set_flag(contact_3d_debug_instance, VS::INSTANCE_FLAG_VISIBLE_IN_ALL_ROOMS, true);
+ //VisualServer::get_singleton()->instance_geometry_set_flag(contact_3d_debug_instance, VS::INSTANCE_FLAG_VISIBLE_IN_ALL_ROOMS, true);
}
VS::get_singleton()->viewport_set_active(viewport, true);
@@ -552,7 +543,7 @@ void Viewport::_notification(int p_what) {
for (int i = 0; i < rc; i++) {
if (res[i].collider_id && res[i].collider) {
- CollisionObject2D *co = res[i].collider->cast_to<CollisionObject2D>();
+ CollisionObject2D *co = Object::cast_to<CollisionObject2D>(res[i].collider);
if (co) {
Map<ObjectID, uint64_t>::Element *E = physics_2d_mouseover.find(res[i].collider_id);
@@ -575,7 +566,7 @@ void Viewport::_notification(int p_what) {
Object *o = ObjectDB::get_instance(E->key());
if (o) {
- CollisionObject2D *co = o->cast_to<CollisionObject2D>();
+ CollisionObject2D *co = Object::cast_to<CollisionObject2D>(o);
if (co) {
co->_mouse_exit();
}
@@ -595,19 +586,14 @@ void Viewport::_notification(int p_what) {
if (physics_object_capture != 0) {
- Object *obj = ObjectDB::get_instance(physics_object_capture);
- if (obj) {
- CollisionObject *co = obj->cast_to<CollisionObject>();
- if (co) {
- co->_input_event(camera, ev, Vector3(), Vector3(), 0);
- captured = true;
- if (mb.is_valid() && mb->get_button_index() == 1 && !mb->is_pressed()) {
- physics_object_capture = 0;
- }
-
- } else {
+ CollisionObject *co = Object::cast_to<CollisionObject>(ObjectDB::get_instance(physics_object_capture));
+ if (co) {
+ co->_input_event(camera, ev, Vector3(), Vector3(), 0);
+ captured = true;
+ if (mb.is_valid() && mb->get_button_index() == 1 && !mb->is_pressed()) {
physics_object_capture = 0;
}
+
} else {
physics_object_capture = 0;
}
@@ -640,18 +626,15 @@ void Viewport::_notification(int p_what) {
ObjectID new_collider = 0;
if (col) {
- if (result.collider) {
-
- CollisionObject *co = result.collider->cast_to<CollisionObject>();
- if (co) {
+ CollisionObject *co = Object::cast_to<CollisionObject>(result.collider);
+ if (co) {
- co->_input_event(camera, ev, result.position, result.normal, result.shape);
- last_object = co;
- last_id = result.collider_id;
- new_collider = last_id;
- if (co->get_capture_input_on_drag() && mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed()) {
- physics_object_capture = last_id;
- }
+ co->_input_event(camera, ev, result.position, result.normal, result.shape);
+ last_object = co;
+ last_id = result.collider_id;
+ new_collider = last_id;
+ if (co->get_capture_input_on_drag() && mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed()) {
+ physics_object_capture = last_id;
}
}
}
@@ -678,11 +661,9 @@ void Viewport::_notification(int p_what) {
bool col = space->intersect_ray(from, from + dir * 10000, result, Set<RID>(), 0xFFFFFFFF, 0xFFFFFFFF, true);
ObjectID new_collider = 0;
if (col) {
- if (result.collider) {
- CollisionObject *co = result.collider->cast_to<CollisionObject>();
- if (co) {
- new_collider = result.collider_id;
- }
+ CollisionObject *co = Object::cast_to<CollisionObject>(result.collider);
+ if (co) {
+ new_collider = result.collider_id;
}
}
@@ -750,7 +731,7 @@ Size2 Viewport::get_size() const {
void Viewport::_update_listener() {
/*
- if (is_inside_tree() && audio_listener && (camera || listener) && (!get_parent() || (get_parent()->cast_to<Control>() && get_parent()->cast_to<Control>()->is_visible_in_tree()))) {
+ if (is_inside_tree() && audio_listener && (camera || listener) && (!get_parent() || (Object::cast_to<Control>(get_parent()) && Object::cast_to<Control>(get_parent())->is_visible_in_tree()))) {
SpatialSoundServer::get_singleton()->listener_set_space(internal_listener, find_world()->get_sound_space());
} else {
SpatialSoundServer::get_singleton()->listener_set_space(internal_listener, RID());
@@ -761,7 +742,7 @@ void Viewport::_update_listener() {
void Viewport::_update_listener_2d() {
/*
- if (is_inside_tree() && audio_listener && (!get_parent() || (get_parent()->cast_to<Control>() && get_parent()->cast_to<Control>()->is_visible_in_tree())))
+ if (is_inside_tree() && audio_listener && (!get_parent() || (Object::cast_to<Control>(get_parent()) && Object::cast_to<Control>(get_parent())->is_visible_in_tree())))
SpatialSound2DServer::get_singleton()->listener_set_space(internal_listener_2d, find_world_2d()->get_sound_space());
else
SpatialSound2DServer::get_singleton()->listener_set_space(internal_listener_2d, RID());
@@ -1029,11 +1010,11 @@ void Viewport::_propagate_enter_world(Node *p_node) {
if (!p_node->is_inside_tree()) //may not have entered scene yet
return;
- if (p_node->cast_to<Spatial>() || p_node->cast_to<WorldEnvironment>()) {
+ if (Object::cast_to<Spatial>(p_node) || Object::cast_to<WorldEnvironment>(p_node)) {
p_node->notification(Spatial::NOTIFICATION_ENTER_WORLD);
} else {
- Viewport *v = p_node->cast_to<Viewport>();
+ Viewport *v = Object::cast_to<Viewport>(p_node);
if (v) {
if (v->world.is_valid())
@@ -1053,7 +1034,7 @@ void Viewport::_propagate_viewport_notification(Node *p_node, int p_what) {
p_node->notification(p_what);
for (int i = 0; i < p_node->get_child_count(); i++) {
Node *c = p_node->get_child(i);
- if (c->cast_to<Viewport>())
+ if (Object::cast_to<Viewport>(c))
continue;
_propagate_viewport_notification(c, p_what);
}
@@ -1066,11 +1047,11 @@ void Viewport::_propagate_exit_world(Node *p_node) {
if (!p_node->is_inside_tree()) //may have exited scene already
return;
- if (p_node->cast_to<Spatial>() || p_node->cast_to<WorldEnvironment>()) {
+ if (Object::cast_to<Spatial>(p_node) || Object::cast_to<WorldEnvironment>(p_node)) {
p_node->notification(Spatial::NOTIFICATION_EXIT_WORLD);
} else {
- Viewport *v = p_node->cast_to<Viewport>();
+ Viewport *v = Object::cast_to<Viewport>(p_node);
if (v) {
if (v->world.is_valid())
@@ -1194,44 +1175,7 @@ bool Viewport::is_size_override_stretch_enabled() const {
return size_override_stretch;
}
-#if 0
-void Viewport::set_as_render_target(bool p_enable){
-
-/* if (render_target==p_enable)
- return;
-
- render_target=p_enable;
-
- VS::get_singleton()->viewport_set_as_render_target(viewport,p_enable);
- if (is_inside_tree()) {
-
- if (p_enable)
- _vp_exit_tree();
- else
- _vp_enter_tree();
- }
-
- if (p_enable) {
-
- texture_rid = VS::get_singleton()->viewport_get_texture(viewport);
- } else {
-
- texture_rid=RID();
- }
-
- texture->set_flags(texture->flags);
- texture->emit_changed();
-
- update_configuration_warning();
- */
-}
-
-bool Viewport::is_set_as_render_target() const{
- return render_target;
-
-}
-#endif
void Viewport::set_update_mode(UpdateMode p_mode) {
update_mode = p_mode;
@@ -1241,7 +1185,6 @@ Viewport::UpdateMode Viewport::get_update_mode() const {
return update_mode;
}
-//RID get_texture() const;
Ref<ViewportTexture> Viewport::get_texture() const {
@@ -1354,7 +1297,7 @@ void Viewport::_vp_input(const Ref<InputEvent> &p_ev) {
return;
#ifdef TOOLS_ENABLED
- if (get_tree()->is_editor_hint() && get_tree()->get_edited_scene_root() && get_tree()->get_edited_scene_root()->is_a_parent_of(this)) {
+ if (Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && get_tree()->get_edited_scene_root()->is_a_parent_of(this)) {
return;
}
#endif
@@ -1374,7 +1317,7 @@ void Viewport::_vp_unhandled_input(const Ref<InputEvent> &p_ev) {
if (disable_input)
return;
#ifdef TOOLS_ENABLED
- if (get_tree()->is_editor_hint() && get_tree()->get_edited_scene_root() && get_tree()->get_edited_scene_root()->is_a_parent_of(this)) {
+ if (Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && get_tree()->get_edited_scene_root()->is_a_parent_of(this)) {
return;
}
#endif
@@ -1456,6 +1399,10 @@ void Viewport::_gui_show_tooltip() {
gui.tooltip_popup = NULL;
}
+ if (!gui.tooltip) {
+ return;
+ }
+
Control *rp = gui.tooltip->get_root_parent_control();
if (!rp)
return;
@@ -1510,12 +1457,12 @@ void Viewport::_gui_call_input(Control *p_control, const Ref<InputEvent> &p_inpu
mb->get_button_index() == BUTTON_WHEEL_LEFT ||
mb->get_button_index() == BUTTON_WHEEL_RIGHT));
- bool ismouse = ev.is_valid() || p_input->cast_to<InputEventMouseMotion>() != NULL;
+ bool ismouse = ev.is_valid() || Object::cast_to<InputEventMouseMotion>(*p_input) != NULL;
CanvasItem *ci = p_control;
while (ci) {
- Control *control = ci->cast_to<Control>();
+ Control *control = Object::cast_to<Control>(ci);
if (control) {
control->call_multilevel(SceneStringNames::get_singleton()->_gui_input, ev);
if (gui.key_event_accepted)
@@ -1588,10 +1535,10 @@ Control *Viewport::_gui_find_control(const Point2 &p_global) {
Control *Viewport::_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_global, const Transform2D &p_xform, Transform2D &r_inv_xform) {
- if (p_node->cast_to<Viewport>())
+ if (Object::cast_to<Viewport>(p_node))
return NULL;
- Control *c = p_node->cast_to<Control>();
+ Control *c = Object::cast_to<Control>(p_node);
if (c) {
//print_line("at "+String(c->get_path())+" POS "+c->get_position()+" bt "+p_xform);
@@ -1616,7 +1563,7 @@ Control *Viewport::_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_
if (p_node == gui.tooltip_popup)
continue;
- CanvasItem *ci = p_node->get_child(i)->cast_to<CanvasItem>();
+ CanvasItem *ci = Object::cast_to<CanvasItem>(p_node->get_child(i));
if (!ci || ci->is_set_as_toplevel())
continue;
@@ -1645,7 +1592,7 @@ bool Viewport::_gui_drop(Control *p_at_control, Point2 p_at_pos, bool p_just_che
CanvasItem *ci = p_at_control;
while (ci) {
- Control *control = ci->cast_to<Control>();
+ Control *control = Object::cast_to<Control>(ci);
if (control) {
if (control->can_drop_data(p_at_pos, gui.drag_data)) {
@@ -1770,7 +1717,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
CanvasItem *ci = gui.mouse_focus;
while (ci) {
- Control *control = ci->cast_to<Control>();
+ Control *control = Object::cast_to<Control>(ci);
if (control) {
if (control->get_focus_mode() != Control::FOCUS_NONE) {
if (control != gui.key_focus) {
@@ -1891,7 +1838,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
CanvasItem *ci = gui.mouse_focus;
while (ci) {
- Control *control = ci->cast_to<Control>();
+ Control *control = Object::cast_to<Control>(ci);
if (control) {
gui.drag_data = control->get_drag_data(control->get_global_transform_with_canvas().affine_inverse().xform(mpos) - gui.drag_accum);
@@ -2236,7 +2183,7 @@ void Viewport::_gui_remove_from_modal_stack(List<Control *>::Element *MI, Object
if (!next) { //top of stack
Object *pfo = ObjectDB::get_instance(p_prev_focus_owner);
- Control *pfoc = pfo->cast_to<Control>();
+ Control *pfoc = Object::cast_to<Control>(pfo);
if (!pfoc)
return;
@@ -2266,7 +2213,7 @@ void Viewport::_gui_force_drag(Control *p_base, const Variant &p_data, Control *
void Viewport::_gui_set_drag_preview(Control *p_base, Control *p_control) {
ERR_FAIL_NULL(p_control);
- ERR_FAIL_COND(!((Object *)p_control)->cast_to<Control>());
+ ERR_FAIL_COND(!Object::cast_to<Control>((Object *)p_control));
ERR_FAIL_COND(p_control->is_inside_tree());
ERR_FAIL_COND(p_control->get_parent() != NULL);
@@ -2441,14 +2388,18 @@ void Viewport::unhandled_input(const Ref<InputEvent> &p_event) {
get_tree()->_call_input_pause(unhandled_input_group, "_unhandled_input", p_event);
//call_group(GROUP_CALL_REVERSE|GROUP_CALL_REALTIME|GROUP_CALL_MULIILEVEL,"unhandled_input","_unhandled_input",ev);
- if (!get_tree()->input_handled && p_event->cast_to<InputEventKey>() != NULL) {
+ if (!get_tree()->input_handled && Object::cast_to<InputEventKey>(*p_event) != NULL) {
get_tree()->_call_input_pause(unhandled_key_input_group, "_unhandled_key_input", p_event);
//call_group(GROUP_CALL_REVERSE|GROUP_CALL_REALTIME|GROUP_CALL_MULIILEVEL,"unhandled_key_input","_unhandled_key_input",ev);
}
if (physics_object_picking && !get_tree()->input_handled) {
- if (Input::get_singleton()->get_mouse_mode() != Input::MOUSE_MODE_CAPTURED && (p_event->cast_to<InputEventMouseButton>() || p_event->cast_to<InputEventMouseMotion>() || p_event->cast_to<InputEventScreenDrag>() || p_event->cast_to<InputEventScreenTouch>())) {
+ if (Input::get_singleton()->get_mouse_mode() != Input::MOUSE_MODE_CAPTURED &&
+ (Object::cast_to<InputEventMouseButton>(*p_event) ||
+ Object::cast_to<InputEventMouseMotion>(*p_event) ||
+ Object::cast_to<InputEventScreenDrag>(*p_event) ||
+ Object::cast_to<InputEventScreenTouch>(*p_event))) {
physics_picking_events.push_back(p_event);
}
}
@@ -2563,7 +2514,7 @@ Control *Viewport::get_modal_stack_top() const {
String Viewport::get_configuration_warning() const {
- /*if (get_parent() && !get_parent()->cast_to<Control>() && !render_target) {
+ /*if (get_parent() && !Object::cast_to<Control>(get_parent()) && !render_target) {
return TTR("This viewport is not set as render target. If you intend for it to display its contents directly to the screen, make it a child of a Control so it can obtain a size. Otherwise, make it a RenderTarget and assign its internal texture to some node for display.");
}*/
@@ -2741,7 +2692,7 @@ void Viewport::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "arvr"), "set_use_arvr", "use_arvr");
- ADD_PROPERTY(PropertyInfo(Variant::RECT2, "size"), "set_size", "get_size");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "own_world"), "set_use_own_world", "is_using_own_world");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "world", PROPERTY_HINT_RESOURCE_TYPE, "World"), "set_world", "get_world");
//ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"world_2d",PROPERTY_HINT_RESOURCE_TYPE,"World2D"), "set_world_2d", "get_world_2d") ;
@@ -2772,38 +2723,38 @@ void Viewport::_bind_methods() {
ADD_SIGNAL(MethodInfo("size_changed"));
- BIND_CONSTANT(UPDATE_DISABLED);
- BIND_CONSTANT(UPDATE_ONCE);
- BIND_CONSTANT(UPDATE_WHEN_VISIBLE);
- BIND_CONSTANT(UPDATE_ALWAYS);
-
- BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_DISABLED);
- BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_1);
- BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_4);
- BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_16);
- BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_64);
- BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_256);
- BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_1024);
- BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_MAX);
-
- BIND_CONSTANT(RENDER_INFO_OBJECTS_IN_FRAME);
- BIND_CONSTANT(RENDER_INFO_VERTICES_IN_FRAME);
- BIND_CONSTANT(RENDER_INFO_MATERIAL_CHANGES_IN_FRAME);
- BIND_CONSTANT(RENDER_INFO_SHADER_CHANGES_IN_FRAME);
- BIND_CONSTANT(RENDER_INFO_SURFACE_CHANGES_IN_FRAME);
- BIND_CONSTANT(RENDER_INFO_DRAW_CALLS_IN_FRAME);
- BIND_CONSTANT(RENDER_INFO_MAX);
-
- BIND_CONSTANT(DEBUG_DRAW_DISABLED);
- BIND_CONSTANT(DEBUG_DRAW_UNSHADED);
- BIND_CONSTANT(DEBUG_DRAW_OVERDRAW);
- BIND_CONSTANT(DEBUG_DRAW_WIREFRAME);
-
- BIND_CONSTANT(MSAA_DISABLED);
- BIND_CONSTANT(MSAA_2X);
- BIND_CONSTANT(MSAA_4X);
- BIND_CONSTANT(MSAA_8X);
- BIND_CONSTANT(MSAA_16X);
+ BIND_ENUM_CONSTANT(UPDATE_DISABLED);
+ BIND_ENUM_CONSTANT(UPDATE_ONCE);
+ BIND_ENUM_CONSTANT(UPDATE_WHEN_VISIBLE);
+ BIND_ENUM_CONSTANT(UPDATE_ALWAYS);
+
+ BIND_ENUM_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_DISABLED);
+ BIND_ENUM_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_1);
+ BIND_ENUM_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_4);
+ BIND_ENUM_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_16);
+ BIND_ENUM_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_64);
+ BIND_ENUM_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_256);
+ BIND_ENUM_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_1024);
+ BIND_ENUM_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_MAX);
+
+ BIND_ENUM_CONSTANT(RENDER_INFO_OBJECTS_IN_FRAME);
+ BIND_ENUM_CONSTANT(RENDER_INFO_VERTICES_IN_FRAME);
+ BIND_ENUM_CONSTANT(RENDER_INFO_MATERIAL_CHANGES_IN_FRAME);
+ BIND_ENUM_CONSTANT(RENDER_INFO_SHADER_CHANGES_IN_FRAME);
+ BIND_ENUM_CONSTANT(RENDER_INFO_SURFACE_CHANGES_IN_FRAME);
+ BIND_ENUM_CONSTANT(RENDER_INFO_DRAW_CALLS_IN_FRAME);
+ BIND_ENUM_CONSTANT(RENDER_INFO_MAX);
+
+ BIND_ENUM_CONSTANT(DEBUG_DRAW_DISABLED);
+ BIND_ENUM_CONSTANT(DEBUG_DRAW_UNSHADED);
+ BIND_ENUM_CONSTANT(DEBUG_DRAW_OVERDRAW);
+ BIND_ENUM_CONSTANT(DEBUG_DRAW_WIREFRAME);
+
+ BIND_ENUM_CONSTANT(MSAA_DISABLED);
+ BIND_ENUM_CONSTANT(MSAA_2X);
+ BIND_ENUM_CONSTANT(MSAA_4X);
+ BIND_ENUM_CONSTANT(MSAA_8X);
+ BIND_ENUM_CONSTANT(MSAA_16X);
}
Viewport::Viewport() {
diff --git a/scene/main/viewport.h b/scene/main/viewport.h
index 83c989db54..f527fa4f5b 100644
--- a/scene/main/viewport.h
+++ b/scene/main/viewport.h
@@ -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) */