summaryrefslogtreecommitdiff
path: root/scene/main
diff options
context:
space:
mode:
Diffstat (limited to 'scene/main')
-rw-r--r--scene/main/canvas_layer.cpp6
-rw-r--r--scene/main/node.cpp200
-rw-r--r--scene/main/node.h22
-rw-r--r--scene/main/scene_main_loop.cpp152
-rw-r--r--scene/main/scene_main_loop.h24
-rw-r--r--scene/main/timer.cpp7
-rw-r--r--scene/main/viewport.cpp110
-rw-r--r--scene/main/viewport.h9
8 files changed, 324 insertions, 206 deletions
diff --git a/scene/main/canvas_layer.cpp b/scene/main/canvas_layer.cpp
index 5006f55daf..ae842577a9 100644
--- a/scene/main/canvas_layer.cpp
+++ b/scene/main/canvas_layer.cpp
@@ -144,7 +144,7 @@ void CanvasLayer::_notification(int p_what) {
switch(p_what) {
- case NOTIFICATION_ENTER_SCENE: {
+ case NOTIFICATION_ENTER_TREE: {
Node *n = this;
vp=NULL;
@@ -169,7 +169,7 @@ void CanvasLayer::_notification(int p_what) {
} break;
- case NOTIFICATION_EXIT_SCENE: {
+ case NOTIFICATION_EXIT_TREE: {
VisualServer::get_singleton()->viewport_remove_canvas(viewport,canvas->get_canvas());
viewport=RID();
@@ -180,7 +180,7 @@ void CanvasLayer::_notification(int p_what) {
Size2 CanvasLayer::get_viewport_size() const {
- if (!is_inside_scene())
+ if (!is_inside_tree())
return Size2(1,1);
Rect2 r = vp->get_visible_rect();
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index 5d89ee80f1..fbdc87a7cc 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -28,7 +28,6 @@
/*************************************************************************/
#include "node.h"
#include "print_string.h"
-#include "scene/io/scene_loader.h"
#include "message_queue.h"
#include "scene/scene_string_names.h"
#include "scene/resources/packed_scene.h"
@@ -65,7 +64,7 @@ void Node::_notification(int p_notification) {
}
} break;
- case NOTIFICATION_ENTER_SCENE: {
+ case NOTIFICATION_ENTER_TREE: {
if (data.pause_mode==PAUSE_MODE_INHERIT) {
@@ -84,12 +83,12 @@ void Node::_notification(int p_notification) {
if (data.unhandled_key_input)
add_to_group("_vp_unhandled_key_input"+itos(get_viewport()->get_instance_ID()));
- get_scene()->node_count++;
+ get_tree()->node_count++;
} break;
- case NOTIFICATION_EXIT_SCENE: {
+ case NOTIFICATION_EXIT_TREE: {
- get_scene()->node_count--;
+ get_tree()->node_count--;
if (data.input)
remove_from_group("_vp_input"+itos(get_viewport()->get_instance_ID()));
if (data.unhandled_input)
@@ -105,7 +104,7 @@ void Node::_notification(int p_notification) {
Variant::CallError err;
get_script_instance()->call_multilevel_reversed(SceneStringNames::get_singleton()->_ready,NULL,0);
}
- //emit_signal(SceneStringNames::get_singleton()->enter_scene);
+ //emit_signal(SceneStringNames::get_singleton()->enter_tree);
} break;
case NOTIFICATION_POSTINITIALIZE: {
@@ -151,11 +150,11 @@ void Node::_propagate_ready() {
}
-void Node::_propagate_enter_scene() {
- // this needs to happen to all childs before any ENTER_SCENE
+void Node::_propagate_enter_tree() {
+ // this needs to happen to all childs before any enter_tree
if (data.parent) {
- data.scene=data.parent->data.scene;
+ data.tree=data.parent->data.tree;
data.depth=data.parent->data.depth+1;
} else {
@@ -166,25 +165,25 @@ void Node::_propagate_enter_scene() {
if (!data.viewport)
data.viewport = data.parent->data.viewport;
- data.inside_scene=true;
+ data.inside_tree=true;
const StringName *K=NULL;
while ((K=data.grouped.next(K))) {
- data.scene->add_to_group(*K,this);
+ data.tree->add_to_group(*K,this);
}
- notification(NOTIFICATION_ENTER_SCENE);
+ notification(NOTIFICATION_ENTER_TREE);
if (get_script_instance()) {
Variant::CallError err;
- get_script_instance()->call_multilevel_reversed(SceneStringNames::get_singleton()->_enter_scene,NULL,0);
+ get_script_instance()->call_multilevel_reversed(SceneStringNames::get_singleton()->_enter_tree,NULL,0);
}
- emit_signal(SceneStringNames::get_singleton()->enter_scene);
+ emit_signal(SceneStringNames::get_singleton()->enter_tree);
data.blocked++;
@@ -192,8 +191,8 @@ void Node::_propagate_enter_scene() {
for (int i=0;i<data.children.size();i++) {
- if (!data.children[i]->is_inside_scene()) // could have been added in ENTER_SCENE
- data.children[i]->_propagate_enter_scene();
+ if (!data.children[i]->is_inside_tree()) // could have been added in enter_tree
+ data.children[i]->_propagate_enter_tree();
}
data.blocked--;
@@ -202,7 +201,7 @@ void Node::_propagate_enter_scene() {
-void Node::_propagate_exit_scene() {
+void Node::_propagate_exit_tree() {
//block while removing children
@@ -210,7 +209,7 @@ void Node::_propagate_exit_scene() {
for (int i=data.children.size()-1;i>=0;i--) {
- data.children[i]->_propagate_exit_scene();
+ data.children[i]->_propagate_exit_tree();
}
data.blocked--;
@@ -218,29 +217,29 @@ void Node::_propagate_exit_scene() {
if (get_script_instance()) {
Variant::CallError err;
- get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_exit_scene,NULL,0);
+ get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_exit_tree,NULL,0);
}
- emit_signal(SceneStringNames::get_singleton()->exit_scene);
+ emit_signal(SceneStringNames::get_singleton()->exit_tree);
- notification(NOTIFICATION_EXIT_SCENE,true);
- if (data.scene)
- data.scene->node_removed(this);
+ notification(NOTIFICATION_EXIT_TREE,true);
+ if (data.tree)
+ data.tree->node_removed(this);
// exit groups
const StringName *K=NULL;
while ((K=data.grouped.next(K))) {
- data.scene->remove_from_group(*K,this);
+ data.tree->remove_from_group(*K,this);
}
data.viewport = NULL;
- if (data.scene)
- data.scene->tree_changed();
+ if (data.tree)
+ data.tree->tree_changed();
- data.inside_scene=false;
- data.scene=NULL;
+ data.inside_tree=false;
+ data.tree=NULL;
data.depth=-1;
}
@@ -261,8 +260,8 @@ void Node::move_child(Node *p_child,int p_pos) {
data.children.remove( p_child->data.pos );
data.children.insert( p_pos, p_child );
- if (data.scene) {
- data.scene->tree_changed();
+ if (data.tree) {
+ data.tree->tree_changed();
}
data.blocked++;
@@ -272,6 +271,7 @@ void Node::move_child(Node *p_child,int p_pos) {
data.children[i]->data.pos=i;
}
// notification second
+ move_child_notify(p_child);
for (int i=0;i<data.children.size();i++) {
data.children[i]->notification( NOTIFICATION_MOVED_IN_PARENT );
@@ -311,6 +311,11 @@ void Node::remove_child_notify(Node *p_child) {
// to be used when not wanted
}
+void Node::move_child_notify(Node *p_child) {
+
+ // to be used when not wanted
+}
+
void Node::set_fixed_process(bool p_process) {
if (data.fixed_process==p_process)
@@ -334,7 +339,7 @@ void Node::set_pause_mode(PauseMode p_mode) {
bool prev_inherits=data.pause_mode==PAUSE_MODE_INHERIT;
data.pause_mode=p_mode;
- if (!is_inside_scene())
+ if (!is_inside_tree())
return; //pointless
if ((data.pause_mode==PAUSE_MODE_INHERIT) == prev_inherits)
return; ///nothing changed
@@ -373,10 +378,12 @@ void Node::_propagate_pause_owner(Node*p_owner) {
bool Node::can_process() const {
- ERR_FAIL_COND_V( !is_inside_scene(), false );
+ ERR_FAIL_COND_V( !is_inside_tree(), false );
- if (get_scene()->is_paused()) {
+ if (get_tree()->is_paused()) {
+ if (data.pause_mode==PAUSE_MODE_STOP)
+ return false;
if (data.pause_mode==PAUSE_MODE_PROCESS)
return true;
if (data.pause_mode==PAUSE_MODE_INHERIT) {
@@ -386,6 +393,9 @@ bool Node::can_process() const {
if (data.pause_owner->data.pause_mode==PAUSE_MODE_PROCESS)
return true;
+
+ if (data.pause_owner->data.pause_mode==PAUSE_MODE_STOP)
+ return false;
}
}
@@ -396,8 +406,8 @@ bool Node::can_process() const {
float Node::get_fixed_process_delta_time() const {
- if (data.scene)
- return data.scene->get_fixed_process_time();
+ if (data.tree)
+ return data.tree->get_fixed_process_time();
else
return 0;
}
@@ -420,8 +430,8 @@ void Node::set_process(bool p_idle_process) {
float Node::get_process_delta_time() const {
- if (data.scene)
- return data.scene->get_idle_process_time();
+ if (data.tree)
+ return data.tree->get_idle_process_time();
else
return 0;
}
@@ -443,7 +453,7 @@ void Node::set_process_input(bool p_enable) {
return;
data.input=p_enable;
- if (!is_inside_scene())
+ if (!is_inside_tree())
return;
if (p_enable)
@@ -463,7 +473,7 @@ void Node::set_process_unhandled_input(bool p_enable) {
if (p_enable==data.unhandled_input)
return;
data.unhandled_input=p_enable;
- if (!is_inside_scene())
+ if (!is_inside_tree())
return;
if (p_enable)
@@ -483,7 +493,7 @@ void Node::set_process_unhandled_key_input(bool p_enable) {
if (p_enable==data.unhandled_key_input)
return;
data.unhandled_key_input=p_enable;
- if (!is_inside_scene())
+ if (!is_inside_tree())
return;
if (p_enable)
@@ -521,10 +531,10 @@ void Node::set_name(const String& p_name) {
data.parent->_validate_child_name(this);
}
- if (is_inside_scene()) {
+ if (is_inside_tree()) {
emit_signal("renamed");
- get_scene()->tree_changed();
+ get_tree()->tree_changed();
}
}
@@ -631,8 +641,8 @@ void Node::_add_child_nocheck(Node* p_child,const StringName& p_name) {
data.children.push_back( p_child );
p_child->data.parent=this;
- if (data.scene) {
- p_child->_set_scene(data.scene);
+ if (data.tree) {
+ p_child->_set_tree(data.tree);
}
/* Notify */
@@ -720,7 +730,7 @@ void Node::remove_child(Node *p_child) {
//if (data.scene) { does not matter
- p_child->_set_scene(NULL);
+ p_child->_set_tree(NULL);
//}
remove_child_notify(p_child);
@@ -756,7 +766,7 @@ Node *Node::get_child(int p_index) const {
Node *Node::_get_node(const NodePath& p_path) const {
- ERR_FAIL_COND_V( !data.inside_scene && p_path.is_absolute(), NULL );
+ ERR_FAIL_COND_V( !data.inside_tree && p_path.is_absolute(), NULL );
Node *current=NULL;
Node *root=NULL;
@@ -852,8 +862,8 @@ bool Node::is_a_parent_of(const Node *p_node) const {
bool Node::is_greater_than(const Node *p_node) const {
ERR_FAIL_NULL_V(p_node,false);
- ERR_FAIL_COND_V( !data.inside_scene, false );
- ERR_FAIL_COND_V( !p_node->data.inside_scene, false );
+ ERR_FAIL_COND_V( !data.inside_tree, false );
+ ERR_FAIL_COND_V( !p_node->data.inside_tree, false );
ERR_FAIL_COND_V( data.depth<0, false);
ERR_FAIL_COND_V( p_node->data.depth<0, false);
@@ -1024,7 +1034,7 @@ NodePath Node::get_path_to(const Node *p_node) const {
NodePath Node::get_path() const {
- ERR_FAIL_COND_V(!is_inside_scene(),NodePath());
+ ERR_FAIL_COND_V(!is_inside_tree(),NodePath());
const Node *n = this;
Vector<StringName> path;
@@ -1053,8 +1063,8 @@ void Node::add_to_group(const StringName& p_identifier,bool p_persistent) {
GroupData gd;
- if (data.scene)
- data.scene->add_to_group(p_identifier,this);
+ if (data.tree)
+ data.tree->add_to_group(p_identifier,this);
gd.persistent=p_persistent;
@@ -1071,8 +1081,8 @@ void Node::remove_from_group(const StringName& p_identifier) {
ERR_FAIL_COND(!g);
- if (data.scene)
- data.scene->remove_from_group(p_identifier,this);
+ if (data.tree)
+ data.tree->remove_from_group(p_identifier,this);
data.grouped.erase(p_identifier);
@@ -1132,7 +1142,7 @@ void Node::_propagate_reverse_notification(int p_notification) {
void Node::_propagate_deferred_notification(int p_notification, bool p_reverse) {
- ERR_FAIL_COND(!is_inside_scene());
+ ERR_FAIL_COND(!is_inside_tree());
data.blocked++;
@@ -1235,7 +1245,7 @@ void Node::generate_instance_state() {
for( List<PropertyInfo>::Element *E=properties.front();E;E=E->next() ) {
PropertyInfo &pi=E->get();
- if (!(pi.usage&PROPERTY_USAGE_EDITOR) || !(pi.usage&PROPERTY_USAGE_STORAGE))
+ 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);
@@ -1425,6 +1435,20 @@ Node *Node::duplicate_and_reown(const Map<Node*,Node*>& p_reown_map) const {
node->set_name(get_name());
+ List<PropertyInfo> plist;
+
+ get_property_list(&plist);
+
+ for(List<PropertyInfo>::Element *E=plist.front();E;E=E->next()) {
+
+ if (!(E->get().usage&PROPERTY_USAGE_STORAGE))
+ continue;
+ String name = E->get().name;
+ node->set( name, get(name) );
+
+ }
+
+
for(int i=0;i<get_child_count();i++) {
get_child(i)->_duplicate_and_reown(node,p_reown_map);
@@ -1611,29 +1635,29 @@ Node *Node::get_node_and_resource(const NodePath& p_path,RES& r_res) const {
return node;
}
-void Node::_set_scene(SceneMainLoop *p_scene) {
+void Node::_set_tree(SceneTree *p_tree) {
- SceneMainLoop *tree_changed_a=NULL;
- SceneMainLoop *tree_changed_b=NULL;
+ SceneTree *tree_changed_a=NULL;
+ SceneTree *tree_changed_b=NULL;
// ERR_FAIL_COND(p_scene && data.parent && !data.parent->data.scene); //nobug if both are null
- if (data.scene) {
- _propagate_exit_scene();
+ if (data.tree) {
+ _propagate_exit_tree();
- tree_changed_a=data.scene;
+ tree_changed_a=data.tree;
}
- data.scene=p_scene;
+ data.tree=p_tree;
- if (data.scene) {
+ if (data.tree) {
- _propagate_enter_scene();
+ _propagate_enter_tree();
_propagate_ready(); //reverse_notification(NOTIFICATION_READY);
- tree_changed_b=data.scene;
+ tree_changed_b=data.tree;
}
@@ -1651,7 +1675,7 @@ static void _Node_debug_sn(Object *p_obj) {
if (!n)
return;
- if (n->is_inside_scene())
+ if (n->is_inside_tree())
return;
Node *p=n;
@@ -1683,8 +1707,8 @@ void Node::print_stray_nodes() {
void Node::queue_delete() {
- ERR_FAIL_COND( !is_inside_scene() );
- get_scene()->queue_delete(this);
+ ERR_FAIL_COND( !is_inside_tree() );
+ get_tree()->queue_delete(this);
}
Array Node::_get_children() const {
@@ -1712,6 +1736,26 @@ NodePath Node::get_import_path() const {
#endif
+static void _add_nodes_to_options(const Node *p_base,const Node *p_node,List<String>*r_options) {
+
+ if (p_node!=p_base && !p_node->get_owner())
+ return;
+ String n = p_base->get_path_to(p_node);
+ r_options->push_back("\""+n+"\"");
+ for(int i=0;i<p_node->get_child_count();i++) {
+ _add_nodes_to_options(p_base,p_node->get_child(i),r_options);
+ }
+}
+
+void Node::get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const {
+
+ String pf=p_function;
+ if ((pf=="has_node" || pf=="get_node") && p_idx==0) {
+
+ _add_nodes_to_options(this,this,r_options);
+ }
+ Object::get_argument_options(p_function,p_idx,r_options);
+}
void Node::_bind_methods() {
@@ -1729,7 +1773,7 @@ void Node::_bind_methods() {
ObjectTypeDB::bind_method(_MD("has_node_and_resource","path"),&Node::has_node_and_resource);
ObjectTypeDB::bind_method(_MD("get_node_and_resource","path"),&Node::_get_node_and_resource);
- ObjectTypeDB::bind_method(_MD("is_inside_scene"),&Node::is_inside_scene);
+ ObjectTypeDB::bind_method(_MD("is_inside_tree"),&Node::is_inside_tree);
ObjectTypeDB::bind_method(_MD("is_a_parent_of","node:Node"),&Node::is_a_parent_of);
ObjectTypeDB::bind_method(_MD("is_greater_than","node:Node"),&Node::is_greater_than);
ObjectTypeDB::bind_method(_MD("get_path"),&Node::get_path);
@@ -1766,7 +1810,7 @@ void Node::_bind_methods() {
ObjectTypeDB::bind_method(_MD("print_stray_nodes"),&Node::_print_stray_nodes);
ObjectTypeDB::bind_method(_MD("get_position_in_parent"),&Node::get_position_in_parent);
- ObjectTypeDB::bind_method(_MD("get_scene:SceneMainLoop"),&Node::get_scene);
+ ObjectTypeDB::bind_method(_MD("get_tree:SceneTree"),&Node::get_tree);
ObjectTypeDB::bind_method(_MD("duplicate:Node"),&Node::duplicate);
ObjectTypeDB::bind_method(_MD("replace_by","node:Node","keep_data"),&Node::replace_by,DEFVAL(false));
@@ -1781,8 +1825,8 @@ void Node::_bind_methods() {
#endif
- BIND_CONSTANT( NOTIFICATION_ENTER_SCENE );
- BIND_CONSTANT( NOTIFICATION_EXIT_SCENE );
+ 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 );
@@ -1799,8 +1843,8 @@ void Node::_bind_methods() {
BIND_CONSTANT( PAUSE_MODE_PROCESS );
ADD_SIGNAL( MethodInfo("renamed") );
- ADD_SIGNAL( MethodInfo("enter_scene") );
- ADD_SIGNAL( MethodInfo("exit_scene") );
+ ADD_SIGNAL( MethodInfo("enter_tree") );
+ ADD_SIGNAL( MethodInfo("exit_tree") );
// ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "process/process" ),_SCS("set_process"),_SCS("is_processing") );
// ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "process/fixed_process" ), _SCS("set_fixed_process"),_SCS("is_fixed_processing") );
@@ -1810,8 +1854,8 @@ void Node::_bind_methods() {
BIND_VMETHOD( MethodInfo("_process",PropertyInfo(Variant::REAL,"delta")) );
BIND_VMETHOD( MethodInfo("_fixed_process",PropertyInfo(Variant::REAL,"delta")) );
- BIND_VMETHOD( MethodInfo("_enter_scene") );
- BIND_VMETHOD( MethodInfo("_exit_scene") );
+ BIND_VMETHOD( MethodInfo("_enter_tree") );
+ BIND_VMETHOD( MethodInfo("_exit_tree") );
BIND_VMETHOD( MethodInfo("_ready") );
BIND_VMETHOD( MethodInfo("_input",PropertyInfo(Variant::INPUT_EVENT,"event")) );
BIND_VMETHOD( MethodInfo("_unhandled_input",PropertyInfo(Variant::INPUT_EVENT,"event")) );
@@ -1828,10 +1872,10 @@ Node::Node() {
data.depth=-1;
data.blocked=0;
data.parent=NULL;
- data.scene=NULL;
+ data.tree=NULL;
data.fixed_process=false;
data.idle_process=false;
- data.inside_scene=false;
+ data.inside_tree=false;
data.owner=NULL;
data.OW=NULL;
diff --git a/scene/main/node.h b/scene/main/node.h
index f1ecf497e0..47f49eb625 100644
--- a/scene/main/node.h
+++ b/scene/main/node.h
@@ -80,8 +80,8 @@ private:
int depth;
int blocked; // safeguard that throws an error when attempting to modify the tree in a harmful way while being traversed.
StringName name;
- SceneMainLoop *scene;
- bool inside_scene;
+ SceneTree *tree;
+ bool inside_tree;
#ifdef TOOLS_ENABLED
NodePath import_path; //path used when imported, used by scene editors to keep tracking
#endif
@@ -118,9 +118,9 @@ private:
void _propagate_reverse_notification(int p_notification);
void _propagate_deferred_notification(int p_notification, bool p_reverse);
- void _propagate_enter_scene();
+ void _propagate_enter_tree();
void _propagate_ready();
- void _propagate_exit_scene();
+ void _propagate_exit_tree();
void _propagate_validate_owner();
void _print_stray_nodes();
void _propagate_pause_owner(Node*p_owner);
@@ -130,9 +130,9 @@ private:
Array _get_children() const;
Array _get_groups() const;
-friend class SceneMainLoop;
+friend class SceneTree;
- void _set_scene(SceneMainLoop *p_scene);
+ void _set_tree(SceneTree *p_tree);
protected:
void _block() { data.blocked++; }
@@ -142,6 +142,7 @@ 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);
@@ -158,8 +159,8 @@ public:
enum {
// you can make your own, but don't use the same numbers as other notifications in other nodes
- NOTIFICATION_ENTER_SCENE=10,
- NOTIFICATION_EXIT_SCENE =11,
+ NOTIFICATION_ENTER_TREE=10,
+ NOTIFICATION_EXIT_TREE =11,
NOTIFICATION_MOVED_IN_PARENT =12,
NOTIFICATION_READY=13,
//NOTIFICATION_PARENT_DECONFIGURED =15, - it's confusing, it's going away
@@ -187,9 +188,9 @@ public:
Node *get_node_and_resource(const NodePath& p_path,RES& r_res) const;
Node *get_parent() const;
- _FORCE_INLINE_ SceneMainLoop *get_scene() const { ERR_FAIL_COND_V( !data.scene, NULL ); return data.scene; }
+ _FORCE_INLINE_ SceneTree *get_tree() const { ERR_FAIL_COND_V( !data.tree, NULL ); return data.tree; }
- _FORCE_INLINE_ bool is_inside_scene() const { return data.inside_scene; }
+ _FORCE_INLINE_ bool is_inside_tree() const { return data.inside_tree; }
bool is_a_parent_of(const Node *p_node) const;
bool is_greater_than(const Node *p_node) const;
@@ -283,6 +284,7 @@ public:
NodePath get_import_path() const;
#endif
+ void get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const;
_FORCE_INLINE_ Viewport *get_viewport() const { return data.viewport; }
diff --git a/scene/main/scene_main_loop.cpp b/scene/main/scene_main_loop.cpp
index bcdc50c880..ed3e419359 100644
--- a/scene/main/scene_main_loop.cpp
+++ b/scene/main/scene_main_loop.cpp
@@ -43,13 +43,13 @@
#include "viewport.h"
-void SceneMainLoop::tree_changed() {
+void SceneTree::tree_changed() {
tree_version++;
emit_signal(tree_changed_name);
}
-void SceneMainLoop::node_removed(Node *p_node) {
+void SceneTree::node_removed(Node *p_node) {
emit_signal(node_removed_name,p_node);
if (call_lock>0)
@@ -59,7 +59,7 @@ void SceneMainLoop::node_removed(Node *p_node) {
}
-void SceneMainLoop::add_to_group(const StringName& p_group, Node *p_node) {
+void SceneTree::add_to_group(const StringName& p_group, Node *p_node) {
Map<StringName,Group>::Element *E=group_map.find(p_group);
if (!E) {
@@ -74,7 +74,7 @@ void SceneMainLoop::add_to_group(const StringName& p_group, Node *p_node) {
E->get().last_tree_version=0;
}
-void SceneMainLoop::remove_from_group(const StringName& p_group, Node *p_node) {
+void SceneTree::remove_from_group(const StringName& p_group, Node *p_node) {
Map<StringName,Group>::Element *E=group_map.find(p_group);
ERR_FAIL_COND(!E);
@@ -85,7 +85,7 @@ void SceneMainLoop::remove_from_group(const StringName& p_group, Node *p_node) {
group_map.erase(E);
}
-void SceneMainLoop::_flush_transform_notifications() {
+void SceneTree::_flush_transform_notifications() {
SelfList<Node>* n = xform_change_list.first();
while(n) {
@@ -98,7 +98,7 @@ void SceneMainLoop::_flush_transform_notifications() {
}
}
-void SceneMainLoop::_flush_ugc() {
+void SceneTree::_flush_ugc() {
ugc_locked=true;
@@ -118,7 +118,7 @@ void SceneMainLoop::_flush_ugc() {
ugc_locked=false;
}
-void SceneMainLoop::_update_group_order(Group& g) {
+void SceneTree::_update_group_order(Group& g) {
if (g.last_tree_version==tree_version)
return;
@@ -134,7 +134,7 @@ void SceneMainLoop::_update_group_order(Group& g) {
}
-void SceneMainLoop::call_group(uint32_t p_call_flags,const StringName& p_group,const StringName& p_function,VARIANT_ARG_DECLARE) {
+void SceneTree::call_group(uint32_t p_call_flags,const StringName& p_group,const StringName& p_function,VARIANT_ARG_DECLARE) {
Map<StringName,Group>::Element *E=group_map.find(p_group);
if (!E)
@@ -216,7 +216,7 @@ void SceneMainLoop::call_group(uint32_t p_call_flags,const StringName& p_group,c
call_skip.clear();
}
-void SceneMainLoop::notify_group(uint32_t p_call_flags,const StringName& p_group,int p_notification) {
+void SceneTree::notify_group(uint32_t p_call_flags,const StringName& p_group,int p_notification) {
Map<StringName,Group>::Element *E=group_map.find(p_group);
if (!E)
@@ -266,7 +266,7 @@ void SceneMainLoop::notify_group(uint32_t p_call_flags,const StringName& p_group
call_skip.clear();
}
-void SceneMainLoop::set_group(uint32_t p_call_flags,const StringName& p_group,const String& p_name,const Variant& p_value) {
+void SceneTree::set_group(uint32_t p_call_flags,const StringName& p_group,const String& p_name,const Variant& p_value) {
Map<StringName,Group>::Element *E=group_map.find(p_group);
if (!E)
@@ -316,12 +316,12 @@ void SceneMainLoop::set_group(uint32_t p_call_flags,const StringName& p_group,co
call_skip.clear();
}
-void SceneMainLoop::set_input_as_handled() {
+void SceneTree::set_input_as_handled() {
input_handled=true;
}
-void SceneMainLoop::input_text( const String& p_text ) {
+void SceneTree::input_text( const String& p_text ) {
root_lock++;
@@ -330,16 +330,20 @@ void SceneMainLoop::input_text( const String& p_text ) {
}
-void SceneMainLoop::input_event( const InputEvent& p_event ) {
+void SceneTree::input_event( const InputEvent& p_event ) {
+ if (is_editor_hint() && (p_event.type==InputEvent::JOYSTICK_MOTION || p_event.type==InputEvent::JOYSTICK_BUTTON))
+ return; //avoid joy input on editor
+
root_lock++;
- last_id=p_event.ID;
+ //last_id=p_event.ID;
input_handled=false;
InputEvent ev = p_event;
+ ev.ID=++last_id; //this should work better
#if 0
switch(ev.type) {
@@ -393,7 +397,7 @@ void SceneMainLoop::input_event( const InputEvent& p_event ) {
#endif
- MainLoop::input_event(p_event);
+ MainLoop::input_event(ev);
#if 0
_call_input_pause("input","_input",ev);
@@ -415,7 +419,7 @@ void SceneMainLoop::input_event( const InputEvent& p_event ) {
//transform for the rest
#else
- call_group(GROUP_CALL_REALTIME,"_viewports","_vp_input",p_event); //special one for GUI, as controls use their own process check
+ call_group(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() && ev.type==InputEvent::KEY && ev.key.pressed && !ev.key.echo && ev.key.scancode==KEY_F8) {
@@ -440,7 +444,7 @@ void SceneMainLoop::input_event( const InputEvent& p_event ) {
}
#else
- call_group(GROUP_CALL_REALTIME,"_viewports","_vp_unhandled_input",p_event); //special one for GUI, as controls use their own process check
+ call_group(GROUP_CALL_REALTIME,"_viewports","_vp_unhandled_input",ev); //special one for GUI, as controls use their own process check
#endif
input_handled=true;
@@ -455,7 +459,7 @@ void SceneMainLoop::input_event( const InputEvent& p_event ) {
}
-void SceneMainLoop::init() {
+void SceneTree::init() {
//_quit=false;
accept_quit=true;
@@ -466,12 +470,12 @@ void SceneMainLoop::init() {
editor_hint=false;
pause=false;
- root->_set_scene(this);
+ root->_set_tree(this);
MainLoop::init();
}
-bool SceneMainLoop::iteration(float p_time) {
+bool SceneTree::iteration(float p_time) {
root_lock++;
@@ -496,7 +500,7 @@ bool SceneMainLoop::iteration(float p_time) {
return _quit;
}
-bool SceneMainLoop::idle(float p_time){
+bool SceneTree::idle(float p_time){
// print_line("ram: "+itos(OS::get_singleton()->get_static_memory_usage())+" sram: "+itos(OS::get_singleton()->get_dynamic_memory_usage()));
@@ -538,7 +542,7 @@ bool SceneMainLoop::idle(float p_time){
return _quit;
}
-void SceneMainLoop::finish() {
+void SceneTree::finish() {
_flush_delete_queue();
@@ -549,7 +553,7 @@ void SceneMainLoop::finish() {
MainLoop::finish();
if (root) {
- root->_set_scene(NULL);
+ root->_set_tree(NULL);
memdelete(root); //delete root
}
@@ -564,12 +568,12 @@ void SceneMainLoop::finish() {
}
-void SceneMainLoop::quit() {
+void SceneTree::quit() {
_quit=true;
}
-void SceneMainLoop::_notification(int p_notification) {
+void SceneTree::_notification(int p_notification) {
@@ -602,22 +606,22 @@ void SceneMainLoop::_notification(int p_notification) {
};
-void SceneMainLoop::set_auto_accept_quit(bool p_enable) {
+void SceneTree::set_auto_accept_quit(bool p_enable) {
accept_quit=p_enable;
}
-void SceneMainLoop::set_editor_hint(bool p_enabled) {
+void SceneTree::set_editor_hint(bool p_enabled) {
editor_hint=p_enabled;
}
-bool SceneMainLoop::is_editor_hint() const {
+bool SceneTree::is_editor_hint() const {
return editor_hint;
}
-void SceneMainLoop::set_pause(bool p_enabled) {
+void SceneTree::set_pause(bool p_enabled) {
if (p_enabled==pause)
return;
@@ -628,12 +632,12 @@ void SceneMainLoop::set_pause(bool p_enabled) {
get_root()->propagate_notification(p_enabled ? Node::NOTIFICATION_PAUSED : Node::NOTIFICATION_UNPAUSED);
}
-bool SceneMainLoop::is_paused() const {
+bool SceneTree::is_paused() const {
return pause;
}
-void SceneMainLoop::_call_input_pause(const StringName& p_group,const StringName& p_method,const InputEvent& p_input) {
+void SceneTree::_call_input_pause(const StringName& p_group,const StringName& p_method,const InputEvent& p_input) {
Map<StringName,Group>::Element *E=group_map.find(p_group);
if (!E)
@@ -678,7 +682,7 @@ void SceneMainLoop::_call_input_pause(const StringName& p_group,const StringName
call_skip.clear();
}
-void SceneMainLoop::_notify_group_pause(const StringName& p_group,int p_notification) {
+void SceneTree::_notify_group_pause(const StringName& p_group,int p_notification) {
Map<StringName,Group>::Element *E=group_map.find(p_group);
if (!E)
@@ -728,13 +732,13 @@ void SceneMainLoop::_update_listener_2d() {
}
*/
-uint32_t SceneMainLoop::get_last_event_id() const {
+uint32_t SceneTree::get_last_event_id() const {
return last_id;
}
-Variant SceneMainLoop::_call_group(const Variant** p_args, int p_argcount, Variant::CallError& r_error) {
+Variant SceneTree::_call_group(const Variant** p_args, int p_argcount, Variant::CallError& r_error) {
r_error.error=Variant::CallError::CALL_OK;
@@ -759,13 +763,13 @@ Variant SceneMainLoop::_call_group(const Variant** p_args, int p_argcount, Varia
}
-int64_t SceneMainLoop::get_frame() const {
+int64_t SceneTree::get_frame() const {
return current_frame;
}
-Array SceneMainLoop::_get_nodes_in_group(const StringName& p_group) {
+Array SceneTree::_get_nodes_in_group(const StringName& p_group) {
Array ret;
Map<StringName,Group>::Element *E=group_map.find(p_group);
@@ -788,7 +792,7 @@ Array SceneMainLoop::_get_nodes_in_group(const StringName& p_group) {
return ret;
}
-void SceneMainLoop::get_nodes_in_group(const StringName& p_group,List<Node*> *p_list) {
+void SceneTree::get_nodes_in_group(const StringName& p_group,List<Node*> *p_list) {
Map<StringName,Group>::Element *E=group_map.find(p_group);
@@ -818,9 +822,9 @@ static void _fill_array(Node *p_node, Array& array, int p_level) {
}
}
-void SceneMainLoop::_debugger_request_tree(void *self) {
+void SceneTree::_debugger_request_tree(void *self) {
- SceneMainLoop *sml = (SceneMainLoop *)self;
+ SceneTree *sml = (SceneTree *)self;
Array arr;
_fill_array(sml->root,arr,0);
@@ -828,7 +832,7 @@ void SceneMainLoop::_debugger_request_tree(void *self) {
}
-void SceneMainLoop::_flush_delete_queue() {
+void SceneTree::_flush_delete_queue() {
_THREAD_SAFE_METHOD_
@@ -842,7 +846,7 @@ void SceneMainLoop::_flush_delete_queue() {
}
}
-void SceneMainLoop::queue_delete(Object *p_object) {
+void SceneTree::queue_delete(Object *p_object) {
_THREAD_SAFE_METHOD_
ERR_FAIL_NULL(p_object);
@@ -850,13 +854,13 @@ void SceneMainLoop::queue_delete(Object *p_object) {
}
-int SceneMainLoop::get_node_count() const {
+int SceneTree::get_node_count() const {
return node_count;
}
-void SceneMainLoop::_update_root_rect() {
+void SceneTree::_update_root_rect() {
if (stretch_mode==STRETCH_MODE_DISABLED) {
@@ -959,7 +963,7 @@ void SceneMainLoop::_update_root_rect() {
}
-void SceneMainLoop::set_screen_stretch(StretchMode p_mode,StretchAspect p_aspect,const Size2 p_minsize) {
+void SceneTree::set_screen_stretch(StretchMode p_mode,StretchAspect p_aspect,const Size2 p_minsize) {
stretch_mode=p_mode;
stretch_aspect=p_aspect;
@@ -968,35 +972,51 @@ void SceneMainLoop::set_screen_stretch(StretchMode p_mode,StretchAspect p_aspect
}
-void SceneMainLoop::_bind_methods() {
+#ifdef TOOLS_ENABLED
+void SceneTree::set_edited_scene_root(Node *p_node) {
+ edited_scene_root=p_node;
+}
+
+Node *SceneTree::get_edited_scene_root() const {
+
+ return edited_scene_root;
+}
+#endif
+
+
+void SceneTree::_bind_methods() {
//ObjectTypeDB::bind_method(_MD("call_group","call_flags","group","method","arg1","arg2"),&SceneMainLoop::_call_group,DEFVAL(Variant()),DEFVAL(Variant()));
- ObjectTypeDB::bind_method(_MD("notify_group","call_flags","group","notification"),&SceneMainLoop::notify_group);
- ObjectTypeDB::bind_method(_MD("set_group","call_flags","group","property","value"),&SceneMainLoop::set_group);
+ ObjectTypeDB::bind_method(_MD("notify_group","call_flags","group","notification"),&SceneTree::notify_group);
+ ObjectTypeDB::bind_method(_MD("set_group","call_flags","group","property","value"),&SceneTree::set_group);
- ObjectTypeDB::bind_method(_MD("get_nodes_in_group"),&SceneMainLoop::_get_nodes_in_group);
+ ObjectTypeDB::bind_method(_MD("get_nodes_in_group"),&SceneTree::_get_nodes_in_group);
- ObjectTypeDB::bind_method(_MD("get_root:Viewport"),&SceneMainLoop::get_root);
+ ObjectTypeDB::bind_method(_MD("get_root:Viewport"),&SceneTree::get_root);
- ObjectTypeDB::bind_method(_MD("set_auto_accept_quit","enabled"),&SceneMainLoop::set_auto_accept_quit);
+ ObjectTypeDB::bind_method(_MD("set_auto_accept_quit","enabled"),&SceneTree::set_auto_accept_quit);
- ObjectTypeDB::bind_method(_MD("set_editor_hint","enable"),&SceneMainLoop::set_editor_hint);
- ObjectTypeDB::bind_method(_MD("is_editor_hint"),&SceneMainLoop::is_editor_hint);
+ ObjectTypeDB::bind_method(_MD("set_editor_hint","enable"),&SceneTree::set_editor_hint);
+ ObjectTypeDB::bind_method(_MD("is_editor_hint"),&SceneTree::is_editor_hint);
+#ifdef TOOLS_ENABLED
+ ObjectTypeDB::bind_method(_MD("set_edited_scene_root","scene"),&SceneTree::set_edited_scene_root);
+ ObjectTypeDB::bind_method(_MD("get_edited_scene_root"),&SceneTree::get_edited_scene_root);
+#endif
- ObjectTypeDB::bind_method(_MD("set_pause","enable"),&SceneMainLoop::set_pause);
- ObjectTypeDB::bind_method(_MD("is_paused"),&SceneMainLoop::is_paused);
- ObjectTypeDB::bind_method(_MD("set_input_as_handled"),&SceneMainLoop::set_input_as_handled);
+ ObjectTypeDB::bind_method(_MD("set_pause","enable"),&SceneTree::set_pause);
+ ObjectTypeDB::bind_method(_MD("is_paused"),&SceneTree::is_paused);
+ ObjectTypeDB::bind_method(_MD("set_input_as_handled"),&SceneTree::set_input_as_handled);
- ObjectTypeDB::bind_method(_MD("get_node_count"),&SceneMainLoop::get_node_count);
- ObjectTypeDB::bind_method(_MD("get_frame"),&SceneMainLoop::get_frame);
- ObjectTypeDB::bind_method(_MD("quit"),&SceneMainLoop::quit);
+ ObjectTypeDB::bind_method(_MD("get_node_count"),&SceneTree::get_node_count);
+ ObjectTypeDB::bind_method(_MD("get_frame"),&SceneTree::get_frame);
+ ObjectTypeDB::bind_method(_MD("quit"),&SceneTree::quit);
- ObjectTypeDB::bind_method(_MD("set_screen_stretch","mode","aspect","minsize"),&SceneMainLoop::set_screen_stretch);
+ ObjectTypeDB::bind_method(_MD("set_screen_stretch","mode","aspect","minsize"),&SceneTree::set_screen_stretch);
- ObjectTypeDB::bind_method(_MD("queue_delete","obj"),&SceneMainLoop::queue_delete);
+ ObjectTypeDB::bind_method(_MD("queue_delete","obj"),&SceneTree::queue_delete);
MethodInfo mi;
@@ -1010,7 +1030,7 @@ void SceneMainLoop::_bind_methods() {
defargs.push_back(Variant());
}
- ObjectTypeDB::bind_native_method(METHOD_FLAGS_DEFAULT,"call_group",&SceneMainLoop::_call_group,mi,defargs);
+ ObjectTypeDB::bind_native_method(METHOD_FLAGS_DEFAULT,"call_group",&SceneTree::_call_group,mi,defargs);
ADD_SIGNAL( MethodInfo("tree_changed") );
ADD_SIGNAL( MethodInfo("node_removed",PropertyInfo( Variant::OBJECT, "node") ) );
@@ -1031,14 +1051,14 @@ void SceneMainLoop::_bind_methods() {
}
-SceneMainLoop::SceneMainLoop() {
+SceneTree::SceneTree() {
_quit=false;
initialized=false;
tree_version=1;
fixed_process_time=1;
idle_process_time=1;
- last_id=0;
+ last_id=1;
root=NULL;
current_frame=0;
tree_changed_name="tree_changed";
@@ -1069,13 +1089,17 @@ SceneMainLoop::SceneMainLoop() {
root->set_physics_object_picking(GLOBAL_DEF("physics/enable_object_picking",true));
+#ifdef TOOLS_ENABLED
+ edited_scene_root=NULL;
+#endif
+
ADD_SIGNAL( MethodInfo("idle_frame"));
ADD_SIGNAL( MethodInfo("fixed_frame"));
}
-SceneMainLoop::~SceneMainLoop() {
+SceneTree::~SceneTree() {
}
diff --git a/scene/main/scene_main_loop.h b/scene/main/scene_main_loop.h
index 493644d2bc..31a823ab1a 100644
--- a/scene/main/scene_main_loop.h
+++ b/scene/main/scene_main_loop.h
@@ -41,16 +41,16 @@
*/
-class SceneMainLoop;
+class SceneTree;
class Node;
class Viewport;
-class SceneMainLoop : public MainLoop {
+class SceneTree : public MainLoop {
_THREAD_SAFE_CLASS_
- OBJ_TYPE( SceneMainLoop, MainLoop );
+ OBJ_TYPE( SceneTree, MainLoop );
public:
@@ -102,6 +102,9 @@ private:
int64_t current_frame;
int node_count;
+#ifdef TOOLS_ENABLED
+ Node *edited_scene_root;
+#endif
struct UGCall {
StringName group;
@@ -223,15 +226,22 @@ public:
void set_screen_stretch(StretchMode p_mode,StretchAspect p_aspect,const Size2 p_minsize);
+ //void change_scene(const String& p_path);
+ //Node *get_loaded_scene();
+
+#ifdef TOOLS_ENABLED
+ void set_edited_scene_root(Node *p_node);
+ Node *get_edited_scene_root() const;
+#endif
- SceneMainLoop();
- ~SceneMainLoop();
+ SceneTree();
+ ~SceneTree();
};
-VARIANT_ENUM_CAST( SceneMainLoop::StretchMode );
-VARIANT_ENUM_CAST( SceneMainLoop::StretchAspect );
+VARIANT_ENUM_CAST( SceneTree::StretchMode );
+VARIANT_ENUM_CAST( SceneTree::StretchAspect );
diff --git a/scene/main/timer.cpp b/scene/main/timer.cpp
index 25d1c8530e..f718a09577 100644
--- a/scene/main/timer.cpp
+++ b/scene/main/timer.cpp
@@ -36,8 +36,13 @@ void Timer::_notification(int p_what) {
case NOTIFICATION_READY: {
- if (autostart)
+ 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)))
+ break;
+#endif
start();
+ }
} break;
case NOTIFICATION_PROCESS: {
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 92dcef803c..e6c787cf9e 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -95,8 +95,8 @@ void Viewport::_update_stretch_transform() {
if (size_override_stretch && size_override) {
- print_line("sive override size "+size_override_size);
- print_line("rect size "+rect.size);
+ //print_line("sive override size "+size_override_size);
+ //print_line("rect size "+rect.size);
stretch_transform=Matrix32();
Size2 scale = rect.size/(size_override_size+size_override_margin*2);
stretch_transform.scale(scale);
@@ -113,7 +113,7 @@ void Viewport::_update_stretch_transform() {
void Viewport::_update_rect() {
- if (!is_inside_scene())
+ if (!is_inside_tree())
return;
Node *parent = get_parent();
@@ -135,7 +135,9 @@ void Viewport::_update_rect() {
}
vr.width=rect.size.width;
vr.height=rect.size.height;
+
VisualServer::get_singleton()->viewport_set_rect(viewport,vr);
+ last_vp_rect=rect;
if (canvas_item.is_valid()) {
VisualServer::get_singleton()->canvas_item_set_custom_rect(canvas_item,true,rect);
@@ -164,13 +166,16 @@ void Viewport::_parent_visibility_changed() {
Control *c = parent->cast_to<Control>();
VisualServer::get_singleton()->canvas_item_set_visible(canvas_item,c->is_visible());
+
+ _update_listener();
+ _update_listener_2d();
}
}
-void Viewport::_vp_enter_scene() {
+void Viewport::_vp_enter_tree() {
Node *parent = get_parent();
//none?
@@ -195,7 +200,7 @@ void Viewport::_vp_enter_scene() {
}
-void Viewport::_vp_exit_scene() {
+void Viewport::_vp_exit_tree() {
Node *parent = get_parent();
if (parent && parent->cast_to<Control>()) {
@@ -226,19 +231,19 @@ void Viewport::_vp_exit_scene() {
void Viewport::update_worlds() {
- if (!is_inside_scene())
+ if (!is_inside_tree())
return;
Rect2 xformed_rect = (global_canvas_transform * canvas_transform).affine_inverse().xform(get_visible_rect());
find_world_2d()->_update_viewport(this,xformed_rect);
find_world_2d()->_update();
- find_world()->_update(get_scene()->get_frame());
+ find_world()->_update(get_tree()->get_frame());
}
void Viewport::_test_new_mouseover(ObjectID new_collider) {
-
+#ifndef _3D_DISABLED
if (new_collider!=physics_object_over) {
if (physics_object_over) {
@@ -266,7 +271,7 @@ void Viewport::_test_new_mouseover(ObjectID new_collider) {
physics_object_over=new_collider;
}
-
+#endif
}
@@ -275,11 +280,11 @@ void Viewport::_notification(int p_what) {
switch( p_what ) {
- case NOTIFICATION_ENTER_SCENE: {
+ case NOTIFICATION_ENTER_TREE: {
if (!render_target)
- _vp_enter_scene();
+ _vp_enter_tree();
this->parent=NULL;
Node *parent=get_parent();
@@ -329,7 +334,7 @@ void Viewport::_notification(int p_what) {
}
#endif
} break;
- case NOTIFICATION_EXIT_SCENE: {
+ case NOTIFICATION_EXIT_TREE: {
@@ -337,7 +342,7 @@ void Viewport::_notification(int p_what) {
world_2d->_remove_viewport(this);
if (!render_target)
- _vp_exit_scene();
+ _vp_exit_tree();
VisualServer::get_singleton()->viewport_set_scenario(viewport,RID());
SpatialSoundServer::get_singleton()->listener_set_space(listener,RID());
@@ -348,7 +353,7 @@ void Viewport::_notification(int p_what) {
case NOTIFICATION_FIXED_PROCESS: {
if (physics_object_picking) {
-
+#ifndef _3D_DISABLED
Vector2 last_pos(1e20,1e20);
CollisionObject *last_object;
ObjectID last_id=0;
@@ -394,7 +399,7 @@ void Viewport::_notification(int p_what) {
if (obj) {
CollisionObject *co = obj->cast_to<CollisionObject>();
if (co) {
- co->_input_event(ev,Vector3(),Vector3(),0);
+ co->_input_event(camera,ev,Vector3(),Vector3(),0);
captured=true;
if (ev.type==InputEvent::MOUSE_BUTTON && ev.mouse_button.button_index==1 && !ev.mouse_button.pressed) {
physics_object_capture=0;
@@ -416,7 +421,7 @@ void Viewport::_notification(int p_what) {
if (last_id) {
if (ObjectDB::get_instance(last_id)) {
//good, exists
- last_object->_input_event(ev,result.position,result.normal,result.shape);
+ last_object->_input_event(camera,ev,result.position,result.normal,result.shape);
if (last_object->get_capture_input_on_drag() && ev.type==InputEvent::MOUSE_BUTTON && ev.mouse_button.button_index==1 && ev.mouse_button.pressed) {
physics_object_capture=last_id;
}
@@ -440,10 +445,13 @@ void Viewport::_notification(int p_what) {
bool col = space->intersect_ray(from,from+dir*10000,result,Set<RID>(),0xFFFFFFFF,0xFFFFFFFF);
ObjectID new_collider=0;
if (col) {
+
if (result.collider) {
+
CollisionObject *co = result.collider->cast_to<CollisionObject>();
if (co) {
- co->_input_event(ev,result.position,result.normal,result.shape);
+
+ co->_input_event(camera,ev,result.position,result.normal,result.shape);
last_object=co;
last_id=result.collider_id;
new_collider=last_id;
@@ -491,6 +499,7 @@ void Viewport::_notification(int p_what) {
}
}
+#endif
}
} break;
@@ -507,6 +516,7 @@ void Viewport::set_rect(const Rect2& p_rect) {
if (rect==p_rect)
return;
rect=p_rect;
+
_update_rect();
_update_stretch_transform();
@@ -541,7 +551,7 @@ Rect2 Viewport::get_rect() const {
void Viewport::_update_listener() {
- if (is_inside_scene() && audio_listener && camera) {
+ if (is_inside_tree() && audio_listener && camera && (!get_parent() || (get_parent()->cast_to<Control>() && get_parent()->cast_to<Control>()->is_visible()))) {
SpatialSoundServer::get_singleton()->listener_set_space(listener,find_world()->get_sound_space());
} else {
SpatialSoundServer::get_singleton()->listener_set_space(listener,RID());
@@ -552,7 +562,7 @@ void Viewport::_update_listener() {
void Viewport::_update_listener_2d() {
- if (is_inside_scene() && audio_listener_2d)
+ if (is_inside_tree() && audio_listener && (!get_parent() || (get_parent()->cast_to<Control>() && get_parent()->cast_to<Control>()->is_visible())))
SpatialSound2DServer::get_singleton()->listener_set_space(listener_2d,find_world_2d()->get_sound_space());
else
SpatialSound2DServer::get_singleton()->listener_set_space(listener_2d,RID());
@@ -731,7 +741,7 @@ void Viewport::_propagate_enter_world(Node *p_node) {
if (p_node!=this) {
- if (!p_node->is_inside_scene()) //may not have entered scene yet
+ if (!p_node->is_inside_tree()) //may not have entered scene yet
return;
Spatial *s = p_node->cast_to<Spatial>();
@@ -760,7 +770,7 @@ void Viewport::_propagate_exit_world(Node *p_node) {
if (p_node!=this) {
- if (!p_node->is_inside_scene()) //may have exited scene already
+ if (!p_node->is_inside_tree()) //may have exited scene already
return;
Spatial *s = p_node->cast_to<Spatial>();
@@ -791,7 +801,7 @@ void Viewport::set_world(const Ref<World>& p_world) {
if (world==p_world)
return;
- if (is_inside_scene())
+ if (is_inside_tree())
_propagate_exit_world(this);
#ifndef _3D_DISABLED
@@ -801,7 +811,7 @@ void Viewport::set_world(const Ref<World>& p_world) {
world=p_world;
- if (is_inside_scene())
+ if (is_inside_tree())
_propagate_enter_world(this);
#ifndef _3D_DISABLED
@@ -811,7 +821,7 @@ void Viewport::set_world(const Ref<World>& p_world) {
//propagate exit
- if (is_inside_scene()) {
+ if (is_inside_tree()) {
VisualServer::get_singleton()->viewport_set_scenario(viewport,find_world()->get_scenario());
}
@@ -899,12 +909,12 @@ void Viewport::set_as_render_target(bool p_enable){
render_target=p_enable;
VS::get_singleton()->viewport_set_as_render_target(viewport,p_enable);
- if (is_inside_scene()) {
+ if (is_inside_tree()) {
if (p_enable)
- _vp_exit_scene();
+ _vp_exit_tree();
else
- _vp_enter_scene();
+ _vp_enter_tree();
}
if (p_enable) {
@@ -1023,13 +1033,16 @@ void Viewport::_make_input_local(InputEvent& ev) {
Matrix32 ai = get_final_transform().affine_inverse() * _get_input_pre_xform();
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.mouse_motion.relative_x,ev.mouse_motion.relative_y));
+ Vector2 r = ai.basis_xform(Vector2(ev.mouse_motion.relative_x,ev.mouse_motion.relative_y));
+ Vector2 s = ai.basis_xform(Vector2(ev.mouse_motion.speed_x,ev.mouse_motion.speed_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.mouse_motion.relative_x=r.x;
ev.mouse_motion.relative_y=r.y;
+ ev.mouse_motion.speed_x=s.x;
+ ev.mouse_motion.speed_y=s.y;
} break;
case InputEvent::SCREEN_TOUCH: {
@@ -1044,8 +1057,8 @@ void Viewport::_make_input_local(InputEvent& ev) {
Matrix32 ai = get_final_transform().affine_inverse() * _get_input_pre_xform();
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));
+ Vector2 r = ai.basis_xform(Vector2(ev.screen_drag.relative_x,ev.screen_drag.relative_y));
+ Vector2 s = ai.basis_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;
@@ -1089,24 +1102,24 @@ void Viewport::_vp_unhandled_input(const InputEvent& p_ev) {
void Viewport::input(const InputEvent& p_event) {
- ERR_FAIL_COND(!is_inside_scene());
- get_scene()->_call_input_pause(input_group,"_input",p_event);
- get_scene()->call_group(SceneMainLoop::GROUP_CALL_REVERSE|SceneMainLoop::GROUP_CALL_REALTIME|SceneMainLoop::GROUP_CALL_MULIILEVEL,gui_input_group,"_gui_input",p_event); //special one for GUI, as controls use their own process check
+ ERR_FAIL_COND(!is_inside_tree());
+ get_tree()->_call_input_pause(input_group,"_input",p_event);
+ get_tree()->call_group(SceneTree::GROUP_CALL_REVERSE|SceneTree::GROUP_CALL_REALTIME|SceneTree::GROUP_CALL_MULIILEVEL,gui_input_group,"_gui_input",p_event); //special one for GUI, as controls use their own process check
}
void Viewport::unhandled_input(const InputEvent& p_event) {
- ERR_FAIL_COND(!is_inside_scene());
+ ERR_FAIL_COND(!is_inside_tree());
- get_scene()->_call_input_pause(unhandled_input_group,"_unhandled_input",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_scene()->input_handled && p_event.type==InputEvent::KEY) {
- get_scene()->_call_input_pause(unhandled_key_input_group,"_unhandled_key_input",p_event);
+ if (!get_tree()->input_handled && p_event.type==InputEvent::KEY) {
+ 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_scene()->input_handled) {
+ if (physics_object_picking && !get_tree()->input_handled) {
if (p_event.type==InputEvent::MOUSE_BUTTON || p_event.type==InputEvent::MOUSE_MOTION || p_event.type==InputEvent::SCREEN_DRAG || p_event.type==InputEvent::SCREEN_TOUCH) {
physics_picking_events.push_back(p_event);
@@ -1121,7 +1134,7 @@ void Viewport::set_use_own_world(bool p_world) {
return;
- if (is_inside_scene())
+ if (is_inside_tree())
_propagate_exit_world(this);
#ifndef _3D_DISABLED
@@ -1134,7 +1147,7 @@ void Viewport::set_use_own_world(bool p_world) {
else
own_world=Ref<World>( memnew( World ));
- if (is_inside_scene())
+ if (is_inside_tree())
_propagate_enter_world(this);
#ifndef _3D_DISABLED
@@ -1144,7 +1157,7 @@ void Viewport::set_use_own_world(bool p_world) {
//propagate exit
- if (is_inside_scene()) {
+ if (is_inside_tree()) {
VisualServer::get_singleton()->viewport_set_scenario(viewport,find_world()->get_scenario());
}
@@ -1179,6 +1192,21 @@ void Viewport::set_physics_object_picking(bool p_enable) {
}
+
+Vector2 Viewport::get_camera_coords(const Vector2 &p_viewport_coords) const {
+
+ Matrix32 xf = get_final_transform();
+ return xf.xform(p_viewport_coords);
+
+
+}
+
+Vector2 Viewport::get_camera_rect_size() const {
+
+ return last_vp_rect.size;
+}
+
+
bool Viewport::get_physics_object_picking() {
diff --git a/scene/main/viewport.h b/scene/main/viewport.h
index 5d68438f0d..4bb5735731 100644
--- a/scene/main/viewport.h
+++ b/scene/main/viewport.h
@@ -110,6 +110,7 @@ friend class RenderTargetTexture;
Size2 size_override_size;
Size2 size_override_margin;
+ Rect2 last_vp_rect;
bool transparent_bg;
bool render_target_vflip;
@@ -158,8 +159,8 @@ friend class RenderTargetTexture;
_FORCE_INLINE_ Matrix32 _get_input_pre_xform() const;
- void _vp_enter_scene();
- void _vp_exit_scene();
+ void _vp_enter_tree();
+ void _vp_exit_tree();
void _vp_input(const InputEvent& p_ev);
void _vp_unhandled_input(const InputEvent& p_ev);
@@ -229,6 +230,10 @@ public:
RenderTargetUpdateMode get_render_target_update_mode() const;
Ref<RenderTargetTexture> get_render_target_texture() const;
+
+ Vector2 get_camera_coords(const Vector2& p_viewport_coords) const;
+ Vector2 get_camera_rect_size() const;
+
void queue_screen_capture();
Image get_screen_capture() const;