summaryrefslogtreecommitdiff
path: root/scene/main/scene_tree.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/main/scene_tree.cpp')
-rw-r--r--scene/main/scene_tree.cpp180
1 files changed, 51 insertions, 129 deletions
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 {