diff options
Diffstat (limited to '')
| -rw-r--r-- | scene/main/canvas_layer.cpp | 165 | ||||
| -rw-r--r-- | scene/main/canvas_layer.h | 15 | ||||
| -rw-r--r-- | scene/main/http_request.cpp | 375 | ||||
| -rw-r--r-- | scene/main/http_request.h | 21 | ||||
| -rw-r--r-- | scene/main/instance_placeholder.cpp | 51 | ||||
| -rw-r--r-- | scene/main/instance_placeholder.h | 13 | ||||
| -rw-r--r-- | scene/main/node.cpp | 1318 | ||||
| -rw-r--r-- | scene/main/node.h | 160 | ||||
| -rw-r--r-- | scene/main/resource_preloader.cpp | 101 | ||||
| -rw-r--r-- | scene/main/resource_preloader.h | 21 | ||||
| -rw-r--r-- | scene/main/scene_main_loop.cpp | 985 | ||||
| -rw-r--r-- | scene/main/scene_main_loop.h | 197 | ||||
| -rw-r--r-- | scene/main/timer.cpp | 82 | ||||
| -rw-r--r-- | scene/main/timer.h | 7 | ||||
| -rw-r--r-- | scene/main/viewport.cpp | 1449 | ||||
| -rw-r--r-- | scene/main/viewport.h | 138 |
16 files changed, 2269 insertions, 2829 deletions
diff --git a/scene/main/canvas_layer.cpp b/scene/main/canvas_layer.cpp index 1de19959d..5898665ff 100644 --- a/scene/main/canvas_layer.cpp +++ b/scene/main/canvas_layer.cpp @@ -29,27 +29,24 @@ #include "canvas_layer.h" #include "viewport.h" - void CanvasLayer::set_layer(int p_xform) { - layer=p_xform; + layer = p_xform; if (viewport.is_valid()) - VisualServer::get_singleton()->viewport_set_canvas_layer(viewport,canvas->get_canvas(),layer); - + VisualServer::get_singleton()->viewport_set_canvas_layer(viewport, canvas->get_canvas(), layer); } -int CanvasLayer::get_layer() const{ +int CanvasLayer::get_layer() const { return layer; } -void CanvasLayer::set_transform(const Matrix32& p_xform) { +void CanvasLayer::set_transform(const Matrix32 &p_xform) { - transform=p_xform; - locrotscale_dirty=true; + transform = p_xform; + locrotscale_dirty = true; if (viewport.is_valid()) - VisualServer::get_singleton()->viewport_set_canvas_transform(viewport,canvas->get_canvas(),transform); - + VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas->get_canvas(), transform); } Matrix32 CanvasLayer::get_transform() const { @@ -59,56 +56,50 @@ Matrix32 CanvasLayer::get_transform() const { void CanvasLayer::_update_xform() { - transform.set_rotation_and_scale(rot,scale); + transform.set_rotation_and_scale(rot, scale); transform.set_origin(ofs); if (viewport.is_valid()) - VisualServer::get_singleton()->viewport_set_canvas_transform(viewport,canvas->get_canvas(),transform); - + VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas->get_canvas(), transform); } void CanvasLayer::_update_locrotscale() { - ofs=transform.elements[2]; - rot=transform.get_rotation(); - scale=transform.get_scale(); - locrotscale_dirty=false; + ofs = transform.elements[2]; + rot = transform.get_rotation(); + scale = transform.get_scale(); + locrotscale_dirty = false; } - -void CanvasLayer::set_offset(const Vector2& p_offset) { +void CanvasLayer::set_offset(const Vector2 &p_offset) { if (locrotscale_dirty) _update_locrotscale(); - ofs=p_offset; + ofs = p_offset; _update_xform(); - } Vector2 CanvasLayer::get_offset() const { if (locrotscale_dirty) - const_cast<CanvasLayer*>(this)->_update_locrotscale(); + const_cast<CanvasLayer *>(this)->_update_locrotscale(); return ofs; } - void CanvasLayer::set_rotation(real_t p_radians) { if (locrotscale_dirty) _update_locrotscale(); - - rot=p_radians; + rot = p_radians; _update_xform(); - } real_t CanvasLayer::get_rotation() const { if (locrotscale_dirty) - const_cast<CanvasLayer*>(this)->_update_locrotscale(); + const_cast<CanvasLayer *>(this)->_update_locrotscale(); return rot; } @@ -137,26 +128,23 @@ real_t CanvasLayer::_get_rotationd() const { return get_rotationd(); } -void CanvasLayer::set_scale(const Vector2& p_scale) { +void CanvasLayer::set_scale(const Vector2 &p_scale) { if (locrotscale_dirty) _update_locrotscale(); - scale=p_scale; + scale = p_scale; _update_xform(); - } Vector2 CanvasLayer::get_scale() const { if (locrotscale_dirty) - const_cast<CanvasLayer*>(this)->_update_locrotscale(); + const_cast<CanvasLayer *>(this)->_update_locrotscale(); return scale; } - - Ref<World2D> CanvasLayer::get_world_2d() const { return canvas; @@ -164,30 +152,28 @@ Ref<World2D> CanvasLayer::get_world_2d() const { void CanvasLayer::_notification(int p_what) { - switch(p_what) { + switch (p_what) { case NOTIFICATION_ENTER_TREE: { if (custom_viewport && ObjectDB::get_instance(custom_viewport_id)) { - vp=custom_viewport; + vp = custom_viewport; } else { - vp=Node::get_viewport(); - + vp = Node::get_viewport(); } ERR_FAIL_COND(!vp); - viewport=vp->get_viewport(); - - VisualServer::get_singleton()->viewport_attach_canvas(viewport,canvas->get_canvas()); - VisualServer::get_singleton()->viewport_set_canvas_layer(viewport,canvas->get_canvas(),layer); - VisualServer::get_singleton()->viewport_set_canvas_transform(viewport,canvas->get_canvas(),transform); + viewport = vp->get_viewport(); + VisualServer::get_singleton()->viewport_attach_canvas(viewport, canvas->get_canvas()); + VisualServer::get_singleton()->viewport_set_canvas_layer(viewport, canvas->get_canvas(), layer); + VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas->get_canvas(), transform); } break; case NOTIFICATION_EXIT_TREE: { - VisualServer::get_singleton()->viewport_remove_canvas(viewport,canvas->get_canvas()); - viewport=RID(); + VisualServer::get_singleton()->viewport_remove_canvas(viewport, canvas->get_canvas()); + viewport = RID(); } break; } @@ -196,14 +182,12 @@ void CanvasLayer::_notification(int p_what) { Size2 CanvasLayer::get_viewport_size() const { if (!is_inside_tree()) - return Size2(1,1); - + return Size2(1, 1); Rect2 r = vp->get_visible_rect(); return r.size; } - RID CanvasLayer::get_viewport() const { return viewport; @@ -212,88 +196,83 @@ RID CanvasLayer::get_viewport() const { void CanvasLayer::set_custom_viewport(Node *p_viewport) { ERR_FAIL_NULL(p_viewport); if (is_inside_tree()) { - VisualServer::get_singleton()->viewport_remove_canvas(viewport,canvas->get_canvas()); - viewport=RID(); + VisualServer::get_singleton()->viewport_remove_canvas(viewport, canvas->get_canvas()); + viewport = RID(); } - custom_viewport=p_viewport->cast_to<Viewport>(); + custom_viewport = p_viewport->cast_to<Viewport>(); if (custom_viewport) { - custom_viewport_id=custom_viewport->get_instance_ID(); + custom_viewport_id = custom_viewport->get_instance_ID(); } else { - custom_viewport_id=0; + custom_viewport_id = 0; } if (is_inside_tree()) { - if (custom_viewport) - vp=custom_viewport; + vp = custom_viewport; else - vp=Node::get_viewport(); + vp = Node::get_viewport(); viewport = vp->get_viewport(); - VisualServer::get_singleton()->viewport_attach_canvas(viewport,canvas->get_canvas()); - VisualServer::get_singleton()->viewport_set_canvas_layer(viewport,canvas->get_canvas(),layer); - VisualServer::get_singleton()->viewport_set_canvas_transform(viewport,canvas->get_canvas(),transform); + VisualServer::get_singleton()->viewport_attach_canvas(viewport, canvas->get_canvas()); + VisualServer::get_singleton()->viewport_set_canvas_layer(viewport, canvas->get_canvas(), layer); + VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas->get_canvas(), transform); } - } -Node* CanvasLayer::get_custom_viewport() const { +Node *CanvasLayer::get_custom_viewport() const { return custom_viewport; } - void CanvasLayer::_bind_methods() { + ObjectTypeDB::bind_method(_MD("set_layer", "layer"), &CanvasLayer::set_layer); + ObjectTypeDB::bind_method(_MD("get_layer"), &CanvasLayer::get_layer); - ObjectTypeDB::bind_method(_MD("set_layer","layer"),&CanvasLayer::set_layer); - ObjectTypeDB::bind_method(_MD("get_layer"),&CanvasLayer::get_layer); + ObjectTypeDB::bind_method(_MD("set_transform", "transform"), &CanvasLayer::set_transform); + ObjectTypeDB::bind_method(_MD("get_transform"), &CanvasLayer::get_transform); - ObjectTypeDB::bind_method(_MD("set_transform","transform"),&CanvasLayer::set_transform); - ObjectTypeDB::bind_method(_MD("get_transform"),&CanvasLayer::get_transform); + ObjectTypeDB::bind_method(_MD("set_offset", "offset"), &CanvasLayer::set_offset); + ObjectTypeDB::bind_method(_MD("get_offset"), &CanvasLayer::get_offset); - ObjectTypeDB::bind_method(_MD("set_offset","offset"),&CanvasLayer::set_offset); - ObjectTypeDB::bind_method(_MD("get_offset"),&CanvasLayer::get_offset); + ObjectTypeDB::bind_method(_MD("set_rotation", "radians"), &CanvasLayer::set_rotation); + ObjectTypeDB::bind_method(_MD("get_rotation"), &CanvasLayer::get_rotation); - ObjectTypeDB::bind_method(_MD("set_rotation","radians"),&CanvasLayer::set_rotation); - ObjectTypeDB::bind_method(_MD("get_rotation"),&CanvasLayer::get_rotation); - - ObjectTypeDB::bind_method(_MD("set_rotationd","degrees"),&CanvasLayer::set_rotationd); - ObjectTypeDB::bind_method(_MD("get_rotationd"),&CanvasLayer::get_rotationd); + ObjectTypeDB::bind_method(_MD("set_rotationd", "degrees"), &CanvasLayer::set_rotationd); + ObjectTypeDB::bind_method(_MD("get_rotationd"), &CanvasLayer::get_rotationd); // TODO: Obsolete those two methods (old name) properly (GH-4397) - ObjectTypeDB::bind_method(_MD("_set_rotationd","degrees"),&CanvasLayer::_set_rotationd); - ObjectTypeDB::bind_method(_MD("_get_rotationd"),&CanvasLayer::_get_rotationd); + ObjectTypeDB::bind_method(_MD("_set_rotationd", "degrees"), &CanvasLayer::_set_rotationd); + ObjectTypeDB::bind_method(_MD("_get_rotationd"), &CanvasLayer::_get_rotationd); - ObjectTypeDB::bind_method(_MD("set_scale","scale"),&CanvasLayer::set_scale); - ObjectTypeDB::bind_method(_MD("get_scale"),&CanvasLayer::get_scale); + ObjectTypeDB::bind_method(_MD("set_scale", "scale"), &CanvasLayer::set_scale); + ObjectTypeDB::bind_method(_MD("get_scale"), &CanvasLayer::get_scale); - ObjectTypeDB::bind_method(_MD("set_custom_viewport","viewport:Viewport"),&CanvasLayer::set_custom_viewport); - ObjectTypeDB::bind_method(_MD("get_custom_viewport:Viewport"),&CanvasLayer::get_custom_viewport); + ObjectTypeDB::bind_method(_MD("set_custom_viewport", "viewport:Viewport"), &CanvasLayer::set_custom_viewport); + ObjectTypeDB::bind_method(_MD("get_custom_viewport:Viewport"), &CanvasLayer::get_custom_viewport); - ObjectTypeDB::bind_method(_MD("get_world_2d:World2D"),&CanvasLayer::get_world_2d); -// ObjectTypeDB::bind_method(_MD("get_viewport"),&CanvasLayer::get_viewport); + ObjectTypeDB::bind_method(_MD("get_world_2d:World2D"), &CanvasLayer::get_world_2d); + // ObjectTypeDB::bind_method(_MD("get_viewport"),&CanvasLayer::get_viewport); - ADD_PROPERTY( PropertyInfo(Variant::INT,"layer",PROPERTY_HINT_RANGE,"-128,128,1"),_SCS("set_layer"),_SCS("get_layer") ); + ADD_PROPERTY(PropertyInfo(Variant::INT, "layer", PROPERTY_HINT_RANGE, "-128,128,1"), _SCS("set_layer"), _SCS("get_layer")); //ADD_PROPERTY( PropertyInfo(Variant::MATRIX32,"transform",PROPERTY_HINT_RANGE),_SCS("set_transform"),_SCS("get_transform") ); - ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"offset"),_SCS("set_offset"),_SCS("get_offset") ); - ADD_PROPERTY( PropertyInfo(Variant::REAL,"rotation"),_SCS("set_rotationd"),_SCS("get_rotationd") ); - ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"scale"),_SCS("set_scale"),_SCS("get_scale") ); - + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset"), _SCS("set_offset"), _SCS("get_offset")); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "rotation"), _SCS("set_rotationd"), _SCS("get_rotationd")); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scale"), _SCS("set_scale"), _SCS("get_scale")); } CanvasLayer::CanvasLayer() { - vp=NULL; - scale=Vector2(1,1); - rot=0; - locrotscale_dirty=false; - layer=1; - canvas = Ref<World2D>( memnew(World2D) ); - custom_viewport=NULL; - custom_viewport_id=0; + vp = NULL; + scale = Vector2(1, 1); + rot = 0; + locrotscale_dirty = false; + layer = 1; + canvas = Ref<World2D>(memnew(World2D)); + custom_viewport = NULL; + custom_viewport_id = 0; } diff --git a/scene/main/canvas_layer.h b/scene/main/canvas_layer.h index 039db8823..0472b66ec 100644 --- a/scene/main/canvas_layer.h +++ b/scene/main/canvas_layer.h @@ -32,11 +32,10 @@ #include "scene/main/node.h" #include "scene/resources/world_2d.h" - class Viewport; class CanvasLayer : public Node { - OBJ_TYPE( CanvasLayer, Node ); + OBJ_TYPE(CanvasLayer, Node); bool locrotscale_dirty; Vector2 ofs; @@ -59,20 +58,18 @@ class CanvasLayer : public Node { void _update_xform(); void _update_locrotscale(); - protected: - void _notification(int p_what); static void _bind_methods(); -public: +public: void set_layer(int p_xform); int get_layer() const; - void set_transform(const Matrix32& p_xform); + void set_transform(const Matrix32 &p_xform); Matrix32 get_transform() const; - void set_offset(const Vector2& p_offset); + void set_offset(const Vector2 &p_offset); Vector2 get_offset() const; void set_rotation(real_t p_radians); @@ -81,7 +78,7 @@ public: void set_rotationd(real_t p_degrees); real_t get_rotationd() const; - void set_scale(const Size2& p_scale); + void set_scale(const Size2 &p_scale); Size2 get_scale() const; Ref<World2D> get_world_2d() const; @@ -91,7 +88,7 @@ public: RID get_viewport() const; void set_custom_viewport(Node *p_viewport); - Node* get_custom_viewport() const; + Node *get_custom_viewport() const; CanvasLayer(); }; diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp index 4203edda7..d977548d6 100644 --- a/scene/main/http_request.cpp +++ b/scene/main/http_request.cpp @@ -32,41 +32,39 @@ void HTTPRequest::set_ip_type(IP::Type p_type) { client->set_ip_type(p_type); } -void HTTPRequest::_redirect_request(const String& p_new_url) { - - +void HTTPRequest::_redirect_request(const String &p_new_url) { } Error HTTPRequest::_request() { //print_line("Requesting:\n\tURL: "+url+"\n\tString: "+request_string+"\n\tPort: "+itos(port)+"\n\tSSL: "+itos(use_ssl)+"\n\tValidate SSL: "+itos(validate_ssl)); - return client->connect(url,port,use_ssl,validate_ssl); + return client->connect(url, port, use_ssl, validate_ssl); } -Error HTTPRequest::_parse_url(const String& p_url) { +Error HTTPRequest::_parse_url(const String &p_url) { - url=p_url; - use_ssl=false; + url = p_url; + use_ssl = false; - request_string=""; - port=80; - request_sent=false; - got_response=false; - body_len=-1; + request_string = ""; + port = 80; + request_sent = false; + got_response = false; + body_len = -1; body.resize(0); - downloaded=0; - redirections=0; + downloaded = 0; + redirections = 0; //print_line("1 url: "+url); if (url.begins_with("http://")) { - url=url.substr(7,url.length()-7); + url = url.substr(7, url.length() - 7); //print_line("no SSL"); } else if (url.begins_with("https://")) { - url=url.substr(8,url.length()-8); - use_ssl=true; - port=443; + url = url.substr(8, url.length() - 8); + use_ssl = true; + port = 443; //print_line("yes SSL"); } else { ERR_EXPLAIN("Malformed URL"); @@ -77,22 +75,22 @@ Error HTTPRequest::_parse_url(const String& p_url) { int slash_pos = url.find("/"); - if (slash_pos!=-1) { - request_string=url.substr(slash_pos,url.length()); - url=url.substr(0,slash_pos); + if (slash_pos != -1) { + request_string = url.substr(slash_pos, url.length()); + url = url.substr(0, slash_pos); //print_line("request string: "+request_string); } else { - request_string="/"; + request_string = "/"; //print_line("no request"); } //print_line("3 url: "+url); int colon_pos = url.find(":"); - if (colon_pos!=-1) { - port=url.substr(colon_pos+1,url.length()).to_int(); - url=url.substr(0,colon_pos); - ERR_FAIL_COND_V(port<1 || port > 65535,ERR_INVALID_PARAMETER); + if (colon_pos != -1) { + port = url.substr(colon_pos + 1, url.length()).to_int(); + url = url.substr(0, colon_pos); + ERR_FAIL_COND_V(port < 1 || port > 65535, ERR_INVALID_PARAMETER); } //print_line("4 url: "+url); @@ -100,79 +98,76 @@ Error HTTPRequest::_parse_url(const String& p_url) { return OK; } -Error HTTPRequest::request(const String& p_url, const Vector<String>& p_custom_headers, bool p_ssl_validate_domain, HTTPClient::Method p_method, const String& p_request_data) { +Error HTTPRequest::request(const String &p_url, const Vector<String> &p_custom_headers, bool p_ssl_validate_domain, HTTPClient::Method p_method, const String &p_request_data) { - ERR_FAIL_COND_V(!is_inside_tree(),ERR_UNCONFIGURED); - if ( requesting ) { + ERR_FAIL_COND_V(!is_inside_tree(), ERR_UNCONFIGURED); + if (requesting) { ERR_EXPLAIN("HTTPRequest is processing a request. Wait for completion or cancel it before attempting a new one."); ERR_FAIL_V(ERR_BUSY); } - method=p_method; + method = p_method; Error err = _parse_url(p_url); if (err) return err; - validate_ssl=p_ssl_validate_domain; + validate_ssl = p_ssl_validate_domain; - bool has_user_agent=false; - bool has_accept=false; - headers=p_custom_headers; + bool has_user_agent = false; + bool has_accept = false; + headers = p_custom_headers; request_data = p_request_data; - for(int i=0;i<headers.size();i++) { + for (int i = 0; i < headers.size(); i++) { - if (headers[i].findn("user-agent:")==0) - has_user_agent=true; - if (headers[i].findn("Accept:")==0) - has_accept=true; + if (headers[i].findn("user-agent:") == 0) + has_user_agent = true; + if (headers[i].findn("Accept:") == 0) + has_accept = true; } if (!has_user_agent) { - headers.push_back("User-Agent: GodotEngine/"+String(VERSION_MKSTRING)+" ("+OS::get_singleton()->get_name()+")"); + headers.push_back("User-Agent: GodotEngine/" + String(VERSION_MKSTRING) + " (" + OS::get_singleton()->get_name() + ")"); } if (!has_accept) { headers.push_back("Accept: */*"); } - requesting=true; + requesting = true; if (use_threads) { - thread_done=false; - thread_request_quit=false; + thread_done = false; + thread_request_quit = false; client->set_blocking_mode(true); - thread=Thread::create(_thread_func,this); + thread = Thread::create(_thread_func, this); } else { client->set_blocking_mode(false); err = _request(); - if (err!=OK) { - call_deferred("_request_done",RESULT_CANT_CONNECT,0,StringArray(),ByteArray()); + if (err != OK) { + call_deferred("_request_done", RESULT_CANT_CONNECT, 0, StringArray(), ByteArray()); return ERR_CANT_CONNECT; } set_process(true); - } - return OK; } - void HTTPRequest::_thread_func(void *p_userdata) { - HTTPRequest *hr = (HTTPRequest*)p_userdata; + HTTPRequest *hr = (HTTPRequest *)p_userdata; Error err = hr->_request(); - if (err!=OK) { - hr->call_deferred("_request_done",RESULT_CANT_CONNECT,0,StringArray(),ByteArray()); + if (err != OK) { + hr->call_deferred("_request_done", RESULT_CANT_CONNECT, 0, StringArray(), ByteArray()); } else { - while(!hr->thread_request_quit) { + while (!hr->thread_request_quit) { bool exit = hr->_update_connection(); if (exit) @@ -181,7 +176,7 @@ void HTTPRequest::_thread_func(void *p_userdata) { } } - hr->thread_done=true; + hr->thread_done = true; } void HTTPRequest::cancel_request() { @@ -192,90 +187,88 @@ void HTTPRequest::cancel_request() { if (!use_threads) { set_process(false); } else { - thread_request_quit=true; + thread_request_quit = true; Thread::wait_to_finish(thread); memdelete(thread); - thread=NULL; + thread = NULL; } if (file) { memdelete(file); - file=NULL; + file = NULL; } client->close(); body.resize(0); //downloaded=0; - got_response=false; - response_code=-1; + got_response = false; + response_code = -1; //body_len=-1; - request_sent=false; - requesting=false; + request_sent = false; + requesting = false; } - bool HTTPRequest::_handle_response(bool *ret_value) { if (!client->has_response()) { - call_deferred("_request_done",RESULT_NO_RESPONSE,0,StringArray(),ByteArray()); - *ret_value=true; + call_deferred("_request_done", RESULT_NO_RESPONSE, 0, StringArray(), ByteArray()); + *ret_value = true; return true; } - got_response=true; - response_code=client->get_response_code(); + got_response = true; + response_code = client->get_response_code(); List<String> rheaders; client->get_response_headers(&rheaders); response_headers.resize(0); - downloaded=0; - for (List<String>::Element *E=rheaders.front();E;E=E->next()) { + downloaded = 0; + for (List<String>::Element *E = rheaders.front(); E; E = E->next()) { //print_line("HEADER: "+E->get()); response_headers.push_back(E->get()); } - if (response_code==301 || response_code==302) { + if (response_code == 301 || response_code == 302) { //redirect - if (max_redirects>=0 && redirections>=max_redirects) { + if (max_redirects >= 0 && redirections >= max_redirects) { - call_deferred("_request_done",RESULT_REDIRECT_LIMIT_REACHED,response_code,response_headers,ByteArray()); - *ret_value=true; + call_deferred("_request_done", RESULT_REDIRECT_LIMIT_REACHED, response_code, response_headers, ByteArray()); + *ret_value = true; return true; } String new_request; - for (List<String>::Element *E=rheaders.front();E;E=E->next()) { - if (E->get().findn("Location: ")!=-1) { - new_request=E->get().substr(9,E->get().length()).strip_edges(); + for (List<String>::Element *E = rheaders.front(); E; E = E->next()) { + if (E->get().findn("Location: ") != -1) { + new_request = E->get().substr(9, E->get().length()).strip_edges(); } } //print_line("NEW LOCATION: "+new_request); - if (new_request!="") { + if (new_request != "") { //process redirect client->close(); - int new_redirs=redirections+1; //because _request() will clear it + int new_redirs = redirections + 1; //because _request() will clear it Error err; if (new_request.begins_with("http")) { //new url, request all again - err=_parse_url(new_request); + err = _parse_url(new_request); } else { - request_string=new_request; + request_string = new_request; } err = _request(); //print_line("new connection: "+itos(err)); - if (err==OK) { - request_sent=false; - got_response=false; - body_len=-1; + if (err == OK) { + request_sent = false; + got_response = false; + body_len = -1; body.resize(0); - downloaded=0; - redirections=new_redirs; - *ret_value=false; + downloaded = 0; + redirections = new_redirs; + *ret_value = false; return true; - } } } @@ -283,12 +276,11 @@ bool HTTPRequest::_handle_response(bool *ret_value) { return false; } - bool HTTPRequest::_update_connection() { - switch( client->get_status() ) { + switch (client->get_status()) { case HTTPClient::STATUS_DISCONNECTED: { - call_deferred("_request_done",RESULT_CANT_CONNECT,0,StringArray(),ByteArray()); + call_deferred("_request_done", RESULT_CANT_CONNECT, 0, StringArray(), ByteArray()); return true; //end it, since it's doing something } break; case HTTPClient::STATUS_RESOLVING: { @@ -297,7 +289,7 @@ bool HTTPRequest::_update_connection() { return false; } break; case HTTPClient::STATUS_CANT_RESOLVE: { - call_deferred("_request_done",RESULT_CANT_RESOLVE,0,StringArray(),ByteArray()); + call_deferred("_request_done", RESULT_CANT_RESOLVE, 0, StringArray(), ByteArray()); return true; } break; @@ -308,7 +300,7 @@ bool HTTPRequest::_update_connection() { } break; //connecting to ip case HTTPClient::STATUS_CANT_CONNECT: { - call_deferred("_request_done",RESULT_CANT_CONNECT,0,StringArray(),ByteArray()); + call_deferred("_request_done", RESULT_CANT_CONNECT, 0, StringArray(), ByteArray()); return true; } break; @@ -325,30 +317,28 @@ bool HTTPRequest::_update_connection() { if (_handle_response(&ret_value)) return ret_value; - - call_deferred("_request_done",RESULT_SUCCESS,response_code,response_headers,ByteArray()); + call_deferred("_request_done", RESULT_SUCCESS, response_code, response_headers, ByteArray()); return true; } - if (got_response && body_len<0) { + if (got_response && body_len < 0) { //chunked transfer is done - call_deferred("_request_done",RESULT_SUCCESS,response_code,response_headers,body); + call_deferred("_request_done", RESULT_SUCCESS, response_code, response_headers, body); return true; - } - call_deferred("_request_done",RESULT_CHUNKED_BODY_SIZE_MISMATCH,response_code,response_headers,ByteArray()); + call_deferred("_request_done", RESULT_CHUNKED_BODY_SIZE_MISMATCH, response_code, response_headers, ByteArray()); return true; //request migh have been done } else { //did not request yet, do request - Error err = client->request(method,request_string,headers,request_data); - if (err!=OK) { - call_deferred("_request_done",RESULT_CONNECTION_ERROR,0,StringArray(),ByteArray()); + Error err = client->request(method, request_string, headers, request_data); + if (err != OK) { + call_deferred("_request_done", RESULT_CONNECTION_ERROR, 0, StringArray(), ByteArray()); return true; } - request_sent=true; + request_sent = true; return false; } } break; //connected: { } break requests only accepted here @@ -362,67 +352,64 @@ bool HTTPRequest::_update_connection() { if (!got_response) { - bool ret_value; if (_handle_response(&ret_value)) return ret_value; - if (!client->is_response_chunked() && client->get_response_body_length()==0) { + if (!client->is_response_chunked() && client->get_response_body_length() == 0) { - call_deferred("_request_done",RESULT_SUCCESS,response_code,response_headers,ByteArray()); + call_deferred("_request_done", RESULT_SUCCESS, response_code, response_headers, ByteArray()); return true; } - if (client->is_response_chunked()) { - body_len=-1; //no body len because chunked, change your webserver configuration if you want body len + body_len = -1; //no body len because chunked, change your webserver configuration if you want body len } else { - body_len=client->get_response_body_length(); + body_len = client->get_response_body_length(); - if (body_size_limit>=0 && body_len>body_size_limit) { - call_deferred("_request_done",RESULT_BODY_SIZE_LIMIT_EXCEEDED,response_code,response_headers,ByteArray()); + if (body_size_limit >= 0 && body_len > body_size_limit) { + call_deferred("_request_done", RESULT_BODY_SIZE_LIMIT_EXCEEDED, response_code, response_headers, ByteArray()); return true; } } - if (download_to_file!=String()) { - file=FileAccess::open(download_to_file,FileAccess::WRITE); + if (download_to_file != String()) { + file = FileAccess::open(download_to_file, FileAccess::WRITE); if (!file) { - call_deferred("_request_done",RESULT_DOWNLOAD_FILE_CANT_OPEN,response_code,response_headers,ByteArray()); + call_deferred("_request_done", RESULT_DOWNLOAD_FILE_CANT_OPEN, response_code, response_headers, ByteArray()); return true; } } } - //print_line("BODY: "+itos(body.size())); client->poll(); ByteArray chunk = client->read_response_body_chunk(); - downloaded+=chunk.size(); + downloaded += chunk.size(); if (file) { - ByteArray::Read r=chunk.read(); - file->store_buffer(r.ptr(),chunk.size()); - if (file->get_error()!=OK) { - call_deferred("_request_done",RESULT_DOWNLOAD_FILE_WRITE_ERROR,response_code,response_headers,ByteArray()); + ByteArray::Read r = chunk.read(); + file->store_buffer(r.ptr(), chunk.size()); + if (file->get_error() != OK) { + call_deferred("_request_done", RESULT_DOWNLOAD_FILE_WRITE_ERROR, response_code, response_headers, ByteArray()); return true; } } else { body.append_array(chunk); } - if (body_size_limit>=0 && downloaded>body_size_limit) { - call_deferred("_request_done",RESULT_BODY_SIZE_LIMIT_EXCEEDED,response_code,response_headers,ByteArray()); + if (body_size_limit >= 0 && downloaded > body_size_limit) { + call_deferred("_request_done", RESULT_BODY_SIZE_LIMIT_EXCEEDED, response_code, response_headers, ByteArray()); return true; } - if (body_len>=0) { + if (body_len >= 0) { - if (downloaded==body_len) { - call_deferred("_request_done",RESULT_SUCCESS,response_code,response_headers,body); + if (downloaded == body_len) { + call_deferred("_request_done", RESULT_SUCCESS, response_code, response_headers, body); return true; } /*if (body.size()>=body_len) { @@ -435,31 +422,27 @@ bool HTTPRequest::_update_connection() { } break; // request resulted in body: { } break which must be read case HTTPClient::STATUS_CONNECTION_ERROR: { - call_deferred("_request_done",RESULT_CONNECTION_ERROR,0,StringArray(),ByteArray()); + call_deferred("_request_done", RESULT_CONNECTION_ERROR, 0, StringArray(), ByteArray()); return true; } break; case HTTPClient::STATUS_SSL_HANDSHAKE_ERROR: { - call_deferred("_request_done",RESULT_SSL_HANDSHAKE_ERROR,0,StringArray(),ByteArray()); + call_deferred("_request_done", RESULT_SSL_HANDSHAKE_ERROR, 0, StringArray(), ByteArray()); return true; } break; - } ERR_FAIL_V(false); } - -void HTTPRequest::_request_done(int p_status, int p_code, const StringArray& headers, const ByteArray& p_data) { - +void HTTPRequest::_request_done(int p_status, int p_code, const StringArray &headers, const ByteArray &p_data) { cancel_request(); - emit_signal("request_completed",p_status,p_code,headers,p_data); + emit_signal("request_completed", p_status, p_code, headers, p_data); } - void HTTPRequest::_notification(int p_what) { - if (p_what==NOTIFICATION_PROCESS) { + if (p_what == NOTIFICATION_PROCESS) { if (use_threads) return; @@ -471,18 +454,17 @@ void HTTPRequest::_notification(int p_what) { } } - if (p_what==NOTIFICATION_EXIT_TREE) { + if (p_what == NOTIFICATION_EXIT_TREE) { if (requesting) { cancel_request(); } } - } void HTTPRequest::set_use_threads(bool p_use) { - ERR_FAIL_COND( status!=HTTPClient::STATUS_DISCONNECTED ); - use_threads=p_use; + ERR_FAIL_COND(status != HTTPClient::STATUS_DISCONNECTED); + use_threads = p_use; } bool HTTPRequest::is_using_threads() const { @@ -492,9 +474,9 @@ bool HTTPRequest::is_using_threads() const { void HTTPRequest::set_body_size_limit(int p_bytes) { - ERR_FAIL_COND( status!=HTTPClient::STATUS_DISCONNECTED ); + ERR_FAIL_COND(status != HTTPClient::STATUS_DISCONNECTED); - body_size_limit=p_bytes; + body_size_limit = p_bytes; } int HTTPRequest::get_body_size_limit() const { @@ -502,12 +484,11 @@ int HTTPRequest::get_body_size_limit() const { return body_size_limit; } +void HTTPRequest::set_download_file(const String &p_file) { -void HTTPRequest::set_download_file(const String& p_file) { - - ERR_FAIL_COND( status!=HTTPClient::STATUS_DISCONNECTED ); + ERR_FAIL_COND(status != HTTPClient::STATUS_DISCONNECTED); - download_to_file=p_file; + download_to_file = p_file; } String HTTPRequest::get_download_file() const { @@ -520,10 +501,10 @@ HTTPClient::Status HTTPRequest::get_http_client_status() const { void HTTPRequest::set_max_redirects(int p_max) { - max_redirects=p_max; + max_redirects = p_max; } -int HTTPRequest::get_max_redirects() const{ +int HTTPRequest::get_max_redirects() const { return max_redirects; } @@ -532,81 +513,77 @@ int HTTPRequest::get_downloaded_bytes() const { return downloaded; } -int HTTPRequest::get_body_size() const{ +int HTTPRequest::get_body_size() const { return body_len; } - void HTTPRequest::_bind_methods() { - ObjectTypeDB::bind_method(_MD("set_ip_type","ip_type"),&HTTPRequest::set_ip_type); - ObjectTypeDB::bind_method(_MD("request","url","custom_headers","ssl_validate_domain","method","request_data"),&HTTPRequest::request,DEFVAL(StringArray()),DEFVAL(true),DEFVAL(HTTPClient::METHOD_GET),DEFVAL(String())); - ObjectTypeDB::bind_method(_MD("cancel_request"),&HTTPRequest::cancel_request); + ObjectTypeDB::bind_method(_MD("set_ip_type", "ip_type"), &HTTPRequest::set_ip_type); + ObjectTypeDB::bind_method(_MD("request", "url", "custom_headers", "ssl_validate_domain", "method", "request_data"), &HTTPRequest::request, DEFVAL(StringArray()), DEFVAL(true), DEFVAL(HTTPClient::METHOD_GET), DEFVAL(String())); + ObjectTypeDB::bind_method(_MD("cancel_request"), &HTTPRequest::cancel_request); - ObjectTypeDB::bind_method(_MD("get_http_client_status"),&HTTPRequest::get_http_client_status); + ObjectTypeDB::bind_method(_MD("get_http_client_status"), &HTTPRequest::get_http_client_status); - ObjectTypeDB::bind_method(_MD("set_use_threads","enable"),&HTTPRequest::set_use_threads); - ObjectTypeDB::bind_method(_MD("is_using_threads"),&HTTPRequest::is_using_threads); + ObjectTypeDB::bind_method(_MD("set_use_threads", "enable"), &HTTPRequest::set_use_threads); + ObjectTypeDB::bind_method(_MD("is_using_threads"), &HTTPRequest::is_using_threads); - ObjectTypeDB::bind_method(_MD("set_body_size_limit","bytes"),&HTTPRequest::set_body_size_limit); - ObjectTypeDB::bind_method(_MD("get_body_size_limit"),&HTTPRequest::get_body_size_limit); + ObjectTypeDB::bind_method(_MD("set_body_size_limit", "bytes"), &HTTPRequest::set_body_size_limit); + ObjectTypeDB::bind_method(_MD("get_body_size_limit"), &HTTPRequest::get_body_size_limit); - ObjectTypeDB::bind_method(_MD("set_max_redirects","amount"),&HTTPRequest::set_max_redirects); - ObjectTypeDB::bind_method(_MD("get_max_redirects"),&HTTPRequest::get_max_redirects); + ObjectTypeDB::bind_method(_MD("set_max_redirects", "amount"), &HTTPRequest::set_max_redirects); + ObjectTypeDB::bind_method(_MD("get_max_redirects"), &HTTPRequest::get_max_redirects); - ObjectTypeDB::bind_method(_MD("set_download_file","path"),&HTTPRequest::set_download_file); - ObjectTypeDB::bind_method(_MD("get_download_file"),&HTTPRequest::get_download_file); + ObjectTypeDB::bind_method(_MD("set_download_file", "path"), &HTTPRequest::set_download_file); + ObjectTypeDB::bind_method(_MD("get_download_file"), &HTTPRequest::get_download_file); - ObjectTypeDB::bind_method(_MD("get_downloaded_bytes"),&HTTPRequest::get_downloaded_bytes); - ObjectTypeDB::bind_method(_MD("get_body_size"),&HTTPRequest::get_body_size); + ObjectTypeDB::bind_method(_MD("get_downloaded_bytes"), &HTTPRequest::get_downloaded_bytes); + ObjectTypeDB::bind_method(_MD("get_body_size"), &HTTPRequest::get_body_size); - ObjectTypeDB::bind_method(_MD("_redirect_request"),&HTTPRequest::_redirect_request); - ObjectTypeDB::bind_method(_MD("_request_done"),&HTTPRequest::_request_done); + ObjectTypeDB::bind_method(_MD("_redirect_request"), &HTTPRequest::_redirect_request); + ObjectTypeDB::bind_method(_MD("_request_done"), &HTTPRequest::_request_done); - ADD_PROPERTY(PropertyInfo(Variant::BOOL,"use_threads"),_SCS("set_use_threads"),_SCS("is_using_threads")); - ADD_PROPERTY(PropertyInfo(Variant::INT,"body_size_limit",PROPERTY_HINT_RANGE,"-1,2000000000"),_SCS("set_body_size_limit"),_SCS("get_body_size_limit")); - ADD_PROPERTY(PropertyInfo(Variant::INT,"max_redirects",PROPERTY_HINT_RANGE,"-1,1024"),_SCS("set_max_redirects"),_SCS("get_max_redirects")); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_threads"), _SCS("set_use_threads"), _SCS("is_using_threads")); + ADD_PROPERTY(PropertyInfo(Variant::INT, "body_size_limit", PROPERTY_HINT_RANGE, "-1,2000000000"), _SCS("set_body_size_limit"), _SCS("get_body_size_limit")); + ADD_PROPERTY(PropertyInfo(Variant::INT, "max_redirects", PROPERTY_HINT_RANGE, "-1,1024"), _SCS("set_max_redirects"), _SCS("get_max_redirects")); - ADD_SIGNAL(MethodInfo("request_completed",PropertyInfo(Variant::INT,"result"),PropertyInfo(Variant::INT,"response_code"),PropertyInfo(Variant::STRING_ARRAY,"headers"),PropertyInfo(Variant::RAW_ARRAY,"body"))); + ADD_SIGNAL(MethodInfo("request_completed", PropertyInfo(Variant::INT, "result"), PropertyInfo(Variant::INT, "response_code"), PropertyInfo(Variant::STRING_ARRAY, "headers"), PropertyInfo(Variant::RAW_ARRAY, "body"))); - BIND_CONSTANT( RESULT_SUCCESS ); + 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_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); } -HTTPRequest::HTTPRequest() -{ +HTTPRequest::HTTPRequest() { - thread=NULL; + thread = NULL; - port=80; - redirections=0; - max_redirects=8; - body_len=-1; - got_response=false; - validate_ssl=false; - use_ssl=false; - response_code=0; - request_sent=false; - requesting=false; + port = 80; + redirections = 0; + max_redirects = 8; + body_len = -1; + got_response = false; + validate_ssl = false; + use_ssl = false; + response_code = 0; + request_sent = false; + requesting = false; client.instance(); - use_threads=false; - thread_done=false; - body_size_limit=-1; - file=NULL; - status=HTTPClient::STATUS_DISCONNECTED; - + use_threads = false; + thread_done = false; + body_size_limit = -1; + file = NULL; + status = HTTPClient::STATUS_DISCONNECTED; } HTTPRequest::~HTTPRequest() { diff --git a/scene/main/http_request.h b/scene/main/http_request.h index 5bf47111e..6a63fa66a 100644 --- a/scene/main/http_request.h +++ b/scene/main/http_request.h @@ -29,16 +29,16 @@ #ifndef HTTPREQUEST_H #define HTTPREQUEST_H -#include "node.h" #include "io/http_client.h" +#include "node.h" #include "os/file_access.h" #include "os/thread.h" class HTTPRequest : public Node { - OBJ_TYPE(HTTPRequest,Node); -public: + OBJ_TYPE(HTTPRequest, Node); +public: enum Result { RESULT_SUCCESS, //RESULT_NO_BODY, @@ -57,7 +57,6 @@ public: }; private: - bool requesting; String request_string; @@ -94,12 +93,11 @@ private: int max_redirects; - void _redirect_request(const String& p_new_url); - + void _redirect_request(const String &p_new_url); bool _handle_response(bool *ret_value); - Error _parse_url(const String& p_url); + Error _parse_url(const String &p_url); Error _request(); volatile bool thread_done; @@ -107,24 +105,23 @@ private: Thread *thread; - void _request_done(int p_status, int p_code, const StringArray& headers, const ByteArray& p_data); + void _request_done(int p_status, int p_code, const StringArray &headers, const ByteArray &p_data); static void _thread_func(void *p_userdata); protected: - void _notification(int p_what); static void _bind_methods(); -public: +public: void set_ip_type(IP::Type p_type); - Error request(const String& p_url, const Vector<String>& p_custom_headers=Vector<String>(), bool p_ssl_validate_domain=true, HTTPClient::Method p_method=HTTPClient::METHOD_GET, const String& p_request_data=""); //connects to a full url and perform request + Error request(const String &p_url, const Vector<String> &p_custom_headers = Vector<String>(), bool p_ssl_validate_domain = true, HTTPClient::Method p_method = HTTPClient::METHOD_GET, const String &p_request_data = ""); //connects to a full url and perform request void cancel_request(); HTTPClient::Status get_http_client_status() const; void set_use_threads(bool p_use); bool is_using_threads() const; - void set_download_file(const String& p_file); + void set_download_file(const String &p_file); String get_download_file() const; void set_body_size_limit(int p_bytes); diff --git a/scene/main/instance_placeholder.cpp b/scene/main/instance_placeholder.cpp index ebba96ff8..ed3f23e65 100644 --- a/scene/main/instance_placeholder.cpp +++ b/scene/main/instance_placeholder.cpp @@ -28,51 +28,50 @@ /*************************************************************************/ #include "instance_placeholder.h" -#include "scene/resources/packed_scene.h" #include "io/resource_loader.h" +#include "scene/resources/packed_scene.h" -bool InstancePlaceholder::_set(const StringName& p_name, const Variant& p_value) { +bool InstancePlaceholder::_set(const StringName &p_name, const Variant &p_value) { PropSet ps; - ps.name=p_name; - ps.value=p_value; + ps.name = p_name; + ps.value = p_value; stored_values.push_back(ps); return true; } -bool InstancePlaceholder::_get(const StringName& p_name,Variant &r_ret) const{ +bool InstancePlaceholder::_get(const StringName &p_name, Variant &r_ret) const { - for (const List<PropSet>::Element *E=stored_values.front();E;E=E->next()) { - if (E->get().name==p_name) { - r_ret=E->get().value; + for (const List<PropSet>::Element *E = stored_values.front(); E; E = E->next()) { + if (E->get().name == p_name) { + r_ret = E->get().value; return true; } } return false; } -void InstancePlaceholder::_get_property_list( List<PropertyInfo> *p_list) const{ +void InstancePlaceholder::_get_property_list(List<PropertyInfo> *p_list) const { - for (const List<PropSet>::Element *E=stored_values.front();E;E=E->next()) { + for (const List<PropSet>::Element *E = stored_values.front(); E; E = E->next()) { PropertyInfo pi; - pi.name=E->get().name; - pi.type=E->get().value.get_type(); - pi.usage=PROPERTY_USAGE_STORAGE; + pi.name = E->get().name; + pi.type = E->get().value.get_type(); + pi.usage = PROPERTY_USAGE_STORAGE; p_list->push_back(pi); } } +void InstancePlaceholder::set_instance_path(const String &p_name) { -void InstancePlaceholder::set_instance_path(const String& p_name) { - - path=p_name; + path = p_name; } String InstancePlaceholder::get_instance_path() const { return path; } -void InstancePlaceholder::replace_by_instance(const Ref<PackedScene> &p_custom_scene){ +void InstancePlaceholder::replace_by_instance(const Ref<PackedScene> &p_custom_scene) { ERR_FAIL_COND(!is_inside_tree()); @@ -84,7 +83,7 @@ void InstancePlaceholder::replace_by_instance(const Ref<PackedScene> &p_custom_s if (p_custom_scene.is_valid()) ps = p_custom_scene; else - ps = ResourceLoader::load(path,"PackedScene"); + ps = ResourceLoader::load(path, "PackedScene"); if (!ps.is_valid()) return; @@ -92,15 +91,15 @@ void InstancePlaceholder::replace_by_instance(const Ref<PackedScene> &p_custom_s scene->set_name(get_name()); int pos = get_position_in_parent(); - for(List<PropSet>::Element *E=stored_values.front();E;E=E->next()) { - scene->set(E->get().name,E->get().value); + for (List<PropSet>::Element *E = stored_values.front(); E; E = E->next()) { + scene->set(E->get().name, E->get().value); } queue_delete(); base->remove_child(this); base->add_child(scene); - base->move_child(scene,pos); + base->move_child(scene, pos); } Dictionary InstancePlaceholder::get_stored_values(bool p_with_order) { @@ -108,7 +107,7 @@ Dictionary InstancePlaceholder::get_stored_values(bool p_with_order) { Dictionary ret; StringArray order; - for(List<PropSet>::Element *E=stored_values.front();E;E=E->next()) { + for (List<PropSet>::Element *E = stored_values.front(); E; E = E->next()) { ret[E->get().name] = E->get().value; if (p_with_order) order.push_back(E->get().name); @@ -122,12 +121,10 @@ Dictionary InstancePlaceholder::get_stored_values(bool p_with_order) { void InstancePlaceholder::_bind_methods() { - ObjectTypeDB::bind_method(_MD("get_stored_values","with_order"),&InstancePlaceholder::get_stored_values,DEFVAL(false)); - ObjectTypeDB::bind_method(_MD("replace_by_instance","custom_scene:PackedScene"),&InstancePlaceholder::replace_by_instance,DEFVAL(Variant())); - ObjectTypeDB::bind_method(_MD("get_instance_path"),&InstancePlaceholder::get_instance_path); + ObjectTypeDB::bind_method(_MD("get_stored_values", "with_order"), &InstancePlaceholder::get_stored_values, DEFVAL(false)); + ObjectTypeDB::bind_method(_MD("replace_by_instance", "custom_scene:PackedScene"), &InstancePlaceholder::replace_by_instance, DEFVAL(Variant())); + ObjectTypeDB::bind_method(_MD("get_instance_path"), &InstancePlaceholder::get_instance_path); } InstancePlaceholder::InstancePlaceholder() { - - } diff --git a/scene/main/instance_placeholder.h b/scene/main/instance_placeholder.h index 85de39324..8b2ec9a45 100644 --- a/scene/main/instance_placeholder.h +++ b/scene/main/instance_placeholder.h @@ -35,7 +35,7 @@ class PackedScene; class InstancePlaceholder : public Node { - OBJ_TYPE(InstancePlaceholder,Node); + OBJ_TYPE(InstancePlaceholder, Node); String path; struct PropSet { @@ -46,20 +46,19 @@ class InstancePlaceholder : public Node { List<PropSet> stored_values; protected: - bool _set(const StringName& p_name, const Variant& p_value); - bool _get(const StringName& p_name,Variant &r_ret) const; - void _get_property_list( List<PropertyInfo> *p_list) const; + bool _set(const StringName &p_name, const Variant &p_value); + bool _get(const StringName &p_name, Variant &r_ret) const; + void _get_property_list(List<PropertyInfo> *p_list) const; static void _bind_methods(); public: - - void set_instance_path(const String& p_name); + void set_instance_path(const String &p_name); String get_instance_path() const; Dictionary get_stored_values(bool p_with_order = false); - void replace_by_instance(const Ref<PackedScene>& p_custom_scene=Ref<PackedScene>()); + void replace_by_instance(const Ref<PackedScene> &p_custom_scene = Ref<PackedScene>()); InstancePlaceholder(); }; diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 5702f5bb3..8f02de4c4 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -27,62 +27,59 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ #include "node.h" -#include "print_string.h" +#include "instance_placeholder.h" +#include "io/resource_loader.h" #include "message_queue.h" -#include "scene/scene_string_names.h" +#include "print_string.h" #include "scene/resources/packed_scene.h" -#include "io/resource_loader.h" +#include "scene/scene_string_names.h" #include "viewport.h" -#include "instance_placeholder.h" VARIANT_ENUM_CAST(Node::PauseMode); - - - void Node::_notification(int p_notification) { - switch(p_notification) { + switch (p_notification) { case NOTIFICATION_PROCESS: { if (get_script_instance()) { - Variant time=get_process_delta_time(); - const Variant*ptr[1]={&time}; + Variant time = get_process_delta_time(); + const Variant *ptr[1] = { &time }; Variant::CallError err; - get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_process,ptr,1); + get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_process, ptr, 1); } } break; case NOTIFICATION_FIXED_PROCESS: { if (get_script_instance()) { - Variant time=get_fixed_process_delta_time(); - const Variant*ptr[1]={&time}; + Variant time = get_fixed_process_delta_time(); + const Variant *ptr[1] = { &time }; Variant::CallError err; - get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_fixed_process,ptr,1); + get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_fixed_process, ptr, 1); } } break; case NOTIFICATION_ENTER_TREE: { - if (data.pause_mode==PAUSE_MODE_INHERIT) { + if (data.pause_mode == PAUSE_MODE_INHERIT) { if (data.parent) - data.pause_owner=data.parent->data.pause_owner; + data.pause_owner = data.parent->data.pause_owner; else - data.pause_owner=NULL; + data.pause_owner = NULL; } else { - data.pause_owner=this; + data.pause_owner = this; } if (data.input) - add_to_group("_vp_input"+itos(get_viewport()->get_instance_ID())); + add_to_group("_vp_input" + itos(get_viewport()->get_instance_ID())); if (data.unhandled_input) - add_to_group("_vp_unhandled_input"+itos(get_viewport()->get_instance_ID())); + add_to_group("_vp_unhandled_input" + itos(get_viewport()->get_instance_ID())); if (data.unhandled_key_input) - add_to_group("_vp_unhandled_key_input"+itos(get_viewport()->get_instance_ID())); + add_to_group("_vp_unhandled_key_input" + itos(get_viewport()->get_instance_ID())); get_tree()->node_count++; @@ -91,11 +88,11 @@ void Node::_notification(int p_notification) { get_tree()->node_count--; if (data.input) - remove_from_group("_vp_input"+itos(get_viewport()->get_instance_ID())); + remove_from_group("_vp_input" + itos(get_viewport()->get_instance_ID())); if (data.unhandled_input) - remove_from_group("_vp_unhandled_input"+itos(get_viewport()->get_instance_ID())); + remove_from_group("_vp_unhandled_input" + itos(get_viewport()->get_instance_ID())); if (data.unhandled_key_input) - remove_from_group("_vp_unhandled_key_input"+itos(get_viewport()->get_instance_ID())); + remove_from_group("_vp_unhandled_key_input" + itos(get_viewport()->get_instance_ID())); } break; case NOTIFICATION_READY: { @@ -103,19 +100,19 @@ void Node::_notification(int p_notification) { if (get_script_instance()) { Variant::CallError err; - get_script_instance()->call_multilevel_reversed(SceneStringNames::get_singleton()->_ready,NULL,0); + get_script_instance()->call_multilevel_reversed(SceneStringNames::get_singleton()->_ready, NULL, 0); } //emit_signal(SceneStringNames::get_singleton()->enter_tree); } break; case NOTIFICATION_POSTINITIALIZE: { - data.in_constructor=false; + data.in_constructor = false; } break; case NOTIFICATION_PREDELETE: { set_owner(NULL); - while ( data.owned.size() ) { + while (data.owned.size()) { data.owned.front()->get()->set_owner(NULL); } @@ -126,69 +123,64 @@ void Node::_notification(int p_notification) { } // kill children as cleanly as possible - while( data.children.size() ) { + while (data.children.size()) { Node *child = data.children[0]; remove_child(child); - memdelete( child ); + memdelete(child); } } break; } } - void Node::_propagate_ready() { - data.ready_notified=true; + data.ready_notified = true; data.blocked++; - for (int i=0;i<data.children.size();i++) { + for (int i = 0; i < data.children.size(); i++) { data.children[i]->_propagate_ready(); } data.blocked--; notification(NOTIFICATION_READY); - } - void Node::_propagate_enter_tree() { // this needs to happen to all childs before any enter_tree if (data.parent) { - data.tree=data.parent->data.tree; - data.depth=data.parent->data.depth+1; + data.tree = data.parent->data.tree; + data.depth = data.parent->data.depth + 1; } else { - data.depth=1; + data.depth = 1; } data.viewport = cast_to<Viewport>(); if (!data.viewport) data.viewport = data.parent->data.viewport; - data.inside_tree=true; + data.inside_tree = true; - for (Map< StringName, GroupData>::Element *E=data.grouped.front();E;E=E->next()) { - E->get().group=data.tree->add_to_group(E->key(),this); + for (Map<StringName, GroupData>::Element *E = data.grouped.front(); E; E = E->next()) { + E->get().group = data.tree->add_to_group(E->key(), this); } - notification(NOTIFICATION_ENTER_TREE); if (get_script_instance()) { Variant::CallError err; - get_script_instance()->call_multilevel_reversed(SceneStringNames::get_singleton()->_enter_tree,NULL,0); + get_script_instance()->call_multilevel_reversed(SceneStringNames::get_singleton()->_enter_tree, NULL, 0); } emit_signal(SceneStringNames::get_singleton()->enter_tree); - data.blocked++; //block while adding children - for (int i=0;i<data.children.size();i++) { + for (int i = 0; i < data.children.size(); i++) { if (!data.children[i]->is_inside_tree()) // could have been added in enter_tree data.children[i]->_propagate_enter_tree(); @@ -198,7 +190,7 @@ void Node::_propagate_enter_tree() { #ifdef DEBUG_ENABLED - if (ScriptDebugger::get_singleton() && data.filename!=String()) { + if (ScriptDebugger::get_singleton() && data.filename != String()) { //used for live edit data.tree->live_scene_edit_cache[data.filename].insert(this); } @@ -206,27 +198,25 @@ void Node::_propagate_enter_tree() { // enter groups } - - void Node::_propagate_exit_tree() { - //block while removing children +//block while removing children #ifdef DEBUG_ENABLED - if (ScriptDebugger::get_singleton() && data.filename!=String()) { + if (ScriptDebugger::get_singleton() && data.filename != String()) { //used for live edit - Map<String,Set<Node*> >::Element *E=data.tree->live_scene_edit_cache.find(data.filename); + Map<String, Set<Node *> >::Element *E = data.tree->live_scene_edit_cache.find(data.filename); if (E) { E->get().erase(this); - if (E->get().size()==0) { + if (E->get().size() == 0) { data.tree->live_scene_edit_cache.erase(E); } } - Map<Node*,Map<ObjectID,Node*> >::Element *F=data.tree->live_edit_remove_list.find(this); + Map<Node *, Map<ObjectID, Node *> >::Element *F = data.tree->live_edit_remove_list.find(this); if (F) { - for (Map<ObjectID,Node*>::Element*G=F->get().front();G;G=G->next()) { + for (Map<ObjectID, Node *>::Element *G = F->get().front(); G; G = G->next()) { memdelete(G->get()); } @@ -236,7 +226,7 @@ void Node::_propagate_exit_tree() { #endif data.blocked++; - for (int i=data.children.size()-1;i>=0;i--) { + for (int i = data.children.size() - 1; i >= 0; i--) { data.children[i]->_propagate_exit_tree(); } @@ -246,52 +236,45 @@ void Node::_propagate_exit_tree() { if (get_script_instance()) { Variant::CallError err; - get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_exit_tree,NULL,0); + get_script_instance()->call_multilevel(SceneStringNames::get_singleton()->_exit_tree, NULL, 0); } emit_signal(SceneStringNames::get_singleton()->exit_tree); - notification(NOTIFICATION_EXIT_TREE,true); + notification(NOTIFICATION_EXIT_TREE, true); if (data.tree) data.tree->node_removed(this); // exit groups - for (Map< StringName, GroupData>::Element *E=data.grouped.front();E;E=E->next()) { - data.tree->remove_from_group(E->key(),this); - E->get().group=NULL; + for (Map<StringName, GroupData>::Element *E = data.grouped.front(); E; E = E->next()) { + data.tree->remove_from_group(E->key(), this); + E->get().group = NULL; } - data.viewport = NULL; if (data.tree) data.tree->tree_changed(); - data.inside_tree=false; - data.tree=NULL; - data.depth=-1; - + data.inside_tree = false; + data.tree = NULL; + data.depth = -1; } - - - - -void Node::move_child(Node *p_child,int p_pos) { +void Node::move_child(Node *p_child, int p_pos) { ERR_FAIL_NULL(p_child); - ERR_EXPLAIN("Invalid new child position: "+itos(p_pos)); - ERR_FAIL_INDEX( p_pos, data.children.size()+1 ); + ERR_EXPLAIN("Invalid new child position: " + itos(p_pos)); + ERR_FAIL_INDEX(p_pos, data.children.size() + 1); ERR_EXPLAIN("child is not a child of this node."); - ERR_FAIL_COND(p_child->data.parent!=this); - if (data.blocked>0) { + ERR_FAIL_COND(p_child->data.parent != this); + if (data.blocked > 0) { ERR_EXPLAIN("Parent node is busy setting up children, move_child() failed. Consider using call_deferred(\"move_child\") instead (or \"popup\" if this is from a popup)."); - ERR_FAIL_COND(data.blocked>0); + ERR_FAIL_COND(data.blocked > 0); } - - data.children.remove( p_child->data.pos ); - data.children.insert( p_pos, p_child ); + data.children.remove(p_child->data.pos); + data.children.insert(p_pos, p_child); if (data.tree) { data.tree->tree_changed(); @@ -299,22 +282,20 @@ void Node::move_child(Node *p_child,int p_pos) { data.blocked++; //new pos first - for (int i=0;i<data.children.size();i++) { + for (int i = 0; i < data.children.size(); i++) { - data.children[i]->data.pos=i; + 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 ); - + for (int i = 0; i < data.children.size(); i++) { + data.children[i]->notification(NOTIFICATION_MOVED_IN_PARENT); } - for (const Map< StringName, GroupData>::Element *E=p_child->data.grouped.front();E;E=E->next()) { - E->get().group->changed=true; + for (const Map<StringName, GroupData>::Element *E = p_child->data.grouped.front(); E; E = E->next()) { + E->get().group->changed = true; } data.blocked--; - } void Node::raise() { @@ -322,8 +303,7 @@ void Node::raise() { if (!data.parent) return; - data.parent->move_child(this,data.parent->data.children.size()-1); - + data.parent->move_child(this, data.parent->data.children.size() - 1); } void Node::add_child_notify(Node *p_child) { @@ -355,46 +335,43 @@ void Node::move_child_notify(Node *p_child) { void Node::set_fixed_process(bool p_process) { - if (data.fixed_process==p_process) + if (data.fixed_process == p_process) return; - data.fixed_process=p_process; + data.fixed_process = p_process; if (data.fixed_process) - add_to_group("fixed_process",false); + add_to_group("fixed_process", false); else remove_from_group("fixed_process"); - data.fixed_process=p_process; + data.fixed_process = p_process; _change_notify("fixed_process"); } void Node::set_pause_mode(PauseMode p_mode) { - if (data.pause_mode==p_mode) + if (data.pause_mode == p_mode) return; - bool prev_inherits=data.pause_mode==PAUSE_MODE_INHERIT; - data.pause_mode=p_mode; + bool prev_inherits = data.pause_mode == PAUSE_MODE_INHERIT; + data.pause_mode = p_mode; if (!is_inside_tree()) return; //pointless - if ((data.pause_mode==PAUSE_MODE_INHERIT) == prev_inherits) + if ((data.pause_mode == PAUSE_MODE_INHERIT) == prev_inherits) return; ///nothing changed - Node *owner=NULL; + Node *owner = NULL; - if (data.pause_mode==PAUSE_MODE_INHERIT) { + if (data.pause_mode == PAUSE_MODE_INHERIT) { if (data.parent) - owner=data.parent->data.pause_owner; + owner = data.parent->data.pause_owner; } else { - owner=this; + owner = this; } _propagate_pause_owner(owner); - - - } Node::PauseMode Node::get_pause_mode() const { @@ -402,12 +379,12 @@ Node::PauseMode Node::get_pause_mode() const { return data.pause_mode; } -void Node::_propagate_pause_owner(Node*p_owner) { +void Node::_propagate_pause_owner(Node *p_owner) { - if (data.pause_mode!=PAUSE_MODE_INHERIT) + if (data.pause_mode != PAUSE_MODE_INHERIT) return; - data.pause_owner=p_owner; - for(int i=0;i<data.children.size();i++) { + data.pause_owner = p_owner; + for (int i = 0; i < data.children.size(); i++) { data.children[i]->_propagate_pause_owner(p_owner); } @@ -415,32 +392,30 @@ void Node::_propagate_pause_owner(Node*p_owner) { bool Node::can_process() const { - ERR_FAIL_COND_V( !is_inside_tree(), false ); + ERR_FAIL_COND_V(!is_inside_tree(), false); if (get_tree()->is_paused()) { - if (data.pause_mode==PAUSE_MODE_STOP) + if (data.pause_mode == PAUSE_MODE_STOP) return false; - if (data.pause_mode==PAUSE_MODE_PROCESS) + if (data.pause_mode == PAUSE_MODE_PROCESS) return true; - if (data.pause_mode==PAUSE_MODE_INHERIT) { + if (data.pause_mode == PAUSE_MODE_INHERIT) { if (!data.pause_owner) return false; //clearly no pause owner by default - if (data.pause_owner->data.pause_mode==PAUSE_MODE_PROCESS) + if (data.pause_owner->data.pause_mode == PAUSE_MODE_PROCESS) return true; - if (data.pause_owner->data.pause_mode==PAUSE_MODE_STOP) + if (data.pause_owner->data.pause_mode == PAUSE_MODE_STOP) return false; } - } return true; } - float Node::get_fixed_process_delta_time() const { if (data.tree) @@ -451,17 +426,17 @@ float Node::get_fixed_process_delta_time() const { void Node::set_process(bool p_idle_process) { - if (data.idle_process==p_idle_process) + if (data.idle_process == p_idle_process) return; - data.idle_process=p_idle_process; + data.idle_process = p_idle_process; if (data.idle_process) - add_to_group("idle_process",false); + add_to_group("idle_process", false); else remove_from_group("idle_process"); - data.idle_process=p_idle_process; + data.idle_process = p_idle_process; _change_notify("idle_process"); } @@ -483,22 +458,19 @@ bool Node::is_processing() const { return data.idle_process; } - void Node::set_process_input(bool p_enable) { - if (p_enable==data.input) + if (p_enable == data.input) return; - data.input=p_enable; + data.input = p_enable; if (!is_inside_tree()) return; if (p_enable) - add_to_group("_vp_input"+itos(get_viewport()->get_instance_ID())); + add_to_group("_vp_input" + itos(get_viewport()->get_instance_ID())); else - remove_from_group("_vp_input"+itos(get_viewport()->get_instance_ID())); - - + remove_from_group("_vp_input" + itos(get_viewport()->get_instance_ID())); } bool Node::is_processing_input() const { @@ -507,61 +479,56 @@ bool Node::is_processing_input() const { void Node::set_process_unhandled_input(bool p_enable) { - if (p_enable==data.unhandled_input) + if (p_enable == data.unhandled_input) return; - data.unhandled_input=p_enable; + data.unhandled_input = p_enable; if (!is_inside_tree()) return; if (p_enable) - add_to_group("_vp_unhandled_input"+itos(get_viewport()->get_instance_ID())); + add_to_group("_vp_unhandled_input" + itos(get_viewport()->get_instance_ID())); else - remove_from_group("_vp_unhandled_input"+itos(get_viewport()->get_instance_ID())); + remove_from_group("_vp_unhandled_input" + itos(get_viewport()->get_instance_ID())); } - bool Node::is_processing_unhandled_input() const { return data.unhandled_input; } - void Node::set_process_unhandled_key_input(bool p_enable) { - if (p_enable==data.unhandled_key_input) + if (p_enable == data.unhandled_key_input) return; - data.unhandled_key_input=p_enable; + data.unhandled_key_input = p_enable; if (!is_inside_tree()) return; if (p_enable) - add_to_group("_vp_unhandled_key_input"+itos(get_viewport()->get_instance_ID())); + add_to_group("_vp_unhandled_key_input" + itos(get_viewport()->get_instance_ID())); else - remove_from_group("_vp_unhandled_key_input"+itos(get_viewport()->get_instance_ID())); + remove_from_group("_vp_unhandled_key_input" + itos(get_viewport()->get_instance_ID())); } - bool Node::is_processing_unhandled_key_input() const { return data.unhandled_key_input; } - StringName Node::get_name() const { return data.name; } -void Node::_set_name_nocheck(const StringName& p_name) { - - data.name=p_name; +void Node::_set_name_nocheck(const StringName &p_name) { + data.name = p_name; } -void Node::set_name(const String& p_name) { +void Node::set_name(const String &p_name) { - String name=p_name.replace(":","").replace("/","").replace("@",""); + String name = p_name.replace(":", "").replace("/", "").replace("@", ""); - ERR_FAIL_COND(name==""); - data.name=name; + ERR_FAIL_COND(name == ""); + data.name = name; if (data.parent) { @@ -575,7 +542,7 @@ void Node::set_name(const String& p_name) { } } -static bool node_hrcr=false; +static bool node_hrcr = false; static SafeRefCount node_hrcr_count; void Node::init_node_hrcr() { @@ -584,40 +551,37 @@ void Node::init_node_hrcr() { void Node::set_human_readable_collision_renaming(bool p_enabled) { - node_hrcr=p_enabled; + node_hrcr = p_enabled; } - - -String Node::validate_child_name(const String& p_name) const { +String Node::validate_child_name(const String &p_name) const { //this approach to autoset node names is human readable but very slow //it's turned on while running in the editor String basename = p_name; - if (basename==String()) { + if (basename == String()) { return String(); } - int val=1; + int val = 1; - for(;;) { + for (;;) { - String attempted = val > 1 ? (basename + " " +itos(val) ) : basename; + String attempted = val > 1 ? (basename + " " + itos(val)) : basename; - bool found=false; + bool found = false; - for (int i=0;i<data.children.size();i++) { + for (int i = 0; i < data.children.size(); i++) { //if (data.children[i]==p_child) // continue; if (data.children[i]->get_name() == attempted) { - found=true; + found = true; break; } - } if (found) { @@ -631,7 +595,6 @@ String Node::validate_child_name(const String& p_name) const { } return basename; - } void Node::_validate_child_name(Node *p_child, bool p_force_human_readable) { @@ -645,28 +608,27 @@ void Node::_validate_child_name(Node *p_child, bool p_force_human_readable) { String basename = p_child->data.name; - if (basename=="") { + if (basename == "") { basename = p_child->get_type(); } - int val=1; + int val = 1; - for(;;) { + for (;;) { - String attempted = val > 1 ? (basename + " " +itos(val) ) : basename; + String attempted = val > 1 ? (basename + " " + itos(val)) : basename; - bool found=false; + bool found = false; - for (int i=0;i<data.children.size();i++) { + for (int i = 0; i < data.children.size(); i++) { - if (data.children[i]==p_child) + if (data.children[i] == p_child) continue; if (data.children[i]->get_name() == attempted) { - found=true; + found = true; break; } - } if (found) { @@ -675,7 +637,7 @@ void Node::_validate_child_name(Node *p_child, bool p_force_human_readable) { continue; } - p_child->data.name=attempted; + p_child->data.name = attempted; break; } } else { @@ -683,21 +645,21 @@ void Node::_validate_child_name(Node *p_child, bool p_force_human_readable) { //this approach to autoset node names is fast but not as readable //it's the default and reserves the '@' character for unique names. - bool unique=true; + bool unique = true; - if (p_child->data.name==StringName() || p_child->data.name.operator String()[0]=='@') { + if (p_child->data.name == StringName() || p_child->data.name.operator String()[0] == '@') { //new unique name must be assigned - unique=false; + unique = false; } else { //check if exists - Node **childs=data.children.ptr(); + Node **childs = data.children.ptr(); int cc = data.children.size(); - for(int i=0;i<cc;i++) { - if (childs[i]==p_child) + for (int i = 0; i < cc; i++) { + if (childs[i] == p_child) continue; - if (childs[i]->data.name==p_child->data.name) { - unique=false; + if (childs[i]->data.name == p_child->data.name) { + unique = false; break; } } @@ -706,19 +668,19 @@ void Node::_validate_child_name(Node *p_child, bool p_force_human_readable) { if (!unique) { node_hrcr_count.ref(); - String name = "@"+String(p_child->get_name())+"@"+itos(node_hrcr_count.get()); - p_child->data.name=name; + String name = "@" + String(p_child->get_name()) + "@" + itos(node_hrcr_count.get()); + p_child->data.name = name; } } } -void Node::_add_child_nocheck(Node* p_child,const StringName& p_name) { +void Node::_add_child_nocheck(Node *p_child, const StringName &p_name) { //add a child node quickly, without name validation - p_child->data.name=p_name; - p_child->data.pos=data.children.size(); - data.children.push_back( p_child ); - p_child->data.parent=this; + p_child->data.name = p_name; + p_child->data.pos = data.children.size(); + data.children.push_back(p_child); + p_child->data.parent = this; p_child->notification(NOTIFICATION_PARENTED); if (data.tree) { @@ -727,37 +689,33 @@ void Node::_add_child_nocheck(Node* p_child,const StringName& p_name) { /* Notify */ //recognize childs created in this node constructor - p_child->data.parent_owned=data.in_constructor; + p_child->data.parent_owned = data.in_constructor; add_child_notify(p_child); - - } - 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_FAIL_COND( p_child==this ); // adding to itself! + if (p_child == this) { + 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 ); + ERR_FAIL_COND(p_child->data.parent); - if (data.blocked>0) { + 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_FAIL_COND(data.blocked>0); + ERR_FAIL_COND(data.blocked > 0); } ERR_EXPLAIN("Can't add child while a notification is happening"); - ERR_FAIL_COND( data.blocked > 0 ); + ERR_FAIL_COND(data.blocked > 0); /* Validate name */ - _validate_child_name(p_child,p_legible_unique_name); - - _add_child_nocheck(p_child,p_child->data.name); + _validate_child_name(p_child, p_legible_unique_name); + _add_child_nocheck(p_child, p_child->data.name); } void Node::add_child_below_node(Node *p_node, Node *p_child, bool p_legible_unique_name) { @@ -770,39 +728,32 @@ void Node::add_child_below_node(Node *p_node, Node *p_child, bool p_legible_uniq } } - void Node::_propagate_validate_owner() { if (data.owner) { - bool found=false; + bool found = false; Node *parent = data.parent; - while(parent) { - + while (parent) { - if (parent==data.owner) { + if (parent == data.owner) { - found=true; + found = true; break; } - parent=parent->data.parent; + parent = parent->data.parent; } - if (!found) { - data.owner->data.owned.erase(data.OW); - data.owner=NULL; + data.owner = NULL; } - } - - for(int i=0;i<data.children.size();i++) { - + for (int i = 0; i < data.children.size(); i++) { data.children[i]->_propagate_validate_owner(); } @@ -811,28 +762,27 @@ void Node::_propagate_validate_owner() { void Node::remove_child(Node *p_child) { ERR_FAIL_NULL(p_child); - if (data.blocked>0) { + if (data.blocked > 0) { ERR_EXPLAIN("Parent node is busy setting up children, remove_node() failed. Consider using call_deferred(\"remove_child\",child) instead."); - ERR_FAIL_COND(data.blocked>0); + ERR_FAIL_COND(data.blocked > 0); } - int idx=-1; - for (int i=0;i<data.children.size();i++) { + int idx = -1; + for (int i = 0; i < data.children.size(); i++) { - if (data.children[i]==p_child) { + if (data.children[i] == p_child) { - idx=i; + idx = i; break; } } - ERR_FAIL_COND( idx==-1 ); + ERR_FAIL_COND(idx == -1); //ERR_FAIL_COND( p_child->data.blocked > 0 ); - //if (data.scene) { does not matter - p_child->_set_tree(NULL); + p_child->_set_tree(NULL); //} remove_child_notify(p_child); @@ -840,19 +790,16 @@ void Node::remove_child(Node *p_child) { data.children.remove(idx); - for (int i=idx;i<data.children.size();i++) { + for (int i = idx; i < data.children.size(); i++) { - data.children[i]->data.pos=i; + data.children[i]->data.pos = i; } - p_child->data.parent=NULL; - p_child->data.pos=-1; - - + p_child->data.parent = NULL; + p_child->data.pos = -1; // validate owner p_child->_propagate_validate_owner(); - } int Node::get_child_count() const { @@ -861,75 +808,72 @@ int Node::get_child_count() const { } Node *Node::get_child(int p_index) const { - ERR_FAIL_INDEX_V( p_index, data.children.size(), NULL ); + ERR_FAIL_INDEX_V(p_index, data.children.size(), NULL); return data.children[p_index]; } +Node *Node::_get_child_by_name(const StringName &p_name) const { -Node *Node::_get_child_by_name(const StringName& p_name) const { + int cc = data.children.size(); + Node *const *cd = data.children.ptr(); - int cc=data.children.size(); - Node* const* cd=data.children.ptr(); - - for(int i=0;i<cc;i++){ - if (cd[i]->data.name==p_name) + for (int i = 0; i < cc; i++) { + if (cd[i]->data.name == p_name) return cd[i]; } return NULL; } -Node *Node::_get_node(const NodePath& p_path) const { +Node *Node::_get_node(const NodePath &p_path) const { if (!data.inside_tree && p_path.is_absolute()) { ERR_EXPLAIN("Can't use get_node() with absolute paths from outside the active scene tree."); ERR_FAIL_V(NULL); } - Node *current=NULL; - Node *root=NULL; + Node *current = NULL; + Node *root = NULL; if (!p_path.is_absolute()) { - current=const_cast<Node*>(this); //start from this + current = const_cast<Node *>(this); //start from this } else { - root=const_cast<Node*>(this); + root = const_cast<Node *>(this); while (root->data.parent) - root=root->data.parent; //start from root + root = root->data.parent; //start from root } - - for(int i=0;i<p_path.get_name_count();i++) { - + for (int i = 0; i < p_path.get_name_count(); i++) { StringName name = p_path.get_name(i); Node *next = NULL; - if (name==SceneStringNames::get_singleton()->dot) { // . + if (name == SceneStringNames::get_singleton()->dot) { // . - next=current; + next = current; - } else if (name==SceneStringNames::get_singleton()->doubledot) { // .. + } else if (name == SceneStringNames::get_singleton()->doubledot) { // .. - if (current==NULL || !current->data.parent) + if (current == NULL || !current->data.parent) return NULL; - next=current->data.parent; - } else if (current==NULL) { + next = current->data.parent; + } else if (current == NULL) { - if (name==root->get_name()) - next=root; + if (name == root->get_name()) + next = root; } else { - next=NULL; + next = NULL; - for(int j=0;j<current->data.children.size();j++) { + for (int j = 0; j < current->data.children.size(); j++) { Node *child = current->data.children[j]; - if ( child->data.name == name ) { + if (child->data.name == name) { next = child; break; @@ -939,33 +883,32 @@ Node *Node::_get_node(const NodePath& p_path) const { return NULL; }; } - current=next; + current = next; } return current; } -Node *Node::get_node(const NodePath& p_path) const { +Node *Node::get_node(const NodePath &p_path) const { Node *node = _get_node(p_path); if (!node) { - ERR_EXPLAIN("Node not found: "+p_path); - ERR_FAIL_COND_V(!node,NULL); + ERR_EXPLAIN("Node not found: " + p_path); + ERR_FAIL_COND_V(!node, NULL); } return node; } -bool Node::has_node(const NodePath& p_path) const { +bool Node::has_node(const NodePath &p_path) const { - return _get_node(p_path)!=NULL; + return _get_node(p_path) != NULL; } +Node *Node::find_node(const String &p_mask, bool p_recursive, bool p_owned) const { -Node* Node::find_node(const String& p_mask,bool p_recursive,bool p_owned) const { - - Node * const*cptr = data.children.ptr(); + Node *const *cptr = data.children.ptr(); int ccount = data.children.size(); - for(int i=0;i<ccount;i++) { + for (int i = 0; i < ccount; i++) { if (p_owned && !cptr[i]->data.owner) continue; if (cptr[i]->data.name.operator String().match(p_mask)) @@ -974,12 +917,11 @@ Node* Node::find_node(const String& p_mask,bool p_recursive,bool p_owned) const if (!p_recursive) continue; - Node* ret = cptr[i]->find_node(p_mask,true,p_owned); + Node *ret = cptr[i]->find_node(p_mask, true, p_owned); if (ret) return ret; } return NULL; - } Node *Node::get_parent() const { @@ -987,16 +929,15 @@ Node *Node::get_parent() const { return data.parent; } - bool Node::is_a_parent_of(const Node *p_node) const { - ERR_FAIL_NULL_V(p_node,false); - Node *p=p_node->data.parent; - while(p) { + ERR_FAIL_NULL_V(p_node, false); + Node *p = p_node->data.parent; + while (p) { - if (p==this) + if (p == this) return true; - p=p->data.parent; + p = p->data.parent; } return false; @@ -1004,12 +945,12 @@ 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_tree, false ); - ERR_FAIL_COND_V( !p_node->data.inside_tree, false ); + ERR_FAIL_NULL_V(p_node, 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); + ERR_FAIL_COND_V(data.depth < 0, false); + ERR_FAIL_COND_V(p_node->data.depth < 0, false); #ifdef NO_ALLOCA Vector<int> this_stack; @@ -1019,46 +960,46 @@ bool Node::is_greater_than(const Node *p_node) const { #else - int *this_stack=(int*)alloca(sizeof(int)*data.depth); - int *that_stack=(int*)alloca(sizeof(int)*p_node->data.depth); + int *this_stack = (int *)alloca(sizeof(int) * data.depth); + int *that_stack = (int *)alloca(sizeof(int) * p_node->data.depth); #endif const Node *n = this; - int idx=data.depth-1; - while(n) { - ERR_FAIL_INDEX_V(idx, data.depth,false); - this_stack[idx--]=n->data.pos; - n=n->data.parent; + int idx = data.depth - 1; + while (n) { + ERR_FAIL_INDEX_V(idx, data.depth, false); + this_stack[idx--] = n->data.pos; + n = n->data.parent; } - ERR_FAIL_COND_V(idx!=-1,false); + ERR_FAIL_COND_V(idx != -1, false); n = p_node; - idx=p_node->data.depth-1; - while(n) { - ERR_FAIL_INDEX_V(idx, p_node->data.depth,false); - that_stack[idx--]=n->data.pos; + idx = p_node->data.depth - 1; + while (n) { + ERR_FAIL_INDEX_V(idx, p_node->data.depth, false); + that_stack[idx--] = n->data.pos; - n=n->data.parent; + n = n->data.parent; } - ERR_FAIL_COND_V(idx!=-1,false); - idx=0; + ERR_FAIL_COND_V(idx != -1, false); + idx = 0; bool res; - while(true) { + while (true) { // using -2 since out-of-tree or nonroot nodes have -1 - int this_idx = (idx >= data.depth)? -2 : this_stack[idx]; - int that_idx = (idx >= p_node->data.depth)? -2 : that_stack[idx]; + int this_idx = (idx >= data.depth) ? -2 : this_stack[idx]; + int that_idx = (idx >= p_node->data.depth) ? -2 : that_stack[idx]; if (this_idx > that_idx) { - res=true; + res = true; break; } else if (this_idx < that_idx) { - res=false; + res = false; break; - } else if (this_idx == -2 ) { - res=false; // equal + } else if (this_idx == -2) { + res = false; // equal break; } idx++; @@ -1067,25 +1008,23 @@ bool Node::is_greater_than(const Node *p_node) const { return res; } -void Node::get_owned_by(Node *p_by,List<Node*> *p_owned) { +void Node::get_owned_by(Node *p_by, List<Node *> *p_owned) { - if (data.owner==p_by) + if (data.owner == p_by) p_owned->push_back(this); - for (int i=0;i<get_child_count();i++) - get_child(i)->get_owned_by(p_by,p_owned); - + for (int i = 0; i < get_child_count(); i++) + get_child(i)->get_owned_by(p_by, p_owned); } +void Node::_set_owner_nocheck(Node *p_owner) { -void Node::_set_owner_nocheck(Node* p_owner) { - - if (data.owner==p_owner) + if (data.owner == p_owner) return; ERR_FAIL_COND(data.owner); - data.owner=p_owner; - data.owner->data.owned.push_back( this ); + data.owner = p_owner; + data.owner->data.owned.push_back(this); data.OW = data.owner->data.owned.back(); } @@ -1093,27 +1032,27 @@ void Node::set_owner(Node *p_owner) { if (data.owner) { - data.owner->data.owned.erase( data.OW ); - data.OW=NULL; - data.owner=NULL; + data.owner->data.owned.erase(data.OW); + data.OW = NULL; + data.owner = NULL; } - ERR_FAIL_COND(p_owner==this); + ERR_FAIL_COND(p_owner == this); if (!p_owner) return; - Node *check=this->get_parent(); - bool owner_valid=false; + Node *check = this->get_parent(); + bool owner_valid = false; - while(check) { + while (check) { - if (check==p_owner) { - owner_valid=true; + if (check == p_owner) { + owner_valid = true; break; } - check=check->data.parent; + check = check->data.parent; } ERR_FAIL_COND(!owner_valid); @@ -1125,115 +1064,113 @@ Node *Node::get_owner() const { return data.owner; } +Node *Node::find_common_parent_with(const Node *p_node) const { -Node* Node::find_common_parent_with(const Node *p_node) const { + if (this == p_node) + return const_cast<Node *>(p_node); - if (this==p_node) - return const_cast<Node*>(p_node); + Set<const Node *> visited; - Set<const Node*> visited; - - const Node *n=this; + const Node *n = this; - while(n) { + while (n) { visited.insert(n); - n=n->data.parent; + n = n->data.parent; } - const Node *common_parent=p_node; + const Node *common_parent = p_node; - while(common_parent) { + while (common_parent) { if (visited.has(common_parent)) break; - common_parent=common_parent->data.parent; + common_parent = common_parent->data.parent; } if (!common_parent) return NULL; - return const_cast<Node*>(common_parent); - + return const_cast<Node *>(common_parent); } NodePath Node::get_path_to(const Node *p_node) const { - ERR_FAIL_NULL_V(p_node,NodePath()); + ERR_FAIL_NULL_V(p_node, NodePath()); - if (this==p_node) + if (this == p_node) return NodePath("."); - Set<const Node*> visited; + Set<const Node *> visited; - const Node *n=this; + const Node *n = this; - while(n) { + while (n) { visited.insert(n); - n=n->data.parent; + n = n->data.parent; } - const Node *common_parent=p_node; + const Node *common_parent = p_node; - while(common_parent) { + while (common_parent) { if (visited.has(common_parent)) break; - common_parent=common_parent->data.parent; + common_parent = common_parent->data.parent; } - ERR_FAIL_COND_V(!common_parent,NodePath()); //nodes not in the same tree + ERR_FAIL_COND_V(!common_parent, NodePath()); //nodes not in the same tree visited.clear(); Vector<StringName> path; - n=p_node; + n = p_node; - while(n!=common_parent) { + while (n != common_parent) { - path.push_back( n->get_name() ); - n=n->data.parent; + path.push_back(n->get_name()); + n = n->data.parent; } - n=this; - StringName up=String(".."); + n = this; + StringName up = String(".."); - while(n!=common_parent) { + while (n != common_parent) { - path.push_back( up ); - n=n->data.parent; + path.push_back(up); + n = n->data.parent; } path.invert(); - return NodePath(path,false); + return NodePath(path, false); } NodePath Node::get_path() const { - ERR_FAIL_COND_V(!is_inside_tree(),NodePath()); + ERR_FAIL_COND_V(!is_inside_tree(), NodePath()); const Node *n = this; Vector<StringName> path; - while(n) { + while (n) { path.push_back(n->get_name()); - n=n->data.parent; + n = n->data.parent; } path.invert(); - return NodePath( path, true ); + return NodePath(path, true); } -bool Node::is_in_group(const StringName& p_identifier) const { +bool Node::is_in_group(const StringName &p_identifier) const { return data.grouped.has(p_identifier); } -void Node::add_to_group(const StringName& p_identifier,bool p_persistent) { +void Node::add_to_group(const StringName &p_identifier, bool p_persistent) { ERR_FAIL_COND(!p_identifier.operator String().length()); @@ -1243,32 +1180,28 @@ void Node::add_to_group(const StringName& p_identifier,bool p_persistent) { GroupData gd; if (data.tree) { - gd.group=data.tree->add_to_group(p_identifier,this); + gd.group = data.tree->add_to_group(p_identifier, this); } else { - gd.group=NULL; + gd.group = NULL; } - gd.persistent=p_persistent; - - data.grouped[p_identifier]=gd; + gd.persistent = p_persistent; + data.grouped[p_identifier] = gd; } -void Node::remove_from_group(const StringName& p_identifier) { +void Node::remove_from_group(const StringName &p_identifier) { + ERR_FAIL_COND(!data.grouped.has(p_identifier)); - ERR_FAIL_COND(!data.grouped.has(p_identifier) ); - - - Map< StringName, GroupData>::Element *E=data.grouped.find(p_identifier); + Map<StringName, GroupData>::Element *E = data.grouped.find(p_identifier); ERR_FAIL_COND(!E); if (data.tree) - data.tree->remove_from_group(E->key(),this); + data.tree->remove_from_group(E->key(), this); data.grouped.erase(E); - } Array Node::_get_groups() const { @@ -1276,7 +1209,7 @@ Array Node::_get_groups() const { Array groups; List<GroupInfo> gi; get_groups(&gi); - for (List<GroupInfo>::Element *E=gi.front();E;E=E->next()) { + for (List<GroupInfo>::Element *E = gi.front(); E; E = E->next()) { groups.push_back(E->get().name); } @@ -1285,33 +1218,27 @@ Array Node::_get_groups() const { void Node::get_groups(List<GroupInfo> *p_groups) const { - - for (const Map< StringName, GroupData>::Element *E=data.grouped.front();E;E=E->next()) { + for (const Map<StringName, GroupData>::Element *E = data.grouped.front(); E; E = E->next()) { GroupInfo gi; - gi.name=E->key(); - gi.persistent=E->get().persistent; + gi.name = E->key(); + gi.persistent = E->get().persistent; p_groups->push_back(gi); } - } bool Node::has_persistent_groups() const { - - for (const Map< StringName, GroupData>::Element *E=data.grouped.front();E;E=E->next()) { + for (const Map<StringName, GroupData>::Element *E = data.grouped.front(); E; E = E->next()) { if (E->get().persistent) return true; } - return false; - - } void Node::_print_tree(const Node *p_node) { print_line(String(p_node->get_path_to(this))); - for (int i=0;i<data.children.size();i++) + for (int i = 0; i < data.children.size(); i++) data.children[i]->_print_tree(p_node); } @@ -1320,16 +1247,15 @@ void Node::print_tree() { _print_tree(this); } - void Node::_propagate_reverse_notification(int p_notification) { data.blocked++; - for (int i=data.children.size()-1;i>=0;i--) { + for (int i = data.children.size() - 1; i >= 0; i--) { data.children[i]->_propagate_reverse_notification(p_notification); } - notification(p_notification,true); + notification(p_notification, true); data.blocked--; } @@ -1340,15 +1266,15 @@ void Node::_propagate_deferred_notification(int p_notification, bool p_reverse) data.blocked++; if (!p_reverse) - MessageQueue::get_singleton()->push_notification(this,p_notification); + MessageQueue::get_singleton()->push_notification(this, p_notification); - for (int i=0;i<data.children.size();i++) { + for (int i = 0; i < data.children.size(); i++) { - data.children[i]->_propagate_deferred_notification(p_notification,p_reverse); + data.children[i]->_propagate_deferred_notification(p_notification, p_reverse); } if (p_reverse) - MessageQueue::get_singleton()->push_notification(this,p_notification); + MessageQueue::get_singleton()->push_notification(this, p_notification); data.blocked--; } @@ -1358,21 +1284,20 @@ void Node::propagate_notification(int p_notification) { data.blocked++; notification(p_notification); - for (int i=0;i<data.children.size();i++) { + for (int i = 0; i < data.children.size(); i++) { data.children[i]->propagate_notification(p_notification); } data.blocked--; } - -void Node::_propagate_replace_owner(Node *p_owner,Node* p_by_owner) { - if (get_owner()==p_owner) +void Node::_propagate_replace_owner(Node *p_owner, Node *p_by_owner) { + if (get_owner() == p_owner) set_owner(p_by_owner); data.blocked++; - for (int i=0;i<data.children.size();i++) - data.children[i]->_propagate_replace_owner(p_owner,p_by_owner); + for (int i = 0; i < data.children.size(); i++) + data.children[i]->_propagate_replace_owner(p_owner, p_by_owner); data.blocked--; } @@ -1384,21 +1309,21 @@ void Node::remove_and_skip() { ERR_FAIL_COND(!data.parent); - Node *new_owner=get_owner(); + Node *new_owner = get_owner(); - List<Node*> children; + List<Node *> children; - while(true) { + while (true) { - bool clear=true; - for (int i=0;i<data.children.size();i++) { + bool clear = true; + for (int i = 0; i < data.children.size(); i++) { if (!data.children[i]->get_owner()) continue; remove_child(data.children[i]); - data.children[i]->_propagate_replace_owner(this,NULL); + data.children[i]->_propagate_replace_owner(this, NULL); children.push_back(data.children[i]); - clear=false; + clear = false; break; } @@ -1406,27 +1331,27 @@ void Node::remove_and_skip() { break; } - while(!children.empty()) { + while (!children.empty()) { - Node *c=children.front()->get(); + Node *c = children.front()->get(); data.parent->add_child(c); - c->_propagate_replace_owner(NULL,new_owner); + c->_propagate_replace_owner(NULL, new_owner); children.pop_front(); } data.parent->remove_child(this); } -void Node::set_filename(const String& p_filename) { +void Node::set_filename(const String &p_filename) { - data.filename=p_filename; + data.filename = p_filename; } String Node::get_filename() const { return data.filename; } -void Node::set_editable_instance(Node* p_node,bool p_editable) { +void Node::set_editable_instance(Node *p_node, bool p_editable) { ERR_FAIL_NULL(p_node); ERR_FAIL_COND(!is_a_parent_of(p_node)); @@ -1434,30 +1359,28 @@ void Node::set_editable_instance(Node* p_node,bool p_editable) { if (!p_editable) data.editable_instances.erase(p); else - data.editable_instances[p]=true; - + data.editable_instances[p] = true; } bool Node::is_editable_instance(Node *p_node) const { if (!p_node) return false; //easier, null is never editable :) - ERR_FAIL_COND_V(!is_a_parent_of(p_node),false); + ERR_FAIL_COND_V(!is_a_parent_of(p_node), false); NodePath p = get_path_to(p_node); return data.editable_instances.has(p); } -void Node::set_editable_instances(const HashMap<NodePath,int>& p_editable_instances) { +void Node::set_editable_instances(const HashMap<NodePath, int> &p_editable_instances) { - data.editable_instances=p_editable_instances; + data.editable_instances = p_editable_instances; } -HashMap<NodePath,int> Node::get_editable_instances() const { +HashMap<NodePath, int> Node::get_editable_instances() const { return data.editable_instances; } - #if 0 void Node::generate_instance_state() { @@ -1511,32 +1434,32 @@ Dictionary Node::get_instance_state() const { #endif -void Node::set_scene_instance_state(const Ref<SceneState>& p_state) { +void Node::set_scene_instance_state(const Ref<SceneState> &p_state) { - data.instance_state=p_state; + data.instance_state = p_state; } -Ref<SceneState> Node::get_scene_instance_state() const{ +Ref<SceneState> Node::get_scene_instance_state() const { return data.instance_state; } -void Node::set_scene_inherited_state(const Ref<SceneState>& p_state) { +void Node::set_scene_inherited_state(const Ref<SceneState> &p_state) { - data.inherited_state=p_state; + data.inherited_state = p_state; } -Ref<SceneState> Node::get_scene_inherited_state() const{ +Ref<SceneState> Node::get_scene_inherited_state() const { return data.inherited_state; } void Node::set_scene_instance_load_placeholder(bool p_enable) { - data.use_placeholder=p_enable; + data.use_placeholder = p_enable; } -bool Node::get_scene_instance_load_placeholder() const{ +bool Node::get_scene_instance_load_placeholder() const { return data.use_placeholder; } @@ -1546,43 +1469,39 @@ int Node::get_position_in_parent() const { return data.pos; } +Node *Node::_duplicate(bool p_use_instancing, int p_flags) const { + Node *node = NULL; -Node *Node::_duplicate(bool p_use_instancing,int p_flags) const { - - - Node *node=NULL; - - bool instanced=false; + bool instanced = false; if (cast_to<InstancePlaceholder>()) { const InstancePlaceholder *ip = cast_to<const InstancePlaceholder>(); - InstancePlaceholder *nip = memnew( InstancePlaceholder ); - nip->set_instance_path( ip->get_instance_path() ); - node=nip; + InstancePlaceholder *nip = memnew(InstancePlaceholder); + nip->set_instance_path(ip->get_instance_path()); + node = nip; - } else if (p_use_instancing && get_filename()!=String()) { + } else if (p_use_instancing && get_filename() != String()) { Ref<PackedScene> res = ResourceLoader::load(get_filename()); - ERR_FAIL_COND_V(res.is_null(),NULL); - node=res->instance(); - ERR_FAIL_COND_V(!node,NULL); + ERR_FAIL_COND_V(res.is_null(), NULL); + node = res->instance(); + ERR_FAIL_COND_V(!node, NULL); - instanced=true; + instanced = true; } else { Object *obj = ObjectTypeDB::instance(get_type()); - ERR_FAIL_COND_V(!obj,NULL); + ERR_FAIL_COND_V(!obj, NULL); node = obj->cast_to<Node>(); if (!node) memdelete(obj); - ERR_FAIL_COND_V(!node,NULL); + ERR_FAIL_COND_V(!node, NULL); } - - if (get_filename()!="") { //an instance + if (get_filename() != "") { //an instance node->set_filename(get_filename()); } @@ -1590,16 +1509,15 @@ Node *Node::_duplicate(bool p_use_instancing,int p_flags) const { get_property_list(&plist); - for(List<PropertyInfo>::Element *E=plist.front();E;E=E->next()) { + for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { - if (!(E->get().usage&PROPERTY_USAGE_STORAGE)) + if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) continue; String name = E->get().name; - if (!(p_flags&DUPLICATE_SCRIPTS) && name=="script/script") + if (!(p_flags & DUPLICATE_SCRIPTS) && name == "script/script") continue; - node->set( name, get(name) ); - + node->set(name, get(name)); } node->set_name(get_name()); @@ -1607,7 +1525,7 @@ Node *Node::_duplicate(bool p_use_instancing,int p_flags) const { if (p_flags & DUPLICATE_GROUPS) { List<GroupInfo> gi; get_groups(&gi); - for (List<GroupInfo>::Element *E=gi.front();E;E=E->next()) { + for (List<GroupInfo>::Element *E = gi.front(); E; E = E->next()) { node->add_to_group(E->get().name, E->get().persistent); } @@ -1616,14 +1534,14 @@ Node *Node::_duplicate(bool p_use_instancing,int p_flags) const { if (p_flags & DUPLICATE_SIGNALS) _duplicate_signals(this, node); - for(int i=0;i<get_child_count();i++) { + for (int i = 0; i < get_child_count(); i++) { if (get_child(i)->data.parent_owned) continue; - if (instanced && get_child(i)->data.owner==this) + if (instanced && get_child(i)->data.owner == this) continue; //part of instance - Node *dup = get_child(i)->duplicate(p_use_instancing,p_flags); + Node *dup = get_child(i)->duplicate(p_use_instancing, p_flags); if (!dup) { memdelete(node); @@ -1633,40 +1551,38 @@ Node *Node::_duplicate(bool p_use_instancing,int p_flags) const { node->add_child(dup); } - return node; } -Node *Node::duplicate(bool p_use_instancing,int p_flags) const { +Node *Node::duplicate(bool p_use_instancing, int p_flags) const { - Node* dupe = _duplicate(p_use_instancing,p_flags); + Node *dupe = _duplicate(p_use_instancing, p_flags); - if (dupe && (p_flags&DUPLICATE_SIGNALS)) { - _duplicate_signals(this,dupe); + if (dupe && (p_flags & DUPLICATE_SIGNALS)) { + _duplicate_signals(this, dupe); } return dupe; } +void Node::_duplicate_and_reown(Node *p_new_parent, const Map<Node *, Node *> &p_reown_map) const { -void Node::_duplicate_and_reown(Node* p_new_parent, const Map<Node*,Node*>& p_reown_map) const { - - if (get_owner()!=get_parent()->get_owner()) + if (get_owner() != get_parent()->get_owner()) return; - Node *node=NULL; + Node *node = NULL; - if (get_filename()!="") { + if (get_filename() != "") { Ref<PackedScene> res = ResourceLoader::load(get_filename()); ERR_FAIL_COND(res.is_null()); - node=res->instance(); + node = res->instance(); ERR_FAIL_COND(!node); } else { Object *obj = ObjectTypeDB::instance(get_type()); if (!obj) { - print_line("could not duplicate: "+String(get_type())); + print_line("could not duplicate: " + String(get_type())); } ERR_FAIL_COND(!obj); node = obj->cast_to<Node>(); @@ -1674,32 +1590,29 @@ void Node::_duplicate_and_reown(Node* p_new_parent, const Map<Node*,Node*>& p_re memdelete(obj); } - List<PropertyInfo> plist; get_property_list(&plist); - for(List<PropertyInfo>::Element *E=plist.front();E;E=E->next()) { + for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { - if (!(E->get().usage&PROPERTY_USAGE_STORAGE)) + if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) continue; String name = E->get().name; - node->set( name, get(name) ); - + node->set(name, get(name)); } node->set_name(get_name()); p_new_parent->add_child(node); - Node *owner=get_owner(); + Node *owner = get_owner(); if (p_reown_map.has(owner)) - owner=p_reown_map[owner]; - + owner = p_reown_map[owner]; if (owner) { NodePath p = get_path_to(owner); - if (owner!=this) { + if (owner != this) { Node *new_owner = node->get_node(p); if (new_owner) { node->set_owner(new_owner); @@ -1707,26 +1620,23 @@ void Node::_duplicate_and_reown(Node* p_new_parent, const Map<Node*,Node*>& p_re } } - for(int i=0;i<get_child_count();i++) { + for (int i = 0; i < get_child_count(); i++) { - get_child(i)->_duplicate_and_reown(node,p_reown_map); + get_child(i)->_duplicate_and_reown(node, p_reown_map); } - } +void Node::_duplicate_signals(const Node *p_original, Node *p_copy) const { -void Node::_duplicate_signals(const Node* p_original,Node* p_copy) const { - - if (this!=p_original && (get_owner()!=p_original && get_owner()!=p_original->get_owner())) + if (this != p_original && (get_owner() != p_original && get_owner() != p_original->get_owner())) return; List<Connection> conns; get_all_signal_connections(&conns); + for (List<Connection>::Element *E = conns.front(); E; E = E->next()) { - for (List<Connection>::Element *E=conns.front();E;E=E->next()) { - - if (E->get().flags&CONNECT_PERSIST) { + if (E->get().flags & CONNECT_PERSIST) { //user connected NodePath p = p_original->get_path_to(this); Node *copy = p_copy->get_node(p); @@ -1738,37 +1648,32 @@ void Node::_duplicate_signals(const Node* p_original,Node* p_copy) const { NodePath ptarget = p_original->get_path_to(target); Node *copytarget = p_copy->get_node(ptarget); - if (copy && copytarget) { - copy->connect(E->get().signal,copytarget,E->get().method,E->get().binds,CONNECT_PERSIST); + copy->connect(E->get().signal, copytarget, E->get().method, E->get().binds, CONNECT_PERSIST); } - } } - for(int i=0;i<get_child_count();i++) { - get_child(i)->_duplicate_signals(p_original,p_copy); + for (int i = 0; i < get_child_count(); i++) { + get_child(i)->_duplicate_signals(p_original, p_copy); } - } +Node *Node::duplicate_and_reown(const Map<Node *, Node *> &p_reown_map) const { -Node *Node::duplicate_and_reown(const Map<Node*,Node*>& p_reown_map) const { - - - ERR_FAIL_COND_V(get_filename()!="",NULL); + ERR_FAIL_COND_V(get_filename() != "", NULL); - Node *node=NULL; + Node *node = NULL; Object *obj = ObjectTypeDB::instance(get_type()); if (!obj) { - print_line("could not duplicate: "+String(get_type())); + print_line("could not duplicate: " + String(get_type())); } - ERR_FAIL_COND_V(!obj,NULL); + ERR_FAIL_COND_V(!obj, NULL); node = obj->cast_to<Node>(); if (!node) memdelete(obj); - ERR_FAIL_COND_V(!node,NULL); + ERR_FAIL_COND_V(!node, NULL); node->set_name(get_name()); @@ -1776,35 +1681,31 @@ Node *Node::duplicate_and_reown(const Map<Node*,Node*>& p_reown_map) const { get_property_list(&plist); - for(List<PropertyInfo>::Element *E=plist.front();E;E=E->next()) { + for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { - if (!(E->get().usage&PROPERTY_USAGE_STORAGE)) + if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) continue; String name = E->get().name; - node->set( name, get(name) ); - + node->set(name, get(name)); } + for (int i = 0; i < get_child_count(); i++) { - for(int i=0;i<get_child_count();i++) { - - get_child(i)->_duplicate_and_reown(node,p_reown_map); + get_child(i)->_duplicate_and_reown(node, p_reown_map); } - _duplicate_signals(this,node); + _duplicate_signals(this, node); return node; - } -static void find_owned_by(Node* p_by, Node* p_node, List<Node*> *p_owned) { +static void find_owned_by(Node *p_by, Node *p_node, List<Node *> *p_owned) { - - if (p_node->get_owner()==p_by) + if (p_node->get_owner() == p_by) p_owned->push_back(p_node); - for(int i=0;i<p_node->get_child_count();i++) { + for (int i = 0; i < p_node->get_child_count(); i++) { - find_owned_by(p_by,p_node->get_child(i),p_owned); + find_owned_by(p_by, p_node->get_child(i), p_owned); } } @@ -1814,14 +1715,14 @@ struct _NodeReplaceByPair { Variant value; }; -void Node::replace_by(Node* p_node,bool p_keep_data) { +void Node::replace_by(Node *p_node, bool p_keep_data) { ERR_FAIL_NULL(p_node); ERR_FAIL_COND(p_node->data.parent); - List<Node*> owned = data.owned; - List<Node*> owned_by_owner; - Node *owner = (data.owner==this)?p_node:data.owner; + List<Node *> owned = data.owned; + List<Node *> owned_by_owner; + Node *owner = (data.owner == this) ? p_node : data.owner; List<_NodeReplaceByPair> replace_data; @@ -1830,27 +1731,27 @@ void Node::replace_by(Node* p_node,bool p_keep_data) { List<PropertyInfo> plist; get_property_list(&plist); - for(List<PropertyInfo>::Element *E=plist.front();E;E=E->next() ) { + for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) { _NodeReplaceByPair rd; - if (!(E->get().usage&PROPERTY_USAGE_STORAGE)) + if (!(E->get().usage & PROPERTY_USAGE_STORAGE)) continue; - rd.name=E->get().name; - rd.value=get(rd.name); + rd.name = E->get().name; + rd.value = get(rd.name); } List<GroupInfo> groups; get_groups(&groups); - for(List<GroupInfo>::Element *E=groups.front();E;E=E->next()) + for (List<GroupInfo>::Element *E = groups.front(); E; E = E->next()) p_node->add_to_group(E->get().name, E->get().persistent); } _replace_connections_target(p_node); if (data.owner) { - for(int i=0;i<get_child_count();i++) - find_owned_by(data.owner,get_child(i),&owned_by_owner); + for (int i = 0; i < get_child_count(); i++) + find_owned_by(data.owner, get_child(i), &owned_by_owner); } Node *parent = data.parent; @@ -1860,73 +1761,70 @@ void Node::replace_by(Node* p_node,bool p_keep_data) { parent->remove_child(this); parent->add_child(p_node); - parent->move_child(p_node,pos_in_parent); + parent->move_child(p_node, pos_in_parent); } - while(get_child_count()) { + while (get_child_count()) { - Node * child = get_child(0); + Node *child = get_child(0); remove_child(child); p_node->add_child(child); } p_node->set_owner(owner); - for(int i=0;i<owned.size();i++) + for (int i = 0; i < owned.size(); i++) owned[i]->set_owner(p_node); - for(int i=0;i<owned_by_owner.size();i++) + for (int i = 0; i < owned_by_owner.size(); i++) owned_by_owner[i]->set_owner(owner); p_node->set_filename(get_filename()); - for (List<_NodeReplaceByPair>::Element *E=replace_data.front();E;E=E->next()) { + for (List<_NodeReplaceByPair>::Element *E = replace_data.front(); E; E = E->next()) { - p_node->set(E->get().name,E->get().value); + p_node->set(E->get().name, E->get().value); } - } -void Node::_replace_connections_target(Node* p_new_target) { +void Node::_replace_connections_target(Node *p_new_target) { List<Connection> cl; get_signals_connected_to_this(&cl); - for(List<Connection>::Element *E=cl.front();E;E=E->next()) { + for (List<Connection>::Element *E = cl.front(); E; E = E->next()) { - Connection &c=E->get(); + Connection &c = E->get(); - c.source->disconnect(c.signal,this,c.method); - c.source->connect(c.signal,p_new_target,c.method,c.binds,c.flags); + c.source->disconnect(c.signal, this, c.method); + c.source->connect(c.signal, p_new_target, c.method, c.binds, c.flags); } } Vector<Variant> Node::make_binds(VARIANT_ARG_DECLARE) { - Vector<Variant> ret; - if (p_arg1.get_type()==Variant::NIL) + if (p_arg1.get_type() == Variant::NIL) return ret; else ret.push_back(p_arg1); - if (p_arg2.get_type()==Variant::NIL) + if (p_arg2.get_type() == Variant::NIL) return ret; else ret.push_back(p_arg2); - - if (p_arg3.get_type()==Variant::NIL) + if (p_arg3.get_type() == Variant::NIL) return ret; else ret.push_back(p_arg3); - if (p_arg4.get_type()==Variant::NIL) + if (p_arg4.get_type() == Variant::NIL) return ret; else ret.push_back(p_arg4); - if (p_arg5.get_type()==Variant::NIL) + if (p_arg5.get_type() == Variant::NIL) return ret; else ret.push_back(p_arg5); @@ -1934,9 +1832,7 @@ Vector<Variant> Node::make_binds(VARIANT_ARG_DECLARE) { return ret; } - - -bool Node::has_node_and_resource(const NodePath& p_path) const { +bool Node::has_node_and_resource(const NodePath &p_path) const { if (!has_node(p_path)) return false; @@ -1945,23 +1841,21 @@ bool Node::has_node_and_resource(const NodePath& p_path) const { if (p_path.get_subname_count()) { RES r; - for(int j=0;j<p_path.get_subname_count();j++) { - r = j==0 ? node->get(p_path.get_subname(j)) : r->get(p_path.get_subname(j)); + for (int j = 0; j < p_path.get_subname_count(); j++) { + r = j == 0 ? node->get(p_path.get_subname(j)) : r->get(p_path.get_subname(j)); if (r.is_null()) return false; } } - return true; } - -Array Node::_get_node_and_resource(const NodePath& p_path) { +Array Node::_get_node_and_resource(const NodePath &p_path) { Node *node; RES res; - node = get_node_and_resource(p_path,res); + node = get_node_and_resource(p_path, res); Array result; if (node) @@ -1977,7 +1871,7 @@ Array Node::_get_node_and_resource(const NodePath& p_path) { return result; } -Node *Node::get_node_and_resource(const NodePath& p_path,RES& r_res) const { +Node *Node::get_node_and_resource(const NodePath &p_path, RES &r_res) const { Node *node = get_node(p_path); r_res = RES(); @@ -1986,9 +1880,9 @@ Node *Node::get_node_and_resource(const NodePath& p_path,RES& r_res) const { if (p_path.get_subname_count()) { - for(int j=0;j<p_path.get_subname_count();j++) { - r_res = j==0 ? node->get(p_path.get_subname(j)) : r_res->get(p_path.get_subname(j)); - ERR_FAIL_COND_V( r_res.is_null(), node ); + for (int j = 0; j < p_path.get_subname_count(); j++) { + r_res = j == 0 ? node->get(p_path.get_subname(j)) : r_res->get(p_path.get_subname(j)); + ERR_FAIL_COND_V(r_res.is_null(), node); } } @@ -1997,40 +1891,35 @@ Node *Node::get_node_and_resource(const NodePath& p_path,RES& r_res) const { void Node::_set_tree(SceneTree *p_tree) { - SceneTree *tree_changed_a=NULL; - SceneTree *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 + // ERR_FAIL_COND(p_scene && data.parent && !data.parent->data.scene); //nobug if both are null if (data.tree) { _propagate_exit_tree(); - tree_changed_a=data.tree; + tree_changed_a = data.tree; } - - data.tree=p_tree; + data.tree = p_tree; if (data.tree) { - _propagate_enter_tree(); if (!data.parent || data.parent->data.ready_notified) { // No parent (root) or parent ready _propagate_ready(); //reverse_notification(NOTIFICATION_READY); } - tree_changed_b=data.tree; - + tree_changed_b = data.tree; } if (tree_changed_a) tree_changed_a->tree_changed(); if (tree_changed_b) tree_changed_b->tree_changed(); - } - static void _Node_debug_sn(Object *p_obj) { Node *n = p_obj->cast_to<Node>(); @@ -2040,18 +1929,17 @@ static void _Node_debug_sn(Object *p_obj) { if (n->is_inside_tree()) return; - Node *p=n; - while(p->get_parent()) { - p=p->get_parent(); + Node *p = n; + while (p->get_parent()) { + p = p->get_parent(); } String path; - if (p==n) - path=n->get_name(); + if (p == n) + path = n->get_name(); else - path=String(p->get_name())+"/"+p->get_path_to(n); - print_line(itos(p_obj->get_instance_ID())+"- Stray Node: "+path+" (Type: "+n->get_type()+")"); - + path = String(p->get_name()) + "/" + p->get_path_to(n); + print_line(itos(p_obj->get_instance_ID()) + "- Stray Node: " + path + " (Type: " + n->get_type() + ")"); } void Node::_print_stray_nodes() { @@ -2069,7 +1957,7 @@ void Node::print_stray_nodes() { void Node::queue_delete() { - ERR_FAIL_COND( !is_inside_tree() ); + ERR_FAIL_COND(!is_inside_tree()); get_tree()->queue_delete(this); } @@ -2078,17 +1966,16 @@ Array Node::_get_children() const { Array arr; int cc = get_child_count(); arr.resize(cc); - for(int i=0;i<cc;i++) - arr[i]=get_child(i); + for (int i = 0; i < cc; i++) + arr[i] = get_child(i); return arr; } #ifdef TOOLS_ENABLED -void Node::set_import_path(const NodePath& p_import_path) { +void Node::set_import_path(const NodePath &p_import_path) { - - data.import_path=p_import_path; + data.import_path = p_import_path; } NodePath Node::get_import_path() const { @@ -2098,35 +1985,33 @@ 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) { +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()) + 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); + 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 { +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) { + String pf = p_function; + if ((pf == "has_node" || pf == "get_node") && p_idx == 0) { - _add_nodes_to_options(this,this,r_options); + _add_nodes_to_options(this, this, r_options); } - Object::get_argument_options(p_function,p_idx,r_options); + Object::get_argument_options(p_function, p_idx, r_options); } - void Node::clear_internal_tree_resource_paths() { clear_internal_resource_paths(); - for(int i=0;i<data.children.size();i++) { + for (int i = 0; i < data.children.size(); i++) { data.children[i]->clear_internal_tree_resource_paths(); } - } String Node::get_configuration_warning() const { @@ -2139,11 +2024,10 @@ void Node::update_configuration_warning() { #ifdef TOOLS_ENABLED if (!is_inside_tree()) return; - if (get_tree()->get_edited_scene_root() && (get_tree()->get_edited_scene_root()==this || get_tree()->get_edited_scene_root()->is_a_parent_of(this))) { - get_tree()->emit_signal(SceneStringNames::get_singleton()->node_configuration_warning_changed,this); + if (get_tree()->get_edited_scene_root() && (get_tree()->get_edited_scene_root() == this || get_tree()->get_edited_scene_root()->is_a_parent_of(this))) { + get_tree()->emit_signal(SceneStringNames::get_singleton()->node_configuration_warning_changed, this); } #endif - } bool Node::is_owned_by_parent() const { @@ -2151,7 +2035,7 @@ bool Node::is_owned_by_parent() const { } void Node::set_display_folded(bool p_folded) { - data.display_folded=p_folded; + data.display_folded = p_folded; } bool Node::is_displayed_folded() const { @@ -2161,174 +2045,162 @@ bool Node::is_displayed_folded() const { void Node::_bind_methods() { - ObjectTypeDB::bind_method(_MD("_add_child_below_node","node:Node","child_node:Node","legible_unique_name"),&Node::add_child_below_node,DEFVAL(false)); + ObjectTypeDB::bind_method(_MD("_add_child_below_node", "node:Node", "child_node:Node", "legible_unique_name"), &Node::add_child_below_node, DEFVAL(false)); - ObjectTypeDB::bind_method(_MD("set_name","name"),&Node::set_name); - ObjectTypeDB::bind_method(_MD("get_name"),&Node::get_name); - ObjectTypeDB::bind_method(_MD("add_child","node:Node","legible_unique_name"),&Node::add_child,DEFVAL(false)); - ObjectTypeDB::bind_method(_MD("remove_child","node:Node"),&Node::remove_child); + ObjectTypeDB::bind_method(_MD("set_name", "name"), &Node::set_name); + ObjectTypeDB::bind_method(_MD("get_name"), &Node::get_name); + ObjectTypeDB::bind_method(_MD("add_child", "node:Node", "legible_unique_name"), &Node::add_child, DEFVAL(false)); + ObjectTypeDB::bind_method(_MD("remove_child", "node:Node"), &Node::remove_child); //ObjectTypeDB::bind_method(_MD("remove_and_delete_child","node:Node"),&Node::remove_and_delete_child); - ObjectTypeDB::bind_method(_MD("get_child_count"),&Node::get_child_count); - ObjectTypeDB::bind_method(_MD("get_children"),&Node::_get_children); - ObjectTypeDB::bind_method(_MD("get_child:Node","idx"),&Node::get_child); - ObjectTypeDB::bind_method(_MD("has_node","path"),&Node::has_node); - ObjectTypeDB::bind_method(_MD("get_node:Node","path"),&Node::get_node); - ObjectTypeDB::bind_method(_MD("get_parent:Node"),&Node::get_parent); - ObjectTypeDB::bind_method(_MD("find_node:Node","mask","recursive","owned"),&Node::find_node,DEFVAL(true),DEFVAL(true)); - 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_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); - ObjectTypeDB::bind_method(_MD("get_path_to","node:Node"),&Node::get_path_to); - ObjectTypeDB::bind_method(_MD("add_to_group","group","persistent"),&Node::add_to_group,DEFVAL(false)); - ObjectTypeDB::bind_method(_MD("remove_from_group","group"),&Node::remove_from_group); - ObjectTypeDB::bind_method(_MD("is_in_group","group"),&Node::is_in_group); - ObjectTypeDB::bind_method(_MD("move_child","child_node:Node","to_pos"),&Node::move_child); - ObjectTypeDB::bind_method(_MD("get_groups"),&Node::_get_groups); - ObjectTypeDB::bind_method(_MD("raise"),&Node::raise); - ObjectTypeDB::bind_method(_MD("set_owner","owner:Node"),&Node::set_owner); - ObjectTypeDB::bind_method(_MD("get_owner:Node"),&Node::get_owner); - ObjectTypeDB::bind_method(_MD("remove_and_skip"),&Node::remove_and_skip); - ObjectTypeDB::bind_method(_MD("get_index"),&Node::get_index); - ObjectTypeDB::bind_method(_MD("print_tree"),&Node::print_tree); - ObjectTypeDB::bind_method(_MD("set_filename","filename"),&Node::set_filename); - ObjectTypeDB::bind_method(_MD("get_filename"),&Node::get_filename); - ObjectTypeDB::bind_method(_MD("propagate_notification","what"),&Node::propagate_notification); - ObjectTypeDB::bind_method(_MD("set_fixed_process","enable"),&Node::set_fixed_process); - ObjectTypeDB::bind_method(_MD("get_fixed_process_delta_time"),&Node::get_fixed_process_delta_time); - ObjectTypeDB::bind_method(_MD("is_fixed_processing"),&Node::is_fixed_processing); - ObjectTypeDB::bind_method(_MD("set_process","enable"),&Node::set_process); - ObjectTypeDB::bind_method(_MD("get_process_delta_time"),&Node::get_process_delta_time); - ObjectTypeDB::bind_method(_MD("is_processing"),&Node::is_processing); - ObjectTypeDB::bind_method(_MD("set_process_input","enable"),&Node::set_process_input); - ObjectTypeDB::bind_method(_MD("is_processing_input"),&Node::is_processing_input); - ObjectTypeDB::bind_method(_MD("set_process_unhandled_input","enable"),&Node::set_process_unhandled_input); - ObjectTypeDB::bind_method(_MD("is_processing_unhandled_input"),&Node::is_processing_unhandled_input); - ObjectTypeDB::bind_method(_MD("set_process_unhandled_key_input","enable"),&Node::set_process_unhandled_key_input); - ObjectTypeDB::bind_method(_MD("is_processing_unhandled_key_input"),&Node::is_processing_unhandled_key_input); - ObjectTypeDB::bind_method(_MD("set_pause_mode","mode"),&Node::set_pause_mode); - ObjectTypeDB::bind_method(_MD("get_pause_mode"),&Node::get_pause_mode); - ObjectTypeDB::bind_method(_MD("can_process"),&Node::can_process); - 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("set_display_folded","fold"),&Node::set_display_folded); - ObjectTypeDB::bind_method(_MD("is_displayed_folded"),&Node::is_displayed_folded); + ObjectTypeDB::bind_method(_MD("get_child_count"), &Node::get_child_count); + ObjectTypeDB::bind_method(_MD("get_children"), &Node::_get_children); + ObjectTypeDB::bind_method(_MD("get_child:Node", "idx"), &Node::get_child); + ObjectTypeDB::bind_method(_MD("has_node", "path"), &Node::has_node); + ObjectTypeDB::bind_method(_MD("get_node:Node", "path"), &Node::get_node); + ObjectTypeDB::bind_method(_MD("get_parent:Node"), &Node::get_parent); + ObjectTypeDB::bind_method(_MD("find_node:Node", "mask", "recursive", "owned"), &Node::find_node, DEFVAL(true), DEFVAL(true)); + 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("get_tree:SceneTree"),&Node::get_tree); + 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); + ObjectTypeDB::bind_method(_MD("get_path_to", "node:Node"), &Node::get_path_to); + ObjectTypeDB::bind_method(_MD("add_to_group", "group", "persistent"), &Node::add_to_group, DEFVAL(false)); + ObjectTypeDB::bind_method(_MD("remove_from_group", "group"), &Node::remove_from_group); + ObjectTypeDB::bind_method(_MD("is_in_group", "group"), &Node::is_in_group); + ObjectTypeDB::bind_method(_MD("move_child", "child_node:Node", "to_pos"), &Node::move_child); + ObjectTypeDB::bind_method(_MD("get_groups"), &Node::_get_groups); + ObjectTypeDB::bind_method(_MD("raise"), &Node::raise); + ObjectTypeDB::bind_method(_MD("set_owner", "owner:Node"), &Node::set_owner); + ObjectTypeDB::bind_method(_MD("get_owner:Node"), &Node::get_owner); + ObjectTypeDB::bind_method(_MD("remove_and_skip"), &Node::remove_and_skip); + ObjectTypeDB::bind_method(_MD("get_index"), &Node::get_index); + ObjectTypeDB::bind_method(_MD("print_tree"), &Node::print_tree); + ObjectTypeDB::bind_method(_MD("set_filename", "filename"), &Node::set_filename); + ObjectTypeDB::bind_method(_MD("get_filename"), &Node::get_filename); + ObjectTypeDB::bind_method(_MD("propagate_notification", "what"), &Node::propagate_notification); + ObjectTypeDB::bind_method(_MD("set_fixed_process", "enable"), &Node::set_fixed_process); + ObjectTypeDB::bind_method(_MD("get_fixed_process_delta_time"), &Node::get_fixed_process_delta_time); + ObjectTypeDB::bind_method(_MD("is_fixed_processing"), &Node::is_fixed_processing); + ObjectTypeDB::bind_method(_MD("set_process", "enable"), &Node::set_process); + ObjectTypeDB::bind_method(_MD("get_process_delta_time"), &Node::get_process_delta_time); + ObjectTypeDB::bind_method(_MD("is_processing"), &Node::is_processing); + ObjectTypeDB::bind_method(_MD("set_process_input", "enable"), &Node::set_process_input); + ObjectTypeDB::bind_method(_MD("is_processing_input"), &Node::is_processing_input); + ObjectTypeDB::bind_method(_MD("set_process_unhandled_input", "enable"), &Node::set_process_unhandled_input); + ObjectTypeDB::bind_method(_MD("is_processing_unhandled_input"), &Node::is_processing_unhandled_input); + ObjectTypeDB::bind_method(_MD("set_process_unhandled_key_input", "enable"), &Node::set_process_unhandled_key_input); + ObjectTypeDB::bind_method(_MD("is_processing_unhandled_key_input"), &Node::is_processing_unhandled_key_input); + ObjectTypeDB::bind_method(_MD("set_pause_mode", "mode"), &Node::set_pause_mode); + ObjectTypeDB::bind_method(_MD("get_pause_mode"), &Node::get_pause_mode); + ObjectTypeDB::bind_method(_MD("can_process"), &Node::can_process); + 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("set_display_folded", "fold"), &Node::set_display_folded); + ObjectTypeDB::bind_method(_MD("is_displayed_folded"), &Node::is_displayed_folded); - ObjectTypeDB::bind_method(_MD("duplicate:Node","use_instancing","flags"),&Node::duplicate,DEFVAL(false),DEFVAL(DUPLICATE_SIGNALS|DUPLICATE_GROUPS|DUPLICATE_SCRIPTS)); - ObjectTypeDB::bind_method(_MD("replace_by","node:Node","keep_data"),&Node::replace_by,DEFVAL(false)); + ObjectTypeDB::bind_method(_MD("get_tree:SceneTree"), &Node::get_tree); - ObjectTypeDB::bind_method(_MD("set_scene_instance_load_placeholder","load_placeholder"),&Node::set_scene_instance_load_placeholder); - ObjectTypeDB::bind_method(_MD("get_scene_instance_load_placeholder"),&Node::get_scene_instance_load_placeholder); - - - ObjectTypeDB::bind_method(_MD("get_viewport"),&Node::get_viewport); - - ObjectTypeDB::bind_method(_MD("queue_free"),&Node::queue_delete); + ObjectTypeDB::bind_method(_MD("duplicate:Node", "use_instancing", "flags"), &Node::duplicate, DEFVAL(false), DEFVAL(DUPLICATE_SIGNALS | DUPLICATE_GROUPS | DUPLICATE_SCRIPTS)); + ObjectTypeDB::bind_method(_MD("replace_by", "node:Node", "keep_data"), &Node::replace_by, DEFVAL(false)); + ObjectTypeDB::bind_method(_MD("set_scene_instance_load_placeholder", "load_placeholder"), &Node::set_scene_instance_load_placeholder); + ObjectTypeDB::bind_method(_MD("get_scene_instance_load_placeholder"), &Node::get_scene_instance_load_placeholder); + ObjectTypeDB::bind_method(_MD("get_viewport"), &Node::get_viewport); + ObjectTypeDB::bind_method(_MD("queue_free"), &Node::queue_delete); #ifdef TOOLS_ENABLED - ObjectTypeDB::bind_method(_MD("_set_import_path","import_path"),&Node::set_import_path); - ObjectTypeDB::bind_method(_MD("_get_import_path"),&Node::get_import_path); - ADD_PROPERTYNZ( PropertyInfo(Variant::NODE_PATH,"_import_path",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),_SCS("_set_import_path"),_SCS("_get_import_path")); + ObjectTypeDB::bind_method(_MD("_set_import_path", "import_path"), &Node::set_import_path); + ObjectTypeDB::bind_method(_MD("_get_import_path"), &Node::get_import_path); + ADD_PROPERTYNZ(PropertyInfo(Variant::NODE_PATH, "_import_path", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), _SCS("_set_import_path"), _SCS("_get_import_path")); #endif - BIND_CONSTANT( NOTIFICATION_ENTER_TREE ); - BIND_CONSTANT( NOTIFICATION_EXIT_TREE ); - BIND_CONSTANT( NOTIFICATION_MOVED_IN_PARENT ); + 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 ); - BIND_CONSTANT( NOTIFICATION_PARENTED ); - BIND_CONSTANT( NOTIFICATION_UNPARENTED ); - BIND_CONSTANT( NOTIFICATION_PAUSED ); - BIND_CONSTANT( NOTIFICATION_UNPAUSED ); - BIND_CONSTANT( NOTIFICATION_INSTANCED ); - BIND_CONSTANT( NOTIFICATION_DRAG_BEGIN ); - BIND_CONSTANT( NOTIFICATION_DRAG_END ); - + BIND_CONSTANT(NOTIFICATION_READY); + BIND_CONSTANT(NOTIFICATION_FIXED_PROCESS); + BIND_CONSTANT(NOTIFICATION_PROCESS); + BIND_CONSTANT(NOTIFICATION_PARENTED); + BIND_CONSTANT(NOTIFICATION_UNPARENTED); + BIND_CONSTANT(NOTIFICATION_PAUSED); + BIND_CONSTANT(NOTIFICATION_UNPAUSED); + BIND_CONSTANT(NOTIFICATION_INSTANCED); + BIND_CONSTANT(NOTIFICATION_DRAG_BEGIN); + BIND_CONSTANT(NOTIFICATION_DRAG_END); + BIND_CONSTANT(PAUSE_MODE_INHERIT); + BIND_CONSTANT(PAUSE_MODE_STOP); + BIND_CONSTANT(PAUSE_MODE_PROCESS); - BIND_CONSTANT( PAUSE_MODE_INHERIT ); - BIND_CONSTANT( PAUSE_MODE_STOP ); - BIND_CONSTANT( PAUSE_MODE_PROCESS ); + BIND_CONSTANT(DUPLICATE_SIGNALS); + BIND_CONSTANT(DUPLICATE_GROUPS); + BIND_CONSTANT(DUPLICATE_SCRIPTS); - BIND_CONSTANT( DUPLICATE_SIGNALS ); - BIND_CONSTANT( DUPLICATE_GROUPS ); - BIND_CONSTANT( DUPLICATE_SCRIPTS ); + ADD_SIGNAL(MethodInfo("renamed")); + ADD_SIGNAL(MethodInfo("enter_tree")); + ADD_SIGNAL(MethodInfo("exit_tree")); - ADD_SIGNAL( MethodInfo("renamed") ); - 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") ); + // 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") ); //ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "process/input" ), _SCS("set_process_input"),_SCS("is_processing_input" ) ); //ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "process/unhandled_input" ), _SCS("set_process_unhandled_input"),_SCS("is_processing_unhandled_input" ) ); - ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "process/pause_mode",PROPERTY_HINT_ENUM,"Inherit,Stop,Process" ), _SCS("set_pause_mode"),_SCS("get_pause_mode" ) ); - ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "editor/display_folded",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR ), _SCS("set_display_folded"),_SCS("is_displayed_folded" ) ); + ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "process/pause_mode", PROPERTY_HINT_ENUM, "Inherit,Stop,Process"), _SCS("set_pause_mode"), _SCS("get_pause_mode")); + ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "editor/display_folded", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), _SCS("set_display_folded"), _SCS("is_displayed_folded")); - BIND_VMETHOD( MethodInfo("_process",PropertyInfo(Variant::REAL,"delta")) ); - BIND_VMETHOD( MethodInfo("_fixed_process",PropertyInfo(Variant::REAL,"delta")) ); - 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")) ); - BIND_VMETHOD( MethodInfo("_unhandled_key_input",PropertyInfo(Variant::INPUT_EVENT,"key_event")) ); + BIND_VMETHOD(MethodInfo("_process", PropertyInfo(Variant::REAL, "delta"))); + BIND_VMETHOD(MethodInfo("_fixed_process", PropertyInfo(Variant::REAL, "delta"))); + 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"))); + BIND_VMETHOD(MethodInfo("_unhandled_key_input", PropertyInfo(Variant::INPUT_EVENT, "key_event"))); //ObjectTypeDB::bind_method(_MD("get_child",&Node::get_child,PH("index"))); //ObjectTypeDB::bind_method(_MD("get_node",&Node::get_node,PH("path"))); } - Node::Node() { - data.pos=-1; - data.depth=-1; - data.blocked=0; - data.parent=NULL; - data.tree=NULL; - data.fixed_process=false; - data.idle_process=false; - data.inside_tree=false; - data.ready_notified=false; + data.pos = -1; + data.depth = -1; + data.blocked = 0; + data.parent = NULL; + data.tree = NULL; + data.fixed_process = false; + data.idle_process = false; + data.inside_tree = false; + data.ready_notified = false; - data.owner=NULL; - data.OW=NULL; - data.input=false; - data.unhandled_input=false; - data.unhandled_key_input=false; - data.pause_mode=PAUSE_MODE_INHERIT; - data.pause_owner=NULL; - data.parent_owned=false; - data.in_constructor=true; - data.viewport=NULL; - data.use_placeholder=false; - data.display_folded=false; + data.owner = NULL; + data.OW = NULL; + data.input = false; + data.unhandled_input = false; + data.unhandled_key_input = false; + data.pause_mode = PAUSE_MODE_INHERIT; + data.pause_owner = NULL; + data.parent_owned = false; + data.in_constructor = true; + data.viewport = NULL; + data.use_placeholder = false; + data.display_folded = false; } Node::~Node() { - data.grouped.clear(); data.owned.clear(); data.children.clear(); - ERR_FAIL_COND(data.parent); ERR_FAIL_COND(data.children.size()); - - } - //////////////////////////////// diff --git a/scene/main/node.h b/scene/main/node.h index cf5d65786..29b8d9bf2 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -29,23 +29,21 @@ #ifndef NODE_H #define NODE_H -#include "object.h" -#include "path_db.h" #include "map.h" +#include "object.h" #include "object_type_db.h" -#include "script_language.h" +#include "path_db.h" #include "scene/main/scene_main_loop.h" - +#include "script_language.h" class Viewport; class SceneState; class Node : public Object { - OBJ_TYPE( Node, Object ); + OBJ_TYPE(Node, Object); OBJ_CATEGORY("Nodes"); public: - enum PauseMode { PAUSE_MODE_INHERIT, @@ -55,23 +53,22 @@ public: enum DuplicateFlags { - DUPLICATE_SIGNALS=1, - DUPLICATE_GROUPS=2, - DUPLICATE_SCRIPTS=4 + DUPLICATE_SIGNALS = 1, + DUPLICATE_GROUPS = 2, + DUPLICATE_SCRIPTS = 4 }; struct Comparator { - bool operator()(const Node* p_a, const Node* p_b) const { return p_b->is_greater_than(p_a); } + bool operator()(const Node *p_a, const Node *p_b) const { return p_b->is_greater_than(p_a); } }; private: - struct GroupData { bool persistent; SceneTree::Group *group; - GroupData() { persistent=false; } + GroupData() { persistent = false; } }; struct Data { @@ -80,11 +77,11 @@ private: Ref<SceneState> instance_state; Ref<SceneState> inherited_state; - HashMap<NodePath,int> editable_instances; + HashMap<NodePath, int> editable_instances; Node *parent; Node *owner; - Vector<Node*> children; // list of children + Vector<Node *> children; // list of children int pos; int depth; int blocked; // safeguard that throws an error when attempting to modify the tree in a harmful way while being traversed. @@ -98,10 +95,9 @@ private: Viewport *viewport; - - Map< StringName, GroupData> grouped; - List<Node*>::Element *OW; // owned element - List<Node*> owned; + Map<StringName, GroupData> grouped; + List<Node *>::Element *OW; // owned element + List<Node *> owned; PauseMode pause_mode; Node *pause_owner; @@ -122,16 +118,15 @@ private: } data; - void _print_tree(const Node *p_node); virtual bool _use_builtin_script() const { return true; } - Node *_get_node(const NodePath& p_path) const; - Node *_get_child_by_name(const StringName& p_name) const; + Node *_get_node(const NodePath &p_path) const; + Node *_get_child_by_name(const StringName &p_name) const; - void _replace_connections_target(Node* p_new_target); + void _replace_connections_target(Node *p_new_target); - void _validate_child_name(Node *p_name, bool p_force_human_readable=false); + void _validate_child_name(Node *p_name, bool p_force_human_readable = false); void _propagate_reverse_notification(int p_notification); void _propagate_deferred_notification(int p_notification, bool p_reverse); @@ -140,23 +135,23 @@ private: void _propagate_exit_tree(); void _propagate_validate_owner(); void _print_stray_nodes(); - void _propagate_pause_owner(Node*p_owner); - Array _get_node_and_resource(const NodePath& p_path); + void _propagate_pause_owner(Node *p_owner); + Array _get_node_and_resource(const NodePath &p_path); - void _duplicate_signals(const Node* p_original,Node* p_copy) const; - void _duplicate_and_reown(Node* p_new_parent, const Map<Node*,Node*>& p_reown_map) const; - Node *_duplicate(bool p_use_instancing,int p_flags) const; + void _duplicate_signals(const Node *p_original, Node *p_copy) const; + void _duplicate_and_reown(Node *p_new_parent, const Map<Node *, Node *> &p_reown_map) const; + Node *_duplicate(bool p_use_instancing, int p_flags) const; Array _get_children() const; Array _get_groups() const; -friend class SceneTree; + friend class SceneTree; void _set_tree(SceneTree *p_tree); -protected: +protected: void _block() { data.blocked++; } - void _unblock() { data.blocked--; } + void _unblock() { data.blocked--; } void _notification(int p_notification); @@ -165,55 +160,57 @@ protected: 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); + void _propagate_replace_owner(Node *p_owner, Node *p_by_owner); static void _bind_methods(); -friend class SceneState; + friend class SceneState; - void _add_child_nocheck(Node* p_child,const StringName& p_name); - void _set_owner_nocheck(Node* p_owner); - void _set_name_nocheck(const StringName& p_name); + void _add_child_nocheck(Node *p_child, const StringName &p_name); + void _set_owner_nocheck(Node *p_owner); + void _set_name_nocheck(const StringName &p_name); public: - enum { // you can make your own, but don't use the same numbers as other notifications in other nodes - NOTIFICATION_ENTER_TREE=10, - NOTIFICATION_EXIT_TREE =11, - NOTIFICATION_MOVED_IN_PARENT =12, - NOTIFICATION_READY=13, + 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 - NOTIFICATION_PAUSED=14, - NOTIFICATION_UNPAUSED=15, + NOTIFICATION_PAUSED = 14, + NOTIFICATION_UNPAUSED = 15, NOTIFICATION_FIXED_PROCESS = 16, NOTIFICATION_PROCESS = 17, - NOTIFICATION_PARENTED=18, - NOTIFICATION_UNPARENTED=19, - NOTIFICATION_INSTANCED=20, - NOTIFICATION_DRAG_BEGIN=21, - NOTIFICATION_DRAG_END=22, + NOTIFICATION_PARENTED = 18, + NOTIFICATION_UNPARENTED = 19, + NOTIFICATION_INSTANCED = 20, + NOTIFICATION_DRAG_BEGIN = 21, + NOTIFICATION_DRAG_END = 22, }; /* NODE/TREE */ StringName get_name() const; - void set_name(const String& p_name); + void set_name(const String &p_name); - void add_child(Node *p_child,bool p_legible_unique_name=false); - void add_child_below_node(Node *p_node, Node *p_child, bool p_legible_unique_name=false); + void add_child(Node *p_child, bool p_legible_unique_name = false); + void add_child_below_node(Node *p_node, Node *p_child, bool p_legible_unique_name = false); void remove_child(Node *p_child); int get_child_count() const; Node *get_child(int p_index) const; - bool has_node(const NodePath& p_path) const; - Node *get_node(const NodePath& p_path) const; - Node* find_node(const String& p_mask,bool p_recursive=true,bool p_owned=true) const; - bool has_node_and_resource(const NodePath& p_path) const; - Node *get_node_and_resource(const NodePath& p_path,RES& r_res) const; + bool has_node(const NodePath &p_path) const; + Node *get_node(const NodePath &p_path) const; + Node *find_node(const String &p_mask, bool p_recursive = true, bool p_owned = true) const; + bool has_node_and_resource(const NodePath &p_path) const; + Node *get_node_and_resource(const NodePath &p_path, RES &r_res) const; Node *get_parent() const; - _FORCE_INLINE_ SceneTree *get_tree() const { ERR_FAIL_COND_V( !data.tree, NULL ); return data.tree; } + _FORCE_INLINE_ SceneTree *get_tree() const { + ERR_FAIL_COND_V(!data.tree, NULL); + return data.tree; + } _FORCE_INLINE_ bool is_inside_tree() const { return data.inside_tree; } @@ -222,11 +219,11 @@ public: NodePath get_path() const; NodePath get_path_to(const Node *p_node) const; - Node* find_common_parent_with(const Node *p_node) const; + Node *find_common_parent_with(const Node *p_node) const; - void add_to_group(const StringName& p_identifier,bool p_persistent=false); - void remove_from_group(const StringName& p_identifier); - bool is_in_group(const StringName& p_identifier) const; + void add_to_group(const StringName &p_identifier, bool p_persistent = false); + void remove_from_group(const StringName &p_identifier); + bool is_in_group(const StringName &p_identifier) const; struct GroupInfo { @@ -237,27 +234,25 @@ public: void get_groups(List<GroupInfo> *p_groups) const; bool has_persistent_groups() const; - void move_child(Node *p_child,int p_pos); + void move_child(Node *p_child, int p_pos); void raise(); void set_owner(Node *p_owner); Node *get_owner() const; - void get_owned_by(Node *p_by,List<Node*> *p_owned); - + void get_owned_by(Node *p_by, List<Node *> *p_owned); void remove_and_skip(); int get_index() const; void print_tree(); - void set_filename(const String& p_filename); + void set_filename(const String &p_filename); String get_filename() const; - void set_editable_instance(Node* p_node,bool p_editable); - bool is_editable_instance(Node* p_node) const; - void set_editable_instances(const HashMap<NodePath,int>& p_editable_instances); - HashMap<NodePath,int> get_editable_instances() const; - + void set_editable_instance(Node *p_node, bool p_editable); + bool is_editable_instance(Node *p_node) const; + void set_editable_instances(const HashMap<NodePath, int> &p_editable_instances); + HashMap<NodePath, int> get_editable_instances() const; /* NOTIFICATIONS */ @@ -272,7 +267,6 @@ public: float get_process_delta_time() const; bool is_processing() const; - void set_process_input(bool p_enable); bool is_processing_input() const; @@ -284,16 +278,16 @@ public: int get_position_in_parent() const; - Node *duplicate(bool p_use_instancing=false,int p_flags=DUPLICATE_GROUPS|DUPLICATE_SIGNALS|DUPLICATE_SCRIPTS) const; - Node *duplicate_and_reown(const Map<Node*,Node*>& p_reown_map) const; + Node *duplicate(bool p_use_instancing = false, int p_flags = DUPLICATE_GROUPS | DUPLICATE_SIGNALS | DUPLICATE_SCRIPTS) const; + Node *duplicate_and_reown(const Map<Node *, Node *> &p_reown_map) const; //Node *clone_tree() const; // used by editors, to save what has changed only - void set_scene_instance_state(const Ref<SceneState>& p_state); + void set_scene_instance_state(const Ref<SceneState> &p_state); Ref<SceneState> get_scene_instance_state() const; - void set_scene_inherited_state(const Ref<SceneState>& p_state); + void set_scene_inherited_state(const Ref<SceneState> &p_state); Ref<SceneState> get_scene_inherited_state() const; void set_scene_instance_load_placeholder(bool p_enable); @@ -301,7 +295,7 @@ public: static Vector<Variant> make_binds(VARIANT_ARG_LIST); - void replace_by(Node* p_node,bool p_keep_data=false); + void replace_by(Node *p_node, bool p_keep_data = false); void set_pause_mode(PauseMode p_mode); PauseMode get_pause_mode() const; @@ -309,24 +303,24 @@ public: static void print_stray_nodes(); - String validate_child_name(const String& p_name) const; + String validate_child_name(const String &p_name) const; void queue_delete(); -//shitty hacks for speed + //shitty hacks for speed static void set_human_readable_collision_renaming(bool p_enabled); static void init_node_hrcr(); - void force_parent_owned() { data.parent_owned=true; } //hack to avoid duplicate nodes + void force_parent_owned() { data.parent_owned = true; } //hack to avoid duplicate nodes #ifdef TOOLS_ENABLED - void set_import_path(const NodePath& p_import_path); //path used when imported, used by scene editors to keep tracking + void set_import_path(const NodePath &p_import_path); //path used when imported, used by scene editors to keep tracking NodePath get_import_path() const; #endif bool is_owned_by_parent() const; - void get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const; + void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const; void clear_internal_tree_resource_paths(); @@ -344,8 +338,6 @@ public: ~Node(); }; - -typedef Set<Node*,Node::Comparator> NodeSet; - +typedef Set<Node *, Node::Comparator> NodeSet; #endif diff --git a/scene/main/resource_preloader.cpp b/scene/main/resource_preloader.cpp index 49bf6106b..ac9ab68e3 100644 --- a/scene/main/resource_preloader.cpp +++ b/scene/main/resource_preloader.cpp @@ -28,26 +28,25 @@ /*************************************************************************/ #include "resource_preloader.h" -void ResourcePreloader::_set_resources(const Array& p_data) { +void ResourcePreloader::_set_resources(const Array &p_data) { resources.clear(); - ERR_FAIL_COND(p_data.size()!=2); - DVector<String> names=p_data[0]; - Array resdata=p_data[1]; + ERR_FAIL_COND(p_data.size() != 2); + DVector<String> names = p_data[0]; + Array resdata = p_data[1]; - ERR_FAIL_COND(names.size()!=resdata.size()); + ERR_FAIL_COND(names.size() != resdata.size()); - for(int i=0;i<resdata.size();i++) { + for (int i = 0; i < resdata.size(); i++) { - String name=names[i]; + String name = names[i]; RES resource = resdata[i]; - ERR_CONTINUE( !resource.is_valid() ); - resources[name]=resource; + ERR_CONTINUE(!resource.is_valid()); + resources[name] = resource; //add_resource(name,resource); } - } Array ResourcePreloader::_get_resources() const { @@ -59,15 +58,15 @@ Array ResourcePreloader::_get_resources() const { Set<String> sorted_names; - for(Map<StringName,RES >::Element *E=resources.front();E;E=E->next()) { + for (Map<StringName, RES>::Element *E = resources.front(); E; E = E->next()) { sorted_names.insert(E->key()); } - int i=0; - for(Set<String>::Element *E=sorted_names.front();E;E=E->next()) { + int i = 0; + for (Set<String>::Element *E = sorted_names.front(); E; E = E->next()) { - names.set(i,E->get()); - arr[i]=resources[E->get()]; + names.set(i, E->get()); + arr[i] = resources[E->get()]; i++; } @@ -77,65 +76,54 @@ Array ResourcePreloader::_get_resources() const { return res; } - -void ResourcePreloader::add_resource(const StringName& p_name,const RES& p_resource) { - +void ResourcePreloader::add_resource(const StringName &p_name, const RES &p_resource) { ERR_FAIL_COND(p_resource.is_null()); if (resources.has(p_name)) { - StringName new_name; - int idx=2; + int idx = 2; - while(true) { + while (true) { - new_name=p_name.operator String()+" "+itos(idx); + new_name = p_name.operator String() + " " + itos(idx); if (resources.has(new_name)) { idx++; continue; } break; - } - add_resource(new_name,p_resource); + add_resource(new_name, p_resource); } else { - resources[p_name]=p_resource; + resources[p_name] = p_resource; } - - - } -void ResourcePreloader::remove_resource(const StringName& p_name) { +void ResourcePreloader::remove_resource(const StringName &p_name) { - ERR_FAIL_COND( !resources.has(p_name) ); + ERR_FAIL_COND(!resources.has(p_name)); resources.erase(p_name); - } -void ResourcePreloader::rename_resource(const StringName& p_from_name,const StringName& p_to_name) { +void ResourcePreloader::rename_resource(const StringName &p_from_name, const StringName &p_to_name) { - ERR_FAIL_COND( !resources.has(p_from_name) ); + ERR_FAIL_COND(!resources.has(p_from_name)); RES res = resources[p_from_name]; resources.erase(p_from_name); - add_resource(p_to_name,res); - - - + add_resource(p_to_name, res); } -bool ResourcePreloader::has_resource(const StringName& p_name) const { +bool ResourcePreloader::has_resource(const StringName &p_name) const { return resources.has(p_name); } -RES ResourcePreloader::get_resource(const StringName& p_name) const { +RES ResourcePreloader::get_resource(const StringName &p_name) const { - ERR_FAIL_COND_V(!resources.has(p_name),RES()); + ERR_FAIL_COND_V(!resources.has(p_name), RES()); return resources[p_name]; } @@ -143,9 +131,9 @@ DVector<String> ResourcePreloader::_get_resource_list() const { DVector<String> res; res.resize(resources.size()); - int i=0; - for(Map<StringName,RES >::Element *E=resources.front();E;E=E->next(),i++) { - res.set(i,E->key()); + int i = 0; + for (Map<StringName, RES>::Element *E = resources.front(); E; E = E->next(), i++) { + res.set(i, E->key()); } return res; @@ -153,31 +141,26 @@ DVector<String> ResourcePreloader::_get_resource_list() const { void ResourcePreloader::get_resource_list(List<StringName> *p_list) { - for(Map<StringName,RES >::Element *E=resources.front();E;E=E->next()) { + for (Map<StringName, RES>::Element *E = resources.front(); E; E = E->next()) { p_list->push_back(E->key()); } - } - void ResourcePreloader::_bind_methods() { - ObjectTypeDB::bind_method(_MD("_set_resources"),&ResourcePreloader::_set_resources); - ObjectTypeDB::bind_method(_MD("_get_resources"),&ResourcePreloader::_get_resources); - - ObjectTypeDB::bind_method(_MD("add_resource","name","resource"),&ResourcePreloader::add_resource); - ObjectTypeDB::bind_method(_MD("remove_resource","name"),&ResourcePreloader::remove_resource); - ObjectTypeDB::bind_method(_MD("rename_resource","name","newname"),&ResourcePreloader::rename_resource); - ObjectTypeDB::bind_method(_MD("has_resource","name"),&ResourcePreloader::has_resource); - ObjectTypeDB::bind_method(_MD("get_resource","name"),&ResourcePreloader::get_resource); - ObjectTypeDB::bind_method(_MD("get_resource_list"),&ResourcePreloader::_get_resource_list); - + ObjectTypeDB::bind_method(_MD("_set_resources"), &ResourcePreloader::_set_resources); + ObjectTypeDB::bind_method(_MD("_get_resources"), &ResourcePreloader::_get_resources); - ADD_PROPERTY( PropertyInfo(Variant::ARRAY,"resources",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR), _SCS("_set_resources"), _SCS("_get_resources")); + ObjectTypeDB::bind_method(_MD("add_resource", "name", "resource"), &ResourcePreloader::add_resource); + ObjectTypeDB::bind_method(_MD("remove_resource", "name"), &ResourcePreloader::remove_resource); + ObjectTypeDB::bind_method(_MD("rename_resource", "name", "newname"), &ResourcePreloader::rename_resource); + ObjectTypeDB::bind_method(_MD("has_resource", "name"), &ResourcePreloader::has_resource); + ObjectTypeDB::bind_method(_MD("get_resource", "name"), &ResourcePreloader::get_resource); + ObjectTypeDB::bind_method(_MD("get_resource_list"), &ResourcePreloader::_get_resource_list); + ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "resources", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), _SCS("_set_resources"), _SCS("_get_resources")); } -ResourcePreloader::ResourcePreloader() -{ +ResourcePreloader::ResourcePreloader() { } diff --git a/scene/main/resource_preloader.h b/scene/main/resource_preloader.h index f2d1461fb..7d0916a71 100644 --- a/scene/main/resource_preloader.h +++ b/scene/main/resource_preloader.h @@ -29,35 +29,30 @@ #ifndef RESOURCE_PRELOADER_H #define RESOURCE_PRELOADER_H - #include "scene/main/node.h" class ResourcePreloader : public Node { - OBJ_TYPE(ResourcePreloader,Node); - - Map<StringName,RES > resources; + OBJ_TYPE(ResourcePreloader, Node); + Map<StringName, RES> resources; - void _set_resources(const Array& p_data); + void _set_resources(const Array &p_data); Array _get_resources() const; DVector<String> _get_resource_list() const; protected: - static void _bind_methods(); public: - - void add_resource(const StringName& p_name,const RES& p_resource); - void remove_resource(const StringName& p_name); - void rename_resource(const StringName& p_from_name,const StringName& p_to_name); - bool has_resource(const StringName& p_name) const; - RES get_resource(const StringName& p_name) const; + void add_resource(const StringName &p_name, const RES &p_resource); + void remove_resource(const StringName &p_name); + void rename_resource(const StringName &p_from_name, const StringName &p_to_name); + bool has_resource(const StringName &p_name) const; + RES get_resource(const StringName &p_name) const; void get_resource_list(List<StringName> *p_list); - ResourcePreloader(); }; diff --git a/scene/main/scene_main_loop.cpp b/scene/main/scene_main_loop.cpp index b0b586cfa..79a6b79f9 100644 --- a/scene/main/scene_main_loop.cpp +++ b/scene/main/scene_main_loop.cpp @@ -28,22 +28,22 @@ /*************************************************************************/ #include "scene_main_loop.h" -#include "print_string.h" -#include "os/os.h" +#include "globals.h" +#include "io/resource_loader.h" #include "message_queue.h" #include "node.h" -#include "globals.h" -#include <stdio.h> #include "os/keyboard.h" -#include "servers/spatial_sound_2d_server.h" +#include "os/os.h" +#include "print_string.h" +#include "scene/resources/material.h" +#include "scene/resources/mesh.h" +#include "scene/resources/packed_scene.h" +#include "scene/scene_string_names.h" #include "servers/physics_2d_server.h" #include "servers/physics_server.h" -#include "scene/scene_string_names.h" -#include "io/resource_loader.h" +#include "servers/spatial_sound_2d_server.h" #include "viewport.h" -#include "scene/resources/packed_scene.h" -#include "scene/resources/material.h" -#include "scene/resources/mesh.h" +#include <stdio.h> void SceneTree::tree_changed() { @@ -53,40 +53,36 @@ void SceneTree::tree_changed() { void SceneTree::node_removed(Node *p_node) { - if (current_scene==p_node) { - current_scene=NULL; + if (current_scene == p_node) { + current_scene = NULL; } - emit_signal(node_removed_name,p_node); - if (call_lock>0) + emit_signal(node_removed_name, p_node); + if (call_lock > 0) call_skip.insert(p_node); - - } +SceneTree::Group *SceneTree::add_to_group(const StringName &p_group, Node *p_node) { -SceneTree::Group *SceneTree::add_to_group(const StringName& p_group, Node *p_node) { - - Map<StringName,Group>::Element *E=group_map.find(p_group); + Map<StringName, Group>::Element *E = group_map.find(p_group); if (!E) { - E=group_map.insert(p_group,Group()); + E = group_map.insert(p_group, Group()); } - if (E->get().nodes.find(p_node)!=-1) { - ERR_EXPLAIN("Already in group: "+p_group); + if (E->get().nodes.find(p_node) != -1) { + ERR_EXPLAIN("Already in group: " + p_group); ERR_FAIL_V(&E->get()); } E->get().nodes.push_back(p_node); //E->get().last_tree_version=0; - E->get().changed=true; + E->get().changed = true; return &E->get(); } -void SceneTree::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); + Map<StringName, Group>::Element *E = group_map.find(p_group); ERR_FAIL_COND(!E); - E->get().nodes.erase(p_node); if (E->get().nodes.empty()) group_map.erase(E); @@ -94,38 +90,38 @@ void SceneTree::remove_from_group(const StringName& p_group, Node *p_node) { void SceneTree::_flush_transform_notifications() { - SelfList<Node>* n = xform_change_list.first(); - while(n) { + SelfList<Node> *n = xform_change_list.first(); + while (n) { - Node *node=n->self(); - SelfList<Node>* nx = n->next(); + Node *node = n->self(); + SelfList<Node> *nx = n->next(); xform_change_list.remove(n); - n=nx; + n = nx; node->notification(NOTIFICATION_TRANSFORM_CHANGED); } } void SceneTree::_flush_ugc() { - ugc_locked=true; + ugc_locked = true; while (unique_group_calls.size()) { - Map<UGCall,Vector<Variant> >::Element *E=unique_group_calls.front(); + Map<UGCall, Vector<Variant> >::Element *E = unique_group_calls.front(); Variant v[VARIANT_ARG_MAX]; - for(int i=0;i<E->get().size();i++) - v[i]=E->get()[i]; + for (int i = 0; i < E->get().size(); i++) + v[i] = E->get()[i]; - call_group(GROUP_CALL_REALTIME,E->key().group,E->key().call,v[0],v[1],v[2],v[3],v[4]); + call_group(GROUP_CALL_REALTIME, E->key().group, E->key().call, v[0], v[1], v[2], v[3], v[4]); unique_group_calls.erase(E); } - ugc_locked=false; + ugc_locked = false; } -void SceneTree::_update_group_order(Group& g) { +void SceneTree::_update_group_order(Group &g) { if (!g.changed) return; @@ -133,32 +129,29 @@ void SceneTree::_update_group_order(Group& g) { return; Node **nodes = &g.nodes[0]; - int node_count=g.nodes.size(); - - SortArray<Node*,Node::Comparator> node_sort; - node_sort.sort(nodes,node_count); - g.changed=false; + int node_count = g.nodes.size(); + SortArray<Node *, Node::Comparator> node_sort; + node_sort.sort(nodes, node_count); + g.changed = false; } +void SceneTree::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); + Map<StringName, Group>::Element *E = group_map.find(p_group); if (!E) return; - Group &g=E->get(); + Group &g = E->get(); if (g.nodes.empty()) return; - - if (p_call_flags&GROUP_CALL_UNIQUE && !(p_call_flags&GROUP_CALL_REALTIME)) { + if (p_call_flags & GROUP_CALL_UNIQUE && !(p_call_flags & GROUP_CALL_REALTIME)) { ERR_FAIL_COND(ugc_locked); UGCall ug; - ug.call=p_function; - ug.group=p_group; + ug.call = p_function; + ug.group = p_group; if (unique_group_calls.has(ug)) return; @@ -166,193 +159,186 @@ void SceneTree::call_group(uint32_t p_call_flags,const StringName& p_group,const VARIANT_ARGPTRS; Vector<Variant> args; - for(int i=0;i<VARIANT_ARG_MAX;i++) { - if (argptr[i]->get_type()==Variant::NIL) + for (int i = 0; i < VARIANT_ARG_MAX; i++) { + if (argptr[i]->get_type() == Variant::NIL) break; args.push_back(*argptr[i]); } - unique_group_calls[ug]=args; + unique_group_calls[ug] = args; return; } _update_group_order(g); - Vector<Node*> nodes_copy = g.nodes; + Vector<Node *> nodes_copy = g.nodes; Node **nodes = &nodes_copy[0]; - int node_count=nodes_copy.size(); + int node_count = nodes_copy.size(); call_lock++; - if (p_call_flags&GROUP_CALL_REVERSE) { + if (p_call_flags & GROUP_CALL_REVERSE) { - for(int i=node_count-1;i>=0;i--) { + for (int i = node_count - 1; i >= 0; i--) { if (call_lock && call_skip.has(nodes[i])) continue; - if (p_call_flags&GROUP_CALL_REALTIME) { - if (p_call_flags&GROUP_CALL_MULIILEVEL) - nodes[i]->call_multilevel(p_function,VARIANT_ARG_PASS); + if (p_call_flags & GROUP_CALL_REALTIME) { + if (p_call_flags & GROUP_CALL_MULIILEVEL) + nodes[i]->call_multilevel(p_function, VARIANT_ARG_PASS); else - nodes[i]->call(p_function,VARIANT_ARG_PASS); + nodes[i]->call(p_function, VARIANT_ARG_PASS); } else - MessageQueue::get_singleton()->push_call(nodes[i],p_function,VARIANT_ARG_PASS); - + MessageQueue::get_singleton()->push_call(nodes[i], p_function, VARIANT_ARG_PASS); } } else { - for(int i=0;i<node_count;i++) { + for (int i = 0; i < node_count; i++) { if (call_lock && call_skip.has(nodes[i])) continue; - if (p_call_flags&GROUP_CALL_REALTIME) { - if (p_call_flags&GROUP_CALL_MULIILEVEL) - nodes[i]->call_multilevel(p_function,VARIANT_ARG_PASS); + if (p_call_flags & GROUP_CALL_REALTIME) { + if (p_call_flags & GROUP_CALL_MULIILEVEL) + nodes[i]->call_multilevel(p_function, VARIANT_ARG_PASS); else - nodes[i]->call(p_function,VARIANT_ARG_PASS); + nodes[i]->call(p_function, VARIANT_ARG_PASS); } else - MessageQueue::get_singleton()->push_call(nodes[i],p_function,VARIANT_ARG_PASS); + MessageQueue::get_singleton()->push_call(nodes[i], p_function, VARIANT_ARG_PASS); } - } call_lock--; - if (call_lock==0) + if (call_lock == 0) call_skip.clear(); } -void SceneTree::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); + Map<StringName, Group>::Element *E = group_map.find(p_group); if (!E) return; - Group &g=E->get(); + Group &g = E->get(); if (g.nodes.empty()) return; _update_group_order(g); - Vector<Node*> nodes_copy = g.nodes; + Vector<Node *> nodes_copy = g.nodes; Node **nodes = &nodes_copy[0]; - int node_count=nodes_copy.size(); + int node_count = nodes_copy.size(); call_lock++; - if (p_call_flags&GROUP_CALL_REVERSE) { + if (p_call_flags & GROUP_CALL_REVERSE) { - for(int i=node_count-1;i>=0;i--) { + for (int i = node_count - 1; i >= 0; i--) { if (call_lock && call_skip.has(nodes[i])) continue; - if (p_call_flags&GROUP_CALL_REALTIME) + if (p_call_flags & GROUP_CALL_REALTIME) nodes[i]->notification(p_notification); else - MessageQueue::get_singleton()->push_notification(nodes[i],p_notification); + MessageQueue::get_singleton()->push_notification(nodes[i], p_notification); } } else { - for(int i=0;i<node_count;i++) { + for (int i = 0; i < node_count; i++) { if (call_lock && call_skip.has(nodes[i])) continue; - if (p_call_flags&GROUP_CALL_REALTIME) + if (p_call_flags & GROUP_CALL_REALTIME) nodes[i]->notification(p_notification); else - MessageQueue::get_singleton()->push_notification(nodes[i],p_notification); + MessageQueue::get_singleton()->push_notification(nodes[i], p_notification); } - } call_lock--; - if (call_lock==0) + if (call_lock == 0) call_skip.clear(); } -void SceneTree::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); + Map<StringName, Group>::Element *E = group_map.find(p_group); if (!E) return; - Group &g=E->get(); + Group &g = E->get(); if (g.nodes.empty()) return; _update_group_order(g); - Vector<Node*> nodes_copy = g.nodes; + Vector<Node *> nodes_copy = g.nodes; Node **nodes = &nodes_copy[0]; - int node_count=nodes_copy.size(); + int node_count = nodes_copy.size(); call_lock++; - if (p_call_flags&GROUP_CALL_REVERSE) { + if (p_call_flags & GROUP_CALL_REVERSE) { - for(int i=node_count-1;i>=0;i--) { + for (int i = node_count - 1; i >= 0; i--) { if (call_lock && call_skip.has(nodes[i])) continue; - if (p_call_flags&GROUP_CALL_REALTIME) - nodes[i]->set(p_name,p_value); + if (p_call_flags & GROUP_CALL_REALTIME) + nodes[i]->set(p_name, p_value); else - MessageQueue::get_singleton()->push_set(nodes[i],p_name,p_value); + MessageQueue::get_singleton()->push_set(nodes[i], p_name, p_value); } } else { - for(int i=0;i<node_count;i++) { + for (int i = 0; i < node_count; i++) { if (call_lock && call_skip.has(nodes[i])) continue; - if (p_call_flags&GROUP_CALL_REALTIME) - nodes[i]->set(p_name,p_value); + if (p_call_flags & GROUP_CALL_REALTIME) + nodes[i]->set(p_name, p_value); else - MessageQueue::get_singleton()->push_set(nodes[i],p_name,p_value); + MessageQueue::get_singleton()->push_set(nodes[i], p_name, p_value); } - } call_lock--; - if (call_lock==0) + if (call_lock == 0) call_skip.clear(); } void SceneTree::set_input_as_handled() { - input_handled=true; + input_handled = true; } -void SceneTree::input_text( const String& p_text ) { +void SceneTree::input_text(const String &p_text) { root_lock++; - call_group(GROUP_CALL_REALTIME,"_viewports","_vp_input_text",p_text); //special one for GUI, as controls use their own process check + call_group(GROUP_CALL_REALTIME, "_viewports", "_vp_input_text", p_text); //special one for GUI, as controls use their own process check root_lock--; - } -void SceneTree::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)) + 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; - input_handled=false; - + input_handled = false; InputEvent ev = p_event; - ev.ID=++last_id; //this should work better + ev.ID = ++last_id; //this should work better #if 0 switch(ev.type) { @@ -428,10 +414,10 @@ void SceneTree::input_event( const InputEvent& p_event ) { //transform for the rest #else - call_group(GROUP_CALL_REALTIME,"_viewports","_vp_input",ev); //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) { + if (ScriptDebugger::get_singleton() && ScriptDebugger::get_singleton()->is_remote() && ev.type == InputEvent::KEY && ev.key.pressed && !ev.key.echo && ev.key.scancode == KEY_F8) { ScriptDebugger::get_singleton()->request_quit(); } @@ -453,39 +439,34 @@ void SceneTree::input_event( const InputEvent& p_event ) { } #else - call_group(GROUP_CALL_REALTIME,"_viewports","_vp_unhandled_input",ev); //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; + input_handled = true; _flush_ugc(); root_lock--; MessageQueue::get_singleton()->flush(); //small little hack } else { - input_handled=true; + input_handled = true; root_lock--; - } - } void SceneTree::init() { //_quit=false; - accept_quit=true; - initialized=true; - input_handled=false; - + accept_quit = true; + initialized = true; + input_handled = false; - pause=false; + pause = false; root->_set_tree(this); MainLoop::init(); - } bool SceneTree::iteration(float p_time) { - root_lock++; current_frame++; @@ -493,14 +474,14 @@ bool SceneTree::iteration(float p_time) { _flush_transform_notifications(); MainLoop::iteration(p_time); - fixed_process_time=p_time; + fixed_process_time = p_time; emit_signal("fixed_frame"); - _notify_group_pause("fixed_process",Node::NOTIFICATION_FIXED_PROCESS); + _notify_group_pause("fixed_process", Node::NOTIFICATION_FIXED_PROCESS); _flush_ugc(); _flush_transform_notifications(); - call_group(GROUP_CALL_REALTIME,"_viewports","update_worlds"); + call_group(GROUP_CALL_REALTIME, "_viewports", "update_worlds"); root_lock--; _flush_delete_queue(); @@ -508,40 +489,36 @@ bool SceneTree::iteration(float p_time) { return _quit; } -bool SceneTree::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())); -// print_line("node count: "+itos(get_node_count())); -// print_line("TEXTURE RAM: "+itos(VS::get_singleton()->get_render_info(VS::INFO_TEXTURE_MEM_USED))); + // print_line("ram: "+itos(OS::get_singleton()->get_static_memory_usage())+" sram: "+itos(OS::get_singleton()->get_dynamic_memory_usage())); + // print_line("node count: "+itos(get_node_count())); + // print_line("TEXTURE RAM: "+itos(VS::get_singleton()->get_render_info(VS::INFO_TEXTURE_MEM_USED))); root_lock++; MainLoop::idle(p_time); - idle_process_time=p_time; + idle_process_time = p_time; emit_signal("idle_frame"); _flush_transform_notifications(); - _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 ); - if(win_size!=last_screen_size) { + _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); + if (win_size != last_screen_size) { - last_screen_size=win_size; + last_screen_size = win_size; _update_root_rect(); - emit_signal("screen_resized"); - } _flush_ugc(); _flush_transform_notifications(); //transforms after world update, to avoid unnecesary enter/exit notifications - call_group(GROUP_CALL_REALTIME,"_viewports","update_worlds"); + call_group(GROUP_CALL_REALTIME, "_viewports", "update_worlds"); root_lock--; @@ -556,7 +533,7 @@ void SceneTree::finish() { _flush_ugc(); - initialized=false; + initialized = false; MainLoop::finish(); @@ -564,27 +541,15 @@ void SceneTree::finish() { root->_set_tree(NULL); memdelete(root); //delete root } - - - - - - - - - } - void SceneTree::quit() { - _quit=true; + _quit = true; } void SceneTree::_notification(int p_notification) { - - switch (p_notification) { case NOTIFICATION_WM_QUIT_REQUEST: { @@ -592,7 +557,7 @@ void SceneTree::_notification(int p_notification) { get_root()->propagate_notification(p_notification); if (accept_quit) { - _quit=true; + _quit = true; break; } } break; @@ -604,7 +569,7 @@ void SceneTree::_notification(int p_notification) { } break; case NOTIFICATION_WM_UNFOCUS_REQUEST: { - notify_group(GROUP_CALL_REALTIME|GROUP_CALL_MULIILEVEL,"input",NOTIFICATION_WM_UNFOCUS_REQUEST); + notify_group(GROUP_CALL_REALTIME | GROUP_CALL_MULIILEVEL, "input", NOTIFICATION_WM_UNFOCUS_REQUEST); } break; @@ -613,18 +578,17 @@ void SceneTree::_notification(int p_notification) { }; }; - void SceneTree::set_auto_accept_quit(bool p_enable) { - accept_quit=p_enable; + accept_quit = p_enable; } void SceneTree::set_editor_hint(bool p_enabled) { - editor_hint=p_enabled; + editor_hint = p_enabled; } -bool SceneTree::is_node_being_edited(const Node* p_node) const { +bool SceneTree::is_node_being_edited(const Node *p_node) const { #ifdef TOOLS_ENABLED return editor_hint && edited_scene_root && edited_scene_root->is_a_parent_of(p_node); #else @@ -639,7 +603,7 @@ bool SceneTree::is_editor_hint() const { void SceneTree::set_debug_collisions_hint(bool p_enabled) { - debug_collisions_hint=p_enabled; + debug_collisions_hint = p_enabled; } bool SceneTree::is_debugging_collisions_hint() const { @@ -649,7 +613,7 @@ bool SceneTree::is_debugging_collisions_hint() const { void SceneTree::set_debug_navigation_hint(bool p_enabled) { - debug_navigation_hint=p_enabled; + debug_navigation_hint = p_enabled; } bool SceneTree::is_debugging_navigation_hint() const { @@ -657,9 +621,9 @@ bool SceneTree::is_debugging_navigation_hint() const { return debug_navigation_hint; } -void SceneTree::set_debug_collisions_color(const Color& p_color) { +void SceneTree::set_debug_collisions_color(const Color &p_color) { - debug_collisions_color=p_color; + debug_collisions_color = p_color; } Color SceneTree::get_debug_collisions_color() const { @@ -667,9 +631,9 @@ Color SceneTree::get_debug_collisions_color() const { return debug_collisions_color; } -void SceneTree::set_debug_collision_contact_color(const Color& p_color) { +void SceneTree::set_debug_collision_contact_color(const Color &p_color) { - debug_collision_contact_color=p_color; + debug_collision_contact_color = p_color; } Color SceneTree::get_debug_collision_contact_color() const { @@ -677,9 +641,9 @@ Color SceneTree::get_debug_collision_contact_color() const { return debug_collision_contact_color; } -void SceneTree::set_debug_navigation_color(const Color& p_color) { +void SceneTree::set_debug_navigation_color(const Color &p_color) { - debug_navigation_color=p_color; + debug_navigation_color = p_color; } Color SceneTree::get_debug_navigation_color() const { @@ -687,9 +651,9 @@ Color SceneTree::get_debug_navigation_color() const { return debug_navigation_color; } -void SceneTree::set_debug_navigation_disabled_color(const Color& p_color) { +void SceneTree::set_debug_navigation_disabled_color(const Color &p_color) { - debug_navigation_disabled_color=p_color; + debug_navigation_disabled_color = p_color; } Color SceneTree::get_debug_navigation_disabled_color() const { @@ -702,50 +666,47 @@ Ref<Material> SceneTree::get_debug_navigation_material() { if (navigation_material.is_valid()) return navigation_material; - Ref<FixedMaterial> line_material = Ref<FixedMaterial>( memnew( FixedMaterial )); + Ref<FixedMaterial> line_material = Ref<FixedMaterial>(memnew(FixedMaterial)); line_material->set_flag(Material::FLAG_UNSHADED, true); line_material->set_line_width(3.0); line_material->set_fixed_flag(FixedMaterial::FLAG_USE_ALPHA, true); line_material->set_fixed_flag(FixedMaterial::FLAG_USE_COLOR_ARRAY, true); - line_material->set_parameter(FixedMaterial::PARAM_DIFFUSE,get_debug_navigation_color()); + line_material->set_parameter(FixedMaterial::PARAM_DIFFUSE, get_debug_navigation_color()); - navigation_material=line_material; + navigation_material = line_material; return navigation_material; - } -Ref<Material> SceneTree::get_debug_navigation_disabled_material(){ +Ref<Material> SceneTree::get_debug_navigation_disabled_material() { if (navigation_disabled_material.is_valid()) return navigation_disabled_material; - Ref<FixedMaterial> line_material = Ref<FixedMaterial>( memnew( FixedMaterial )); + Ref<FixedMaterial> line_material = Ref<FixedMaterial>(memnew(FixedMaterial)); line_material->set_flag(Material::FLAG_UNSHADED, true); line_material->set_line_width(3.0); line_material->set_fixed_flag(FixedMaterial::FLAG_USE_ALPHA, true); line_material->set_fixed_flag(FixedMaterial::FLAG_USE_COLOR_ARRAY, true); - line_material->set_parameter(FixedMaterial::PARAM_DIFFUSE,get_debug_navigation_disabled_color()); + line_material->set_parameter(FixedMaterial::PARAM_DIFFUSE, get_debug_navigation_disabled_color()); - navigation_disabled_material=line_material; + navigation_disabled_material = line_material; return navigation_disabled_material; - } Ref<Material> SceneTree::get_debug_collision_material() { if (collision_material.is_valid()) return collision_material; - - Ref<FixedMaterial> line_material = Ref<FixedMaterial>( memnew( FixedMaterial )); + Ref<FixedMaterial> line_material = Ref<FixedMaterial>(memnew(FixedMaterial)); line_material->set_flag(Material::FLAG_UNSHADED, true); line_material->set_line_width(3.0); line_material->set_fixed_flag(FixedMaterial::FLAG_USE_ALPHA, true); line_material->set_fixed_flag(FixedMaterial::FLAG_USE_COLOR_ARRAY, true); - line_material->set_parameter(FixedMaterial::PARAM_DIFFUSE,get_debug_collisions_color()); + line_material->set_parameter(FixedMaterial::PARAM_DIFFUSE, get_debug_collisions_color()); - collision_material=line_material; + collision_material = line_material; return collision_material; } @@ -755,62 +716,58 @@ Ref<Mesh> SceneTree::get_debug_contact_mesh() { if (debug_contact_mesh.is_valid()) return debug_contact_mesh; - debug_contact_mesh = Ref<Mesh>( memnew( Mesh ) ); + debug_contact_mesh = Ref<Mesh>(memnew(Mesh)); - Ref<FixedMaterial> mat = memnew( FixedMaterial ); - mat->set_flag(Material::FLAG_UNSHADED,true); - mat->set_flag(Material::FLAG_DOUBLE_SIDED,true); - mat->set_fixed_flag(FixedMaterial::FLAG_USE_ALPHA,true); - mat->set_parameter(FixedMaterial::PARAM_DIFFUSE,get_debug_collision_contact_color()); + Ref<FixedMaterial> mat = memnew(FixedMaterial); + mat->set_flag(Material::FLAG_UNSHADED, true); + mat->set_flag(Material::FLAG_DOUBLE_SIDED, true); + mat->set_fixed_flag(FixedMaterial::FLAG_USE_ALPHA, true); + mat->set_parameter(FixedMaterial::PARAM_DIFFUSE, get_debug_collision_contact_color()); - Vector3 diamond[6]={ + Vector3 diamond[6] = { Vector3(-1, 0, 0), - Vector3( 1, 0, 0), - Vector3( 0, -1, 0), - Vector3( 0, 1, 0), - Vector3( 0, 0, -1), - Vector3( 0, 0, 1) + Vector3(1, 0, 0), + Vector3(0, -1, 0), + Vector3(0, 1, 0), + Vector3(0, 0, -1), + Vector3(0, 0, 1) }; - int diamond_faces[8*3]={ - 0,2,4, - 0,3,4, - 1,2,4, - 1,3,4, - 0,2,5, - 0,3,5, - 1,2,5, - 1,3,5, + int diamond_faces[8 * 3] = { + 0, 2, 4, + 0, 3, 4, + 1, 2, 4, + 1, 3, 4, + 0, 2, 5, + 0, 3, 5, + 1, 2, 5, + 1, 3, 5, }; DVector<int> indices; - for(int i=0;i<8*3;i++) + for (int i = 0; i < 8 * 3; i++) indices.push_back(diamond_faces[i]); DVector<Vector3> vertices; - for(int i=0;i<6;i++) - vertices.push_back(diamond[i]*0.1); + for (int i = 0; i < 6; i++) + vertices.push_back(diamond[i] * 0.1); Array arr; arr.resize(Mesh::ARRAY_MAX); - arr[Mesh::ARRAY_VERTEX]=vertices; - arr[Mesh::ARRAY_INDEX]=indices; + arr[Mesh::ARRAY_VERTEX] = vertices; + arr[Mesh::ARRAY_INDEX] = indices; - - debug_contact_mesh->add_surface(Mesh::PRIMITIVE_TRIANGLES,arr); - debug_contact_mesh->surface_set_material(0,mat); + debug_contact_mesh->add_surface(Mesh::PRIMITIVE_TRIANGLES, arr); + debug_contact_mesh->surface_set_material(0, mat); return debug_contact_mesh; - } - - void SceneTree::set_pause(bool p_enabled) { - if (p_enabled==pause) + if (p_enabled == pause) return; - pause=p_enabled; + pause = p_enabled; PhysicsServer::get_singleton()->set_active(!p_enabled); Physics2DServer::get_singleton()->set_active(!p_enabled); if (get_root()) @@ -822,12 +779,12 @@ bool SceneTree::is_paused() const { return pause; } -void SceneTree::_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); + Map<StringName, Group>::Element *E = group_map.find(p_group); if (!E) return; - Group &g=E->get(); + Group &g = E->get(); if (g.nodes.empty()) return; @@ -835,17 +792,17 @@ void SceneTree::_call_input_pause(const StringName& p_group,const StringName& p_ //copy, so copy on write happens in case something is removed from process while being called //performance is not lost because only if something is added/removed the vector is copied. - Vector<Node*> nodes_copy = g.nodes; + Vector<Node *> nodes_copy = g.nodes; - int node_count=nodes_copy.size(); + int node_count = nodes_copy.size(); Node **nodes = &nodes_copy[0]; - Variant arg=p_input; - const Variant *v[1]={&arg}; + Variant arg = p_input; + const Variant *v[1] = { &arg }; call_lock++; - for(int i=node_count-1;i>=0;i--) { + for (int i = node_count - 1; i >= 0; i--) { if (input_handled) break; @@ -858,37 +815,36 @@ void SceneTree::_call_input_pause(const StringName& p_group,const StringName& p_ continue; Variant::CallError ce; - n->call_multilevel(p_method,(const Variant**)v,1); + n->call_multilevel(p_method, (const Variant **)v, 1); //ERR_FAIL_COND(node_count != g.nodes.size()); } call_lock--; - if (call_lock==0) + if (call_lock == 0) call_skip.clear(); } -void SceneTree::_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); + Map<StringName, Group>::Element *E = group_map.find(p_group); if (!E) return; - Group &g=E->get(); + Group &g = E->get(); if (g.nodes.empty()) return; - _update_group_order(g); //copy, so copy on write happens in case something is removed from process while being called //performance is not lost because only if something is added/removed the vector is copied. - Vector<Node*> nodes_copy = g.nodes; + Vector<Node *> nodes_copy = g.nodes; - int node_count=nodes_copy.size(); + int node_count = nodes_copy.size(); Node **nodes = &nodes_copy[0]; call_lock++; - for(int i=0;i<node_count;i++) { + for (int i = 0; i < node_count; i++) { Node *n = nodes[i]; if (call_lock && call_skip.has(n)) @@ -902,7 +858,7 @@ void SceneTree::_notify_group_pause(const StringName& p_group,int p_notification } call_lock--; - if (call_lock==0) + if (call_lock == 0) call_skip.clear(); } @@ -922,93 +878,87 @@ uint32_t SceneTree::get_last_event_id() const { return last_id; } +Variant SceneTree::_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; + r_error.error = Variant::CallError::CALL_OK; - ERR_FAIL_COND_V(p_argcount<3,Variant()); - ERR_FAIL_COND_V(!p_args[0]->is_num(),Variant()); - ERR_FAIL_COND_V(p_args[1]->get_type()!=Variant::STRING,Variant()); - ERR_FAIL_COND_V(p_args[2]->get_type()!=Variant::STRING,Variant()); + ERR_FAIL_COND_V(p_argcount < 3, Variant()); + ERR_FAIL_COND_V(!p_args[0]->is_num(), Variant()); + ERR_FAIL_COND_V(p_args[1]->get_type() != Variant::STRING, Variant()); + ERR_FAIL_COND_V(p_args[2]->get_type() != Variant::STRING, Variant()); int flags = *p_args[0]; StringName group = *p_args[1]; StringName method = *p_args[2]; Variant v[VARIANT_ARG_MAX]; - for(int i=0;i<MIN(p_argcount-3,5);i++) { + for (int i = 0; i < MIN(p_argcount - 3, 5); i++) { - v[i]=*p_args[i+3]; + v[i] = *p_args[i + 3]; } - call_group(flags,group,method,v[0],v[1],v[2],v[3],v[4]); + call_group(flags, group, method, v[0], v[1], v[2], v[3], v[4]); return Variant(); } - int64_t SceneTree::get_frame() const { return current_frame; } - -Array SceneTree::_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); + Map<StringName, Group>::Element *E = group_map.find(p_group); if (!E) return ret; _update_group_order(E->get()); //update order just in case int nc = E->get().nodes.size(); - if (nc==0) + if (nc == 0) return ret; ret.resize(nc); Node **ptr = E->get().nodes.ptr(); - for(int i=0;i<nc;i++) { + for (int i = 0; i < nc; i++) { - ret[i]=ptr[i]; + ret[i] = ptr[i]; } return ret; } -bool SceneTree::has_group(const StringName& p_identifier) const { +bool SceneTree::has_group(const StringName &p_identifier) const { return group_map.has(p_identifier); } -void SceneTree::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); + Map<StringName, Group>::Element *E = group_map.find(p_group); if (!E) return; _update_group_order(E->get()); //update order just in case int nc = E->get().nodes.size(); - if (nc==0) + if (nc == 0) return; Node **ptr = E->get().nodes.ptr(); - for(int i=0;i<nc;i++) { + for (int i = 0; i < nc; i++) { p_list->push_back(ptr[i]); } } - -static void _fill_array(Node *p_node, Array& array, int p_level) { +static void _fill_array(Node *p_node, Array &array, int p_level) { array.push_back(p_level); array.push_back(p_node->get_name()); array.push_back(p_node->get_type()); array.push_back(p_node->get_instance_ID()); - for(int i=0;i<p_node->get_child_count();i++) { + for (int i = 0; i < p_node->get_child_count(); i++) { - _fill_array(p_node->get_child(i),array,p_level+1); + _fill_array(p_node->get_child(i), array, p_level + 1); } } @@ -1017,20 +967,19 @@ void SceneTree::_debugger_request_tree(void *self) { SceneTree *sml = (SceneTree *)self; Array arr; - _fill_array(sml->root,arr,0); - ScriptDebugger::get_singleton()->send_message("scene_tree",arr); + _fill_array(sml->root, arr, 0); + ScriptDebugger::get_singleton()->send_message("scene_tree", arr); } - void SceneTree::_flush_delete_queue() { _THREAD_SAFE_METHOD_ - while( delete_queue.size() ) { + while (delete_queue.size()) { - Object *obj = ObjectDB::get_instance( delete_queue.front()->get() ); + Object *obj = ObjectDB::get_instance(delete_queue.front()->get()); if (obj) { - memdelete( obj ); + memdelete(obj); } delete_queue.pop_front(); } @@ -1044,23 +993,20 @@ void SceneTree::queue_delete(Object *p_object) { delete_queue.push_back(p_object->get_instance_ID()); } - int SceneTree::get_node_count() const { return node_count; } - void SceneTree::_update_root_rect() { - - if (stretch_mode==STRETCH_MODE_DISABLED) { - root->set_rect(Rect2(Point2(),last_screen_size)); + if (stretch_mode == STRETCH_MODE_DISABLED) { + root->set_rect(Rect2(Point2(), last_screen_size)); return; //user will take care } //actual screen video mode - Size2 video_mode = Size2(OS::get_singleton()->get_video_mode().width,OS::get_singleton()->get_video_mode().height); + Size2 video_mode = Size2(OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height); Size2 desired_res = stretch_min; Size2 viewport_size; @@ -1069,42 +1015,41 @@ void SceneTree::_update_root_rect() { float viewport_aspect = desired_res.get_aspect(); float video_mode_aspect = video_mode.get_aspect(); - if (stretch_aspect==STRETCH_ASPECT_IGNORE || ABS(viewport_aspect - video_mode_aspect)<CMP_EPSILON) { + if (stretch_aspect == STRETCH_ASPECT_IGNORE || ABS(viewport_aspect - video_mode_aspect) < CMP_EPSILON) { //same aspect or ignore aspect - viewport_size=desired_res; - screen_size=video_mode; + viewport_size = desired_res; + screen_size = video_mode; } else if (viewport_aspect < video_mode_aspect) { // screen ratio is smaller vertically - if (stretch_aspect==STRETCH_ASPECT_KEEP_HEIGHT) { + if (stretch_aspect == STRETCH_ASPECT_KEEP_HEIGHT) { //will stretch horizontally - viewport_size.x=desired_res.y*video_mode_aspect; - viewport_size.y=desired_res.y; - screen_size=video_mode; + viewport_size.x = desired_res.y * video_mode_aspect; + viewport_size.y = desired_res.y; + screen_size = video_mode; } else { //will need black bars - viewport_size=desired_res; + viewport_size = desired_res; screen_size.x = video_mode.y * viewport_aspect; - screen_size.y=video_mode.y; + screen_size.y = video_mode.y; } } else { //screen ratio is smaller horizontally - if (stretch_aspect==STRETCH_ASPECT_KEEP_WIDTH) { + if (stretch_aspect == STRETCH_ASPECT_KEEP_WIDTH) { //will stretch horizontally - viewport_size.x=desired_res.x; - viewport_size.y=desired_res.x / video_mode_aspect; - screen_size=video_mode; + viewport_size.x = desired_res.x; + viewport_size.y = desired_res.x / video_mode_aspect; + screen_size = video_mode; } else { //will need black bars - viewport_size=desired_res; - screen_size.x=video_mode.x; + viewport_size = desired_res; + screen_size.x = video_mode.x; screen_size.y = video_mode.x / viewport_aspect; } - } screen_size = screen_size.floor(); @@ -1114,58 +1059,54 @@ void SceneTree::_update_root_rect() { Size2 offset; //black bars and margin if (screen_size.x < video_mode.x) { - margin.x = Math::round((video_mode.x - screen_size.x)/2.0); - VisualServer::get_singleton()->black_bars_set_margins(margin.x,0,margin.x,0); + margin.x = Math::round((video_mode.x - screen_size.x) / 2.0); + VisualServer::get_singleton()->black_bars_set_margins(margin.x, 0, margin.x, 0); offset.x = Math::round(margin.x * viewport_size.y / screen_size.y); } else if (screen_size.y < video_mode.y) { - margin.y = Math::round((video_mode.y - screen_size.y)/2.0); - VisualServer::get_singleton()->black_bars_set_margins(0,margin.y,0,margin.y); + margin.y = Math::round((video_mode.y - screen_size.y) / 2.0); + VisualServer::get_singleton()->black_bars_set_margins(0, margin.y, 0, margin.y); offset.y = Math::round(margin.y * viewport_size.x / screen_size.x); } else { - VisualServer::get_singleton()->black_bars_set_margins(0,0,0,0); + VisualServer::get_singleton()->black_bars_set_margins(0, 0, 0, 0); } -// print_line("VP SIZE: "+viewport_size+" OFFSET: "+offset+" = "+(offset*2+viewport_size)); -// print_line("SS: "+video_mode); + // print_line("VP SIZE: "+viewport_size+" OFFSET: "+offset+" = "+(offset*2+viewport_size)); + // print_line("SS: "+video_mode); switch (stretch_mode) { case STRETCH_MODE_2D: { -// root->set_rect(Rect2(Point2(),video_mode)); + // root->set_rect(Rect2(Point2(),video_mode)); root->set_as_render_target(false); - root->set_rect(Rect2(margin,screen_size)); + root->set_rect(Rect2(margin, screen_size)); root->set_size_override_stretch(true); - root->set_size_override(true,viewport_size); + root->set_size_override(true, viewport_size); } break; case STRETCH_MODE_VIEWPORT: { - root->set_rect(Rect2(Point2(),viewport_size)); + root->set_rect(Rect2(Point2(), viewport_size)); root->set_size_override_stretch(false); - root->set_size_override(false,Size2()); + root->set_size_override(false, Size2()); root->set_as_render_target(true); root->set_render_target_update_mode(Viewport::RENDER_TARGET_UPDATE_ALWAYS); - root->set_render_target_to_screen_rect(Rect2(margin,screen_size)); + root->set_render_target_to_screen_rect(Rect2(margin, screen_size)); } break; - - } - } -void SceneTree::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; - stretch_min=p_minsize; + stretch_mode = p_mode; + stretch_aspect = p_aspect; + stretch_min = p_minsize; _update_root_rect(); } - #ifdef TOOLS_ENABLED void SceneTree::set_edited_scene_root(Node *p_node) { - edited_scene_root=p_node; + edited_scene_root = p_node; } Node *SceneTree::get_edited_scene_root() const { @@ -1174,76 +1115,74 @@ Node *SceneTree::get_edited_scene_root() const { } #endif -void SceneTree::set_current_scene(Node* p_scene) { +void SceneTree::set_current_scene(Node *p_scene) { - ERR_FAIL_COND(p_scene && p_scene->get_parent()!=root); - current_scene=p_scene; + ERR_FAIL_COND(p_scene && p_scene->get_parent() != root); + current_scene = p_scene; } -Node* SceneTree::get_current_scene() const{ +Node *SceneTree::get_current_scene() const { return current_scene; } -void SceneTree::_change_scene(Node* p_to) { +void SceneTree::_change_scene(Node *p_to) { if (current_scene) { - memdelete( current_scene ); - current_scene=NULL; + memdelete(current_scene); + current_scene = NULL; } if (p_to) { - current_scene=p_to; + current_scene = p_to; root->add_child(p_to); } } -Error SceneTree::change_scene(const String& p_path){ +Error SceneTree::change_scene(const String &p_path) { Ref<PackedScene> new_scene = ResourceLoader::load(p_path); if (new_scene.is_null()) return ERR_CANT_OPEN; return change_scene_to(new_scene); - } -Error SceneTree::change_scene_to(const Ref<PackedScene>& p_scene){ +Error SceneTree::change_scene_to(const Ref<PackedScene> &p_scene) { - Node *new_scene=NULL; + Node *new_scene = NULL; if (p_scene.is_valid()) { new_scene = p_scene->instance(); - ERR_FAIL_COND_V(!new_scene,ERR_CANT_CREATE); + ERR_FAIL_COND_V(!new_scene, ERR_CANT_CREATE); } - call_deferred("_change_scene",new_scene); + call_deferred("_change_scene", new_scene); return OK; - } Error SceneTree::reload_current_scene() { - ERR_FAIL_COND_V(!current_scene,ERR_UNCONFIGURED); + ERR_FAIL_COND_V(!current_scene, ERR_UNCONFIGURED); String fname = current_scene->get_filename(); return change_scene(fname); } -void SceneTree::add_current_scene(Node * p_current) { +void SceneTree::add_current_scene(Node *p_current) { - current_scene=p_current; + current_scene = p_current; root->add_child(p_current); } #ifdef DEBUG_ENABLED -void SceneTree::_live_edit_node_path_func(const NodePath &p_path,int p_id) { +void SceneTree::_live_edit_node_path_func(const NodePath &p_path, int p_id) { - live_edit_node_path_cache[p_id]=p_path; + live_edit_node_path_cache[p_id] = p_path; } -void SceneTree::_live_edit_res_path_func(const String &p_path,int p_id) { +void SceneTree::_live_edit_res_path_func(const String &p_path, int p_id) { - live_edit_resource_cache[p_id]=p_path; + live_edit_resource_cache[p_id] = p_path; } -void SceneTree::_live_edit_node_set_func(int p_id,const StringName& p_prop,const Variant& p_value) { +void SceneTree::_live_edit_node_set_func(int p_id, const StringName &p_prop, const Variant &p_value) { if (!live_edit_node_path_cache.has(p_id)) return; @@ -1253,13 +1192,13 @@ void SceneTree::_live_edit_node_set_func(int p_id,const StringName& p_prop,const if (root->has_node(live_edit_root)) base = root->get_node(live_edit_root); - Map<String,Set<Node*> >::Element *E=live_scene_edit_cache.find(live_edit_scene); + Map<String, Set<Node *> >::Element *E = live_scene_edit_cache.find(live_edit_scene); if (!E) return; //scene not editable - for(Set<Node*>::Element *F=E->get().front();F;F=F->next()) { + for (Set<Node *>::Element *F = E->get().front(); F; F = F->next()) { - Node *n=F->get(); + Node *n = F->get(); if (base && !base->is_a_parent_of(n)) continue; @@ -1268,20 +1207,18 @@ void SceneTree::_live_edit_node_set_func(int p_id,const StringName& p_prop,const continue; Node *n2 = n->get_node(np); - n2->set(p_prop,p_value); + n2->set(p_prop, p_value); } - } -void SceneTree::_live_edit_node_set_res_func(int p_id,const StringName& p_prop,const String& p_value) { +void SceneTree::_live_edit_node_set_res_func(int p_id, const StringName &p_prop, const String &p_value) { RES r = ResourceLoader::load(p_value); if (!r.is_valid()) return; - _live_edit_node_set_func(p_id,p_prop,r); - + _live_edit_node_set_func(p_id, p_prop, r); } -void SceneTree::_live_edit_node_call_func(int p_id,const StringName& p_method,VARIANT_ARG_DECLARE) { +void SceneTree::_live_edit_node_call_func(int p_id, const StringName &p_method, VARIANT_ARG_DECLARE) { if (!live_edit_node_path_cache.has(p_id)) return; @@ -1291,13 +1228,13 @@ void SceneTree::_live_edit_node_call_func(int p_id,const StringName& p_method,VA if (root->has_node(live_edit_root)) base = root->get_node(live_edit_root); - Map<String,Set<Node*> >::Element *E=live_scene_edit_cache.find(live_edit_scene); + Map<String, Set<Node *> >::Element *E = live_scene_edit_cache.find(live_edit_scene); if (!E) return; //scene not editable - for(Set<Node*>::Element *F=E->get().front();F;F=F->next()) { + for (Set<Node *>::Element *F = E->get().front(); F; F = F->next()) { - Node *n=F->get(); + Node *n = F->get(); if (base && !base->is_a_parent_of(n)) continue; @@ -1306,10 +1243,10 @@ void SceneTree::_live_edit_node_call_func(int p_id,const StringName& p_method,VA continue; Node *n2 = n->get_node(np); - n2->call(p_method,VARIANT_ARG_PASS); + n2->call(p_method, VARIANT_ARG_PASS); } } -void SceneTree::_live_edit_res_set_func(int p_id,const StringName& p_prop,const Variant& p_value) { +void SceneTree::_live_edit_res_set_func(int p_id, const StringName &p_prop, const Variant &p_value) { if (!live_edit_resource_cache.has(p_id)) return; @@ -1323,17 +1260,16 @@ void SceneTree::_live_edit_res_set_func(int p_id,const StringName& p_prop,const if (!r.is_valid()) return; - r->set(p_prop,p_value); + r->set(p_prop, p_value); } -void SceneTree::_live_edit_res_set_res_func(int p_id,const StringName& p_prop,const String& p_value) { +void SceneTree::_live_edit_res_set_res_func(int p_id, const StringName &p_prop, const String &p_value) { RES r = ResourceLoader::load(p_value); if (!r.is_valid()) return; - _live_edit_res_set_func(p_id,p_prop,r); - + _live_edit_res_set_func(p_id, p_prop, r); } -void SceneTree::_live_edit_res_call_func(int p_id,const StringName& p_method,VARIANT_ARG_DECLARE) { +void SceneTree::_live_edit_res_call_func(int p_id, const StringName &p_method, VARIANT_ARG_DECLARE) { if (!live_edit_resource_cache.has(p_id)) return; @@ -1347,29 +1283,28 @@ void SceneTree::_live_edit_res_call_func(int p_id,const StringName& p_method,VAR if (!r.is_valid()) return; - r->call(p_method,VARIANT_ARG_PASS); + r->call(p_method, VARIANT_ARG_PASS); } -void SceneTree::_live_edit_root_func(const NodePath& p_scene_path,const String& p_scene_from) { +void SceneTree::_live_edit_root_func(const NodePath &p_scene_path, const String &p_scene_from) { - live_edit_root=p_scene_path; - live_edit_scene=p_scene_from; + live_edit_root = p_scene_path; + live_edit_scene = p_scene_from; } -void SceneTree::_live_edit_create_node_func(const NodePath& p_parent,const String& p_type,const String& p_name) { - +void SceneTree::_live_edit_create_node_func(const NodePath &p_parent, const String &p_type, const String &p_name) { Node *base = NULL; if (root->has_node(live_edit_root)) base = root->get_node(live_edit_root); - Map<String,Set<Node*> >::Element *E=live_scene_edit_cache.find(live_edit_scene); + Map<String, Set<Node *> >::Element *E = live_scene_edit_cache.find(live_edit_scene); if (!E) return; //scene not editable - for(Set<Node*>::Element *F=E->get().front();F;F=F->next()) { + for (Set<Node *>::Element *F = E->get().front(); F; F = F->next()) { - Node *n=F->get(); + Node *n = F->get(); if (base && !base->is_a_parent_of(n)) continue; @@ -1381,13 +1316,13 @@ void SceneTree::_live_edit_create_node_func(const NodePath& p_parent,const Strin Object *o = ObjectTypeDB::instance(p_type); if (!o) continue; - Node *no=o->cast_to<Node>(); + Node *no = o->cast_to<Node>(); no->set_name(p_name); n2->add_child(no); } } -void SceneTree::_live_edit_instance_node_func(const NodePath& p_parent,const String& p_path,const String& p_name){ +void SceneTree::_live_edit_instance_node_func(const NodePath &p_parent, const String &p_path, const String &p_name) { Ref<PackedScene> ps = ResourceLoader::load(p_path); @@ -1398,13 +1333,13 @@ void SceneTree::_live_edit_instance_node_func(const NodePath& p_parent,const Str if (root->has_node(live_edit_root)) base = root->get_node(live_edit_root); - Map<String,Set<Node*> >::Element *E=live_scene_edit_cache.find(live_edit_scene); + Map<String, Set<Node *> >::Element *E = live_scene_edit_cache.find(live_edit_scene); if (!E) return; //scene not editable - for(Set<Node*>::Element *F=E->get().front();F;F=F->next()) { + for (Set<Node *>::Element *F = E->get().front(); F; F = F->next()) { - Node *n=F->get(); + Node *n = F->get(); if (base && !base->is_a_parent_of(n)) continue; @@ -1413,29 +1348,27 @@ void SceneTree::_live_edit_instance_node_func(const NodePath& p_parent,const Str continue; Node *n2 = n->get_node(p_parent); - - - Node *no=ps->instance(); + Node *no = ps->instance(); no->set_name(p_name); n2->add_child(no); } } -void SceneTree::_live_edit_remove_node_func(const NodePath& p_at){ +void SceneTree::_live_edit_remove_node_func(const NodePath &p_at) { Node *base = NULL; if (root->has_node(live_edit_root)) base = root->get_node(live_edit_root); - Map<String,Set<Node*> >::Element *E=live_scene_edit_cache.find(live_edit_scene); + Map<String, Set<Node *> >::Element *E = live_scene_edit_cache.find(live_edit_scene); if (!E) return; //scene not editable - for(Set<Node*>::Element *F=E->get().front();F;) { + for (Set<Node *>::Element *F = E->get().front(); F;) { - Set<Node*>::Element *N=F->next(); + Set<Node *>::Element *N = F->next(); - Node *n=F->get(); + Node *n = F->get(); if (base && !base->is_a_parent_of(n)) continue; @@ -1446,26 +1379,24 @@ void SceneTree::_live_edit_remove_node_func(const NodePath& p_at){ memdelete(n2); - F=N; - + F = N; } } -void SceneTree::_live_edit_remove_and_keep_node_func(const NodePath& p_at,ObjectID p_keep_id){ +void SceneTree::_live_edit_remove_and_keep_node_func(const NodePath &p_at, ObjectID p_keep_id) { Node *base = NULL; if (root->has_node(live_edit_root)) base = root->get_node(live_edit_root); - Map<String,Set<Node*> >::Element *E=live_scene_edit_cache.find(live_edit_scene); + Map<String, Set<Node *> >::Element *E = live_scene_edit_cache.find(live_edit_scene); if (!E) return; //scene not editable + for (Set<Node *>::Element *F = E->get().front(); F;) { - for(Set<Node*>::Element *F=E->get().front();F;) { - - Set<Node*>::Element *N=F->next(); + Set<Node *>::Element *N = F->next(); - Node *n=F->get(); + Node *n = F->get(); if (base && !base->is_a_parent_of(n)) continue; @@ -1477,28 +1408,26 @@ void SceneTree::_live_edit_remove_and_keep_node_func(const NodePath& p_at,Object n2->get_parent()->remove_child(n2); - live_edit_remove_list[n][p_keep_id]=n2; - - F=N; + live_edit_remove_list[n][p_keep_id] = n2; + F = N; } } -void SceneTree::_live_edit_restore_node_func(ObjectID p_id,const NodePath& p_at,int p_at_pos){ - +void SceneTree::_live_edit_restore_node_func(ObjectID p_id, const NodePath &p_at, int p_at_pos) { Node *base = NULL; if (root->has_node(live_edit_root)) base = root->get_node(live_edit_root); - Map<String,Set<Node*> >::Element *E=live_scene_edit_cache.find(live_edit_scene); + Map<String, Set<Node *> >::Element *E = live_scene_edit_cache.find(live_edit_scene); if (!E) return; //scene not editable - for(Set<Node*>::Element *F=E->get().front();F;) { + for (Set<Node *>::Element *F = E->get().front(); F;) { - Set<Node*>::Element *N=F->next(); + Set<Node *>::Element *N = F->next(); - Node *n=F->get(); + Node *n = F->get(); if (base && !base->is_a_parent_of(n)) continue; @@ -1507,12 +1436,12 @@ void SceneTree::_live_edit_restore_node_func(ObjectID p_id,const NodePath& p_at, continue; Node *n2 = n->get_node(p_at); - Map<Node*,Map<ObjectID,Node*> >::Element *EN=live_edit_remove_list.find(n); + Map<Node *, Map<ObjectID, Node *> >::Element *EN = live_edit_remove_list.find(n); if (!EN) continue; - Map<ObjectID,Node*>::Element *FN=EN->get().find(p_id); + Map<ObjectID, Node *>::Element *FN = EN->get().find(p_id); if (!FN) continue; @@ -1520,27 +1449,26 @@ void SceneTree::_live_edit_restore_node_func(ObjectID p_id,const NodePath& p_at, EN->get().erase(FN); - if (EN->get().size()==0) { + if (EN->get().size() == 0) { live_edit_remove_list.erase(EN); } - F=N; - + F = N; } } -void SceneTree::_live_edit_duplicate_node_func(const NodePath& p_at,const String& p_new_name){ +void SceneTree::_live_edit_duplicate_node_func(const NodePath &p_at, const String &p_new_name) { Node *base = NULL; if (root->has_node(live_edit_root)) base = root->get_node(live_edit_root); - Map<String,Set<Node*> >::Element *E=live_scene_edit_cache.find(live_edit_scene); + Map<String, Set<Node *> >::Element *E = live_scene_edit_cache.find(live_edit_scene); if (!E) return; //scene not editable - for(Set<Node*>::Element *F=E->get().front();F;F=F->next()) { + for (Set<Node *>::Element *F = E->get().front(); F; F = F->next()) { - Node *n=F->get(); + Node *n = F->get(); if (base && !base->is_a_parent_of(n)) continue; @@ -1556,22 +1484,21 @@ void SceneTree::_live_edit_duplicate_node_func(const NodePath& p_at,const String dup->set_name(p_new_name); n2->get_parent()->add_child(dup); - } } -void SceneTree::_live_edit_reparent_node_func(const NodePath& p_at,const NodePath& p_new_place,const String& p_new_name,int p_at_pos){ +void SceneTree::_live_edit_reparent_node_func(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos) { Node *base = NULL; if (root->has_node(live_edit_root)) base = root->get_node(live_edit_root); - Map<String,Set<Node*> >::Element *E=live_scene_edit_cache.find(live_edit_scene); + Map<String, Set<Node *> >::Element *E = live_scene_edit_cache.find(live_edit_scene); if (!E) return; //scene not editable - for(Set<Node*>::Element *F=E->get().front();F;F=F->next()) { + for (Set<Node *>::Element *F = E->get().front(); F; F = F->next()) { - Node *n=F->get(); + Node *n = F->get(); if (base && !base->is_a_parent_of(n)) continue; @@ -1588,203 +1515,187 @@ void SceneTree::_live_edit_reparent_node_func(const NodePath& p_at,const NodePat nfrom->set_name(p_new_name); nto->add_child(nfrom); - if (p_at_pos>=0) - nto->move_child(nfrom,p_at_pos); - + if (p_at_pos >= 0) + nto->move_child(nfrom, p_at_pos); } } - #endif +void SceneTree::drop_files(const Vector<String> &p_files, int p_from_screen) { -void SceneTree::drop_files(const Vector<String>& p_files,int p_from_screen) { - - emit_signal("files_dropped",p_files,p_from_screen); - MainLoop::drop_files(p_files,p_from_screen); + emit_signal("files_dropped", p_files, p_from_screen); + MainLoop::drop_files(p_files, p_from_screen); } 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"),&SceneTree::notify_group); - ObjectTypeDB::bind_method(_MD("set_group","call_flags","group","property","value"),&SceneTree::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","group"),&SceneTree::_get_nodes_in_group); + ObjectTypeDB::bind_method(_MD("get_nodes_in_group", "group"), &SceneTree::_get_nodes_in_group); - ObjectTypeDB::bind_method(_MD("get_root:Viewport"),&SceneTree::get_root); - ObjectTypeDB::bind_method(_MD("has_group","name"),&SceneTree::has_group); + ObjectTypeDB::bind_method(_MD("get_root:Viewport"), &SceneTree::get_root); + ObjectTypeDB::bind_method(_MD("has_group", "name"), &SceneTree::has_group); - ObjectTypeDB::bind_method(_MD("set_auto_accept_quit","enabled"),&SceneTree::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"),&SceneTree::set_editor_hint); - ObjectTypeDB::bind_method(_MD("is_editor_hint"),&SceneTree::is_editor_hint); - ObjectTypeDB::bind_method(_MD("set_debug_collisions_hint","enable"),&SceneTree::set_debug_collisions_hint); - ObjectTypeDB::bind_method(_MD("is_debugging_collisions_hint"),&SceneTree::is_debugging_collisions_hint); - ObjectTypeDB::bind_method(_MD("set_debug_navigation_hint","enable"),&SceneTree::set_debug_navigation_hint); - ObjectTypeDB::bind_method(_MD("is_debugging_navigation_hint"),&SceneTree::is_debugging_navigation_hint); + ObjectTypeDB::bind_method(_MD("set_editor_hint", "enable"), &SceneTree::set_editor_hint); + ObjectTypeDB::bind_method(_MD("is_editor_hint"), &SceneTree::is_editor_hint); + ObjectTypeDB::bind_method(_MD("set_debug_collisions_hint", "enable"), &SceneTree::set_debug_collisions_hint); + ObjectTypeDB::bind_method(_MD("is_debugging_collisions_hint"), &SceneTree::is_debugging_collisions_hint); + ObjectTypeDB::bind_method(_MD("set_debug_navigation_hint", "enable"), &SceneTree::set_debug_navigation_hint); + ObjectTypeDB::bind_method(_MD("is_debugging_navigation_hint"), &SceneTree::is_debugging_navigation_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); + 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"),&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"),&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"),&SceneTree::set_screen_stretch); - - ObjectTypeDB::bind_method(_MD("queue_delete","obj"),&SceneTree::queue_delete); + 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"), &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"), &SceneTree::set_screen_stretch); + ObjectTypeDB::bind_method(_MD("queue_delete", "obj"), &SceneTree::queue_delete); MethodInfo mi; - mi.name="call_group"; - mi.arguments.push_back( PropertyInfo( Variant::INT, "flags")); - mi.arguments.push_back( PropertyInfo( Variant::STRING, "group")); - mi.arguments.push_back( PropertyInfo( Variant::STRING, "method")); + mi.name = "call_group"; + mi.arguments.push_back(PropertyInfo(Variant::INT, "flags")); + mi.arguments.push_back(PropertyInfo(Variant::STRING, "group")); + mi.arguments.push_back(PropertyInfo(Variant::STRING, "method")); Vector<Variant> defargs; - for(int i=0;i<VARIANT_ARG_MAX;i++) { - mi.arguments.push_back( PropertyInfo( Variant::NIL, "arg"+itos(i))); + for (int i = 0; i < VARIANT_ARG_MAX; i++) { + mi.arguments.push_back(PropertyInfo(Variant::NIL, "arg" + itos(i))); defargs.push_back(Variant()); } - ObjectTypeDB::bind_native_method(METHOD_FLAGS_DEFAULT,"call_group",&SceneTree::_call_group,mi,defargs); - - ObjectTypeDB::bind_method(_MD("set_current_scene","child_node:Node"),&SceneTree::set_current_scene); - ObjectTypeDB::bind_method(_MD("get_current_scene:Node"),&SceneTree::get_current_scene); + ObjectTypeDB::bind_native_method(METHOD_FLAGS_DEFAULT, "call_group", &SceneTree::_call_group, mi, defargs); - ObjectTypeDB::bind_method(_MD("change_scene","path"),&SceneTree::change_scene); - ObjectTypeDB::bind_method(_MD("change_scene_to","packed_scene:PackedScene"),&SceneTree::change_scene_to); + ObjectTypeDB::bind_method(_MD("set_current_scene", "child_node:Node"), &SceneTree::set_current_scene); + ObjectTypeDB::bind_method(_MD("get_current_scene:Node"), &SceneTree::get_current_scene); - ObjectTypeDB::bind_method(_MD("reload_current_scene"),&SceneTree::reload_current_scene); + ObjectTypeDB::bind_method(_MD("change_scene", "path"), &SceneTree::change_scene); + ObjectTypeDB::bind_method(_MD("change_scene_to", "packed_scene:PackedScene"), &SceneTree::change_scene_to); - ObjectTypeDB::bind_method(_MD("_change_scene"),&SceneTree::_change_scene); + ObjectTypeDB::bind_method(_MD("reload_current_scene"), &SceneTree::reload_current_scene); - ADD_SIGNAL( MethodInfo("tree_changed") ); - ADD_SIGNAL( MethodInfo("node_removed",PropertyInfo( Variant::OBJECT, "node") ) ); - ADD_SIGNAL( MethodInfo("screen_resized") ); - ADD_SIGNAL( MethodInfo("node_configuration_warning_changed",PropertyInfo( Variant::OBJECT, "node")) ); + ObjectTypeDB::bind_method(_MD("_change_scene"), &SceneTree::_change_scene); - ADD_SIGNAL( MethodInfo("idle_frame")); - ADD_SIGNAL( MethodInfo("fixed_frame")); + ADD_SIGNAL(MethodInfo("tree_changed")); + ADD_SIGNAL(MethodInfo("node_removed", PropertyInfo(Variant::OBJECT, "node"))); + ADD_SIGNAL(MethodInfo("screen_resized")); + ADD_SIGNAL(MethodInfo("node_configuration_warning_changed", PropertyInfo(Variant::OBJECT, "node"))); - ADD_SIGNAL( MethodInfo("files_dropped",PropertyInfo(Variant::STRING_ARRAY,"files"),PropertyInfo(Variant::INT,"screen")) ); + ADD_SIGNAL(MethodInfo("idle_frame")); + ADD_SIGNAL(MethodInfo("fixed_frame")); - BIND_CONSTANT( GROUP_CALL_DEFAULT ); - BIND_CONSTANT( GROUP_CALL_REVERSE ); - BIND_CONSTANT( GROUP_CALL_REALTIME ); - BIND_CONSTANT( GROUP_CALL_UNIQUE ); + ADD_SIGNAL(MethodInfo("files_dropped", PropertyInfo(Variant::STRING_ARRAY, "files"), PropertyInfo(Variant::INT, "screen"))); - 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_CONSTANT(GROUP_CALL_DEFAULT); + BIND_CONSTANT(GROUP_CALL_REVERSE); + BIND_CONSTANT(GROUP_CALL_REALTIME); + BIND_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); } -SceneTree *SceneTree::singleton=NULL; +SceneTree *SceneTree::singleton = NULL; SceneTree::SceneTree() { - singleton=this; - _quit=false; - initialized=false; - editor_hint=false; - debug_collisions_hint=false; - debug_navigation_hint=false; - debug_collisions_color=GLOBAL_DEF("debug/collision_shape_color",Color(0.0,0.6,0.7,0.5)); - debug_collision_contact_color=GLOBAL_DEF("debug/collision_contact_color",Color(1.0,0.2,0.1,0.8)); - debug_navigation_color=GLOBAL_DEF("debug/navigation_geometry_color",Color(0.1,1.0,0.7,0.4)); - debug_navigation_disabled_color=GLOBAL_DEF("debug/navigation_disabled_geometry_color",Color(1.0,0.7,0.1,0.4)); - collision_debug_contacts=GLOBAL_DEF("debug/collision_max_contacts_displayed",10000); - + singleton = this; + _quit = false; + initialized = false; + editor_hint = false; + debug_collisions_hint = false; + debug_navigation_hint = false; + debug_collisions_color = GLOBAL_DEF("debug/collision_shape_color", Color(0.0, 0.6, 0.7, 0.5)); + debug_collision_contact_color = GLOBAL_DEF("debug/collision_contact_color", Color(1.0, 0.2, 0.1, 0.8)); + debug_navigation_color = GLOBAL_DEF("debug/navigation_geometry_color", Color(0.1, 1.0, 0.7, 0.4)); + debug_navigation_disabled_color = GLOBAL_DEF("debug/navigation_disabled_geometry_color", Color(1.0, 0.7, 0.1, 0.4)); + collision_debug_contacts = GLOBAL_DEF("debug/collision_max_contacts_displayed", 10000); - tree_version=1; - fixed_process_time=1; - idle_process_time=1; - last_id=1; - root=NULL; - current_frame=0; - tree_changed_name="tree_changed"; - node_removed_name="node_removed"; - ugc_locked=false; - call_lock=0; - root_lock=0; - node_count=0; + tree_version = 1; + fixed_process_time = 1; + idle_process_time = 1; + last_id = 1; + root = NULL; + current_frame = 0; + tree_changed_name = "tree_changed"; + node_removed_name = "node_removed"; + ugc_locked = false; + call_lock = 0; + root_lock = 0; + node_count = 0; //create with mainloop - root = memnew( Viewport ); + root = memnew(Viewport); root->set_name("root"); - root->set_world( Ref<World>( memnew( World ))); + root->set_world(Ref<World>(memnew(World))); //root->set_world_2d( Ref<World2D>( memnew( World2D ))); root->set_as_audio_listener(true); root->set_as_audio_listener_2d(true); - current_scene=NULL; + current_scene = NULL; - stretch_mode=STRETCH_MODE_DISABLED; - stretch_aspect=STRETCH_ASPECT_IGNORE; + stretch_mode = STRETCH_MODE_DISABLED; + stretch_aspect = STRETCH_ASPECT_IGNORE; - last_screen_size=Size2( OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height ); - root->set_rect(Rect2(Point2(),last_screen_size)); + last_screen_size = Size2(OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height); + root->set_rect(Rect2(Point2(), last_screen_size)); if (ScriptDebugger::get_singleton()) { - ScriptDebugger::get_singleton()->set_request_scene_tree_message_func(_debugger_request_tree,this); + ScriptDebugger::get_singleton()->set_request_scene_tree_message_func(_debugger_request_tree, this); } - root->set_physics_object_picking(GLOBAL_DEF("physics/enable_object_picking",true)); + root->set_physics_object_picking(GLOBAL_DEF("physics/enable_object_picking", true)); #ifdef TOOLS_ENABLED - edited_scene_root=NULL; + edited_scene_root = NULL; #endif #ifdef DEBUG_ENABLED + live_edit_funcs.udata = this; + live_edit_funcs.node_path_func = _live_edit_node_path_funcs; + live_edit_funcs.res_path_func = _live_edit_res_path_funcs; + live_edit_funcs.node_set_func = _live_edit_node_set_funcs; + live_edit_funcs.node_set_res_func = _live_edit_node_set_res_funcs; + live_edit_funcs.node_call_func = _live_edit_node_call_funcs; + live_edit_funcs.res_set_func = _live_edit_res_set_funcs; + live_edit_funcs.res_set_res_func = _live_edit_res_set_res_funcs; + live_edit_funcs.res_call_func = _live_edit_res_call_funcs; + live_edit_funcs.root_func = _live_edit_root_funcs; - live_edit_funcs.udata=this; - live_edit_funcs.node_path_func=_live_edit_node_path_funcs; - live_edit_funcs.res_path_func=_live_edit_res_path_funcs; - live_edit_funcs.node_set_func=_live_edit_node_set_funcs; - live_edit_funcs.node_set_res_func=_live_edit_node_set_res_funcs; - live_edit_funcs.node_call_func=_live_edit_node_call_funcs; - live_edit_funcs.res_set_func=_live_edit_res_set_funcs; - live_edit_funcs.res_set_res_func=_live_edit_res_set_res_funcs; - live_edit_funcs.res_call_func=_live_edit_res_call_funcs; - live_edit_funcs.root_func=_live_edit_root_funcs; - - live_edit_funcs.tree_create_node_func=_live_edit_create_node_funcs; - live_edit_funcs.tree_instance_node_func=_live_edit_instance_node_funcs; - live_edit_funcs.tree_remove_node_func=_live_edit_remove_node_funcs; - live_edit_funcs.tree_remove_and_keep_node_func=_live_edit_remove_and_keep_node_funcs; - live_edit_funcs.tree_restore_node_func=_live_edit_restore_node_funcs; - live_edit_funcs.tree_duplicate_node_func=_live_edit_duplicate_node_funcs; - live_edit_funcs.tree_reparent_node_func=_live_edit_reparent_node_funcs; + live_edit_funcs.tree_create_node_func = _live_edit_create_node_funcs; + live_edit_funcs.tree_instance_node_func = _live_edit_instance_node_funcs; + live_edit_funcs.tree_remove_node_func = _live_edit_remove_node_funcs; + live_edit_funcs.tree_remove_and_keep_node_func = _live_edit_remove_and_keep_node_funcs; + live_edit_funcs.tree_restore_node_func = _live_edit_restore_node_funcs; + live_edit_funcs.tree_duplicate_node_func = _live_edit_duplicate_node_funcs; + live_edit_funcs.tree_reparent_node_func = _live_edit_reparent_node_funcs; if (ScriptDebugger::get_singleton()) { ScriptDebugger::get_singleton()->set_live_edit_funcs(&live_edit_funcs); } - live_edit_root=NodePath("/root"); + live_edit_root = NodePath("/root"); #endif - - } - SceneTree::~SceneTree() { - - } diff --git a/scene/main/scene_main_loop.h b/scene/main/scene_main_loop.h index 4d89cd5ec..8b20c8dbf 100644 --- a/scene/main/scene_main_loop.h +++ b/scene/main/scene_main_loop.h @@ -29,17 +29,15 @@ #ifndef SCENE_MAIN_LOOP_H #define SCENE_MAIN_LOOP_H - #include "os/main_loop.h" +#include "os/thread_safe.h" #include "scene/resources/world.h" #include "scene/resources/world_2d.h" -#include "os/thread_safe.h" #include "self_list.h" /** @author Juan Linietsky <reduzio@gmail.com> */ - class SceneTree; class PackedScene; class Node; @@ -51,10 +49,9 @@ class SceneTree : public MainLoop { _THREAD_SAFE_CLASS_ - OBJ_TYPE( SceneTree, MainLoop ); -public: - + OBJ_TYPE(SceneTree, MainLoop); +public: enum StretchMode { STRETCH_MODE_DISABLED, @@ -69,15 +66,14 @@ public: STRETCH_ASPECT_KEEP_WIDTH, STRETCH_ASPECT_KEEP_HEIGHT, }; -private: - +private: struct Group { - Vector<Node*> nodes; + Vector<Node *> nodes; //uint64_t last_tree_version; bool changed; - Group() { changed=false; }; + Group() { changed = false; }; }; Viewport *root; @@ -94,7 +90,7 @@ private: bool pause; int root_lock; - Map<StringName,Group> group_map; + Map<StringName, Group> group_map; bool _quit; bool initialized; bool input_handled; @@ -102,7 +98,6 @@ private: StringName tree_changed_name; StringName node_removed_name; - int64_t current_frame; int node_count; @@ -114,13 +109,12 @@ private: StringName group; StringName call; - bool operator<(const UGCall& p_with) const { return group==p_with.group?call<p_with.call:group<p_with.group; } + bool operator<(const UGCall &p_with) const { return group == p_with.group ? call < p_with.call : group < p_with.group; } }; //safety for when a node is deleted while a group is being called int call_lock; - Set<Node*> call_skip; //skip erased nodes - + Set<Node *> call_skip; //skip erased nodes StretchMode stretch_mode; StretchAspect stretch_aspect; @@ -130,15 +124,15 @@ private: List<ObjectID> delete_queue; - Map<UGCall,Vector<Variant> > unique_group_calls; + Map<UGCall, Vector<Variant> > unique_group_calls; bool ugc_locked; void _flush_ugc(); void _flush_transform_notifications(); - _FORCE_INLINE_ void _update_group_order(Group& g); + _FORCE_INLINE_ void _update_group_order(Group &g); void _update_listener(); - Array _get_nodes_in_group(const StringName& p_group); + Array _get_nodes_in_group(const StringName &p_group); Node *current_scene; @@ -152,115 +146,110 @@ private: Ref<Material> collision_material; int collision_debug_contacts; - void _change_scene(Node* p_to); + void _change_scene(Node *p_to); //void _call_group(uint32_t p_call_flags,const StringName& p_group,const StringName& p_function,const Variant& p_arg1,const Variant& p_arg2); static SceneTree *singleton; -friend class Node; + friend class Node; void tree_changed(); void node_removed(Node *p_node); + Group *add_to_group(const StringName &p_group, Node *p_node); + void remove_from_group(const StringName &p_group, Node *p_node); - Group* add_to_group(const StringName& p_group, Node *p_node); - void remove_from_group(const StringName& p_group, Node *p_node); - - void _notify_group_pause(const StringName& p_group,int p_notification); - void _call_input_pause(const StringName& p_group,const StringName& p_method,const InputEvent& p_input); - Variant _call_group(const Variant** p_args, int p_argcount, Variant::CallError& r_error); - + void _notify_group_pause(const StringName &p_group, int p_notification); + void _call_input_pause(const StringName &p_group, const StringName &p_method, const InputEvent &p_input); + Variant _call_group(const Variant **p_args, int p_argcount, Variant::CallError &r_error); static void _debugger_request_tree(void *self); void _flush_delete_queue(); -//optimization -friend class CanvasItem; -friend class Spatial; -friend class Viewport; + //optimization + friend class CanvasItem; + friend class Spatial; + friend class Viewport; SelfList<Node>::List xform_change_list; #ifdef DEBUG_ENABLED - Map<int,NodePath> live_edit_node_path_cache; - Map<int,String> live_edit_resource_cache; + Map<int, NodePath> live_edit_node_path_cache; + Map<int, String> live_edit_resource_cache; NodePath live_edit_root; String live_edit_scene; - Map<String,Set<Node*> > live_scene_edit_cache; - Map<Node*,Map<ObjectID,Node*> > live_edit_remove_list; + Map<String, Set<Node *> > live_scene_edit_cache; + Map<Node *, Map<ObjectID, Node *> > live_edit_remove_list; ScriptDebugger::LiveEditFuncs live_edit_funcs; - void _live_edit_node_path_func(const NodePath &p_path,int p_id) ; - void _live_edit_res_path_func(const String &p_path,int p_id) ; + void _live_edit_node_path_func(const NodePath &p_path, int p_id); + void _live_edit_res_path_func(const String &p_path, int p_id); - void _live_edit_node_set_func(int p_id,const StringName& p_prop,const Variant& p_value) ; - void _live_edit_node_set_res_func(int p_id,const StringName& p_prop,const String& p_value) ; - void _live_edit_node_call_func(int p_id,const StringName& p_method,VARIANT_ARG_DECLARE) ; - void _live_edit_res_set_func(int p_id,const StringName& p_prop,const Variant& p_value) ; - void _live_edit_res_set_res_func(int p_id,const StringName& p_prop,const String& p_value) ; - void _live_edit_res_call_func(int p_id,const StringName& p_method,VARIANT_ARG_DECLARE) ; - void _live_edit_root_func(const NodePath& p_scene_path,const String& p_scene_from) ; + void _live_edit_node_set_func(int p_id, const StringName &p_prop, const Variant &p_value); + void _live_edit_node_set_res_func(int p_id, const StringName &p_prop, const String &p_value); + void _live_edit_node_call_func(int p_id, const StringName &p_method, VARIANT_ARG_DECLARE); + void _live_edit_res_set_func(int p_id, const StringName &p_prop, const Variant &p_value); + void _live_edit_res_set_res_func(int p_id, const StringName &p_prop, const String &p_value); + void _live_edit_res_call_func(int p_id, const StringName &p_method, VARIANT_ARG_DECLARE); + void _live_edit_root_func(const NodePath &p_scene_path, const String &p_scene_from); - void _live_edit_create_node_func(const NodePath& p_parent,const String& p_type,const String& p_name); - void _live_edit_instance_node_func(const NodePath& p_parent,const String& p_path,const String& p_name); - void _live_edit_remove_node_func(const NodePath& p_at); - void _live_edit_remove_and_keep_node_func(const NodePath& p_at,ObjectID p_keep_id); - void _live_edit_restore_node_func(ObjectID p_id,const NodePath& p_at,int p_at_pos); - void _live_edit_duplicate_node_func(const NodePath& p_at,const String& p_new_name); - void _live_edit_reparent_node_func(const NodePath& p_at,const NodePath& p_new_place,const String& p_new_name,int p_at_pos); + void _live_edit_create_node_func(const NodePath &p_parent, const String &p_type, const String &p_name); + void _live_edit_instance_node_func(const NodePath &p_parent, const String &p_path, const String &p_name); + void _live_edit_remove_node_func(const NodePath &p_at); + void _live_edit_remove_and_keep_node_func(const NodePath &p_at, ObjectID p_keep_id); + void _live_edit_restore_node_func(ObjectID p_id, const NodePath &p_at, int p_at_pos); + void _live_edit_duplicate_node_func(const NodePath &p_at, const String &p_new_name); + void _live_edit_reparent_node_func(const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos); - static void _live_edit_node_path_funcs(void *self,const NodePath &p_path,int p_id) { reinterpret_cast<SceneTree*>(self)->_live_edit_node_path_func(p_path,p_id); } - static void _live_edit_res_path_funcs(void *self,const String &p_path,int p_id) { reinterpret_cast<SceneTree*>(self)->_live_edit_res_path_func(p_path,p_id); } + static void _live_edit_node_path_funcs(void *self, const NodePath &p_path, int p_id) { reinterpret_cast<SceneTree *>(self)->_live_edit_node_path_func(p_path, p_id); } + static void _live_edit_res_path_funcs(void *self, const String &p_path, int p_id) { reinterpret_cast<SceneTree *>(self)->_live_edit_res_path_func(p_path, p_id); } - static void _live_edit_node_set_funcs(void *self,int p_id,const StringName& p_prop,const Variant& p_value) { reinterpret_cast<SceneTree*>(self)->_live_edit_node_set_func(p_id,p_prop,p_value); } - static void _live_edit_node_set_res_funcs(void *self,int p_id,const StringName& p_prop,const String& p_value) { reinterpret_cast<SceneTree*>(self)->_live_edit_node_set_res_func(p_id,p_prop,p_value); } - static void _live_edit_node_call_funcs(void *self,int p_id,const StringName& p_method,VARIANT_ARG_DECLARE) { reinterpret_cast<SceneTree*>(self)->_live_edit_node_call_func(p_id,p_method,VARIANT_ARG_PASS); } - static void _live_edit_res_set_funcs(void *self,int p_id,const StringName& p_prop,const Variant& p_value) { reinterpret_cast<SceneTree*>(self)->_live_edit_res_set_func(p_id,p_prop,p_value); } - static void _live_edit_res_set_res_funcs(void *self,int p_id,const StringName& p_prop,const String& p_value) { reinterpret_cast<SceneTree*>(self)->_live_edit_res_set_res_func(p_id,p_prop,p_value); } - static void _live_edit_res_call_funcs(void *self,int p_id,const StringName& p_method,VARIANT_ARG_DECLARE) { reinterpret_cast<SceneTree*>(self)->_live_edit_res_call_func(p_id,p_method,VARIANT_ARG_PASS); } - static void _live_edit_root_funcs(void *self, const NodePath& p_scene_path,const String& p_scene_from) { reinterpret_cast<SceneTree*>(self)->_live_edit_root_func(p_scene_path,p_scene_from); } + static void _live_edit_node_set_funcs(void *self, int p_id, const StringName &p_prop, const Variant &p_value) { reinterpret_cast<SceneTree *>(self)->_live_edit_node_set_func(p_id, p_prop, p_value); } + static void _live_edit_node_set_res_funcs(void *self, int p_id, const StringName &p_prop, const String &p_value) { reinterpret_cast<SceneTree *>(self)->_live_edit_node_set_res_func(p_id, p_prop, p_value); } + static void _live_edit_node_call_funcs(void *self, int p_id, const StringName &p_method, VARIANT_ARG_DECLARE) { reinterpret_cast<SceneTree *>(self)->_live_edit_node_call_func(p_id, p_method, VARIANT_ARG_PASS); } + static void _live_edit_res_set_funcs(void *self, int p_id, const StringName &p_prop, const Variant &p_value) { reinterpret_cast<SceneTree *>(self)->_live_edit_res_set_func(p_id, p_prop, p_value); } + static void _live_edit_res_set_res_funcs(void *self, int p_id, const StringName &p_prop, const String &p_value) { reinterpret_cast<SceneTree *>(self)->_live_edit_res_set_res_func(p_id, p_prop, p_value); } + static void _live_edit_res_call_funcs(void *self, int p_id, const StringName &p_method, VARIANT_ARG_DECLARE) { reinterpret_cast<SceneTree *>(self)->_live_edit_res_call_func(p_id, p_method, VARIANT_ARG_PASS); } + static void _live_edit_root_funcs(void *self, const NodePath &p_scene_path, const String &p_scene_from) { reinterpret_cast<SceneTree *>(self)->_live_edit_root_func(p_scene_path, p_scene_from); } - static void _live_edit_create_node_funcs(void* self,const NodePath& p_parent,const String& p_type,const String& p_name) { reinterpret_cast<SceneTree*>(self)->_live_edit_create_node_func(p_parent,p_type,p_name); } - static void _live_edit_instance_node_funcs(void* self,const NodePath& p_parent,const String& p_path,const String& p_name) { reinterpret_cast<SceneTree*>(self)->_live_edit_instance_node_func(p_parent,p_path,p_name); } - static void _live_edit_remove_node_funcs(void* self,const NodePath& p_at) { reinterpret_cast<SceneTree*>(self)->_live_edit_remove_node_func(p_at); } - static void _live_edit_remove_and_keep_node_funcs(void* self,const NodePath& p_at,ObjectID p_keep_id) { reinterpret_cast<SceneTree*>(self)->_live_edit_remove_and_keep_node_func(p_at,p_keep_id); } - static void _live_edit_restore_node_funcs(void* self,ObjectID p_id,const NodePath& p_at,int p_at_pos) { reinterpret_cast<SceneTree*>(self)->_live_edit_restore_node_func(p_id,p_at,p_at_pos); } - static void _live_edit_duplicate_node_funcs(void* self,const NodePath& p_at,const String& p_new_name) { reinterpret_cast<SceneTree*>(self)->_live_edit_duplicate_node_func(p_at,p_new_name); } - static void _live_edit_reparent_node_funcs(void* self,const NodePath& p_at,const NodePath& p_new_place,const String& p_new_name,int p_at_pos) { reinterpret_cast<SceneTree*>(self)->_live_edit_reparent_node_func(p_at,p_new_place,p_new_name,p_at_pos); } + static void _live_edit_create_node_funcs(void *self, const NodePath &p_parent, const String &p_type, const String &p_name) { reinterpret_cast<SceneTree *>(self)->_live_edit_create_node_func(p_parent, p_type, p_name); } + static void _live_edit_instance_node_funcs(void *self, const NodePath &p_parent, const String &p_path, const String &p_name) { reinterpret_cast<SceneTree *>(self)->_live_edit_instance_node_func(p_parent, p_path, p_name); } + static void _live_edit_remove_node_funcs(void *self, const NodePath &p_at) { reinterpret_cast<SceneTree *>(self)->_live_edit_remove_node_func(p_at); } + static void _live_edit_remove_and_keep_node_funcs(void *self, const NodePath &p_at, ObjectID p_keep_id) { reinterpret_cast<SceneTree *>(self)->_live_edit_remove_and_keep_node_func(p_at, p_keep_id); } + static void _live_edit_restore_node_funcs(void *self, ObjectID p_id, const NodePath &p_at, int p_at_pos) { reinterpret_cast<SceneTree *>(self)->_live_edit_restore_node_func(p_id, p_at, p_at_pos); } + static void _live_edit_duplicate_node_funcs(void *self, const NodePath &p_at, const String &p_new_name) { reinterpret_cast<SceneTree *>(self)->_live_edit_duplicate_node_func(p_at, p_new_name); } + static void _live_edit_reparent_node_funcs(void *self, const NodePath &p_at, const NodePath &p_new_place, const String &p_new_name, int p_at_pos) { reinterpret_cast<SceneTree *>(self)->_live_edit_reparent_node_func(p_at, p_new_place, p_new_name, p_at_pos); } #endif protected: - void _notification(int p_notification); static void _bind_methods(); public: - enum { - NOTIFICATION_TRANSFORM_CHANGED=29 + NOTIFICATION_TRANSFORM_CHANGED = 29 }; enum CallGroupFlags { - GROUP_CALL_DEFAULT=0, - GROUP_CALL_REVERSE=1, - GROUP_CALL_REALTIME=2, - GROUP_CALL_UNIQUE=4, - GROUP_CALL_MULIILEVEL=8, + GROUP_CALL_DEFAULT = 0, + GROUP_CALL_REVERSE = 1, + GROUP_CALL_REALTIME = 2, + GROUP_CALL_UNIQUE = 4, + GROUP_CALL_MULIILEVEL = 8, }; _FORCE_INLINE_ Viewport *get_root() const { return root; } uint32_t get_last_event_id() const; - void call_group(uint32_t p_call_flags,const StringName& p_group,const StringName& p_function,VARIANT_ARG_LIST); - void notify_group(uint32_t p_call_flags,const StringName& p_group,int p_notification); - void set_group(uint32_t p_call_flags,const StringName& p_group,const String& p_name,const Variant& p_value); - + void call_group(uint32_t p_call_flags, const StringName &p_group, const StringName &p_function, VARIANT_ARG_LIST); + void notify_group(uint32_t p_call_flags, const StringName &p_group, int p_notification); + void set_group(uint32_t p_call_flags, const StringName &p_group, const String &p_name, const Variant &p_value); - virtual void input_text( const String& p_text ); - virtual void input_event( const InputEvent& p_event ); + virtual void input_text(const String &p_text); + virtual void input_event(const InputEvent &p_event); virtual void init(); virtual bool iteration(float p_time); @@ -279,12 +268,12 @@ public: void set_editor_hint(bool p_enabled); bool is_editor_hint() const; - bool is_node_being_edited(const Node* p_node) const; + bool is_node_being_edited(const Node *p_node) const; void set_pause(bool p_enabled); bool is_paused() const; - void set_camera(const RID& p_camera); + void set_camera(const RID &p_camera); RID get_camera() const; void set_debug_collisions_hint(bool p_enabled); @@ -293,19 +282,18 @@ public: void set_debug_navigation_hint(bool p_enabled); bool is_debugging_navigation_hint() const; - void set_debug_collisions_color(const Color& p_color); + void set_debug_collisions_color(const Color &p_color); Color get_debug_collisions_color() const; - void set_debug_collision_contact_color(const Color& p_color); + void set_debug_collision_contact_color(const Color &p_color); Color get_debug_collision_contact_color() const; - void set_debug_navigation_color(const Color& p_color); + void set_debug_navigation_color(const Color &p_color); Color get_debug_navigation_color() const; - void set_debug_navigation_disabled_color(const Color& p_color); + void set_debug_navigation_disabled_color(const Color &p_color); Color get_debug_navigation_disabled_color() const; - Ref<Material> get_debug_navigation_material(); Ref<Material> get_debug_navigation_disabled_material(); Ref<Material> get_debug_collision_material(); @@ -319,42 +307,37 @@ public: void queue_delete(Object *p_object); - void get_nodes_in_group(const StringName& p_group,List<Node*> *p_list); - bool has_group(const StringName& p_identifier) const; + void get_nodes_in_group(const StringName &p_group, List<Node *> *p_list); + bool has_group(const StringName &p_identifier) const; + void set_screen_stretch(StretchMode p_mode, StretchAspect p_aspect, const Size2 p_minsize); - 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(); +//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 - void set_current_scene(Node* p_scene); - Node* get_current_scene() const; - Error change_scene(const String& p_path); - Error change_scene_to(const Ref<PackedScene>& p_scene); + void set_current_scene(Node *p_scene); + Node *get_current_scene() const; + Error change_scene(const String &p_path); + Error change_scene_to(const Ref<PackedScene> &p_scene); Error reload_current_scene(); //used by Main::start, don't use otherwise - void add_current_scene(Node * p_current); + void add_current_scene(Node *p_current); - static SceneTree* get_singleton() { return singleton; } + static SceneTree *get_singleton() { return singleton; } - void drop_files(const Vector<String>& p_files,int p_from_screen=0); + void drop_files(const Vector<String> &p_files, int p_from_screen = 0); SceneTree(); ~SceneTree(); - }; - -VARIANT_ENUM_CAST( SceneTree::StretchMode ); -VARIANT_ENUM_CAST( SceneTree::StretchAspect ); - - +VARIANT_ENUM_CAST(SceneTree::StretchMode); +VARIANT_ENUM_CAST(SceneTree::StretchAspect); #endif diff --git a/scene/main/timer.cpp b/scene/main/timer.cpp index 721e9a56c..1010e76ba 100644 --- a/scene/main/timer.cpp +++ b/scene/main/timer.cpp @@ -28,21 +28,19 @@ /*************************************************************************/ #include "timer.h" - void Timer::_notification(int p_what) { - switch(p_what) { - + switch (p_what) { case NOTIFICATION_READY: { 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 (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(); - autostart=false; + autostart = false; } } break; case NOTIFICATION_PROCESS: { @@ -50,7 +48,7 @@ void Timer::_notification(int p_what) { return; time_left -= get_process_delta_time(); - if (time_left<0) { + if (time_left < 0) { if (!one_shot) //time_left=wait_time+time_left; time_left = wait_time; @@ -66,7 +64,7 @@ void Timer::_notification(int p_what) { return; time_left -= get_fixed_process_delta_time(); - if (time_left<0) { + if (time_left < 0) { if (!one_shot) //time_left = wait_time + time_left; time_left = wait_time; @@ -79,13 +77,10 @@ void Timer::_notification(int p_what) { } } - - void Timer::set_wait_time(float p_time) { ERR_EXPLAIN("time should be greater than zero."); - ERR_FAIL_COND(p_time<=0); - wait_time=p_time; - + ERR_FAIL_COND(p_time <= 0); + wait_time = p_time; } float Timer::get_wait_time() const { @@ -94,7 +89,7 @@ float Timer::get_wait_time() const { void Timer::set_one_shot(bool p_one_shot) { - one_shot=p_one_shot; + one_shot = p_one_shot; } bool Timer::is_one_shot() const { @@ -103,7 +98,7 @@ bool Timer::is_one_shot() const { void Timer::set_autostart(bool p_start) { - autostart=p_start; + autostart = p_start; } bool Timer::has_autostart() const { @@ -111,24 +106,22 @@ bool Timer::has_autostart() const { } void Timer::start() { - time_left=wait_time; + time_left = wait_time; _set_process(true); } void Timer::stop() { - time_left=-1; + time_left = -1; _set_process(false); - autostart=false; + autostart = false; } - void Timer::set_active(bool p_active) { if (active == p_active) return; active = p_active; _set_process(processing); - } bool Timer::is_active() const { @@ -137,7 +130,7 @@ bool Timer::is_active() const { float Timer::get_time_left() const { - return time_left >0 ? time_left : 0; + return time_left > 0 ? time_left : 0; } void Timer::set_timer_process_mode(TimerProcessMode p_mode) { @@ -151,25 +144,23 @@ void Timer::set_timer_process_mode(TimerProcessMode p_mode) { set_fixed_process(false); set_process(true); } - break; + break; case TIMER_PROCESS_IDLE: if (is_processing()) { set_process(false); set_fixed_process(true); } - break; + break; } timer_process_mode = p_mode; } -Timer::TimerProcessMode Timer::get_timer_process_mode() const{ +Timer::TimerProcessMode Timer::get_timer_process_mode() const { return timer_process_mode; } - -void Timer::_set_process(bool p_process, bool p_force) -{ +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; @@ -179,43 +170,42 @@ void Timer::_set_process(bool p_process, bool p_force) void Timer::_bind_methods() { - ObjectTypeDB::bind_method(_MD("set_wait_time","time_sec"),&Timer::set_wait_time); - ObjectTypeDB::bind_method(_MD("get_wait_time"),&Timer::get_wait_time); + ObjectTypeDB::bind_method(_MD("set_wait_time", "time_sec"), &Timer::set_wait_time); + ObjectTypeDB::bind_method(_MD("get_wait_time"), &Timer::get_wait_time); - ObjectTypeDB::bind_method(_MD("set_one_shot","enable"),&Timer::set_one_shot); - ObjectTypeDB::bind_method(_MD("is_one_shot"),&Timer::is_one_shot); + ObjectTypeDB::bind_method(_MD("set_one_shot", "enable"), &Timer::set_one_shot); + ObjectTypeDB::bind_method(_MD("is_one_shot"), &Timer::is_one_shot); - ObjectTypeDB::bind_method(_MD("set_autostart","enable"),&Timer::set_autostart); - ObjectTypeDB::bind_method(_MD("has_autostart"),&Timer::has_autostart); + ObjectTypeDB::bind_method(_MD("set_autostart", "enable"), &Timer::set_autostart); + ObjectTypeDB::bind_method(_MD("has_autostart"), &Timer::has_autostart); - ObjectTypeDB::bind_method(_MD("start"),&Timer::start); - ObjectTypeDB::bind_method(_MD("stop"),&Timer::stop); + ObjectTypeDB::bind_method(_MD("start"), &Timer::start); + ObjectTypeDB::bind_method(_MD("stop"), &Timer::stop); ObjectTypeDB::bind_method(_MD("set_active", "active"), &Timer::set_active); ObjectTypeDB::bind_method(_MD("is_active"), &Timer::is_active); - ObjectTypeDB::bind_method(_MD("get_time_left"),&Timer::get_time_left); + ObjectTypeDB::bind_method(_MD("get_time_left"), &Timer::get_time_left); ObjectTypeDB::bind_method(_MD("set_timer_process_mode", "mode"), &Timer::set_timer_process_mode); ObjectTypeDB::bind_method(_MD("get_timer_process_mode"), &Timer::get_timer_process_mode); - ADD_SIGNAL( MethodInfo("timeout") ); - - ADD_PROPERTY( PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Fixed,Idle"), _SCS("set_timer_process_mode"), _SCS("get_timer_process_mode") ); - ADD_PROPERTY( PropertyInfo(Variant::REAL, "wait_time", PROPERTY_HINT_EXP_RANGE, "0.01,4096,0.01" ), _SCS("set_wait_time"), _SCS("get_wait_time") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL, "one_shot" ), _SCS("set_one_shot"), _SCS("is_one_shot") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL, "autostart" ), _SCS("set_autostart"), _SCS("has_autostart") ); + ADD_SIGNAL(MethodInfo("timeout")); - BIND_CONSTANT( TIMER_PROCESS_FIXED ); - BIND_CONSTANT( TIMER_PROCESS_IDLE ); + ADD_PROPERTY(PropertyInfo(Variant::INT, "process_mode", PROPERTY_HINT_ENUM, "Fixed,Idle"), _SCS("set_timer_process_mode"), _SCS("get_timer_process_mode")); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "wait_time", PROPERTY_HINT_EXP_RANGE, "0.01,4096,0.01"), _SCS("set_wait_time"), _SCS("get_wait_time")); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "one_shot"), _SCS("set_one_shot"), _SCS("is_one_shot")); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "autostart"), _SCS("set_autostart"), _SCS("has_autostart")); + BIND_CONSTANT(TIMER_PROCESS_FIXED); + BIND_CONSTANT(TIMER_PROCESS_IDLE); } Timer::Timer() { timer_process_mode = TIMER_PROCESS_IDLE; - autostart=false; - wait_time=1; - one_shot=false; + autostart = false; + wait_time = 1; + one_shot = false; time_left = -1; processing = false; active = true; diff --git a/scene/main/timer.h b/scene/main/timer.h index ea8d24b3a..024dbfd1c 100644 --- a/scene/main/timer.h +++ b/scene/main/timer.h @@ -33,7 +33,7 @@ class Timer : public Node { - OBJ_TYPE( Timer, Node ); + OBJ_TYPE(Timer, Node); float wait_time; bool one_shot; @@ -42,12 +42,12 @@ class Timer : public Node { bool active; double time_left; -protected: +protected: void _notification(int p_what); static void _bind_methods(); -public: +public: enum TimerProcessMode { TIMER_PROCESS_FIXED, TIMER_PROCESS_IDLE, @@ -76,7 +76,6 @@ public: private: TimerProcessMode timer_process_mode; void _set_process(bool p_process, bool p_force = false); - }; VARIANT_ENUM_CAST(Timer::TimerProcessMode); diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 0068ac57f..d37f95641 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -27,25 +27,25 @@ /* 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 "os/input.h" #include "servers/physics_2d_server.h" //#include "scene/3d/camera.h" -#include "servers/spatial_sound_server.h" -#include "servers/spatial_sound_2d_server.h" -#include "scene/gui/control.h" #include "scene/3d/camera.h" +#include "scene/3d/collision_object.h" #include "scene/3d/listener.h" -#include "scene/resources/mesh.h" #include "scene/3d/spatial_indexer.h" -#include "scene/3d/collision_object.h" +#include "scene/gui/control.h" +#include "scene/resources/mesh.h" +#include "servers/spatial_sound_2d_server.h" +#include "servers/spatial_sound_server.h" #include "scene/2d/collision_object_2d.h" -#include "scene/gui/panel.h" #include "scene/gui/label.h" +#include "scene/gui/panel.h" #include "scene/main/timer.h" #include "scene/scene_string_names.h" @@ -53,88 +53,82 @@ int RenderTargetTexture::get_width() const { - ERR_FAIL_COND_V(!vp,0); + ERR_FAIL_COND_V(!vp, 0); return vp->rect.size.width; } -int RenderTargetTexture::get_height() const{ +int RenderTargetTexture::get_height() const { - ERR_FAIL_COND_V(!vp,0); + ERR_FAIL_COND_V(!vp, 0); return vp->rect.size.height; } -Size2 RenderTargetTexture::get_size() const{ +Size2 RenderTargetTexture::get_size() const { - ERR_FAIL_COND_V(!vp,Size2()); + ERR_FAIL_COND_V(!vp, Size2()); return vp->rect.size; } -RID RenderTargetTexture::get_rid() const{ +RID RenderTargetTexture::get_rid() const { - ERR_FAIL_COND_V(!vp,RID()); + ERR_FAIL_COND_V(!vp, RID()); return vp->render_target_texture_rid; } -bool RenderTargetTexture::has_alpha() const{ +bool RenderTargetTexture::has_alpha() const { return false; } -void RenderTargetTexture::set_flags(uint32_t p_flags){ +void RenderTargetTexture::set_flags(uint32_t p_flags) { ERR_FAIL_COND(!vp); - if (p_flags&FLAG_FILTER) - flags=FLAG_FILTER; + if (p_flags & FLAG_FILTER) + flags = FLAG_FILTER; else - flags=0; - - VS::get_singleton()->texture_set_flags(vp->render_target_texture_rid,flags); + flags = 0; + VS::get_singleton()->texture_set_flags(vp->render_target_texture_rid, flags); } -uint32_t RenderTargetTexture::get_flags() const{ +uint32_t RenderTargetTexture::get_flags() const { return flags; } -RenderTargetTexture::RenderTargetTexture(Viewport *p_vp){ +RenderTargetTexture::RenderTargetTexture(Viewport *p_vp) { - vp=p_vp; - flags=0; + vp = p_vp; + flags = 0; } ///////////////////////////////////// class TooltipPanel : public Panel { - OBJ_TYPE(TooltipPanel,Panel) + OBJ_TYPE(TooltipPanel, Panel) public: - TooltipPanel() {}; - + TooltipPanel(){}; }; class TooltipLabel : public Label { - OBJ_TYPE(TooltipLabel,Label) + OBJ_TYPE(TooltipLabel, Label) public: - TooltipLabel() {}; - + TooltipLabel(){}; }; - Viewport::GUI::GUI() { + mouse_focus = NULL; + mouse_focus_button = -1; + key_focus = NULL; + mouse_over = NULL; - mouse_focus=NULL; - mouse_focus_button=-1; - key_focus=NULL; - mouse_over=NULL; - - cancelled_input_ID=0; - tooltip=NULL; - tooltip_popup=NULL; - tooltip_label=NULL; - subwindow_order_dirty=false; + cancelled_input_ID = 0; + tooltip = NULL; + tooltip_popup = NULL; + tooltip_label = NULL; + subwindow_order_dirty = false; } - ///////////////////////////////////// void Viewport::_update_stretch_transform() { @@ -142,20 +136,17 @@ void Viewport::_update_stretch_transform() { //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 = Matrix32(); + Size2 scale = rect.size / (size_override_size + size_override_margin * 2); stretch_transform.scale(scale); - stretch_transform.elements[2]=size_override_margin*scale; - + stretch_transform.elements[2] = size_override_margin * scale; } else { - - stretch_transform=Matrix32(); + stretch_transform = Matrix32(); } _update_global_transform(); - } void Viewport::_update_rect() { @@ -163,37 +154,34 @@ void Viewport::_update_rect() { if (!is_inside_tree()) return; - if (!render_target && parent_control) { Control *c = parent_control; - rect.pos=Point2(); - rect.size=c->get_size(); + rect.pos = Point2(); + rect.size = c->get_size(); } VisualServer::ViewportRect vr; - vr.x=rect.pos.x; - vr.y=rect.pos.y; + vr.x = rect.pos.x; + vr.y = rect.pos.y; if (render_target) { - vr.x=0; - vr.y=0; + vr.x = 0; + vr.y = 0; } - vr.width=rect.size.width; - vr.height=rect.size.height; + vr.width = rect.size.width; + vr.height = rect.size.height; - VisualServer::get_singleton()->viewport_set_rect(viewport,vr); - last_vp_rect=rect; + 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); + VisualServer::get_singleton()->canvas_item_set_custom_rect(canvas_item, true, rect); } emit_signal("size_changed"); render_target_texture->emit_changed(); - - } void Viewport::_parent_resized() { @@ -202,92 +190,79 @@ void Viewport::_parent_resized() { } void Viewport::_parent_draw() { - } void Viewport::_parent_visibility_changed() { - if (parent_control) { Control *c = parent_control; - VisualServer::get_singleton()->canvas_item_set_visible(canvas_item,c->is_visible()); + VisualServer::get_singleton()->canvas_item_set_visible(canvas_item, c->is_visible()); _update_listener(); _update_listener_2d(); } - - } - void Viewport::_vp_enter_tree() { if (parent_control) { - Control *cparent=parent_control; + Control *cparent = parent_control; RID parent_ci = cparent->get_canvas_item(); ERR_FAIL_COND(!parent_ci.is_valid()); canvas_item = VisualServer::get_singleton()->canvas_item_create(); - VisualServer::get_singleton()->canvas_item_set_parent(canvas_item,parent_ci); - VisualServer::get_singleton()->canvas_item_set_visible(canvas_item,false); - VisualServer::get_singleton()->canvas_item_attach_viewport(canvas_item,viewport); - parent_control->connect("resized",this,"_parent_resized"); - parent_control->connect("visibility_changed",this,"_parent_visibility_changed"); - } else if (!parent){ - - VisualServer::get_singleton()->viewport_attach_to_screen(viewport,0); + VisualServer::get_singleton()->canvas_item_set_parent(canvas_item, parent_ci); + VisualServer::get_singleton()->canvas_item_set_visible(canvas_item, false); + VisualServer::get_singleton()->canvas_item_attach_viewport(canvas_item, viewport); + parent_control->connect("resized", this, "_parent_resized"); + parent_control->connect("visibility_changed", this, "_parent_visibility_changed"); + } else if (!parent) { + VisualServer::get_singleton()->viewport_attach_to_screen(viewport, 0); } - - } void Viewport::_vp_exit_tree() { if (parent_control) { - parent_control->disconnect("resized",this,"_parent_resized"); + parent_control->disconnect("resized", this, "_parent_resized"); } if (parent_control) { - parent_control->disconnect("visibility_changed",this,"_parent_visibility_changed"); + parent_control->disconnect("visibility_changed", this, "_parent_visibility_changed"); } if (canvas_item.is_valid()) { VisualServer::get_singleton()->free(canvas_item); - canvas_item=RID(); - + canvas_item = RID(); } if (!parent) { VisualServer::get_singleton()->viewport_detach(viewport); - } - } - void Viewport::update_worlds() { 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_viewport(this, xformed_rect); find_world_2d()->_update(); 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 (new_collider != physics_object_over) { if (physics_object_over) { Object *obj = ObjectDB::get_instance(physics_object_over); @@ -305,90 +280,80 @@ void Viewport::_test_new_mouseover(ObjectID new_collider) { CollisionObject *co = obj->cast_to<CollisionObject>(); if (co) { co->_mouse_enter(); - } } - } - physics_object_over=new_collider; - + physics_object_over = new_collider; } #endif - } void Viewport::_notification(int p_what) { - - switch( p_what ) { + switch (p_what) { case NOTIFICATION_ENTER_TREE: { if (get_parent()) { - Node *parent=get_parent(); + Node *parent = get_parent(); if (parent) { - parent_control=parent->cast_to<Control>(); + parent_control = parent->cast_to<Control>(); } } + parent = NULL; + Node *parent_node = get_parent(); - parent=NULL; - Node *parent_node=get_parent(); - - - while(parent_node) { + while (parent_node) { parent = parent_node->cast_to<Viewport>(); if (parent) break; - parent_node=parent_node->get_parent(); + parent_node = parent_node->get_parent(); } - if (!render_target) _vp_enter_tree(); - - current_canvas=find_world_2d()->get_canvas(); - VisualServer::get_singleton()->viewport_set_scenario(viewport,find_world()->get_scenario()); - VisualServer::get_singleton()->viewport_attach_canvas(viewport,current_canvas); + current_canvas = find_world_2d()->get_canvas(); + VisualServer::get_singleton()->viewport_set_scenario(viewport, find_world()->get_scenario()); + VisualServer::get_singleton()->viewport_attach_canvas(viewport, current_canvas); _update_listener(); _update_listener_2d(); _update_rect(); - find_world_2d()->_register_viewport(this,Rect2()); + find_world_2d()->_register_viewport(this, Rect2()); add_to_group("_viewports"); if (get_tree()->is_debugging_collisions_hint()) { //2D - Physics2DServer::get_singleton()->space_set_debug_contacts(find_world_2d()->get_space(),get_tree()->get_collision_debug_contact_count()); - contact_2d_debug=VisualServer::get_singleton()->canvas_item_create(); - VisualServer::get_singleton()->canvas_item_set_parent(contact_2d_debug,find_world_2d()->get_canvas()); + Physics2DServer::get_singleton()->space_set_debug_contacts(find_world_2d()->get_space(), get_tree()->get_collision_debug_contact_count()); + contact_2d_debug = VisualServer::get_singleton()->canvas_item_create(); + VisualServer::get_singleton()->canvas_item_set_parent(contact_2d_debug, find_world_2d()->get_canvas()); //3D - PhysicsServer::get_singleton()->space_set_debug_contacts(find_world()->get_space(),get_tree()->get_collision_debug_contact_count()); - contact_3d_debug_multimesh=VisualServer::get_singleton()->multimesh_create(); - VisualServer::get_singleton()->multimesh_set_instance_count(contact_3d_debug_multimesh,get_tree()->get_collision_debug_contact_count()); - VisualServer::get_singleton()->multimesh_set_visible_instances(contact_3d_debug_multimesh,0); - VisualServer::get_singleton()->multimesh_set_mesh(contact_3d_debug_multimesh,get_tree()->get_debug_contact_mesh()->get_rid()); - 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); - + PhysicsServer::get_singleton()->space_set_debug_contacts(find_world()->get_space(), get_tree()->get_collision_debug_contact_count()); + contact_3d_debug_multimesh = VisualServer::get_singleton()->multimesh_create(); + VisualServer::get_singleton()->multimesh_set_instance_count(contact_3d_debug_multimesh, get_tree()->get_collision_debug_contact_count()); + VisualServer::get_singleton()->multimesh_set_visible_instances(contact_3d_debug_multimesh, 0); + VisualServer::get_singleton()->multimesh_set_mesh(contact_3d_debug_multimesh, get_tree()->get_debug_contact_mesh()->get_rid()); + 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); } } break; case NOTIFICATION_READY: { #ifndef _3D_DISABLED if (listeners.size() && !listener) { - Listener *first=NULL; - for(Set<Listener*>::Element *E=listeners.front();E;E=E->next()) { + Listener *first = NULL; + for (Set<Listener *>::Element *E = listeners.front(); E; E = E->next()) { - if (first==NULL || first->is_greater_than(E->get())) { - first=E->get(); + if (first == NULL || first->is_greater_than(E->get())) { + first = E->get(); } } @@ -398,11 +363,11 @@ void Viewport::_notification(int p_what) { if (cameras.size() && !camera) { //there are cameras but no current camera, pick first in tree and make it current - Camera *first=NULL; - for(Set<Camera*>::Element *E=cameras.front();E;E=E->next()) { + Camera *first = NULL; + for (Set<Camera *>::Element *E = cameras.front(); E; E = E->next()) { - if (first==NULL || first->is_greater_than(E->get())) { - first=E->get(); + if (first == NULL || first->is_greater_than(E->get())) { + first = E->get(); } } @@ -413,7 +378,6 @@ void Viewport::_notification(int p_what) { } break; case NOTIFICATION_EXIT_TREE: { - _gui_cancel_tooltip(); if (world_2d.is_valid()) world_2d->_remove_viewport(this); @@ -421,30 +385,30 @@ void Viewport::_notification(int p_what) { if (!render_target) _vp_exit_tree(); - VisualServer::get_singleton()->viewport_set_scenario(viewport,RID()); + VisualServer::get_singleton()->viewport_set_scenario(viewport, RID()); SpatialSoundServer::get_singleton()->listener_set_space(internal_listener, RID()); - VisualServer::get_singleton()->viewport_remove_canvas(viewport,current_canvas); + VisualServer::get_singleton()->viewport_remove_canvas(viewport, current_canvas); if (contact_2d_debug.is_valid()) { VisualServer::get_singleton()->free(contact_2d_debug); - contact_2d_debug=RID(); + contact_2d_debug = RID(); } if (contact_3d_debug_multimesh.is_valid()) { VisualServer::get_singleton()->free(contact_3d_debug_multimesh); VisualServer::get_singleton()->free(contact_3d_debug_instance); - contact_3d_debug_instance=RID(); - contact_3d_debug_multimesh=RID(); + contact_3d_debug_instance = RID(); + contact_3d_debug_multimesh = RID(); } remove_from_group("_viewports"); - parent_control=NULL; + parent_control = NULL; } break; case NOTIFICATION_FIXED_PROCESS: { - if (gui.tooltip_timer>=0) { - gui.tooltip_timer-=get_fixed_process_delta_time(); - if (gui.tooltip_timer<0) { + if (gui.tooltip_timer >= 0) { + gui.tooltip_timer -= get_fixed_process_delta_time(); + if (gui.tooltip_timer < 0) { _gui_show_tooltip(); } } @@ -458,117 +422,110 @@ void Viewport::_notification(int p_what) { int point_count = Physics2DServer::get_singleton()->space_get_contact_count(find_world_2d()->get_space()); Color ccol = get_tree()->get_debug_collision_contact_color(); + for (int i = 0; i < point_count; i++) { - for(int i=0;i<point_count;i++) { - - VisualServer::get_singleton()->canvas_item_add_rect(contact_2d_debug,Rect2(points[i]-Vector2(2,2),Vector2(5,5)),ccol); + VisualServer::get_singleton()->canvas_item_add_rect(contact_2d_debug, Rect2(points[i] - Vector2(2, 2), Vector2(5, 5)), ccol); } } if (get_tree()->is_debugging_collisions_hint() && contact_3d_debug_multimesh.is_valid()) { - Vector<Vector3> points = PhysicsServer::get_singleton()->space_get_contacts(find_world()->get_space()); int point_count = PhysicsServer::get_singleton()->space_get_contact_count(find_world()->get_space()); + VS::get_singleton()->multimesh_set_visible_instances(contact_3d_debug_multimesh, point_count); - VS::get_singleton()->multimesh_set_visible_instances(contact_3d_debug_multimesh,point_count); - - if (point_count>0) { + if (point_count > 0) { AABB aabb; Transform t; - for(int i=0;i<point_count;i++) { + for (int i = 0; i < point_count; i++) { - if (i==0) - aabb.pos=points[i]; + if (i == 0) + aabb.pos = points[i]; else aabb.expand_to(points[i]); - t.origin=points[i]; - VisualServer::get_singleton()->multimesh_instance_set_transform(contact_3d_debug_multimesh,i,t); + t.origin = points[i]; + VisualServer::get_singleton()->multimesh_instance_set_transform(contact_3d_debug_multimesh, i, t); } - aabb.grow(aabb.get_longest_axis_size()*0.01); - VisualServer::get_singleton()->multimesh_set_aabb(contact_3d_debug_multimesh,aabb); + aabb.grow(aabb.get_longest_axis_size() * 0.01); + VisualServer::get_singleton()->multimesh_set_aabb(contact_3d_debug_multimesh, aabb); } } + if (physics_object_picking && (render_target || Input::get_singleton()->get_mouse_mode() != Input::MOUSE_MODE_CAPTURED)) { - - if (physics_object_picking && (render_target || Input::get_singleton()->get_mouse_mode()!=Input::MOUSE_MODE_CAPTURED)) { - - Vector2 last_pos(1e20,1e20); + Vector2 last_pos(1e20, 1e20); CollisionObject *last_object; - ObjectID last_id=0; + ObjectID last_id = 0; PhysicsDirectSpaceState::RayResult result; - Physics2DDirectSpaceState *ss2d=Physics2DServer::get_singleton()->space_get_direct_state(find_world_2d()->get_space()); + Physics2DDirectSpaceState *ss2d = Physics2DServer::get_singleton()->space_get_direct_state(find_world_2d()->get_space()); - bool motion_tested=false; + bool motion_tested = false; - while(physics_picking_events.size()) { + while (physics_picking_events.size()) { InputEvent ev = physics_picking_events.front()->get(); physics_picking_events.pop_front(); Vector2 pos; - switch(ev.type) { + switch (ev.type) { case InputEvent::MOUSE_MOTION: { - pos.x=ev.mouse_motion.x; - pos.y=ev.mouse_motion.y; - motion_tested=true; - physics_last_mousepos=pos; + pos.x = ev.mouse_motion.x; + pos.y = ev.mouse_motion.y; + motion_tested = true; + physics_last_mousepos = pos; } break; case InputEvent::MOUSE_BUTTON: { - pos.x=ev.mouse_button.x; - pos.y=ev.mouse_button.y; + pos.x = ev.mouse_button.x; + pos.y = ev.mouse_button.y; } break; case InputEvent::SCREEN_DRAG: { - pos.x=ev.screen_drag.x; - pos.y=ev.screen_drag.y; + pos.x = ev.screen_drag.x; + pos.y = ev.screen_drag.y; } break; case InputEvent::SCREEN_TOUCH: { - pos.x=ev.screen_touch.x; - pos.y=ev.screen_touch.y; + pos.x = ev.screen_touch.x; + pos.y = ev.screen_touch.y; } break; - } if (ss2d) { //send to 2D - uint64_t frame = get_tree()->get_frame(); Vector2 point = get_canvas_transform().affine_inverse().xform(pos); Physics2DDirectSpaceState::ShapeResult res[64]; - int rc = ss2d->intersect_point(point,res,64,Set<RID>(),0xFFFFFFFF,0xFFFFFFFF,true); - for(int i=0;i<rc;i++) { + int rc = ss2d->intersect_point(point, res, 64, Set<RID>(), 0xFFFFFFFF, 0xFFFFFFFF, true); + 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 = res[i].collider->cast_to<CollisionObject2D>(); if (co) { - Map<ObjectID,uint64_t>::Element *E=physics_2d_mouseover.find(res[i].collider_id); + Map<ObjectID, uint64_t>::Element *E = physics_2d_mouseover.find(res[i].collider_id); if (!E) { - E=physics_2d_mouseover.insert(res[i].collider_id,frame); + E = physics_2d_mouseover.insert(res[i].collider_id, frame); co->_mouse_enter(); } else { - E->get()=frame; + E->get() = frame; } - co->_input_event(this,ev,res[i].shape); + co->_input_event(this, ev, res[i].shape); } } } - List<Map<ObjectID,uint64_t>::Element*> to_erase; + List<Map<ObjectID, uint64_t>::Element *> to_erase; - for (Map<ObjectID,uint64_t>::Element*E=physics_2d_mouseover.front();E;E=E->next()) { - if (E->get()!=frame) { - Object *o=ObjectDB::get_instance(E->key()); + for (Map<ObjectID, uint64_t>::Element *E = physics_2d_mouseover.front(); E; E = E->next()) { + if (E->get() != frame) { + Object *o = ObjectDB::get_instance(E->key()); if (o) { - CollisionObject2D *co=o->cast_to<CollisionObject2D>(); + CollisionObject2D *co = o->cast_to<CollisionObject2D>(); if (co) { co->_mouse_exit(); } @@ -577,60 +534,50 @@ void Viewport::_notification(int p_what) { } } - while(to_erase.size()) { + while (to_erase.size()) { physics_2d_mouseover.erase(to_erase.front()->get()); to_erase.pop_front(); } - } - - #ifndef _3D_DISABLED - bool captured=false; - - if (physics_object_capture!=0) { + bool captured = false; + 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 (ev.type==InputEvent::MOUSE_BUTTON && ev.mouse_button.button_index==1 && !ev.mouse_button.pressed) { - physics_object_capture=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; } } else { - physics_object_capture=0; + physics_object_capture = 0; } } else { - physics_object_capture=0; + physics_object_capture = 0; } } - if (captured) { //none - } else if (pos==last_pos) { + } else if (pos == last_pos) { if (last_id) { if (ObjectDB::get_instance(last_id)) { //good, exists - 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; + 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; } - - } } } else { - - - if (camera) { Vector3 from = camera->project_ray_origin(pos); @@ -639,8 +586,8 @@ void Viewport::_notification(int p_what) { PhysicsDirectSpaceState *space = PhysicsServer::get_singleton()->space_get_direct_state(find_world()->get_space()); if (space) { - bool col = space->intersect_ray(from,from+dir*10000,result,Set<RID>(),0xFFFFFFFF,0xFFFFFFFF,true); - ObjectID new_collider=0; + bool col = space->intersect_ray(from, from + dir * 10000, result, Set<RID>(), 0xFFFFFFFF, 0xFFFFFFFF, true); + ObjectID new_collider = 0; if (col) { if (result.collider) { @@ -648,29 +595,28 @@ void Viewport::_notification(int p_what) { CollisionObject *co = result.collider->cast_to<CollisionObject>(); 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() && ev.type==InputEvent::MOUSE_BUTTON && ev.mouse_button.button_index==1 && ev.mouse_button.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() && ev.type == InputEvent::MOUSE_BUTTON && ev.mouse_button.button_index == 1 && ev.mouse_button.pressed) { + physics_object_capture = last_id; } - } } } - if (ev.type==InputEvent::MOUSE_MOTION) { + if (ev.type == InputEvent::MOUSE_MOTION) { _test_new_mouseover(new_collider); } } - last_pos=pos; + last_pos = pos; } } } - if (!motion_tested && camera && physics_last_mousepos!=Vector2(1e20,1e20)) { + if (!motion_tested && camera && physics_last_mousepos != Vector2(1e20, 1e20)) { //test anyway for mouseenter/exit because objects might move Vector3 from = camera->project_ray_origin(physics_last_mousepos); @@ -679,24 +625,21 @@ void Viewport::_notification(int p_what) { PhysicsDirectSpaceState *space = PhysicsServer::get_singleton()->space_get_direct_state(find_world()->get_space()); if (space) { - bool col = space->intersect_ray(from,from+dir*10000,result,Set<RID>(),0xFFFFFFFF,0xFFFFFFFF,true); - ObjectID new_collider=0; + 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; - + new_collider = result.collider_id; } } } _test_new_mouseover(new_collider); - } #endif } - } } break; @@ -708,35 +651,32 @@ RID Viewport::get_viewport() const { return viewport; } -void Viewport::set_rect(const Rect2& p_rect) { +void Viewport::set_rect(const Rect2 &p_rect) { - if (rect==p_rect) + if (rect == p_rect) return; - rect=p_rect; + rect = p_rect; _update_rect(); _update_stretch_transform(); - } Rect2 Viewport::get_visible_rect() const { - Rect2 r; - if (rect.pos==Vector2() && rect.size==Size2()) { + if (rect.pos == Vector2() && rect.size == Size2()) { - r=Rect2( Point2(), Size2( OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height ) ); + r = Rect2(Point2(), Size2(OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height)); } else { - r=Rect2( rect.pos , rect.size ); + r = Rect2(rect.pos, rect.size); } if (size_override) { - r.size=size_override_size; + r.size = size_override_size; } - return r; } @@ -745,16 +685,13 @@ Rect2 Viewport::get_rect() const { return rect; } - 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()))) { + if (is_inside_tree() && audio_listener && (camera || listener) && (!get_parent() || (get_parent()->cast_to<Control>() && get_parent()->cast_to<Control>()->is_visible()))) { SpatialSoundServer::get_singleton()->listener_set_space(internal_listener, find_world()->get_sound_space()); } else { SpatialSoundServer::get_singleton()->listener_set_space(internal_listener, RID()); } - - } void Viewport::_update_listener_2d() { @@ -763,93 +700,79 @@ void Viewport::_update_listener_2d() { 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()); - } - void Viewport::set_as_audio_listener(bool p_enable) { - if (p_enable==audio_listener) + if (p_enable == audio_listener) return; - audio_listener=p_enable; + audio_listener = p_enable; _update_listener(); - } bool Viewport::is_audio_listener() const { - return audio_listener; + return audio_listener; } void Viewport::set_as_audio_listener_2d(bool p_enable) { - if (p_enable==audio_listener_2d) + if (p_enable == audio_listener_2d) return; - audio_listener_2d=p_enable; + audio_listener_2d = p_enable; _update_listener_2d(); - - } bool Viewport::is_audio_listener_2d() const { - return audio_listener_2d; + return audio_listener_2d; } -void Viewport::set_canvas_transform(const Matrix32& p_transform) { +void Viewport::set_canvas_transform(const Matrix32 &p_transform) { - canvas_transform=p_transform; - VisualServer::get_singleton()->viewport_set_canvas_transform(viewport,find_world_2d()->get_canvas(),canvas_transform); + canvas_transform = p_transform; + VisualServer::get_singleton()->viewport_set_canvas_transform(viewport, find_world_2d()->get_canvas(), canvas_transform); Matrix32 xform = (global_canvas_transform * canvas_transform).affine_inverse(); Size2 ss = get_visible_rect().size; - SpatialSound2DServer::get_singleton()->listener_set_transform(internal_listener_2d, Matrix32(0, xform.xform(ss*0.5))); - Vector2 ss2 = ss*xform.get_scale(); - float panrange = MAX(ss2.x,ss2.y); + SpatialSound2DServer::get_singleton()->listener_set_transform(internal_listener_2d, Matrix32(0, xform.xform(ss * 0.5))); + Vector2 ss2 = ss * xform.get_scale(); + float panrange = MAX(ss2.x, ss2.y); SpatialSound2DServer::get_singleton()->listener_set_param(internal_listener_2d, SpatialSound2DServer::LISTENER_PARAM_PAN_RANGE, panrange); - - } -Matrix32 Viewport::get_canvas_transform() const{ +Matrix32 Viewport::get_canvas_transform() const { return canvas_transform; } - - void Viewport::_update_global_transform() { - Matrix32 sxform = stretch_transform * global_canvas_transform; - VisualServer::get_singleton()->viewport_set_global_canvas_transform(viewport,sxform); + VisualServer::get_singleton()->viewport_set_global_canvas_transform(viewport, sxform); Matrix32 xform = (sxform * canvas_transform).affine_inverse(); Size2 ss = get_visible_rect().size; - SpatialSound2DServer::get_singleton()->listener_set_transform(internal_listener_2d, Matrix32(0, xform.xform(ss*0.5))); - Vector2 ss2 = ss*xform.get_scale(); - float panrange = MAX(ss2.x,ss2.y); + SpatialSound2DServer::get_singleton()->listener_set_transform(internal_listener_2d, Matrix32(0, xform.xform(ss * 0.5))); + Vector2 ss2 = ss * xform.get_scale(); + float panrange = MAX(ss2.x, ss2.y); SpatialSound2DServer::get_singleton()->listener_set_param(internal_listener_2d, SpatialSound2DServer::LISTENER_PARAM_PAN_RANGE, panrange); - } +void Viewport::set_global_canvas_transform(const Matrix32 &p_transform) { -void Viewport::set_global_canvas_transform(const Matrix32& p_transform) { - - global_canvas_transform=p_transform; + global_canvas_transform = p_transform; _update_global_transform(); - - } -Matrix32 Viewport::get_global_canvas_transform() const{ +Matrix32 Viewport::get_global_canvas_transform() const { return global_canvas_transform; } @@ -862,7 +785,7 @@ void Viewport::_listener_transform_changed_notify() { #endif } -void Viewport::_listener_set(Listener* p_listener) { +void Viewport::_listener_set(Listener *p_listener) { #ifndef _3D_DISABLED @@ -876,13 +799,13 @@ void Viewport::_listener_set(Listener* p_listener) { #endif } -bool Viewport::_listener_add(Listener* p_listener) { +bool Viewport::_listener_add(Listener *p_listener) { listeners.insert(p_listener); return listeners.size() == 1; } -void Viewport::_listener_remove(Listener* p_listener) { +void Viewport::_listener_remove(Listener *p_listener) { listeners.erase(p_listener); if (listener == p_listener) { @@ -891,10 +814,10 @@ void Viewport::_listener_remove(Listener* p_listener) { } #ifndef _3D_DISABLED -void Viewport::_listener_make_next_current(Listener* p_exclude) { +void Viewport::_listener_make_next_current(Listener *p_exclude) { if (listeners.size() > 0) { - for (Set<Listener*>::Element *E = listeners.front(); E; E = E->next()) { + for (Set<Listener *>::Element *E = listeners.front(); E; E = E->next()) { if (p_exclude == E->get()) continue; @@ -904,10 +827,8 @@ void Viewport::_listener_make_next_current(Listener* p_exclude) { return; E->get()->make_current(); - } - } - else { + } else { // Attempt to reset listener to the camera position if (camera != NULL) { _update_listener(); @@ -926,21 +847,21 @@ void Viewport::_camera_transform_changed_notify() { #endif } -void Viewport::_camera_set(Camera* p_camera) { +void Viewport::_camera_set(Camera *p_camera) { #ifndef _3D_DISABLED - if (camera==p_camera) + if (camera == p_camera) return; if (camera && find_world().is_valid()) { camera->notification(Camera::NOTIFICATION_LOST_CURRENT); } - camera=p_camera; + camera = p_camera; if (camera) - VisualServer::get_singleton()->viewport_attach_camera(viewport,camera->get_camera()); + VisualServer::get_singleton()->viewport_attach_camera(viewport, camera->get_camera()); else - VisualServer::get_singleton()->viewport_attach_camera(viewport,RID()); + VisualServer::get_singleton()->viewport_attach_camera(viewport, RID()); if (camera && find_world().is_valid()) { camera->notification(Camera::NOTIFICATION_BECAME_CURRENT); @@ -951,43 +872,41 @@ void Viewport::_camera_set(Camera* p_camera) { #endif } -bool Viewport::_camera_add(Camera* p_camera) { +bool Viewport::_camera_add(Camera *p_camera) { cameras.insert(p_camera); - return cameras.size()==1; + return cameras.size() == 1; } -void Viewport::_camera_remove(Camera* p_camera) { +void Viewport::_camera_remove(Camera *p_camera) { cameras.erase(p_camera); - if (camera==p_camera) { - camera=NULL; + if (camera == p_camera) { + camera = NULL; } } #ifndef _3D_DISABLED -void Viewport::_camera_make_next_current(Camera* p_exclude) { +void Viewport::_camera_make_next_current(Camera *p_exclude) { - for(Set<Camera*>::Element *E=cameras.front();E;E=E->next()) { + for (Set<Camera *>::Element *E = cameras.front(); E; E = E->next()) { - if (p_exclude==E->get()) + if (p_exclude == E->get()) continue; if (!E->get()->is_inside_tree()) continue; - if (camera!=NULL) + if (camera != NULL) return; E->get()->make_current(); - } } #endif void Viewport::set_transparent_background(bool p_enable) { - transparent_bg=p_enable; - VS::get_singleton()->viewport_set_transparent_background(viewport,p_enable); - + transparent_bg = p_enable; + VS::get_singleton()->viewport_set_transparent_background(viewport, p_enable); } bool Viewport::has_transparent_background() const { @@ -995,37 +914,37 @@ bool Viewport::has_transparent_background() const { return transparent_bg; } -void Viewport::set_world_2d(const Ref<World2D>& p_world_2d) { - if (world_2d==p_world_2d) +void Viewport::set_world_2d(const Ref<World2D> &p_world_2d) { + if (world_2d == p_world_2d) return; - if (parent && parent->find_world_2d()==p_world_2d) { + if (parent && parent->find_world_2d() == p_world_2d) { WARN_PRINT("Unable to use parent world as world_2d"); return; } if (is_inside_tree()) { find_world_2d()->_remove_viewport(this); - VisualServer::get_singleton()->viewport_remove_canvas(viewport,current_canvas); + VisualServer::get_singleton()->viewport_remove_canvas(viewport, current_canvas); } if (p_world_2d.is_valid()) - world_2d=p_world_2d; + world_2d = p_world_2d; else { WARN_PRINT("Invalid world"); - world_2d=Ref<World2D>( memnew( World2D )); + world_2d = Ref<World2D>(memnew(World2D)); } _update_listener_2d(); if (is_inside_tree()) { - current_canvas=find_world_2d()->get_canvas(); - VisualServer::get_singleton()->viewport_attach_canvas(viewport,current_canvas); - find_world_2d()->_register_viewport(this,Rect2()); + current_canvas = find_world_2d()->get_canvas(); + VisualServer::get_singleton()->viewport_attach_canvas(viewport, current_canvas); + find_world_2d()->_register_viewport(this, Rect2()); } } -Ref<World2D> Viewport::find_world_2d() const{ +Ref<World2D> Viewport::find_world_2d() const { if (world_2d.is_valid()) return world_2d; @@ -1037,8 +956,7 @@ Ref<World2D> Viewport::find_world_2d() const{ void Viewport::_propagate_enter_world(Node *p_node) { - - if (p_node!=this) { + if (p_node != this) { if (!p_node->is_inside_tree()) //may not have entered scene yet return; @@ -1057,27 +975,26 @@ void Viewport::_propagate_enter_world(Node *p_node) { } } - - for(int i=0;i<p_node->get_child_count();i++) { + for (int i = 0; i < p_node->get_child_count(); i++) { _propagate_enter_world(p_node->get_child(i)); } } -void Viewport::_propagate_viewport_notification(Node* p_node,int p_what) { +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++) { + for (int i = 0; i < p_node->get_child_count(); i++) { Node *c = p_node->get_child(i); if (c->cast_to<Viewport>()) continue; - _propagate_viewport_notification(c,p_what); + _propagate_viewport_notification(c, p_what); } } void Viewport::_propagate_exit_world(Node *p_node) { - if (p_node!=this) { + if (p_node != this) { if (!p_node->is_inside_tree()) //may have exited scene already return; @@ -1096,18 +1013,15 @@ void Viewport::_propagate_exit_world(Node *p_node) { } } - - for(int i=0;i<p_node->get_child_count();i++) { + for (int i = 0; i < p_node->get_child_count(); i++) { _propagate_exit_world(p_node->get_child(i)); } - } +void Viewport::set_world(const Ref<World> &p_world) { -void Viewport::set_world(const Ref<World>& p_world) { - - if (world==p_world) + if (world == p_world) return; if (is_inside_tree()) @@ -1118,7 +1032,7 @@ void Viewport::set_world(const Ref<World>& p_world) { camera->notification(Camera::NOTIFICATION_LOST_CURRENT); #endif - world=p_world; + world = p_world; if (is_inside_tree()) _propagate_enter_world(this); @@ -1131,24 +1045,23 @@ void Viewport::set_world(const Ref<World>& p_world) { //propagate exit if (is_inside_tree()) { - VisualServer::get_singleton()->viewport_set_scenario(viewport,find_world()->get_scenario()); + VisualServer::get_singleton()->viewport_set_scenario(viewport, find_world()->get_scenario()); } _update_listener(); - } -Ref<World> Viewport::get_world() const{ +Ref<World> Viewport::get_world() const { return world; } -Ref<World2D> Viewport::get_world_2d() const{ +Ref<World2D> Viewport::get_world_2d() const { return world_2d; } -Ref<World> Viewport::find_world() const{ +Ref<World> Viewport::find_world() const { if (own_world.is_valid()) return own_world; @@ -1160,36 +1073,33 @@ Ref<World> Viewport::find_world() const{ return Ref<World>(); } -Listener* Viewport::get_listener() const { +Listener *Viewport::get_listener() const { return listener; } -Camera* Viewport::get_camera() const { +Camera *Viewport::get_camera() const { return camera; } - Matrix32 Viewport::get_final_transform() const { return stretch_transform * global_canvas_transform; } -void Viewport::set_size_override(bool p_enable, const Size2& p_size, const Vector2 &p_margin) { +void Viewport::set_size_override(bool p_enable, const Size2 &p_size, const Vector2 &p_margin) { - if (size_override==p_enable && p_size==size_override_size) + if (size_override == p_enable && p_size == size_override_size) return; - size_override=p_enable; - if (p_size.x>=0 || p_size.y>=0) { - size_override_size=p_size; + size_override = p_enable; + if (p_size.x >= 0 || p_size.y >= 0) { + size_override_size = p_size; } - size_override_margin=p_margin; + size_override_margin = p_margin; _update_rect(); _update_stretch_transform(); - - } Size2 Viewport::get_size_override() const { @@ -1202,32 +1112,30 @@ bool Viewport::is_size_override_enabled() const { } void Viewport::set_size_override_stretch(bool p_enable) { - if (p_enable==size_override_stretch) + if (p_enable == size_override_stretch) return; - size_override_stretch=p_enable; + size_override_stretch = p_enable; if (size_override) { _update_rect(); } - _update_stretch_transform(); } - bool Viewport::is_size_override_stretch_enabled() const { return size_override_stretch; } -void Viewport::set_as_render_target(bool p_enable){ +void Viewport::set_as_render_target(bool p_enable) { - if (render_target==p_enable) + if (render_target == p_enable) return; - render_target=p_enable; + render_target = p_enable; - VS::get_singleton()->viewport_set_as_render_target(viewport,p_enable); + VS::get_singleton()->viewport_set_as_render_target(viewport, p_enable); if (is_inside_tree()) { if (p_enable) @@ -1241,7 +1149,7 @@ void Viewport::set_as_render_target(bool p_enable){ render_target_texture_rid = VS::get_singleton()->viewport_get_render_target_texture(viewport); } else { - render_target_texture_rid=RID(); + render_target_texture_rid = RID(); } render_target_texture->set_flags(render_target_texture->flags); @@ -1250,23 +1158,22 @@ void Viewport::set_as_render_target(bool p_enable){ update_configuration_warning(); } -bool Viewport::is_set_as_render_target() const{ +bool Viewport::is_set_as_render_target() const { return render_target; } -void Viewport::set_render_target_update_mode(RenderTargetUpdateMode p_mode){ - - render_target_update_mode=p_mode; - VS::get_singleton()->viewport_set_render_target_update_mode(viewport,VS::RenderTargetUpdateMode(p_mode)); +void Viewport::set_render_target_update_mode(RenderTargetUpdateMode p_mode) { + render_target_update_mode = p_mode; + VS::get_singleton()->viewport_set_render_target_update_mode(viewport, VS::RenderTargetUpdateMode(p_mode)); } -Viewport::RenderTargetUpdateMode Viewport::get_render_target_update_mode() const{ +Viewport::RenderTargetUpdateMode Viewport::get_render_target_update_mode() const { return render_target_update_mode; } //RID get_render_target_texture() const; -void Viewport::queue_screen_capture(){ +void Viewport::queue_screen_capture() { VS::get_singleton()->viewport_queue_screen_capture(viewport); } @@ -1282,22 +1189,22 @@ Ref<RenderTargetTexture> Viewport::get_render_target_texture() const { void Viewport::set_render_target_vflip(bool p_enable) { - render_target_vflip=p_enable; - VisualServer::get_singleton()->viewport_set_render_target_vflip(viewport,p_enable); + render_target_vflip = p_enable; + VisualServer::get_singleton()->viewport_set_render_target_vflip(viewport, p_enable); } -bool Viewport::get_render_target_vflip() const{ +bool Viewport::get_render_target_vflip() const { return render_target_vflip; } void Viewport::set_render_target_clear_on_new_frame(bool p_enable) { - render_target_clear_on_new_frame=p_enable; - VisualServer::get_singleton()->viewport_set_render_target_clear_on_new_frame(viewport,p_enable); + render_target_clear_on_new_frame = p_enable; + VisualServer::get_singleton()->viewport_set_render_target_clear_on_new_frame(viewport, p_enable); } -bool Viewport::get_render_target_clear_on_new_frame() const{ +bool Viewport::get_render_target_clear_on_new_frame() const { return render_target_clear_on_new_frame; } @@ -1310,45 +1217,42 @@ void Viewport::render_target_clear() { void Viewport::set_render_target_filter(bool p_enable) { - if(!render_target) + if (!render_target) return; - render_target_texture->set_flags(p_enable?int(Texture::FLAG_FILTER):int(0)); - + render_target_texture->set_flags(p_enable ? int(Texture::FLAG_FILTER) : int(0)); } -bool Viewport::get_render_target_filter() const{ +bool Viewport::get_render_target_filter() const { - return (render_target_texture->get_flags()&Texture::FLAG_FILTER)!=0; + return (render_target_texture->get_flags() & Texture::FLAG_FILTER) != 0; } void Viewport::set_render_target_gen_mipmaps(bool p_enable) { //render_target_texture->set_flags(p_enable?int(Texture::FLAG_FILTER):int(0)); - render_target_gen_mipmaps=p_enable; - + render_target_gen_mipmaps = p_enable; } -bool Viewport::get_render_target_gen_mipmaps() const{ +bool Viewport::get_render_target_gen_mipmaps() const { //return (render_target_texture->get_flags()&Texture::FLAG_FILTER)!=0; return render_target_gen_mipmaps; } - Matrix32 Viewport::_get_input_pre_xform() const { Matrix32 pre_xf; if (render_target) { - if (to_screen_rect!=Rect2()) { + if (to_screen_rect != Rect2()) { - pre_xf.elements[2]=-to_screen_rect.pos; - pre_xf.scale(rect.size/to_screen_rect.size); + pre_xf.elements[2] = -to_screen_rect.pos; + pre_xf.scale(rect.size / to_screen_rect.size); } } else { - pre_xf.elements[2]=-rect.pos; + pre_xf.elements[2] = -rect.pos; } return pre_xf; @@ -1363,24 +1267,22 @@ Vector2 Viewport::_get_window_offset() const { return Vector2(); } -void Viewport::_make_input_local(InputEvent& ev) { - +void Viewport::_make_input_local(InputEvent &ev) { - switch(ev.type) { + switch (ev.type) { case InputEvent::MOUSE_BUTTON: { Vector2 vp_ofs = _get_window_offset(); Matrix32 ai = get_final_transform().affine_inverse() * _get_input_pre_xform(); - Vector2 g = ai.xform(Vector2(ev.mouse_button.global_x,ev.mouse_button.global_y)); - Vector2 l = ai.xform(Vector2(ev.mouse_button.x,ev.mouse_button.y)-vp_ofs); + Vector2 g = ai.xform(Vector2(ev.mouse_button.global_x, ev.mouse_button.global_y)); + Vector2 l = ai.xform(Vector2(ev.mouse_button.x, ev.mouse_button.y) - vp_ofs); - - ev.mouse_button.x=l.x; - ev.mouse_button.y=l.y; - ev.mouse_button.global_x=g.x; - ev.mouse_button.global_y=g.y; + ev.mouse_button.x = l.x; + ev.mouse_button.y = l.y; + ev.mouse_button.global_x = g.x; + ev.mouse_button.global_y = g.y; } break; case InputEvent::MOUSE_MOTION: { @@ -1388,20 +1290,19 @@ void Viewport::_make_input_local(InputEvent& ev) { Vector2 vp_ofs = _get_window_offset(); 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)-vp_ofs); - 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)); - + 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) - vp_ofs); + 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; + 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: { @@ -1409,11 +1310,10 @@ void Viewport::_make_input_local(InputEvent& ev) { Vector2 vp_ofs = _get_window_offset(); Matrix32 ai = get_final_transform().affine_inverse() * _get_input_pre_xform(); - Vector2 t = ai.xform(Vector2(ev.screen_touch.x,ev.screen_touch.y)-vp_ofs); - + Vector2 t = ai.xform(Vector2(ev.screen_touch.x, ev.screen_touch.y) - vp_ofs); - ev.screen_touch.x=t.x; - ev.screen_touch.y=t.y; + ev.screen_touch.x = t.x; + ev.screen_touch.y = t.y; } break; case InputEvent::SCREEN_DRAG: { @@ -1421,29 +1321,27 @@ void Viewport::_make_input_local(InputEvent& ev) { Vector2 vp_ofs = _get_window_offset(); Matrix32 ai = get_final_transform().affine_inverse() * _get_input_pre_xform(); - Vector2 t = ai.xform(Vector2(ev.screen_drag.x,ev.screen_drag.y)-vp_ofs); - 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; - ev.screen_drag.relative_y=r.y; - ev.screen_drag.speed_x=s.x; - ev.screen_drag.speed_y=s.y; + Vector2 t = ai.xform(Vector2(ev.screen_drag.x, ev.screen_drag.y) - vp_ofs); + 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; + ev.screen_drag.relative_y = r.y; + ev.screen_drag.speed_x = s.x; + ev.screen_drag.speed_y = s.y; } break; } - - } -void Viewport::_vp_input_text(const String& p_text) { +void Viewport::_vp_input_text(const String &p_text) { if (gui.key_focus) { - gui.key_focus->call("set_text",p_text); + gui.key_focus->call("set_text", p_text); } } -void Viewport::_vp_input(const InputEvent& p_ev) { +void Viewport::_vp_input(const InputEvent &p_ev) { if (disable_input) return; @@ -1457,20 +1355,18 @@ void Viewport::_vp_input(const InputEvent& p_ev) { if (parent_control && !parent_control->is_visible()) return; - if (render_target && to_screen_rect==Rect2()) + if (render_target && to_screen_rect == Rect2()) return; //if render target, can't get input events //this one handles system input, p_ev are in system coordinates //they are converted to viewport coordinates - InputEvent ev = p_ev; _make_input_local(ev); input(ev); - } -void Viewport::_vp_unhandled_input(const InputEvent& p_ev) { +void Viewport::_vp_unhandled_input(const InputEvent &p_ev) { if (disable_input) return; @@ -1483,7 +1379,7 @@ void Viewport::_vp_unhandled_input(const InputEvent& p_ev) { if (parent_control && !parent_control->is_visible()) return; - if (render_target && to_screen_rect==Rect2()) + if (render_target && to_screen_rect == Rect2()) return; //if render target, can't get input events //this one handles system input, p_ev are in system coordinates @@ -1492,7 +1388,6 @@ void Viewport::_vp_unhandled_input(const InputEvent& p_ev) { InputEvent ev = p_ev; _make_input_local(ev); unhandled_input(ev); - } Vector2 Viewport::get_mouse_pos() const { @@ -1500,24 +1395,21 @@ Vector2 Viewport::get_mouse_pos() const { return (get_final_transform().affine_inverse() * _get_input_pre_xform()).xform(Input::get_singleton()->get_mouse_pos() - _get_window_offset()); } -void Viewport::warp_mouse(const Vector2& p_pos) { +void Viewport::warp_mouse(const Vector2 &p_pos) { Vector2 gpos = (get_final_transform().affine_inverse() * _get_input_pre_xform()).affine_inverse().xform(p_pos); Input::get_singleton()->warp_mouse_pos(gpos); } - - void Viewport::_gui_sort_subwindows() { if (!gui.subwindow_order_dirty) return; - gui.modal_stack.sort_custom<Control::CComparator>(); gui.subwindows.sort_custom<Control::CComparator>(); - gui.subwindow_order_dirty=false; + gui.subwindow_order_dirty = false; } void Viewport::_gui_sort_modal_stack() { @@ -1525,7 +1417,6 @@ void Viewport::_gui_sort_modal_stack() { gui.modal_stack.sort_custom<Control::CComparator>(); } - void Viewport::_gui_sort_roots() { if (!gui.roots_order_dirty) @@ -1533,19 +1424,17 @@ void Viewport::_gui_sort_roots() { gui.roots.sort_custom<Control::CComparator>(); - gui.roots_order_dirty=false; + gui.roots_order_dirty = false; } - void Viewport::_gui_cancel_tooltip() { - gui.tooltip=NULL; - gui.tooltip_timer=-1; + gui.tooltip = NULL; + gui.tooltip_timer = -1; if (gui.tooltip_popup) { gui.tooltip_popup->queue_delete(); - gui.tooltip_popup=NULL; + gui.tooltip_popup = NULL; } - } void Viewport::_gui_show_tooltip() { @@ -1554,47 +1443,46 @@ void Viewport::_gui_show_tooltip() { return; } - String tooltip = gui.tooltip->get_tooltip( gui.tooltip->get_global_transform().xform_inv(gui.tooltip_pos) ); - if (tooltip.length()==0) + String tooltip = gui.tooltip->get_tooltip(gui.tooltip->get_global_transform().xform_inv(gui.tooltip_pos)); + if (tooltip.length() == 0) return; // bye if (gui.tooltip_popup) { memdelete(gui.tooltip_popup); - gui.tooltip_popup=NULL; + gui.tooltip_popup = NULL; } Control *rp = gui.tooltip->get_root_parent_control(); if (!rp) return; - - gui.tooltip_popup = memnew( TooltipPanel ); + gui.tooltip_popup = memnew(TooltipPanel); rp->add_child(gui.tooltip_popup); gui.tooltip_popup->force_parent_owned(); - gui.tooltip_label = memnew( TooltipLabel ); + gui.tooltip_label = memnew(TooltipLabel); gui.tooltip_popup->add_child(gui.tooltip_label); gui.tooltip_popup->set_as_toplevel(true); gui.tooltip_popup->hide(); - Ref<StyleBox> ttp = gui.tooltip_label->get_stylebox("panel","TooltipPanel"); + Ref<StyleBox> ttp = gui.tooltip_label->get_stylebox("panel", "TooltipPanel"); - gui.tooltip_label->set_anchor_and_margin(MARGIN_LEFT,Control::ANCHOR_BEGIN,ttp->get_margin(MARGIN_LEFT)); - gui.tooltip_label->set_anchor_and_margin(MARGIN_TOP,Control::ANCHOR_BEGIN,ttp->get_margin(MARGIN_TOP)); - gui.tooltip_label->set_anchor_and_margin(MARGIN_RIGHT,Control::ANCHOR_END,ttp->get_margin(MARGIN_RIGHT)); - gui.tooltip_label->set_anchor_and_margin(MARGIN_BOTTOM,Control::ANCHOR_END,ttp->get_margin(MARGIN_BOTTOM)); + gui.tooltip_label->set_anchor_and_margin(MARGIN_LEFT, Control::ANCHOR_BEGIN, ttp->get_margin(MARGIN_LEFT)); + gui.tooltip_label->set_anchor_and_margin(MARGIN_TOP, Control::ANCHOR_BEGIN, ttp->get_margin(MARGIN_TOP)); + gui.tooltip_label->set_anchor_and_margin(MARGIN_RIGHT, Control::ANCHOR_END, ttp->get_margin(MARGIN_RIGHT)); + gui.tooltip_label->set_anchor_and_margin(MARGIN_BOTTOM, Control::ANCHOR_END, ttp->get_margin(MARGIN_BOTTOM)); gui.tooltip_label->set_text(tooltip); - Rect2 r(gui.tooltip_pos+Point2(10,10),gui.tooltip_label->get_combined_minimum_size()+ttp->get_minimum_size()); + Rect2 r(gui.tooltip_pos + Point2(10, 10), gui.tooltip_label->get_combined_minimum_size() + ttp->get_minimum_size()); Rect2 vr = gui.tooltip_label->get_viewport_rect(); - if (r.size.x+r.pos.x>vr.size.x) - r.pos.x=vr.size.x-r.size.x; - else if (r.pos.x<0) - r.pos.x=0; + if (r.size.x + r.pos.x > vr.size.x) + r.pos.x = vr.size.x - r.size.x; + else if (r.pos.x < 0) + r.pos.x = 0; - if (r.size.y+r.pos.y>vr.size.y) - r.pos.y=vr.size.y-r.size.y; - else if (r.pos.y<0) - r.pos.y=0; + if (r.size.y + r.pos.y > vr.size.y) + r.pos.y = vr.size.y - r.size.y; + else if (r.pos.y < 0) + r.pos.y = 0; gui.tooltip_popup->set_global_pos(r.pos); gui.tooltip_popup->set_size(r.size); @@ -1603,56 +1491,53 @@ void Viewport::_gui_show_tooltip() { gui.tooltip_popup->show(); } +void Viewport::_gui_call_input(Control *p_control, const InputEvent &p_input) { -void Viewport::_gui_call_input(Control *p_control,const InputEvent& p_input) { - -// _block(); - + // _block(); InputEvent ev = p_input; //mouse wheel events can't be stopped - bool cant_stop_me_now = (ev.type==InputEvent::MOUSE_BUTTON && - (ev.mouse_button.button_index==BUTTON_WHEEL_DOWN || - ev.mouse_button.button_index==BUTTON_WHEEL_UP || - ev.mouse_button.button_index==BUTTON_WHEEL_LEFT || - ev.mouse_button.button_index==BUTTON_WHEEL_RIGHT ) ); + bool cant_stop_me_now = (ev.type == InputEvent::MOUSE_BUTTON && + (ev.mouse_button.button_index == BUTTON_WHEEL_DOWN || + ev.mouse_button.button_index == BUTTON_WHEEL_UP || + ev.mouse_button.button_index == BUTTON_WHEEL_LEFT || + ev.mouse_button.button_index == BUTTON_WHEEL_RIGHT)); - CanvasItem *ci=p_control; - while(ci) { + CanvasItem *ci = p_control; + while (ci) { Control *control = ci->cast_to<Control>(); if (control) { - control->call_multilevel(SceneStringNames::get_singleton()->_input_event,ev); + control->call_multilevel(SceneStringNames::get_singleton()->_input_event, ev); if (gui.key_event_accepted) break; if (!control->is_inside_tree()) break; - control->emit_signal(SceneStringNames::get_singleton()->input_event,ev); + control->emit_signal(SceneStringNames::get_singleton()->input_event, ev); if (!control->is_inside_tree() || control->is_set_as_toplevel()) break; if (gui.key_event_accepted) break; - if (!cant_stop_me_now && control->data.stop_mouse && (ev.type==InputEvent::MOUSE_BUTTON || ev.type==InputEvent::MOUSE_MOTION)) + if (!cant_stop_me_now && control->data.stop_mouse && (ev.type == InputEvent::MOUSE_BUTTON || ev.type == InputEvent::MOUSE_MOTION)) break; } if (ci->is_set_as_toplevel()) break; - ev=ev.xform_by(ci->get_transform()); //transform event upwards - ci=ci->get_parent_item(); + ev = ev.xform_by(ci->get_transform()); //transform event upwards + ci = ci->get_parent_item(); } //_unblock(); - } -Control* Viewport::_gui_find_control(const Point2& p_global) { +Control *Viewport::_gui_find_control(const Point2 &p_global) { _gui_sort_subwindows(); - for (List<Control*>::Element *E=gui.subwindows.back();E;E=E->prev()) { + for (List<Control *>::Element *E = gui.subwindows.back(); E; E = E->prev()) { Control *sw = E->get(); if (!sw->is_visible()) @@ -1661,18 +1546,18 @@ Control* Viewport::_gui_find_control(const Point2& p_global) { Matrix32 xform; CanvasItem *pci = sw->get_parent_item(); if (pci) - xform=pci->get_global_transform_with_canvas(); + xform = pci->get_global_transform_with_canvas(); else - xform=sw->get_canvas_transform(); + xform = sw->get_canvas_transform(); - Control *ret = _gui_find_control_at_pos(sw,p_global,xform,gui.focus_inv_xform); + Control *ret = _gui_find_control_at_pos(sw, p_global, xform, gui.focus_inv_xform); if (ret) return ret; } _gui_sort_roots(); - for (List<Control*>::Element *E=gui.roots.back();E;E=E->prev()) { + for (List<Control *>::Element *E = gui.roots.back(); E; E = E->prev()) { Control *sw = E->get(); if (!sw->is_visible()) @@ -1681,30 +1566,27 @@ Control* Viewport::_gui_find_control(const Point2& p_global) { Matrix32 xform; CanvasItem *pci = sw->get_parent_item(); if (pci) - xform=pci->get_global_transform_with_canvas(); + xform = pci->get_global_transform_with_canvas(); else - xform=sw->get_canvas_transform(); - + xform = sw->get_canvas_transform(); - Control *ret = _gui_find_control_at_pos(sw,p_global,xform,gui.focus_inv_xform); + Control *ret = _gui_find_control_at_pos(sw, p_global, xform, gui.focus_inv_xform); if (ret) return ret; } return NULL; - } - -Control* Viewport::_gui_find_control_at_pos(CanvasItem* p_node,const Point2& p_global,const Matrix32& p_xform,Matrix32& r_inv_xform) { +Control *Viewport::_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_global, const Matrix32 &p_xform, Matrix32 &r_inv_xform) { if (p_node->cast_to<Viewport>()) return NULL; - Control *c=p_node->cast_to<Control>(); + Control *c = p_node->cast_to<Control>(); if (c) { - // print_line("at "+String(c->get_path())+" POS "+c->get_pos()+" bt "+p_xform); + // print_line("at "+String(c->get_path())+" POS "+c->get_pos()+" bt "+p_xform); } //subwindows first!! @@ -1716,21 +1598,21 @@ Control* Viewport::_gui_find_control_at_pos(CanvasItem* p_node,const Point2& p_g Matrix32 matrix = p_xform * p_node->get_transform(); // matrix.basis_determinant() == 0.0f implies that node does not exist on scene - if(matrix.basis_determinant() == 0.0f) + if (matrix.basis_determinant() == 0.0f) return NULL; if (!c || !c->clips_input() || c->has_point(matrix.affine_inverse().xform(p_global))) { - for(int i=p_node->get_child_count()-1;i>=0;i--) { + for (int i = p_node->get_child_count() - 1; i >= 0; i--) { - if (p_node==gui.tooltip_popup) + if (p_node == gui.tooltip_popup) continue; CanvasItem *ci = p_node->get_child(i)->cast_to<CanvasItem>(); if (!ci || ci->is_set_as_toplevel()) continue; - Control *ret=_gui_find_control_at_pos(ci,p_global,matrix,r_inv_xform); + Control *ret = _gui_find_control_at_pos(ci, p_global, matrix, r_inv_xform); if (ret) return ret; } @@ -1742,8 +1624,8 @@ Control* Viewport::_gui_find_control_at_pos(CanvasItem* p_node,const Point2& p_g matrix.affine_invert(); //conditions for considering this as a valid control for return - if (!c->data.ignore_mouse && c->has_point(matrix.xform(p_global)) && (!gui.drag_preview || (c!=gui.drag_preview && !gui.drag_preview->is_a_parent_of(c)))) { - r_inv_xform=matrix; + if (!c->data.ignore_mouse && c->has_point(matrix.xform(p_global)) && (!gui.drag_preview || (c != gui.drag_preview && !gui.drag_preview->is_a_parent_of(c)))) { + r_inv_xform = matrix; return c; } else return NULL; @@ -1751,37 +1633,30 @@ Control* Viewport::_gui_find_control_at_pos(CanvasItem* p_node,const Point2& p_g void Viewport::_gui_input_event(InputEvent p_event) { - - - if (p_event.ID==gui.cancelled_input_ID) { + if (p_event.ID == gui.cancelled_input_ID) { return; } //? -// if (!is_visible()) { -// return; //simple and plain -// } - + // if (!is_visible()) { + // return; //simple and plain + // } - switch(p_event.type) { + switch (p_event.type) { case InputEvent::MOUSE_BUTTON: { + gui.key_event_accepted = false; - gui.key_event_accepted=false; - - Point2 mpos=Point2(p_event.mouse_button.x,p_event.mouse_button.y); + Point2 mpos = Point2(p_event.mouse_button.x, p_event.mouse_button.y); if (p_event.mouse_button.pressed) { - - Size2 pos = mpos; - if (gui.mouse_focus && p_event.mouse_button.button_index!=gui.mouse_focus_button) { + if (gui.mouse_focus && p_event.mouse_button.button_index != gui.mouse_focus_button) { //do not steal mouse focus and stuff } else { - _gui_sort_modal_stack(); while (!gui.modal_stack.empty()) { @@ -1789,7 +1664,7 @@ void Viewport::_gui_input_event(InputEvent p_event) { Vector2 pos = top->get_global_transform_with_canvas().affine_inverse().xform(mpos); if (!top->has_point(pos)) { - if (top->data.modal_exclusive || top->data.modal_frame==OS::get_singleton()->get_frames_drawn()) { + if (top->data.modal_exclusive || top->data.modal_frame == OS::get_singleton()->get_frames_drawn()) { //cancel event, sorry, modal exclusive EATS UP ALL //alternative, you can't pop out a window the same frame it was made modal (fixes many issues) get_tree()->set_input_as_handled(); @@ -1804,32 +1679,25 @@ void Viewport::_gui_input_event(InputEvent p_event) { } } - - //Matrix32 parent_xform; //if (data.parent_canvas_item) // parent_xform=data.parent_canvas_item->get_global_transform(); - - gui.mouse_focus = _gui_find_control(pos); //print_line("has mf "+itos(gui.mouse_focus!=NULL)); - gui.mouse_focus_button=p_event.mouse_button.button_index; + gui.mouse_focus_button = p_event.mouse_button.button_index; if (!gui.mouse_focus) { break; } - if (p_event.mouse_button.button_index==BUTTON_LEFT) { - gui.drag_accum=Vector2(); - gui.drag_attempted=false; + if (p_event.mouse_button.button_index == BUTTON_LEFT) { + gui.drag_accum = Vector2(); + gui.drag_attempted = false; } - - } - p_event.mouse_button.global_x = pos.x; p_event.mouse_button.global_y = pos.y; @@ -1843,72 +1711,66 @@ void Viewport::_gui_input_event(InputEvent p_event) { Array arr; arr.push_back(gui.mouse_focus->get_path()); arr.push_back(gui.mouse_focus->get_type()); - ScriptDebugger::get_singleton()->send_message("click_ctrl",arr); + ScriptDebugger::get_singleton()->send_message("click_ctrl", arr); } - /*if (bool(GLOBAL_DEF("debug/print_clicked_control",false))) { +/*if (bool(GLOBAL_DEF("debug/print_clicked_control",false))) { print_line(String(gui.mouse_focus->get_path())+" - "+pos); }*/ #endif - if (gui.mouse_focus->get_focus_mode()!=Control::FOCUS_NONE && gui.mouse_focus!=gui.key_focus && p_event.mouse_button.button_index==BUTTON_LEFT) { + if (gui.mouse_focus->get_focus_mode() != Control::FOCUS_NONE && gui.mouse_focus != gui.key_focus && p_event.mouse_button.button_index == BUTTON_LEFT) { // also get keyboard focus gui.mouse_focus->grab_focus(); } - if (gui.mouse_focus->can_process()) { - _gui_call_input(gui.mouse_focus,p_event); + _gui_call_input(gui.mouse_focus, p_event); } - get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); + get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME, "windows", "_cancel_input_ID", p_event.ID); get_tree()->set_input_as_handled(); - - if (gui.drag_data.get_type()!=Variant::NIL && p_event.mouse_button.button_index==BUTTON_LEFT) { + if (gui.drag_data.get_type() != Variant::NIL && p_event.mouse_button.button_index == BUTTON_LEFT) { //alternate drop use (when using force_drag(), as proposed by #5342 - if (gui.mouse_focus && gui.mouse_focus->can_drop_data(pos,gui.drag_data)) { - gui.mouse_focus->drop_data(pos,gui.drag_data); + if (gui.mouse_focus && gui.mouse_focus->can_drop_data(pos, gui.drag_data)) { + gui.mouse_focus->drop_data(pos, gui.drag_data); } - gui.drag_data=Variant(); + gui.drag_data = Variant(); if (gui.drag_preview) { - memdelete( gui.drag_preview ); - gui.drag_preview=NULL; + memdelete(gui.drag_preview); + gui.drag_preview = NULL; } - _propagate_viewport_notification(this,NOTIFICATION_DRAG_END); + _propagate_viewport_notification(this, NOTIFICATION_DRAG_END); //change mouse accordingly } - - _gui_cancel_tooltip(); //gui.tooltip_popup->hide(); } else { - - - if (gui.drag_data.get_type()!=Variant::NIL && p_event.mouse_button.button_index==BUTTON_LEFT) { + if (gui.drag_data.get_type() != Variant::NIL && p_event.mouse_button.button_index == BUTTON_LEFT) { if (gui.mouse_over) { Size2 pos = mpos; pos = gui.focus_inv_xform.xform(pos); - if (gui.mouse_over->can_drop_data(pos,gui.drag_data)) { - gui.mouse_over->drop_data(pos,gui.drag_data); + if (gui.mouse_over->can_drop_data(pos, gui.drag_data)) { + gui.mouse_over->drop_data(pos, gui.drag_data); } } - if (gui.drag_preview && p_event.mouse_button.button_index==BUTTON_LEFT) { - memdelete( gui.drag_preview ); - gui.drag_preview=NULL; + if (gui.drag_preview && p_event.mouse_button.button_index == BUTTON_LEFT) { + memdelete(gui.drag_preview); + gui.drag_preview = NULL; } - gui.drag_data=Variant(); - _propagate_viewport_notification(this,NOTIFICATION_DRAG_END); + gui.drag_data = Variant(); + _propagate_viewport_notification(this, NOTIFICATION_DRAG_END); //change mouse accordingly } @@ -1925,12 +1787,12 @@ void Viewport::_gui_input_event(InputEvent p_event) { p_event.mouse_button.y = pos.y; if (gui.mouse_focus->can_process()) { - _gui_call_input(gui.mouse_focus,p_event); + _gui_call_input(gui.mouse_focus, p_event); } - if (p_event.mouse_button.button_index==gui.mouse_focus_button) { - gui.mouse_focus=NULL; - gui.mouse_focus_button=-1; + if (p_event.mouse_button.button_index == gui.mouse_focus_button) { + gui.mouse_focus = NULL; + gui.mouse_focus_button = -1; } /*if (gui.drag_data.get_type()!=Variant::NIL && p_event.mouse_button.button_index==BUTTON_LEFT) { @@ -1938,44 +1800,40 @@ void Viewport::_gui_input_event(InputEvent p_event) { gui.drag_data=Variant(); //always clear }*/ - - get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID); + get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME, "windows", "_cancel_input_ID", p_event.ID); get_tree()->set_input_as_handled(); - } } break; case InputEvent::MOUSE_MOTION: { - gui.key_event_accepted=false; - Point2 mpos=Point2(p_event.mouse_motion.x,p_event.mouse_motion.y); + gui.key_event_accepted = false; + Point2 mpos = Point2(p_event.mouse_motion.x, p_event.mouse_motion.y); - gui.last_mouse_pos=mpos; + gui.last_mouse_pos = mpos; Control *over = NULL; - // D&D - if (!gui.drag_attempted && gui.mouse_focus && p_event.mouse_motion.button_mask&BUTTON_MASK_LEFT) { + if (!gui.drag_attempted && gui.mouse_focus && p_event.mouse_motion.button_mask & BUTTON_MASK_LEFT) { - gui.drag_accum+=Point2(p_event.mouse_motion.relative_x,p_event.mouse_motion.relative_y); + gui.drag_accum += Point2(p_event.mouse_motion.relative_x, p_event.mouse_motion.relative_y); float len = gui.drag_accum.length(); - if (len>10) { - gui.drag_data=gui.mouse_focus->get_drag_data(gui.focus_inv_xform.xform(mpos)-gui.drag_accum); - if (gui.drag_data.get_type()!=Variant::NIL) { + if (len > 10) { + gui.drag_data = gui.mouse_focus->get_drag_data(gui.focus_inv_xform.xform(mpos) - gui.drag_accum); + if (gui.drag_data.get_type() != Variant::NIL) { - gui.mouse_focus=NULL; + gui.mouse_focus = NULL; } - gui.drag_attempted=true; - if (gui.drag_data.get_type()!=Variant::NIL) { + gui.drag_attempted = true; + if (gui.drag_data.get_type() != Variant::NIL) { - _propagate_viewport_notification(this,NOTIFICATION_DRAG_BEGIN); + _propagate_viewport_notification(this, NOTIFICATION_DRAG_BEGIN); } } } - if (gui.mouse_focus) { - over=gui.mouse_focus; + over = gui.mouse_focus; //recompute focus_inv_xform again here } else { @@ -1983,19 +1841,16 @@ void Viewport::_gui_input_event(InputEvent p_event) { over = _gui_find_control(mpos); } - - - if (gui.drag_data.get_type()==Variant::NIL && over && !gui.modal_stack.empty()) { + if (gui.drag_data.get_type() == Variant::NIL && over && !gui.modal_stack.empty()) { Control *top = gui.modal_stack.back()->get(); - if (over!=top && !top->is_a_parent_of(over)) { + if (over != top && !top->is_a_parent_of(over)) { break; // don't send motion event to anything below modal stack top } } - - if (over!=gui.mouse_over) { + if (over != gui.mouse_over) { if (gui.mouse_over) gui.mouse_over->notification(Control::NOTIFICATION_MOUSE_EXIT); @@ -2004,10 +1859,9 @@ void Viewport::_gui_input_event(InputEvent p_event) { if (over) over->notification(Control::NOTIFICATION_MOUSE_ENTER); - } - gui.mouse_over=over; + gui.mouse_over = over; if (gui.drag_preview) { gui.drag_preview->set_pos(mpos); @@ -2018,29 +1872,26 @@ void Viewport::_gui_input_event(InputEvent p_event) { break; } - Matrix32 localizer = over->get_global_transform_with_canvas().affine_inverse(); Size2 pos = localizer.xform(mpos); - Vector2 speed = localizer.basis_xform(Point2(p_event.mouse_motion.speed_x,p_event.mouse_motion.speed_y)); - Vector2 rel = localizer.basis_xform(Point2(p_event.mouse_motion.relative_x,p_event.mouse_motion.relative_y)); - + Vector2 speed = localizer.basis_xform(Point2(p_event.mouse_motion.speed_x, p_event.mouse_motion.speed_y)); + Vector2 rel = localizer.basis_xform(Point2(p_event.mouse_motion.relative_x, p_event.mouse_motion.relative_y)); p_event.mouse_motion.global_x = mpos.x; p_event.mouse_motion.global_y = mpos.y; - p_event.mouse_motion.speed_x=speed.x; - p_event.mouse_motion.speed_y=speed.y; - p_event.mouse_motion.relative_x=rel.x; - p_event.mouse_motion.relative_y=rel.y; + p_event.mouse_motion.speed_x = speed.x; + p_event.mouse_motion.speed_y = speed.y; + p_event.mouse_motion.relative_x = rel.x; + p_event.mouse_motion.relative_y = rel.y; - if (p_event.mouse_motion.button_mask==0) { + if (p_event.mouse_motion.button_mask == 0) { //nothing pressed - bool can_tooltip=true; + bool can_tooltip = true; if (!gui.modal_stack.empty()) { - if (gui.modal_stack.back()->get()!=over && !gui.modal_stack.back()->get()->is_a_parent_of(over)) - can_tooltip=false; - + if (gui.modal_stack.back()->get() != over && !gui.modal_stack.back()->get()->is_a_parent_of(over)) + can_tooltip = false; } bool is_tooltip_shown = false; @@ -2053,51 +1904,40 @@ void Viewport::_gui_input_event(InputEvent p_event) { _gui_cancel_tooltip(); else if (tooltip == gui.tooltip_label->get_text()) is_tooltip_shown = true; - } - else + } else _gui_cancel_tooltip(); } if (can_tooltip && !is_tooltip_shown) { - gui.tooltip=over; - gui.tooltip_pos=mpos;//(parent_xform * get_transform()).affine_inverse().xform(pos); - gui.tooltip_timer=gui.tooltip_delay; - + gui.tooltip = over; + gui.tooltip_pos = mpos; //(parent_xform * get_transform()).affine_inverse().xform(pos); + gui.tooltip_timer = gui.tooltip_delay; } } - //pos = gui.focus_inv_xform.xform(pos); - p_event.mouse_motion.x = pos.x; p_event.mouse_motion.y = pos.y; - Control::CursorShape cursor_shape = over->get_cursor_shape(pos); - OS::get_singleton()->set_cursor_shape( (OS::CursorShape)cursor_shape ); - + OS::get_singleton()->set_cursor_shape((OS::CursorShape)cursor_shape); if (over->can_process()) { - _gui_call_input(over,p_event); + _gui_call_input(over, p_event); } - - get_tree()->set_input_as_handled(); + if (gui.drag_data.get_type() != Variant::NIL && p_event.mouse_motion.button_mask & BUTTON_MASK_LEFT) { - if (gui.drag_data.get_type()!=Variant::NIL && p_event.mouse_motion.button_mask&BUTTON_MASK_LEFT) { - - - bool can_drop = over->can_drop_data(pos,gui.drag_data); + bool can_drop = over->can_drop_data(pos, gui.drag_data); if (!can_drop) { - OS::get_singleton()->set_cursor_shape( OS::CURSOR_FORBIDDEN ); + OS::get_singleton()->set_cursor_shape(OS::CURSOR_FORBIDDEN); } else { - OS::get_singleton()->set_cursor_shape( OS::CURSOR_CAN_DROP ); - + OS::get_singleton()->set_cursor_shape(OS::CURSOR_CAN_DROP); } //change mouse accordingly i guess } @@ -2108,21 +1948,19 @@ void Viewport::_gui_input_event(InputEvent p_event) { case InputEvent::JOYSTICK_MOTION: case InputEvent::KEY: { - if (gui.key_focus && !gui.key_focus->is_visible()) { gui.key_focus->release_focus(); } - if (gui.key_focus) { + if (gui.key_focus) { - gui.key_event_accepted=false; + gui.key_event_accepted = false; if (gui.key_focus->can_process()) { - gui.key_focus->call_multilevel("_input_event",p_event); + gui.key_focus->call_multilevel("_input_event", p_event); if (gui.key_focus) //maybe lost it - gui.key_focus->emit_signal(SceneStringNames::get_singleton()->input_event,p_event); + gui.key_focus->emit_signal(SceneStringNames::get_singleton()->input_event, p_event); } - if (gui.key_event_accepted) { get_tree()->set_input_as_handled(); @@ -2130,7 +1968,6 @@ void Viewport::_gui_input_event(InputEvent p_event) { } } - if (p_event.is_pressed() && p_event.is_action("ui_cancel") && !gui.modal_stack.empty()) { _gui_sort_modal_stack(); @@ -2143,14 +1980,13 @@ void Viewport::_gui_input_event(InputEvent p_event) { } } - - Control * from = gui.key_focus ? gui.key_focus : NULL; //hmm + Control *from = gui.key_focus ? gui.key_focus : NULL; //hmm //keyboard focus //if (from && p_event.key.pressed && !p_event.key.mod.alt && !p_event.key.mod.meta && !p_event.key.mod.command) { if (from && p_event.is_pressed()) { - Control * next=NULL; + Control *next = NULL; if (p_event.is_action("ui_focus_next")) { @@ -2182,7 +2018,6 @@ void Viewport::_gui_input_event(InputEvent p_event) { next = from->_get_focus_neighbour(MARGIN_BOTTOM); } - if (next) { next->grab_focus(); get_tree()->set_input_as_handled(); @@ -2193,41 +2028,39 @@ void Viewport::_gui_input_event(InputEvent p_event) { } } +List<Control *>::Element *Viewport::_gui_add_root_control(Control *p_control) { -List<Control*>::Element* Viewport::_gui_add_root_control(Control* p_control) { - - gui.roots_order_dirty=true; + gui.roots_order_dirty = true; return gui.roots.push_back(p_control); } -List<Control*>::Element* Viewport::_gui_add_subwindow_control(Control* p_control) { +List<Control *>::Element *Viewport::_gui_add_subwindow_control(Control *p_control) { - gui.subwindow_order_dirty=true; + gui.subwindow_order_dirty = true; return gui.subwindows.push_back(p_control); - } void Viewport::_gui_set_subwindow_order_dirty() { - gui.subwindow_order_dirty=true; + gui.subwindow_order_dirty = true; } void Viewport::_gui_set_root_order_dirty() { - gui.roots_order_dirty=true; + gui.roots_order_dirty = true; } -void Viewport::_gui_remove_modal_control(List<Control*>::Element *MI) { +void Viewport::_gui_remove_modal_control(List<Control *>::Element *MI) { gui.modal_stack.erase(MI); } -void Viewport::_gui_remove_from_modal_stack(List<Control*>::Element *MI,ObjectID p_prev_focus_owner) { +void Viewport::_gui_remove_from_modal_stack(List<Control *>::Element *MI, ObjectID p_prev_focus_owner) { //transfer the focus stack to the next - List<Control*>::Element *next = MI->next(); + List<Control *>::Element *next = MI->next(); gui.modal_stack.erase(MI); - MI=NULL; + MI = NULL; if (p_prev_focus_owner) { @@ -2251,25 +2084,25 @@ void Viewport::_gui_remove_from_modal_stack(List<Control*>::Element *MI,ObjectID } } -void Viewport::_gui_force_drag(Control *p_base, const Variant& p_data, Control *p_control) { +void Viewport::_gui_force_drag(Control *p_base, const Variant &p_data, Control *p_control) { ERR_EXPLAIN("Drag data must be a value"); - ERR_FAIL_COND(p_data.get_type()==Variant::NIL); + ERR_FAIL_COND(p_data.get_type() == Variant::NIL); - gui.drag_data=p_data; - gui.mouse_focus=NULL; + gui.drag_data = p_data; + gui.mouse_focus = NULL; if (p_control) { - _gui_set_drag_preview(p_base,p_control); + _gui_set_drag_preview(p_base, p_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 *)p_control)->cast_to<Control>()); ERR_FAIL_COND(p_control->is_inside_tree()); - ERR_FAIL_COND(p_control->get_parent()!=NULL); + ERR_FAIL_COND(p_control->get_parent() != NULL); if (gui.drag_preview) { memdelete(gui.drag_preview); @@ -2279,25 +2112,24 @@ void Viewport::_gui_set_drag_preview(Control *p_base, Control *p_control) { p_base->get_root_parent_control()->add_child(p_control); //add as child of viewport p_control->raise(); if (gui.drag_preview) { - memdelete( gui.drag_preview ); + memdelete(gui.drag_preview); } - gui.drag_preview=p_control; + gui.drag_preview = p_control; } - -void Viewport::_gui_remove_root_control(List<Control*>::Element *RI) { +void Viewport::_gui_remove_root_control(List<Control *>::Element *RI) { gui.roots.erase(RI); } -void Viewport::_gui_remove_subwindow_control(List<Control*>::Element* SI){ +void Viewport::_gui_remove_subwindow_control(List<Control *>::Element *SI) { gui.subwindows.erase(SI); } void Viewport::_gui_unfocus_control(Control *p_control) { - if (gui.key_focus==p_control) { + if (gui.key_focus == p_control) { gui.key_focus->release_focus(); } } @@ -2305,7 +2137,7 @@ void Viewport::_gui_unfocus_control(Control *p_control) { void Viewport::_gui_hid_control(Control *p_control) { if (gui.mouse_focus == p_control) { - gui.mouse_focus=NULL; + gui.mouse_focus = NULL; } /* ??? @@ -2319,81 +2151,71 @@ void Viewport::_gui_hid_control(Control *p_control) { */ if (gui.key_focus == p_control) - gui.key_focus=NULL; + gui.key_focus = NULL; if (gui.mouse_over == p_control) - gui.mouse_over=NULL; + gui.mouse_over = NULL; if (gui.tooltip == p_control) - gui.tooltip=NULL; + gui.tooltip = NULL; if (gui.tooltip == p_control) { - gui.tooltip=NULL; + gui.tooltip = NULL; _gui_cancel_tooltip(); } - } void Viewport::_gui_remove_control(Control *p_control) { - if (gui.mouse_focus == p_control) - gui.mouse_focus=NULL; + gui.mouse_focus = NULL; if (gui.key_focus == p_control) - gui.key_focus=NULL; + gui.key_focus = NULL; if (gui.mouse_over == p_control) - gui.mouse_over=NULL; + gui.mouse_over = NULL; if (gui.tooltip == p_control) - gui.tooltip=NULL; + gui.tooltip = NULL; if (gui.tooltip_popup == p_control) { _gui_cancel_tooltip(); } - - } void Viewport::_gui_remove_focus() { if (gui.key_focus) { - Node *f=gui.key_focus; - gui.key_focus=NULL; - f->notification( Control::NOTIFICATION_FOCUS_EXIT,true ); - - + Node *f = gui.key_focus; + gui.key_focus = NULL; + f->notification(Control::NOTIFICATION_FOCUS_EXIT, true); } } -bool Viewport::_gui_is_modal_on_top(const Control* p_control) { - - return (gui.modal_stack.size() && gui.modal_stack.back()->get()==p_control); +bool Viewport::_gui_is_modal_on_top(const Control *p_control) { + return (gui.modal_stack.size() && gui.modal_stack.back()->get() == p_control); } -bool Viewport::_gui_control_has_focus(const Control* p_control) { +bool Viewport::_gui_control_has_focus(const Control *p_control) { - return gui.key_focus==p_control; + return gui.key_focus == p_control; } -void Viewport::_gui_control_grab_focus(Control* p_control) { - +void Viewport::_gui_control_grab_focus(Control *p_control) { //no need for change - if (gui.key_focus && gui.key_focus==p_control) + if (gui.key_focus && gui.key_focus == p_control) return; - get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME,"_viewports","_gui_remove_focus"); - gui.key_focus=p_control; + get_tree()->call_group(SceneTree::GROUP_CALL_REALTIME, "_viewports", "_gui_remove_focus"); + gui.key_focus = p_control; p_control->notification(Control::NOTIFICATION_FOCUS_ENTER); p_control->update(); - } void Viewport::_gui_accept_event() { - gui.key_event_accepted=true; + gui.key_event_accepted = true; if (is_inside_tree()) get_tree()->set_input_as_handled(); } - -List<Control*>::Element* Viewport::_gui_show_modal(Control* p_control) { +List<Control *>::Element *Viewport::_gui_show_modal(Control *p_control) { gui.modal_stack.push_back(p_control); if (gui.key_focus) @@ -2413,77 +2235,67 @@ void Viewport::_gui_grab_click_focus(Control *p_control) { if (gui.mouse_focus) { - - if (gui.mouse_focus==p_control) + if (gui.mouse_focus == p_control) return; InputEvent ie; - ie.type=InputEvent::MOUSE_BUTTON; - InputEventMouseButton &mb=ie.mouse_button; + ie.type = InputEvent::MOUSE_BUTTON; + InputEventMouseButton &mb = ie.mouse_button; //send unclic - Point2 click =gui.mouse_focus->get_global_transform_with_canvas().affine_inverse().xform(gui.last_mouse_pos); - mb.x=click.x; - mb.y=click.y; - mb.button_index=gui.mouse_focus_button; - mb.pressed=false; - gui.mouse_focus->call_deferred("_input_event",ie); - - - gui.mouse_focus=p_control; - gui.focus_inv_xform=gui.mouse_focus->get_global_transform_with_canvas().affine_inverse(); - click =gui.mouse_focus->get_global_transform_with_canvas().affine_inverse().xform(gui.last_mouse_pos); - mb.x=click.x; - mb.y=click.y; - mb.button_index=gui.mouse_focus_button; - mb.pressed=true; - gui.mouse_focus->call_deferred("_input_event",ie); + Point2 click = gui.mouse_focus->get_global_transform_with_canvas().affine_inverse().xform(gui.last_mouse_pos); + mb.x = click.x; + mb.y = click.y; + mb.button_index = gui.mouse_focus_button; + mb.pressed = false; + gui.mouse_focus->call_deferred("_input_event", ie); + gui.mouse_focus = p_control; + gui.focus_inv_xform = gui.mouse_focus->get_global_transform_with_canvas().affine_inverse(); + click = gui.mouse_focus->get_global_transform_with_canvas().affine_inverse().xform(gui.last_mouse_pos); + mb.x = click.x; + mb.y = click.y; + mb.button_index = gui.mouse_focus_button; + mb.pressed = true; + gui.mouse_focus->call_deferred("_input_event", ie); } } - /////////////////////////////// - -void Viewport::input(const InputEvent& p_event) { +void Viewport::input(const InputEvent &p_event) { ERR_FAIL_COND(!is_inside_tree()); - - get_tree()->_call_input_pause(input_group,"_input",p_event); //not a bug, must happen before GUI, order is _input -> gui input -> _unhandled input + get_tree()->_call_input_pause(input_group, "_input", p_event); //not a bug, must happen before GUI, order is _input -> gui input -> _unhandled input _gui_input_event(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) { +void Viewport::unhandled_input(const InputEvent &p_event) { ERR_FAIL_COND(!is_inside_tree()); - - get_tree()->_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_tree()->input_handled && p_event.type==InputEvent::KEY) { - get_tree()->_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_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) { + 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); } } - } void Viewport::set_use_own_world(bool p_world) { - if (p_world==own_world.is_valid()) + if (p_world == own_world.is_valid()) return; - if (is_inside_tree()) _propagate_exit_world(this); @@ -2493,9 +2305,9 @@ void Viewport::set_use_own_world(bool p_world) { #endif if (!p_world) - own_world=Ref<World>(); + own_world = Ref<World>(); else - own_world=Ref<World>( memnew( World )); + own_world = Ref<World>(memnew(World)); if (is_inside_tree()) _propagate_enter_world(this); @@ -2508,12 +2320,10 @@ void Viewport::set_use_own_world(bool p_world) { //propagate exit if (is_inside_tree()) { - VisualServer::get_singleton()->viewport_set_scenario(viewport,find_world()->get_scenario()); + VisualServer::get_singleton()->viewport_set_scenario(viewport, find_world()->get_scenario()); } _update_listener(); - - } bool Viewport::is_using_own_world() const { @@ -2521,34 +2331,29 @@ bool Viewport::is_using_own_world() const { return own_world.is_valid(); } -void Viewport::set_render_target_to_screen_rect(const Rect2& p_rect) { +void Viewport::set_render_target_to_screen_rect(const Rect2 &p_rect) { - to_screen_rect=p_rect; - VisualServer::get_singleton()->viewport_set_render_target_to_screen_rect(viewport,to_screen_rect); + to_screen_rect = p_rect; + VisualServer::get_singleton()->viewport_set_render_target_to_screen_rect(viewport, to_screen_rect); } -Rect2 Viewport::get_render_target_to_screen_rect() const{ +Rect2 Viewport::get_render_target_to_screen_rect() const { return to_screen_rect; } void Viewport::set_physics_object_picking(bool p_enable) { - physics_object_picking=p_enable; + physics_object_picking = p_enable; set_fixed_process(physics_object_picking); if (!physics_object_picking) physics_picking_events.clear(); - - } - 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 { @@ -2556,10 +2361,8 @@ Vector2 Viewport::get_camera_rect_size() const { return last_vp_rect.size; } - bool Viewport::get_physics_object_picking() { - return physics_object_picking; } @@ -2569,7 +2372,7 @@ bool Viewport::gui_has_modal_stack() const { } void Viewport::set_disable_input(bool p_disable) { - disable_input=p_disable; + disable_input = p_disable; } bool Viewport::is_input_disabled() const { @@ -2582,7 +2385,7 @@ Variant Viewport::gui_get_drag_data() const { } Control *Viewport::get_modal_stack_top() const { - return gui.modal_stack.size()?gui.modal_stack.back()->get():NULL; + return gui.modal_stack.size() ? gui.modal_stack.back()->get() : NULL; } String Viewport::get_configuration_warning() const { @@ -2597,190 +2400,176 @@ String Viewport::get_configuration_warning() const { void Viewport::_bind_methods() { - - ObjectTypeDB::bind_method(_MD("set_rect","rect"), &Viewport::set_rect); + ObjectTypeDB::bind_method(_MD("set_rect", "rect"), &Viewport::set_rect); ObjectTypeDB::bind_method(_MD("get_rect"), &Viewport::get_rect); - ObjectTypeDB::bind_method(_MD("set_world_2d","world_2d:World2D"), &Viewport::set_world_2d); + ObjectTypeDB::bind_method(_MD("set_world_2d", "world_2d:World2D"), &Viewport::set_world_2d); ObjectTypeDB::bind_method(_MD("get_world_2d:World2D"), &Viewport::get_world_2d); ObjectTypeDB::bind_method(_MD("find_world_2d:World2D"), &Viewport::find_world_2d); - ObjectTypeDB::bind_method(_MD("set_world","world:World"), &Viewport::set_world); + ObjectTypeDB::bind_method(_MD("set_world", "world:World"), &Viewport::set_world); ObjectTypeDB::bind_method(_MD("get_world:World"), &Viewport::get_world); ObjectTypeDB::bind_method(_MD("find_world:World"), &Viewport::find_world); - ObjectTypeDB::bind_method(_MD("set_canvas_transform","xform"), &Viewport::set_canvas_transform); + ObjectTypeDB::bind_method(_MD("set_canvas_transform", "xform"), &Viewport::set_canvas_transform); ObjectTypeDB::bind_method(_MD("get_canvas_transform"), &Viewport::get_canvas_transform); - ObjectTypeDB::bind_method(_MD("set_global_canvas_transform","xform"), &Viewport::set_global_canvas_transform); + ObjectTypeDB::bind_method(_MD("set_global_canvas_transform", "xform"), &Viewport::set_global_canvas_transform); ObjectTypeDB::bind_method(_MD("get_global_canvas_transform"), &Viewport::get_global_canvas_transform); ObjectTypeDB::bind_method(_MD("get_final_transform"), &Viewport::get_final_transform); ObjectTypeDB::bind_method(_MD("get_visible_rect"), &Viewport::get_visible_rect); - ObjectTypeDB::bind_method(_MD("set_transparent_background","enable"), &Viewport::set_transparent_background); + ObjectTypeDB::bind_method(_MD("set_transparent_background", "enable"), &Viewport::set_transparent_background); ObjectTypeDB::bind_method(_MD("has_transparent_background"), &Viewport::has_transparent_background); ObjectTypeDB::bind_method(_MD("_parent_visibility_changed"), &Viewport::_parent_visibility_changed); ObjectTypeDB::bind_method(_MD("_parent_resized"), &Viewport::_parent_resized); ObjectTypeDB::bind_method(_MD("_vp_input"), &Viewport::_vp_input); - ObjectTypeDB::bind_method(_MD("_vp_input_text","text"), &Viewport::_vp_input_text); + ObjectTypeDB::bind_method(_MD("_vp_input_text", "text"), &Viewport::_vp_input_text); ObjectTypeDB::bind_method(_MD("_vp_unhandled_input"), &Viewport::_vp_unhandled_input); - ObjectTypeDB::bind_method(_MD("set_size_override","enable","size","margin"), &Viewport::set_size_override,DEFVAL(Size2(-1,-1)),DEFVAL(Size2(0,0))); + ObjectTypeDB::bind_method(_MD("set_size_override", "enable", "size", "margin"), &Viewport::set_size_override, DEFVAL(Size2(-1, -1)), DEFVAL(Size2(0, 0))); ObjectTypeDB::bind_method(_MD("get_size_override"), &Viewport::get_size_override); ObjectTypeDB::bind_method(_MD("is_size_override_enabled"), &Viewport::is_size_override_enabled); - ObjectTypeDB::bind_method(_MD("set_size_override_stretch","enabled"), &Viewport::set_size_override_stretch); + ObjectTypeDB::bind_method(_MD("set_size_override_stretch", "enabled"), &Viewport::set_size_override_stretch); ObjectTypeDB::bind_method(_MD("is_size_override_stretch_enabled"), &Viewport::is_size_override_stretch_enabled); ObjectTypeDB::bind_method(_MD("queue_screen_capture"), &Viewport::queue_screen_capture); ObjectTypeDB::bind_method(_MD("get_screen_capture"), &Viewport::get_screen_capture); - ObjectTypeDB::bind_method(_MD("set_as_render_target","enable"), &Viewport::set_as_render_target); + ObjectTypeDB::bind_method(_MD("set_as_render_target", "enable"), &Viewport::set_as_render_target); ObjectTypeDB::bind_method(_MD("is_set_as_render_target"), &Viewport::is_set_as_render_target); - ObjectTypeDB::bind_method(_MD("set_render_target_vflip","enable"), &Viewport::set_render_target_vflip); + ObjectTypeDB::bind_method(_MD("set_render_target_vflip", "enable"), &Viewport::set_render_target_vflip); ObjectTypeDB::bind_method(_MD("get_render_target_vflip"), &Viewport::get_render_target_vflip); - ObjectTypeDB::bind_method(_MD("set_render_target_clear_on_new_frame","enable"), &Viewport::set_render_target_clear_on_new_frame); + ObjectTypeDB::bind_method(_MD("set_render_target_clear_on_new_frame", "enable"), &Viewport::set_render_target_clear_on_new_frame); ObjectTypeDB::bind_method(_MD("get_render_target_clear_on_new_frame"), &Viewport::get_render_target_clear_on_new_frame); ObjectTypeDB::bind_method(_MD("render_target_clear"), &Viewport::render_target_clear); - ObjectTypeDB::bind_method(_MD("set_render_target_filter","enable"), &Viewport::set_render_target_filter); + ObjectTypeDB::bind_method(_MD("set_render_target_filter", "enable"), &Viewport::set_render_target_filter); ObjectTypeDB::bind_method(_MD("get_render_target_filter"), &Viewport::get_render_target_filter); - ObjectTypeDB::bind_method(_MD("set_render_target_gen_mipmaps","enable"), &Viewport::set_render_target_gen_mipmaps); + ObjectTypeDB::bind_method(_MD("set_render_target_gen_mipmaps", "enable"), &Viewport::set_render_target_gen_mipmaps); ObjectTypeDB::bind_method(_MD("get_render_target_gen_mipmaps"), &Viewport::get_render_target_gen_mipmaps); - ObjectTypeDB::bind_method(_MD("set_render_target_update_mode","mode"), &Viewport::set_render_target_update_mode); + ObjectTypeDB::bind_method(_MD("set_render_target_update_mode", "mode"), &Viewport::set_render_target_update_mode); ObjectTypeDB::bind_method(_MD("get_render_target_update_mode"), &Viewport::get_render_target_update_mode); ObjectTypeDB::bind_method(_MD("get_render_target_texture:RenderTargetTexture"), &Viewport::get_render_target_texture); - ObjectTypeDB::bind_method(_MD("set_physics_object_picking","enable"), &Viewport::set_physics_object_picking); + ObjectTypeDB::bind_method(_MD("set_physics_object_picking", "enable"), &Viewport::set_physics_object_picking); ObjectTypeDB::bind_method(_MD("get_physics_object_picking"), &Viewport::get_physics_object_picking); ObjectTypeDB::bind_method(_MD("get_viewport"), &Viewport::get_viewport); - ObjectTypeDB::bind_method(_MD("input","local_event"), &Viewport::input); - ObjectTypeDB::bind_method(_MD("unhandled_input","local_event"), &Viewport::unhandled_input); + ObjectTypeDB::bind_method(_MD("input", "local_event"), &Viewport::input); + ObjectTypeDB::bind_method(_MD("unhandled_input", "local_event"), &Viewport::unhandled_input); ObjectTypeDB::bind_method(_MD("update_worlds"), &Viewport::update_worlds); - ObjectTypeDB::bind_method(_MD("set_use_own_world","enable"), &Viewport::set_use_own_world); + ObjectTypeDB::bind_method(_MD("set_use_own_world", "enable"), &Viewport::set_use_own_world); ObjectTypeDB::bind_method(_MD("is_using_own_world"), &Viewport::is_using_own_world); ObjectTypeDB::bind_method(_MD("get_camera:Camera"), &Viewport::get_camera); - ObjectTypeDB::bind_method(_MD("set_as_audio_listener","enable"), &Viewport::set_as_audio_listener); - ObjectTypeDB::bind_method(_MD("is_audio_listener","enable"), &Viewport::is_audio_listener); + ObjectTypeDB::bind_method(_MD("set_as_audio_listener", "enable"), &Viewport::set_as_audio_listener); + ObjectTypeDB::bind_method(_MD("is_audio_listener", "enable"), &Viewport::is_audio_listener); - ObjectTypeDB::bind_method(_MD("set_as_audio_listener_2d","enable"), &Viewport::set_as_audio_listener_2d); - ObjectTypeDB::bind_method(_MD("is_audio_listener_2d","enable"), &Viewport::is_audio_listener_2d); - ObjectTypeDB::bind_method(_MD("set_render_target_to_screen_rect","rect"), &Viewport::set_render_target_to_screen_rect); + ObjectTypeDB::bind_method(_MD("set_as_audio_listener_2d", "enable"), &Viewport::set_as_audio_listener_2d); + ObjectTypeDB::bind_method(_MD("is_audio_listener_2d", "enable"), &Viewport::is_audio_listener_2d); + ObjectTypeDB::bind_method(_MD("set_render_target_to_screen_rect", "rect"), &Viewport::set_render_target_to_screen_rect); ObjectTypeDB::bind_method(_MD("get_mouse_pos"), &Viewport::get_mouse_pos); - ObjectTypeDB::bind_method(_MD("warp_mouse","to_pos"), &Viewport::warp_mouse); + ObjectTypeDB::bind_method(_MD("warp_mouse", "to_pos"), &Viewport::warp_mouse); ObjectTypeDB::bind_method(_MD("gui_has_modal_stack"), &Viewport::gui_has_modal_stack); ObjectTypeDB::bind_method(_MD("gui_get_drag_data:Variant"), &Viewport::gui_get_drag_data); - ObjectTypeDB::bind_method(_MD("set_disable_input","disable"), &Viewport::set_disable_input); + ObjectTypeDB::bind_method(_MD("set_disable_input", "disable"), &Viewport::set_disable_input); ObjectTypeDB::bind_method(_MD("is_input_disabled"), &Viewport::is_input_disabled); ObjectTypeDB::bind_method(_MD("_gui_show_tooltip"), &Viewport::_gui_show_tooltip); ObjectTypeDB::bind_method(_MD("_gui_remove_focus"), &Viewport::_gui_remove_focus); - ADD_PROPERTY( PropertyInfo(Variant::RECT2,"rect"), _SCS("set_rect"), _SCS("get_rect") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"own_world"), _SCS("set_use_own_world"), _SCS("is_using_own_world") ); - ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"world",PROPERTY_HINT_RESOURCE_TYPE,"World"), _SCS("set_world"), _SCS("get_world") ); -// ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"world_2d",PROPERTY_HINT_RESOURCE_TYPE,"World2D"), _SCS("set_world_2d"), _SCS("get_world_2d") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"transparent_bg"), _SCS("set_transparent_background"), _SCS("has_transparent_background") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"render_target/enabled"), _SCS("set_as_render_target"), _SCS("is_set_as_render_target") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"render_target/v_flip"), _SCS("set_render_target_vflip"), _SCS("get_render_target_vflip") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"render_target/clear_on_new_frame"), _SCS("set_render_target_clear_on_new_frame"), _SCS("get_render_target_clear_on_new_frame") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"render_target/filter"), _SCS("set_render_target_filter"), _SCS("get_render_target_filter") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"render_target/gen_mipmaps"), _SCS("set_render_target_gen_mipmaps"), _SCS("get_render_target_gen_mipmaps") ); - ADD_PROPERTY( PropertyInfo(Variant::INT,"render_target/update_mode",PROPERTY_HINT_ENUM,"Disabled,Once,When Visible,Always"), _SCS("set_render_target_update_mode"), _SCS("get_render_target_update_mode") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"audio_listener/enable_2d"), _SCS("set_as_audio_listener_2d"), _SCS("is_audio_listener_2d") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"audio_listener/enable_3d"), _SCS("set_as_audio_listener"), _SCS("is_audio_listener") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"physics/object_picking"), _SCS("set_physics_object_picking"), _SCS("get_physics_object_picking") ); - ADD_PROPERTY( PropertyInfo(Variant::BOOL,"gui/disable_input"), _SCS("set_disable_input"), _SCS("is_input_disabled") ); + ADD_PROPERTY(PropertyInfo(Variant::RECT2, "rect"), _SCS("set_rect"), _SCS("get_rect")); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "own_world"), _SCS("set_use_own_world"), _SCS("is_using_own_world")); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "world", PROPERTY_HINT_RESOURCE_TYPE, "World"), _SCS("set_world"), _SCS("get_world")); + // ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"world_2d",PROPERTY_HINT_RESOURCE_TYPE,"World2D"), _SCS("set_world_2d"), _SCS("get_world_2d") ); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "transparent_bg"), _SCS("set_transparent_background"), _SCS("has_transparent_background")); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "render_target/enabled"), _SCS("set_as_render_target"), _SCS("is_set_as_render_target")); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "render_target/v_flip"), _SCS("set_render_target_vflip"), _SCS("get_render_target_vflip")); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "render_target/clear_on_new_frame"), _SCS("set_render_target_clear_on_new_frame"), _SCS("get_render_target_clear_on_new_frame")); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "render_target/filter"), _SCS("set_render_target_filter"), _SCS("get_render_target_filter")); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "render_target/gen_mipmaps"), _SCS("set_render_target_gen_mipmaps"), _SCS("get_render_target_gen_mipmaps")); + ADD_PROPERTY(PropertyInfo(Variant::INT, "render_target/update_mode", PROPERTY_HINT_ENUM, "Disabled,Once,When Visible,Always"), _SCS("set_render_target_update_mode"), _SCS("get_render_target_update_mode")); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "audio_listener/enable_2d"), _SCS("set_as_audio_listener_2d"), _SCS("is_audio_listener_2d")); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "audio_listener/enable_3d"), _SCS("set_as_audio_listener"), _SCS("is_audio_listener")); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "physics/object_picking"), _SCS("set_physics_object_picking"), _SCS("get_physics_object_picking")); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gui/disable_input"), _SCS("set_disable_input"), _SCS("is_input_disabled")); ADD_SIGNAL(MethodInfo("size_changed")); - BIND_CONSTANT( RENDER_TARGET_UPDATE_DISABLED ); - BIND_CONSTANT( RENDER_TARGET_UPDATE_ONCE ); - BIND_CONSTANT( RENDER_TARGET_UPDATE_WHEN_VISIBLE ); - BIND_CONSTANT( RENDER_TARGET_UPDATE_ALWAYS ); - + BIND_CONSTANT(RENDER_TARGET_UPDATE_DISABLED); + BIND_CONSTANT(RENDER_TARGET_UPDATE_ONCE); + BIND_CONSTANT(RENDER_TARGET_UPDATE_WHEN_VISIBLE); + BIND_CONSTANT(RENDER_TARGET_UPDATE_ALWAYS); } - - - - Viewport::Viewport() { - - world_2d = Ref<World2D>( memnew( World2D )); + world_2d = Ref<World2D>(memnew(World2D)); viewport = VisualServer::get_singleton()->viewport_create(); internal_listener = SpatialSoundServer::get_singleton()->listener_create(); - audio_listener=false; + audio_listener = false; internal_listener_2d = SpatialSound2DServer::get_singleton()->listener_create(); - audio_listener_2d=false; - transparent_bg=false; - parent=NULL; - listener=NULL; - camera=NULL; - size_override=false; - size_override_stretch=false; - size_override_size=Size2(1,1); - render_target_gen_mipmaps=false; - render_target=false; - render_target_vflip=false; - render_target_clear_on_new_frame=true; + audio_listener_2d = false; + transparent_bg = false; + parent = NULL; + listener = NULL; + camera = NULL; + size_override = false; + size_override_stretch = false; + size_override_size = Size2(1, 1); + render_target_gen_mipmaps = false; + render_target = false; + render_target_vflip = false; + render_target_clear_on_new_frame = true; //render_target_clear=true; - render_target_update_mode=RENDER_TARGET_UPDATE_WHEN_VISIBLE; - render_target_texture = Ref<RenderTargetTexture>( memnew( RenderTargetTexture(this) ) ); + render_target_update_mode = RENDER_TARGET_UPDATE_WHEN_VISIBLE; + render_target_texture = Ref<RenderTargetTexture>(memnew(RenderTargetTexture(this))); - physics_object_picking=false; - physics_object_capture=0; - physics_object_over=0; - physics_last_mousepos=Vector2(1e20,1e20); + physics_object_picking = false; + physics_object_capture = 0; + physics_object_over = 0; + physics_last_mousepos = Vector2(1e20, 1e20); + String id = itos(get_instance_ID()); + input_group = "_vp_input" + id; + gui_input_group = "_vp_gui_input" + id; + unhandled_input_group = "_vp_unhandled_input" + id; + unhandled_key_input_group = "_vp_unhandled_key_input" + id; - String id=itos(get_instance_ID()); - input_group = "_vp_input"+id; - gui_input_group = "_vp_gui_input"+id; - unhandled_input_group = "_vp_unhandled_input"+id; - unhandled_key_input_group = "_vp_unhandled_key_input"+id; - - disable_input=false; + disable_input = false; //window tooltip gui.tooltip_timer = -1; //gui.tooltip_timer->force_parent_owned(); - gui.tooltip_delay=GLOBAL_DEF("display/tooltip_delay",0.7); - - gui.tooltip=NULL; - gui.tooltip_label=NULL; - gui.drag_preview=NULL; - gui.drag_attempted=false; - - - parent_control=NULL; + gui.tooltip_delay = GLOBAL_DEF("display/tooltip_delay", 0.7); + gui.tooltip = NULL; + gui.tooltip_label = NULL; + gui.drag_preview = NULL; + gui.drag_attempted = false; + parent_control = NULL; } - Viewport::~Viewport() { - VisualServer::get_singleton()->free( viewport ); + VisualServer::get_singleton()->free(viewport); SpatialSoundServer::get_singleton()->free(internal_listener); SpatialSound2DServer::get_singleton()->free(internal_listener_2d); if (render_target_texture.is_valid()) - render_target_texture->vp=NULL; //so if used, will crash + render_target_texture->vp = NULL; //so if used, will crash } - - diff --git a/scene/main/viewport.h b/scene/main/viewport.h index 2a54aec96..b9103ac48 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -29,11 +29,11 @@ #ifndef VIEWPORT_H #define VIEWPORT_H -#include "scene/main/node.h" -#include "servers/visual_server.h" -#include "scene/resources/world_2d.h" #include "math_2d.h" +#include "scene/main/node.h" #include "scene/resources/texture.h" +#include "scene/resources/world_2d.h" +#include "servers/visual_server.h" /** @author Juan Linietsky <reduzio@gmail.com> */ @@ -50,16 +50,13 @@ class Viewport; class RenderTargetTexture : public Texture { - OBJ_TYPE( RenderTargetTexture, Texture ); + OBJ_TYPE(RenderTargetTexture, Texture); int flags; -friend class Viewport; + friend class Viewport; Viewport *vp; - public: - - virtual int get_width() const; virtual int get_height() const; virtual Size2 get_size() const; @@ -70,15 +67,14 @@ public: virtual void set_flags(uint32_t p_flags); virtual uint32_t get_flags() const; - RenderTargetTexture(Viewport *p_vp=NULL); - + RenderTargetTexture(Viewport *p_vp = NULL); }; class Viewport : public Node { - OBJ_TYPE( Viewport, Node ); -public: + OBJ_TYPE(Viewport, Node); +public: enum RenderTargetUpdateMode { RENDER_TARGET_UPDATE_DISABLED, RENDER_TARGET_UPDATE_ONCE, //then goes to disabled @@ -87,18 +83,16 @@ public: }; private: - -friend class RenderTargetTexture; - + friend class RenderTargetTexture; Control *parent_control; Viewport *parent; Listener *listener; - Set<Listener*> listeners; + Set<Listener *> listeners; Camera *camera; - Set<Camera*> cameras; + Set<Camera *> cameras; RID viewport; RID canvas_item; @@ -121,8 +115,6 @@ friend class RenderTargetTexture; RID contact_3d_debug_multimesh; RID contact_3d_debug_instance; - - bool size_override; bool size_override_stretch; Size2 size_override_size; @@ -142,7 +134,7 @@ friend class RenderTargetTexture; ObjectID physics_object_over; Vector2 physics_last_mousepos; void _test_new_mouseover(ObjectID new_collider); - Map<ObjectID,uint64_t> physics_2d_mouseover; + Map<ObjectID, uint64_t> physics_2d_mouseover; void _update_rect(); @@ -166,7 +158,6 @@ friend class RenderTargetTexture; void _propagate_exit_world(Node *p_node); void _propagate_viewport_notification(Node *p_node, int p_what); - void _update_stretch_transform(); void _update_global_transform(); @@ -175,7 +166,6 @@ friend class RenderTargetTexture; RID render_target_texture_rid; Ref<RenderTargetTexture> render_target_texture; - struct GUI { // info used when this is a window @@ -195,30 +185,28 @@ friend class RenderTargetTexture; Control *drag_preview; float tooltip_timer; float tooltip_delay; - List<Control*> modal_stack; + List<Control *> modal_stack; unsigned int cancelled_input_ID; Matrix32 focus_inv_xform; bool subwindow_order_dirty; - List<Control*> subwindows; + List<Control *> subwindows; bool roots_order_dirty; - List<Control*> roots; - + List<Control *> roots; GUI(); } gui; bool disable_input; - void _gui_call_input(Control *p_control,const InputEvent& p_input); + void _gui_call_input(Control *p_control, const InputEvent &p_input); void _gui_sort_subwindows(); void _gui_sort_roots(); void _gui_sort_modal_stack(); - Control* _gui_find_control(const Point2& p_global); - Control* _gui_find_control_at_pos(CanvasItem* p_node,const Point2& p_global,const Matrix32& p_xform,Matrix32& r_inv_xform); + Control *_gui_find_control(const Point2 &p_global); + Control *_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_global, const Matrix32 &p_xform, Matrix32 &r_inv_xform); void _gui_input_event(InputEvent p_event); - void update_worlds(); _FORCE_INLINE_ Matrix32 _get_input_pre_xform() const; @@ -226,43 +214,40 @@ friend class RenderTargetTexture; void _vp_enter_tree(); void _vp_exit_tree(); - void _vp_input(const InputEvent& p_ev); - void _vp_input_text(const String& p_text); - void _vp_unhandled_input(const InputEvent& p_ev); - void _make_input_local(InputEvent& ev); - + void _vp_input(const InputEvent &p_ev); + void _vp_input_text(const String &p_text); + void _vp_unhandled_input(const InputEvent &p_ev); + void _make_input_local(InputEvent &ev); -friend class Control; + friend class Control; - List<Control*>::Element* _gui_add_root_control(Control* p_control); - List<Control*>::Element* _gui_add_subwindow_control(Control* p_control); + List<Control *>::Element *_gui_add_root_control(Control *p_control); + List<Control *>::Element *_gui_add_subwindow_control(Control *p_control); void _gui_set_subwindow_order_dirty(); void _gui_set_root_order_dirty(); - - void _gui_remove_modal_control(List<Control*>::Element *MI); - void _gui_remove_from_modal_stack(List<Control*>::Element *MI,ObjectID p_prev_focus_owner); - void _gui_remove_root_control(List<Control*>::Element *RI); - void _gui_remove_subwindow_control(List<Control*>::Element* SI); + void _gui_remove_modal_control(List<Control *>::Element *MI); + void _gui_remove_from_modal_stack(List<Control *>::Element *MI, ObjectID p_prev_focus_owner); + void _gui_remove_root_control(List<Control *>::Element *RI); + void _gui_remove_subwindow_control(List<Control *>::Element *SI); void _gui_cancel_tooltip(); void _gui_show_tooltip(); - void _gui_remove_control(Control *p_control); void _gui_hid_control(Control *p_control); - void _gui_force_drag(Control *p_base,const Variant& p_data,Control *p_control); - void _gui_set_drag_preview(Control *p_base,Control *p_control); + void _gui_force_drag(Control *p_base, const Variant &p_data, Control *p_control); + void _gui_set_drag_preview(Control *p_base, Control *p_control); - bool _gui_is_modal_on_top(const Control* p_control); - List<Control*>::Element* _gui_show_modal(Control* p_control); + bool _gui_is_modal_on_top(const Control *p_control); + List<Control *>::Element *_gui_show_modal(Control *p_control); void _gui_remove_focus(); void _gui_unfocus_control(Control *p_control); - bool _gui_control_has_focus(const Control* p_control); - void _gui_control_grab_focus(Control* p_control); + bool _gui_control_has_focus(const Control *p_control); + void _gui_control_grab_focus(Control *p_control); void _gui_grab_click_focus(Control *p_control); void _gui_accept_event(); @@ -270,28 +255,27 @@ friend class Control; Vector2 _get_window_offset() const; -friend class Listener; + friend class Listener; void _listener_transform_changed_notify(); - void _listener_set(Listener* p_listener); - bool _listener_add(Listener* p_listener); //true if first - void _listener_remove(Listener* p_listener); - void _listener_make_next_current(Listener* p_exclude); + void _listener_set(Listener *p_listener); + bool _listener_add(Listener *p_listener); //true if first + void _listener_remove(Listener *p_listener); + void _listener_make_next_current(Listener *p_exclude); -friend class Camera; + friend class Camera; void _camera_transform_changed_notify(); - void _camera_set(Camera* p_camera); - bool _camera_add(Camera* p_camera); //true if first - void _camera_remove(Camera* p_camera); - void _camera_make_next_current(Camera* p_exclude); - + void _camera_set(Camera *p_camera); + bool _camera_add(Camera *p_camera); //true if first + void _camera_remove(Camera *p_camera); + void _camera_make_next_current(Camera *p_exclude); protected: void _notification(int p_what); static void _bind_methods(); -public: - Listener* get_listener() const; - Camera* get_camera() const; +public: + Listener *get_listener() const; + Camera *get_camera() const; void set_as_audio_listener(bool p_enable); bool is_audio_listener() const; @@ -299,24 +283,23 @@ public: void set_as_audio_listener_2d(bool p_enable); bool is_audio_listener_2d() const; - void set_rect(const Rect2& p_rect); + void set_rect(const Rect2 &p_rect); Rect2 get_rect() const; Rect2 get_visible_rect() const; RID get_viewport() const; - void set_world(const Ref<World>& p_world); - void set_world_2d(const Ref<World2D>& p_world_2d); + void set_world(const Ref<World> &p_world); + void set_world_2d(const Ref<World2D> &p_world_2d); Ref<World> get_world() const; Ref<World> find_world() const; Ref<World2D> get_world_2d() const; Ref<World2D> find_world_2d() const; - - void set_canvas_transform(const Matrix32& p_transform); + void set_canvas_transform(const Matrix32 &p_transform); Matrix32 get_canvas_transform() const; - void set_global_canvas_transform(const Matrix32& p_transform); + void set_global_canvas_transform(const Matrix32 &p_transform); Matrix32 get_global_canvas_transform() const; Matrix32 get_final_transform() const; @@ -324,8 +307,7 @@ public: void set_transparent_background(bool p_enable); bool has_transparent_background() const; - - void set_size_override(bool p_enable,const Size2& p_size=Size2(-1,-1),const Vector2& p_margin=Vector2()); + void set_size_override(bool p_enable, const Size2 &p_size = Size2(-1, -1), const Vector2 &p_margin = Vector2()); Size2 get_size_override() const; bool is_size_override_enabled() const; void set_size_override_stretch(bool p_enable); @@ -351,8 +333,7 @@ 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_coords(const Vector2 &p_viewport_coords) const; Vector2 get_camera_rect_size() const; void queue_screen_capture(); @@ -361,17 +342,17 @@ public: void set_use_own_world(bool p_world); bool is_using_own_world() const; - void input(const InputEvent& p_event); - void unhandled_input(const InputEvent& p_event); + void input(const InputEvent &p_event); + void unhandled_input(const InputEvent &p_event); void set_disable_input(bool p_disable); bool is_input_disabled() const; - void set_render_target_to_screen_rect(const Rect2& p_rect); + void set_render_target_to_screen_rect(const Rect2 &p_rect); Rect2 get_render_target_to_screen_rect() const; Vector2 get_mouse_pos() const; - void warp_mouse(const Vector2& p_pos); + void warp_mouse(const Vector2 &p_pos); void set_physics_object_picking(bool p_enable); bool get_physics_object_picking(); @@ -385,7 +366,6 @@ public: Viewport(); ~Viewport(); - }; VARIANT_ENUM_CAST(Viewport::RenderTargetUpdateMode); |
