summaryrefslogtreecommitdiff
path: root/scene/main
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2017-01-10 18:02:19 -0300
committerJuan Linietsky <reduzio@gmail.com>2017-01-10 18:04:33 -0300
commitf3f4a11cfb9767e1d691aec431dd2f1a87a31977 (patch)
tree7918ff8c7b366df911374c93d5077d27d788f9c3 /scene/main
parent6eeb994a7bbd3cb1500c42af8f3ac1227f323ce4 (diff)
- _ready() callback only happens once now, if you want to receive it again, use request_ready()
- C++ Nodes mostly do an internal process callback, so it does not conflict with users willing to use their own process callbacks - callbacks such as _input, _process, _fixed_process _unhandled_input, _unhandled_key_input do not requiere calling a function to enable them. They are enabled automatically if found on the script.
Diffstat (limited to 'scene/main')
-rw-r--r--scene/main/http_request.cpp8
-rw-r--r--scene/main/node.cpp109
-rw-r--r--scene/main/node.h16
-rw-r--r--scene/main/scene_main_loop.cpp2
-rw-r--r--scene/main/timer.cpp24
-rw-r--r--scene/main/viewport.cpp11
-rw-r--r--scene/main/viewport.h1
7 files changed, 138 insertions, 33 deletions
diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp
index 1be43826f7..848be375ca 100644
--- a/scene/main/http_request.cpp
+++ b/scene/main/http_request.cpp
@@ -154,7 +154,7 @@ Error HTTPRequest::request(const String& p_url, const Vector<String>& p_custom_h
return ERR_CANT_CONNECT;
}
- set_process(true);
+ set_process_internal(true);
}
@@ -190,7 +190,7 @@ void HTTPRequest::cancel_request() {
return;
if (!use_threads) {
- set_process(false);
+ set_process_internal(false);
} else {
thread_request_quit=true;
Thread::wait_to_finish(thread);
@@ -459,14 +459,14 @@ void HTTPRequest::_request_done(int p_status, int p_code, const StringArray& hea
void HTTPRequest::_notification(int p_what) {
- if (p_what==NOTIFICATION_PROCESS) {
+ if (p_what==NOTIFICATION_INTERNAL_PROCESS) {
if (use_threads)
return;
bool done = _update_connection();
if (done) {
- set_process(false);
+ set_process_internal(false);
//cancel_request(); called from _request done now
}
}
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index 58829dbee3..672f54e187 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -89,6 +89,7 @@ void Node::_notification(int p_notification) {
data.network_owner=this;
}
+
if (data.input)
add_to_group("_vp_input"+itos(get_viewport()->get_instance_ID()));
if (data.unhandled_input)
@@ -128,6 +129,26 @@ void Node::_notification(int p_notification) {
if (get_script_instance()) {
+ if (get_script_instance()->has_method(SceneStringNames::get_singleton()->_input)) {
+ set_process_input(true);
+ }
+
+ if (get_script_instance()->has_method(SceneStringNames::get_singleton()->_unhandled_input)) {
+ set_process_unhandled_input(true);
+ }
+
+ if (get_script_instance()->has_method(SceneStringNames::get_singleton()->_unhandled_key_input)) {
+ set_process_unhandled_key_input(true);
+ }
+
+ if (get_script_instance()->has_method(SceneStringNames::get_singleton()->_process)) {
+ set_process(true);
+ }
+
+ if (get_script_instance()->has_method(SceneStringNames::get_singleton()->_fixed_process)) {
+ set_fixed_process(true);
+ }
+
Variant::CallError err;
get_script_instance()->call_multilevel_reversed(SceneStringNames::get_singleton()->_ready,NULL,0);
}
@@ -173,7 +194,10 @@ void Node::_propagate_ready() {
data.children[i]->_propagate_ready();
}
data.blocked--;
- notification(NOTIFICATION_READY);
+ if (data.ready_first) {
+ notification(NOTIFICATION_READY);
+ data.ready_first=false;
+ }
}
@@ -294,6 +318,7 @@ void Node::_propagate_exit_tree() {
data.tree->tree_changed();
data.inside_tree=false;
+ data.ready_notified=false;
data.tree=NULL;
data.depth=-1;
@@ -401,6 +426,33 @@ void Node::set_fixed_process(bool p_process) {
_change_notify("fixed_process");
}
+bool Node::is_fixed_processing() const {
+
+ return data.fixed_process;
+}
+
+void Node::set_fixed_process_internal(bool p_process_internal) {
+
+ if (data.fixed_process_internal==p_process_internal)
+ return;
+
+ data.fixed_process_internal=p_process_internal;
+
+ if (data.fixed_process_internal)
+ add_to_group("fixed_process_internal",false);
+ else
+ remove_from_group("fixed_process_internal");
+
+ data.fixed_process_internal=p_process_internal;
+ _change_notify("fixed_process_internal");
+}
+
+bool Node::is_fixed_processing_internal() const {
+
+ return data.fixed_process_internal;
+}
+
+
void Node::set_pause_mode(PauseMode p_mode) {
if (data.pause_mode==p_mode)
@@ -1115,6 +1167,14 @@ float Node::get_fixed_process_delta_time() const {
return 0;
}
+float Node::get_process_delta_time() const {
+
+ if (data.tree)
+ return data.tree->get_idle_process_time();
+ else
+ return 0;
+}
+
void Node::set_process(bool p_idle_process) {
if (data.idle_process==p_idle_process)
@@ -1131,22 +1191,31 @@ void Node::set_process(bool p_idle_process) {
_change_notify("idle_process");
}
-float Node::get_process_delta_time() const {
- if (data.tree)
- return data.tree->get_idle_process_time();
- else
- return 0;
+bool Node::is_processing() const {
+
+ return data.idle_process;
}
-bool Node::is_fixed_processing() const {
+void Node::set_process_internal(bool p_idle_process_internal) {
- return data.fixed_process;
+ if (data.idle_process_internal==p_idle_process_internal)
+ return;
+
+ data.idle_process_internal=p_idle_process_internal;
+
+ if (data.idle_process_internal)
+ add_to_group("idle_process_internal",false);
+ else
+ remove_from_group("idle_process_internal");
+
+ data.idle_process_internal=p_idle_process_internal;
+ _change_notify("idle_process_internal");
}
-bool Node::is_processing() const {
+bool Node::is_processing_internal() const {
- return data.idle_process;
+ return data.idle_process_internal;
}
@@ -2813,6 +2882,10 @@ bool Node::is_displayed_folded() const {
return data.display_folded;
}
+void Node::request_ready() {
+ data.ready_first=true;
+}
+
void Node::_bind_methods() {
_GLOBAL_DEF("editor/node_name_num_separator",0);
@@ -2858,8 +2931,8 @@ void Node::_bind_methods() {
ClassDB::bind_method(_MD("set_fixed_process","enable"),&Node::set_fixed_process);
ClassDB::bind_method(_MD("get_fixed_process_delta_time"),&Node::get_fixed_process_delta_time);
ClassDB::bind_method(_MD("is_fixed_processing"),&Node::is_fixed_processing);
- ClassDB::bind_method(_MD("set_process","enable"),&Node::set_process);
ClassDB::bind_method(_MD("get_process_delta_time"),&Node::get_process_delta_time);
+ ClassDB::bind_method(_MD("set_process","enable"),&Node::set_process);
ClassDB::bind_method(_MD("is_processing"),&Node::is_processing);
ClassDB::bind_method(_MD("set_process_input","enable"),&Node::set_process_input);
ClassDB::bind_method(_MD("is_processing_input"),&Node::is_processing_input);
@@ -2875,6 +2948,12 @@ void Node::_bind_methods() {
ClassDB::bind_method(_MD("set_display_folded","fold"),&Node::set_display_folded);
ClassDB::bind_method(_MD("is_displayed_folded"),&Node::is_displayed_folded);
+ ClassDB::bind_method(_MD("set_process_internal","enable"),&Node::set_process_internal);
+ ClassDB::bind_method(_MD("is_processing_internal"),&Node::is_processing_internal);
+
+ ClassDB::bind_method(_MD("set_fixed_process_internal","enable"),&Node::set_fixed_process_internal);
+ ClassDB::bind_method(_MD("is_fixed_processing_internal"),&Node::is_fixed_processing_internal);
+
ClassDB::bind_method(_MD("get_tree:SceneTree"),&Node::get_tree);
ClassDB::bind_method(_MD("duplicate:Node","use_instancing"),&Node::duplicate,DEFVAL(false));
@@ -2888,6 +2967,8 @@ void Node::_bind_methods() {
ClassDB::bind_method(_MD("queue_free"),&Node::queue_delete);
+ ClassDB::bind_method(_MD("request_ready"),&Node::request_ready);
+
ClassDB::bind_method(_MD("set_network_mode","mode"),&Node::set_network_mode);
ClassDB::bind_method(_MD("get_network_mode"),&Node::get_network_mode);
@@ -2946,6 +3027,9 @@ void Node::_bind_methods() {
BIND_CONSTANT( NOTIFICATION_DRAG_BEGIN );
BIND_CONSTANT( NOTIFICATION_DRAG_END );
BIND_CONSTANT( NOTIFICATION_PATH_CHANGED);
+ BIND_CONSTANT( NOTIFICATION_TRANSLATION_CHANGED );
+ BIND_CONSTANT( NOTIFICATION_INTERNAL_PROCESS );
+ BIND_CONSTANT( NOTIFICATION_INTERNAL_FIXED_PROCESS );
BIND_CONSTANT( NETWORK_MODE_INHERIT );
@@ -3008,6 +3092,8 @@ Node::Node() {
data.tree=NULL;
data.fixed_process=false;
data.idle_process=false;
+ data.fixed_process_internal=false;
+ data.idle_process_internal=false;
data.inside_tree=false;
data.ready_notified=false;
@@ -3026,6 +3112,7 @@ Node::Node() {
data.viewport=NULL;
data.use_placeholder=false;
data.display_folded=false;
+ data.ready_first=true;
}
diff --git a/scene/main/node.h b/scene/main/node.h
index f9d334629e..e27404d46e 100644
--- a/scene/main/node.h
+++ b/scene/main/node.h
@@ -103,7 +103,8 @@ private:
StringName name;
SceneTree *tree;
bool inside_tree;
- bool ready_notified;
+ bool ready_notified; //this is a small hack, so if a node is added during _ready() to the tree, it corretly gets the _ready() notification
+ bool ready_first;
#ifdef TOOLS_ENABLED
NodePath import_path; //path used when imported, used by scene editors to keep tracking
#endif
@@ -129,6 +130,9 @@ private:
bool fixed_process;
bool idle_process;
+ bool fixed_process_internal;
+ bool idle_process_internal;
+
bool input;
bool unhandled_input;
bool unhandled_key_input;
@@ -223,6 +227,9 @@ public:
NOTIFICATION_DRAG_END=22,
NOTIFICATION_PATH_CHANGED=23,
NOTIFICATION_TRANSLATION_CHANGED=24,
+ NOTIFICATION_INTERNAL_PROCESS = 25,
+ NOTIFICATION_INTERNAL_FIXED_PROCESS = 26,
+
};
/* NODE/TREE */
@@ -302,6 +309,11 @@ public:
float get_process_delta_time() const;
bool is_processing() const;
+ void set_fixed_process_internal(bool p_process);
+ bool is_fixed_processing_internal() const;
+
+ void set_process_internal(bool p_process);
+ bool is_processing_internal() const;
void set_process_input(bool p_enable);
bool is_processing_input() const;
@@ -337,6 +349,8 @@ public:
PauseMode get_pause_mode() const;
bool can_process() const;
+ void request_ready();
+
static void print_stray_nodes();
#ifdef TOOLS_ENABLED
diff --git a/scene/main/scene_main_loop.cpp b/scene/main/scene_main_loop.cpp
index 7ea7e49020..5cb60d25d9 100644
--- a/scene/main/scene_main_loop.cpp
+++ b/scene/main/scene_main_loop.cpp
@@ -523,6 +523,7 @@ bool SceneTree::iteration(float p_time) {
emit_signal("fixed_frame");
+ _notify_group_pause("fixed_process_internal",Node::NOTIFICATION_INTERNAL_FIXED_PROCESS);
_notify_group_pause("fixed_process",Node::NOTIFICATION_FIXED_PROCESS);
_flush_ugc();
_flush_transform_notifications();
@@ -554,6 +555,7 @@ bool SceneTree::idle(float p_time){
_flush_transform_notifications();
+ _notify_group_pause("idle_process_internal",Node::NOTIFICATION_INTERNAL_PROCESS);
_notify_group_pause("idle_process",Node::NOTIFICATION_PROCESS);
Size2 win_size=Size2( OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height );
diff --git a/scene/main/timer.cpp b/scene/main/timer.cpp
index 408a3e9a2c..7852e2b46b 100644
--- a/scene/main/timer.cpp
+++ b/scene/main/timer.cpp
@@ -45,8 +45,8 @@ void Timer::_notification(int p_what) {
autostart=false;
}
} break;
- case NOTIFICATION_PROCESS: {
- if (timer_process_mode == TIMER_PROCESS_FIXED || !is_processing())
+ case NOTIFICATION_INTERNAL_PROCESS: {
+ if (timer_process_mode == TIMER_PROCESS_FIXED || !is_processing_internal())
return;
time_left -= get_process_delta_time();
@@ -61,8 +61,8 @@ void Timer::_notification(int p_what) {
}
} break;
- case NOTIFICATION_FIXED_PROCESS: {
- if (timer_process_mode == TIMER_PROCESS_IDLE || !is_fixed_processing())
+ case NOTIFICATION_INTERNAL_FIXED_PROCESS: {
+ if (timer_process_mode == TIMER_PROCESS_IDLE || !is_fixed_processing_internal())
return;
time_left -= get_fixed_process_delta_time();
@@ -147,15 +147,15 @@ void Timer::set_timer_process_mode(TimerProcessMode p_mode) {
switch (timer_process_mode) {
case TIMER_PROCESS_FIXED:
- if (is_fixed_processing()) {
- set_fixed_process(false);
- set_process(true);
+ if (is_fixed_processing_internal()) {
+ set_fixed_process_internal(false);
+ set_process_internal(true);
}
break;
case TIMER_PROCESS_IDLE:
- if (is_processing()) {
- set_process(false);
- set_fixed_process(true);
+ if (is_processing_internal()) {
+ set_process_internal(false);
+ set_fixed_process_internal(true);
}
break;
}
@@ -171,8 +171,8 @@ Timer::TimerProcessMode Timer::get_timer_process_mode() const{
void Timer::_set_process(bool p_process, bool p_force)
{
switch (timer_process_mode) {
- case TIMER_PROCESS_FIXED: set_fixed_process(p_process && active); break;
- case TIMER_PROCESS_IDLE: set_process(p_process && active); break;
+ case TIMER_PROCESS_FIXED: set_fixed_process_internal(p_process && active); break;
+ case TIMER_PROCESS_IDLE: set_process_internal(p_process && active); break;
}
processing = p_process;
}
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 02d5d5ce30..bd80f97c22 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -1315,11 +1315,7 @@ Image Viewport::get_screen_capture() const {
Ref<ViewportTexture> Viewport::get_texture() const {
- Ref<ViewportTexture> vt;
- vt.instance();
- vt->vp=const_cast<Viewport*>(this);
-
- return vt;
+ return default_texture;
}
void Viewport::set_vflip(bool p_enable) {
@@ -2852,6 +2848,11 @@ Viewport::Viewport() {
viewport = VisualServer::get_singleton()->viewport_create();
texture_rid=VisualServer::get_singleton()->viewport_get_texture(viewport);
texture_flags=0;
+
+ default_texture.instance();
+ default_texture->vp=const_cast<Viewport*>(this);
+ viewport_textures.insert(default_texture.ptr());
+
internal_listener = SpatialSoundServer::get_singleton()->listener_create();
audio_listener=false;
internal_listener_2d = SpatialSound2DServer::get_singleton()->listener_create();
diff --git a/scene/main/viewport.h b/scene/main/viewport.h
index 5feeae6237..6666565069 100644
--- a/scene/main/viewport.h
+++ b/scene/main/viewport.h
@@ -207,6 +207,7 @@ friend class ViewportTexture;
MSAA msaa;
bool hdr;
+ Ref<ViewportTexture> default_texture;
Set<ViewportTexture*> viewport_textures;