summaryrefslogtreecommitdiff
path: root/scene/main
diff options
context:
space:
mode:
Diffstat (limited to 'scene/main')
-rw-r--r--scene/main/canvas_layer.cpp167
-rw-r--r--scene/main/canvas_layer.h15
-rw-r--r--scene/main/http_request.cpp377
-rw-r--r--scene/main/http_request.h21
-rw-r--r--scene/main/instance_placeholder.cpp51
-rw-r--r--scene/main/instance_placeholder.h13
-rw-r--r--scene/main/node.cpp1848
-rw-r--r--scene/main/node.h209
-rw-r--r--scene/main/resource_preloader.cpp101
-rw-r--r--scene/main/resource_preloader.h21
-rw-r--r--scene/main/scene_main_loop.cpp1417
-rw-r--r--scene/main/scene_main_loop.h246
-rw-r--r--scene/main/timer.cpp82
-rw-r--r--scene/main/timer.h7
-rw-r--r--scene/main/viewport.cpp1515
-rw-r--r--scene/main/viewport.h157
16 files changed, 2797 insertions, 3450 deletions
diff --git a/scene/main/canvas_layer.cpp b/scene/main/canvas_layer.cpp
index 04d72b5a3d..1fecb6fd9a 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 Transform2D& p_xform) {
+void CanvasLayer::set_transform(const Transform2D &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);
}
Transform2D CanvasLayer::get_transform() const {
@@ -59,56 +56,50 @@ Transform2D 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_rid();
-
- 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_rid();
+ 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,42 +196,40 @@ 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_rid();
- 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::reset_sort_index() {
- sort_index=0;
+ sort_index = 0;
}
int CanvasLayer::get_sort_index() {
@@ -255,55 +237,52 @@ int CanvasLayer::get_sort_index() {
return sort_index++;
}
-
void CanvasLayer::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_layer", "layer"), &CanvasLayer::set_layer);
+ ClassDB::bind_method(D_METHOD("get_layer"), &CanvasLayer::get_layer);
- ClassDB::bind_method(D_METHOD("set_layer","layer"),&CanvasLayer::set_layer);
- ClassDB::bind_method(D_METHOD("get_layer"),&CanvasLayer::get_layer);
+ ClassDB::bind_method(D_METHOD("set_transform", "transform"), &CanvasLayer::set_transform);
+ ClassDB::bind_method(D_METHOD("get_transform"), &CanvasLayer::get_transform);
- ClassDB::bind_method(D_METHOD("set_transform","transform"),&CanvasLayer::set_transform);
- ClassDB::bind_method(D_METHOD("get_transform"),&CanvasLayer::get_transform);
+ ClassDB::bind_method(D_METHOD("set_offset", "offset"), &CanvasLayer::set_offset);
+ ClassDB::bind_method(D_METHOD("get_offset"), &CanvasLayer::get_offset);
- ClassDB::bind_method(D_METHOD("set_offset","offset"),&CanvasLayer::set_offset);
- ClassDB::bind_method(D_METHOD("get_offset"),&CanvasLayer::get_offset);
+ ClassDB::bind_method(D_METHOD("set_rotation", "radians"), &CanvasLayer::set_rotation);
+ ClassDB::bind_method(D_METHOD("get_rotation"), &CanvasLayer::get_rotation);
- ClassDB::bind_method(D_METHOD("set_rotation","radians"),&CanvasLayer::set_rotation);
- ClassDB::bind_method(D_METHOD("get_rotation"),&CanvasLayer::get_rotation);
-
- ClassDB::bind_method(D_METHOD("set_rotationd","degrees"),&CanvasLayer::set_rotationd);
- ClassDB::bind_method(D_METHOD("get_rotationd"),&CanvasLayer::get_rotationd);
+ ClassDB::bind_method(D_METHOD("set_rotationd", "degrees"), &CanvasLayer::set_rotationd);
+ ClassDB::bind_method(D_METHOD("get_rotationd"), &CanvasLayer::get_rotationd);
// TODO: Obsolete those two methods (old name) properly (GH-4397)
- ClassDB::bind_method(D_METHOD("_set_rotationd","degrees"),&CanvasLayer::_set_rotationd);
- ClassDB::bind_method(D_METHOD("_get_rotationd"),&CanvasLayer::_get_rotationd);
+ ClassDB::bind_method(D_METHOD("_set_rotationd", "degrees"), &CanvasLayer::_set_rotationd);
+ ClassDB::bind_method(D_METHOD("_get_rotationd"), &CanvasLayer::_get_rotationd);
- ClassDB::bind_method(D_METHOD("set_scale","scale"),&CanvasLayer::set_scale);
- ClassDB::bind_method(D_METHOD("get_scale"),&CanvasLayer::get_scale);
+ ClassDB::bind_method(D_METHOD("set_scale", "scale"), &CanvasLayer::set_scale);
+ ClassDB::bind_method(D_METHOD("get_scale"), &CanvasLayer::get_scale);
- ClassDB::bind_method(D_METHOD("set_custom_viewport","viewport:Viewport"),&CanvasLayer::set_custom_viewport);
- ClassDB::bind_method(D_METHOD("get_custom_viewport:Viewport"),&CanvasLayer::get_custom_viewport);
+ ClassDB::bind_method(D_METHOD("set_custom_viewport", "viewport:Viewport"), &CanvasLayer::set_custom_viewport);
+ ClassDB::bind_method(D_METHOD("get_custom_viewport:Viewport"), &CanvasLayer::get_custom_viewport);
- ClassDB::bind_method(D_METHOD("get_world_2d:World2D"),&CanvasLayer::get_world_2d);
+ ClassDB::bind_method(D_METHOD("get_world_2d:World2D"), &CanvasLayer::get_world_2d);
//ClassDB::bind_method(D_METHOD("get_viewport"),&CanvasLayer::get_viewport);
- ADD_PROPERTY( PropertyInfo(Variant::INT,"layer",PROPERTY_HINT_RANGE,"-128,128,1"),"set_layer","get_layer") ;
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "layer", PROPERTY_HINT_RANGE, "-128,128,1"), "set_layer", "get_layer");
//ADD_PROPERTY( PropertyInfo(Variant::MATRIX32,"transform",PROPERTY_HINT_RANGE),"set_transform","get_transform") ;
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"offset"),"set_offset","get_offset") ;
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"rotation"),"set_rotationd","get_rotationd") ;
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"scale"),"set_scale","get_scale") ;
-
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset"), "set_offset", "get_offset");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "rotation"), "set_rotationd", "get_rotationd");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scale"), "set_scale", "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;
- sort_index=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;
+ sort_index = 0;
}
diff --git a/scene/main/canvas_layer.h b/scene/main/canvas_layer.h
index 8efbbd5a05..26d21e3a0f 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 {
- GDCLASS( CanvasLayer, Node );
+ GDCLASS(CanvasLayer, Node);
bool locrotscale_dirty;
Vector2 ofs;
@@ -61,20 +60,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 Transform2D& p_xform);
+ void set_transform(const Transform2D &p_xform);
Transform2D 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);
@@ -83,7 +80,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;
@@ -93,7 +90,7 @@ public:
RID get_viewport() const;
void set_custom_viewport(Node *p_viewport);
- Node* get_custom_viewport() const;
+ Node *get_custom_viewport() const;
void reset_sort_index();
int get_sort_index();
diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp
index 77b08fd58b..38ee03ab47 100644
--- a/scene/main/http_request.cpp
+++ b/scene/main/http_request.cpp
@@ -28,41 +28,39 @@
/*************************************************************************/
#include "http_request.h"
-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_to_host(url,port,use_ssl,validate_ssl);
+ return client->connect_to_host(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");
@@ -73,22 +71,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);
@@ -96,79 +94,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,PoolStringArray(),PoolByteArray());
+ if (err != OK) {
+ call_deferred("_request_done", RESULT_CANT_CONNECT, 0, PoolStringArray(), PoolByteArray());
return ERR_CANT_CONNECT;
}
set_process_internal(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,PoolStringArray(),PoolByteArray());
+ if (err != OK) {
+ hr->call_deferred("_request_done", RESULT_CANT_CONNECT, 0, PoolStringArray(), PoolByteArray());
} else {
- while(!hr->thread_request_quit) {
+ while (!hr->thread_request_quit) {
bool exit = hr->_update_connection();
if (exit)
@@ -177,7 +172,7 @@ void HTTPRequest::_thread_func(void *p_userdata) {
}
}
- hr->thread_done=true;
+ hr->thread_done = true;
}
void HTTPRequest::cancel_request() {
@@ -188,90 +183,88 @@ void HTTPRequest::cancel_request() {
if (!use_threads) {
set_process_internal(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,PoolStringArray(),PoolByteArray());
- *ret_value=true;
+ call_deferred("_request_done", RESULT_NO_RESPONSE, 0, PoolStringArray(), PoolByteArray());
+ *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,PoolByteArray());
- *ret_value=true;
+ call_deferred("_request_done", RESULT_REDIRECT_LIMIT_REACHED, response_code, response_headers, PoolByteArray());
+ *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;
-
}
}
}
@@ -279,12 +272,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,PoolStringArray(),PoolByteArray());
+ call_deferred("_request_done", RESULT_CANT_CONNECT, 0, PoolStringArray(), PoolByteArray());
return true; //end it, since it's doing something
} break;
case HTTPClient::STATUS_RESOLVING: {
@@ -293,7 +285,7 @@ bool HTTPRequest::_update_connection() {
return false;
} break;
case HTTPClient::STATUS_CANT_RESOLVE: {
- call_deferred("_request_done",RESULT_CANT_RESOLVE,0,PoolStringArray(),PoolByteArray());
+ call_deferred("_request_done", RESULT_CANT_RESOLVE, 0, PoolStringArray(), PoolByteArray());
return true;
} break;
@@ -304,7 +296,7 @@ bool HTTPRequest::_update_connection() {
} break; //connecting to ip
case HTTPClient::STATUS_CANT_CONNECT: {
- call_deferred("_request_done",RESULT_CANT_CONNECT,0,PoolStringArray(),PoolByteArray());
+ call_deferred("_request_done", RESULT_CANT_CONNECT, 0, PoolStringArray(), PoolByteArray());
return true;
} break;
@@ -321,30 +313,28 @@ bool HTTPRequest::_update_connection() {
if (_handle_response(&ret_value))
return ret_value;
-
- call_deferred("_request_done",RESULT_SUCCESS,response_code,response_headers,PoolByteArray());
+ call_deferred("_request_done", RESULT_SUCCESS, response_code, response_headers, PoolByteArray());
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,PoolByteArray());
+ call_deferred("_request_done", RESULT_CHUNKED_BODY_SIZE_MISMATCH, response_code, response_headers, PoolByteArray());
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,PoolStringArray(),PoolByteArray());
+ Error err = client->request(method, request_string, headers, request_data);
+ if (err != OK) {
+ call_deferred("_request_done", RESULT_CONNECTION_ERROR, 0, PoolStringArray(), PoolByteArray());
return true;
}
- request_sent=true;
+ request_sent = true;
return false;
}
} break; //connected: { } break requests only accepted here
@@ -358,67 +348,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,PoolByteArray());
+ call_deferred("_request_done", RESULT_SUCCESS, response_code, response_headers, PoolByteArray());
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,PoolByteArray());
+ if (body_size_limit >= 0 && body_len > body_size_limit) {
+ call_deferred("_request_done", RESULT_BODY_SIZE_LIMIT_EXCEEDED, response_code, response_headers, PoolByteArray());
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,PoolByteArray());
+ call_deferred("_request_done", RESULT_DOWNLOAD_FILE_CANT_OPEN, response_code, response_headers, PoolByteArray());
return true;
}
}
}
-
//print_line("BODY: "+itos(body.size()));
client->poll();
PoolByteArray chunk = client->read_response_body_chunk();
- downloaded+=chunk.size();
+ downloaded += chunk.size();
if (file) {
- PoolByteArray::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,PoolByteArray());
+ PoolByteArray::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, PoolByteArray());
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,PoolByteArray());
+ if (body_size_limit >= 0 && downloaded > body_size_limit) {
+ call_deferred("_request_done", RESULT_BODY_SIZE_LIMIT_EXCEEDED, response_code, response_headers, PoolByteArray());
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) {
@@ -431,31 +418,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,PoolStringArray(),PoolByteArray());
+ call_deferred("_request_done", RESULT_CONNECTION_ERROR, 0, PoolStringArray(), PoolByteArray());
return true;
} break;
case HTTPClient::STATUS_SSL_HANDSHAKE_ERROR: {
- call_deferred("_request_done",RESULT_SSL_HANDSHAKE_ERROR,0,PoolStringArray(),PoolByteArray());
+ call_deferred("_request_done", RESULT_SSL_HANDSHAKE_ERROR, 0, PoolStringArray(), PoolByteArray());
return true;
} break;
-
}
ERR_FAIL_V(false);
}
-
-void HTTPRequest::_request_done(int p_status, int p_code, const PoolStringArray& headers, const PoolByteArray& p_data) {
-
+void HTTPRequest::_request_done(int p_status, int p_code, const PoolStringArray &headers, const PoolByteArray &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_INTERNAL_PROCESS) {
+ if (p_what == NOTIFICATION_INTERNAL_PROCESS) {
if (use_threads)
return;
@@ -467,18 +450,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 {
@@ -488,9 +470,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 {
@@ -498,12 +480,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 {
@@ -516,10 +497,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;
}
@@ -528,80 +509,76 @@ 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() {
- ClassDB::bind_method(D_METHOD("request","url","custom_headers","ssl_validate_domain","method","request_data"),&HTTPRequest::request,DEFVAL(PoolStringArray()),DEFVAL(true),DEFVAL(HTTPClient::METHOD_GET),DEFVAL(String()));
- ClassDB::bind_method(D_METHOD("cancel_request"),&HTTPRequest::cancel_request);
+ ClassDB::bind_method(D_METHOD("request", "url", "custom_headers", "ssl_validate_domain", "method", "request_data"), &HTTPRequest::request, DEFVAL(PoolStringArray()), DEFVAL(true), DEFVAL(HTTPClient::METHOD_GET), DEFVAL(String()));
+ ClassDB::bind_method(D_METHOD("cancel_request"), &HTTPRequest::cancel_request);
- ClassDB::bind_method(D_METHOD("get_http_client_status"),&HTTPRequest::get_http_client_status);
+ ClassDB::bind_method(D_METHOD("get_http_client_status"), &HTTPRequest::get_http_client_status);
- ClassDB::bind_method(D_METHOD("set_use_threads","enable"),&HTTPRequest::set_use_threads);
- ClassDB::bind_method(D_METHOD("is_using_threads"),&HTTPRequest::is_using_threads);
+ ClassDB::bind_method(D_METHOD("set_use_threads", "enable"), &HTTPRequest::set_use_threads);
+ ClassDB::bind_method(D_METHOD("is_using_threads"), &HTTPRequest::is_using_threads);
- ClassDB::bind_method(D_METHOD("set_body_size_limit","bytes"),&HTTPRequest::set_body_size_limit);
- ClassDB::bind_method(D_METHOD("get_body_size_limit"),&HTTPRequest::get_body_size_limit);
+ ClassDB::bind_method(D_METHOD("set_body_size_limit", "bytes"), &HTTPRequest::set_body_size_limit);
+ ClassDB::bind_method(D_METHOD("get_body_size_limit"), &HTTPRequest::get_body_size_limit);
- ClassDB::bind_method(D_METHOD("set_max_redirects","amount"),&HTTPRequest::set_max_redirects);
- ClassDB::bind_method(D_METHOD("get_max_redirects"),&HTTPRequest::get_max_redirects);
+ ClassDB::bind_method(D_METHOD("set_max_redirects", "amount"), &HTTPRequest::set_max_redirects);
+ ClassDB::bind_method(D_METHOD("get_max_redirects"), &HTTPRequest::get_max_redirects);
- ClassDB::bind_method(D_METHOD("set_download_file","path"),&HTTPRequest::set_download_file);
- ClassDB::bind_method(D_METHOD("get_download_file"),&HTTPRequest::get_download_file);
+ ClassDB::bind_method(D_METHOD("set_download_file", "path"), &HTTPRequest::set_download_file);
+ ClassDB::bind_method(D_METHOD("get_download_file"), &HTTPRequest::get_download_file);
- ClassDB::bind_method(D_METHOD("get_downloaded_bytes"),&HTTPRequest::get_downloaded_bytes);
- ClassDB::bind_method(D_METHOD("get_body_size"),&HTTPRequest::get_body_size);
+ ClassDB::bind_method(D_METHOD("get_downloaded_bytes"), &HTTPRequest::get_downloaded_bytes);
+ ClassDB::bind_method(D_METHOD("get_body_size"), &HTTPRequest::get_body_size);
- ClassDB::bind_method(D_METHOD("_redirect_request"),&HTTPRequest::_redirect_request);
- ClassDB::bind_method(D_METHOD("_request_done"),&HTTPRequest::_request_done);
+ ClassDB::bind_method(D_METHOD("_redirect_request"), &HTTPRequest::_redirect_request);
+ ClassDB::bind_method(D_METHOD("_request_done"), &HTTPRequest::_request_done);
- ADD_PROPERTY(PropertyInfo(Variant::BOOL,"use_threads"),"set_use_threads","is_using_threads");
- ADD_PROPERTY(PropertyInfo(Variant::INT,"body_size_limit",PROPERTY_HINT_RANGE,"-1,2000000000"),"set_body_size_limit","get_body_size_limit");
- ADD_PROPERTY(PropertyInfo(Variant::INT,"max_redirects",PROPERTY_HINT_RANGE,"-1,1024"),"set_max_redirects","get_max_redirects");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_threads"), "set_use_threads", "is_using_threads");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "body_size_limit", PROPERTY_HINT_RANGE, "-1,2000000000"), "set_body_size_limit", "get_body_size_limit");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "max_redirects", PROPERTY_HINT_RANGE, "-1,1024"), "set_max_redirects", "get_max_redirects");
- ADD_SIGNAL(MethodInfo("request_completed",PropertyInfo(Variant::INT,"result"),PropertyInfo(Variant::INT,"response_code"),PropertyInfo(Variant::POOL_STRING_ARRAY,"headers"),PropertyInfo(Variant::POOL_BYTE_ARRAY,"body")));
+ ADD_SIGNAL(MethodInfo("request_completed", PropertyInfo(Variant::INT, "result"), PropertyInfo(Variant::INT, "response_code"), PropertyInfo(Variant::POOL_STRING_ARRAY, "headers"), PropertyInfo(Variant::POOL_BYTE_ARRAY, "body")));
- BIND_CONSTANT( RESULT_SUCCESS );
+ BIND_CONSTANT(RESULT_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()
-{
-
- 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;
- client.instance();
- use_threads=false;
- thread_done=false;
- body_size_limit=-1;
- file=NULL;
- status=HTTPClient::STATUS_DISCONNECTED;
+HTTPRequest::HTTPRequest() {
+
+ 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;
+ client.instance();
+ 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 a9c495fd81..2b2d7f9a38 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 {
- GDCLASS(HTTPRequest,Node);
-public:
+ GDCLASS(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,23 +105,22 @@ private:
Thread *thread;
- void _request_done(int p_status, int p_code, const PoolStringArray& headers, const PoolByteArray& p_data);
+ void _request_done(int p_status, int p_code, const PoolStringArray &headers, const PoolByteArray &p_data);
static void _thread_func(void *p_userdata);
protected:
-
void _notification(int p_what);
static void _bind_methods();
-public:
- 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
+public:
+ 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 935811009b..469a5e9441 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;
PoolStringArray 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() {
- ClassDB::bind_method(D_METHOD("get_stored_values","with_order"),&InstancePlaceholder::get_stored_values,DEFVAL(false));
- ClassDB::bind_method(D_METHOD("replace_by_instance","custom_scene:PackedScene"),&InstancePlaceholder::replace_by_instance,DEFVAL(Variant()));
- ClassDB::bind_method(D_METHOD("get_instance_path"),&InstancePlaceholder::get_instance_path);
+ ClassDB::bind_method(D_METHOD("get_stored_values", "with_order"), &InstancePlaceholder::get_stored_values, DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("replace_by_instance", "custom_scene:PackedScene"), &InstancePlaceholder::replace_by_instance, DEFVAL(Variant()));
+ ClassDB::bind_method(D_METHOD("get_instance_path"), &InstancePlaceholder::get_instance_path);
}
InstancePlaceholder::InstancePlaceholder() {
-
-
}
diff --git a/scene/main/instance_placeholder.h b/scene/main/instance_placeholder.h
index 069b1c9756..7900e35b00 100644
--- a/scene/main/instance_placeholder.h
+++ b/scene/main/instance_placeholder.h
@@ -35,7 +35,7 @@ class PackedScene;
class InstancePlaceholder : public Node {
- GDCLASS(InstancePlaceholder,Node);
+ GDCLASS(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 a189702894..864e26a651 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -27,75 +27,71 @@
/* 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);
VARIANT_ENUM_CAST(Node::NetworkMode);
VARIANT_ENUM_CAST(Node::RPCMode);
-
-
-
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.network_mode==NETWORK_MODE_INHERIT) {
+ if (data.network_mode == NETWORK_MODE_INHERIT) {
if (data.parent)
- data.network_owner=data.parent->data.network_owner;
+ data.network_owner = data.parent->data.network_owner;
else
- data.network_owner=NULL;
+ data.network_owner = NULL;
} else {
- data.network_owner=this;
+ data.network_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++;
@@ -104,25 +100,24 @@ 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()));
- data.pause_owner=NULL;
- data.network_owner=NULL;
+ data.pause_owner = NULL;
+ data.network_owner = NULL;
if (data.path_cache) {
memdelete(data.path_cache);
- data.path_cache=NULL;
+ data.path_cache = NULL;
}
} break;
case NOTIFICATION_PATH_CHANGED: {
if (data.path_cache) {
memdelete(data.path_cache);
- data.path_cache=NULL;
+ data.path_cache = NULL;
}
} break;
case NOTIFICATION_READY: {
@@ -150,19 +145,19 @@ void Node::_notification(int p_notification) {
}
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);
}
@@ -173,72 +168,67 @@ 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--;
if (data.ready_first) {
notification(NOTIFICATION_READY);
- data.ready_first=false;
+ data.ready_first = false;
}
-
}
-
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()->tree_entered);
-
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();
@@ -248,7 +238,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);
}
@@ -256,27 +246,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());
}
@@ -286,7 +274,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();
}
@@ -296,59 +284,52 @@ 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()->tree_exited);
- 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.ready_notified=false;
- data.tree=NULL;
- data.depth=-1;
-
+ data.inside_tree = false;
+ data.ready_notified = 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);
}
-
- if (p_child->data.pos==p_pos)
+ if (p_child->data.pos == p_pos)
return; //do nothing
- int motion_from = MIN(p_pos,p_child->data.pos);
- int motion_to = MAX(p_pos,p_child->data.pos);
+ int motion_from = MIN(p_pos, p_child->data.pos);
+ int motion_to = MAX(p_pos, p_child->data.pos);
- 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();
@@ -356,22 +337,20 @@ void Node::move_child(Node *p_child,int p_pos) {
data.blocked++;
//new pos first
- for (int i=motion_from;i<=motion_to;i++) {
+ for (int i = motion_from; i <= motion_to; i++) {
- data.children[i]->data.pos=i;
+ data.children[i]->data.pos = i;
}
// notification second
move_child_notify(p_child);
- for (int i=motion_from;i<=motion_to;i++) {
- data.children[i]->notification( NOTIFICATION_MOVED_IN_PARENT );
-
+ for (int i = motion_from; i <= motion_to; 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() {
@@ -379,8 +358,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) {
@@ -412,17 +390,17 @@ 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");
}
@@ -433,17 +411,17 @@ bool Node::is_fixed_processing() const {
void Node::set_fixed_process_internal(bool p_process_internal) {
- if (data.fixed_process_internal==p_process_internal)
+ if (data.fixed_process_internal == p_process_internal)
return;
- data.fixed_process_internal=p_process_internal;
+ data.fixed_process_internal = p_process_internal;
if (data.fixed_process_internal)
- add_to_group("fixed_process_internal",false);
+ add_to_group("fixed_process_internal", false);
else
remove_from_group("fixed_process_internal");
- data.fixed_process_internal=p_process_internal;
+ data.fixed_process_internal = p_process_internal;
_change_notify("fixed_process_internal");
}
@@ -452,33 +430,29 @@ bool Node::is_fixed_processing_internal() const {
return data.fixed_process_internal;
}
-
void Node::set_pause_mode(PauseMode p_mode) {
- if (data.pause_mode==p_mode)
+ 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 {
@@ -486,12 +460,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);
}
@@ -499,30 +473,27 @@ void Node::_propagate_pause_owner(Node*p_owner) {
void Node::set_network_mode(NetworkMode p_mode) {
- if (data.network_mode==p_mode)
+ if (data.network_mode == p_mode)
return;
- bool prev_inherits=data.network_mode==NETWORK_MODE_INHERIT;
- data.network_mode=p_mode;
+ bool prev_inherits = data.network_mode == NETWORK_MODE_INHERIT;
+ data.network_mode = p_mode;
if (!is_inside_tree())
return; //pointless
- if ((data.network_mode==NETWORK_MODE_INHERIT) == prev_inherits)
+ if ((data.network_mode == NETWORK_MODE_INHERIT) == prev_inherits)
return; ///nothing changed
- Node *owner=NULL;
+ Node *owner = NULL;
- if (data.network_mode==NETWORK_MODE_INHERIT) {
+ if (data.network_mode == NETWORK_MODE_INHERIT) {
if (data.parent)
- owner=data.parent->data.network_owner;
+ owner = data.parent->data.network_owner;
} else {
- owner=this;
+ owner = this;
}
_propagate_network_owner(owner);
-
-
-
}
Node::NetworkMode Node::get_network_mode() const {
@@ -532,9 +503,9 @@ Node::NetworkMode Node::get_network_mode() const {
bool Node::is_network_master() const {
- ERR_FAIL_COND_V(!is_inside_tree(),false);
+ ERR_FAIL_COND_V(!is_inside_tree(), false);
- switch(data.network_mode) {
+ switch (data.network_mode) {
case NETWORK_MODE_INHERIT: {
if (data.network_owner)
@@ -554,14 +525,12 @@ bool Node::is_network_master() const {
return false;
}
+void Node::_propagate_network_owner(Node *p_owner) {
-
-void Node::_propagate_network_owner(Node*p_owner) {
-
- if (data.network_mode!=NETWORK_MODE_INHERIT)
+ if (data.network_mode != NETWORK_MODE_INHERIT)
return;
- data.network_owner=p_owner;
- for(int i=0;i<data.children.size();i++) {
+ data.network_owner = p_owner;
+ for (int i = 0; i < data.children.size(); i++) {
data.children[i]->_propagate_network_owner(p_owner);
}
@@ -569,194 +538,187 @@ void Node::_propagate_network_owner(Node*p_owner) {
/***** RPC CONFIG ********/
-void Node::rpc_config(const StringName& p_method,RPCMode p_mode) {
+void Node::rpc_config(const StringName &p_method, RPCMode p_mode) {
- if (p_mode==RPC_MODE_DISABLED) {
+ if (p_mode == RPC_MODE_DISABLED) {
data.rpc_methods.erase(p_method);
} else {
- data.rpc_methods[p_method]=p_mode;
+ data.rpc_methods[p_method] = p_mode;
};
}
-void Node::rset_config(const StringName& p_property,RPCMode p_mode) {
+void Node::rset_config(const StringName &p_property, RPCMode p_mode) {
- if (p_mode==RPC_MODE_DISABLED) {
+ if (p_mode == RPC_MODE_DISABLED) {
data.rpc_properties.erase(p_property);
} else {
- data.rpc_properties[p_property]=p_mode;
+ data.rpc_properties[p_property] = p_mode;
};
}
/***** RPC FUNCTIONS ********/
-void Node::rpc(const StringName& p_method,VARIANT_ARG_DECLARE) {
+void Node::rpc(const StringName &p_method, VARIANT_ARG_DECLARE) {
VARIANT_ARGPTRS;
- int argc=0;
- for(int i=0;i<VARIANT_ARG_MAX;i++) {
- if (argptr[i]->get_type()==Variant::NIL)
+ int argc = 0;
+ for (int i = 0; i < VARIANT_ARG_MAX; i++) {
+ if (argptr[i]->get_type() == Variant::NIL)
break;
argc++;
}
- rpcp(0,false,p_method,argptr,argc);
+ rpcp(0, false, p_method, argptr, argc);
}
-
-void Node::rpc_id(int p_peer_id,const StringName& p_method,VARIANT_ARG_DECLARE) {
+void Node::rpc_id(int p_peer_id, const StringName &p_method, VARIANT_ARG_DECLARE) {
VARIANT_ARGPTRS;
- int argc=0;
- for(int i=0;i<VARIANT_ARG_MAX;i++) {
- if (argptr[i]->get_type()==Variant::NIL)
+ int argc = 0;
+ for (int i = 0; i < VARIANT_ARG_MAX; i++) {
+ if (argptr[i]->get_type() == Variant::NIL)
break;
argc++;
}
- rpcp(p_peer_id,false,p_method,argptr,argc);
+ rpcp(p_peer_id, false, p_method, argptr, argc);
}
-
-void Node::rpc_unreliable(const StringName& p_method,VARIANT_ARG_DECLARE) {
+void Node::rpc_unreliable(const StringName &p_method, VARIANT_ARG_DECLARE) {
VARIANT_ARGPTRS;
- int argc=0;
- for(int i=0;i<VARIANT_ARG_MAX;i++) {
- if (argptr[i]->get_type()==Variant::NIL)
+ int argc = 0;
+ for (int i = 0; i < VARIANT_ARG_MAX; i++) {
+ if (argptr[i]->get_type() == Variant::NIL)
break;
argc++;
}
- rpcp(0,true,p_method,argptr,argc);
+ rpcp(0, true, p_method, argptr, argc);
}
-
-void Node::rpc_unreliable_id(int p_peer_id,const StringName& p_method,VARIANT_ARG_DECLARE) {
+void Node::rpc_unreliable_id(int p_peer_id, const StringName &p_method, VARIANT_ARG_DECLARE) {
VARIANT_ARGPTRS;
- int argc=0;
- for(int i=0;i<VARIANT_ARG_MAX;i++) {
- if (argptr[i]->get_type()==Variant::NIL)
+ int argc = 0;
+ for (int i = 0; i < VARIANT_ARG_MAX; i++) {
+ if (argptr[i]->get_type() == Variant::NIL)
break;
argc++;
}
- rpcp(p_peer_id,true,p_method,argptr,argc);
+ rpcp(p_peer_id, true, p_method, argptr, argc);
}
+Variant Node::_rpc_bind(const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
-Variant Node::_rpc_bind(const Variant** p_args, int p_argcount, Variant::CallError& r_error) {
-
- if (p_argcount<1) {
- r_error.error=Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
- r_error.argument=1;
+ if (p_argcount < 1) {
+ r_error.error = Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
+ r_error.argument = 1;
return Variant();
}
- if (p_args[0]->get_type()!=Variant::STRING) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::STRING;
+ if (p_args[0]->get_type() != Variant::STRING) {
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::STRING;
return Variant();
}
StringName method = *p_args[0];
- rpcp(0,false,method,&p_args[1],p_argcount-1);
+ rpcp(0, false, method, &p_args[1], p_argcount - 1);
- r_error.error=Variant::CallError::CALL_OK;
+ r_error.error = Variant::CallError::CALL_OK;
return Variant();
}
+Variant Node::_rpc_id_bind(const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
-Variant Node::_rpc_id_bind(const Variant** p_args, int p_argcount, Variant::CallError& r_error) {
-
- if (p_argcount<2) {
- r_error.error=Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
- r_error.argument=2;
+ if (p_argcount < 2) {
+ r_error.error = Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
+ r_error.argument = 2;
return Variant();
}
- if (p_args[0]->get_type()!=Variant::INT) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::INT;
+ if (p_args[0]->get_type() != Variant::INT) {
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::INT;
return Variant();
}
- if (p_args[1]->get_type()!=Variant::STRING) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=1;
- r_error.expected=Variant::STRING;
+ if (p_args[1]->get_type() != Variant::STRING) {
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 1;
+ r_error.expected = Variant::STRING;
return Variant();
}
int peer_id = *p_args[0];
StringName method = *p_args[1];
- rpcp(peer_id,false,method,&p_args[2],p_argcount-2);
+ rpcp(peer_id, false, method, &p_args[2], p_argcount - 2);
- r_error.error=Variant::CallError::CALL_OK;
+ r_error.error = Variant::CallError::CALL_OK;
return Variant();
}
+Variant Node::_rpc_unreliable_bind(const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
-Variant Node::_rpc_unreliable_bind(const Variant** p_args, int p_argcount, Variant::CallError& r_error) {
-
- if (p_argcount<1) {
- r_error.error=Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
- r_error.argument=1;
+ if (p_argcount < 1) {
+ r_error.error = Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
+ r_error.argument = 1;
return Variant();
}
- if (p_args[0]->get_type()!=Variant::STRING) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::STRING;
+ if (p_args[0]->get_type() != Variant::STRING) {
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::STRING;
return Variant();
}
StringName method = *p_args[0];
- rpcp(0,true,method,&p_args[1],p_argcount-1);
+ rpcp(0, true, method, &p_args[1], p_argcount - 1);
- r_error.error=Variant::CallError::CALL_OK;
+ r_error.error = Variant::CallError::CALL_OK;
return Variant();
}
+Variant Node::_rpc_unreliable_id_bind(const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
-Variant Node::_rpc_unreliable_id_bind(const Variant** p_args, int p_argcount, Variant::CallError& r_error) {
-
- if (p_argcount<2) {
- r_error.error=Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
- r_error.argument=2;
+ if (p_argcount < 2) {
+ r_error.error = Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
+ r_error.argument = 2;
return Variant();
}
- if (p_args[0]->get_type()!=Variant::INT) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=0;
- r_error.expected=Variant::INT;
+ if (p_args[0]->get_type() != Variant::INT) {
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 0;
+ r_error.expected = Variant::INT;
return Variant();
}
- if (p_args[1]->get_type()!=Variant::STRING) {
- r_error.error=Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
- r_error.argument=1;
- r_error.expected=Variant::STRING;
+ if (p_args[1]->get_type() != Variant::STRING) {
+ r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT;
+ r_error.argument = 1;
+ r_error.expected = Variant::STRING;
return Variant();
}
int peer_id = *p_args[0];
StringName method = *p_args[1];
- rpcp(peer_id,true,method,&p_args[2],p_argcount-2);
+ rpcp(peer_id, true, method, &p_args[2], p_argcount - 2);
- r_error.error=Variant::CallError::CALL_OK;
+ r_error.error = Variant::CallError::CALL_OK;
return Variant();
}
@@ -785,24 +747,21 @@ Variant Node::_rpc_bind(const Variant** p_args, int p_argcount, Variant::CallErr
}
#endif
-void Node::rpcp(int p_peer_id,bool p_unreliable,const StringName& p_method,const Variant** p_arg,int p_argcount) {
+void Node::rpcp(int p_peer_id, bool p_unreliable, const StringName &p_method, const Variant **p_arg, int p_argcount) {
ERR_FAIL_COND(!is_inside_tree());
- bool skip_rpc=false;
+ bool skip_rpc = false;
- if (p_peer_id==0 || p_peer_id==get_tree()->get_network_unique_id() || (p_peer_id<0 && p_peer_id!=-get_tree()->get_network_unique_id())) {
+ if (p_peer_id == 0 || p_peer_id == get_tree()->get_network_unique_id() || (p_peer_id < 0 && p_peer_id != -get_tree()->get_network_unique_id())) {
//check that send mode can use local call
+ bool call_local = false;
- bool call_local=false;
-
-
-
- Map<StringName,RPCMode>::Element *E = data.rpc_methods.find(p_method);
+ Map<StringName, RPCMode>::Element *E = data.rpc_methods.find(p_method);
if (E) {
- switch(E->get()) {
+ switch (E->get()) {
case RPC_MODE_DISABLED: {
//do nothing
@@ -812,36 +771,34 @@ void Node::rpcp(int p_peer_id,bool p_unreliable,const StringName& p_method,const
} break;
case RPC_MODE_SYNC: {
//call it, sync always results in call
- call_local=true;
+ call_local = true;
} break;
case RPC_MODE_MASTER: {
- call_local=is_network_master();
+ call_local = is_network_master();
if (call_local) {
- skip_rpc=true; //no other master so..
+ skip_rpc = true; //no other master so..
}
} break;
case RPC_MODE_SLAVE: {
- call_local=!is_network_master();
+ call_local = !is_network_master();
} break;
-
}
}
-
if (call_local) {
Variant::CallError ce;
- call(p_method,p_arg,p_argcount,ce);
- if (ce.error!=Variant::CallError::CALL_OK) {
- String error = Variant::get_call_error_text(this,p_method,p_arg,p_argcount,ce);
- error="rpc() aborted in local call: - "+error;
+ call(p_method, p_arg, p_argcount, ce);
+ if (ce.error != Variant::CallError::CALL_OK) {
+ String error = Variant::get_call_error_text(this, p_method, p_arg, p_argcount, ce);
+ error = "rpc() aborted in local call: - " + error;
ERR_PRINTS(error);
return;
}
- } else if (get_script_instance()){
+ } else if (get_script_instance()) {
//attempt with script
ScriptInstance::RPCMode rpc_mode = get_script_instance()->get_rpc_mode(p_method);
- switch(rpc_mode) {
+ switch (rpc_mode) {
case ScriptInstance::RPC_MODE_DISABLED: {
//do nothing
@@ -851,26 +808,26 @@ void Node::rpcp(int p_peer_id,bool p_unreliable,const StringName& p_method,const
} break;
case ScriptInstance::RPC_MODE_SYNC: {
//call it, sync always results in call
- call_local=true;
+ call_local = true;
} break;
case ScriptInstance::RPC_MODE_MASTER: {
- call_local=is_network_master();
+ call_local = is_network_master();
if (call_local) {
- skip_rpc=true; //no other master so..
+ skip_rpc = true; //no other master so..
}
} break;
case ScriptInstance::RPC_MODE_SLAVE: {
- call_local=!is_network_master();
+ call_local = !is_network_master();
} break;
}
if (call_local) {
Variant::CallError ce;
- ce.error=Variant::CallError::CALL_OK;
- get_script_instance()->call(p_method,p_arg,p_argcount,ce);
- if (ce.error!=Variant::CallError::CALL_OK) {
- String error = Variant::get_call_error_text(this,p_method,p_arg,p_argcount,ce);
- error="rpc() aborted in script local call: - "+error;
+ ce.error = Variant::CallError::CALL_OK;
+ get_script_instance()->call(p_method, p_arg, p_argcount, ce);
+ if (ce.error != Variant::CallError::CALL_OK) {
+ String error = Variant::get_call_error_text(this, p_method, p_arg, p_argcount, ce);
+ error = "rpc() aborted in script local call: - " + error;
ERR_PRINTS(error);
return;
}
@@ -881,31 +838,26 @@ void Node::rpcp(int p_peer_id,bool p_unreliable,const StringName& p_method,const
if (skip_rpc)
return;
-
- get_tree()->_rpc(this,p_peer_id,p_unreliable,false,p_method,p_arg,p_argcount);
-
+ get_tree()->_rpc(this, p_peer_id, p_unreliable, false, p_method, p_arg, p_argcount);
}
-
/******** RSET *********/
-
-void Node::rsetp(int p_peer_id,bool p_unreliable,const StringName& p_property,const Variant& p_value) {
+void Node::rsetp(int p_peer_id, bool p_unreliable, const StringName &p_property, const Variant &p_value) {
ERR_FAIL_COND(!is_inside_tree());
- bool skip_rset=false;
+ bool skip_rset = false;
- if (p_peer_id==0 || p_peer_id==get_tree()->get_network_unique_id() || (p_peer_id<0 && p_peer_id!=-get_tree()->get_network_unique_id())) {
+ if (p_peer_id == 0 || p_peer_id == get_tree()->get_network_unique_id() || (p_peer_id < 0 && p_peer_id != -get_tree()->get_network_unique_id())) {
//check that send mode can use local call
+ bool set_local = false;
- bool set_local=false;
-
- Map<StringName,RPCMode>::Element *E = data.rpc_properties.find(p_property);
+ Map<StringName, RPCMode>::Element *E = data.rpc_properties.find(p_property);
if (E) {
- switch(E->get()) {
+ switch (E->get()) {
case RPC_MODE_DISABLED: {
//do nothing
@@ -915,37 +867,35 @@ void Node::rsetp(int p_peer_id,bool p_unreliable,const StringName& p_property,co
} break;
case RPC_MODE_SYNC: {
//call it, sync always results in call
- set_local=true;
+ set_local = true;
} break;
case RPC_MODE_MASTER: {
- set_local=is_network_master();
+ set_local = is_network_master();
if (set_local) {
- skip_rset=true;
+ skip_rset = true;
}
} break;
case RPC_MODE_SLAVE: {
- set_local=!is_network_master();
+ set_local = !is_network_master();
} break;
-
}
}
-
if (set_local) {
bool valid;
- set(p_property,p_value,&valid);
+ set(p_property, p_value, &valid);
if (!valid) {
- String error="rset() aborted in local set, property not found: - "+String(p_property);
+ String error = "rset() aborted in local set, property not found: - " + String(p_property);
ERR_PRINTS(error);
return;
}
- } else if (get_script_instance()){
+ } else if (get_script_instance()) {
//attempt with script
ScriptInstance::RPCMode rpc_mode = get_script_instance()->get_rset_mode(p_property);
- switch(rpc_mode) {
+ switch (rpc_mode) {
case ScriptInstance::RPC_MODE_DISABLED: {
//do nothing
@@ -955,76 +905,68 @@ void Node::rsetp(int p_peer_id,bool p_unreliable,const StringName& p_property,co
} break;
case ScriptInstance::RPC_MODE_SYNC: {
//call it, sync always results in call
- set_local=true;
+ set_local = true;
} break;
case ScriptInstance::RPC_MODE_MASTER: {
- set_local=is_network_master();
+ set_local = is_network_master();
if (set_local) {
- skip_rset=true;
+ skip_rset = true;
}
} break;
case ScriptInstance::RPC_MODE_SLAVE: {
- set_local=!is_network_master();
+ set_local = !is_network_master();
} break;
}
if (set_local) {
- bool valid = get_script_instance()->set(p_property,p_value);
+ bool valid = get_script_instance()->set(p_property, p_value);
if (!valid) {
- String error="rset() aborted in local script set, property not found: - "+String(p_property);
+ String error = "rset() aborted in local script set, property not found: - " + String(p_property);
ERR_PRINTS(error);
return;
}
}
-
}
}
if (skip_rset)
return;
- const Variant*vptr = &p_value;
-
- get_tree()->_rpc(this,p_peer_id,p_unreliable,true,p_property,&vptr,1);
+ const Variant *vptr = &p_value;
+ get_tree()->_rpc(this, p_peer_id, p_unreliable, true, p_property, &vptr, 1);
}
+void Node::rset(const StringName &p_property, const Variant &p_value) {
-
-void Node::rset(const StringName& p_property,const Variant& p_value) {
-
- rsetp(0,false,p_property,p_value);
-
+ rsetp(0, false, p_property, p_value);
}
-void Node::rset_id(int p_peer_id,const StringName& p_property,const Variant& p_value) {
-
- rsetp(p_peer_id,false,p_property,p_value);
+void Node::rset_id(int p_peer_id, const StringName &p_property, const Variant &p_value) {
+ rsetp(p_peer_id, false, p_property, p_value);
}
-void Node::rset_unreliable(const StringName& p_property,const Variant& p_value) {
-
- rsetp(0,true,p_property,p_value);
+void Node::rset_unreliable(const StringName &p_property, const Variant &p_value) {
+ rsetp(0, true, p_property, p_value);
}
-void Node::rset_unreliable_id(int p_peer_id,const StringName& p_property,const Variant& p_value) {
-
- rsetp(p_peer_id,true,p_property,p_value);
+void Node::rset_unreliable_id(int p_peer_id, const StringName &p_property, const Variant &p_value) {
+ rsetp(p_peer_id, true, p_property, p_value);
}
//////////// end of rpc
-bool Node::can_call_rpc(const StringName& p_method) const {
+bool Node::can_call_rpc(const StringName &p_method) const {
- const Map<StringName,RPCMode>::Element *E = data.rpc_methods.find(p_method);
+ const Map<StringName, RPCMode>::Element *E = data.rpc_methods.find(p_method);
if (E) {
- switch(E->get()) {
+ switch (E->get()) {
case RPC_MODE_DISABLED: {
return false;
@@ -1044,12 +986,11 @@ bool Node::can_call_rpc(const StringName& p_method) const {
}
}
-
- if (get_script_instance()){
+ if (get_script_instance()) {
//attempt with script
ScriptInstance::RPCMode rpc_mode = get_script_instance()->get_rpc_mode(p_method);
- switch(rpc_mode) {
+ switch (rpc_mode) {
case ScriptInstance::RPC_MODE_DISABLED: {
return false;
@@ -1067,19 +1008,18 @@ bool Node::can_call_rpc(const StringName& p_method) const {
return !is_network_master();
} break;
}
-
}
- ERR_PRINTS("RPC on unauthorized method attempted: "+String(p_method)+" on base: "+String(Variant(this)));
+ ERR_PRINTS("RPC on unauthorized method attempted: " + String(p_method) + " on base: " + String(Variant(this)));
return false;
}
-bool Node::can_call_rset(const StringName& p_property) const {
+bool Node::can_call_rset(const StringName &p_property) const {
- const Map<StringName,RPCMode>::Element *E = data.rpc_properties.find(p_property);
+ const Map<StringName, RPCMode>::Element *E = data.rpc_properties.find(p_property);
if (E) {
- switch(E->get()) {
+ switch (E->get()) {
case RPC_MODE_DISABLED: {
return false;
@@ -1099,12 +1039,11 @@ bool Node::can_call_rset(const StringName& p_property) const {
}
}
-
- if (get_script_instance()){
+ if (get_script_instance()) {
//attempt with script
ScriptInstance::RPCMode rpc_mode = get_script_instance()->get_rset_mode(p_property);
- switch(rpc_mode) {
+ switch (rpc_mode) {
case ScriptInstance::RPC_MODE_DISABLED: {
return false;
@@ -1122,43 +1061,39 @@ bool Node::can_call_rset(const StringName& p_property) const {
return !is_network_master();
} break;
}
-
}
- ERR_PRINTS("RSET on unauthorized property attempted: "+String(p_property)+" on base: "+String(Variant(this)));
+ ERR_PRINTS("RSET on unauthorized property attempted: " + String(p_property) + " on base: " + String(Variant(this)));
return false;
}
-
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)
@@ -1177,21 +1112,20 @@ float Node::get_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");
}
-
bool Node::is_processing() const {
return data.idle_process;
@@ -1199,17 +1133,17 @@ bool Node::is_processing() const {
void Node::set_process_internal(bool p_idle_process_internal) {
- if (data.idle_process_internal==p_idle_process_internal)
+ if (data.idle_process_internal == p_idle_process_internal)
return;
- data.idle_process_internal=p_idle_process_internal;
+ data.idle_process_internal = p_idle_process_internal;
if (data.idle_process_internal)
- add_to_group("idle_process_internal",false);
+ add_to_group("idle_process_internal", false);
else
remove_from_group("idle_process_internal");
- data.idle_process_internal=p_idle_process_internal;
+ data.idle_process_internal = p_idle_process_internal;
_change_notify("idle_process_internal");
}
@@ -1218,22 +1152,19 @@ bool Node::is_processing_internal() const {
return data.idle_process_internal;
}
-
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 {
@@ -1242,61 +1173,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) {
@@ -1312,7 +1238,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() {
@@ -1321,12 +1247,11 @@ void Node::init_node_hrcr() {
void Node::set_human_readable_collision_renaming(bool p_enabled) {
- node_hrcr=p_enabled;
+ node_hrcr = p_enabled;
}
-
#ifdef TOOLS_ENABLED
-String Node::validate_child_name(Node* p_child) {
+String Node::validate_child_name(Node *p_child) {
return _generate_serial_child_name(p_child);
}
@@ -1341,28 +1266,28 @@ void Node::_validate_child_name(Node *p_child, bool p_force_human_readable) {
//this approach to autoset node names is human readable but very slow
//it's turned on while running in the editor
- p_child->data.name=_generate_serial_child_name(p_child);
+ p_child->data.name = _generate_serial_child_name(p_child);
} else {
//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;
}
}
@@ -1371,8 +1296,8 @@ 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;
}
}
}
@@ -1381,7 +1306,7 @@ String Node::_generate_serial_child_name(Node *p_child) {
String name = p_child->data.name;
- if (name=="") {
+ if (name == "") {
name = p_child->get_class();
// Adjust casing according to project setting. The current type name is expected to be in PascalCase.
@@ -1399,48 +1324,48 @@ String Node::_generate_serial_child_name(Node *p_child) {
// Extract trailing number
String nums;
- for(int i=name.length()-1;i>=0;i--) {
- CharType n=name[i];
- if (n>='0' && n<='9') {
- nums=String::chr(name[i])+nums;
+ for (int i = name.length() - 1; i >= 0; i--) {
+ CharType n = name[i];
+ if (n >= '0' && n <= '9') {
+ nums = String::chr(name[i]) + nums;
} else {
break;
}
}
- String nnsep=_get_name_num_separator();
- int num=0;
- bool explicit_zero=false;
- if (nums.length()>0 && name.substr(name.length()-nnsep.length()-nums.length(),nnsep.length()) == nnsep) {
+ String nnsep = _get_name_num_separator();
+ int num = 0;
+ bool explicit_zero = false;
+ if (nums.length() > 0 && name.substr(name.length() - nnsep.length() - nums.length(), nnsep.length()) == nnsep) {
// Base name + Separator + Number
- num=nums.to_int();
- name=name.substr(0,name.length()-nnsep.length()-nums.length()); // Keep base name
- if (num==0) {
- explicit_zero=true;
+ num = nums.to_int();
+ name = name.substr(0, name.length() - nnsep.length() - nums.length()); // Keep base name
+ if (num == 0) {
+ explicit_zero = true;
}
}
- for(;;) {
+ for (;;) {
String attempt = (name + (num > 0 || explicit_zero ? nnsep + itos(num) : "")).strip_edges();
- bool found=false;
- for(int i=0;i<data.children.size();i++) {
- if (data.children[i]==p_child)
+ bool found = false;
+ for (int i = 0; i < data.children.size(); i++) {
+ if (data.children[i] == p_child)
continue;
- if (data.children[i]->data.name==attempt) {
- found=true;
+ if (data.children[i]->data.name == attempt) {
+ found = true;
break;
}
}
if (!found) {
return attempt;
} else {
- if (num==0) {
+ if (num == 0) {
if (explicit_zero) {
// Name ended in separator + 0; user expects to get to separator + 1
- num=1;
+ num = 1;
} else {
// Name was undecorated so skip to 2 for a more natural result
- num=2;
+ num = 2;
}
} else {
num++;
@@ -1449,13 +1374,13 @@ String Node::_generate_serial_child_name(Node *p_child) {
}
}
-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) {
@@ -1464,37 +1389,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) {
@@ -1507,39 +1428,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();
}
@@ -1548,28 +1462,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);
@@ -1577,19 +1490,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 {
@@ -1598,75 +1508,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;
@@ -1676,33 +1583,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))
@@ -1711,12 +1617,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 {
@@ -1724,16 +1629,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;
@@ -1741,12 +1645,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;
@@ -1756,46 +1660,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++;
@@ -1804,22 +1708,20 @@ 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) {
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();
}
@@ -1827,27 +1729,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);
@@ -1859,95 +1761,93 @@ 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());
if (data.path_cache)
return *data.path_cache;
@@ -1956,24 +1856,24 @@ NodePath Node::get_path() const {
Vector<StringName> path;
- while(n) {
+ while (n) {
path.push_back(n->get_name());
- n=n->data.parent;
+ n = n->data.parent;
}
path.invert();
- data.path_cache = memnew( NodePath( path, true ) );
+ data.path_cache = memnew(NodePath(path, true));
return *data.path_cache;
}
-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());
@@ -1983,32 +1883,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 {
@@ -2016,7 +1912,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);
}
@@ -2025,33 +1921,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);
}
@@ -2060,16 +1950,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--;
}
@@ -2080,15 +1969,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--;
}
@@ -2098,21 +1987,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--;
}
@@ -2124,21 +2012,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;
}
@@ -2146,27 +2034,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));
@@ -2174,30 +2062,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() {
@@ -2251,32 +2137,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;
}
@@ -2286,43 +2172,39 @@ int Node::get_position_in_parent() const {
return data.pos;
}
-
-
Node *Node::_duplicate(int p_flags) const {
+ Node *node = NULL;
- 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_flags&DUPLICATE_USE_INSTANCING) && get_filename()!=String()) {
+ } else if ((p_flags & DUPLICATE_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 = ClassDB::instance(get_class());
- 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());
}
@@ -2330,16 +2212,15 @@ Node *Node::_duplicate(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());
@@ -2347,7 +2228,7 @@ Node *Node::_duplicate(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);
}
@@ -2356,11 +2237,11 @@ Node *Node::_duplicate(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_flags);
@@ -2373,40 +2254,38 @@ Node *Node::_duplicate(int p_flags) const {
node->add_child(dup);
}
-
return node;
}
Node *Node::duplicate(int p_flags) const {
- Node* dupe = _duplicate(p_flags);
+ Node *dupe = _duplicate(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 = ClassDB::instance(get_class());
if (!obj) {
- print_line("could not duplicate: "+String(get_class()));
+ print_line("could not duplicate: " + String(get_class()));
}
ERR_FAIL_COND(!obj);
node = obj->cast_to<Node>();
@@ -2414,32 +2293,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);
@@ -2447,26 +2323,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);
@@ -2478,37 +2351,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 = ClassDB::instance(get_class());
if (!obj) {
- print_line("could not duplicate: "+String(get_class()));
+ print_line("could not duplicate: " + String(get_class()));
}
- 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());
@@ -2516,35 +2384,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);
}
}
@@ -2554,14 +2418,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;
@@ -2570,27 +2434,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;
@@ -2600,73 +2464,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);
@@ -2674,9 +2535,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;
@@ -2685,23 +2544,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)
@@ -2717,7 +2574,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();
@@ -2726,9 +2583,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);
}
}
@@ -2737,40 +2594,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
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>();
@@ -2780,18 +2632,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_class()+")");
-
+ path = String(p->get_name()) + "/" + p->get_path_to(n);
+ print_line(itos(p_obj->get_instance_ID()) + "- Stray Node: " + path + " (Type: " + n->get_class() + ")");
}
void Node::_print_stray_nodes() {
@@ -2809,7 +2660,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);
}
@@ -2818,17 +2669,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 {
@@ -2838,35 +2688,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 {
@@ -2879,11 +2727,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 {
@@ -2891,7 +2738,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 {
@@ -2900,202 +2747,194 @@ bool Node::is_displayed_folded() const {
}
void Node::request_ready() {
- data.ready_first=true;
+ data.ready_first = true;
}
void Node::_bind_methods() {
- GLOBAL_DEF("node/name_num_separator",0);
- GlobalConfig::get_singleton()->set_custom_property_info("node/name_num_separator",PropertyInfo(Variant::INT,"node/name_num_separator",PROPERTY_HINT_ENUM, "None,Space,Underscore,Dash"));
- GLOBAL_DEF("node/name_casing",NAME_CASING_PASCAL_CASE);
- GlobalConfig::get_singleton()->set_custom_property_info("node/name_casing",PropertyInfo(Variant::INT,"node/name_casing",PROPERTY_HINT_ENUM,"PascalCase,camelCase,snake_case"));
+ GLOBAL_DEF("node/name_num_separator", 0);
+ GlobalConfig::get_singleton()->set_custom_property_info("node/name_num_separator", PropertyInfo(Variant::INT, "node/name_num_separator", PROPERTY_HINT_ENUM, "None,Space,Underscore,Dash"));
+ GLOBAL_DEF("node/name_casing", NAME_CASING_PASCAL_CASE);
+ GlobalConfig::get_singleton()->set_custom_property_info("node/name_casing", PropertyInfo(Variant::INT, "node/name_casing", PROPERTY_HINT_ENUM, "PascalCase,camelCase,snake_case"));
- ClassDB::bind_method(D_METHOD("_add_child_below_node","node:Node","child_node:Node","legible_unique_name"),&Node::add_child_below_node,DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("_add_child_below_node", "node:Node", "child_node:Node", "legible_unique_name"), &Node::add_child_below_node, DEFVAL(false));
- ClassDB::bind_method(D_METHOD("set_name","name"),&Node::set_name);
- ClassDB::bind_method(D_METHOD("get_name"),&Node::get_name);
- ClassDB::bind_method(D_METHOD("add_child","node:Node","legible_unique_name"),&Node::add_child,DEFVAL(false));
- ClassDB::bind_method(D_METHOD("remove_child","node:Node"),&Node::remove_child);
+ ClassDB::bind_method(D_METHOD("set_name", "name"), &Node::set_name);
+ ClassDB::bind_method(D_METHOD("get_name"), &Node::get_name);
+ ClassDB::bind_method(D_METHOD("add_child", "node:Node", "legible_unique_name"), &Node::add_child, DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("remove_child", "node:Node"), &Node::remove_child);
//ClassDB::bind_method(D_METHOD("remove_and_delete_child","node:Node"),&Node::remove_and_delete_child);
- ClassDB::bind_method(D_METHOD("get_child_count"),&Node::get_child_count);
- ClassDB::bind_method(D_METHOD("get_children"),&Node::_get_children);
- ClassDB::bind_method(D_METHOD("get_child:Node","idx"),&Node::get_child);
- ClassDB::bind_method(D_METHOD("has_node","path"),&Node::has_node);
- ClassDB::bind_method(D_METHOD("get_node:Node","path"),&Node::get_node);
- ClassDB::bind_method(D_METHOD("get_parent:Node"),&Node::get_parent);
- ClassDB::bind_method(D_METHOD("find_node:Node","mask","recursive","owned"),&Node::find_node,DEFVAL(true),DEFVAL(true));
- ClassDB::bind_method(D_METHOD("has_node_and_resource","path"),&Node::has_node_and_resource);
- ClassDB::bind_method(D_METHOD("get_node_and_resource","path"),&Node::_get_node_and_resource);
-
- ClassDB::bind_method(D_METHOD("is_inside_tree"),&Node::is_inside_tree);
- ClassDB::bind_method(D_METHOD("is_a_parent_of","node:Node"),&Node::is_a_parent_of);
- ClassDB::bind_method(D_METHOD("is_greater_than","node:Node"),&Node::is_greater_than);
- ClassDB::bind_method(D_METHOD("get_path"),&Node::get_path);
- ClassDB::bind_method(D_METHOD("get_path_to","node:Node"),&Node::get_path_to);
- ClassDB::bind_method(D_METHOD("add_to_group","group","persistent"),&Node::add_to_group,DEFVAL(false));
- ClassDB::bind_method(D_METHOD("remove_from_group","group"),&Node::remove_from_group);
- ClassDB::bind_method(D_METHOD("is_in_group","group"),&Node::is_in_group);
- ClassDB::bind_method(D_METHOD("move_child","child_node:Node","to_pos"),&Node::move_child);
- ClassDB::bind_method(D_METHOD("get_groups"),&Node::_get_groups);
- ClassDB::bind_method(D_METHOD("raise"),&Node::raise);
- ClassDB::bind_method(D_METHOD("set_owner","owner:Node"),&Node::set_owner);
- ClassDB::bind_method(D_METHOD("get_owner:Node"),&Node::get_owner);
- ClassDB::bind_method(D_METHOD("remove_and_skip"),&Node::remove_and_skip);
- ClassDB::bind_method(D_METHOD("get_index"),&Node::get_index);
- ClassDB::bind_method(D_METHOD("print_tree"),&Node::print_tree);
- ClassDB::bind_method(D_METHOD("set_filename","filename"),&Node::set_filename);
- ClassDB::bind_method(D_METHOD("get_filename"),&Node::get_filename);
- ClassDB::bind_method(D_METHOD("propagate_notification","what"),&Node::propagate_notification);
- ClassDB::bind_method(D_METHOD("set_fixed_process","enable"),&Node::set_fixed_process);
- ClassDB::bind_method(D_METHOD("get_fixed_process_delta_time"),&Node::get_fixed_process_delta_time);
- ClassDB::bind_method(D_METHOD("is_fixed_processing"),&Node::is_fixed_processing);
- ClassDB::bind_method(D_METHOD("get_process_delta_time"),&Node::get_process_delta_time);
- ClassDB::bind_method(D_METHOD("set_process","enable"),&Node::set_process);
- ClassDB::bind_method(D_METHOD("is_processing"),&Node::is_processing);
- ClassDB::bind_method(D_METHOD("set_process_input","enable"),&Node::set_process_input);
- ClassDB::bind_method(D_METHOD("is_processing_input"),&Node::is_processing_input);
- ClassDB::bind_method(D_METHOD("set_process_unhandled_input","enable"),&Node::set_process_unhandled_input);
- ClassDB::bind_method(D_METHOD("is_processing_unhandled_input"),&Node::is_processing_unhandled_input);
- ClassDB::bind_method(D_METHOD("set_process_unhandled_key_input","enable"),&Node::set_process_unhandled_key_input);
- ClassDB::bind_method(D_METHOD("is_processing_unhandled_key_input"),&Node::is_processing_unhandled_key_input);
- ClassDB::bind_method(D_METHOD("set_pause_mode","mode"),&Node::set_pause_mode);
- ClassDB::bind_method(D_METHOD("get_pause_mode"),&Node::get_pause_mode);
- ClassDB::bind_method(D_METHOD("can_process"),&Node::can_process);
- ClassDB::bind_method(D_METHOD("print_stray_nodes"),&Node::_print_stray_nodes);
- ClassDB::bind_method(D_METHOD("get_position_in_parent"),&Node::get_position_in_parent);
- ClassDB::bind_method(D_METHOD("set_display_folded","fold"),&Node::set_display_folded);
- ClassDB::bind_method(D_METHOD("is_displayed_folded"),&Node::is_displayed_folded);
-
- ClassDB::bind_method(D_METHOD("set_process_internal","enable"),&Node::set_process_internal);
- ClassDB::bind_method(D_METHOD("is_processing_internal"),&Node::is_processing_internal);
-
- ClassDB::bind_method(D_METHOD("set_fixed_process_internal","enable"),&Node::set_fixed_process_internal);
- ClassDB::bind_method(D_METHOD("is_fixed_processing_internal"),&Node::is_fixed_processing_internal);
-
- ClassDB::bind_method(D_METHOD("get_tree:SceneTree"),&Node::get_tree);
-
- ClassDB::bind_method(D_METHOD("duplicate:Node","flags"),&Node::duplicate,DEFVAL(DUPLICATE_USE_INSTANCING|DUPLICATE_SIGNALS|DUPLICATE_GROUPS|DUPLICATE_SCRIPTS));
- ClassDB::bind_method(D_METHOD("replace_by","node:Node","keep_data"),&Node::replace_by,DEFVAL(false));
-
- ClassDB::bind_method(D_METHOD("set_scene_instance_load_placeholder","load_placeholder"),&Node::set_scene_instance_load_placeholder);
- ClassDB::bind_method(D_METHOD("get_scene_instance_load_placeholder"),&Node::get_scene_instance_load_placeholder);
-
-
- ClassDB::bind_method(D_METHOD("get_viewport"),&Node::get_viewport);
-
- ClassDB::bind_method(D_METHOD("queue_free"),&Node::queue_delete);
-
- ClassDB::bind_method(D_METHOD("request_ready"),&Node::request_ready);
-
- ClassDB::bind_method(D_METHOD("set_network_mode","mode"),&Node::set_network_mode);
- ClassDB::bind_method(D_METHOD("get_network_mode"),&Node::get_network_mode);
-
- ClassDB::bind_method(D_METHOD("is_network_master"),&Node::is_network_master);
-
- ClassDB::bind_method(D_METHOD("rpc_config","method","mode"),&Node::rpc_config);
- ClassDB::bind_method(D_METHOD("rset_config","property","mode"),&Node::rset_config);
-
+ ClassDB::bind_method(D_METHOD("get_child_count"), &Node::get_child_count);
+ ClassDB::bind_method(D_METHOD("get_children"), &Node::_get_children);
+ ClassDB::bind_method(D_METHOD("get_child:Node", "idx"), &Node::get_child);
+ ClassDB::bind_method(D_METHOD("has_node", "path"), &Node::has_node);
+ ClassDB::bind_method(D_METHOD("get_node:Node", "path"), &Node::get_node);
+ ClassDB::bind_method(D_METHOD("get_parent:Node"), &Node::get_parent);
+ ClassDB::bind_method(D_METHOD("find_node:Node", "mask", "recursive", "owned"), &Node::find_node, DEFVAL(true), DEFVAL(true));
+ ClassDB::bind_method(D_METHOD("has_node_and_resource", "path"), &Node::has_node_and_resource);
+ ClassDB::bind_method(D_METHOD("get_node_and_resource", "path"), &Node::_get_node_and_resource);
+
+ ClassDB::bind_method(D_METHOD("is_inside_tree"), &Node::is_inside_tree);
+ ClassDB::bind_method(D_METHOD("is_a_parent_of", "node:Node"), &Node::is_a_parent_of);
+ ClassDB::bind_method(D_METHOD("is_greater_than", "node:Node"), &Node::is_greater_than);
+ ClassDB::bind_method(D_METHOD("get_path"), &Node::get_path);
+ ClassDB::bind_method(D_METHOD("get_path_to", "node:Node"), &Node::get_path_to);
+ ClassDB::bind_method(D_METHOD("add_to_group", "group", "persistent"), &Node::add_to_group, DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("remove_from_group", "group"), &Node::remove_from_group);
+ ClassDB::bind_method(D_METHOD("is_in_group", "group"), &Node::is_in_group);
+ ClassDB::bind_method(D_METHOD("move_child", "child_node:Node", "to_pos"), &Node::move_child);
+ ClassDB::bind_method(D_METHOD("get_groups"), &Node::_get_groups);
+ ClassDB::bind_method(D_METHOD("raise"), &Node::raise);
+ ClassDB::bind_method(D_METHOD("set_owner", "owner:Node"), &Node::set_owner);
+ ClassDB::bind_method(D_METHOD("get_owner:Node"), &Node::get_owner);
+ ClassDB::bind_method(D_METHOD("remove_and_skip"), &Node::remove_and_skip);
+ ClassDB::bind_method(D_METHOD("get_index"), &Node::get_index);
+ ClassDB::bind_method(D_METHOD("print_tree"), &Node::print_tree);
+ ClassDB::bind_method(D_METHOD("set_filename", "filename"), &Node::set_filename);
+ ClassDB::bind_method(D_METHOD("get_filename"), &Node::get_filename);
+ ClassDB::bind_method(D_METHOD("propagate_notification", "what"), &Node::propagate_notification);
+ ClassDB::bind_method(D_METHOD("set_fixed_process", "enable"), &Node::set_fixed_process);
+ ClassDB::bind_method(D_METHOD("get_fixed_process_delta_time"), &Node::get_fixed_process_delta_time);
+ ClassDB::bind_method(D_METHOD("is_fixed_processing"), &Node::is_fixed_processing);
+ ClassDB::bind_method(D_METHOD("get_process_delta_time"), &Node::get_process_delta_time);
+ ClassDB::bind_method(D_METHOD("set_process", "enable"), &Node::set_process);
+ ClassDB::bind_method(D_METHOD("is_processing"), &Node::is_processing);
+ ClassDB::bind_method(D_METHOD("set_process_input", "enable"), &Node::set_process_input);
+ ClassDB::bind_method(D_METHOD("is_processing_input"), &Node::is_processing_input);
+ ClassDB::bind_method(D_METHOD("set_process_unhandled_input", "enable"), &Node::set_process_unhandled_input);
+ ClassDB::bind_method(D_METHOD("is_processing_unhandled_input"), &Node::is_processing_unhandled_input);
+ ClassDB::bind_method(D_METHOD("set_process_unhandled_key_input", "enable"), &Node::set_process_unhandled_key_input);
+ ClassDB::bind_method(D_METHOD("is_processing_unhandled_key_input"), &Node::is_processing_unhandled_key_input);
+ ClassDB::bind_method(D_METHOD("set_pause_mode", "mode"), &Node::set_pause_mode);
+ ClassDB::bind_method(D_METHOD("get_pause_mode"), &Node::get_pause_mode);
+ ClassDB::bind_method(D_METHOD("can_process"), &Node::can_process);
+ ClassDB::bind_method(D_METHOD("print_stray_nodes"), &Node::_print_stray_nodes);
+ ClassDB::bind_method(D_METHOD("get_position_in_parent"), &Node::get_position_in_parent);
+ ClassDB::bind_method(D_METHOD("set_display_folded", "fold"), &Node::set_display_folded);
+ ClassDB::bind_method(D_METHOD("is_displayed_folded"), &Node::is_displayed_folded);
+
+ ClassDB::bind_method(D_METHOD("set_process_internal", "enable"), &Node::set_process_internal);
+ ClassDB::bind_method(D_METHOD("is_processing_internal"), &Node::is_processing_internal);
+
+ ClassDB::bind_method(D_METHOD("set_fixed_process_internal", "enable"), &Node::set_fixed_process_internal);
+ ClassDB::bind_method(D_METHOD("is_fixed_processing_internal"), &Node::is_fixed_processing_internal);
+
+ ClassDB::bind_method(D_METHOD("get_tree:SceneTree"), &Node::get_tree);
+
+ ClassDB::bind_method(D_METHOD("duplicate:Node", "flags"), &Node::duplicate, DEFVAL(DUPLICATE_USE_INSTANCING | DUPLICATE_SIGNALS | DUPLICATE_GROUPS | DUPLICATE_SCRIPTS));
+ ClassDB::bind_method(D_METHOD("replace_by", "node:Node", "keep_data"), &Node::replace_by, DEFVAL(false));
+
+ ClassDB::bind_method(D_METHOD("set_scene_instance_load_placeholder", "load_placeholder"), &Node::set_scene_instance_load_placeholder);
+ ClassDB::bind_method(D_METHOD("get_scene_instance_load_placeholder"), &Node::get_scene_instance_load_placeholder);
+
+ ClassDB::bind_method(D_METHOD("get_viewport"), &Node::get_viewport);
+
+ ClassDB::bind_method(D_METHOD("queue_free"), &Node::queue_delete);
+
+ ClassDB::bind_method(D_METHOD("request_ready"), &Node::request_ready);
+
+ ClassDB::bind_method(D_METHOD("set_network_mode", "mode"), &Node::set_network_mode);
+ ClassDB::bind_method(D_METHOD("get_network_mode"), &Node::get_network_mode);
+
+ ClassDB::bind_method(D_METHOD("is_network_master"), &Node::is_network_master);
+
+ ClassDB::bind_method(D_METHOD("rpc_config", "method", "mode"), &Node::rpc_config);
+ ClassDB::bind_method(D_METHOD("rset_config", "property", "mode"), &Node::rset_config);
#ifdef TOOLS_ENABLED
- ClassDB::bind_method(D_METHOD("_set_import_path","import_path"),&Node::set_import_path);
- ClassDB::bind_method(D_METHOD("_get_import_path"),&Node::get_import_path);
- ADD_PROPERTYNZ( PropertyInfo(Variant::NODE_PATH,"_import_path",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"_set_import_path","_get_import_path");
+ ClassDB::bind_method(D_METHOD("_set_import_path", "import_path"), &Node::set_import_path);
+ ClassDB::bind_method(D_METHOD("_get_import_path"), &Node::get_import_path);
+ ADD_PROPERTYNZ(PropertyInfo(Variant::NODE_PATH, "_import_path", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_import_path", "_get_import_path");
#endif
{
MethodInfo mi;
- mi.arguments.push_back( PropertyInfo( Variant::STRING, "method"));
+ mi.arguments.push_back(PropertyInfo(Variant::STRING, "method"));
+ mi.name = "rpc";
+ ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "rpc", &Node::_rpc_bind, mi);
+ mi.name = "rpc_unreliable";
+ ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "rpc_unreliable", &Node::_rpc_unreliable_bind, mi);
- mi.name="rpc";
- ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT,"rpc",&Node::_rpc_bind,mi);
- mi.name="rpc_unreliable";
- ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT,"rpc_unreliable",&Node::_rpc_unreliable_bind,mi);
-
- mi.arguments.push_front( PropertyInfo( Variant::INT, "peer_id") );
-
- mi.name="rpc_id";
- ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT,"rpc_id",&Node::_rpc_id_bind,mi);
- mi.name="rpc_unreliable_id";
- ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT,"rpc_unreliable_id",&Node::_rpc_unreliable_id_bind,mi);
-
+ mi.arguments.push_front(PropertyInfo(Variant::INT, "peer_id"));
+ mi.name = "rpc_id";
+ ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "rpc_id", &Node::_rpc_id_bind, mi);
+ mi.name = "rpc_unreliable_id";
+ ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "rpc_unreliable_id", &Node::_rpc_unreliable_id_bind, mi);
}
- ClassDB::bind_method(D_METHOD("rset","property","value:Variant"),&Node::rset);
- ClassDB::bind_method(D_METHOD("rset_id","peer_id","property","value:Variant"),&Node::rset_id);
- ClassDB::bind_method(D_METHOD("rset_unreliable","property","value:Variant"),&Node::rset_unreliable);
- ClassDB::bind_method(D_METHOD("rset_unreliable_id","peer_id","property","value:Variant"),&Node::rset_unreliable_id);
-
+ ClassDB::bind_method(D_METHOD("rset", "property", "value:Variant"), &Node::rset);
+ ClassDB::bind_method(D_METHOD("rset_id", "peer_id", "property", "value:Variant"), &Node::rset_id);
+ ClassDB::bind_method(D_METHOD("rset_unreliable", "property", "value:Variant"), &Node::rset_unreliable);
+ ClassDB::bind_method(D_METHOD("rset_unreliable_id", "peer_id", "property", "value:Variant"), &Node::rset_unreliable_id);
- 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_PATH_CHANGED);
- BIND_CONSTANT( NOTIFICATION_TRANSLATION_CHANGED );
- BIND_CONSTANT( NOTIFICATION_INTERNAL_PROCESS );
- BIND_CONSTANT( NOTIFICATION_INTERNAL_FIXED_PROCESS );
-
-
- BIND_CONSTANT( NETWORK_MODE_INHERIT );
- BIND_CONSTANT( NETWORK_MODE_MASTER );
- BIND_CONSTANT( NETWORK_MODE_SLAVE );
-
- BIND_CONSTANT( RPC_MODE_DISABLED );
- BIND_CONSTANT( RPC_MODE_REMOTE );
- BIND_CONSTANT( RPC_MODE_SYNC );
- BIND_CONSTANT( RPC_MODE_MASTER );
- BIND_CONSTANT( RPC_MODE_SLAVE );
-
- BIND_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 );
-
- ADD_SIGNAL( MethodInfo("renamed") );
- ADD_SIGNAL( MethodInfo("tree_entered") );
- ADD_SIGNAL( MethodInfo("tree_exited") );
+ 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_PATH_CHANGED);
+ BIND_CONSTANT(NOTIFICATION_TRANSLATION_CHANGED);
+ BIND_CONSTANT(NOTIFICATION_INTERNAL_PROCESS);
+ BIND_CONSTANT(NOTIFICATION_INTERNAL_FIXED_PROCESS);
+
+ BIND_CONSTANT(NETWORK_MODE_INHERIT);
+ BIND_CONSTANT(NETWORK_MODE_MASTER);
+ BIND_CONSTANT(NETWORK_MODE_SLAVE);
+
+ BIND_CONSTANT(RPC_MODE_DISABLED);
+ BIND_CONSTANT(RPC_MODE_REMOTE);
+ BIND_CONSTANT(RPC_MODE_SYNC);
+ BIND_CONSTANT(RPC_MODE_MASTER);
+ BIND_CONSTANT(RPC_MODE_SLAVE);
+
+ BIND_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);
+
+ ADD_SIGNAL(MethodInfo("renamed"));
+ ADD_SIGNAL(MethodInfo("tree_entered"));
+ ADD_SIGNAL(MethodInfo("tree_exited"));
//ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "process/process" ),"set_process","is_processing") ;
//ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "process/fixed_process" ), "set_fixed_process","is_fixed_processing") ;
//ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "process/input" ), "set_process_input","is_processing_input" ) ;
//ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "process/unhandled_input" ), "set_process_unhandled_input","is_processing_unhandled_input" ) ;
- ADD_GROUP("Pause","pause_");
- ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "pause_mode",PROPERTY_HINT_ENUM,"Inherit,Stop,Process" ), "set_pause_mode", "get_pause_mode" );
- ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "editor/display_folded",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR ), "set_display_folded", "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")) );
+ ADD_GROUP("Pause", "pause_");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "pause_mode", PROPERTY_HINT_ENUM, "Inherit,Stop,Process"), "set_pause_mode", "get_pause_mode");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "editor/display_folded", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_display_folded", "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")));
//ClassDB::bind_method(D_METHOD("get_child",&Node::get_child,PH("index")));
//ClassDB::bind_method(D_METHOD("get_node",&Node::get_node,PH("path")));
}
-
String Node::_get_name_num_separator() {
- switch(GlobalConfig::get_singleton()->get("node/name_num_separator").operator int()) {
+ switch (GlobalConfig::get_singleton()->get("node/name_num_separator").operator int()) {
case 0: return "";
case 1: return " ";
case 2: return "_";
@@ -3104,53 +2943,46 @@ String Node::_get_name_num_separator() {
return " ";
}
-
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.fixed_process_internal=false;
- data.idle_process_internal=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.network_mode=NETWORK_MODE_INHERIT;
- data.network_owner=NULL;
- data.path_cache=NULL;
- data.parent_owned=false;
- data.in_constructor=true;
- data.viewport=NULL;
- data.use_placeholder=false;
- data.display_folded=false;
- data.ready_first=true;
-
+ data.pos = -1;
+ data.depth = -1;
+ data.blocked = 0;
+ data.parent = NULL;
+ data.tree = NULL;
+ data.fixed_process = false;
+ data.idle_process = false;
+ data.fixed_process_internal = false;
+ data.idle_process_internal = false;
+ data.inside_tree = false;
+ data.ready_notified = false;
+
+ 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.network_mode = NETWORK_MODE_INHERIT;
+ data.network_owner = NULL;
+ data.path_cache = NULL;
+ data.parent_owned = false;
+ data.in_constructor = true;
+ data.viewport = NULL;
+ data.use_placeholder = false;
+ data.display_folded = false;
+ data.ready_first = true;
}
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 b042cabb6f..714a58bd82 100644
--- a/scene/main/node.h
+++ b/scene/main/node.h
@@ -29,24 +29,22 @@
#ifndef NODE_H
#define NODE_H
+#include "class_db.h"
#include "global_config.h"
+#include "map.h"
#include "object.h"
#include "path_db.h"
-#include "map.h"
-#include "class_db.h"
-#include "script_language.h"
#include "scene/main/scene_main_loop.h"
-
+#include "script_language.h"
class Viewport;
class SceneState;
class Node : public Object {
- GDCLASS( Node, Object );
+ GDCLASS(Node, Object);
OBJ_CATEGORY("Nodes");
public:
-
enum PauseMode {
PAUSE_MODE_INHERIT,
@@ -56,10 +54,10 @@ public:
enum DuplicateFlags {
- DUPLICATE_SIGNALS=1,
- DUPLICATE_GROUPS=2,
- DUPLICATE_SCRIPTS=4,
- DUPLICATE_USE_INSTANCING=8
+ DUPLICATE_SIGNALS = 1,
+ DUPLICATE_GROUPS = 2,
+ DUPLICATE_SCRIPTS = 4,
+ DUPLICATE_USE_INSTANCING = 8
};
enum NetworkMode {
@@ -80,31 +78,28 @@ public:
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 {
String filename;
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.
@@ -119,19 +114,17 @@ 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;
NetworkMode network_mode;
Node *network_owner;
- Map<StringName,RPCMode> rpc_methods;
- Map<StringName,RPCMode> rpc_properties;
-
+ Map<StringName, RPCMode> rpc_methods;
+ Map<StringName, RPCMode> rpc_properties;
// variables used to properly sort the node when processing, ignored otherwise
//should move all the stuff below to bits
@@ -161,15 +154,14 @@ private:
NAME_CASING_SNAKE_CASE
};
-
void _print_tree(const Node *p_node);
- 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_child, bool p_force_human_readable=false);
+ void _validate_child_name(Node *p_child, bool p_force_human_readable = false);
String _generate_serial_child_name(Node *p_child);
void _propagate_reverse_notification(int p_notification);
@@ -179,29 +171,29 @@ private:
void _propagate_exit_tree();
void _propagate_validate_owner();
void _print_stray_nodes();
- void _propagate_pause_owner(Node*p_owner);
- void _propagate_network_owner(Node*p_owner);
- Array _get_node_and_resource(const NodePath& p_path);
+ void _propagate_pause_owner(Node *p_owner);
+ void _propagate_network_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;
+ 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(int p_flags) const;
Array _get_children() const;
Array _get_groups() const;
- Variant _rpc_bind(const Variant** p_args, int p_argcount, Variant::CallError& r_error);
- Variant _rpc_unreliable_bind(const Variant** p_args, int p_argcount, Variant::CallError& r_error);
- Variant _rpc_id_bind(const Variant** p_args, int p_argcount, Variant::CallError& r_error);
- Variant _rpc_unreliable_id_bind(const Variant** p_args, int p_argcount, Variant::CallError& r_error);
+ Variant _rpc_bind(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
+ Variant _rpc_unreliable_bind(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
+ Variant _rpc_id_bind(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
+ Variant _rpc_unreliable_id_bind(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
-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);
@@ -210,37 +202,36 @@ 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();
static String _get_name_num_separator();
-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_PATH_CHANGED=23,
- NOTIFICATION_TRANSLATION_CHANGED=24,
+ NOTIFICATION_PARENTED = 18,
+ NOTIFICATION_UNPARENTED = 19,
+ NOTIFICATION_INSTANCED = 20,
+ NOTIFICATION_DRAG_BEGIN = 21,
+ NOTIFICATION_DRAG_END = 22,
+ NOTIFICATION_PATH_CHANGED = 23,
+ NOTIFICATION_TRANSLATION_CHANGED = 24,
NOTIFICATION_INTERNAL_PROCESS = 25,
NOTIFICATION_INTERNAL_FIXED_PROCESS = 26,
@@ -249,22 +240,25 @@ public:
/* 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; }
@@ -273,11 +267,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 {
@@ -288,27 +282,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 */
@@ -340,16 +332,16 @@ public:
int get_position_in_parent() const;
- Node *duplicate(int p_flags=DUPLICATE_GROUPS|DUPLICATE_SIGNALS|DUPLICATE_SCRIPTS) const;
- Node *duplicate_and_reown(const Map<Node*,Node*>& p_reown_map) const;
+ Node *duplicate(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);
@@ -357,7 +349,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;
@@ -368,25 +360,25 @@ public:
static void print_stray_nodes();
#ifdef TOOLS_ENABLED
- String validate_child_name(Node* p_child);
+ String validate_child_name(Node *p_child);
#endif
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();
@@ -404,33 +396,30 @@ public:
NetworkMode get_network_mode() const;
bool is_network_master() const;
- void rpc_config(const StringName& p_method,RPCMode p_mode); // config a local method for RPC
- void rset_config(const StringName& p_property,RPCMode p_mode); // config a local property for RPC
-
- void rpc(const StringName& p_method,VARIANT_ARG_LIST); //rpc call, honors RPCMode
- void rpc_unreliable(const StringName& p_method,VARIANT_ARG_LIST); //rpc call, honors RPCMode
- void rpc_id(int p_peer_id,const StringName& p_method,VARIANT_ARG_LIST); //rpc call, honors RPCMode
- void rpc_unreliable_id(int p_peer_id,const StringName& p_method,VARIANT_ARG_LIST); //rpc call, honors RPCMode
+ void rpc_config(const StringName &p_method, RPCMode p_mode); // config a local method for RPC
+ void rset_config(const StringName &p_property, RPCMode p_mode); // config a local property for RPC
- void rpcp(int p_peer_id,bool p_unreliable,const StringName& p_method,const Variant** p_arg,int p_argcount);
+ void rpc(const StringName &p_method, VARIANT_ARG_LIST); //rpc call, honors RPCMode
+ void rpc_unreliable(const StringName &p_method, VARIANT_ARG_LIST); //rpc call, honors RPCMode
+ void rpc_id(int p_peer_id, const StringName &p_method, VARIANT_ARG_LIST); //rpc call, honors RPCMode
+ void rpc_unreliable_id(int p_peer_id, const StringName &p_method, VARIANT_ARG_LIST); //rpc call, honors RPCMode
- void rset(const StringName& p_property, const Variant& p_value); //remote set call, honors RPCMode
- void rset_unreliable(const StringName& p_property,const Variant& p_value); //remote set call, honors RPCMode
- void rset_id(int p_peer_id,const StringName& p_property,const Variant& p_value); //remote set call, honors RPCMode
- void rset_unreliable_id(int p_peer_id,const StringName& p_property,const Variant& p_value); //remote set call, honors RPCMode
+ void rpcp(int p_peer_id, bool p_unreliable, const StringName &p_method, const Variant **p_arg, int p_argcount);
- void rsetp(int p_peer_id,bool p_unreliable,const StringName& p_property,const Variant& p_value);
+ void rset(const StringName &p_property, const Variant &p_value); //remote set call, honors RPCMode
+ void rset_unreliable(const StringName &p_property, const Variant &p_value); //remote set call, honors RPCMode
+ void rset_id(int p_peer_id, const StringName &p_property, const Variant &p_value); //remote set call, honors RPCMode
+ void rset_unreliable_id(int p_peer_id, const StringName &p_property, const Variant &p_value); //remote set call, honors RPCMode
- bool can_call_rpc(const StringName& p_method) const;
- bool can_call_rset(const StringName& p_property) const;
+ void rsetp(int p_peer_id, bool p_unreliable, const StringName &p_property, const Variant &p_value);
+ bool can_call_rpc(const StringName &p_method) const;
+ bool can_call_rset(const StringName &p_property) const;
Node();
~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 29333ff4bc..c08a6bcd5b 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);
- PoolVector<String> names=p_data[0];
- Array resdata=p_data[1];
+ ERR_FAIL_COND(p_data.size() != 2);
+ PoolVector<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 @@ PoolVector<String> ResourcePreloader::_get_resource_list() const {
PoolVector<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 @@ PoolVector<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() {
- ClassDB::bind_method(D_METHOD("_set_resources"),&ResourcePreloader::_set_resources);
- ClassDB::bind_method(D_METHOD("_get_resources"),&ResourcePreloader::_get_resources);
-
- ClassDB::bind_method(D_METHOD("add_resource","name","resource"),&ResourcePreloader::add_resource);
- ClassDB::bind_method(D_METHOD("remove_resource","name"),&ResourcePreloader::remove_resource);
- ClassDB::bind_method(D_METHOD("rename_resource","name","newname"),&ResourcePreloader::rename_resource);
- ClassDB::bind_method(D_METHOD("has_resource","name"),&ResourcePreloader::has_resource);
- ClassDB::bind_method(D_METHOD("get_resource","name"),&ResourcePreloader::get_resource);
- ClassDB::bind_method(D_METHOD("get_resource_list"),&ResourcePreloader::_get_resource_list);
-
+ ClassDB::bind_method(D_METHOD("_set_resources"), &ResourcePreloader::_set_resources);
+ ClassDB::bind_method(D_METHOD("_get_resources"), &ResourcePreloader::_get_resources);
- ADD_PROPERTY( PropertyInfo(Variant::ARRAY,"resources",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR), "_set_resources", "_get_resources");
+ ClassDB::bind_method(D_METHOD("add_resource", "name", "resource"), &ResourcePreloader::add_resource);
+ ClassDB::bind_method(D_METHOD("remove_resource", "name"), &ResourcePreloader::remove_resource);
+ ClassDB::bind_method(D_METHOD("rename_resource", "name", "newname"), &ResourcePreloader::rename_resource);
+ ClassDB::bind_method(D_METHOD("has_resource", "name"), &ResourcePreloader::has_resource);
+ ClassDB::bind_method(D_METHOD("get_resource", "name"), &ResourcePreloader::get_resource);
+ ClassDB::bind_method(D_METHOD("get_resource_list"), &ResourcePreloader::_get_resource_list);
+ ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "resources", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_resources", "_get_resources");
}
-ResourcePreloader::ResourcePreloader()
-{
+ResourcePreloader::ResourcePreloader() {
}
diff --git a/scene/main/resource_preloader.h b/scene/main/resource_preloader.h
index 4e585d1751..5fba70c1c0 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 {
- GDCLASS(ResourcePreloader,Node);
-
- Map<StringName,RES > resources;
+ GDCLASS(ResourcePreloader, Node);
+ Map<StringName, RES> resources;
- void _set_resources(const Array& p_data);
+ void _set_resources(const Array &p_data);
Array _get_resources() const;
PoolVector<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 093359ab16..e766d1c149 100644
--- a/scene/main/scene_main_loop.cpp
+++ b/scene/main/scene_main_loop.cpp
@@ -28,35 +28,34 @@
/*************************************************************************/
#include "scene_main_loop.h"
-#include "print_string.h"
-#include "os/os.h"
+#include "global_config.h"
#include "message_queue.h"
#include "node.h"
-#include "global_config.h"
-#include <stdio.h>
#include "os/keyboard.h"
+#include "os/os.h"
+#include "print_string.h"
+#include <stdio.h>
//#include "servers/spatial_sound_2d_server.h"
-#include "servers/physics_2d_server.h"
-#include "servers/physics_server.h"
-#include "scene/scene_string_names.h"
+#include "io/marshalls.h"
#include "io/resource_loader.h"
-#include "viewport.h"
-#include "scene/resources/packed_scene.h"
#include "scene/resources/material.h"
#include "scene/resources/mesh.h"
-#include "io/marshalls.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 "viewport.h"
void SceneTreeTimer::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_time_left","time"),&SceneTreeTimer::set_time_left);
- ClassDB::bind_method(D_METHOD("get_time_left"),&SceneTreeTimer::get_time_left);
+ ClassDB::bind_method(D_METHOD("set_time_left", "time"), &SceneTreeTimer::set_time_left);
+ ClassDB::bind_method(D_METHOD("get_time_left"), &SceneTreeTimer::get_time_left);
ADD_SIGNAL(MethodInfo("timeout"));
}
-
void SceneTreeTimer::set_time_left(float p_time) {
- time_left=p_time;
+ time_left = p_time;
}
float SceneTreeTimer::get_time_left() const {
@@ -74,11 +73,10 @@ bool SceneTreeTimer::is_pause_mode_process() {
}
SceneTreeTimer::SceneTreeTimer() {
- time_left=0;
+ time_left = 0;
process_pause = true;
}
-
void SceneTree::tree_changed() {
tree_version++;
@@ -87,40 +85,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);
@@ -128,38 +122,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_flags(GROUP_CALL_REALTIME,E->key().group,E->key().call,v[0],v[1],v[2],v[3],v[4]);
+ call_group_flags(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;
@@ -167,32 +161,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_flags(uint32_t p_call_flags, const StringName &p_group, const StringName &p_function, VARIANT_ARG_DECLARE) {
-void SceneTree::call_group_flags(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;
@@ -200,210 +191,201 @@ void SceneTree::call_group_flags(uint32_t p_call_flags,const StringName& p_group
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_MULTILEVEL)
- nodes[i]->call_multilevel(p_function,VARIANT_ARG_PASS);
+ if (p_call_flags & GROUP_CALL_REALTIME) {
+ if (p_call_flags & GROUP_CALL_MULTILEVEL)
+ 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_MULTILEVEL)
- nodes[i]->call_multilevel(p_function,VARIANT_ARG_PASS);
+ if (p_call_flags & GROUP_CALL_REALTIME) {
+ if (p_call_flags & GROUP_CALL_MULTILEVEL)
+ 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_flags(uint32_t p_call_flags,const StringName& p_group,int p_notification) {
+void SceneTree::notify_group_flags(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_flags(uint32_t p_call_flags,const StringName& p_group,const String& p_name,const Variant& p_value) {
+void SceneTree::set_group_flags(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::call_group(const StringName &p_group, const StringName &p_function, VARIANT_ARG_DECLARE) {
-void SceneTree::call_group(const StringName& p_group,const StringName& p_function,VARIANT_ARG_DECLARE) {
-
- call_group_flags(0,p_group,VARIANT_ARG_PASS);
+ call_group_flags(0, p_group, VARIANT_ARG_PASS);
}
-void SceneTree::notify_group(const StringName& p_group,int p_notification) {
+void SceneTree::notify_group(const StringName &p_group, int p_notification) {
- notify_group_flags(0,p_group,p_notification);
+ notify_group_flags(0, p_group, p_notification);
}
-void SceneTree::set_group(const StringName& p_group,const String& p_name,const Variant& p_value) {
+void SceneTree::set_group(const StringName &p_group, const String &p_name, const Variant &p_value) {
- set_group_flags(0,p_group,p_name,p_value);
+ set_group_flags(0, p_group, p_name, p_value);
}
-
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_flags(GROUP_CALL_REALTIME,"_viewports","_vp_input_text",p_text); //special one for GUI, as controls use their own process check
+ call_group_flags(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::JOYPAD_MOTION || p_event.type==InputEvent::JOYPAD_BUTTON))
+ if (is_editor_hint() && (p_event.type == InputEvent::JOYPAD_MOTION || p_event.type == InputEvent::JOYPAD_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) {
@@ -480,10 +462,10 @@ void SceneTree::input_event( const InputEvent& p_event ) {
//transform for the rest
#else
- call_group_flags(GROUP_CALL_REALTIME,"_viewports","_vp_input",ev); //special one for GUI, as controls use their own process check
+ call_group_flags(GROUP_CALL_REALTIME, "_viewports", "_vp_input", ev); //special one for GUI, as controls use their own process check
#endif
- if (ScriptDebugger::get_singleton() && ScriptDebugger::get_singleton()->is_remote() && 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();
}
@@ -505,42 +487,37 @@ void SceneTree::input_event( const InputEvent& p_event ) {
}
#else
- call_group_flags(GROUP_CALL_REALTIME,"_viewports","_vp_unhandled_input",ev); //special one for GUI, as controls use their own process check
+ call_group_flags(GROUP_CALL_REALTIME, "_viewports", "_vp_unhandled_input", ev); //special one for GUI, as controls use their own process check
#endif
- input_handled=true;
+ input_handled = true;
_flush_ugc();
root_lock--;
MessageQueue::get_singleton()->flush(); //small little hack
} else {
- input_handled=true;
+ input_handled = true;
root_lock--;
-
}
_call_idle_callbacks();
-
}
void SceneTree::init() {
//_quit=false;
- accept_quit=true;
- quit_on_go_back=true;
- initialized=true;
- input_handled=false;
+ accept_quit = true;
+ quit_on_go_back = 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++;
@@ -548,15 +525,15 @@ 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_internal",Node::NOTIFICATION_INTERNAL_FIXED_PROCESS);
- _notify_group_pause("fixed_process",Node::NOTIFICATION_FIXED_PROCESS);
+ _notify_group_pause("fixed_process_internal", Node::NOTIFICATION_INTERNAL_FIXED_PROCESS);
+ _notify_group_pause("fixed_process", Node::NOTIFICATION_FIXED_PROCESS);
_flush_ugc();
_flush_transform_notifications();
- call_group_flags(GROUP_CALL_REALTIME,"_viewports","update_worlds");
+ call_group_flags(GROUP_CALL_REALTIME, "_viewports", "update_worlds");
root_lock--;
_flush_delete_queue();
@@ -565,8 +542,7 @@ 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()));
@@ -576,7 +552,7 @@ bool SceneTree::idle(float p_time){
MainLoop::idle(p_time);
- idle_process_time=p_time;
+ idle_process_time = p_time;
_network_poll();
@@ -584,24 +560,21 @@ bool SceneTree::idle(float p_time){
_flush_transform_notifications();
- _notify_group_pause("idle_process_internal",Node::NOTIFICATION_INTERNAL_PROCESS);
- _notify_group_pause("idle_process",Node::NOTIFICATION_PROCESS);
+ _notify_group_pause("idle_process_internal", Node::NOTIFICATION_INTERNAL_PROCESS);
+ _notify_group_pause("idle_process", Node::NOTIFICATION_PROCESS);
- Size2 win_size=Size2( OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height );
- if(win_size!=last_screen_size) {
+ 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_flags(GROUP_CALL_REALTIME,"_viewports","update_worlds");
+ call_group_flags(GROUP_CALL_REALTIME, "_viewports", "update_worlds");
root_lock--;
@@ -609,22 +582,22 @@ bool SceneTree::idle(float p_time){
//go through timers
- for (List<Ref<SceneTreeTimer> >::Element *E=timers.front();E;) {
+ for (List<Ref<SceneTreeTimer> >::Element *E = timers.front(); E;) {
List<Ref<SceneTreeTimer> >::Element *N = E->next();
if (pause && !E->get()->is_pause_mode_process()) {
- E=N;
+ E = N;
continue;
}
float time_left = E->get()->get_time_left();
- time_left-=p_time;
+ time_left -= p_time;
E->get()->set_time_left(time_left);
- if (time_left<0) {
+ if (time_left < 0) {
E->get()->emit_signal("timeout");
timers.erase(E);
}
- E=N;
+ E = N;
}
_call_idle_callbacks();
@@ -638,7 +611,7 @@ void SceneTree::finish() {
_flush_ugc();
- initialized=false;
+ initialized = false;
MainLoop::finish();
@@ -646,27 +619,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: {
@@ -674,7 +635,7 @@ void SceneTree::_notification(int p_notification) {
get_root()->propagate_notification(p_notification);
if (accept_quit) {
- _quit=true;
+ _quit = true;
break;
}
} break;
@@ -683,7 +644,7 @@ void SceneTree::_notification(int p_notification) {
get_root()->propagate_notification(p_notification);
if (quit_on_go_back) {
- _quit=true;
+ _quit = true;
break;
}
} break;
@@ -698,7 +659,7 @@ void SceneTree::_notification(int p_notification) {
} break;
case NOTIFICATION_WM_UNFOCUS_REQUEST: {
- notify_group_flags(GROUP_CALL_REALTIME|GROUP_CALL_MULTILEVEL,"input",NOTIFICATION_WM_UNFOCUS_REQUEST);
+ notify_group_flags(GROUP_CALL_REALTIME | GROUP_CALL_MULTILEVEL, "input", NOTIFICATION_WM_UNFOCUS_REQUEST);
} break;
@@ -707,23 +668,22 @@ 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_quit_on_go_back(bool p_enable) {
- quit_on_go_back=p_enable;
+ quit_on_go_back = 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
@@ -738,7 +698,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 {
@@ -748,7 +708,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 {
@@ -756,9 +716,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 {
@@ -766,9 +726,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 {
@@ -776,9 +736,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 {
@@ -786,9 +746,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 {
@@ -801,50 +761,47 @@ Ref<Material> SceneTree::get_debug_navigation_material() {
if (navigation_material.is_valid())
return navigation_material;
- Ref<FixedSpatialMaterial> line_material = Ref<FixedSpatialMaterial>( memnew( FixedSpatialMaterial ));
-/* line_material->set_flag(Material::FLAG_UNSHADED, true);
+ Ref<FixedSpatialMaterial> line_material = Ref<FixedSpatialMaterial>(memnew(FixedSpatialMaterial));
+ /* line_material->set_flag(Material::FLAG_UNSHADED, true);
line_material->set_line_width(3.0);
line_material->set_fixed_flag(FixedSpatialMaterial::FLAG_USE_ALPHA, true);
line_material->set_fixed_flag(FixedSpatialMaterial::FLAG_USE_COLOR_ARRAY, true);
line_material->set_parameter(FixedSpatialMaterial::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<FixedSpatialMaterial> line_material = Ref<FixedSpatialMaterial>( memnew( FixedSpatialMaterial ));
-/* line_material->set_flag(Material::FLAG_UNSHADED, true);
+ Ref<FixedSpatialMaterial> line_material = Ref<FixedSpatialMaterial>(memnew(FixedSpatialMaterial));
+ /* line_material->set_flag(Material::FLAG_UNSHADED, true);
line_material->set_line_width(3.0);
line_material->set_fixed_flag(FixedSpatialMaterial::FLAG_USE_ALPHA, true);
line_material->set_fixed_flag(FixedSpatialMaterial::FLAG_USE_COLOR_ARRAY, true);
line_material->set_parameter(FixedSpatialMaterial::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<FixedSpatialMaterial> line_material = Ref<FixedSpatialMaterial>( memnew( FixedSpatialMaterial ));
+ Ref<FixedSpatialMaterial> line_material = Ref<FixedSpatialMaterial>(memnew(FixedSpatialMaterial));
/*line_material->set_flag(Material::FLAG_UNSHADED, true);
line_material->set_line_width(3.0);
line_material->set_fixed_flag(FixedSpatialMaterial::FLAG_USE_ALPHA, true);
line_material->set_fixed_flag(FixedSpatialMaterial::FLAG_USE_COLOR_ARRAY, true);
line_material->set_parameter(FixedSpatialMaterial::PARAM_DIFFUSE,get_debug_collisions_color());*/
- collision_material=line_material;
+ collision_material = line_material;
return collision_material;
}
@@ -854,62 +811,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<FixedSpatialMaterial> mat = memnew( FixedSpatialMaterial );
+ Ref<FixedSpatialMaterial> mat = memnew(FixedSpatialMaterial);
/*mat->set_flag(Material::FLAG_UNSHADED,true);
mat->set_flag(Material::FLAG_DOUBLE_SIDED,true);
mat->set_fixed_flag(FixedSpatialMaterial::FLAG_USE_ALPHA,true);
mat->set_parameter(FixedSpatialMaterial::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,
};
PoolVector<int> indices;
- for(int i=0;i<8*3;i++)
+ for (int i = 0; i < 8 * 3; i++)
indices.push_back(diamond_faces[i]);
PoolVector<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_from_arrays(Mesh::PRIMITIVE_TRIANGLES,arr);
- debug_contact_mesh->surface_set_material(0,mat);
+ debug_contact_mesh->add_surface_from_arrays(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())
@@ -921,12 +874,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;
@@ -934,17 +887,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;
@@ -957,37 +910,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))
@@ -1001,7 +953,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();
}
@@ -1021,51 +973,47 @@ uint32_t SceneTree::get_last_event_id() const {
return last_id;
}
+Variant SceneTree::_call_group_flags(const Variant **p_args, int p_argcount, Variant::CallError &r_error) {
-Variant SceneTree::_call_group_flags(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(flags,group,method,v[0],v[1],v[2],v[3],v[4]);
+ call_group_flags(flags, group, method, v[0], v[1], v[2], v[3], v[4]);
return Variant();
}
+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<2,Variant());
- ERR_FAIL_COND_V(p_args[0]->get_type()!=Variant::STRING,Variant());
- ERR_FAIL_COND_V(p_args[1]->get_type()!=Variant::STRING,Variant());
+ ERR_FAIL_COND_V(p_argcount < 2, Variant());
+ ERR_FAIL_COND_V(p_args[0]->get_type() != Variant::STRING, Variant());
+ ERR_FAIL_COND_V(p_args[1]->get_type() != Variant::STRING, Variant());
StringName group = *p_args[0];
StringName method = *p_args[1];
Variant v[VARIANT_ARG_MAX];
- for(int i=0;i<MIN(p_argcount-2,5);i++) {
+ for (int i = 0; i < MIN(p_argcount - 2, 5); i++) {
- v[i]=*p_args[i+2];
+ v[i] = *p_args[i + 2];
}
- call_group_flags(0,group,method,v[0],v[1],v[2],v[3],v[4]);
+ call_group_flags(0, group, method, v[0], v[1], v[2], v[3], v[4]);
return Variant();
}
@@ -1074,62 +1022,59 @@ 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_class());
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);
}
}
@@ -1138,20 +1083,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();
}
@@ -1165,27 +1109,24 @@ 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) {
- if (stretch_mode==STRETCH_MODE_DISABLED) {
-
- root->set_size(last_screen_size);
- root->set_attach_to_screen_rect(Rect2(Point2(),last_screen_size));
+ root->set_size(last_screen_size);
+ root->set_attach_to_screen_rect(Rect2(Point2(), last_screen_size));
root->set_size_override_stretch(false);
- root->set_size_override(false,Size2());
+ root->set_size_override(false, Size2());
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;
@@ -1194,42 +1135,41 @@ void SceneTree::_update_root_rect() {
float viewport_aspect = desired_res.aspect();
float video_mode_aspect = video_mode.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();
@@ -1239,16 +1179,16 @@ 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));
@@ -1257,37 +1197,33 @@ void SceneTree::_update_root_rect() {
case STRETCH_MODE_2D: {
root->set_size(screen_size);
- root->set_attach_to_screen_rect(Rect2(margin,screen_size));
+ root->set_attach_to_screen_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_size(viewport_size);
- root->set_attach_to_screen_rect(Rect2(margin,screen_size));
+ root->set_attach_to_screen_rect(Rect2(margin, screen_size));
root->set_size_override_stretch(false);
- root->set_size_override(false,Size2());
+ root->set_size_override(false, Size2());
} 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 {
@@ -1296,76 +1232,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;
@@ -1375,13 +1309,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;
@@ -1390,20 +1324,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;
@@ -1413,13 +1345,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;
@@ -1428,10 +1360,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;
@@ -1445,17 +1377,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;
@@ -1469,29 +1400,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;
@@ -1503,13 +1433,13 @@ void SceneTree::_live_edit_create_node_func(const NodePath& p_parent,const Strin
Object *o = ClassDB::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);
@@ -1520,13 +1450,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;
@@ -1535,29 +1465,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;
@@ -1568,26 +1496,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;
@@ -1599,28 +1525,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;
@@ -1629,12 +1553,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;
@@ -1642,27 +1566,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;
@@ -1678,22 +1601,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;
@@ -1710,23 +1632,19 @@ 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);
}
-
Ref<SceneTreeTimer> SceneTree::create_timer(float p_delay_sec, bool p_process_pause) {
Ref<SceneTreeTimer> stt;
@@ -1739,19 +1657,17 @@ Ref<SceneTreeTimer> SceneTree::create_timer(float p_delay_sec, bool p_process_pa
void SceneTree::_network_peer_connected(int p_id) {
-
connected_peers.insert(p_id);
- path_get_cache.insert(p_id,PathGetCache());
-
+ path_get_cache.insert(p_id, PathGetCache());
- emit_signal("network_peer_connected",p_id);
+ emit_signal("network_peer_connected", p_id);
}
void SceneTree::_network_peer_disconnected(int p_id) {
connected_peers.erase(p_id);
path_get_cache.erase(p_id); //I no longer need your cache, sorry
- emit_signal("network_peer_disconnected",p_id);
+ emit_signal("network_peer_disconnected", p_id);
}
void SceneTree::_connected_to_server() {
@@ -1769,38 +1685,37 @@ void SceneTree::_server_disconnected() {
emit_signal("server_disconnected");
}
-void SceneTree::set_network_peer(const Ref<NetworkedMultiplayerPeer>& p_network_peer) {
+void SceneTree::set_network_peer(const Ref<NetworkedMultiplayerPeer> &p_network_peer) {
if (network_peer.is_valid()) {
- network_peer->disconnect("peer_connected",this,"_network_peer_connected");
- network_peer->disconnect("peer_disconnected",this,"_network_peer_disconnected");
- network_peer->disconnect("connection_succeeded",this,"_connected_to_server");
- network_peer->disconnect("connection_failed",this,"_connection_failed");
- network_peer->disconnect("server_disconnected",this,"_server_disconnected");
+ network_peer->disconnect("peer_connected", this, "_network_peer_connected");
+ network_peer->disconnect("peer_disconnected", this, "_network_peer_disconnected");
+ network_peer->disconnect("connection_succeeded", this, "_connected_to_server");
+ network_peer->disconnect("connection_failed", this, "_connection_failed");
+ network_peer->disconnect("server_disconnected", this, "_server_disconnected");
connected_peers.clear();
path_get_cache.clear();
path_send_cache.clear();
- last_send_cache_id=1;
+ last_send_cache_id = 1;
}
ERR_EXPLAIN("Supplied NetworkedNetworkPeer must be connecting or connected.");
- ERR_FAIL_COND(p_network_peer.is_valid() && p_network_peer->get_connection_status()==NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED);
+ ERR_FAIL_COND(p_network_peer.is_valid() && p_network_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED);
- network_peer=p_network_peer;
+ network_peer = p_network_peer;
if (network_peer.is_valid()) {
- network_peer->connect("peer_connected",this,"_network_peer_connected");
- network_peer->connect("peer_disconnected",this,"_network_peer_disconnected");
- network_peer->connect("connection_succeeded",this,"_connected_to_server");
- network_peer->connect("connection_failed",this,"_connection_failed");
- network_peer->connect("server_disconnected",this,"_server_disconnected");
+ network_peer->connect("peer_connected", this, "_network_peer_connected");
+ network_peer->connect("peer_disconnected", this, "_network_peer_disconnected");
+ network_peer->connect("connection_succeeded", this, "_connected_to_server");
+ network_peer->connect("connection_failed", this, "_connection_failed");
+ network_peer->connect("server_disconnected", this, "_server_disconnected");
}
}
bool SceneTree::is_network_server() const {
- ERR_FAIL_COND_V(!network_peer.is_valid(),false);
+ ERR_FAIL_COND_V(!network_peer.is_valid(), false);
return network_peer->is_server();
-
}
bool SceneTree::has_network_peer() const {
@@ -1809,7 +1724,7 @@ bool SceneTree::has_network_peer() const {
int SceneTree::get_network_unique_id() const {
- ERR_FAIL_COND_V(!network_peer.is_valid(),0);
+ ERR_FAIL_COND_V(!network_peer.is_valid(), 0);
return network_peer->get_unique_id();
}
@@ -1820,41 +1735,38 @@ void SceneTree::set_refuse_new_network_connections(bool p_refuse) {
bool SceneTree::is_refusing_new_network_connections() const {
- ERR_FAIL_COND_V(!network_peer.is_valid(),false);
+ ERR_FAIL_COND_V(!network_peer.is_valid(), false);
return network_peer->is_refusing_new_connections();
-
}
-
-void SceneTree::_rpc(Node* p_from,int p_to,bool p_unreliable,bool p_set,const StringName& p_name,const Variant** p_arg,int p_argcount) {
+void SceneTree::_rpc(Node *p_from, int p_to, bool p_unreliable, bool p_set, const StringName &p_name, const Variant **p_arg, int p_argcount) {
if (network_peer.is_null()) {
ERR_EXPLAIN("Attempt to remote call/set when networking is not active in SceneTree.");
ERR_FAIL();
}
- if (network_peer->get_connection_status()==NetworkedMultiplayerPeer::CONNECTION_CONNECTING) {
+ if (network_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_CONNECTING) {
ERR_EXPLAIN("Attempt to remote call/set when networking is not connected yet in SceneTree.");
ERR_FAIL();
}
- if (network_peer->get_connection_status()==NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED) {
+ if (network_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED) {
ERR_EXPLAIN("Attempt to remote call/set when networking is disconnected.");
ERR_FAIL();
}
- if (p_argcount>255) {
+ if (p_argcount > 255) {
ERR_EXPLAIN("Too many arguments >255.");
ERR_FAIL();
}
- if (p_to!=0 && !connected_peers.has(ABS(p_to))) {
- if (p_to==get_network_unique_id()) {
- ERR_EXPLAIN("Attempt to remote call/set yourself! unique ID: "+itos(get_network_unique_id()));
+ if (p_to != 0 && !connected_peers.has(ABS(p_to))) {
+ if (p_to == get_network_unique_id()) {
+ ERR_EXPLAIN("Attempt to remote call/set yourself! unique ID: " + itos(get_network_unique_id()));
} else {
- ERR_EXPLAIN("Attempt to remote call unexisting ID: "+itos(p_to));
-
+ ERR_EXPLAIN("Attempt to remote call unexisting ID: " + itos(p_to));
}
ERR_FAIL();
@@ -1863,111 +1775,107 @@ void SceneTree::_rpc(Node* p_from,int p_to,bool p_unreliable,bool p_set,const St
NodePath from_path = p_from->get_path();
ERR_FAIL_COND(from_path.is_empty());
-
-
//see if the path is cached
PathSentCache *psc = path_send_cache.getptr(from_path);
if (!psc) {
//path is not cached, create
- path_send_cache[from_path]=PathSentCache();
+ path_send_cache[from_path] = PathSentCache();
psc = path_send_cache.getptr(from_path);
- psc->id=last_send_cache_id++;
-
+ psc->id = last_send_cache_id++;
}
-
//create base packet, lots of harcode because it must be tight
- int ofs=0;
+ int ofs = 0;
-#define MAKE_ROOM(m_amount) if (packet_cache.size() < m_amount) packet_cache.resize(m_amount);
+#define MAKE_ROOM(m_amount) \
+ if (packet_cache.size() < m_amount) packet_cache.resize(m_amount);
//encode type
MAKE_ROOM(1);
- packet_cache[0]=p_set ? NETWORK_COMMAND_REMOTE_SET : NETWORK_COMMAND_REMOTE_CALL;
- ofs+=1;
+ packet_cache[0] = p_set ? NETWORK_COMMAND_REMOTE_SET : NETWORK_COMMAND_REMOTE_CALL;
+ ofs += 1;
//encode ID
- MAKE_ROOM(ofs+4);
- encode_uint32(psc->id,&packet_cache[ofs]);
- ofs+=4;
+ MAKE_ROOM(ofs + 4);
+ encode_uint32(psc->id, &packet_cache[ofs]);
+ ofs += 4;
//encode function name
CharString name = String(p_name).utf8();
- int len = encode_cstring(name.get_data(),NULL);
- MAKE_ROOM(ofs+len);
- encode_cstring(name.get_data(),&packet_cache[ofs]);
- ofs+=len;
+ int len = encode_cstring(name.get_data(), NULL);
+ MAKE_ROOM(ofs + len);
+ encode_cstring(name.get_data(), &packet_cache[ofs]);
+ ofs += len;
if (p_set) {
//set argument
- Error err = encode_variant(*p_arg[0],NULL,len);
- ERR_FAIL_COND(err!=OK);
- MAKE_ROOM(ofs+len);
- encode_variant(*p_arg[0],&packet_cache[ofs],len);
- ofs+=len;
+ Error err = encode_variant(*p_arg[0], NULL, len);
+ ERR_FAIL_COND(err != OK);
+ MAKE_ROOM(ofs + len);
+ encode_variant(*p_arg[0], &packet_cache[ofs], len);
+ ofs += len;
} else {
//call arguments
- MAKE_ROOM(ofs+1);
- packet_cache[ofs]=p_argcount;
- ofs+=1;
- for(int i=0;i<p_argcount;i++) {
- Error err = encode_variant(*p_arg[i],NULL,len);
- ERR_FAIL_COND(err!=OK);
- MAKE_ROOM(ofs+len);
- encode_variant(*p_arg[i],&packet_cache[ofs],len);
- ofs+=len;
+ MAKE_ROOM(ofs + 1);
+ packet_cache[ofs] = p_argcount;
+ ofs += 1;
+ for (int i = 0; i < p_argcount; i++) {
+ Error err = encode_variant(*p_arg[i], NULL, len);
+ ERR_FAIL_COND(err != OK);
+ MAKE_ROOM(ofs + len);
+ encode_variant(*p_arg[i], &packet_cache[ofs], len);
+ ofs += len;
}
-
}
//see if all peers have cached path (is so, call can be fast)
- bool has_all_peers=true;
+ bool has_all_peers = true;
List<int> peers_to_add; //if one is missing, take note to add it
- for (Set<int>::Element *E=connected_peers.front();E;E=E->next()) {
+ for (Set<int>::Element *E = connected_peers.front(); E; E = E->next()) {
- if (p_to<0 && E->get()==-p_to)
+ if (p_to < 0 && E->get() == -p_to)
continue; //continue, excluded
- if (p_to>0 && E->get()!=p_to)
+ if (p_to > 0 && E->get() != p_to)
continue; //continue, not for this peer
- Map<int,bool>::Element *F = psc->confirmed_peers.find(E->get());
+ Map<int, bool>::Element *F = psc->confirmed_peers.find(E->get());
- if (!F || F->get()==false) {
+ if (!F || F->get() == false) {
//path was not cached, or was cached but is unconfirmed
if (!F) {
//not cached at all, take note
peers_to_add.push_back(E->get());
}
- has_all_peers=false;
+ has_all_peers = false;
}
}
//those that need to be added, send a message for this
- for (List<int>::Element *E=peers_to_add.front();E;E=E->next()) {
+ for (List<int>::Element *E = peers_to_add.front(); E; E = E->next()) {
//encode function name
CharString pname = String(from_path).utf8();
- int len = encode_cstring(pname.get_data(),NULL);
+ int len = encode_cstring(pname.get_data(), NULL);
Vector<uint8_t> packet;
- packet.resize(1+4+len);
- packet[0]=NETWORK_COMMAND_SIMPLIFY_PATH;
- encode_uint32(psc->id,&packet[1]);
- encode_cstring(pname.get_data(),&packet[5]);
+ packet.resize(1 + 4 + len);
+ packet[0] = NETWORK_COMMAND_SIMPLIFY_PATH;
+ encode_uint32(psc->id, &packet[1]);
+ encode_cstring(pname.get_data(), &packet[5]);
network_peer->set_target_peer(E->get()); //to all of you
network_peer->set_transfer_mode(NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE);
- network_peer->put_packet(packet.ptr(),packet.size());
+ network_peer->put_packet(packet.ptr(), packet.size());
- psc->confirmed_peers.insert(E->get(),false); //insert into confirmed, but as false since it was not confirmed
+ psc->confirmed_peers.insert(E->get(), false); //insert into confirmed, but as false since it was not confirmed
}
//take chance and set transfer mode, since all send methods will use it
@@ -1977,150 +1885,141 @@ void SceneTree::_rpc(Node* p_from,int p_to,bool p_unreliable,bool p_set,const St
//they all have verified paths, so send fast
network_peer->set_target_peer(p_to); //to all of you
- network_peer->put_packet(packet_cache.ptr(),ofs); //a message with love
+ network_peer->put_packet(packet_cache.ptr(), ofs); //a message with love
} else {
//not all verified path, so send one by one
//apend path at the end, since we will need it for some packets
CharString pname = String(from_path).utf8();
- int path_len = encode_cstring(pname.get_data(),NULL);
- MAKE_ROOM(ofs+path_len);
- encode_cstring(pname.get_data(),&packet_cache[ofs]);
+ int path_len = encode_cstring(pname.get_data(), NULL);
+ MAKE_ROOM(ofs + path_len);
+ encode_cstring(pname.get_data(), &packet_cache[ofs]);
+ for (Set<int>::Element *E = connected_peers.front(); E; E = E->next()) {
- for (Set<int>::Element *E=connected_peers.front();E;E=E->next()) {
-
- if (p_to<0 && E->get()==-p_to)
+ if (p_to < 0 && E->get() == -p_to)
continue; //continue, excluded
- if (p_to>0 && E->get()!=p_to)
+ if (p_to > 0 && E->get() != p_to)
continue; //continue, not for this peer
- Map<int,bool>::Element *F = psc->confirmed_peers.find(E->get());
- ERR_CONTINUE(!F);//should never happen
+ Map<int, bool>::Element *F = psc->confirmed_peers.find(E->get());
+ ERR_CONTINUE(!F); //should never happen
network_peer->set_target_peer(E->get()); //to this one specifically
- if (F->get()==true) {
+ if (F->get() == true) {
//this one confirmed path, so use id
- encode_uint32(psc->id,&packet_cache[1]);
- network_peer->put_packet(packet_cache.ptr(),ofs);
+ encode_uint32(psc->id, &packet_cache[1]);
+ network_peer->put_packet(packet_cache.ptr(), ofs);
} else {
//this one did not confirm path yet, so use entire path (sorry!)
- encode_uint32(0x80000000|ofs,&packet_cache[1]); //offset to path and flag
- network_peer->put_packet(packet_cache.ptr(),ofs+path_len);
+ encode_uint32(0x80000000 | ofs, &packet_cache[1]); //offset to path and flag
+ network_peer->put_packet(packet_cache.ptr(), ofs + path_len);
}
-
}
}
}
+void SceneTree::_network_process_packet(int p_from, const uint8_t *p_packet, int p_packet_len) {
-void SceneTree::_network_process_packet(int p_from, const uint8_t* p_packet, int p_packet_len) {
-
- ERR_FAIL_COND(p_packet_len<5);
+ ERR_FAIL_COND(p_packet_len < 5);
uint8_t packet_type = p_packet[0];
- switch(packet_type) {
+ switch (packet_type) {
case NETWORK_COMMAND_REMOTE_CALL:
case NETWORK_COMMAND_REMOTE_SET: {
- ERR_FAIL_COND(p_packet_len<5);
+ ERR_FAIL_COND(p_packet_len < 5);
uint32_t target = decode_uint32(&p_packet[1]);
+ Node *node = NULL;
- Node *node=NULL;
-
- if (target&0x80000000) {
+ if (target & 0x80000000) {
- int ofs = target&0x7FFFFFFF;
- ERR_FAIL_COND(ofs>=p_packet_len);
+ int ofs = target & 0x7FFFFFFF;
+ ERR_FAIL_COND(ofs >= p_packet_len);
String paths;
- paths.parse_utf8((const char*)&p_packet[ofs],p_packet_len-ofs);
+ paths.parse_utf8((const char *)&p_packet[ofs], p_packet_len - ofs);
NodePath np = paths;
node = get_root()->get_node(np);
- if (node==NULL) {
- ERR_EXPLAIN("Failed to get path from RPC: "+String(np));
- ERR_FAIL_COND(node==NULL);
+ if (node == NULL) {
+ ERR_EXPLAIN("Failed to get path from RPC: " + String(np));
+ ERR_FAIL_COND(node == NULL);
}
} else {
int id = target;
- Map<int,PathGetCache>::Element *E=path_get_cache.find(p_from);
+ Map<int, PathGetCache>::Element *E = path_get_cache.find(p_from);
ERR_FAIL_COND(!E);
- Map<int,PathGetCache::NodeInfo>::Element *F=E->get().nodes.find(id);
+ Map<int, PathGetCache::NodeInfo>::Element *F = E->get().nodes.find(id);
ERR_FAIL_COND(!F);
PathGetCache::NodeInfo *ni = &F->get();
//do proper caching later
node = get_root()->get_node(ni->path);
- if (node==NULL) {
- ERR_EXPLAIN("Failed to get cached path from RPC: "+String(ni->path));
- ERR_FAIL_COND(node==NULL);
+ if (node == NULL) {
+ ERR_EXPLAIN("Failed to get cached path from RPC: " + String(ni->path));
+ ERR_FAIL_COND(node == NULL);
}
-
-
}
- ERR_FAIL_COND(p_packet_len<6);
+ ERR_FAIL_COND(p_packet_len < 6);
//detect cstring end
- int len_end=5;
- for(;len_end<p_packet_len;len_end++) {
- if (p_packet[len_end]==0) {
+ int len_end = 5;
+ for (; len_end < p_packet_len; len_end++) {
+ if (p_packet[len_end] == 0) {
break;
}
}
- ERR_FAIL_COND(len_end>=p_packet_len);
+ ERR_FAIL_COND(len_end >= p_packet_len);
- StringName name = String::utf8((const char*)&p_packet[5]);
+ StringName name = String::utf8((const char *)&p_packet[5]);
-
-
-
- if (packet_type==NETWORK_COMMAND_REMOTE_CALL) {
+ if (packet_type == NETWORK_COMMAND_REMOTE_CALL) {
if (!node->can_call_rpc(name))
return;
- int ofs = len_end+1;
+ int ofs = len_end + 1;
- ERR_FAIL_COND(ofs>=p_packet_len);
+ ERR_FAIL_COND(ofs >= p_packet_len);
int argc = p_packet[ofs];
Vector<Variant> args;
- Vector<const Variant*> argp;
+ Vector<const Variant *> argp;
args.resize(argc);
argp.resize(argc);
ofs++;
- for(int i=0;i<argc;i++) {
+ for (int i = 0; i < argc; i++) {
- ERR_FAIL_COND(ofs>=p_packet_len);
+ ERR_FAIL_COND(ofs >= p_packet_len);
int vlen;
- Error err = decode_variant(args[i],&p_packet[ofs],p_packet_len-ofs,&vlen);
- ERR_FAIL_COND(err!=OK);
+ Error err = decode_variant(args[i], &p_packet[ofs], p_packet_len - ofs, &vlen);
+ ERR_FAIL_COND(err != OK);
//args[i]=p_packet[3+i];
- argp[i]=&args[i];
- ofs+=vlen;
+ argp[i] = &args[i];
+ ofs += vlen;
}
Variant::CallError ce;
- node->call(name,argp.ptr(),argc,ce);
- if (ce.error!=Variant::CallError::CALL_OK) {
- String error = Variant::get_call_error_text(node,name,argp.ptr(),argc,ce);
- error="RPC - "+error;
+ node->call(name, argp.ptr(), argc, ce);
+ if (ce.error != Variant::CallError::CALL_OK) {
+ String error = Variant::get_call_error_text(node, name, argp.ptr(), argc, ce);
+ error = "RPC - " + error;
ERR_PRINTS(error);
}
@@ -2129,18 +2028,18 @@ void SceneTree::_network_process_packet(int p_from, const uint8_t* p_packet, int
if (!node->can_call_rset(name))
return;
- int ofs = len_end+1;
+ int ofs = len_end + 1;
- ERR_FAIL_COND(ofs>=p_packet_len);
+ ERR_FAIL_COND(ofs >= p_packet_len);
Variant value;
- decode_variant(value,&p_packet[ofs],p_packet_len-ofs);
+ decode_variant(value, &p_packet[ofs], p_packet_len - ofs);
bool valid;
- node->set(name,value,&valid);
+ node->set(name, value, &valid);
if (!valid) {
- String error = "Error setting remote property '"+String(name)+"', not found in object of type "+node->get_class();
+ String error = "Error setting remote property '" + String(name) + "', not found in object of type " + node->get_class();
ERR_PRINTS(error);
}
}
@@ -2148,64 +2047,62 @@ void SceneTree::_network_process_packet(int p_from, const uint8_t* p_packet, int
} break;
case NETWORK_COMMAND_SIMPLIFY_PATH: {
- ERR_FAIL_COND(p_packet_len<5);
+ ERR_FAIL_COND(p_packet_len < 5);
int id = decode_uint32(&p_packet[1]);
String paths;
- paths.parse_utf8((const char*)&p_packet[5],p_packet_len-5);
+ paths.parse_utf8((const char *)&p_packet[5], p_packet_len - 5);
NodePath path = paths;
if (!path_get_cache.has(p_from)) {
- path_get_cache[p_from]=PathGetCache();
+ path_get_cache[p_from] = PathGetCache();
}
PathGetCache::NodeInfo ni;
- ni.path=path;
- ni.instance=0;
-
- path_get_cache[p_from].nodes[id]=ni;
+ ni.path = path;
+ ni.instance = 0;
+ path_get_cache[p_from].nodes[id] = ni;
{
//send ack
//encode path
CharString pname = String(path).utf8();
- int len = encode_cstring(pname.get_data(),NULL);
+ int len = encode_cstring(pname.get_data(), NULL);
Vector<uint8_t> packet;
- packet.resize(1+len);
- packet[0]=NETWORK_COMMAND_CONFIRM_PATH;
- encode_cstring(pname.get_data(),&packet[1]);
+ packet.resize(1 + len);
+ packet[0] = NETWORK_COMMAND_CONFIRM_PATH;
+ encode_cstring(pname.get_data(), &packet[1]);
network_peer->set_transfer_mode(NetworkedMultiplayerPeer::TRANSFER_MODE_RELIABLE);
network_peer->set_target_peer(p_from);
- network_peer->put_packet(packet.ptr(),packet.size());
+ network_peer->put_packet(packet.ptr(), packet.size());
}
} break;
case NETWORK_COMMAND_CONFIRM_PATH: {
String paths;
- paths.parse_utf8((const char*)&p_packet[1],p_packet_len-1);
+ paths.parse_utf8((const char *)&p_packet[1], p_packet_len - 1);
NodePath path = paths;
PathSentCache *psc = path_send_cache.getptr(path);
ERR_FAIL_COND(!psc);
- Map<int,bool>::Element *E=psc->confirmed_peers.find(p_from);
+ Map<int, bool>::Element *E = psc->confirmed_peers.find(p_from);
ERR_FAIL_COND(!E);
- E->get()=true;
+ E->get() = true;
} break;
}
-
}
void SceneTree::_network_poll() {
- if (!network_peer.is_valid() || network_peer->get_connection_status()==NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED)
+ if (!network_peer.is_valid() || network_peer->get_connection_status() == NetworkedMultiplayerPeer::CONNECTION_DISCONNECTED)
return;
network_peer->poll();
@@ -2213,269 +2110,245 @@ void SceneTree::_network_poll() {
if (!network_peer.is_valid()) //it's possible that polling might have resulted in a disconnection, so check here
return;
- while(network_peer->get_available_packet_count()) {
+ while (network_peer->get_available_packet_count()) {
int sender = network_peer->get_packet_peer();
const uint8_t *packet;
int len;
- Error err = network_peer->get_packet(&packet,len);
- if (err!=OK) {
+ Error err = network_peer->get_packet(&packet, len);
+ if (err != OK) {
ERR_PRINT("Error getting packet!");
}
- _network_process_packet(sender,packet,len);
+ _network_process_packet(sender, packet, len);
if (!network_peer.is_valid()) {
break; //it's also possible that a packet or RPC caused a disconnection, so also check here
}
}
-
-
}
-
void SceneTree::_bind_methods() {
-
//ClassDB::bind_method(D_METHOD("call_group","call_flags","group","method","arg1","arg2"),&SceneMainLoop::_call_group,DEFVAL(Variant()),DEFVAL(Variant()));
- ClassDB::bind_method(D_METHOD("get_root:Viewport"),&SceneTree::get_root);
- ClassDB::bind_method(D_METHOD("has_group","name"),&SceneTree::has_group);
+ ClassDB::bind_method(D_METHOD("get_root:Viewport"), &SceneTree::get_root);
+ ClassDB::bind_method(D_METHOD("has_group", "name"), &SceneTree::has_group);
- ClassDB::bind_method(D_METHOD("set_auto_accept_quit","enabled"),&SceneTree::set_auto_accept_quit);
+ ClassDB::bind_method(D_METHOD("set_auto_accept_quit", "enabled"), &SceneTree::set_auto_accept_quit);
- ClassDB::bind_method(D_METHOD("set_editor_hint","enable"),&SceneTree::set_editor_hint);
- ClassDB::bind_method(D_METHOD("is_editor_hint"),&SceneTree::is_editor_hint);
- ClassDB::bind_method(D_METHOD("set_debug_collisions_hint","enable"),&SceneTree::set_debug_collisions_hint);
- ClassDB::bind_method(D_METHOD("is_debugging_collisions_hint"),&SceneTree::is_debugging_collisions_hint);
- ClassDB::bind_method(D_METHOD("set_debug_navigation_hint","enable"),&SceneTree::set_debug_navigation_hint);
- ClassDB::bind_method(D_METHOD("is_debugging_navigation_hint"),&SceneTree::is_debugging_navigation_hint);
+ ClassDB::bind_method(D_METHOD("set_editor_hint", "enable"), &SceneTree::set_editor_hint);
+ ClassDB::bind_method(D_METHOD("is_editor_hint"), &SceneTree::is_editor_hint);
+ ClassDB::bind_method(D_METHOD("set_debug_collisions_hint", "enable"), &SceneTree::set_debug_collisions_hint);
+ ClassDB::bind_method(D_METHOD("is_debugging_collisions_hint"), &SceneTree::is_debugging_collisions_hint);
+ ClassDB::bind_method(D_METHOD("set_debug_navigation_hint", "enable"), &SceneTree::set_debug_navigation_hint);
+ ClassDB::bind_method(D_METHOD("is_debugging_navigation_hint"), &SceneTree::is_debugging_navigation_hint);
#ifdef TOOLS_ENABLED
- ClassDB::bind_method(D_METHOD("set_edited_scene_root","scene"),&SceneTree::set_edited_scene_root);
- ClassDB::bind_method(D_METHOD("get_edited_scene_root"),&SceneTree::get_edited_scene_root);
+ ClassDB::bind_method(D_METHOD("set_edited_scene_root", "scene"), &SceneTree::set_edited_scene_root);
+ ClassDB::bind_method(D_METHOD("get_edited_scene_root"), &SceneTree::get_edited_scene_root);
#endif
- ClassDB::bind_method(D_METHOD("set_pause","enable"),&SceneTree::set_pause);
- ClassDB::bind_method(D_METHOD("is_paused"),&SceneTree::is_paused);
- ClassDB::bind_method(D_METHOD("set_input_as_handled"),&SceneTree::set_input_as_handled);
+ ClassDB::bind_method(D_METHOD("set_pause", "enable"), &SceneTree::set_pause);
+ ClassDB::bind_method(D_METHOD("is_paused"), &SceneTree::is_paused);
+ ClassDB::bind_method(D_METHOD("set_input_as_handled"), &SceneTree::set_input_as_handled);
- ClassDB::bind_method(D_METHOD("create_timer:SceneTreeTimer","time_sec", "pause_mode_process"),&SceneTree::create_timer, DEFVAL(true));
-
-
- ClassDB::bind_method(D_METHOD("get_node_count"),&SceneTree::get_node_count);
- ClassDB::bind_method(D_METHOD("get_frame"),&SceneTree::get_frame);
- ClassDB::bind_method(D_METHOD("quit"),&SceneTree::quit);
-
- ClassDB::bind_method(D_METHOD("set_screen_stretch","mode","aspect","minsize"),&SceneTree::set_screen_stretch);
-
- ClassDB::bind_method(D_METHOD("queue_delete","obj"),&SceneTree::queue_delete);
+ ClassDB::bind_method(D_METHOD("create_timer:SceneTreeTimer", "time_sec", "pause_mode_process"), &SceneTree::create_timer, DEFVAL(true));
+ ClassDB::bind_method(D_METHOD("get_node_count"), &SceneTree::get_node_count);
+ ClassDB::bind_method(D_METHOD("get_frame"), &SceneTree::get_frame);
+ ClassDB::bind_method(D_METHOD("quit"), &SceneTree::quit);
+ ClassDB::bind_method(D_METHOD("set_screen_stretch", "mode", "aspect", "minsize"), &SceneTree::set_screen_stretch);
+ ClassDB::bind_method(D_METHOD("queue_delete", "obj"), &SceneTree::queue_delete);
MethodInfo mi;
- mi.name="call_group_flags";
- 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_flags";
+ mi.arguments.push_back(PropertyInfo(Variant::INT, "flags"));
+ mi.arguments.push_back(PropertyInfo(Variant::STRING, "group"));
+ mi.arguments.push_back(PropertyInfo(Variant::STRING, "method"));
- ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT,"call_group_flags",&SceneTree::_call_group_flags,mi);
+ ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "call_group_flags", &SceneTree::_call_group_flags, mi);
- ClassDB::bind_method(D_METHOD("notify_group_flags","call_flags","group","notification"),&SceneTree::notify_group_flags);
- ClassDB::bind_method(D_METHOD("set_group_flags","call_flags","group","property","value"),&SceneTree::set_group_flags);
+ ClassDB::bind_method(D_METHOD("notify_group_flags", "call_flags", "group", "notification"), &SceneTree::notify_group_flags);
+ ClassDB::bind_method(D_METHOD("set_group_flags", "call_flags", "group", "property", "value"), &SceneTree::set_group_flags);
MethodInfo mi2;
- mi2.name="call_group";
- mi2.arguments.push_back( PropertyInfo( Variant::STRING, "group"));
- mi2.arguments.push_back( PropertyInfo( Variant::STRING, "method"));
-
-
- ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT,"call_group",&SceneTree::_call_group,mi2);
-
- ClassDB::bind_method(D_METHOD("notify_group","call_flags","group","notification"),&SceneTree::notify_group);
- ClassDB::bind_method(D_METHOD("set_group","call_flags","group","property","value"),&SceneTree::set_group);
-
- ClassDB::bind_method(D_METHOD("get_nodes_in_group","group"),&SceneTree::_get_nodes_in_group);
+ mi2.name = "call_group";
+ mi2.arguments.push_back(PropertyInfo(Variant::STRING, "group"));
+ mi2.arguments.push_back(PropertyInfo(Variant::STRING, "method"));
+ ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "call_group", &SceneTree::_call_group, mi2);
- ClassDB::bind_method(D_METHOD("set_current_scene","child_node:Node"),&SceneTree::set_current_scene);
- ClassDB::bind_method(D_METHOD("get_current_scene:Node"),&SceneTree::get_current_scene);
+ ClassDB::bind_method(D_METHOD("notify_group", "call_flags", "group", "notification"), &SceneTree::notify_group);
+ ClassDB::bind_method(D_METHOD("set_group", "call_flags", "group", "property", "value"), &SceneTree::set_group);
- ClassDB::bind_method(D_METHOD("change_scene","path"),&SceneTree::change_scene);
- ClassDB::bind_method(D_METHOD("change_scene_to","packed_scene:PackedScene"),&SceneTree::change_scene_to);
+ ClassDB::bind_method(D_METHOD("get_nodes_in_group", "group"), &SceneTree::_get_nodes_in_group);
- ClassDB::bind_method(D_METHOD("reload_current_scene"),&SceneTree::reload_current_scene);
+ ClassDB::bind_method(D_METHOD("set_current_scene", "child_node:Node"), &SceneTree::set_current_scene);
+ ClassDB::bind_method(D_METHOD("get_current_scene:Node"), &SceneTree::get_current_scene);
- ClassDB::bind_method(D_METHOD("_change_scene"),&SceneTree::_change_scene);
+ ClassDB::bind_method(D_METHOD("change_scene", "path"), &SceneTree::change_scene);
+ ClassDB::bind_method(D_METHOD("change_scene_to", "packed_scene:PackedScene"), &SceneTree::change_scene_to);
+ ClassDB::bind_method(D_METHOD("reload_current_scene"), &SceneTree::reload_current_scene);
- ClassDB::bind_method(D_METHOD("set_network_peer","peer:NetworkedMultiplayerPeer"),&SceneTree::set_network_peer);
- ClassDB::bind_method(D_METHOD("is_network_server"),&SceneTree::is_network_server);
- ClassDB::bind_method(D_METHOD("has_network_peer"),&SceneTree::has_network_peer);
- ClassDB::bind_method(D_METHOD("get_network_unique_id"),&SceneTree::get_network_unique_id);
- ClassDB::bind_method(D_METHOD("set_refuse_new_network_connections","refuse"),&SceneTree::set_refuse_new_network_connections);
- ClassDB::bind_method(D_METHOD("is_refusing_new_network_connections"),&SceneTree::is_refusing_new_network_connections);
- ClassDB::bind_method(D_METHOD("_network_peer_connected"),&SceneTree::_network_peer_connected);
- ClassDB::bind_method(D_METHOD("_network_peer_disconnected"),&SceneTree::_network_peer_disconnected);
- ClassDB::bind_method(D_METHOD("_connected_to_server"),&SceneTree::_connected_to_server);
- ClassDB::bind_method(D_METHOD("_connection_failed"),&SceneTree::_connection_failed);
- ClassDB::bind_method(D_METHOD("_server_disconnected"),&SceneTree::_server_disconnected);
+ ClassDB::bind_method(D_METHOD("_change_scene"), &SceneTree::_change_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")) );
+ ClassDB::bind_method(D_METHOD("set_network_peer", "peer:NetworkedMultiplayerPeer"), &SceneTree::set_network_peer);
+ ClassDB::bind_method(D_METHOD("is_network_server"), &SceneTree::is_network_server);
+ ClassDB::bind_method(D_METHOD("has_network_peer"), &SceneTree::has_network_peer);
+ ClassDB::bind_method(D_METHOD("get_network_unique_id"), &SceneTree::get_network_unique_id);
+ ClassDB::bind_method(D_METHOD("set_refuse_new_network_connections", "refuse"), &SceneTree::set_refuse_new_network_connections);
+ ClassDB::bind_method(D_METHOD("is_refusing_new_network_connections"), &SceneTree::is_refusing_new_network_connections);
+ ClassDB::bind_method(D_METHOD("_network_peer_connected"), &SceneTree::_network_peer_connected);
+ ClassDB::bind_method(D_METHOD("_network_peer_disconnected"), &SceneTree::_network_peer_disconnected);
+ ClassDB::bind_method(D_METHOD("_connected_to_server"), &SceneTree::_connected_to_server);
+ ClassDB::bind_method(D_METHOD("_connection_failed"), &SceneTree::_connection_failed);
+ ClassDB::bind_method(D_METHOD("_server_disconnected"), &SceneTree::_server_disconnected);
- 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::POOL_STRING_ARRAY,"files"),PropertyInfo(Variant::INT,"screen")) );
- ADD_SIGNAL( MethodInfo("network_peer_connected",PropertyInfo(Variant::INT,"id")));
- ADD_SIGNAL( MethodInfo("network_peer_disconnected",PropertyInfo(Variant::INT,"id")));
- ADD_SIGNAL( MethodInfo("connected_to_server"));
- ADD_SIGNAL( MethodInfo("connection_failed"));
- ADD_SIGNAL( MethodInfo("server_disconnected"));
+ 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::POOL_STRING_ARRAY, "files"), PropertyInfo(Variant::INT, "screen")));
+ ADD_SIGNAL(MethodInfo("network_peer_connected", PropertyInfo(Variant::INT, "id")));
+ ADD_SIGNAL(MethodInfo("network_peer_disconnected", PropertyInfo(Variant::INT, "id")));
+ ADD_SIGNAL(MethodInfo("connected_to_server"));
+ ADD_SIGNAL(MethodInfo("connection_failed"));
+ ADD_SIGNAL(MethodInfo("server_disconnected"));
- 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::IdleCallback SceneTree::idle_callbacks[SceneTree::MAX_IDLE_CALLBACKS];
-int SceneTree::idle_callback_count=0;
+int SceneTree::idle_callback_count = 0;
void SceneTree::_call_idle_callbacks() {
- for(int i=0;i<idle_callback_count;i++) {
+ for (int i = 0; i < idle_callback_count; i++) {
idle_callbacks[i]();
}
}
void SceneTree::add_idle_callback(IdleCallback p_callback) {
- ERR_FAIL_COND(idle_callback_count>=MAX_IDLE_CALLBACKS);
- idle_callbacks[idle_callback_count++]=p_callback;
+ ERR_FAIL_COND(idle_callback_count >= MAX_IDLE_CALLBACKS);
+ idle_callbacks[idle_callback_count++] = p_callback;
}
-
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);
-
-
-
- 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;
+ 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;
//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;
- int ref_atlas_size = GLOBAL_DEF("rendering/reflections/atlas_size",2048);
- int ref_atlas_subdiv = GLOBAL_DEF("rendering/reflections/atlas_subdiv",8);
- int msaa_mode = GLOBAL_DEF("rendering/quality/msaa",0);
- GlobalConfig::get_singleton()->set_custom_property_info("rendering/quality/msaa",PropertyInfo(Variant::INT,"rendering/quality/msaa",PROPERTY_HINT_ENUM,"Disabled,2x,4x,8x,16x"));
+ int ref_atlas_size = GLOBAL_DEF("rendering/reflections/atlas_size", 2048);
+ int ref_atlas_subdiv = GLOBAL_DEF("rendering/reflections/atlas_subdiv", 8);
+ int msaa_mode = GLOBAL_DEF("rendering/quality/msaa", 0);
+ GlobalConfig::get_singleton()->set_custom_property_info("rendering/quality/msaa", PropertyInfo(Variant::INT, "rendering/quality/msaa", PROPERTY_HINT_ENUM, "Disabled,2x,4x,8x,16x"));
root->set_msaa(Viewport::MSAA(msaa_mode));
- bool hdr = GLOBAL_DEF("rendering/quality/hdr",true);
+ bool hdr = GLOBAL_DEF("rendering/quality/hdr", true);
root->set_hdr(hdr);
- VS::get_singleton()->scenario_set_reflection_atlas_size(root->get_world()->get_scenario(),ref_atlas_size,ref_atlas_subdiv);
-
+ VS::get_singleton()->scenario_set_reflection_atlas_size(root->get_world()->get_scenario(), ref_atlas_size, ref_atlas_subdiv);
- 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 );
+ last_screen_size = Size2(OS::get_singleton()->get_video_mode().width, OS::get_singleton()->get_video_mode().height);
root->set_size(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/common/enable_object_picking",true));
+ root->set_physics_object_picking(GLOBAL_DEF("physics/common/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.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.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;
if (ScriptDebugger::get_singleton()) {
ScriptDebugger::get_singleton()->set_live_edit_funcs(&live_edit_funcs);
}
- live_edit_root=NodePath("/root");
+ live_edit_root = NodePath("/root");
- last_send_cache_id=1;
+ last_send_cache_id = 1;
#endif
-
-
}
-
SceneTree::~SceneTree() {
-
-
}
diff --git a/scene/main/scene_main_loop.h b/scene/main/scene_main_loop.h
index 7f69f5eef7..fadf77e30f 100644
--- a/scene/main/scene_main_loop.h
+++ b/scene/main/scene_main_loop.h
@@ -29,20 +29,17 @@
#ifndef SCENE_MAIN_LOOP_H
#define SCENE_MAIN_LOOP_H
-
+#include "io/networked_multiplayer_peer.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"
-#include "io/networked_multiplayer_peer.h"
-
/**
@author Juan Linietsky <reduzio@gmail.com>
*/
-
class SceneTree;
class PackedScene;
class Node;
@@ -50,17 +47,16 @@ class Viewport;
class Material;
class Mesh;
-
-
class SceneTreeTimer : public Reference {
- GDCLASS(SceneTreeTimer,Reference);
+ GDCLASS(SceneTreeTimer, Reference);
float time_left;
bool process_pause;
+
protected:
static void _bind_methods();
-public:
+public:
void set_time_left(float p_time);
float get_time_left() const;
@@ -74,10 +70,9 @@ class SceneTree : public MainLoop {
_THREAD_SAFE_CLASS_
- GDCLASS( SceneTree, MainLoop );
-public:
-
+ GDCLASS(SceneTree, MainLoop);
+public:
typedef void (*IdleCallback)();
enum StretchMode {
@@ -94,15 +89,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;
@@ -120,7 +114,7 @@ private:
bool pause;
int root_lock;
- Map<StringName,Group> group_map;
+ Map<StringName, Group> group_map;
bool _quit;
bool initialized;
bool input_handled;
@@ -128,7 +122,6 @@ private:
StringName tree_changed_name;
StringName node_removed_name;
-
int64_t current_frame;
int node_count;
@@ -140,13 +133,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;
@@ -156,15 +148,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;
@@ -178,12 +170,11 @@ 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);
List<Ref<SceneTreeTimer> > timers;
-
///network///
enum NetworkCommands {
@@ -205,11 +196,11 @@ private:
//path sent caches
struct PathSentCache {
- Map<int,bool> confirmed_peers;
+ Map<int, bool> confirmed_peers;
int id;
};
- HashMap<NodePath,PathSentCache> path_send_cache;
+ HashMap<NodePath, PathSentCache> path_send_cache;
int last_send_cache_id;
//path get caches
@@ -219,10 +210,10 @@ private:
ObjectID instance;
};
- Map<int,NodeInfo> nodes;
+ Map<int, NodeInfo> nodes;
};
- Map<int,PathGetCache> path_get_cache;
+ Map<int, PathGetCache> path_get_cache;
Vector<uint8_t> packet_cache;
@@ -230,91 +221,85 @@ private:
void _network_poll();
static SceneTree *singleton;
-friend class Node;
-
-
+ friend class Node;
-
- void _rpc(Node* p_from,int p_to,bool p_unreliable,bool p_set,const StringName& p_name,const Variant** p_arg,int p_argcount);
+ void _rpc(Node *p_from, int p_to, bool p_unreliable, bool p_set, const StringName &p_name, const Variant **p_arg, int p_argcount);
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_flags(const Variant** p_args, int p_argcount, Variant::CallError& r_error);
- 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_flags(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
+ 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_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);
-
- 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_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); }
+ 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_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_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); }
#endif
enum {
- MAX_IDLE_CALLBACKS=256
+ MAX_IDLE_CALLBACKS = 256
};
static IdleCallback idle_callbacks[MAX_IDLE_CALLBACKS];
@@ -322,39 +307,36 @@ friend class Viewport;
void _call_idle_callbacks();
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_MULTILEVEL=8,
+ GROUP_CALL_DEFAULT = 0,
+ GROUP_CALL_REVERSE = 1,
+ GROUP_CALL_REALTIME = 2,
+ GROUP_CALL_UNIQUE = 4,
+ GROUP_CALL_MULTILEVEL = 8,
};
_FORCE_INLINE_ Viewport *get_root() const { return root; }
uint32_t get_last_event_id() const;
- void call_group_flags(uint32_t p_call_flags,const StringName& p_group,const StringName& p_function,VARIANT_ARG_LIST);
- void notify_group_flags(uint32_t p_call_flags,const StringName& p_group,int p_notification);
- void set_group_flags(uint32_t p_call_flags,const StringName& p_group,const String& p_name,const Variant& p_value);
+ void call_group_flags(uint32_t p_call_flags, const StringName &p_group, const StringName &p_function, VARIANT_ARG_LIST);
+ void notify_group_flags(uint32_t p_call_flags, const StringName &p_group, int p_notification);
+ void set_group_flags(uint32_t p_call_flags, const StringName &p_group, const String &p_name, const Variant &p_value);
- void call_group(const StringName& p_group,const StringName& p_function,VARIANT_ARG_LIST);
- void notify_group(const StringName& p_group,int p_notification);
- void set_group(const StringName& p_group,const String& p_name,const Variant& p_value);
+ void call_group(const StringName &p_group, const StringName &p_function, VARIANT_ARG_LIST);
+ void notify_group(const StringName &p_group, int p_notification);
+ void set_group(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);
@@ -374,12 +356,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);
@@ -388,19 +370,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();
@@ -414,38 +395,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();
- Ref<SceneTreeTimer> create_timer(float p_delay_sec, bool p_process_pause=true);
+ Ref<SceneTreeTimer> create_timer(float p_delay_sec, bool p_process_pause = true);
//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);
//network API
- void set_network_peer(const Ref<NetworkedMultiplayerPeer>& p_network_peer);
+ void set_network_peer(const Ref<NetworkedMultiplayerPeer> &p_network_peer);
bool is_network_server() const;
bool has_network_peer() const;
int get_network_unique_id() const;
@@ -456,13 +436,9 @@ public:
static void add_idle_callback(IdleCallback p_callback);
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 d27b53d48b..5df30e5080 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_INTERNAL_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_internal(false);
set_process_internal(true);
}
- break;
+ break;
case TIMER_PROCESS_IDLE:
if (is_processing_internal()) {
set_process_internal(false);
set_fixed_process_internal(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_internal(p_process && active); break;
case TIMER_PROCESS_IDLE: set_process_internal(p_process && active); break;
@@ -179,43 +170,42 @@ void Timer::_set_process(bool p_process, bool p_force)
void Timer::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_wait_time","time_sec"),&Timer::set_wait_time);
- ClassDB::bind_method(D_METHOD("get_wait_time"),&Timer::get_wait_time);
+ ClassDB::bind_method(D_METHOD("set_wait_time", "time_sec"), &Timer::set_wait_time);
+ ClassDB::bind_method(D_METHOD("get_wait_time"), &Timer::get_wait_time);
- ClassDB::bind_method(D_METHOD("set_one_shot","enable"),&Timer::set_one_shot);
- ClassDB::bind_method(D_METHOD("is_one_shot"),&Timer::is_one_shot);
+ ClassDB::bind_method(D_METHOD("set_one_shot", "enable"), &Timer::set_one_shot);
+ ClassDB::bind_method(D_METHOD("is_one_shot"), &Timer::is_one_shot);
- ClassDB::bind_method(D_METHOD("set_autostart","enable"),&Timer::set_autostart);
- ClassDB::bind_method(D_METHOD("has_autostart"),&Timer::has_autostart);
+ ClassDB::bind_method(D_METHOD("set_autostart", "enable"), &Timer::set_autostart);
+ ClassDB::bind_method(D_METHOD("has_autostart"), &Timer::has_autostart);
- ClassDB::bind_method(D_METHOD("start"),&Timer::start);
- ClassDB::bind_method(D_METHOD("stop"),&Timer::stop);
+ ClassDB::bind_method(D_METHOD("start"), &Timer::start);
+ ClassDB::bind_method(D_METHOD("stop"), &Timer::stop);
ClassDB::bind_method(D_METHOD("set_active", "active"), &Timer::set_active);
ClassDB::bind_method(D_METHOD("is_active"), &Timer::is_active);
- ClassDB::bind_method(D_METHOD("get_time_left"),&Timer::get_time_left);
+ ClassDB::bind_method(D_METHOD("get_time_left"), &Timer::get_time_left);
ClassDB::bind_method(D_METHOD("set_timer_process_mode", "mode"), &Timer::set_timer_process_mode);
ClassDB::bind_method(D_METHOD("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"), "set_timer_process_mode", "get_timer_process_mode") ;
- ADD_PROPERTY( PropertyInfo(Variant::REAL, "wait_time", PROPERTY_HINT_EXP_RANGE, "0.01,4096,0.01" ), "set_wait_time", "get_wait_time") ;
- ADD_PROPERTY( PropertyInfo(Variant::BOOL, "one_shot" ), "set_one_shot", "is_one_shot") ;
- ADD_PROPERTY( PropertyInfo(Variant::BOOL, "autostart" ), "set_autostart", "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"), "set_timer_process_mode", "get_timer_process_mode");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "wait_time", PROPERTY_HINT_EXP_RANGE, "0.01,4096,0.01"), "set_wait_time", "get_wait_time");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "one_shot"), "set_one_shot", "is_one_shot");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "autostart"), "set_autostart", "has_autostart");
+ BIND_CONSTANT(TIMER_PROCESS_FIXED);
+ BIND_CONSTANT(TIMER_PROCESS_IDLE);
}
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 6b69f3f409..756b779717 100644
--- a/scene/main/timer.h
+++ b/scene/main/timer.h
@@ -33,7 +33,7 @@
class Timer : public Node {
- GDCLASS( Timer, Node );
+ GDCLASS(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 ef39dcde4b..23f8189167 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -27,24 +27,23 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "viewport.h"
+#include "os/input.h"
#include "os/os.h"
#include "scene/3d/spatial.h"
-#include "os/input.h"
#include "servers/physics_2d_server.h"
//#include "scene/3d/camera.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 "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"
@@ -56,7 +55,7 @@ void ViewportTexture::setup_local_to_scene() {
vp->viewport_textures.erase(this);
}
- vp=NULL;
+ vp = NULL;
Node *local_scene = get_local_scene();
if (!local_scene) {
@@ -75,17 +74,16 @@ void ViewportTexture::setup_local_to_scene() {
vp->viewport_textures.insert(this);
}
-void ViewportTexture::set_viewport_path_in_scene(const NodePath& p_path) {
+void ViewportTexture::set_viewport_path_in_scene(const NodePath &p_path) {
- if (path==p_path)
+ if (path == p_path)
return;
- path=p_path;
+ path = p_path;
if (get_local_scene()) {
setup_local_to_scene();
}
-
}
NodePath ViewportTexture::get_viewport_path_in_scene() const {
@@ -95,41 +93,40 @@ NodePath ViewportTexture::get_viewport_path_in_scene() const {
int ViewportTexture::get_width() const {
- ERR_FAIL_COND_V(!vp,0);
+ ERR_FAIL_COND_V(!vp, 0);
return vp->size.width;
}
-int ViewportTexture::get_height() const{
+int ViewportTexture::get_height() const {
- ERR_FAIL_COND_V(!vp,0);
+ ERR_FAIL_COND_V(!vp, 0);
return vp->size.height;
}
-Size2 ViewportTexture::get_size() const{
+Size2 ViewportTexture::get_size() const {
- ERR_FAIL_COND_V(!vp,Size2());
+ ERR_FAIL_COND_V(!vp, Size2());
return vp->size;
}
-RID ViewportTexture::get_rid() const{
+RID ViewportTexture::get_rid() const {
- ERR_FAIL_COND_V(!vp,RID());
+ ERR_FAIL_COND_V(!vp, RID());
return vp->texture_rid;
}
-bool ViewportTexture::has_alpha() const{
+bool ViewportTexture::has_alpha() const {
return false;
}
-void ViewportTexture::set_flags(uint32_t p_flags){
+void ViewportTexture::set_flags(uint32_t p_flags) {
if (!vp)
return;
- vp->texture_flags=p_flags;
- VS::get_singleton()->texture_set_flags(vp->texture_rid,p_flags);
-
+ vp->texture_flags = p_flags;
+ VS::get_singleton()->texture_set_flags(vp->texture_rid, p_flags);
}
-uint32_t ViewportTexture::get_flags() const{
+uint32_t ViewportTexture::get_flags() const {
if (!vp)
return 0;
@@ -139,21 +136,19 @@ uint32_t ViewportTexture::get_flags() const{
void ViewportTexture::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_viewport_path_in_scene","path"),&ViewportTexture::set_viewport_path_in_scene);
- ClassDB::bind_method(D_METHOD("get_viewport_path_in_scene"),&ViewportTexture::get_viewport_path_in_scene);
-
- ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH,"viewport_path"),"set_viewport_path_in_scene","get_viewport_path_in_scene");
+ ClassDB::bind_method(D_METHOD("set_viewport_path_in_scene", "path"), &ViewportTexture::set_viewport_path_in_scene);
+ ClassDB::bind_method(D_METHOD("get_viewport_path_in_scene"), &ViewportTexture::get_viewport_path_in_scene);
+ ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "viewport_path"), "set_viewport_path_in_scene", "get_viewport_path_in_scene");
}
-ViewportTexture::ViewportTexture(){
+ViewportTexture::ViewportTexture() {
- vp=NULL;
+ vp = NULL;
set_local_to_scene(true);
-
}
-ViewportTexture::~ViewportTexture(){
+ViewportTexture::~ViewportTexture() {
if (vp) {
vp->viewport_textures.erase(this);
@@ -164,37 +159,32 @@ ViewportTexture::~ViewportTexture(){
class TooltipPanel : public Panel {
- GDCLASS(TooltipPanel,Panel)
+ GDCLASS(TooltipPanel, Panel)
public:
- TooltipPanel() {};
-
+ TooltipPanel(){};
};
class TooltipLabel : public Label {
- GDCLASS(TooltipLabel,Label)
+ GDCLASS(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() {
@@ -202,20 +192,17 @@ void Viewport::_update_stretch_transform() {
//print_line("sive override size "+size_override_size);
//print_line("rect size "+size);
- stretch_transform=Transform2D();
- Size2 scale = size/(size_override_size+size_override_margin*2);
+ stretch_transform = Transform2D();
+ Size2 scale = 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=Transform2D();
+ stretch_transform = Transform2D();
}
_update_global_transform();
-
}
void Viewport::_update_rect() {
@@ -223,7 +210,6 @@ void Viewport::_update_rect() {
if (!is_inside_tree())
return;
-
/*if (!render_target && parent_control) {
Control *c = parent_control;
@@ -231,7 +217,7 @@ void Viewport::_update_rect() {
rect.pos=Point2();
rect.size=c->get_size();
}*/
-/*
+ /*
VisualServer::ViewportRect vr;
vr.x=rect.pos.x;
vr.y=rect.pos.y;
@@ -253,7 +239,6 @@ void Viewport::_update_rect() {
emit_signal("size_changed");
texture->emit_changed();
*/
-
}
void Viewport::_parent_resized() {
@@ -262,12 +247,11 @@ void Viewport::_parent_resized() {
}
void Viewport::_parent_draw() {
-
}
void Viewport::_parent_visibility_changed() {
-/*
+ /*
if (parent_control) {
Control *c = parent_control;
@@ -277,13 +261,11 @@ void Viewport::_parent_visibility_changed() {
_update_listener_2d();
}
*/
-
}
-
void Viewport::_vp_enter_tree() {
-/* if (parent_control) {
+ /* if (parent_control) {
Control *cparent=parent_control;
RID parent_ci = cparent->get_canvas_item();
@@ -301,7 +283,6 @@ void Viewport::_vp_enter_tree() {
}
*/
-
}
void Viewport::_vp_exit_tree() {
@@ -332,23 +313,21 @@ void Viewport::_vp_exit_tree() {
*/
}
-
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);
@@ -366,72 +345,66 @@ 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()) {
parent = get_parent()->get_viewport();
- VisualServer::get_singleton()->viewport_set_parent_viewport(viewport,parent->get_viewport_rid());
+ VisualServer::get_singleton()->viewport_set_parent_viewport(viewport, parent->get_viewport_rid());
} else {
- parent=NULL;
+ parent = NULL;
}
- 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_allocate(contact_3d_debug_multimesh,get_tree()->get_collision_debug_contact_count(),VS::MULTIMESH_TRANSFORM_3D,VS::MULTIMESH_COLOR_8BIT);
- 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_allocate(contact_3d_debug_multimesh, get_tree()->get_collision_debug_contact_count(), VS::MULTIMESH_TRANSFORM_3D, VS::MULTIMESH_COLOR_8BIT);
+ 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);
}
- VS::get_singleton()->viewport_set_active(viewport,true);
+ VS::get_singleton()->viewport_set_active(viewport, 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();
}
}
@@ -441,11 +414,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();
}
}
@@ -456,7 +429,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);
@@ -466,33 +438,31 @@ void Viewport::_notification(int p_what) {
_vp_exit_tree();
*/
- 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_set_scenario(viewport, RID());
+ // SpatialSoundServer::get_singleton()->listener_set_space(internal_listener, RID());
+ 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");
-
- VS::get_singleton()->viewport_set_active(viewport,false);
-
+ VS::get_singleton()->viewport_set_active(viewport, false);
} 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();
}
}
@@ -500,107 +470,99 @@ void Viewport::_notification(int p_what) {
if (get_tree()->is_debugging_collisions_hint() && contact_2d_debug.is_valid()) {
VisualServer::get_singleton()->canvas_item_clear(contact_2d_debug);
- VisualServer::get_singleton()->canvas_item_set_draw_index(contact_2d_debug,0xFFFFF); //very high index
+ VisualServer::get_singleton()->canvas_item_set_draw_index(contact_2d_debug, 0xFFFFF); //very high index
Vector<Vector2> points = Physics2DServer::get_singleton()->space_get_contacts(find_world_2d()->get_space());
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 (physics_object_picking && (to_screen_rect == Rect2() || Input::get_singleton()->get_mouse_mode() != Input::MOUSE_MODE_CAPTURED)) {
-
- if (physics_object_picking && (to_screen_rect==Rect2() || 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();
}
@@ -609,60 +571,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);
@@ -671,8 +623,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) {
@@ -680,29 +632,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);
@@ -711,24 +662,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;
@@ -742,36 +690,33 @@ RID Viewport::get_viewport_rid() const {
void Viewport::set_size(const Size2 &p_size) {
- if (size==p_size.floor())
+ if (size == p_size.floor())
return;
- size=p_size.floor();
- VS::get_singleton()->viewport_set_size(viewport,size.width,size.height);
+ size = p_size.floor();
+ VS::get_singleton()->viewport_set_size(viewport, size.width, size.height);
_update_rect();
_update_stretch_transform();
emit_signal("size_changed");
-
}
Rect2 Viewport::get_visible_rect() const {
-
Rect2 r;
- if (size==Size2()) {
+ if (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( Point2() , size );
+ r = Rect2(Point2(), size);
}
if (size_override) {
- r.size=size_override_size;
+ r.size = size_override_size;
}
-
return r;
}
@@ -780,16 +725,14 @@ Size2 Viewport::get_size() const {
return size;
}
-
void Viewport::_update_listener() {
-/*
+ /*
if (is_inside_tree() && audio_listener && (camera || listener) && (!get_parent() || (get_parent()->cast_to<Control>() && get_parent()->cast_to<Control>()->is_visible_in_tree()))) {
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() {
@@ -802,43 +745,39 @@ void Viewport::_update_listener_2d() {
*/
}
-
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 Transform2D& p_transform) {
+void Viewport::set_canvas_transform(const Transform2D &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);
Transform2D xform = (global_canvas_transform * canvas_transform).affine_inverse();
Size2 ss = get_visible_rect().size;
@@ -848,22 +787,18 @@ void Viewport::set_canvas_transform(const Transform2D& p_transform) {
SpatialSound2DServer::get_singleton()->listener_set_param(internal_listener_2d, SpatialSound2DServer::LISTENER_PARAM_PAN_RANGE, panrange);
*/
-
}
-Transform2D Viewport::get_canvas_transform() const{
+Transform2D Viewport::get_canvas_transform() const {
return canvas_transform;
}
-
-
void Viewport::_update_global_transform() {
-
Transform2D 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);
Transform2D xform = (sxform * canvas_transform).affine_inverse();
Size2 ss = get_visible_rect().size;
@@ -875,17 +810,14 @@ void Viewport::_update_global_transform() {
*/
}
+void Viewport::set_global_canvas_transform(const Transform2D &p_transform) {
-void Viewport::set_global_canvas_transform(const Transform2D& p_transform) {
-
- global_canvas_transform=p_transform;
+ global_canvas_transform = p_transform;
_update_global_transform();
-
-
}
-Transform2D Viewport::get_global_canvas_transform() const{
+Transform2D Viewport::get_global_canvas_transform() const {
return global_canvas_transform;
}
@@ -893,12 +825,12 @@ Transform2D Viewport::get_global_canvas_transform() const{
void Viewport::_listener_transform_changed_notify() {
#ifndef _3D_DISABLED
- //if (listener)
+//if (listener)
// SpatialSoundServer::get_singleton()->listener_set_transform(internal_listener, listener->get_listener_transform());
#endif
}
-void Viewport::_listener_set(Listener* p_listener) {
+void Viewport::_listener_set(Listener *p_listener) {
#ifndef _3D_DISABLED
@@ -912,13 +844,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) {
@@ -927,10 +859,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;
@@ -940,10 +872,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();
@@ -956,27 +886,27 @@ void Viewport::_listener_make_next_current(Listener* p_exclude) {
void Viewport::_camera_transform_changed_notify() {
#ifndef _3D_DISABLED
- // If there is an active listener in the scene, it takes priority over the camera
+// If there is an active listener in the scene, it takes priority over the camera
// if (camera && !listener)
// SpatialSoundServer::get_singleton()->listener_set_transform(internal_listener, camera->get_camera_transform());
#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);
@@ -987,43 +917,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 {
@@ -1031,37 +959,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;
@@ -1073,8 +1001,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;
@@ -1093,27 +1020,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;
@@ -1132,18 +1058,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())
@@ -1154,7 +1077,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);
@@ -1167,24 +1090,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;
@@ -1196,36 +1118,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;
}
-
Transform2D 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 {
@@ -1238,19 +1157,17 @@ 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;
@@ -1293,19 +1210,18 @@ bool Viewport::is_set_as_render_target() const{
}
#endif
-void Viewport::set_update_mode(UpdateMode p_mode){
-
- update_mode=p_mode;
- VS::get_singleton()->viewport_set_update_mode(viewport,VS::ViewportUpdateMode(p_mode));
+void Viewport::set_update_mode(UpdateMode p_mode) {
+ update_mode = p_mode;
+ VS::get_singleton()->viewport_set_update_mode(viewport, VS::ViewportUpdateMode(p_mode));
}
-Viewport::UpdateMode Viewport::get_update_mode() const{
+Viewport::UpdateMode Viewport::get_update_mode() const {
return update_mode;
}
//RID get_texture() const;
-void Viewport::queue_screen_capture(){
+void Viewport::queue_screen_capture() {
//VS::get_singleton()->viewport_queue_screen_capture(viewport);
}
@@ -1322,78 +1238,73 @@ Ref<ViewportTexture> Viewport::get_texture() const {
void Viewport::set_vflip(bool p_enable) {
- vflip=p_enable;
- VisualServer::get_singleton()->viewport_set_vflip(viewport,p_enable);
+ vflip = p_enable;
+ VisualServer::get_singleton()->viewport_set_vflip(viewport, p_enable);
}
-bool Viewport::get_vflip() const{
+bool Viewport::get_vflip() const {
return vflip;
}
void Viewport::set_clear_on_new_frame(bool p_enable) {
- clear_on_new_frame=p_enable;
+ clear_on_new_frame = p_enable;
//VisualServer::get_singleton()->viewport_set_clear_on_new_frame(viewport,p_enable);
}
-bool Viewport::get_clear_on_new_frame() const{
+bool Viewport::get_clear_on_new_frame() const {
return clear_on_new_frame;
}
void Viewport::set_shadow_atlas_size(int p_size) {
- if (shadow_atlas_size==p_size)
+ if (shadow_atlas_size == p_size)
return;
- shadow_atlas_size=p_size;
- VS::get_singleton()->viewport_set_shadow_atlas_size(viewport,p_size);
+ shadow_atlas_size = p_size;
+ VS::get_singleton()->viewport_set_shadow_atlas_size(viewport, p_size);
}
-int Viewport::get_shadow_atlas_size() const{
+int Viewport::get_shadow_atlas_size() const {
return shadow_atlas_size;
}
-void Viewport::set_shadow_atlas_quadrant_subdiv(int p_quadrant,ShadowAtlasQuadrantSubdiv p_subdiv){
+void Viewport::set_shadow_atlas_quadrant_subdiv(int p_quadrant, ShadowAtlasQuadrantSubdiv p_subdiv) {
+ ERR_FAIL_INDEX(p_quadrant, 4);
+ ERR_FAIL_INDEX(p_subdiv, SHADOW_ATLAS_QUADRANT_SUBDIV_MAX);
- ERR_FAIL_INDEX(p_quadrant,4);
- ERR_FAIL_INDEX(p_subdiv,SHADOW_ATLAS_QUADRANT_SUBDIV_MAX);
-
- if (shadow_atlas_quadrant_subdiv[p_quadrant]==p_subdiv)
+ if (shadow_atlas_quadrant_subdiv[p_quadrant] == p_subdiv)
return;
- shadow_atlas_quadrant_subdiv[p_quadrant]=p_subdiv;
- static const int subdiv[SHADOW_ATLAS_QUADRANT_SUBDIV_MAX]={0,1,4,16,64,256,1024};
-
- VS::get_singleton()->viewport_set_shadow_atlas_quadrant_subdivision(viewport,p_quadrant,subdiv[p_subdiv]);
+ shadow_atlas_quadrant_subdiv[p_quadrant] = p_subdiv;
+ static const int subdiv[SHADOW_ATLAS_QUADRANT_SUBDIV_MAX] = { 0, 1, 4, 16, 64, 256, 1024 };
+ VS::get_singleton()->viewport_set_shadow_atlas_quadrant_subdivision(viewport, p_quadrant, subdiv[p_subdiv]);
}
-Viewport::ShadowAtlasQuadrantSubdiv Viewport::get_shadow_atlas_quadrant_subdiv(int p_quadrant) const{
+Viewport::ShadowAtlasQuadrantSubdiv Viewport::get_shadow_atlas_quadrant_subdiv(int p_quadrant) const {
- ERR_FAIL_INDEX_V(p_quadrant,4,SHADOW_ATLAS_QUADRANT_SUBDIV_DISABLED);
+ ERR_FAIL_INDEX_V(p_quadrant, 4, SHADOW_ATLAS_QUADRANT_SUBDIV_DISABLED);
return shadow_atlas_quadrant_subdiv[p_quadrant];
}
-
void Viewport::clear() {
//clear=true;
//VisualServer::get_singleton()->viewport_clear(viewport);
}
-
Transform2D Viewport::_get_input_pre_xform() const {
Transform2D pre_xf;
+ if (to_screen_rect != Rect2()) {
- if (to_screen_rect!=Rect2()) {
-
- pre_xf.elements[2]=-to_screen_rect.pos;
- pre_xf.scale(size/to_screen_rect.size);
+ pre_xf.elements[2] = -to_screen_rect.pos;
+ pre_xf.scale(size / to_screen_rect.size);
}
return pre_xf;
@@ -1410,24 +1321,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();
Transform2D 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: {
@@ -1435,20 +1344,19 @@ void Viewport::_make_input_local(InputEvent& ev) {
Vector2 vp_ofs = _get_window_offset();
Transform2D 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));
-
-
- 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;
+ 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;
} break;
case InputEvent::SCREEN_TOUCH: {
@@ -1456,11 +1364,10 @@ void Viewport::_make_input_local(InputEvent& ev) {
Vector2 vp_ofs = _get_window_offset();
Transform2D 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: {
@@ -1468,29 +1375,27 @@ void Viewport::_make_input_local(InputEvent& ev) {
Vector2 vp_ofs = _get_window_offset();
Transform2D 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;
@@ -1501,21 +1406,18 @@ void Viewport::_vp_input(const InputEvent& p_ev) {
}
#endif
-
- if (to_screen_rect==Rect2())
+ if (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;
@@ -1530,7 +1432,7 @@ void Viewport::_vp_unhandled_input(const InputEvent& p_ev) {
return;
*/
- if (to_screen_rect==Rect2())
+ if (to_screen_rect == Rect2())
return; //if render target, can't get input events
//this one handles system input, p_ev are in system coordinates
@@ -1539,7 +1441,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 {
@@ -1547,24 +1448,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() {
@@ -1572,7 +1470,6 @@ void Viewport::_gui_sort_modal_stack() {
gui.modal_stack.sort_custom<Control::CComparator>();
}
-
void Viewport::_gui_sort_roots() {
if (!gui.roots_order_dirty)
@@ -1580,19 +1477,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() {
@@ -1601,47 +1496,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);
@@ -1650,56 +1544,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();
-
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()->_gui_input,ev);
+ control->call_multilevel(SceneStringNames::get_singleton()->_gui_input, ev);
if (gui.key_event_accepted)
break;
if (!control->is_inside_tree())
break;
- control->emit_signal(SceneStringNames::get_singleton()->gui_input,ev);
+ control->emit_signal(SceneStringNames::get_singleton()->gui_input, 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.mouse_filter==Control::MOUSE_FILTER_STOP && (ev.type==InputEvent::MOUSE_BUTTON || ev.type==InputEvent::MOUSE_MOTION))
+ if (!cant_stop_me_now && control->data.mouse_filter == Control::MOUSE_FILTER_STOP && (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_in_tree())
@@ -1708,18 +1599,18 @@ Control* Viewport::_gui_find_control(const Point2& p_global) {
Transform2D 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_in_tree())
@@ -1728,27 +1619,24 @@ Control* Viewport::_gui_find_control(const Point2& p_global) {
Transform2D 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 Transform2D& p_xform,Transform2D& r_inv_xform) {
+Control *Viewport::_gui_find_control_at_pos(CanvasItem *p_node, const Point2 &p_global, const Transform2D &p_xform, Transform2D &r_inv_xform) {
if (p_node->cast_to<Viewport>())
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);
@@ -1763,21 +1651,21 @@ Control* Viewport::_gui_find_control_at_pos(CanvasItem* p_node,const Point2& p_g
Transform2D 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;
}
@@ -1789,33 +1677,31 @@ 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.mouse_filter!=Control::MOUSE_FILTER_IGNORE && 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.mouse_filter != Control::MOUSE_FILTER_IGNORE && 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;
}
-bool Viewport::_gui_drop(Control *p_at_control,Point2 p_at_pos,bool p_just_check) {
-
+bool Viewport::_gui_drop(Control *p_at_control, Point2 p_at_pos, bool p_just_check) {
{ //attempt grab, try parent controls too
- CanvasItem *ci=p_at_control;
- while(ci) {
+ CanvasItem *ci = p_at_control;
+ while (ci) {
Control *control = ci->cast_to<Control>();
if (control) {
-
- if (control->can_drop_data(p_at_pos,gui.drag_data)) {
+ if (control->can_drop_data(p_at_pos, gui.drag_data)) {
if (!p_just_check) {
- control->drop_data(p_at_pos,gui.drag_data);
+ control->drop_data(p_at_pos, gui.drag_data);
}
return true;
}
- if (control->data.mouse_filter==Control::MOUSE_FILTER_STOP)
+ if (control->data.mouse_filter == Control::MOUSE_FILTER_STOP)
break;
}
@@ -1824,19 +1710,16 @@ bool Viewport::_gui_drop(Control *p_at_control,Point2 p_at_pos,bool p_just_check
if (ci->is_set_as_toplevel())
break;
- ci=ci->get_parent_item();
+ ci = ci->get_parent_item();
}
}
return false;
}
-
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;
}
//?
@@ -1846,27 +1729,22 @@ void Viewport::_gui_input_event(InputEvent p_event) {
}
*/
-
- 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()) {
@@ -1874,7 +1752,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==Engine::get_singleton()->get_frames_drawn()) {
+ if (top->data.modal_exclusive || top->data.modal_frame == Engine::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();
@@ -1889,8 +1767,6 @@ void Viewport::_gui_input_event(InputEvent p_event) {
}
}
-
-
//Matrix32 parent_xform;
/*
@@ -1900,21 +1776,18 @@ void Viewport::_gui_input_event(InputEvent p_event) {
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;
@@ -1928,91 +1801,84 @@ 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_class());
- 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 (p_event.mouse_button.button_index==BUTTON_LEFT) { //assign focus
- CanvasItem *ci=gui.mouse_focus;
- while(ci) {
+ if (p_event.mouse_button.button_index == BUTTON_LEFT) { //assign focus
+ CanvasItem *ci = gui.mouse_focus;
+ while (ci) {
Control *control = ci->cast_to<Control>();
if (control) {
- if (control->get_focus_mode()!=Control::FOCUS_NONE) {
- if (control!=gui.key_focus) {
+ if (control->get_focus_mode() != Control::FOCUS_NONE) {
+ if (control != gui.key_focus) {
control->grab_focus();
}
break;
}
- if (control->data.mouse_filter==Control::MOUSE_FILTER_STOP)
+ if (control->data.mouse_filter == Control::MOUSE_FILTER_STOP)
break;
}
if (ci->is_set_as_toplevel())
break;
- ci=ci->get_parent_item();
+ ci = ci->get_parent_item();
}
}
-
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_flags(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID);
+ get_tree()->call_group_flags(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_drop(gui.mouse_focus,pos,false);
+ _gui_drop(gui.mouse_focus, pos, false);
}
- 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);
- _gui_drop(gui.mouse_over,pos,false);
-
+ _gui_drop(gui.mouse_over, pos, false);
}
- 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
}
@@ -2029,12 +1895,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) {
@@ -2042,66 +1908,60 @@ void Viewport::_gui_input_event(InputEvent p_event) {
gui.drag_data=Variant(); //always clear
}*/
-
- get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME,"windows","_cancel_input_ID",p_event.ID);
+ get_tree()->call_group_flags(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) {
+ if (len > 10) {
{ //attempt grab, try parent controls too
- CanvasItem *ci=gui.mouse_focus;
- while(ci) {
+ CanvasItem *ci = gui.mouse_focus;
+ while (ci) {
Control *control = ci->cast_to<Control>();
if (control) {
- gui.drag_data=control->get_drag_data(control->get_global_transform_with_canvas().affine_inverse().xform(mpos)-gui.drag_accum);
- if (gui.drag_data.get_type()!=Variant::NIL) {
+ gui.drag_data = control->get_drag_data(control->get_global_transform_with_canvas().affine_inverse().xform(mpos) - gui.drag_accum);
+ if (gui.drag_data.get_type() != Variant::NIL) {
- gui.mouse_focus=NULL;
+ gui.mouse_focus = NULL;
}
- if (control->data.mouse_filter==Control::MOUSE_FILTER_STOP)
+ if (control->data.mouse_filter == Control::MOUSE_FILTER_STOP)
break;
}
if (ci->is_set_as_toplevel())
break;
- ci=ci->get_parent_item();
+ ci = ci->get_parent_item();
}
}
+ 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 {
@@ -2109,19 +1969,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);
@@ -2130,10 +1987,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);
@@ -2144,29 +2000,26 @@ void Viewport::_gui_input_event(InputEvent p_event) {
break;
}
-
Transform2D 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;
@@ -2179,51 +2032,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 = _gui_drop(over,pos,true);
+ bool can_drop = _gui_drop(over, pos, true);
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
}
@@ -2234,21 +2076,19 @@ void Viewport::_gui_input_event(InputEvent p_event) {
case InputEvent::JOYPAD_MOTION:
case InputEvent::KEY: {
-
if (gui.key_focus && !gui.key_focus->is_visible_in_tree()) {
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(SceneStringNames::get_singleton()->_gui_input,p_event);
+ gui.key_focus->call_multilevel(SceneStringNames::get_singleton()->_gui_input, p_event);
if (gui.key_focus) //maybe lost it
- gui.key_focus->emit_signal(SceneStringNames::get_singleton()->gui_input,p_event);
+ gui.key_focus->emit_signal(SceneStringNames::get_singleton()->gui_input, p_event);
}
-
if (gui.key_event_accepted) {
get_tree()->set_input_as_handled();
@@ -2256,7 +2096,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();
@@ -2269,14 +2108,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")) {
@@ -2308,7 +2146,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();
@@ -2319,41 +2156,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) {
@@ -2377,25 +2212,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);
@@ -2405,25 +2240,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();
}
}
@@ -2431,7 +2265,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;
}
/* ???
@@ -2445,81 +2279,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_flags(SceneTree::GROUP_CALL_REALTIME,"_viewports","_gui_remove_focus");
- gui.key_focus=p_control;
+ get_tree()->call_group_flags(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)
@@ -2539,77 +2363,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(SceneStringNames::get_singleton()->_gui_input,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(SceneStringNames::get_singleton()->_gui_input,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(SceneStringNames::get_singleton()->_gui_input, 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(SceneStringNames::get_singleton()->_gui_input, 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);
@@ -2619,9 +2433,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);
@@ -2634,12 +2448,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 {
@@ -2647,35 +2459,29 @@ bool Viewport::is_using_own_world() const {
return own_world.is_valid();
}
-void Viewport::set_attach_to_screen_rect(const Rect2& p_rect) {
+void Viewport::set_attach_to_screen_rect(const Rect2 &p_rect) {
- VS::get_singleton()->viewport_attach_to_screen(viewport,p_rect);
- to_screen_rect=p_rect;
+ VS::get_singleton()->viewport_attach_to_screen(viewport, p_rect);
+ to_screen_rect = p_rect;
}
-Rect2 Viewport::get_attach_to_screen_rect() const{
+Rect2 Viewport::get_attach_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 {
Transform2D xf = get_final_transform();
return xf.xform(p_viewport_coords);
-
-
}
Vector2 Viewport::get_camera_rect_size() const {
@@ -2683,10 +2489,8 @@ Vector2 Viewport::get_camera_rect_size() const {
return size;
}
-
bool Viewport::get_physics_object_picking() {
-
return physics_object_picking;
}
@@ -2696,7 +2500,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 {
@@ -2705,8 +2509,8 @@ bool Viewport::is_input_disabled() const {
}
void Viewport::set_disable_3d(bool p_disable) {
- disable_3d=p_disable;
- VS::get_singleton()->viewport_set_disable_3d(viewport,p_disable);
+ disable_3d = p_disable;
+ VS::get_singleton()->viewport_set_disable_3d(viewport, p_disable);
}
bool Viewport::is_3d_disabled() const {
@@ -2719,7 +2523,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 {
@@ -2732,8 +2536,8 @@ String Viewport::get_configuration_warning() const {
return String();
}
-void Viewport::gui_reset_canvas_sort_index() {
- gui.canvas_sort_index=0;
+void Viewport::gui_reset_canvas_sort_index() {
+ gui.canvas_sort_index = 0;
}
int Viewport::gui_get_canvas_sort_index() {
@@ -2742,11 +2546,11 @@ int Viewport::gui_get_canvas_sort_index() {
void Viewport::set_msaa(MSAA p_msaa) {
- ERR_FAIL_INDEX(p_msaa,5);
- if (msaa==p_msaa)
+ ERR_FAIL_INDEX(p_msaa, 5);
+ if (msaa == p_msaa)
return;
- msaa=p_msaa;
- VS::get_singleton()->viewport_set_msaa(viewport,VS::ViewportMSAA(p_msaa));
+ msaa = p_msaa;
+ VS::get_singleton()->viewport_set_msaa(viewport, VS::ViewportMSAA(p_msaa));
}
Viewport::MSAA Viewport::get_msaa() const {
@@ -2756,260 +2560,241 @@ Viewport::MSAA Viewport::get_msaa() const {
void Viewport::set_hdr(bool p_hdr) {
- if (hdr==p_hdr)
+ if (hdr == p_hdr)
return;
- hdr=p_hdr;
- VS::get_singleton()->viewport_set_hdr(viewport,p_hdr);
-
+ hdr = p_hdr;
+ VS::get_singleton()->viewport_set_hdr(viewport, p_hdr);
}
-bool Viewport::get_hdr() const{
+bool Viewport::get_hdr() const {
return hdr;
}
-
-
void Viewport::_bind_methods() {
-
- ClassDB::bind_method(D_METHOD("set_size","size"), &Viewport::set_size);
+ ClassDB::bind_method(D_METHOD("set_size", "size"), &Viewport::set_size);
ClassDB::bind_method(D_METHOD("get_size"), &Viewport::get_size);
- ClassDB::bind_method(D_METHOD("set_world_2d","world_2d:World2D"), &Viewport::set_world_2d);
+ ClassDB::bind_method(D_METHOD("set_world_2d", "world_2d:World2D"), &Viewport::set_world_2d);
ClassDB::bind_method(D_METHOD("get_world_2d:World2D"), &Viewport::get_world_2d);
ClassDB::bind_method(D_METHOD("find_world_2d:World2D"), &Viewport::find_world_2d);
- ClassDB::bind_method(D_METHOD("set_world","world:World"), &Viewport::set_world);
+ ClassDB::bind_method(D_METHOD("set_world", "world:World"), &Viewport::set_world);
ClassDB::bind_method(D_METHOD("get_world:World"), &Viewport::get_world);
ClassDB::bind_method(D_METHOD("find_world:World"), &Viewport::find_world);
- ClassDB::bind_method(D_METHOD("set_canvas_transform","xform"), &Viewport::set_canvas_transform);
+ ClassDB::bind_method(D_METHOD("set_canvas_transform", "xform"), &Viewport::set_canvas_transform);
ClassDB::bind_method(D_METHOD("get_canvas_transform"), &Viewport::get_canvas_transform);
- ClassDB::bind_method(D_METHOD("set_global_canvas_transform","xform"), &Viewport::set_global_canvas_transform);
+ ClassDB::bind_method(D_METHOD("set_global_canvas_transform", "xform"), &Viewport::set_global_canvas_transform);
ClassDB::bind_method(D_METHOD("get_global_canvas_transform"), &Viewport::get_global_canvas_transform);
ClassDB::bind_method(D_METHOD("get_final_transform"), &Viewport::get_final_transform);
ClassDB::bind_method(D_METHOD("get_visible_rect"), &Viewport::get_visible_rect);
- ClassDB::bind_method(D_METHOD("set_transparent_background","enable"), &Viewport::set_transparent_background);
+ ClassDB::bind_method(D_METHOD("set_transparent_background", "enable"), &Viewport::set_transparent_background);
ClassDB::bind_method(D_METHOD("has_transparent_background"), &Viewport::has_transparent_background);
ClassDB::bind_method(D_METHOD("_parent_visibility_changed"), &Viewport::_parent_visibility_changed);
ClassDB::bind_method(D_METHOD("_parent_resized"), &Viewport::_parent_resized);
ClassDB::bind_method(D_METHOD("_vp_input"), &Viewport::_vp_input);
- ClassDB::bind_method(D_METHOD("_vp_input_text","text"), &Viewport::_vp_input_text);
+ ClassDB::bind_method(D_METHOD("_vp_input_text", "text"), &Viewport::_vp_input_text);
ClassDB::bind_method(D_METHOD("_vp_unhandled_input"), &Viewport::_vp_unhandled_input);
- ClassDB::bind_method(D_METHOD("set_size_override","enable","size","margin"), &Viewport::set_size_override,DEFVAL(Size2(-1,-1)),DEFVAL(Size2(0,0)));
+ ClassDB::bind_method(D_METHOD("set_size_override", "enable", "size", "margin"), &Viewport::set_size_override, DEFVAL(Size2(-1, -1)), DEFVAL(Size2(0, 0)));
ClassDB::bind_method(D_METHOD("get_size_override"), &Viewport::get_size_override);
ClassDB::bind_method(D_METHOD("is_size_override_enabled"), &Viewport::is_size_override_enabled);
- ClassDB::bind_method(D_METHOD("set_size_override_stretch","enabled"), &Viewport::set_size_override_stretch);
+ ClassDB::bind_method(D_METHOD("set_size_override_stretch", "enabled"), &Viewport::set_size_override_stretch);
ClassDB::bind_method(D_METHOD("is_size_override_stretch_enabled"), &Viewport::is_size_override_stretch_enabled);
ClassDB::bind_method(D_METHOD("queue_screen_capture"), &Viewport::queue_screen_capture);
ClassDB::bind_method(D_METHOD("get_screen_capture"), &Viewport::get_screen_capture);
-
- ClassDB::bind_method(D_METHOD("set_vflip","enable"), &Viewport::set_vflip);
+ ClassDB::bind_method(D_METHOD("set_vflip", "enable"), &Viewport::set_vflip);
ClassDB::bind_method(D_METHOD("get_vflip"), &Viewport::get_vflip);
- ClassDB::bind_method(D_METHOD("set_clear_on_new_frame","enable"), &Viewport::set_clear_on_new_frame);
+ ClassDB::bind_method(D_METHOD("set_clear_on_new_frame", "enable"), &Viewport::set_clear_on_new_frame);
ClassDB::bind_method(D_METHOD("get_clear_on_new_frame"), &Viewport::get_clear_on_new_frame);
ClassDB::bind_method(D_METHOD("clear"), &Viewport::clear);
- ClassDB::bind_method(D_METHOD("set_update_mode","mode"), &Viewport::set_update_mode);
+ ClassDB::bind_method(D_METHOD("set_update_mode", "mode"), &Viewport::set_update_mode);
ClassDB::bind_method(D_METHOD("get_update_mode"), &Viewport::get_update_mode);
- ClassDB::bind_method(D_METHOD("set_msaa","msaa"), &Viewport::set_msaa);
+ ClassDB::bind_method(D_METHOD("set_msaa", "msaa"), &Viewport::set_msaa);
ClassDB::bind_method(D_METHOD("get_msaa"), &Viewport::get_msaa);
- ClassDB::bind_method(D_METHOD("set_hdr","enable"), &Viewport::set_hdr);
+ ClassDB::bind_method(D_METHOD("set_hdr", "enable"), &Viewport::set_hdr);
ClassDB::bind_method(D_METHOD("get_hdr"), &Viewport::get_hdr);
ClassDB::bind_method(D_METHOD("get_texture:ViewportTexture"), &Viewport::get_texture);
- ClassDB::bind_method(D_METHOD("set_physics_object_picking","enable"), &Viewport::set_physics_object_picking);
+ ClassDB::bind_method(D_METHOD("set_physics_object_picking", "enable"), &Viewport::set_physics_object_picking);
ClassDB::bind_method(D_METHOD("get_physics_object_picking"), &Viewport::get_physics_object_picking);
ClassDB::bind_method(D_METHOD("get_viewport_rid"), &Viewport::get_viewport_rid);
- ClassDB::bind_method(D_METHOD("input","local_event"), &Viewport::input);
- ClassDB::bind_method(D_METHOD("unhandled_input","local_event"), &Viewport::unhandled_input);
+ ClassDB::bind_method(D_METHOD("input", "local_event"), &Viewport::input);
+ ClassDB::bind_method(D_METHOD("unhandled_input", "local_event"), &Viewport::unhandled_input);
ClassDB::bind_method(D_METHOD("update_worlds"), &Viewport::update_worlds);
- ClassDB::bind_method(D_METHOD("set_use_own_world","enable"), &Viewport::set_use_own_world);
+ ClassDB::bind_method(D_METHOD("set_use_own_world", "enable"), &Viewport::set_use_own_world);
ClassDB::bind_method(D_METHOD("is_using_own_world"), &Viewport::is_using_own_world);
ClassDB::bind_method(D_METHOD("get_camera:Camera"), &Viewport::get_camera);
- ClassDB::bind_method(D_METHOD("set_as_audio_listener","enable"), &Viewport::set_as_audio_listener);
- ClassDB::bind_method(D_METHOD("is_audio_listener","enable"), &Viewport::is_audio_listener);
+ ClassDB::bind_method(D_METHOD("set_as_audio_listener", "enable"), &Viewport::set_as_audio_listener);
+ ClassDB::bind_method(D_METHOD("is_audio_listener", "enable"), &Viewport::is_audio_listener);
- ClassDB::bind_method(D_METHOD("set_as_audio_listener_2d","enable"), &Viewport::set_as_audio_listener_2d);
- ClassDB::bind_method(D_METHOD("is_audio_listener_2d","enable"), &Viewport::is_audio_listener_2d);
- ClassDB::bind_method(D_METHOD("set_attach_to_screen_rect","rect"), &Viewport::set_attach_to_screen_rect);
+ ClassDB::bind_method(D_METHOD("set_as_audio_listener_2d", "enable"), &Viewport::set_as_audio_listener_2d);
+ ClassDB::bind_method(D_METHOD("is_audio_listener_2d", "enable"), &Viewport::is_audio_listener_2d);
+ ClassDB::bind_method(D_METHOD("set_attach_to_screen_rect", "rect"), &Viewport::set_attach_to_screen_rect);
ClassDB::bind_method(D_METHOD("get_mouse_pos"), &Viewport::get_mouse_pos);
- ClassDB::bind_method(D_METHOD("warp_mouse","to_pos"), &Viewport::warp_mouse);
+ ClassDB::bind_method(D_METHOD("warp_mouse", "to_pos"), &Viewport::warp_mouse);
ClassDB::bind_method(D_METHOD("gui_has_modal_stack"), &Viewport::gui_has_modal_stack);
ClassDB::bind_method(D_METHOD("gui_get_drag_data:Variant"), &Viewport::gui_get_drag_data);
- ClassDB::bind_method(D_METHOD("set_disable_input","disable"), &Viewport::set_disable_input);
+ ClassDB::bind_method(D_METHOD("set_disable_input", "disable"), &Viewport::set_disable_input);
ClassDB::bind_method(D_METHOD("is_input_disabled"), &Viewport::is_input_disabled);
- ClassDB::bind_method(D_METHOD("set_disable_3d","disable"), &Viewport::set_disable_3d);
+ ClassDB::bind_method(D_METHOD("set_disable_3d", "disable"), &Viewport::set_disable_3d);
ClassDB::bind_method(D_METHOD("is_3d_disabled"), &Viewport::is_3d_disabled);
ClassDB::bind_method(D_METHOD("_gui_show_tooltip"), &Viewport::_gui_show_tooltip);
ClassDB::bind_method(D_METHOD("_gui_remove_focus"), &Viewport::_gui_remove_focus);
- ClassDB::bind_method(D_METHOD("set_shadow_atlas_size","size"), &Viewport::set_shadow_atlas_size);
+ ClassDB::bind_method(D_METHOD("set_shadow_atlas_size", "size"), &Viewport::set_shadow_atlas_size);
ClassDB::bind_method(D_METHOD("get_shadow_atlas_size"), &Viewport::get_shadow_atlas_size);
- ClassDB::bind_method(D_METHOD("set_shadow_atlas_quadrant_subdiv","quadrant","subdiv"), &Viewport::set_shadow_atlas_quadrant_subdiv);
- ClassDB::bind_method(D_METHOD("get_shadow_atlas_quadrant_subdiv","quadrant"), &Viewport::get_shadow_atlas_quadrant_subdiv);
+ ClassDB::bind_method(D_METHOD("set_shadow_atlas_quadrant_subdiv", "quadrant", "subdiv"), &Viewport::set_shadow_atlas_quadrant_subdiv);
+ ClassDB::bind_method(D_METHOD("get_shadow_atlas_quadrant_subdiv", "quadrant"), &Viewport::get_shadow_atlas_quadrant_subdiv);
- ADD_PROPERTY( PropertyInfo(Variant::RECT2,"size"), "set_size", "get_size") ;
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"own_world"), "set_use_own_world", "is_using_own_world") ;
- ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"world",PROPERTY_HINT_RESOURCE_TYPE,"World"), "set_world", "get_world") ;
+ ADD_PROPERTY(PropertyInfo(Variant::RECT2, "size"), "set_size", "get_size");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "own_world"), "set_use_own_world", "is_using_own_world");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "world", PROPERTY_HINT_RESOURCE_TYPE, "World"), "set_world", "get_world");
//ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"world_2d",PROPERTY_HINT_RESOURCE_TYPE,"World2D"), "set_world_2d", "get_world_2d") ;
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"transparent_bg"), "set_transparent_background", "has_transparent_background") ;
- ADD_GROUP("Rendering","");
- ADD_PROPERTY( PropertyInfo(Variant::INT,"msaa",PROPERTY_HINT_ENUM,"Disabled,2x,4x,8x,16x"), "set_msaa", "get_msaa") ;
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"hdr"), "set_hdr", "get_hdr") ;
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"disable_3d"), "set_disable_3d", "is_3d_disabled") ;
- ADD_GROUP("Render Target","render_target_");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"render_target_v_flip"), "set_vflip", "get_vflip") ;
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"render_target_clear_on_new_frame"), "set_clear_on_new_frame", "get_clear_on_new_frame") ;
- ADD_PROPERTY( PropertyInfo(Variant::INT,"render_target_update_mode",PROPERTY_HINT_ENUM,"Disabled,Once,When Visible,Always"), "set_update_mode", "get_update_mode") ;
- ADD_GROUP("Audio Listener","audio_listener_");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"audio_listener_enable_2d"), "set_as_audio_listener_2d", "is_audio_listener_2d") ;
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"audio_listener_enable_3d"), "set_as_audio_listener", "is_audio_listener") ;
- ADD_GROUP("Physics","physics_");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"physics_object_picking"), "set_physics_object_picking", "get_physics_object_picking") ;
- ADD_GROUP("GUI","gui_");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"gui_disable_input"), "set_disable_input", "is_input_disabled") ;
- ADD_GROUP("Shadow Atlas","shadow_atlas_");
- ADD_PROPERTY( PropertyInfo(Variant::INT,"shadow_atlas_size"), "set_shadow_atlas_size", "get_shadow_atlas_size") ;
- ADD_PROPERTYI( PropertyInfo(Variant::INT,"shadow_atlas_quad_0",PROPERTY_HINT_ENUM,"Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"), "set_shadow_atlas_quadrant_subdiv", "get_shadow_atlas_quadrant_subdiv",0 );
- ADD_PROPERTYI( PropertyInfo(Variant::INT,"shadow_atlas_quad_1",PROPERTY_HINT_ENUM,"Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"), "set_shadow_atlas_quadrant_subdiv", "get_shadow_atlas_quadrant_subdiv",1 );
- ADD_PROPERTYI( PropertyInfo(Variant::INT,"shadow_atlas_quad_2",PROPERTY_HINT_ENUM,"Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"), "set_shadow_atlas_quadrant_subdiv", "get_shadow_atlas_quadrant_subdiv",2 );
- ADD_PROPERTYI( PropertyInfo(Variant::INT,"shadow_atlas_quad_3",PROPERTY_HINT_ENUM,"Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"), "set_shadow_atlas_quadrant_subdiv", "get_shadow_atlas_quadrant_subdiv",3 );
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "transparent_bg"), "set_transparent_background", "has_transparent_background");
+ ADD_GROUP("Rendering", "");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "msaa", PROPERTY_HINT_ENUM, "Disabled,2x,4x,8x,16x"), "set_msaa", "get_msaa");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hdr"), "set_hdr", "get_hdr");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "disable_3d"), "set_disable_3d", "is_3d_disabled");
+ ADD_GROUP("Render Target", "render_target_");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "render_target_v_flip"), "set_vflip", "get_vflip");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "render_target_clear_on_new_frame"), "set_clear_on_new_frame", "get_clear_on_new_frame");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "render_target_update_mode", PROPERTY_HINT_ENUM, "Disabled,Once,When Visible,Always"), "set_update_mode", "get_update_mode");
+ ADD_GROUP("Audio Listener", "audio_listener_");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "audio_listener_enable_2d"), "set_as_audio_listener_2d", "is_audio_listener_2d");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "audio_listener_enable_3d"), "set_as_audio_listener", "is_audio_listener");
+ ADD_GROUP("Physics", "physics_");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "physics_object_picking"), "set_physics_object_picking", "get_physics_object_picking");
+ ADD_GROUP("GUI", "gui_");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "gui_disable_input"), "set_disable_input", "is_input_disabled");
+ ADD_GROUP("Shadow Atlas", "shadow_atlas_");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "shadow_atlas_size"), "set_shadow_atlas_size", "get_shadow_atlas_size");
+ ADD_PROPERTYI(PropertyInfo(Variant::INT, "shadow_atlas_quad_0", PROPERTY_HINT_ENUM, "Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"), "set_shadow_atlas_quadrant_subdiv", "get_shadow_atlas_quadrant_subdiv", 0);
+ ADD_PROPERTYI(PropertyInfo(Variant::INT, "shadow_atlas_quad_1", PROPERTY_HINT_ENUM, "Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"), "set_shadow_atlas_quadrant_subdiv", "get_shadow_atlas_quadrant_subdiv", 1);
+ ADD_PROPERTYI(PropertyInfo(Variant::INT, "shadow_atlas_quad_2", PROPERTY_HINT_ENUM, "Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"), "set_shadow_atlas_quadrant_subdiv", "get_shadow_atlas_quadrant_subdiv", 2);
+ ADD_PROPERTYI(PropertyInfo(Variant::INT, "shadow_atlas_quad_3", PROPERTY_HINT_ENUM, "Disabled,1 Shadow,4 Shadows,16 Shadows,64 Shadows,256 Shadows,1024 Shadows"), "set_shadow_atlas_quadrant_subdiv", "get_shadow_atlas_quadrant_subdiv", 3);
ADD_SIGNAL(MethodInfo("size_changed"));
- BIND_CONSTANT( UPDATE_DISABLED );
- BIND_CONSTANT( UPDATE_ONCE );
- BIND_CONSTANT( UPDATE_WHEN_VISIBLE );
- BIND_CONSTANT( UPDATE_ALWAYS );
+ BIND_CONSTANT(UPDATE_DISABLED);
+ BIND_CONSTANT(UPDATE_ONCE);
+ BIND_CONSTANT(UPDATE_WHEN_VISIBLE);
+ BIND_CONSTANT(UPDATE_ALWAYS);
- BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_DISABLED );
- BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_1 );
- BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_4 );
- BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_16 );
- BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_64 );
- BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_256 );
- BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_1024 );
- BIND_CONSTANT( SHADOW_ATLAS_QUADRANT_SUBDIV_MAX );
-
- BIND_CONSTANT( MSAA_DISABLED );
- BIND_CONSTANT( MSAA_2X );
- BIND_CONSTANT( MSAA_4X );
- BIND_CONSTANT( MSAA_8X );
- BIND_CONSTANT( MSAA_16X );
+ BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_DISABLED);
+ BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_1);
+ BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_4);
+ BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_16);
+ BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_64);
+ BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_256);
+ BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_1024);
+ BIND_CONSTANT(SHADOW_ATLAS_QUADRANT_SUBDIV_MAX);
+ BIND_CONSTANT(MSAA_DISABLED);
+ BIND_CONSTANT(MSAA_2X);
+ BIND_CONSTANT(MSAA_4X);
+ BIND_CONSTANT(MSAA_8X);
+ BIND_CONSTANT(MSAA_16X);
}
-
-
-
-
Viewport::Viewport() {
-
- world_2d = Ref<World2D>( memnew( World2D ));
+ world_2d = Ref<World2D>(memnew(World2D));
viewport = VisualServer::get_singleton()->viewport_create();
- texture_rid=VisualServer::get_singleton()->viewport_get_texture(viewport);
- texture_flags=0;
+ texture_rid = VisualServer::get_singleton()->viewport_get_texture(viewport);
+ texture_flags = 0;
default_texture.instance();
- default_texture->vp=const_cast<Viewport*>(this);
+ default_texture->vp = const_cast<Viewport *>(this);
viewport_textures.insert(default_texture.ptr());
//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);
- gen_mipmaps=false;
-
- vflip=false;
- 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);
+ gen_mipmaps = false;
+
+ vflip = false;
+ clear_on_new_frame = true;
//clear=true;
- update_mode=UPDATE_WHEN_VISIBLE;
+ update_mode = UPDATE_WHEN_VISIBLE;
- 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);
- shadow_atlas_size=0;
- for(int i=0;i<4;i++) {
- shadow_atlas_quadrant_subdiv[i]=SHADOW_ATLAS_QUADRANT_SUBDIV_MAX;
+ shadow_atlas_size = 0;
+ for (int i = 0; i < 4; i++) {
+ shadow_atlas_quadrant_subdiv[i] = SHADOW_ATLAS_QUADRANT_SUBDIV_MAX;
}
- set_shadow_atlas_quadrant_subdiv(0,SHADOW_ATLAS_QUADRANT_SUBDIV_4);
- set_shadow_atlas_quadrant_subdiv(1,SHADOW_ATLAS_QUADRANT_SUBDIV_4);
- set_shadow_atlas_quadrant_subdiv(2,SHADOW_ATLAS_QUADRANT_SUBDIV_16);
- set_shadow_atlas_quadrant_subdiv(3,SHADOW_ATLAS_QUADRANT_SUBDIV_64);
-
+ set_shadow_atlas_quadrant_subdiv(0, SHADOW_ATLAS_QUADRANT_SUBDIV_4);
+ set_shadow_atlas_quadrant_subdiv(1, SHADOW_ATLAS_QUADRANT_SUBDIV_4);
+ set_shadow_atlas_quadrant_subdiv(2, SHADOW_ATLAS_QUADRANT_SUBDIV_16);
+ set_shadow_atlas_quadrant_subdiv(3, SHADOW_ATLAS_QUADRANT_SUBDIV_64);
- 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_3d=false;
+ disable_input = false;
+ disable_3d = false;
//window tooltip
gui.tooltip_timer = -1;
//gui.tooltip_timer->force_parent_owned();
- gui.tooltip_delay=GLOBAL_DEF("gui/timers/tooltip_delay_sec",0.7);
-
- gui.tooltip=NULL;
- gui.tooltip_label=NULL;
- gui.drag_preview=NULL;
- gui.drag_attempted=false;
- gui.canvas_sort_index=0;
-
-
- msaa=MSAA_DISABLED;
- hdr=false;
+ gui.tooltip_delay = GLOBAL_DEF("gui/timers/tooltip_delay_sec", 0.7);
+ gui.tooltip = NULL;
+ gui.tooltip_label = NULL;
+ gui.drag_preview = NULL;
+ gui.drag_attempted = false;
+ gui.canvas_sort_index = 0;
+ msaa = MSAA_DISABLED;
+ hdr = false;
}
-
Viewport::~Viewport() {
//erase itself from viewport textures
- for(Set<ViewportTexture*>::Element *E=viewport_textures.front();E;E=E->next()) {
- E->get()->vp=NULL;
+ for (Set<ViewportTexture *>::Element *E = viewport_textures.front(); E; E = E->next()) {
+ E->get()->vp = NULL;
}
- VisualServer::get_singleton()->free( viewport );
+ VisualServer::get_singleton()->free(viewport);
//SpatialSoundServer::get_singleton()->free(internal_listener);
//SpatialSound2DServer::get_singleton()->free(internal_listener_2d);
-
}
-
-
diff --git a/scene/main/viewport.h b/scene/main/viewport.h
index 59e34d5c62..3fc781c62c 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,23 +50,22 @@ class Viewport;
class ViewportTexture : public Texture {
- GDCLASS( ViewportTexture, Texture );
+ GDCLASS(ViewportTexture, Texture);
NodePath path;
-friend class Viewport;
- Viewport* vp;
-protected:
+ friend class Viewport;
+ Viewport *vp;
+protected:
static void _bind_methods();
-public:
- void set_viewport_path_in_scene(const NodePath& p_path);
+public:
+ void set_viewport_path_in_scene(const NodePath &p_path);
NodePath get_viewport_path_in_scene() const;
virtual void setup_local_to_scene();
-
virtual int get_width() const;
virtual int get_height() const;
virtual Size2 get_size() const;
@@ -79,14 +78,13 @@ public:
ViewportTexture();
~ViewportTexture();
-
};
class Viewport : public Node {
- GDCLASS( Viewport, Node );
-public:
+ GDCLASS(Viewport, Node);
+public:
enum UpdateMode {
UPDATE_DISABLED,
UPDATE_ONCE, //then goes to disabled
@@ -115,18 +113,15 @@ public:
};
private:
-
-friend class ViewportTexture;
-
-
+ friend class ViewportTexture;
Viewport *parent;
Listener *listener;
- Set<Listener*> listeners;
+ Set<Listener *> listeners;
Camera *camera;
- Set<Camera*> cameras;
+ Set<Camera *> cameras;
RID viewport;
RID current_canvas;
@@ -167,7 +162,7 @@ friend class ViewportTexture;
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();
@@ -191,11 +186,9 @@ friend class ViewportTexture;
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();
-
bool disable_3d;
UpdateMode update_mode;
RID texture_rid;
@@ -208,8 +201,7 @@ friend class ViewportTexture;
bool hdr;
Ref<ViewportTexture> default_texture;
- Set<ViewportTexture*> viewport_textures;
-
+ Set<ViewportTexture *> viewport_textures;
struct GUI {
// info used when this is a window
@@ -230,31 +222,29 @@ friend class ViewportTexture;
Control *drag_preview;
float tooltip_timer;
float tooltip_delay;
- List<Control*> modal_stack;
+ List<Control *> modal_stack;
unsigned int cancelled_input_ID;
Transform2D focus_inv_xform;
bool subwindow_order_dirty;
- List<Control*> subwindows;
+ List<Control *> subwindows;
bool roots_order_dirty;
- List<Control*> roots;
+ List<Control *> roots;
int canvas_sort_index; //for sorting items with canvas as root
-
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 Transform2D& p_xform,Transform2D& 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 Transform2D &p_xform, Transform2D &r_inv_xform);
void _gui_input_event(InputEvent p_event);
-
void update_worlds();
_FORCE_INLINE_ Transform2D _get_input_pre_xform() const;
@@ -262,43 +252,40 @@ friend class ViewportTexture;
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();
@@ -306,30 +293,29 @@ friend class Control;
Vector2 _get_window_offset() const;
- bool _gui_drop(Control *p_at_control,Point2 p_at_pos,bool p_just_check);
+ bool _gui_drop(Control *p_at_control, Point2 p_at_pos, bool p_just_check);
-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;
@@ -337,26 +323,24 @@ public:
void set_as_audio_listener_2d(bool p_enable);
bool is_audio_listener_2d() const;
- void set_size(const Size2& p_size);
-
+ void set_size(const Size2 &p_size);
Size2 get_size() const;
Rect2 get_visible_rect() const;
RID get_viewport_rid() 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 Transform2D& p_transform);
+ void set_canvas_transform(const Transform2D &p_transform);
Transform2D get_canvas_transform() const;
- void set_global_canvas_transform(const Transform2D& p_transform);
+ void set_global_canvas_transform(const Transform2D &p_transform);
Transform2D get_global_canvas_transform() const;
Transform2D get_final_transform() const;
@@ -364,8 +348,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;
@@ -379,7 +362,6 @@ public:
bool get_clear_on_new_frame() const;
void clear();
-
void set_update_mode(UpdateMode p_mode);
UpdateMode get_update_mode() const;
Ref<ViewportTexture> get_texture() const;
@@ -387,7 +369,7 @@ public:
void set_shadow_atlas_size(int p_size);
int get_shadow_atlas_size() const;
- void set_shadow_atlas_quadrant_subdiv(int p_quadrant,ShadowAtlasQuadrantSubdiv p_subdiv);
+ void set_shadow_atlas_quadrant_subdiv(int p_quadrant, ShadowAtlasQuadrantSubdiv p_subdiv);
ShadowAtlasQuadrantSubdiv get_shadow_atlas_quadrant_subdiv(int p_quadrant) const;
void set_msaa(MSAA p_msaa);
@@ -396,7 +378,7 @@ public:
void set_hdr(bool p_hdr);
bool get_hdr() 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();
@@ -405,8 +387,8 @@ 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;
@@ -414,11 +396,11 @@ public:
void set_disable_3d(bool p_disable);
bool is_3d_disabled() const;
- void set_attach_to_screen_rect(const Rect2& p_rect);
+ void set_attach_to_screen_rect(const Rect2 &p_rect);
Rect2 get_attach_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();
@@ -433,15 +415,12 @@ public:
virtual String get_configuration_warning() const;
-
-
Viewport();
~Viewport();
-
};
-VARIANT_ENUM_CAST( Viewport::UpdateMode );
-VARIANT_ENUM_CAST( Viewport::ShadowAtlasQuadrantSubdiv );
-VARIANT_ENUM_CAST( Viewport::MSAA );
+VARIANT_ENUM_CAST(Viewport::UpdateMode);
+VARIANT_ENUM_CAST(Viewport::ShadowAtlasQuadrantSubdiv);
+VARIANT_ENUM_CAST(Viewport::MSAA);
#endif