summaryrefslogtreecommitdiffstats
path: root/scene/2d
diff options
context:
space:
mode:
authorRémi Verschelde <rverschelde@gmail.com>2017-03-05 16:44:50 +0100
committerRémi Verschelde <rverschelde@gmail.com>2017-03-05 16:44:50 +0100
commit5dbf1809c6e3e905b94b8764e99491e608122261 (patch)
tree5e5a5360db15d86d59ec8c6e4f7eb511388c5a9a /scene/2d
parent45438e9918d421b244bfd7776a30e67dc7f2d3e3 (diff)
downloadredot-engine-5dbf1809c6e3e905b94b8764e99491e608122261.tar.gz
A Whole New World (clang-format edition)
I can show you the code Pretty, with proper whitespace Tell me, coder, now when did You last write readable code? I can open your eyes Make you see your bad indent Force you to respect the style The core devs agreed upon A whole new world A new fantastic code format A de facto standard With some sugar Enforced with clang-format A whole new world A dazzling style we all dreamed of And when we read it through It's crystal clear That now we're in a whole new world of code
Diffstat (limited to 'scene/2d')
-rw-r--r--scene/2d/animated_sprite.cpp408
-rw-r--r--scene/2d/animated_sprite.h86
-rw-r--r--scene/2d/area_2d.cpp489
-rw-r--r--scene/2d/area_2d.h45
-rw-r--r--scene/2d/back_buffer_copy.cpp50
-rw-r--r--scene/2d/back_buffer_copy.h9
-rw-r--r--scene/2d/camera_2d.cpp452
-rw-r--r--scene/2d/camera_2d.h19
-rw-r--r--scene/2d/canvas_item.cpp651
-rw-r--r--scene/2d/canvas_item.h112
-rw-r--r--scene/2d/canvas_modulate.cpp56
-rw-r--r--scene/2d/canvas_modulate.h7
-rw-r--r--scene/2d/collision_object_2d.cpp228
-rw-r--r--scene/2d/collision_object_2d.h30
-rw-r--r--scene/2d/collision_polygon_2d.cpp203
-rw-r--r--scene/2d/collision_polygon_2d.h19
-rw-r--r--scene/2d/collision_shape_2d.cpp107
-rw-r--r--scene/2d/collision_shape_2d.h7
-rw-r--r--scene/2d/joints_2d.cpp265
-rw-r--r--scene/2d/joints_2d.h31
-rw-r--r--scene/2d/light_2d.cpp363
-rw-r--r--scene/2d/light_2d.h51
-rw-r--r--scene/2d/light_occluder_2d.cpp132
-rw-r--r--scene/2d/light_occluder_2d.h19
-rw-r--r--scene/2d/line_2d.cpp105
-rw-r--r--scene/2d/line_2d.h10
-rw-r--r--scene/2d/line_builder.cpp214
-rw-r--r--scene/2d/line_builder.h6
-rw-r--r--scene/2d/navigation2d.cpp556
-rw-r--r--scene/2d/navigation2d.h79
-rw-r--r--scene/2d/navigation_polygon.cpp291
-rw-r--r--scene/2d/navigation_polygon.h34
-rw-r--r--scene/2d/node_2d.cpp289
-rw-r--r--scene/2d/node_2d.h38
-rw-r--r--scene/2d/parallax_background.cpp128
-rw-r--r--scene/2d/parallax_background.h22
-rw-r--r--scene/2d/parallax_layer.cpp89
-rw-r--r--scene/2d/parallax_layer.h12
-rw-r--r--scene/2d/particles_2d.cpp814
-rw-r--r--scene/2d/particles_2d.h54
-rw-r--r--scene/2d/path_2d.cpp230
-rw-r--r--scene/2d/path_2d.h29
-rw-r--r--scene/2d/path_texture.cpp40
-rw-r--r--scene/2d/path_texture.h10
-rw-r--r--scene/2d/physics_body_2d.cpp1030
-rw-r--r--scene/2d/physics_body_2d.h86
-rw-r--r--scene/2d/polygon_2d.cpp300
-rw-r--r--scene/2d/polygon_2d.h23
-rw-r--r--scene/2d/position_2d.cpp13
-rw-r--r--scene/2d/position_2d.h7
-rw-r--r--scene/2d/ray_cast_2d.cpp178
-rw-r--r--scene/2d/ray_cast_2d.h18
-rw-r--r--scene/2d/remote_transform_2d.cpp32
-rw-r--r--scene/2d/remote_transform_2d.h7
-rw-r--r--scene/2d/screen_button.cpp240
-rw-r--r--scene/2d/screen_button.h25
-rw-r--r--scene/2d/sprite.cpp190
-rw-r--r--scene/2d/sprite.h17
-rw-r--r--scene/2d/tile_map.cpp923
-rw-r--r--scene/2d/tile_map.h114
-rw-r--r--scene/2d/visibility_notifier_2d.cpp218
-rw-r--r--scene/2d/visibility_notifier_2d.h34
-rw-r--r--scene/2d/y_sort.cpp19
-rw-r--r--scene/2d/y_sort.h4
64 files changed, 4695 insertions, 5672 deletions
diff --git a/scene/2d/animated_sprite.cpp b/scene/2d/animated_sprite.cpp
index faecbf3e6d..f10bd2f303 100644
--- a/scene/2d/animated_sprite.cpp
+++ b/scene/2d/animated_sprite.cpp
@@ -27,24 +27,19 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "animated_sprite.h"
-#include "scene/scene_string_names.h"
#include "os/os.h"
#include "scene/scene_string_names.h"
-
-
-
+#include "scene/scene_string_names.h"
////////////////////////////
+void SpriteFrames::add_frame(const StringName &p_anim, const Ref<Texture> &p_frame, int p_at_pos) {
-
-void SpriteFrames::add_frame(const StringName &p_anim, const Ref<Texture>& p_frame, int p_at_pos) {
-
- Map<StringName,Anim>::Element *E=animations.find(p_anim);
+ Map<StringName, Anim>::Element *E = animations.find(p_anim);
ERR_FAIL_COND(!E);
- if (p_at_pos>=0 && p_at_pos<E->get().frames.size())
- E->get().frames.insert(p_at_pos,p_frame);
+ if (p_at_pos >= 0 && p_at_pos < E->get().frames.size())
+ E->get().frames.insert(p_at_pos, p_frame);
else
E->get().frames.push_back(p_frame);
@@ -52,15 +47,15 @@ void SpriteFrames::add_frame(const StringName &p_anim, const Ref<Texture>& p_fra
}
int SpriteFrames::get_frame_count(const StringName &p_anim) const {
- const Map<StringName,Anim>::Element *E=animations.find(p_anim);
- ERR_FAIL_COND_V(!E,0);
+ const Map<StringName, Anim>::Element *E = animations.find(p_anim);
+ ERR_FAIL_COND_V(!E, 0);
return E->get().frames.size();
}
void SpriteFrames::remove_frame(const StringName &p_anim, int p_idx) {
- Map<StringName,Anim>::Element *E=animations.find(p_anim);
+ Map<StringName, Anim>::Element *E = animations.find(p_anim);
ERR_FAIL_COND(!E);
E->get().frames.remove(p_idx);
@@ -68,7 +63,7 @@ void SpriteFrames::remove_frame(const StringName &p_anim, int p_idx) {
}
void SpriteFrames::clear(const StringName &p_anim) {
- Map<StringName,Anim>::Element *E=animations.find(p_anim);
+ Map<StringName, Anim>::Element *E = animations.find(p_anim);
ERR_FAIL_COND(!E);
E->get().frames.clear();
@@ -81,33 +76,30 @@ void SpriteFrames::clear_all() {
add_animation("default");
}
-
-
-void SpriteFrames::add_animation(const StringName& p_anim) {
+void SpriteFrames::add_animation(const StringName &p_anim) {
ERR_FAIL_COND(animations.has(p_anim));
- animations[p_anim]=Anim();
+ animations[p_anim] = Anim();
}
-bool SpriteFrames::has_animation(const StringName& p_anim) const{
+bool SpriteFrames::has_animation(const StringName &p_anim) const {
return animations.has(p_anim);
}
-void SpriteFrames::remove_animation(const StringName& p_anim){
+void SpriteFrames::remove_animation(const StringName &p_anim) {
animations.erase(p_anim);
}
-void SpriteFrames::rename_animation(const StringName& p_prev,const StringName& p_next) {
+void SpriteFrames::rename_animation(const StringName &p_prev, const StringName &p_next) {
ERR_FAIL_COND(!animations.has(p_prev));
ERR_FAIL_COND(animations.has(p_next));
Anim anim = animations[p_prev];
animations.erase(p_prev);
- animations[p_next]=anim;
-
+ animations[p_next] = anim;
}
Vector<String> SpriteFrames::_get_animation_list() const {
@@ -115,7 +107,7 @@ Vector<String> SpriteFrames::_get_animation_list() const {
Vector<String> ret;
List<StringName> al;
get_animation_list(&al);
- for(List<StringName>::Element *E=al.front();E;E=E->next()) {
+ for (List<StringName>::Element *E = al.front(); E; E = E->next()) {
ret.push_back(E->get());
}
@@ -123,49 +115,47 @@ Vector<String> SpriteFrames::_get_animation_list() const {
return ret;
}
-void SpriteFrames::get_animation_list(List<StringName> *r_animations) const{
+void SpriteFrames::get_animation_list(List<StringName> *r_animations) const {
- for (const Map<StringName,Anim>::Element *E=animations.front();E;E=E->next()) {
+ for (const Map<StringName, Anim>::Element *E = animations.front(); E; E = E->next()) {
r_animations->push_back(E->key());
}
}
-void SpriteFrames::set_animation_speed(const StringName& p_anim,float p_fps){
+void SpriteFrames::set_animation_speed(const StringName &p_anim, float p_fps) {
- ERR_FAIL_COND(p_fps<0);
- Map<StringName,Anim>::Element *E=animations.find(p_anim);
+ ERR_FAIL_COND(p_fps < 0);
+ Map<StringName, Anim>::Element *E = animations.find(p_anim);
ERR_FAIL_COND(!E);
- E->get().speed=p_fps;
+ E->get().speed = p_fps;
}
-float SpriteFrames::get_animation_speed(const StringName& p_anim) const{
+float SpriteFrames::get_animation_speed(const StringName &p_anim) const {
- const Map<StringName,Anim>::Element *E=animations.find(p_anim);
- ERR_FAIL_COND_V(!E,0);
+ const Map<StringName, Anim>::Element *E = animations.find(p_anim);
+ ERR_FAIL_COND_V(!E, 0);
return E->get().speed;
}
-void SpriteFrames::set_animation_loop(const StringName& p_anim,bool p_loop){
- Map<StringName,Anim>::Element *E=animations.find(p_anim);
+void SpriteFrames::set_animation_loop(const StringName &p_anim, bool p_loop) {
+ Map<StringName, Anim>::Element *E = animations.find(p_anim);
ERR_FAIL_COND(!E);
- E->get().loop=p_loop;
+ E->get().loop = p_loop;
}
-bool SpriteFrames::get_animation_loop(const StringName& p_anim) const{
- const Map<StringName,Anim>::Element *E=animations.find(p_anim);
- ERR_FAIL_COND_V(!E,false);
+bool SpriteFrames::get_animation_loop(const StringName &p_anim) const {
+ const Map<StringName, Anim>::Element *E = animations.find(p_anim);
+ ERR_FAIL_COND_V(!E, false);
return E->get().loop;
-
}
-void SpriteFrames::_set_frames(const Array& p_frames) {
+void SpriteFrames::_set_frames(const Array &p_frames) {
clear_all();
- Map<StringName,Anim>::Element *E=animations.find(SceneStringNames::get_singleton()->_default);
+ Map<StringName, Anim>::Element *E = animations.find(SceneStringNames::get_singleton()->_default);
ERR_FAIL_COND(!E);
E->get().frames.resize(p_frames.size());
- for(int i=0;i<E->get().frames.size();i++)
- E->get().frames[i]=p_frames[i];
-
+ for (int i = 0; i < E->get().frames.size(); i++)
+ E->get().frames[i] = p_frames[i];
}
Array SpriteFrames::_get_frames() const {
@@ -175,27 +165,27 @@ Array SpriteFrames::_get_frames() const {
Array SpriteFrames::_get_animations() const {
Array anims;
- for (Map<StringName,Anim>::Element *E=animations.front();E;E=E->next()) {
+ for (Map<StringName, Anim>::Element *E = animations.front(); E; E = E->next()) {
Dictionary d;
- d["name"]=E->key();
- d["speed"]=E->get().speed;
- d["loop"]=E->get().loop;
+ d["name"] = E->key();
+ d["speed"] = E->get().speed;
+ d["loop"] = E->get().loop;
Array frames;
- for(int i=0;i<E->get().frames.size();i++) {
+ for (int i = 0; i < E->get().frames.size(); i++) {
frames.push_back(E->get().frames[i]);
}
- d["frames"]=frames;
+ d["frames"] = frames;
anims.push_back(d);
}
return anims;
}
-void SpriteFrames::_set_animations(const Array& p_animations) {
+void SpriteFrames::_set_animations(const Array &p_animations) {
animations.clear();
- for(int i=0;i<p_animations.size();i++) {
+ for (int i = 0; i < p_animations.size(); i++) {
- Dictionary d=p_animations[i];
+ Dictionary d = p_animations[i];
ERR_CONTINUE(!d.has("name"));
ERR_CONTINUE(!d.has("speed"));
@@ -203,71 +193,57 @@ void SpriteFrames::_set_animations(const Array& p_animations) {
ERR_CONTINUE(!d.has("frames"));
Anim anim;
- anim.speed=d["speed"];
- anim.loop=d["loop"];
- Array frames=d["frames"];
- for(int i=0;i<frames.size();i++) {
+ anim.speed = d["speed"];
+ anim.loop = d["loop"];
+ Array frames = d["frames"];
+ for (int i = 0; i < frames.size(); i++) {
RES res = frames[i];
anim.frames.push_back(res);
}
- animations[d["name"]]=anim;
-
-
+ animations[d["name"]] = anim;
}
}
-
void SpriteFrames::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("add_animation", "anim"), &SpriteFrames::add_animation);
+ ClassDB::bind_method(D_METHOD("has_animation", "anim"), &SpriteFrames::has_animation);
+ ClassDB::bind_method(D_METHOD("remove_animation", "anim"), &SpriteFrames::remove_animation);
+ ClassDB::bind_method(D_METHOD("rename_animation", "anim", "newname"), &SpriteFrames::rename_animation);
- ClassDB::bind_method(D_METHOD("add_animation","anim"),&SpriteFrames::add_animation);
- ClassDB::bind_method(D_METHOD("has_animation","anim"),&SpriteFrames::has_animation);
- ClassDB::bind_method(D_METHOD("remove_animation","anim"),&SpriteFrames::remove_animation);
- ClassDB::bind_method(D_METHOD("rename_animation","anim","newname"),&SpriteFrames::rename_animation);
-
- ClassDB::bind_method(D_METHOD("set_animation_speed","anim","speed"),&SpriteFrames::set_animation_speed);
- ClassDB::bind_method(D_METHOD("get_animation_speed","anim"),&SpriteFrames::get_animation_speed);
-
- ClassDB::bind_method(D_METHOD("set_animation_loop","anim","loop"),&SpriteFrames::set_animation_loop);
- ClassDB::bind_method(D_METHOD("get_animation_loop","anim"),&SpriteFrames::get_animation_loop);
+ ClassDB::bind_method(D_METHOD("set_animation_speed", "anim", "speed"), &SpriteFrames::set_animation_speed);
+ ClassDB::bind_method(D_METHOD("get_animation_speed", "anim"), &SpriteFrames::get_animation_speed);
- ClassDB::bind_method(D_METHOD("add_frame","anim","frame","atpos"),&SpriteFrames::add_frame,DEFVAL(-1));
- ClassDB::bind_method(D_METHOD("get_frame_count","anim"),&SpriteFrames::get_frame_count);
- ClassDB::bind_method(D_METHOD("get_frame","anim","idx"),&SpriteFrames::get_frame);
- ClassDB::bind_method(D_METHOD("set_frame","anim","idx","txt"),&SpriteFrames::set_frame);
- ClassDB::bind_method(D_METHOD("remove_frame","anim","idx"),&SpriteFrames::remove_frame);
- ClassDB::bind_method(D_METHOD("clear","anim"),&SpriteFrames::clear);
- ClassDB::bind_method(D_METHOD("clear_all"),&SpriteFrames::clear_all);
+ ClassDB::bind_method(D_METHOD("set_animation_loop", "anim", "loop"), &SpriteFrames::set_animation_loop);
+ ClassDB::bind_method(D_METHOD("get_animation_loop", "anim"), &SpriteFrames::get_animation_loop);
- ClassDB::bind_method(D_METHOD("_set_frames"),&SpriteFrames::_set_frames);
- ClassDB::bind_method(D_METHOD("_get_frames"),&SpriteFrames::_get_frames);
+ ClassDB::bind_method(D_METHOD("add_frame", "anim", "frame", "atpos"), &SpriteFrames::add_frame, DEFVAL(-1));
+ ClassDB::bind_method(D_METHOD("get_frame_count", "anim"), &SpriteFrames::get_frame_count);
+ ClassDB::bind_method(D_METHOD("get_frame", "anim", "idx"), &SpriteFrames::get_frame);
+ ClassDB::bind_method(D_METHOD("set_frame", "anim", "idx", "txt"), &SpriteFrames::set_frame);
+ ClassDB::bind_method(D_METHOD("remove_frame", "anim", "idx"), &SpriteFrames::remove_frame);
+ ClassDB::bind_method(D_METHOD("clear", "anim"), &SpriteFrames::clear);
+ ClassDB::bind_method(D_METHOD("clear_all"), &SpriteFrames::clear_all);
- ADD_PROPERTYNZ( PropertyInfo(Variant::ARRAY,"frames",PROPERTY_HINT_NONE,"",0),"_set_frames","_get_frames"); //compatibility
+ ClassDB::bind_method(D_METHOD("_set_frames"), &SpriteFrames::_set_frames);
+ ClassDB::bind_method(D_METHOD("_get_frames"), &SpriteFrames::_get_frames);
- ClassDB::bind_method(D_METHOD("_set_animations"),&SpriteFrames::_set_animations);
- ClassDB::bind_method(D_METHOD("_get_animations"),&SpriteFrames::_get_animations);
+ ADD_PROPERTYNZ(PropertyInfo(Variant::ARRAY, "frames", PROPERTY_HINT_NONE, "", 0), "_set_frames", "_get_frames"); //compatibility
- ADD_PROPERTYNZ( PropertyInfo(Variant::ARRAY,"animations",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"_set_animations","_get_animations"); //compatibility
+ ClassDB::bind_method(D_METHOD("_set_animations"), &SpriteFrames::_set_animations);
+ ClassDB::bind_method(D_METHOD("_get_animations"), &SpriteFrames::_get_animations);
+ ADD_PROPERTYNZ(PropertyInfo(Variant::ARRAY, "animations", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_animations", "_get_animations"); //compatibility
}
-
-
-
SpriteFrames::SpriteFrames() {
add_animation(SceneStringNames::get_singleton()->_default);
-
}
-
-
-
-
-
-void AnimatedSprite::edit_set_pivot(const Point2& p_pivot) {
+void AnimatedSprite::edit_set_pivot(const Point2 &p_pivot) {
set_offset(p_pivot);
}
@@ -281,88 +257,85 @@ bool AnimatedSprite::edit_has_pivot() const {
return true;
}
-
-void AnimatedSprite::_validate_property(PropertyInfo& property) const {
+void AnimatedSprite::_validate_property(PropertyInfo &property) const {
if (!frames.is_valid())
return;
- if (property.name=="animation") {
+ if (property.name == "animation") {
- property.hint=PROPERTY_HINT_ENUM;
+ property.hint = PROPERTY_HINT_ENUM;
List<StringName> names;
frames->get_animation_list(&names);
names.sort_custom<StringName::AlphCompare>();
- bool current_found=false;
+ bool current_found = false;
- for (List<StringName>::Element *E=names.front();E;E=E->next()) {
+ for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
if (E->prev()) {
- property.hint_string+=",";
+ property.hint_string += ",";
}
- property.hint_string+=String(E->get());
- if (animation==E->get()) {
- current_found=true;
+ property.hint_string += String(E->get());
+ if (animation == E->get()) {
+ current_found = true;
}
}
if (!current_found) {
- if (property.hint_string==String()) {
- property.hint_string=String(animation);
+ if (property.hint_string == String()) {
+ property.hint_string = String(animation);
} else {
- property.hint_string=String(animation)+","+property.hint_string;
+ property.hint_string = String(animation) + "," + property.hint_string;
}
}
}
+ if (property.name == "frame") {
- if (property.name=="frame") {
-
- property.hint=PROPERTY_HINT_SPRITE_FRAME;
+ property.hint = PROPERTY_HINT_SPRITE_FRAME;
if (frames->has_animation(animation)) {
- property.hint_string="0,"+itos(frames->get_frame_count(animation)-1)+",1";
+ property.hint_string = "0," + itos(frames->get_frame_count(animation) - 1) + ",1";
} else {
- property.hint_string="0,0,0";
+ property.hint_string = "0,0,0";
}
}
-
}
void AnimatedSprite::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_INTERNAL_PROCESS: {
if (frames.is_null())
return;
if (!frames->has_animation(animation))
return;
- if (frame<0)
+ if (frame < 0)
return;
float speed = frames->get_animation_speed(animation);
- if (speed==0)
+ if (speed == 0)
return; //do nothing
float remaining = get_process_delta_time();
- while(remaining) {
+ while (remaining) {
- if (timeout<=0) {
+ if (timeout <= 0) {
- timeout=1.0/speed;
+ timeout = 1.0 / speed;
int fc = frames->get_frame_count(animation);
- if (frame>=fc-1) {
+ if (frame >= fc - 1) {
if (frames->get_animation_loop(animation)) {
- frame=0;
+ frame = 0;
} else {
- frame=fc-1;
+ frame = fc - 1;
}
} else {
frame++;
- if (frame==fc-1) {
+ if (frame == fc - 1) {
emit_signal(SceneStringNames::get_singleton()->animation_finished);
}
}
@@ -371,9 +344,9 @@ void AnimatedSprite::_notification(int p_what) {
_change_notify("frame");
}
- float to_process = MIN(timeout,remaining);
- remaining-=to_process;
- timeout-=to_process;
+ float to_process = MIN(timeout, remaining);
+ remaining -= to_process;
+ timeout -= to_process;
}
} break;
@@ -384,19 +357,17 @@ void AnimatedSprite::_notification(int p_what) {
return;
}
- if (frame<0) {
+ if (frame < 0) {
print_line("no draw frame <0");
return;
}
if (!frames->has_animation(animation)) {
- print_line("no draw no anim: "+String(animation));
+ print_line("no draw no anim: " + String(animation));
return;
}
-
-
- Ref<Texture> texture = frames->get_frame(animation,frame);
+ Ref<Texture> texture = frames->get_frame(animation, frame);
if (texture.is_null()) {
print_line("no draw texture is null");
return;
@@ -413,50 +384,46 @@ void AnimatedSprite::_notification(int p_what) {
Size2i s;
s = texture->get_size();
- Point2 ofs=offset;
+ Point2 ofs = offset;
if (centered)
- ofs-=s/2;
+ ofs -= s / 2;
if (Engine::get_singleton()->get_use_pixel_snap()) {
- ofs=ofs.floor();
+ ofs = ofs.floor();
}
- Rect2 dst_rect(ofs,s);
+ Rect2 dst_rect(ofs, s);
if (hflip)
- dst_rect.size.x=-dst_rect.size.x;
+ dst_rect.size.x = -dst_rect.size.x;
if (vflip)
- dst_rect.size.y=-dst_rect.size.y;
+ dst_rect.size.y = -dst_rect.size.y;
//texture->draw_rect(ci,dst_rect,false,modulate);
- texture->draw_rect_region(ci,dst_rect,Rect2(Vector2(),texture->get_size()));
+ texture->draw_rect_region(ci, dst_rect, Rect2(Vector2(), texture->get_size()));
//VisualServer::get_singleton()->canvas_item_add_texture_rect_region(ci,dst_rect,texture->get_rid(),src_rect,modulate);
} break;
}
-
}
void AnimatedSprite::set_sprite_frames(const Ref<SpriteFrames> &p_frames) {
if (frames.is_valid())
- frames->disconnect("changed",this,"_res_changed");
- frames=p_frames;
+ frames->disconnect("changed", this, "_res_changed");
+ frames = p_frames;
if (frames.is_valid())
- frames->connect("changed",this,"_res_changed");
+ frames->connect("changed", this, "_res_changed");
if (!frames.is_valid()) {
- frame=0;
+ frame = 0;
} else {
set_frame(frame);
}
-
-
_change_notify();
_reset_timeout();
update();
update_configuration_warning();
-
}
Ref<SpriteFrames> AnimatedSprite::get_sprite_frames() const {
@@ -472,36 +439,30 @@ void AnimatedSprite::set_frame(int p_frame) {
if (frames->has_animation(animation)) {
int limit = frames->get_frame_count(animation);
- if (p_frame>=limit)
- p_frame=limit-1;
-
+ if (p_frame >= limit)
+ p_frame = limit - 1;
}
- if (p_frame<0)
- p_frame=0;
+ if (p_frame < 0)
+ p_frame = 0;
-
- if (frame==p_frame)
+ if (frame == p_frame)
return;
- frame=p_frame;
+ frame = p_frame;
_reset_timeout();
update();
_change_notify("frame");
emit_signal(SceneStringNames::get_singleton()->frame_changed);
-
-
-
}
int AnimatedSprite::get_frame() const {
return frame;
}
-
void AnimatedSprite::set_centered(bool p_center) {
- centered=p_center;
+ centered = p_center;
update();
item_rect_changed();
}
@@ -511,9 +472,9 @@ bool AnimatedSprite::is_centered() const {
return centered;
}
-void AnimatedSprite::set_offset(const Point2& p_offset) {
+void AnimatedSprite::set_offset(const Point2 &p_offset) {
- offset=p_offset;
+ offset = p_offset;
update();
item_rect_changed();
_change_notify("offset");
@@ -525,7 +486,7 @@ Point2 AnimatedSprite::get_offset() const {
void AnimatedSprite::set_flip_h(bool p_flip) {
- hflip=p_flip;
+ hflip = p_flip;
update();
}
bool AnimatedSprite::is_flipped_h() const {
@@ -535,7 +496,7 @@ bool AnimatedSprite::is_flipped_h() const {
void AnimatedSprite::set_flip_v(bool p_flip) {
- vflip=p_flip;
+ vflip = p_flip;
update();
}
bool AnimatedSprite::is_flipped_v() const {
@@ -543,29 +504,27 @@ bool AnimatedSprite::is_flipped_v() const {
return vflip;
}
-
-
Rect2 AnimatedSprite::get_item_rect() const {
- if (!frames.is_valid() || !frames->has_animation(animation) || frame<0 || frame>=frames->get_frame_count(animation)) {
+ if (!frames.is_valid() || !frames->has_animation(animation) || frame < 0 || frame >= frames->get_frame_count(animation)) {
return Node2D::get_item_rect();
}
Ref<Texture> t;
if (animation)
- t = frames->get_frame(animation,frame);
+ t = frames->get_frame(animation, frame);
if (t.is_null())
return Node2D::get_item_rect();
Size2i s = t->get_size();
- Point2 ofs=offset;
+ Point2 ofs = offset;
if (centered)
- ofs-=s/2;
+ ofs -= s / 2;
- if (s==Size2(0,0))
- s=Size2(1,1);
+ if (s == Size2(0, 0))
+ s = Size2(1, 1);
- return Rect2(ofs,s);
+ return Rect2(ofs, s);
}
void AnimatedSprite::_res_changed() {
@@ -578,9 +537,9 @@ void AnimatedSprite::_res_changed() {
void AnimatedSprite::_set_playing(bool p_playing) {
- if (playing==p_playing)
+ if (playing == p_playing)
return;
- playing=p_playing;
+ playing = p_playing;
_reset_timeout();
set_process_internal(playing);
}
@@ -590,14 +549,14 @@ bool AnimatedSprite::_is_playing() const {
return playing;
}
-void AnimatedSprite::play(const StringName& p_animation) {
+void AnimatedSprite::play(const StringName &p_animation) {
if (p_animation)
set_animation(p_animation);
_set_playing(true);
}
-void AnimatedSprite::stop(){
+void AnimatedSprite::stop() {
_set_playing(false);
}
@@ -614,29 +573,28 @@ void AnimatedSprite::_reset_timeout() {
if (frames.is_valid() && frames->has_animation(animation)) {
float speed = frames->get_animation_speed(animation);
- if (speed>0) {
- timeout=1.0/speed;
+ if (speed > 0) {
+ timeout = 1.0 / speed;
} else {
- timeout=0;
+ timeout = 0;
}
} else {
- timeout=0;
+ timeout = 0;
}
-
}
-void AnimatedSprite::set_animation(const StringName& p_animation){
+void AnimatedSprite::set_animation(const StringName &p_animation) {
- if (animation==p_animation)
+ if (animation == p_animation)
return;
- animation=p_animation;
+ animation = p_animation;
_reset_timeout();
set_frame(0);
_change_notify();
update();
}
-StringName AnimatedSprite::get_animation() const{
+StringName AnimatedSprite::get_animation() const {
return animation;
}
@@ -652,65 +610,57 @@ String AnimatedSprite::get_configuration_warning() const {
void AnimatedSprite::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_sprite_frames", "sprite_frames:SpriteFrames"), &AnimatedSprite::set_sprite_frames);
+ ClassDB::bind_method(D_METHOD("get_sprite_frames:SpriteFrames"), &AnimatedSprite::get_sprite_frames);
- ClassDB::bind_method(D_METHOD("set_sprite_frames","sprite_frames:SpriteFrames"),&AnimatedSprite::set_sprite_frames);
- ClassDB::bind_method(D_METHOD("get_sprite_frames:SpriteFrames"),&AnimatedSprite::get_sprite_frames);
-
- ClassDB::bind_method(D_METHOD("set_animation","animation"),&AnimatedSprite::set_animation);
- ClassDB::bind_method(D_METHOD("get_animation"),&AnimatedSprite::get_animation);
-
- ClassDB::bind_method(D_METHOD("_set_playing","playing"),&AnimatedSprite::_set_playing);
- ClassDB::bind_method(D_METHOD("_is_playing"),&AnimatedSprite::_is_playing);
+ ClassDB::bind_method(D_METHOD("set_animation", "animation"), &AnimatedSprite::set_animation);
+ ClassDB::bind_method(D_METHOD("get_animation"), &AnimatedSprite::get_animation);
- ClassDB::bind_method(D_METHOD("play","anim"),&AnimatedSprite::play,DEFVAL(StringName()));
- ClassDB::bind_method(D_METHOD("stop"),&AnimatedSprite::stop);
- ClassDB::bind_method(D_METHOD("is_playing"),&AnimatedSprite::is_playing);
+ ClassDB::bind_method(D_METHOD("_set_playing", "playing"), &AnimatedSprite::_set_playing);
+ ClassDB::bind_method(D_METHOD("_is_playing"), &AnimatedSprite::_is_playing);
- ClassDB::bind_method(D_METHOD("set_centered","centered"),&AnimatedSprite::set_centered);
- ClassDB::bind_method(D_METHOD("is_centered"),&AnimatedSprite::is_centered);
+ ClassDB::bind_method(D_METHOD("play", "anim"), &AnimatedSprite::play, DEFVAL(StringName()));
+ ClassDB::bind_method(D_METHOD("stop"), &AnimatedSprite::stop);
+ ClassDB::bind_method(D_METHOD("is_playing"), &AnimatedSprite::is_playing);
- ClassDB::bind_method(D_METHOD("set_offset","offset"),&AnimatedSprite::set_offset);
- ClassDB::bind_method(D_METHOD("get_offset"),&AnimatedSprite::get_offset);
+ ClassDB::bind_method(D_METHOD("set_centered", "centered"), &AnimatedSprite::set_centered);
+ ClassDB::bind_method(D_METHOD("is_centered"), &AnimatedSprite::is_centered);
- ClassDB::bind_method(D_METHOD("set_flip_h","flip_h"),&AnimatedSprite::set_flip_h);
- ClassDB::bind_method(D_METHOD("is_flipped_h"),&AnimatedSprite::is_flipped_h);
+ ClassDB::bind_method(D_METHOD("set_offset", "offset"), &AnimatedSprite::set_offset);
+ ClassDB::bind_method(D_METHOD("get_offset"), &AnimatedSprite::get_offset);
- ClassDB::bind_method(D_METHOD("set_flip_v","flip_v"),&AnimatedSprite::set_flip_v);
- ClassDB::bind_method(D_METHOD("is_flipped_v"),&AnimatedSprite::is_flipped_v);
+ ClassDB::bind_method(D_METHOD("set_flip_h", "flip_h"), &AnimatedSprite::set_flip_h);
+ ClassDB::bind_method(D_METHOD("is_flipped_h"), &AnimatedSprite::is_flipped_h);
- ClassDB::bind_method(D_METHOD("set_frame","frame"),&AnimatedSprite::set_frame);
- ClassDB::bind_method(D_METHOD("get_frame"),&AnimatedSprite::get_frame);
+ ClassDB::bind_method(D_METHOD("set_flip_v", "flip_v"), &AnimatedSprite::set_flip_v);
+ ClassDB::bind_method(D_METHOD("is_flipped_v"), &AnimatedSprite::is_flipped_v);
+ ClassDB::bind_method(D_METHOD("set_frame", "frame"), &AnimatedSprite::set_frame);
+ ClassDB::bind_method(D_METHOD("get_frame"), &AnimatedSprite::get_frame);
- ClassDB::bind_method(D_METHOD("_res_changed"),&AnimatedSprite::_res_changed);
+ ClassDB::bind_method(D_METHOD("_res_changed"), &AnimatedSprite::_res_changed);
ADD_SIGNAL(MethodInfo("frame_changed"));
ADD_SIGNAL(MethodInfo("animation_finished"));
- ADD_PROPERTYNZ( PropertyInfo( Variant::OBJECT, "frames",PROPERTY_HINT_RESOURCE_TYPE,"SpriteFrames"), "set_sprite_frames","get_sprite_frames");
- ADD_PROPERTY( PropertyInfo( Variant::STRING, "animation"), "set_animation","get_animation");
- ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "frame",PROPERTY_HINT_SPRITE_FRAME), "set_frame","get_frame");
- ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "playing"), "_set_playing","_is_playing");
- ADD_PROPERTYNO( PropertyInfo( Variant::BOOL, "centered"), "set_centered","is_centered");
- ADD_PROPERTYNZ( PropertyInfo( Variant::VECTOR2, "offset"), "set_offset","get_offset");
- ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "flip_h"), "set_flip_h","is_flipped_h");
- ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "flip_v"), "set_flip_v","is_flipped_v");
-
-
+ ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "frames", PROPERTY_HINT_RESOURCE_TYPE, "SpriteFrames"), "set_sprite_frames", "get_sprite_frames");
+ ADD_PROPERTY(PropertyInfo(Variant::STRING, "animation"), "set_animation", "get_animation");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "frame", PROPERTY_HINT_SPRITE_FRAME), "set_frame", "get_frame");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "playing"), "_set_playing", "_is_playing");
+ ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "centered"), "set_centered", "is_centered");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "offset"), "set_offset", "get_offset");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "flip_h"), "set_flip_h", "is_flipped_h");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "flip_v"), "set_flip_v", "is_flipped_v");
}
AnimatedSprite::AnimatedSprite() {
- centered=true;
- hflip=false;
- vflip=false;
-
- frame=0;
- playing=false;
- animation="default";
- timeout=0;
-
+ centered = true;
+ hflip = false;
+ vflip = false;
+ frame = 0;
+ playing = false;
+ animation = "default";
+ timeout = 0;
}
-
-
diff --git a/scene/2d/animated_sprite.h b/scene/2d/animated_sprite.h
index fbeea7f69b..bc0e85b0ca 100644
--- a/scene/2d/animated_sprite.h
+++ b/scene/2d/animated_sprite.h
@@ -32,84 +32,80 @@
#include "scene/2d/node_2d.h"
#include "scene/resources/texture.h"
-
class SpriteFrames : public Resource {
- GDCLASS(SpriteFrames,Resource);
+ GDCLASS(SpriteFrames, Resource);
struct Anim {
float speed;
bool loop;
- Vector< Ref<Texture> > frames;
+ Vector<Ref<Texture> > frames;
- Anim() { loop=true; speed=5; }
+ Anim() {
+ loop = true;
+ speed = 5;
+ }
};
- Map<StringName,Anim> animations;
+ Map<StringName, Anim> animations;
Array _get_frames() const;
- void _set_frames(const Array& p_frames);
+ void _set_frames(const Array &p_frames);
Array _get_animations() const;
- void _set_animations(const Array& p_animations);
+ void _set_animations(const Array &p_animations);
Vector<String> _get_animation_list() const;
protected:
-
static void _bind_methods();
public:
-
- void add_animation(const StringName& p_anim);
- bool has_animation(const StringName& p_anim) const;
- void remove_animation(const StringName& p_anim);
- void rename_animation(const StringName& p_prev,const StringName& p_next);
+ void add_animation(const StringName &p_anim);
+ bool has_animation(const StringName &p_anim) const;
+ void remove_animation(const StringName &p_anim);
+ void rename_animation(const StringName &p_prev, const StringName &p_next);
void get_animation_list(List<StringName> *r_animations) const;
- void set_animation_speed(const StringName& p_anim,float p_fps);
- float get_animation_speed(const StringName& p_anim) const;
+ void set_animation_speed(const StringName &p_anim, float p_fps);
+ float get_animation_speed(const StringName &p_anim) const;
- void set_animation_loop(const StringName& p_anim,bool p_loop);
- bool get_animation_loop(const StringName& p_anim) const;
+ void set_animation_loop(const StringName &p_anim, bool p_loop);
+ bool get_animation_loop(const StringName &p_anim) const;
- void add_frame(const StringName& p_anim,const Ref<Texture>& p_frame,int p_at_pos=-1);
- int get_frame_count(const StringName& p_anim) const;
- _FORCE_INLINE_ Ref<Texture> get_frame(const StringName& p_anim,int p_idx) const {
+ void add_frame(const StringName &p_anim, const Ref<Texture> &p_frame, int p_at_pos = -1);
+ int get_frame_count(const StringName &p_anim) const;
+ _FORCE_INLINE_ Ref<Texture> get_frame(const StringName &p_anim, int p_idx) const {
- const Map<StringName,Anim>::Element *E=animations.find(p_anim);
- ERR_FAIL_COND_V(!E,Ref<Texture>());
- ERR_FAIL_COND_V(p_idx<0,Ref<Texture>());
- if (p_idx>=E->get().frames.size())
+ const Map<StringName, Anim>::Element *E = animations.find(p_anim);
+ ERR_FAIL_COND_V(!E, Ref<Texture>());
+ ERR_FAIL_COND_V(p_idx < 0, Ref<Texture>());
+ if (p_idx >= E->get().frames.size())
return Ref<Texture>();
return E->get().frames[p_idx];
}
- void set_frame(const StringName& p_anim,int p_idx,const Ref<Texture>& p_frame){
- Map<StringName,Anim>::Element *E=animations.find(p_anim);
+ void set_frame(const StringName &p_anim, int p_idx, const Ref<Texture> &p_frame) {
+ Map<StringName, Anim>::Element *E = animations.find(p_anim);
ERR_FAIL_COND(!E);
- ERR_FAIL_COND(p_idx<0);
- if (p_idx>=E->get().frames.size())
+ ERR_FAIL_COND(p_idx < 0);
+ if (p_idx >= E->get().frames.size())
return;
- E->get().frames[p_idx]=p_frame;
+ E->get().frames[p_idx] = p_frame;
}
- void remove_frame(const StringName& p_anim,int p_idx);
- void clear(const StringName& p_anim);
+ void remove_frame(const StringName &p_anim, int p_idx);
+ void clear(const StringName &p_anim);
void clear_all();
-
SpriteFrames();
-
};
-
-
class AnimatedSprite : public Node2D {
- GDCLASS(AnimatedSprite,Node2D);
+ GDCLASS(AnimatedSprite, Node2D);
Ref<SpriteFrames> frames;
bool playing;
@@ -124,35 +120,30 @@ class AnimatedSprite : public Node2D {
bool hflip;
bool vflip;
-
void _res_changed();
void _reset_timeout();
void _set_playing(bool p_playing);
bool _is_playing() const;
-
protected:
-
static void _bind_methods();
void _notification(int p_what);
- virtual void _validate_property(PropertyInfo& property) const;
+ virtual void _validate_property(PropertyInfo &property) const;
public:
-
-
- virtual void edit_set_pivot(const Point2& p_pivot);
+ virtual void edit_set_pivot(const Point2 &p_pivot);
virtual Point2 edit_get_pivot() const;
virtual bool edit_has_pivot() const;
void set_sprite_frames(const Ref<SpriteFrames> &p_frames);
Ref<SpriteFrames> get_sprite_frames() const;
- void play(const StringName& p_animation=StringName());
+ void play(const StringName &p_animation = StringName());
void stop();
bool is_playing() const;
- void set_animation(const StringName& p_animation);
+ void set_animation(const StringName &p_animation);
StringName get_animation() const;
void set_frame(int p_frame);
@@ -161,7 +152,7 @@ public:
void set_centered(bool p_center);
bool is_centered() const;
- void set_offset(const Point2& p_offset);
+ void set_offset(const Point2 &p_offset);
Point2 get_offset() const;
void set_flip_h(bool p_flip);
@@ -170,7 +161,7 @@ public:
void set_flip_v(bool p_flip);
bool is_flipped_v() const;
- void set_modulate(const Color& p_color);
+ void set_modulate(const Color &p_color);
Color get_modulate() const;
virtual Rect2 get_item_rect() const;
@@ -179,5 +170,4 @@ public:
AnimatedSprite();
};
-
#endif // ANIMATED_SPRITE_H
diff --git a/scene/2d/area_2d.cpp b/scene/2d/area_2d.cpp
index 55c7716b6b..61e8ee16a2 100644
--- a/scene/2d/area_2d.cpp
+++ b/scene/2d/area_2d.cpp
@@ -31,108 +31,101 @@
#include "servers/physics_2d_server.h"
void Area2D::set_space_override_mode(SpaceOverride p_mode) {
- space_override=p_mode;
- Physics2DServer::get_singleton()->area_set_space_override_mode(get_rid(),Physics2DServer::AreaSpaceOverrideMode(p_mode));
-
-
+ space_override = p_mode;
+ Physics2DServer::get_singleton()->area_set_space_override_mode(get_rid(), Physics2DServer::AreaSpaceOverrideMode(p_mode));
}
-Area2D::SpaceOverride Area2D::get_space_override_mode() const{
+Area2D::SpaceOverride Area2D::get_space_override_mode() const {
return space_override;
}
-void Area2D::set_gravity_is_point(bool p_enabled){
-
- gravity_is_point=p_enabled;
- Physics2DServer::get_singleton()->area_set_param(get_rid(),Physics2DServer::AREA_PARAM_GRAVITY_IS_POINT,p_enabled);
+void Area2D::set_gravity_is_point(bool p_enabled) {
+ gravity_is_point = p_enabled;
+ Physics2DServer::get_singleton()->area_set_param(get_rid(), Physics2DServer::AREA_PARAM_GRAVITY_IS_POINT, p_enabled);
}
-bool Area2D::is_gravity_a_point() const{
+bool Area2D::is_gravity_a_point() const {
return gravity_is_point;
}
-void Area2D::set_gravity_distance_scale(real_t p_scale){
-
- gravity_distance_scale=p_scale;
- Physics2DServer::get_singleton()->area_set_param(get_rid(),Physics2DServer::AREA_PARAM_GRAVITY_DISTANCE_SCALE,p_scale);
+void Area2D::set_gravity_distance_scale(real_t p_scale) {
+ gravity_distance_scale = p_scale;
+ Physics2DServer::get_singleton()->area_set_param(get_rid(), Physics2DServer::AREA_PARAM_GRAVITY_DISTANCE_SCALE, p_scale);
}
-real_t Area2D::get_gravity_distance_scale() const{
+real_t Area2D::get_gravity_distance_scale() const {
return gravity_distance_scale;
}
-void Area2D::set_gravity_vector(const Vector2& p_vec){
-
- gravity_vec=p_vec;
- Physics2DServer::get_singleton()->area_set_param(get_rid(),Physics2DServer::AREA_PARAM_GRAVITY_VECTOR,p_vec);
+void Area2D::set_gravity_vector(const Vector2 &p_vec) {
+ gravity_vec = p_vec;
+ Physics2DServer::get_singleton()->area_set_param(get_rid(), Physics2DServer::AREA_PARAM_GRAVITY_VECTOR, p_vec);
}
-Vector2 Area2D::get_gravity_vector() const{
+Vector2 Area2D::get_gravity_vector() const {
return gravity_vec;
}
-void Area2D::set_gravity(real_t p_gravity){
+void Area2D::set_gravity(real_t p_gravity) {
- gravity=p_gravity;
- Physics2DServer::get_singleton()->area_set_param(get_rid(),Physics2DServer::AREA_PARAM_GRAVITY,p_gravity);
+ gravity = p_gravity;
+ Physics2DServer::get_singleton()->area_set_param(get_rid(), Physics2DServer::AREA_PARAM_GRAVITY, p_gravity);
}
-real_t Area2D::get_gravity() const{
+real_t Area2D::get_gravity() const {
return gravity;
}
-void Area2D::set_linear_damp(real_t p_linear_damp){
+void Area2D::set_linear_damp(real_t p_linear_damp) {
- linear_damp=p_linear_damp;
- Physics2DServer::get_singleton()->area_set_param(get_rid(),Physics2DServer::AREA_PARAM_LINEAR_DAMP,p_linear_damp);
+ linear_damp = p_linear_damp;
+ Physics2DServer::get_singleton()->area_set_param(get_rid(), Physics2DServer::AREA_PARAM_LINEAR_DAMP, p_linear_damp);
}
-real_t Area2D::get_linear_damp() const{
+real_t Area2D::get_linear_damp() const {
return linear_damp;
}
-void Area2D::set_angular_damp(real_t p_angular_damp){
+void Area2D::set_angular_damp(real_t p_angular_damp) {
- angular_damp=p_angular_damp;
- Physics2DServer::get_singleton()->area_set_param(get_rid(),Physics2DServer::AREA_PARAM_ANGULAR_DAMP,p_angular_damp);
+ angular_damp = p_angular_damp;
+ Physics2DServer::get_singleton()->area_set_param(get_rid(), Physics2DServer::AREA_PARAM_ANGULAR_DAMP, p_angular_damp);
}
-real_t Area2D::get_angular_damp() const{
+real_t Area2D::get_angular_damp() const {
return angular_damp;
}
-void Area2D::set_priority(real_t p_priority){
+void Area2D::set_priority(real_t p_priority) {
- priority=p_priority;
- Physics2DServer::get_singleton()->area_set_param(get_rid(),Physics2DServer::AREA_PARAM_PRIORITY,p_priority);
+ priority = p_priority;
+ Physics2DServer::get_singleton()->area_set_param(get_rid(), Physics2DServer::AREA_PARAM_PRIORITY, p_priority);
}
-real_t Area2D::get_priority() const{
+real_t Area2D::get_priority() const {
return priority;
}
-
void Area2D::_body_enter_tree(ObjectID p_id) {
Object *obj = ObjectDB::get_instance(p_id);
Node *node = obj ? obj->cast_to<Node>() : NULL;
ERR_FAIL_COND(!node);
- Map<ObjectID,BodyState>::Element *E=body_map.find(p_id);
+ Map<ObjectID, BodyState>::Element *E = body_map.find(p_id);
ERR_FAIL_COND(!E);
ERR_FAIL_COND(E->get().in_tree);
- E->get().in_tree=true;
- emit_signal(SceneStringNames::get_singleton()->body_entered,node);
- for(int i=0;i<E->get().shapes.size();i++) {
+ E->get().in_tree = true;
+ emit_signal(SceneStringNames::get_singleton()->body_entered, node);
+ for (int i = 0; i < E->get().shapes.size(); i++) {
- emit_signal(SceneStringNames::get_singleton()->body_shape_entered,p_id,node,E->get().shapes[i].body_shape,E->get().shapes[i].area_shape);
+ emit_signal(SceneStringNames::get_singleton()->body_shape_entered, p_id, node, E->get().shapes[i].body_shape, E->get().shapes[i].area_shape);
}
-
}
void Area2D::_body_exit_tree(ObjectID p_id) {
@@ -140,54 +133,51 @@ void Area2D::_body_exit_tree(ObjectID p_id) {
Object *obj = ObjectDB::get_instance(p_id);
Node *node = obj ? obj->cast_to<Node>() : NULL;
ERR_FAIL_COND(!node);
- Map<ObjectID,BodyState>::Element *E=body_map.find(p_id);
+ Map<ObjectID, BodyState>::Element *E = body_map.find(p_id);
ERR_FAIL_COND(!E);
ERR_FAIL_COND(!E->get().in_tree);
- E->get().in_tree=false;
- emit_signal(SceneStringNames::get_singleton()->body_exited,node);
- for(int i=0;i<E->get().shapes.size();i++) {
+ E->get().in_tree = false;
+ emit_signal(SceneStringNames::get_singleton()->body_exited, node);
+ for (int i = 0; i < E->get().shapes.size(); i++) {
- emit_signal(SceneStringNames::get_singleton()->body_shape_exited,p_id,node,E->get().shapes[i].body_shape,E->get().shapes[i].area_shape);
+ emit_signal(SceneStringNames::get_singleton()->body_shape_exited, p_id, node, E->get().shapes[i].body_shape, E->get().shapes[i].area_shape);
}
-
}
-void Area2D::_body_inout(int p_status,const RID& p_body, int p_instance, int p_body_shape,int p_area_shape) {
+void Area2D::_body_inout(int p_status, const RID &p_body, int p_instance, int p_body_shape, int p_area_shape) {
- bool body_in = p_status==Physics2DServer::AREA_BODY_ADDED;
- ObjectID objid=p_instance;
+ bool body_in = p_status == Physics2DServer::AREA_BODY_ADDED;
+ ObjectID objid = p_instance;
Object *obj = ObjectDB::get_instance(objid);
Node *node = obj ? obj->cast_to<Node>() : NULL;
- Map<ObjectID,BodyState>::Element *E=body_map.find(objid);
+ Map<ObjectID, BodyState>::Element *E = body_map.find(objid);
ERR_FAIL_COND(!body_in && !E);
- locked=true;
+ locked = true;
if (body_in) {
if (!E) {
- E = body_map.insert(objid,BodyState());
- E->get().rc=0;
- E->get().in_tree=node && node->is_inside_tree();
+ E = body_map.insert(objid, BodyState());
+ E->get().rc = 0;
+ E->get().in_tree = node && node->is_inside_tree();
if (node) {
- node->connect(SceneStringNames::get_singleton()->tree_entered,this,SceneStringNames::get_singleton()->_body_enter_tree,make_binds(objid));
- node->connect(SceneStringNames::get_singleton()->tree_exited,this,SceneStringNames::get_singleton()->_body_exit_tree,make_binds(objid));
+ node->connect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_body_enter_tree, make_binds(objid));
+ node->connect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_body_exit_tree, make_binds(objid));
if (E->get().in_tree) {
- emit_signal(SceneStringNames::get_singleton()->body_entered,node);
+ emit_signal(SceneStringNames::get_singleton()->body_entered, node);
}
}
-
}
E->get().rc++;
if (node)
- E->get().shapes.insert(ShapePair(p_body_shape,p_area_shape));
-
+ E->get().shapes.insert(ShapePair(p_body_shape, p_area_shape));
if (!node || E->get().in_tree) {
- emit_signal(SceneStringNames::get_singleton()->body_shape_entered,objid,node,p_body_shape,p_area_shape);
+ emit_signal(SceneStringNames::get_singleton()->body_shape_entered, objid, node, p_body_shape, p_area_shape);
}
} else {
@@ -195,56 +185,48 @@ void Area2D::_body_inout(int p_status,const RID& p_body, int p_instance, int p_b
E->get().rc--;
if (node)
- E->get().shapes.erase(ShapePair(p_body_shape,p_area_shape));
+ E->get().shapes.erase(ShapePair(p_body_shape, p_area_shape));
- bool eraseit=false;
+ bool eraseit = false;
- if (E->get().rc==0) {
+ if (E->get().rc == 0) {
if (node) {
- node->disconnect(SceneStringNames::get_singleton()->tree_entered,this,SceneStringNames::get_singleton()->_body_enter_tree);
- node->disconnect(SceneStringNames::get_singleton()->tree_exited,this,SceneStringNames::get_singleton()->_body_exit_tree);
+ node->disconnect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_body_enter_tree);
+ node->disconnect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_body_exit_tree);
if (E->get().in_tree)
- emit_signal(SceneStringNames::get_singleton()->body_exited,obj);
-
+ emit_signal(SceneStringNames::get_singleton()->body_exited, obj);
}
- eraseit=true;
-
+ eraseit = true;
}
if (!node || E->get().in_tree) {
- emit_signal(SceneStringNames::get_singleton()->body_shape_exited,objid,obj,p_body_shape,p_area_shape);
+ emit_signal(SceneStringNames::get_singleton()->body_shape_exited, objid, obj, p_body_shape, p_area_shape);
}
if (eraseit)
body_map.erase(E);
-
}
- locked=false;
-
-
+ locked = false;
}
-
-
void Area2D::_area_enter_tree(ObjectID p_id) {
Object *obj = ObjectDB::get_instance(p_id);
Node *node = obj ? obj->cast_to<Node>() : NULL;
ERR_FAIL_COND(!node);
- Map<ObjectID,AreaState>::Element *E=area_map.find(p_id);
+ Map<ObjectID, AreaState>::Element *E = area_map.find(p_id);
ERR_FAIL_COND(!E);
ERR_FAIL_COND(E->get().in_tree);
- E->get().in_tree=true;
- emit_signal(SceneStringNames::get_singleton()->area_entered,node);
- for(int i=0;i<E->get().shapes.size();i++) {
+ E->get().in_tree = true;
+ emit_signal(SceneStringNames::get_singleton()->area_entered, node);
+ for (int i = 0; i < E->get().shapes.size(); i++) {
- emit_signal(SceneStringNames::get_singleton()->area_shape_entered,p_id,node,E->get().shapes[i].area_shape,E->get().shapes[i].self_shape);
+ emit_signal(SceneStringNames::get_singleton()->area_shape_entered, p_id, node, E->get().shapes[i].area_shape, E->get().shapes[i].self_shape);
}
-
}
void Area2D::_area_exit_tree(ObjectID p_id) {
@@ -252,54 +234,51 @@ void Area2D::_area_exit_tree(ObjectID p_id) {
Object *obj = ObjectDB::get_instance(p_id);
Node *node = obj ? obj->cast_to<Node>() : NULL;
ERR_FAIL_COND(!node);
- Map<ObjectID,AreaState>::Element *E=area_map.find(p_id);
+ Map<ObjectID, AreaState>::Element *E = area_map.find(p_id);
ERR_FAIL_COND(!E);
ERR_FAIL_COND(!E->get().in_tree);
- E->get().in_tree=false;
- emit_signal(SceneStringNames::get_singleton()->area_exited,node);
- for(int i=0;i<E->get().shapes.size();i++) {
+ E->get().in_tree = false;
+ emit_signal(SceneStringNames::get_singleton()->area_exited, node);
+ for (int i = 0; i < E->get().shapes.size(); i++) {
- emit_signal(SceneStringNames::get_singleton()->area_shape_exited,p_id,node,E->get().shapes[i].area_shape,E->get().shapes[i].self_shape);
+ emit_signal(SceneStringNames::get_singleton()->area_shape_exited, p_id, node, E->get().shapes[i].area_shape, E->get().shapes[i].self_shape);
}
-
}
-void Area2D::_area_inout(int p_status,const RID& p_area, int p_instance, int p_area_shape,int p_self_shape) {
+void Area2D::_area_inout(int p_status, const RID &p_area, int p_instance, int p_area_shape, int p_self_shape) {
- bool area_in = p_status==Physics2DServer::AREA_BODY_ADDED;
- ObjectID objid=p_instance;
+ bool area_in = p_status == Physics2DServer::AREA_BODY_ADDED;
+ ObjectID objid = p_instance;
Object *obj = ObjectDB::get_instance(objid);
Node *node = obj ? obj->cast_to<Node>() : NULL;
- Map<ObjectID,AreaState>::Element *E=area_map.find(objid);
+ Map<ObjectID, AreaState>::Element *E = area_map.find(objid);
ERR_FAIL_COND(!area_in && !E);
- locked=true;
+ locked = true;
if (area_in) {
if (!E) {
- E = area_map.insert(objid,AreaState());
- E->get().rc=0;
- E->get().in_tree=node && node->is_inside_tree();
+ E = area_map.insert(objid, AreaState());
+ E->get().rc = 0;
+ E->get().in_tree = node && node->is_inside_tree();
if (node) {
- node->connect(SceneStringNames::get_singleton()->tree_entered,this,SceneStringNames::get_singleton()->_area_enter_tree,make_binds(objid));
- node->connect(SceneStringNames::get_singleton()->tree_exited,this,SceneStringNames::get_singleton()->_area_exit_tree,make_binds(objid));
+ node->connect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_area_enter_tree, make_binds(objid));
+ node->connect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_area_exit_tree, make_binds(objid));
if (E->get().in_tree) {
- emit_signal(SceneStringNames::get_singleton()->area_entered,node);
+ emit_signal(SceneStringNames::get_singleton()->area_entered, node);
}
}
-
}
E->get().rc++;
if (node)
- E->get().shapes.insert(AreaShapePair(p_area_shape,p_self_shape));
-
+ E->get().shapes.insert(AreaShapePair(p_area_shape, p_self_shape));
if (!node || E->get().in_tree) {
- emit_signal(SceneStringNames::get_singleton()->area_shape_entered,objid,node,p_area_shape,p_self_shape);
+ emit_signal(SceneStringNames::get_singleton()->area_shape_entered, objid, node, p_area_shape, p_self_shape);
}
} else {
@@ -307,39 +286,32 @@ void Area2D::_area_inout(int p_status,const RID& p_area, int p_instance, int p_a
E->get().rc--;
if (node)
- E->get().shapes.erase(AreaShapePair(p_area_shape,p_self_shape));
+ E->get().shapes.erase(AreaShapePair(p_area_shape, p_self_shape));
- bool eraseit=false;
+ bool eraseit = false;
- if (E->get().rc==0) {
+ if (E->get().rc == 0) {
if (node) {
- node->disconnect(SceneStringNames::get_singleton()->tree_entered,this,SceneStringNames::get_singleton()->_area_enter_tree);
- node->disconnect(SceneStringNames::get_singleton()->tree_exited,this,SceneStringNames::get_singleton()->_area_exit_tree);
+ node->disconnect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_area_enter_tree);
+ node->disconnect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_area_exit_tree);
if (E->get().in_tree)
- emit_signal(SceneStringNames::get_singleton()->area_exited,obj);
-
+ emit_signal(SceneStringNames::get_singleton()->area_exited, obj);
}
- eraseit=true;
-
+ eraseit = true;
}
if (!node || E->get().in_tree) {
- emit_signal(SceneStringNames::get_singleton()->area_shape_exited,objid,obj,p_area_shape,p_self_shape);
+ emit_signal(SceneStringNames::get_singleton()->area_shape_exited, objid, obj, p_area_shape, p_self_shape);
}
if (eraseit)
area_map.erase(E);
-
}
- locked=false;
-
-
+ locked = false;
}
-
-
void Area2D::_clear_monitoring() {
if (locked) {
@@ -348,39 +320,38 @@ void Area2D::_clear_monitoring() {
ERR_FAIL_COND(locked);
{
- Map<ObjectID,BodyState> bmcopy = body_map;
+ Map<ObjectID, BodyState> bmcopy = body_map;
body_map.clear();
//disconnect all monitored stuff
- for (Map<ObjectID,BodyState>::Element *E=bmcopy.front();E;E=E->next()) {
+ for (Map<ObjectID, BodyState>::Element *E = bmcopy.front(); E; E = E->next()) {
Object *obj = ObjectDB::get_instance(E->key());
Node *node = obj ? obj->cast_to<Node>() : NULL;
ERR_CONTINUE(!node);
- node->disconnect(SceneStringNames::get_singleton()->tree_entered,this,SceneStringNames::get_singleton()->_body_enter_tree);
- node->disconnect(SceneStringNames::get_singleton()->tree_exited,this,SceneStringNames::get_singleton()->_body_exit_tree);
+ node->disconnect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_body_enter_tree);
+ node->disconnect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_body_exit_tree);
if (!E->get().in_tree)
continue;
- for(int i=0;i<E->get().shapes.size();i++) {
+ for (int i = 0; i < E->get().shapes.size(); i++) {
- emit_signal(SceneStringNames::get_singleton()->body_shape_exited,E->key(),node,E->get().shapes[i].body_shape,E->get().shapes[i].area_shape);
+ emit_signal(SceneStringNames::get_singleton()->body_shape_exited, E->key(), node, E->get().shapes[i].body_shape, E->get().shapes[i].area_shape);
}
- emit_signal(SceneStringNames::get_singleton()->body_exited,obj);
+ emit_signal(SceneStringNames::get_singleton()->body_exited, obj);
}
-
}
{
- Map<ObjectID,AreaState> bmcopy = area_map;
+ Map<ObjectID, AreaState> bmcopy = area_map;
area_map.clear();
//disconnect all monitored stuff
- for (Map<ObjectID,AreaState>::Element *E=bmcopy.front();E;E=E->next()) {
+ for (Map<ObjectID, AreaState>::Element *E = bmcopy.front(); E; E = E->next()) {
Object *obj = ObjectDB::get_instance(E->key());
Node *node = obj ? obj->cast_to<Node>() : NULL;
@@ -389,58 +360,53 @@ void Area2D::_clear_monitoring() {
continue;
//ERR_CONTINUE(!node);
- node->disconnect(SceneStringNames::get_singleton()->tree_entered,this,SceneStringNames::get_singleton()->_area_enter_tree);
- node->disconnect(SceneStringNames::get_singleton()->tree_exited,this,SceneStringNames::get_singleton()->_area_exit_tree);
+ node->disconnect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_area_enter_tree);
+ node->disconnect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_area_exit_tree);
if (!E->get().in_tree)
continue;
- for(int i=0;i<E->get().shapes.size();i++) {
+ for (int i = 0; i < E->get().shapes.size(); i++) {
- emit_signal(SceneStringNames::get_singleton()->area_shape_exited,E->key(),node,E->get().shapes[i].area_shape,E->get().shapes[i].self_shape);
+ emit_signal(SceneStringNames::get_singleton()->area_shape_exited, E->key(), node, E->get().shapes[i].area_shape, E->get().shapes[i].self_shape);
}
- emit_signal(SceneStringNames::get_singleton()->area_exited,obj);
+ emit_signal(SceneStringNames::get_singleton()->area_exited, obj);
}
}
-
}
void Area2D::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_EXIT_TREE: {
_clear_monitoring();
} break;
}
-
}
-
void Area2D::set_monitoring(bool p_enable) {
-
- if (p_enable==monitoring)
+ if (p_enable == monitoring)
return;
if (locked) {
ERR_EXPLAIN("Function blocked during in/out signal. Use call_deferred(\"set_enable_monitoring\",true/false)");
}
ERR_FAIL_COND(locked);
- monitoring=p_enable;
+ monitoring = p_enable;
if (monitoring) {
- Physics2DServer::get_singleton()->area_set_monitor_callback(get_rid(),this,SceneStringNames::get_singleton()->_body_inout);
- Physics2DServer::get_singleton()->area_set_area_monitor_callback(get_rid(),this,SceneStringNames::get_singleton()->_area_inout);
+ Physics2DServer::get_singleton()->area_set_monitor_callback(get_rid(), this, SceneStringNames::get_singleton()->_body_inout);
+ Physics2DServer::get_singleton()->area_set_area_monitor_callback(get_rid(), this, SceneStringNames::get_singleton()->_area_inout);
} else {
- Physics2DServer::get_singleton()->area_set_monitor_callback(get_rid(),NULL,StringName());
- Physics2DServer::get_singleton()->area_set_area_monitor_callback(get_rid(),NULL,StringName());
+ Physics2DServer::get_singleton()->area_set_monitor_callback(get_rid(), NULL, StringName());
+ Physics2DServer::get_singleton()->area_set_area_monitor_callback(get_rid(), NULL, StringName());
_clear_monitoring();
-
}
}
@@ -456,12 +422,12 @@ void Area2D::set_monitorable(bool p_enable) {
}
ERR_FAIL_COND(locked);
- if (p_enable==monitorable)
+ if (p_enable == monitorable)
return;
- monitorable=p_enable;
+ monitorable = p_enable;
- Physics2DServer::get_singleton()->area_set_monitorable(get_rid(),monitorable);
+ Physics2DServer::get_singleton()->area_set_monitorable(get_rid(), monitorable);
}
bool Area2D::is_monitorable() const {
@@ -471,18 +437,17 @@ bool Area2D::is_monitorable() const {
Array Area2D::get_overlapping_bodies() const {
- ERR_FAIL_COND_V(!monitoring,Array());
+ ERR_FAIL_COND_V(!monitoring, Array());
Array ret;
ret.resize(body_map.size());
- int idx=0;
- for (const Map<ObjectID,BodyState>::Element *E=body_map.front();E;E=E->next()) {
+ int idx = 0;
+ for (const Map<ObjectID, BodyState>::Element *E = body_map.front(); E; E = E->next()) {
Object *obj = ObjectDB::get_instance(E->key());
if (!obj) {
- ret.resize( ret.size() -1 ); //ops
+ ret.resize(ret.size() - 1); //ops
} else {
- ret[idx++]=obj;
+ ret[idx++] = obj;
}
-
}
return ret;
@@ -490,49 +455,44 @@ Array Area2D::get_overlapping_bodies() const {
Array Area2D::get_overlapping_areas() const {
- ERR_FAIL_COND_V(!monitoring,Array());
+ ERR_FAIL_COND_V(!monitoring, Array());
Array ret;
ret.resize(area_map.size());
- int idx=0;
- for (const Map<ObjectID,AreaState>::Element *E=area_map.front();E;E=E->next()) {
+ int idx = 0;
+ for (const Map<ObjectID, AreaState>::Element *E = area_map.front(); E; E = E->next()) {
Object *obj = ObjectDB::get_instance(E->key());
if (!obj) {
- ret.resize( ret.size() -1 ); //ops
+ ret.resize(ret.size() - 1); //ops
} else {
- ret[idx++]=obj;
+ ret[idx++] = obj;
}
-
}
return ret;
}
-bool Area2D::overlaps_area(Node* p_area) const {
+bool Area2D::overlaps_area(Node *p_area) const {
- ERR_FAIL_NULL_V(p_area,false);
- const Map<ObjectID,AreaState>::Element *E=area_map.find(p_area->get_instance_ID());
+ ERR_FAIL_NULL_V(p_area, false);
+ const Map<ObjectID, AreaState>::Element *E = area_map.find(p_area->get_instance_ID());
if (!E)
return false;
return E->get().in_tree;
-
-
-
}
-bool Area2D::overlaps_body(Node* p_body) const{
+bool Area2D::overlaps_body(Node *p_body) const {
- ERR_FAIL_NULL_V(p_body,false);
- const Map<ObjectID,BodyState>::Element *E=body_map.find(p_body->get_instance_ID());
+ ERR_FAIL_NULL_V(p_body, false);
+ const Map<ObjectID, BodyState>::Element *E = body_map.find(p_body->get_instance_ID());
if (!E)
return false;
return E->get().in_tree;
-
}
void Area2D::set_collision_mask(uint32_t p_mask) {
- collision_mask=p_mask;
- Physics2DServer::get_singleton()->area_set_collision_mask(get_rid(),p_mask);
+ collision_mask = p_mask;
+ Physics2DServer::get_singleton()->area_set_collision_mask(get_rid(), p_mask);
}
uint32_t Area2D::get_collision_mask() const {
@@ -540,11 +500,10 @@ uint32_t Area2D::get_collision_mask() const {
return collision_mask;
}
-
void Area2D::set_layer_mask(uint32_t p_mask) {
- layer_mask=p_mask;
- Physics2DServer::get_singleton()->area_set_layer_mask(get_rid(),p_mask);
+ layer_mask = p_mask;
+ Physics2DServer::get_singleton()->area_set_layer_mask(get_rid(), p_mask);
}
uint32_t Area2D::get_layer_mask() const {
@@ -556,143 +515,135 @@ void Area2D::set_collision_mask_bit(int p_bit, bool p_value) {
uint32_t mask = get_collision_mask();
if (p_value)
- mask|=1<<p_bit;
+ mask |= 1 << p_bit;
else
- mask&=~(1<<p_bit);
+ mask &= ~(1 << p_bit);
set_collision_mask(mask);
-
}
-bool Area2D::get_collision_mask_bit(int p_bit) const{
+bool Area2D::get_collision_mask_bit(int p_bit) const {
- return get_collision_mask()&(1<<p_bit);
+ return get_collision_mask() & (1 << p_bit);
}
-
void Area2D::set_layer_mask_bit(int p_bit, bool p_value) {
uint32_t mask = get_layer_mask();
if (p_value)
- mask|=1<<p_bit;
+ mask |= 1 << p_bit;
else
- mask&=~(1<<p_bit);
+ mask &= ~(1 << p_bit);
set_layer_mask(mask);
-
}
-bool Area2D::get_layer_mask_bit(int p_bit) const{
+bool Area2D::get_layer_mask_bit(int p_bit) const {
- return get_layer_mask()&(1<<p_bit);
+ return get_layer_mask() & (1 << p_bit);
}
-
void Area2D::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_body_enter_tree","id"),&Area2D::_body_enter_tree);
- ClassDB::bind_method(D_METHOD("_body_exit_tree","id"),&Area2D::_body_exit_tree);
-
- ClassDB::bind_method(D_METHOD("_area_enter_tree","id"),&Area2D::_area_enter_tree);
- ClassDB::bind_method(D_METHOD("_area_exit_tree","id"),&Area2D::_area_exit_tree);
-
- ClassDB::bind_method(D_METHOD("set_space_override_mode","enable"),&Area2D::set_space_override_mode);
- ClassDB::bind_method(D_METHOD("get_space_override_mode"),&Area2D::get_space_override_mode);
+ ClassDB::bind_method(D_METHOD("_body_enter_tree", "id"), &Area2D::_body_enter_tree);
+ ClassDB::bind_method(D_METHOD("_body_exit_tree", "id"), &Area2D::_body_exit_tree);
- ClassDB::bind_method(D_METHOD("set_gravity_is_point","enable"),&Area2D::set_gravity_is_point);
- ClassDB::bind_method(D_METHOD("is_gravity_a_point"),&Area2D::is_gravity_a_point);
+ ClassDB::bind_method(D_METHOD("_area_enter_tree", "id"), &Area2D::_area_enter_tree);
+ ClassDB::bind_method(D_METHOD("_area_exit_tree", "id"), &Area2D::_area_exit_tree);
- ClassDB::bind_method(D_METHOD("set_gravity_distance_scale","distance_scale"),&Area2D::set_gravity_distance_scale);
- ClassDB::bind_method(D_METHOD("get_gravity_distance_scale"),&Area2D::get_gravity_distance_scale);
+ ClassDB::bind_method(D_METHOD("set_space_override_mode", "enable"), &Area2D::set_space_override_mode);
+ ClassDB::bind_method(D_METHOD("get_space_override_mode"), &Area2D::get_space_override_mode);
- ClassDB::bind_method(D_METHOD("set_gravity_vector","vector"),&Area2D::set_gravity_vector);
- ClassDB::bind_method(D_METHOD("get_gravity_vector"),&Area2D::get_gravity_vector);
+ ClassDB::bind_method(D_METHOD("set_gravity_is_point", "enable"), &Area2D::set_gravity_is_point);
+ ClassDB::bind_method(D_METHOD("is_gravity_a_point"), &Area2D::is_gravity_a_point);
- ClassDB::bind_method(D_METHOD("set_gravity","gravity"),&Area2D::set_gravity);
- ClassDB::bind_method(D_METHOD("get_gravity"),&Area2D::get_gravity);
+ ClassDB::bind_method(D_METHOD("set_gravity_distance_scale", "distance_scale"), &Area2D::set_gravity_distance_scale);
+ ClassDB::bind_method(D_METHOD("get_gravity_distance_scale"), &Area2D::get_gravity_distance_scale);
- ClassDB::bind_method(D_METHOD("set_linear_damp","linear_damp"),&Area2D::set_linear_damp);
- ClassDB::bind_method(D_METHOD("get_linear_damp"),&Area2D::get_linear_damp);
+ ClassDB::bind_method(D_METHOD("set_gravity_vector", "vector"), &Area2D::set_gravity_vector);
+ ClassDB::bind_method(D_METHOD("get_gravity_vector"), &Area2D::get_gravity_vector);
- ClassDB::bind_method(D_METHOD("set_angular_damp","angular_damp"),&Area2D::set_angular_damp);
- ClassDB::bind_method(D_METHOD("get_angular_damp"),&Area2D::get_angular_damp);
+ ClassDB::bind_method(D_METHOD("set_gravity", "gravity"), &Area2D::set_gravity);
+ ClassDB::bind_method(D_METHOD("get_gravity"), &Area2D::get_gravity);
- ClassDB::bind_method(D_METHOD("set_priority","priority"),&Area2D::set_priority);
- ClassDB::bind_method(D_METHOD("get_priority"),&Area2D::get_priority);
+ ClassDB::bind_method(D_METHOD("set_linear_damp", "linear_damp"), &Area2D::set_linear_damp);
+ ClassDB::bind_method(D_METHOD("get_linear_damp"), &Area2D::get_linear_damp);
- ClassDB::bind_method(D_METHOD("set_collision_mask","collision_mask"),&Area2D::set_collision_mask);
- ClassDB::bind_method(D_METHOD("get_collision_mask"),&Area2D::get_collision_mask);
+ ClassDB::bind_method(D_METHOD("set_angular_damp", "angular_damp"), &Area2D::set_angular_damp);
+ ClassDB::bind_method(D_METHOD("get_angular_damp"), &Area2D::get_angular_damp);
- ClassDB::bind_method(D_METHOD("set_layer_mask","layer_mask"),&Area2D::set_layer_mask);
- ClassDB::bind_method(D_METHOD("get_layer_mask"),&Area2D::get_layer_mask);
+ ClassDB::bind_method(D_METHOD("set_priority", "priority"), &Area2D::set_priority);
+ ClassDB::bind_method(D_METHOD("get_priority"), &Area2D::get_priority);
- ClassDB::bind_method(D_METHOD("set_collision_mask_bit","bit","value"),&Area2D::set_collision_mask_bit);
- ClassDB::bind_method(D_METHOD("get_collision_mask_bit","bit"),&Area2D::get_collision_mask_bit);
+ ClassDB::bind_method(D_METHOD("set_collision_mask", "collision_mask"), &Area2D::set_collision_mask);
+ ClassDB::bind_method(D_METHOD("get_collision_mask"), &Area2D::get_collision_mask);
- ClassDB::bind_method(D_METHOD("set_layer_mask_bit","bit","value"),&Area2D::set_layer_mask_bit);
- ClassDB::bind_method(D_METHOD("get_layer_mask_bit","bit"),&Area2D::get_layer_mask_bit);
+ ClassDB::bind_method(D_METHOD("set_layer_mask", "layer_mask"), &Area2D::set_layer_mask);
+ ClassDB::bind_method(D_METHOD("get_layer_mask"), &Area2D::get_layer_mask);
- ClassDB::bind_method(D_METHOD("set_monitoring","enable"),&Area2D::set_monitoring);
- ClassDB::bind_method(D_METHOD("is_monitoring"),&Area2D::is_monitoring);
+ ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &Area2D::set_collision_mask_bit);
+ ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &Area2D::get_collision_mask_bit);
- ClassDB::bind_method(D_METHOD("set_monitorable","enable"),&Area2D::set_monitorable);
- ClassDB::bind_method(D_METHOD("is_monitorable"),&Area2D::is_monitorable);
+ ClassDB::bind_method(D_METHOD("set_layer_mask_bit", "bit", "value"), &Area2D::set_layer_mask_bit);
+ ClassDB::bind_method(D_METHOD("get_layer_mask_bit", "bit"), &Area2D::get_layer_mask_bit);
- ClassDB::bind_method(D_METHOD("get_overlapping_bodies"),&Area2D::get_overlapping_bodies);
- ClassDB::bind_method(D_METHOD("get_overlapping_areas"),&Area2D::get_overlapping_areas);
+ ClassDB::bind_method(D_METHOD("set_monitoring", "enable"), &Area2D::set_monitoring);
+ ClassDB::bind_method(D_METHOD("is_monitoring"), &Area2D::is_monitoring);
- ClassDB::bind_method(D_METHOD("overlaps_body","body"),&Area2D::overlaps_body);
- ClassDB::bind_method(D_METHOD("overlaps_area","area"),&Area2D::overlaps_area);
+ ClassDB::bind_method(D_METHOD("set_monitorable", "enable"), &Area2D::set_monitorable);
+ ClassDB::bind_method(D_METHOD("is_monitorable"), &Area2D::is_monitorable);
- ClassDB::bind_method(D_METHOD("_body_inout"),&Area2D::_body_inout);
- ClassDB::bind_method(D_METHOD("_area_inout"),&Area2D::_area_inout);
+ ClassDB::bind_method(D_METHOD("get_overlapping_bodies"), &Area2D::get_overlapping_bodies);
+ ClassDB::bind_method(D_METHOD("get_overlapping_areas"), &Area2D::get_overlapping_areas);
+ ClassDB::bind_method(D_METHOD("overlaps_body", "body"), &Area2D::overlaps_body);
+ ClassDB::bind_method(D_METHOD("overlaps_area", "area"), &Area2D::overlaps_area);
- ADD_SIGNAL( MethodInfo("body_shape_entered",PropertyInfo(Variant::INT,"body_id"),PropertyInfo(Variant::OBJECT,"body",PROPERTY_HINT_RESOURCE_TYPE,"PhysicsBody2D"),PropertyInfo(Variant::INT,"body_shape"),PropertyInfo(Variant::INT,"area_shape")));
- ADD_SIGNAL( MethodInfo("body_shape_exited",PropertyInfo(Variant::INT,"body_id"),PropertyInfo(Variant::OBJECT,"body",PROPERTY_HINT_RESOURCE_TYPE,"PhysicsBody2D"),PropertyInfo(Variant::INT,"body_shape"),PropertyInfo(Variant::INT,"area_shape")));
- ADD_SIGNAL( MethodInfo("body_entered",PropertyInfo(Variant::OBJECT,"body",PROPERTY_HINT_RESOURCE_TYPE,"PhysicsBody2D")));
- ADD_SIGNAL( MethodInfo("body_exited",PropertyInfo(Variant::OBJECT,"body",PROPERTY_HINT_RESOURCE_TYPE,"PhysicsBody2D")));
+ ClassDB::bind_method(D_METHOD("_body_inout"), &Area2D::_body_inout);
+ ClassDB::bind_method(D_METHOD("_area_inout"), &Area2D::_area_inout);
- ADD_SIGNAL( MethodInfo("area_shape_entered",PropertyInfo(Variant::INT,"area_id"),PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area2D"),PropertyInfo(Variant::INT,"area_shape"),PropertyInfo(Variant::INT,"self_shape")));
- ADD_SIGNAL( MethodInfo("area_shape_exited",PropertyInfo(Variant::INT,"area_id"),PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area2D"),PropertyInfo(Variant::INT,"area_shape"),PropertyInfo(Variant::INT,"self_shape")));
- ADD_SIGNAL( MethodInfo("area_entered",PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area2D")));
- ADD_SIGNAL( MethodInfo("area_exited",PropertyInfo(Variant::OBJECT,"area",PROPERTY_HINT_RESOURCE_TYPE,"Area2D")));
+ ADD_SIGNAL(MethodInfo("body_shape_entered", PropertyInfo(Variant::INT, "body_id"), PropertyInfo(Variant::OBJECT, "body", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsBody2D"), PropertyInfo(Variant::INT, "body_shape"), PropertyInfo(Variant::INT, "area_shape")));
+ ADD_SIGNAL(MethodInfo("body_shape_exited", PropertyInfo(Variant::INT, "body_id"), PropertyInfo(Variant::OBJECT, "body", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsBody2D"), PropertyInfo(Variant::INT, "body_shape"), PropertyInfo(Variant::INT, "area_shape")));
+ ADD_SIGNAL(MethodInfo("body_entered", PropertyInfo(Variant::OBJECT, "body", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsBody2D")));
+ ADD_SIGNAL(MethodInfo("body_exited", PropertyInfo(Variant::OBJECT, "body", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsBody2D")));
+ ADD_SIGNAL(MethodInfo("area_shape_entered", PropertyInfo(Variant::INT, "area_id"), PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area2D"), PropertyInfo(Variant::INT, "area_shape"), PropertyInfo(Variant::INT, "self_shape")));
+ ADD_SIGNAL(MethodInfo("area_shape_exited", PropertyInfo(Variant::INT, "area_id"), PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area2D"), PropertyInfo(Variant::INT, "area_shape"), PropertyInfo(Variant::INT, "self_shape")));
+ ADD_SIGNAL(MethodInfo("area_entered", PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area2D")));
+ ADD_SIGNAL(MethodInfo("area_exited", PropertyInfo(Variant::OBJECT, "area", PROPERTY_HINT_RESOURCE_TYPE, "Area2D")));
- ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"space_override",PROPERTY_HINT_ENUM,"Disabled,Combine,Combine-Replace,Replace,Replace-Combine"),"set_space_override_mode","get_space_override_mode");
- ADD_PROPERTYNZ( PropertyInfo(Variant::BOOL,"gravity_point"),"set_gravity_is_point","is_gravity_a_point");
- ADD_PROPERTYNZ( PropertyInfo(Variant::REAL,"gravity_distance_scale", PROPERTY_HINT_RANGE,"0,1024,0.001"),"set_gravity_distance_scale","get_gravity_distance_scale");
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"gravity_vec"),"set_gravity_vector","get_gravity_vector");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"gravity",PROPERTY_HINT_RANGE,"-1024,1024,0.001"),"set_gravity","get_gravity");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"linear_damp",PROPERTY_HINT_RANGE,"0,100,0.01"),"set_linear_damp","get_linear_damp");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"angular_damp",PROPERTY_HINT_RANGE,"0,100,0.01"),"set_angular_damp","get_angular_damp");
- ADD_PROPERTYNZ( PropertyInfo(Variant::INT,"priority",PROPERTY_HINT_RANGE,"0,128,1"),"set_priority","get_priority");
- ADD_PROPERTYNO( PropertyInfo(Variant::BOOL,"monitoring"),"set_monitoring","is_monitoring");
- ADD_PROPERTYNO( PropertyInfo(Variant::BOOL,"monitorable"),"set_monitorable","is_monitorable");
- ADD_GROUP("Collision","collision_");
- ADD_PROPERTYNO( PropertyInfo(Variant::INT,"collision_layers",PROPERTY_HINT_LAYERS_2D_PHYSICS),"set_layer_mask","get_layer_mask");
- ADD_PROPERTYNO( PropertyInfo(Variant::INT,"collision_mask",PROPERTY_HINT_LAYERS_2D_PHYSICS),"set_collision_mask","get_collision_mask");
-
+ ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "space_override", PROPERTY_HINT_ENUM, "Disabled,Combine,Combine-Replace,Replace,Replace-Combine"), "set_space_override_mode", "get_space_override_mode");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "gravity_point"), "set_gravity_is_point", "is_gravity_a_point");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "gravity_distance_scale", PROPERTY_HINT_RANGE, "0,1024,0.001"), "set_gravity_distance_scale", "get_gravity_distance_scale");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "gravity_vec"), "set_gravity_vector", "get_gravity_vector");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "gravity", PROPERTY_HINT_RANGE, "-1024,1024,0.001"), "set_gravity", "get_gravity");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "linear_damp", PROPERTY_HINT_RANGE, "0,100,0.01"), "set_linear_damp", "get_linear_damp");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_damp", PROPERTY_HINT_RANGE, "0,100,0.01"), "set_angular_damp", "get_angular_damp");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "priority", PROPERTY_HINT_RANGE, "0,128,1"), "set_priority", "get_priority");
+ ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "monitoring"), "set_monitoring", "is_monitoring");
+ ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "monitorable"), "set_monitorable", "is_monitorable");
+ ADD_GROUP("Collision", "collision_");
+ ADD_PROPERTYNO(PropertyInfo(Variant::INT, "collision_layers", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_layer_mask", "get_layer_mask");
+ ADD_PROPERTYNO(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_collision_mask", "get_collision_mask");
}
-Area2D::Area2D() : CollisionObject2D(Physics2DServer::get_singleton()->area_create(),true) {
+Area2D::Area2D()
+ : CollisionObject2D(Physics2DServer::get_singleton()->area_create(), true) {
- space_override=SPACE_OVERRIDE_DISABLED;
+ space_override = SPACE_OVERRIDE_DISABLED;
set_gravity(98);
- set_gravity_vector(Vector2(0,1));
- gravity_is_point=false;
- gravity_distance_scale=0;
- linear_damp=0.1;
- angular_damp=1;
- locked=false;
- priority=0;
- monitoring=false;
- monitorable=false;
- collision_mask=1;
- layer_mask=1;
+ set_gravity_vector(Vector2(0, 1));
+ gravity_is_point = false;
+ gravity_distance_scale = 0;
+ linear_damp = 0.1;
+ angular_damp = 1;
+ locked = false;
+ priority = 0;
+ monitoring = false;
+ monitorable = false;
+ collision_mask = 1;
+ layer_mask = 1;
set_monitoring(true);
set_monitorable(true);
}
Area2D::~Area2D() {
-
-
}
diff --git a/scene/2d/area_2d.h b/scene/2d/area_2d.h
index 68bada707b..2402ff763b 100644
--- a/scene/2d/area_2d.h
+++ b/scene/2d/area_2d.h
@@ -34,9 +34,9 @@
class Area2D : public CollisionObject2D {
- GDCLASS( Area2D, CollisionObject2D );
-public:
+ GDCLASS(Area2D, CollisionObject2D);
+public:
enum SpaceOverride {
SPACE_OVERRIDE_DISABLED,
SPACE_OVERRIDE_COMBINE,
@@ -44,9 +44,8 @@ public:
SPACE_OVERRIDE_REPLACE,
SPACE_OVERRIDE_REPLACE_COMBINE
};
-private:
-
+private:
SpaceOverride space_override;
Vector2 gravity_vec;
real_t gravity;
@@ -61,7 +60,7 @@ private:
bool monitorable;
bool locked;
- void _body_inout(int p_status,const RID& p_body, int p_instance, int p_body_shape,int p_area_shape);
+ void _body_inout(int p_status, const RID &p_body, int p_instance, int p_body_shape, int p_area_shape);
void _body_enter_tree(ObjectID p_id);
void _body_exit_tree(ObjectID p_id);
@@ -70,15 +69,18 @@ private:
int body_shape;
int area_shape;
- bool operator<(const ShapePair& p_sp) const {
- if (body_shape==p_sp.body_shape)
+ bool operator<(const ShapePair &p_sp) const {
+ if (body_shape == p_sp.body_shape)
return area_shape < p_sp.area_shape;
else
return body_shape < p_sp.body_shape;
}
ShapePair() {}
- ShapePair(int p_bs, int p_as) { body_shape=p_bs; area_shape=p_as; }
+ ShapePair(int p_bs, int p_as) {
+ body_shape = p_bs;
+ area_shape = p_as;
+ }
};
struct BodyState {
@@ -88,11 +90,9 @@ private:
VSet<ShapePair> shapes;
};
- Map<ObjectID,BodyState> body_map;
-
+ Map<ObjectID, BodyState> body_map;
-
- void _area_inout(int p_status,const RID& p_area, int p_instance, int p_area_shape,int p_self_shape);
+ void _area_inout(int p_status, const RID &p_area, int p_instance, int p_area_shape, int p_self_shape);
void _area_enter_tree(ObjectID p_id);
void _area_exit_tree(ObjectID p_id);
@@ -101,15 +101,18 @@ private:
int area_shape;
int self_shape;
- bool operator<(const AreaShapePair& p_sp) const {
- if (area_shape==p_sp.area_shape)
+ bool operator<(const AreaShapePair &p_sp) const {
+ if (area_shape == p_sp.area_shape)
return self_shape < p_sp.self_shape;
else
return area_shape < p_sp.area_shape;
}
AreaShapePair() {}
- AreaShapePair(int p_bs, int p_as) { area_shape=p_bs; self_shape=p_as; }
+ AreaShapePair(int p_bs, int p_as) {
+ area_shape = p_bs;
+ self_shape = p_as;
+ }
};
struct AreaState {
@@ -119,16 +122,14 @@ private:
VSet<AreaShapePair> shapes;
};
- Map<ObjectID,AreaState> area_map;
+ Map<ObjectID, AreaState> area_map;
void _clear_monitoring();
-
protected:
-
void _notification(int p_what);
static void _bind_methods();
-public:
+public:
void set_space_override_mode(SpaceOverride p_mode);
SpaceOverride get_space_override_mode() const;
@@ -138,7 +139,7 @@ public:
void set_gravity_distance_scale(real_t p_scale);
real_t get_gravity_distance_scale() const;
- void set_gravity_vector(const Vector2& p_vec);
+ void set_gravity_vector(const Vector2 &p_vec);
Vector2 get_gravity_vector() const;
void set_gravity(real_t p_gravity);
@@ -174,8 +175,8 @@ public:
Array get_overlapping_bodies() const; //function for script
Array get_overlapping_areas() const; //function for script
- bool overlaps_area(Node* p_area) const;
- bool overlaps_body(Node* p_body) const;
+ bool overlaps_area(Node *p_area) const;
+ bool overlaps_body(Node *p_body) const;
Area2D();
~Area2D();
diff --git a/scene/2d/back_buffer_copy.cpp b/scene/2d/back_buffer_copy.cpp
index eaa33fe70a..5a79cee6d0 100644
--- a/scene/2d/back_buffer_copy.cpp
+++ b/scene/2d/back_buffer_copy.cpp
@@ -30,22 +30,21 @@
void BackBufferCopy::_update_copy_mode() {
- switch(copy_mode) {
+ switch (copy_mode) {
case COPY_MODE_DISABLED: {
- VS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(),false,Rect2());
+ VS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(), false, Rect2());
} break;
case COPY_MODE_RECT: {
- VS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(),true,rect);
+ VS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(), true, rect);
} break;
case COPY_MODE_VIEWPORT: {
- VS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(),true,Rect2());
+ VS::get_singleton()->canvas_item_set_copy_to_backbuffer(get_canvas_item(), true, Rect2());
} break;
-
}
}
@@ -54,50 +53,47 @@ Rect2 BackBufferCopy::get_item_rect() const {
return rect;
}
-void BackBufferCopy::set_rect(const Rect2& p_rect) {
+void BackBufferCopy::set_rect(const Rect2 &p_rect) {
- rect=p_rect;
+ rect = p_rect;
_update_copy_mode();
}
-Rect2 BackBufferCopy::get_rect() const{
+Rect2 BackBufferCopy::get_rect() const {
return rect;
}
-void BackBufferCopy::set_copy_mode(CopyMode p_mode){
+void BackBufferCopy::set_copy_mode(CopyMode p_mode) {
- copy_mode=p_mode;
+ copy_mode = p_mode;
_update_copy_mode();
}
-BackBufferCopy::CopyMode BackBufferCopy::get_copy_mode() const{
+BackBufferCopy::CopyMode BackBufferCopy::get_copy_mode() const {
return copy_mode;
}
-
void BackBufferCopy::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_rect","rect"),&BackBufferCopy::set_rect);
- ClassDB::bind_method(D_METHOD("get_rect"),&BackBufferCopy::get_rect);
+ ClassDB::bind_method(D_METHOD("set_rect", "rect"), &BackBufferCopy::set_rect);
+ ClassDB::bind_method(D_METHOD("get_rect"), &BackBufferCopy::get_rect);
- ClassDB::bind_method(D_METHOD("set_copy_mode","copy_mode"),&BackBufferCopy::set_copy_mode);
- ClassDB::bind_method(D_METHOD("get_copy_mode"),&BackBufferCopy::get_copy_mode);
+ ClassDB::bind_method(D_METHOD("set_copy_mode", "copy_mode"), &BackBufferCopy::set_copy_mode);
+ ClassDB::bind_method(D_METHOD("get_copy_mode"), &BackBufferCopy::get_copy_mode);
- ADD_PROPERTY( PropertyInfo(Variant::INT,"copy_mode",PROPERTY_HINT_ENUM,"Disabled,Rect,Viewport"),"set_copy_mode","get_copy_mode");
- ADD_PROPERTY( PropertyInfo(Variant::RECT2,"rect"),"set_rect","get_rect");
-
- BIND_CONSTANT( COPY_MODE_DISABLED );
- BIND_CONSTANT( COPY_MODE_RECT );
- BIND_CONSTANT( COPY_MODE_VIEWPORT );
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "copy_mode", PROPERTY_HINT_ENUM, "Disabled,Rect,Viewport"), "set_copy_mode", "get_copy_mode");
+ ADD_PROPERTY(PropertyInfo(Variant::RECT2, "rect"), "set_rect", "get_rect");
+ BIND_CONSTANT(COPY_MODE_DISABLED);
+ BIND_CONSTANT(COPY_MODE_RECT);
+ BIND_CONSTANT(COPY_MODE_VIEWPORT);
}
-BackBufferCopy::BackBufferCopy(){
+BackBufferCopy::BackBufferCopy() {
- rect=Rect2(-100,-100,200,200);
- copy_mode=COPY_MODE_RECT;
+ rect = Rect2(-100, -100, 200, 200);
+ copy_mode = COPY_MODE_RECT;
_update_copy_mode();
}
-BackBufferCopy::~BackBufferCopy(){
-
+BackBufferCopy::~BackBufferCopy() {
}
diff --git a/scene/2d/back_buffer_copy.h b/scene/2d/back_buffer_copy.h
index 22387f3e9d..b4f83e7db1 100644
--- a/scene/2d/back_buffer_copy.h
+++ b/scene/2d/back_buffer_copy.h
@@ -32,27 +32,26 @@
#include "scene/2d/node_2d.h"
class BackBufferCopy : public Node2D {
- GDCLASS( BackBufferCopy,Node2D);
+ GDCLASS(BackBufferCopy, Node2D);
+
public:
enum CopyMode {
COPY_MODE_DISABLED,
COPY_MODE_RECT,
COPY_MODE_VIEWPORT
};
-private:
+private:
Rect2 rect;
CopyMode copy_mode;
void _update_copy_mode();
protected:
-
static void _bind_methods();
public:
-
- void set_rect(const Rect2& p_rect);
+ void set_rect(const Rect2 &p_rect);
Rect2 get_rect() const;
void set_copy_mode(CopyMode p_mode);
diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp
index 9ae2315867..f8388cdcc5 100644
--- a/scene/2d/camera_2d.cpp
+++ b/scene/2d/camera_2d.cpp
@@ -27,14 +27,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "camera_2d.h"
+#include "core/math/math_funcs.h"
#include "scene/scene_string_names.h"
#include "servers/visual_server.h"
-#include "core/math/math_funcs.h"
#include <editor/editor_node.h>
void Camera2D::_update_scroll() {
-
if (!is_inside_tree())
return;
@@ -45,16 +44,15 @@ void Camera2D::_update_scroll() {
if (current) {
- ERR_FAIL_COND( custom_viewport && !ObjectDB::get_instance(custom_viewport_id) );
+ ERR_FAIL_COND(custom_viewport && !ObjectDB::get_instance(custom_viewport_id));
Transform2D xform = get_camera_transform();
if (viewport) {
- viewport->set_canvas_transform( xform );
+ viewport->set_canvas_transform(xform);
}
- get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME,group_name,"_camera_moved",xform);
+ get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, group_name, "_camera_moved", xform);
};
-
}
void Camera2D::set_zoom(const Vector2 &p_zoom) {
@@ -70,31 +68,28 @@ Vector2 Camera2D::get_zoom() const {
return zoom;
};
-
-Transform2D Camera2D::get_camera_transform() {
+Transform2D Camera2D::get_camera_transform() {
if (!get_tree())
return Transform2D();
- ERR_FAIL_COND_V( custom_viewport && !ObjectDB::get_instance(custom_viewport_id), Transform2D() );
+ ERR_FAIL_COND_V(custom_viewport && !ObjectDB::get_instance(custom_viewport_id), Transform2D());
Size2 screen_size = viewport->get_visible_rect().size;
-
Point2 new_camera_pos = get_global_transform().get_origin();
Point2 ret_camera_pos;
if (!first) {
-
- if (anchor_mode==ANCHOR_MODE_DRAG_CENTER) {
+ if (anchor_mode == ANCHOR_MODE_DRAG_CENTER) {
if (h_drag_enabled && !get_tree()->is_editor_hint()) {
- camera_pos.x = MIN( camera_pos.x, (new_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_RIGHT]));
- camera_pos.x = MAX( camera_pos.x, (new_camera_pos.x - screen_size.x * 0.5 * drag_margin[MARGIN_LEFT]));
+ camera_pos.x = MIN(camera_pos.x, (new_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_RIGHT]));
+ camera_pos.x = MAX(camera_pos.x, (new_camera_pos.x - screen_size.x * 0.5 * drag_margin[MARGIN_LEFT]));
} else {
- if (h_ofs<0) {
+ if (h_ofs < 0) {
camera_pos.x = new_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_RIGHT] * h_ofs;
} else {
camera_pos.x = new_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_LEFT] * h_ofs;
@@ -103,33 +98,33 @@ Transform2D Camera2D::get_camera_transform() {
if (v_drag_enabled && !get_tree()->is_editor_hint()) {
- camera_pos.y = MIN( camera_pos.y, (new_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_BOTTOM]));
- camera_pos.y = MAX( camera_pos.y, (new_camera_pos.y - screen_size.y * 0.5 * drag_margin[MARGIN_TOP]));
+ camera_pos.y = MIN(camera_pos.y, (new_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_BOTTOM]));
+ camera_pos.y = MAX(camera_pos.y, (new_camera_pos.y - screen_size.y * 0.5 * drag_margin[MARGIN_TOP]));
} else {
- if (v_ofs<0) {
+ if (v_ofs < 0) {
camera_pos.y = new_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_TOP] * v_ofs;
} else {
camera_pos.y = new_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_BOTTOM] * v_ofs;
}
}
- } else if (anchor_mode==ANCHOR_MODE_FIXED_TOP_LEFT){
+ } else if (anchor_mode == ANCHOR_MODE_FIXED_TOP_LEFT) {
- camera_pos=new_camera_pos;
+ camera_pos = new_camera_pos;
}
- Point2 screen_offset = (anchor_mode==ANCHOR_MODE_DRAG_CENTER ? (screen_size * 0.5 * zoom) : Point2());
- Rect2 screen_rect(-screen_offset+camera_pos,screen_size*zoom);
-
- if (offset!=Vector2())
- screen_rect.pos+=offset;
-
+ Point2 screen_offset = (anchor_mode == ANCHOR_MODE_DRAG_CENTER ? (screen_size * 0.5 * zoom) : Point2());
+ Rect2 screen_rect(-screen_offset + camera_pos, screen_size * zoom);
+
+ if (offset != Vector2())
+ screen_rect.pos += offset;
+
if (limit_smoothing_enabled) {
if (screen_rect.pos.x < limit[MARGIN_LEFT])
camera_pos.x -= screen_rect.pos.x - limit[MARGIN_LEFT];
-
+
if (screen_rect.pos.x + screen_rect.size.x > limit[MARGIN_RIGHT])
camera_pos.x -= screen_rect.pos.x + screen_rect.size.x - limit[MARGIN_RIGHT];
@@ -142,35 +137,31 @@ Transform2D Camera2D::get_camera_transform() {
if (smoothing_enabled && !get_tree()->is_editor_hint()) {
- float c = smoothing*get_fixed_process_delta_time();
- smoothed_camera_pos = ((camera_pos-smoothed_camera_pos)*c)+smoothed_camera_pos;
- ret_camera_pos=smoothed_camera_pos;
+ float c = smoothing * get_fixed_process_delta_time();
+ smoothed_camera_pos = ((camera_pos - smoothed_camera_pos) * c) + smoothed_camera_pos;
+ ret_camera_pos = smoothed_camera_pos;
//camera_pos=camera_pos*(1.0-smoothing)+new_camera_pos*smoothing;
} else {
- ret_camera_pos=smoothed_camera_pos=camera_pos;
-
+ ret_camera_pos = smoothed_camera_pos = camera_pos;
}
-
-
} else {
- ret_camera_pos=smoothed_camera_pos=camera_pos=new_camera_pos;
- first=false;
+ ret_camera_pos = smoothed_camera_pos = camera_pos = new_camera_pos;
+ first = false;
}
-
- Point2 screen_offset = (anchor_mode==ANCHOR_MODE_DRAG_CENTER ? (screen_size * 0.5 * zoom) : Point2());
+ Point2 screen_offset = (anchor_mode == ANCHOR_MODE_DRAG_CENTER ? (screen_size * 0.5 * zoom) : Point2());
float angle = get_global_transform().get_rotation();
- if(rotating){
+ if (rotating) {
screen_offset = screen_offset.rotated(angle);
}
- Rect2 screen_rect(-screen_offset+ret_camera_pos,screen_size*zoom);
+ Rect2 screen_rect(-screen_offset + ret_camera_pos, screen_size * zoom);
if (screen_rect.pos.x < limit[MARGIN_LEFT])
screen_rect.pos.x = limit[MARGIN_LEFT];
-
+
if (screen_rect.pos.x + screen_rect.size.x > limit[MARGIN_RIGHT])
screen_rect.pos.x = limit[MARGIN_RIGHT] - screen_rect.size.x;
@@ -178,38 +169,34 @@ Transform2D Camera2D::get_camera_transform() {
screen_rect.pos.y = limit[MARGIN_BOTTOM] - screen_rect.size.y;
if (screen_rect.pos.y < limit[MARGIN_TOP])
- screen_rect.pos.y =limit[MARGIN_TOP];
-
-
- if (offset!=Vector2()) {
+ screen_rect.pos.y = limit[MARGIN_TOP];
- screen_rect.pos+=offset;
+ if (offset != Vector2()) {
+
+ screen_rect.pos += offset;
if (screen_rect.pos.x + screen_rect.size.x > limit[MARGIN_RIGHT])
screen_rect.pos.x = limit[MARGIN_RIGHT] - screen_rect.size.x;
if (screen_rect.pos.y + screen_rect.size.y > limit[MARGIN_BOTTOM])
screen_rect.pos.y = limit[MARGIN_BOTTOM] - screen_rect.size.y;
-
if (screen_rect.pos.x < limit[MARGIN_LEFT])
- screen_rect.pos.x=limit[MARGIN_LEFT];
+ screen_rect.pos.x = limit[MARGIN_LEFT];
if (screen_rect.pos.y < limit[MARGIN_TOP])
- screen_rect.pos.y =limit[MARGIN_TOP];
-
+ screen_rect.pos.y = limit[MARGIN_TOP];
}
- camera_screen_center=screen_rect.pos+screen_rect.size*0.5;
+ camera_screen_center = screen_rect.pos + screen_rect.size * 0.5;
Transform2D xform;
- if(rotating){
+ if (rotating) {
xform.set_rotation(angle);
}
xform.scale_basis(zoom);
- xform.set_origin(screen_rect.pos/*.floor()*/);
+ xform.set_origin(screen_rect.pos /*.floor()*/);
-
-/*
+ /*
if (0) {
xform = get_global_transform() * xform;
@@ -219,15 +206,12 @@ Transform2D Camera2D::get_camera_transform() {
}
*/
-
return (xform).affine_inverse();
}
-
-
void Camera2D::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_FIXED_PROCESS: {
@@ -236,48 +220,45 @@ void Camera2D::_notification(int p_what) {
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
-
if (!is_fixed_processing())
_update_scroll();
} break;
case NOTIFICATION_ENTER_TREE: {
-
if (custom_viewport && ObjectDB::get_instance(custom_viewport_id)) {
- viewport=custom_viewport;
+ viewport = custom_viewport;
} else {
- viewport=get_viewport();
+ viewport = get_viewport();
}
canvas = get_canvas();
RID vp = viewport->get_viewport_rid();
- group_name = "__cameras_"+itos(vp.get_id());
- canvas_group_name ="__cameras_c"+itos(canvas.get_id());
+ group_name = "__cameras_" + itos(vp.get_id());
+ canvas_group_name = "__cameras_c" + itos(canvas.get_id());
add_to_group(group_name);
add_to_group(canvas_group_name);
- if(get_tree()->is_editor_hint()) {
+ if (get_tree()->is_editor_hint()) {
set_fixed_process(false);
}
_update_scroll();
- first=true;
-
+ first = true;
} break;
case NOTIFICATION_EXIT_TREE: {
- if (is_current()) {
+ if (is_current()) {
if (viewport && !(custom_viewport && !ObjectDB::get_instance(custom_viewport_id))) {
- viewport->set_canvas_transform( Transform2D() );
+ viewport->set_canvas_transform(Transform2D());
}
}
remove_from_group(group_name);
remove_from_group(canvas_group_name);
- viewport=NULL;
+ viewport = NULL;
} break;
case NOTIFICATION_DRAW: {
@@ -287,44 +268,43 @@ void Camera2D::_notification(int p_what) {
Color area_axis_color(0.5, 0.42, 0.87, 0.63);
float area_axis_width = 1;
- if(current)
+ if (current)
area_axis_width = 3;
Transform2D inv_camera_transform = get_camera_transform().affine_inverse();
Size2 screen_size = get_viewport_rect().size;
- Vector2 screen_endpoints[4]= {
+ Vector2 screen_endpoints[4] = {
inv_camera_transform.xform(Vector2(0, 0)),
- inv_camera_transform.xform(Vector2(screen_size.width,0)),
+ inv_camera_transform.xform(Vector2(screen_size.width, 0)),
inv_camera_transform.xform(Vector2(screen_size.width, screen_size.height)),
inv_camera_transform.xform(Vector2(0, screen_size.height))
};
Transform2D inv_transform = get_global_transform().affine_inverse(); // undo global space
- for(int i=0;i<4;i++) {
- draw_line(inv_transform.xform(screen_endpoints[i]), inv_transform.xform(screen_endpoints[(i+1)%4]), area_axis_color, area_axis_width);
+ for (int i = 0; i < 4; i++) {
+ draw_line(inv_transform.xform(screen_endpoints[i]), inv_transform.xform(screen_endpoints[(i + 1) % 4]), area_axis_color, area_axis_width);
}
} break;
}
}
-void Camera2D::set_offset(const Vector2& p_offset) {
+void Camera2D::set_offset(const Vector2 &p_offset) {
- offset=p_offset;
+ offset = p_offset;
_update_scroll();
-
}
-Vector2 Camera2D::get_offset() const{
+Vector2 Camera2D::get_offset() const {
return offset;
}
-void Camera2D::set_anchor_mode(AnchorMode p_anchor_mode){
+void Camera2D::set_anchor_mode(AnchorMode p_anchor_mode) {
- anchor_mode=p_anchor_mode;
+ anchor_mode = p_anchor_mode;
_update_scroll();
}
@@ -333,9 +313,9 @@ Camera2D::AnchorMode Camera2D::get_anchor_mode() const {
return anchor_mode;
}
-void Camera2D::set_rotating(bool p_rotating){
+void Camera2D::set_rotating(bool p_rotating) {
- rotating=p_rotating;
+ rotating = p_rotating;
_update_scroll();
}
@@ -344,25 +324,23 @@ bool Camera2D::is_rotating() const {
return rotating;
}
-
void Camera2D::_make_current(Object *p_which) {
- if (p_which==this) {
+ if (p_which == this) {
- current=true;
+ current = true;
_update_scroll();
} else {
- current=false;
+ current = false;
}
}
-
void Camera2D::_set_current(bool p_current) {
if (p_current)
make_current();
- current=p_current;
+ current = p_current;
}
bool Camera2D::is_current() const {
@@ -373,33 +351,30 @@ bool Camera2D::is_current() const {
void Camera2D::make_current() {
if (!is_inside_tree()) {
- current=true;
+ current = true;
} else {
- get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME,group_name,"_make_current",this);
+ get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, group_name, "_make_current", this);
}
}
void Camera2D::clear_current() {
- current=false;
+ current = false;
if (is_inside_tree()) {
- get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME,group_name,"_make_current",(Object*)(NULL));
+ get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, group_name, "_make_current", (Object *)(NULL));
}
-
}
+void Camera2D::set_limit(Margin p_margin, int p_limit) {
-void Camera2D::set_limit(Margin p_margin,int p_limit) {
-
- ERR_FAIL_INDEX(p_margin,4);
- limit[p_margin]=p_limit;
+ ERR_FAIL_INDEX(p_margin, 4);
+ limit[p_margin] = p_limit;
}
-int Camera2D::get_limit(Margin p_margin) const{
+int Camera2D::get_limit(Margin p_margin) const {
- ERR_FAIL_INDEX_V(p_margin,4,0);
+ ERR_FAIL_INDEX_V(p_margin, 4, 0);
return limit[p_margin];
-
}
void Camera2D::set_limit_smoothing_enabled(bool enable) {
@@ -408,34 +383,30 @@ void Camera2D::set_limit_smoothing_enabled(bool enable) {
_update_scroll();
}
-bool Camera2D::is_limit_smoothing_enabled() const{
+bool Camera2D::is_limit_smoothing_enabled() const {
return limit_smoothing_enabled;
}
-void Camera2D::set_drag_margin(Margin p_margin,float p_drag_margin) {
+void Camera2D::set_drag_margin(Margin p_margin, float p_drag_margin) {
- ERR_FAIL_INDEX(p_margin,4);
- drag_margin[p_margin]=p_drag_margin;
+ ERR_FAIL_INDEX(p_margin, 4);
+ drag_margin[p_margin] = p_drag_margin;
}
-float Camera2D::get_drag_margin(Margin p_margin) const{
+float Camera2D::get_drag_margin(Margin p_margin) const {
- ERR_FAIL_INDEX_V(p_margin,4,0);
+ ERR_FAIL_INDEX_V(p_margin, 4, 0);
return drag_margin[p_margin];
-
}
-
Vector2 Camera2D::get_camera_pos() const {
-
return camera_pos;
}
void Camera2D::force_update_scroll() {
-
_update_scroll();
}
@@ -447,25 +418,25 @@ void Camera2D::reset_smoothing() {
void Camera2D::align() {
- ERR_FAIL_COND( custom_viewport && !ObjectDB::get_instance(custom_viewport_id) );
+ ERR_FAIL_COND(custom_viewport && !ObjectDB::get_instance(custom_viewport_id));
Size2 screen_size = viewport->get_visible_rect().size;
Point2 current_camera_pos = get_global_transform().get_origin();
- if (anchor_mode==ANCHOR_MODE_DRAG_CENTER) {
- if (h_ofs<0) {
+ if (anchor_mode == ANCHOR_MODE_DRAG_CENTER) {
+ if (h_ofs < 0) {
camera_pos.x = current_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_RIGHT] * h_ofs;
} else {
camera_pos.x = current_camera_pos.x + screen_size.x * 0.5 * drag_margin[MARGIN_LEFT] * h_ofs;
}
- if (v_ofs<0) {
+ if (v_ofs < 0) {
camera_pos.y = current_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_TOP] * v_ofs;
} else {
camera_pos.y = current_camera_pos.y + screen_size.y * 0.5 * drag_margin[MARGIN_BOTTOM] * v_ofs;
}
- } else if (anchor_mode==ANCHOR_MODE_FIXED_TOP_LEFT){
+ } else if (anchor_mode == ANCHOR_MODE_FIXED_TOP_LEFT) {
- camera_pos=current_camera_pos;
+ camera_pos = current_camera_pos;
}
_update_scroll();
@@ -473,77 +444,73 @@ void Camera2D::align() {
void Camera2D::set_follow_smoothing(float p_speed) {
- smoothing=p_speed;
- if (smoothing>0 && !(is_inside_tree() && get_tree()->is_editor_hint()))
+ smoothing = p_speed;
+ if (smoothing > 0 && !(is_inside_tree() && get_tree()->is_editor_hint()))
set_fixed_process(true);
else
set_fixed_process(false);
}
-float Camera2D::get_follow_smoothing() const{
+float Camera2D::get_follow_smoothing() const {
return smoothing;
}
Point2 Camera2D::get_camera_screen_center() const {
- return camera_screen_center;
+ return camera_screen_center;
}
-
void Camera2D::set_h_drag_enabled(bool p_enabled) {
- h_drag_enabled=p_enabled;
+ h_drag_enabled = p_enabled;
}
-bool Camera2D::is_h_drag_enabled() const{
+bool Camera2D::is_h_drag_enabled() const {
- return h_drag_enabled;
+ return h_drag_enabled;
}
-void Camera2D::set_v_drag_enabled(bool p_enabled){
+void Camera2D::set_v_drag_enabled(bool p_enabled) {
- v_drag_enabled=p_enabled;
+ v_drag_enabled = p_enabled;
}
-bool Camera2D::is_v_drag_enabled() const{
+bool Camera2D::is_v_drag_enabled() const {
- return v_drag_enabled;
+ return v_drag_enabled;
}
void Camera2D::set_v_offset(float p_offset) {
- v_ofs=p_offset;
+ v_ofs = p_offset;
}
-float Camera2D::get_v_offset() const{
+float Camera2D::get_v_offset() const {
- return v_ofs;
+ return v_ofs;
}
-void Camera2D::set_h_offset(float p_offset){
+void Camera2D::set_h_offset(float p_offset) {
- h_ofs=p_offset;
+ h_ofs = p_offset;
}
-float Camera2D::get_h_offset() const{
+float Camera2D::get_h_offset() const {
- return h_ofs;
+ return h_ofs;
}
-
void Camera2D::_set_old_smoothing(float p_val) {
//compatibility
- if (p_val>0) {
- smoothing_enabled=true;
+ if (p_val > 0) {
+ smoothing_enabled = true;
set_follow_smoothing(p_val);
}
-
}
void Camera2D::set_enable_follow_smoothing(bool p_enabled) {
- smoothing_enabled=p_enabled;
-
+ smoothing_enabled = p_enabled;
}
bool Camera2D::is_follow_smoothing_enabled() const {
@@ -558,161 +525,154 @@ void Camera2D::set_custom_viewport(Node *p_viewport) {
remove_from_group(canvas_group_name);
}
- 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)
- viewport=custom_viewport;
+ viewport = custom_viewport;
else
- viewport=get_viewport();
+ viewport = get_viewport();
RID vp = viewport->get_viewport_rid();
- group_name = "__cameras_"+itos(vp.get_id());
- canvas_group_name ="__cameras_c"+itos(canvas.get_id());
+ group_name = "__cameras_" + itos(vp.get_id());
+ canvas_group_name = "__cameras_c" + itos(canvas.get_id());
add_to_group(group_name);
add_to_group(canvas_group_name);
}
-
}
-Node* Camera2D::get_custom_viewport() const {
+Node *Camera2D::get_custom_viewport() const {
return custom_viewport;
}
-
void Camera2D::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_offset","offset"),&Camera2D::set_offset);
- ClassDB::bind_method(D_METHOD("get_offset"),&Camera2D::get_offset);
+ ClassDB::bind_method(D_METHOD("set_offset", "offset"), &Camera2D::set_offset);
+ ClassDB::bind_method(D_METHOD("get_offset"), &Camera2D::get_offset);
- ClassDB::bind_method(D_METHOD("set_anchor_mode","anchor_mode"),&Camera2D::set_anchor_mode);
- ClassDB::bind_method(D_METHOD("get_anchor_mode"),&Camera2D::get_anchor_mode);
+ ClassDB::bind_method(D_METHOD("set_anchor_mode", "anchor_mode"), &Camera2D::set_anchor_mode);
+ ClassDB::bind_method(D_METHOD("get_anchor_mode"), &Camera2D::get_anchor_mode);
- ClassDB::bind_method(D_METHOD("set_rotating","rotating"),&Camera2D::set_rotating);
- ClassDB::bind_method(D_METHOD("is_rotating"),&Camera2D::is_rotating);
+ ClassDB::bind_method(D_METHOD("set_rotating", "rotating"), &Camera2D::set_rotating);
+ ClassDB::bind_method(D_METHOD("is_rotating"), &Camera2D::is_rotating);
- ClassDB::bind_method(D_METHOD("make_current"),&Camera2D::make_current);
- ClassDB::bind_method(D_METHOD("clear_current"),&Camera2D::clear_current);
- ClassDB::bind_method(D_METHOD("_make_current"),&Camera2D::_make_current);
+ ClassDB::bind_method(D_METHOD("make_current"), &Camera2D::make_current);
+ ClassDB::bind_method(D_METHOD("clear_current"), &Camera2D::clear_current);
+ ClassDB::bind_method(D_METHOD("_make_current"), &Camera2D::_make_current);
- ClassDB::bind_method(D_METHOD("_update_scroll"),&Camera2D::_update_scroll);
+ ClassDB::bind_method(D_METHOD("_update_scroll"), &Camera2D::_update_scroll);
- ClassDB::bind_method(D_METHOD("_set_current","current"),&Camera2D::_set_current);
- ClassDB::bind_method(D_METHOD("is_current"),&Camera2D::is_current);
+ ClassDB::bind_method(D_METHOD("_set_current", "current"), &Camera2D::_set_current);
+ ClassDB::bind_method(D_METHOD("is_current"), &Camera2D::is_current);
- ClassDB::bind_method(D_METHOD("set_limit","margin","limit"),&Camera2D::set_limit);
- ClassDB::bind_method(D_METHOD("get_limit","margin"),&Camera2D::get_limit);
+ ClassDB::bind_method(D_METHOD("set_limit", "margin", "limit"), &Camera2D::set_limit);
+ ClassDB::bind_method(D_METHOD("get_limit", "margin"), &Camera2D::get_limit);
- ClassDB::bind_method(D_METHOD("set_limit_smoothing_enabled","limit_smoothing_enabled"),&Camera2D::set_limit_smoothing_enabled);
- ClassDB::bind_method(D_METHOD("is_limit_smoothing_enabled"),&Camera2D::is_limit_smoothing_enabled);
+ ClassDB::bind_method(D_METHOD("set_limit_smoothing_enabled", "limit_smoothing_enabled"), &Camera2D::set_limit_smoothing_enabled);
+ ClassDB::bind_method(D_METHOD("is_limit_smoothing_enabled"), &Camera2D::is_limit_smoothing_enabled);
- ClassDB::bind_method(D_METHOD("set_v_drag_enabled","enabled"),&Camera2D::set_v_drag_enabled);
- ClassDB::bind_method(D_METHOD("is_v_drag_enabled"),&Camera2D::is_v_drag_enabled);
+ ClassDB::bind_method(D_METHOD("set_v_drag_enabled", "enabled"), &Camera2D::set_v_drag_enabled);
+ ClassDB::bind_method(D_METHOD("is_v_drag_enabled"), &Camera2D::is_v_drag_enabled);
- ClassDB::bind_method(D_METHOD("set_h_drag_enabled","enabled"),&Camera2D::set_h_drag_enabled);
- ClassDB::bind_method(D_METHOD("is_h_drag_enabled"),&Camera2D::is_h_drag_enabled);
+ ClassDB::bind_method(D_METHOD("set_h_drag_enabled", "enabled"), &Camera2D::set_h_drag_enabled);
+ ClassDB::bind_method(D_METHOD("is_h_drag_enabled"), &Camera2D::is_h_drag_enabled);
- ClassDB::bind_method(D_METHOD("set_v_offset","ofs"),&Camera2D::set_v_offset);
- ClassDB::bind_method(D_METHOD("get_v_offset"),&Camera2D::get_v_offset);
+ ClassDB::bind_method(D_METHOD("set_v_offset", "ofs"), &Camera2D::set_v_offset);
+ ClassDB::bind_method(D_METHOD("get_v_offset"), &Camera2D::get_v_offset);
- ClassDB::bind_method(D_METHOD("set_h_offset","ofs"),&Camera2D::set_h_offset);
- ClassDB::bind_method(D_METHOD("get_h_offset"),&Camera2D::get_h_offset);
+ ClassDB::bind_method(D_METHOD("set_h_offset", "ofs"), &Camera2D::set_h_offset);
+ ClassDB::bind_method(D_METHOD("get_h_offset"), &Camera2D::get_h_offset);
- ClassDB::bind_method(D_METHOD("set_drag_margin","margin","drag_margin"),&Camera2D::set_drag_margin);
- ClassDB::bind_method(D_METHOD("get_drag_margin","margin"),&Camera2D::get_drag_margin);
+ ClassDB::bind_method(D_METHOD("set_drag_margin", "margin", "drag_margin"), &Camera2D::set_drag_margin);
+ ClassDB::bind_method(D_METHOD("get_drag_margin", "margin"), &Camera2D::get_drag_margin);
- ClassDB::bind_method(D_METHOD("get_camera_pos"),&Camera2D::get_camera_pos);
- ClassDB::bind_method(D_METHOD("get_camera_screen_center"),&Camera2D::get_camera_screen_center);
+ ClassDB::bind_method(D_METHOD("get_camera_pos"), &Camera2D::get_camera_pos);
+ ClassDB::bind_method(D_METHOD("get_camera_screen_center"), &Camera2D::get_camera_screen_center);
- ClassDB::bind_method(D_METHOD("set_zoom","zoom"),&Camera2D::set_zoom);
- ClassDB::bind_method(D_METHOD("get_zoom"),&Camera2D::get_zoom);
+ ClassDB::bind_method(D_METHOD("set_zoom", "zoom"), &Camera2D::set_zoom);
+ ClassDB::bind_method(D_METHOD("get_zoom"), &Camera2D::get_zoom);
- ClassDB::bind_method(D_METHOD("set_custom_viewport","viewport:Viewport"),&Camera2D::set_custom_viewport);
- ClassDB::bind_method(D_METHOD("get_custom_viewport:Viewport"),&Camera2D::get_custom_viewport);
+ ClassDB::bind_method(D_METHOD("set_custom_viewport", "viewport:Viewport"), &Camera2D::set_custom_viewport);
+ ClassDB::bind_method(D_METHOD("get_custom_viewport:Viewport"), &Camera2D::get_custom_viewport);
- ClassDB::bind_method(D_METHOD("set_follow_smoothing","follow_smoothing"),&Camera2D::set_follow_smoothing);
- ClassDB::bind_method(D_METHOD("get_follow_smoothing"),&Camera2D::get_follow_smoothing);
+ ClassDB::bind_method(D_METHOD("set_follow_smoothing", "follow_smoothing"), &Camera2D::set_follow_smoothing);
+ ClassDB::bind_method(D_METHOD("get_follow_smoothing"), &Camera2D::get_follow_smoothing);
- ClassDB::bind_method(D_METHOD("set_enable_follow_smoothing","follow_smoothing"),&Camera2D::set_enable_follow_smoothing);
- ClassDB::bind_method(D_METHOD("is_follow_smoothing_enabled"),&Camera2D::is_follow_smoothing_enabled);
+ ClassDB::bind_method(D_METHOD("set_enable_follow_smoothing", "follow_smoothing"), &Camera2D::set_enable_follow_smoothing);
+ ClassDB::bind_method(D_METHOD("is_follow_smoothing_enabled"), &Camera2D::is_follow_smoothing_enabled);
- ClassDB::bind_method(D_METHOD("force_update_scroll"),&Camera2D::force_update_scroll);
- ClassDB::bind_method(D_METHOD("reset_smoothing"),&Camera2D::reset_smoothing);
- ClassDB::bind_method(D_METHOD("align"),&Camera2D::align);
+ ClassDB::bind_method(D_METHOD("force_update_scroll"), &Camera2D::force_update_scroll);
+ ClassDB::bind_method(D_METHOD("reset_smoothing"), &Camera2D::reset_smoothing);
+ ClassDB::bind_method(D_METHOD("align"), &Camera2D::align);
- ClassDB::bind_method(D_METHOD("_set_old_smoothing","follow_smoothing"),&Camera2D::_set_old_smoothing);
+ ClassDB::bind_method(D_METHOD("_set_old_smoothing", "follow_smoothing"), &Camera2D::_set_old_smoothing);
- ADD_PROPERTYNZ( PropertyInfo(Variant::VECTOR2,"offset"),"set_offset","get_offset");
- ADD_PROPERTY( PropertyInfo(Variant::INT,"anchor_mode",PROPERTY_HINT_ENUM,"Fixed TopLeft,Drag Center"),"set_anchor_mode","get_anchor_mode");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"rotating"),"set_rotating","is_rotating");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"current"),"_set_current","is_current");
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"zoom"),"set_zoom","get_zoom") ;
+ ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "offset"), "set_offset", "get_offset");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "anchor_mode", PROPERTY_HINT_ENUM, "Fixed TopLeft,Drag Center"), "set_anchor_mode", "get_anchor_mode");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "rotating"), "set_rotating", "is_rotating");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "current"), "_set_current", "is_current");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "zoom"), "set_zoom", "get_zoom");
- ADD_GROUP("Limit","limit_");
- ADD_PROPERTYI( PropertyInfo(Variant::INT,"limit_left"),"set_limit","get_limit",MARGIN_LEFT);
- ADD_PROPERTYI( PropertyInfo(Variant::INT,"limit_top"),"set_limit","get_limit",MARGIN_TOP);
- ADD_PROPERTYI( PropertyInfo(Variant::INT,"limit_right"),"set_limit","get_limit",MARGIN_RIGHT);
- ADD_PROPERTYI( PropertyInfo(Variant::INT,"limit_bottom"),"set_limit","get_limit",MARGIN_BOTTOM);
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"limit_smoothed"),"set_limit_smoothing_enabled","is_limit_smoothing_enabled") ;
+ ADD_GROUP("Limit", "limit_");
+ ADD_PROPERTYI(PropertyInfo(Variant::INT, "limit_left"), "set_limit", "get_limit", MARGIN_LEFT);
+ ADD_PROPERTYI(PropertyInfo(Variant::INT, "limit_top"), "set_limit", "get_limit", MARGIN_TOP);
+ ADD_PROPERTYI(PropertyInfo(Variant::INT, "limit_right"), "set_limit", "get_limit", MARGIN_RIGHT);
+ ADD_PROPERTYI(PropertyInfo(Variant::INT, "limit_bottom"), "set_limit", "get_limit", MARGIN_BOTTOM);
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "limit_smoothed"), "set_limit_smoothing_enabled", "is_limit_smoothing_enabled");
- ADD_GROUP("Draw Margin","draw_margin_");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"drag_margin_h_enabled"),"set_h_drag_enabled","is_h_drag_enabled") ;
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"drag_margin_v_enabled"),"set_v_drag_enabled","is_v_drag_enabled") ;
+ ADD_GROUP("Draw Margin", "draw_margin_");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "drag_margin_h_enabled"), "set_h_drag_enabled", "is_h_drag_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "drag_margin_v_enabled"), "set_v_drag_enabled", "is_v_drag_enabled");
- ADD_GROUP("Smoothing","smoothing_");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"smoothing_enabled"),"set_enable_follow_smoothing","is_follow_smoothing_enabled") ;
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"smoothing_speed"),"set_follow_smoothing","get_follow_smoothing") ;
+ ADD_GROUP("Smoothing", "smoothing_");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "smoothing_enabled"), "set_enable_follow_smoothing", "is_follow_smoothing_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "smoothing_speed"), "set_follow_smoothing", "get_follow_smoothing");
- ADD_GROUP("Drag Margin","drag_margin_");
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"drag_margin_left",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_drag_margin","get_drag_margin",MARGIN_LEFT);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"drag_margin_top",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_drag_margin","get_drag_margin",MARGIN_TOP);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"drag_margin_right",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_drag_margin","get_drag_margin",MARGIN_RIGHT);
- ADD_PROPERTYI( PropertyInfo(Variant::REAL,"drag_margin_bottom",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_drag_margin","get_drag_margin",MARGIN_BOTTOM);
-
-
- BIND_CONSTANT( ANCHOR_MODE_DRAG_CENTER );
- BIND_CONSTANT( ANCHOR_MODE_FIXED_TOP_LEFT );
+ ADD_GROUP("Drag Margin", "drag_margin_");
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "drag_margin_left", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_drag_margin", "get_drag_margin", MARGIN_LEFT);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "drag_margin_top", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_drag_margin", "get_drag_margin", MARGIN_TOP);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "drag_margin_right", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_drag_margin", "get_drag_margin", MARGIN_RIGHT);
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, "drag_margin_bottom", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_drag_margin", "get_drag_margin", MARGIN_BOTTOM);
+ BIND_CONSTANT(ANCHOR_MODE_DRAG_CENTER);
+ BIND_CONSTANT(ANCHOR_MODE_FIXED_TOP_LEFT);
}
Camera2D::Camera2D() {
-
-
- anchor_mode=ANCHOR_MODE_DRAG_CENTER;
- rotating=false;
- current=false;
- limit[MARGIN_LEFT]=-10000000;
- limit[MARGIN_TOP]=-10000000;
- limit[MARGIN_RIGHT]=10000000;
- limit[MARGIN_BOTTOM]=10000000;
-
- drag_margin[MARGIN_LEFT]=0.2;
- drag_margin[MARGIN_TOP]=0.2;
- drag_margin[MARGIN_RIGHT]=0.2;
- drag_margin[MARGIN_BOTTOM]=0.2;
- camera_pos=Vector2();
- first=true;
- smoothing_enabled=false;
- limit_smoothing_enabled=false;
- custom_viewport=NULL;
- custom_viewport_id=0;
-
- smoothing=5.0;
+ anchor_mode = ANCHOR_MODE_DRAG_CENTER;
+ rotating = false;
+ current = false;
+ limit[MARGIN_LEFT] = -10000000;
+ limit[MARGIN_TOP] = -10000000;
+ limit[MARGIN_RIGHT] = 10000000;
+ limit[MARGIN_BOTTOM] = 10000000;
+
+ drag_margin[MARGIN_LEFT] = 0.2;
+ drag_margin[MARGIN_TOP] = 0.2;
+ drag_margin[MARGIN_RIGHT] = 0.2;
+ drag_margin[MARGIN_BOTTOM] = 0.2;
+ camera_pos = Vector2();
+ first = true;
+ smoothing_enabled = false;
+ limit_smoothing_enabled = false;
+ custom_viewport = NULL;
+ custom_viewport_id = 0;
+
+ smoothing = 5.0;
zoom = Vector2(1, 1);
- h_drag_enabled=true;
- v_drag_enabled=true;
- h_ofs=0;
- v_ofs=0;
+ h_drag_enabled = true;
+ v_drag_enabled = true;
+ h_ofs = 0;
+ v_ofs = 0;
set_notify_transform(true);
-
}
diff --git a/scene/2d/camera_2d.h b/scene/2d/camera_2d.h
index 85d90b225a..44cdb5cd99 100644
--- a/scene/2d/camera_2d.h
+++ b/scene/2d/camera_2d.h
@@ -32,12 +32,11 @@
#include "scene/2d/node_2d.h"
#include "scene/main/viewport.h"
-
class Camera2D : public Node2D {
- GDCLASS( Camera2D, Node2D );
-public:
+ GDCLASS(Camera2D, Node2D);
+public:
enum AnchorMode {
ANCHOR_MODE_FIXED_TOP_LEFT,
ANCHOR_MODE_DRAG_CENTER
@@ -78,14 +77,14 @@ protected:
void _set_current(bool p_current);
void _set_old_smoothing(float p_enable);
-protected:
+protected:
virtual Transform2D get_camera_transform();
void _notification(int p_what);
static void _bind_methods();
-public:
- void set_offset(const Vector2& p_offset);
+public:
+ void set_offset(const Vector2 &p_offset);
Vector2 get_offset() const;
void set_anchor_mode(AnchorMode p_anchor_mode);
@@ -94,7 +93,7 @@ public:
void set_rotating(bool p_rotating);
bool is_rotating() const;
- void set_limit(Margin p_margin,int p_limit);
+ void set_limit(Margin p_margin, int p_limit);
int get_limit(Margin p_margin) const;
void set_limit_smoothing_enabled(bool enable);
@@ -106,7 +105,7 @@ public:
void set_v_drag_enabled(bool p_enabled);
bool is_v_drag_enabled() const;
- void set_drag_margin(Margin p_margin,float p_drag_margin);
+ void set_drag_margin(Margin p_margin, float p_drag_margin);
float get_drag_margin(Margin p_margin) const;
void set_v_offset(float p_offset);
@@ -125,13 +124,13 @@ public:
void clear_current();
bool is_current() const;
- void set_zoom(const Vector2& p_zoom);
+ void set_zoom(const Vector2 &p_zoom);
Vector2 get_zoom() const;
Point2 get_camera_screen_center() const;
void set_custom_viewport(Node *p_viewport);
- Node* get_custom_viewport() const;
+ Node *get_custom_viewport() const;
Vector2 get_camera_pos() const;
void force_update_scroll();
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp
index 4f7acf7f97..b52dd8d660 100644
--- a/scene/2d/canvas_item.cpp
+++ b/scene/2d/canvas_item.cpp
@@ -27,35 +27,34 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "canvas_item.h"
-#include "servers/visual_server.h"
-#include "scene/main/viewport.h"
-#include "scene/main/canvas_layer.h"
#include "message_queue.h"
-#include "scene/scene_string_names.h"
+#include "os/input.h"
+#include "scene/main/canvas_layer.h"
+#include "scene/main/viewport.h"
#include "scene/resources/font.h"
-#include "scene/resources/texture.h"
#include "scene/resources/style_box.h"
-#include "os/input.h"
+#include "scene/resources/texture.h"
+#include "scene/scene_string_names.h"
+#include "servers/visual_server.h"
-bool CanvasItemMaterial::_set(const StringName& p_name, const Variant& p_value) {
+bool CanvasItemMaterial::_set(const StringName &p_name, const Variant &p_value) {
- if (p_name==SceneStringNames::get_singleton()->shader_shader) {
+ if (p_name == SceneStringNames::get_singleton()->shader_shader) {
set_shader(p_value);
return true;
} else {
if (shader.is_valid()) {
-
StringName pr = shader->remap_param(p_name);
if (!pr) {
String n = p_name;
- if (n.find("param/")==0) { //backwards compatibility
- pr = n.substr(6,n.length());
+ if (n.find("param/") == 0) { //backwards compatibility
+ pr = n.substr(6, n.length());
}
}
if (pr) {
- VisualServer::get_singleton()->material_set_param(_get_material(),pr,p_value);
+ VisualServer::get_singleton()->material_set_param(_get_material(), pr, p_value);
return true;
}
}
@@ -64,12 +63,11 @@ bool CanvasItemMaterial::_set(const StringName& p_name, const Variant& p_value)
return false;
}
-bool CanvasItemMaterial::_get(const StringName& p_name,Variant &r_ret) const {
+bool CanvasItemMaterial::_get(const StringName &p_name, Variant &r_ret) const {
+ if (p_name == SceneStringNames::get_singleton()->shader_shader) {
- if (p_name==SceneStringNames::get_singleton()->shader_shader) {
-
- r_ret=get_shader();
+ r_ret = get_shader();
return true;
} else {
@@ -78,128 +76,103 @@ bool CanvasItemMaterial::_get(const StringName& p_name,Variant &r_ret) const {
StringName pr = shader->remap_param(p_name);
if (pr) {
- r_ret=VisualServer::get_singleton()->material_get_param(_get_material(),pr);
+ r_ret = VisualServer::get_singleton()->material_get_param(_get_material(), pr);
return true;
}
}
-
}
-
return false;
}
+void CanvasItemMaterial::_get_property_list(List<PropertyInfo> *p_list) const {
-void CanvasItemMaterial::_get_property_list( List<PropertyInfo> *p_list) const {
-
- p_list->push_back( PropertyInfo( Variant::OBJECT, "shader/shader", PROPERTY_HINT_RESOURCE_TYPE,"CanvasItemShader,CanvasItemShaderGraph" ) );
+ p_list->push_back(PropertyInfo(Variant::OBJECT, "shader/shader", PROPERTY_HINT_RESOURCE_TYPE, "CanvasItemShader,CanvasItemShaderGraph"));
if (!shader.is_null()) {
shader->get_param_list(p_list);
}
-
}
-void CanvasItemMaterial::set_shader(const Ref<Shader>& p_shader) {
+void CanvasItemMaterial::set_shader(const Ref<Shader> &p_shader) {
- ERR_FAIL_COND(p_shader.is_valid() && p_shader->get_mode()!=Shader::MODE_CANVAS_ITEM);
+ ERR_FAIL_COND(p_shader.is_valid() && p_shader->get_mode() != Shader::MODE_CANVAS_ITEM);
- shader=p_shader;
+ shader = p_shader;
RID rid;
if (shader.is_valid())
- rid=shader->get_rid();
+ rid = shader->get_rid();
- VS::get_singleton()->material_set_shader(_get_material(),rid);
+ VS::get_singleton()->material_set_shader(_get_material(), rid);
_change_notify(); //properties for shader exposed
emit_changed();
}
-Ref<Shader> CanvasItemMaterial::get_shader() const{
+Ref<Shader> CanvasItemMaterial::get_shader() const {
return shader;
}
-void CanvasItemMaterial::set_shader_param(const StringName& p_param,const Variant& p_value){
+void CanvasItemMaterial::set_shader_param(const StringName &p_param, const Variant &p_value) {
- VS::get_singleton()->material_set_param(_get_material(),p_param,p_value);
+ VS::get_singleton()->material_set_param(_get_material(), p_param, p_value);
}
-Variant CanvasItemMaterial::get_shader_param(const StringName& p_param) const{
+Variant CanvasItemMaterial::get_shader_param(const StringName &p_param) const {
- return VS::get_singleton()->material_get_param(_get_material(),p_param);
+ return VS::get_singleton()->material_get_param(_get_material(), p_param);
}
-
-
void CanvasItemMaterial::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_shader","shader:Shader"),&CanvasItemMaterial::set_shader);
- ClassDB::bind_method(D_METHOD("get_shader:Shader"),&CanvasItemMaterial::get_shader);
- ClassDB::bind_method(D_METHOD("set_shader_param","param","value"),&CanvasItemMaterial::set_shader_param);
- ClassDB::bind_method(D_METHOD("get_shader_param","param"),&CanvasItemMaterial::get_shader_param);
-
-
-
+ ClassDB::bind_method(D_METHOD("set_shader", "shader:Shader"), &CanvasItemMaterial::set_shader);
+ ClassDB::bind_method(D_METHOD("get_shader:Shader"), &CanvasItemMaterial::get_shader);
+ ClassDB::bind_method(D_METHOD("set_shader_param", "param", "value"), &CanvasItemMaterial::set_shader_param);
+ ClassDB::bind_method(D_METHOD("get_shader_param", "param"), &CanvasItemMaterial::get_shader_param);
}
-void CanvasItemMaterial::get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const {
+void CanvasItemMaterial::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
String f = p_function.operator String();
- if ((f=="get_shader_param" || f=="set_shader_param") && p_idx==0) {
+ if ((f == "get_shader_param" || f == "set_shader_param") && p_idx == 0) {
if (shader.is_valid()) {
List<PropertyInfo> pl;
shader->get_param_list(&pl);
- for (List<PropertyInfo>::Element *E=pl.front();E;E=E->next()) {
- r_options->push_back("\""+E->get().name.replace_first("shader_param/","")+"\"");
+ for (List<PropertyInfo>::Element *E = pl.front(); E; E = E->next()) {
+ r_options->push_back("\"" + E->get().name.replace_first("shader_param/", "") + "\"");
}
}
}
- Resource::get_argument_options(p_function,p_idx,r_options);
+ Resource::get_argument_options(p_function, p_idx, r_options);
}
CanvasItemMaterial::CanvasItemMaterial() {
-
-
-
}
-CanvasItemMaterial::~CanvasItemMaterial(){
-
-
+CanvasItemMaterial::~CanvasItemMaterial() {
}
-
-
-
-
-
-
-
///////////////////////////////////////////////////////////////////
-
-
bool CanvasItem::is_visible_in_tree() const {
if (!is_inside_tree())
return false;
- const CanvasItem *p=this;
+ const CanvasItem *p = this;
- while(p) {
+ while (p) {
if (!p->visible)
return false;
- p=p->get_parent_item();
+ p = p->get_parent_item();
}
-
return true;
}
-
void CanvasItem::_propagate_visibility_changed(bool p_visible) {
notification(NOTIFICATION_VISIBILITY_CHANGED);
@@ -210,16 +183,15 @@ void CanvasItem::_propagate_visibility_changed(bool p_visible) {
emit_signal(SceneStringNames::get_singleton()->hide);
_block();
- for(int i=0;i<get_child_count();i++) {
+ for (int i = 0; i < get_child_count(); i++) {
- CanvasItem *c=get_child(i)->cast_to<CanvasItem>();
+ CanvasItem *c = get_child(i)->cast_to<CanvasItem>();
if (c && c->visible) //should the toplevels stop propagation? i think so but..
c->_propagate_visibility_changed(p_visible);
}
_unblock();
-
}
void CanvasItem::show() {
@@ -227,8 +199,8 @@ void CanvasItem::show() {
if (visible)
return;
- visible=true;
- VisualServer::get_singleton()->canvas_item_set_visible(canvas_item,true);
+ visible = true;
+ VisualServer::get_singleton()->canvas_item_set_visible(canvas_item, true);
if (!is_inside_tree())
return;
@@ -237,14 +209,13 @@ void CanvasItem::show() {
_change_notify("visibility/visible");
}
-
void CanvasItem::hide() {
if (!visible)
return;
- visible=false;
- VisualServer::get_singleton()->canvas_item_set_visible(canvas_item,false);
+ visible = false;
+ VisualServer::get_singleton()->canvas_item_set_visible(canvas_item, false);
if (!is_inside_tree())
return;
@@ -255,35 +226,28 @@ void CanvasItem::hide() {
Variant CanvasItem::edit_get_state() const {
-
return Variant();
}
-void CanvasItem::edit_set_state(const Variant& p_state) {
-
-
+void CanvasItem::edit_set_state(const Variant &p_state) {
}
-void CanvasItem::edit_set_rect(const Rect2& p_edit_rect) {
+void CanvasItem::edit_set_rect(const Rect2 &p_edit_rect) {
//used by editors, implement at will
}
void CanvasItem::edit_rotate(float p_rot) {
-
-
}
Size2 CanvasItem::edit_get_minimum_size() const {
- return Size2(-1,-1); //no limit
+ return Size2(-1, -1); //no limit
}
void CanvasItem::_update_callback() {
-
-
if (!is_inside_tree()) {
- pending_update=false;
+ pending_update = false;
return;
}
@@ -292,33 +256,32 @@ void CanvasItem::_update_callback() {
if (is_visible_in_tree()) { //todo optimize this!!
if (first_draw) {
notification(NOTIFICATION_VISIBILITY_CHANGED);
- first_draw=false;
+ first_draw = false;
}
- drawing=true;
+ drawing = true;
notification(NOTIFICATION_DRAW);
emit_signal(SceneStringNames::get_singleton()->draw);
if (get_script_instance()) {
Variant::CallError err;
- get_script_instance()->call_multilevel_reversed(SceneStringNames::get_singleton()->_draw,NULL,0);
+ get_script_instance()->call_multilevel_reversed(SceneStringNames::get_singleton()->_draw, NULL, 0);
}
- drawing=false;
-
+ drawing = false;
}
//todo updating = false
- pending_update=false; // don't change to false until finished drawing (avoid recursive update)
+ pending_update = false; // don't change to false until finished drawing (avoid recursive update)
}
Transform2D CanvasItem::get_global_transform_with_canvas() const {
const CanvasItem *ci = this;
Transform2D xform;
- const CanvasItem *last_valid=NULL;
+ const CanvasItem *last_valid = NULL;
- while(ci) {
+ while (ci) {
- last_valid=ci;
+ last_valid = ci;
xform = ci->get_transform() * xform;
- ci=ci->get_parent_item();
+ ci = ci->get_parent_item();
}
if (last_valid->canvas_layer)
@@ -331,7 +294,6 @@ Transform2D CanvasItem::get_global_transform_with_canvas() const {
Transform2D CanvasItem::get_global_transform() const {
-
if (global_invalid) {
const CanvasItem *pi = get_parent_item();
@@ -340,11 +302,10 @@ Transform2D CanvasItem::get_global_transform() const {
else
global_transform = get_transform();
- global_invalid=false;
+ global_invalid = false;
}
return global_transform;
-
}
void CanvasItem::_toplevel_raise_self() {
@@ -353,40 +314,37 @@ void CanvasItem::_toplevel_raise_self() {
return;
if (canvas_layer)
- VisualServer::get_singleton()->canvas_item_set_draw_index(canvas_item,canvas_layer->get_sort_index());
+ VisualServer::get_singleton()->canvas_item_set_draw_index(canvas_item, canvas_layer->get_sort_index());
else
- VisualServer::get_singleton()->canvas_item_set_draw_index(canvas_item,get_viewport()->gui_get_canvas_sort_index());
-
-
+ VisualServer::get_singleton()->canvas_item_set_draw_index(canvas_item, get_viewport()->gui_get_canvas_sort_index());
}
-
void CanvasItem::_enter_canvas() {
if ((!get_parent() || !get_parent()->cast_to<CanvasItem>()) || toplevel) {
Node *n = this;
- canvas_layer=NULL;
+ canvas_layer = NULL;
- while(n) {
+ while (n) {
canvas_layer = n->cast_to<CanvasLayer>();
if (canvas_layer) {
break;
}
- n=n->get_parent();
+ n = n->get_parent();
}
RID canvas;
if (canvas_layer)
- canvas=canvas_layer->get_world_2d()->get_canvas();
+ canvas = canvas_layer->get_world_2d()->get_canvas();
else
- canvas=get_viewport()->find_world_2d()->get_canvas();
+ canvas = get_viewport()->find_world_2d()->get_canvas();
- VisualServer::get_singleton()->canvas_item_set_parent(canvas_item,canvas);
+ VisualServer::get_singleton()->canvas_item_set_parent(canvas_item, canvas);
- group = "root_canvas"+itos(canvas.get_id());
+ group = "root_canvas" + itos(canvas.get_id());
add_to_group(group);
if (canvas_layer)
@@ -394,44 +352,40 @@ void CanvasItem::_enter_canvas() {
else
get_viewport()->gui_reset_canvas_sort_index();
- get_tree()->call_group_flags(SceneTree::GROUP_CALL_UNIQUE,group,"_toplevel_raise_self");
+ get_tree()->call_group_flags(SceneTree::GROUP_CALL_UNIQUE, group, "_toplevel_raise_self");
} else {
CanvasItem *parent = get_parent_item();
- canvas_layer=parent->canvas_layer;
- VisualServer::get_singleton()->canvas_item_set_parent(canvas_item,parent->get_canvas_item());
- VisualServer::get_singleton()->canvas_item_set_draw_index(canvas_item,get_index());
+ canvas_layer = parent->canvas_layer;
+ VisualServer::get_singleton()->canvas_item_set_parent(canvas_item, parent->get_canvas_item());
+ VisualServer::get_singleton()->canvas_item_set_draw_index(canvas_item, get_index());
}
- pending_update=false;
+ pending_update = false;
update();
notification(NOTIFICATION_ENTER_CANVAS);
-
}
void CanvasItem::_exit_canvas() {
- notification(NOTIFICATION_EXIT_CANVAS,true); //reverse the notification
- VisualServer::get_singleton()->canvas_item_set_parent(canvas_item,RID());
- canvas_layer=NULL;
- group="";
-
+ notification(NOTIFICATION_EXIT_CANVAS, true); //reverse the notification
+ VisualServer::get_singleton()->canvas_item_set_parent(canvas_item, RID());
+ canvas_layer = NULL;
+ group = "";
}
-
void CanvasItem::_notification(int p_what) {
-
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
- first_draw=true;
+ first_draw = true;
if (get_parent()) {
CanvasItem *ci = get_parent()->cast_to<CanvasItem>();
if (ci)
- C=ci->children_items.push_back(this);
+ C = ci->children_items.push_back(this);
}
_enter_canvas();
if (!block_transform_notify && !xform_change.in_list()) {
@@ -443,15 +397,14 @@ void CanvasItem::_notification(int p_what) {
if (!is_inside_tree())
break;
- if (group!="") {
- get_tree()->call_group_flags(SceneTree::GROUP_CALL_UNIQUE,group,"_toplevel_raise_self");
+ if (group != "") {
+ get_tree()->call_group_flags(SceneTree::GROUP_CALL_UNIQUE, group, "_toplevel_raise_self");
} else {
CanvasItem *p = get_parent_item();
ERR_FAIL_COND(!p);
- VisualServer::get_singleton()->canvas_item_set_draw_index(canvas_item,get_index());
+ VisualServer::get_singleton()->canvas_item_set_draw_index(canvas_item, get_index());
}
-
} break;
case NOTIFICATION_EXIT_TREE: {
if (xform_change.in_list())
@@ -459,22 +412,20 @@ void CanvasItem::_notification(int p_what) {
_exit_canvas();
if (C) {
get_parent()->cast_to<CanvasItem>()->children_items.erase(C);
- C=NULL;
+ C = NULL;
}
- global_invalid=true;
+ global_invalid = true;
} break;
case NOTIFICATION_DRAW: {
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
-
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
emit_signal(SceneStringNames::get_singleton()->visibility_changed);
} break;
-
}
}
@@ -490,7 +441,6 @@ bool CanvasItem::is_visible() const {
return visible;
}
-
void CanvasItem::update() {
if (!is_inside_tree())
@@ -498,35 +448,33 @@ void CanvasItem::update() {
if (pending_update)
return;
- pending_update=true;
+ pending_update = true;
- MessageQueue::get_singleton()->push_call(this,"_update_callback");
+ MessageQueue::get_singleton()->push_call(this, "_update_callback");
}
-void CanvasItem::set_modulate(const Color& p_modulate) {
-
- modulate=p_modulate;
- VisualServer::get_singleton()->canvas_item_set_modulate(canvas_item,modulate);
+void CanvasItem::set_modulate(const Color &p_modulate) {
+ modulate = p_modulate;
+ VisualServer::get_singleton()->canvas_item_set_modulate(canvas_item, modulate);
}
Color CanvasItem::get_modulate() const {
return modulate;
}
-
void CanvasItem::set_as_toplevel(bool p_toplevel) {
- if (toplevel==p_toplevel)
+ if (toplevel == p_toplevel)
return;
if (!is_inside_tree()) {
- toplevel=p_toplevel;
+ toplevel = p_toplevel;
return;
}
_exit_canvas();
- toplevel=p_toplevel;
+ toplevel = p_toplevel;
_enter_canvas();
}
@@ -547,31 +495,27 @@ CanvasItem *CanvasItem::get_parent_item() const {
return parent->cast_to<CanvasItem>();
}
+void CanvasItem::set_self_modulate(const Color &p_self_modulate) {
-void CanvasItem::set_self_modulate(const Color& p_self_modulate) {
-
- self_modulate=p_self_modulate;
- VisualServer::get_singleton()->canvas_item_set_self_modulate(canvas_item,self_modulate);
-
+ self_modulate = p_self_modulate;
+ VisualServer::get_singleton()->canvas_item_set_self_modulate(canvas_item, self_modulate);
}
Color CanvasItem::get_self_modulate() const {
return self_modulate;
}
-
void CanvasItem::set_light_mask(int p_light_mask) {
- light_mask=p_light_mask;
- VS::get_singleton()->canvas_item_set_light_mask(canvas_item,p_light_mask);
+ light_mask = p_light_mask;
+ VS::get_singleton()->canvas_item_set_light_mask(canvas_item, p_light_mask);
}
-int CanvasItem::get_light_mask() const{
+int CanvasItem::get_light_mask() const {
return light_mask;
}
-
void CanvasItem::item_rect_changed(bool p_size_changed) {
if (p_size_changed)
@@ -579,40 +523,37 @@ void CanvasItem::item_rect_changed(bool p_size_changed) {
emit_signal(SceneStringNames::get_singleton()->item_rect_changed);
}
-
-void CanvasItem::draw_line(const Point2& p_from, const Point2& p_to,const Color& p_color,float p_width,bool p_antialiased) {
+void CanvasItem::draw_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, float p_width, bool p_antialiased) {
if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
ERR_FAIL();
}
- VisualServer::get_singleton()->canvas_item_add_line(canvas_item,p_from,p_to,p_color,p_width,p_antialiased);
+ VisualServer::get_singleton()->canvas_item_add_line(canvas_item, p_from, p_to, p_color, p_width, p_antialiased);
}
-void CanvasItem::draw_rect(const Rect2& p_rect, const Color& p_color) {
+void CanvasItem::draw_rect(const Rect2 &p_rect, const Color &p_color) {
if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
ERR_FAIL();
}
- VisualServer::get_singleton()->canvas_item_add_rect(canvas_item,p_rect,p_color);
-
+ VisualServer::get_singleton()->canvas_item_add_rect(canvas_item, p_rect, p_color);
}
-void CanvasItem::draw_circle(const Point2& p_pos, float p_radius, const Color& p_color) {
+void CanvasItem::draw_circle(const Point2 &p_pos, float p_radius, const Color &p_color) {
if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
ERR_FAIL();
}
- VisualServer::get_singleton()->canvas_item_add_circle(canvas_item,p_pos,p_radius,p_color);
-
+ VisualServer::get_singleton()->canvas_item_add_circle(canvas_item, p_pos, p_radius, p_color);
}
-void CanvasItem::draw_texture(const Ref<Texture>& p_texture,const Point2& p_pos,const Color& p_modulate) {
+void CanvasItem::draw_texture(const Ref<Texture> &p_texture, const Point2 &p_pos, const Color &p_modulate) {
if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
@@ -621,10 +562,10 @@ void CanvasItem::draw_texture(const Ref<Texture>& p_texture,const Point2& p_pos,
ERR_FAIL_COND(p_texture.is_null());
- p_texture->draw(canvas_item,p_pos,p_modulate);
+ p_texture->draw(canvas_item, p_pos, p_modulate);
}
-void CanvasItem::draw_texture_rect(const Ref<Texture>& p_texture,const Rect2& p_rect, bool p_tile,const Color& p_modulate, bool p_transpose) {
+void CanvasItem::draw_texture_rect(const Ref<Texture> &p_texture, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose) {
if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
@@ -632,20 +573,19 @@ void CanvasItem::draw_texture_rect(const Ref<Texture>& p_texture,const Rect2& p_
}
ERR_FAIL_COND(p_texture.is_null());
- p_texture->draw_rect(canvas_item,p_rect,p_tile,p_modulate,p_transpose);
-
+ p_texture->draw_rect(canvas_item, p_rect, p_tile, p_modulate, p_transpose);
}
-void CanvasItem::draw_texture_rect_region(const Ref<Texture>& p_texture,const Rect2& p_rect, const Rect2& p_src_rect,const Color& p_modulate, bool p_transpose) {
+void CanvasItem::draw_texture_rect_region(const Ref<Texture> &p_texture, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate, bool p_transpose) {
if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
ERR_FAIL();
}
ERR_FAIL_COND(p_texture.is_null());
- p_texture->draw_rect_region(canvas_item,p_rect,p_src_rect,p_modulate,p_transpose);
+ p_texture->draw_rect_region(canvas_item, p_rect, p_src_rect, p_modulate, p_transpose);
}
-void CanvasItem::draw_style_box(const Ref<StyleBox>& p_style_box,const Rect2& p_rect) {
+void CanvasItem::draw_style_box(const Ref<StyleBox> &p_style_box, const Rect2 &p_rect) {
if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
ERR_FAIL();
@@ -653,10 +593,9 @@ void CanvasItem::draw_style_box(const Ref<StyleBox>& p_style_box,const Rect2& p_
ERR_FAIL_COND(p_style_box.is_null());
- p_style_box->draw(canvas_item,p_rect);
-
+ p_style_box->draw(canvas_item, p_rect);
}
-void CanvasItem::draw_primitive(const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, Ref<Texture> p_texture,float p_width) {
+void CanvasItem::draw_primitive(const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs, Ref<Texture> p_texture, float p_width) {
if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
@@ -665,32 +604,31 @@ void CanvasItem::draw_primitive(const Vector<Point2>& p_points, const Vector<Col
RID rid = p_texture.is_valid() ? p_texture->get_rid() : RID();
- VisualServer::get_singleton()->canvas_item_add_primitive(canvas_item,p_points,p_colors,p_uvs,rid,p_width);
+ VisualServer::get_singleton()->canvas_item_add_primitive(canvas_item, p_points, p_colors, p_uvs, rid, p_width);
}
-void CanvasItem::draw_set_transform(const Point2& p_offset, float p_rot, const Size2& p_scale) {
+void CanvasItem::draw_set_transform(const Point2 &p_offset, float p_rot, const Size2 &p_scale) {
if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
ERR_FAIL();
}
- Transform2D xform(p_rot,p_offset);
+ Transform2D xform(p_rot, p_offset);
xform.scale_basis(p_scale);
- VisualServer::get_singleton()->canvas_item_add_set_transform(canvas_item,xform);
+ VisualServer::get_singleton()->canvas_item_add_set_transform(canvas_item, xform);
}
-void CanvasItem::draw_set_transform_matrix(const Transform2D& p_matrix) {
+void CanvasItem::draw_set_transform_matrix(const Transform2D &p_matrix) {
if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
ERR_FAIL();
}
- VisualServer::get_singleton()->canvas_item_add_set_transform(canvas_item,p_matrix);
-
+ VisualServer::get_singleton()->canvas_item_add_set_transform(canvas_item, p_matrix);
}
-void CanvasItem::draw_polygon(const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, Ref<Texture> p_texture) {
+void CanvasItem::draw_polygon(const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs, Ref<Texture> p_texture) {
if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
@@ -699,12 +637,10 @@ void CanvasItem::draw_polygon(const Vector<Point2>& p_points, const Vector<Color
RID rid = p_texture.is_valid() ? p_texture->get_rid() : RID();
- VisualServer::get_singleton()->canvas_item_add_polygon(canvas_item,p_points,p_colors,p_uvs,rid);
-
-
+ VisualServer::get_singleton()->canvas_item_add_polygon(canvas_item, p_points, p_colors, p_uvs, rid);
}
-void CanvasItem::draw_colored_polygon(const Vector<Point2>& p_points, const Color& p_color,const Vector<Point2>& p_uvs, Ref<Texture> p_texture) {
+void CanvasItem::draw_colored_polygon(const Vector<Point2> &p_points, const Color &p_color, const Vector<Point2> &p_uvs, Ref<Texture> p_texture) {
if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
@@ -715,10 +651,10 @@ void CanvasItem::draw_colored_polygon(const Vector<Point2>& p_points, const Colo
colors.push_back(p_color);
RID rid = p_texture.is_valid() ? p_texture->get_rid() : RID();
- VisualServer::get_singleton()->canvas_item_add_polygon(canvas_item,p_points,colors,p_uvs,rid);
+ VisualServer::get_singleton()->canvas_item_add_polygon(canvas_item, p_points, colors, p_uvs, rid);
}
-void CanvasItem::draw_string(const Ref<Font>& p_font,const Point2& p_pos, const String& p_text,const Color& p_modulate,int p_clip_w) {
+void CanvasItem::draw_string(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_text, const Color &p_modulate, int p_clip_w) {
if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
@@ -726,31 +662,28 @@ void CanvasItem::draw_string(const Ref<Font>& p_font,const Point2& p_pos, const
}
ERR_FAIL_COND(p_font.is_null());
- p_font->draw(canvas_item,p_pos,p_text,p_modulate,p_clip_w);
-
+ p_font->draw(canvas_item, p_pos, p_text, p_modulate, p_clip_w);
}
-float CanvasItem::draw_char(const Ref<Font>& p_font,const Point2& p_pos, const String& p_char,const String& p_next,const Color& p_modulate) {
+float CanvasItem::draw_char(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_char, const String &p_next, const Color &p_modulate) {
if (!drawing) {
ERR_EXPLAIN("Drawing is only allowed inside NOTIFICATION_DRAW, _draw() function or 'draw' signal.");
ERR_FAIL_V(0);
}
- ERR_FAIL_COND_V(p_char.length()!=1,0);
- ERR_FAIL_COND_V(p_font.is_null(),0);
-
- return p_font->draw_char(canvas_item,p_pos,p_char[0],p_next.c_str()[0],p_modulate);
+ ERR_FAIL_COND_V(p_char.length() != 1, 0);
+ ERR_FAIL_COND_V(p_font.is_null(), 0);
+ return p_font->draw_char(canvas_item, p_pos, p_char[0], p_next.c_str()[0], p_modulate);
}
-
void CanvasItem::_notify_transform(CanvasItem *p_node) {
if (/*p_node->xform_change.in_list() &&*/ p_node->global_invalid)
return; //nothing to do
- p_node->global_invalid=true;
+ p_node->global_invalid = true;
if (p_node->notify_transform && !p_node->xform_change.in_list()) {
if (!p_node->block_transform_notify) {
@@ -759,51 +692,46 @@ void CanvasItem::_notify_transform(CanvasItem *p_node) {
}
}
+ for (List<CanvasItem *>::Element *E = p_node->children_items.front(); E; E = E->next()) {
- for(List<CanvasItem*>::Element *E=p_node->children_items.front();E;E=E->next()) {
-
- CanvasItem* ci=E->get();
+ CanvasItem *ci = E->get();
if (ci->toplevel)
continue;
_notify_transform(ci);
}
}
-
Rect2 CanvasItem::get_viewport_rect() const {
- ERR_FAIL_COND_V(!is_inside_tree(),Rect2());
+ ERR_FAIL_COND_V(!is_inside_tree(), Rect2());
return get_viewport()->get_visible_rect();
}
RID CanvasItem::get_canvas() const {
- ERR_FAIL_COND_V(!is_inside_tree(),RID());
+ ERR_FAIL_COND_V(!is_inside_tree(), RID());
if (canvas_layer)
return canvas_layer->get_world_2d()->get_canvas();
else
return get_viewport()->find_world_2d()->get_canvas();
-
-
}
CanvasItem *CanvasItem::get_toplevel() const {
- CanvasItem *ci=const_cast<CanvasItem*>(this);
- while(!ci->toplevel && ci->get_parent() && ci->get_parent()->cast_to<CanvasItem>()) {
- ci=ci->get_parent()->cast_to<CanvasItem>();
+ CanvasItem *ci = const_cast<CanvasItem *>(this);
+ while (!ci->toplevel && ci->get_parent() && ci->get_parent()->cast_to<CanvasItem>()) {
+ ci = ci->get_parent()->cast_to<CanvasItem>();
}
return ci;
}
-
Ref<World2D> CanvasItem::get_world_2d() const {
- ERR_FAIL_COND_V(!is_inside_tree(),Ref<World2D>());
+ ERR_FAIL_COND_V(!is_inside_tree(), Ref<World2D>());
- CanvasItem *tl=get_toplevel();
+ CanvasItem *tl = get_toplevel();
if (tl->canvas_layer) {
return tl->canvas_layer->get_world_2d();
@@ -812,17 +740,16 @@ Ref<World2D> CanvasItem::get_world_2d() const {
} else {
return Ref<World2D>();
}
-
}
RID CanvasItem::get_viewport_rid() const {
- ERR_FAIL_COND_V(!is_inside_tree(),RID());
+ ERR_FAIL_COND_V(!is_inside_tree(), RID());
return get_viewport()->get_viewport_rid();
}
void CanvasItem::set_block_transform_notify(bool p_enable) {
- block_transform_notify=p_enable;
+ block_transform_notify = p_enable;
}
bool CanvasItem::is_block_transform_notify_enabled() const {
@@ -832,205 +759,196 @@ bool CanvasItem::is_block_transform_notify_enabled() const {
void CanvasItem::set_draw_behind_parent(bool p_enable) {
- if (behind==p_enable)
+ if (behind == p_enable)
return;
- behind=p_enable;
- VisualServer::get_singleton()->canvas_item_set_draw_behind_parent(canvas_item,behind);
-
+ behind = p_enable;
+ VisualServer::get_singleton()->canvas_item_set_draw_behind_parent(canvas_item, behind);
}
-bool CanvasItem::is_draw_behind_parent_enabled() const{
+bool CanvasItem::is_draw_behind_parent_enabled() const {
return behind;
}
-void CanvasItem::set_material(const Ref<CanvasItemMaterial>& p_material) {
-
+void CanvasItem::set_material(const Ref<CanvasItemMaterial> &p_material) {
- material=p_material;
+ material = p_material;
RID rid;
if (material.is_valid())
- rid=material->get_rid();
- VS::get_singleton()->canvas_item_set_material(canvas_item,rid);
+ rid = material->get_rid();
+ VS::get_singleton()->canvas_item_set_material(canvas_item, rid);
_change_notify(); //properties for material exposed
}
void CanvasItem::set_use_parent_material(bool p_use_parent_material) {
- use_parent_material=p_use_parent_material;
- VS::get_singleton()->canvas_item_set_use_parent_material(canvas_item,p_use_parent_material);
+ use_parent_material = p_use_parent_material;
+ VS::get_singleton()->canvas_item_set_use_parent_material(canvas_item, p_use_parent_material);
}
-bool CanvasItem::get_use_parent_material() const{
+bool CanvasItem::get_use_parent_material() const {
return use_parent_material;
}
-Ref<CanvasItemMaterial> CanvasItem::get_material() const{
+Ref<CanvasItemMaterial> CanvasItem::get_material() const {
return material;
}
-Vector2 CanvasItem::make_canvas_pos_local(const Vector2& screen_point) const {
+Vector2 CanvasItem::make_canvas_pos_local(const Vector2 &screen_point) const {
- ERR_FAIL_COND_V(!is_inside_tree(),screen_point);
+ ERR_FAIL_COND_V(!is_inside_tree(), screen_point);
- Transform2D local_matrix = (get_canvas_transform() *
- get_global_transform()).affine_inverse();
+ Transform2D local_matrix = (get_canvas_transform() *
+ get_global_transform())
+ .affine_inverse();
return local_matrix.xform(screen_point);
}
-InputEvent CanvasItem::make_input_local(const InputEvent& p_event) const {
-
- ERR_FAIL_COND_V(!is_inside_tree(),p_event);
+InputEvent CanvasItem::make_input_local(const InputEvent &p_event) const {
- return p_event.xform_by( (get_canvas_transform() * get_global_transform()).affine_inverse() );
+ ERR_FAIL_COND_V(!is_inside_tree(), p_event);
+ return p_event.xform_by((get_canvas_transform() * get_global_transform()).affine_inverse());
}
-
Vector2 CanvasItem::get_global_mouse_pos() const {
- ERR_FAIL_COND_V(!get_viewport(),Vector2());
- return get_canvas_transform().affine_inverse().xform( get_viewport()->get_mouse_pos() );
+ ERR_FAIL_COND_V(!get_viewport(), Vector2());
+ return get_canvas_transform().affine_inverse().xform(get_viewport()->get_mouse_pos());
}
-Vector2 CanvasItem::get_local_mouse_pos() const{
+Vector2 CanvasItem::get_local_mouse_pos() const {
- ERR_FAIL_COND_V(!get_viewport(),Vector2());
+ ERR_FAIL_COND_V(!get_viewport(), Vector2());
- return get_global_transform().affine_inverse().xform( get_global_mouse_pos() );
+ return get_global_transform().affine_inverse().xform(get_global_mouse_pos());
}
-
void CanvasItem::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_toplevel_raise_self"),&CanvasItem::_toplevel_raise_self);
- ClassDB::bind_method(D_METHOD("_update_callback"),&CanvasItem::_update_callback);
+ ClassDB::bind_method(D_METHOD("_toplevel_raise_self"), &CanvasItem::_toplevel_raise_self);
+ ClassDB::bind_method(D_METHOD("_update_callback"), &CanvasItem::_update_callback);
- ClassDB::bind_method(D_METHOD("edit_set_state","state"),&CanvasItem::edit_set_state);
- ClassDB::bind_method(D_METHOD("edit_get_state:Variant"),&CanvasItem::edit_get_state);
- ClassDB::bind_method(D_METHOD("edit_set_rect","rect"),&CanvasItem::edit_set_rect);
- ClassDB::bind_method(D_METHOD("edit_rotate","degrees"),&CanvasItem::edit_rotate);
+ ClassDB::bind_method(D_METHOD("edit_set_state", "state"), &CanvasItem::edit_set_state);
+ ClassDB::bind_method(D_METHOD("edit_get_state:Variant"), &CanvasItem::edit_get_state);
+ ClassDB::bind_method(D_METHOD("edit_set_rect", "rect"), &CanvasItem::edit_set_rect);
+ ClassDB::bind_method(D_METHOD("edit_rotate", "degrees"), &CanvasItem::edit_rotate);
- ClassDB::bind_method(D_METHOD("get_item_rect"),&CanvasItem::get_item_rect);
- ClassDB::bind_method(D_METHOD("get_item_and_children_rect"),&CanvasItem::get_item_and_children_rect);
+ ClassDB::bind_method(D_METHOD("get_item_rect"), &CanvasItem::get_item_rect);
+ ClassDB::bind_method(D_METHOD("get_item_and_children_rect"), &CanvasItem::get_item_and_children_rect);
//ClassDB::bind_method(D_METHOD("get_transform"),&CanvasItem::get_transform);
- ClassDB::bind_method(D_METHOD("get_canvas_item"),&CanvasItem::get_canvas_item);
+ ClassDB::bind_method(D_METHOD("get_canvas_item"), &CanvasItem::get_canvas_item);
- ClassDB::bind_method(D_METHOD("set_visible"),&CanvasItem::set_visible);
- ClassDB::bind_method(D_METHOD("is_visible"),&CanvasItem::is_visible);
- ClassDB::bind_method(D_METHOD("is_visible_in_tree"),&CanvasItem::is_visible_in_tree);
- ClassDB::bind_method(D_METHOD("show"),&CanvasItem::show);
- ClassDB::bind_method(D_METHOD("hide"),&CanvasItem::hide);
+ ClassDB::bind_method(D_METHOD("set_visible"), &CanvasItem::set_visible);
+ ClassDB::bind_method(D_METHOD("is_visible"), &CanvasItem::is_visible);
+ ClassDB::bind_method(D_METHOD("is_visible_in_tree"), &CanvasItem::is_visible_in_tree);
+ ClassDB::bind_method(D_METHOD("show"), &CanvasItem::show);
+ ClassDB::bind_method(D_METHOD("hide"), &CanvasItem::hide);
- ClassDB::bind_method(D_METHOD("update"),&CanvasItem::update);
+ ClassDB::bind_method(D_METHOD("update"), &CanvasItem::update);
- ClassDB::bind_method(D_METHOD("set_as_toplevel","enable"),&CanvasItem::set_as_toplevel);
- ClassDB::bind_method(D_METHOD("is_set_as_toplevel"),&CanvasItem::is_set_as_toplevel);
+ ClassDB::bind_method(D_METHOD("set_as_toplevel", "enable"), &CanvasItem::set_as_toplevel);
+ ClassDB::bind_method(D_METHOD("is_set_as_toplevel"), &CanvasItem::is_set_as_toplevel);
- ClassDB::bind_method(D_METHOD("set_light_mask","light_mask"),&CanvasItem::set_light_mask);
- ClassDB::bind_method(D_METHOD("get_light_mask"),&CanvasItem::get_light_mask);
+ ClassDB::bind_method(D_METHOD("set_light_mask", "light_mask"), &CanvasItem::set_light_mask);
+ ClassDB::bind_method(D_METHOD("get_light_mask"), &CanvasItem::get_light_mask);
- ClassDB::bind_method(D_METHOD("set_modulate","modulate"),&CanvasItem::set_modulate);
- ClassDB::bind_method(D_METHOD("get_modulate"),&CanvasItem::get_modulate);
- ClassDB::bind_method(D_METHOD("set_self_modulate","self_modulate"),&CanvasItem::set_self_modulate);
- ClassDB::bind_method(D_METHOD("get_self_modulate"),&CanvasItem::get_self_modulate);
+ ClassDB::bind_method(D_METHOD("set_modulate", "modulate"), &CanvasItem::set_modulate);
+ ClassDB::bind_method(D_METHOD("get_modulate"), &CanvasItem::get_modulate);
+ ClassDB::bind_method(D_METHOD("set_self_modulate", "self_modulate"), &CanvasItem::set_self_modulate);
+ ClassDB::bind_method(D_METHOD("get_self_modulate"), &CanvasItem::get_self_modulate);
- ClassDB::bind_method(D_METHOD("set_draw_behind_parent","enable"),&CanvasItem::set_draw_behind_parent);
- ClassDB::bind_method(D_METHOD("is_draw_behind_parent_enabled"),&CanvasItem::is_draw_behind_parent_enabled);
+ ClassDB::bind_method(D_METHOD("set_draw_behind_parent", "enable"), &CanvasItem::set_draw_behind_parent);
+ ClassDB::bind_method(D_METHOD("is_draw_behind_parent_enabled"), &CanvasItem::is_draw_behind_parent_enabled);
- ClassDB::bind_method(D_METHOD("_set_on_top","on_top"),&CanvasItem::_set_on_top);
- ClassDB::bind_method(D_METHOD("_is_on_top"),&CanvasItem::_is_on_top);
+ ClassDB::bind_method(D_METHOD("_set_on_top", "on_top"), &CanvasItem::_set_on_top);
+ ClassDB::bind_method(D_METHOD("_is_on_top"), &CanvasItem::_is_on_top);
//ClassDB::bind_method(D_METHOD("get_transform"),&CanvasItem::get_transform);
- ClassDB::bind_method(D_METHOD("draw_line","from","to","color","width","antialiased"),&CanvasItem::draw_line,DEFVAL(1.0),DEFVAL(false));
- ClassDB::bind_method(D_METHOD("draw_rect","rect","color"),&CanvasItem::draw_rect);
- ClassDB::bind_method(D_METHOD("draw_circle","pos","radius","color"),&CanvasItem::draw_circle);
- ClassDB::bind_method(D_METHOD("draw_texture","texture:Texture","pos","modulate"),&CanvasItem::draw_texture,DEFVAL(Color(1,1,1,1)));
- ClassDB::bind_method(D_METHOD("draw_texture_rect","texture:Texture","rect","tile","modulate","transpose"),&CanvasItem::draw_texture_rect,DEFVAL(Color(1,1,1)),DEFVAL(false));
- ClassDB::bind_method(D_METHOD("draw_texture_rect_region","texture:Texture","rect","src_rect","modulate","transpose"),&CanvasItem::draw_texture_rect_region,DEFVAL(Color(1,1,1)),DEFVAL(false));
- ClassDB::bind_method(D_METHOD("draw_style_box","style_box:StyleBox","rect"),&CanvasItem::draw_style_box);
- ClassDB::bind_method(D_METHOD("draw_primitive","points","colors","uvs","texture:Texture","width"),&CanvasItem::draw_primitive,DEFVAL(Variant()),DEFVAL(1.0));
- ClassDB::bind_method(D_METHOD("draw_polygon","points","colors","uvs","texture:Texture"),&CanvasItem::draw_polygon,DEFVAL(PoolVector2Array()),DEFVAL(Variant()));
- ClassDB::bind_method(D_METHOD("draw_colored_polygon","points","color","uvs","texture:Texture"),&CanvasItem::draw_colored_polygon,DEFVAL(PoolVector2Array()),DEFVAL(Variant()));
- ClassDB::bind_method(D_METHOD("draw_string","font:Font","pos","text","modulate","clip_w"),&CanvasItem::draw_string,DEFVAL(Color(1,1,1)),DEFVAL(-1));
- ClassDB::bind_method(D_METHOD("draw_char","font:Font","pos","char","next","modulate"),&CanvasItem::draw_char,DEFVAL(Color(1,1,1)));
-
- ClassDB::bind_method(D_METHOD("draw_set_transform","pos","rot","scale"),&CanvasItem::draw_set_transform);
- ClassDB::bind_method(D_METHOD("draw_set_transform_matrix","xform"),&CanvasItem::draw_set_transform_matrix);
- ClassDB::bind_method(D_METHOD("get_transform"),&CanvasItem::get_transform);
- ClassDB::bind_method(D_METHOD("get_global_transform"),&CanvasItem::get_global_transform);
- ClassDB::bind_method(D_METHOD("get_global_transform_with_canvas"),&CanvasItem::get_global_transform_with_canvas);
- ClassDB::bind_method(D_METHOD("get_viewport_transform"),&CanvasItem::get_viewport_transform);
- ClassDB::bind_method(D_METHOD("get_viewport_rect"),&CanvasItem::get_viewport_rect);
- ClassDB::bind_method(D_METHOD("get_canvas_transform"),&CanvasItem::get_canvas_transform);
- ClassDB::bind_method(D_METHOD("get_local_mouse_pos"),&CanvasItem::get_local_mouse_pos);
- ClassDB::bind_method(D_METHOD("get_global_mouse_pos"),&CanvasItem::get_global_mouse_pos);
- ClassDB::bind_method(D_METHOD("get_canvas"),&CanvasItem::get_canvas);
- ClassDB::bind_method(D_METHOD("get_world_2d"),&CanvasItem::get_world_2d);
+ ClassDB::bind_method(D_METHOD("draw_line", "from", "to", "color", "width", "antialiased"), &CanvasItem::draw_line, DEFVAL(1.0), DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("draw_rect", "rect", "color"), &CanvasItem::draw_rect);
+ ClassDB::bind_method(D_METHOD("draw_circle", "pos", "radius", "color"), &CanvasItem::draw_circle);
+ ClassDB::bind_method(D_METHOD("draw_texture", "texture:Texture", "pos", "modulate"), &CanvasItem::draw_texture, DEFVAL(Color(1, 1, 1, 1)));
+ ClassDB::bind_method(D_METHOD("draw_texture_rect", "texture:Texture", "rect", "tile", "modulate", "transpose"), &CanvasItem::draw_texture_rect, DEFVAL(Color(1, 1, 1)), DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("draw_texture_rect_region", "texture:Texture", "rect", "src_rect", "modulate", "transpose"), &CanvasItem::draw_texture_rect_region, DEFVAL(Color(1, 1, 1)), DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("draw_style_box", "style_box:StyleBox", "rect"), &CanvasItem::draw_style_box);
+ ClassDB::bind_method(D_METHOD("draw_primitive", "points", "colors", "uvs", "texture:Texture", "width"), &CanvasItem::draw_primitive, DEFVAL(Variant()), DEFVAL(1.0));
+ ClassDB::bind_method(D_METHOD("draw_polygon", "points", "colors", "uvs", "texture:Texture"), &CanvasItem::draw_polygon, DEFVAL(PoolVector2Array()), DEFVAL(Variant()));
+ ClassDB::bind_method(D_METHOD("draw_colored_polygon", "points", "color", "uvs", "texture:Texture"), &CanvasItem::draw_colored_polygon, DEFVAL(PoolVector2Array()), DEFVAL(Variant()));
+ ClassDB::bind_method(D_METHOD("draw_string", "font:Font", "pos", "text", "modulate", "clip_w"), &CanvasItem::draw_string, DEFVAL(Color(1, 1, 1)), DEFVAL(-1));
+ ClassDB::bind_method(D_METHOD("draw_char", "font:Font", "pos", "char", "next", "modulate"), &CanvasItem::draw_char, DEFVAL(Color(1, 1, 1)));
+
+ ClassDB::bind_method(D_METHOD("draw_set_transform", "pos", "rot", "scale"), &CanvasItem::draw_set_transform);
+ ClassDB::bind_method(D_METHOD("draw_set_transform_matrix", "xform"), &CanvasItem::draw_set_transform_matrix);
+ ClassDB::bind_method(D_METHOD("get_transform"), &CanvasItem::get_transform);
+ ClassDB::bind_method(D_METHOD("get_global_transform"), &CanvasItem::get_global_transform);
+ ClassDB::bind_method(D_METHOD("get_global_transform_with_canvas"), &CanvasItem::get_global_transform_with_canvas);
+ ClassDB::bind_method(D_METHOD("get_viewport_transform"), &CanvasItem::get_viewport_transform);
+ ClassDB::bind_method(D_METHOD("get_viewport_rect"), &CanvasItem::get_viewport_rect);
+ ClassDB::bind_method(D_METHOD("get_canvas_transform"), &CanvasItem::get_canvas_transform);
+ ClassDB::bind_method(D_METHOD("get_local_mouse_pos"), &CanvasItem::get_local_mouse_pos);
+ ClassDB::bind_method(D_METHOD("get_global_mouse_pos"), &CanvasItem::get_global_mouse_pos);
+ ClassDB::bind_method(D_METHOD("get_canvas"), &CanvasItem::get_canvas);
+ ClassDB::bind_method(D_METHOD("get_world_2d"), &CanvasItem::get_world_2d);
//ClassDB::bind_method(D_METHOD("get_viewport"),&CanvasItem::get_viewport);
- ClassDB::bind_method(D_METHOD("set_material","material:CanvasItemMaterial"),&CanvasItem::set_material);
- ClassDB::bind_method(D_METHOD("get_material:CanvasItemMaterial"),&CanvasItem::get_material);
+ ClassDB::bind_method(D_METHOD("set_material", "material:CanvasItemMaterial"), &CanvasItem::set_material);
+ ClassDB::bind_method(D_METHOD("get_material:CanvasItemMaterial"), &CanvasItem::get_material);
- ClassDB::bind_method(D_METHOD("set_use_parent_material","enable"),&CanvasItem::set_use_parent_material);
- ClassDB::bind_method(D_METHOD("get_use_parent_material"),&CanvasItem::get_use_parent_material);
+ ClassDB::bind_method(D_METHOD("set_use_parent_material", "enable"), &CanvasItem::set_use_parent_material);
+ ClassDB::bind_method(D_METHOD("get_use_parent_material"), &CanvasItem::get_use_parent_material);
- ClassDB::bind_method(D_METHOD("set_notify_local_transform","enable"),&CanvasItem::set_notify_local_transform);
- ClassDB::bind_method(D_METHOD("is_local_transform_notification_enabled"),&CanvasItem::is_local_transform_notification_enabled);
+ ClassDB::bind_method(D_METHOD("set_notify_local_transform", "enable"), &CanvasItem::set_notify_local_transform);
+ ClassDB::bind_method(D_METHOD("is_local_transform_notification_enabled"), &CanvasItem::is_local_transform_notification_enabled);
- ClassDB::bind_method(D_METHOD("set_notify_transform","enable"),&CanvasItem::set_notify_transform);
- ClassDB::bind_method(D_METHOD("is_transform_notification_enabled"),&CanvasItem::is_transform_notification_enabled);
+ ClassDB::bind_method(D_METHOD("set_notify_transform", "enable"), &CanvasItem::set_notify_transform);
+ ClassDB::bind_method(D_METHOD("is_transform_notification_enabled"), &CanvasItem::is_transform_notification_enabled);
- ClassDB::bind_method(D_METHOD("make_canvas_pos_local","screen_point"),
+ ClassDB::bind_method(D_METHOD("make_canvas_pos_local", "screen_point"),
&CanvasItem::make_canvas_pos_local);
- ClassDB::bind_method(D_METHOD("make_input_local","event"),&CanvasItem::make_input_local);
+ ClassDB::bind_method(D_METHOD("make_input_local", "event"), &CanvasItem::make_input_local);
BIND_VMETHOD(MethodInfo("_draw"));
- ADD_GROUP("Visibility","");
- ADD_PROPERTYNO( PropertyInfo(Variant::BOOL,"visible"), "set_visible","is_visible") ;
- ADD_PROPERTYNO( PropertyInfo(Variant::COLOR,"modulate"), "set_modulate","get_modulate") ;
- ADD_PROPERTYNO( PropertyInfo(Variant::COLOR,"self_modulate"), "set_self_modulate","get_self_modulate") ;
- ADD_PROPERTYNZ( PropertyInfo(Variant::BOOL,"show_behind_parent"), "set_draw_behind_parent","is_draw_behind_parent_enabled") ;
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"show_on_top",PROPERTY_HINT_NONE,"",0), "_set_on_top","_is_on_top") ; //compatibility
- ADD_PROPERTYNO( PropertyInfo(Variant::INT,"light_mask",PROPERTY_HINT_LAYERS_2D_RENDER), "set_light_mask","get_light_mask") ;
-
- ADD_GROUP("Material","");
- ADD_PROPERTYNZ( PropertyInfo(Variant::OBJECT,"material",PROPERTY_HINT_RESOURCE_TYPE, "CanvasItemMaterial"), "set_material","get_material") ;
- ADD_PROPERTYNZ( PropertyInfo(Variant::BOOL,"use_parent_material"), "set_use_parent_material","get_use_parent_material") ;
+ ADD_GROUP("Visibility", "");
+ ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "visible"), "set_visible", "is_visible");
+ ADD_PROPERTYNO(PropertyInfo(Variant::COLOR, "modulate"), "set_modulate", "get_modulate");
+ ADD_PROPERTYNO(PropertyInfo(Variant::COLOR, "self_modulate"), "set_self_modulate", "get_self_modulate");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "show_behind_parent"), "set_draw_behind_parent", "is_draw_behind_parent_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_on_top", PROPERTY_HINT_NONE, "", 0), "_set_on_top", "_is_on_top"); //compatibility
+ ADD_PROPERTYNO(PropertyInfo(Variant::INT, "light_mask", PROPERTY_HINT_LAYERS_2D_RENDER), "set_light_mask", "get_light_mask");
+
+ ADD_GROUP("Material", "");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "material", PROPERTY_HINT_RESOURCE_TYPE, "CanvasItemMaterial"), "set_material", "get_material");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "use_parent_material"), "set_use_parent_material", "get_use_parent_material");
//exporting these two things doesn't really make much sense i think
//ADD_PROPERTY( PropertyInfo(Variant::BOOL,"transform/toplevel"), "set_as_toplevel","is_set_as_toplevel") ;
//ADD_PROPERTY(PropertyInfo(Variant::BOOL,"transform/notify"),"set_transform_notify","is_transform_notify_enabled");
- ADD_SIGNAL( MethodInfo("draw") );
- ADD_SIGNAL( MethodInfo("visibility_changed") );
- ADD_SIGNAL( MethodInfo("hide") );
- ADD_SIGNAL( MethodInfo("item_rect_changed") );
-
-
-
- BIND_CONSTANT( BLEND_MODE_MIX );
- BIND_CONSTANT( BLEND_MODE_ADD );
- BIND_CONSTANT( BLEND_MODE_SUB );
- BIND_CONSTANT( BLEND_MODE_MUL );
- BIND_CONSTANT( BLEND_MODE_PREMULT_ALPHA );
-
-
- BIND_CONSTANT( NOTIFICATION_DRAW);
- BIND_CONSTANT( NOTIFICATION_VISIBILITY_CHANGED );
- BIND_CONSTANT( NOTIFICATION_ENTER_CANVAS );
- BIND_CONSTANT( NOTIFICATION_EXIT_CANVAS );
- BIND_CONSTANT( NOTIFICATION_TRANSFORM_CHANGED );
+ ADD_SIGNAL(MethodInfo("draw"));
+ ADD_SIGNAL(MethodInfo("visibility_changed"));
+ ADD_SIGNAL(MethodInfo("hide"));
+ ADD_SIGNAL(MethodInfo("item_rect_changed"));
+ BIND_CONSTANT(BLEND_MODE_MIX);
+ BIND_CONSTANT(BLEND_MODE_ADD);
+ BIND_CONSTANT(BLEND_MODE_SUB);
+ BIND_CONSTANT(BLEND_MODE_MUL);
+ BIND_CONSTANT(BLEND_MODE_PREMULT_ALPHA);
+ BIND_CONSTANT(NOTIFICATION_DRAW);
+ BIND_CONSTANT(NOTIFICATION_VISIBILITY_CHANGED);
+ BIND_CONSTANT(NOTIFICATION_ENTER_CANVAS);
+ BIND_CONSTANT(NOTIFICATION_EXIT_CANVAS);
+ BIND_CONSTANT(NOTIFICATION_TRANSFORM_CHANGED);
}
Transform2D CanvasItem::get_canvas_transform() const {
- ERR_FAIL_COND_V(!is_inside_tree(),Transform2D());
+ ERR_FAIL_COND_V(!is_inside_tree(), Transform2D());
if (canvas_layer)
return canvas_layer->get_transform();
@@ -1038,12 +956,11 @@ Transform2D CanvasItem::get_canvas_transform() const {
return get_parent()->cast_to<CanvasItem>()->get_canvas_transform();
else
return get_viewport()->get_canvas_transform();
-
}
Transform2D CanvasItem::get_viewport_transform() const {
- ERR_FAIL_COND_V(!is_inside_tree(),Transform2D());
+ ERR_FAIL_COND_V(!is_inside_tree(), Transform2D());
if (canvas_layer) {
@@ -1056,21 +973,18 @@ Transform2D CanvasItem::get_viewport_transform() const {
} else {
return get_viewport()->get_final_transform() * get_viewport()->get_canvas_transform();
}
-
}
-
void CanvasItem::set_notify_local_transform(bool p_enable) {
- notify_local_transform=p_enable;
+ notify_local_transform = p_enable;
}
bool CanvasItem::is_local_transform_notification_enabled() const {
return notify_local_transform;
}
-
void CanvasItem::set_notify_transform(bool p_enable) {
- notify_transform=p_enable;
+ notify_transform = p_enable;
}
bool CanvasItem::is_transform_notification_enabled() const {
@@ -1085,14 +999,12 @@ int CanvasItem::get_canvas_layer() const {
return 0;
}
-
Rect2 CanvasItem::get_item_and_children_rect() const {
Rect2 rect = get_item_rect();
-
- for(int i=0;i<get_child_count();i++) {
- CanvasItem *c=get_child(i)->cast_to<CanvasItem>();
+ for (int i = 0; i < get_child_count(); i++) {
+ CanvasItem *c = get_child(i)->cast_to<CanvasItem>();
if (c) {
Rect2 sir = c->get_transform().xform(c->get_item_and_children_rect());
rect = rect.merge(sir);
@@ -1102,29 +1014,28 @@ Rect2 CanvasItem::get_item_and_children_rect() const {
return rect;
}
-CanvasItem::CanvasItem() : xform_change(this) {
+CanvasItem::CanvasItem()
+ : xform_change(this) {
-
- canvas_item=VisualServer::get_singleton()->canvas_item_create();
- visible=true;
- pending_update=false;
- modulate=Color(1,1,1,1);
- self_modulate=Color(1,1,1,1);
- toplevel=false;
- first_draw=false;
- drawing=false;
- behind=false;
- block_transform_notify=false;
+ canvas_item = VisualServer::get_singleton()->canvas_item_create();
+ visible = true;
+ pending_update = false;
+ modulate = Color(1, 1, 1, 1);
+ self_modulate = Color(1, 1, 1, 1);
+ toplevel = false;
+ first_draw = false;
+ drawing = false;
+ behind = false;
+ block_transform_notify = false;
//viewport=NULL;
- canvas_layer=NULL;
- use_parent_material=false;
- global_invalid=true;
- notify_local_transform=false;
- notify_transform=false;
- light_mask=1;
-
- C=NULL;
-
+ canvas_layer = NULL;
+ use_parent_material = false;
+ global_invalid = true;
+ notify_local_transform = false;
+ notify_transform = false;
+ light_mask = 1;
+
+ C = NULL;
}
CanvasItem::~CanvasItem() {
diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h
index 9688b873c0..a188ce495a 100644
--- a/scene/2d/canvas_item.h
+++ b/scene/2d/canvas_item.h
@@ -30,10 +30,10 @@
#define CANVAS_ITEM_H
#include "scene/main/node.h"
-#include "scene/resources/texture.h"
#include "scene/main/scene_main_loop.h"
-#include "scene/resources/shader.h"
#include "scene/resources/material.h"
+#include "scene/resources/shader.h"
+#include "scene/resources/texture.h"
class CanvasLayer;
class Viewport;
@@ -43,8 +43,9 @@ class StyleBox;
class CanvasItemMaterial : public Material {
- GDCLASS(CanvasItemMaterial,Material);
+ GDCLASS(CanvasItemMaterial, Material);
Ref<Shader> shader;
+
public:
/*enum ShadingMode {
SHADING_NORMAL,
@@ -53,34 +54,30 @@ public:
};*/
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();
- 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;
public:
-
- void set_shader(const Ref<Shader>& p_shader);
+ void set_shader(const Ref<Shader> &p_shader);
Ref<Shader> get_shader() const;
- void set_shader_param(const StringName& p_param,const Variant& p_value);
- Variant get_shader_param(const StringName& p_param) const;
+ void set_shader_param(const StringName &p_param, const Variant &p_value);
+ Variant get_shader_param(const StringName &p_param) const;
CanvasItemMaterial();
~CanvasItemMaterial();
};
-
-
-
class CanvasItem : public Node {
- GDCLASS( CanvasItem, Node );
-public:
+ GDCLASS(CanvasItem, Node);
+public:
enum BlendMode {
BLEND_MODE_MIX, //default
@@ -91,20 +88,18 @@ public:
};
private:
-
mutable SelfList<Node> xform_change;
RID canvas_item;
String group;
-
CanvasLayer *canvas_layer;
Color modulate;
Color self_modulate;
- List<CanvasItem*> children_items;
- List<CanvasItem*>::Element *C;
+ List<CanvasItem *> children_items;
+ List<CanvasItem *>::Element *C;
int light_mask;
@@ -124,12 +119,10 @@ private:
mutable Transform2D global_transform;
mutable bool global_invalid;
-
void _toplevel_raise_self();
void _propagate_visibility_changed(bool p_visible);
-
void _update_callback();
void _enter_canvas();
@@ -141,32 +134,34 @@ private:
bool _is_on_top() const { return !is_draw_behind_parent_enabled(); }
protected:
+ _FORCE_INLINE_ void _notify_transform() {
+ if (!is_inside_tree()) return;
+ _notify_transform(this);
+ if (!block_transform_notify && notify_local_transform) notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED);
+ }
- _FORCE_INLINE_ void _notify_transform() { if (!is_inside_tree()) return; _notify_transform(this); if (!block_transform_notify && notify_local_transform) notification(NOTIFICATION_LOCAL_TRANSFORM_CHANGED); }
-
- void item_rect_changed(bool p_size_changed=true);
+ void item_rect_changed(bool p_size_changed = true);
void _notification(int p_what);
static void _bind_methods();
-public:
-
+public:
enum {
- NOTIFICATION_TRANSFORM_CHANGED=SceneTree::NOTIFICATION_TRANSFORM_CHANGED, //unique
- NOTIFICATION_DRAW=30,
- NOTIFICATION_VISIBILITY_CHANGED=31,
- NOTIFICATION_ENTER_CANVAS=32,
- NOTIFICATION_EXIT_CANVAS=33,
- NOTIFICATION_LOCAL_TRANSFORM_CHANGED=35,
- NOTIFICATION_WORLD_2D_CHANGED=36,
+ NOTIFICATION_TRANSFORM_CHANGED = SceneTree::NOTIFICATION_TRANSFORM_CHANGED, //unique
+ NOTIFICATION_DRAW = 30,
+ NOTIFICATION_VISIBILITY_CHANGED = 31,
+ NOTIFICATION_ENTER_CANVAS = 32,
+ NOTIFICATION_EXIT_CANVAS = 33,
+ NOTIFICATION_LOCAL_TRANSFORM_CHANGED = 35,
+ NOTIFICATION_WORLD_2D_CHANGED = 36,
};
/* EDITOR */
virtual Variant edit_get_state() const;
- virtual void edit_set_state(const Variant& p_state);
- virtual void edit_set_rect(const Rect2& p_edit_rect);
+ virtual void edit_set_state(const Variant &p_state);
+ virtual void edit_set_rect(const Rect2 &p_edit_rect);
virtual void edit_rotate(float p_rot);
virtual Size2 edit_get_minimum_size() const;
@@ -183,30 +178,30 @@ public:
virtual void set_light_mask(int p_light_mask);
int get_light_mask() const;
- void set_modulate(const Color& p_modulate);
+ void set_modulate(const Color &p_modulate);
Color get_modulate() const;
- void set_self_modulate(const Color& p_self_modulate);
+ void set_self_modulate(const Color &p_self_modulate);
Color get_self_modulate() const;
/* DRAWING API */
- void draw_line(const Point2& p_from, const Point2& p_to, const Color& p_color, float p_width=1.0, bool p_antialiased=false);
- void draw_rect(const Rect2& p_rect, const Color& p_color);
- void draw_circle(const Point2& p_pos, float p_radius, const Color& p_color);
- void draw_texture(const Ref<Texture>& p_texture, const Point2& p_pos, const Color &p_modulate=Color(1,1,1,1));
- void draw_texture_rect(const Ref<Texture>& p_texture, const Rect2& p_rect, bool p_tile=false,const Color& p_modulate=Color(1,1,1), bool p_transpose=false);
- void draw_texture_rect_region(const Ref<Texture>& p_texture,const Rect2& p_rect, const Rect2& p_src_rect,const Color& p_modulate=Color(1,1,1), bool p_transpose=false);
- void draw_style_box(const Ref<StyleBox>& p_style_box,const Rect2& p_rect);
- void draw_primitive(const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs, Ref<Texture> p_texture=Ref<Texture>(),float p_width=1);
- void draw_polygon(const Vector<Point2>& p_points, const Vector<Color>& p_colors,const Vector<Point2>& p_uvs=Vector<Point2>(), Ref<Texture> p_texture=Ref<Texture>());
- void draw_colored_polygon(const Vector<Point2>& p_points, const Color& p_color,const Vector<Point2>& p_uvs=Vector<Point2>(), Ref<Texture> p_texture=Ref<Texture>());
+ void draw_line(const Point2 &p_from, const Point2 &p_to, const Color &p_color, float p_width = 1.0, bool p_antialiased = false);
+ void draw_rect(const Rect2 &p_rect, const Color &p_color);
+ void draw_circle(const Point2 &p_pos, float p_radius, const Color &p_color);
+ void draw_texture(const Ref<Texture> &p_texture, const Point2 &p_pos, const Color &p_modulate = Color(1, 1, 1, 1));
+ void draw_texture_rect(const Ref<Texture> &p_texture, const Rect2 &p_rect, bool p_tile = false, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false);
+ void draw_texture_rect_region(const Ref<Texture> &p_texture, const Rect2 &p_rect, const Rect2 &p_src_rect, const Color &p_modulate = Color(1, 1, 1), bool p_transpose = false);
+ void draw_style_box(const Ref<StyleBox> &p_style_box, const Rect2 &p_rect);
+ void draw_primitive(const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs, Ref<Texture> p_texture = Ref<Texture>(), float p_width = 1);
+ void draw_polygon(const Vector<Point2> &p_points, const Vector<Color> &p_colors, const Vector<Point2> &p_uvs = Vector<Point2>(), Ref<Texture> p_texture = Ref<Texture>());
+ void draw_colored_polygon(const Vector<Point2> &p_points, const Color &p_color, const Vector<Point2> &p_uvs = Vector<Point2>(), Ref<Texture> p_texture = Ref<Texture>());
- void draw_string(const Ref<Font>& p_font, const Point2& p_pos, const String& p_text,const Color& p_modulate=Color(1,1,1),int p_clip_w=-1);
- float draw_char(const Ref<Font>& p_font,const Point2& p_pos, const String& p_char,const String& p_next="",const Color& p_modulate=Color(1,1,1));
+ void draw_string(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_text, const Color &p_modulate = Color(1, 1, 1), int p_clip_w = -1);
+ float draw_char(const Ref<Font> &p_font, const Point2 &p_pos, const String &p_char, const String &p_next = "", const Color &p_modulate = Color(1, 1, 1));
- void draw_set_transform(const Point2& p_offset, float p_rot, const Size2& p_scale);
- void draw_set_transform_matrix(const Transform2D& p_matrix);
+ void draw_set_transform(const Point2 &p_offset, float p_rot, const Size2 &p_scale);
+ void draw_set_transform_matrix(const Transform2D &p_matrix);
/* RECT / TRANSFORM */
@@ -218,8 +213,8 @@ public:
CanvasItem *get_parent_item() const;
- virtual Rect2 get_item_rect() const=0;
- virtual Transform2D get_transform() const=0;
+ virtual Rect2 get_item_rect() const = 0;
+ virtual Transform2D get_transform() const = 0;
virtual Transform2D get_global_transform() const;
virtual Transform2D get_global_transform_with_canvas() const;
@@ -232,7 +227,6 @@ public:
void set_block_transform_notify(bool p_enable);
bool is_block_transform_notify_enabled() const;
-
Transform2D get_canvas_transform() const;
Transform2D get_viewport_transform() const;
Rect2 get_viewport_rect() const;
@@ -240,14 +234,14 @@ public:
RID get_canvas() const;
Ref<World2D> get_world_2d() const;
- void set_material(const Ref<CanvasItemMaterial>& p_material);
+ void set_material(const Ref<CanvasItemMaterial> &p_material);
Ref<CanvasItemMaterial> get_material() const;
void set_use_parent_material(bool p_use_parent_material);
bool get_use_parent_material() const;
- InputEvent make_input_local(const InputEvent& pevent) const;
- Vector2 make_canvas_pos_local(const Vector2& screen_point) const;
+ InputEvent make_input_local(const InputEvent &pevent) const;
+ Vector2 make_canvas_pos_local(const Vector2 &screen_point) const;
Vector2 get_global_mouse_pos() const;
Vector2 get_local_mouse_pos() const;
@@ -264,6 +258,6 @@ public:
~CanvasItem();
};
-VARIANT_ENUM_CAST( CanvasItem::BlendMode );
+VARIANT_ENUM_CAST(CanvasItem::BlendMode);
#endif // CANVAS_ITEM_H
diff --git a/scene/2d/canvas_modulate.cpp b/scene/2d/canvas_modulate.cpp
index ecc11ea60f..a0e3061c85 100644
--- a/scene/2d/canvas_modulate.cpp
+++ b/scene/2d/canvas_modulate.cpp
@@ -28,52 +28,48 @@
/*************************************************************************/
#include "canvas_modulate.h"
-
void CanvasModulate::_notification(int p_what) {
- if (p_what==NOTIFICATION_ENTER_CANVAS) {
+ if (p_what == NOTIFICATION_ENTER_CANVAS) {
if (is_visible_in_tree()) {
- VS::get_singleton()->canvas_set_modulate(get_canvas(),color);
- add_to_group("_canvas_modulate_"+itos(get_canvas().get_id()));
+ VS::get_singleton()->canvas_set_modulate(get_canvas(), color);
+ add_to_group("_canvas_modulate_" + itos(get_canvas().get_id()));
}
-
-
- } else if (p_what==NOTIFICATION_EXIT_CANVAS) {
+ } else if (p_what == NOTIFICATION_EXIT_CANVAS) {
if (is_visible_in_tree()) {
- VS::get_singleton()->canvas_set_modulate(get_canvas(),Color(1,1,1,1));
- remove_from_group("_canvas_modulate_"+itos(get_canvas().get_id()));
+ VS::get_singleton()->canvas_set_modulate(get_canvas(), Color(1, 1, 1, 1));
+ remove_from_group("_canvas_modulate_" + itos(get_canvas().get_id()));
}
- } else if (p_what==NOTIFICATION_VISIBILITY_CHANGED) {
+ } else if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
if (is_visible_in_tree()) {
- VS::get_singleton()->canvas_set_modulate(get_canvas(),color);
- add_to_group("_canvas_modulate_"+itos(get_canvas().get_id()));
+ VS::get_singleton()->canvas_set_modulate(get_canvas(), color);
+ add_to_group("_canvas_modulate_" + itos(get_canvas().get_id()));
} else {
- VS::get_singleton()->canvas_set_modulate(get_canvas(),Color(1,1,1,1));
- remove_from_group("_canvas_modulate_"+itos(get_canvas().get_id()));
+ VS::get_singleton()->canvas_set_modulate(get_canvas(), Color(1, 1, 1, 1));
+ remove_from_group("_canvas_modulate_" + itos(get_canvas().get_id()));
}
update_configuration_warning();
}
}
-void CanvasModulate::_bind_methods(){
+void CanvasModulate::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_color","color"),&CanvasModulate::set_color);
- ClassDB::bind_method(D_METHOD("get_color"),&CanvasModulate::get_color);
+ ClassDB::bind_method(D_METHOD("set_color", "color"), &CanvasModulate::set_color);
+ ClassDB::bind_method(D_METHOD("get_color"), &CanvasModulate::get_color);
- ADD_PROPERTY(PropertyInfo(Variant::COLOR,"color"),"set_color","get_color");
+ ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color");
}
+void CanvasModulate::set_color(const Color &p_color) {
-void CanvasModulate::set_color(const Color& p_color){
-
- color=p_color;
+ color = p_color;
if (is_inside_tree()) {
- VS::get_singleton()->canvas_set_modulate(get_canvas(),color);
+ VS::get_singleton()->canvas_set_modulate(get_canvas(), color);
}
}
Color CanvasModulate::get_color() const {
@@ -86,23 +82,19 @@ String CanvasModulate::get_configuration_warning() const {
if (!is_visible_in_tree() || !is_inside_tree())
return String();
- List<Node*> nodes;
- get_tree()->get_nodes_in_group("_canvas_modulate_"+itos(get_canvas().get_id()),&nodes);
+ List<Node *> nodes;
+ get_tree()->get_nodes_in_group("_canvas_modulate_" + itos(get_canvas().get_id()), &nodes);
- if (nodes.size()>1) {
+ if (nodes.size() > 1) {
return TTR("Only one visible CanvasModulate is allowed per scene (or set of instanced scenes). The first created one will work, while the rest will be ignored.");
}
return String();
}
-CanvasModulate::CanvasModulate()
-{
- color=Color(1,1,1,1);
+CanvasModulate::CanvasModulate() {
+ color = Color(1, 1, 1, 1);
}
-CanvasModulate::~CanvasModulate()
-{
-
+CanvasModulate::~CanvasModulate() {
}
-
diff --git a/scene/2d/canvas_modulate.h b/scene/2d/canvas_modulate.h
index a0bb27b1c5..8e62b5ccb9 100644
--- a/scene/2d/canvas_modulate.h
+++ b/scene/2d/canvas_modulate.h
@@ -33,15 +33,16 @@
class CanvasModulate : public Node2D {
- GDCLASS(CanvasModulate,Node2D);
+ GDCLASS(CanvasModulate, Node2D);
Color color;
+
protected:
void _notification(int p_what);
static void _bind_methods();
-public:
- void set_color(const Color& p_color);
+public:
+ void set_color(const Color &p_color);
Color get_color() const;
String get_configuration_warning() const;
diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp
index f9e1cc0bd7..1242599d46 100644
--- a/scene/2d/collision_object_2d.cpp
+++ b/scene/2d/collision_object_2d.cpp
@@ -27,16 +27,16 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "collision_object_2d.h"
-#include "servers/physics_2d_server.h"
#include "scene/scene_string_names.h"
+#include "servers/physics_2d_server.h"
void CollisionObject2D::_update_shapes_from_children() {
shapes.clear();
- for(int i=0;i<get_child_count();i++) {
+ for (int i = 0; i < get_child_count(); i++) {
- Node* n = get_child(i);
- n->call("_add_to_collision_object",this);
+ Node *n = get_child(i);
+ n->call("_add_to_collision_object", this);
}
_update_shapes();
@@ -44,24 +44,24 @@ void CollisionObject2D::_update_shapes_from_children() {
void CollisionObject2D::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
if (area)
- Physics2DServer::get_singleton()->area_set_transform(rid,get_global_transform());
+ Physics2DServer::get_singleton()->area_set_transform(rid, get_global_transform());
else
- Physics2DServer::get_singleton()->body_set_state(rid,Physics2DServer::BODY_STATE_TRANSFORM,get_global_transform());
+ Physics2DServer::get_singleton()->body_set_state(rid, Physics2DServer::BODY_STATE_TRANSFORM, get_global_transform());
RID space = get_world_2d()->get_space();
if (area) {
- Physics2DServer::get_singleton()->area_set_space(rid,space);
+ Physics2DServer::get_singleton()->area_set_space(rid, space);
} else
- Physics2DServer::get_singleton()->body_set_space(rid,space);
+ Physics2DServer::get_singleton()->body_set_space(rid, space);
_update_pickable();
- //get space
+ //get space
}
case NOTIFICATION_VISIBILITY_CHANGED: {
@@ -71,17 +71,17 @@ void CollisionObject2D::_notification(int p_what) {
case NOTIFICATION_TRANSFORM_CHANGED: {
if (area)
- Physics2DServer::get_singleton()->area_set_transform(rid,get_global_transform());
+ Physics2DServer::get_singleton()->area_set_transform(rid, get_global_transform());
else
- Physics2DServer::get_singleton()->body_set_state(rid,Physics2DServer::BODY_STATE_TRANSFORM,get_global_transform());
+ Physics2DServer::get_singleton()->body_set_state(rid, Physics2DServer::BODY_STATE_TRANSFORM, get_global_transform());
} break;
case NOTIFICATION_EXIT_TREE: {
if (area) {
- Physics2DServer::get_singleton()->area_set_space(rid,RID());
+ Physics2DServer::get_singleton()->area_set_space(rid, RID());
} else
- Physics2DServer::get_singleton()->body_set_space(rid,RID());
+ Physics2DServer::get_singleton()->body_set_space(rid, RID());
} break;
}
@@ -97,84 +97,80 @@ void CollisionObject2D::_update_shapes() {
else
Physics2DServer::get_singleton()->body_clear_shapes(rid);
- for(int i=0;i<shapes.size();i++) {
+ for (int i = 0; i < shapes.size(); i++) {
if (shapes[i].shape.is_null())
continue;
if (area)
- Physics2DServer::get_singleton()->area_add_shape(rid,shapes[i].shape->get_rid(),shapes[i].xform);
+ Physics2DServer::get_singleton()->area_add_shape(rid, shapes[i].shape->get_rid(), shapes[i].xform);
else {
- Physics2DServer::get_singleton()->body_add_shape(rid,shapes[i].shape->get_rid(),shapes[i].xform);
+ Physics2DServer::get_singleton()->body_add_shape(rid, shapes[i].shape->get_rid(), shapes[i].xform);
if (shapes[i].trigger)
- Physics2DServer::get_singleton()->body_set_shape_as_trigger(rid,i,shapes[i].trigger);
+ Physics2DServer::get_singleton()->body_set_shape_as_trigger(rid, i, shapes[i].trigger);
}
}
}
-
-bool CollisionObject2D::_set(const StringName& p_name, const Variant& p_value) {
- String name=p_name;
+bool CollisionObject2D::_set(const StringName &p_name, const Variant &p_value) {
+ String name = p_name;
if (name.begins_with("shapes/")) {
- int idx=name.get_slicec('/',1).to_int();
- String what=name.get_slicec('/',2);
- if (what=="shape") {
- if (idx>=shapes.size())
+ int idx = name.get_slicec('/', 1).to_int();
+ String what = name.get_slicec('/', 2);
+ if (what == "shape") {
+ if (idx >= shapes.size())
add_shape(RefPtr(p_value));
else
- set_shape(idx,RefPtr(p_value));
- } else if (what=="transform")
- set_shape_transform(idx,p_value);
- else if (what=="trigger")
- set_shape_as_trigger(idx,p_value);
+ set_shape(idx, RefPtr(p_value));
+ } else if (what == "transform")
+ set_shape_transform(idx, p_value);
+ else if (what == "trigger")
+ set_shape_as_trigger(idx, p_value);
} else
return false;
return true;
-
-
}
-bool CollisionObject2D::_get(const StringName& p_name,Variant &r_ret) const {
+bool CollisionObject2D::_get(const StringName &p_name, Variant &r_ret) const {
- String name=p_name;
+ String name = p_name;
if (name.begins_with("shapes/")) {
- int idx=name.get_slicec('/',1).to_int();
- String what=name.get_slicec('/',2);
- if (what=="shape")
- r_ret= get_shape(idx);
- else if (what=="transform")
- r_ret= get_shape_transform(idx);
- else if (what=="trigger")
- r_ret= is_shape_set_as_trigger(idx);
+ int idx = name.get_slicec('/', 1).to_int();
+ String what = name.get_slicec('/', 2);
+ if (what == "shape")
+ r_ret = get_shape(idx);
+ else if (what == "transform")
+ r_ret = get_shape_transform(idx);
+ else if (what == "trigger")
+ r_ret = is_shape_set_as_trigger(idx);
} else
return false;
return true;
}
-void CollisionObject2D::_get_property_list( List<PropertyInfo> *p_list) const {
+void CollisionObject2D::_get_property_list(List<PropertyInfo> *p_list) const {
//p_list->push_back( PropertyInfo(Variant::INT,"shape_count",PROPERTY_HINT_RANGE,"0,256,1",PROPERTY_USAGE_NOEDITOR|PROPERTY_USAGE_NO_INSTANCE_STATE) );
- for(int i=0;i<shapes.size();i++) {
- String path="shapes/"+itos(i)+"/";
- p_list->push_back( PropertyInfo(Variant::OBJECT,path+"shape",PROPERTY_HINT_RESOURCE_TYPE,"Shape2D",PROPERTY_USAGE_NOEDITOR|PROPERTY_USAGE_NO_INSTANCE_STATE) );
- p_list->push_back( PropertyInfo(Variant::TRANSFORM,path+"transform",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR|PROPERTY_USAGE_NO_INSTANCE_STATE) );
- p_list->push_back( PropertyInfo(Variant::BOOL,path+"trigger",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR|PROPERTY_USAGE_NO_INSTANCE_STATE) );
+ for (int i = 0; i < shapes.size(); i++) {
+ String path = "shapes/" + itos(i) + "/";
+ p_list->push_back(PropertyInfo(Variant::OBJECT, path + "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape2D", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_NO_INSTANCE_STATE));
+ p_list->push_back(PropertyInfo(Variant::TRANSFORM, path + "transform", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_NO_INSTANCE_STATE));
+ p_list->push_back(PropertyInfo(Variant::BOOL, path + "trigger", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_NO_INSTANCE_STATE));
}
}
-
void CollisionObject2D::set_pickable(bool p_enabled) {
- if (pickable==p_enabled)
+ if (pickable == p_enabled)
return;
- pickable=p_enabled;
+ pickable = p_enabled;
_update_pickable();
}
@@ -183,12 +179,12 @@ bool CollisionObject2D::is_pickable() const {
return pickable;
}
-void CollisionObject2D::_input_event(Node *p_viewport, const InputEvent& p_input_event, int p_shape) {
+void CollisionObject2D::_input_event(Node *p_viewport, const InputEvent &p_input_event, int p_shape) {
if (get_script_instance()) {
- get_script_instance()->call(SceneStringNames::get_singleton()->_input_event,p_viewport,p_input_event,p_shape);
+ get_script_instance()->call(SceneStringNames::get_singleton()->_input_event, p_viewport, p_input_event, p_shape);
}
- emit_signal(SceneStringNames::get_singleton()->input_event,p_viewport,p_input_event,p_shape);
+ emit_signal(SceneStringNames::get_singleton()->input_event, p_viewport, p_input_event, p_shape);
}
void CollisionObject2D::_mouse_enter() {
@@ -199,14 +195,12 @@ void CollisionObject2D::_mouse_enter() {
emit_signal(SceneStringNames::get_singleton()->mouse_entered);
}
-
void CollisionObject2D::_mouse_exit() {
if (get_script_instance()) {
get_script_instance()->call(SceneStringNames::get_singleton()->_mouse_exit);
}
emit_signal(SceneStringNames::get_singleton()->mouse_exited);
-
}
void CollisionObject2D::_update_pickable() {
@@ -214,105 +208,99 @@ void CollisionObject2D::_update_pickable() {
return;
bool pickable = this->pickable && is_inside_tree() && is_visible_in_tree();
if (area)
- Physics2DServer::get_singleton()->area_set_pickable(rid,pickable);
+ Physics2DServer::get_singleton()->area_set_pickable(rid, pickable);
else
- Physics2DServer::get_singleton()->body_set_pickable(rid,pickable);
+ Physics2DServer::get_singleton()->body_set_pickable(rid, pickable);
}
void CollisionObject2D::_bind_methods() {
- ClassDB::bind_method(D_METHOD("add_shape","shape:Shape2D","transform"),&CollisionObject2D::add_shape,DEFVAL(Transform2D()));
- ClassDB::bind_method(D_METHOD("get_shape_count"),&CollisionObject2D::get_shape_count);
- ClassDB::bind_method(D_METHOD("set_shape","shape_idx","shape:Shape"),&CollisionObject2D::set_shape);
- ClassDB::bind_method(D_METHOD("set_shape_transform","shape_idx","transform"),&CollisionObject2D::set_shape_transform);
- ClassDB::bind_method(D_METHOD("set_shape_as_trigger","shape_idx","enable"),&CollisionObject2D::set_shape_as_trigger);
- ClassDB::bind_method(D_METHOD("get_shape:Shape2D","shape_idx"),&CollisionObject2D::get_shape);
- ClassDB::bind_method(D_METHOD("get_shape_transform","shape_idx"),&CollisionObject2D::get_shape_transform);
- ClassDB::bind_method(D_METHOD("is_shape_set_as_trigger","shape_idx"),&CollisionObject2D::is_shape_set_as_trigger);
- ClassDB::bind_method(D_METHOD("remove_shape","shape_idx"),&CollisionObject2D::remove_shape);
- ClassDB::bind_method(D_METHOD("clear_shapes"),&CollisionObject2D::clear_shapes);
- ClassDB::bind_method(D_METHOD("get_rid"),&CollisionObject2D::get_rid);
-
- ClassDB::bind_method(D_METHOD("set_pickable","enabled"),&CollisionObject2D::set_pickable);
- ClassDB::bind_method(D_METHOD("is_pickable"),&CollisionObject2D::is_pickable);
-
- BIND_VMETHOD( MethodInfo("_input_event",PropertyInfo(Variant::OBJECT,"viewport"),PropertyInfo(Variant::INPUT_EVENT,"event"),PropertyInfo(Variant::INT,"shape_idx")));
-
- ADD_SIGNAL( MethodInfo("input_event",PropertyInfo(Variant::OBJECT,"viewport"),PropertyInfo(Variant::INPUT_EVENT,"event"),PropertyInfo(Variant::INT,"shape_idx")));
- ADD_SIGNAL( MethodInfo("mouse_entered"));
- ADD_SIGNAL( MethodInfo("mouse_exited"));
-
- ADD_GROUP("Pickable","input_");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"input_pickable"),"set_pickable","is_pickable");
- ADD_GROUP("","");
-
+ ClassDB::bind_method(D_METHOD("add_shape", "shape:Shape2D", "transform"), &CollisionObject2D::add_shape, DEFVAL(Transform2D()));
+ ClassDB::bind_method(D_METHOD("get_shape_count"), &CollisionObject2D::get_shape_count);
+ ClassDB::bind_method(D_METHOD("set_shape", "shape_idx", "shape:Shape"), &CollisionObject2D::set_shape);
+ ClassDB::bind_method(D_METHOD("set_shape_transform", "shape_idx", "transform"), &CollisionObject2D::set_shape_transform);
+ ClassDB::bind_method(D_METHOD("set_shape_as_trigger", "shape_idx", "enable"), &CollisionObject2D::set_shape_as_trigger);
+ ClassDB::bind_method(D_METHOD("get_shape:Shape2D", "shape_idx"), &CollisionObject2D::get_shape);
+ ClassDB::bind_method(D_METHOD("get_shape_transform", "shape_idx"), &CollisionObject2D::get_shape_transform);
+ ClassDB::bind_method(D_METHOD("is_shape_set_as_trigger", "shape_idx"), &CollisionObject2D::is_shape_set_as_trigger);
+ ClassDB::bind_method(D_METHOD("remove_shape", "shape_idx"), &CollisionObject2D::remove_shape);
+ ClassDB::bind_method(D_METHOD("clear_shapes"), &CollisionObject2D::clear_shapes);
+ ClassDB::bind_method(D_METHOD("get_rid"), &CollisionObject2D::get_rid);
+
+ ClassDB::bind_method(D_METHOD("set_pickable", "enabled"), &CollisionObject2D::set_pickable);
+ ClassDB::bind_method(D_METHOD("is_pickable"), &CollisionObject2D::is_pickable);
+
+ BIND_VMETHOD(MethodInfo("_input_event", PropertyInfo(Variant::OBJECT, "viewport"), PropertyInfo(Variant::INPUT_EVENT, "event"), PropertyInfo(Variant::INT, "shape_idx")));
+
+ ADD_SIGNAL(MethodInfo("input_event", PropertyInfo(Variant::OBJECT, "viewport"), PropertyInfo(Variant::INPUT_EVENT, "event"), PropertyInfo(Variant::INT, "shape_idx")));
+ ADD_SIGNAL(MethodInfo("mouse_entered"));
+ ADD_SIGNAL(MethodInfo("mouse_exited"));
+
+ ADD_GROUP("Pickable", "input_");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "input_pickable"), "set_pickable", "is_pickable");
+ ADD_GROUP("", "");
}
-
-void CollisionObject2D::add_shape(const Ref<Shape2D>& p_shape, const Transform2D& p_transform) {
+void CollisionObject2D::add_shape(const Ref<Shape2D> &p_shape, const Transform2D &p_transform) {
ERR_FAIL_COND(p_shape.is_null());
ShapeData sdata;
- sdata.shape=p_shape;
- sdata.xform=p_transform;
- sdata.trigger=false;
+ sdata.shape = p_shape;
+ sdata.xform = p_transform;
+ sdata.trigger = false;
if (area)
- Physics2DServer::get_singleton()->area_add_shape(get_rid(),p_shape->get_rid(),p_transform);
+ Physics2DServer::get_singleton()->area_add_shape(get_rid(), p_shape->get_rid(), p_transform);
else
- Physics2DServer::get_singleton()->body_add_shape(get_rid(),p_shape->get_rid(),p_transform);
+ Physics2DServer::get_singleton()->body_add_shape(get_rid(), p_shape->get_rid(), p_transform);
shapes.push_back(sdata);
-
}
int CollisionObject2D::get_shape_count() const {
return shapes.size();
-
}
-void CollisionObject2D::set_shape(int p_shape_idx, const Ref<Shape2D>& p_shape) {
+void CollisionObject2D::set_shape(int p_shape_idx, const Ref<Shape2D> &p_shape) {
- ERR_FAIL_INDEX(p_shape_idx,shapes.size());
+ ERR_FAIL_INDEX(p_shape_idx, shapes.size());
ERR_FAIL_COND(p_shape.is_null());
- shapes[p_shape_idx].shape=p_shape;
+ shapes[p_shape_idx].shape = p_shape;
if (area)
- Physics2DServer::get_singleton()->area_set_shape(get_rid(),p_shape_idx,p_shape->get_rid());
+ Physics2DServer::get_singleton()->area_set_shape(get_rid(), p_shape_idx, p_shape->get_rid());
else
- Physics2DServer::get_singleton()->body_set_shape(get_rid(),p_shape_idx,p_shape->get_rid());
+ Physics2DServer::get_singleton()->body_set_shape(get_rid(), p_shape_idx, p_shape->get_rid());
//_update_shapes();
}
-void CollisionObject2D::set_shape_transform(int p_shape_idx, const Transform2D& p_transform) {
+void CollisionObject2D::set_shape_transform(int p_shape_idx, const Transform2D &p_transform) {
- ERR_FAIL_INDEX(p_shape_idx,shapes.size());
- shapes[p_shape_idx].xform=p_transform;
+ ERR_FAIL_INDEX(p_shape_idx, shapes.size());
+ shapes[p_shape_idx].xform = p_transform;
if (area)
- Physics2DServer::get_singleton()->area_set_shape_transform(get_rid(),p_shape_idx,p_transform);
+ Physics2DServer::get_singleton()->area_set_shape_transform(get_rid(), p_shape_idx, p_transform);
else
- Physics2DServer::get_singleton()->body_set_shape_transform(get_rid(),p_shape_idx,p_transform);
+ Physics2DServer::get_singleton()->body_set_shape_transform(get_rid(), p_shape_idx, p_transform);
//_update_shapes();
}
Ref<Shape2D> CollisionObject2D::get_shape(int p_shape_idx) const {
- ERR_FAIL_INDEX_V(p_shape_idx,shapes.size(),Ref<Shape2D>());
+ ERR_FAIL_INDEX_V(p_shape_idx, shapes.size(), Ref<Shape2D>());
return shapes[p_shape_idx].shape;
-
}
Transform2D CollisionObject2D::get_shape_transform(int p_shape_idx) const {
- ERR_FAIL_INDEX_V(p_shape_idx,shapes.size(),Transform2D());
+ ERR_FAIL_INDEX_V(p_shape_idx, shapes.size(), Transform2D());
return shapes[p_shape_idx].xform;
-
}
void CollisionObject2D::remove_shape(int p_shape_idx) {
- ERR_FAIL_INDEX(p_shape_idx,shapes.size());
+ ERR_FAIL_INDEX(p_shape_idx, shapes.size());
shapes.remove(p_shape_idx);
_update_shapes();
@@ -320,18 +308,17 @@ void CollisionObject2D::remove_shape(int p_shape_idx) {
void CollisionObject2D::set_shape_as_trigger(int p_shape_idx, bool p_trigger) {
- ERR_FAIL_INDEX(p_shape_idx,shapes.size());
- shapes[p_shape_idx].trigger=p_trigger;
+ ERR_FAIL_INDEX(p_shape_idx, shapes.size());
+ shapes[p_shape_idx].trigger = p_trigger;
if (!area && rid.is_valid()) {
- Physics2DServer::get_singleton()->body_set_shape_as_trigger(rid,p_shape_idx,p_trigger);
-
+ Physics2DServer::get_singleton()->body_set_shape_as_trigger(rid, p_shape_idx, p_trigger);
}
}
bool CollisionObject2D::is_shape_set_as_trigger(int p_shape_idx) const {
- ERR_FAIL_INDEX_V(p_shape_idx,shapes.size(),false);
+ ERR_FAIL_INDEX_V(p_shape_idx, shapes.size(), false);
return shapes[p_shape_idx].trigger;
}
@@ -342,32 +329,25 @@ void CollisionObject2D::clear_shapes() {
_update_shapes();
}
-
CollisionObject2D::CollisionObject2D(RID p_rid, bool p_area) {
- rid=p_rid;
- area=p_area;
- pickable=true;
+ rid = p_rid;
+ area = p_area;
+ pickable = true;
set_notify_transform(true);
if (p_area) {
- Physics2DServer::get_singleton()->area_attach_object_instance_ID(rid,get_instance_ID());
+ Physics2DServer::get_singleton()->area_attach_object_instance_ID(rid, get_instance_ID());
} else {
- Physics2DServer::get_singleton()->body_attach_object_instance_ID(rid,get_instance_ID());
+ Physics2DServer::get_singleton()->body_attach_object_instance_ID(rid, get_instance_ID());
}
-
-
}
-
CollisionObject2D::CollisionObject2D() {
-
//owner=
set_notify_transform(true);
-
-
}
CollisionObject2D::~CollisionObject2D() {
diff --git a/scene/2d/collision_object_2d.h b/scene/2d/collision_object_2d.h
index 429b4fafe6..e6ea0f42d3 100644
--- a/scene/2d/collision_object_2d.h
+++ b/scene/2d/collision_object_2d.h
@@ -34,7 +34,7 @@
class CollisionObject2D : public Node2D {
- GDCLASS( CollisionObject2D, Node2D );
+ GDCLASS(CollisionObject2D, Node2D);
bool area;
RID rid;
@@ -46,42 +46,38 @@ class CollisionObject2D : public Node2D {
bool trigger;
ShapeData() {
- trigger=false;
+ trigger = false;
}
};
-
Vector<ShapeData> shapes;
void _update_shapes();
-friend class CollisionShape2D;
-friend class CollisionPolygon2D;
+ friend class CollisionShape2D;
+ friend class CollisionPolygon2D;
void _update_shapes_from_children();
-protected:
+protected:
CollisionObject2D(RID p_rid, bool p_area);
void _notification(int p_what);
- 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();
void _update_pickable();
-friend class Viewport;
- void _input_event(Node *p_viewport, const InputEvent& p_input_event, int p_shape);
+ friend class Viewport;
+ void _input_event(Node *p_viewport, const InputEvent &p_input_event, int p_shape);
void _mouse_enter();
void _mouse_exit();
public:
-
-
-
- void add_shape(const Ref<Shape2D>& p_shape, const Transform2D& p_transform=Transform2D());
+ void add_shape(const Ref<Shape2D> &p_shape, const Transform2D &p_transform = Transform2D());
int get_shape_count() const;
- void set_shape(int p_shape_idx, const Ref<Shape2D>& p_shape);
- void set_shape_transform(int p_shape_idx, const Transform2D& p_transform);
+ void set_shape(int p_shape_idx, const Ref<Shape2D> &p_shape);
+ void set_shape_transform(int p_shape_idx, const Transform2D &p_transform);
Ref<Shape2D> get_shape(int p_shape_idx) const;
Transform2D get_shape_transform(int p_shape_idx) const;
void set_shape_as_trigger(int p_shape_idx, bool p_trigger);
diff --git a/scene/2d/collision_polygon_2d.cpp b/scene/2d/collision_polygon_2d.cpp
index 85241a79e0..abc044f10f 100644
--- a/scene/2d/collision_polygon_2d.cpp
+++ b/scene/2d/collision_polygon_2d.cpp
@@ -39,57 +39,54 @@ void CollisionPolygon2D::_add_to_collision_object(Object *p_obj) {
CollisionObject2D *co = p_obj->cast_to<CollisionObject2D>();
ERR_FAIL_COND(!co);
- if (polygon.size()==0)
+ if (polygon.size() == 0)
return;
- bool solids=build_mode==BUILD_SOLIDS;
+ bool solids = build_mode == BUILD_SOLIDS;
if (solids) {
//here comes the sun, lalalala
//decompose concave into multiple convex polygons and add them
- Vector< Vector<Vector2> > decomp = _decompose_in_convex();
- shape_from=co->get_shape_count();
- for(int i=0;i<decomp.size();i++) {
- Ref<ConvexPolygonShape2D> convex = memnew( ConvexPolygonShape2D );
+ Vector<Vector<Vector2> > decomp = _decompose_in_convex();
+ shape_from = co->get_shape_count();
+ for (int i = 0; i < decomp.size(); i++) {
+ Ref<ConvexPolygonShape2D> convex = memnew(ConvexPolygonShape2D);
convex->set_points(decomp[i]);
- co->add_shape(convex,get_transform());
+ co->add_shape(convex, get_transform());
if (trigger)
- co->set_shape_as_trigger(co->get_shape_count()-1,true);
-
+ co->set_shape_as_trigger(co->get_shape_count() - 1, true);
}
- shape_to=co->get_shape_count()-1;
- if (shape_to<shape_from) {
- shape_from=-1;
- shape_to=-1;
+ shape_to = co->get_shape_count() - 1;
+ if (shape_to < shape_from) {
+ shape_from = -1;
+ shape_to = -1;
}
} else {
- Ref<ConcavePolygonShape2D> concave = memnew( ConcavePolygonShape2D );
+ Ref<ConcavePolygonShape2D> concave = memnew(ConcavePolygonShape2D);
PoolVector<Vector2> segments;
- segments.resize(polygon.size()*2);
- PoolVector<Vector2>::Write w=segments.write();
+ segments.resize(polygon.size() * 2);
+ PoolVector<Vector2>::Write w = segments.write();
- for(int i=0;i<polygon.size();i++) {
- w[(i<<1)+0]=polygon[i];
- w[(i<<1)+1]=polygon[(i+1)%polygon.size()];
+ for (int i = 0; i < polygon.size(); i++) {
+ w[(i << 1) + 0] = polygon[i];
+ w[(i << 1) + 1] = polygon[(i + 1) % polygon.size()];
}
- w=PoolVector<Vector2>::Write();
+ w = PoolVector<Vector2>::Write();
concave->set_segments(segments);
- co->add_shape(concave,get_transform());
+ co->add_shape(concave, get_transform());
if (trigger)
- co->set_shape_as_trigger(co->get_shape_count()-1,true);
-
- shape_from=co->get_shape_count()-1;
- shape_to=co->get_shape_count()-1;
+ co->set_shape_as_trigger(co->get_shape_count() - 1, true);
+ shape_from = co->get_shape_count() - 1;
+ shape_to = co->get_shape_count() - 1;
}
-
//co->add_shape(shape,get_transform());
}
@@ -106,41 +103,41 @@ void CollisionPolygon2D::_update_parent() {
co->_update_shapes_from_children();
}
-Vector< Vector<Vector2> > CollisionPolygon2D::_decompose_in_convex() {
+Vector<Vector<Vector2> > CollisionPolygon2D::_decompose_in_convex() {
- Vector< Vector<Vector2> > decomp;
+ Vector<Vector<Vector2> > decomp;
#if 0
//fast but imprecise triangulator, gave us problems
decomp = Geometry::decompose_polygon(polygon);
#else
- List<TriangulatorPoly> in_poly,out_poly;
+ List<TriangulatorPoly> in_poly, out_poly;
TriangulatorPoly inp;
inp.Init(polygon.size());
- for(int i=0;i<polygon.size();i++) {
- inp.GetPoint(i)=polygon[i];
+ for (int i = 0; i < polygon.size(); i++) {
+ inp.GetPoint(i) = polygon[i];
}
inp.SetOrientation(TRIANGULATOR_CCW);
in_poly.push_back(inp);
TriangulatorPartition tpart;
- if (tpart.ConvexPartition_HM(&in_poly,&out_poly)==0) { //failed!
+ if (tpart.ConvexPartition_HM(&in_poly, &out_poly) == 0) { //failed!
ERR_PRINT("Convex decomposing failed!");
return decomp;
}
decomp.resize(out_poly.size());
- int idx=0;
+ int idx = 0;
- for(List<TriangulatorPoly>::Element*I = out_poly.front();I;I=I->next()) {
+ for (List<TriangulatorPoly>::Element *I = out_poly.front(); I; I = I->next()) {
- TriangulatorPoly& tp = I->get();
+ TriangulatorPoly &tp = I->get();
decomp[idx].resize(tp.GetNumPoints());
- for(int i=0;i<tp.GetNumPoints();i++) {
+ for (int i = 0; i < tp.GetNumPoints(); i++) {
- decomp[idx][i]=tp.GetPoint(i);
+ decomp[idx][i] = tp.GetPoint(i);
}
idx++;
@@ -153,20 +150,19 @@ Vector< Vector<Vector2> > CollisionPolygon2D::_decompose_in_convex() {
void CollisionPolygon2D::_notification(int p_what) {
-
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
- unparenting=false;
- can_update_body=get_tree()->is_editor_hint();
+ unparenting = false;
+ can_update_body = get_tree()->is_editor_hint();
if (!get_tree()->is_editor_hint()) {
//display above all else
set_z_as_relative(false);
- set_z(VS::CANVAS_ITEM_Z_MAX-1);
+ set_z(VS::CANVAS_ITEM_Z_MAX - 1);
}
} break;
case NOTIFICATION_EXIT_TREE: {
- can_update_body=false;
+ can_update_body = false;
} break;
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
@@ -174,14 +170,13 @@ void CollisionPolygon2D::_notification(int p_what) {
break;
if (can_update_body) {
_update_parent();
- } else if (shape_from>=0 && shape_to>=0) {
+ } else if (shape_from >= 0 && shape_to >= 0) {
CollisionObject2D *co = get_parent()->cast_to<CollisionObject2D>();
- for(int i=shape_from;i<=shape_to;i++) {
- co->set_shape_transform(i,get_transform());
+ for (int i = shape_from; i <= shape_to; i++) {
+ co->set_shape_transform(i, get_transform());
}
}
-
} break;
case NOTIFICATION_DRAW: {
@@ -190,55 +185,52 @@ void CollisionPolygon2D::_notification(int p_what) {
break;
}
-
- for(int i=0;i<polygon.size();i++) {
+ for (int i = 0; i < polygon.size(); i++) {
Vector2 p = polygon[i];
- Vector2 n = polygon[(i+1)%polygon.size()];
- draw_line(p,n,Color(0.9,0.2,0.0,0.8),3);
+ Vector2 n = polygon[(i + 1) % polygon.size()];
+ draw_line(p, n, Color(0.9, 0.2, 0.0, 0.8), 3);
}
#define DEBUG_DECOMPOSE
-#if defined(TOOLS_ENABLED) && defined (DEBUG_DECOMPOSE)
+#if defined(TOOLS_ENABLED) && defined(DEBUG_DECOMPOSE)
- Vector< Vector<Vector2> > decomp = _decompose_in_convex();
+ Vector<Vector<Vector2> > decomp = _decompose_in_convex();
- Color c(0.4,0.9,0.1);
- for(int i=0;i<decomp.size();i++) {
+ Color c(0.4, 0.9, 0.1);
+ for (int i = 0; i < decomp.size(); i++) {
- c.set_hsv( Math::fmod(c.get_h() + 0.738,1),c.get_s(),c.get_v(),0.5);
- draw_colored_polygon(decomp[i],c);
+ c.set_hsv(Math::fmod(c.get_h() + 0.738, 1), c.get_s(), c.get_v(), 0.5);
+ draw_colored_polygon(decomp[i], c);
}
#else
- draw_colored_polygon(polygon,get_tree()->get_debug_collisions_color());
+ draw_colored_polygon(polygon, get_tree()->get_debug_collisions_color());
#endif
-
} break;
case NOTIFICATION_UNPARENTED: {
unparenting = true;
_update_parent();
} break;
-
}
}
-void CollisionPolygon2D::set_polygon(const Vector<Point2>& p_polygon) {
+void CollisionPolygon2D::set_polygon(const Vector<Point2> &p_polygon) {
- polygon=p_polygon;
+ polygon = p_polygon;
if (can_update_body) {
- for(int i=0;i<polygon.size();i++) {
- if (i==0)
- aabb=Rect2(polygon[i],Size2());
+ for (int i = 0; i < polygon.size(); i++) {
+ if (i == 0)
+ aabb = Rect2(polygon[i], Size2());
else
aabb.expand_to(polygon[i]);
}
- if (aabb==Rect2()) {
+ if (aabb == Rect2()) {
- aabb=Rect2(-10,-10,20,20);
+ aabb = Rect2(-10, -10, 20, 20);
} else {
- aabb.pos-=aabb.size*0.3;
- aabb.size+=aabb.size*0.6;
+ aabb.pos -= aabb.size * 0.3;
+ aabb.size += aabb.size * 0.6;
}
_update_parent();
}
@@ -253,12 +245,12 @@ Vector<Point2> CollisionPolygon2D::get_polygon() const {
void CollisionPolygon2D::set_build_mode(BuildMode p_mode) {
- ERR_FAIL_INDEX(p_mode,2);
- build_mode=p_mode;
+ ERR_FAIL_INDEX(p_mode, 2);
+ build_mode = p_mode;
_update_parent();
}
-CollisionPolygon2D::BuildMode CollisionPolygon2D::get_build_mode() const{
+CollisionPolygon2D::BuildMode CollisionPolygon2D::get_build_mode() const {
return build_mode;
}
@@ -270,32 +262,30 @@ Rect2 CollisionPolygon2D::get_item_rect() const {
void CollisionPolygon2D::set_trigger(bool p_trigger) {
- trigger=p_trigger;
+ trigger = p_trigger;
_update_parent();
- if (!can_update_body && is_inside_tree() && shape_from>=0 && shape_to>=0) {
+ if (!can_update_body && is_inside_tree() && shape_from >= 0 && shape_to >= 0) {
CollisionObject2D *co = get_parent()->cast_to<CollisionObject2D>();
- for(int i=shape_from;i<=shape_to;i++) {
- co->set_shape_as_trigger(i,p_trigger);
+ for (int i = shape_from; i <= shape_to; i++) {
+ co->set_shape_as_trigger(i, p_trigger);
}
-
}
}
-bool CollisionPolygon2D::is_trigger() const{
+bool CollisionPolygon2D::is_trigger() const {
return trigger;
}
+void CollisionPolygon2D::_set_shape_range(const Vector2 &p_range) {
-void CollisionPolygon2D::_set_shape_range(const Vector2& p_range) {
-
- shape_from=p_range.x;
- shape_to=p_range.y;
+ shape_from = p_range.x;
+ shape_to = p_range.y;
}
Vector2 CollisionPolygon2D::_get_shape_range() const {
- return Vector2(shape_from,shape_to);
+ return Vector2(shape_from, shape_to);
}
String CollisionPolygon2D::get_configuration_warning() const {
@@ -306,7 +296,6 @@ String CollisionPolygon2D::get_configuration_warning() const {
if (polygon.empty()) {
return TTR("An empty CollisionPolygon2D has no effect on collision.");
-
}
return String();
@@ -314,38 +303,36 @@ String CollisionPolygon2D::get_configuration_warning() const {
void CollisionPolygon2D::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_add_to_collision_object"),&CollisionPolygon2D::_add_to_collision_object);
- ClassDB::bind_method(D_METHOD("set_polygon","polygon"),&CollisionPolygon2D::set_polygon);
- ClassDB::bind_method(D_METHOD("get_polygon"),&CollisionPolygon2D::get_polygon);
-
- ClassDB::bind_method(D_METHOD("set_build_mode","build_mode"),&CollisionPolygon2D::set_build_mode);
- ClassDB::bind_method(D_METHOD("get_build_mode"),&CollisionPolygon2D::get_build_mode);
+ ClassDB::bind_method(D_METHOD("_add_to_collision_object"), &CollisionPolygon2D::_add_to_collision_object);
+ ClassDB::bind_method(D_METHOD("set_polygon", "polygon"), &CollisionPolygon2D::set_polygon);
+ ClassDB::bind_method(D_METHOD("get_polygon"), &CollisionPolygon2D::get_polygon);
- ClassDB::bind_method(D_METHOD("set_trigger","trigger"),&CollisionPolygon2D::set_trigger);
- ClassDB::bind_method(D_METHOD("is_trigger"),&CollisionPolygon2D::is_trigger);
+ ClassDB::bind_method(D_METHOD("set_build_mode", "build_mode"), &CollisionPolygon2D::set_build_mode);
+ ClassDB::bind_method(D_METHOD("get_build_mode"), &CollisionPolygon2D::get_build_mode);
- ClassDB::bind_method(D_METHOD("_set_shape_range","shape_range"),&CollisionPolygon2D::_set_shape_range);
- ClassDB::bind_method(D_METHOD("_get_shape_range"),&CollisionPolygon2D::_get_shape_range);
+ ClassDB::bind_method(D_METHOD("set_trigger", "trigger"), &CollisionPolygon2D::set_trigger);
+ ClassDB::bind_method(D_METHOD("is_trigger"), &CollisionPolygon2D::is_trigger);
- ClassDB::bind_method(D_METHOD("get_collision_object_first_shape"),&CollisionPolygon2D::get_collision_object_first_shape);
- ClassDB::bind_method(D_METHOD("get_collision_object_last_shape"),&CollisionPolygon2D::get_collision_object_last_shape);
+ ClassDB::bind_method(D_METHOD("_set_shape_range", "shape_range"), &CollisionPolygon2D::_set_shape_range);
+ ClassDB::bind_method(D_METHOD("_get_shape_range"), &CollisionPolygon2D::_get_shape_range);
- ADD_PROPERTY( PropertyInfo(Variant::INT,"build_mode",PROPERTY_HINT_ENUM,"Solids,Segments"),"set_build_mode","get_build_mode");
- ADD_PROPERTY( PropertyInfo(Variant::POOL_VECTOR2_ARRAY,"polygon"),"set_polygon","get_polygon");
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"shape_range",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"_set_shape_range","_get_shape_range");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"trigger"),"set_trigger","is_trigger");
+ ClassDB::bind_method(D_METHOD("get_collision_object_first_shape"), &CollisionPolygon2D::get_collision_object_first_shape);
+ ClassDB::bind_method(D_METHOD("get_collision_object_last_shape"), &CollisionPolygon2D::get_collision_object_last_shape);
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "build_mode", PROPERTY_HINT_ENUM, "Solids,Segments"), "set_build_mode", "get_build_mode");
+ ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR2_ARRAY, "polygon"), "set_polygon", "get_polygon");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "shape_range", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_shape_range", "_get_shape_range");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "trigger"), "set_trigger", "is_trigger");
}
CollisionPolygon2D::CollisionPolygon2D() {
- aabb=Rect2(-10,-10,20,20);
- build_mode=BUILD_SOLIDS;
- trigger=false;
- unparenting=false;
- shape_from=-1;
- shape_to=-1;
- can_update_body=false;
+ aabb = Rect2(-10, -10, 20, 20);
+ build_mode = BUILD_SOLIDS;
+ trigger = false;
+ unparenting = false;
+ shape_from = -1;
+ shape_to = -1;
+ can_update_body = false;
set_notify_local_transform(true);
-
}
diff --git a/scene/2d/collision_polygon_2d.h b/scene/2d/collision_polygon_2d.h
index dda850b41d..f1f31a2854 100644
--- a/scene/2d/collision_polygon_2d.h
+++ b/scene/2d/collision_polygon_2d.h
@@ -32,21 +32,17 @@
#include "scene/2d/node_2d.h"
#include "scene/resources/shape_2d.h"
-
-
class CollisionPolygon2D : public Node2D {
- GDCLASS(CollisionPolygon2D,Node2D);
-public:
+ GDCLASS(CollisionPolygon2D, Node2D);
+public:
enum BuildMode {
BUILD_SOLIDS,
BUILD_SEGMENTS,
};
protected:
-
-
Rect2 aabb;
BuildMode build_mode;
Vector<Point2> polygon;
@@ -60,24 +56,23 @@ protected:
int shape_from;
int shape_to;
- void _set_shape_range(const Vector2& p_range);
+ void _set_shape_range(const Vector2 &p_range);
Vector2 _get_shape_range() const;
- Vector< Vector<Vector2> > _decompose_in_convex();
+ Vector<Vector<Vector2> > _decompose_in_convex();
protected:
-
void _notification(int p_what);
static void _bind_methods();
-public:
+public:
void set_trigger(bool p_trigger);
bool is_trigger() const;
void set_build_mode(BuildMode p_mode);
BuildMode get_build_mode() const;
- void set_polygon(const Vector<Point2>& p_polygon);
+ void set_polygon(const Vector<Point2> &p_polygon);
Vector<Point2> get_polygon() const;
virtual Rect2 get_item_rect() const;
@@ -90,6 +85,6 @@ public:
CollisionPolygon2D();
};
-VARIANT_ENUM_CAST( CollisionPolygon2D::BuildMode );
+VARIANT_ENUM_CAST(CollisionPolygon2D::BuildMode);
#endif // COLLISION_POLYGON_2D_H
diff --git a/scene/2d/collision_shape_2d.cpp b/scene/2d/collision_shape_2d.cpp
index 37a49577b5..39e0017e92 100644
--- a/scene/2d/collision_shape_2d.cpp
+++ b/scene/2d/collision_shape_2d.cpp
@@ -28,14 +28,13 @@
/*************************************************************************/
#include "collision_shape_2d.h"
#include "collision_object_2d.h"
-#include "scene/resources/segment_shape_2d.h"
-#include "scene/resources/shape_line_2d.h"
-#include "scene/resources/circle_shape_2d.h"
-#include "scene/resources/rectangle_shape_2d.h"
#include "scene/resources/capsule_shape_2d.h"
-#include "scene/resources/convex_polygon_shape_2d.h"
+#include "scene/resources/circle_shape_2d.h"
#include "scene/resources/concave_polygon_shape_2d.h"
-
+#include "scene/resources/convex_polygon_shape_2d.h"
+#include "scene/resources/rectangle_shape_2d.h"
+#include "scene/resources/segment_shape_2d.h"
+#include "scene/resources/shape_line_2d.h"
void CollisionShape2D::_add_to_collision_object(Object *p_obj) {
@@ -44,12 +43,10 @@ void CollisionShape2D::_add_to_collision_object(Object *p_obj) {
CollisionObject2D *co = p_obj->cast_to<CollisionObject2D>();
ERR_FAIL_COND(!co);
- update_shape_index=co->get_shape_count();
- co->add_shape(shape,get_transform());
+ update_shape_index = co->get_shape_count();
+ co->add_shape(shape, get_transform());
if (trigger)
- co->set_shape_as_trigger(co->get_shape_count()-1,true);
-
-
+ co->set_shape_as_trigger(co->get_shape_count() - 1, true);
}
void CollisionShape2D::_shape_changed() {
@@ -60,7 +57,6 @@ void CollisionShape2D::_shape_changed() {
void CollisionShape2D::_update_parent() {
-
Node *parent = get_parent();
if (!parent)
return;
@@ -72,15 +68,15 @@ void CollisionShape2D::_update_parent() {
void CollisionShape2D::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
- unparenting=false;
- can_update_body=get_tree()->is_editor_hint();
+ unparenting = false;
+ can_update_body = get_tree()->is_editor_hint();
if (!get_tree()->is_editor_hint()) {
//display above all else
set_z_as_relative(false);
- set_z(VS::CANVAS_ITEM_Z_MAX-1);
+ set_z(VS::CANVAS_ITEM_Z_MAX - 1);
}
} break;
@@ -90,18 +86,17 @@ void CollisionShape2D::_notification(int p_what) {
break;
if (can_update_body) {
_update_parent();
- } else if (update_shape_index>=0){
+ } else if (update_shape_index >= 0) {
CollisionObject2D *co = get_parent()->cast_to<CollisionObject2D>();
if (co) {
- co->set_shape_transform(update_shape_index,get_transform());
+ co->set_shape_transform(update_shape_index, get_transform());
}
-
}
} break;
case NOTIFICATION_EXIT_TREE: {
- can_update_body=false;
+ can_update_body = false;
} break;
/*
@@ -122,16 +117,13 @@ void CollisionShape2D::_notification(int p_what) {
break;
}
- rect=Rect2();
-
-
-
- Color draw_col=get_tree()->get_debug_collisions_color();
- shape->draw(get_canvas_item(),draw_col);
+ rect = Rect2();
+ Color draw_col = get_tree()->get_debug_collisions_color();
+ shape->draw(get_canvas_item(), draw_col);
- rect=shape->get_rect();
- rect=rect.grow(3);
+ rect = shape->get_rect();
+ rect = rect.grow(3);
} break;
case NOTIFICATION_UNPARENTED: {
@@ -139,25 +131,24 @@ void CollisionShape2D::_notification(int p_what) {
_update_parent();
} break;
}
-
}
-void CollisionShape2D::set_shape(const Ref<Shape2D>& p_shape) {
+void CollisionShape2D::set_shape(const Ref<Shape2D> &p_shape) {
if (shape.is_valid())
- shape->disconnect("changed",this,"_shape_changed");
- shape=p_shape;
+ shape->disconnect("changed", this, "_shape_changed");
+ shape = p_shape;
update();
if (is_inside_tree() && can_update_body)
_update_parent();
- if (is_inside_tree() && !can_update_body && update_shape_index>=0) {
+ if (is_inside_tree() && !can_update_body && update_shape_index >= 0) {
CollisionObject2D *co = get_parent()->cast_to<CollisionObject2D>();
if (co) {
- co->set_shape(update_shape_index,p_shape);
+ co->set_shape(update_shape_index, p_shape);
}
}
if (shape.is_valid())
- shape->connect("changed",this,"_shape_changed");
+ shape->connect("changed", this, "_shape_changed");
update_configuration_warning();
}
@@ -174,30 +165,28 @@ Rect2 CollisionShape2D::get_item_rect() const {
void CollisionShape2D::set_trigger(bool p_trigger) {
- trigger=p_trigger;
+ trigger = p_trigger;
if (can_update_body) {
_update_parent();
- } else if (is_inside_tree() && update_shape_index>=0){
+ } else if (is_inside_tree() && update_shape_index >= 0) {
CollisionObject2D *co = get_parent()->cast_to<CollisionObject2D>();
if (co) {
- co->set_shape_as_trigger(update_shape_index,p_trigger);
+ co->set_shape_as_trigger(update_shape_index, p_trigger);
}
}
}
-bool CollisionShape2D::is_trigger() const{
+bool CollisionShape2D::is_trigger() const {
return trigger;
}
-
void CollisionShape2D::_set_update_shape_index(int p_index) {
-
- update_shape_index=p_index;
+ update_shape_index = p_index;
}
-int CollisionShape2D::_get_update_shape_index() const{
+int CollisionShape2D::_get_update_shape_index() const {
return update_shape_index;
}
@@ -215,33 +204,31 @@ String CollisionShape2D::get_configuration_warning() const {
return String();
}
-
void CollisionShape2D::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_shape","shape"),&CollisionShape2D::set_shape);
- ClassDB::bind_method(D_METHOD("get_shape"),&CollisionShape2D::get_shape);
- ClassDB::bind_method(D_METHOD("_shape_changed"),&CollisionShape2D::_shape_changed);
- ClassDB::bind_method(D_METHOD("_add_to_collision_object"),&CollisionShape2D::_add_to_collision_object);
- ClassDB::bind_method(D_METHOD("set_trigger","enable"),&CollisionShape2D::set_trigger);
- ClassDB::bind_method(D_METHOD("is_trigger"),&CollisionShape2D::is_trigger);
-
- ClassDB::bind_method(D_METHOD("_set_update_shape_index","index"),&CollisionShape2D::_set_update_shape_index);
- ClassDB::bind_method(D_METHOD("_get_update_shape_index"),&CollisionShape2D::_get_update_shape_index);
+ ClassDB::bind_method(D_METHOD("set_shape", "shape"), &CollisionShape2D::set_shape);
+ ClassDB::bind_method(D_METHOD("get_shape"), &CollisionShape2D::get_shape);
+ ClassDB::bind_method(D_METHOD("_shape_changed"), &CollisionShape2D::_shape_changed);
+ ClassDB::bind_method(D_METHOD("_add_to_collision_object"), &CollisionShape2D::_add_to_collision_object);
+ ClassDB::bind_method(D_METHOD("set_trigger", "enable"), &CollisionShape2D::set_trigger);
+ ClassDB::bind_method(D_METHOD("is_trigger"), &CollisionShape2D::is_trigger);
- ClassDB::bind_method(D_METHOD("get_collision_object_shape_index"),&CollisionShape2D::get_collision_object_shape_index);
+ ClassDB::bind_method(D_METHOD("_set_update_shape_index", "index"), &CollisionShape2D::_set_update_shape_index);
+ ClassDB::bind_method(D_METHOD("_get_update_shape_index"), &CollisionShape2D::_get_update_shape_index);
- ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT,"shape",PROPERTY_HINT_RESOURCE_TYPE,"Shape2D"),"set_shape","get_shape");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL,"trigger"),"set_trigger","is_trigger");
- ADD_PROPERTY( PropertyInfo( Variant::INT, "_update_shape_index", PROPERTY_HINT_NONE, "",PROPERTY_USAGE_NOEDITOR), "_set_update_shape_index", "_get_update_shape_index");
+ ClassDB::bind_method(D_METHOD("get_collision_object_shape_index"), &CollisionShape2D::get_collision_object_shape_index);
+ ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape2D"), "set_shape", "get_shape");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "trigger"), "set_trigger", "is_trigger");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "_update_shape_index", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_update_shape_index", "_get_update_shape_index");
}
CollisionShape2D::CollisionShape2D() {
- rect=Rect2(-Point2(10,10),Point2(20,20));
+ rect = Rect2(-Point2(10, 10), Point2(20, 20));
set_notify_local_transform(true);
- trigger=false;
+ trigger = false;
unparenting = false;
can_update_body = false;
- update_shape_index=-1;
+ update_shape_index = -1;
}
diff --git a/scene/2d/collision_shape_2d.h b/scene/2d/collision_shape_2d.h
index b5cc789416..a3395cdc1e 100644
--- a/scene/2d/collision_shape_2d.h
+++ b/scene/2d/collision_shape_2d.h
@@ -34,7 +34,7 @@
class CollisionShape2D : public Node2D {
- GDCLASS(CollisionShape2D,Node2D);
+ GDCLASS(CollisionShape2D, Node2D);
Ref<Shape2D> shape;
Rect2 rect;
bool trigger;
@@ -47,15 +47,14 @@ class CollisionShape2D : public Node2D {
int _get_update_shape_index() const;
protected:
-
void _update_parent();
void _notification(int p_what);
static void _bind_methods();
void _add_to_collision_object(Object *p_obj);
-public:
- void set_shape(const Ref<Shape2D>& p_shape);
+public:
+ void set_shape(const Ref<Shape2D> &p_shape);
Ref<Shape2D> get_shape() const;
virtual Rect2 get_item_rect() const;
void set_trigger(bool p_trigger);
diff --git a/scene/2d/joints_2d.cpp b/scene/2d/joints_2d.cpp
index 6754eb3981..96ef714f1b 100644
--- a/scene/2d/joints_2d.cpp
+++ b/scene/2d/joints_2d.cpp
@@ -27,8 +27,8 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "joints_2d.h"
-#include "servers/physics_2d_server.h"
#include "physics_body_2d.h"
+#include "servers/physics_2d_server.h"
void Joint2D::_update_joint() {
@@ -39,49 +39,41 @@ void Joint2D::_update_joint() {
Physics2DServer::get_singleton()->free(joint);
}
- joint=RID();
-
+ joint = RID();
joint = _configure_joint();
- Physics2DServer::get_singleton()->get_singleton()->joint_set_param(joint,Physics2DServer::JOINT_PARAM_BIAS,bias);
-
-
+ Physics2DServer::get_singleton()->get_singleton()->joint_set_param(joint, Physics2DServer::JOINT_PARAM_BIAS, bias);
}
+void Joint2D::set_node_a(const NodePath &p_node_a) {
-void Joint2D::set_node_a(const NodePath& p_node_a) {
-
-
- if (a==p_node_a)
+ if (a == p_node_a)
return;
- a=p_node_a;
+ a = p_node_a;
_update_joint();
}
-NodePath Joint2D::get_node_a() const{
+NodePath Joint2D::get_node_a() const {
return a;
}
-void Joint2D::set_node_b(const NodePath& p_node_b){
+void Joint2D::set_node_b(const NodePath &p_node_b) {
- if (b==p_node_b)
+ if (b == p_node_b)
return;
- b=p_node_b;
+ b = p_node_b;
_update_joint();
-
}
-NodePath Joint2D::get_node_b() const{
-
+NodePath Joint2D::get_node_b() const {
return b;
}
-
void Joint2D::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_READY: {
_update_joint();
@@ -90,70 +82,61 @@ void Joint2D::_notification(int p_what) {
if (joint.is_valid()) {
Physics2DServer::get_singleton()->free(joint);
- joint=RID();
+ joint = RID();
}
} break;
-
}
-
}
void Joint2D::set_bias(real_t p_bias) {
- bias=p_bias;
+ bias = p_bias;
if (joint.is_valid())
- Physics2DServer::get_singleton()->get_singleton()->joint_set_param(joint,Physics2DServer::JOINT_PARAM_BIAS,bias);
+ Physics2DServer::get_singleton()->get_singleton()->joint_set_param(joint, Physics2DServer::JOINT_PARAM_BIAS, bias);
}
-real_t Joint2D::get_bias() const{
-
+real_t Joint2D::get_bias() const {
return bias;
}
void Joint2D::set_exclude_nodes_from_collision(bool p_enable) {
- if (exclude_from_collision==p_enable)
+ if (exclude_from_collision == p_enable)
return;
- exclude_from_collision=p_enable;
+ exclude_from_collision = p_enable;
_update_joint();
}
-bool Joint2D::get_exclude_nodes_from_collision() const{
+bool Joint2D::get_exclude_nodes_from_collision() const {
return exclude_from_collision;
}
-
void Joint2D::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_node_a", "node"), &Joint2D::set_node_a);
+ ClassDB::bind_method(D_METHOD("get_node_a"), &Joint2D::get_node_a);
- ClassDB::bind_method( D_METHOD("set_node_a","node"), &Joint2D::set_node_a );
- ClassDB::bind_method( D_METHOD("get_node_a"), &Joint2D::get_node_a );
-
- ClassDB::bind_method( D_METHOD("set_node_b","node"), &Joint2D::set_node_b );
- ClassDB::bind_method( D_METHOD("get_node_b"), &Joint2D::get_node_b );
+ ClassDB::bind_method(D_METHOD("set_node_b", "node"), &Joint2D::set_node_b);
+ ClassDB::bind_method(D_METHOD("get_node_b"), &Joint2D::get_node_b);
- ClassDB::bind_method( D_METHOD("set_bias","bias"), &Joint2D::set_bias );
- ClassDB::bind_method( D_METHOD("get_bias"), &Joint2D::get_bias );
-
- ClassDB::bind_method( D_METHOD("set_exclude_nodes_from_collision","enable"), &Joint2D::set_exclude_nodes_from_collision );
- ClassDB::bind_method( D_METHOD("get_exclude_nodes_from_collision"), &Joint2D::get_exclude_nodes_from_collision );
-
- ADD_PROPERTY( PropertyInfo( Variant::NODE_PATH, "node_a"), "set_node_a","get_node_a") ;
- ADD_PROPERTY( PropertyInfo( Variant::NODE_PATH, "node_b"), "set_node_b","get_node_b") ;
- ADD_PROPERTY( PropertyInfo( Variant::REAL, "bias",PROPERTY_HINT_RANGE,"0,0.9,0.001"), "set_bias","get_bias") ;
- ADD_PROPERTY( PropertyInfo( Variant::BOOL, "disable_collision"), "set_exclude_nodes_from_collision","get_exclude_nodes_from_collision") ;
+ ClassDB::bind_method(D_METHOD("set_bias", "bias"), &Joint2D::set_bias);
+ ClassDB::bind_method(D_METHOD("get_bias"), &Joint2D::get_bias);
+ ClassDB::bind_method(D_METHOD("set_exclude_nodes_from_collision", "enable"), &Joint2D::set_exclude_nodes_from_collision);
+ ClassDB::bind_method(D_METHOD("get_exclude_nodes_from_collision"), &Joint2D::get_exclude_nodes_from_collision);
+ ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "node_a"), "set_node_a", "get_node_a");
+ ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "node_b"), "set_node_b", "get_node_b");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "bias", PROPERTY_HINT_RANGE, "0,0.9,0.001"), "set_bias", "get_bias");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "disable_collision"), "set_exclude_nodes_from_collision", "get_exclude_nodes_from_collision");
}
-
-
Joint2D::Joint2D() {
- bias=0;
- exclude_from_collision=true;
+ bias = 0;
+ exclude_from_collision = true;
}
///////////////////////////////////////////////////////////////////////////////
@@ -162,7 +145,7 @@ Joint2D::Joint2D() {
void PinJoint2D::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_DRAW: {
if (!is_inside_tree())
@@ -172,50 +155,46 @@ void PinJoint2D::_notification(int p_what) {
break;
}
-
- draw_line(Point2(-10,0),Point2(+10,0),Color(0.7,0.6,0.0,0.5),3);
- draw_line(Point2(0,-10),Point2(0,+10),Color(0.7,0.6,0.0,0.5),3);
+ draw_line(Point2(-10, 0), Point2(+10, 0), Color(0.7, 0.6, 0.0, 0.5), 3);
+ draw_line(Point2(0, -10), Point2(0, +10), Color(0.7, 0.6, 0.0, 0.5), 3);
} break;
}
-
}
RID PinJoint2D::_configure_joint() {
- Node *node_a = has_node( get_node_a() ) ? get_node( get_node_a() ) : (Node*)NULL;
- Node *node_b = has_node( get_node_b() ) ? get_node( get_node_b() ) : (Node*)NULL;
+ Node *node_a = has_node(get_node_a()) ? get_node(get_node_a()) : (Node *)NULL;
+ Node *node_b = has_node(get_node_b()) ? get_node(get_node_b()) : (Node *)NULL;
if (!node_a && !node_b)
return RID();
- PhysicsBody2D *body_a=node_a ? node_a->cast_to<PhysicsBody2D>() : (PhysicsBody2D*)NULL;
- PhysicsBody2D *body_b=node_b ? node_b->cast_to<PhysicsBody2D>() : (PhysicsBody2D*)NULL;
+ PhysicsBody2D *body_a = node_a ? node_a->cast_to<PhysicsBody2D>() : (PhysicsBody2D *)NULL;
+ PhysicsBody2D *body_b = node_b ? node_b->cast_to<PhysicsBody2D>() : (PhysicsBody2D *)NULL;
if (!body_a && !body_b)
return RID();
if (!body_a) {
- SWAP(body_a,body_b);
+ SWAP(body_a, body_b);
} else if (body_b) {
//add a collision exception between both
if (get_exclude_nodes_from_collision())
- Physics2DServer::get_singleton()->body_add_collision_exception(body_a->get_rid(),body_b->get_rid());
+ Physics2DServer::get_singleton()->body_add_collision_exception(body_a->get_rid(), body_b->get_rid());
else
- Physics2DServer::get_singleton()->body_remove_collision_exception(body_a->get_rid(),body_b->get_rid());
+ Physics2DServer::get_singleton()->body_remove_collision_exception(body_a->get_rid(), body_b->get_rid());
}
- RID pj = Physics2DServer::get_singleton()->pin_joint_create(get_global_transform().get_origin(),body_a->get_rid(),body_b?body_b->get_rid():RID());
+ RID pj = Physics2DServer::get_singleton()->pin_joint_create(get_global_transform().get_origin(), body_a->get_rid(), body_b ? body_b->get_rid() : RID());
Physics2DServer::get_singleton()->pin_joint_set_param(pj, Physics2DServer::PIN_JOINT_SOFTNESS, softness);
return pj;
-
}
void PinJoint2D::set_softness(real_t p_softness) {
- softness=p_softness;
+ softness = p_softness;
update();
if (get_joint().is_valid())
Physics2DServer::get_singleton()->pin_joint_set_param(get_joint(), Physics2DServer::PIN_JOINT_SOFTNESS, p_softness);
-
}
real_t PinJoint2D::get_softness() const {
@@ -225,10 +204,10 @@ real_t PinJoint2D::get_softness() const {
void PinJoint2D::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_softness","softness"), &PinJoint2D::set_softness);
+ ClassDB::bind_method(D_METHOD("set_softness", "softness"), &PinJoint2D::set_softness);
ClassDB::bind_method(D_METHOD("get_softness"), &PinJoint2D::get_softness);
- ADD_PROPERTY( PropertyInfo( Variant::REAL, "softness", PROPERTY_HINT_EXP_RANGE,"0.00,16,0.01"), "set_softness", "get_softness");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "softness", PROPERTY_HINT_EXP_RANGE, "0.00,16,0.01"), "set_softness", "get_softness");
}
PinJoint2D::PinJoint2D() {
@@ -236,16 +215,13 @@ PinJoint2D::PinJoint2D() {
softness = 0;
}
-
-
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
-
void GrooveJoint2D::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_DRAW: {
if (!is_inside_tree())
break;
@@ -254,48 +230,44 @@ void GrooveJoint2D::_notification(int p_what) {
break;
}
- draw_line(Point2(-10,0),Point2(+10,0),Color(0.7,0.6,0.0,0.5),3);
- draw_line(Point2(-10,length),Point2(+10,length),Color(0.7,0.6,0.0,0.5),3);
- draw_line(Point2(0,0),Point2(0,length),Color(0.7,0.6,0.0,0.5),3);
- draw_line(Point2(-10,initial_offset),Point2(+10,initial_offset),Color(0.8,0.8,0.9,0.5),5);
+ draw_line(Point2(-10, 0), Point2(+10, 0), Color(0.7, 0.6, 0.0, 0.5), 3);
+ draw_line(Point2(-10, length), Point2(+10, length), Color(0.7, 0.6, 0.0, 0.5), 3);
+ draw_line(Point2(0, 0), Point2(0, length), Color(0.7, 0.6, 0.0, 0.5), 3);
+ draw_line(Point2(-10, initial_offset), Point2(+10, initial_offset), Color(0.8, 0.8, 0.9, 0.5), 5);
} break;
}
}
-RID GrooveJoint2D::_configure_joint(){
+RID GrooveJoint2D::_configure_joint() {
-
- Node *node_a = has_node( get_node_a() ) ? get_node( get_node_a() ) : (Node*)NULL;
- Node *node_b = has_node( get_node_b() ) ? get_node( get_node_b() ) : (Node*)NULL;
+ Node *node_a = has_node(get_node_a()) ? get_node(get_node_a()) : (Node *)NULL;
+ Node *node_b = has_node(get_node_b()) ? get_node(get_node_b()) : (Node *)NULL;
if (!node_a || !node_b)
return RID();
- PhysicsBody2D *body_a=node_a->cast_to<PhysicsBody2D>();
- PhysicsBody2D *body_b=node_b->cast_to<PhysicsBody2D>();
+ PhysicsBody2D *body_a = node_a->cast_to<PhysicsBody2D>();
+ PhysicsBody2D *body_b = node_b->cast_to<PhysicsBody2D>();
if (!body_a || !body_b)
return RID();
-
if (get_exclude_nodes_from_collision())
- Physics2DServer::get_singleton()->body_add_collision_exception(body_a->get_rid(),body_b->get_rid());
+ Physics2DServer::get_singleton()->body_add_collision_exception(body_a->get_rid(), body_b->get_rid());
else
- Physics2DServer::get_singleton()->body_remove_collision_exception(body_a->get_rid(),body_b->get_rid());
+ Physics2DServer::get_singleton()->body_remove_collision_exception(body_a->get_rid(), body_b->get_rid());
Transform2D gt = get_global_transform();
Vector2 groove_A1 = gt.get_origin();
- Vector2 groove_A2 = gt.xform( Vector2(0,length) );
- Vector2 anchor_B = gt.xform( Vector2(0,initial_offset) );
-
+ Vector2 groove_A2 = gt.xform(Vector2(0, length));
+ Vector2 anchor_B = gt.xform(Vector2(0, initial_offset));
- return Physics2DServer::get_singleton()->groove_joint_create(groove_A1,groove_A2,anchor_B,body_a->get_rid(),body_b->get_rid());
+ return Physics2DServer::get_singleton()->groove_joint_create(groove_A1, groove_A2, anchor_B, body_a->get_rid(), body_b->get_rid());
}
-
void GrooveJoint2D::set_length(real_t p_length) {
- length=p_length;
+ length = p_length;
update();
}
@@ -304,10 +276,9 @@ real_t GrooveJoint2D::get_length() const {
return length;
}
-
void GrooveJoint2D::set_initial_offset(real_t p_initial_offset) {
- initial_offset=p_initial_offset;
+ initial_offset = p_initial_offset;
update();
}
@@ -316,38 +287,30 @@ real_t GrooveJoint2D::get_initial_offset() const {
return initial_offset;
}
-
-
void GrooveJoint2D::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_length", "length"), &GrooveJoint2D::set_length);
+ ClassDB::bind_method(D_METHOD("get_length"), &GrooveJoint2D::get_length);
+ ClassDB::bind_method(D_METHOD("set_initial_offset", "offset"), &GrooveJoint2D::set_initial_offset);
+ ClassDB::bind_method(D_METHOD("get_initial_offset"), &GrooveJoint2D::get_initial_offset);
- ClassDB::bind_method(D_METHOD("set_length","length"),&GrooveJoint2D::set_length);
- ClassDB::bind_method(D_METHOD("get_length"),&GrooveJoint2D::get_length);
- ClassDB::bind_method(D_METHOD("set_initial_offset","offset"),&GrooveJoint2D::set_initial_offset);
- ClassDB::bind_method(D_METHOD("get_initial_offset"),&GrooveJoint2D::get_initial_offset);
-
- ADD_PROPERTY( PropertyInfo( Variant::REAL, "length", PROPERTY_HINT_EXP_RANGE,"1,65535,1"), "set_length","get_length");
- ADD_PROPERTY( PropertyInfo( Variant::REAL, "initial_offset", PROPERTY_HINT_EXP_RANGE,"1,65535,1"), "set_initial_offset","get_initial_offset");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "length", PROPERTY_HINT_EXP_RANGE, "1,65535,1"), "set_length", "get_length");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "initial_offset", PROPERTY_HINT_EXP_RANGE, "1,65535,1"), "set_initial_offset", "get_initial_offset");
}
GrooveJoint2D::GrooveJoint2D() {
- length=50;
- initial_offset=25;
+ length = 50;
+ initial_offset = 25;
}
-
-
-
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
-
-
void DampedSpringJoint2D::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_DRAW: {
if (!is_inside_tree())
@@ -357,50 +320,48 @@ void DampedSpringJoint2D::_notification(int p_what) {
break;
}
- draw_line(Point2(-10,0),Point2(+10,0),Color(0.7,0.6,0.0,0.5),3);
- draw_line(Point2(-10,length),Point2(+10,length),Color(0.7,0.6,0.0,0.5),3);
- draw_line(Point2(0,0),Point2(0,length),Color(0.7,0.6,0.0,0.5),3);
+ draw_line(Point2(-10, 0), Point2(+10, 0), Color(0.7, 0.6, 0.0, 0.5), 3);
+ draw_line(Point2(-10, length), Point2(+10, length), Color(0.7, 0.6, 0.0, 0.5), 3);
+ draw_line(Point2(0, 0), Point2(0, length), Color(0.7, 0.6, 0.0, 0.5), 3);
} break;
}
}
-RID DampedSpringJoint2D::_configure_joint(){
-
+RID DampedSpringJoint2D::_configure_joint() {
- Node *node_a = has_node( get_node_a() ) ? get_node( get_node_a() ) : (Node*)NULL;
- Node *node_b = has_node( get_node_b() ) ? get_node( get_node_b() ) : (Node*)NULL;
+ Node *node_a = has_node(get_node_a()) ? get_node(get_node_a()) : (Node *)NULL;
+ Node *node_b = has_node(get_node_b()) ? get_node(get_node_b()) : (Node *)NULL;
if (!node_a || !node_b)
return RID();
- PhysicsBody2D *body_a=node_a->cast_to<PhysicsBody2D>();
- PhysicsBody2D *body_b=node_b->cast_to<PhysicsBody2D>();
+ PhysicsBody2D *body_a = node_a->cast_to<PhysicsBody2D>();
+ PhysicsBody2D *body_b = node_b->cast_to<PhysicsBody2D>();
if (!body_a || !body_b)
return RID();
if (get_exclude_nodes_from_collision())
- Physics2DServer::get_singleton()->body_add_collision_exception(body_a->get_rid(),body_b->get_rid());
+ Physics2DServer::get_singleton()->body_add_collision_exception(body_a->get_rid(), body_b->get_rid());
else
- Physics2DServer::get_singleton()->body_remove_collision_exception(body_a->get_rid(),body_b->get_rid());
+ Physics2DServer::get_singleton()->body_remove_collision_exception(body_a->get_rid(), body_b->get_rid());
Transform2D gt = get_global_transform();
Vector2 anchor_A = gt.get_origin();
- Vector2 anchor_B = gt.xform( Vector2(0,length) );
+ Vector2 anchor_B = gt.xform(Vector2(0, length));
- RID dsj = Physics2DServer::get_singleton()->damped_spring_joint_create(anchor_A,anchor_B,body_a->get_rid(),body_b->get_rid());
+ RID dsj = Physics2DServer::get_singleton()->damped_spring_joint_create(anchor_A, anchor_B, body_a->get_rid(), body_b->get_rid());
if (rest_length)
- Physics2DServer::get_singleton()->damped_string_joint_set_param(dsj,Physics2DServer::DAMPED_STRING_REST_LENGTH,rest_length);
- Physics2DServer::get_singleton()->damped_string_joint_set_param(dsj,Physics2DServer::DAMPED_STRING_STIFFNESS,stiffness);
- Physics2DServer::get_singleton()->damped_string_joint_set_param(dsj,Physics2DServer::DAMPED_STRING_DAMPING,damping);
+ Physics2DServer::get_singleton()->damped_string_joint_set_param(dsj, Physics2DServer::DAMPED_STRING_REST_LENGTH, rest_length);
+ Physics2DServer::get_singleton()->damped_string_joint_set_param(dsj, Physics2DServer::DAMPED_STRING_STIFFNESS, stiffness);
+ Physics2DServer::get_singleton()->damped_string_joint_set_param(dsj, Physics2DServer::DAMPED_STRING_DAMPING, damping);
return dsj;
}
-
void DampedSpringJoint2D::set_length(real_t p_length) {
- length=p_length;
+ length = p_length;
update();
}
@@ -411,11 +372,10 @@ real_t DampedSpringJoint2D::get_length() const {
void DampedSpringJoint2D::set_rest_length(real_t p_rest_length) {
- rest_length=p_rest_length;
+ rest_length = p_rest_length;
update();
if (get_joint().is_valid())
- Physics2DServer::get_singleton()->damped_string_joint_set_param(get_joint(),Physics2DServer::DAMPED_STRING_REST_LENGTH,p_rest_length?p_rest_length:length);
-
+ Physics2DServer::get_singleton()->damped_string_joint_set_param(get_joint(), Physics2DServer::DAMPED_STRING_REST_LENGTH, p_rest_length ? p_rest_length : length);
}
real_t DampedSpringJoint2D::get_rest_length() const {
@@ -425,10 +385,10 @@ real_t DampedSpringJoint2D::get_rest_length() const {
void DampedSpringJoint2D::set_stiffness(real_t p_stiffness) {
- stiffness=p_stiffness;
+ stiffness = p_stiffness;
update();
if (get_joint().is_valid())
- Physics2DServer::get_singleton()->damped_string_joint_set_param(get_joint(),Physics2DServer::DAMPED_STRING_STIFFNESS,p_stiffness);
+ Physics2DServer::get_singleton()->damped_string_joint_set_param(get_joint(), Physics2DServer::DAMPED_STRING_STIFFNESS, p_stiffness);
}
real_t DampedSpringJoint2D::get_stiffness() const {
@@ -438,10 +398,10 @@ real_t DampedSpringJoint2D::get_stiffness() const {
void DampedSpringJoint2D::set_damping(real_t p_damping) {
- damping=p_damping;
+ damping = p_damping;
update();
if (get_joint().is_valid())
- Physics2DServer::get_singleton()->damped_string_joint_set_param(get_joint(),Physics2DServer::DAMPED_STRING_DAMPING,p_damping);
+ Physics2DServer::get_singleton()->damped_string_joint_set_param(get_joint(), Physics2DServer::DAMPED_STRING_DAMPING, p_damping);
}
real_t DampedSpringJoint2D::get_damping() const {
@@ -449,30 +409,27 @@ real_t DampedSpringJoint2D::get_damping() const {
return damping;
}
-
void DampedSpringJoint2D::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_length", "length"), &DampedSpringJoint2D::set_length);
+ ClassDB::bind_method(D_METHOD("get_length"), &DampedSpringJoint2D::get_length);
+ ClassDB::bind_method(D_METHOD("set_rest_length", "rest_length"), &DampedSpringJoint2D::set_rest_length);
+ ClassDB::bind_method(D_METHOD("get_rest_length"), &DampedSpringJoint2D::get_rest_length);
+ ClassDB::bind_method(D_METHOD("set_stiffness", "stiffness"), &DampedSpringJoint2D::set_stiffness);
+ ClassDB::bind_method(D_METHOD("get_stiffness"), &DampedSpringJoint2D::get_stiffness);
+ ClassDB::bind_method(D_METHOD("set_damping", "damping"), &DampedSpringJoint2D::set_damping);
+ ClassDB::bind_method(D_METHOD("get_damping"), &DampedSpringJoint2D::get_damping);
- ClassDB::bind_method(D_METHOD("set_length","length"),&DampedSpringJoint2D::set_length);
- ClassDB::bind_method(D_METHOD("get_length"),&DampedSpringJoint2D::get_length);
- ClassDB::bind_method(D_METHOD("set_rest_length","rest_length"),&DampedSpringJoint2D::set_rest_length);
- ClassDB::bind_method(D_METHOD("get_rest_length"),&DampedSpringJoint2D::get_rest_length);
- ClassDB::bind_method(D_METHOD("set_stiffness","stiffness"),&DampedSpringJoint2D::set_stiffness);
- ClassDB::bind_method(D_METHOD("get_stiffness"),&DampedSpringJoint2D::get_stiffness);
- ClassDB::bind_method(D_METHOD("set_damping","damping"),&DampedSpringJoint2D::set_damping);
- ClassDB::bind_method(D_METHOD("get_damping"),&DampedSpringJoint2D::get_damping);
-
- ADD_PROPERTY( PropertyInfo( Variant::REAL, "length", PROPERTY_HINT_EXP_RANGE,"1,65535,1"), "set_length","get_length");
- ADD_PROPERTY( PropertyInfo( Variant::REAL, "rest_length", PROPERTY_HINT_EXP_RANGE,"0,65535,1"), "set_rest_length","get_rest_length");
- ADD_PROPERTY( PropertyInfo( Variant::REAL, "stiffness", PROPERTY_HINT_EXP_RANGE,"0.1,64,0.1"), "set_stiffness","get_stiffness");
- ADD_PROPERTY( PropertyInfo( Variant::REAL, "damping", PROPERTY_HINT_EXP_RANGE,"0.01,16,0.01"), "set_damping","get_damping");
-
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "length", PROPERTY_HINT_EXP_RANGE, "1,65535,1"), "set_length", "get_length");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "rest_length", PROPERTY_HINT_EXP_RANGE, "0,65535,1"), "set_rest_length", "get_rest_length");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "stiffness", PROPERTY_HINT_EXP_RANGE, "0.1,64,0.1"), "set_stiffness", "get_stiffness");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "damping", PROPERTY_HINT_EXP_RANGE, "0.01,16,0.01"), "set_damping", "get_damping");
}
DampedSpringJoint2D::DampedSpringJoint2D() {
- length=50;
- rest_length=0;
- stiffness=20;
- damping=1;
+ length = 50;
+ rest_length = 0;
+ stiffness = 20;
+ damping = 1;
}
diff --git a/scene/2d/joints_2d.h b/scene/2d/joints_2d.h
index 3b3eec6bd6..c172620461 100644
--- a/scene/2d/joints_2d.h
+++ b/scene/2d/joints_2d.h
@@ -29,12 +29,11 @@
#ifndef JOINTS_2D_H
#define JOINTS_2D_H
-
#include "node_2d.h"
class Joint2D : public Node2D {
- GDCLASS(Joint2D,Node2D);
+ GDCLASS(Joint2D, Node2D);
RID joint;
@@ -44,21 +43,19 @@ class Joint2D : public Node2D {
bool exclude_from_collision;
-
protected:
-
void _update_joint();
void _notification(int p_what);
- virtual RID _configure_joint()=0;
+ virtual RID _configure_joint() = 0;
static void _bind_methods();
-public:
- void set_node_a(const NodePath& p_node_a);
+public:
+ void set_node_a(const NodePath &p_node_a);
NodePath get_node_a() const;
- void set_node_b(const NodePath& p_node_b);
+ void set_node_b(const NodePath &p_node_b);
NodePath get_node_b() const;
void set_bias(real_t p_bias);
@@ -69,23 +66,20 @@ public:
RID get_joint() const { return joint; }
Joint2D();
-
};
-
class PinJoint2D : public Joint2D {
- GDCLASS(PinJoint2D,Joint2D);
+ GDCLASS(PinJoint2D, Joint2D);
real_t softness;
protected:
-
void _notification(int p_what);
virtual RID _configure_joint();
static void _bind_methods();
-public:
+public:
void set_softness(real_t p_stiffness);
real_t get_softness() const;
@@ -94,18 +88,17 @@ public:
class GrooveJoint2D : public Joint2D {
- GDCLASS(GrooveJoint2D,Joint2D);
+ GDCLASS(GrooveJoint2D, Joint2D);
real_t length;
real_t initial_offset;
protected:
-
void _notification(int p_what);
virtual RID _configure_joint();
static void _bind_methods();
-public:
+public:
void set_length(real_t p_length);
real_t get_length() const;
@@ -117,7 +110,7 @@ public:
class DampedSpringJoint2D : public Joint2D {
- GDCLASS(DampedSpringJoint2D,Joint2D);
+ GDCLASS(DampedSpringJoint2D, Joint2D);
real_t stiffness;
real_t damping;
@@ -125,12 +118,11 @@ class DampedSpringJoint2D : public Joint2D {
real_t length;
protected:
-
void _notification(int p_what);
virtual RID _configure_joint();
static void _bind_methods();
-public:
+public:
void set_length(real_t p_length);
real_t get_length() const;
@@ -146,5 +138,4 @@ public:
DampedSpringJoint2D();
};
-
#endif // JOINTS_2D_H
diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp
index d7f5a890e8..7cf98c8c09 100644
--- a/scene/2d/light_2d.cpp
+++ b/scene/2d/light_2d.cpp
@@ -29,10 +29,9 @@
#include "light_2d.h"
#include "servers/visual_server.h"
-void Light2D::edit_set_pivot(const Point2& p_pivot) {
+void Light2D::edit_set_pivot(const Point2 &p_pivot) {
set_texture_offset(p_pivot);
-
}
Point2 Light2D::edit_get_pivot() const {
@@ -47,49 +46,47 @@ bool Light2D::edit_has_pivot() const {
Rect2 Light2D::get_item_rect() const {
if (texture.is_null())
- return Rect2(0,0,1,1);
+ return Rect2(0, 0, 1, 1);
Size2i s;
- s = texture->get_size()*_scale;
- Point2i ofs=texture_offset;
- ofs-=s/2;
+ s = texture->get_size() * _scale;
+ Point2i ofs = texture_offset;
+ ofs -= s / 2;
- if (s==Size2(0,0))
- s=Size2(1,1);
+ if (s == Size2(0, 0))
+ s = Size2(1, 1);
- return Rect2(ofs,s);
+ return Rect2(ofs, s);
}
-
void Light2D::_update_light_visibility() {
if (!is_inside_tree())
return;
- bool editor_ok=true;
+ bool editor_ok = true;
#ifdef TOOLS_ENABLED
if (editor_only) {
if (!get_tree()->is_editor_hint()) {
- editor_ok=false;
+ editor_ok = false;
} else {
- editor_ok = (get_tree()->get_edited_scene_root() && (this==get_tree()->get_edited_scene_root() || get_owner()==get_tree()->get_edited_scene_root()));
+ editor_ok = (get_tree()->get_edited_scene_root() && (this == get_tree()->get_edited_scene_root() || get_owner() == get_tree()->get_edited_scene_root()));
}
}
#else
if (editor_only) {
- editor_ok=false;
+ editor_ok = false;
}
#endif
- VS::get_singleton()->canvas_light_set_enabled(canvas_light,enabled && is_visible_in_tree() && editor_ok);
+ VS::get_singleton()->canvas_light_set_enabled(canvas_light, enabled && is_visible_in_tree() && editor_ok);
}
-void Light2D::set_enabled( bool p_enabled) {
-
+void Light2D::set_enabled(bool p_enabled) {
- enabled=p_enabled;
+ enabled = p_enabled;
_update_light_visibility();
}
@@ -100,22 +97,22 @@ bool Light2D::is_enabled() const {
void Light2D::set_editor_only(bool p_editor_only) {
- editor_only=p_editor_only;
+ editor_only = p_editor_only;
_update_light_visibility();
}
-bool Light2D::is_editor_only() const{
+bool Light2D::is_editor_only() const {
return editor_only;
}
-void Light2D::set_texture( const Ref<Texture>& p_texture) {
+void Light2D::set_texture(const Ref<Texture> &p_texture) {
- texture=p_texture;
+ texture = p_texture;
if (texture.is_valid())
- VS::get_singleton()->canvas_light_set_texture(canvas_light,texture->get_rid());
+ VS::get_singleton()->canvas_light_set_texture(canvas_light, texture->get_rid());
else
- VS::get_singleton()->canvas_light_set_texture(canvas_light,RID());
+ VS::get_singleton()->canvas_light_set_texture(canvas_light, RID());
update_configuration_warning();
}
@@ -125,12 +122,11 @@ Ref<Texture> Light2D::get_texture() const {
return texture;
}
-void Light2D::set_texture_offset( const Vector2& p_offset) {
+void Light2D::set_texture_offset(const Vector2 &p_offset) {
- texture_offset=p_offset;
- VS::get_singleton()->canvas_light_set_texture_offset(canvas_light,texture_offset);
+ texture_offset = p_offset;
+ VS::get_singleton()->canvas_light_set_texture_offset(canvas_light, texture_offset);
item_rect_changed();
-
}
Vector2 Light2D::get_texture_offset() const {
@@ -138,108 +134,94 @@ Vector2 Light2D::get_texture_offset() const {
return texture_offset;
}
-void Light2D::set_color( const Color& p_color) {
-
- color=p_color;
- VS::get_singleton()->canvas_light_set_color(canvas_light,color);
+void Light2D::set_color(const Color &p_color) {
+ color = p_color;
+ VS::get_singleton()->canvas_light_set_color(canvas_light, color);
}
Color Light2D::get_color() const {
return color;
}
-void Light2D::set_height( float p_height) {
-
- height=p_height;
- VS::get_singleton()->canvas_light_set_height(canvas_light,height);
+void Light2D::set_height(float p_height) {
+ height = p_height;
+ VS::get_singleton()->canvas_light_set_height(canvas_light, height);
}
-
float Light2D::get_height() const {
return height;
}
-void Light2D::set_energy( float p_energy) {
-
- energy=p_energy;
- VS::get_singleton()->canvas_light_set_energy(canvas_light,energy);
+void Light2D::set_energy(float p_energy) {
+ energy = p_energy;
+ VS::get_singleton()->canvas_light_set_energy(canvas_light, energy);
}
-
float Light2D::get_energy() const {
return energy;
}
+void Light2D::set_texture_scale(float p_scale) {
-
-void Light2D::set_texture_scale( float p_scale) {
-
- _scale=p_scale;
- VS::get_singleton()->canvas_light_set_scale(canvas_light,_scale);
+ _scale = p_scale;
+ VS::get_singleton()->canvas_light_set_scale(canvas_light, _scale);
item_rect_changed();
-
}
-
float Light2D::get_texture_scale() const {
return _scale;
}
-void Light2D::set_z_range_min( int p_min_z) {
-
- z_min=p_min_z;
- VS::get_singleton()->canvas_light_set_z_range(canvas_light,z_min,z_max);
+void Light2D::set_z_range_min(int p_min_z) {
+ z_min = p_min_z;
+ VS::get_singleton()->canvas_light_set_z_range(canvas_light, z_min, z_max);
}
int Light2D::get_z_range_min() const {
return z_min;
}
-void Light2D::set_z_range_max( int p_max_z) {
-
- z_max=p_max_z;
- VS::get_singleton()->canvas_light_set_z_range(canvas_light,z_min,z_max);
+void Light2D::set_z_range_max(int p_max_z) {
+ z_max = p_max_z;
+ VS::get_singleton()->canvas_light_set_z_range(canvas_light, z_min, z_max);
}
int Light2D::get_z_range_max() const {
return z_max;
}
-void Light2D::set_layer_range_min( int p_min_layer) {
-
- layer_min=p_min_layer;
- VS::get_singleton()->canvas_light_set_layer_range(canvas_light,layer_min,layer_max);
+void Light2D::set_layer_range_min(int p_min_layer) {
+ layer_min = p_min_layer;
+ VS::get_singleton()->canvas_light_set_layer_range(canvas_light, layer_min, layer_max);
}
int Light2D::get_layer_range_min() const {
return layer_min;
}
-void Light2D::set_layer_range_max( int p_max_layer) {
-
- layer_max=p_max_layer;
- VS::get_singleton()->canvas_light_set_layer_range(canvas_light,layer_min,layer_max);
+void Light2D::set_layer_range_max(int p_max_layer) {
+ layer_max = p_max_layer;
+ VS::get_singleton()->canvas_light_set_layer_range(canvas_light, layer_min, layer_max);
}
int Light2D::get_layer_range_max() const {
return layer_max;
}
-void Light2D::set_item_cull_mask( int p_mask) {
-
- item_mask=p_mask;
- VS::get_singleton()->canvas_light_set_item_cull_mask(canvas_light,item_mask);
+void Light2D::set_item_cull_mask(int p_mask) {
+ item_mask = p_mask;
+ VS::get_singleton()->canvas_light_set_item_cull_mask(canvas_light, item_mask);
}
int Light2D::get_item_cull_mask() const {
@@ -247,11 +229,10 @@ int Light2D::get_item_cull_mask() const {
return item_mask;
}
-void Light2D::set_item_shadow_cull_mask( int p_mask) {
-
- item_shadow_mask=p_mask;
- VS::get_singleton()->canvas_light_set_item_shadow_cull_mask(canvas_light,item_shadow_mask);
+void Light2D::set_item_shadow_cull_mask(int p_mask) {
+ item_shadow_mask = p_mask;
+ VS::get_singleton()->canvas_light_set_item_shadow_cull_mask(canvas_light, item_shadow_mask);
}
int Light2D::get_item_shadow_cull_mask() const {
@@ -259,10 +240,10 @@ int Light2D::get_item_shadow_cull_mask() const {
return item_shadow_mask;
}
-void Light2D::set_mode( Mode p_mode ) {
+void Light2D::set_mode(Mode p_mode) {
- mode=p_mode;
- VS::get_singleton()->canvas_light_set_mode(canvas_light,VS::CanvasLightMode(p_mode));
+ mode = p_mode;
+ VS::get_singleton()->canvas_light_set_mode(canvas_light, VS::CanvasLightMode(p_mode));
}
Light2D::Mode Light2D::get_mode() const {
@@ -270,21 +251,20 @@ Light2D::Mode Light2D::get_mode() const {
return mode;
}
-void Light2D::set_shadow_enabled( bool p_enabled) {
-
- shadow=p_enabled;
- VS::get_singleton()->canvas_light_set_shadow_enabled(canvas_light,shadow);
+void Light2D::set_shadow_enabled(bool p_enabled) {
+ shadow = p_enabled;
+ VS::get_singleton()->canvas_light_set_shadow_enabled(canvas_light, shadow);
}
bool Light2D::is_shadow_enabled() const {
return shadow;
}
-void Light2D::set_shadow_buffer_size( int p_size ) {
+void Light2D::set_shadow_buffer_size(int p_size) {
- shadow_buffer_size=p_size;
- VS::get_singleton()->canvas_light_set_shadow_buffer_size(canvas_light,shadow_buffer_size);
+ shadow_buffer_size = p_size;
+ VS::get_singleton()->canvas_light_set_shadow_buffer_size(canvas_light, shadow_buffer_size);
}
int Light2D::get_shadow_buffer_size() const {
@@ -292,21 +272,20 @@ int Light2D::get_shadow_buffer_size() const {
return shadow_buffer_size;
}
-void Light2D::set_shadow_gradient_length( float p_multiplier) {
+void Light2D::set_shadow_gradient_length(float p_multiplier) {
- shadow_gradient_length=p_multiplier;
- VS::get_singleton()->canvas_light_set_shadow_gradient_length(canvas_light,p_multiplier);
+ shadow_gradient_length = p_multiplier;
+ VS::get_singleton()->canvas_light_set_shadow_gradient_length(canvas_light, p_multiplier);
}
-float Light2D::get_shadow_gradient_length() const{
+float Light2D::get_shadow_gradient_length() const {
return shadow_gradient_length;
}
-
-void Light2D::set_shadow_filter( ShadowFilter p_filter) {
- shadow_filter=p_filter;
- VS::get_singleton()->canvas_light_set_shadow_filter(canvas_light,VS::CanvasLightShadowFilter(p_filter ));
+void Light2D::set_shadow_filter(ShadowFilter p_filter) {
+ shadow_filter = p_filter;
+ VS::get_singleton()->canvas_light_set_shadow_filter(canvas_light, VS::CanvasLightShadowFilter(p_filter));
}
Light2D::ShadowFilter Light2D::get_shadow_filter() const {
@@ -314,42 +293,37 @@ Light2D::ShadowFilter Light2D::get_shadow_filter() const {
return shadow_filter;
}
-
-
-void Light2D::set_shadow_color( const Color& p_shadow_color) {
- shadow_color=p_shadow_color;
- VS::get_singleton()->canvas_light_set_shadow_color(canvas_light,shadow_color);
+void Light2D::set_shadow_color(const Color &p_shadow_color) {
+ shadow_color = p_shadow_color;
+ VS::get_singleton()->canvas_light_set_shadow_color(canvas_light, shadow_color);
}
Color Light2D::get_shadow_color() const {
return shadow_color;
}
-
-
void Light2D::_notification(int p_what) {
- if (p_what==NOTIFICATION_ENTER_TREE) {
+ if (p_what == NOTIFICATION_ENTER_TREE) {
- VS::get_singleton()->canvas_light_attach_to_canvas( canvas_light, get_canvas() );
+ VS::get_singleton()->canvas_light_attach_to_canvas(canvas_light, get_canvas());
_update_light_visibility();
}
- if (p_what==NOTIFICATION_TRANSFORM_CHANGED) {
+ if (p_what == NOTIFICATION_TRANSFORM_CHANGED) {
- VS::get_singleton()->canvas_light_set_transform( canvas_light, get_global_transform());
+ VS::get_singleton()->canvas_light_set_transform(canvas_light, get_global_transform());
}
- if (p_what==NOTIFICATION_VISIBILITY_CHANGED) {
+ if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
_update_light_visibility();
}
- if (p_what==NOTIFICATION_EXIT_TREE) {
+ if (p_what == NOTIFICATION_EXIT_TREE) {
- VS::get_singleton()->canvas_light_attach_to_canvas( canvas_light, RID() );
+ VS::get_singleton()->canvas_light_attach_to_canvas(canvas_light, RID());
_update_light_visibility();
}
-
}
String Light2D::get_configuration_warning() const {
@@ -361,126 +335,119 @@ String Light2D::get_configuration_warning() const {
return String();
}
-
void Light2D::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &Light2D::set_enabled);
+ ClassDB::bind_method(D_METHOD("is_enabled"), &Light2D::is_enabled);
- ClassDB::bind_method(D_METHOD("set_enabled","enabled"),&Light2D::set_enabled);
- ClassDB::bind_method(D_METHOD("is_enabled"),&Light2D::is_enabled);
-
- ClassDB::bind_method(D_METHOD("set_editor_only","editor_only"), &Light2D::set_editor_only );
- ClassDB::bind_method(D_METHOD("is_editor_only"), &Light2D::is_editor_only );
-
- ClassDB::bind_method(D_METHOD("set_texture","texture"),&Light2D::set_texture);
- ClassDB::bind_method(D_METHOD("get_texture"),&Light2D::get_texture);
-
- ClassDB::bind_method(D_METHOD("set_texture_offset","texture_offset"),&Light2D::set_texture_offset);
- ClassDB::bind_method(D_METHOD("get_texture_offset"),&Light2D::get_texture_offset);
-
- ClassDB::bind_method(D_METHOD("set_color","color"),&Light2D::set_color);
- ClassDB::bind_method(D_METHOD("get_color"),&Light2D::get_color);
-
- ClassDB::bind_method(D_METHOD("set_height","height"),&Light2D::set_height);
- ClassDB::bind_method(D_METHOD("get_height"),&Light2D::get_height);
-
- ClassDB::bind_method(D_METHOD("set_energy","energy"),&Light2D::set_energy);
- ClassDB::bind_method(D_METHOD("get_energy"),&Light2D::get_energy);
+ ClassDB::bind_method(D_METHOD("set_editor_only", "editor_only"), &Light2D::set_editor_only);
+ ClassDB::bind_method(D_METHOD("is_editor_only"), &Light2D::is_editor_only);
- ClassDB::bind_method(D_METHOD("set_texture_scale","texture_scale"),&Light2D::set_texture_scale);
- ClassDB::bind_method(D_METHOD("get_texture_scale"),&Light2D::get_texture_scale);
+ ClassDB::bind_method(D_METHOD("set_texture", "texture"), &Light2D::set_texture);
+ ClassDB::bind_method(D_METHOD("get_texture"), &Light2D::get_texture);
+ ClassDB::bind_method(D_METHOD("set_texture_offset", "texture_offset"), &Light2D::set_texture_offset);
+ ClassDB::bind_method(D_METHOD("get_texture_offset"), &Light2D::get_texture_offset);
- ClassDB::bind_method(D_METHOD("set_z_range_min","z"),&Light2D::set_z_range_min);
- ClassDB::bind_method(D_METHOD("get_z_range_min"),&Light2D::get_z_range_min);
+ ClassDB::bind_method(D_METHOD("set_color", "color"), &Light2D::set_color);
+ ClassDB::bind_method(D_METHOD("get_color"), &Light2D::get_color);
- ClassDB::bind_method(D_METHOD("set_z_range_max","z"),&Light2D::set_z_range_max);
- ClassDB::bind_method(D_METHOD("get_z_range_max"),&Light2D::get_z_range_max);
+ ClassDB::bind_method(D_METHOD("set_height", "height"), &Light2D::set_height);
+ ClassDB::bind_method(D_METHOD("get_height"), &Light2D::get_height);
- ClassDB::bind_method(D_METHOD("set_layer_range_min","layer"),&Light2D::set_layer_range_min);
- ClassDB::bind_method(D_METHOD("get_layer_range_min"),&Light2D::get_layer_range_min);
+ ClassDB::bind_method(D_METHOD("set_energy", "energy"), &Light2D::set_energy);
+ ClassDB::bind_method(D_METHOD("get_energy"), &Light2D::get_energy);
- ClassDB::bind_method(D_METHOD("set_layer_range_max","layer"),&Light2D::set_layer_range_max);
- ClassDB::bind_method(D_METHOD("get_layer_range_max"),&Light2D::get_layer_range_max);
+ ClassDB::bind_method(D_METHOD("set_texture_scale", "texture_scale"), &Light2D::set_texture_scale);
+ ClassDB::bind_method(D_METHOD("get_texture_scale"), &Light2D::get_texture_scale);
+ ClassDB::bind_method(D_METHOD("set_z_range_min", "z"), &Light2D::set_z_range_min);
+ ClassDB::bind_method(D_METHOD("get_z_range_min"), &Light2D::get_z_range_min);
- ClassDB::bind_method(D_METHOD("set_item_cull_mask","item_cull_mask"),&Light2D::set_item_cull_mask);
- ClassDB::bind_method(D_METHOD("get_item_cull_mask"),&Light2D::get_item_cull_mask);
+ ClassDB::bind_method(D_METHOD("set_z_range_max", "z"), &Light2D::set_z_range_max);
+ ClassDB::bind_method(D_METHOD("get_z_range_max"), &Light2D::get_z_range_max);
- ClassDB::bind_method(D_METHOD("set_item_shadow_cull_mask","item_shadow_cull_mask"),&Light2D::set_item_shadow_cull_mask);
- ClassDB::bind_method(D_METHOD("get_item_shadow_cull_mask"),&Light2D::get_item_shadow_cull_mask);
+ ClassDB::bind_method(D_METHOD("set_layer_range_min", "layer"), &Light2D::set_layer_range_min);
+ ClassDB::bind_method(D_METHOD("get_layer_range_min"), &Light2D::get_layer_range_min);
- ClassDB::bind_method(D_METHOD("set_mode","mode"),&Light2D::set_mode);
- ClassDB::bind_method(D_METHOD("get_mode"),&Light2D::get_mode);
+ ClassDB::bind_method(D_METHOD("set_layer_range_max", "layer"), &Light2D::set_layer_range_max);
+ ClassDB::bind_method(D_METHOD("get_layer_range_max"), &Light2D::get_layer_range_max);
- ClassDB::bind_method(D_METHOD("set_shadow_enabled","enabled"),&Light2D::set_shadow_enabled);
- ClassDB::bind_method(D_METHOD("is_shadow_enabled"),&Light2D::is_shadow_enabled);
+ ClassDB::bind_method(D_METHOD("set_item_cull_mask", "item_cull_mask"), &Light2D::set_item_cull_mask);
+ ClassDB::bind_method(D_METHOD("get_item_cull_mask"), &Light2D::get_item_cull_mask);
- ClassDB::bind_method(D_METHOD("set_shadow_buffer_size","size"),&Light2D::set_shadow_buffer_size);
- ClassDB::bind_method(D_METHOD("get_shadow_buffer_size"),&Light2D::get_shadow_buffer_size);
+ ClassDB::bind_method(D_METHOD("set_item_shadow_cull_mask", "item_shadow_cull_mask"), &Light2D::set_item_shadow_cull_mask);
+ ClassDB::bind_method(D_METHOD("get_item_shadow_cull_mask"), &Light2D::get_item_shadow_cull_mask);
- ClassDB::bind_method(D_METHOD("set_shadow_gradient_length","multiplier"),&Light2D::set_shadow_gradient_length);
- ClassDB::bind_method(D_METHOD("get_shadow_gradient_length"),&Light2D::get_shadow_gradient_length);
+ ClassDB::bind_method(D_METHOD("set_mode", "mode"), &Light2D::set_mode);
+ ClassDB::bind_method(D_METHOD("get_mode"), &Light2D::get_mode);
- ClassDB::bind_method(D_METHOD("set_shadow_filter","filter"),&Light2D::set_shadow_filter);
- ClassDB::bind_method(D_METHOD("get_shadow_filter"),&Light2D::get_shadow_filter);
+ ClassDB::bind_method(D_METHOD("set_shadow_enabled", "enabled"), &Light2D::set_shadow_enabled);
+ ClassDB::bind_method(D_METHOD("is_shadow_enabled"), &Light2D::is_shadow_enabled);
- ClassDB::bind_method(D_METHOD("set_shadow_color","shadow_color"),&Light2D::set_shadow_color);
- ClassDB::bind_method(D_METHOD("get_shadow_color"),&Light2D::get_shadow_color);
+ ClassDB::bind_method(D_METHOD("set_shadow_buffer_size", "size"), &Light2D::set_shadow_buffer_size);
+ ClassDB::bind_method(D_METHOD("get_shadow_buffer_size"), &Light2D::get_shadow_buffer_size);
+ ClassDB::bind_method(D_METHOD("set_shadow_gradient_length", "multiplier"), &Light2D::set_shadow_gradient_length);
+ ClassDB::bind_method(D_METHOD("get_shadow_gradient_length"), &Light2D::get_shadow_gradient_length);
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"enabled"),"set_enabled","is_enabled");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL, "editor_only"),"set_editor_only","is_editor_only");
- ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"texture",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),"set_texture","get_texture");
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"offset"),"set_texture_offset","get_texture_offset");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"scale",PROPERTY_HINT_RANGE,"0.01,50,0.01"),"set_texture_scale","get_texture_scale");
- ADD_PROPERTY( PropertyInfo(Variant::COLOR,"color"),"set_color","get_color");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"energy",PROPERTY_HINT_RANGE,"0.01,100,0.01"),"set_energy","get_energy");
- ADD_PROPERTY( PropertyInfo(Variant::INT,"mode",PROPERTY_HINT_ENUM,"Add,Sub,Mix,Mask"),"set_mode","get_mode");
- ADD_GROUP("Range","range_");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"range_height",PROPERTY_HINT_RANGE,"-100,100,0.1"),"set_height","get_height");
- ADD_PROPERTY( PropertyInfo(Variant::INT,"range_z_min",PROPERTY_HINT_RANGE,itos(VS::CANVAS_ITEM_Z_MIN)+","+itos(VS::CANVAS_ITEM_Z_MAX)+",1"),"set_z_range_min","get_z_range_min");
- ADD_PROPERTY( PropertyInfo(Variant::INT,"range_z_max",PROPERTY_HINT_RANGE,itos(VS::CANVAS_ITEM_Z_MIN)+","+itos(VS::CANVAS_ITEM_Z_MAX)+",1"),"set_z_range_max","get_z_range_max");
- ADD_PROPERTY( PropertyInfo(Variant::INT,"range_layer_min",PROPERTY_HINT_RANGE,"-512,512,1"),"set_layer_range_min","get_layer_range_min");
- ADD_PROPERTY( PropertyInfo(Variant::INT,"range_layer_max",PROPERTY_HINT_RANGE,"-512,512,1"),"set_layer_range_max","get_layer_range_max");
- ADD_PROPERTY( PropertyInfo(Variant::INT,"range_item_cull_mask",PROPERTY_HINT_LAYERS_2D_RENDER),"set_item_cull_mask","get_item_cull_mask");
+ ClassDB::bind_method(D_METHOD("set_shadow_filter", "filter"), &Light2D::set_shadow_filter);
+ ClassDB::bind_method(D_METHOD("get_shadow_filter"), &Light2D::get_shadow_filter);
- ADD_GROUP("Shadow","shadow_");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"shadow_enabled"),"set_shadow_enabled","is_shadow_enabled");
- ADD_PROPERTY( PropertyInfo(Variant::COLOR,"shadow_color"),"set_shadow_color","get_shadow_color");
- ADD_PROPERTY( PropertyInfo(Variant::INT,"shadow_buffer_size",PROPERTY_HINT_RANGE,"32,16384,1"),"set_shadow_buffer_size","get_shadow_buffer_size");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"shadow_gradient_length",PROPERTY_HINT_RANGE,"1,4096,0.1"),"set_shadow_gradient_length","get_shadow_gradient_length");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"shadow_filter",PROPERTY_HINT_ENUM,"None,PCF3,PCF5,PCF9,PCF13"),"set_shadow_filter","get_shadow_filter");
- ADD_PROPERTY( PropertyInfo(Variant::INT,"shadow_item_cull_mask",PROPERTY_HINT_LAYERS_2D_RENDER),"set_item_shadow_cull_mask","get_item_shadow_cull_mask");
+ ClassDB::bind_method(D_METHOD("set_shadow_color", "shadow_color"), &Light2D::set_shadow_color);
+ ClassDB::bind_method(D_METHOD("get_shadow_color"), &Light2D::get_shadow_color);
- BIND_CONSTANT( MODE_ADD );
- BIND_CONSTANT( MODE_SUB );
- BIND_CONSTANT( MODE_MIX );
- BIND_CONSTANT( MODE_MASK );
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor_only"), "set_editor_only", "is_editor_only");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset"), "set_texture_offset", "get_texture_offset");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "scale", PROPERTY_HINT_RANGE, "0.01,50,0.01"), "set_texture_scale", "get_texture_scale");
+ ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "energy", PROPERTY_HINT_RANGE, "0.01,100,0.01"), "set_energy", "get_energy");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Add,Sub,Mix,Mask"), "set_mode", "get_mode");
+ ADD_GROUP("Range", "range_");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "range_height", PROPERTY_HINT_RANGE, "-100,100,0.1"), "set_height", "get_height");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "range_z_min", PROPERTY_HINT_RANGE, itos(VS::CANVAS_ITEM_Z_MIN) + "," + itos(VS::CANVAS_ITEM_Z_MAX) + ",1"), "set_z_range_min", "get_z_range_min");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "range_z_max", PROPERTY_HINT_RANGE, itos(VS::CANVAS_ITEM_Z_MIN) + "," + itos(VS::CANVAS_ITEM_Z_MAX) + ",1"), "set_z_range_max", "get_z_range_max");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "range_layer_min", PROPERTY_HINT_RANGE, "-512,512,1"), "set_layer_range_min", "get_layer_range_min");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "range_layer_max", PROPERTY_HINT_RANGE, "-512,512,1"), "set_layer_range_max", "get_layer_range_max");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "range_item_cull_mask", PROPERTY_HINT_LAYERS_2D_RENDER), "set_item_cull_mask", "get_item_cull_mask");
+ ADD_GROUP("Shadow", "shadow_");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shadow_enabled"), "set_shadow_enabled", "is_shadow_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::COLOR, "shadow_color"), "set_shadow_color", "get_shadow_color");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "shadow_buffer_size", PROPERTY_HINT_RANGE, "32,16384,1"), "set_shadow_buffer_size", "get_shadow_buffer_size");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "shadow_gradient_length", PROPERTY_HINT_RANGE, "1,4096,0.1"), "set_shadow_gradient_length", "get_shadow_gradient_length");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "shadow_filter", PROPERTY_HINT_ENUM, "None,PCF3,PCF5,PCF9,PCF13"), "set_shadow_filter", "get_shadow_filter");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "shadow_item_cull_mask", PROPERTY_HINT_LAYERS_2D_RENDER), "set_item_shadow_cull_mask", "get_item_shadow_cull_mask");
+ BIND_CONSTANT(MODE_ADD);
+ BIND_CONSTANT(MODE_SUB);
+ BIND_CONSTANT(MODE_MIX);
+ BIND_CONSTANT(MODE_MASK);
}
Light2D::Light2D() {
- canvas_light=VisualServer::get_singleton()->canvas_light_create();
- enabled=true;
- editor_only=false;
- shadow=false;
- color=Color(1,1,1);
- height=0;
- _scale=1.0;
- z_min=-1024;
- z_max=1024;
- layer_min=0;
- layer_max=0;
- item_mask=1;
- item_shadow_mask=1;
- mode=MODE_ADD;
- shadow_buffer_size=2048;
- shadow_gradient_length=0;
- energy=1.0;
- shadow_color=Color(0,0,0,0);
- shadow_filter=SHADOW_FILTER_NONE;
+ canvas_light = VisualServer::get_singleton()->canvas_light_create();
+ enabled = true;
+ editor_only = false;
+ shadow = false;
+ color = Color(1, 1, 1);
+ height = 0;
+ _scale = 1.0;
+ z_min = -1024;
+ z_max = 1024;
+ layer_min = 0;
+ layer_max = 0;
+ item_mask = 1;
+ item_shadow_mask = 1;
+ mode = MODE_ADD;
+ shadow_buffer_size = 2048;
+ shadow_gradient_length = 0;
+ energy = 1.0;
+ shadow_color = Color(0, 0, 0, 0);
+ shadow_filter = SHADOW_FILTER_NONE;
set_notify_transform(true);
}
diff --git a/scene/2d/light_2d.h b/scene/2d/light_2d.h
index 2bdcca5d01..e9f0e069d4 100644
--- a/scene/2d/light_2d.h
+++ b/scene/2d/light_2d.h
@@ -33,7 +33,8 @@
class Light2D : public Node2D {
- GDCLASS(Light2D,Node2D);
+ GDCLASS(Light2D, Node2D);
+
public:
enum Mode {
MODE_ADD,
@@ -73,80 +74,77 @@ private:
Vector2 texture_offset;
ShadowFilter shadow_filter;
-
void _update_light_visibility();
-protected:
+protected:
void _notification(int p_what);
static void _bind_methods();
-public:
-
- virtual void edit_set_pivot(const Point2& p_pivot);
+public:
+ virtual void edit_set_pivot(const Point2 &p_pivot);
virtual Point2 edit_get_pivot() const;
virtual bool edit_has_pivot() const;
- void set_enabled( bool p_enabled);
+ void set_enabled(bool p_enabled);
bool is_enabled() const;
void set_editor_only(bool p_editor_only);
bool is_editor_only() const;
- void set_texture( const Ref<Texture>& p_texture);
+ void set_texture(const Ref<Texture> &p_texture);
Ref<Texture> get_texture() const;
- void set_texture_offset( const Vector2& p_offset);
+ void set_texture_offset(const Vector2 &p_offset);
Vector2 get_texture_offset() const;
- void set_color( const Color& p_color);
+ void set_color(const Color &p_color);
Color get_color() const;
- void set_height( float p_height);
+ void set_height(float p_height);
float get_height() const;
- void set_energy( float p_energy);
+ void set_energy(float p_energy);
float get_energy() const;
- void set_texture_scale( float p_scale);
+ void set_texture_scale(float p_scale);
float get_texture_scale() const;
- void set_z_range_min( int p_min_z);
+ void set_z_range_min(int p_min_z);
int get_z_range_min() const;
- void set_z_range_max( int p_max_z);
+ void set_z_range_max(int p_max_z);
int get_z_range_max() const;
- void set_layer_range_min( int p_min_layer);
+ void set_layer_range_min(int p_min_layer);
int get_layer_range_min() const;
- void set_layer_range_max( int p_max_layer);
+ void set_layer_range_max(int p_max_layer);
int get_layer_range_max() const;
- void set_item_cull_mask( int p_mask);
+ void set_item_cull_mask(int p_mask);
int get_item_cull_mask() const;
- void set_item_shadow_cull_mask( int p_mask);
+ void set_item_shadow_cull_mask(int p_mask);
int get_item_shadow_cull_mask() const;
- void set_mode( Mode p_mode );
+ void set_mode(Mode p_mode);
Mode get_mode() const;
- void set_shadow_enabled( bool p_enabled);
+ void set_shadow_enabled(bool p_enabled);
bool is_shadow_enabled() const;
- void set_shadow_buffer_size( int p_size );
+ void set_shadow_buffer_size(int p_size);
int get_shadow_buffer_size() const;
- void set_shadow_gradient_length( float p_multiplier);
+ void set_shadow_gradient_length(float p_multiplier);
float get_shadow_gradient_length() const;
- void set_shadow_filter( ShadowFilter p_filter);
+ void set_shadow_filter(ShadowFilter p_filter);
ShadowFilter get_shadow_filter() const;
- void set_shadow_color( const Color& p_shadow_color);
+ void set_shadow_color(const Color &p_shadow_color);
Color get_shadow_color() const;
-
virtual Rect2 get_item_rect() const;
String get_configuration_warning() const;
@@ -158,5 +156,4 @@ public:
VARIANT_ENUM_CAST(Light2D::Mode);
VARIANT_ENUM_CAST(Light2D::ShadowFilter);
-
#endif // LIGHT_2D_H
diff --git a/scene/2d/light_occluder_2d.cpp b/scene/2d/light_occluder_2d.cpp
index 6a024fe330..401bbcedb2 100644
--- a/scene/2d/light_occluder_2d.cpp
+++ b/scene/2d/light_occluder_2d.cpp
@@ -28,80 +28,74 @@
/*************************************************************************/
#include "light_occluder_2d.h"
+void OccluderPolygon2D::set_polygon(const PoolVector<Vector2> &p_polygon) {
-void OccluderPolygon2D::set_polygon(const PoolVector<Vector2>& p_polygon) {
-
- polygon=p_polygon;
- VS::get_singleton()->canvas_occluder_polygon_set_shape(occ_polygon,p_polygon,closed);
+ polygon = p_polygon;
+ VS::get_singleton()->canvas_occluder_polygon_set_shape(occ_polygon, p_polygon, closed);
emit_changed();
}
-PoolVector<Vector2> OccluderPolygon2D::get_polygon() const{
+PoolVector<Vector2> OccluderPolygon2D::get_polygon() const {
return polygon;
}
void OccluderPolygon2D::set_closed(bool p_closed) {
- if (closed==p_closed)
+ if (closed == p_closed)
return;
- closed=p_closed;
+ closed = p_closed;
if (polygon.size())
- VS::get_singleton()->canvas_occluder_polygon_set_shape(occ_polygon,polygon,closed);
+ VS::get_singleton()->canvas_occluder_polygon_set_shape(occ_polygon, polygon, closed);
emit_changed();
}
-bool OccluderPolygon2D::is_closed() const{
+bool OccluderPolygon2D::is_closed() const {
return closed;
}
-void OccluderPolygon2D::set_cull_mode(CullMode p_mode){
+void OccluderPolygon2D::set_cull_mode(CullMode p_mode) {
- cull=p_mode;
- VS::get_singleton()->canvas_occluder_polygon_set_cull_mode(occ_polygon,VS::CanvasOccluderPolygonCullMode(p_mode));
+ cull = p_mode;
+ VS::get_singleton()->canvas_occluder_polygon_set_cull_mode(occ_polygon, VS::CanvasOccluderPolygonCullMode(p_mode));
}
-OccluderPolygon2D::CullMode OccluderPolygon2D::get_cull_mode() const{
+OccluderPolygon2D::CullMode OccluderPolygon2D::get_cull_mode() const {
return cull;
}
-
RID OccluderPolygon2D::get_rid() const {
return occ_polygon;
}
-
-
void OccluderPolygon2D::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_closed", "closed"), &OccluderPolygon2D::set_closed);
+ ClassDB::bind_method(D_METHOD("is_closed"), &OccluderPolygon2D::is_closed);
- ClassDB::bind_method(D_METHOD("set_closed","closed"),&OccluderPolygon2D::set_closed);
- ClassDB::bind_method(D_METHOD("is_closed"),&OccluderPolygon2D::is_closed);
+ ClassDB::bind_method(D_METHOD("set_cull_mode", "cull_mode"), &OccluderPolygon2D::set_cull_mode);
+ ClassDB::bind_method(D_METHOD("get_cull_mode"), &OccluderPolygon2D::get_cull_mode);
- ClassDB::bind_method(D_METHOD("set_cull_mode","cull_mode"),&OccluderPolygon2D::set_cull_mode);
- ClassDB::bind_method(D_METHOD("get_cull_mode"),&OccluderPolygon2D::get_cull_mode);
+ ClassDB::bind_method(D_METHOD("set_polygon", "polygon"), &OccluderPolygon2D::set_polygon);
+ ClassDB::bind_method(D_METHOD("get_polygon"), &OccluderPolygon2D::get_polygon);
- ClassDB::bind_method(D_METHOD("set_polygon","polygon"),&OccluderPolygon2D::set_polygon);
- ClassDB::bind_method(D_METHOD("get_polygon"),&OccluderPolygon2D::get_polygon);
-
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"closed"),"set_closed","is_closed");
- ADD_PROPERTY( PropertyInfo(Variant::INT,"cull_mode",PROPERTY_HINT_ENUM,"Disabled,ClockWise,CounterClockWise"),"set_cull_mode","get_cull_mode");
- ADD_PROPERTY( PropertyInfo(Variant::POOL_VECTOR2_ARRAY,"polygon"),"set_polygon","get_polygon");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "closed"), "set_closed", "is_closed");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "cull_mode", PROPERTY_HINT_ENUM, "Disabled,ClockWise,CounterClockWise"), "set_cull_mode", "get_cull_mode");
+ ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR2_ARRAY, "polygon"), "set_polygon", "get_polygon");
BIND_CONSTANT(CULL_DISABLED);
BIND_CONSTANT(CULL_CLOCKWISE);
BIND_CONSTANT(CULL_COUNTER_CLOCKWISE);
}
-
OccluderPolygon2D::OccluderPolygon2D() {
- occ_polygon=VS::get_singleton()->canvas_occluder_polygon_create();
- closed=true;
- cull=CULL_DISABLED;
+ occ_polygon = VS::get_singleton()->canvas_occluder_polygon_create();
+ closed = true;
+ cull = CULL_DISABLED;
}
OccluderPolygon2D::~OccluderPolygon2D() {
@@ -116,26 +110,24 @@ void LightOccluder2D::_poly_changed() {
}
#endif
-
void LightOccluder2D::_notification(int p_what) {
- if (p_what==NOTIFICATION_ENTER_CANVAS) {
-
- VS::get_singleton()->canvas_light_occluder_attach_to_canvas(occluder,get_canvas());
- VS::get_singleton()->canvas_light_occluder_set_transform(occluder,get_global_transform());
- VS::get_singleton()->canvas_light_occluder_set_enabled(occluder,is_visible_in_tree());
+ if (p_what == NOTIFICATION_ENTER_CANVAS) {
+ VS::get_singleton()->canvas_light_occluder_attach_to_canvas(occluder, get_canvas());
+ VS::get_singleton()->canvas_light_occluder_set_transform(occluder, get_global_transform());
+ VS::get_singleton()->canvas_light_occluder_set_enabled(occluder, is_visible_in_tree());
}
- if (p_what==NOTIFICATION_TRANSFORM_CHANGED) {
+ if (p_what == NOTIFICATION_TRANSFORM_CHANGED) {
- VS::get_singleton()->canvas_light_occluder_set_transform(occluder,get_global_transform());
+ VS::get_singleton()->canvas_light_occluder_set_transform(occluder, get_global_transform());
}
- if (p_what==NOTIFICATION_VISIBILITY_CHANGED) {
+ if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
- VS::get_singleton()->canvas_light_occluder_set_enabled(occluder,is_visible_in_tree());
+ VS::get_singleton()->canvas_light_occluder_set_enabled(occluder, is_visible_in_tree());
}
- if (p_what==NOTIFICATION_DRAW) {
+ if (p_what == NOTIFICATION_DRAW) {
if (get_tree()->is_editor_hint()) {
@@ -146,15 +138,15 @@ void LightOccluder2D::_notification(int p_what) {
if (poly.size()) {
if (occluder_polygon->is_closed()) {
Vector<Color> color;
- color.push_back(Color(0,0,0,0.6));
- draw_polygon(Variant(poly),color);
+ color.push_back(Color(0, 0, 0, 0.6));
+ draw_polygon(Variant(poly), color);
} else {
- int ps=poly.size();
+ int ps = poly.size();
PoolVector<Vector2>::Read r = poly.read();
- for(int i=0;i<ps-1;i++) {
+ for (int i = 0; i < ps - 1; i++) {
- draw_line(r[i],r[i+1],Color(0,0,0,0.6),3);
+ draw_line(r[i], r[i + 1], Color(0, 0, 0, 0.6), 3);
}
}
}
@@ -162,34 +154,30 @@ void LightOccluder2D::_notification(int p_what) {
}
}
+ if (p_what == NOTIFICATION_EXIT_CANVAS) {
- if (p_what==NOTIFICATION_EXIT_CANVAS) {
-
- VS::get_singleton()->canvas_light_occluder_attach_to_canvas(occluder,RID());
+ VS::get_singleton()->canvas_light_occluder_attach_to_canvas(occluder, RID());
}
-
-
}
-void LightOccluder2D::set_occluder_polygon(const Ref<OccluderPolygon2D>& p_polygon) {
+void LightOccluder2D::set_occluder_polygon(const Ref<OccluderPolygon2D> &p_polygon) {
#ifdef DEBUG_ENABLED
if (occluder_polygon.is_valid())
- occluder_polygon->disconnect("changed",this,"_poly_changed");
+ occluder_polygon->disconnect("changed", this, "_poly_changed");
#endif
- occluder_polygon=p_polygon;
+ occluder_polygon = p_polygon;
if (occluder_polygon.is_valid())
- VS::get_singleton()->canvas_light_occluder_set_polygon(occluder,occluder_polygon->get_rid());
+ VS::get_singleton()->canvas_light_occluder_set_polygon(occluder, occluder_polygon->get_rid());
else
- VS::get_singleton()->canvas_light_occluder_set_polygon(occluder,RID());
+ VS::get_singleton()->canvas_light_occluder_set_polygon(occluder, RID());
#ifdef DEBUG_ENABLED
if (occluder_polygon.is_valid())
- occluder_polygon->connect("changed",this,"_poly_changed");
+ occluder_polygon->connect("changed", this, "_poly_changed");
update();
#endif
-
}
Ref<OccluderPolygon2D> LightOccluder2D::get_occluder_polygon() const {
@@ -199,23 +187,22 @@ Ref<OccluderPolygon2D> LightOccluder2D::get_occluder_polygon() const {
void LightOccluder2D::set_occluder_light_mask(int p_mask) {
- mask=p_mask;
- VS::get_singleton()->canvas_light_occluder_set_light_mask(occluder,mask);
+ mask = p_mask;
+ VS::get_singleton()->canvas_light_occluder_set_light_mask(occluder, mask);
}
-int LightOccluder2D::get_occluder_light_mask() const{
+int LightOccluder2D::get_occluder_light_mask() const {
return mask;
}
-
String LightOccluder2D::get_configuration_warning() const {
if (!occluder_polygon.is_valid()) {
return TTR("An occluder polygon must be set (or drawn) for this occluder to take effect.");
}
- if (occluder_polygon.is_valid() && occluder_polygon->get_polygon().size()==0) {
+ if (occluder_polygon.is_valid() && occluder_polygon->get_polygon().size() == 0) {
return TTR("The occluder polygon for this occluder is empty. Please draw a polygon!");
}
@@ -224,24 +211,24 @@ String LightOccluder2D::get_configuration_warning() const {
void LightOccluder2D::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_occluder_polygon","polygon:OccluderPolygon2D"),&LightOccluder2D::set_occluder_polygon);
- ClassDB::bind_method(D_METHOD("get_occluder_polygon:OccluderPolygon2D"),&LightOccluder2D::get_occluder_polygon);
+ ClassDB::bind_method(D_METHOD("set_occluder_polygon", "polygon:OccluderPolygon2D"), &LightOccluder2D::set_occluder_polygon);
+ ClassDB::bind_method(D_METHOD("get_occluder_polygon:OccluderPolygon2D"), &LightOccluder2D::get_occluder_polygon);
- ClassDB::bind_method(D_METHOD("set_occluder_light_mask","mask"),&LightOccluder2D::set_occluder_light_mask);
- ClassDB::bind_method(D_METHOD("get_occluder_light_mask"),&LightOccluder2D::get_occluder_light_mask);
+ ClassDB::bind_method(D_METHOD("set_occluder_light_mask", "mask"), &LightOccluder2D::set_occluder_light_mask);
+ ClassDB::bind_method(D_METHOD("get_occluder_light_mask"), &LightOccluder2D::get_occluder_light_mask);
#ifdef DEBUG_ENABLED
- ClassDB::bind_method("_poly_changed",&LightOccluder2D::_poly_changed);
+ ClassDB::bind_method("_poly_changed", &LightOccluder2D::_poly_changed);
#endif
- ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"occluder",PROPERTY_HINT_RESOURCE_TYPE,"OccluderPolygon2D"),"set_occluder_polygon","get_occluder_polygon");
- ADD_PROPERTY( PropertyInfo(Variant::INT,"light_mask",PROPERTY_HINT_LAYERS_2D_RENDER),"set_occluder_light_mask","get_occluder_light_mask");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "occluder", PROPERTY_HINT_RESOURCE_TYPE, "OccluderPolygon2D"), "set_occluder_polygon", "get_occluder_polygon");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "light_mask", PROPERTY_HINT_LAYERS_2D_RENDER), "set_occluder_light_mask", "get_occluder_light_mask");
}
LightOccluder2D::LightOccluder2D() {
- occluder=VS::get_singleton()->canvas_light_occluder_create();
- mask=1;
+ occluder = VS::get_singleton()->canvas_light_occluder_create();
+ mask = 1;
set_notify_transform(true);
}
@@ -249,4 +236,3 @@ LightOccluder2D::~LightOccluder2D() {
VS::get_singleton()->free(occluder);
}
-
diff --git a/scene/2d/light_occluder_2d.h b/scene/2d/light_occluder_2d.h
index 777785cd1d..26135334fc 100644
--- a/scene/2d/light_occluder_2d.h
+++ b/scene/2d/light_occluder_2d.h
@@ -33,28 +33,26 @@
class OccluderPolygon2D : public Resource {
- GDCLASS(OccluderPolygon2D,Resource);
-public:
+ GDCLASS(OccluderPolygon2D, Resource);
+public:
enum CullMode {
CULL_DISABLED,
CULL_CLOCKWISE,
CULL_COUNTER_CLOCKWISE
};
-private:
-
+private:
RID occ_polygon;
PoolVector<Vector2> polygon;
bool closed;
CullMode cull;
protected:
-
static void _bind_methods();
-public:
- void set_polygon(const PoolVector<Vector2>& p_polygon);
+public:
+ void set_polygon(const PoolVector<Vector2> &p_polygon);
PoolVector<Vector2> get_polygon() const;
void set_closed(bool p_closed);
@@ -66,13 +64,12 @@ public:
virtual RID get_rid() const;
OccluderPolygon2D();
~OccluderPolygon2D();
-
};
VARIANT_ENUM_CAST(OccluderPolygon2D::CullMode);
class LightOccluder2D : public Node2D {
- GDCLASS(LightOccluder2D,Node2D);
+ GDCLASS(LightOccluder2D, Node2D);
RID occluder;
bool enabled;
@@ -86,9 +83,9 @@ class LightOccluder2D : public Node2D {
protected:
void _notification(int p_what);
static void _bind_methods();
-public:
- void set_occluder_polygon(const Ref<OccluderPolygon2D>& p_polygon);
+public:
+ void set_occluder_polygon(const Ref<OccluderPolygon2D> &p_polygon);
Ref<OccluderPolygon2D> get_occluder_polygon() const;
void set_occluder_light_mask(int p_mask);
diff --git a/scene/2d/line_2d.cpp b/scene/2d/line_2d.cpp
index 059711549f..cd9b8e8cb9 100644
--- a/scene/2d/line_2d.cpp
+++ b/scene/2d/line_2d.cpp
@@ -30,19 +30,18 @@
#include "core_string_names.h"
-
// Needed so we can bind functions
VARIANT_ENUM_CAST(LineJointMode)
VARIANT_ENUM_CAST(LineCapMode)
VARIANT_ENUM_CAST(LineTextureMode)
-
-Line2D::Line2D() : Node2D() {
+Line2D::Line2D()
+ : Node2D() {
_joint_mode = LINE_JOINT_SHARP;
_begin_cap_mode = LINE_CAP_NONE;
_end_cap_mode = LINE_CAP_NONE;
_width = 10;
- _default_color = Color(0.4,0.5,1);
+ _default_color = Color(0.4, 0.5, 1);
_sharp_limit = 2.f;
_round_precision = 8;
}
@@ -53,7 +52,7 @@ void Line2D::set_points(const PoolVector<Vector2> &p_points) {
}
void Line2D::set_width(float width) {
- if(width < 0.0)
+ if (width < 0.0)
width = 0.0;
_width = width;
update();
@@ -99,17 +98,17 @@ Color Line2D::get_default_color() const {
return _default_color;
}
-void Line2D::set_gradient(const Ref<ColorRamp>& gradient) {
+void Line2D::set_gradient(const Ref<ColorRamp> &gradient) {
// Cleanup previous connection if any
- if(_gradient.is_valid()) {
+ if (_gradient.is_valid()) {
(**_gradient).disconnect(CoreStringNames::get_singleton()->changed, this, "_gradient_changed");
}
_gradient = gradient;
// Connect to the gradient so the line will update when the ColorRamp is changed
- if(_gradient.is_valid()) {
+ if (_gradient.is_valid()) {
(**_gradient).connect(CoreStringNames::get_singleton()->changed, this, "_gradient_changed");
}
@@ -120,7 +119,7 @@ Ref<ColorRamp> Line2D::get_gradient() const {
return _gradient;
}
-void Line2D::set_texture(const Ref<Texture>& texture) {
+void Line2D::set_texture(const Ref<Texture> &texture) {
_texture = texture;
update();
}
@@ -166,15 +165,15 @@ LineCapMode Line2D::get_end_cap_mode() const {
}
void Line2D::_notification(int p_what) {
- switch(p_what) {
- case NOTIFICATION_DRAW:
- _draw();
- break;
+ switch (p_what) {
+ case NOTIFICATION_DRAW:
+ _draw();
+ break;
}
}
void Line2D::set_sharp_limit(float limit) {
- if(limit < 0.f)
+ if (limit < 0.f)
limit = 0.f;
_sharp_limit = limit;
update();
@@ -185,7 +184,7 @@ float Line2D::get_sharp_limit() const {
}
void Line2D::set_round_precision(int precision) {
- if(precision < 1)
+ if (precision < 1)
precision = 1;
_round_precision = precision;
update();
@@ -196,16 +195,17 @@ int Line2D::get_round_precision() const {
}
void Line2D::_draw() {
- if(_points.size() <= 1 || _width == 0.f)
+ if (_points.size() <= 1 || _width == 0.f)
return;
// TODO Is this really needed?
// Copy points for faster access
Vector<Vector2> points;
points.resize(_points.size());
- int len = points.size(); {
+ int len = points.size();
+ {
PoolVector<Vector2>::Read points_read = _points.read();
- for(int i = 0; i < len; ++i) {
+ for (int i = 0; i < len; ++i) {
points[i] = points_read[i];
}
}
@@ -226,36 +226,36 @@ void Line2D::_draw() {
lb.build();
RID texture_rid;
- if(_texture.is_valid())
+ if (_texture.is_valid())
texture_rid = (**_texture).get_rid();
VS::get_singleton()->canvas_item_add_triangle_array(
- get_canvas_item(),
- lb.indices,
- lb.vertices,
- lb.colors,
- lb.uvs,
- texture_rid);
+ get_canvas_item(),
+ lb.indices,
+ lb.vertices,
+ lb.colors,
+ lb.uvs,
+ texture_rid);
// DEBUG
// Draw wireframe
-// if(lb.indices.size() % 3 == 0) {
-// Color col(0,0,0);
-// for(int i = 0; i < lb.indices.size(); i += 3) {
-// int vi = lb.indices[i];
-// int lbvsize = lb.vertices.size();
-// Vector2 a = lb.vertices[lb.indices[i]];
-// Vector2 b = lb.vertices[lb.indices[i+1]];
-// Vector2 c = lb.vertices[lb.indices[i+2]];
-// draw_line(a, b, col);
-// draw_line(b, c, col);
-// draw_line(c, a, col);
-// }
-// for(int i = 0; i < lb.vertices.size(); ++i) {
-// Vector2 p = lb.vertices[i];
-// draw_rect(Rect2(p.x-1, p.y-1, 2, 2), Color(0,0,0,0.5));
-// }
-// }
+ // if(lb.indices.size() % 3 == 0) {
+ // Color col(0,0,0);
+ // for(int i = 0; i < lb.indices.size(); i += 3) {
+ // int vi = lb.indices[i];
+ // int lbvsize = lb.vertices.size();
+ // Vector2 a = lb.vertices[lb.indices[i]];
+ // Vector2 b = lb.vertices[lb.indices[i+1]];
+ // Vector2 c = lb.vertices[lb.indices[i+2]];
+ // draw_line(a, b, col);
+ // draw_line(b, c, col);
+ // draw_line(c, a, col);
+ // }
+ // for(int i = 0; i < lb.vertices.size(); ++i) {
+ // Vector2 p = lb.vertices[i];
+ // draw_rect(Rect2(p.x-1, p.y-1, 2, 2), Color(0,0,0,0.5));
+ // }
+ // }
}
void Line2D::_gradient_changed() {
@@ -265,10 +265,10 @@ void Line2D::_gradient_changed() {
// static
void Line2D::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_points","points"), &Line2D::set_points);
+ ClassDB::bind_method(D_METHOD("set_points", "points"), &Line2D::set_points);
ClassDB::bind_method(D_METHOD("get_points"), &Line2D::get_points);
- ClassDB::bind_method(D_METHOD("set_point_pos","i", "pos"), &Line2D::set_point_pos);
+ ClassDB::bind_method(D_METHOD("set_point_pos", "i", "pos"), &Line2D::set_point_pos);
ClassDB::bind_method(D_METHOD("get_point_pos", "i"), &Line2D::get_point_pos);
ClassDB::bind_method(D_METHOD("get_point_count"), &Line2D::get_point_count);
@@ -276,7 +276,7 @@ void Line2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("add_point", "pos"), &Line2D::add_point);
ClassDB::bind_method(D_METHOD("remove_point", "i"), &Line2D::remove_point);
- ClassDB::bind_method(D_METHOD("set_width","width"), &Line2D::set_width);
+ ClassDB::bind_method(D_METHOD("set_width", "width"), &Line2D::set_width);
ClassDB::bind_method(D_METHOD("get_width"), &Line2D::get_width);
ClassDB::bind_method(D_METHOD("set_default_color", "color"), &Line2D::set_default_color);
@@ -309,12 +309,12 @@ void Line2D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR2_ARRAY, "points"), "set_points", "get_points");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "width"), "set_width", "get_width");
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "default_color"), "set_default_color", "get_default_color");
- ADD_PROPERTYNZ( PropertyInfo( Variant::OBJECT, "gradient", PROPERTY_HINT_RESOURCE_TYPE, "ColorRamp"), "set_gradient", "get_gradient");
- ADD_PROPERTYNZ( PropertyInfo( Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture");
- ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "texture_mode", PROPERTY_HINT_ENUM, "None,Tile" ), "set_texture_mode","get_texture_mode");
- ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "joint_mode", PROPERTY_HINT_ENUM, "Sharp,Bevel,Round" ), "set_joint_mode","get_joint_mode");
- ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "begin_cap_mode", PROPERTY_HINT_ENUM, "None,Box,Round" ), "set_begin_cap_mode","get_begin_cap_mode");
- ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "end_cap_mode", PROPERTY_HINT_ENUM, "None,Box,Round" ), "set_end_cap_mode","get_end_cap_mode");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "gradient", PROPERTY_HINT_RESOURCE_TYPE, "ColorRamp"), "set_gradient", "get_gradient");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "texture_mode", PROPERTY_HINT_ENUM, "None,Tile"), "set_texture_mode", "get_texture_mode");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "joint_mode", PROPERTY_HINT_ENUM, "Sharp,Bevel,Round"), "set_joint_mode", "get_joint_mode");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "begin_cap_mode", PROPERTY_HINT_ENUM, "None,Box,Round"), "set_begin_cap_mode", "get_begin_cap_mode");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "end_cap_mode", PROPERTY_HINT_ENUM, "None,Box,Round"), "set_end_cap_mode", "get_end_cap_mode");
ADD_PROPERTY(PropertyInfo(Variant::REAL, "sharp_limit"), "set_sharp_limit", "get_sharp_limit");
ADD_PROPERTY(PropertyInfo(Variant::INT, "round_precision"), "set_round_precision", "get_round_precision");
@@ -330,7 +330,4 @@ void Line2D::_bind_methods() {
BIND_CONSTANT(LINE_TEXTURE_TILE);
ClassDB::bind_method(D_METHOD("_gradient_changed"), &Line2D::_gradient_changed);
-
}
-
-
diff --git a/scene/2d/line_2d.h b/scene/2d/line_2d.h
index 5435c7489f..2cd71e9727 100644
--- a/scene/2d/line_2d.h
+++ b/scene/2d/line_2d.h
@@ -29,9 +29,8 @@
#ifndef LINE2D_H
#define LINE2D_H
-#include "node_2d.h"
#include "line_builder.h"
-
+#include "node_2d.h"
class Line2D : public Node2D {
@@ -40,7 +39,7 @@ class Line2D : public Node2D {
public:
Line2D();
- void set_points(const PoolVector<Vector2> & p_points);
+ void set_points(const PoolVector<Vector2> &p_points);
PoolVector<Vector2> get_points() const;
void set_point_pos(int i, Vector2 pos);
@@ -57,10 +56,10 @@ public:
void set_default_color(Color color);
Color get_default_color() const;
- void set_gradient(const Ref<ColorRamp>& gradient);
+ void set_gradient(const Ref<ColorRamp> &gradient);
Ref<ColorRamp> get_gradient() const;
- void set_texture(const Ref<Texture>& texture);
+ void set_texture(const Ref<Texture> &texture);
Ref<Texture> get_texture() const;
void set_texture_mode(const LineTextureMode mode);
@@ -102,7 +101,6 @@ private:
LineTextureMode _texture_mode;
float _sharp_limit;
int _round_precision;
-
};
#endif // LINE2D_H
diff --git a/scene/2d/line_builder.cpp b/scene/2d/line_builder.cpp
index 69543f004d..0912f6cfe8 100644
--- a/scene/2d/line_builder.cpp
+++ b/scene/2d/line_builder.cpp
@@ -40,19 +40,18 @@ enum SegmentIntersectionResult {
static SegmentIntersectionResult segment_intersection(
Vector2 a, Vector2 b, Vector2 c, Vector2 d,
- Vector2 * out_intersection)
-{
+ Vector2 *out_intersection) {
// http://paulbourke.net/geometry/pointlineplane/ <-- Good stuff
Vector2 cd = d - c;
Vector2 ab = b - a;
- float div = cd.y*ab.x - cd.x*ab.y;
+ float div = cd.y * ab.x - cd.x * ab.y;
- if(Math::abs(div) > 0.001f) {
- float ua = (cd.x * (a.y-c.y) - cd.y * (a.x-c.x)) / div;
- float ub = (ab.x * (a.y-c.y) - ab.y * (a.x-c.x)) / div;
+ if (Math::abs(div) > 0.001f) {
+ float ua = (cd.x * (a.y - c.y) - cd.y * (a.x - c.x)) / div;
+ float ub = (ab.x * (a.y - c.y) - ab.y * (a.x - c.x)) / div;
*out_intersection = a + ua * ab;
- if(ua >= 0.f && ua <= 1.f &&
- ub >= 0.f && ub <= 1.f)
+ if (ua >= 0.f && ua <= 1.f &&
+ ub >= 0.f && ub <= 1.f)
return SEGMENT_INTERSECT;
return SEGMENT_NO_INTERSECT;
}
@@ -62,30 +61,29 @@ static SegmentIntersectionResult segment_intersection(
// TODO I'm pretty sure there is an even faster way to swap things
template <typename T>
-static inline void swap(T & a, T & b) {
+static inline void swap(T &a, T &b) {
T tmp = a;
a = b;
b = tmp;
}
-static float calculate_total_distance(const Vector<Vector2> & points) {
+static float calculate_total_distance(const Vector<Vector2> &points) {
float d = 0.f;
- for(int i = 1; i < points.size(); ++i) {
- d += points[i].distance_to(points[i-1]);
+ for (int i = 1; i < points.size(); ++i) {
+ d += points[i].distance_to(points[i - 1]);
}
return d;
}
-static inline Vector2 rotate90(const Vector2 & v) {
+static inline Vector2 rotate90(const Vector2 &v) {
// Note: the 2D referential is X-right, Y-down
return Vector2(v.y, -v.x);
}
-static inline Vector2 interpolate(const Rect2 & r, const Vector2 & v) {
+static inline Vector2 interpolate(const Rect2 &r, const Vector2 &v) {
return Vector2(
- Math::lerp(r.get_pos().x, r.get_pos().x + r.get_size().x, v.x),
- Math::lerp(r.get_pos().y, r.get_pos().y + r.get_size().y, v.y)
- );
+ Math::lerp(r.get_pos().x, r.get_pos().x + r.get_size().x, v.x),
+ Math::lerp(r.get_pos().y, r.get_pos().y + r.get_size().y, v.y));
}
//----------------------------------------------------------------------------
@@ -95,7 +93,7 @@ static inline Vector2 interpolate(const Rect2 & r, const Vector2 & v) {
LineBuilder::LineBuilder() {
joint_mode = LINE_JOINT_SHARP;
width = 10;
- default_color = Color(0.4,0.5,1);
+ default_color = Color(0.4, 0.5, 1);
gradient = NULL;
sharp_limit = 2.f;
round_precision = 8;
@@ -107,7 +105,6 @@ LineBuilder::LineBuilder() {
_last_index[1] = 0;
}
-
void LineBuilder::clear_output() {
vertices.clear();
colors.clear();
@@ -117,13 +114,13 @@ void LineBuilder::clear_output() {
void LineBuilder::build() {
// Need at least 2 points to draw a line
- if(points.size() < 2) {
+ if (points.size() < 2) {
clear_output();
return;
}
const float hw = width / 2.f;
- const float hw_sq = hw*hw;
+ const float hw_sq = hw * hw;
const float sharp_limit_sq = sharp_limit * sharp_limit;
const int len = points.size();
@@ -144,9 +141,9 @@ void LineBuilder::build() {
float total_distance;
_interpolate_color = gradient != NULL;
bool distance_required = _interpolate_color || texture_mode == LINE_TEXTURE_TILE;
- if(distance_required)
+ if (distance_required)
total_distance = calculate_total_distance(points);
- if(_interpolate_color)
+ if (_interpolate_color)
color0 = gradient->get_color(0);
else
colors.push_back(default_color);
@@ -155,7 +152,7 @@ void LineBuilder::build() {
float uvx1 = 0.f;
// Begin cap
- if(begin_cap_mode == LINE_CAP_BOX) {
+ if (begin_cap_mode == LINE_CAP_BOX) {
// Push back first vertices a little bit
pos_up0 -= f0 * hw;
pos_down0 -= f0 * hw;
@@ -163,9 +160,8 @@ void LineBuilder::build() {
total_distance += width;
current_distance0 += hw;
current_distance1 = current_distance0;
- }
- else if(begin_cap_mode == LINE_CAP_ROUND) {
- if(texture_mode == LINE_TEXTURE_TILE) {
+ } else if (begin_cap_mode == LINE_CAP_ROUND) {
+ if (texture_mode == LINE_TEXTURE_TILE) {
uvx0 = 0.5f;
}
new_arc(pos0, pos_up0 - pos0, -Math_PI, color0, Rect2(0.f, 0.f, 1.f, 1.f));
@@ -188,10 +184,10 @@ void LineBuilder::build() {
// (not the same implementation but visuals help a lot)
// For each additional segment
- for(int i = 1; i < len-1; ++i) {
+ for (int i = 1; i < len - 1; ++i) {
pos1 = points[i];
- Vector2 pos2 = points[i+1];
+ Vector2 pos2 = points[i + 1];
Vector2 f1 = (pos2 - pos1).normalized();
Vector2 u1 = rotate90(f1);
@@ -201,11 +197,10 @@ void LineBuilder::build() {
const Orientation orientation = (dp > 0.f ? UP : DOWN);
Vector2 inner_normal0, inner_normal1;
- if(orientation == UP) {
+ if (orientation == UP) {
inner_normal0 = u0 * hw;
inner_normal1 = u1 * hw;
- }
- else {
+ } else {
inner_normal0 = -u0 * hw;
inner_normal1 = -u1 * hw;
}
@@ -225,11 +220,11 @@ void LineBuilder::build() {
// Find inner intersection at the joint
Vector2 corner_pos_in, corner_pos_out;
SegmentIntersectionResult intersection_result = segment_intersection(
- pos0 + inner_normal0, pos1 + inner_normal0,
- pos1 + inner_normal1, pos2 + inner_normal1,
- &corner_pos_in);
+ pos0 + inner_normal0, pos1 + inner_normal0,
+ pos1 + inner_normal1, pos2 + inner_normal1,
+ &corner_pos_in);
- if(intersection_result == SEGMENT_INTERSECT)
+ if (intersection_result == SEGMENT_INTERSECT)
// Inner parts of the segments intersect
corner_pos_out = 2.f * pos1 - corner_pos_in;
else {
@@ -239,11 +234,10 @@ void LineBuilder::build() {
}
Vector2 corner_pos_up, corner_pos_down;
- if(orientation == UP) {
+ if (orientation == UP) {
corner_pos_up = corner_pos_in;
corner_pos_down = corner_pos_out;
- }
- else {
+ } else {
corner_pos_up = corner_pos_out;
corner_pos_down = corner_pos_in;
}
@@ -251,30 +245,27 @@ void LineBuilder::build() {
LineJointMode current_joint_mode = joint_mode;
Vector2 pos_up1, pos_down1;
- if(intersection_result == SEGMENT_INTERSECT) {
+ if (intersection_result == SEGMENT_INTERSECT) {
// Fallback on bevel if sharp angle is too high (because it would produce very long miters)
- if(current_joint_mode == LINE_JOINT_SHARP && corner_pos_out.distance_squared_to(pos1) / hw_sq > sharp_limit_sq) {
+ if (current_joint_mode == LINE_JOINT_SHARP && corner_pos_out.distance_squared_to(pos1) / hw_sq > sharp_limit_sq) {
current_joint_mode = LINE_JOINT_BEVEL;
}
- if(current_joint_mode == LINE_JOINT_SHARP) {
+ if (current_joint_mode == LINE_JOINT_SHARP) {
// In this case, we won't create joint geometry,
// The previous and next line quads will directly share an edge.
pos_up1 = corner_pos_up;
pos_down1 = corner_pos_down;
- }
- else {
+ } else {
// Bevel or round
- if(orientation == UP) {
+ if (orientation == UP) {
pos_up1 = corner_pos_up;
pos_down1 = pos1 - u0 * hw;
- }
- else {
+ } else {
pos_up1 = pos1 + u0 * hw;
pos_down1 = corner_pos_down;
}
}
- }
- else {
+ } else {
// No intersection: fallback
pos_up1 = corner_pos_up;
pos_down1 = corner_pos_down;
@@ -282,13 +273,13 @@ void LineBuilder::build() {
// Add current line body quad
// Triangles are clockwise
- if(distance_required) {
+ if (distance_required) {
current_distance1 += pos0.distance_to(pos1);
}
- if(_interpolate_color) {
+ if (_interpolate_color) {
color1 = gradient->get_color_at_offset(current_distance1 / total_distance);
}
- if(texture_mode == LINE_TEXTURE_TILE) {
+ if (texture_mode == LINE_TEXTURE_TILE) {
uvx0 = current_distance0 / width;
uvx1 = current_distance1 / width;
}
@@ -301,30 +292,27 @@ void LineBuilder::build() {
f0 = f1;
pos0 = pos1;
current_distance0 = current_distance1;
- if(intersection_result == SEGMENT_INTERSECT) {
- if(current_joint_mode == LINE_JOINT_SHARP) {
+ if (intersection_result == SEGMENT_INTERSECT) {
+ if (current_joint_mode == LINE_JOINT_SHARP) {
pos_up0 = pos_up1;
pos_down0 = pos_down1;
- }
- else {
- if(orientation == UP) {
+ } else {
+ if (orientation == UP) {
pos_up0 = corner_pos_up;
pos_down0 = pos1 - u1 * hw;
- }
- else {
+ } else {
pos_up0 = pos1 + u1 * hw;
pos_down0 = corner_pos_down;
}
}
- }
- else {
+ } else {
pos_up0 = pos1 + u1 * hw;
pos_down0 = pos1 - u1 * hw;
}
// From this point, bu0 and bd0 concern the next segment
// Add joint geometry
- if(current_joint_mode != LINE_JOINT_SHARP) {
+ if (current_joint_mode != LINE_JOINT_SHARP) {
// ________________ cbegin
// / \
@@ -335,25 +323,23 @@ void LineBuilder::build() {
// | |
Vector2 cbegin, cend;
- if(orientation == UP) {
+ if (orientation == UP) {
cbegin = pos_down1;
cend = pos_down0;
- }
- else {
+ } else {
cbegin = pos_up1;
cend = pos_up0;
}
- if(current_joint_mode == LINE_JOINT_BEVEL) {
+ if (current_joint_mode == LINE_JOINT_BEVEL) {
strip_add_tri(cend, orientation);
- }
- else if(current_joint_mode == LINE_JOINT_ROUND) {
+ } else if (current_joint_mode == LINE_JOINT_ROUND) {
Vector2 vbegin = cbegin - pos1;
Vector2 vend = cend - pos1;
strip_add_arc(pos1, vend.angle_to(vbegin), orientation);
}
- if(intersection_result != SEGMENT_INTERSECT)
+ if (intersection_result != SEGMENT_INTERSECT)
// In this case the joint is too fucked up to be re-used,
// start again the strip with fallback points
strip_begin(pos_up0, pos_down0, color1, uvx1);
@@ -362,34 +348,34 @@ void LineBuilder::build() {
// Last (or only) segment
- pos1 = points[points.size()-1];
+ pos1 = points[points.size() - 1];
Vector2 pos_up1 = pos1 + u0 * hw;
Vector2 pos_down1 = pos1 - u0 * hw;
// End cap (box)
- if(end_cap_mode == LINE_CAP_BOX) {
+ if (end_cap_mode == LINE_CAP_BOX) {
pos_up1 += f0 * hw;
pos_down1 += f0 * hw;
}
- if(distance_required) {
+ if (distance_required) {
current_distance1 += pos0.distance_to(pos1);
}
- if(_interpolate_color) {
- color1 = gradient->get_color(gradient->get_points_count()-1);
+ if (_interpolate_color) {
+ color1 = gradient->get_color(gradient->get_points_count() - 1);
}
- if(texture_mode == LINE_TEXTURE_TILE) {
+ if (texture_mode == LINE_TEXTURE_TILE) {
uvx1 = current_distance1 / width;
}
strip_add_quad(pos_up1, pos_down1, color1, uvx1);
// End cap (round)
- if(end_cap_mode == LINE_CAP_ROUND) {
+ if (end_cap_mode == LINE_CAP_ROUND) {
// Note: color is not used in case we don't interpolate...
- Color color = _interpolate_color ? gradient->get_color(gradient->get_points_count()-1) : Color(0,0,0);
- new_arc(pos1, pos_up1 - pos1, Math_PI, color, Rect2(uvx1-0.5f, 0.f, 1.f, 1.f));
+ Color color = _interpolate_color ? gradient->get_color(gradient->get_points_count() - 1) : Color(0, 0, 0);
+ new_arc(pos1, pos_up1 - pos1, Math_PI, color, Rect2(uvx1 - 0.5f, 0.f, 1.f, 1.f));
}
}
@@ -399,18 +385,18 @@ void LineBuilder::strip_begin(Vector2 up, Vector2 down, Color color, float uvx)
vertices.push_back(up);
vertices.push_back(down);
- if(_interpolate_color) {
+ if (_interpolate_color) {
colors.push_back(color);
colors.push_back(color);
}
- if(texture_mode != LINE_TEXTURE_NONE) {
+ if (texture_mode != LINE_TEXTURE_NONE) {
uvs.push_back(Vector2(uvx, 0.f));
uvs.push_back(Vector2(uvx, 1.f));
}
_last_index[UP] = vi;
- _last_index[DOWN] = vi+1;
+ _last_index[DOWN] = vi + 1;
}
void LineBuilder::strip_new_quad(Vector2 up, Vector2 down, Color color, float uvx) {
@@ -421,14 +407,14 @@ void LineBuilder::strip_new_quad(Vector2 up, Vector2 down, Color color, float uv
vertices.push_back(up);
vertices.push_back(down);
- if(_interpolate_color) {
+ if (_interpolate_color) {
colors.push_back(color);
colors.push_back(color);
colors.push_back(color);
colors.push_back(color);
}
- if(texture_mode != LINE_TEXTURE_NONE) {
+ if (texture_mode != LINE_TEXTURE_NONE) {
uvs.push_back(uvs[_last_index[UP]]);
uvs.push_back(uvs[_last_index[DOWN]]);
uvs.push_back(Vector2(uvx, UP));
@@ -436,14 +422,14 @@ void LineBuilder::strip_new_quad(Vector2 up, Vector2 down, Color color, float uv
}
indices.push_back(vi);
- indices.push_back(vi+3);
- indices.push_back(vi+1);
+ indices.push_back(vi + 3);
+ indices.push_back(vi + 1);
indices.push_back(vi);
- indices.push_back(vi+2);
- indices.push_back(vi+3);
+ indices.push_back(vi + 2);
+ indices.push_back(vi + 3);
- _last_index[UP] = vi+2;
- _last_index[DOWN] = vi+3;
+ _last_index[UP] = vi + 2;
+ _last_index[DOWN] = vi + 3;
}
void LineBuilder::strip_add_quad(Vector2 up, Vector2 down, Color color, float uvx) {
@@ -452,25 +438,25 @@ void LineBuilder::strip_add_quad(Vector2 up, Vector2 down, Color color, float uv
vertices.push_back(up);
vertices.push_back(down);
- if(_interpolate_color) {
+ if (_interpolate_color) {
colors.push_back(color);
colors.push_back(color);
}
- if(texture_mode != LINE_TEXTURE_NONE) {
+ if (texture_mode != LINE_TEXTURE_NONE) {
uvs.push_back(Vector2(uvx, 0.f));
uvs.push_back(Vector2(uvx, 1.f));
}
indices.push_back(_last_index[UP]);
- indices.push_back(vi+1);
+ indices.push_back(vi + 1);
indices.push_back(_last_index[DOWN]);
indices.push_back(_last_index[UP]);
indices.push_back(vi);
- indices.push_back(vi+1);
+ indices.push_back(vi + 1);
_last_index[UP] = vi;
- _last_index[DOWN] = vi+1;
+ _last_index[DOWN] = vi + 1;
}
void LineBuilder::strip_add_tri(Vector2 up, Orientation orientation) {
@@ -478,13 +464,13 @@ void LineBuilder::strip_add_tri(Vector2 up, Orientation orientation) {
vertices.push_back(up);
- if(_interpolate_color) {
- colors.push_back(colors[colors.size()-1]);
+ if (_interpolate_color) {
+ colors.push_back(colors[colors.size() - 1]);
}
Orientation opposite_orientation = orientation == UP ? DOWN : UP;
- if(texture_mode != LINE_TEXTURE_NONE) {
+ if (texture_mode != LINE_TEXTURE_NONE) {
// UVs are just one slice of the texture all along
// (otherwise we can't share the bottom vertice)
uvs.push_back(uvs[_last_index[opposite_orientation]]);
@@ -508,15 +494,15 @@ void LineBuilder::strip_add_arc(Vector2 center, float angle_delta, Orientation o
float angle_step = Math_PI / static_cast<float>(round_precision);
float steps = Math::abs(angle_delta) / angle_step;
- if(angle_delta < 0.f)
+ if (angle_delta < 0.f)
angle_step = -angle_step;
float t = vbegin.angle_to(Vector2(1, 0));
float end_angle = t + angle_delta;
- Vector2 rpos(0,0);
+ Vector2 rpos(0, 0);
// Arc vertices
- for(int ti = 0; ti < steps; ++ti, t += angle_step) {
+ for (int ti = 0; ti < steps; ++ti, t += angle_step) {
rpos = center + Vector2(Math::cos(t), Math::sin(t)) * radius;
strip_add_tri(rpos, orientation);
}
@@ -535,34 +521,34 @@ void LineBuilder::new_arc(Vector2 center, Vector2 vbegin, float angle_delta, Col
float angle_step = Math_PI / static_cast<float>(round_precision);
float steps = Math::abs(angle_delta) / angle_step;
- if(angle_delta < 0.f)
+ if (angle_delta < 0.f)
angle_step = -angle_step;
float t = vbegin.angle_to(Vector2(1, 0));
float end_angle = t + angle_delta;
- Vector2 rpos(0,0);
+ Vector2 rpos(0, 0);
float tt_begin = -Math_PI / 2.f;
float tt = tt_begin;
// Center vertice
int vi = vertices.size();
vertices.push_back(center);
- if(_interpolate_color)
+ if (_interpolate_color)
colors.push_back(color);
- if(texture_mode != LINE_TEXTURE_NONE)
+ if (texture_mode != LINE_TEXTURE_NONE)
uvs.push_back(interpolate(uv_rect, Vector2(0.5f, 0.5f)));
// Arc vertices
- for(int ti = 0; ti < steps; ++ti, t += angle_step) {
+ for (int ti = 0; ti < steps; ++ti, t += angle_step) {
Vector2 sc = Vector2(Math::cos(t), Math::sin(t));
rpos = center + sc * radius;
vertices.push_back(rpos);
- if(_interpolate_color)
+ if (_interpolate_color)
colors.push_back(color);
- if(texture_mode != LINE_TEXTURE_NONE) {
+ if (texture_mode != LINE_TEXTURE_NONE) {
Vector2 tsc = Vector2(Math::cos(tt), Math::sin(tt));
- uvs.push_back(interpolate(uv_rect, 0.5f*(tsc+Vector2(1.f,1.f))));
+ uvs.push_back(interpolate(uv_rect, 0.5f * (tsc + Vector2(1.f, 1.f))));
tt += angle_step;
}
}
@@ -571,21 +557,19 @@ void LineBuilder::new_arc(Vector2 center, Vector2 vbegin, float angle_delta, Col
Vector2 sc = Vector2(Math::cos(end_angle), Math::sin(end_angle));
rpos = center + sc * radius;
vertices.push_back(rpos);
- if(_interpolate_color)
+ if (_interpolate_color)
colors.push_back(color);
- if(texture_mode != LINE_TEXTURE_NONE) {
+ if (texture_mode != LINE_TEXTURE_NONE) {
tt = tt_begin + angle_delta;
Vector2 tsc = Vector2(Math::cos(tt), Math::sin(tt));
- uvs.push_back(interpolate(uv_rect, 0.5f*(tsc+Vector2(1.f,1.f))));
+ uvs.push_back(interpolate(uv_rect, 0.5f * (tsc + Vector2(1.f, 1.f))));
}
// Make up triangles
int vi0 = vi;
- for(int ti = 0; ti < steps; ++ti) {
+ for (int ti = 0; ti < steps; ++ti) {
indices.push_back(vi0);
indices.push_back(++vi);
- indices.push_back(vi+1);
+ indices.push_back(vi + 1);
}
}
-
-
diff --git a/scene/2d/line_builder.h b/scene/2d/line_builder.h
index 3fc9e4bb85..43fd281d99 100644
--- a/scene/2d/line_builder.h
+++ b/scene/2d/line_builder.h
@@ -29,8 +29,8 @@
#ifndef LINE_BUILDER_H
#define LINE_BUILDER_H
-#include "math_2d.h"
#include "color.h"
+#include "math_2d.h"
#include "scene/resources/color_ramp.h"
enum LineJointMode {
@@ -61,7 +61,7 @@ public:
LineCapMode end_cap_mode;
float width;
Color default_color;
- ColorRamp* gradient;
+ ColorRamp *gradient;
LineTextureMode texture_mode;
float sharp_limit;
int round_precision;
@@ -97,8 +97,6 @@ private:
private:
bool _interpolate_color;
int _last_index[2]; // Index of last up and down vertices of the strip
-
};
-
#endif // LINE_BUILDER_H
diff --git a/scene/2d/navigation2d.cpp b/scene/2d/navigation2d.cpp
index 7f48749dc3..f0280a2f81 100644
--- a/scene/2d/navigation2d.cpp
+++ b/scene/2d/navigation2d.cpp
@@ -33,61 +33,59 @@
void Navigation2D::_navpoly_link(int p_id) {
ERR_FAIL_COND(!navpoly_map.has(p_id));
- NavMesh &nm=navpoly_map[p_id];
+ NavMesh &nm = navpoly_map[p_id];
ERR_FAIL_COND(nm.linked);
- PoolVector<Vector2> vertices=nm.navpoly->get_vertices();
+ PoolVector<Vector2> vertices = nm.navpoly->get_vertices();
int len = vertices.size();
- if (len==0)
+ if (len == 0)
return;
- PoolVector<Vector2>::Read r=vertices.read();
+ PoolVector<Vector2>::Read r = vertices.read();
- for(int i=0;i<nm.navpoly->get_polygon_count();i++) {
+ for (int i = 0; i < nm.navpoly->get_polygon_count(); i++) {
//build
- List<Polygon>::Element *P=nm.polygons.push_back(Polygon());
- Polygon &p=P->get();
- p.owner=&nm;
+ List<Polygon>::Element *P = nm.polygons.push_back(Polygon());
+ Polygon &p = P->get();
+ p.owner = &nm;
Vector<int> poly = nm.navpoly->get_polygon(i);
- int plen=poly.size();
- const int *indices=poly.ptr();
- bool valid=true;
+ int plen = poly.size();
+ const int *indices = poly.ptr();
+ bool valid = true;
p.edges.resize(plen);
Vector2 center;
- float sum=0;
+ float sum = 0;
- for(int j=0;j<plen;j++) {
+ for (int j = 0; j < plen; j++) {
int idx = indices[j];
- if (idx<0 || idx>=len) {
- valid=false;
+ if (idx < 0 || idx >= len) {
+ valid = false;
break;
}
Polygon::Edge e;
- Vector2 ep=nm.xform.xform(r[idx]);
- center+=ep;
- e.point=_get_point(ep);
- p.edges[j]=e;
-
- int idxn = indices[(j+1)%plen];
- if (idxn<0 || idxn>=len) {
- valid=false;
+ Vector2 ep = nm.xform.xform(r[idx]);
+ center += ep;
+ e.point = _get_point(ep);
+ p.edges[j] = e;
+
+ int idxn = indices[(j + 1) % plen];
+ if (idxn < 0 || idxn >= len) {
+ valid = false;
break;
}
Vector2 epn = nm.xform.xform(r[idxn]);
- sum+=(epn.x-ep.x)*(epn.y+ep.y);
-
-
+ sum += (epn.x - ep.x) * (epn.y + ep.y);
}
- p.clockwise=sum>0;
+ p.clockwise = sum > 0;
if (!valid) {
nm.polygons.pop_back();
@@ -95,106 +93,103 @@ void Navigation2D::_navpoly_link(int p_id) {
continue;
}
- p.center=center/plen;
+ p.center = center / plen;
//connect
- for(int j=0;j<plen;j++) {
+ for (int j = 0; j < plen; j++) {
- int next = (j+1)%plen;
- EdgeKey ek(p.edges[j].point,p.edges[next].point);
+ int next = (j + 1) % plen;
+ EdgeKey ek(p.edges[j].point, p.edges[next].point);
- Map<EdgeKey,Connection>::Element *C=connections.find(ek);
+ Map<EdgeKey, Connection>::Element *C = connections.find(ek);
if (!C) {
Connection c;
- c.A=&p;
- c.A_edge=j;
- c.B=NULL;
- c.B_edge=-1;
- connections[ek]=c;
+ c.A = &p;
+ c.A_edge = j;
+ c.B = NULL;
+ c.B_edge = -1;
+ connections[ek] = c;
} else {
- if (C->get().B!=NULL) {
+ if (C->get().B != NULL) {
ConnectionPending pending;
- pending.polygon=&p;
- pending.edge=j;
- p.edges[j].P=C->get().pending.push_back(pending);
+ pending.polygon = &p;
+ pending.edge = j;
+ p.edges[j].P = C->get().pending.push_back(pending);
continue;
//print_line(String()+_get_vertex(ek.a)+" -> "+_get_vertex(ek.b));
}
- C->get().B=&p;
- C->get().B_edge=j;
- C->get().A->edges[C->get().A_edge].C=&p;
- C->get().A->edges[C->get().A_edge].C_edge=j;
- p.edges[j].C=C->get().A;
- p.edges[j].C_edge=C->get().A_edge;
+ C->get().B = &p;
+ C->get().B_edge = j;
+ C->get().A->edges[C->get().A_edge].C = &p;
+ C->get().A->edges[C->get().A_edge].C_edge = j;
+ p.edges[j].C = C->get().A;
+ p.edges[j].C_edge = C->get().A_edge;
//connection successful.
}
}
}
- nm.linked=true;
-
+ nm.linked = true;
}
-
void Navigation2D::_navpoly_unlink(int p_id) {
ERR_FAIL_COND(!navpoly_map.has(p_id));
- NavMesh &nm=navpoly_map[p_id];
+ NavMesh &nm = navpoly_map[p_id];
ERR_FAIL_COND(!nm.linked);
//print_line("UNLINK");
- for (List<Polygon>::Element *E=nm.polygons.front();E;E=E->next()) {
-
+ for (List<Polygon>::Element *E = nm.polygons.front(); E; E = E->next()) {
- Polygon &p=E->get();
+ Polygon &p = E->get();
int ec = p.edges.size();
- Polygon::Edge *edges=p.edges.ptr();
+ Polygon::Edge *edges = p.edges.ptr();
- for(int i=0;i<ec;i++) {
- int next = (i+1)%ec;
+ for (int i = 0; i < ec; i++) {
+ int next = (i + 1) % ec;
- EdgeKey ek(edges[i].point,edges[next].point);
- Map<EdgeKey,Connection>::Element *C=connections.find(ek);
+ EdgeKey ek(edges[i].point, edges[next].point);
+ Map<EdgeKey, Connection>::Element *C = connections.find(ek);
ERR_CONTINUE(!C);
if (edges[i].P) {
C->get().pending.erase(edges[i].P);
- edges[i].P=NULL;
+ edges[i].P = NULL;
} else if (C->get().B) {
//disconnect
- C->get().B->edges[C->get().B_edge].C=NULL;
- C->get().B->edges[C->get().B_edge].C_edge=-1;
- C->get().A->edges[C->get().A_edge].C=NULL;
- C->get().A->edges[C->get().A_edge].C_edge=-1;
+ C->get().B->edges[C->get().B_edge].C = NULL;
+ C->get().B->edges[C->get().B_edge].C_edge = -1;
+ C->get().A->edges[C->get().A_edge].C = NULL;
+ C->get().A->edges[C->get().A_edge].C_edge = -1;
- if (C->get().A==&E->get()) {
+ if (C->get().A == &E->get()) {
- C->get().A=C->get().B;
- C->get().A_edge=C->get().B_edge;
+ C->get().A = C->get().B;
+ C->get().A_edge = C->get().B_edge;
}
- C->get().B=NULL;
- C->get().B_edge=-1;
+ C->get().B = NULL;
+ C->get().B_edge = -1;
if (C->get().pending.size()) {
//reconnect if something is pending
ConnectionPending cp = C->get().pending.front()->get();
C->get().pending.pop_front();
- C->get().B=cp.polygon;
- C->get().B_edge=cp.edge;
- C->get().A->edges[C->get().A_edge].C=cp.polygon;
- C->get().A->edges[C->get().A_edge].C_edge=cp.edge;
- cp.polygon->edges[cp.edge].C=C->get().A;
- cp.polygon->edges[cp.edge].C_edge=C->get().A_edge;
- cp.polygon->edges[cp.edge].P=NULL;
+ C->get().B = cp.polygon;
+ C->get().B_edge = cp.edge;
+ C->get().A->edges[C->get().A_edge].C = cp.polygon;
+ C->get().A->edges[C->get().A_edge].C_edge = cp.edge;
+ cp.polygon->edges[cp.edge].C = C->get().A;
+ cp.polygon->edges[cp.edge].C_edge = C->get().A_edge;
+ cp.polygon->edges[cp.edge].P = NULL;
}
} else {
@@ -206,46 +201,39 @@ void Navigation2D::_navpoly_unlink(int p_id) {
nm.polygons.clear();
- nm.linked=false;
-
-
+ nm.linked = false;
}
-
-int Navigation2D::navpoly_create(const Ref<NavigationPolygon>& p_mesh, const Transform2D& p_xform, Object *p_owner) {
+int Navigation2D::navpoly_create(const Ref<NavigationPolygon> &p_mesh, const Transform2D &p_xform, Object *p_owner) {
int id = last_id++;
NavMesh nm;
- nm.linked=false;
- nm.navpoly=p_mesh;
- nm.xform=p_xform;
- nm.owner=p_owner;
- navpoly_map[id]=nm;
+ nm.linked = false;
+ nm.navpoly = p_mesh;
+ nm.xform = p_xform;
+ nm.owner = p_owner;
+ navpoly_map[id] = nm;
_navpoly_link(id);
return id;
}
-void Navigation2D::navpoly_set_transform(int p_id, const Transform2D& p_xform){
+void Navigation2D::navpoly_set_transform(int p_id, const Transform2D &p_xform) {
ERR_FAIL_COND(!navpoly_map.has(p_id));
- NavMesh &nm=navpoly_map[p_id];
- if (nm.xform==p_xform)
+ NavMesh &nm = navpoly_map[p_id];
+ if (nm.xform == p_xform)
return; //bleh
_navpoly_unlink(p_id);
- nm.xform=p_xform;
+ nm.xform = p_xform;
_navpoly_link(p_id);
-
-
-
}
-void Navigation2D::navpoly_remove(int p_id){
+void Navigation2D::navpoly_remove(int p_id) {
ERR_FAIL_COND(!navpoly_map.has(p_id));
_navpoly_unlink(p_id);
navpoly_map.erase(p_id);
-
}
#if 0
void Navigation2D::_clip_path(Vector<Vector2>& path, Polygon *from_poly, const Vector2& p_to_point, Polygon* p_to_poly) {
@@ -284,96 +272,91 @@ void Navigation2D::_clip_path(Vector<Vector2>& path, Polygon *from_poly, const V
}
#endif
-Vector<Vector2> Navigation2D::get_simple_path(const Vector2& p_start, const Vector2& p_end, bool p_optimize) {
+Vector<Vector2> Navigation2D::get_simple_path(const Vector2 &p_start, const Vector2 &p_end, bool p_optimize) {
-
- Polygon *begin_poly=NULL;
- Polygon *end_poly=NULL;
+ Polygon *begin_poly = NULL;
+ Polygon *end_poly = NULL;
Vector2 begin_point;
Vector2 end_point;
- float begin_d=1e20;
- float end_d=1e20;
+ float begin_d = 1e20;
+ float end_d = 1e20;
//look for point inside triangle
- for (Map<int,NavMesh>::Element*E=navpoly_map.front();E;E=E->next()) {
+ for (Map<int, NavMesh>::Element *E = navpoly_map.front(); E; E = E->next()) {
if (!E->get().linked)
continue;
- for(List<Polygon>::Element *F=E->get().polygons.front();F;F=F->next()) {
-
+ for (List<Polygon>::Element *F = E->get().polygons.front(); F; F = F->next()) {
- Polygon &p=F->get();
+ Polygon &p = F->get();
if (begin_d || end_d) {
- for(int i=2;i<p.edges.size();i++) {
+ for (int i = 2; i < p.edges.size(); i++) {
- if (begin_d>0) {
+ if (begin_d > 0) {
- if (Geometry::is_point_in_triangle(p_start,_get_vertex(p.edges[0].point),_get_vertex(p.edges[i-1].point),_get_vertex(p.edges[i].point))) {
+ if (Geometry::is_point_in_triangle(p_start, _get_vertex(p.edges[0].point), _get_vertex(p.edges[i - 1].point), _get_vertex(p.edges[i].point))) {
- begin_poly=&p;
- begin_point=p_start;
- begin_d=0;
- if (end_d==0)
+ begin_poly = &p;
+ begin_point = p_start;
+ begin_d = 0;
+ if (end_d == 0)
break;
-
}
}
- if (end_d>0) {
+ if (end_d > 0) {
- if (Geometry::is_point_in_triangle(p_end,_get_vertex(p.edges[0].point),_get_vertex(p.edges[i-1].point),_get_vertex(p.edges[i].point))) {
+ if (Geometry::is_point_in_triangle(p_end, _get_vertex(p.edges[0].point), _get_vertex(p.edges[i - 1].point), _get_vertex(p.edges[i].point))) {
- end_poly=&p;
- end_point=p_end;
- end_d=0;
- if (begin_d==0)
+ end_poly = &p;
+ end_point = p_end;
+ end_d = 0;
+ if (begin_d == 0)
break;
}
}
-
}
}
- p.prev_edge=-1;
+ p.prev_edge = -1;
}
}
//start or end not inside triangle.. look for closest segment :|
if (begin_d || end_d) {
- for (Map<int,NavMesh>::Element*E=navpoly_map.front();E;E=E->next()) {
+ for (Map<int, NavMesh>::Element *E = navpoly_map.front(); E; E = E->next()) {
if (!E->get().linked)
continue;
- for(List<Polygon>::Element *F=E->get().polygons.front();F;F=F->next()) {
+ for (List<Polygon>::Element *F = E->get().polygons.front(); F; F = F->next()) {
- Polygon &p=F->get();
+ Polygon &p = F->get();
int es = p.edges.size();
- for(int i=0;i<es;i++) {
+ for (int i = 0; i < es; i++) {
- Vector2 edge[2]={
+ Vector2 edge[2] = {
_get_vertex(p.edges[i].point),
- _get_vertex(p.edges[(i+1)%es].point)
+ _get_vertex(p.edges[(i + 1) % es].point)
};
-
- if (begin_d>0) {
- Vector2 spoint=Geometry::get_closest_point_to_segment_2d(p_start,edge);
+ if (begin_d > 0) {
+ Vector2 spoint = Geometry::get_closest_point_to_segment_2d(p_start, edge);
float d = spoint.distance_to(p_start);
- if (d<begin_d) {
- begin_poly=&p;
- begin_point=spoint;
- begin_d=d;
+ if (d < begin_d) {
+ begin_poly = &p;
+ begin_point = spoint;
+ begin_d = d;
}
}
- if (end_d>0) {
- Vector2 spoint=Geometry::get_closest_point_to_segment_2d(p_end,edge);
+ if (end_d > 0) {
+ Vector2 spoint = Geometry::get_closest_point_to_segment_2d(p_end, edge);
float d = spoint.distance_to(p_end);
- if (d<end_d) {
- end_poly=&p;
- end_point=spoint;
- end_d=d;
+ if (d < end_d) {
+ end_poly = &p;
+ end_point = spoint;
+ end_d = d;
}
}
}
@@ -386,96 +369,91 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2& p_start, const Vect
return Vector<Vector2>(); //no path
}
- if (begin_poly==end_poly) {
+ if (begin_poly == end_poly) {
Vector<Vector2> path;
path.resize(2);
- path[0]=begin_point;
- path[1]=end_point;
+ path[0] = begin_point;
+ path[1] = end_point;
//print_line("Direct Path");
return path;
}
+ bool found_route = false;
- bool found_route=false;
-
- List<Polygon*> open_list;
+ List<Polygon *> open_list;
- begin_poly->entry=p_start;
+ begin_poly->entry = p_start;
- for(int i=0;i<begin_poly->edges.size();i++) {
+ for (int i = 0; i < begin_poly->edges.size(); i++) {
if (begin_poly->edges[i].C) {
- begin_poly->edges[i].C->prev_edge=begin_poly->edges[i].C_edge;
+ begin_poly->edges[i].C->prev_edge = begin_poly->edges[i].C_edge;
#ifdef USE_ENTRY_POINT
- Vector2 edge[2]={
+ Vector2 edge[2] = {
_get_vertex(begin_poly->edges[i].point),
- _get_vertex(begin_poly->edges[(i+1)%begin_poly->edges.size()].point)
+ _get_vertex(begin_poly->edges[(i + 1) % begin_poly->edges.size()].point)
};
- Vector2 entry = Geometry::get_closest_point_to_segment_2d(begin_poly->entry,edge);
+ Vector2 entry = Geometry::get_closest_point_to_segment_2d(begin_poly->entry, edge);
begin_poly->edges[i].C->distance = begin_poly->entry.distance_to(entry);
- begin_poly->edges[i].C->entry=entry;
+ begin_poly->edges[i].C->entry = entry;
#else
- begin_poly->edges[i].C->distance=begin_poly->center.distance_to(begin_poly->edges[i].C->center);
+ begin_poly->edges[i].C->distance = begin_poly->center.distance_to(begin_poly->edges[i].C->center);
#endif
open_list.push_back(begin_poly->edges[i].C);
- if (begin_poly->edges[i].C==end_poly) {
- found_route=true;
+ if (begin_poly->edges[i].C == end_poly) {
+ found_route = true;
}
}
}
+ while (!found_route) {
- while(!found_route) {
-
- if (open_list.size()==0) {
+ if (open_list.size() == 0) {
//print_line("NOU OPEN LIST");
break;
}
//check open list
- List<Polygon*>::Element *least_cost_poly=NULL;
- float least_cost=1e30;
+ List<Polygon *>::Element *least_cost_poly = NULL;
+ float least_cost = 1e30;
//this could be faster (cache previous results)
- for (List<Polygon*>::Element *E=open_list.front();E;E=E->next()) {
-
- Polygon *p=E->get();
+ for (List<Polygon *>::Element *E = open_list.front(); E; E = E->next()) {
+ Polygon *p = E->get();
- float cost=p->distance;
- cost+=p->center.distance_to(end_point);
+ float cost = p->distance;
+ cost += p->center.distance_to(end_point);
- if (cost<least_cost) {
+ if (cost < least_cost) {
- least_cost_poly=E;
- least_cost=cost;
+ least_cost_poly = E;
+ least_cost = cost;
}
}
-
- Polygon *p=least_cost_poly->get();
+ Polygon *p = least_cost_poly->get();
//open the neighbours for search
int es = p->edges.size();
- for(int i=0;i<es;i++) {
+ for (int i = 0; i < es; i++) {
-
- Polygon::Edge &e=p->edges[i];
+ Polygon::Edge &e = p->edges[i];
if (!e.C)
continue;
#ifdef USE_ENTRY_POINT
- Vector2 edge[2]={
+ Vector2 edge[2] = {
_get_vertex(p->edges[i].point),
- _get_vertex(p->edges[(i+1)%es].point)
+ _get_vertex(p->edges[(i + 1) % es].point)
};
- Vector2 edge_entry = Geometry::get_closest_point_to_segment_2d(p->entry,edge);
+ Vector2 edge_entry = Geometry::get_closest_point_to_segment_2d(p->entry, edge);
float distance = p->entry.distance_to(edge_entry) + p->distance;
#else
@@ -484,36 +462,33 @@ Vector<Vector2> Navigation2D::get_simple_path(const Vector2& p_start, const Vect
#endif
-
- if (e.C->prev_edge!=-1) {
+ if (e.C->prev_edge != -1) {
//oh this was visited already, can we win the cost?
- if (e.C->distance>distance) {
+ if (e.C->distance > distance) {
- e.C->prev_edge=e.C_edge;
- e.C->distance=distance;
+ e.C->prev_edge = e.C_edge;
+ e.C->distance = distance;
#ifdef USE_ENTRY_POINT
- e.C->entry=edge_entry;
+ e.C->entry = edge_entry;
#endif
}
} else {
//add to open neighbours
- e.C->prev_edge=e.C_edge;
- e.C->distance=distance;
+ e.C->prev_edge = e.C_edge;
+ e.C->distance = distance;
#ifdef USE_ENTRY_POINT
- e.C->entry=edge_entry;
+ e.C->entry = edge_entry;
#endif
open_list.push_back(e.C);
- if (e.C==end_poly) {
+ if (e.C == end_poly) {
//oh my reached end! stop algorithm
- found_route=true;
+ found_route = true;
break;
-
}
-
}
}
@@ -552,40 +527,40 @@ debug path
if (p_optimize) {
//string pulling
- Vector2 apex_point=end_point;
- Vector2 portal_left=apex_point;
- Vector2 portal_right=apex_point;
- Polygon *left_poly=end_poly;
- Polygon *right_poly=end_poly;
- Polygon *p=end_poly;
+ Vector2 apex_point = end_point;
+ Vector2 portal_left = apex_point;
+ Vector2 portal_right = apex_point;
+ Polygon *left_poly = end_poly;
+ Polygon *right_poly = end_poly;
+ Polygon *p = end_poly;
path.push_back(end_point);
- while(p) {
+ while (p) {
Vector2 left;
Vector2 right;
//#define CLOCK_TANGENT(m_a,m_b,m_c) ( ((m_a)-(m_c)).cross((m_a)-(m_b)) )
-#define CLOCK_TANGENT(m_a,m_b,m_c) ((((m_a).x - (m_c).x) * ((m_b).y - (m_c).y) - ((m_b).x - (m_c).x) * ((m_a).y - (m_c).y)))
+#define CLOCK_TANGENT(m_a, m_b, m_c) ((((m_a).x - (m_c).x) * ((m_b).y - (m_c).y) - ((m_b).x - (m_c).x) * ((m_a).y - (m_c).y)))
- if (p==begin_poly) {
- left=begin_point;
- right=begin_point;
+ if (p == begin_poly) {
+ left = begin_point;
+ right = begin_point;
} else {
int prev = p->prev_edge;
- int prev_n = (p->prev_edge+1)%p->edges.size();
+ int prev_n = (p->prev_edge + 1) % p->edges.size();
left = _get_vertex(p->edges[prev].point);
right = _get_vertex(p->edges[prev_n].point);
if (p->clockwise) {
- SWAP(left,right);
+ SWAP(left, right);
}
/*if (CLOCK_TANGENT(apex_point,left,(left+right)*0.5) < 0){
SWAP(left,right);
}*/
}
- bool skip=false;
+ bool skip = false;
/*
print_line("-----\nAPEX: "+(apex_point-end_point));
@@ -603,221 +578,202 @@ debug path
print_line("\tRight Test: "+rtos(CLOCK_TANGENT(apex_point,right,portal_left)));
*/
-
- if (CLOCK_TANGENT(apex_point,portal_left,left) >= 0){
+ if (CLOCK_TANGENT(apex_point, portal_left, left) >= 0) {
//process
- if (portal_left.distance_squared_to(apex_point)<CMP_EPSILON || CLOCK_TANGENT(apex_point,left,portal_right) > 0) {
- left_poly=p;
- portal_left=left;
+ if (portal_left.distance_squared_to(apex_point) < CMP_EPSILON || CLOCK_TANGENT(apex_point, left, portal_right) > 0) {
+ left_poly = p;
+ portal_left = left;
//print_line("***ADVANCE LEFT");
} else {
- apex_point=portal_right;
- p=right_poly;
- left_poly=p;
- portal_left=apex_point;
- portal_right=apex_point;
- if (path[path.size()-1].distance_to(apex_point)>CMP_EPSILON)
+ apex_point = portal_right;
+ p = right_poly;
+ left_poly = p;
+ portal_left = apex_point;
+ portal_right = apex_point;
+ if (path[path.size() - 1].distance_to(apex_point) > CMP_EPSILON)
path.push_back(apex_point);
- skip=true;
+ skip = true;
//print_line("addpoint left");
//print_line("***CLIP LEFT");
}
}
- if (!skip && CLOCK_TANGENT(apex_point,portal_right,right) <= 0){
+ if (!skip && CLOCK_TANGENT(apex_point, portal_right, right) <= 0) {
//process
- if (portal_right.distance_squared_to(apex_point)<CMP_EPSILON || CLOCK_TANGENT(apex_point,right,portal_left) < 0) {
- right_poly=p;
- portal_right=right;
+ if (portal_right.distance_squared_to(apex_point) < CMP_EPSILON || CLOCK_TANGENT(apex_point, right, portal_left) < 0) {
+ right_poly = p;
+ portal_right = right;
//print_line("***ADVANCE RIGHT");
} else {
- apex_point=portal_left;
- p=left_poly;
- right_poly=p;
- portal_right=apex_point;
- portal_left=apex_point;
- if (path[path.size()-1].distance_to(apex_point)>CMP_EPSILON)
+ apex_point = portal_left;
+ p = left_poly;
+ right_poly = p;
+ portal_right = apex_point;
+ portal_left = apex_point;
+ if (path[path.size() - 1].distance_to(apex_point) > CMP_EPSILON)
path.push_back(apex_point);
//print_line("addpoint right");
//print_line("***CLIP RIGHT");
-
}
}
- if (p!=begin_poly)
- p=p->edges[p->prev_edge].C;
+ if (p != begin_poly)
+ p = p->edges[p->prev_edge].C;
else
- p=NULL;
-
+ p = NULL;
}
- if (path[path.size()-1].distance_to(begin_point)>CMP_EPSILON)
+ if (path[path.size() - 1].distance_to(begin_point) > CMP_EPSILON)
path.push_back(begin_point);
path.invert();
-
-
-
} else {
//midpoints
- Polygon *p=end_poly;
+ Polygon *p = end_poly;
path.push_back(end_point);
- while(true) {
+ while (true) {
int prev = p->prev_edge;
- int prev_n = (p->prev_edge+1)%p->edges.size();
- Vector2 point = (_get_vertex(p->edges[prev].point) + _get_vertex(p->edges[prev_n].point))*0.5;
+ int prev_n = (p->prev_edge + 1) % p->edges.size();
+ Vector2 point = (_get_vertex(p->edges[prev].point) + _get_vertex(p->edges[prev_n].point)) * 0.5;
path.push_back(point);
p = p->edges[prev].C;
- if (p==begin_poly)
+ if (p == begin_poly)
break;
}
path.push_back(begin_point);
-
path.invert();
}
return path;
}
-
return Vector<Vector2>();
-
}
+Vector2 Navigation2D::get_closest_point(const Vector2 &p_point) {
-Vector2 Navigation2D::get_closest_point(const Vector2& p_point) {
-
- Vector2 closest_point=Vector2();
- float closest_point_d=1e20;
+ Vector2 closest_point = Vector2();
+ float closest_point_d = 1e20;
- for (Map<int,NavMesh>::Element*E=navpoly_map.front();E;E=E->next()) {
+ for (Map<int, NavMesh>::Element *E = navpoly_map.front(); E; E = E->next()) {
if (!E->get().linked)
continue;
- for(List<Polygon>::Element *F=E->get().polygons.front();F;F=F->next()) {
+ for (List<Polygon>::Element *F = E->get().polygons.front(); F; F = F->next()) {
- Polygon &p=F->get();
- for(int i=2;i<p.edges.size();i++) {
+ Polygon &p = F->get();
+ for (int i = 2; i < p.edges.size(); i++) {
- if (Geometry::is_point_in_triangle(p_point,_get_vertex(p.edges[0].point),_get_vertex(p.edges[i-1].point),_get_vertex(p.edges[i].point))) {
+ if (Geometry::is_point_in_triangle(p_point, _get_vertex(p.edges[0].point), _get_vertex(p.edges[i - 1].point), _get_vertex(p.edges[i].point))) {
return p_point; //inside triangle, nothing else to discuss
}
-
}
}
}
- for (Map<int,NavMesh>::Element*E=navpoly_map.front();E;E=E->next()) {
+ for (Map<int, NavMesh>::Element *E = navpoly_map.front(); E; E = E->next()) {
if (!E->get().linked)
continue;
- for(List<Polygon>::Element *F=E->get().polygons.front();F;F=F->next()) {
+ for (List<Polygon>::Element *F = E->get().polygons.front(); F; F = F->next()) {
- Polygon &p=F->get();
+ Polygon &p = F->get();
int es = p.edges.size();
- for(int i=0;i<es;i++) {
+ for (int i = 0; i < es; i++) {
- Vector2 edge[2]={
+ Vector2 edge[2] = {
_get_vertex(p.edges[i].point),
- _get_vertex(p.edges[(i+1)%es].point)
+ _get_vertex(p.edges[(i + 1) % es].point)
};
-
- Vector2 spoint=Geometry::get_closest_point_to_segment_2d(p_point,edge);
+ Vector2 spoint = Geometry::get_closest_point_to_segment_2d(p_point, edge);
float d = spoint.distance_squared_to(p_point);
- if (d<closest_point_d) {
+ if (d < closest_point_d) {
- closest_point=spoint;
- closest_point_d=d;
+ closest_point = spoint;
+ closest_point_d = d;
}
}
}
}
return closest_point;
-
}
-Object* Navigation2D::get_closest_point_owner(const Vector2& p_point) {
+Object *Navigation2D::get_closest_point_owner(const Vector2 &p_point) {
- Object *owner=NULL;
- Vector2 closest_point=Vector2();
- float closest_point_d=1e20;
+ Object *owner = NULL;
+ Vector2 closest_point = Vector2();
+ float closest_point_d = 1e20;
- for (Map<int,NavMesh>::Element*E=navpoly_map.front();E;E=E->next()) {
+ for (Map<int, NavMesh>::Element *E = navpoly_map.front(); E; E = E->next()) {
if (!E->get().linked)
continue;
- for(List<Polygon>::Element *F=E->get().polygons.front();F;F=F->next()) {
+ for (List<Polygon>::Element *F = E->get().polygons.front(); F; F = F->next()) {
- Polygon &p=F->get();
- for(int i=2;i<p.edges.size();i++) {
+ Polygon &p = F->get();
+ for (int i = 2; i < p.edges.size(); i++) {
- if (Geometry::is_point_in_triangle(p_point,_get_vertex(p.edges[0].point),_get_vertex(p.edges[i-1].point),_get_vertex(p.edges[i].point))) {
+ if (Geometry::is_point_in_triangle(p_point, _get_vertex(p.edges[0].point), _get_vertex(p.edges[i - 1].point), _get_vertex(p.edges[i].point))) {
E->get().owner;
}
-
}
}
}
- for (Map<int,NavMesh>::Element*E=navpoly_map.front();E;E=E->next()) {
+ for (Map<int, NavMesh>::Element *E = navpoly_map.front(); E; E = E->next()) {
if (!E->get().linked)
continue;
- for(List<Polygon>::Element *F=E->get().polygons.front();F;F=F->next()) {
+ for (List<Polygon>::Element *F = E->get().polygons.front(); F; F = F->next()) {
- Polygon &p=F->get();
+ Polygon &p = F->get();
int es = p.edges.size();
- for(int i=0;i<es;i++) {
+ for (int i = 0; i < es; i++) {
- Vector2 edge[2]={
+ Vector2 edge[2] = {
_get_vertex(p.edges[i].point),
- _get_vertex(p.edges[(i+1)%es].point)
+ _get_vertex(p.edges[(i + 1) % es].point)
};
-
- Vector2 spoint=Geometry::get_closest_point_to_segment_2d(p_point,edge);
+ Vector2 spoint = Geometry::get_closest_point_to_segment_2d(p_point, edge);
float d = spoint.distance_squared_to(p_point);
- if (d<closest_point_d) {
+ if (d < closest_point_d) {
- closest_point=spoint;
- closest_point_d=d;
- owner=E->get().owner;
+ closest_point = spoint;
+ closest_point_d = d;
+ owner = E->get().owner;
}
}
}
}
return owner;
-
}
-
void Navigation2D::_bind_methods() {
- ClassDB::bind_method(D_METHOD("navpoly_create","mesh:NavigationPolygon","xform","owner"),&Navigation2D::navpoly_create,DEFVAL(Variant()));
- ClassDB::bind_method(D_METHOD("navpoly_set_transform","id","xform"),&Navigation2D::navpoly_set_transform);
- ClassDB::bind_method(D_METHOD("navpoly_remove","id"),&Navigation2D::navpoly_remove);
-
- ClassDB::bind_method(D_METHOD("get_simple_path","start","end","optimize"),&Navigation2D::get_simple_path,DEFVAL(true));
- ClassDB::bind_method(D_METHOD("get_closest_point","to_point"),&Navigation2D::get_closest_point);
- ClassDB::bind_method(D_METHOD("get_closest_point_owner","to_point"),&Navigation2D::get_closest_point_owner);
+ ClassDB::bind_method(D_METHOD("navpoly_create", "mesh:NavigationPolygon", "xform", "owner"), &Navigation2D::navpoly_create, DEFVAL(Variant()));
+ ClassDB::bind_method(D_METHOD("navpoly_set_transform", "id", "xform"), &Navigation2D::navpoly_set_transform);
+ ClassDB::bind_method(D_METHOD("navpoly_remove", "id"), &Navigation2D::navpoly_remove);
+ ClassDB::bind_method(D_METHOD("get_simple_path", "start", "end", "optimize"), &Navigation2D::get_simple_path, DEFVAL(true));
+ ClassDB::bind_method(D_METHOD("get_closest_point", "to_point"), &Navigation2D::get_closest_point);
+ ClassDB::bind_method(D_METHOD("get_closest_point_owner", "to_point"), &Navigation2D::get_closest_point_owner);
}
Navigation2D::Navigation2D() {
- ERR_FAIL_COND( sizeof(Point)!=8 );
- cell_size=1; // one pixel
- last_id=1;
-
+ ERR_FAIL_COND(sizeof(Point) != 8);
+ cell_size = 1; // one pixel
+ last_id = 1;
}
diff --git a/scene/2d/navigation2d.h b/scene/2d/navigation2d.h
index 63827ebb6d..afa565518d 100644
--- a/scene/2d/navigation2d.h
+++ b/scene/2d/navigation2d.h
@@ -29,45 +29,42 @@
#ifndef NAVIGATION_2D_H
#define NAVIGATION_2D_H
-#include "scene/2d/node_2d.h"
#include "scene/2d/navigation_polygon.h"
+#include "scene/2d/node_2d.h"
class Navigation2D : public Node2D {
- GDCLASS( Navigation2D, Node2D);
-
+ GDCLASS(Navigation2D, Node2D);
union Point {
struct {
- int64_t x:32;
- int64_t y:32;
+ int64_t x : 32;
+ int64_t y : 32;
};
uint64_t key;
- bool operator<(const Point& p_key) const { return key < p_key.key; }
+ bool operator<(const Point &p_key) const { return key < p_key.key; }
};
-
struct EdgeKey {
Point a;
Point b;
- bool operator<(const EdgeKey& p_key) const {
- return (a.key==p_key.a.key)?(b.key<p_key.b.key):(a.key<p_key.a.key);
+ bool operator<(const EdgeKey &p_key) const {
+ return (a.key == p_key.a.key) ? (b.key < p_key.b.key) : (a.key < p_key.a.key);
};
- EdgeKey(const Point& p_a=Point(),const Point& p_b=Point()) {
- a=p_a;
- b=p_b;
+ EdgeKey(const Point &p_a = Point(), const Point &p_b = Point()) {
+ a = p_a;
+ b = p_b;
if (a.key > b.key) {
- SWAP(a,b);
+ SWAP(a, b);
}
}
};
-
struct NavMesh;
struct Polygon;
@@ -84,7 +81,11 @@ class Navigation2D : public Node2D {
Polygon *C; //connection
int C_edge;
List<ConnectionPending>::Element *P;
- Edge() { C=NULL; C_edge=-1; P=NULL; }
+ Edge() {
+ C = NULL;
+ C_edge = -1;
+ P = NULL;
+ }
};
Vector<Edge> edges;
@@ -100,7 +101,6 @@ class Navigation2D : public Node2D {
NavMesh *owner;
};
-
struct Connection {
Polygon *A;
@@ -110,11 +110,15 @@ class Navigation2D : public Node2D {
List<ConnectionPending> pending;
- Connection() { A=NULL; B=NULL; A_edge=-1; B_edge=-1;}
+ Connection() {
+ A = NULL;
+ B = NULL;
+ A_edge = -1;
+ B_edge = -1;
+ }
};
- Map<EdgeKey,Connection> connections;
-
+ Map<EdgeKey, Connection> connections;
struct NavMesh {
@@ -123,57 +127,48 @@ class Navigation2D : public Node2D {
bool linked;
Ref<NavigationPolygon> navpoly;
List<Polygon> polygons;
-
};
+ _FORCE_INLINE_ Point _get_point(const Vector2 &p_pos) const {
-
- _FORCE_INLINE_ Point _get_point(const Vector2& p_pos) const {
-
- int x = int(Math::floor(p_pos.x/cell_size));
- int y = int(Math::floor(p_pos.y/cell_size));
+ int x = int(Math::floor(p_pos.x / cell_size));
+ int y = int(Math::floor(p_pos.y / cell_size));
Point p;
- p.key=0;
- p.x=x;
- p.y=y;
+ p.key = 0;
+ p.x = x;
+ p.y = y;
return p;
-
}
- _FORCE_INLINE_ Vector2 _get_vertex(const Point& p_point) const {
+ _FORCE_INLINE_ Vector2 _get_vertex(const Point &p_point) const {
- return Vector2(p_point.x,p_point.y)*cell_size;
+ return Vector2(p_point.x, p_point.y) * cell_size;
}
-
-
void _navpoly_link(int p_id);
void _navpoly_unlink(int p_id);
float cell_size;
- Map<int,NavMesh> navpoly_map;
+ Map<int, NavMesh> navpoly_map;
int last_id;
#if 0
void _clip_path(Vector<Vector2>& path,Polygon *from_poly, const Vector2& p_to_point, Polygon* p_to_poly);
#endif
protected:
-
static void _bind_methods();
public:
-
//API should be as dynamic as possible
- int navpoly_create(const Ref<NavigationPolygon>& p_mesh,const Transform2D& p_xform,Object* p_owner=NULL);
- void navpoly_set_transform(int p_id, const Transform2D& p_xform);
+ int navpoly_create(const Ref<NavigationPolygon> &p_mesh, const Transform2D &p_xform, Object *p_owner = NULL);
+ void navpoly_set_transform(int p_id, const Transform2D &p_xform);
void navpoly_remove(int p_id);
- Vector<Vector2> get_simple_path(const Vector2& p_start, const Vector2& p_end,bool p_optimize=true);
- Vector2 get_closest_point(const Vector2& p_point);
- Object* get_closest_point_owner(const Vector2& p_point);
+ Vector<Vector2> get_simple_path(const Vector2 &p_start, const Vector2 &p_end, bool p_optimize = true);
+ Vector2 get_closest_point(const Vector2 &p_point);
+ Object *get_closest_point_owner(const Vector2 &p_point);
Navigation2D();
};
-
#endif // Navigation2D2D_H
diff --git a/scene/2d/navigation_polygon.cpp b/scene/2d/navigation_polygon.cpp
index 9dbbd34ae9..570bd00a5b 100644
--- a/scene/2d/navigation_polygon.cpp
+++ b/scene/2d/navigation_polygon.cpp
@@ -27,26 +27,25 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "navigation_polygon.h"
+#include "core_string_names.h"
#include "navigation2d.h"
#include "triangulator.h"
-#include "core_string_names.h"
-void NavigationPolygon::set_vertices(const PoolVector<Vector2>& p_vertices) {
+void NavigationPolygon::set_vertices(const PoolVector<Vector2> &p_vertices) {
- vertices=p_vertices;
+ vertices = p_vertices;
}
-PoolVector<Vector2> NavigationPolygon::get_vertices() const{
+PoolVector<Vector2> NavigationPolygon::get_vertices() const {
return vertices;
}
-
-void NavigationPolygon::_set_polygons(const Array& p_array) {
+void NavigationPolygon::_set_polygons(const Array &p_array) {
polygons.resize(p_array.size());
- for(int i=0;i<p_array.size();i++) {
- polygons[i].indices=p_array[i];
+ for (int i = 0; i < p_array.size(); i++) {
+ polygons[i].indices = p_array[i];
}
}
@@ -54,18 +53,18 @@ Array NavigationPolygon::_get_polygons() const {
Array ret;
ret.resize(polygons.size());
- for(int i=0;i<ret.size();i++) {
- ret[i]=polygons[i].indices;
+ for (int i = 0; i < ret.size(); i++) {
+ ret[i] = polygons[i].indices;
}
return ret;
}
-void NavigationPolygon::_set_outlines(const Array& p_array) {
+void NavigationPolygon::_set_outlines(const Array &p_array) {
outlines.resize(p_array.size());
- for(int i=0;i<p_array.size();i++) {
- outlines[i]=p_array[i];
+ for (int i = 0; i < p_array.size(); i++) {
+ outlines[i] = p_array[i];
}
}
@@ -73,132 +72,125 @@ Array NavigationPolygon::_get_outlines() const {
Array ret;
ret.resize(outlines.size());
- for(int i=0;i<ret.size();i++) {
- ret[i]=outlines[i];
+ for (int i = 0; i < ret.size(); i++) {
+ ret[i] = outlines[i];
}
return ret;
}
-
-void NavigationPolygon::add_polygon(const Vector<int>& p_polygon){
+void NavigationPolygon::add_polygon(const Vector<int> &p_polygon) {
Polygon polygon;
- polygon.indices=p_polygon;
+ polygon.indices = p_polygon;
polygons.push_back(polygon);
-
}
-void NavigationPolygon::add_outline_at_index(const PoolVector<Vector2>& p_outline,int p_index) {
+void NavigationPolygon::add_outline_at_index(const PoolVector<Vector2> &p_outline, int p_index) {
- outlines.insert(p_index,p_outline);
+ outlines.insert(p_index, p_outline);
}
-int NavigationPolygon::get_polygon_count() const{
+int NavigationPolygon::get_polygon_count() const {
return polygons.size();
}
-Vector<int> NavigationPolygon::get_polygon(int p_idx){
+Vector<int> NavigationPolygon::get_polygon(int p_idx) {
- ERR_FAIL_INDEX_V(p_idx,polygons.size(),Vector<int>());
+ ERR_FAIL_INDEX_V(p_idx, polygons.size(), Vector<int>());
return polygons[p_idx].indices;
}
-void NavigationPolygon::clear_polygons(){
+void NavigationPolygon::clear_polygons() {
polygons.clear();
}
-void NavigationPolygon::add_outline(const PoolVector<Vector2>& p_outline) {
+void NavigationPolygon::add_outline(const PoolVector<Vector2> &p_outline) {
outlines.push_back(p_outline);
}
-int NavigationPolygon::get_outline_count() const{
+int NavigationPolygon::get_outline_count() const {
return outlines.size();
}
-void NavigationPolygon::set_outline(int p_idx,const PoolVector<Vector2>& p_outline) {
- ERR_FAIL_INDEX(p_idx,outlines.size());
- outlines[p_idx]=p_outline;
+void NavigationPolygon::set_outline(int p_idx, const PoolVector<Vector2> &p_outline) {
+ ERR_FAIL_INDEX(p_idx, outlines.size());
+ outlines[p_idx] = p_outline;
}
void NavigationPolygon::remove_outline(int p_idx) {
- ERR_FAIL_INDEX(p_idx,outlines.size());
+ ERR_FAIL_INDEX(p_idx, outlines.size());
outlines.remove(p_idx);
-
}
PoolVector<Vector2> NavigationPolygon::get_outline(int p_idx) const {
- ERR_FAIL_INDEX_V(p_idx,outlines.size(),PoolVector<Vector2>());
+ ERR_FAIL_INDEX_V(p_idx, outlines.size(), PoolVector<Vector2>());
return outlines[p_idx];
}
-void NavigationPolygon::clear_outlines(){
+void NavigationPolygon::clear_outlines() {
outlines.clear();
}
-void NavigationPolygon::make_polygons_from_outlines(){
+void NavigationPolygon::make_polygons_from_outlines() {
- List<TriangulatorPoly> in_poly,out_poly;
+ List<TriangulatorPoly> in_poly, out_poly;
- Vector2 outside_point(-1e10,-1e10);
+ Vector2 outside_point(-1e10, -1e10);
- for(int i=0;i<outlines.size();i++) {
+ for (int i = 0; i < outlines.size(); i++) {
PoolVector<Vector2> ol = outlines[i];
int olsize = ol.size();
- if (olsize<3)
+ if (olsize < 3)
continue;
- PoolVector<Vector2>::Read r=ol.read();
- for(int j=0;j<olsize;j++) {
- outside_point.x = MAX( r[j].x, outside_point.x );
- outside_point.y = MAX( r[j].y, outside_point.y );
+ PoolVector<Vector2>::Read r = ol.read();
+ for (int j = 0; j < olsize; j++) {
+ outside_point.x = MAX(r[j].x, outside_point.x);
+ outside_point.y = MAX(r[j].y, outside_point.y);
}
-
}
- outside_point+=Vector2(0.7239784,0.819238); //avoid precision issues
+ outside_point += Vector2(0.7239784, 0.819238); //avoid precision issues
-
-
- for(int i=0;i<outlines.size();i++) {
+ for (int i = 0; i < outlines.size(); i++) {
PoolVector<Vector2> ol = outlines[i];
int olsize = ol.size();
- if (olsize<3)
+ if (olsize < 3)
continue;
- PoolVector<Vector2>::Read r=ol.read();
+ PoolVector<Vector2>::Read r = ol.read();
- int interscount=0;
+ int interscount = 0;
//test if this is an outer outline
- for(int k=0;k<outlines.size();k++) {
+ for (int k = 0; k < outlines.size(); k++) {
- if (i==k)
+ if (i == k)
continue; //no self intersect
PoolVector<Vector2> ol2 = outlines[k];
int olsize2 = ol2.size();
- if (olsize2<3)
+ if (olsize2 < 3)
continue;
- PoolVector<Vector2>::Read r2=ol2.read();
+ PoolVector<Vector2>::Read r2 = ol2.read();
- for(int l=0;l<olsize2;l++) {
+ for (int l = 0; l < olsize2; l++) {
- if (Geometry::segment_intersects_segment_2d(r[0],outside_point,r2[l],r2[(l+1)%olsize2],NULL)) {
+ if (Geometry::segment_intersects_segment_2d(r[0], outside_point, r2[l], r2[(l + 1) % olsize2], NULL)) {
interscount++;
}
}
-
}
- bool outer = (interscount%2)==0;
+ bool outer = (interscount % 2) == 0;
TriangulatorPoly tp;
tp.Init(olsize);
- for(int j=0;j<olsize;j++) {
- tp[j]=r[j];
+ for (int j = 0; j < olsize; j++) {
+ tp[j] = r[j];
}
if (outer)
@@ -211,9 +203,8 @@ void NavigationPolygon::make_polygons_from_outlines(){
in_poly.push_back(tp);
}
-
TriangulatorPartition tpart;
- if (tpart.ConvexPartition_HM(&in_poly,&out_poly)==0) { //failed!
+ if (tpart.ConvexPartition_HM(&in_poly, &out_poly) == 0) { //failed!
print_line("convex partition failed!");
return;
}
@@ -221,18 +212,18 @@ void NavigationPolygon::make_polygons_from_outlines(){
polygons.clear();
vertices.resize(0);
- Map<Vector2,int> points;
- for(List<TriangulatorPoly>::Element*I = out_poly.front();I;I=I->next()) {
+ Map<Vector2, int> points;
+ for (List<TriangulatorPoly>::Element *I = out_poly.front(); I; I = I->next()) {
- TriangulatorPoly& tp = I->get();
+ TriangulatorPoly &tp = I->get();
struct Polygon p;
- for(int i=0;i<tp.GetNumPoints();i++) {
+ for (int i = 0; i < tp.GetNumPoints(); i++) {
- Map<Vector2,int>::Element *E=points.find(tp[i]);
+ Map<Vector2, int>::Element *E = points.find(tp[i]);
if (!E) {
- E=points.insert(tp[i],vertices.size());
+ E = points.insert(tp[i], vertices.size());
vertices.push_back(tp[i]);
}
p.indices.push_back(E->get());
@@ -244,56 +235,53 @@ void NavigationPolygon::make_polygons_from_outlines(){
emit_signal(CoreStringNames::get_singleton()->changed);
}
-
void NavigationPolygon::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_vertices","vertices"),&NavigationPolygon::set_vertices);
- ClassDB::bind_method(D_METHOD("get_vertices"),&NavigationPolygon::get_vertices);
+ ClassDB::bind_method(D_METHOD("set_vertices", "vertices"), &NavigationPolygon::set_vertices);
+ ClassDB::bind_method(D_METHOD("get_vertices"), &NavigationPolygon::get_vertices);
- ClassDB::bind_method(D_METHOD("add_polygon","polygon"),&NavigationPolygon::add_polygon);
- ClassDB::bind_method(D_METHOD("get_polygon_count"),&NavigationPolygon::get_polygon_count);
- ClassDB::bind_method(D_METHOD("get_polygon","idx"),&NavigationPolygon::get_polygon);
- ClassDB::bind_method(D_METHOD("clear_polygons"),&NavigationPolygon::clear_polygons);
+ ClassDB::bind_method(D_METHOD("add_polygon", "polygon"), &NavigationPolygon::add_polygon);
+ ClassDB::bind_method(D_METHOD("get_polygon_count"), &NavigationPolygon::get_polygon_count);
+ ClassDB::bind_method(D_METHOD("get_polygon", "idx"), &NavigationPolygon::get_polygon);
+ ClassDB::bind_method(D_METHOD("clear_polygons"), &NavigationPolygon::clear_polygons);
- ClassDB::bind_method(D_METHOD("add_outline","outline"),&NavigationPolygon::add_outline);
- ClassDB::bind_method(D_METHOD("add_outline_at_index","outline","index"),&NavigationPolygon::add_outline_at_index);
- ClassDB::bind_method(D_METHOD("get_outline_count"),&NavigationPolygon::get_outline_count);
- ClassDB::bind_method(D_METHOD("set_outline","idx","outline"),&NavigationPolygon::set_outline);
- ClassDB::bind_method(D_METHOD("get_outline","idx"),&NavigationPolygon::get_outline);
- ClassDB::bind_method(D_METHOD("remove_outline","idx"),&NavigationPolygon::remove_outline);
- ClassDB::bind_method(D_METHOD("clear_outlines"),&NavigationPolygon::clear_outlines);
- ClassDB::bind_method(D_METHOD("make_polygons_from_outlines"),&NavigationPolygon::make_polygons_from_outlines);
+ ClassDB::bind_method(D_METHOD("add_outline", "outline"), &NavigationPolygon::add_outline);
+ ClassDB::bind_method(D_METHOD("add_outline_at_index", "outline", "index"), &NavigationPolygon::add_outline_at_index);
+ ClassDB::bind_method(D_METHOD("get_outline_count"), &NavigationPolygon::get_outline_count);
+ ClassDB::bind_method(D_METHOD("set_outline", "idx", "outline"), &NavigationPolygon::set_outline);
+ ClassDB::bind_method(D_METHOD("get_outline", "idx"), &NavigationPolygon::get_outline);
+ ClassDB::bind_method(D_METHOD("remove_outline", "idx"), &NavigationPolygon::remove_outline);
+ ClassDB::bind_method(D_METHOD("clear_outlines"), &NavigationPolygon::clear_outlines);
+ ClassDB::bind_method(D_METHOD("make_polygons_from_outlines"), &NavigationPolygon::make_polygons_from_outlines);
- ClassDB::bind_method(D_METHOD("_set_polygons","polygons"),&NavigationPolygon::_set_polygons);
- ClassDB::bind_method(D_METHOD("_get_polygons"),&NavigationPolygon::_get_polygons);
+ ClassDB::bind_method(D_METHOD("_set_polygons", "polygons"), &NavigationPolygon::_set_polygons);
+ ClassDB::bind_method(D_METHOD("_get_polygons"), &NavigationPolygon::_get_polygons);
- ClassDB::bind_method(D_METHOD("_set_outlines","outlines"),&NavigationPolygon::_set_outlines);
- ClassDB::bind_method(D_METHOD("_get_outlines"),&NavigationPolygon::_get_outlines);
+ ClassDB::bind_method(D_METHOD("_set_outlines", "outlines"), &NavigationPolygon::_set_outlines);
+ ClassDB::bind_method(D_METHOD("_get_outlines"), &NavigationPolygon::_get_outlines);
- ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR3_ARRAY,"vertices",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"set_vertices","get_vertices");
- ADD_PROPERTY(PropertyInfo(Variant::ARRAY,"polygons",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"_set_polygons","_get_polygons");
- ADD_PROPERTY(PropertyInfo(Variant::ARRAY,"outlines",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"_set_outlines","_get_outlines");
+ ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR3_ARRAY, "vertices", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_vertices", "get_vertices");
+ ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "polygons", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_polygons", "_get_polygons");
+ ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "outlines", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_outlines", "_get_outlines");
}
NavigationPolygon::NavigationPolygon() {
-
-
}
void NavigationPolygonInstance::set_enabled(bool p_enabled) {
- if (enabled==p_enabled)
+ if (enabled == p_enabled)
return;
- enabled=p_enabled;
+ enabled = p_enabled;
if (!is_inside_tree())
return;
if (!enabled) {
- if (nav_id!=-1) {
+ if (nav_id != -1) {
navigation->navpoly_remove(nav_id);
- nav_id=-1;
+ nav_id = -1;
}
} else {
@@ -301,10 +289,9 @@ void NavigationPolygonInstance::set_enabled(bool p_enabled) {
if (navpoly.is_valid()) {
- nav_id = navigation->navpoly_create(navpoly,get_relative_transform_to_parent(navigation),this);
+ nav_id = navigation->navpoly_create(navpoly, get_relative_transform_to_parent(navigation), this);
}
}
-
}
if (get_tree()->is_editor_hint() || get_tree()->is_debugging_navigation_hint())
@@ -315,41 +302,37 @@ void NavigationPolygonInstance::set_enabled(bool p_enabled) {
bool NavigationPolygonInstance::is_enabled() const {
-
return enabled;
}
-
/////////////////////////////
-
void NavigationPolygonInstance::_notification(int p_what) {
-
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
- Node2D *c=this;
- while(c) {
+ Node2D *c = this;
+ while (c) {
- navigation=c->cast_to<Navigation2D>();
+ navigation = c->cast_to<Navigation2D>();
if (navigation) {
if (enabled && navpoly.is_valid()) {
- nav_id = navigation->navpoly_create(navpoly,get_relative_transform_to_parent(navigation),this);
+ nav_id = navigation->navpoly_create(navpoly, get_relative_transform_to_parent(navigation), this);
}
break;
}
- c=c->get_parent()->cast_to<Node2D>();
+ c = c->get_parent()->cast_to<Node2D>();
}
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
- if (navigation && nav_id!=-1) {
- navigation->navpoly_set_transform(nav_id,get_relative_transform_to_parent(navigation));
+ if (navigation && nav_id != -1) {
+ navigation->navpoly_set_transform(nav_id, get_relative_transform_to_parent(navigation));
}
} break;
@@ -357,28 +340,27 @@ void NavigationPolygonInstance::_notification(int p_what) {
if (navigation) {
- if (nav_id!=-1) {
+ if (nav_id != -1) {
navigation->navpoly_remove(nav_id);
- nav_id=-1;
+ nav_id = -1;
}
}
- navigation=NULL;
+ navigation = NULL;
} break;
case NOTIFICATION_DRAW: {
if (is_inside_tree() && (get_tree()->is_editor_hint() || get_tree()->is_debugging_navigation_hint()) && navpoly.is_valid()) {
- PoolVector<Vector2> verts=navpoly->get_vertices();
+ PoolVector<Vector2> verts = navpoly->get_vertices();
int vsize = verts.size();
- if (vsize<3)
+ if (vsize < 3)
return;
-
Color color;
if (enabled) {
- color=get_tree()->get_debug_navigation_color();
+ color = get_tree()->get_debug_navigation_color();
} else {
- color=get_tree()->get_debug_navigation_disabled_color();
+ color = get_tree()->get_debug_navigation_disabled_color();
}
Vector<Color> colors;
Vector<Vector2> vertices;
@@ -386,66 +368,61 @@ void NavigationPolygonInstance::_notification(int p_what) {
colors.resize(vsize);
{
PoolVector<Vector2>::Read vr = verts.read();
- for(int i=0;i<vsize;i++) {
- vertices[i]=vr[i];
- colors[i]=color;
+ for (int i = 0; i < vsize; i++) {
+ vertices[i] = vr[i];
+ colors[i] = color;
}
}
Vector<int> indices;
-
- for(int i=0;i<navpoly->get_polygon_count();i++) {
+ for (int i = 0; i < navpoly->get_polygon_count(); i++) {
Vector<int> polygon = navpoly->get_polygon(i);
- for(int j=2;j<polygon.size();j++) {
+ for (int j = 2; j < polygon.size(); j++) {
- int kofs[3]={0,j-1,j};
- for(int k=0;k<3;k++) {
+ int kofs[3] = { 0, j - 1, j };
+ for (int k = 0; k < 3; k++) {
- int idx = polygon[ kofs[k] ];
- ERR_FAIL_INDEX(idx,vsize);
+ int idx = polygon[kofs[k]];
+ ERR_FAIL_INDEX(idx, vsize);
indices.push_back(idx);
}
}
}
- VS::get_singleton()->canvas_item_add_triangle_array(get_canvas_item(),indices,vertices,colors);
-
+ VS::get_singleton()->canvas_item_add_triangle_array(get_canvas_item(), indices, vertices, colors);
}
} break;
-
}
}
+void NavigationPolygonInstance::set_navigation_polygon(const Ref<NavigationPolygon> &p_navpoly) {
-void NavigationPolygonInstance::set_navigation_polygon(const Ref<NavigationPolygon>& p_navpoly) {
-
- if (p_navpoly==navpoly)
+ if (p_navpoly == navpoly)
return;
- if (navigation && nav_id!=-1) {
+ if (navigation && nav_id != -1) {
navigation->navpoly_remove(nav_id);
- nav_id=-1;
+ nav_id = -1;
}
if (navpoly.is_valid()) {
- navpoly->disconnect(CoreStringNames::get_singleton()->changed,this,"_navpoly_changed");
+ navpoly->disconnect(CoreStringNames::get_singleton()->changed, this, "_navpoly_changed");
}
- navpoly=p_navpoly;
+ navpoly = p_navpoly;
if (navpoly.is_valid()) {
- navpoly->connect(CoreStringNames::get_singleton()->changed,this,"_navpoly_changed");
+ navpoly->connect(CoreStringNames::get_singleton()->changed, this, "_navpoly_changed");
}
if (navigation && navpoly.is_valid() && enabled) {
- nav_id = navigation->navpoly_create(navpoly,get_relative_transform_to_parent(navigation),this);
+ nav_id = navigation->navpoly_create(navpoly, get_relative_transform_to_parent(navigation), this);
}
//update_gizmo();
_change_notify("navpoly");
update_configuration_warning();
-
}
-Ref<NavigationPolygon> NavigationPolygonInstance::get_navigation_polygon() const{
+Ref<NavigationPolygon> NavigationPolygonInstance::get_navigation_polygon() const {
return navpoly;
}
@@ -456,7 +433,6 @@ void NavigationPolygonInstance::_navpoly_changed() {
update();
}
-
String NavigationPolygonInstance::get_configuration_warning() const {
if (!is_visible_in_tree() || !is_inside_tree())
@@ -465,14 +441,14 @@ String NavigationPolygonInstance::get_configuration_warning() const {
if (!navpoly.is_valid()) {
return TTR("A NavigationPolygon resource must be set or created for this node to work. Please set a property or draw a polygon.");
}
- const Node2D *c=this;
- while(c) {
+ const Node2D *c = this;
+ while (c) {
if (c->cast_to<Navigation2D>()) {
return String();
}
- c=c->get_parent()->cast_to<Node2D>();
+ c = c->get_parent()->cast_to<Node2D>();
}
return TTR("NavigationPolygonInstance must be a child or grandchild to a Navigation2D node. It only provides navigation data.");
@@ -480,23 +456,22 @@ String NavigationPolygonInstance::get_configuration_warning() const {
void NavigationPolygonInstance::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_navigation_polygon","navpoly:NavigationPolygon"),&NavigationPolygonInstance::set_navigation_polygon);
- ClassDB::bind_method(D_METHOD("get_navigation_polygon:NavigationPolygon"),&NavigationPolygonInstance::get_navigation_polygon);
+ ClassDB::bind_method(D_METHOD("set_navigation_polygon", "navpoly:NavigationPolygon"), &NavigationPolygonInstance::set_navigation_polygon);
+ ClassDB::bind_method(D_METHOD("get_navigation_polygon:NavigationPolygon"), &NavigationPolygonInstance::get_navigation_polygon);
- ClassDB::bind_method(D_METHOD("set_enabled","enabled"),&NavigationPolygonInstance::set_enabled);
- ClassDB::bind_method(D_METHOD("is_enabled"),&NavigationPolygonInstance::is_enabled);
+ ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &NavigationPolygonInstance::set_enabled);
+ ClassDB::bind_method(D_METHOD("is_enabled"), &NavigationPolygonInstance::is_enabled);
- ClassDB::bind_method(D_METHOD("_navpoly_changed"),&NavigationPolygonInstance::_navpoly_changed);
+ ClassDB::bind_method(D_METHOD("_navpoly_changed"), &NavigationPolygonInstance::_navpoly_changed);
- ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"navpoly",PROPERTY_HINT_RESOURCE_TYPE,"NavigationPolygon"),"set_navigation_polygon","get_navigation_polygon");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"enabled"),"set_enabled","is_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "navpoly", PROPERTY_HINT_RESOURCE_TYPE, "NavigationPolygon"), "set_navigation_polygon", "get_navigation_polygon");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled");
}
NavigationPolygonInstance::NavigationPolygonInstance() {
- navigation=NULL;
- nav_id=-1;
- enabled=true;
+ navigation = NULL;
+ nav_id = -1;
+ enabled = true;
set_notify_transform(true);
-
}
diff --git a/scene/2d/navigation_polygon.h b/scene/2d/navigation_polygon.h
index 7f1762b6f5..6bc3b903c7 100644
--- a/scene/2d/navigation_polygon.h
+++ b/scene/2d/navigation_polygon.h
@@ -31,41 +31,36 @@
#include "scene/2d/node_2d.h"
+class NavigationPolygon : public Resource {
-class NavigationPolygon : public Resource {
-
- GDCLASS( NavigationPolygon, Resource );
+ GDCLASS(NavigationPolygon, Resource);
PoolVector<Vector2> vertices;
struct Polygon {
Vector<int> indices;
};
Vector<Polygon> polygons;
- Vector< PoolVector<Vector2> > outlines;
+ Vector<PoolVector<Vector2> > outlines;
protected:
-
static void _bind_methods();
- void _set_polygons(const Array& p_array);
+ void _set_polygons(const Array &p_array);
Array _get_polygons() const;
- void _set_outlines(const Array& p_array);
+ void _set_outlines(const Array &p_array);
Array _get_outlines() const;
public:
-
-
-
- void set_vertices(const PoolVector<Vector2>& p_vertices);
+ void set_vertices(const PoolVector<Vector2> &p_vertices);
PoolVector<Vector2> get_vertices() const;
- void add_polygon(const Vector<int>& p_polygon);
+ void add_polygon(const Vector<int> &p_polygon);
int get_polygon_count() const;
- void add_outline(const PoolVector<Vector2>& p_outline);
- void add_outline_at_index(const PoolVector<Vector2>& p_outline,int p_index);
- void set_outline(int p_idx,const PoolVector<Vector2>& p_outline);
+ void add_outline(const PoolVector<Vector2> &p_outline);
+ void add_outline_at_index(const PoolVector<Vector2> &p_outline, int p_index);
+ void set_outline(int p_idx, const PoolVector<Vector2> &p_outline);
PoolVector<Vector2> get_outline(int p_idx) const;
void remove_outline(int p_idx);
int get_outline_count() const;
@@ -79,12 +74,11 @@ public:
NavigationPolygon();
};
-
class Navigation2D;
class NavigationPolygonInstance : public Node2D {
- GDCLASS(NavigationPolygonInstance,Node2D);
+ GDCLASS(NavigationPolygonInstance, Node2D);
bool enabled;
int nav_id;
@@ -94,15 +88,14 @@ class NavigationPolygonInstance : public Node2D {
void _navpoly_changed();
protected:
-
void _notification(int p_what);
static void _bind_methods();
-public:
+public:
void set_enabled(bool p_enabled);
bool is_enabled() const;
- void set_navigation_polygon(const Ref<NavigationPolygon>& p_navpoly);
+ void set_navigation_polygon(const Ref<NavigationPolygon> &p_navpoly);
Ref<NavigationPolygon> get_navigation_polygon() const;
String get_configuration_warning() const;
@@ -110,5 +103,4 @@ public:
NavigationPolygonInstance();
};
-
#endif // NAVIGATIONPOLYGON_H
diff --git a/scene/2d/node_2d.cpp b/scene/2d/node_2d.cpp
index 710f9731c5..1ba6ec46cf 100644
--- a/scene/2d/node_2d.cpp
+++ b/scene/2d/node_2d.cpp
@@ -28,15 +28,12 @@
/*************************************************************************/
#include "node_2d.h"
-#include "servers/visual_server.h"
+#include "message_queue.h"
#include "scene/gui/control.h"
#include "scene/main/viewport.h"
-#include "message_queue.h"
-
-
-void Node2D::edit_set_pivot(const Point2& p_pivot) {
-
+#include "servers/visual_server.h"
+void Node2D::edit_set_pivot(const Point2 &p_pivot) {
}
Point2 Node2D::edit_get_pivot() const {
@@ -56,12 +53,11 @@ Variant Node2D::edit_get_state() const {
state.push_back(get_scale());
return state;
-
}
-void Node2D::edit_set_state(const Variant& p_state) {
+void Node2D::edit_set_state(const Variant &p_state) {
Array state = p_state;
- ERR_FAIL_COND( state.size() != 3);
+ ERR_FAIL_COND(state.size() != 3);
pos = state[0];
angle = state[1];
@@ -70,89 +66,82 @@ void Node2D::edit_set_state(const Variant& p_state) {
_change_notify("transform/rot");
_change_notify("transform/scale");
_change_notify("transform/pos");
-
}
-void Node2D::edit_set_rect(const Rect2& p_edit_rect) {
+void Node2D::edit_set_rect(const Rect2 &p_edit_rect) {
Rect2 r = get_item_rect();
Vector2 zero_offset;
- if (r.size.x!=0)
+ if (r.size.x != 0)
zero_offset.x = -r.pos.x / r.size.x;
- if (r.size.y!=0)
+ if (r.size.y != 0)
zero_offset.y = -r.pos.y / r.size.y;
- Size2 new_scale(1,1);
+ Size2 new_scale(1, 1);
- if (r.size.x!=0)
+ if (r.size.x != 0)
new_scale.x = p_edit_rect.size.x / r.size.x;
- if (r.size.y!=0)
+ if (r.size.y != 0)
new_scale.y = p_edit_rect.size.y / r.size.y;
- Point2 new_pos = p_edit_rect.pos + p_edit_rect.size*zero_offset;//p_edit_rect.pos - r.pos;
+ Point2 new_pos = p_edit_rect.pos + p_edit_rect.size * zero_offset; //p_edit_rect.pos - r.pos;
Transform2D postxf;
- postxf.set_rotation_and_scale(angle,_scale);
+ postxf.set_rotation_and_scale(angle, _scale);
new_pos = postxf.xform(new_pos);
- pos+=new_pos;
- _scale*=new_scale;
+ pos += new_pos;
+ _scale *= new_scale;
_update_transform();
_change_notify("transform/scale");
_change_notify("transform/pos");
-
}
-
void Node2D::edit_rotate(float p_rot) {
- angle+=p_rot;
+ angle += p_rot;
_update_transform();
_change_notify("transform/rot");
}
-
void Node2D::_update_xform_values() {
- pos=_mat.elements[2];
- angle=_mat.get_rotation();
- _scale=_mat.get_scale();
- _xform_dirty=false;
+ pos = _mat.elements[2];
+ angle = _mat.get_rotation();
+ _scale = _mat.get_scale();
+ _xform_dirty = false;
}
void Node2D::_update_transform() {
- Transform2D mat(angle,pos);
- _mat.set_rotation_and_scale(angle,_scale);
- _mat.elements[2]=pos;
+ Transform2D mat(angle, pos);
+ _mat.set_rotation_and_scale(angle, _scale);
+ _mat.elements[2] = pos;
- VisualServer::get_singleton()->canvas_item_set_transform(get_canvas_item(),_mat);
+ VisualServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), _mat);
if (!is_inside_tree())
return;
-
_notify_transform();
}
-void Node2D::set_position(const Point2& p_pos) {
+void Node2D::set_position(const Point2 &p_pos) {
if (_xform_dirty)
- ((Node2D*)this)->_update_xform_values();
- pos=p_pos;
+ ((Node2D *)this)->_update_xform_values();
+ pos = p_pos;
_update_transform();
_change_notify("transform/pos");
-
-
}
void Node2D::set_rotation(float p_radians) {
if (_xform_dirty)
- ((Node2D*)this)->_update_xform_values();
- angle=p_radians;
+ ((Node2D *)this)->_update_xform_values();
+ angle = p_radians;
_update_transform();
_change_notify("transform/rot");
}
@@ -170,29 +159,28 @@ void Node2D::_set_rotd(float p_degrees) {
set_rotation_in_degrees(p_degrees);
}
-void Node2D::set_scale(const Size2& p_scale) {
+void Node2D::set_scale(const Size2 &p_scale) {
if (_xform_dirty)
- ((Node2D*)this)->_update_xform_values();
- _scale=p_scale;
- if (_scale.x==0)
- _scale.x=CMP_EPSILON;
- if (_scale.y==0)
- _scale.y=CMP_EPSILON;
+ ((Node2D *)this)->_update_xform_values();
+ _scale = p_scale;
+ if (_scale.x == 0)
+ _scale.x = CMP_EPSILON;
+ if (_scale.y == 0)
+ _scale.y = CMP_EPSILON;
_update_transform();
_change_notify("transform/scale");
-
}
Point2 Node2D::get_position() const {
if (_xform_dirty)
- ((Node2D*)this)->_update_xform_values();
+ ((Node2D *)this)->_update_xform_values();
return pos;
}
float Node2D::get_rotation() const {
if (_xform_dirty)
- ((Node2D*)this)->_update_xform_values();
+ ((Node2D *)this)->_update_xform_values();
return angle;
}
@@ -209,16 +197,14 @@ float Node2D::_get_rotd() const {
}
Size2 Node2D::get_scale() const {
if (_xform_dirty)
- ((Node2D*)this)->_update_xform_values();
+ ((Node2D *)this)->_update_xform_values();
return _scale;
}
-
void Node2D::_notification(int p_what) {
- switch(p_what) {
-
+ switch (p_what) {
}
}
@@ -231,59 +217,57 @@ Rect2 Node2D::get_item_rect() const {
if (get_script_instance()) {
Variant::CallError err;
- Rect2 r = get_script_instance()->call("_get_item_rect",NULL,0,err);
- if (err.error==Variant::CallError::CALL_OK)
+ Rect2 r = get_script_instance()->call("_get_item_rect", NULL, 0, err);
+ if (err.error == Variant::CallError::CALL_OK)
return r;
}
- return Rect2(Point2(-32,-32),Size2(64,64));
+ return Rect2(Point2(-32, -32), Size2(64, 64));
}
void Node2D::rotate(float p_radians) {
- set_rotation( get_rotation() + p_radians);
+ set_rotation(get_rotation() + p_radians);
}
-void Node2D::translate(const Vector2& p_amount) {
+void Node2D::translate(const Vector2 &p_amount) {
- set_position( get_position() + p_amount );
+ set_position(get_position() + p_amount);
}
-void Node2D::global_translate(const Vector2& p_amount) {
+void Node2D::global_translate(const Vector2 &p_amount) {
- set_global_position( get_global_position() + p_amount );
+ set_global_position(get_global_position() + p_amount);
}
-void Node2D::scale(const Size2& p_amount) {
+void Node2D::scale(const Size2 &p_amount) {
- set_scale( get_scale() * p_amount );
+ set_scale(get_scale() * p_amount);
}
-
-void Node2D::move_x(float p_delta,bool p_scaled){
+void Node2D::move_x(float p_delta, bool p_scaled) {
Transform2D t = get_transform();
Vector2 m = t[0];
if (!p_scaled)
m.normalize();
- set_position(t[2]+m*p_delta);
+ set_position(t[2] + m * p_delta);
}
-void Node2D::move_y(float p_delta,bool p_scaled){
+void Node2D::move_y(float p_delta, bool p_scaled) {
Transform2D t = get_transform();
Vector2 m = t[1];
if (!p_scaled)
m.normalize();
- set_position(t[2]+m*p_delta);
+ set_position(t[2] + m * p_delta);
}
-
Point2 Node2D::get_global_position() const {
return get_global_transform().get_origin();
}
-void Node2D::set_global_position(const Point2& p_pos) {
+void Node2D::set_global_position(const Point2 &p_pos) {
Transform2D inv;
CanvasItem *pi = get_parent_item();
@@ -295,7 +279,6 @@ void Node2D::set_global_position(const Point2& p_pos) {
}
}
-
float Node2D::get_global_rotation() const {
return get_global_transform().get_rotation();
@@ -312,7 +295,6 @@ void Node2D::set_global_rotation(float p_radians) {
}
}
-
float Node2D::get_global_rotation_in_degrees() const {
return Math::rad2deg(get_global_rotation());
@@ -323,13 +305,12 @@ void Node2D::set_global_rotation_in_degrees(float p_degrees) {
set_global_rotation(Math::deg2rad(p_degrees));
}
-
Size2 Node2D::get_global_scale() const {
return get_global_transform().get_scale();
}
-void Node2D::set_global_scale(const Size2& p_scale) {
+void Node2D::set_global_scale(const Size2 &p_scale) {
CanvasItem *pi = get_parent_item();
if (pi) {
@@ -338,16 +319,14 @@ void Node2D::set_global_scale(const Size2& p_scale) {
} else {
set_scale(p_scale);
}
-
}
+void Node2D::set_transform(const Transform2D &p_transform) {
-void Node2D::set_transform(const Transform2D& p_transform) {
+ _mat = p_transform;
+ _xform_dirty = true;
- _mat=p_transform;
- _xform_dirty=true;
-
- VisualServer::get_singleton()->canvas_item_set_transform(get_canvas_item(),_mat);
+ VisualServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), _mat);
if (!is_inside_tree())
return;
@@ -355,32 +334,29 @@ void Node2D::set_transform(const Transform2D& p_transform) {
_notify_transform();
}
-void Node2D::set_global_transform(const Transform2D& p_transform) {
+void Node2D::set_global_transform(const Transform2D &p_transform) {
CanvasItem *pi = get_parent_item();
if (pi)
- set_transform( pi->get_global_transform().affine_inverse() * p_transform);
+ set_transform(pi->get_global_transform().affine_inverse() * p_transform);
else
set_transform(p_transform);
-
-
}
void Node2D::set_z(int p_z) {
- ERR_FAIL_COND(p_z<VS::CANVAS_ITEM_Z_MIN);
- ERR_FAIL_COND(p_z>VS::CANVAS_ITEM_Z_MAX);
- z=p_z;
- VS::get_singleton()->canvas_item_set_z(get_canvas_item(),z);
-
+ ERR_FAIL_COND(p_z < VS::CANVAS_ITEM_Z_MIN);
+ ERR_FAIL_COND(p_z > VS::CANVAS_ITEM_Z_MAX);
+ z = p_z;
+ VS::get_singleton()->canvas_item_set_z(get_canvas_item(), z);
}
void Node2D::set_z_as_relative(bool p_enabled) {
- if (z_relative==p_enabled)
+ if (z_relative == p_enabled)
return;
- z_relative=p_enabled;
- VS::get_singleton()->canvas_item_set_z_as_relative_to_parent(get_canvas_item(),p_enabled);
+ z_relative = p_enabled;
+ VS::get_singleton()->canvas_item_set_z_as_relative_to_parent(get_canvas_item(), p_enabled);
}
bool Node2D::is_z_relative() const {
@@ -388,115 +364,106 @@ bool Node2D::is_z_relative() const {
return z_relative;
}
-
-int Node2D::get_z() const{
+int Node2D::get_z() const {
return z;
}
Transform2D Node2D::get_relative_transform_to_parent(const Node *p_parent) const {
- if (p_parent==this)
+ if (p_parent == this)
return Transform2D();
Node2D *parent_2d = get_parent()->cast_to<Node2D>();
- ERR_FAIL_COND_V(!parent_2d,Transform2D());
- if (p_parent==parent_2d)
+ ERR_FAIL_COND_V(!parent_2d, Transform2D());
+ if (p_parent == parent_2d)
return get_transform();
else
return parent_2d->get_relative_transform_to_parent(p_parent) * get_transform();
}
-
-void Node2D::look_at(const Vector2& p_pos) {
+void Node2D::look_at(const Vector2 &p_pos) {
rotate(get_angle_to(p_pos));
}
-float Node2D::get_angle_to(const Vector2& p_pos) const {
+float Node2D::get_angle_to(const Vector2 &p_pos) const {
return (get_global_transform().affine_inverse().xform(p_pos)).angle();
}
void Node2D::_bind_methods() {
-
// TODO: Obsolete those two methods (old name) properly (GH-4397)
- ClassDB::bind_method(D_METHOD("_get_rotd"),&Node2D::_get_rotd);
- ClassDB::bind_method(D_METHOD("_set_rotd","degrees"),&Node2D::_set_rotd);
-
- ClassDB::bind_method(D_METHOD("set_position","pos"),&Node2D::set_position);
- ClassDB::bind_method(D_METHOD("set_rotation","radians"),&Node2D::set_rotation);
- ClassDB::bind_method(D_METHOD("set_rotation_in_degrees","degrees"),&Node2D::set_rotation_in_degrees);
- ClassDB::bind_method(D_METHOD("set_scale","scale"),&Node2D::set_scale);
-
- ClassDB::bind_method(D_METHOD("get_position"),&Node2D::get_position);
- ClassDB::bind_method(D_METHOD("get_rotation"),&Node2D::get_rotation);
- ClassDB::bind_method(D_METHOD("get_rotation_in_degrees"),&Node2D::get_rotation_in_degrees);
- ClassDB::bind_method(D_METHOD("get_scale"),&Node2D::get_scale);
+ ClassDB::bind_method(D_METHOD("_get_rotd"), &Node2D::_get_rotd);
+ ClassDB::bind_method(D_METHOD("_set_rotd", "degrees"), &Node2D::_set_rotd);
- ClassDB::bind_method(D_METHOD("rotate","radians"),&Node2D::rotate);
- ClassDB::bind_method(D_METHOD("move_local_x","delta","scaled"),&Node2D::move_x,DEFVAL(false));
- ClassDB::bind_method(D_METHOD("move_local_y","delta","scaled"),&Node2D::move_y,DEFVAL(false));
- ClassDB::bind_method(D_METHOD("translate","offset"),&Node2D::translate);
- ClassDB::bind_method(D_METHOD("global_translate","offset"),&Node2D::global_translate);
- ClassDB::bind_method(D_METHOD("scale","ratio"),&Node2D::scale);
+ ClassDB::bind_method(D_METHOD("set_position", "pos"), &Node2D::set_position);
+ ClassDB::bind_method(D_METHOD("set_rotation", "radians"), &Node2D::set_rotation);
+ ClassDB::bind_method(D_METHOD("set_rotation_in_degrees", "degrees"), &Node2D::set_rotation_in_degrees);
+ ClassDB::bind_method(D_METHOD("set_scale", "scale"), &Node2D::set_scale);
- ClassDB::bind_method(D_METHOD("set_global_position","pos"),&Node2D::set_global_position);
- ClassDB::bind_method(D_METHOD("get_global_position"),&Node2D::get_global_position);
- ClassDB::bind_method(D_METHOD("set_global_rotation","radians"),&Node2D::set_global_rotation);
- ClassDB::bind_method(D_METHOD("get_global_rotation"),&Node2D::get_global_rotation);
- ClassDB::bind_method(D_METHOD("set_global_rotation_in_degrees","degrees"),&Node2D::set_global_rotation_in_degrees);
- ClassDB::bind_method(D_METHOD("get_global_rotation_in_degrees"),&Node2D::get_global_rotation_in_degrees);
- ClassDB::bind_method(D_METHOD("set_global_scale","scale"),&Node2D::set_global_scale);
- ClassDB::bind_method(D_METHOD("get_global_scale"),&Node2D::get_global_scale);
+ ClassDB::bind_method(D_METHOD("get_position"), &Node2D::get_position);
+ ClassDB::bind_method(D_METHOD("get_rotation"), &Node2D::get_rotation);
+ ClassDB::bind_method(D_METHOD("get_rotation_in_degrees"), &Node2D::get_rotation_in_degrees);
+ ClassDB::bind_method(D_METHOD("get_scale"), &Node2D::get_scale);
- ClassDB::bind_method(D_METHOD("set_transform","xform"),&Node2D::set_transform);
- ClassDB::bind_method(D_METHOD("set_global_transform","xform"),&Node2D::set_global_transform);
+ ClassDB::bind_method(D_METHOD("rotate", "radians"), &Node2D::rotate);
+ ClassDB::bind_method(D_METHOD("move_local_x", "delta", "scaled"), &Node2D::move_x, DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("move_local_y", "delta", "scaled"), &Node2D::move_y, DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("translate", "offset"), &Node2D::translate);
+ ClassDB::bind_method(D_METHOD("global_translate", "offset"), &Node2D::global_translate);
+ ClassDB::bind_method(D_METHOD("scale", "ratio"), &Node2D::scale);
- ClassDB::bind_method(D_METHOD("look_at","point"),&Node2D::look_at);
- ClassDB::bind_method(D_METHOD("get_angle_to","point"),&Node2D::get_angle_to);
+ ClassDB::bind_method(D_METHOD("set_global_position", "pos"), &Node2D::set_global_position);
+ ClassDB::bind_method(D_METHOD("get_global_position"), &Node2D::get_global_position);
+ ClassDB::bind_method(D_METHOD("set_global_rotation", "radians"), &Node2D::set_global_rotation);
+ ClassDB::bind_method(D_METHOD("get_global_rotation"), &Node2D::get_global_rotation);
+ ClassDB::bind_method(D_METHOD("set_global_rotation_in_degrees", "degrees"), &Node2D::set_global_rotation_in_degrees);
+ ClassDB::bind_method(D_METHOD("get_global_rotation_in_degrees"), &Node2D::get_global_rotation_in_degrees);
+ ClassDB::bind_method(D_METHOD("set_global_scale", "scale"), &Node2D::set_global_scale);
+ ClassDB::bind_method(D_METHOD("get_global_scale"), &Node2D::get_global_scale);
- ClassDB::bind_method(D_METHOD("set_z","z"),&Node2D::set_z);
- ClassDB::bind_method(D_METHOD("get_z"),&Node2D::get_z);
+ ClassDB::bind_method(D_METHOD("set_transform", "xform"), &Node2D::set_transform);
+ ClassDB::bind_method(D_METHOD("set_global_transform", "xform"), &Node2D::set_global_transform);
- ClassDB::bind_method(D_METHOD("set_z_as_relative","enable"),&Node2D::set_z_as_relative);
- ClassDB::bind_method(D_METHOD("is_z_relative"),&Node2D::is_z_relative);
+ ClassDB::bind_method(D_METHOD("look_at", "point"), &Node2D::look_at);
+ ClassDB::bind_method(D_METHOD("get_angle_to", "point"), &Node2D::get_angle_to);
- ClassDB::bind_method(D_METHOD("edit_set_pivot","pivot"),&Node2D::edit_set_pivot);
+ ClassDB::bind_method(D_METHOD("set_z", "z"), &Node2D::set_z);
+ ClassDB::bind_method(D_METHOD("get_z"), &Node2D::get_z);
- ClassDB::bind_method(D_METHOD("get_relative_transform_to_parent","parent"),&Node2D::get_relative_transform_to_parent);
+ ClassDB::bind_method(D_METHOD("set_z_as_relative", "enable"), &Node2D::set_z_as_relative);
+ ClassDB::bind_method(D_METHOD("is_z_relative"), &Node2D::is_z_relative);
- ADD_GROUP("Transform","");
- ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2,"position"),"set_position","get_position");
- ADD_PROPERTYNZ(PropertyInfo(Variant::REAL,"rotation",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"set_rotation","get_rotation");
- ADD_PROPERTYNZ(PropertyInfo(Variant::REAL,"rotation_deg",PROPERTY_HINT_RANGE,"-1440,1440,0.1",PROPERTY_USAGE_EDITOR),"set_rotation_in_degrees","get_rotation_in_degrees");
- ADD_PROPERTYNO(PropertyInfo(Variant::VECTOR2,"scale"),"set_scale","get_scale");
- ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D,"transform",PROPERTY_HINT_NONE,"",0),"set_transform","get_transform");
+ ClassDB::bind_method(D_METHOD("edit_set_pivot", "pivot"), &Node2D::edit_set_pivot);
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"global_position",PROPERTY_HINT_NONE,"",0),"set_global_position","get_global_position");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"global_rotation",PROPERTY_HINT_NONE,"",0),"set_global_rotation","get_global_rotation");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"global_rotation_deg",PROPERTY_HINT_NONE,"",0),"set_global_rotation_in_degrees","get_global_rotation_in_degrees");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"global_scale",PROPERTY_HINT_NONE,"",0),"set_global_scale","get_global_scale");
- ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D,"global_transform",PROPERTY_HINT_NONE,"",0),"set_global_transform","get_global_transform");
+ ClassDB::bind_method(D_METHOD("get_relative_transform_to_parent", "parent"), &Node2D::get_relative_transform_to_parent);
- ADD_GROUP("Z","");
- ADD_PROPERTYNZ(PropertyInfo(Variant::INT,"z",PROPERTY_HINT_RANGE,itos(VS::CANVAS_ITEM_Z_MIN)+","+itos(VS::CANVAS_ITEM_Z_MAX)+",1"),"set_z","get_z");
- ADD_PROPERTYNO(PropertyInfo(Variant::BOOL,"z_as_relative"),"set_z_as_relative","is_z_relative");
+ ADD_GROUP("Transform", "");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "position"), "set_position", "get_position");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "rotation", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_rotation", "get_rotation");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "rotation_deg", PROPERTY_HINT_RANGE, "-1440,1440,0.1", PROPERTY_USAGE_EDITOR), "set_rotation_in_degrees", "get_rotation_in_degrees");
+ ADD_PROPERTYNO(PropertyInfo(Variant::VECTOR2, "scale"), "set_scale", "get_scale");
+ ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "transform", PROPERTY_HINT_NONE, "", 0), "set_transform", "get_transform");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "global_position", PROPERTY_HINT_NONE, "", 0), "set_global_position", "get_global_position");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "global_rotation", PROPERTY_HINT_NONE, "", 0), "set_global_rotation", "get_global_rotation");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "global_rotation_deg", PROPERTY_HINT_NONE, "", 0), "set_global_rotation_in_degrees", "get_global_rotation_in_degrees");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "global_scale", PROPERTY_HINT_NONE, "", 0), "set_global_scale", "get_global_scale");
+ ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "global_transform", PROPERTY_HINT_NONE, "", 0), "set_global_transform", "get_global_transform");
+ ADD_GROUP("Z", "");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "z", PROPERTY_HINT_RANGE, itos(VS::CANVAS_ITEM_Z_MIN) + "," + itos(VS::CANVAS_ITEM_Z_MAX) + ",1"), "set_z", "get_z");
+ ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "z_as_relative"), "set_z_as_relative", "is_z_relative");
}
-
Node2D::Node2D() {
-
- angle=0;
- _scale=Vector2(1,1);
- _xform_dirty=false;
- z=0;
- z_relative=true;
-
+ angle = 0;
+ _scale = Vector2(1, 1);
+ _xform_dirty = false;
+ z = 0;
+ z_relative = true;
}
-
diff --git a/scene/2d/node_2d.h b/scene/2d/node_2d.h
index 2cceef0f06..b9c6894333 100644
--- a/scene/2d/node_2d.h
+++ b/scene/2d/node_2d.h
@@ -33,7 +33,7 @@
class Node2D : public CanvasItem {
- GDCLASS(Node2D, CanvasItem );
+ GDCLASS(Node2D, CanvasItem);
Point2 pos;
float angle;
@@ -54,32 +54,30 @@ class Node2D : public CanvasItem {
void _update_xform_values();
protected:
-
-
void _notification(int p_what);
static void _bind_methods();
-public:
+public:
virtual Variant edit_get_state() const;
- virtual void edit_set_state(const Variant& p_state);
- virtual void edit_set_rect(const Rect2& p_edit_rect);
+ virtual void edit_set_state(const Variant &p_state);
+ virtual void edit_set_rect(const Rect2 &p_edit_rect);
virtual void edit_rotate(float p_rot);
- virtual void edit_set_pivot(const Point2& p_pivot);
+ virtual void edit_set_pivot(const Point2 &p_pivot);
virtual Point2 edit_get_pivot() const;
virtual bool edit_has_pivot() const;
- void set_position(const Point2& p_pos);
+ void set_position(const Point2 &p_pos);
void set_rotation(float p_radians);
void set_rotation_in_degrees(float p_degrees);
- void set_scale(const Size2& p_scale);
+ void set_scale(const Size2 &p_scale);
void rotate(float p_radians);
- void move_x(float p_delta,bool p_scaled=false);
- void move_y(float p_delta,bool p_scaled=false);
- void translate(const Vector2& p_amount);
- void global_translate(const Vector2& p_amount);
- void scale(const Size2& p_amount);
+ void move_x(float p_delta, bool p_scaled = false);
+ void move_y(float p_delta, bool p_scaled = false);
+ void translate(const Vector2 &p_amount);
+ void global_translate(const Vector2 &p_amount);
+ void scale(const Size2 &p_amount);
Point2 get_position() const;
float get_rotation() const;
@@ -92,18 +90,18 @@ public:
Size2 get_global_scale() const;
virtual Rect2 get_item_rect() const;
- void set_transform(const Transform2D& p_transform);
- void set_global_transform(const Transform2D& p_transform);
- void set_global_position(const Point2& p_pos);
+ void set_transform(const Transform2D &p_transform);
+ void set_global_transform(const Transform2D &p_transform);
+ void set_global_position(const Point2 &p_pos);
void set_global_rotation(float p_radians);
void set_global_rotation_in_degrees(float p_degrees);
- void set_global_scale(const Size2& p_scale);
+ void set_global_scale(const Size2 &p_scale);
void set_z(int p_z);
int get_z() const;
- void look_at(const Vector2& p_pos);
- float get_angle_to(const Vector2& p_pos) const;
+ void look_at(const Vector2 &p_pos);
+ float get_angle_to(const Vector2 &p_pos) const;
void set_z_as_relative(bool p_enabled);
bool is_z_relative() const;
diff --git a/scene/2d/parallax_background.cpp b/scene/2d/parallax_background.cpp
index 9336dc51af..17bc26aa7f 100644
--- a/scene/2d/parallax_background.cpp
+++ b/scene/2d/parallax_background.cpp
@@ -29,16 +29,13 @@
#include "parallax_background.h"
#include "parallax_layer.h"
-
-
void ParallaxBackground::_notification(int p_what) {
- switch(p_what) {
-
+ switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
- group_name = "__cameras_"+itos(get_viewport().get_id());
+ group_name = "__cameras_" + itos(get_viewport().get_id());
add_to_group(group_name);
} break;
@@ -47,31 +44,27 @@ void ParallaxBackground::_notification(int p_what) {
remove_from_group(group_name);
} break;
}
-
}
-void ParallaxBackground::_camera_moved(const Transform2D& p_transform) {
-
+void ParallaxBackground::_camera_moved(const Transform2D &p_transform) {
set_scroll_offset(p_transform.get_origin());
- set_scroll_scale(p_transform.get_scale().dot(Vector2(0.5,0.5)));
+ set_scroll_scale(p_transform.get_scale().dot(Vector2(0.5, 0.5)));
}
-
void ParallaxBackground::set_scroll_scale(float p_scale) {
- scale=p_scale;
+ scale = p_scale;
}
-float ParallaxBackground::get_scroll_scale() const{
+float ParallaxBackground::get_scroll_scale() const {
return scale;
}
+void ParallaxBackground::set_scroll_offset(const Point2 &p_ofs) {
-void ParallaxBackground::set_scroll_offset(const Point2& p_ofs) {
-
- offset=p_ofs;
+ offset = p_ofs;
_update_scroll();
}
@@ -81,7 +74,7 @@ void ParallaxBackground::_update_scroll() {
if (!is_inside_tree())
return;
- Vector2 ofs = base_offset+offset*base_scale;
+ Vector2 ofs = base_offset + offset * base_scale;
Size2 vps = get_viewport_size();
@@ -89,26 +82,25 @@ void ParallaxBackground::_update_scroll() {
if (limit_begin.x < limit_end.x) {
if (ofs.x < limit_begin.x)
- ofs.x=limit_begin.x;
- else if (ofs.x+vps.x > limit_end.x)
- ofs.x=limit_end.x-vps.x;
+ ofs.x = limit_begin.x;
+ else if (ofs.x + vps.x > limit_end.x)
+ ofs.x = limit_end.x - vps.x;
}
-
if (limit_begin.y < limit_end.y) {
if (ofs.y < limit_begin.y)
- ofs.y=limit_begin.y;
- else if (ofs.y+vps.y > limit_end.y)
- ofs.y=limit_end.y-vps.y;
+ ofs.y = limit_begin.y;
+ else if (ofs.y + vps.y > limit_end.y)
+ ofs.y = limit_end.y - vps.y;
}
ofs = -ofs;
- final_offset=ofs;
+ final_offset = ofs;
- for(int i=0;i<get_child_count();i++) {
+ for (int i = 0; i < get_child_count(); i++) {
- ParallaxLayer *l=get_child(i)->cast_to<ParallaxLayer>();
+ ParallaxLayer *l = get_child(i)->cast_to<ParallaxLayer>();
if (!l)
continue;
@@ -124,32 +116,31 @@ Point2 ParallaxBackground::get_scroll_offset() const {
return offset;
}
-void ParallaxBackground::set_scroll_base_offset(const Point2& p_ofs) {
+void ParallaxBackground::set_scroll_base_offset(const Point2 &p_ofs) {
- base_offset=p_ofs;
+ base_offset = p_ofs;
_update_scroll();
}
-Point2 ParallaxBackground::get_scroll_base_offset() const{
+Point2 ParallaxBackground::get_scroll_base_offset() const {
return base_offset;
}
-void ParallaxBackground::set_scroll_base_scale(const Point2& p_ofs) {
+void ParallaxBackground::set_scroll_base_scale(const Point2 &p_ofs) {
- base_scale=p_ofs;
+ base_scale = p_ofs;
_update_scroll();
}
-Point2 ParallaxBackground::get_scroll_base_scale() const{
+Point2 ParallaxBackground::get_scroll_base_scale() const {
return base_scale;
}
+void ParallaxBackground::set_limit_begin(const Point2 &p_ofs) {
-void ParallaxBackground::set_limit_begin(const Point2& p_ofs) {
-
- limit_begin=p_ofs;
+ limit_begin = p_ofs;
_update_scroll();
}
@@ -158,11 +149,10 @@ Point2 ParallaxBackground::get_limit_begin() const {
return limit_begin;
}
-void ParallaxBackground::set_limit_end(const Point2& p_ofs) {
+void ParallaxBackground::set_limit_end(const Point2 &p_ofs) {
- limit_end=p_ofs;
+ limit_end = p_ofs;
_update_scroll();
-
}
Point2 ParallaxBackground::get_limit_end() const {
@@ -170,16 +160,14 @@ Point2 ParallaxBackground::get_limit_end() const {
return limit_end;
}
-void ParallaxBackground::set_ignore_camera_zoom(bool ignore){
-
- ignore_camera_zoom = ignore;
+void ParallaxBackground::set_ignore_camera_zoom(bool ignore) {
+ ignore_camera_zoom = ignore;
}
-bool ParallaxBackground::is_ignore_camera_zoom(){
-
- return ignore_camera_zoom;
+bool ParallaxBackground::is_ignore_camera_zoom() {
+ return ignore_camera_zoom;
}
Vector2 ParallaxBackground::get_final_offset() const {
@@ -189,38 +177,32 @@ Vector2 ParallaxBackground::get_final_offset() const {
void ParallaxBackground::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_camera_moved"),&ParallaxBackground::_camera_moved);
- ClassDB::bind_method(D_METHOD("set_scroll_offset","ofs"),&ParallaxBackground::set_scroll_offset);
- ClassDB::bind_method(D_METHOD("get_scroll_offset"),&ParallaxBackground::get_scroll_offset);
- ClassDB::bind_method(D_METHOD("set_scroll_base_offset","ofs"),&ParallaxBackground::set_scroll_base_offset);
- ClassDB::bind_method(D_METHOD("get_scroll_base_offset"),&ParallaxBackground::get_scroll_base_offset);
- ClassDB::bind_method(D_METHOD("set_scroll_base_scale","scale"),&ParallaxBackground::set_scroll_base_scale);
- ClassDB::bind_method(D_METHOD("get_scroll_base_scale"),&ParallaxBackground::get_scroll_base_scale);
- ClassDB::bind_method(D_METHOD("set_limit_begin","ofs"),&ParallaxBackground::set_limit_begin);
- ClassDB::bind_method(D_METHOD("get_limit_begin"),&ParallaxBackground::get_limit_begin);
- ClassDB::bind_method(D_METHOD("set_limit_end","ofs"),&ParallaxBackground::set_limit_end);
- ClassDB::bind_method(D_METHOD("get_limit_end"),&ParallaxBackground::get_limit_end);
- ClassDB::bind_method(D_METHOD("set_ignore_camera_zoom","ignore"), &ParallaxBackground::set_ignore_camera_zoom);
- ClassDB::bind_method(D_METHOD("is_ignore_camera_zoom"), &ParallaxBackground::is_ignore_camera_zoom);
-
-
- ADD_GROUP("Scroll","scroll_");
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"scroll_offset"),"set_scroll_offset","get_scroll_offset");
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"scroll_base_offset"),"set_scroll_base_offset","get_scroll_base_offset");
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"scroll_base_scale"),"set_scroll_base_scale","get_scroll_base_scale");
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"scroll_limit_begin"),"set_limit_begin","get_limit_begin");
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"scroll_limit_end"),"set_limit_end","get_limit_end");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL, "scroll_ignore_camera_zoom"), "set_ignore_camera_zoom", "is_ignore_camera_zoom");
-
+ ClassDB::bind_method(D_METHOD("_camera_moved"), &ParallaxBackground::_camera_moved);
+ ClassDB::bind_method(D_METHOD("set_scroll_offset", "ofs"), &ParallaxBackground::set_scroll_offset);
+ ClassDB::bind_method(D_METHOD("get_scroll_offset"), &ParallaxBackground::get_scroll_offset);
+ ClassDB::bind_method(D_METHOD("set_scroll_base_offset", "ofs"), &ParallaxBackground::set_scroll_base_offset);
+ ClassDB::bind_method(D_METHOD("get_scroll_base_offset"), &ParallaxBackground::get_scroll_base_offset);
+ ClassDB::bind_method(D_METHOD("set_scroll_base_scale", "scale"), &ParallaxBackground::set_scroll_base_scale);
+ ClassDB::bind_method(D_METHOD("get_scroll_base_scale"), &ParallaxBackground::get_scroll_base_scale);
+ ClassDB::bind_method(D_METHOD("set_limit_begin", "ofs"), &ParallaxBackground::set_limit_begin);
+ ClassDB::bind_method(D_METHOD("get_limit_begin"), &ParallaxBackground::get_limit_begin);
+ ClassDB::bind_method(D_METHOD("set_limit_end", "ofs"), &ParallaxBackground::set_limit_end);
+ ClassDB::bind_method(D_METHOD("get_limit_end"), &ParallaxBackground::get_limit_end);
+ ClassDB::bind_method(D_METHOD("set_ignore_camera_zoom", "ignore"), &ParallaxBackground::set_ignore_camera_zoom);
+ ClassDB::bind_method(D_METHOD("is_ignore_camera_zoom"), &ParallaxBackground::is_ignore_camera_zoom);
+
+ ADD_GROUP("Scroll", "scroll_");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scroll_offset"), "set_scroll_offset", "get_scroll_offset");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scroll_base_offset"), "set_scroll_base_offset", "get_scroll_base_offset");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scroll_base_scale"), "set_scroll_base_scale", "get_scroll_base_scale");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scroll_limit_begin"), "set_limit_begin", "get_limit_begin");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scroll_limit_end"), "set_limit_end", "get_limit_end");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scroll_ignore_camera_zoom"), "set_ignore_camera_zoom", "is_ignore_camera_zoom");
}
-
-
-
-
ParallaxBackground::ParallaxBackground() {
- base_scale=Vector2(1,1);
- scale=1.0;
+ base_scale = Vector2(1, 1);
+ scale = 1.0;
set_layer(-1); //behind all by default
}
diff --git a/scene/2d/parallax_background.h b/scene/2d/parallax_background.h
index caef4962e8..5914c21c95 100644
--- a/scene/2d/parallax_background.h
+++ b/scene/2d/parallax_background.h
@@ -29,13 +29,13 @@
#ifndef PARALLAX_BACKGROUND_H
#define PARALLAX_BACKGROUND_H
-#include "scene/main/canvas_layer.h"
-#include "scene/2d/node_2d.h"
#include "scene/2d/camera_2d.h"
+#include "scene/2d/node_2d.h"
+#include "scene/main/canvas_layer.h"
class ParallaxBackground : public CanvasLayer {
- GDCLASS( ParallaxBackground, CanvasLayer );
+ GDCLASS(ParallaxBackground, CanvasLayer);
Point2 offset;
float scale;
@@ -48,30 +48,30 @@ class ParallaxBackground : public CanvasLayer {
bool ignore_camera_zoom;
void _update_scroll();
-protected:
- void _camera_moved(const Transform2D& p_transform);
+protected:
+ void _camera_moved(const Transform2D &p_transform);
void _notification(int p_what);
static void _bind_methods();
-public:
- void set_scroll_offset(const Point2& p_ofs);
+public:
+ void set_scroll_offset(const Point2 &p_ofs);
Point2 get_scroll_offset() const;
void set_scroll_scale(float p_ofs);
float get_scroll_scale() const;
- void set_scroll_base_offset(const Point2& p_ofs);
+ void set_scroll_base_offset(const Point2 &p_ofs);
Point2 get_scroll_base_offset() const;
- void set_scroll_base_scale(const Point2& p_ofs);
+ void set_scroll_base_scale(const Point2 &p_ofs);
Point2 get_scroll_base_scale() const;
- void set_limit_begin(const Point2& p_ofs);
+ void set_limit_begin(const Point2 &p_ofs);
Point2 get_limit_begin() const;
- void set_limit_end(const Point2& p_ofs);
+ void set_limit_end(const Point2 &p_ofs);
Point2 get_limit_end() const;
void set_ignore_camera_zoom(bool ignore);
diff --git a/scene/2d/parallax_layer.cpp b/scene/2d/parallax_layer.cpp
index 37d8fb52f1..2387234607 100644
--- a/scene/2d/parallax_layer.cpp
+++ b/scene/2d/parallax_layer.cpp
@@ -29,42 +29,38 @@
#include "parallax_layer.h"
#include "parallax_background.h"
-void ParallaxLayer::set_motion_scale(const Size2& p_scale) {
-
- motion_scale=p_scale;
+void ParallaxLayer::set_motion_scale(const Size2 &p_scale) {
+ motion_scale = p_scale;
ParallaxBackground *pb = get_parent()->cast_to<ParallaxBackground>();
if (is_inside_tree() && pb) {
Vector2 ofs = pb->get_final_offset();
float scale = pb->get_scroll_scale();
- set_base_offset_and_scale(ofs,scale);
+ set_base_offset_and_scale(ofs, scale);
}
-
}
Size2 ParallaxLayer::get_motion_scale() const {
return motion_scale;
-
}
-void ParallaxLayer::set_motion_offset(const Size2& p_offset) {
+void ParallaxLayer::set_motion_offset(const Size2 &p_offset) {
- motion_offset=p_offset;
+ motion_offset = p_offset;
ParallaxBackground *pb = get_parent()->cast_to<ParallaxBackground>();
if (is_inside_tree() && pb) {
Vector2 ofs = pb->get_final_offset();
float scale = pb->get_scroll_scale();
- set_base_offset_and_scale(ofs,scale);
+ set_base_offset_and_scale(ofs, scale);
}
}
Size2 ParallaxLayer::get_motion_offset() const {
return motion_offset;
-
}
void ParallaxLayer::_update_mirroring() {
@@ -77,68 +73,61 @@ void ParallaxLayer::_update_mirroring() {
RID c = pb->get_world_2d()->get_canvas();
RID ci = get_canvas_item();
- VisualServer::get_singleton()->canvas_set_item_mirroring(c,ci,mirroring);
+ VisualServer::get_singleton()->canvas_set_item_mirroring(c, ci, mirroring);
}
-
}
-void ParallaxLayer::set_mirroring(const Size2& p_mirroring) {
+void ParallaxLayer::set_mirroring(const Size2 &p_mirroring) {
- mirroring=p_mirroring;
- if (mirroring.x<0)
- mirroring.x=0;
- if (mirroring.y<0)
- mirroring.y=0;
+ mirroring = p_mirroring;
+ if (mirroring.x < 0)
+ mirroring.x = 0;
+ if (mirroring.y < 0)
+ mirroring.y = 0;
_update_mirroring();
-
}
-Size2 ParallaxLayer::get_mirroring() const{
+Size2 ParallaxLayer::get_mirroring() const {
return mirroring;
}
-
-
void ParallaxLayer::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
- orig_offset=get_position();
- orig_scale=get_scale();
+ orig_offset = get_position();
+ orig_scale = get_scale();
_update_mirroring();
} break;
}
}
-void ParallaxLayer::set_base_offset_and_scale(const Point2& p_offset,float p_scale) {
+void ParallaxLayer::set_base_offset_and_scale(const Point2 &p_offset, float p_scale) {
if (!is_inside_tree())
return;
if (get_tree()->is_editor_hint())
return;
- Point2 new_ofs = ((orig_offset+p_offset)*motion_scale)*p_scale+motion_offset;
+ Point2 new_ofs = ((orig_offset + p_offset) * motion_scale) * p_scale + motion_offset;
if (mirroring.x) {
- double den = mirroring.x*p_scale;
- new_ofs.x -= den*ceil(new_ofs.x/den);
+ double den = mirroring.x * p_scale;
+ new_ofs.x -= den * ceil(new_ofs.x / den);
}
if (mirroring.y) {
- double den = mirroring.y*p_scale;
- new_ofs.y -= den*ceil(new_ofs.y/den);
+ double den = mirroring.y * p_scale;
+ new_ofs.y -= den * ceil(new_ofs.y / den);
}
set_position(new_ofs);
- set_scale(Vector2(1,1)*p_scale);
-
-
+ set_scale(Vector2(1, 1) * p_scale);
}
-
String ParallaxLayer::get_configuration_warning() const {
if (!get_parent() || !get_parent()->cast_to<ParallaxBackground>()) {
@@ -150,23 +139,19 @@ String ParallaxLayer::get_configuration_warning() const {
void ParallaxLayer::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_motion_scale","scale"),&ParallaxLayer::set_motion_scale);
- ClassDB::bind_method(D_METHOD("get_motion_scale"),&ParallaxLayer::get_motion_scale);
- ClassDB::bind_method(D_METHOD("set_motion_offset","offset"),&ParallaxLayer::set_motion_offset);
- ClassDB::bind_method(D_METHOD("get_motion_offset"),&ParallaxLayer::get_motion_offset);
- ClassDB::bind_method(D_METHOD("set_mirroring","mirror"),&ParallaxLayer::set_mirroring);
- ClassDB::bind_method(D_METHOD("get_mirroring"),&ParallaxLayer::get_mirroring);
-
- ADD_GROUP("Motion","motion_");
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"motion_scale"),"set_motion_scale","get_motion_scale");
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"motion_offset"),"set_motion_offset","get_motion_offset");
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"motion_mirroring"),"set_mirroring","get_mirroring");
-
+ ClassDB::bind_method(D_METHOD("set_motion_scale", "scale"), &ParallaxLayer::set_motion_scale);
+ ClassDB::bind_method(D_METHOD("get_motion_scale"), &ParallaxLayer::get_motion_scale);
+ ClassDB::bind_method(D_METHOD("set_motion_offset", "offset"), &ParallaxLayer::set_motion_offset);
+ ClassDB::bind_method(D_METHOD("get_motion_offset"), &ParallaxLayer::get_motion_offset);
+ ClassDB::bind_method(D_METHOD("set_mirroring", "mirror"), &ParallaxLayer::set_mirroring);
+ ClassDB::bind_method(D_METHOD("get_mirroring"), &ParallaxLayer::get_mirroring);
+
+ ADD_GROUP("Motion", "motion_");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "motion_scale"), "set_motion_scale", "get_motion_scale");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "motion_offset"), "set_motion_offset", "get_motion_offset");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "motion_mirroring"), "set_mirroring", "get_mirroring");
}
-
-
-ParallaxLayer::ParallaxLayer()
-{
- motion_scale=Size2(1,1);
+ParallaxLayer::ParallaxLayer() {
+ motion_scale = Size2(1, 1);
}
diff --git a/scene/2d/parallax_layer.h b/scene/2d/parallax_layer.h
index 1b3d67af5e..01293e85ac 100644
--- a/scene/2d/parallax_layer.h
+++ b/scene/2d/parallax_layer.h
@@ -33,7 +33,7 @@
class ParallaxLayer : public Node2D {
- GDCLASS( ParallaxLayer, Node2D );
+ GDCLASS(ParallaxLayer, Node2D);
Point2 orig_offset;
Point2 orig_scale;
@@ -43,22 +43,20 @@ class ParallaxLayer : public Node2D {
void _update_mirroring();
protected:
-
void _notification(int p_what);
static void _bind_methods();
public:
-
- void set_motion_offset(const Size2& p_scale);
+ void set_motion_offset(const Size2 &p_scale);
Size2 get_motion_offset() const;
- void set_motion_scale(const Size2& p_scale);
+ void set_motion_scale(const Size2 &p_scale);
Size2 get_motion_scale() const;
- void set_mirroring(const Size2& p_mirroring);
+ void set_mirroring(const Size2 &p_mirroring);
Size2 get_mirroring() const;
- void set_base_offset_and_scale(const Point2& p_offsetf,float p_scale);
+ void set_base_offset_and_scale(const Point2 &p_offsetf, float p_scale);
virtual String get_configuration_warning() const;
ParallaxLayer();
diff --git a/scene/2d/particles_2d.cpp b/scene/2d/particles_2d.cpp
index 77ace0348a..c9d5bebe56 100644
--- a/scene/2d/particles_2d.cpp
+++ b/scene/2d/particles_2d.cpp
@@ -29,11 +29,9 @@
#include "particles_2d.h"
#include "scene/scene_string_names.h"
-
-
void ParticleAttractor2D::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
@@ -46,16 +44,16 @@ void ParticleAttractor2D::_notification(int p_what) {
return;
Vector2 pv;
- float dr = MIN(disable_radius,radius);
- for(int i=0;i<=32;i++) {
- Vector2 v(Math::sin(i/32.0*Math_PI*2),Math::cos(i/32.0*Math_PI*2));
- if (i>0) {
- draw_line(pv*radius,v*radius,Color(0,0,0.5,0.9));
- if (dr>0) {
- draw_line(pv*dr,v*dr,Color(0.5,0,0.0,0.9));
+ float dr = MIN(disable_radius, radius);
+ for (int i = 0; i <= 32; i++) {
+ Vector2 v(Math::sin(i / 32.0 * Math_PI * 2), Math::cos(i / 32.0 * Math_PI * 2));
+ if (i > 0) {
+ draw_line(pv * radius, v * radius, Color(0, 0, 0.5, 0.9));
+ if (dr > 0) {
+ draw_line(pv * dr, v * dr, Color(0.5, 0, 0.0, 0.9));
}
}
- pv=v;
+ pv = v;
}
} break;
@@ -72,7 +70,7 @@ void ParticleAttractor2D::_owner_exited() {
ERR_FAIL_COND(!owner);
owner->attractors.erase(this);
- owner=NULL;
+ owner = NULL;
}
void ParticleAttractor2D::_update_owner() {
@@ -93,63 +91,59 @@ void ParticleAttractor2D::_update_owner() {
_set_owner(pn);
}
-void ParticleAttractor2D::_set_owner(Particles2D* p_owner) {
+void ParticleAttractor2D::_set_owner(Particles2D *p_owner) {
- if (owner==p_owner)
+ if (owner == p_owner)
return;
if (owner) {
- owner->disconnect("tree_exited",this,"_owner_exited");
+ owner->disconnect("tree_exited", this, "_owner_exited");
owner->attractors.erase(this);
- owner=NULL;
+ owner = NULL;
}
- owner=p_owner;
+ owner = p_owner;
if (owner) {
- owner->connect("tree_exited",this,"_owner_exited",varray(),CONNECT_ONESHOT);
+ owner->connect("tree_exited", this, "_owner_exited", varray(), CONNECT_ONESHOT);
owner->attractors.insert(this);
}
}
void ParticleAttractor2D::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_enabled","enabled"),&ParticleAttractor2D::set_enabled);
- ClassDB::bind_method(D_METHOD("is_enabled"),&ParticleAttractor2D::is_enabled);
-
- ClassDB::bind_method(D_METHOD("set_radius","radius"),&ParticleAttractor2D::set_radius);
- ClassDB::bind_method(D_METHOD("get_radius"),&ParticleAttractor2D::get_radius);
-
- ClassDB::bind_method(D_METHOD("set_disable_radius","radius"),&ParticleAttractor2D::set_disable_radius);
- ClassDB::bind_method(D_METHOD("get_disable_radius"),&ParticleAttractor2D::get_disable_radius);
+ ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &ParticleAttractor2D::set_enabled);
+ ClassDB::bind_method(D_METHOD("is_enabled"), &ParticleAttractor2D::is_enabled);
- ClassDB::bind_method(D_METHOD("set_gravity","gravity"),&ParticleAttractor2D::set_gravity);
- ClassDB::bind_method(D_METHOD("get_gravity"),&ParticleAttractor2D::get_gravity);
+ ClassDB::bind_method(D_METHOD("set_radius", "radius"), &ParticleAttractor2D::set_radius);
+ ClassDB::bind_method(D_METHOD("get_radius"), &ParticleAttractor2D::get_radius);
- ClassDB::bind_method(D_METHOD("set_absorption","absorption"),&ParticleAttractor2D::set_absorption);
- ClassDB::bind_method(D_METHOD("get_absorption"),&ParticleAttractor2D::get_absorption);
+ ClassDB::bind_method(D_METHOD("set_disable_radius", "radius"), &ParticleAttractor2D::set_disable_radius);
+ ClassDB::bind_method(D_METHOD("get_disable_radius"), &ParticleAttractor2D::get_disable_radius);
- ClassDB::bind_method(D_METHOD("set_particles_path","path"),&ParticleAttractor2D::set_particles_path);
- ClassDB::bind_method(D_METHOD("get_particles_path"),&ParticleAttractor2D::get_particles_path);
-
- ADD_PROPERTY(PropertyInfo(Variant::BOOL,"enabled"),"set_enabled","is_enabled");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"radius",PROPERTY_HINT_RANGE,"0.1,16000,0.1"),"set_radius","get_radius");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"disable_radius",PROPERTY_HINT_RANGE,"0.1,16000,0.1"),"set_disable_radius","get_disable_radius");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"gravity",PROPERTY_HINT_RANGE,"-512,512,0.01"),"set_gravity","get_gravity");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"absorption",PROPERTY_HINT_RANGE,"0,512,0.01"),"set_absorption","get_absorption");
- ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH,"particles_path",PROPERTY_HINT_RESOURCE_TYPE,"Particles2D"),"set_particles_path","get_particles_path");
+ ClassDB::bind_method(D_METHOD("set_gravity", "gravity"), &ParticleAttractor2D::set_gravity);
+ ClassDB::bind_method(D_METHOD("get_gravity"), &ParticleAttractor2D::get_gravity);
+ ClassDB::bind_method(D_METHOD("set_absorption", "absorption"), &ParticleAttractor2D::set_absorption);
+ ClassDB::bind_method(D_METHOD("get_absorption"), &ParticleAttractor2D::get_absorption);
+ ClassDB::bind_method(D_METHOD("set_particles_path", "path"), &ParticleAttractor2D::set_particles_path);
+ ClassDB::bind_method(D_METHOD("get_particles_path"), &ParticleAttractor2D::get_particles_path);
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "radius", PROPERTY_HINT_RANGE, "0.1,16000,0.1"), "set_radius", "get_radius");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "disable_radius", PROPERTY_HINT_RANGE, "0.1,16000,0.1"), "set_disable_radius", "get_disable_radius");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "gravity", PROPERTY_HINT_RANGE, "-512,512,0.01"), "set_gravity", "get_gravity");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "absorption", PROPERTY_HINT_RANGE, "0,512,0.01"), "set_absorption", "get_absorption");
+ ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "particles_path", PROPERTY_HINT_RESOURCE_TYPE, "Particles2D"), "set_particles_path", "get_particles_path");
}
-
void ParticleAttractor2D::set_enabled(bool p_enabled) {
- enabled=p_enabled;
+ enabled = p_enabled;
}
-bool ParticleAttractor2D::is_enabled() const{
+bool ParticleAttractor2D::is_enabled() const {
return enabled;
}
@@ -177,8 +171,7 @@ float ParticleAttractor2D::get_disable_radius() const {
void ParticleAttractor2D::set_gravity(float p_gravity) {
- gravity=p_gravity;
-
+ gravity = p_gravity;
}
float ParticleAttractor2D::get_gravity() const {
@@ -187,8 +180,7 @@ float ParticleAttractor2D::get_gravity() const {
void ParticleAttractor2D::set_absorption(float p_absorption) {
- absorption=p_absorption;
-
+ absorption = p_absorption;
}
float ParticleAttractor2D::get_absorption() const {
@@ -197,7 +189,7 @@ float ParticleAttractor2D::get_absorption() const {
void ParticleAttractor2D::set_particles_path(NodePath p_path) {
- path=p_path;
+ path = p_path;
_update_owner();
update_configuration_warning();
}
@@ -217,13 +209,13 @@ String ParticleAttractor2D::get_configuration_warning() const {
ParticleAttractor2D::ParticleAttractor2D() {
- owner=NULL;
- radius=50;
- disable_radius=0;
- gravity=100;
- absorption=0;
- path=String("..");
- enabled=true;
+ owner = NULL;
+ radius = 50;
+ disable_radius = 0;
+ gravity = 100;
+ absorption = 0;
+ path = String("..");
+ enabled = true;
}
/****************************************/
@@ -236,12 +228,12 @@ _FORCE_INLINE_ static float _rand_from_seed(uint64_t *seed) {
void Particles2D::_process_particles(float p_delta) {
- if (particles.size()==0 || lifetime==0)
+ if (particles.size() == 0 || lifetime == 0)
return;
- p_delta*=time_scale;
+ p_delta *= time_scale;
- float frame_time=p_delta;
+ float frame_time = p_delta;
if (emit_timeout > 0) {
time_to_live -= frame_time;
@@ -252,114 +244,110 @@ void Particles2D::_process_particles(float p_delta) {
};
};
- float next_time = time+frame_time;
+ float next_time = time + frame_time;
if (next_time > lifetime)
- next_time=Math::fmod(next_time,lifetime);
-
+ next_time = Math::fmod(next_time, lifetime);
- Particle *pdata=&particles[0];
- int particle_count=particles.size();
+ Particle *pdata = &particles[0];
+ int particle_count = particles.size();
Transform2D xform;
if (!local_space)
- xform=get_global_transform();
+ xform = get_global_transform();
- active_count=0;
+ active_count = 0;
PoolVector<Point2>::Read r;
- int emission_point_count=0;
+ int emission_point_count = 0;
if (emission_points.size()) {
- emission_point_count=emission_points.size();
- r=emission_points.read();
+ emission_point_count = emission_points.size();
+ r = emission_points.read();
}
- int attractor_count=0;
- AttractorCache *attractor_ptr=NULL;
+ int attractor_count = 0;
+ AttractorCache *attractor_ptr = NULL;
if (attractors.size()) {
- if (attractors.size()!=attractor_cache.size()) {
+ if (attractors.size() != attractor_cache.size()) {
attractor_cache.resize(attractors.size());
}
- int idx=0;
+ int idx = 0;
Transform2D m;
if (local_space) {
- m= get_global_transform().affine_inverse();
+ m = get_global_transform().affine_inverse();
}
- for (Set<ParticleAttractor2D*>::Element *E=attractors.front();E;E=E->next()) {
+ for (Set<ParticleAttractor2D *>::Element *E = attractors.front(); E; E = E->next()) {
- attractor_cache[idx].pos=m.xform( E->get()->get_global_position() );
- attractor_cache[idx].attractor=E->get();
+ attractor_cache[idx].pos = m.xform(E->get()->get_global_position());
+ attractor_cache[idx].attractor = E->get();
idx++;
}
- attractor_ptr=attractor_cache.ptr();
- attractor_count=attractor_cache.size();
+ attractor_ptr = attractor_cache.ptr();
+ attractor_count = attractor_cache.size();
}
- for(int i=0;i<particle_count;i++) {
+ for (int i = 0; i < particle_count; i++) {
- Particle &p=pdata[i];
+ Particle &p = pdata[i];
float restart_time = (i * lifetime / particle_count) * explosiveness;
- bool restart=false;
+ bool restart = false;
- if ( next_time < time ) {
+ if (next_time < time) {
- if (restart_time > time || restart_time < next_time )
- restart=true;
+ if (restart_time > time || restart_time < next_time)
+ restart = true;
- } else if (restart_time > time && restart_time < next_time ) {
- restart=true;
+ } else if (restart_time > time && restart_time < next_time) {
+ restart = true;
}
if (restart) {
-
if (emitting) {
- p.pos=emissor_offset;
+ p.pos = emissor_offset;
if (emission_point_count) {
-
- Vector2 ep = r[Math::rand()%emission_point_count];
+ Vector2 ep = r[Math::rand() % emission_point_count];
if (!local_space) {
- p.pos=xform.xform(p.pos+ep*extents);
+ p.pos = xform.xform(p.pos + ep * extents);
} else {
- p.pos+=ep*extents;
+ p.pos += ep * extents;
}
} else {
if (!local_space) {
- p.pos=xform.xform(p.pos+Vector2(Math::random(-extents.x,extents.x),Math::random(-extents.y,extents.y)));
+ p.pos = xform.xform(p.pos + Vector2(Math::random(-extents.x, extents.x), Math::random(-extents.y, extents.y)));
} else {
- p.pos+=Vector2(Math::random(-extents.x,extents.x),Math::random(-extents.y,extents.y));
+ p.pos += Vector2(Math::random(-extents.x, extents.x), Math::random(-extents.y, extents.y));
}
}
- p.seed=Math::rand() % 12345678;
- uint64_t rand_seed=p.seed*(i+1);
+ p.seed = Math::rand() % 12345678;
+ uint64_t rand_seed = p.seed * (i + 1);
- float angle = Math::deg2rad(param[PARAM_DIRECTION]+_rand_from_seed(&rand_seed)*param[PARAM_SPREAD]);
+ float angle = Math::deg2rad(param[PARAM_DIRECTION] + _rand_from_seed(&rand_seed) * param[PARAM_SPREAD]);
- p.velocity=Vector2( Math::sin(angle), Math::cos(angle) );
+ p.velocity = Vector2(Math::sin(angle), Math::cos(angle));
if (!local_space) {
p.velocity = xform.basis_xform(p.velocity).normalized();
}
- p.velocity*=param[PARAM_LINEAR_VELOCITY]+param[PARAM_LINEAR_VELOCITY]*_rand_from_seed(&rand_seed)*randomness[PARAM_LINEAR_VELOCITY];
- p.velocity+=initial_velocity;
- p.active=true;
- p.rot=Math::deg2rad(param[PARAM_INITIAL_ANGLE]+param[PARAM_INITIAL_ANGLE]*randomness[PARAM_INITIAL_ANGLE]*_rand_from_seed(&rand_seed));
+ p.velocity *= param[PARAM_LINEAR_VELOCITY] + param[PARAM_LINEAR_VELOCITY] * _rand_from_seed(&rand_seed) * randomness[PARAM_LINEAR_VELOCITY];
+ p.velocity += initial_velocity;
+ p.active = true;
+ p.rot = Math::deg2rad(param[PARAM_INITIAL_ANGLE] + param[PARAM_INITIAL_ANGLE] * randomness[PARAM_INITIAL_ANGLE] * _rand_from_seed(&rand_seed));
active_count++;
- p.frame=Math::fmod(param[PARAM_ANIM_INITIAL_POS]+randomness[PARAM_ANIM_INITIAL_POS]*_rand_from_seed(&rand_seed),1.0f);
-
+ p.frame = Math::fmod(param[PARAM_ANIM_INITIAL_POS] + randomness[PARAM_ANIM_INITIAL_POS] * _rand_from_seed(&rand_seed), 1.0f);
} else {
- p.active=false;
+ p.active = false;
}
} else {
@@ -367,136 +355,122 @@ void Particles2D::_process_particles(float p_delta) {
if (!p.active)
continue;
- uint64_t rand_seed=p.seed*(i+1);
+ uint64_t rand_seed = p.seed * (i + 1);
Vector2 force;
//apply gravity
- float gravity_dir = Math::deg2rad( param[PARAM_GRAVITY_DIRECTION]+180*randomness[PARAM_GRAVITY_DIRECTION]*_rand_from_seed(&rand_seed));
- force+=Vector2( Math::sin(gravity_dir), Math::cos(gravity_dir) ) * (param[PARAM_GRAVITY_STRENGTH]+param[PARAM_GRAVITY_STRENGTH]*randomness[PARAM_GRAVITY_STRENGTH]*_rand_from_seed(&rand_seed));
+ float gravity_dir = Math::deg2rad(param[PARAM_GRAVITY_DIRECTION] + 180 * randomness[PARAM_GRAVITY_DIRECTION] * _rand_from_seed(&rand_seed));
+ force += Vector2(Math::sin(gravity_dir), Math::cos(gravity_dir)) * (param[PARAM_GRAVITY_STRENGTH] + param[PARAM_GRAVITY_STRENGTH] * randomness[PARAM_GRAVITY_STRENGTH] * _rand_from_seed(&rand_seed));
//apply radial
Vector2 rvec = (p.pos - emissor_offset).normalized();
- force+=rvec*(param[PARAM_RADIAL_ACCEL]+param[PARAM_RADIAL_ACCEL]*randomness[PARAM_RADIAL_ACCEL]*_rand_from_seed(&rand_seed));
+ force += rvec * (param[PARAM_RADIAL_ACCEL] + param[PARAM_RADIAL_ACCEL] * randomness[PARAM_RADIAL_ACCEL] * _rand_from_seed(&rand_seed));
//apply orbit
- float orbitvel = (param[PARAM_ORBIT_VELOCITY]+param[PARAM_ORBIT_VELOCITY]*randomness[PARAM_ORBIT_VELOCITY]*_rand_from_seed(&rand_seed));
- if (orbitvel!=0) {
+ float orbitvel = (param[PARAM_ORBIT_VELOCITY] + param[PARAM_ORBIT_VELOCITY] * randomness[PARAM_ORBIT_VELOCITY] * _rand_from_seed(&rand_seed));
+ if (orbitvel != 0) {
Vector2 rel = p.pos - xform.elements[2];
- Transform2D rot(orbitvel*frame_time,Vector2());
+ Transform2D rot(orbitvel * frame_time, Vector2());
p.pos = rot.xform(rel) + xform.elements[2];
-
}
- Vector2 tvec=rvec.tangent();
- force+=tvec*(param[PARAM_TANGENTIAL_ACCEL]+param[PARAM_TANGENTIAL_ACCEL]*randomness[PARAM_TANGENTIAL_ACCEL]*_rand_from_seed(&rand_seed));
+ Vector2 tvec = rvec.tangent();
+ force += tvec * (param[PARAM_TANGENTIAL_ACCEL] + param[PARAM_TANGENTIAL_ACCEL] * randomness[PARAM_TANGENTIAL_ACCEL] * _rand_from_seed(&rand_seed));
- for(int j=0;j<attractor_count;j++) {
+ for (int j = 0; j < attractor_count; j++) {
Vector2 vec = (attractor_ptr[j].pos - p.pos);
float vl = vec.length();
- if (!attractor_ptr[j].attractor->enabled || vl==0 || vl > attractor_ptr[j].attractor->radius)
+ if (!attractor_ptr[j].attractor->enabled || vl == 0 || vl > attractor_ptr[j].attractor->radius)
continue;
-
-
- force+=vec*attractor_ptr[j].attractor->gravity;
+ force += vec * attractor_ptr[j].attractor->gravity;
float fvl = p.velocity.length();
if (fvl && attractor_ptr[j].attractor->absorption) {
Vector2 target = vec.normalized();
- p.velocity = p.velocity.normalized().linear_interpolate(target,MIN(frame_time*attractor_ptr[j].attractor->absorption,1))*fvl;
+ p.velocity = p.velocity.normalized().linear_interpolate(target, MIN(frame_time * attractor_ptr[j].attractor->absorption, 1)) * fvl;
}
if (attractor_ptr[j].attractor->disable_radius && vl < attractor_ptr[j].attractor->disable_radius) {
- p.active=false;
+ p.active = false;
}
}
- p.velocity+=force*frame_time;
+ p.velocity += force * frame_time;
if (param[PARAM_DAMPING]) {
- float dmp = param[PARAM_DAMPING]+param[PARAM_DAMPING]*randomness[PARAM_DAMPING]*_rand_from_seed(&rand_seed);
+ float dmp = param[PARAM_DAMPING] + param[PARAM_DAMPING] * randomness[PARAM_DAMPING] * _rand_from_seed(&rand_seed);
float v = p.velocity.length();
v -= dmp * frame_time;
- if (v<=0) {
- p.velocity=Vector2();
+ if (v <= 0) {
+ p.velocity = Vector2();
} else {
- p.velocity=p.velocity.normalized() * v;
+ p.velocity = p.velocity.normalized() * v;
}
-
}
- p.pos+=p.velocity*frame_time;
- p.rot+=Math::lerp(param[PARAM_SPIN_VELOCITY],param[PARAM_SPIN_VELOCITY]*randomness[PARAM_SPIN_VELOCITY]*_rand_from_seed(&rand_seed),randomness[PARAM_SPIN_VELOCITY])*frame_time;
- float anim_spd=param[PARAM_ANIM_SPEED_SCALE]+param[PARAM_ANIM_SPEED_SCALE]*randomness[PARAM_ANIM_SPEED_SCALE]*_rand_from_seed(&rand_seed);
- p.frame=Math::fposmod(p.frame+(frame_time/lifetime)*anim_spd,1.0f);
+ p.pos += p.velocity * frame_time;
+ p.rot += Math::lerp(param[PARAM_SPIN_VELOCITY], param[PARAM_SPIN_VELOCITY] * randomness[PARAM_SPIN_VELOCITY] * _rand_from_seed(&rand_seed), randomness[PARAM_SPIN_VELOCITY]) * frame_time;
+ float anim_spd = param[PARAM_ANIM_SPEED_SCALE] + param[PARAM_ANIM_SPEED_SCALE] * randomness[PARAM_ANIM_SPEED_SCALE] * _rand_from_seed(&rand_seed);
+ p.frame = Math::fposmod(p.frame + (frame_time / lifetime) * anim_spd, 1.0f);
active_count++;
-
}
-
-
}
-
-
- time=Math::fmod( time+frame_time, lifetime );
- if (!emitting && active_count==0) {
+ time = Math::fmod(time + frame_time, lifetime);
+ if (!emitting && active_count == 0) {
emit_signal(SceneStringNames::get_singleton()->emission_finished);
set_process(false);
set_fixed_process(false);
}
update();
-
-
}
-
void Particles2D::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_PROCESS: {
- _process_particles( get_process_delta_time() );
+ _process_particles(get_process_delta_time());
} break;
case NOTIFICATION_FIXED_PROCESS: {
- _process_particles( get_fixed_process_delta_time() );
+ _process_particles(get_fixed_process_delta_time());
} break;
case NOTIFICATION_ENTER_TREE: {
- float ppt=preprocess;
- while(ppt>0) {
+ float ppt = preprocess;
+ while (ppt > 0) {
_process_particles(0.1);
- ppt-=0.1;
+ ppt -= 0.1;
}
} break;
case NOTIFICATION_DRAW: {
-
- if (particles.size()==0 || lifetime==0)
+ if (particles.size() == 0 || lifetime == 0)
return;
- RID ci=get_canvas_item();
- Size2 size(1,1);
+ RID ci = get_canvas_item();
+ Size2 size(1, 1);
Point2 center;
- int total_frames=1;
+ int total_frames = 1;
if (!texture.is_null()) {
- size=texture->get_size();
- size.x/=h_frames;
- size.y/=v_frames;
- total_frames=h_frames*v_frames;
+ size = texture->get_size();
+ size.x /= h_frames;
+ size.y /= v_frames;
+ total_frames = h_frames * v_frames;
}
+ float time_pos = (time / lifetime);
- float time_pos=(time/lifetime);
-
- Particle *pdata=&particles[0];
- int particle_count=particles.size();
+ Particle *pdata = &particles[0];
+ int particle_count = particles.size();
RID texrid;
@@ -505,64 +479,61 @@ void Particles2D::_notification(int p_what) {
Transform2D invxform;
if (!local_space)
- invxform=get_global_transform().affine_inverse();
+ invxform = get_global_transform().affine_inverse();
int start_particle = (int)(time * (float)particle_count / lifetime);
- for (int id=0;id<particle_count;++id) {
+ for (int id = 0; id < particle_count; ++id) {
int i = start_particle + id;
if (i >= particle_count) {
i -= particle_count;
}
- Particle &p=pdata[i];
+ Particle &p = pdata[i];
if (!p.active)
continue;
- float ptime = ((float)i / particle_count)*explosiveness;
+ float ptime = ((float)i / particle_count) * explosiveness;
- if (ptime<time_pos)
- ptime=time_pos-ptime;
+ if (ptime < time_pos)
+ ptime = time_pos - ptime;
else
- ptime=(1.0-ptime)+time_pos;
+ ptime = (1.0 - ptime) + time_pos;
- uint64_t rand_seed=p.seed*(i+1);
+ uint64_t rand_seed = p.seed * (i + 1);
Color color;
- if(color_ramp.is_valid())
- {
+ if (color_ramp.is_valid()) {
color = color_ramp->get_color_at_offset(ptime);
- } else
- {
+ } else {
color = default_color;
}
-
{
- float huerand=_rand_from_seed(&rand_seed);
+ float huerand = _rand_from_seed(&rand_seed);
float huerot = param[PARAM_HUE_VARIATION] + randomness[PARAM_HUE_VARIATION] * huerand;
if (Math::abs(huerot) > CMP_EPSILON) {
- float h=color.get_h();
- float s=color.get_s();
- float v=color.get_v();
- float a=color.a;
+ float h = color.get_h();
+ float s = color.get_s();
+ float v = color.get_v();
+ float a = color.a;
//float preh=h;
- h+=huerot;
- h=Math::abs(Math::fposmod(h,1.0f));
+ h += huerot;
+ h = Math::abs(Math::fposmod(h, 1.0f));
//print_line("rand: "+rtos(randomness[PARAM_HUE_VARIATION])+" rand: "+rtos(huerand));
//print_line(itos(i)+":hue: "+rtos(preh)+" + "+rtos(huerot)+" = "+rtos(h));
- color.set_hsv(h,s,v);
- color.a=a;
+ color.set_hsv(h, s, v);
+ color.a = a;
}
}
- float initial_size = param[PARAM_INITIAL_SIZE]+param[PARAM_INITIAL_SIZE]*_rand_from_seed(&rand_seed)*randomness[PARAM_INITIAL_SIZE];
- float final_size = param[PARAM_FINAL_SIZE]+param[PARAM_FINAL_SIZE]*_rand_from_seed(&rand_seed)*randomness[PARAM_FINAL_SIZE];
+ float initial_size = param[PARAM_INITIAL_SIZE] + param[PARAM_INITIAL_SIZE] * _rand_from_seed(&rand_seed) * randomness[PARAM_INITIAL_SIZE];
+ float final_size = param[PARAM_FINAL_SIZE] + param[PARAM_FINAL_SIZE] * _rand_from_seed(&rand_seed) * randomness[PARAM_FINAL_SIZE];
- float size_mult=initial_size*(1.0-ptime) + final_size*ptime;
+ float size_mult = initial_size * (1.0 - ptime) + final_size * ptime;
//Size2 rectsize=size * size_mult;
//rectsize=rectsize.floor();
@@ -574,57 +545,49 @@ void Particles2D::_notification(int p_what) {
if (p.rot) {
xform.set_rotation(p.rot);
- xform.translate(-size*size_mult/2.0);
- xform.elements[2]+=p.pos;
+ xform.translate(-size * size_mult / 2.0);
+ xform.elements[2] += p.pos;
} else {
- xform.elements[2]=-size*size_mult/2.0;
- xform.elements[2]+=p.pos;
+ xform.elements[2] = -size * size_mult / 2.0;
+ xform.elements[2] += p.pos;
}
if (!local_space) {
xform = invxform * xform;
}
+ xform.scale_basis(Size2(size_mult, size_mult));
- xform.scale_basis(Size2(size_mult,size_mult));
-
-
- VisualServer::get_singleton()->canvas_item_add_set_transform(ci,xform);
-
+ VisualServer::get_singleton()->canvas_item_add_set_transform(ci, xform);
if (texrid.is_valid()) {
Rect2 src_rect;
- src_rect.size=size;
+ src_rect.size = size;
- if (total_frames>1) {
- int frame = Math::fast_ftoi(Math::floor(p.frame*total_frames)) % total_frames;
- src_rect.pos.x = size.x * (frame%h_frames);
- src_rect.pos.y = size.y * (frame/h_frames);
+ if (total_frames > 1) {
+ int frame = Math::fast_ftoi(Math::floor(p.frame * total_frames)) % total_frames;
+ src_rect.pos.x = size.x * (frame % h_frames);
+ src_rect.pos.y = size.y * (frame / h_frames);
}
if (flip_h)
- src_rect.size.x=-src_rect.size.x;
+ src_rect.size.x = -src_rect.size.x;
if (flip_v)
- src_rect.size.y=-src_rect.size.y;
+ src_rect.size.y = -src_rect.size.y;
- texture->draw_rect_region(ci,Rect2(Point2(),size),src_rect,color);
+ texture->draw_rect_region(ci, Rect2(Point2(), size), src_rect, color);
//VisualServer::get_singleton()->canvas_item_add_texture_rect(ci,r,texrid,false,color);
} else {
- VisualServer::get_singleton()->canvas_item_add_rect(ci,Rect2(Point2(),size),color);
-
+ VisualServer::get_singleton()->canvas_item_add_rect(ci, Rect2(Point2(), size), color);
}
-
}
-
} break;
-
}
-
}
-static const char* _particlesframe_property_names[Particles2D::PARAM_MAX]={
+static const char *_particlesframe_property_names[Particles2D::PARAM_MAX] = {
"params/direction",
"params/spread",
"params/linear_velocity",
@@ -643,7 +606,7 @@ static const char* _particlesframe_property_names[Particles2D::PARAM_MAX]={
"params/anim_initial_pos",
};
-static const char* _particlesframe_property_rnames[Particles2D::PARAM_MAX]={
+static const char *_particlesframe_property_rnames[Particles2D::PARAM_MAX] = {
"randomness/direction",
"randomness/spread",
"randomness/linear_velocity",
@@ -662,7 +625,7 @@ static const char* _particlesframe_property_rnames[Particles2D::PARAM_MAX]={
"randomness/anim_initial_pos",
};
-static const char* _particlesframe_property_ranges[Particles2D::PARAM_MAX]={
+static const char *_particlesframe_property_ranges[Particles2D::PARAM_MAX] = {
"0,360,0.01",
"0,180,0.01",
"-1024,1024,0.01",
@@ -681,21 +644,20 @@ static const char* _particlesframe_property_ranges[Particles2D::PARAM_MAX]={
"0,1,0.01",
};
-
void Particles2D::set_emitting(bool p_emitting) {
- if (emitting==p_emitting)
+ if (emitting == p_emitting)
return;
if (p_emitting) {
- if (active_count==0)
- time=0;
- set_process(process_mode==PROCESS_IDLE);
- set_fixed_process(process_mode==PROCESS_FIXED);
+ if (active_count == 0)
+ time = 0;
+ set_process(process_mode == PROCESS_IDLE);
+ set_fixed_process(process_mode == PROCESS_FIXED);
time_to_live = emit_timeout;
};
- emitting=p_emitting;
+ emitting = p_emitting;
_change_notify("config/emitting");
}
@@ -706,10 +668,10 @@ bool Particles2D::is_emitting() const {
void Particles2D::set_process_mode(ProcessMode p_mode) {
- process_mode=p_mode;
- const bool should_process=emitting || active_count!=0;
- set_process(should_process && process_mode==PROCESS_IDLE);
- set_fixed_process(should_process && process_mode==PROCESS_FIXED);
+ process_mode = p_mode;
+ const bool should_process = emitting || active_count != 0;
+ set_process(should_process && process_mode == PROCESS_IDLE);
+ set_fixed_process(should_process && process_mode == PROCESS_FIXED);
}
Particles2D::ProcessMode Particles2D::get_process_mode() const {
@@ -719,7 +681,7 @@ Particles2D::ProcessMode Particles2D::get_process_mode() const {
void Particles2D::set_amount(int p_amount) {
- ERR_FAIL_INDEX(p_amount,1024+1);
+ ERR_FAIL_INDEX(p_amount, 1024 + 1);
particles.resize(p_amount);
}
@@ -741,9 +703,9 @@ float Particles2D::get_emit_timeout() const {
void Particles2D::set_lifetime(float p_lifetime) {
- ERR_FAIL_INDEX(p_lifetime,3600+1);
+ ERR_FAIL_INDEX(p_lifetime, 3600 + 1);
- lifetime=p_lifetime;
+ lifetime = p_lifetime;
}
float Particles2D::get_lifetime() const {
@@ -752,7 +714,7 @@ float Particles2D::get_lifetime() const {
void Particles2D::set_time_scale(float p_time_scale) {
- time_scale=p_time_scale;
+ time_scale = p_time_scale;
}
float Particles2D::get_time_scale() const {
@@ -761,42 +723,39 @@ float Particles2D::get_time_scale() const {
void Particles2D::set_pre_process_time(float p_pre_process_time) {
- preprocess=p_pre_process_time;
+ preprocess = p_pre_process_time;
}
-float Particles2D::get_pre_process_time() const{
+float Particles2D::get_pre_process_time() const {
return preprocess;
}
-
void Particles2D::set_param(Parameter p_param, float p_value) {
- ERR_FAIL_INDEX(p_param,PARAM_MAX);
- param[p_param]=p_value;
+ ERR_FAIL_INDEX(p_param, PARAM_MAX);
+ param[p_param] = p_value;
}
float Particles2D::get_param(Parameter p_param) const {
- ERR_FAIL_INDEX_V(p_param,PARAM_MAX,0);
+ ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
return param[p_param];
}
void Particles2D::set_randomness(Parameter p_param, float p_value) {
- ERR_FAIL_INDEX(p_param,PARAM_MAX);
- randomness[p_param]=p_value;
-
+ ERR_FAIL_INDEX(p_param, PARAM_MAX);
+ randomness[p_param] = p_value;
}
-float Particles2D::get_randomness(Parameter p_param) const {
+float Particles2D::get_randomness(Parameter p_param) const {
- ERR_FAIL_INDEX_V(p_param,PARAM_MAX,0);
+ ERR_FAIL_INDEX_V(p_param, PARAM_MAX, 0);
return randomness[p_param];
-
}
-void Particles2D::set_texture(const Ref<Texture>& p_texture) {
+void Particles2D::set_texture(const Ref<Texture> &p_texture) {
- texture=p_texture;
+ texture = p_texture;
}
Ref<Texture> Particles2D::get_texture() const {
@@ -804,7 +763,7 @@ Ref<Texture> Particles2D::get_texture() const {
return texture;
}
-void Particles2D::set_color(const Color& p_color) {
+void Particles2D::set_color(const Color &p_color) {
default_color = p_color;
}
@@ -814,10 +773,9 @@ Color Particles2D::get_color() const {
return default_color;
}
+void Particles2D::set_color_ramp(const Ref<ColorRamp> &p_color_ramp) {
-void Particles2D::set_color_ramp(const Ref<ColorRamp>& p_color_ramp) {
-
- color_ramp=p_color_ramp;
+ color_ramp = p_color_ramp;
}
Ref<ColorRamp> Particles2D::get_color_ramp() const {
@@ -825,9 +783,9 @@ Ref<ColorRamp> Particles2D::get_color_ramp() const {
return color_ramp;
}
-void Particles2D::set_emissor_offset(const Point2& p_offset) {
+void Particles2D::set_emissor_offset(const Point2 &p_offset) {
- emissor_offset=p_offset;
+ emissor_offset = p_offset;
}
Point2 Particles2D::get_emissor_offset() const {
@@ -835,10 +793,9 @@ Point2 Particles2D::get_emissor_offset() const {
return emissor_offset;
}
-
void Particles2D::set_use_local_space(bool p_use) {
- local_space=p_use;
+ local_space = p_use;
}
bool Particles2D::is_using_local_space() const {
@@ -851,12 +808,10 @@ void Particles2D::set_color_phases(int p_phases) {
//Create color ramp if we have 2 or more phases.
//Otherwise first phase phase will be assigned to default color.
- if(p_phases > 1 && color_ramp.is_null())
- {
- color_ramp = Ref<ColorRamp>(memnew (ColorRamp()));
+ if (p_phases > 1 && color_ramp.is_null()) {
+ color_ramp = Ref<ColorRamp>(memnew(ColorRamp()));
}
- if(color_ramp.is_valid())
- {
+ if (color_ramp.is_valid()) {
color_ramp->get_points().resize(p_phases);
}
}
@@ -864,24 +819,21 @@ void Particles2D::set_color_phases(int p_phases) {
//Deprecated.
int Particles2D::get_color_phases() const {
- if(color_ramp.is_valid())
- {
+ if (color_ramp.is_valid()) {
return color_ramp->get_points_count();
}
return 0;
}
//Deprecated. Converts color phases to color ramp
-void Particles2D::set_color_phase_color(int p_phase,const Color& p_color) {
+void Particles2D::set_color_phase_color(int p_phase, const Color &p_color) {
- ERR_FAIL_INDEX(p_phase,MAX_COLOR_PHASES);
- if(color_ramp.is_valid())
- {
- if(color_ramp->get_points_count() > p_phase)
+ ERR_FAIL_INDEX(p_phase, MAX_COLOR_PHASES);
+ if (color_ramp.is_valid()) {
+ if (color_ramp->get_points_count() > p_phase)
color_ramp->set_color(p_phase, p_color);
- } else
- {
- if(p_phase == 0)
+ } else {
+ if (p_phase == 0)
default_color = p_color;
}
}
@@ -889,20 +841,18 @@ void Particles2D::set_color_phase_color(int p_phase,const Color& p_color) {
//Deprecated.
Color Particles2D::get_color_phase_color(int p_phase) const {
- ERR_FAIL_INDEX_V(p_phase,MAX_COLOR_PHASES,Color());
- if(color_ramp.is_valid())
- {
+ ERR_FAIL_INDEX_V(p_phase, MAX_COLOR_PHASES, Color());
+ if (color_ramp.is_valid()) {
return color_ramp->get_color(p_phase);
}
- return Color(0,0,0,1);
+ return Color(0, 0, 0, 1);
}
//Deprecated. Converts color phases to color ramp
-void Particles2D::set_color_phase_pos(int p_phase,float p_pos) {
- ERR_FAIL_INDEX(p_phase,MAX_COLOR_PHASES);
- ERR_FAIL_COND(p_pos<0.0 || p_pos>1.0);
- if(color_ramp.is_valid() && color_ramp->get_points_count() > p_phase)
- {
+void Particles2D::set_color_phase_pos(int p_phase, float p_pos) {
+ ERR_FAIL_INDEX(p_phase, MAX_COLOR_PHASES);
+ ERR_FAIL_COND(p_pos < 0.0 || p_pos > 1.0);
+ if (color_ramp.is_valid() && color_ramp->get_points_count() > p_phase) {
return color_ramp->set_offset(p_phase, p_pos);
}
}
@@ -910,17 +860,16 @@ void Particles2D::set_color_phase_pos(int p_phase,float p_pos) {
//Deprecated.
float Particles2D::get_color_phase_pos(int p_phase) const {
- ERR_FAIL_INDEX_V(p_phase,MAX_COLOR_PHASES,0);
- if(color_ramp.is_valid())
- {
+ ERR_FAIL_INDEX_V(p_phase, MAX_COLOR_PHASES, 0);
+ if (color_ramp.is_valid()) {
return color_ramp->get_offset(p_phase);
}
return 0;
}
-void Particles2D::set_emission_half_extents(const Vector2& p_extents) {
+void Particles2D::set_emission_half_extents(const Vector2 &p_extents) {
- extents=p_extents;
+ extents = p_extents;
}
Vector2 Particles2D::get_emission_half_extents() const {
@@ -928,278 +877,269 @@ Vector2 Particles2D::get_emission_half_extents() const {
return extents;
}
-void Particles2D::set_initial_velocity(const Vector2& p_velocity) {
-
+void Particles2D::set_initial_velocity(const Vector2 &p_velocity) {
- initial_velocity=p_velocity;
+ initial_velocity = p_velocity;
}
-Vector2 Particles2D::get_initial_velocity() const{
+Vector2 Particles2D::get_initial_velocity() const {
return initial_velocity;
}
-
void Particles2D::pre_process(float p_delta) {
_process_particles(p_delta);
}
-
void Particles2D::set_explosiveness(float p_value) {
- explosiveness=p_value;
+ explosiveness = p_value;
}
-float Particles2D::get_explosiveness() const{
+float Particles2D::get_explosiveness() const {
return explosiveness;
}
void Particles2D::set_flip_h(bool p_flip) {
- flip_h=p_flip;
+ flip_h = p_flip;
}
-bool Particles2D::is_flipped_h() const{
+bool Particles2D::is_flipped_h() const {
return flip_h;
}
-void Particles2D::set_flip_v(bool p_flip){
+void Particles2D::set_flip_v(bool p_flip) {
- flip_v=p_flip;
+ flip_v = p_flip;
}
-bool Particles2D::is_flipped_v() const{
+bool Particles2D::is_flipped_v() const {
return flip_v;
}
void Particles2D::set_h_frames(int p_frames) {
- ERR_FAIL_COND(p_frames<1);
- h_frames=p_frames;
+ ERR_FAIL_COND(p_frames < 1);
+ h_frames = p_frames;
}
-int Particles2D::get_h_frames() const{
+int Particles2D::get_h_frames() const {
return h_frames;
}
-void Particles2D::set_v_frames(int p_frames){
+void Particles2D::set_v_frames(int p_frames) {
- ERR_FAIL_COND(p_frames<1);
- v_frames=p_frames;
+ ERR_FAIL_COND(p_frames < 1);
+ v_frames = p_frames;
}
-int Particles2D::get_v_frames() const{
+int Particles2D::get_v_frames() const {
return v_frames;
}
+void Particles2D::set_emission_points(const PoolVector<Vector2> &p_points) {
-
-void Particles2D::set_emission_points(const PoolVector<Vector2>& p_points) {
-
- emission_points=p_points;
+ emission_points = p_points;
}
-PoolVector<Vector2> Particles2D::get_emission_points() const{
+PoolVector<Vector2> Particles2D::get_emission_points() const {
return emission_points;
}
void Particles2D::reset() {
- for(int i=0;i<particles.size();i++) {
- particles[i].active=false;
+ for (int i = 0; i < particles.size(); i++) {
+ particles[i].active = false;
}
- time=0;
- active_count=0;
+ time = 0;
+ active_count = 0;
}
void Particles2D::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_emitting","active"),&Particles2D::set_emitting);
- ClassDB::bind_method(D_METHOD("is_emitting"),&Particles2D::is_emitting);
+ ClassDB::bind_method(D_METHOD("set_emitting", "active"), &Particles2D::set_emitting);
+ ClassDB::bind_method(D_METHOD("is_emitting"), &Particles2D::is_emitting);
- ClassDB::bind_method(D_METHOD("set_process_mode","mode"),&Particles2D::set_process_mode);
- ClassDB::bind_method(D_METHOD("get_process_mode"),&Particles2D::get_process_mode);
+ ClassDB::bind_method(D_METHOD("set_process_mode", "mode"), &Particles2D::set_process_mode);
+ ClassDB::bind_method(D_METHOD("get_process_mode"), &Particles2D::get_process_mode);
- ClassDB::bind_method(D_METHOD("set_amount","amount"),&Particles2D::set_amount);
- ClassDB::bind_method(D_METHOD("get_amount"),&Particles2D::get_amount);
+ ClassDB::bind_method(D_METHOD("set_amount", "amount"), &Particles2D::set_amount);
+ ClassDB::bind_method(D_METHOD("get_amount"), &Particles2D::get_amount);
- ClassDB::bind_method(D_METHOD("set_lifetime","lifetime"),&Particles2D::set_lifetime);
- ClassDB::bind_method(D_METHOD("get_lifetime"),&Particles2D::get_lifetime);
+ ClassDB::bind_method(D_METHOD("set_lifetime", "lifetime"), &Particles2D::set_lifetime);
+ ClassDB::bind_method(D_METHOD("get_lifetime"), &Particles2D::get_lifetime);
- ClassDB::bind_method(D_METHOD("set_time_scale","time_scale"),&Particles2D::set_time_scale);
- ClassDB::bind_method(D_METHOD("get_time_scale"),&Particles2D::get_time_scale);
+ ClassDB::bind_method(D_METHOD("set_time_scale", "time_scale"), &Particles2D::set_time_scale);
+ ClassDB::bind_method(D_METHOD("get_time_scale"), &Particles2D::get_time_scale);
- ClassDB::bind_method(D_METHOD("set_pre_process_time","time"),&Particles2D::set_pre_process_time);
- ClassDB::bind_method(D_METHOD("get_pre_process_time"),&Particles2D::get_pre_process_time);
+ ClassDB::bind_method(D_METHOD("set_pre_process_time", "time"), &Particles2D::set_pre_process_time);
+ ClassDB::bind_method(D_METHOD("get_pre_process_time"), &Particles2D::get_pre_process_time);
- ClassDB::bind_method(D_METHOD("set_emit_timeout","value"),&Particles2D::set_emit_timeout);
- ClassDB::bind_method(D_METHOD("get_emit_timeout"),&Particles2D::get_emit_timeout);
+ ClassDB::bind_method(D_METHOD("set_emit_timeout", "value"), &Particles2D::set_emit_timeout);
+ ClassDB::bind_method(D_METHOD("get_emit_timeout"), &Particles2D::get_emit_timeout);
- ClassDB::bind_method(D_METHOD("set_param","param","value"),&Particles2D::set_param);
- ClassDB::bind_method(D_METHOD("get_param","param"),&Particles2D::get_param);
+ ClassDB::bind_method(D_METHOD("set_param", "param", "value"), &Particles2D::set_param);
+ ClassDB::bind_method(D_METHOD("get_param", "param"), &Particles2D::get_param);
- ClassDB::bind_method(D_METHOD("set_randomness","param","value"),&Particles2D::set_randomness);
- ClassDB::bind_method(D_METHOD("get_randomness","param"),&Particles2D::get_randomness);
+ ClassDB::bind_method(D_METHOD("set_randomness", "param", "value"), &Particles2D::set_randomness);
+ ClassDB::bind_method(D_METHOD("get_randomness", "param"), &Particles2D::get_randomness);
- ClassDB::bind_method(D_METHOD("set_texture:Texture","texture"),&Particles2D::set_texture);
- ClassDB::bind_method(D_METHOD("get_texture:Texture"),&Particles2D::get_texture);
+ ClassDB::bind_method(D_METHOD("set_texture:Texture", "texture"), &Particles2D::set_texture);
+ ClassDB::bind_method(D_METHOD("get_texture:Texture"), &Particles2D::get_texture);
- ClassDB::bind_method(D_METHOD("set_color","color"),&Particles2D::set_color);
- ClassDB::bind_method(D_METHOD("get_color"),&Particles2D::get_color);
+ ClassDB::bind_method(D_METHOD("set_color", "color"), &Particles2D::set_color);
+ ClassDB::bind_method(D_METHOD("get_color"), &Particles2D::get_color);
- ClassDB::bind_method(D_METHOD("set_color_ramp:ColorRamp","color_ramp"),&Particles2D::set_color_ramp);
- ClassDB::bind_method(D_METHOD("get_color_ramp:ColorRamp"),&Particles2D::get_color_ramp);
+ ClassDB::bind_method(D_METHOD("set_color_ramp:ColorRamp", "color_ramp"), &Particles2D::set_color_ramp);
+ ClassDB::bind_method(D_METHOD("get_color_ramp:ColorRamp"), &Particles2D::get_color_ramp);
- ClassDB::bind_method(D_METHOD("set_emissor_offset","offset"),&Particles2D::set_emissor_offset);
- ClassDB::bind_method(D_METHOD("get_emissor_offset"),&Particles2D::get_emissor_offset);
+ ClassDB::bind_method(D_METHOD("set_emissor_offset", "offset"), &Particles2D::set_emissor_offset);
+ ClassDB::bind_method(D_METHOD("get_emissor_offset"), &Particles2D::get_emissor_offset);
- ClassDB::bind_method(D_METHOD("set_flip_h","enable"),&Particles2D::set_flip_h);
- ClassDB::bind_method(D_METHOD("is_flipped_h"),&Particles2D::is_flipped_h);
+ ClassDB::bind_method(D_METHOD("set_flip_h", "enable"), &Particles2D::set_flip_h);
+ ClassDB::bind_method(D_METHOD("is_flipped_h"), &Particles2D::is_flipped_h);
- ClassDB::bind_method(D_METHOD("set_flip_v","enable"),&Particles2D::set_flip_v);
- ClassDB::bind_method(D_METHOD("is_flipped_v"),&Particles2D::is_flipped_v);
+ ClassDB::bind_method(D_METHOD("set_flip_v", "enable"), &Particles2D::set_flip_v);
+ ClassDB::bind_method(D_METHOD("is_flipped_v"), &Particles2D::is_flipped_v);
- ClassDB::bind_method(D_METHOD("set_h_frames","enable"),&Particles2D::set_h_frames);
- ClassDB::bind_method(D_METHOD("get_h_frames"),&Particles2D::get_h_frames);
+ ClassDB::bind_method(D_METHOD("set_h_frames", "enable"), &Particles2D::set_h_frames);
+ ClassDB::bind_method(D_METHOD("get_h_frames"), &Particles2D::get_h_frames);
- ClassDB::bind_method(D_METHOD("set_v_frames","enable"),&Particles2D::set_v_frames);
- ClassDB::bind_method(D_METHOD("get_v_frames"),&Particles2D::get_v_frames);
+ ClassDB::bind_method(D_METHOD("set_v_frames", "enable"), &Particles2D::set_v_frames);
+ ClassDB::bind_method(D_METHOD("get_v_frames"), &Particles2D::get_v_frames);
- ClassDB::bind_method(D_METHOD("set_emission_half_extents","extents"),&Particles2D::set_emission_half_extents);
- ClassDB::bind_method(D_METHOD("get_emission_half_extents"),&Particles2D::get_emission_half_extents);
+ ClassDB::bind_method(D_METHOD("set_emission_half_extents", "extents"), &Particles2D::set_emission_half_extents);
+ ClassDB::bind_method(D_METHOD("get_emission_half_extents"), &Particles2D::get_emission_half_extents);
- ClassDB::bind_method(D_METHOD("set_color_phases","phases"),&Particles2D::set_color_phases);
- ClassDB::bind_method(D_METHOD("get_color_phases"),&Particles2D::get_color_phases);
+ ClassDB::bind_method(D_METHOD("set_color_phases", "phases"), &Particles2D::set_color_phases);
+ ClassDB::bind_method(D_METHOD("get_color_phases"), &Particles2D::get_color_phases);
- ClassDB::bind_method(D_METHOD("set_color_phase_color","phase","color"),&Particles2D::set_color_phase_color);
- ClassDB::bind_method(D_METHOD("get_color_phase_color","phase"),&Particles2D::get_color_phase_color);
+ ClassDB::bind_method(D_METHOD("set_color_phase_color", "phase", "color"), &Particles2D::set_color_phase_color);
+ ClassDB::bind_method(D_METHOD("get_color_phase_color", "phase"), &Particles2D::get_color_phase_color);
- ClassDB::bind_method(D_METHOD("set_color_phase_pos","phase","pos"),&Particles2D::set_color_phase_pos);
- ClassDB::bind_method(D_METHOD("get_color_phase_pos","phase"),&Particles2D::get_color_phase_pos);
+ ClassDB::bind_method(D_METHOD("set_color_phase_pos", "phase", "pos"), &Particles2D::set_color_phase_pos);
+ ClassDB::bind_method(D_METHOD("get_color_phase_pos", "phase"), &Particles2D::get_color_phase_pos);
- ClassDB::bind_method(D_METHOD("pre_process","time"),&Particles2D::pre_process);
- ClassDB::bind_method(D_METHOD("reset"),&Particles2D::reset);
+ ClassDB::bind_method(D_METHOD("pre_process", "time"), &Particles2D::pre_process);
+ ClassDB::bind_method(D_METHOD("reset"), &Particles2D::reset);
- ClassDB::bind_method(D_METHOD("set_use_local_space","enable"),&Particles2D::set_use_local_space);
- ClassDB::bind_method(D_METHOD("is_using_local_space"),&Particles2D::is_using_local_space);
+ ClassDB::bind_method(D_METHOD("set_use_local_space", "enable"), &Particles2D::set_use_local_space);
+ ClassDB::bind_method(D_METHOD("is_using_local_space"), &Particles2D::is_using_local_space);
- ClassDB::bind_method(D_METHOD("set_initial_velocity","velocity"),&Particles2D::set_initial_velocity);
- ClassDB::bind_method(D_METHOD("get_initial_velocity"),&Particles2D::get_initial_velocity);
+ ClassDB::bind_method(D_METHOD("set_initial_velocity", "velocity"), &Particles2D::set_initial_velocity);
+ ClassDB::bind_method(D_METHOD("get_initial_velocity"), &Particles2D::get_initial_velocity);
- ClassDB::bind_method(D_METHOD("set_explosiveness","amount"),&Particles2D::set_explosiveness);
- ClassDB::bind_method(D_METHOD("get_explosiveness"),&Particles2D::get_explosiveness);
+ ClassDB::bind_method(D_METHOD("set_explosiveness", "amount"), &Particles2D::set_explosiveness);
+ ClassDB::bind_method(D_METHOD("get_explosiveness"), &Particles2D::get_explosiveness);
- ClassDB::bind_method(D_METHOD("set_emission_points","points"),&Particles2D::set_emission_points);
- ClassDB::bind_method(D_METHOD("get_emission_points"),&Particles2D::get_emission_points);
+ ClassDB::bind_method(D_METHOD("set_emission_points", "points"), &Particles2D::set_emission_points);
+ ClassDB::bind_method(D_METHOD("get_emission_points"), &Particles2D::get_emission_points);
ADD_SIGNAL(MethodInfo("emission_finished"));
- ADD_PROPERTY(PropertyInfo(Variant::INT,"config/amount",PROPERTY_HINT_EXP_RANGE,"1,1024"),"set_amount","get_amount") ;
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"config/lifetime",PROPERTY_HINT_EXP_RANGE,"0.1,3600,0.1"),"set_lifetime","get_lifetime") ;
- ADD_PROPERTYNO(PropertyInfo(Variant::REAL,"config/time_scale",PROPERTY_HINT_EXP_RANGE,"0.01,128,0.01"),"set_time_scale","get_time_scale") ;
- ADD_PROPERTYNZ(PropertyInfo(Variant::REAL,"config/preprocess",PROPERTY_HINT_EXP_RANGE,"0.1,3600,0.1"),"set_pre_process_time","get_pre_process_time") ;
- ADD_PROPERTYNZ(PropertyInfo(Variant::REAL,"config/emit_timeout",PROPERTY_HINT_RANGE,"0,3600,0.1"),"set_emit_timeout","get_emit_timeout") ;
- ADD_PROPERTYNO(PropertyInfo(Variant::BOOL,"config/emitting"),"set_emitting","is_emitting") ;
- ADD_PROPERTY(PropertyInfo(Variant::INT,"config/process_mode",PROPERTY_HINT_ENUM, "Fixed,Idle"),"set_process_mode","get_process_mode");
- ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2,"config/offset"),"set_emissor_offset","get_emissor_offset");
- ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2,"config/half_extents"),"set_emission_half_extents","get_emission_half_extents");
- ADD_PROPERTYNO(PropertyInfo(Variant::BOOL,"config/local_space"),"set_use_local_space","is_using_local_space");
- ADD_PROPERTYNO(PropertyInfo(Variant::REAL,"config/explosiveness",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_explosiveness","get_explosiveness");
- ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL,"config/flip_h"),"set_flip_h","is_flipped_h");
- ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL,"config/flip_v"),"set_flip_v","is_flipped_v");
- ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT,"config/texture",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),"set_texture","get_texture");
- ADD_PROPERTYNO(PropertyInfo(Variant::INT,"config/h_frames",PROPERTY_HINT_RANGE,"1,512,1"),"set_h_frames","get_h_frames");
- ADD_PROPERTYNO(PropertyInfo(Variant::INT,"config/v_frames",PROPERTY_HINT_RANGE,"1,512,1"),"set_v_frames","get_v_frames");
-
-
- for(int i=0;i<PARAM_MAX;i++) {
- ADD_PROPERTYI(PropertyInfo(Variant::REAL,_particlesframe_property_names[i],PROPERTY_HINT_RANGE,_particlesframe_property_ranges[i]),"set_param","get_param",i);
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "config/amount", PROPERTY_HINT_EXP_RANGE, "1,1024"), "set_amount", "get_amount");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "config/lifetime", PROPERTY_HINT_EXP_RANGE, "0.1,3600,0.1"), "set_lifetime", "get_lifetime");
+ ADD_PROPERTYNO(PropertyInfo(Variant::REAL, "config/time_scale", PROPERTY_HINT_EXP_RANGE, "0.01,128,0.01"), "set_time_scale", "get_time_scale");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "config/preprocess", PROPERTY_HINT_EXP_RANGE, "0.1,3600,0.1"), "set_pre_process_time", "get_pre_process_time");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "config/emit_timeout", PROPERTY_HINT_RANGE, "0,3600,0.1"), "set_emit_timeout", "get_emit_timeout");
+ ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "config/emitting"), "set_emitting", "is_emitting");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "config/process_mode", PROPERTY_HINT_ENUM, "Fixed,Idle"), "set_process_mode", "get_process_mode");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "config/offset"), "set_emissor_offset", "get_emissor_offset");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "config/half_extents"), "set_emission_half_extents", "get_emission_half_extents");
+ ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "config/local_space"), "set_use_local_space", "is_using_local_space");
+ ADD_PROPERTYNO(PropertyInfo(Variant::REAL, "config/explosiveness", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_explosiveness", "get_explosiveness");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "config/flip_h"), "set_flip_h", "is_flipped_h");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "config/flip_v"), "set_flip_v", "is_flipped_v");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "config/texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture");
+ ADD_PROPERTYNO(PropertyInfo(Variant::INT, "config/h_frames", PROPERTY_HINT_RANGE, "1,512,1"), "set_h_frames", "get_h_frames");
+ ADD_PROPERTYNO(PropertyInfo(Variant::INT, "config/v_frames", PROPERTY_HINT_RANGE, "1,512,1"), "set_v_frames", "get_v_frames");
+
+ for (int i = 0; i < PARAM_MAX; i++) {
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, _particlesframe_property_names[i], PROPERTY_HINT_RANGE, _particlesframe_property_ranges[i]), "set_param", "get_param", i);
}
- for(int i=0;i<PARAM_MAX;i++) {
- ADD_PROPERTYINZ(PropertyInfo(Variant::REAL,_particlesframe_property_rnames[i],PROPERTY_HINT_RANGE,"-1,1,0.01"),"set_randomness","get_randomness",i);
+ for (int i = 0; i < PARAM_MAX; i++) {
+ ADD_PROPERTYINZ(PropertyInfo(Variant::REAL, _particlesframe_property_rnames[i], PROPERTY_HINT_RANGE, "-1,1,0.01"), "set_randomness", "get_randomness", i);
}
- ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "color_phases/count",PROPERTY_HINT_RANGE,"0,4,1", 0), "set_color_phases", "get_color_phases");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "color_phases/count", PROPERTY_HINT_RANGE, "0,4,1", 0), "set_color_phases", "get_color_phases");
//Backward compatibility. They will be converted to color ramp
- for(int i=0;i<MAX_COLOR_PHASES;i++) {
- String phase="phase_"+itos(i)+"/";
- ADD_PROPERTYI( PropertyInfo( Variant::REAL, phase+"pos", PROPERTY_HINT_RANGE,"0,1,0.01", 0),"set_color_phase_pos","get_color_phase_pos",i );
- ADD_PROPERTYI( PropertyInfo( Variant::COLOR, phase+"color", PROPERTY_HINT_NONE, "", 0),"set_color_phase_color","get_color_phase_color",i );
+ for (int i = 0; i < MAX_COLOR_PHASES; i++) {
+ String phase = "phase_" + itos(i) + "/";
+ ADD_PROPERTYI(PropertyInfo(Variant::REAL, phase + "pos", PROPERTY_HINT_RANGE, "0,1,0.01", 0), "set_color_phase_pos", "get_color_phase_pos", i);
+ ADD_PROPERTYI(PropertyInfo(Variant::COLOR, phase + "color", PROPERTY_HINT_NONE, "", 0), "set_color_phase_color", "get_color_phase_color", i);
}
- ADD_PROPERTYNO(PropertyInfo(Variant::COLOR, "color/color"),"set_color","get_color");
- ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT,"color/color_ramp",PROPERTY_HINT_RESOURCE_TYPE,"ColorRamp"),"set_color_ramp","get_color_ramp");
-
- ADD_PROPERTYNZ(PropertyInfo(Variant::POOL_VECTOR2_ARRAY,"emission_points",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"set_emission_points","get_emission_points");
+ ADD_PROPERTYNO(PropertyInfo(Variant::COLOR, "color/color"), "set_color", "get_color");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "color/color_ramp", PROPERTY_HINT_RESOURCE_TYPE, "ColorRamp"), "set_color_ramp", "get_color_ramp");
- BIND_CONSTANT( PARAM_DIRECTION );
- BIND_CONSTANT( PARAM_SPREAD );
- BIND_CONSTANT( PARAM_LINEAR_VELOCITY );
- BIND_CONSTANT( PARAM_SPIN_VELOCITY );
- BIND_CONSTANT( PARAM_ORBIT_VELOCITY );
- BIND_CONSTANT( PARAM_GRAVITY_DIRECTION );
- BIND_CONSTANT( PARAM_GRAVITY_STRENGTH );
- BIND_CONSTANT( PARAM_RADIAL_ACCEL );
- BIND_CONSTANT( PARAM_TANGENTIAL_ACCEL );
- BIND_CONSTANT( PARAM_DAMPING );
- BIND_CONSTANT( PARAM_INITIAL_ANGLE );
- BIND_CONSTANT( PARAM_INITIAL_SIZE );
- BIND_CONSTANT( PARAM_FINAL_SIZE );
- BIND_CONSTANT( PARAM_HUE_VARIATION );
- BIND_CONSTANT( PARAM_ANIM_SPEED_SCALE );
- BIND_CONSTANT( PARAM_ANIM_INITIAL_POS );
- BIND_CONSTANT( PARAM_MAX );
+ ADD_PROPERTYNZ(PropertyInfo(Variant::POOL_VECTOR2_ARRAY, "emission_points", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "set_emission_points", "get_emission_points");
- BIND_CONSTANT( MAX_COLOR_PHASES );
+ BIND_CONSTANT(PARAM_DIRECTION);
+ BIND_CONSTANT(PARAM_SPREAD);
+ BIND_CONSTANT(PARAM_LINEAR_VELOCITY);
+ BIND_CONSTANT(PARAM_SPIN_VELOCITY);
+ BIND_CONSTANT(PARAM_ORBIT_VELOCITY);
+ BIND_CONSTANT(PARAM_GRAVITY_DIRECTION);
+ BIND_CONSTANT(PARAM_GRAVITY_STRENGTH);
+ BIND_CONSTANT(PARAM_RADIAL_ACCEL);
+ BIND_CONSTANT(PARAM_TANGENTIAL_ACCEL);
+ BIND_CONSTANT(PARAM_DAMPING);
+ BIND_CONSTANT(PARAM_INITIAL_ANGLE);
+ BIND_CONSTANT(PARAM_INITIAL_SIZE);
+ BIND_CONSTANT(PARAM_FINAL_SIZE);
+ BIND_CONSTANT(PARAM_HUE_VARIATION);
+ BIND_CONSTANT(PARAM_ANIM_SPEED_SCALE);
+ BIND_CONSTANT(PARAM_ANIM_INITIAL_POS);
+ BIND_CONSTANT(PARAM_MAX);
+ BIND_CONSTANT(MAX_COLOR_PHASES);
}
Particles2D::Particles2D() {
- for(int i=0;i<PARAM_MAX;i++) {
+ for (int i = 0; i < PARAM_MAX; i++) {
- param[i]=0;
- randomness[i]=0;
+ param[i] = 0;
+ randomness[i] = 0;
}
-
- set_param(PARAM_SPREAD,10);
- set_param(PARAM_LINEAR_VELOCITY,20);
- set_param(PARAM_GRAVITY_STRENGTH,9.8);
- set_param(PARAM_RADIAL_ACCEL,0);
- set_param(PARAM_TANGENTIAL_ACCEL,0);
- set_param(PARAM_INITIAL_ANGLE,0.0);
- set_param(PARAM_INITIAL_SIZE,1.0);
- set_param(PARAM_FINAL_SIZE,1.0);
- set_param(PARAM_ANIM_SPEED_SCALE,1.0);
-
- set_color(Color(1,1,1,1));
-
- time=0;
- lifetime=2;
- emitting=false;
+ set_param(PARAM_SPREAD, 10);
+ set_param(PARAM_LINEAR_VELOCITY, 20);
+ set_param(PARAM_GRAVITY_STRENGTH, 9.8);
+ set_param(PARAM_RADIAL_ACCEL, 0);
+ set_param(PARAM_TANGENTIAL_ACCEL, 0);
+ set_param(PARAM_INITIAL_ANGLE, 0.0);
+ set_param(PARAM_INITIAL_SIZE, 1.0);
+ set_param(PARAM_FINAL_SIZE, 1.0);
+ set_param(PARAM_ANIM_SPEED_SCALE, 1.0);
+
+ set_color(Color(1, 1, 1, 1));
+
+ time = 0;
+ lifetime = 2;
+ emitting = false;
particles.resize(32);
- active_count=-1;
+ active_count = -1;
set_emitting(true);
- process_mode=PROCESS_IDLE;
- local_space=true;
- preprocess=0;
- time_scale=1.0;
-
+ process_mode = PROCESS_IDLE;
+ local_space = true;
+ preprocess = 0;
+ time_scale = 1.0;
- flip_h=false;
- flip_v=false;
+ flip_h = false;
+ flip_v = false;
- v_frames=1;
- h_frames=1;
+ v_frames = 1;
+ h_frames = 1;
emit_timeout = 0;
time_to_live = 0;
- explosiveness=1.0;
+ explosiveness = 1.0;
}
diff --git a/scene/2d/particles_2d.h b/scene/2d/particles_2d.h
index c6ababe3be..0cf4063cef 100644
--- a/scene/2d/particles_2d.h
+++ b/scene/2d/particles_2d.h
@@ -30,16 +30,15 @@
#define PARTICLES_FRAME_H
#include "scene/2d/node_2d.h"
-#include "scene/resources/texture.h"
#include "scene/resources/color_ramp.h"
+#include "scene/resources/texture.h"
class Particles2D;
class ParticleAttractor2D : public Node2D {
- GDCLASS(ParticleAttractor2D,Node2D);
+ GDCLASS(ParticleAttractor2D, Node2D);
-
-friend class Particles2D;
+ friend class Particles2D;
bool enabled;
float radius;
float disable_radius;
@@ -51,12 +50,12 @@ friend class Particles2D;
void _update_owner();
void _owner_exited();
- void _set_owner(Particles2D* p_owner);
+ void _set_owner(Particles2D *p_owner);
void _notification(int p_what);
static void _bind_methods();
-public:
+public:
void set_enabled(bool p_enabled);
bool is_enabled() const;
@@ -80,13 +79,11 @@ public:
ParticleAttractor2D();
};
-
-
class Particles2D : public Node2D {
GDCLASS(Particles2D, Node2D);
-public:
+public:
enum Parameter {
PARAM_DIRECTION,
PARAM_SPREAD,
@@ -108,7 +105,7 @@ public:
};
enum {
- MAX_COLOR_PHASES=4
+ MAX_COLOR_PHASES = 4
};
enum ProcessMode {
@@ -117,7 +114,6 @@ public:
};
private:
-
float param[PARAM_MAX];
float randomness[PARAM_MAX];
@@ -128,7 +124,12 @@ private:
float rot;
float frame;
uint64_t seed;
- Particle() { active=false; seed=123465789; rot=0; frame=0;}
+ Particle() {
+ active = false;
+ seed = 123465789;
+ rot = 0;
+ frame = 0;
+ }
};
Vector<Particle> particles;
@@ -170,17 +171,15 @@ private:
Ref<ColorRamp> color_ramp;
void _process_particles(float p_delta);
-friend class ParticleAttractor2D;
+ friend class ParticleAttractor2D;
- Set<ParticleAttractor2D*> attractors;
+ Set<ParticleAttractor2D *> attractors;
protected:
-
void _notification(int p_what);
static void _bind_methods();
public:
-
void set_emitting(bool p_emitting);
bool is_emitting() const;
@@ -202,7 +201,7 @@ public:
void set_emit_timeout(float p_timeout);
float get_emit_timeout() const;
- void set_emission_half_extents(const Vector2& p_extents);
+ void set_emission_half_extents(const Vector2 &p_extents);
Vector2 get_emission_half_extents() const;
void set_param(Parameter p_param, float p_value);
@@ -220,7 +219,6 @@ public:
void set_flip_v(bool p_flip);
bool is_flipped_v() const;
-
void set_h_frames(int p_frames);
int get_h_frames() const;
@@ -230,31 +228,31 @@ public:
void set_color_phases(int p_phases);
int get_color_phases() const;
- void set_color_phase_color(int p_phase,const Color& p_color);
+ void set_color_phase_color(int p_phase, const Color &p_color);
Color get_color_phase_color(int p_phase) const;
- void set_color_phase_pos(int p_phase,float p_pos);
+ void set_color_phase_pos(int p_phase, float p_pos);
float get_color_phase_pos(int p_phase) const;
- void set_texture(const Ref<Texture>& p_texture);
+ void set_texture(const Ref<Texture> &p_texture);
Ref<Texture> get_texture() const;
- void set_color(const Color& p_color);
+ void set_color(const Color &p_color);
Color get_color() const;
- void set_color_ramp(const Ref<ColorRamp>& p_texture);
+ void set_color_ramp(const Ref<ColorRamp> &p_texture);
Ref<ColorRamp> get_color_ramp() const;
- void set_emissor_offset(const Point2& p_offset);
+ void set_emissor_offset(const Point2 &p_offset);
Point2 get_emissor_offset() const;
void set_use_local_space(bool p_use);
bool is_using_local_space() const;
- void set_initial_velocity(const Vector2& p_velocity);
+ void set_initial_velocity(const Vector2 &p_velocity);
Vector2 get_initial_velocity() const;
- void set_emission_points(const PoolVector<Vector2>& p_points);
+ void set_emission_points(const PoolVector<Vector2> &p_points);
PoolVector<Vector2> get_emission_points() const;
void pre_process(float p_delta);
@@ -263,7 +261,7 @@ public:
Particles2D();
};
-VARIANT_ENUM_CAST( Particles2D::ProcessMode );
-VARIANT_ENUM_CAST( Particles2D::Parameter );
+VARIANT_ENUM_CAST(Particles2D::ProcessMode);
+VARIANT_ENUM_CAST(Particles2D::Parameter);
#endif // PARTICLES_FRAME_H
diff --git a/scene/2d/path_2d.cpp b/scene/2d/path_2d.cpp
index 63531ae599..9e8be7fa1a 100644
--- a/scene/2d/path_2d.cpp
+++ b/scene/2d/path_2d.cpp
@@ -31,23 +31,23 @@
void Path2D::_notification(int p_what) {
- if (p_what==NOTIFICATION_DRAW && curve.is_valid()) {
+ if (p_what == NOTIFICATION_DRAW && curve.is_valid()) {
//draw the curve!!
if (!get_tree()->is_editor_hint() && !get_tree()->is_debugging_navigation_hint()) {
return;
}
- for(int i=0;i<curve->get_point_count();i++) {
+ for (int i = 0; i < curve->get_point_count(); i++) {
- Vector2 prev_p=curve->get_point_pos(i);
+ Vector2 prev_p = curve->get_point_pos(i);
- for(int j=1;j<=8;j++) {
+ for (int j = 1; j <= 8; j++) {
- real_t frac = j/8.0;
- Vector2 p = curve->interpolate(i,frac);
- draw_line(prev_p,p,Color(0.5,0.6,1.0,0.7),2);
- prev_p=p;
+ real_t frac = j / 8.0;
+ Vector2 p = curve->interpolate(i, frac);
+ draw_line(prev_p, p, Color(0.5, 0.6, 1.0, 0.7), 2);
+ prev_p = p;
}
}
}
@@ -55,98 +55,89 @@ void Path2D::_notification(int p_what) {
void Path2D::_curve_changed() {
-
if (is_inside_tree() && get_tree()->is_editor_hint())
update();
-
}
-
-void Path2D::set_curve(const Ref<Curve2D>& p_curve) {
+void Path2D::set_curve(const Ref<Curve2D> &p_curve) {
if (curve.is_valid()) {
- curve->disconnect("changed",this,"_curve_changed");
+ curve->disconnect("changed", this, "_curve_changed");
}
- curve=p_curve;
+ curve = p_curve;
if (curve.is_valid()) {
- curve->connect("changed",this,"_curve_changed");
+ curve->connect("changed", this, "_curve_changed");
}
_curve_changed();
-
}
-Ref<Curve2D> Path2D::get_curve() const{
+Ref<Curve2D> Path2D::get_curve() const {
return curve;
}
void Path2D::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_curve","curve:Curve2D"),&Path2D::set_curve);
- ClassDB::bind_method(D_METHOD("get_curve:Curve2D","curve"),&Path2D::get_curve);
- ClassDB::bind_method(D_METHOD("_curve_changed"),&Path2D::_curve_changed);
+ ClassDB::bind_method(D_METHOD("set_curve", "curve:Curve2D"), &Path2D::set_curve);
+ ClassDB::bind_method(D_METHOD("get_curve:Curve2D", "curve"), &Path2D::get_curve);
+ ClassDB::bind_method(D_METHOD("_curve_changed"), &Path2D::_curve_changed);
- ADD_PROPERTY( PropertyInfo( Variant::OBJECT, "curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve2D"), "set_curve","get_curve");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "curve", PROPERTY_HINT_RESOURCE_TYPE, "Curve2D"), "set_curve", "get_curve");
}
Path2D::Path2D() {
- set_curve(Ref<Curve2D>( memnew( Curve2D ))); //create one by default
+ set_curve(Ref<Curve2D>(memnew(Curve2D))); //create one by default
}
/////////////////////////////////////////////////////////////////////////////////
-
void PathFollow2D::_update_transform() {
-
if (!path)
return;
- Ref<Curve2D> c =path->get_curve();
+ Ref<Curve2D> c = path->get_curve();
if (!c.is_valid())
return;
-
float o = offset;
if (loop)
- o=Math::fposmod(o,c->get_baked_length());
+ o = Math::fposmod(o, c->get_baked_length());
- Vector2 pos = c->interpolate_baked(o,cubic);
+ Vector2 pos = c->interpolate_baked(o, cubic);
if (rotate) {
- Vector2 n = (c->interpolate_baked(o+lookahead,cubic)-pos).normalized();
+ Vector2 n = (c->interpolate_baked(o + lookahead, cubic) - pos).normalized();
Vector2 t = -n.tangent();
- pos+=n*h_offset;
- pos+=t*v_offset;
+ pos += n * h_offset;
+ pos += t * v_offset;
set_rotation(t.angle());
} else {
- pos.x+=h_offset;
- pos.y+=v_offset;
+ pos.x += h_offset;
+ pos.y += v_offset;
}
set_position(pos);
-
}
void PathFollow2D::_notification(int p_what) {
-
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
- Node *parent=get_parent();
+ Node *parent = get_parent();
if (parent) {
- path=parent->cast_to<Path2D>();
+ path = parent->cast_to<Path2D>();
if (path) {
_update_transform();
}
@@ -155,16 +146,14 @@ void PathFollow2D::_notification(int p_what) {
} break;
case NOTIFICATION_EXIT_TREE: {
-
- path=NULL;
+ path = NULL;
} break;
}
-
}
void PathFollow2D::set_cubic_interpolation(bool p_enable) {
- cubic=p_enable;
+ cubic = p_enable;
}
bool PathFollow2D::get_cubic_interpolation() const {
@@ -172,24 +161,23 @@ bool PathFollow2D::get_cubic_interpolation() const {
return cubic;
}
+bool PathFollow2D::_set(const StringName &p_name, const Variant &p_value) {
-bool PathFollow2D::_set(const StringName& p_name, const Variant& p_value) {
-
- if (p_name==SceneStringNames::get_singleton()->offset) {
+ if (p_name == SceneStringNames::get_singleton()->offset) {
set_offset(p_value);
- } else if (p_name==SceneStringNames::get_singleton()->unit_offset) {
+ } else if (p_name == SceneStringNames::get_singleton()->unit_offset) {
set_unit_offset(p_value);
- } else if (p_name==SceneStringNames::get_singleton()->rotate) {
+ } else if (p_name == SceneStringNames::get_singleton()->rotate) {
set_rotate(p_value);
- } else if (p_name==SceneStringNames::get_singleton()->v_offset) {
+ } else if (p_name == SceneStringNames::get_singleton()->v_offset) {
set_v_offset(p_value);
- } else if (p_name==SceneStringNames::get_singleton()->h_offset) {
+ } else if (p_name == SceneStringNames::get_singleton()->h_offset) {
set_h_offset(p_value);
- } else if (String(p_name)=="cubic_interp") {
+ } else if (String(p_name) == "cubic_interp") {
set_cubic_interpolation(p_value);
- } else if (String(p_name)=="loop") {
+ } else if (String(p_name) == "loop") {
set_loop(p_value);
- } else if (String(p_name)=="lookahead") {
+ } else if (String(p_name) == "lookahead") {
set_lookahead(p_value);
} else
return false;
@@ -197,46 +185,44 @@ bool PathFollow2D::_set(const StringName& p_name, const Variant& p_value) {
return true;
}
-bool PathFollow2D::_get(const StringName& p_name,Variant &r_ret) const{
-
- if (p_name==SceneStringNames::get_singleton()->offset) {
- r_ret=get_offset();
- } else if (p_name==SceneStringNames::get_singleton()->unit_offset) {
- r_ret=get_unit_offset();
- } else if (p_name==SceneStringNames::get_singleton()->rotate) {
- r_ret=is_rotating();
- } else if (p_name==SceneStringNames::get_singleton()->v_offset) {
- r_ret=get_v_offset();
- } else if (p_name==SceneStringNames::get_singleton()->h_offset) {
- r_ret=get_h_offset();
- } else if (String(p_name)=="cubic_interp") {
- r_ret=cubic;
- } else if (String(p_name)=="loop") {
- r_ret=loop;
- } else if (String(p_name)=="lookahead") {
- r_ret=lookahead;
+bool PathFollow2D::_get(const StringName &p_name, Variant &r_ret) const {
+
+ if (p_name == SceneStringNames::get_singleton()->offset) {
+ r_ret = get_offset();
+ } else if (p_name == SceneStringNames::get_singleton()->unit_offset) {
+ r_ret = get_unit_offset();
+ } else if (p_name == SceneStringNames::get_singleton()->rotate) {
+ r_ret = is_rotating();
+ } else if (p_name == SceneStringNames::get_singleton()->v_offset) {
+ r_ret = get_v_offset();
+ } else if (p_name == SceneStringNames::get_singleton()->h_offset) {
+ r_ret = get_h_offset();
+ } else if (String(p_name) == "cubic_interp") {
+ r_ret = cubic;
+ } else if (String(p_name) == "loop") {
+ r_ret = loop;
+ } else if (String(p_name) == "lookahead") {
+ r_ret = lookahead;
} else
return false;
return true;
-
}
-void PathFollow2D::_get_property_list( List<PropertyInfo> *p_list) const{
+void PathFollow2D::_get_property_list(List<PropertyInfo> *p_list) const {
- float max=10000;
+ float max = 10000;
if (path && path->get_curve().is_valid())
- max=path->get_curve()->get_baked_length();
- p_list->push_back( PropertyInfo( Variant::REAL, "offset", PROPERTY_HINT_RANGE,"0,"+rtos(max)+",0.01"));
- p_list->push_back( PropertyInfo( Variant::REAL, "unit_offset", PROPERTY_HINT_RANGE,"0,1,0.0001",PROPERTY_USAGE_EDITOR));
- p_list->push_back( PropertyInfo( Variant::REAL, "h_offset") );
- p_list->push_back( PropertyInfo( Variant::REAL, "v_offset") );
- p_list->push_back( PropertyInfo( Variant::BOOL, "rotate") );
- p_list->push_back( PropertyInfo( Variant::BOOL, "cubic_interp"));
- p_list->push_back( PropertyInfo( Variant::BOOL, "loop"));
- p_list->push_back( PropertyInfo( Variant::REAL, "lookahead",PROPERTY_HINT_RANGE,"0.001,1024.0,0.001"));
+ max = path->get_curve()->get_baked_length();
+ p_list->push_back(PropertyInfo(Variant::REAL, "offset", PROPERTY_HINT_RANGE, "0," + rtos(max) + ",0.01"));
+ p_list->push_back(PropertyInfo(Variant::REAL, "unit_offset", PROPERTY_HINT_RANGE, "0,1,0.0001", PROPERTY_USAGE_EDITOR));
+ p_list->push_back(PropertyInfo(Variant::REAL, "h_offset"));
+ p_list->push_back(PropertyInfo(Variant::REAL, "v_offset"));
+ p_list->push_back(PropertyInfo(Variant::BOOL, "rotate"));
+ p_list->push_back(PropertyInfo(Variant::BOOL, "cubic_interp"));
+ p_list->push_back(PropertyInfo(Variant::BOOL, "loop"));
+ p_list->push_back(PropertyInfo(Variant::REAL, "lookahead", PROPERTY_HINT_RANGE, "0.001,1024.0,0.001"));
}
-
String PathFollow2D::get_configuration_warning() const {
if (!is_visible_in_tree() || !is_inside_tree())
@@ -247,51 +233,46 @@ String PathFollow2D::get_configuration_warning() const {
}
return String();
-
}
void PathFollow2D::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_offset","offset"),&PathFollow2D::set_offset);
- ClassDB::bind_method(D_METHOD("get_offset"),&PathFollow2D::get_offset);
+ ClassDB::bind_method(D_METHOD("set_offset", "offset"), &PathFollow2D::set_offset);
+ ClassDB::bind_method(D_METHOD("get_offset"), &PathFollow2D::get_offset);
- ClassDB::bind_method(D_METHOD("set_h_offset","h_offset"),&PathFollow2D::set_h_offset);
- ClassDB::bind_method(D_METHOD("get_h_offset"),&PathFollow2D::get_h_offset);
+ ClassDB::bind_method(D_METHOD("set_h_offset", "h_offset"), &PathFollow2D::set_h_offset);
+ ClassDB::bind_method(D_METHOD("get_h_offset"), &PathFollow2D::get_h_offset);
- ClassDB::bind_method(D_METHOD("set_v_offset","v_offset"),&PathFollow2D::set_v_offset);
- ClassDB::bind_method(D_METHOD("get_v_offset"),&PathFollow2D::get_v_offset);
+ ClassDB::bind_method(D_METHOD("set_v_offset", "v_offset"), &PathFollow2D::set_v_offset);
+ ClassDB::bind_method(D_METHOD("get_v_offset"), &PathFollow2D::get_v_offset);
- ClassDB::bind_method(D_METHOD("set_unit_offset","unit_offset"),&PathFollow2D::set_unit_offset);
- ClassDB::bind_method(D_METHOD("get_unit_offset"),&PathFollow2D::get_unit_offset);
+ ClassDB::bind_method(D_METHOD("set_unit_offset", "unit_offset"), &PathFollow2D::set_unit_offset);
+ ClassDB::bind_method(D_METHOD("get_unit_offset"), &PathFollow2D::get_unit_offset);
- ClassDB::bind_method(D_METHOD("set_rotate","enable"),&PathFollow2D::set_rotate);
- ClassDB::bind_method(D_METHOD("is_rotating"),&PathFollow2D::is_rotating);
-
- ClassDB::bind_method(D_METHOD("set_cubic_interpolation","enable"),&PathFollow2D::set_cubic_interpolation);
- ClassDB::bind_method(D_METHOD("get_cubic_interpolation"),&PathFollow2D::get_cubic_interpolation);
-
- ClassDB::bind_method(D_METHOD("set_loop","loop"),&PathFollow2D::set_loop);
- ClassDB::bind_method(D_METHOD("has_loop"),&PathFollow2D::has_loop);
+ ClassDB::bind_method(D_METHOD("set_rotate", "enable"), &PathFollow2D::set_rotate);
+ ClassDB::bind_method(D_METHOD("is_rotating"), &PathFollow2D::is_rotating);
+ ClassDB::bind_method(D_METHOD("set_cubic_interpolation", "enable"), &PathFollow2D::set_cubic_interpolation);
+ ClassDB::bind_method(D_METHOD("get_cubic_interpolation"), &PathFollow2D::get_cubic_interpolation);
+ ClassDB::bind_method(D_METHOD("set_loop", "loop"), &PathFollow2D::set_loop);
+ ClassDB::bind_method(D_METHOD("has_loop"), &PathFollow2D::has_loop);
}
void PathFollow2D::set_offset(float p_offset) {
- offset=p_offset;
+ offset = p_offset;
if (path)
_update_transform();
_change_notify("offset");
_change_notify("unit_offset");
-
}
void PathFollow2D::set_h_offset(float p_h_offset) {
- h_offset=p_h_offset;
+ h_offset = p_h_offset;
if (path)
_update_transform();
-
}
float PathFollow2D::get_h_offset() const {
@@ -301,10 +282,9 @@ float PathFollow2D::get_h_offset() const {
void PathFollow2D::set_v_offset(float p_v_offset) {
- v_offset=p_v_offset;
+ v_offset = p_v_offset;
if (path)
_update_transform();
-
}
float PathFollow2D::get_v_offset() const {
@@ -312,8 +292,7 @@ float PathFollow2D::get_v_offset() const {
return v_offset;
}
-
-float PathFollow2D::get_offset() const{
+float PathFollow2D::get_offset() const {
return offset;
}
@@ -321,32 +300,30 @@ float PathFollow2D::get_offset() const{
void PathFollow2D::set_unit_offset(float p_unit_offset) {
if (path && path->get_curve().is_valid() && path->get_curve()->get_baked_length())
- set_offset(p_unit_offset*path->get_curve()->get_baked_length());
-
+ set_offset(p_unit_offset * path->get_curve()->get_baked_length());
}
-float PathFollow2D::get_unit_offset() const{
+float PathFollow2D::get_unit_offset() const {
if (path && path->get_curve().is_valid() && path->get_curve()->get_baked_length())
- return get_offset()/path->get_curve()->get_baked_length();
+ return get_offset() / path->get_curve()->get_baked_length();
else
return 0;
}
void PathFollow2D::set_lookahead(float p_lookahead) {
- lookahead=p_lookahead;
-
+ lookahead = p_lookahead;
}
-float PathFollow2D::get_lookahead() const{
+float PathFollow2D::get_lookahead() const {
return lookahead;
}
void PathFollow2D::set_rotate(bool p_rotate) {
- rotate=p_rotate;
+ rotate = p_rotate;
_update_transform();
}
@@ -357,23 +334,22 @@ bool PathFollow2D::is_rotating() const {
void PathFollow2D::set_loop(bool p_loop) {
- loop=p_loop;
+ loop = p_loop;
}
-bool PathFollow2D::has_loop() const{
+bool PathFollow2D::has_loop() const {
return loop;
}
-
PathFollow2D::PathFollow2D() {
- offset=0;
- h_offset=0;
- v_offset=0;
- path=NULL;
- rotate=true;
- cubic=true;
- loop=true;
- lookahead=4;
+ offset = 0;
+ h_offset = 0;
+ v_offset = 0;
+ path = NULL;
+ rotate = true;
+ cubic = true;
+ loop = true;
+ lookahead = 4;
}
diff --git a/scene/2d/path_2d.h b/scene/2d/path_2d.h
index 4fc26dbf9b..7357b6810e 100644
--- a/scene/2d/path_2d.h
+++ b/scene/2d/path_2d.h
@@ -29,39 +29,33 @@
#ifndef PATH_2D_H
#define PATH_2D_H
-#include "scene/resources/curve.h"
#include "scene/2d/node_2d.h"
+#include "scene/resources/curve.h"
class Path2D : public Node2D {
- GDCLASS( Path2D, Node2D );
+ GDCLASS(Path2D, Node2D);
Ref<Curve2D> curve;
void _curve_changed();
-
protected:
-
void _notification(int p_what);
static void _bind_methods();
-public:
- void set_curve(const Ref<Curve2D>& p_curve);
+public:
+ void set_curve(const Ref<Curve2D> &p_curve);
Ref<Curve2D> get_curve() const;
-
Path2D();
};
-
-
class PathFollow2D : public Node2D {
- GDCLASS(PathFollow2D,Node2D);
-public:
-
+ GDCLASS(PathFollow2D, Node2D);
+public:
private:
Path2D *path;
real_t offset;
@@ -74,17 +68,15 @@ private:
void _update_transform();
-
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;
void _notification(int p_what);
static void _bind_methods();
-public:
+public:
void set_offset(float p_offset);
float get_offset() const;
@@ -114,5 +106,4 @@ public:
PathFollow2D();
};
-
#endif // PATH_2D_H
diff --git a/scene/2d/path_texture.cpp b/scene/2d/path_texture.cpp
index 626928a244..60efccec3d 100644
--- a/scene/2d/path_texture.cpp
+++ b/scene/2d/path_texture.cpp
@@ -28,65 +28,61 @@
/*************************************************************************/
#include "path_texture.h"
+void PathTexture::set_begin_texture(const Ref<Texture> &p_texture) {
-void PathTexture::set_begin_texture(const Ref<Texture>& p_texture) {
-
- begin=p_texture;
+ begin = p_texture;
update();
}
-Ref<Texture> PathTexture::get_begin_texture() const{
+Ref<Texture> PathTexture::get_begin_texture() const {
return begin;
}
-void PathTexture::set_repeat_texture(const Ref<Texture>& p_texture){
+void PathTexture::set_repeat_texture(const Ref<Texture> &p_texture) {
- repeat=p_texture;
+ repeat = p_texture;
update();
-
}
-Ref<Texture> PathTexture::get_repeat_texture() const{
+Ref<Texture> PathTexture::get_repeat_texture() const {
return repeat;
}
-void PathTexture::set_end_texture(const Ref<Texture>& p_texture){
+void PathTexture::set_end_texture(const Ref<Texture> &p_texture) {
- end=p_texture;
+ end = p_texture;
update();
}
-Ref<Texture> PathTexture::get_end_texture() const{
+Ref<Texture> PathTexture::get_end_texture() const {
return end;
}
-void PathTexture::set_subdivisions(int p_amount){
+void PathTexture::set_subdivisions(int p_amount) {
- ERR_FAIL_INDEX(p_amount,32);
- subdivs=p_amount;
+ ERR_FAIL_INDEX(p_amount, 32);
+ subdivs = p_amount;
update();
-
}
-int PathTexture::get_subdivisions() const{
+int PathTexture::get_subdivisions() const {
return subdivs;
}
-void PathTexture::set_overlap(int p_amount){
+void PathTexture::set_overlap(int p_amount) {
- overlap=p_amount;
+ overlap = p_amount;
update();
}
-int PathTexture::get_overlap() const{
+int PathTexture::get_overlap() const {
return overlap;
}
-
PathTexture::PathTexture() {
- overlap=0;
- subdivs=1;
+ overlap = 0;
+ subdivs = 1;
}
diff --git a/scene/2d/path_texture.h b/scene/2d/path_texture.h
index cc502a2fa4..8d5adc49c8 100644
--- a/scene/2d/path_texture.h
+++ b/scene/2d/path_texture.h
@@ -32,22 +32,22 @@
#include "scene/2d/node_2d.h"
class PathTexture : public Node2D {
- GDCLASS( PathTexture, Node2D );
+ GDCLASS(PathTexture, Node2D);
Ref<Texture> begin;
Ref<Texture> repeat;
Ref<Texture> end;
int subdivs;
bool overlap;
-public:
- void set_begin_texture(const Ref<Texture>& p_texture);
+public:
+ void set_begin_texture(const Ref<Texture> &p_texture);
Ref<Texture> get_begin_texture() const;
- void set_repeat_texture(const Ref<Texture>& p_texture);
+ void set_repeat_texture(const Ref<Texture> &p_texture);
Ref<Texture> get_repeat_texture() const;
- void set_end_texture(const Ref<Texture>& p_texture);
+ void set_end_texture(const Ref<Texture> &p_texture);
Ref<Texture> get_end_texture() const;
void set_subdivisions(int p_amount);
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index 0ffaf81e3d..88845a7290 100644
--- a/scene/2d/physics_body_2d.cpp
+++ b/scene/2d/physics_body_2d.cpp
@@ -31,7 +31,7 @@
void PhysicsBody2D::_notification(int p_what) {
-/*
+ /*
switch(p_what) {
case NOTIFICATION_TRANSFORM_CHANGED: {
@@ -43,78 +43,74 @@ void PhysicsBody2D::_notification(int p_what) {
*/
}
-void PhysicsBody2D::set_one_way_collision_direction(const Vector2& p_dir) {
+void PhysicsBody2D::set_one_way_collision_direction(const Vector2 &p_dir) {
- one_way_collision_direction=p_dir;
- Physics2DServer::get_singleton()->body_set_one_way_collision_direction(get_rid(),p_dir);
+ one_way_collision_direction = p_dir;
+ Physics2DServer::get_singleton()->body_set_one_way_collision_direction(get_rid(), p_dir);
}
-Vector2 PhysicsBody2D::get_one_way_collision_direction() const{
+Vector2 PhysicsBody2D::get_one_way_collision_direction() const {
return one_way_collision_direction;
}
-
void PhysicsBody2D::set_one_way_collision_max_depth(float p_depth) {
- one_way_collision_max_depth=p_depth;
- Physics2DServer::get_singleton()->body_set_one_way_collision_max_depth(get_rid(),p_depth);
-
+ one_way_collision_max_depth = p_depth;
+ Physics2DServer::get_singleton()->body_set_one_way_collision_max_depth(get_rid(), p_depth);
}
-float PhysicsBody2D::get_one_way_collision_max_depth() const{
+float PhysicsBody2D::get_one_way_collision_max_depth() const {
return one_way_collision_max_depth;
}
-
void PhysicsBody2D::_set_layers(uint32_t p_mask) {
set_collision_layer(p_mask);
set_collision_mask(p_mask);
}
-uint32_t PhysicsBody2D::_get_layers() const{
+uint32_t PhysicsBody2D::_get_layers() const {
return get_collision_layer();
}
void PhysicsBody2D::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_collision_layer","mask"),&PhysicsBody2D::set_collision_layer);
- ClassDB::bind_method(D_METHOD("get_collision_layer"),&PhysicsBody2D::get_collision_layer);
- ClassDB::bind_method(D_METHOD("set_collision_mask","mask"),&PhysicsBody2D::set_collision_mask);
- ClassDB::bind_method(D_METHOD("get_collision_mask"),&PhysicsBody2D::get_collision_mask);
+ ClassDB::bind_method(D_METHOD("set_collision_layer", "mask"), &PhysicsBody2D::set_collision_layer);
+ ClassDB::bind_method(D_METHOD("get_collision_layer"), &PhysicsBody2D::get_collision_layer);
+ ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &PhysicsBody2D::set_collision_mask);
+ ClassDB::bind_method(D_METHOD("get_collision_mask"), &PhysicsBody2D::get_collision_mask);
+ ClassDB::bind_method(D_METHOD("set_collision_mask_bit", "bit", "value"), &PhysicsBody2D::set_collision_mask_bit);
+ ClassDB::bind_method(D_METHOD("get_collision_mask_bit", "bit"), &PhysicsBody2D::get_collision_mask_bit);
- ClassDB::bind_method(D_METHOD("set_collision_mask_bit","bit","value"),&PhysicsBody2D::set_collision_mask_bit);
- ClassDB::bind_method(D_METHOD("get_collision_mask_bit","bit"),&PhysicsBody2D::get_collision_mask_bit);
+ ClassDB::bind_method(D_METHOD("set_collision_layer_bit", "bit", "value"), &PhysicsBody2D::set_collision_layer_bit);
+ ClassDB::bind_method(D_METHOD("get_collision_layer_bit", "bit"), &PhysicsBody2D::get_collision_layer_bit);
- ClassDB::bind_method(D_METHOD("set_collision_layer_bit","bit","value"),&PhysicsBody2D::set_collision_layer_bit);
- ClassDB::bind_method(D_METHOD("get_collision_layer_bit","bit"),&PhysicsBody2D::get_collision_layer_bit);
+ ClassDB::bind_method(D_METHOD("_set_layers", "mask"), &PhysicsBody2D::_set_layers);
+ ClassDB::bind_method(D_METHOD("_get_layers"), &PhysicsBody2D::_get_layers);
+ ClassDB::bind_method(D_METHOD("set_one_way_collision_direction", "dir"), &PhysicsBody2D::set_one_way_collision_direction);
+ ClassDB::bind_method(D_METHOD("get_one_way_collision_direction"), &PhysicsBody2D::get_one_way_collision_direction);
+ ClassDB::bind_method(D_METHOD("set_one_way_collision_max_depth", "depth"), &PhysicsBody2D::set_one_way_collision_max_depth);
+ ClassDB::bind_method(D_METHOD("get_one_way_collision_max_depth"), &PhysicsBody2D::get_one_way_collision_max_depth);
+ ClassDB::bind_method(D_METHOD("add_collision_exception_with", "body:PhysicsBody2D"), &PhysicsBody2D::add_collision_exception_with);
+ ClassDB::bind_method(D_METHOD("remove_collision_exception_with", "body:PhysicsBody2D"), &PhysicsBody2D::remove_collision_exception_with);
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "layers", PROPERTY_HINT_LAYERS_2D_PHYSICS, "", 0), "_set_layers", "_get_layers"); //for backwards compat
- ClassDB::bind_method(D_METHOD("_set_layers","mask"),&PhysicsBody2D::_set_layers);
- ClassDB::bind_method(D_METHOD("_get_layers"),&PhysicsBody2D::_get_layers);
- ClassDB::bind_method(D_METHOD("set_one_way_collision_direction","dir"),&PhysicsBody2D::set_one_way_collision_direction);
- ClassDB::bind_method(D_METHOD("get_one_way_collision_direction"),&PhysicsBody2D::get_one_way_collision_direction);
- ClassDB::bind_method(D_METHOD("set_one_way_collision_max_depth","depth"),&PhysicsBody2D::set_one_way_collision_max_depth);
- ClassDB::bind_method(D_METHOD("get_one_way_collision_max_depth"),&PhysicsBody2D::get_one_way_collision_max_depth);
- ClassDB::bind_method(D_METHOD("add_collision_exception_with","body:PhysicsBody2D"),&PhysicsBody2D::add_collision_exception_with);
- ClassDB::bind_method(D_METHOD("remove_collision_exception_with","body:PhysicsBody2D"),&PhysicsBody2D::remove_collision_exception_with);
- ADD_PROPERTY(PropertyInfo(Variant::INT,"layers",PROPERTY_HINT_LAYERS_2D_PHYSICS,"",0),"_set_layers","_get_layers"); //for backwards compat
-
- ADD_GROUP("Collision","collision_");
- ADD_PROPERTY(PropertyInfo(Variant::INT,"collision_layer",PROPERTY_HINT_LAYERS_2D_PHYSICS),"set_collision_layer","get_collision_layer");
- ADD_PROPERTY(PropertyInfo(Variant::INT,"collision_mask",PROPERTY_HINT_LAYERS_2D_PHYSICS),"set_collision_mask","get_collision_mask");
- ADD_GROUP("","");
- ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2,"one_way_collision/direction"),"set_one_way_collision_direction","get_one_way_collision_direction");
- ADD_PROPERTYNZ(PropertyInfo(Variant::REAL,"one_way_collision/max_depth"),"set_one_way_collision_max_depth","get_one_way_collision_max_depth");
+ ADD_GROUP("Collision", "collision_");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_layer", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_collision_layer", "get_collision_layer");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_collision_mask", "get_collision_mask");
+ ADD_GROUP("", "");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "one_way_collision/direction"), "set_one_way_collision_direction", "get_one_way_collision_direction");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "one_way_collision/max_depth"), "set_one_way_collision_max_depth", "get_one_way_collision_max_depth");
}
void PhysicsBody2D::set_collision_layer(uint32_t p_mask) {
- mask=p_mask;
- Physics2DServer::get_singleton()->body_set_layer_mask(get_rid(),p_mask);
+ mask = p_mask;
+ Physics2DServer::get_singleton()->body_set_layer_mask(get_rid(), p_mask);
}
uint32_t PhysicsBody2D::get_collision_layer() const {
@@ -124,8 +120,8 @@ uint32_t PhysicsBody2D::get_collision_layer() const {
void PhysicsBody2D::set_collision_mask(uint32_t p_mask) {
- collision_mask=p_mask;
- Physics2DServer::get_singleton()->body_set_collision_mask(get_rid(),p_mask);
+ collision_mask = p_mask;
+ Physics2DServer::get_singleton()->body_set_collision_mask(get_rid(), p_mask);
}
uint32_t PhysicsBody2D::get_collision_mask() const {
@@ -137,44 +133,41 @@ void PhysicsBody2D::set_collision_mask_bit(int p_bit, bool p_value) {
uint32_t mask = get_collision_mask();
if (p_value)
- mask|=1<<p_bit;
+ mask |= 1 << p_bit;
else
- mask&=~(1<<p_bit);
+ mask &= ~(1 << p_bit);
set_collision_mask(mask);
-
}
-bool PhysicsBody2D::get_collision_mask_bit(int p_bit) const{
+bool PhysicsBody2D::get_collision_mask_bit(int p_bit) const {
- return get_collision_mask()&(1<<p_bit);
+ return get_collision_mask() & (1 << p_bit);
}
-
void PhysicsBody2D::set_collision_layer_bit(int p_bit, bool p_value) {
uint32_t mask = get_collision_layer();
if (p_value)
- mask|=1<<p_bit;
+ mask |= 1 << p_bit;
else
- mask&=~(1<<p_bit);
+ mask &= ~(1 << p_bit);
set_collision_layer(mask);
-
}
-bool PhysicsBody2D::get_collision_layer_bit(int p_bit) const{
+bool PhysicsBody2D::get_collision_layer_bit(int p_bit) const {
- return get_collision_layer()&(1<<p_bit);
+ return get_collision_layer() & (1 << p_bit);
}
-PhysicsBody2D::PhysicsBody2D(Physics2DServer::BodyMode p_mode) : CollisionObject2D( Physics2DServer::get_singleton()->body_create(p_mode), false) {
+PhysicsBody2D::PhysicsBody2D(Physics2DServer::BodyMode p_mode)
+ : CollisionObject2D(Physics2DServer::get_singleton()->body_create(p_mode), false) {
- mask=1;
- collision_mask=1;
+ mask = 1;
+ collision_mask = 1;
set_one_way_collision_max_depth(0);
set_pickable(false);
-
}
-void PhysicsBody2D::add_collision_exception_with(Node* p_node) {
+void PhysicsBody2D::add_collision_exception_with(Node *p_node) {
ERR_FAIL_NULL(p_node);
PhysicsBody2D *physics_body = p_node->cast_to<PhysicsBody2D>();
@@ -182,11 +175,10 @@ void PhysicsBody2D::add_collision_exception_with(Node* p_node) {
ERR_EXPLAIN("Collision exception only works between two objects of PhysicsBody type");
}
ERR_FAIL_COND(!physics_body);
- Physics2DServer::get_singleton()->body_add_collision_exception(get_rid(),physics_body->get_rid());
-
+ Physics2DServer::get_singleton()->body_add_collision_exception(get_rid(), physics_body->get_rid());
}
-void PhysicsBody2D::remove_collision_exception_with(Node* p_node) {
+void PhysicsBody2D::remove_collision_exception_with(Node *p_node) {
ERR_FAIL_NULL(p_node);
PhysicsBody2D *physics_body = p_node->cast_to<PhysicsBody2D>();
@@ -194,20 +186,19 @@ void PhysicsBody2D::remove_collision_exception_with(Node* p_node) {
ERR_EXPLAIN("Collision exception only works between two objects of PhysicsBody type");
}
ERR_FAIL_COND(!physics_body);
- Physics2DServer::get_singleton()->body_remove_collision_exception(get_rid(),physics_body->get_rid());
+ Physics2DServer::get_singleton()->body_remove_collision_exception(get_rid(), physics_body->get_rid());
}
-void StaticBody2D::set_constant_linear_velocity(const Vector2& p_vel) {
-
- constant_linear_velocity=p_vel;
- Physics2DServer::get_singleton()->body_set_state(get_rid(),Physics2DServer::BODY_STATE_LINEAR_VELOCITY,constant_linear_velocity);
+void StaticBody2D::set_constant_linear_velocity(const Vector2 &p_vel) {
+ constant_linear_velocity = p_vel;
+ Physics2DServer::get_singleton()->body_set_state(get_rid(), Physics2DServer::BODY_STATE_LINEAR_VELOCITY, constant_linear_velocity);
}
void StaticBody2D::set_constant_angular_velocity(real_t p_vel) {
- constant_angular_velocity=p_vel;
- Physics2DServer::get_singleton()->body_set_state(get_rid(),Physics2DServer::BODY_STATE_ANGULAR_VELOCITY,constant_angular_velocity);
+ constant_angular_velocity = p_vel;
+ Physics2DServer::get_singleton()->body_set_state(get_rid(), Physics2DServer::BODY_STATE_ANGULAR_VELOCITY, constant_angular_velocity);
}
Vector2 StaticBody2D::get_constant_linear_velocity() const {
@@ -242,91 +233,80 @@ void StaticBody2D::_update_xform() {
}
#endif
+void StaticBody2D::set_friction(real_t p_friction) {
-void StaticBody2D::set_friction(real_t p_friction){
-
- ERR_FAIL_COND(p_friction<0 || p_friction>1);
-
- friction=p_friction;
- Physics2DServer::get_singleton()->body_set_param(get_rid(),Physics2DServer::BODY_PARAM_FRICTION,friction);
+ ERR_FAIL_COND(p_friction < 0 || p_friction > 1);
+ friction = p_friction;
+ Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_FRICTION, friction);
}
-real_t StaticBody2D::get_friction() const{
+real_t StaticBody2D::get_friction() const {
return friction;
}
-void StaticBody2D::set_bounce(real_t p_bounce){
+void StaticBody2D::set_bounce(real_t p_bounce) {
- ERR_FAIL_COND(p_bounce<0 || p_bounce>1);
-
- bounce=p_bounce;
- Physics2DServer::get_singleton()->body_set_param(get_rid(),Physics2DServer::BODY_PARAM_BOUNCE,bounce);
+ ERR_FAIL_COND(p_bounce < 0 || p_bounce > 1);
+ bounce = p_bounce;
+ Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_BOUNCE, bounce);
}
-real_t StaticBody2D::get_bounce() const{
+real_t StaticBody2D::get_bounce() const {
return bounce;
}
void StaticBody2D::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_constant_linear_velocity","vel"),&StaticBody2D::set_constant_linear_velocity);
- ClassDB::bind_method(D_METHOD("set_constant_angular_velocity","vel"),&StaticBody2D::set_constant_angular_velocity);
- ClassDB::bind_method(D_METHOD("get_constant_linear_velocity"),&StaticBody2D::get_constant_linear_velocity);
- ClassDB::bind_method(D_METHOD("get_constant_angular_velocity"),&StaticBody2D::get_constant_angular_velocity);
- ClassDB::bind_method(D_METHOD("set_friction","friction"),&StaticBody2D::set_friction);
- ClassDB::bind_method(D_METHOD("get_friction"),&StaticBody2D::get_friction);
+ ClassDB::bind_method(D_METHOD("set_constant_linear_velocity", "vel"), &StaticBody2D::set_constant_linear_velocity);
+ ClassDB::bind_method(D_METHOD("set_constant_angular_velocity", "vel"), &StaticBody2D::set_constant_angular_velocity);
+ ClassDB::bind_method(D_METHOD("get_constant_linear_velocity"), &StaticBody2D::get_constant_linear_velocity);
+ ClassDB::bind_method(D_METHOD("get_constant_angular_velocity"), &StaticBody2D::get_constant_angular_velocity);
+ ClassDB::bind_method(D_METHOD("set_friction", "friction"), &StaticBody2D::set_friction);
+ ClassDB::bind_method(D_METHOD("get_friction"), &StaticBody2D::get_friction);
- ClassDB::bind_method(D_METHOD("set_bounce","bounce"),&StaticBody2D::set_bounce);
- ClassDB::bind_method(D_METHOD("get_bounce"),&StaticBody2D::get_bounce);
+ ClassDB::bind_method(D_METHOD("set_bounce", "bounce"), &StaticBody2D::set_bounce);
+ ClassDB::bind_method(D_METHOD("get_bounce"), &StaticBody2D::get_bounce);
- ADD_PROPERTY(PropertyInfo(Variant::VECTOR2,"constant_linear_velocity"),"set_constant_linear_velocity","get_constant_linear_velocity");
- ADD_PROPERTY(PropertyInfo(Variant::REAL,"constant_angular_velocity"),"set_constant_angular_velocity","get_constant_angular_velocity");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"friction",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_friction","get_friction");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"bounce",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_bounce","get_bounce");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "constant_linear_velocity"), "set_constant_linear_velocity", "get_constant_linear_velocity");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "constant_angular_velocity"), "set_constant_angular_velocity", "get_constant_angular_velocity");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "friction", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_friction", "get_friction");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "bounce", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_bounce", "get_bounce");
}
-StaticBody2D::StaticBody2D() : PhysicsBody2D(Physics2DServer::BODY_MODE_STATIC) {
-
- constant_angular_velocity=0;
- bounce=0;
- friction=1;
-
+StaticBody2D::StaticBody2D()
+ : PhysicsBody2D(Physics2DServer::BODY_MODE_STATIC) {
+ constant_angular_velocity = 0;
+ bounce = 0;
+ friction = 1;
}
StaticBody2D::~StaticBody2D() {
-
}
-
-
-
void RigidBody2D::_body_enter_tree(ObjectID p_id) {
Object *obj = ObjectDB::get_instance(p_id);
Node *node = obj ? obj->cast_to<Node>() : NULL;
ERR_FAIL_COND(!node);
- Map<ObjectID,BodyState>::Element *E=contact_monitor->body_map.find(p_id);
+ Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.find(p_id);
ERR_FAIL_COND(!E);
ERR_FAIL_COND(E->get().in_scene);
- contact_monitor->locked=true;
-
- E->get().in_scene=true;
- emit_signal(SceneStringNames::get_singleton()->body_entered,node);
+ contact_monitor->locked = true;
+ E->get().in_scene = true;
+ emit_signal(SceneStringNames::get_singleton()->body_entered, node);
- for(int i=0;i<E->get().shapes.size();i++) {
+ for (int i = 0; i < E->get().shapes.size(); i++) {
- emit_signal(SceneStringNames::get_singleton()->body_shape_entered,p_id,node,E->get().shapes[i].body_shape,E->get().shapes[i].local_shape);
+ emit_signal(SceneStringNames::get_singleton()->body_shape_entered, p_id, node, E->get().shapes[i].body_shape, E->get().shapes[i].local_shape);
}
- contact_monitor->locked=false;
-
-
+ contact_monitor->locked = false;
}
void RigidBody2D::_body_exit_tree(ObjectID p_id) {
@@ -334,33 +314,32 @@ void RigidBody2D::_body_exit_tree(ObjectID p_id) {
Object *obj = ObjectDB::get_instance(p_id);
Node *node = obj ? obj->cast_to<Node>() : NULL;
ERR_FAIL_COND(!node);
- Map<ObjectID,BodyState>::Element *E=contact_monitor->body_map.find(p_id);
+ Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.find(p_id);
ERR_FAIL_COND(!E);
ERR_FAIL_COND(!E->get().in_scene);
- E->get().in_scene=false;
+ E->get().in_scene = false;
- contact_monitor->locked=true;
+ contact_monitor->locked = true;
- emit_signal(SceneStringNames::get_singleton()->body_exited,node);
+ emit_signal(SceneStringNames::get_singleton()->body_exited, node);
- for(int i=0;i<E->get().shapes.size();i++) {
+ for (int i = 0; i < E->get().shapes.size(); i++) {
- emit_signal(SceneStringNames::get_singleton()->body_shape_exited,p_id,node,E->get().shapes[i].body_shape,E->get().shapes[i].local_shape);
+ emit_signal(SceneStringNames::get_singleton()->body_shape_exited, p_id, node, E->get().shapes[i].body_shape, E->get().shapes[i].local_shape);
}
- contact_monitor->locked=false;
-
+ contact_monitor->locked = false;
}
-void RigidBody2D::_body_inout(int p_status, ObjectID p_instance, int p_body_shape,int p_local_shape) {
+void RigidBody2D::_body_inout(int p_status, ObjectID p_instance, int p_body_shape, int p_local_shape) {
- bool body_in = p_status==1;
- ObjectID objid=p_instance;
+ bool body_in = p_status == 1;
+ ObjectID objid = p_instance;
Object *obj = ObjectDB::get_instance(objid);
Node *node = obj ? obj->cast_to<Node>() : NULL;
- Map<ObjectID,BodyState>::Element *E=contact_monitor->body_map.find(objid);
+ Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.find(objid);
/*if (obj) {
if (body_in)
@@ -374,14 +353,14 @@ void RigidBody2D::_body_inout(int p_status, ObjectID p_instance, int p_body_shap
if (body_in) {
if (!E) {
- E = contact_monitor->body_map.insert(objid,BodyState());
+ E = contact_monitor->body_map.insert(objid, BodyState());
//E->get().rc=0;
- E->get().in_scene=node && node->is_inside_tree();
+ E->get().in_scene = node && node->is_inside_tree();
if (node) {
- node->connect(SceneStringNames::get_singleton()->tree_entered,this,SceneStringNames::get_singleton()->_body_enter_tree,make_binds(objid));
- node->connect(SceneStringNames::get_singleton()->tree_exited,this,SceneStringNames::get_singleton()->_body_exit_tree,make_binds(objid));
+ node->connect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_body_enter_tree, make_binds(objid));
+ node->connect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_body_exit_tree, make_binds(objid));
if (E->get().in_scene) {
- emit_signal(SceneStringNames::get_singleton()->body_entered,node);
+ emit_signal(SceneStringNames::get_singleton()->body_entered, node);
}
}
@@ -389,11 +368,10 @@ void RigidBody2D::_body_inout(int p_status, ObjectID p_instance, int p_body_shap
}
if (node)
- E->get().shapes.insert(ShapePair(p_body_shape,p_local_shape));
-
+ E->get().shapes.insert(ShapePair(p_body_shape, p_local_shape));
if (E->get().in_scene) {
- emit_signal(SceneStringNames::get_singleton()->body_shape_entered,objid,node,p_body_shape,p_local_shape);
+ emit_signal(SceneStringNames::get_singleton()->body_shape_entered, objid, node, p_body_shape, p_local_shape);
}
} else {
@@ -401,31 +379,27 @@ void RigidBody2D::_body_inout(int p_status, ObjectID p_instance, int p_body_shap
//E->get().rc--;
if (node)
- E->get().shapes.erase(ShapePair(p_body_shape,p_local_shape));
+ E->get().shapes.erase(ShapePair(p_body_shape, p_local_shape));
bool in_scene = E->get().in_scene;
if (E->get().shapes.empty()) {
if (node) {
- node->disconnect(SceneStringNames::get_singleton()->tree_entered,this,SceneStringNames::get_singleton()->_body_enter_tree);
- node->disconnect(SceneStringNames::get_singleton()->tree_exited,this,SceneStringNames::get_singleton()->_body_exit_tree);
+ node->disconnect(SceneStringNames::get_singleton()->tree_entered, this, SceneStringNames::get_singleton()->_body_enter_tree);
+ node->disconnect(SceneStringNames::get_singleton()->tree_exited, this, SceneStringNames::get_singleton()->_body_exit_tree);
if (in_scene)
- emit_signal(SceneStringNames::get_singleton()->body_exited,obj);
-
+ emit_signal(SceneStringNames::get_singleton()->body_exited, obj);
}
contact_monitor->body_map.erase(E);
}
if (node && in_scene) {
- emit_signal(SceneStringNames::get_singleton()->body_shape_exited,objid,obj,p_body_shape,p_local_shape);
+ emit_signal(SceneStringNames::get_singleton()->body_shape_exited, objid, obj, p_body_shape, p_local_shape);
}
-
}
-
}
-
struct _RigidBody2DInOut {
ObjectID id;
@@ -433,62 +407,60 @@ struct _RigidBody2DInOut {
int local_shape;
};
+bool RigidBody2D::_test_motion(const Vector2 &p_motion, float p_margin, const Ref<Physics2DTestMotionResult> &p_result) {
-bool RigidBody2D::_test_motion(const Vector2& p_motion,float p_margin,const Ref<Physics2DTestMotionResult>& p_result) {
-
- Physics2DServer::MotionResult *r=NULL;
+ Physics2DServer::MotionResult *r = NULL;
if (p_result.is_valid())
- r=p_result->get_result_ptr();
- return Physics2DServer::get_singleton()->body_test_motion(get_rid(),get_global_transform(),p_motion,p_margin,r);
-
+ r = p_result->get_result_ptr();
+ return Physics2DServer::get_singleton()->body_test_motion(get_rid(), get_global_transform(), p_motion, p_margin, r);
}
void RigidBody2D::_direct_state_changed(Object *p_state) {
- //eh.. fuck
+//eh.. fuck
#ifdef DEBUG_ENABLED
- state=p_state->cast_to<Physics2DDirectBodyState>();
+ state = p_state->cast_to<Physics2DDirectBodyState>();
#else
- state=(Physics2DDirectBodyState*)p_state; //trust it
+ state = (Physics2DDirectBodyState *)p_state; //trust it
#endif
set_block_transform_notify(true); // don't want notify (would feedback loop)
- if (mode!=MODE_KINEMATIC)
+ if (mode != MODE_KINEMATIC)
set_global_transform(state->get_transform());
- linear_velocity=state->get_linear_velocity();
- angular_velocity=state->get_angular_velocity();
- if(sleeping!=state->is_sleeping()) {
- sleeping=state->is_sleeping();
+ linear_velocity = state->get_linear_velocity();
+ angular_velocity = state->get_angular_velocity();
+ if (sleeping != state->is_sleeping()) {
+ sleeping = state->is_sleeping();
emit_signal(SceneStringNames::get_singleton()->sleeping_state_changed);
}
if (get_script_instance())
- get_script_instance()->call("_integrate_forces",state);
+ get_script_instance()->call("_integrate_forces", state);
set_block_transform_notify(false); // want it back
if (contact_monitor) {
- contact_monitor->locked=true;
+ contact_monitor->locked = true;
//untag all
- int rc=0;
- for( Map<ObjectID,BodyState>::Element *E=contact_monitor->body_map.front();E;E=E->next()) {
+ int rc = 0;
+ for (Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.front(); E; E = E->next()) {
- for(int i=0;i<E->get().shapes.size();i++) {
+ for (int i = 0; i < E->get().shapes.size(); i++) {
- E->get().shapes[i].tagged=false;
+ E->get().shapes[i].tagged = false;
rc++;
}
}
- _RigidBody2DInOut *toadd=(_RigidBody2DInOut*)alloca(state->get_contact_count()*sizeof(_RigidBody2DInOut));
- int toadd_count=0;//state->get_contact_count();
- RigidBody2D_RemoveAction *toremove=(RigidBody2D_RemoveAction*)alloca(rc*sizeof(RigidBody2D_RemoveAction));
- int toremove_count=0;
+ _RigidBody2DInOut *toadd = (_RigidBody2DInOut *)alloca(state->get_contact_count() * sizeof(_RigidBody2DInOut));
+ int toadd_count = 0; //state->get_contact_count();
+ RigidBody2D_RemoveAction *toremove = (RigidBody2D_RemoveAction *)alloca(rc * sizeof(RigidBody2D_RemoveAction));
+ int toremove_count = 0;
//put the ones to add
- for(int i=0;i<state->get_contact_count();i++) {
+ for (int i = 0; i < state->get_contact_count(); i++) {
ObjectID obj = state->get_contact_collider_id(i);
int local_shape = state->get_contact_local_shape(i);
@@ -496,270 +468,250 @@ void RigidBody2D::_direct_state_changed(Object *p_state) {
//bool found=false;
- Map<ObjectID,BodyState>::Element *E=contact_monitor->body_map.find(obj);
+ Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.find(obj);
if (!E) {
- toadd[toadd_count].local_shape=local_shape;
- toadd[toadd_count].id=obj;
- toadd[toadd_count].shape=shape;
+ toadd[toadd_count].local_shape = local_shape;
+ toadd[toadd_count].id = obj;
+ toadd[toadd_count].shape = shape;
toadd_count++;
continue;
}
- ShapePair sp( shape,local_shape );
+ ShapePair sp(shape, local_shape);
int idx = E->get().shapes.find(sp);
- if (idx==-1) {
+ if (idx == -1) {
- toadd[toadd_count].local_shape=local_shape;
- toadd[toadd_count].id=obj;
- toadd[toadd_count].shape=shape;
+ toadd[toadd_count].local_shape = local_shape;
+ toadd[toadd_count].id = obj;
+ toadd[toadd_count].shape = shape;
toadd_count++;
continue;
}
- E->get().shapes[idx].tagged=true;
+ E->get().shapes[idx].tagged = true;
}
//put the ones to remove
- for( Map<ObjectID,BodyState>::Element *E=contact_monitor->body_map.front();E;E=E->next()) {
+ for (Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.front(); E; E = E->next()) {
- for(int i=0;i<E->get().shapes.size();i++) {
+ for (int i = 0; i < E->get().shapes.size(); i++) {
if (!E->get().shapes[i].tagged) {
- toremove[toremove_count].body_id=E->key();
- toremove[toremove_count].pair=E->get().shapes[i];
+ toremove[toremove_count].body_id = E->key();
+ toremove[toremove_count].pair = E->get().shapes[i];
toremove_count++;
}
}
}
-
//process remotions
+ for (int i = 0; i < toremove_count; i++) {
- for(int i=0;i<toremove_count;i++) {
-
- _body_inout(0,toremove[i].body_id,toremove[i].pair.body_shape,toremove[i].pair.local_shape);
+ _body_inout(0, toremove[i].body_id, toremove[i].pair.body_shape, toremove[i].pair.local_shape);
}
//process aditions
+ for (int i = 0; i < toadd_count; i++) {
- for(int i=0;i<toadd_count;i++) {
-
- _body_inout(1,toadd[i].id,toadd[i].shape,toadd[i].local_shape);
+ _body_inout(1, toadd[i].id, toadd[i].shape, toadd[i].local_shape);
}
- contact_monitor->locked=false;
-
+ contact_monitor->locked = false;
}
-
-
- state=NULL;
+ state = NULL;
}
-
void RigidBody2D::set_mode(Mode p_mode) {
- mode=p_mode;
- switch(p_mode) {
+ mode = p_mode;
+ switch (p_mode) {
case MODE_RIGID: {
- Physics2DServer::get_singleton()->body_set_mode(get_rid(),Physics2DServer::BODY_MODE_RIGID);
+ Physics2DServer::get_singleton()->body_set_mode(get_rid(), Physics2DServer::BODY_MODE_RIGID);
} break;
case MODE_STATIC: {
- Physics2DServer::get_singleton()->body_set_mode(get_rid(),Physics2DServer::BODY_MODE_STATIC);
+ Physics2DServer::get_singleton()->body_set_mode(get_rid(), Physics2DServer::BODY_MODE_STATIC);
} break;
case MODE_KINEMATIC: {
- Physics2DServer::get_singleton()->body_set_mode(get_rid(),Physics2DServer::BODY_MODE_KINEMATIC);
+ Physics2DServer::get_singleton()->body_set_mode(get_rid(), Physics2DServer::BODY_MODE_KINEMATIC);
} break;
case MODE_CHARACTER: {
- Physics2DServer::get_singleton()->body_set_mode(get_rid(),Physics2DServer::BODY_MODE_CHARACTER);
+ Physics2DServer::get_singleton()->body_set_mode(get_rid(), Physics2DServer::BODY_MODE_CHARACTER);
} break;
-
}
}
-RigidBody2D::Mode RigidBody2D::get_mode() const{
+RigidBody2D::Mode RigidBody2D::get_mode() const {
return mode;
}
-void RigidBody2D::set_mass(real_t p_mass){
+void RigidBody2D::set_mass(real_t p_mass) {
- ERR_FAIL_COND(p_mass<=0);
- mass=p_mass;
+ ERR_FAIL_COND(p_mass <= 0);
+ mass = p_mass;
_change_notify("mass");
_change_notify("weight");
- Physics2DServer::get_singleton()->body_set_param(get_rid(),Physics2DServer::BODY_PARAM_MASS,mass);
-
+ Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_MASS, mass);
}
-real_t RigidBody2D::get_mass() const{
+real_t RigidBody2D::get_mass() const {
return mass;
}
void RigidBody2D::set_inertia(real_t p_inertia) {
- ERR_FAIL_COND(p_inertia<=0);
- Physics2DServer::get_singleton()->body_set_param(get_rid(),Physics2DServer::BODY_PARAM_INERTIA,p_inertia);
+ ERR_FAIL_COND(p_inertia <= 0);
+ Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_INERTIA, p_inertia);
}
-real_t RigidBody2D::get_inertia() const{
+real_t RigidBody2D::get_inertia() const {
- return Physics2DServer::get_singleton()->body_get_param(get_rid(),Physics2DServer::BODY_PARAM_INERTIA);
+ return Physics2DServer::get_singleton()->body_get_param(get_rid(), Physics2DServer::BODY_PARAM_INERTIA);
}
-void RigidBody2D::set_weight(real_t p_weight){
+void RigidBody2D::set_weight(real_t p_weight) {
- set_mass(p_weight/9.8);
+ set_mass(p_weight / 9.8);
}
-real_t RigidBody2D::get_weight() const{
+real_t RigidBody2D::get_weight() const {
- return mass*9.8;
+ return mass * 9.8;
}
+void RigidBody2D::set_friction(real_t p_friction) {
-void RigidBody2D::set_friction(real_t p_friction){
-
- ERR_FAIL_COND(p_friction<0 || p_friction>1);
-
- friction=p_friction;
- Physics2DServer::get_singleton()->body_set_param(get_rid(),Physics2DServer::BODY_PARAM_FRICTION,friction);
+ ERR_FAIL_COND(p_friction < 0 || p_friction > 1);
+ friction = p_friction;
+ Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_FRICTION, friction);
}
-real_t RigidBody2D::get_friction() const{
+real_t RigidBody2D::get_friction() const {
return friction;
}
-void RigidBody2D::set_bounce(real_t p_bounce){
+void RigidBody2D::set_bounce(real_t p_bounce) {
- ERR_FAIL_COND(p_bounce<0 || p_bounce>1);
-
- bounce=p_bounce;
- Physics2DServer::get_singleton()->body_set_param(get_rid(),Physics2DServer::BODY_PARAM_BOUNCE,bounce);
+ ERR_FAIL_COND(p_bounce < 0 || p_bounce > 1);
+ bounce = p_bounce;
+ Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_BOUNCE, bounce);
}
-real_t RigidBody2D::get_bounce() const{
+real_t RigidBody2D::get_bounce() const {
return bounce;
}
+void RigidBody2D::set_gravity_scale(real_t p_gravity_scale) {
-void RigidBody2D::set_gravity_scale(real_t p_gravity_scale){
-
- gravity_scale=p_gravity_scale;
- Physics2DServer::get_singleton()->body_set_param(get_rid(),Physics2DServer::BODY_PARAM_GRAVITY_SCALE,gravity_scale);
-
+ gravity_scale = p_gravity_scale;
+ Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_GRAVITY_SCALE, gravity_scale);
}
-real_t RigidBody2D::get_gravity_scale() const{
+real_t RigidBody2D::get_gravity_scale() const {
return gravity_scale;
}
-void RigidBody2D::set_linear_damp(real_t p_linear_damp){
-
- ERR_FAIL_COND(p_linear_damp<-1);
- linear_damp=p_linear_damp;
- Physics2DServer::get_singleton()->body_set_param(get_rid(),Physics2DServer::BODY_PARAM_LINEAR_DAMP,linear_damp);
+void RigidBody2D::set_linear_damp(real_t p_linear_damp) {
+ ERR_FAIL_COND(p_linear_damp < -1);
+ linear_damp = p_linear_damp;
+ Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_LINEAR_DAMP, linear_damp);
}
-real_t RigidBody2D::get_linear_damp() const{
+real_t RigidBody2D::get_linear_damp() const {
return linear_damp;
}
-void RigidBody2D::set_angular_damp(real_t p_angular_damp){
-
- ERR_FAIL_COND(p_angular_damp<-1);
- angular_damp=p_angular_damp;
- Physics2DServer::get_singleton()->body_set_param(get_rid(),Physics2DServer::BODY_PARAM_ANGULAR_DAMP,angular_damp);
+void RigidBody2D::set_angular_damp(real_t p_angular_damp) {
+ ERR_FAIL_COND(p_angular_damp < -1);
+ angular_damp = p_angular_damp;
+ Physics2DServer::get_singleton()->body_set_param(get_rid(), Physics2DServer::BODY_PARAM_ANGULAR_DAMP, angular_damp);
}
-real_t RigidBody2D::get_angular_damp() const{
+real_t RigidBody2D::get_angular_damp() const {
return angular_damp;
}
-void RigidBody2D::set_axis_velocity(const Vector2& p_axis) {
+void RigidBody2D::set_axis_velocity(const Vector2 &p_axis) {
- Vector2 v = state? state->get_linear_velocity() : linear_velocity;
+ Vector2 v = state ? state->get_linear_velocity() : linear_velocity;
Vector2 axis = p_axis.normalized();
- v-=axis*axis.dot(v);
- v+=p_axis;
+ v -= axis * axis.dot(v);
+ v += p_axis;
if (state) {
set_linear_velocity(v);
} else {
- Physics2DServer::get_singleton()->body_set_axis_velocity(get_rid(),p_axis);
- linear_velocity=v;
+ Physics2DServer::get_singleton()->body_set_axis_velocity(get_rid(), p_axis);
+ linear_velocity = v;
}
}
-void RigidBody2D::set_linear_velocity(const Vector2& p_velocity){
+void RigidBody2D::set_linear_velocity(const Vector2 &p_velocity) {
- linear_velocity=p_velocity;
+ linear_velocity = p_velocity;
if (state)
state->set_linear_velocity(linear_velocity);
else {
- Physics2DServer::get_singleton()->body_set_state(get_rid(),Physics2DServer::BODY_STATE_LINEAR_VELOCITY,linear_velocity);
+ Physics2DServer::get_singleton()->body_set_state(get_rid(), Physics2DServer::BODY_STATE_LINEAR_VELOCITY, linear_velocity);
}
-
}
-Vector2 RigidBody2D::get_linear_velocity() const{
+Vector2 RigidBody2D::get_linear_velocity() const {
return linear_velocity;
}
-void RigidBody2D::set_angular_velocity(real_t p_velocity){
+void RigidBody2D::set_angular_velocity(real_t p_velocity) {
- angular_velocity=p_velocity;
+ angular_velocity = p_velocity;
if (state)
state->set_angular_velocity(angular_velocity);
else
- Physics2DServer::get_singleton()->body_set_state(get_rid(),Physics2DServer::BODY_STATE_ANGULAR_VELOCITY,angular_velocity);
+ Physics2DServer::get_singleton()->body_set_state(get_rid(), Physics2DServer::BODY_STATE_ANGULAR_VELOCITY, angular_velocity);
}
-real_t RigidBody2D::get_angular_velocity() const{
+real_t RigidBody2D::get_angular_velocity() const {
return angular_velocity;
}
-void RigidBody2D::set_use_custom_integrator(bool p_enable){
+void RigidBody2D::set_use_custom_integrator(bool p_enable) {
- if (custom_integrator==p_enable)
+ if (custom_integrator == p_enable)
return;
- custom_integrator=p_enable;
- Physics2DServer::get_singleton()->body_set_omit_force_integration(get_rid(),p_enable);
-
-
+ custom_integrator = p_enable;
+ Physics2DServer::get_singleton()->body_set_omit_force_integration(get_rid(), p_enable);
}
-bool RigidBody2D::is_using_custom_integrator(){
+bool RigidBody2D::is_using_custom_integrator() {
return custom_integrator;
}
void RigidBody2D::set_sleeping(bool p_sleeping) {
- sleeping=p_sleeping;
- Physics2DServer::get_singleton()->body_set_state(get_rid(),Physics2DServer::BODY_STATE_SLEEPING,sleeping);
-
+ sleeping = p_sleeping;
+ Physics2DServer::get_singleton()->body_set_state(get_rid(), Physics2DServer::BODY_STATE_SLEEPING, sleeping);
}
void RigidBody2D::set_can_sleep(bool p_active) {
- can_sleep=p_active;
- Physics2DServer::get_singleton()->body_set_state(get_rid(),Physics2DServer::BODY_STATE_CAN_SLEEP,p_active);
+ can_sleep = p_active;
+ Physics2DServer::get_singleton()->body_set_state(get_rid(), Physics2DServer::BODY_STATE_CAN_SLEEP, p_active);
}
bool RigidBody2D::is_able_to_sleep() const {
@@ -774,21 +726,21 @@ bool RigidBody2D::is_sleeping() const {
void RigidBody2D::set_max_contacts_reported(int p_amount) {
- max_contacts_reported=p_amount;
- Physics2DServer::get_singleton()->body_set_max_contacts_reported(get_rid(),p_amount);
+ max_contacts_reported = p_amount;
+ Physics2DServer::get_singleton()->body_set_max_contacts_reported(get_rid(), p_amount);
}
-int RigidBody2D::get_max_contacts_reported() const{
+int RigidBody2D::get_max_contacts_reported() const {
return max_contacts_reported;
}
-void RigidBody2D::apply_impulse(const Vector2& p_offset, const Vector2& p_impulse) {
+void RigidBody2D::apply_impulse(const Vector2 &p_offset, const Vector2 &p_impulse) {
- Physics2DServer::get_singleton()->body_apply_impulse(get_rid(),p_offset,p_impulse);
+ Physics2DServer::get_singleton()->body_apply_impulse(get_rid(), p_offset, p_impulse);
}
-void RigidBody2D::set_applied_force(const Vector2& p_force) {
+void RigidBody2D::set_applied_force(const Vector2 &p_force) {
Physics2DServer::get_singleton()->body_set_applied_force(get_rid(), p_force);
};
@@ -808,16 +760,15 @@ float RigidBody2D::get_applied_torque() const {
return Physics2DServer::get_singleton()->body_get_applied_torque(get_rid());
};
-void RigidBody2D::add_force(const Vector2& p_offset, const Vector2& p_force) {
+void RigidBody2D::add_force(const Vector2 &p_offset, const Vector2 &p_force) {
- Physics2DServer::get_singleton()->body_add_force(get_rid(),p_offset,p_force);
+ Physics2DServer::get_singleton()->body_add_force(get_rid(), p_offset, p_force);
}
void RigidBody2D::set_continuous_collision_detection_mode(CCDMode p_mode) {
- ccd_mode=p_mode;
- Physics2DServer::get_singleton()->body_set_continuous_collision_detection_mode(get_rid(),Physics2DServer::CCDMode(p_mode));
-
+ ccd_mode = p_mode;
+ Physics2DServer::get_singleton()->body_set_continuous_collision_detection_mode(get_rid(), Physics2DServer::CCDMode(p_mode));
}
RigidBody2D::CCDMode RigidBody2D::get_continuous_collision_detection_mode() const {
@@ -825,22 +776,20 @@ RigidBody2D::CCDMode RigidBody2D::get_continuous_collision_detection_mode() cons
return ccd_mode;
}
-
Array RigidBody2D::get_colliding_bodies() const {
- ERR_FAIL_COND_V(!contact_monitor,Array());
+ ERR_FAIL_COND_V(!contact_monitor, Array());
Array ret;
ret.resize(contact_monitor->body_map.size());
- int idx=0;
- for (const Map<ObjectID,BodyState>::Element *E=contact_monitor->body_map.front();E;E=E->next()) {
+ int idx = 0;
+ for (const Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.front(); E; E = E->next()) {
Object *obj = ObjectDB::get_instance(E->key());
if (!obj) {
- ret.resize( ret.size() -1 ); //ops
+ ret.resize(ret.size() - 1); //ops
} else {
- ret[idx++]=obj;
+ ret[idx++] = obj;
}
-
}
return ret;
@@ -848,7 +797,7 @@ Array RigidBody2D::get_colliding_bodies() const {
void RigidBody2D::set_contact_monitor(bool p_enabled) {
- if (p_enabled==is_contact_monitor_enabled())
+ if (p_enabled == is_contact_monitor_enabled())
return;
if (!p_enabled) {
@@ -858,180 +807,173 @@ void RigidBody2D::set_contact_monitor(bool p_enabled) {
}
ERR_FAIL_COND(contact_monitor->locked);
- for(Map<ObjectID,BodyState>::Element *E=contact_monitor->body_map.front();E;E=E->next()) {
+ for (Map<ObjectID, BodyState>::Element *E = contact_monitor->body_map.front(); E; E = E->next()) {
//clean up mess
}
- memdelete( contact_monitor );
- contact_monitor=NULL;
+ memdelete(contact_monitor);
+ contact_monitor = NULL;
} else {
- contact_monitor = memnew( ContactMonitor );
- contact_monitor->locked=false;
+ contact_monitor = memnew(ContactMonitor);
+ contact_monitor->locked = false;
}
-
}
bool RigidBody2D::is_contact_monitor_enabled() const {
- return contact_monitor!=NULL;
+ return contact_monitor != NULL;
}
-
-
void RigidBody2D::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_mode","mode"),&RigidBody2D::set_mode);
- ClassDB::bind_method(D_METHOD("get_mode"),&RigidBody2D::get_mode);
-
- ClassDB::bind_method(D_METHOD("set_mass","mass"),&RigidBody2D::set_mass);
- ClassDB::bind_method(D_METHOD("get_mass"),&RigidBody2D::get_mass);
+ ClassDB::bind_method(D_METHOD("set_mode", "mode"), &RigidBody2D::set_mode);
+ ClassDB::bind_method(D_METHOD("get_mode"), &RigidBody2D::get_mode);
- ClassDB::bind_method(D_METHOD("get_inertia"),&RigidBody2D::get_inertia);
- ClassDB::bind_method(D_METHOD("set_inertia","inertia"),&RigidBody2D::set_inertia);
+ ClassDB::bind_method(D_METHOD("set_mass", "mass"), &RigidBody2D::set_mass);
+ ClassDB::bind_method(D_METHOD("get_mass"), &RigidBody2D::get_mass);
- ClassDB::bind_method(D_METHOD("set_weight","weight"),&RigidBody2D::set_weight);
- ClassDB::bind_method(D_METHOD("get_weight"),&RigidBody2D::get_weight);
+ ClassDB::bind_method(D_METHOD("get_inertia"), &RigidBody2D::get_inertia);
+ ClassDB::bind_method(D_METHOD("set_inertia", "inertia"), &RigidBody2D::set_inertia);
- ClassDB::bind_method(D_METHOD("set_friction","friction"),&RigidBody2D::set_friction);
- ClassDB::bind_method(D_METHOD("get_friction"),&RigidBody2D::get_friction);
+ ClassDB::bind_method(D_METHOD("set_weight", "weight"), &RigidBody2D::set_weight);
+ ClassDB::bind_method(D_METHOD("get_weight"), &RigidBody2D::get_weight);
- ClassDB::bind_method(D_METHOD("set_bounce","bounce"),&RigidBody2D::set_bounce);
- ClassDB::bind_method(D_METHOD("get_bounce"),&RigidBody2D::get_bounce);
+ ClassDB::bind_method(D_METHOD("set_friction", "friction"), &RigidBody2D::set_friction);
+ ClassDB::bind_method(D_METHOD("get_friction"), &RigidBody2D::get_friction);
- ClassDB::bind_method(D_METHOD("set_gravity_scale","gravity_scale"),&RigidBody2D::set_gravity_scale);
- ClassDB::bind_method(D_METHOD("get_gravity_scale"),&RigidBody2D::get_gravity_scale);
+ ClassDB::bind_method(D_METHOD("set_bounce", "bounce"), &RigidBody2D::set_bounce);
+ ClassDB::bind_method(D_METHOD("get_bounce"), &RigidBody2D::get_bounce);
- ClassDB::bind_method(D_METHOD("set_linear_damp","linear_damp"),&RigidBody2D::set_linear_damp);
- ClassDB::bind_method(D_METHOD("get_linear_damp"),&RigidBody2D::get_linear_damp);
+ ClassDB::bind_method(D_METHOD("set_gravity_scale", "gravity_scale"), &RigidBody2D::set_gravity_scale);
+ ClassDB::bind_method(D_METHOD("get_gravity_scale"), &RigidBody2D::get_gravity_scale);
- ClassDB::bind_method(D_METHOD("set_angular_damp","angular_damp"),&RigidBody2D::set_angular_damp);
- ClassDB::bind_method(D_METHOD("get_angular_damp"),&RigidBody2D::get_angular_damp);
+ ClassDB::bind_method(D_METHOD("set_linear_damp", "linear_damp"), &RigidBody2D::set_linear_damp);
+ ClassDB::bind_method(D_METHOD("get_linear_damp"), &RigidBody2D::get_linear_damp);
- ClassDB::bind_method(D_METHOD("set_linear_velocity","linear_velocity"),&RigidBody2D::set_linear_velocity);
- ClassDB::bind_method(D_METHOD("get_linear_velocity"),&RigidBody2D::get_linear_velocity);
+ ClassDB::bind_method(D_METHOD("set_angular_damp", "angular_damp"), &RigidBody2D::set_angular_damp);
+ ClassDB::bind_method(D_METHOD("get_angular_damp"), &RigidBody2D::get_angular_damp);
- ClassDB::bind_method(D_METHOD("set_angular_velocity","angular_velocity"),&RigidBody2D::set_angular_velocity);
- ClassDB::bind_method(D_METHOD("get_angular_velocity"),&RigidBody2D::get_angular_velocity);
+ ClassDB::bind_method(D_METHOD("set_linear_velocity", "linear_velocity"), &RigidBody2D::set_linear_velocity);
+ ClassDB::bind_method(D_METHOD("get_linear_velocity"), &RigidBody2D::get_linear_velocity);
- ClassDB::bind_method(D_METHOD("set_max_contacts_reported","amount"),&RigidBody2D::set_max_contacts_reported);
- ClassDB::bind_method(D_METHOD("get_max_contacts_reported"),&RigidBody2D::get_max_contacts_reported);
+ ClassDB::bind_method(D_METHOD("set_angular_velocity", "angular_velocity"), &RigidBody2D::set_angular_velocity);
+ ClassDB::bind_method(D_METHOD("get_angular_velocity"), &RigidBody2D::get_angular_velocity);
- ClassDB::bind_method(D_METHOD("set_use_custom_integrator","enable"),&RigidBody2D::set_use_custom_integrator);
- ClassDB::bind_method(D_METHOD("is_using_custom_integrator"),&RigidBody2D::is_using_custom_integrator);
+ ClassDB::bind_method(D_METHOD("set_max_contacts_reported", "amount"), &RigidBody2D::set_max_contacts_reported);
+ ClassDB::bind_method(D_METHOD("get_max_contacts_reported"), &RigidBody2D::get_max_contacts_reported);
- ClassDB::bind_method(D_METHOD("set_contact_monitor","enabled"),&RigidBody2D::set_contact_monitor);
- ClassDB::bind_method(D_METHOD("is_contact_monitor_enabled"),&RigidBody2D::is_contact_monitor_enabled);
+ ClassDB::bind_method(D_METHOD("set_use_custom_integrator", "enable"), &RigidBody2D::set_use_custom_integrator);
+ ClassDB::bind_method(D_METHOD("is_using_custom_integrator"), &RigidBody2D::is_using_custom_integrator);
- ClassDB::bind_method(D_METHOD("set_continuous_collision_detection_mode","mode"),&RigidBody2D::set_continuous_collision_detection_mode);
- ClassDB::bind_method(D_METHOD("get_continuous_collision_detection_mode"),&RigidBody2D::get_continuous_collision_detection_mode);
+ ClassDB::bind_method(D_METHOD("set_contact_monitor", "enabled"), &RigidBody2D::set_contact_monitor);
+ ClassDB::bind_method(D_METHOD("is_contact_monitor_enabled"), &RigidBody2D::is_contact_monitor_enabled);
- ClassDB::bind_method(D_METHOD("set_axis_velocity","axis_velocity"),&RigidBody2D::set_axis_velocity);
- ClassDB::bind_method(D_METHOD("apply_impulse","offset","impulse"),&RigidBody2D::apply_impulse);
+ ClassDB::bind_method(D_METHOD("set_continuous_collision_detection_mode", "mode"), &RigidBody2D::set_continuous_collision_detection_mode);
+ ClassDB::bind_method(D_METHOD("get_continuous_collision_detection_mode"), &RigidBody2D::get_continuous_collision_detection_mode);
- ClassDB::bind_method(D_METHOD("set_applied_force","force"),&RigidBody2D::set_applied_force);
- ClassDB::bind_method(D_METHOD("get_applied_force"),&RigidBody2D::get_applied_force);
+ ClassDB::bind_method(D_METHOD("set_axis_velocity", "axis_velocity"), &RigidBody2D::set_axis_velocity);
+ ClassDB::bind_method(D_METHOD("apply_impulse", "offset", "impulse"), &RigidBody2D::apply_impulse);
- ClassDB::bind_method(D_METHOD("set_applied_torque","torque"),&RigidBody2D::set_applied_torque);
- ClassDB::bind_method(D_METHOD("get_applied_torque"),&RigidBody2D::get_applied_torque);
+ ClassDB::bind_method(D_METHOD("set_applied_force", "force"), &RigidBody2D::set_applied_force);
+ ClassDB::bind_method(D_METHOD("get_applied_force"), &RigidBody2D::get_applied_force);
- ClassDB::bind_method(D_METHOD("add_force","offset","force"),&RigidBody2D::add_force);
+ ClassDB::bind_method(D_METHOD("set_applied_torque", "torque"), &RigidBody2D::set_applied_torque);
+ ClassDB::bind_method(D_METHOD("get_applied_torque"), &RigidBody2D::get_applied_torque);
- ClassDB::bind_method(D_METHOD("set_sleeping","sleeping"),&RigidBody2D::set_sleeping);
- ClassDB::bind_method(D_METHOD("is_sleeping"),&RigidBody2D::is_sleeping);
+ ClassDB::bind_method(D_METHOD("add_force", "offset", "force"), &RigidBody2D::add_force);
- ClassDB::bind_method(D_METHOD("set_can_sleep","able_to_sleep"),&RigidBody2D::set_can_sleep);
- ClassDB::bind_method(D_METHOD("is_able_to_sleep"),&RigidBody2D::is_able_to_sleep);
+ ClassDB::bind_method(D_METHOD("set_sleeping", "sleeping"), &RigidBody2D::set_sleeping);
+ ClassDB::bind_method(D_METHOD("is_sleeping"), &RigidBody2D::is_sleeping);
- ClassDB::bind_method(D_METHOD("test_motion","motion","margin","result:Physics2DTestMotionResult"),&RigidBody2D::_test_motion,DEFVAL(0.08),DEFVAL(Variant()));
+ ClassDB::bind_method(D_METHOD("set_can_sleep", "able_to_sleep"), &RigidBody2D::set_can_sleep);
+ ClassDB::bind_method(D_METHOD("is_able_to_sleep"), &RigidBody2D::is_able_to_sleep);
- ClassDB::bind_method(D_METHOD("_direct_state_changed"),&RigidBody2D::_direct_state_changed);
- ClassDB::bind_method(D_METHOD("_body_enter_tree"),&RigidBody2D::_body_enter_tree);
- ClassDB::bind_method(D_METHOD("_body_exit_tree"),&RigidBody2D::_body_exit_tree);
+ ClassDB::bind_method(D_METHOD("test_motion", "motion", "margin", "result:Physics2DTestMotionResult"), &RigidBody2D::_test_motion, DEFVAL(0.08), DEFVAL(Variant()));
- ClassDB::bind_method(D_METHOD("get_colliding_bodies"),&RigidBody2D::get_colliding_bodies);
+ ClassDB::bind_method(D_METHOD("_direct_state_changed"), &RigidBody2D::_direct_state_changed);
+ ClassDB::bind_method(D_METHOD("_body_enter_tree"), &RigidBody2D::_body_enter_tree);
+ ClassDB::bind_method(D_METHOD("_body_exit_tree"), &RigidBody2D::_body_exit_tree);
- BIND_VMETHOD(MethodInfo("_integrate_forces",PropertyInfo(Variant::OBJECT,"state:Physics2DDirectBodyState")));
+ ClassDB::bind_method(D_METHOD("get_colliding_bodies"), &RigidBody2D::get_colliding_bodies);
- ADD_PROPERTY( PropertyInfo(Variant::INT,"mode",PROPERTY_HINT_ENUM,"Rigid,Static,Character,Kinematic"),"set_mode","get_mode");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"mass",PROPERTY_HINT_EXP_RANGE,"0.01,65535,0.01"),"set_mass","get_mass");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"weight",PROPERTY_HINT_EXP_RANGE,"0.01,65535,0.01",PROPERTY_USAGE_EDITOR),"set_weight","get_weight");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"friction",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_friction","get_friction");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"bounce",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_bounce","get_bounce");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"gravity_scale",PROPERTY_HINT_RANGE,"-128,128,0.01"),"set_gravity_scale","get_gravity_scale");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"custom_integrator"),"set_use_custom_integrator","is_using_custom_integrator");
- ADD_PROPERTY( PropertyInfo(Variant::INT,"continuous_cd",PROPERTY_HINT_ENUM,"Disabled,Cast Ray,Cast Shape"),"set_continuous_collision_detection_mode","get_continuous_collision_detection_mode");
- ADD_PROPERTY( PropertyInfo(Variant::INT,"contacts_reported"),"set_max_contacts_reported","get_max_contacts_reported");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"contact_monitor"),"set_contact_monitor","is_contact_monitor_enabled");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"sleeping"),"set_sleeping","is_sleeping");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"can_sleep"),"set_can_sleep","is_able_to_sleep");
- ADD_GROUP("Linear","linear_");
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"linear_velocity"),"set_linear_velocity","get_linear_velocity");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"linear_damp",PROPERTY_HINT_RANGE,"-1,128,0.01"),"set_linear_damp","get_linear_damp");
- ADD_GROUP("Angular","angular_");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"angular_velocity"),"set_angular_velocity","get_angular_velocity");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"angular_damp",PROPERTY_HINT_RANGE,"-1,128,0.01"),"set_angular_damp","get_angular_damp");
+ BIND_VMETHOD(MethodInfo("_integrate_forces", PropertyInfo(Variant::OBJECT, "state:Physics2DDirectBodyState")));
- ADD_SIGNAL( MethodInfo("body_shape_entered",PropertyInfo(Variant::INT,"body_id"),PropertyInfo(Variant::OBJECT,"body"),PropertyInfo(Variant::INT,"body_shape"),PropertyInfo(Variant::INT,"local_shape")));
- ADD_SIGNAL( MethodInfo("body_shape_exited",PropertyInfo(Variant::INT,"body_id"),PropertyInfo(Variant::OBJECT,"body"),PropertyInfo(Variant::INT,"body_shape"),PropertyInfo(Variant::INT,"local_shape")));
- ADD_SIGNAL( MethodInfo("body_entered",PropertyInfo(Variant::OBJECT,"body")));
- ADD_SIGNAL( MethodInfo("body_exited",PropertyInfo(Variant::OBJECT,"body")));
- ADD_SIGNAL( MethodInfo("sleeping_state_changed"));
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Rigid,Static,Character,Kinematic"), "set_mode", "get_mode");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "mass", PROPERTY_HINT_EXP_RANGE, "0.01,65535,0.01"), "set_mass", "get_mass");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "weight", PROPERTY_HINT_EXP_RANGE, "0.01,65535,0.01", PROPERTY_USAGE_EDITOR), "set_weight", "get_weight");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "friction", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_friction", "get_friction");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "bounce", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_bounce", "get_bounce");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "gravity_scale", PROPERTY_HINT_RANGE, "-128,128,0.01"), "set_gravity_scale", "get_gravity_scale");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "custom_integrator"), "set_use_custom_integrator", "is_using_custom_integrator");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "continuous_cd", PROPERTY_HINT_ENUM, "Disabled,Cast Ray,Cast Shape"), "set_continuous_collision_detection_mode", "get_continuous_collision_detection_mode");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "contacts_reported"), "set_max_contacts_reported", "get_max_contacts_reported");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "contact_monitor"), "set_contact_monitor", "is_contact_monitor_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sleeping"), "set_sleeping", "is_sleeping");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "can_sleep"), "set_can_sleep", "is_able_to_sleep");
+ ADD_GROUP("Linear", "linear_");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "linear_velocity"), "set_linear_velocity", "get_linear_velocity");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "linear_damp", PROPERTY_HINT_RANGE, "-1,128,0.01"), "set_linear_damp", "get_linear_damp");
+ ADD_GROUP("Angular", "angular_");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_velocity"), "set_angular_velocity", "get_angular_velocity");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "angular_damp", PROPERTY_HINT_RANGE, "-1,128,0.01"), "set_angular_damp", "get_angular_damp");
- BIND_CONSTANT( MODE_STATIC );
- BIND_CONSTANT( MODE_KINEMATIC );
- BIND_CONSTANT( MODE_RIGID );
- BIND_CONSTANT( MODE_CHARACTER );
+ ADD_SIGNAL(MethodInfo("body_shape_entered", PropertyInfo(Variant::INT, "body_id"), PropertyInfo(Variant::OBJECT, "body"), PropertyInfo(Variant::INT, "body_shape"), PropertyInfo(Variant::INT, "local_shape")));
+ ADD_SIGNAL(MethodInfo("body_shape_exited", PropertyInfo(Variant::INT, "body_id"), PropertyInfo(Variant::OBJECT, "body"), PropertyInfo(Variant::INT, "body_shape"), PropertyInfo(Variant::INT, "local_shape")));
+ ADD_SIGNAL(MethodInfo("body_entered", PropertyInfo(Variant::OBJECT, "body")));
+ ADD_SIGNAL(MethodInfo("body_exited", PropertyInfo(Variant::OBJECT, "body")));
+ ADD_SIGNAL(MethodInfo("sleeping_state_changed"));
- BIND_CONSTANT( CCD_MODE_DISABLED );
- BIND_CONSTANT( CCD_MODE_CAST_RAY );
- BIND_CONSTANT( CCD_MODE_CAST_SHAPE );
+ BIND_CONSTANT(MODE_STATIC);
+ BIND_CONSTANT(MODE_KINEMATIC);
+ BIND_CONSTANT(MODE_RIGID);
+ BIND_CONSTANT(MODE_CHARACTER);
+ BIND_CONSTANT(CCD_MODE_DISABLED);
+ BIND_CONSTANT(CCD_MODE_CAST_RAY);
+ BIND_CONSTANT(CCD_MODE_CAST_SHAPE);
}
-RigidBody2D::RigidBody2D() : PhysicsBody2D(Physics2DServer::BODY_MODE_RIGID) {
+RigidBody2D::RigidBody2D()
+ : PhysicsBody2D(Physics2DServer::BODY_MODE_RIGID) {
- mode=MODE_RIGID;
+ mode = MODE_RIGID;
- bounce=0;
- mass=1;
- friction=1;
+ bounce = 0;
+ mass = 1;
+ friction = 1;
- gravity_scale=1;
- linear_damp=-1;
- angular_damp=-1;
+ gravity_scale = 1;
+ linear_damp = -1;
+ angular_damp = -1;
- max_contacts_reported=0;
- state=NULL;
+ max_contacts_reported = 0;
+ state = NULL;
- angular_velocity=0;
- sleeping=false;
- ccd_mode=CCD_MODE_DISABLED;
+ angular_velocity = 0;
+ sleeping = false;
+ ccd_mode = CCD_MODE_DISABLED;
- custom_integrator=false;
- contact_monitor=NULL;
- can_sleep=true;
+ custom_integrator = false;
+ contact_monitor = NULL;
+ can_sleep = true;
- Physics2DServer::get_singleton()->body_set_force_integration_callback(get_rid(),this,"_direct_state_changed");
+ Physics2DServer::get_singleton()->body_set_force_integration_callback(get_rid(), this, "_direct_state_changed");
}
RigidBody2D::~RigidBody2D() {
if (contact_monitor)
- memdelete( contact_monitor );
-
-
-
+ memdelete(contact_monitor);
}
//////////////////////////
-
Variant KinematicBody2D::_get_collider() const {
- ObjectID oid=get_collider();
- if (oid==0)
+ ObjectID oid = get_collider();
+ if (oid == 0)
return Variant();
Object *obj = ObjectDB::get_instance(oid);
if (!obj)
@@ -1048,10 +990,9 @@ Variant KinematicBody2D::_get_collider() const {
void KinematicBody2D::revert_motion() {
Transform2D gt = get_global_transform();
- gt.elements[2]-=travel;
- travel=Vector2();
+ gt.elements[2] -= travel;
+ travel = Vector2();
set_global_transform(gt);
-
}
Vector2 KinematicBody2D::get_travel() const {
@@ -1059,26 +1000,24 @@ Vector2 KinematicBody2D::get_travel() const {
return travel;
}
-Vector2 KinematicBody2D::move(const Vector2& p_motion) {
+Vector2 KinematicBody2D::move(const Vector2 &p_motion) {
#if 1
Transform2D gt = get_global_transform();
Physics2DServer::MotionResult result;
- colliding = Physics2DServer::get_singleton()->body_test_motion(get_rid(),gt,p_motion,margin,&result);
-
- collider_metadata=result.collider_metadata;
- collider_shape=result.collider_shape;
- collider_vel=result.collider_velocity;
- collision=result.collision_point;
- normal=result.collision_normal;
- collider=result.collider_id;
+ colliding = Physics2DServer::get_singleton()->body_test_motion(get_rid(), gt, p_motion, margin, &result);
+ collider_metadata = result.collider_metadata;
+ collider_shape = result.collider_shape;
+ collider_vel = result.collider_velocity;
+ collision = result.collision_point;
+ normal = result.collision_normal;
+ collider = result.collider_id;
- gt.elements[2]+=result.motion;
+ gt.elements[2] += result.motion;
set_global_transform(gt);
- travel=result.motion;
-
+ travel = result.motion;
return result.remainder;
@@ -1090,43 +1029,41 @@ Vector2 KinematicBody2D::move(const Vector2& p_motion) {
//this took about a week to get right..
//but is it right? who knows at this point..
- colliding=false;
- ERR_FAIL_COND_V(!is_inside_tree(),Vector2());
+ colliding = false;
+ ERR_FAIL_COND_V(!is_inside_tree(), Vector2());
Physics2DDirectSpaceState *dss = Physics2DServer::get_singleton()->space_get_direct_state(get_world_2d()->get_space());
- ERR_FAIL_COND_V(!dss,Vector2());
- const int max_shapes=32;
- Vector2 sr[max_shapes*2];
+ ERR_FAIL_COND_V(!dss, Vector2());
+ const int max_shapes = 32;
+ Vector2 sr[max_shapes * 2];
int res_shapes;
Set<RID> exclude;
exclude.insert(get_rid());
-
//recover first
- int recover_attempts=4;
+ int recover_attempts = 4;
- bool collided=false;
- uint32_t mask=0;
+ bool collided = false;
+ uint32_t mask = 0;
if (true)
- mask|=Physics2DDirectSpaceState::TYPE_MASK_STATIC_BODY;
+ mask |= Physics2DDirectSpaceState::TYPE_MASK_STATIC_BODY;
if (true)
- mask|=Physics2DDirectSpaceState::TYPE_MASK_KINEMATIC_BODY;
+ mask |= Physics2DDirectSpaceState::TYPE_MASK_KINEMATIC_BODY;
if (true)
- mask|=Physics2DDirectSpaceState::TYPE_MASK_RIGID_BODY;
+ mask |= Physics2DDirectSpaceState::TYPE_MASK_RIGID_BODY;
if (true)
- mask|=Physics2DDirectSpaceState::TYPE_MASK_CHARACTER_BODY;
+ mask |= Physics2DDirectSpaceState::TYPE_MASK_CHARACTER_BODY;
//print_line("margin: "+rtos(margin));
do {
//motion recover
- for(int i=0;i<get_shape_count();i++) {
+ for (int i = 0; i < get_shape_count(); i++) {
if (is_shape_set_as_trigger(i))
continue;
- if (dss->collide_shape(get_shape(i)->get_rid(), get_global_transform() * get_shape_transform(i),Vector2(),margin,sr,max_shapes,res_shapes,exclude,get_layer_mask(),mask))
- collided=true;
-
+ if (dss->collide_shape(get_shape(i)->get_rid(), get_global_transform() * get_shape_transform(i), Vector2(), margin, sr, max_shapes, res_shapes, exclude, get_layer_mask(), mask))
+ collided = true;
}
if (!collided)
@@ -1134,10 +1071,10 @@ Vector2 KinematicBody2D::move(const Vector2& p_motion) {
Vector2 recover_motion;
- for(int i=0;i<res_shapes;i++) {
+ for (int i = 0; i < res_shapes; i++) {
- Vector2 a = sr[i*2+0];
- Vector2 b = sr[i*2+1];
+ Vector2 a = sr[i * 2 + 0];
+ Vector2 b = sr[i * 2 + 1];
float d = a.distance_to(b);
@@ -1145,145 +1082,133 @@ Vector2 KinematicBody2D::move(const Vector2& p_motion) {
if (d<margin)
continue;
*/
- recover_motion+=(b-a)*0.4;
+ recover_motion += (b - a) * 0.4;
}
- if (recover_motion==Vector2()) {
- collided=false;
+ if (recover_motion == Vector2()) {
+ collided = false;
break;
}
-
-
Transform2D gt = get_global_transform();
- gt.elements[2]+=recover_motion;
+ gt.elements[2] += recover_motion;
set_global_transform(gt);
recover_attempts--;
} while (recover_attempts);
-
//move second
float safe = 1.0;
float unsafe = 1.0;
- int best_shape=-1;
+ int best_shape = -1;
- for(int i=0;i<get_shape_count();i++) {
+ for (int i = 0; i < get_shape_count(); i++) {
if (is_shape_set_as_trigger(i))
continue;
- float lsafe,lunsafe;
- bool valid = dss->cast_motion(get_shape(i)->get_rid(), get_global_transform() * get_shape_transform(i), p_motion, 0,lsafe,lunsafe,exclude,get_layer_mask(),mask);
+ float lsafe, lunsafe;
+ bool valid = dss->cast_motion(get_shape(i)->get_rid(), get_global_transform() * get_shape_transform(i), p_motion, 0, lsafe, lunsafe, exclude, get_layer_mask(), mask);
//print_line("shape: "+itos(i)+" travel:"+rtos(ltravel));
if (!valid) {
- safe=0;
- unsafe=0;
- best_shape=i; //sadly it's the best
+ safe = 0;
+ unsafe = 0;
+ best_shape = i; //sadly it's the best
break;
}
- if (lsafe==1.0) {
+ if (lsafe == 1.0) {
continue;
}
if (lsafe < safe) {
- safe=lsafe;
- unsafe=lunsafe;
- best_shape=i;
+ safe = lsafe;
+ unsafe = lunsafe;
+ best_shape = i;
}
}
-
//print_line("best shape: "+itos(best_shape)+" motion "+p_motion);
- if (safe>=1) {
+ if (safe >= 1) {
//not collided
- colliding=false;
-
+ colliding = false;
} else {
//it collided, let's get the rest info in unsafe advance
Transform2D ugt = get_global_transform();
- ugt.elements[2]+=p_motion*unsafe;
+ ugt.elements[2] += p_motion * unsafe;
Physics2DDirectSpaceState::ShapeRestInfo rest_info;
- bool c2 = dss->rest_info(get_shape(best_shape)->get_rid(), ugt*get_shape_transform(best_shape), Vector2(), margin,&rest_info,exclude,get_layer_mask(),mask);
+ bool c2 = dss->rest_info(get_shape(best_shape)->get_rid(), ugt * get_shape_transform(best_shape), Vector2(), margin, &rest_info, exclude, get_layer_mask(), mask);
if (!c2) {
//should not happen, but floating point precision is so weird..
- colliding=false;
+ colliding = false;
} else {
-
//print_line("Travel: "+rtos(travel));
- colliding=true;
- collision=rest_info.point;
- normal=rest_info.normal;
- collider=rest_info.collider_id;
- collider_vel=rest_info.linear_velocity;
- collider_shape=rest_info.shape;
- collider_metadata=rest_info.metadata;
+ colliding = true;
+ collision = rest_info.point;
+ normal = rest_info.normal;
+ collider = rest_info.collider_id;
+ collider_vel = rest_info.linear_velocity;
+ collider_shape = rest_info.shape;
+ collider_metadata = rest_info.metadata;
}
-
}
- Vector2 motion=p_motion*safe;
+ Vector2 motion = p_motion * safe;
Transform2D gt = get_global_transform();
- gt.elements[2]+=motion;
+ gt.elements[2] += motion;
set_global_transform(gt);
- return p_motion-motion;
+ return p_motion - motion;
#endif
}
+Vector2 KinematicBody2D::move_and_slide(const Vector2 &p_linear_velocity, const Vector2 &p_floor_direction, float p_slope_stop_min_velocity, int p_max_bounces) {
-
-Vector2 KinematicBody2D::move_and_slide(const Vector2& p_linear_velocity,const Vector2& p_floor_direction,float p_slope_stop_min_velocity,int p_max_bounces) {
-
- Vector2 motion = (move_and_slide_floor_velocity+p_linear_velocity)*get_fixed_process_delta_time();
+ Vector2 motion = (move_and_slide_floor_velocity + p_linear_velocity) * get_fixed_process_delta_time();
Vector2 lv = p_linear_velocity;
- move_and_slide_on_floor=false;
- move_and_slide_on_ceiling=false;
- move_and_slide_on_wall=false;
+ move_and_slide_on_floor = false;
+ move_and_slide_on_ceiling = false;
+ move_and_slide_on_wall = false;
move_and_slide_colliders.clear();
- move_and_slide_floor_velocity=Vector2();
+ move_and_slide_floor_velocity = Vector2();
- while(p_max_bounces) {
+ while (p_max_bounces) {
- motion=move(motion);
+ motion = move(motion);
if (is_colliding()) {
-
- if (p_floor_direction==Vector2()) {
+ if (p_floor_direction == Vector2()) {
//all is a wall
- move_and_slide_on_wall=true;
+ move_and_slide_on_wall = true;
} else {
- if ( get_collision_normal().dot(p_floor_direction) > Math::cos(Math::deg2rad((float)45))) { //floor
-
+ if (get_collision_normal().dot(p_floor_direction) > Math::cos(Math::deg2rad((float)45))) { //floor
- move_and_slide_on_floor=true;
- move_and_slide_floor_velocity=get_collider_velocity();
+ move_and_slide_on_floor = true;
+ move_and_slide_floor_velocity = get_collider_velocity();
- if (get_travel().length()<1 && ABS((lv.x-move_and_slide_floor_velocity.x))<p_slope_stop_min_velocity) {
+ if (get_travel().length() < 1 && ABS((lv.x - move_and_slide_floor_velocity.x)) < p_slope_stop_min_velocity) {
revert_motion();
return Vector2();
}
- } else if ( get_collision_normal().dot(p_floor_direction) < Math::cos(Math::deg2rad((float)45))) { //ceiling
- move_and_slide_on_ceiling=true;
+ } else if (get_collision_normal().dot(p_floor_direction) < Math::cos(Math::deg2rad((float)45))) { //ceiling
+ move_and_slide_on_ceiling = true;
} else {
- move_and_slide_on_wall=true;
+ move_and_slide_on_wall = true;
}
-
}
- motion=get_collision_normal().slide(motion);
- lv=get_collision_normal().slide(lv);
+ motion = get_collision_normal().slide(motion);
+ lv = get_collision_normal().slide(lv);
Variant collider = _get_collider();
- if (collider.get_type()!=Variant::NIL) {
+ if (collider.get_type() != Variant::NIL) {
move_and_slide_colliders.push_back(collider);
}
@@ -1292,7 +1217,7 @@ Vector2 KinematicBody2D::move_and_slide(const Vector2& p_linear_velocity,const V
}
p_max_bounces--;
- if (motion==Vector2())
+ if (motion == Vector2())
break;
}
@@ -1303,45 +1228,41 @@ bool KinematicBody2D::is_move_and_slide_on_floor() const {
return move_and_slide_on_floor;
}
-bool KinematicBody2D::is_move_and_slide_on_wall() const{
+bool KinematicBody2D::is_move_and_slide_on_wall() const {
return move_and_slide_on_wall;
}
-bool KinematicBody2D::is_move_and_slide_on_ceiling() const{
+bool KinematicBody2D::is_move_and_slide_on_ceiling() const {
return move_and_slide_on_ceiling;
}
-Array KinematicBody2D::get_move_and_slide_colliders() const{
+Array KinematicBody2D::get_move_and_slide_colliders() const {
return move_and_slide_colliders;
}
-Vector2 KinematicBody2D::move_to(const Vector2& p_position) {
+Vector2 KinematicBody2D::move_to(const Vector2 &p_position) {
- return move(p_position-get_global_position());
+ return move(p_position - get_global_position());
}
-bool KinematicBody2D::test_move(const Transform2D& p_from,const Vector2& p_motion) {
-
- ERR_FAIL_COND_V(!is_inside_tree(),false);
-
- return Physics2DServer::get_singleton()->body_test_motion(get_rid(),p_from,p_motion,margin);
+bool KinematicBody2D::test_move(const Transform2D &p_from, const Vector2 &p_motion) {
+ ERR_FAIL_COND_V(!is_inside_tree(), false);
+ return Physics2DServer::get_singleton()->body_test_motion(get_rid(), p_from, p_motion, margin);
}
Vector2 KinematicBody2D::get_collision_pos() const {
- ERR_FAIL_COND_V(!colliding,Vector2());
+ ERR_FAIL_COND_V(!colliding, Vector2());
return collision;
-
}
Vector2 KinematicBody2D::get_collision_normal() const {
- ERR_FAIL_COND_V(!colliding,Vector2());
+ ERR_FAIL_COND_V(!colliding, Vector2());
return normal;
-
}
Vector2 KinematicBody2D::get_collider_velocity() const {
@@ -1351,88 +1272,79 @@ Vector2 KinematicBody2D::get_collider_velocity() const {
ObjectID KinematicBody2D::get_collider() const {
- ERR_FAIL_COND_V(!colliding,0);
+ ERR_FAIL_COND_V(!colliding, 0);
return collider;
}
-
int KinematicBody2D::get_collider_shape() const {
- ERR_FAIL_COND_V(!colliding,0);
+ ERR_FAIL_COND_V(!colliding, 0);
return collider_shape;
}
Variant KinematicBody2D::get_collider_metadata() const {
- ERR_FAIL_COND_V(!colliding,0);
+ ERR_FAIL_COND_V(!colliding, 0);
return collider_metadata;
-
}
-
-bool KinematicBody2D::is_colliding() const{
+bool KinematicBody2D::is_colliding() const {
return colliding;
}
void KinematicBody2D::set_collision_margin(float p_margin) {
- margin=p_margin;
+ margin = p_margin;
}
-float KinematicBody2D::get_collision_margin() const{
+float KinematicBody2D::get_collision_margin() const {
return margin;
}
void KinematicBody2D::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("move", "rel_vec"), &KinematicBody2D::move);
+ ClassDB::bind_method(D_METHOD("move_to", "position"), &KinematicBody2D::move_to);
+ ClassDB::bind_method(D_METHOD("move_and_slide", "linear_velocity", "floor_normal", "slope_stop_min_velocity", "max_bounces"), &KinematicBody2D::move_and_slide, DEFVAL(Vector2(0, 0)), DEFVAL(5), DEFVAL(4));
- ClassDB::bind_method(D_METHOD("move","rel_vec"),&KinematicBody2D::move);
- ClassDB::bind_method(D_METHOD("move_to","position"),&KinematicBody2D::move_to);
- ClassDB::bind_method(D_METHOD("move_and_slide","linear_velocity","floor_normal","slope_stop_min_velocity","max_bounces"),&KinematicBody2D::move_and_slide,DEFVAL(Vector2(0,0)),DEFVAL(5),DEFVAL(4));
-
- ClassDB::bind_method(D_METHOD("test_move","from","rel_vec"),&KinematicBody2D::test_move);
- ClassDB::bind_method(D_METHOD("get_travel"),&KinematicBody2D::get_travel);
- ClassDB::bind_method(D_METHOD("revert_motion"),&KinematicBody2D::revert_motion);
-
- ClassDB::bind_method(D_METHOD("is_colliding"),&KinematicBody2D::is_colliding);
+ ClassDB::bind_method(D_METHOD("test_move", "from", "rel_vec"), &KinematicBody2D::test_move);
+ ClassDB::bind_method(D_METHOD("get_travel"), &KinematicBody2D::get_travel);
+ ClassDB::bind_method(D_METHOD("revert_motion"), &KinematicBody2D::revert_motion);
- ClassDB::bind_method(D_METHOD("get_collision_pos"),&KinematicBody2D::get_collision_pos);
- ClassDB::bind_method(D_METHOD("get_collision_normal"),&KinematicBody2D::get_collision_normal);
- ClassDB::bind_method(D_METHOD("get_collider_velocity"),&KinematicBody2D::get_collider_velocity);
- ClassDB::bind_method(D_METHOD("get_collider:Variant"),&KinematicBody2D::_get_collider);
- ClassDB::bind_method(D_METHOD("get_collider_shape"),&KinematicBody2D::get_collider_shape);
- ClassDB::bind_method(D_METHOD("get_collider_metadata:Variant"),&KinematicBody2D::get_collider_metadata);
- ClassDB::bind_method(D_METHOD("get_move_and_slide_colliders"),&KinematicBody2D::get_move_and_slide_colliders);
- ClassDB::bind_method(D_METHOD("is_move_and_slide_on_floor"),&KinematicBody2D::is_move_and_slide_on_floor);
- ClassDB::bind_method(D_METHOD("is_move_and_slide_on_ceiling"),&KinematicBody2D::is_move_and_slide_on_ceiling);
- ClassDB::bind_method(D_METHOD("is_move_and_slide_on_wall"),&KinematicBody2D::is_move_and_slide_on_wall);
+ ClassDB::bind_method(D_METHOD("is_colliding"), &KinematicBody2D::is_colliding);
- ClassDB::bind_method(D_METHOD("set_collision_margin","pixels"),&KinematicBody2D::set_collision_margin);
- ClassDB::bind_method(D_METHOD("get_collision_margin","pixels"),&KinematicBody2D::get_collision_margin);
-
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"collision/margin",PROPERTY_HINT_RANGE,"0.001,256,0.001"),"set_collision_margin","get_collision_margin");
+ ClassDB::bind_method(D_METHOD("get_collision_pos"), &KinematicBody2D::get_collision_pos);
+ ClassDB::bind_method(D_METHOD("get_collision_normal"), &KinematicBody2D::get_collision_normal);
+ ClassDB::bind_method(D_METHOD("get_collider_velocity"), &KinematicBody2D::get_collider_velocity);
+ ClassDB::bind_method(D_METHOD("get_collider:Variant"), &KinematicBody2D::_get_collider);
+ ClassDB::bind_method(D_METHOD("get_collider_shape"), &KinematicBody2D::get_collider_shape);
+ ClassDB::bind_method(D_METHOD("get_collider_metadata:Variant"), &KinematicBody2D::get_collider_metadata);
+ ClassDB::bind_method(D_METHOD("get_move_and_slide_colliders"), &KinematicBody2D::get_move_and_slide_colliders);
+ ClassDB::bind_method(D_METHOD("is_move_and_slide_on_floor"), &KinematicBody2D::is_move_and_slide_on_floor);
+ ClassDB::bind_method(D_METHOD("is_move_and_slide_on_ceiling"), &KinematicBody2D::is_move_and_slide_on_ceiling);
+ ClassDB::bind_method(D_METHOD("is_move_and_slide_on_wall"), &KinematicBody2D::is_move_and_slide_on_wall);
+ ClassDB::bind_method(D_METHOD("set_collision_margin", "pixels"), &KinematicBody2D::set_collision_margin);
+ ClassDB::bind_method(D_METHOD("get_collision_margin", "pixels"), &KinematicBody2D::get_collision_margin);
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "collision/margin", PROPERTY_HINT_RANGE, "0.001,256,0.001"), "set_collision_margin", "get_collision_margin");
}
-KinematicBody2D::KinematicBody2D() : PhysicsBody2D(Physics2DServer::BODY_MODE_KINEMATIC){
-
- colliding=false;
- collider=0;
+KinematicBody2D::KinematicBody2D()
+ : PhysicsBody2D(Physics2DServer::BODY_MODE_KINEMATIC) {
- collider_shape=0;
+ colliding = false;
+ collider = 0;
- margin=0.08;
+ collider_shape = 0;
- move_and_slide_on_floor=false;
- move_and_slide_on_ceiling=false;
- move_and_slide_on_wall=false;
+ margin = 0.08;
+ move_and_slide_on_floor = false;
+ move_and_slide_on_ceiling = false;
+ move_and_slide_on_wall = false;
}
-KinematicBody2D::~KinematicBody2D() {
-
-
+KinematicBody2D::~KinematicBody2D() {
}
-
diff --git a/scene/2d/physics_body_2d.h b/scene/2d/physics_body_2d.h
index 5b7db35fe8..e51b512302 100644
--- a/scene/2d/physics_body_2d.h
+++ b/scene/2d/physics_body_2d.h
@@ -33,57 +33,52 @@
#include "servers/physics_2d_server.h"
#include "vset.h"
-
class PhysicsBody2D : public CollisionObject2D {
- GDCLASS(PhysicsBody2D,CollisionObject2D);
+ GDCLASS(PhysicsBody2D, CollisionObject2D);
uint32_t mask;
uint32_t collision_mask;
Vector2 one_way_collision_direction;
float one_way_collision_max_depth;
-
void _set_layers(uint32_t p_mask);
uint32_t _get_layers() const;
protected:
-
void _notification(int p_what);
PhysicsBody2D(Physics2DServer::BodyMode p_mode);
static void _bind_methods();
-public:
+public:
void set_collision_layer(uint32_t p_mask);
uint32_t get_collision_layer() const;
void set_collision_mask(uint32_t p_mask);
uint32_t get_collision_mask() const;
-
void set_collision_mask_bit(int p_bit, bool p_value);
bool get_collision_mask_bit(int p_bit) const;
void set_collision_layer_bit(int p_bit, bool p_value);
bool get_collision_layer_bit(int p_bit) const;
- void add_collision_exception_with(Node* p_node); //must be physicsbody
- void remove_collision_exception_with(Node* p_node);
+ void add_collision_exception_with(Node *p_node); //must be physicsbody
+ void remove_collision_exception_with(Node *p_node);
- void set_one_way_collision_direction(const Vector2& p_dir);
+ void set_one_way_collision_direction(const Vector2 &p_dir);
Vector2 get_one_way_collision_direction() const;
void set_one_way_collision_max_depth(float p_dir);
float get_one_way_collision_max_depth() const;
PhysicsBody2D();
-
};
class StaticBody2D : public PhysicsBody2D {
- GDCLASS(StaticBody2D,PhysicsBody2D);
+ GDCLASS(StaticBody2D, PhysicsBody2D);
Vector2 constant_linear_velocity;
real_t constant_angular_velocity;
@@ -91,21 +86,17 @@ class StaticBody2D : public PhysicsBody2D {
real_t bounce;
real_t friction;
-
protected:
-
static void _bind_methods();
public:
-
void set_friction(real_t p_friction);
real_t get_friction() const;
void set_bounce(real_t p_bounce);
real_t get_bounce() const;
-
- void set_constant_linear_velocity(const Vector2& p_vel);
+ void set_constant_linear_velocity(const Vector2 &p_vel);
void set_constant_angular_velocity(real_t p_vel);
Vector2 get_constant_linear_velocity() const;
@@ -113,14 +104,13 @@ public:
StaticBody2D();
~StaticBody2D();
-
};
class RigidBody2D : public PhysicsBody2D {
- GDCLASS(RigidBody2D,PhysicsBody2D);
-public:
+ GDCLASS(RigidBody2D, PhysicsBody2D);
+public:
enum Mode {
MODE_RIGID,
MODE_STATIC,
@@ -135,7 +125,6 @@ public:
};
private:
-
bool can_sleep;
Physics2DDirectBodyState *state;
Mode mode;
@@ -151,35 +140,34 @@ private:
real_t angular_velocity;
bool sleeping;
-
int max_contacts_reported;
bool custom_integrator;
CCDMode ccd_mode;
-
struct ShapePair {
int body_shape;
int local_shape;
bool tagged;
- bool operator<(const ShapePair& p_sp) const {
- if (body_shape==p_sp.body_shape)
+ bool operator<(const ShapePair &p_sp) const {
+ if (body_shape == p_sp.body_shape)
return local_shape < p_sp.local_shape;
else
return body_shape < p_sp.body_shape;
}
ShapePair() {}
- ShapePair(int p_bs, int p_ls) { body_shape=p_bs; local_shape=p_ls; }
+ ShapePair(int p_bs, int p_ls) {
+ body_shape = p_bs;
+ local_shape = p_ls;
+ }
};
struct RigidBody2D_RemoveAction {
-
ObjectID body_id;
ShapePair pair;
-
};
struct BodyState {
@@ -191,26 +179,22 @@ private:
struct ContactMonitor {
bool locked;
- Map<ObjectID,BodyState> body_map;
-
+ Map<ObjectID, BodyState> body_map;
};
-
ContactMonitor *contact_monitor;
void _body_enter_tree(ObjectID p_id);
void _body_exit_tree(ObjectID p_id);
-
- void _body_inout(int p_status, ObjectID p_instance, int p_body_shape,int p_local_shape);
+ void _body_inout(int p_status, ObjectID p_instance, int p_body_shape, int p_local_shape);
void _direct_state_changed(Object *p_state);
- bool _test_motion(const Vector2& p_motion,float p_margin=0.08,const Ref<Physics2DTestMotionResult>& p_result=Ref<Physics2DTestMotionResult>());
+ bool _test_motion(const Vector2 &p_motion, float p_margin = 0.08, const Ref<Physics2DTestMotionResult> &p_result = Ref<Physics2DTestMotionResult>());
protected:
-
static void _bind_methods();
-public:
+public:
void set_mode(Mode p_mode);
Mode get_mode() const;
@@ -238,10 +222,10 @@ public:
void set_angular_damp(real_t p_angular_damp);
real_t get_angular_damp() const;
- void set_linear_velocity(const Vector2& p_velocity);
+ void set_linear_velocity(const Vector2 &p_velocity);
Vector2 get_linear_velocity() const;
- void set_axis_velocity(const Vector2& p_axis);
+ void set_axis_velocity(const Vector2 &p_axis);
void set_angular_velocity(real_t p_velocity);
real_t get_angular_velocity() const;
@@ -264,33 +248,28 @@ public:
void set_continuous_collision_detection_mode(CCDMode p_mode);
CCDMode get_continuous_collision_detection_mode() const;
- void apply_impulse(const Vector2& p_offset, const Vector2& p_impulse);
+ void apply_impulse(const Vector2 &p_offset, const Vector2 &p_impulse);
- void set_applied_force(const Vector2& p_force);
+ void set_applied_force(const Vector2 &p_force);
Vector2 get_applied_force() const;
void set_applied_torque(const float p_torque);
float get_applied_torque() const;
- void add_force(const Vector2& p_offset, const Vector2& p_force);
-
-
+ void add_force(const Vector2 &p_offset, const Vector2 &p_force);
Array get_colliding_bodies() const; //function for script
RigidBody2D();
~RigidBody2D();
-
};
VARIANT_ENUM_CAST(RigidBody2D::Mode);
VARIANT_ENUM_CAST(RigidBody2D::CCDMode);
-
-
class KinematicBody2D : public PhysicsBody2D {
- GDCLASS(KinematicBody2D,PhysicsBody2D);
+ GDCLASS(KinematicBody2D, PhysicsBody2D);
float margin;
bool colliding;
@@ -311,15 +290,15 @@ class KinematicBody2D : public PhysicsBody2D {
Variant _get_collider() const;
_FORCE_INLINE_ bool _ignores_mode(Physics2DServer::BodyMode) const;
-protected:
+protected:
static void _bind_methods();
-public:
- Vector2 move(const Vector2& p_motion);
- Vector2 move_to(const Vector2& p_position);
+public:
+ Vector2 move(const Vector2 &p_motion);
+ Vector2 move_to(const Vector2 &p_position);
- bool test_move(const Transform2D &p_from, const Vector2& p_motion);
+ bool test_move(const Transform2D &p_from, const Vector2 &p_motion);
bool is_colliding() const;
Vector2 get_travel() const;
@@ -335,17 +314,14 @@ public:
void set_collision_margin(float p_margin);
float get_collision_margin() const;
- Vector2 move_and_slide(const Vector2& p_linear_velocity, const Vector2& p_floor_direction=Vector2(0,0), float p_slope_stop_min_velocity=5, int p_max_bounces=4);
+ Vector2 move_and_slide(const Vector2 &p_linear_velocity, const Vector2 &p_floor_direction = Vector2(0, 0), float p_slope_stop_min_velocity = 5, int p_max_bounces = 4);
bool is_move_and_slide_on_floor() const;
bool is_move_and_slide_on_wall() const;
bool is_move_and_slide_on_ceiling() const;
Array get_move_and_slide_colliders() const;
-
KinematicBody2D();
~KinematicBody2D();
-
};
-
#endif // PHYSICS_BODY_2D_H
diff --git a/scene/2d/polygon_2d.cpp b/scene/2d/polygon_2d.cpp
index ec6729844b..1d54fd1538 100644
--- a/scene/2d/polygon_2d.cpp
+++ b/scene/2d/polygon_2d.cpp
@@ -30,29 +30,25 @@
Rect2 Polygon2D::get_item_rect() const {
-
- if (rect_cache_dirty){
- int l =polygon.size();
+ if (rect_cache_dirty) {
+ int l = polygon.size();
PoolVector<Vector2>::Read r = polygon.read();
- item_rect=Rect2();
- for(int i=0;i<l;i++) {
+ item_rect = Rect2();
+ for (int i = 0; i < l; i++) {
Vector2 pos = r[i] + offset;
- if (i==0)
- item_rect.pos=pos;
+ if (i == 0)
+ item_rect.pos = pos;
else
item_rect.expand_to(pos);
}
- item_rect=item_rect.grow(20);
- rect_cache_dirty=false;
+ item_rect = item_rect.grow(20);
+ rect_cache_dirty = false;
}
-
return item_rect;
-
-
}
-void Polygon2D::edit_set_pivot(const Point2& p_pivot) {
+void Polygon2D::edit_set_pivot(const Point2 &p_pivot) {
set_offset(p_pivot);
}
@@ -68,12 +64,11 @@ bool Polygon2D::edit_has_pivot() const {
void Polygon2D::_notification(int p_what) {
-
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_DRAW: {
- if (polygon.size()<3)
+ if (polygon.size() < 3)
return;
Vector<Vector2> points;
@@ -84,162 +79,155 @@ void Polygon2D::_notification(int p_what) {
int len = points.size();
{
- PoolVector<Vector2>::Read polyr =polygon.read();
- for(int i=0;i<len;i++) {
- points[i]=polyr[i]+offset;
+ PoolVector<Vector2>::Read polyr = polygon.read();
+ for (int i = 0; i < len; i++) {
+ points[i] = polyr[i] + offset;
}
}
if (invert) {
Rect2 bounds;
- int highest_idx=-1;
- float highest_y=-1e20;
- float sum=0;
+ int highest_idx = -1;
+ float highest_y = -1e20;
+ float sum = 0;
- for(int i=0;i<len;i++) {
- if (i==0)
- bounds.pos=points[i];
+ for (int i = 0; i < len; i++) {
+ if (i == 0)
+ bounds.pos = points[i];
else
bounds.expand_to(points[i]);
- if (points[i].y>highest_y) {
- highest_idx=i;
- highest_y=points[i].y;
+ if (points[i].y > highest_y) {
+ highest_idx = i;
+ highest_y = points[i].y;
}
- int ni=(i+1)%len;
- sum+=(points[ni].x-points[i].x)*(points[ni].y+points[i].y);
+ int ni = (i + 1) % len;
+ sum += (points[ni].x - points[i].x) * (points[ni].y + points[i].y);
}
- bounds=bounds.grow(invert_border);
+ bounds = bounds.grow(invert_border);
- Vector2 ep[7]={
- Vector2(points[highest_idx].x,points[highest_idx].y+invert_border),
- Vector2(bounds.pos+bounds.size),
- Vector2(bounds.pos+Vector2(bounds.size.x,0)),
+ Vector2 ep[7] = {
+ Vector2(points[highest_idx].x, points[highest_idx].y + invert_border),
+ Vector2(bounds.pos + bounds.size),
+ Vector2(bounds.pos + Vector2(bounds.size.x, 0)),
Vector2(bounds.pos),
- Vector2(bounds.pos+Vector2(0,bounds.size.y)),
- Vector2(points[highest_idx].x-CMP_EPSILON,points[highest_idx].y+invert_border),
- Vector2(points[highest_idx].x-CMP_EPSILON,points[highest_idx].y),
+ Vector2(bounds.pos + Vector2(0, bounds.size.y)),
+ Vector2(points[highest_idx].x - CMP_EPSILON, points[highest_idx].y + invert_border),
+ Vector2(points[highest_idx].x - CMP_EPSILON, points[highest_idx].y),
};
-
- if (sum>0) {
- SWAP(ep[1],ep[4]);
- SWAP(ep[2],ep[3]);
- SWAP(ep[5],ep[0]);
- SWAP(ep[6],points[highest_idx]);
+ if (sum > 0) {
+ SWAP(ep[1], ep[4]);
+ SWAP(ep[2], ep[3]);
+ SWAP(ep[5], ep[0]);
+ SWAP(ep[6], points[highest_idx]);
}
- points.resize(points.size()+7);
- for(int i=points.size()-1;i>=highest_idx+7;i--) {
+ points.resize(points.size() + 7);
+ for (int i = points.size() - 1; i >= highest_idx + 7; i--) {
- points[i]=points[i-7];
+ points[i] = points[i - 7];
}
- for(int i=0;i<7;i++) {
+ for (int i = 0; i < 7; i++) {
- points[highest_idx+i+1]=ep[i];
+ points[highest_idx + i + 1] = ep[i];
}
-
- len=points.size();
-
+ len = points.size();
}
if (texture.is_valid()) {
- Transform2D texmat(tex_rot,tex_ofs);
+ Transform2D texmat(tex_rot, tex_ofs);
texmat.scale(tex_scale);
- Size2 tex_size=Vector2(1,1);
+ Size2 tex_size = Vector2(1, 1);
- tex_size=texture->get_size();
+ tex_size = texture->get_size();
uvs.resize(points.size());
- if (points.size()==uv.size()) {
+ if (points.size() == uv.size()) {
PoolVector<Vector2>::Read uvr = uv.read();
- for(int i=0;i<len;i++) {
- uvs[i]=texmat.xform(uvr[i])/tex_size;
+ for (int i = 0; i < len; i++) {
+ uvs[i] = texmat.xform(uvr[i]) / tex_size;
}
} else {
- for(int i=0;i<len;i++) {
- uvs[i]=texmat.xform(points[i])/tex_size;
+ for (int i = 0; i < len; i++) {
+ uvs[i] = texmat.xform(points[i]) / tex_size;
}
}
-
}
-
Vector<Color> colors;
- int color_len=vertex_colors.size();
+ int color_len = vertex_colors.size();
colors.resize(len);
{
- PoolVector<Color>::Read color_r=vertex_colors.read();
- for(int i=0;i<color_len && i<len;i++){
- colors[i]=color_r[i];
+ PoolVector<Color>::Read color_r = vertex_colors.read();
+ for (int i = 0; i < color_len && i < len; i++) {
+ colors[i] = color_r[i];
}
- for(int i=color_len;i<len;i++){
- colors[i]=color;
+ for (int i = color_len; i < len; i++) {
+ colors[i] = color;
}
}
Vector<int> indices = Geometry::triangulate_polygon(points);
- VS::get_singleton()->canvas_item_add_triangle_array(get_canvas_item(),indices,points,colors,uvs,texture.is_valid()?texture->get_rid():RID());
+ VS::get_singleton()->canvas_item_add_triangle_array(get_canvas_item(), indices, points, colors, uvs, texture.is_valid() ? texture->get_rid() : RID());
} break;
}
}
-
-void Polygon2D::set_polygon(const PoolVector<Vector2>& p_polygon) {
- polygon=p_polygon;
- rect_cache_dirty=true;
+void Polygon2D::set_polygon(const PoolVector<Vector2> &p_polygon) {
+ polygon = p_polygon;
+ rect_cache_dirty = true;
update();
}
-PoolVector<Vector2> Polygon2D::get_polygon() const{
+PoolVector<Vector2> Polygon2D::get_polygon() const {
return polygon;
}
+void Polygon2D::set_uv(const PoolVector<Vector2> &p_uv) {
-void Polygon2D::set_uv(const PoolVector<Vector2>& p_uv) {
-
- uv=p_uv;
+ uv = p_uv;
update();
}
-PoolVector<Vector2> Polygon2D::get_uv() const{
+PoolVector<Vector2> Polygon2D::get_uv() const {
return uv;
}
-void Polygon2D::set_color(const Color& p_color){
+void Polygon2D::set_color(const Color &p_color) {
- color=p_color;
+ color = p_color;
update();
}
-Color Polygon2D::get_color() const{
+Color Polygon2D::get_color() const {
return color;
}
-void Polygon2D::set_vertex_colors(const PoolVector<Color>& p_colors){
+void Polygon2D::set_vertex_colors(const PoolVector<Color> &p_colors) {
- vertex_colors=p_colors;
+ vertex_colors = p_colors;
update();
}
-PoolVector<Color> Polygon2D::get_vertex_colors() const{
+PoolVector<Color> Polygon2D::get_vertex_colors() const {
return vertex_colors;
}
-void Polygon2D::set_texture(const Ref<Texture>& p_texture){
+void Polygon2D::set_texture(const Ref<Texture> &p_texture) {
- texture=p_texture;
+ texture = p_texture;
/*if (texture.is_valid()) {
uint32_t flags=texture->get_flags();
@@ -251,77 +239,74 @@ void Polygon2D::set_texture(const Ref<Texture>& p_texture){
}*/
update();
}
-Ref<Texture> Polygon2D::get_texture() const{
+Ref<Texture> Polygon2D::get_texture() const {
return texture;
}
+void Polygon2D::set_texture_offset(const Vector2 &p_offset) {
-void Polygon2D::set_texture_offset(const Vector2& p_offset){
-
- tex_ofs=p_offset;
+ tex_ofs = p_offset;
update();
}
-Vector2 Polygon2D::get_texture_offset() const{
+Vector2 Polygon2D::get_texture_offset() const {
return tex_ofs;
}
-void Polygon2D::set_texture_rotation(float p_rot){
+void Polygon2D::set_texture_rotation(float p_rot) {
- tex_rot=p_rot;
+ tex_rot = p_rot;
update();
}
-float Polygon2D::get_texture_rotation() const{
+float Polygon2D::get_texture_rotation() const {
return tex_rot;
}
-
-void Polygon2D::_set_texture_rotationd(float p_rot){
+void Polygon2D::_set_texture_rotationd(float p_rot) {
set_texture_rotation(Math::deg2rad(p_rot));
}
-float Polygon2D::_get_texture_rotationd() const{
+float Polygon2D::_get_texture_rotationd() const {
return Math::rad2deg(get_texture_rotation());
}
+void Polygon2D::set_texture_scale(const Size2 &p_scale) {
-void Polygon2D::set_texture_scale(const Size2& p_scale){
-
- tex_scale=p_scale;
+ tex_scale = p_scale;
update();
}
-Size2 Polygon2D::get_texture_scale() const{
+Size2 Polygon2D::get_texture_scale() const {
return tex_scale;
}
-void Polygon2D::set_invert(bool p_invert){
+void Polygon2D::set_invert(bool p_invert) {
- invert=p_invert;
+ invert = p_invert;
update();
}
-bool Polygon2D::get_invert() const{
+bool Polygon2D::get_invert() const {
return invert;
}
-void Polygon2D::set_invert_border(float p_invert_border){
+void Polygon2D::set_invert_border(float p_invert_border) {
- invert_border=p_invert_border;
+ invert_border = p_invert_border;
update();
}
-float Polygon2D::get_invert_border() const{
+float Polygon2D::get_invert_border() const {
return invert_border;
}
-void Polygon2D::set_offset(const Vector2& p_offset) {
+void Polygon2D::set_offset(const Vector2 &p_offset) {
- offset=p_offset;
- rect_cache_dirty=true;
+ offset = p_offset;
+ rect_cache_dirty = true;
update();
}
@@ -330,73 +315,68 @@ Vector2 Polygon2D::get_offset() const {
return offset;
}
-
void Polygon2D::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_polygon","polygon"),&Polygon2D::set_polygon);
- ClassDB::bind_method(D_METHOD("get_polygon"),&Polygon2D::get_polygon);
-
- ClassDB::bind_method(D_METHOD("set_uv","uv"),&Polygon2D::set_uv);
- ClassDB::bind_method(D_METHOD("get_uv"),&Polygon2D::get_uv);
-
- ClassDB::bind_method(D_METHOD("set_color","color"),&Polygon2D::set_color);
- ClassDB::bind_method(D_METHOD("get_color"),&Polygon2D::get_color);
-
- ClassDB::bind_method(D_METHOD("set_vertex_colors","vertex_colors"),&Polygon2D::set_vertex_colors);
- ClassDB::bind_method(D_METHOD("get_vertex_colors"),&Polygon2D::get_vertex_colors);
-
- ClassDB::bind_method(D_METHOD("set_texture","texture"),&Polygon2D::set_texture);
- ClassDB::bind_method(D_METHOD("get_texture"),&Polygon2D::get_texture);
+ ClassDB::bind_method(D_METHOD("set_polygon", "polygon"), &Polygon2D::set_polygon);
+ ClassDB::bind_method(D_METHOD("get_polygon"), &Polygon2D::get_polygon);
- ClassDB::bind_method(D_METHOD("set_texture_offset","texture_offset"),&Polygon2D::set_texture_offset);
- ClassDB::bind_method(D_METHOD("get_texture_offset"),&Polygon2D::get_texture_offset);
+ ClassDB::bind_method(D_METHOD("set_uv", "uv"), &Polygon2D::set_uv);
+ ClassDB::bind_method(D_METHOD("get_uv"), &Polygon2D::get_uv);
- ClassDB::bind_method(D_METHOD("set_texture_rotation","texture_rotation"),&Polygon2D::set_texture_rotation);
- ClassDB::bind_method(D_METHOD("get_texture_rotation"),&Polygon2D::get_texture_rotation);
+ ClassDB::bind_method(D_METHOD("set_color", "color"), &Polygon2D::set_color);
+ ClassDB::bind_method(D_METHOD("get_color"), &Polygon2D::get_color);
- ClassDB::bind_method(D_METHOD("_set_texture_rotationd","texture_rotation"),&Polygon2D::_set_texture_rotationd);
- ClassDB::bind_method(D_METHOD("_get_texture_rotationd"),&Polygon2D::_get_texture_rotationd);
+ ClassDB::bind_method(D_METHOD("set_vertex_colors", "vertex_colors"), &Polygon2D::set_vertex_colors);
+ ClassDB::bind_method(D_METHOD("get_vertex_colors"), &Polygon2D::get_vertex_colors);
- ClassDB::bind_method(D_METHOD("set_texture_scale","texture_scale"),&Polygon2D::set_texture_scale);
- ClassDB::bind_method(D_METHOD("get_texture_scale"),&Polygon2D::get_texture_scale);
+ ClassDB::bind_method(D_METHOD("set_texture", "texture"), &Polygon2D::set_texture);
+ ClassDB::bind_method(D_METHOD("get_texture"), &Polygon2D::get_texture);
+ ClassDB::bind_method(D_METHOD("set_texture_offset", "texture_offset"), &Polygon2D::set_texture_offset);
+ ClassDB::bind_method(D_METHOD("get_texture_offset"), &Polygon2D::get_texture_offset);
- ClassDB::bind_method(D_METHOD("set_invert","invert"),&Polygon2D::set_invert);
- ClassDB::bind_method(D_METHOD("get_invert"),&Polygon2D::get_invert);
+ ClassDB::bind_method(D_METHOD("set_texture_rotation", "texture_rotation"), &Polygon2D::set_texture_rotation);
+ ClassDB::bind_method(D_METHOD("get_texture_rotation"), &Polygon2D::get_texture_rotation);
- ClassDB::bind_method(D_METHOD("set_invert_border","invert_border"),&Polygon2D::set_invert_border);
- ClassDB::bind_method(D_METHOD("get_invert_border"),&Polygon2D::get_invert_border);
+ ClassDB::bind_method(D_METHOD("_set_texture_rotationd", "texture_rotation"), &Polygon2D::_set_texture_rotationd);
+ ClassDB::bind_method(D_METHOD("_get_texture_rotationd"), &Polygon2D::_get_texture_rotationd);
- ClassDB::bind_method(D_METHOD("set_offset","offset"),&Polygon2D::set_offset);
- ClassDB::bind_method(D_METHOD("get_offset"),&Polygon2D::get_offset);
+ ClassDB::bind_method(D_METHOD("set_texture_scale", "texture_scale"), &Polygon2D::set_texture_scale);
+ ClassDB::bind_method(D_METHOD("get_texture_scale"), &Polygon2D::get_texture_scale);
+ ClassDB::bind_method(D_METHOD("set_invert", "invert"), &Polygon2D::set_invert);
+ ClassDB::bind_method(D_METHOD("get_invert"), &Polygon2D::get_invert);
+ ClassDB::bind_method(D_METHOD("set_invert_border", "invert_border"), &Polygon2D::set_invert_border);
+ ClassDB::bind_method(D_METHOD("get_invert_border"), &Polygon2D::get_invert_border);
- ADD_PROPERTY( PropertyInfo(Variant::POOL_VECTOR2_ARRAY,"polygon"),"set_polygon","get_polygon");
- ADD_PROPERTY( PropertyInfo(Variant::POOL_VECTOR2_ARRAY,"uv"),"set_uv","get_uv");
- ADD_PROPERTY( PropertyInfo(Variant::COLOR,"color"),"set_color","get_color");
- ADD_PROPERTY( PropertyInfo(Variant::POOL_COLOR_ARRAY,"vertex_colors"),"set_vertex_colors","get_vertex_colors");
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"offset"),"set_offset","get_offset");
- ADD_GROUP("Texture","");
- ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"texture",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),"set_texture","get_texture");
- ADD_GROUP("Texture","texture_");
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"texture_offset"),"set_texture_offset","get_texture_offset");
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"texture_scale"),"set_texture_scale","get_texture_scale");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"texture_rotation",PROPERTY_HINT_RANGE,"-1440,1440,0.1"),"_set_texture_rotationd","_get_texture_rotationd");
+ ClassDB::bind_method(D_METHOD("set_offset", "offset"), &Polygon2D::set_offset);
+ ClassDB::bind_method(D_METHOD("get_offset"), &Polygon2D::get_offset);
- ADD_GROUP("Invert","invert_");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"invert_enable"),"set_invert","get_invert");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"invert_border",PROPERTY_HINT_RANGE,"0.1,16384,0.1"),"set_invert_border","get_invert_border");
+ ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR2_ARRAY, "polygon"), "set_polygon", "get_polygon");
+ ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR2_ARRAY, "uv"), "set_uv", "get_uv");
+ ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color");
+ ADD_PROPERTY(PropertyInfo(Variant::POOL_COLOR_ARRAY, "vertex_colors"), "set_vertex_colors", "get_vertex_colors");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset"), "set_offset", "get_offset");
+ ADD_GROUP("Texture", "");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture");
+ ADD_GROUP("Texture", "texture_");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "texture_offset"), "set_texture_offset", "get_texture_offset");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "texture_scale"), "set_texture_scale", "get_texture_scale");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "texture_rotation", PROPERTY_HINT_RANGE, "-1440,1440,0.1"), "_set_texture_rotationd", "_get_texture_rotationd");
+ ADD_GROUP("Invert", "invert_");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "invert_enable"), "set_invert", "get_invert");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "invert_border", PROPERTY_HINT_RANGE, "0.1,16384,0.1"), "set_invert_border", "get_invert_border");
}
Polygon2D::Polygon2D() {
- invert=0;
- invert_border=100;
- tex_rot=0;
- tex_tile=true;
- tex_scale=Vector2(1,1);
- color=Color(1,1,1);
- rect_cache_dirty=true;
+ invert = 0;
+ invert_border = 100;
+ tex_rot = 0;
+ tex_tile = true;
+ tex_scale = Vector2(1, 1);
+ color = Color(1, 1, 1);
+ rect_cache_dirty = true;
}
diff --git a/scene/2d/polygon_2d.h b/scene/2d/polygon_2d.h
index 8434dae40c..50968f3de4 100644
--- a/scene/2d/polygon_2d.h
+++ b/scene/2d/polygon_2d.h
@@ -33,7 +33,7 @@
class Polygon2D : public Node2D {
- GDCLASS(Polygon2D,Node2D);
+ GDCLASS(Polygon2D, Node2D);
PoolVector<Vector2> polygon;
PoolVector<Vector2> uv;
@@ -55,33 +55,32 @@ class Polygon2D : public Node2D {
float _get_texture_rotationd() const;
protected:
-
void _notification(int p_what);
static void _bind_methods();
-public:
- void set_polygon(const PoolVector<Vector2>& p_polygon);
+public:
+ void set_polygon(const PoolVector<Vector2> &p_polygon);
PoolVector<Vector2> get_polygon() const;
- void set_uv(const PoolVector<Vector2>& p_uv);
+ void set_uv(const PoolVector<Vector2> &p_uv);
PoolVector<Vector2> get_uv() const;
- void set_color(const Color& p_color);
+ void set_color(const Color &p_color);
Color get_color() const;
- void set_vertex_colors(const PoolVector<Color>& p_colors);
+ void set_vertex_colors(const PoolVector<Color> &p_colors);
PoolVector<Color> get_vertex_colors() const;
- void set_texture(const Ref<Texture>& p_texture);
+ void set_texture(const Ref<Texture> &p_texture);
Ref<Texture> get_texture() const;
- void set_texture_offset(const Vector2& p_offset);
+ void set_texture_offset(const Vector2 &p_offset);
Vector2 get_texture_offset() const;
void set_texture_rotation(float p_rot);
float get_texture_rotation() const;
- void set_texture_scale(const Size2& p_scale);
+ void set_texture_scale(const Size2 &p_scale);
Size2 get_texture_scale() const;
void set_invert(bool p_rot);
@@ -90,12 +89,12 @@ public:
void set_invert_border(float p_border);
float get_invert_border() const;
- void set_offset(const Vector2& p_offset);
+ void set_offset(const Vector2 &p_offset);
Vector2 get_offset() const;
//editor stuff
- virtual void edit_set_pivot(const Point2& p_pivot);
+ virtual void edit_set_pivot(const Point2 &p_pivot);
virtual Point2 edit_get_pivot() const;
virtual bool edit_has_pivot() const;
diff --git a/scene/2d/position_2d.cpp b/scene/2d/position_2d.cpp
index a25be18cb9..39fc6352e9 100644
--- a/scene/2d/position_2d.cpp
+++ b/scene/2d/position_2d.cpp
@@ -31,19 +31,18 @@
void Position2D::_draw_cross() {
- draw_line(Point2(-10,0),Point2(+10,0),Color(1,0.5,0.5));
- draw_line(Point2(0,-10),Point2(0,+10),Color(0.5,1,0.5));
-
+ draw_line(Point2(-10, 0), Point2(+10, 0), Color(1, 0.5, 0.5));
+ draw_line(Point2(0, -10), Point2(0, +10), Color(0.5, 1, 0.5));
}
Rect2 Position2D::get_item_rect() const {
- return Rect2(Point2(-10,-10),Size2(20,20));
+ return Rect2(Point2(-10, -10), Size2(20, 20));
}
void Position2D::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
@@ -57,9 +56,7 @@ void Position2D::_notification(int p_what) {
} break;
}
-
}
-Position2D::Position2D()
-{
+Position2D::Position2D() {
}
diff --git a/scene/2d/position_2d.h b/scene/2d/position_2d.h
index fb68c265b3..a9ead3d87f 100644
--- a/scene/2d/position_2d.h
+++ b/scene/2d/position_2d.h
@@ -29,19 +29,18 @@
#ifndef POSITION_2D_H
#define POSITION_2D_H
-
#include "scene/2d/node_2d.h"
class Position2D : public Node2D {
- GDCLASS(Position2D,Node2D)
+ GDCLASS(Position2D, Node2D)
void _draw_cross();
-protected:
+protected:
void _notification(int p_what);
-public:
+public:
virtual Rect2 get_item_rect() const;
Position2D();
};
diff --git a/scene/2d/ray_cast_2d.cpp b/scene/2d/ray_cast_2d.cpp
index 72247811dc..83a0717acf 100644
--- a/scene/2d/ray_cast_2d.cpp
+++ b/scene/2d/ray_cast_2d.cpp
@@ -27,26 +27,25 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "ray_cast_2d.h"
-#include "servers/physics_2d_server.h"
#include "collision_object_2d.h"
#include "physics_body_2d.h"
+#include "servers/physics_2d_server.h"
-void RayCast2D::set_cast_to(const Vector2& p_point) {
+void RayCast2D::set_cast_to(const Vector2 &p_point) {
- cast_to=p_point;
+ cast_to = p_point;
if (is_inside_tree() && (get_tree()->is_editor_hint() || get_tree()->is_debugging_collisions_hint()))
update();
-
}
-Vector2 RayCast2D::get_cast_to() const{
+Vector2 RayCast2D::get_cast_to() const {
return cast_to;
}
void RayCast2D::set_layer_mask(uint32_t p_mask) {
- layer_mask=p_mask;
+ layer_mask = p_mask;
}
uint32_t RayCast2D::get_layer_mask() const {
@@ -56,7 +55,7 @@ uint32_t RayCast2D::get_layer_mask() const {
void RayCast2D::set_type_mask(uint32_t p_mask) {
- type_mask=p_mask;
+ type_mask = p_mask;
}
uint32_t RayCast2D::get_type_mask() const {
@@ -64,13 +63,13 @@ uint32_t RayCast2D::get_type_mask() const {
return type_mask;
}
-bool RayCast2D::is_colliding() const{
+bool RayCast2D::is_colliding() const {
return collided;
}
-Object *RayCast2D::get_collider() const{
+Object *RayCast2D::get_collider() const {
- if (against==0)
+ if (against == 0)
return NULL;
return ObjectDB::get_instance(against);
@@ -80,61 +79,55 @@ int RayCast2D::get_collider_shape() const {
return against_shape;
}
-Vector2 RayCast2D::get_collision_point() const{
+Vector2 RayCast2D::get_collision_point() const {
return collision_point;
}
-Vector2 RayCast2D::get_collision_normal() const{
+Vector2 RayCast2D::get_collision_normal() const {
return collision_normal;
}
-
void RayCast2D::set_enabled(bool p_enabled) {
- enabled=p_enabled;
+ enabled = p_enabled;
if (is_inside_tree() && !get_tree()->is_editor_hint())
set_fixed_process(p_enabled);
if (!p_enabled)
- collided=false;
-
+ collided = false;
}
-
bool RayCast2D::is_enabled() const {
-
return enabled;
}
void RayCast2D::set_exclude_parent_body(bool p_exclude_parent_body) {
- if (exclude_parent_body==p_exclude_parent_body)
+ if (exclude_parent_body == p_exclude_parent_body)
return;
- exclude_parent_body=p_exclude_parent_body;
+ exclude_parent_body = p_exclude_parent_body;
if (!is_inside_tree())
return;
-
-
if (get_parent()->cast_to<PhysicsBody2D>()) {
if (exclude_parent_body)
- exclude.insert( get_parent()->cast_to<PhysicsBody2D>()->get_rid() );
+ exclude.insert(get_parent()->cast_to<PhysicsBody2D>()->get_rid());
else
- exclude.erase( get_parent()->cast_to<PhysicsBody2D>()->get_rid() );
+ exclude.erase(get_parent()->cast_to<PhysicsBody2D>()->get_rid());
}
}
-bool RayCast2D::get_exclude_parent_body() const{
+bool RayCast2D::get_exclude_parent_body() const {
return exclude_parent_body;
}
void RayCast2D::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
@@ -145,9 +138,9 @@ void RayCast2D::_notification(int p_what) {
if (get_parent()->cast_to<PhysicsBody2D>()) {
if (exclude_parent_body)
- exclude.insert( get_parent()->cast_to<PhysicsBody2D>()->get_rid() );
+ exclude.insert(get_parent()->cast_to<PhysicsBody2D>()->get_rid());
else
- exclude.erase( get_parent()->cast_to<PhysicsBody2D>()->get_rid() );
+ exclude.erase(get_parent()->cast_to<PhysicsBody2D>()->get_rid());
}
} break;
case NOTIFICATION_EXIT_TREE: {
@@ -159,29 +152,28 @@ void RayCast2D::_notification(int p_what) {
case NOTIFICATION_DRAW: {
- if (!get_tree()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint())
+ if (!get_tree()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint())
break;
Transform2D xf;
xf.rotate(cast_to.angle());
- xf.translate(Vector2(0,cast_to.length()));
+ xf.translate(Vector2(0, cast_to.length()));
//Vector2 tip = Vector2(0,s->get_length());
- Color dcol=get_tree()->get_debug_collisions_color();//0.9,0.2,0.2,0.4);
- draw_line(Vector2(),cast_to,dcol,3);
+ Color dcol = get_tree()->get_debug_collisions_color(); //0.9,0.2,0.2,0.4);
+ draw_line(Vector2(), cast_to, dcol, 3);
Vector<Vector2> pts;
- float tsize=4;
- pts.push_back(xf.xform(Vector2(0,tsize)));
- pts.push_back(xf.xform(Vector2(0.707*tsize,0)));
- pts.push_back(xf.xform(Vector2(-0.707*tsize,0)));
+ float tsize = 4;
+ pts.push_back(xf.xform(Vector2(0, tsize)));
+ pts.push_back(xf.xform(Vector2(0.707 * tsize, 0)));
+ pts.push_back(xf.xform(Vector2(-0.707 * tsize, 0)));
Vector<Color> cols;
- for(int i=0;i<3;i++)
+ for (int i = 0; i < 3; i++)
cols.push_back(dcol);
- draw_primitive(pts,cols,Vector<Vector2>()); //small arrow
+ draw_primitive(pts, cols, Vector<Vector2>()); //small arrow
} break;
-
case NOTIFICATION_FIXED_PROCESS: {
if (!enabled)
@@ -189,35 +181,34 @@ void RayCast2D::_notification(int p_what) {
_update_raycast_state();
-
} break;
}
}
void RayCast2D::_update_raycast_state() {
Ref<World2D> w2d = get_world_2d();
- ERR_FAIL_COND( w2d.is_null() );
+ ERR_FAIL_COND(w2d.is_null());
Physics2DDirectSpaceState *dss = Physics2DServer::get_singleton()->space_get_direct_state(w2d->get_space());
- ERR_FAIL_COND( !dss );
+ ERR_FAIL_COND(!dss);
Transform2D gt = get_global_transform();
Vector2 to = cast_to;
- if (to==Vector2())
- to=Vector2(0,0.01);
+ if (to == Vector2())
+ to = Vector2(0, 0.01);
Physics2DDirectSpaceState::RayResult rr;
- if (dss->intersect_ray(gt.get_origin(),gt.xform(to),rr,exclude,layer_mask,type_mask)) {
+ if (dss->intersect_ray(gt.get_origin(), gt.xform(to), rr, exclude, layer_mask, type_mask)) {
- collided=true;
- against=rr.collider_id;
- collision_point=rr.position;
- collision_normal=rr.normal;
- against_shape=rr.shape;
+ collided = true;
+ against = rr.collider_id;
+ collision_point = rr.position;
+ collision_normal = rr.normal;
+ against_shape = rr.shape;
} else {
- collided=false;
+ collided = false;
}
}
@@ -225,90 +216,87 @@ void RayCast2D::force_raycast_update() {
_update_raycast_state();
}
-void RayCast2D::add_exception_rid(const RID& p_rid) {
+void RayCast2D::add_exception_rid(const RID &p_rid) {
exclude.insert(p_rid);
}
-void RayCast2D::add_exception(const Object* p_object){
+void RayCast2D::add_exception(const Object *p_object) {
ERR_FAIL_NULL(p_object);
- CollisionObject2D *co=((Object*)p_object)->cast_to<CollisionObject2D>();
+ CollisionObject2D *co = ((Object *)p_object)->cast_to<CollisionObject2D>();
if (!co)
return;
add_exception_rid(co->get_rid());
}
-void RayCast2D::remove_exception_rid(const RID& p_rid) {
+void RayCast2D::remove_exception_rid(const RID &p_rid) {
exclude.erase(p_rid);
}
-void RayCast2D::remove_exception(const Object* p_object){
+void RayCast2D::remove_exception(const Object *p_object) {
ERR_FAIL_NULL(p_object);
- CollisionObject2D *co=((Object*)p_object)->cast_to<CollisionObject2D>();
+ CollisionObject2D *co = ((Object *)p_object)->cast_to<CollisionObject2D>();
if (!co)
return;
remove_exception_rid(co->get_rid());
}
-
-void RayCast2D::clear_exceptions(){
+void RayCast2D::clear_exceptions() {
exclude.clear();
}
-
void RayCast2D::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &RayCast2D::set_enabled);
+ ClassDB::bind_method(D_METHOD("is_enabled"), &RayCast2D::is_enabled);
- ClassDB::bind_method(D_METHOD("set_enabled","enabled"),&RayCast2D::set_enabled);
- ClassDB::bind_method(D_METHOD("is_enabled"),&RayCast2D::is_enabled);
-
- ClassDB::bind_method(D_METHOD("set_cast_to","local_point"),&RayCast2D::set_cast_to);
- ClassDB::bind_method(D_METHOD("get_cast_to"),&RayCast2D::get_cast_to);
+ ClassDB::bind_method(D_METHOD("set_cast_to", "local_point"), &RayCast2D::set_cast_to);
+ ClassDB::bind_method(D_METHOD("get_cast_to"), &RayCast2D::get_cast_to);
- ClassDB::bind_method(D_METHOD("is_colliding"),&RayCast2D::is_colliding);
- ClassDB::bind_method(D_METHOD("force_raycast_update"),&RayCast2D::force_raycast_update);
+ ClassDB::bind_method(D_METHOD("is_colliding"), &RayCast2D::is_colliding);
+ ClassDB::bind_method(D_METHOD("force_raycast_update"), &RayCast2D::force_raycast_update);
- ClassDB::bind_method(D_METHOD("get_collider"),&RayCast2D::get_collider);
- ClassDB::bind_method(D_METHOD("get_collider_shape"),&RayCast2D::get_collider_shape);
- ClassDB::bind_method(D_METHOD("get_collision_point"),&RayCast2D::get_collision_point);
- ClassDB::bind_method(D_METHOD("get_collision_normal"),&RayCast2D::get_collision_normal);
+ ClassDB::bind_method(D_METHOD("get_collider"), &RayCast2D::get_collider);
+ ClassDB::bind_method(D_METHOD("get_collider_shape"), &RayCast2D::get_collider_shape);
+ ClassDB::bind_method(D_METHOD("get_collision_point"), &RayCast2D::get_collision_point);
+ ClassDB::bind_method(D_METHOD("get_collision_normal"), &RayCast2D::get_collision_normal);
- ClassDB::bind_method(D_METHOD("add_exception_rid","rid"),&RayCast2D::add_exception_rid);
- ClassDB::bind_method(D_METHOD("add_exception","node"),&RayCast2D::add_exception);
+ ClassDB::bind_method(D_METHOD("add_exception_rid", "rid"), &RayCast2D::add_exception_rid);
+ ClassDB::bind_method(D_METHOD("add_exception", "node"), &RayCast2D::add_exception);
- ClassDB::bind_method(D_METHOD("remove_exception_rid","rid"),&RayCast2D::remove_exception_rid);
- ClassDB::bind_method(D_METHOD("remove_exception","node"),&RayCast2D::remove_exception);
+ ClassDB::bind_method(D_METHOD("remove_exception_rid", "rid"), &RayCast2D::remove_exception_rid);
+ ClassDB::bind_method(D_METHOD("remove_exception", "node"), &RayCast2D::remove_exception);
- ClassDB::bind_method(D_METHOD("clear_exceptions"),&RayCast2D::clear_exceptions);
+ ClassDB::bind_method(D_METHOD("clear_exceptions"), &RayCast2D::clear_exceptions);
- ClassDB::bind_method(D_METHOD("set_layer_mask","mask"),&RayCast2D::set_layer_mask);
- ClassDB::bind_method(D_METHOD("get_layer_mask"),&RayCast2D::get_layer_mask);
+ ClassDB::bind_method(D_METHOD("set_layer_mask", "mask"), &RayCast2D::set_layer_mask);
+ ClassDB::bind_method(D_METHOD("get_layer_mask"), &RayCast2D::get_layer_mask);
- ClassDB::bind_method(D_METHOD("set_type_mask","mask"),&RayCast2D::set_type_mask);
- ClassDB::bind_method(D_METHOD("get_type_mask"),&RayCast2D::get_type_mask);
+ ClassDB::bind_method(D_METHOD("set_type_mask", "mask"), &RayCast2D::set_type_mask);
+ ClassDB::bind_method(D_METHOD("get_type_mask"), &RayCast2D::get_type_mask);
- ClassDB::bind_method(D_METHOD("set_exclude_parent_body","mask"),&RayCast2D::set_exclude_parent_body);
- ClassDB::bind_method(D_METHOD("get_exclude_parent_body"),&RayCast2D::get_exclude_parent_body);
+ ClassDB::bind_method(D_METHOD("set_exclude_parent_body", "mask"), &RayCast2D::set_exclude_parent_body);
+ ClassDB::bind_method(D_METHOD("get_exclude_parent_body"), &RayCast2D::get_exclude_parent_body);
- ADD_PROPERTY(PropertyInfo(Variant::BOOL,"enabled"),"set_enabled","is_enabled");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL,"exclude_parent"),"set_exclude_parent_body","get_exclude_parent_body");
- ADD_PROPERTY(PropertyInfo(Variant::VECTOR2,"cast_to"),"set_cast_to","get_cast_to");
- ADD_PROPERTY(PropertyInfo(Variant::INT,"layer_mask",PROPERTY_HINT_LAYERS_2D_PHYSICS),"set_layer_mask","get_layer_mask");
- ADD_PROPERTY(PropertyInfo(Variant::INT,"type_mask",PROPERTY_HINT_FLAGS,"Static,Kinematic,Rigid,Character,Area"),"set_type_mask","get_type_mask");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "enabled"), "set_enabled", "is_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "exclude_parent"), "set_exclude_parent_body", "get_exclude_parent_body");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "cast_to"), "set_cast_to", "get_cast_to");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "layer_mask", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_layer_mask", "get_layer_mask");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "type_mask", PROPERTY_HINT_FLAGS, "Static,Kinematic,Rigid,Character,Area"), "set_type_mask", "get_type_mask");
}
RayCast2D::RayCast2D() {
- enabled=false;
- against=0;
- collided=false;
- against_shape=0;
- layer_mask=1;
- type_mask=Physics2DDirectSpaceState::TYPE_MASK_COLLISION;
- cast_to=Vector2(0,50);
- exclude_parent_body=true;
+ enabled = false;
+ against = 0;
+ collided = false;
+ against_shape = 0;
+ layer_mask = 1;
+ type_mask = Physics2DDirectSpaceState::TYPE_MASK_COLLISION;
+ cast_to = Vector2(0, 50);
+ exclude_parent_body = true;
}
diff --git a/scene/2d/ray_cast_2d.h b/scene/2d/ray_cast_2d.h
index 3e7a39ffde..6a59ef963b 100644
--- a/scene/2d/ray_cast_2d.h
+++ b/scene/2d/ray_cast_2d.h
@@ -33,8 +33,7 @@
class RayCast2D : public Node2D {
- GDCLASS(RayCast2D,Node2D);
-
+ GDCLASS(RayCast2D, Node2D);
bool enabled;
bool collided;
@@ -47,19 +46,18 @@ class RayCast2D : public Node2D {
uint32_t type_mask;
bool exclude_parent_body;
-
Vector2 cast_to;
-protected:
+protected:
void _notification(int p_what);
void _update_raycast_state();
static void _bind_methods();
-public:
+public:
void set_enabled(bool p_enabled);
bool is_enabled() const;
- void set_cast_to(const Vector2& p_point);
+ void set_cast_to(const Vector2 &p_point);
Vector2 get_cast_to() const;
void set_layer_mask(uint32_t p_mask);
@@ -79,10 +77,10 @@ public:
Vector2 get_collision_point() const;
Vector2 get_collision_normal() const;
- void add_exception_rid(const RID& p_rid);
- void add_exception(const Object* p_object);
- void remove_exception_rid(const RID& p_rid);
- void remove_exception(const Object* p_object);
+ void add_exception_rid(const RID &p_rid);
+ void add_exception(const Object *p_object);
+ void remove_exception_rid(const RID &p_rid);
+ void remove_exception(const Object *p_object);
void clear_exceptions();
RayCast2D();
diff --git a/scene/2d/remote_transform_2d.cpp b/scene/2d/remote_transform_2d.cpp
index e1f360c0c1..210f64ae23 100644
--- a/scene/2d/remote_transform_2d.cpp
+++ b/scene/2d/remote_transform_2d.cpp
@@ -31,20 +31,19 @@
void RemoteTransform2D::_update_cache() {
- cache=0;
+ cache = 0;
if (has_node(remote_node)) {
Node *node = get_node(remote_node);
- if (!node || this==node || node->is_a_parent_of(this) || this->is_a_parent_of(node)) {
+ if (!node || this == node || node->is_a_parent_of(this) || this->is_a_parent_of(node)) {
return;
}
- cache=node->get_instance_ID();
+ cache = node->get_instance_ID();
}
}
void RemoteTransform2D::_update_remote() {
-
if (!is_inside_tree())
return;
@@ -62,14 +61,13 @@ void RemoteTransform2D::_update_remote() {
if (!n->is_inside_tree())
return;
- //todo make faster
+ //todo make faster
n->set_global_transform(get_global_transform());
-
}
void RemoteTransform2D::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_READY: {
@@ -83,30 +81,26 @@ void RemoteTransform2D::_notification(int p_what) {
if (cache) {
_update_remote();
-
}
} break;
-
}
}
+void RemoteTransform2D::set_remote_node(const NodePath &p_remote_node) {
-void RemoteTransform2D::set_remote_node(const NodePath& p_remote_node) {
-
- remote_node=p_remote_node;
+ remote_node = p_remote_node;
if (is_inside_tree())
_update_cache();
update_configuration_warning();
}
-NodePath RemoteTransform2D::get_remote_node() const{
+NodePath RemoteTransform2D::get_remote_node() const {
return remote_node;
}
-
String RemoteTransform2D::get_configuration_warning() const {
if (!has_node(remote_node) || !get_node(remote_node) || !get_node(remote_node)->cast_to<Node2D>()) {
@@ -118,16 +112,14 @@ String RemoteTransform2D::get_configuration_warning() const {
void RemoteTransform2D::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_remote_node","path"),&RemoteTransform2D::set_remote_node);
- ClassDB::bind_method(D_METHOD("get_remote_node"),&RemoteTransform2D::get_remote_node);
+ ClassDB::bind_method(D_METHOD("set_remote_node", "path"), &RemoteTransform2D::set_remote_node);
+ ClassDB::bind_method(D_METHOD("get_remote_node"), &RemoteTransform2D::get_remote_node);
- ADD_PROPERTY( PropertyInfo(Variant::NODE_PATH,"remote_path"),"set_remote_node","get_remote_node");
+ ADD_PROPERTY(PropertyInfo(Variant::NODE_PATH, "remote_path"), "set_remote_node", "get_remote_node");
}
RemoteTransform2D::RemoteTransform2D() {
- cache=0;
+ cache = 0;
set_notify_transform(true);
}
-
-
diff --git a/scene/2d/remote_transform_2d.h b/scene/2d/remote_transform_2d.h
index 52c28ffd4f..aa1b214314 100644
--- a/scene/2d/remote_transform_2d.h
+++ b/scene/2d/remote_transform_2d.h
@@ -30,7 +30,7 @@
class RemoteTransform2D : public Node2D {
- GDCLASS(RemoteTransform2D,Node2D);
+ GDCLASS(RemoteTransform2D, Node2D);
NodePath remote_node;
@@ -40,12 +40,11 @@ class RemoteTransform2D : public Node2D {
void _update_cache();
//void _node_exited_scene();
protected:
-
static void _bind_methods();
void _notification(int p_what);
-public:
- void set_remote_node(const NodePath& p_remote_node);
+public:
+ void set_remote_node(const NodePath &p_remote_node);
NodePath get_remote_node() const;
virtual String get_configuration_warning() const;
diff --git a/scene/2d/screen_button.cpp b/scene/2d/screen_button.cpp
index 4b607e9261..9b9fa6cfa8 100644
--- a/scene/2d/screen_button.cpp
+++ b/scene/2d/screen_button.cpp
@@ -27,45 +27,45 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
#include "screen_button.h"
-#include "os/os.h"
#include "input_map.h"
#include "os/input.h"
+#include "os/os.h"
-void TouchScreenButton::set_texture(const Ref<Texture>& p_texture) {
+void TouchScreenButton::set_texture(const Ref<Texture> &p_texture) {
- texture=p_texture;
+ texture = p_texture;
update();
}
-Ref<Texture> TouchScreenButton::get_texture() const{
+Ref<Texture> TouchScreenButton::get_texture() const {
return texture;
}
-void TouchScreenButton::set_texture_pressed(const Ref<Texture>& p_texture_pressed) {
+void TouchScreenButton::set_texture_pressed(const Ref<Texture> &p_texture_pressed) {
- texture_pressed=p_texture_pressed;
+ texture_pressed = p_texture_pressed;
update();
}
-Ref<Texture> TouchScreenButton::get_texture_pressed() const{
+Ref<Texture> TouchScreenButton::get_texture_pressed() const {
return texture_pressed;
}
-void TouchScreenButton::set_bitmask(const Ref<BitMap>& p_bitmask){
+void TouchScreenButton::set_bitmask(const Ref<BitMap> &p_bitmask) {
- bitmask=p_bitmask;
+ bitmask = p_bitmask;
}
-Ref<BitMap> TouchScreenButton::get_bitmask() const{
+Ref<BitMap> TouchScreenButton::get_bitmask() const {
return bitmask;
}
-void TouchScreenButton::set_shape(const Ref<Shape2D>& p_shape){
+void TouchScreenButton::set_shape(const Ref<Shape2D> &p_shape) {
- shape=p_shape;
+ shape = p_shape;
if (!is_inside_tree())
return;
@@ -74,14 +74,14 @@ void TouchScreenButton::set_shape(const Ref<Shape2D>& p_shape){
update();
}
-Ref<Shape2D> TouchScreenButton::get_shape() const{
+Ref<Shape2D> TouchScreenButton::get_shape() const {
return shape;
}
void TouchScreenButton::set_shape_centered(bool p_shape_centered) {
- shape_centered=p_shape_centered;
+ shape_centered = p_shape_centered;
if (!is_inside_tree())
return;
@@ -97,50 +97,50 @@ bool TouchScreenButton::is_shape_centered() const {
void TouchScreenButton::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_DRAW: {
if (!is_inside_tree())
return;
- if (!get_tree()->is_editor_hint() && !OS::get_singleton()->has_touchscreen_ui_hint() && visibility==VISIBILITY_TOUCHSCREEN_ONLY)
+ if (!get_tree()->is_editor_hint() && !OS::get_singleton()->has_touchscreen_ui_hint() && visibility == VISIBILITY_TOUCHSCREEN_ONLY)
return;
- if (finger_pressed!=-1) {
+ if (finger_pressed != -1) {
if (texture_pressed.is_valid())
- draw_texture(texture_pressed,Point2());
+ draw_texture(texture_pressed, Point2());
else if (texture.is_valid())
- draw_texture(texture,Point2());
+ draw_texture(texture, Point2());
} else {
if (texture.is_valid())
- draw_texture(texture,Point2());
+ draw_texture(texture, Point2());
}
if (!get_tree()->is_editor_hint() && !get_tree()->is_debugging_collisions_hint())
return;
if (shape.is_valid()) {
- Color draw_col=get_tree()->get_debug_collisions_color();
- Vector2 pos=shape_centered ? get_item_rect().size*0.5f : Vector2();
+ Color draw_col = get_tree()->get_debug_collisions_color();
+ Vector2 pos = shape_centered ? get_item_rect().size * 0.5f : Vector2();
draw_set_transform_matrix(get_canvas_transform().translated(pos));
- shape->draw(get_canvas_item(),draw_col);
+ shape->draw(get_canvas_item(), draw_col);
}
} break;
case NOTIFICATION_ENTER_TREE: {
- if (!get_tree()->is_editor_hint() && !OS::get_singleton()->has_touchscreen_ui_hint() && visibility==VISIBILITY_TOUCHSCREEN_ONLY)
+ if (!get_tree()->is_editor_hint() && !OS::get_singleton()->has_touchscreen_ui_hint() && visibility == VISIBILITY_TOUCHSCREEN_ONLY)
return;
update();
if (!get_tree()->is_editor_hint())
set_process_input(true);
- if (action.operator String()!="" && InputMap::get_singleton()->has_action(action)) {
- action_id=InputMap::get_singleton()->get_action_id(action);
+ if (action.operator String() != "" && InputMap::get_singleton()->has_action(action)) {
+ action_id = InputMap::get_singleton()->get_action_id(action);
} else {
- action_id=-1;
+ action_id = -1;
}
} break;
case NOTIFICATION_EXIT_TREE: {
@@ -149,26 +149,24 @@ void TouchScreenButton::_notification(int p_what) {
} break;
case NOTIFICATION_PAUSED: {
// So the button can be pressed again even though the release gets unhandled because of coming during pause
- allow_repress=true;
+ allow_repress = true;
}
}
}
+bool TouchScreenButton::is_pressed() const {
-bool TouchScreenButton::is_pressed() const{
-
- return finger_pressed!=-1;
+ return finger_pressed != -1;
}
-void TouchScreenButton::set_action(const String& p_action) {
+void TouchScreenButton::set_action(const String &p_action) {
- action=p_action;
- if (action.operator String()!="" && InputMap::get_singleton()->has_action(action)) {
- action_id=InputMap::get_singleton()->get_action_id(action);
+ action = p_action;
+ if (action.operator String() != "" && InputMap::get_singleton()->has_action(action)) {
+ action_id = InputMap::get_singleton()->get_action_id(action);
} else {
- action_id=-1;
+ action_id = -1;
}
-
}
String TouchScreenButton::get_action() const {
@@ -176,7 +174,7 @@ String TouchScreenButton::get_action() const {
return action;
}
-void TouchScreenButton::_input(const InputEvent& p_event) {
+void TouchScreenButton::_input(const InputEvent &p_event) {
if (!get_tree())
return;
@@ -186,94 +184,88 @@ void TouchScreenButton::_input(const InputEvent& p_event) {
if (passby_press) {
- if (p_event.type==InputEvent::SCREEN_TOUCH && !p_event.screen_touch.pressed && finger_pressed==p_event.screen_touch.index) {
+ if (p_event.type == InputEvent::SCREEN_TOUCH && !p_event.screen_touch.pressed && finger_pressed == p_event.screen_touch.index) {
_release();
}
- if ((p_event.type==InputEvent::SCREEN_TOUCH && p_event.screen_touch.pressed)|| p_event.type==InputEvent::SCREEN_DRAG) {
+ if ((p_event.type == InputEvent::SCREEN_TOUCH && p_event.screen_touch.pressed) || p_event.type == InputEvent::SCREEN_DRAG) {
- if (finger_pressed==-1 || p_event.screen_touch.index==finger_pressed) {
+ if (finger_pressed == -1 || p_event.screen_touch.index == finger_pressed) {
- Point2 coord = (get_global_transform_with_canvas()).affine_inverse().xform(Point2(p_event.screen_touch.x,p_event.screen_touch.y));
+ Point2 coord = (get_global_transform_with_canvas()).affine_inverse().xform(Point2(p_event.screen_touch.x, p_event.screen_touch.y));
- bool touched=false;
+ bool touched = false;
if (bitmask.is_valid()) {
- if (Rect2(Point2(),bitmask->get_size()).has_point(coord)) {
+ if (Rect2(Point2(), bitmask->get_size()).has_point(coord)) {
if (bitmask->get_bit(coord))
- touched=true;
+ touched = true;
}
} else {
if (texture.is_valid())
- touched=Rect2(Point2(),texture->get_size()).has_point(coord);
+ touched = Rect2(Point2(), texture->get_size()).has_point(coord);
}
-
-
if (touched) {
- if (finger_pressed==-1) {
+ if (finger_pressed == -1) {
_press(p_event.screen_touch.index);
}
} else {
- if (finger_pressed!=-1) {
+ if (finger_pressed != -1) {
_release();
}
}
-
}
-
-
}
} else {
- if (p_event.type==InputEvent::SCREEN_TOUCH) {
+ if (p_event.type == InputEvent::SCREEN_TOUCH) {
if (p_event.screen_touch.pressed) {
if (!is_visible_in_tree())
return;
- const bool can_press=finger_pressed==-1 || allow_repress;
+ const bool can_press = finger_pressed == -1 || allow_repress;
if (!can_press)
return; //already fingering
- Point2 coord = (get_global_transform_with_canvas()).affine_inverse().xform(Point2(p_event.screen_touch.x,p_event.screen_touch.y));
+ Point2 coord = (get_global_transform_with_canvas()).affine_inverse().xform(Point2(p_event.screen_touch.x, p_event.screen_touch.y));
Rect2 item_rect = get_item_rect();
- bool touched=false;
- bool check_rect=true;
+ bool touched = false;
+ bool check_rect = true;
if (shape.is_valid()) {
- check_rect=false;
- Transform2D xform=shape_centered ? Transform2D().translated(get_item_rect().size*0.5f) : Transform2D();
- touched=shape->collide(xform, unit_rect, Transform2D(0, coord + Vector2(0.5,0.5)));
+ check_rect = false;
+ Transform2D xform = shape_centered ? Transform2D().translated(get_item_rect().size * 0.5f) : Transform2D();
+ touched = shape->collide(xform, unit_rect, Transform2D(0, coord + Vector2(0.5, 0.5)));
}
if (bitmask.is_valid()) {
- check_rect=false;
- if (!touched && Rect2(Point2(),bitmask->get_size()).has_point(coord)) {
+ check_rect = false;
+ if (!touched && Rect2(Point2(), bitmask->get_size()).has_point(coord)) {
if (bitmask->get_bit(coord))
- touched=true;
+ touched = true;
}
}
if (!touched && check_rect) {
if (!texture.is_null())
- touched=item_rect.has_point(coord);
+ touched = item_rect.has_point(coord);
}
-
if (touched) {
_press(p_event.screen_touch.index);
}
} else {
- if (p_event.screen_touch.index==finger_pressed) {
+ if (p_event.screen_touch.index == finger_pressed) {
_release();
}
}
@@ -283,17 +275,17 @@ void TouchScreenButton::_input(const InputEvent& p_event) {
void TouchScreenButton::_press(int p_finger_pressed) {
- finger_pressed=p_finger_pressed;
- allow_repress=false;
+ finger_pressed = p_finger_pressed;
+ allow_repress = false;
- if (action_id!=-1) {
+ if (action_id != -1) {
Input::get_singleton()->action_press(action);
InputEvent ie;
- ie.type=InputEvent::ACTION;
- ie.ID=0;
- ie.action.action=action_id;
- ie.action.pressed=true;
+ ie.type = InputEvent::ACTION;
+ ie.ID = 0;
+ ie.action.action = action_id;
+ ie.action.pressed = true;
get_tree()->input_event(ie);
}
@@ -303,17 +295,17 @@ void TouchScreenButton::_press(int p_finger_pressed) {
void TouchScreenButton::_release(bool p_exiting_tree) {
- finger_pressed=-1;
+ finger_pressed = -1;
- if (action_id!=-1) {
+ if (action_id != -1) {
Input::get_singleton()->action_release(action);
if (!p_exiting_tree) {
InputEvent ie;
- ie.type=InputEvent::ACTION;
- ie.ID=0;
- ie.action.action=action_id;
- ie.action.pressed=false;
+ ie.type = InputEvent::ACTION;
+ ie.ID = 0;
+ ie.action.action = action_id;
+ ie.action.pressed = false;
get_tree()->input_event(ie);
}
}
@@ -327,18 +319,17 @@ void TouchScreenButton::_release(bool p_exiting_tree) {
Rect2 TouchScreenButton::get_item_rect() const {
if (texture.is_null())
- return Rect2(0,0,1,1);
+ return Rect2(0, 0, 1, 1);
/*
if (texture.is_null())
return CanvasItem::get_item_rect();
*/
- return Rect2(Size2(),texture->get_size());
+ return Rect2(Size2(), texture->get_size());
}
-
void TouchScreenButton::set_visibility_mode(VisibilityMode p_mode) {
- visibility=p_mode;
+ visibility = p_mode;
update();
}
@@ -349,70 +340,65 @@ TouchScreenButton::VisibilityMode TouchScreenButton::get_visibility_mode() const
void TouchScreenButton::set_passby_press(bool p_enable) {
- passby_press=p_enable;
+ passby_press = p_enable;
}
-bool TouchScreenButton::is_passby_press_enabled() const{
+bool TouchScreenButton::is_passby_press_enabled() const {
return passby_press;
}
-
-
void TouchScreenButton::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_texture","texture"),&TouchScreenButton::set_texture);
- ClassDB::bind_method(D_METHOD("get_texture"),&TouchScreenButton::get_texture);
-
- ClassDB::bind_method(D_METHOD("set_texture_pressed","texture_pressed"),&TouchScreenButton::set_texture_pressed);
- ClassDB::bind_method(D_METHOD("get_texture_pressed"),&TouchScreenButton::get_texture_pressed);
-
- ClassDB::bind_method(D_METHOD("set_bitmask","bitmask"),&TouchScreenButton::set_bitmask);
- ClassDB::bind_method(D_METHOD("get_bitmask"),&TouchScreenButton::get_bitmask);
-
- ClassDB::bind_method(D_METHOD("set_shape","shape"),&TouchScreenButton::set_shape);
- ClassDB::bind_method(D_METHOD("get_shape"),&TouchScreenButton::get_shape);
+ ClassDB::bind_method(D_METHOD("set_texture", "texture"), &TouchScreenButton::set_texture);
+ ClassDB::bind_method(D_METHOD("get_texture"), &TouchScreenButton::get_texture);
- ClassDB::bind_method(D_METHOD("set_shape_centered","bool"),&TouchScreenButton::set_shape_centered);
- ClassDB::bind_method(D_METHOD("is_shape_centered"),&TouchScreenButton::is_shape_centered);
+ ClassDB::bind_method(D_METHOD("set_texture_pressed", "texture_pressed"), &TouchScreenButton::set_texture_pressed);
+ ClassDB::bind_method(D_METHOD("get_texture_pressed"), &TouchScreenButton::get_texture_pressed);
- ClassDB::bind_method(D_METHOD("set_action","action"),&TouchScreenButton::set_action);
- ClassDB::bind_method(D_METHOD("get_action"),&TouchScreenButton::get_action);
+ ClassDB::bind_method(D_METHOD("set_bitmask", "bitmask"), &TouchScreenButton::set_bitmask);
+ ClassDB::bind_method(D_METHOD("get_bitmask"), &TouchScreenButton::get_bitmask);
- ClassDB::bind_method(D_METHOD("set_visibility_mode","mode"),&TouchScreenButton::set_visibility_mode);
- ClassDB::bind_method(D_METHOD("get_visibility_mode"),&TouchScreenButton::get_visibility_mode);
+ ClassDB::bind_method(D_METHOD("set_shape", "shape"), &TouchScreenButton::set_shape);
+ ClassDB::bind_method(D_METHOD("get_shape"), &TouchScreenButton::get_shape);
- ClassDB::bind_method(D_METHOD("set_passby_press","enabled"),&TouchScreenButton::set_passby_press);
- ClassDB::bind_method(D_METHOD("is_passby_press_enabled"),&TouchScreenButton::is_passby_press_enabled);
+ ClassDB::bind_method(D_METHOD("set_shape_centered", "bool"), &TouchScreenButton::set_shape_centered);
+ ClassDB::bind_method(D_METHOD("is_shape_centered"), &TouchScreenButton::is_shape_centered);
- ClassDB::bind_method(D_METHOD("is_pressed"),&TouchScreenButton::is_pressed);
+ ClassDB::bind_method(D_METHOD("set_action", "action"), &TouchScreenButton::set_action);
+ ClassDB::bind_method(D_METHOD("get_action"), &TouchScreenButton::get_action);
- ClassDB::bind_method(D_METHOD("_input"),&TouchScreenButton::_input);
+ ClassDB::bind_method(D_METHOD("set_visibility_mode", "mode"), &TouchScreenButton::set_visibility_mode);
+ ClassDB::bind_method(D_METHOD("get_visibility_mode"), &TouchScreenButton::get_visibility_mode);
- ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"normal",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),"set_texture","get_texture");
- ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"pressed",PROPERTY_HINT_RESOURCE_TYPE,"Texture"),"set_texture_pressed","get_texture_pressed");
- ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"bitmask",PROPERTY_HINT_RESOURCE_TYPE,"BitMap"),"set_bitmask","get_bitmask");
- ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"shape",PROPERTY_HINT_RESOURCE_TYPE,"Shape2D"),"set_shape","get_shape");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"shape_centered"),"set_shape_centered","is_shape_centered");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"passby_press"),"set_passby_press","is_passby_press_enabled");
- ADD_PROPERTY( PropertyInfo(Variant::STRING,"action"),"set_action","get_action");
- ADD_PROPERTY( PropertyInfo(Variant::INT,"visibility_mode",PROPERTY_HINT_ENUM,"Always,TouchScreen Only"),"set_visibility_mode","get_visibility_mode");
+ ClassDB::bind_method(D_METHOD("set_passby_press", "enabled"), &TouchScreenButton::set_passby_press);
+ ClassDB::bind_method(D_METHOD("is_passby_press_enabled"), &TouchScreenButton::is_passby_press_enabled);
- ADD_SIGNAL( MethodInfo("pressed" ) );
- ADD_SIGNAL( MethodInfo("released" ) );
+ ClassDB::bind_method(D_METHOD("is_pressed"), &TouchScreenButton::is_pressed);
+ ClassDB::bind_method(D_METHOD("_input"), &TouchScreenButton::_input);
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "normal", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "pressed", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture_pressed", "get_texture_pressed");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "bitmask", PROPERTY_HINT_RESOURCE_TYPE, "BitMap"), "set_bitmask", "get_bitmask");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "shape", PROPERTY_HINT_RESOURCE_TYPE, "Shape2D"), "set_shape", "get_shape");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shape_centered"), "set_shape_centered", "is_shape_centered");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "passby_press"), "set_passby_press", "is_passby_press_enabled");
+ ADD_PROPERTY(PropertyInfo(Variant::STRING, "action"), "set_action", "get_action");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "visibility_mode", PROPERTY_HINT_ENUM, "Always,TouchScreen Only"), "set_visibility_mode", "get_visibility_mode");
+ ADD_SIGNAL(MethodInfo("pressed"));
+ ADD_SIGNAL(MethodInfo("released"));
}
TouchScreenButton::TouchScreenButton() {
- finger_pressed=-1;
- allow_repress=false;
- action_id=-1;
- passby_press=false;
- visibility=VISIBILITY_ALWAYS;
- shape_centered=true;
- unit_rect=Ref<RectangleShape2D>(memnew(RectangleShape2D));
- unit_rect->set_extents(Vector2(0.5,0.5));
+ finger_pressed = -1;
+ allow_repress = false;
+ action_id = -1;
+ passby_press = false;
+ visibility = VISIBILITY_ALWAYS;
+ shape_centered = true;
+ unit_rect = Ref<RectangleShape2D>(memnew(RectangleShape2D));
+ unit_rect->set_extents(Vector2(0.5, 0.5));
}
diff --git a/scene/2d/screen_button.h b/scene/2d/screen_button.h
index 8ce378c660..d648920b21 100644
--- a/scene/2d/screen_button.h
+++ b/scene/2d/screen_button.h
@@ -30,15 +30,15 @@
#define SCREEN_BUTTON_H
#include "scene/2d/node_2d.h"
-#include "scene/resources/texture.h"
#include "scene/resources/bit_mask.h"
#include "scene/resources/rectangle_shape_2d.h"
+#include "scene/resources/texture.h"
class TouchScreenButton : public Node2D {
- GDCLASS(TouchScreenButton,Node2D);
-public:
+ GDCLASS(TouchScreenButton, Node2D);
+public:
enum VisibilityMode {
VISIBILITY_ALWAYS,
VISIBILITY_TOUCHSCREEN_ONLY
@@ -61,34 +61,32 @@ private:
VisibilityMode visibility;
- void _input(const InputEvent& p_Event);
+ void _input(const InputEvent &p_Event);
void _press(int p_finger_pressed);
- void _release(bool p_exiting_tree=false);
+ void _release(bool p_exiting_tree = false);
protected:
-
void _notification(int p_what);
static void _bind_methods();
-public:
-
- void set_texture(const Ref<Texture>& p_texture);
+public:
+ void set_texture(const Ref<Texture> &p_texture);
Ref<Texture> get_texture() const;
- void set_texture_pressed(const Ref<Texture>& p_texture_pressed);
+ void set_texture_pressed(const Ref<Texture> &p_texture_pressed);
Ref<Texture> get_texture_pressed() const;
- void set_bitmask(const Ref<BitMap>& p_bitmask);
+ void set_bitmask(const Ref<BitMap> &p_bitmask);
Ref<BitMap> get_bitmask() const;
- void set_shape(const Ref<Shape2D>& p_shape);
+ void set_shape(const Ref<Shape2D> &p_shape);
Ref<Shape2D> get_shape() const;
void set_shape_centered(bool p_shape_centered);
bool is_shape_centered() const;
- void set_action(const String& p_action);
+ void set_action(const String &p_action);
String get_action() const;
void set_passby_press(bool p_enable);
@@ -101,7 +99,6 @@ public:
Rect2 get_item_rect() const;
-
TouchScreenButton();
};
diff --git a/scene/2d/sprite.cpp b/scene/2d/sprite.cpp
index 26c2756acd..41ea6a39e5 100644
--- a/scene/2d/sprite.cpp
+++ b/scene/2d/sprite.cpp
@@ -28,14 +28,13 @@
/*************************************************************************/
#include "sprite.h"
#include "core/core_string_names.h"
-#include "scene/scene_string_names.h"
-#include "scene/main/viewport.h"
#include "os/os.h"
+#include "scene/main/viewport.h"
+#include "scene/scene_string_names.h"
-void Sprite::edit_set_pivot(const Point2& p_pivot) {
+void Sprite::edit_set_pivot(const Point2 &p_pivot) {
set_offset(p_pivot);
-
}
Point2 Sprite::edit_get_pivot() const {
@@ -49,16 +48,13 @@ bool Sprite::edit_has_pivot() const {
void Sprite::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_DRAW: {
if (texture.is_null())
return;
-
-
-
RID ci = get_canvas_item();
/*
@@ -71,52 +67,51 @@ void Sprite::_notification(int p_what) {
if (region) {
- s=region_rect.size;
- src_rect=region_rect;
+ s = region_rect.size;
+ src_rect = region_rect;
} else {
s = Size2(texture->get_size());
- s=s/Size2(hframes,vframes);
-
- src_rect.size=s;
- src_rect.pos.x+=float(frame%hframes)*s.x;
- src_rect.pos.y+=float(frame/hframes)*s.y;
+ s = s / Size2(hframes, vframes);
+ src_rect.size = s;
+ src_rect.pos.x += float(frame % hframes) * s.x;
+ src_rect.pos.y += float(frame / hframes) * s.y;
}
- Point2 ofs=offset;
+ Point2 ofs = offset;
if (centered)
- ofs-=s/2;
+ ofs -= s / 2;
if (Engine::get_singleton()->get_use_pixel_snap()) {
- ofs=ofs.floor();
+ ofs = ofs.floor();
}
- Rect2 dst_rect(ofs,s);
+ Rect2 dst_rect(ofs, s);
if (hflip)
- dst_rect.size.x=-dst_rect.size.x;
+ dst_rect.size.x = -dst_rect.size.x;
if (vflip)
- dst_rect.size.y=-dst_rect.size.y;
+ dst_rect.size.y = -dst_rect.size.y;
- texture->draw_rect_region(ci,dst_rect,src_rect);
+ texture->draw_rect_region(ci, dst_rect, src_rect);
} break;
}
}
-void Sprite::set_texture(const Ref<Texture>& p_texture) {
+void Sprite::set_texture(const Ref<Texture> &p_texture) {
- if (p_texture==texture)
+ if (p_texture == texture)
return;
#ifdef DEBUG_ENABLED
if (texture.is_valid()) {
- texture->disconnect(CoreStringNames::get_singleton()->changed,this,SceneStringNames::get_singleton()->update);
+ texture->disconnect(CoreStringNames::get_singleton()->changed, this, SceneStringNames::get_singleton()->update);
}
#endif
- texture=p_texture;
+ texture = p_texture;
#ifdef DEBUG_ENABLED
if (texture.is_valid()) {
texture->set_flags(texture->get_flags()); //remove repeat from texture, it looks bad in sprites
- texture->connect(CoreStringNames::get_singleton()->changed,this,SceneStringNames::get_singleton()->update);
+ texture->connect(CoreStringNames::get_singleton()->changed, this, SceneStringNames::get_singleton()->update);
}
#endif
update();
@@ -131,7 +126,7 @@ Ref<Texture> Sprite::get_texture() const {
void Sprite::set_centered(bool p_center) {
- centered=p_center;
+ centered = p_center;
update();
item_rect_changed();
}
@@ -141,9 +136,9 @@ bool Sprite::is_centered() const {
return centered;
}
-void Sprite::set_offset(const Point2& p_offset) {
+void Sprite::set_offset(const Point2 &p_offset) {
- offset=p_offset;
+ offset = p_offset;
update();
item_rect_changed();
_change_notify("offset");
@@ -155,7 +150,7 @@ Point2 Sprite::get_offset() const {
void Sprite::set_flip_h(bool p_flip) {
- hflip=p_flip;
+ hflip = p_flip;
update();
}
bool Sprite::is_flipped_h() const {
@@ -165,7 +160,7 @@ bool Sprite::is_flipped_h() const {
void Sprite::set_flip_v(bool p_flip) {
- vflip=p_flip;
+ vflip = p_flip;
update();
}
bool Sprite::is_flipped_v() const {
@@ -175,24 +170,24 @@ bool Sprite::is_flipped_v() const {
void Sprite::set_region(bool p_region) {
- if (p_region==region)
+ if (p_region == region)
return;
- region=p_region;
+ region = p_region;
update();
}
-bool Sprite::is_region() const{
+bool Sprite::is_region() const {
return region;
}
-void Sprite::set_region_rect(const Rect2& p_region_rect) {
+void Sprite::set_region_rect(const Rect2 &p_region_rect) {
- if (region_rect==p_region_rect)
+ if (region_rect == p_region_rect)
return;
- region_rect=p_region_rect;
+ region_rect = p_region_rect;
if (region)
item_rect_changed();
@@ -207,12 +202,12 @@ Rect2 Sprite::get_region_rect() const {
void Sprite::set_frame(int p_frame) {
- ERR_FAIL_INDEX(p_frame,vframes*hframes);
+ ERR_FAIL_INDEX(p_frame, vframes * hframes);
if (frame != p_frame)
item_rect_changed();
- frame=p_frame;
+ frame = p_frame;
_change_notify("frame");
emit_signal(SceneStringNames::get_singleton()->frame_changed);
@@ -225,8 +220,8 @@ int Sprite::get_frame() const {
void Sprite::set_vframes(int p_amount) {
- ERR_FAIL_COND(p_amount<1);
- vframes=p_amount;
+ ERR_FAIL_COND(p_amount < 1);
+ vframes = p_amount;
update();
item_rect_changed();
_change_notify("frame");
@@ -238,8 +233,8 @@ int Sprite::get_vframes() const {
void Sprite::set_hframes(int p_amount) {
- ERR_FAIL_COND(p_amount<1);
- hframes=p_amount;
+ ERR_FAIL_COND(p_amount < 1);
+ hframes = p_amount;
update();
item_rect_changed();
_change_notify("frame");
@@ -249,12 +244,10 @@ int Sprite::get_hframes() const {
return hframes;
}
-
-
Rect2 Sprite::get_item_rect() const {
if (texture.is_null())
- return Rect2(0,0,1,1);
+ return Rect2(0, 0, 1, 1);
/*
if (texture.is_null())
return CanvasItem::get_item_rect();
@@ -264,99 +257,92 @@ Rect2 Sprite::get_item_rect() const {
if (region) {
- s=region_rect.size;
+ s = region_rect.size;
} else {
s = texture->get_size();
- s=s/Point2(hframes,vframes);
+ s = s / Point2(hframes, vframes);
}
- Point2 ofs=offset;
+ Point2 ofs = offset;
if (centered)
- ofs-=s/2;
+ ofs -= s / 2;
- if (s==Size2(0,0))
- s=Size2(1,1);
+ if (s == Size2(0, 0))
+ s = Size2(1, 1);
- return Rect2(ofs,s);
+ return Rect2(ofs, s);
}
+void Sprite::_validate_property(PropertyInfo &property) const {
+ if (property.name == "frame") {
-void Sprite::_validate_property(PropertyInfo& property) const {
-
- if (property.name=="frame") {
-
- property.hint=PROPERTY_HINT_SPRITE_FRAME;
+ property.hint = PROPERTY_HINT_SPRITE_FRAME;
- property.hint_string="0,"+itos(vframes*hframes-1)+",1";
+ property.hint_string = "0," + itos(vframes * hframes - 1) + ",1";
}
}
void Sprite::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_texture","texture:Texture"),&Sprite::set_texture);
- ClassDB::bind_method(D_METHOD("get_texture:Texture"),&Sprite::get_texture);
+ ClassDB::bind_method(D_METHOD("set_texture", "texture:Texture"), &Sprite::set_texture);
+ ClassDB::bind_method(D_METHOD("get_texture:Texture"), &Sprite::get_texture);
- ClassDB::bind_method(D_METHOD("set_centered","centered"),&Sprite::set_centered);
- ClassDB::bind_method(D_METHOD("is_centered"),&Sprite::is_centered);
+ ClassDB::bind_method(D_METHOD("set_centered", "centered"), &Sprite::set_centered);
+ ClassDB::bind_method(D_METHOD("is_centered"), &Sprite::is_centered);
- ClassDB::bind_method(D_METHOD("set_offset","offset"),&Sprite::set_offset);
- ClassDB::bind_method(D_METHOD("get_offset"),&Sprite::get_offset);
+ ClassDB::bind_method(D_METHOD("set_offset", "offset"), &Sprite::set_offset);
+ ClassDB::bind_method(D_METHOD("get_offset"), &Sprite::get_offset);
- ClassDB::bind_method(D_METHOD("set_flip_h","flip_h"),&Sprite::set_flip_h);
- ClassDB::bind_method(D_METHOD("is_flipped_h"),&Sprite::is_flipped_h);
+ ClassDB::bind_method(D_METHOD("set_flip_h", "flip_h"), &Sprite::set_flip_h);
+ ClassDB::bind_method(D_METHOD("is_flipped_h"), &Sprite::is_flipped_h);
- ClassDB::bind_method(D_METHOD("set_flip_v","flip_v"),&Sprite::set_flip_v);
- ClassDB::bind_method(D_METHOD("is_flipped_v"),&Sprite::is_flipped_v);
+ ClassDB::bind_method(D_METHOD("set_flip_v", "flip_v"), &Sprite::set_flip_v);
+ ClassDB::bind_method(D_METHOD("is_flipped_v"), &Sprite::is_flipped_v);
- ClassDB::bind_method(D_METHOD("set_region","enabled"),&Sprite::set_region);
- ClassDB::bind_method(D_METHOD("is_region"),&Sprite::is_region);
+ ClassDB::bind_method(D_METHOD("set_region", "enabled"), &Sprite::set_region);
+ ClassDB::bind_method(D_METHOD("is_region"), &Sprite::is_region);
- ClassDB::bind_method(D_METHOD("set_region_rect","rect"),&Sprite::set_region_rect);
- ClassDB::bind_method(D_METHOD("get_region_rect"),&Sprite::get_region_rect);
+ ClassDB::bind_method(D_METHOD("set_region_rect", "rect"), &Sprite::set_region_rect);
+ ClassDB::bind_method(D_METHOD("get_region_rect"), &Sprite::get_region_rect);
- ClassDB::bind_method(D_METHOD("set_frame","frame"),&Sprite::set_frame);
- ClassDB::bind_method(D_METHOD("get_frame"),&Sprite::get_frame);
+ ClassDB::bind_method(D_METHOD("set_frame", "frame"), &Sprite::set_frame);
+ ClassDB::bind_method(D_METHOD("get_frame"), &Sprite::get_frame);
- ClassDB::bind_method(D_METHOD("set_vframes","vframes"),&Sprite::set_vframes);
- ClassDB::bind_method(D_METHOD("get_vframes"),&Sprite::get_vframes);
+ ClassDB::bind_method(D_METHOD("set_vframes", "vframes"), &Sprite::set_vframes);
+ ClassDB::bind_method(D_METHOD("get_vframes"), &Sprite::get_vframes);
- ClassDB::bind_method(D_METHOD("set_hframes","hframes"),&Sprite::set_hframes);
- ClassDB::bind_method(D_METHOD("get_hframes"),&Sprite::get_hframes);
+ ClassDB::bind_method(D_METHOD("set_hframes", "hframes"), &Sprite::set_hframes);
+ ClassDB::bind_method(D_METHOD("get_hframes"), &Sprite::get_hframes);
ADD_SIGNAL(MethodInfo("frame_changed"));
ADD_SIGNAL(MethodInfo("texture_changed"));
- ADD_PROPERTYNZ( PropertyInfo( Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE,"Texture"), "set_texture","get_texture");
- ADD_PROPERTYNO( PropertyInfo( Variant::BOOL, "centered"), "set_centered","is_centered");
- ADD_PROPERTYNZ( PropertyInfo( Variant::VECTOR2, "offset"), "set_offset","get_offset");
- ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "flip_h"), "set_flip_h","is_flipped_h");
- ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "flip_v"), "set_flip_v","is_flipped_v");
- ADD_PROPERTYNO( PropertyInfo( Variant::INT, "vframes",PROPERTY_HINT_RANGE,"1,16384,1"), "set_vframes","get_vframes");
- ADD_PROPERTYNO( PropertyInfo( Variant::INT, "hframes",PROPERTY_HINT_RANGE,"1,16384,1"), "set_hframes","get_hframes");
- ADD_PROPERTYNZ( PropertyInfo( Variant::INT, "frame",PROPERTY_HINT_SPRITE_FRAME), "set_frame","get_frame");
- ADD_PROPERTYNZ( PropertyInfo( Variant::BOOL, "region"), "set_region","is_region");
- ADD_PROPERTYNZ( PropertyInfo( Variant::RECT2, "region_rect"), "set_region_rect","get_region_rect");
-
+ ADD_PROPERTYNZ(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture");
+ ADD_PROPERTYNO(PropertyInfo(Variant::BOOL, "centered"), "set_centered", "is_centered");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "offset"), "set_offset", "get_offset");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "flip_h"), "set_flip_h", "is_flipped_h");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "flip_v"), "set_flip_v", "is_flipped_v");
+ ADD_PROPERTYNO(PropertyInfo(Variant::INT, "vframes", PROPERTY_HINT_RANGE, "1,16384,1"), "set_vframes", "get_vframes");
+ ADD_PROPERTYNO(PropertyInfo(Variant::INT, "hframes", PROPERTY_HINT_RANGE, "1,16384,1"), "set_hframes", "get_hframes");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::INT, "frame", PROPERTY_HINT_SPRITE_FRAME), "set_frame", "get_frame");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::BOOL, "region"), "set_region", "is_region");
+ ADD_PROPERTYNZ(PropertyInfo(Variant::RECT2, "region_rect"), "set_region_rect", "get_region_rect");
}
Sprite::Sprite() {
- centered=true;
- hflip=false;
- vflip=false;
- region=false;
-
- frame=0;
+ centered = true;
+ hflip = false;
+ vflip = false;
+ region = false;
- vframes=1;
- hframes=1;
+ frame = 0;
+ vframes = 1;
+ hframes = 1;
}
-
-
-
//////////////////////////// VPSPRITE
///
///
diff --git a/scene/2d/sprite.h b/scene/2d/sprite.h
index ab4487ef7b..c4bc800647 100644
--- a/scene/2d/sprite.h
+++ b/scene/2d/sprite.h
@@ -32,10 +32,9 @@
#include "scene/2d/node_2d.h"
#include "scene/resources/texture.h"
-
class Sprite : public Node2D {
- GDCLASS( Sprite, Node2D );
+ GDCLASS(Sprite, Node2D);
Ref<Texture> texture;
@@ -52,29 +51,25 @@ class Sprite : public Node2D {
int vframes;
int hframes;
-
-
protected:
-
void _notification(int p_what);
static void _bind_methods();
- virtual void _validate_property(PropertyInfo& property) const;
+ virtual void _validate_property(PropertyInfo &property) const;
public:
-
- virtual void edit_set_pivot(const Point2& p_pivot);
+ virtual void edit_set_pivot(const Point2 &p_pivot);
virtual Point2 edit_get_pivot() const;
virtual bool edit_has_pivot() const;
- void set_texture(const Ref<Texture>& p_texture);
+ void set_texture(const Ref<Texture> &p_texture);
Ref<Texture> get_texture() const;
void set_centered(bool p_center);
bool is_centered() const;
- void set_offset(const Point2& p_offset);
+ void set_offset(const Point2 &p_offset);
Point2 get_offset() const;
void set_flip_h(bool p_flip);
@@ -86,7 +81,7 @@ public:
void set_region(bool p_region);
bool is_region() const;
- void set_region_rect(const Rect2& p_region_rect);
+ void set_region_rect(const Rect2 &p_region_rect);
Rect2 get_region_rect() const;
void set_frame(int p_frame);
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index f89a72e1b9..02b41fbd0c 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -28,11 +28,9 @@
/*************************************************************************/
#include "tile_map.h"
#include "io/marshalls.h"
-#include "servers/physics_2d_server.h"
#include "method_bind_ext.inc"
#include "os/os.h"
-
-
+#include "servers/physics_2d_server.h"
int TileMap::_get_quadrant_size() const {
@@ -44,51 +42,49 @@ int TileMap::_get_quadrant_size() const {
void TileMap::_notification(int p_what) {
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
- Node2D *c=this;
- while(c) {
+ Node2D *c = this;
+ while (c) {
- navigation=c->cast_to<Navigation2D>();
+ navigation = c->cast_to<Navigation2D>();
if (navigation) {
break;
}
- c=c->get_parent()->cast_to<Node2D>();
+ c = c->get_parent()->cast_to<Node2D>();
}
- pending_update=true;
+ pending_update = true;
_update_dirty_quadrants();
RID space = get_world_2d()->get_space();
_update_quadrant_transform();
_update_quadrant_space(space);
-
} break;
case NOTIFICATION_EXIT_TREE: {
_update_quadrant_space(RID());
- for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) {
+ for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
- Quadrant &q=E->get();
+ Quadrant &q = E->get();
if (navigation) {
- for(Map<PosKey,Quadrant::NavPoly>::Element *E=q.navpoly_ids.front();E;E=E->next()) {
+ for (Map<PosKey, Quadrant::NavPoly>::Element *E = q.navpoly_ids.front(); E; E = E->next()) {
navigation->navpoly_remove(E->get().id);
}
q.navpoly_ids.clear();
}
- for(Map<PosKey,Quadrant::Occluder>::Element *E=q.occluder_instances.front();E;E=E->next()) {
+ for (Map<PosKey, Quadrant::Occluder>::Element *E = q.occluder_instances.front(); E; E = E->next()) {
VS::get_singleton()->free(E->get().id);
}
q.occluder_instances.clear();
}
- navigation=NULL;
-
+ navigation = NULL;
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
@@ -100,12 +96,12 @@ void TileMap::_notification(int p_what) {
}
}
-void TileMap::_update_quadrant_space(const RID& p_space) {
+void TileMap::_update_quadrant_space(const RID &p_space) {
- for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) {
+ for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
- Quadrant &q=E->get();
- Physics2DServer::get_singleton()->body_set_space(q.body,p_space);
+ Quadrant &q = E->get();
+ Physics2DServer::get_singleton()->body_set_space(q.body, p_space);
}
}
@@ -120,43 +116,42 @@ void TileMap::_update_quadrant_transform() {
if (navigation)
nav_rel = get_relative_transform_to_parent(navigation);
- for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) {
+ for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
- Quadrant &q=E->get();
+ Quadrant &q = E->get();
Transform2D xform;
- xform.set_origin( q.pos );
+ xform.set_origin(q.pos);
xform = global_transform * xform;
- Physics2DServer::get_singleton()->body_set_state(q.body,Physics2DServer::BODY_STATE_TRANSFORM,xform);
+ Physics2DServer::get_singleton()->body_set_state(q.body, Physics2DServer::BODY_STATE_TRANSFORM, xform);
if (navigation) {
- for(Map<PosKey,Quadrant::NavPoly>::Element *E=q.navpoly_ids.front();E;E=E->next()) {
+ for (Map<PosKey, Quadrant::NavPoly>::Element *E = q.navpoly_ids.front(); E; E = E->next()) {
- navigation->navpoly_set_transform(E->get().id,nav_rel * E->get().xform);
+ navigation->navpoly_set_transform(E->get().id, nav_rel * E->get().xform);
}
}
- for(Map<PosKey,Quadrant::Occluder>::Element *E=q.occluder_instances.front();E;E=E->next()) {
- VS::get_singleton()->canvas_light_occluder_set_transform(E->get().id,global_transform * E->get().xform);
+ for (Map<PosKey, Quadrant::Occluder>::Element *E = q.occluder_instances.front(); E; E = E->next()) {
+ VS::get_singleton()->canvas_light_occluder_set_transform(E->get().id, global_transform * E->get().xform);
}
}
}
-void TileMap::set_tileset(const Ref<TileSet>& p_tileset) {
+void TileMap::set_tileset(const Ref<TileSet> &p_tileset) {
if (tile_set.is_valid())
- tile_set->disconnect("changed",this,"_recreate_quadrants");
+ tile_set->disconnect("changed", this, "_recreate_quadrants");
_clear_quadrants();
- tile_set=p_tileset;
+ tile_set = p_tileset;
if (tile_set.is_valid())
- tile_set->connect("changed",this,"_recreate_quadrants");
+ tile_set->connect("changed", this, "_recreate_quadrants");
else
clear();
_recreate_quadrants();
emit_signal("settings_changed");
-
}
Ref<TileSet> TileMap::get_tileset() const {
@@ -166,14 +161,12 @@ Ref<TileSet> TileMap::get_tileset() const {
void TileMap::set_cell_size(Size2 p_size) {
- ERR_FAIL_COND(p_size.x<1 || p_size.y<1);
+ ERR_FAIL_COND(p_size.x < 1 || p_size.y < 1);
_clear_quadrants();
- cell_size=p_size;
+ cell_size = p_size;
_recreate_quadrants();
emit_signal("settings_changed");
-
-
}
Size2 TileMap::get_cell_size() const {
@@ -181,13 +174,12 @@ Size2 TileMap::get_cell_size() const {
}
void TileMap::set_quadrant_size(int p_size) {
- ERR_FAIL_COND(p_size<1);
+ ERR_FAIL_COND(p_size < 1);
_clear_quadrants();
- quadrant_size=p_size;
+ quadrant_size = p_size;
_recreate_quadrants();
emit_signal("settings_changed");
-
}
int TileMap::get_quadrant_size() const {
@@ -196,11 +188,9 @@ int TileMap::get_quadrant_size() const {
void TileMap::set_center_x(bool p_enable) {
- center_x=p_enable;
+ center_x = p_enable;
_recreate_quadrants();
emit_signal("settings_changed");
-
-
}
bool TileMap::get_center_x() const {
@@ -208,24 +198,22 @@ bool TileMap::get_center_x() const {
}
void TileMap::set_center_y(bool p_enable) {
- center_y=p_enable;
+ center_y = p_enable;
_recreate_quadrants();
emit_signal("settings_changed");
-
}
bool TileMap::get_center_y() const {
return center_y;
}
-void TileMap::_fix_cell_transform(Transform2D& xform,const Cell& p_cell, const Vector2& p_offset, const Size2 &p_sc) {
+void TileMap::_fix_cell_transform(Transform2D &xform, const Cell &p_cell, const Vector2 &p_offset, const Size2 &p_sc) {
- Size2 s=p_sc;
+ Size2 s = p_sc;
Vector2 offset = p_offset;
-
- if (tile_origin==TILE_ORIGIN_BOTTOM_LEFT)
- offset.y+=cell_size.y;
+ if (tile_origin == TILE_ORIGIN_BOTTOM_LEFT)
+ offset.y += cell_size.y;
if (s.y > s.x) {
if ((p_cell.flip_h && (p_cell.flip_v || p_cell.transpose)) || (p_cell.flip_v && !p_cell.transpose))
@@ -242,26 +230,25 @@ void TileMap::_fix_cell_transform(Transform2D& xform,const Cell& p_cell, const V
SWAP(s.x, s.y);
}
if (p_cell.flip_h) {
- xform.elements[0].x=-xform.elements[0].x;
- xform.elements[1].x=-xform.elements[1].x;
- if (tile_origin==TILE_ORIGIN_TOP_LEFT || tile_origin==TILE_ORIGIN_BOTTOM_LEFT)
- offset.x=s.x-offset.x;
+ xform.elements[0].x = -xform.elements[0].x;
+ xform.elements[1].x = -xform.elements[1].x;
+ if (tile_origin == TILE_ORIGIN_TOP_LEFT || tile_origin == TILE_ORIGIN_BOTTOM_LEFT)
+ offset.x = s.x - offset.x;
}
if (p_cell.flip_v) {
- xform.elements[0].y=-xform.elements[0].y;
- xform.elements[1].y=-xform.elements[1].y;
- if (tile_origin==TILE_ORIGIN_TOP_LEFT)
- offset.y=s.y-offset.y;
- else if (tile_origin==TILE_ORIGIN_BOTTOM_LEFT) {
- if(p_cell.transpose)
- offset.y+=s.y;
+ xform.elements[0].y = -xform.elements[0].y;
+ xform.elements[1].y = -xform.elements[1].y;
+ if (tile_origin == TILE_ORIGIN_TOP_LEFT)
+ offset.y = s.y - offset.y;
+ else if (tile_origin == TILE_ORIGIN_BOTTOM_LEFT) {
+ if (p_cell.transpose)
+ offset.y += s.y;
else
- offset.y-=s.y;
+ offset.y -= s.y;
}
}
- xform.elements[2].x+=offset.x;
- xform.elements[2].y+=offset.y;
-
+ xform.elements[2].x += offset.x;
+ xform.elements[2].y += offset.y;
}
void TileMap::_update_dirty_quadrants() {
@@ -276,26 +263,26 @@ void TileMap::_update_dirty_quadrants() {
VisualServer *vs = VisualServer::get_singleton();
Physics2DServer *ps = Physics2DServer::get_singleton();
Vector2 tofs = get_cell_draw_offset();
- Vector2 tcenter = cell_size/2;
+ Vector2 tcenter = cell_size / 2;
Transform2D nav_rel;
if (navigation)
nav_rel = get_relative_transform_to_parent(navigation);
Vector2 qofs;
- SceneTree *st=SceneTree::get_singleton();
+ SceneTree *st = SceneTree::get_singleton();
Color debug_collision_color;
bool debug_shapes = st && st->is_debugging_collisions_hint();
if (debug_shapes) {
- debug_collision_color=st->get_debug_collisions_color();
+ debug_collision_color = st->get_debug_collisions_color();
}
while (dirty_quadrant_list.first()) {
Quadrant &q = *dirty_quadrant_list.first()->self();
- for (List<RID>::Element *E=q.canvas_items.front();E;E=E->next()) {
+ for (List<RID>::Element *E = q.canvas_items.front(); E; E = E->next()) {
vs->free(E->get());
}
@@ -303,17 +290,17 @@ void TileMap::_update_dirty_quadrants() {
q.canvas_items.clear();
ps->body_clear_shapes(q.body);
- int shape_idx=0;
+ int shape_idx = 0;
if (navigation) {
- for(Map<PosKey,Quadrant::NavPoly>::Element *E=q.navpoly_ids.front();E;E=E->next()) {
+ for (Map<PosKey, Quadrant::NavPoly>::Element *E = q.navpoly_ids.front(); E; E = E->next()) {
navigation->navpoly_remove(E->get().id);
}
q.navpoly_ids.clear();
}
- for(Map<PosKey,Quadrant::Occluder>::Element *E=q.occluder_instances.front();E;E=E->next()) {
+ for (Map<PosKey, Quadrant::Occluder>::Element *E = q.occluder_instances.front(); E; E = E->next()) {
VS::get_singleton()->free(E->get().id);
}
q.occluder_instances.clear();
@@ -321,10 +308,10 @@ void TileMap::_update_dirty_quadrants() {
RID prev_canvas_item;
RID prev_debug_canvas_item;
- for(int i=0;i<q.cells.size();i++) {
+ for (int i = 0; i < q.cells.size(); i++) {
- Map<PosKey,Cell>::Element *E=tile_map.find( q.cells[i] );
- Cell &c=E->get();
+ Map<PosKey, Cell>::Element *E = tile_map.find(q.cells[i]);
+ Cell &c = E->get();
//moment of truth
if (!tile_set->has_tile(c.id))
continue;
@@ -342,57 +329,55 @@ void TileMap::_update_dirty_quadrants() {
RID canvas_item;
RID debug_canvas_item;
- if (prev_canvas_item==RID() || prev_material!=mat) {
+ if (prev_canvas_item == RID() || prev_material != mat) {
- canvas_item=vs->canvas_item_create();
+ canvas_item = vs->canvas_item_create();
if (mat.is_valid())
- vs->canvas_item_set_material(canvas_item,mat->get_rid());
- vs->canvas_item_set_parent( canvas_item, get_canvas_item() );
+ vs->canvas_item_set_material(canvas_item, mat->get_rid());
+ vs->canvas_item_set_parent(canvas_item, get_canvas_item());
Transform2D xform;
- xform.set_origin( q.pos );
- vs->canvas_item_set_transform( canvas_item, xform );
- vs->canvas_item_set_light_mask(canvas_item,get_light_mask());
+ xform.set_origin(q.pos);
+ vs->canvas_item_set_transform(canvas_item, xform);
+ vs->canvas_item_set_light_mask(canvas_item, get_light_mask());
q.canvas_items.push_back(canvas_item);
if (debug_shapes) {
- debug_canvas_item=vs->canvas_item_create();
- vs->canvas_item_set_parent( debug_canvas_item, canvas_item );
- vs->canvas_item_set_z_as_relative_to_parent(debug_canvas_item,false);
- vs->canvas_item_set_z(debug_canvas_item,VS::CANVAS_ITEM_Z_MAX-1);
+ debug_canvas_item = vs->canvas_item_create();
+ vs->canvas_item_set_parent(debug_canvas_item, canvas_item);
+ vs->canvas_item_set_z_as_relative_to_parent(debug_canvas_item, false);
+ vs->canvas_item_set_z(debug_canvas_item, VS::CANVAS_ITEM_Z_MAX - 1);
q.canvas_items.push_back(debug_canvas_item);
- prev_debug_canvas_item=debug_canvas_item;
+ prev_debug_canvas_item = debug_canvas_item;
}
- prev_canvas_item=canvas_item;
- prev_material=mat;
+ prev_canvas_item = canvas_item;
+ prev_material = mat;
} else {
- canvas_item=prev_canvas_item;
+ canvas_item = prev_canvas_item;
if (debug_shapes) {
- debug_canvas_item=prev_debug_canvas_item;
+ debug_canvas_item = prev_debug_canvas_item;
}
}
-
-
Rect2 r = tile_set->tile_get_region(c.id);
Size2 s = tex->get_size();
- if (r==Rect2())
+ if (r == Rect2())
s = tex->get_size();
else {
s = r.size;
- r.pos.x+=fp_adjust;
- r.pos.y+=fp_adjust;
- r.size.x-=fp_adjust*2.0;
- r.size.y-=fp_adjust*2.0;
+ r.pos.x += fp_adjust;
+ r.pos.y += fp_adjust;
+ r.size.x -= fp_adjust * 2.0;
+ r.size.y -= fp_adjust * 2.0;
}
Rect2 rect;
- rect.pos=offset.floor();
- rect.size=s;
+ rect.pos = offset.floor();
+ rect.size = s;
if (rect.size.y > rect.size.x) {
if ((c.flip_h && (c.flip_v || c.transpose)) || (c.flip_v && !c.transpose))
@@ -402,75 +387,72 @@ void TileMap::_update_dirty_quadrants() {
tile_ofs.x += rect.size.x - rect.size.y;
}
- /* rect.size.x+=fp_adjust;
+ /* rect.size.x+=fp_adjust;
rect.size.y+=fp_adjust;*/
if (c.transpose)
SWAP(tile_ofs.x, tile_ofs.y);
if (c.flip_h) {
- rect.size.x=-rect.size.x;
- tile_ofs.x=-tile_ofs.x;
+ rect.size.x = -rect.size.x;
+ tile_ofs.x = -tile_ofs.x;
}
if (c.flip_v) {
- rect.size.y=-rect.size.y;
- tile_ofs.y=-tile_ofs.y;
+ rect.size.y = -rect.size.y;
+ tile_ofs.y = -tile_ofs.y;
}
Vector2 center_ofs;
- if (tile_origin==TILE_ORIGIN_TOP_LEFT) {
- rect.pos+=tile_ofs;
-
- } else if (tile_origin==TILE_ORIGIN_BOTTOM_LEFT) {
-
- rect.pos+=tile_ofs;
-
- if(c.transpose)
- {
- if(c.flip_h)
- rect.pos.x-=cell_size.x;
+ if (tile_origin == TILE_ORIGIN_TOP_LEFT) {
+ rect.pos += tile_ofs;
+
+ } else if (tile_origin == TILE_ORIGIN_BOTTOM_LEFT) {
+
+ rect.pos += tile_ofs;
+
+ if (c.transpose) {
+ if (c.flip_h)
+ rect.pos.x -= cell_size.x;
else
- rect.pos.x+=cell_size.x;
+ rect.pos.x += cell_size.x;
} else {
- if(c.flip_v)
- rect.pos.y-=cell_size.y;
+ if (c.flip_v)
+ rect.pos.y -= cell_size.y;
else
- rect.pos.y+=cell_size.y;
+ rect.pos.y += cell_size.y;
}
-
- } else if (tile_origin==TILE_ORIGIN_CENTER) {
- rect.pos+=tcenter;
- Vector2 center = (s/2) - tile_ofs;
- center_ofs=tcenter-(s/2);
+ } else if (tile_origin == TILE_ORIGIN_CENTER) {
+ rect.pos += tcenter;
+
+ Vector2 center = (s / 2) - tile_ofs;
+ center_ofs = tcenter - (s / 2);
if (c.flip_h)
- rect.pos.x-=s.x-center.x;
+ rect.pos.x -= s.x - center.x;
else
- rect.pos.x-=center.x;
+ rect.pos.x -= center.x;
if (c.flip_v)
- rect.pos.y-=s.y-center.y;
+ rect.pos.y -= s.y - center.y;
else
- rect.pos.y-=center.y;
+ rect.pos.y -= center.y;
}
-
Color modulate = tile_set->tile_get_modulate(c.id);
Color self_modulate = get_self_modulate();
- modulate = Color(modulate.r*self_modulate.r, modulate.g*self_modulate.g,
- modulate.b*self_modulate.b, modulate.a*self_modulate.a);
- if (r==Rect2()) {
- tex->draw_rect(canvas_item,rect,false,modulate,c.transpose);
+ modulate = Color(modulate.r * self_modulate.r, modulate.g * self_modulate.g,
+ modulate.b * self_modulate.b, modulate.a * self_modulate.a);
+ if (r == Rect2()) {
+ tex->draw_rect(canvas_item, rect, false, modulate, c.transpose);
} else {
- tex->draw_rect_region(canvas_item,rect,r,modulate,c.transpose);
+ tex->draw_rect_region(canvas_item, rect, r, modulate, c.transpose);
}
- Vector< Ref<Shape2D> > shapes = tile_set->tile_get_shapes(c.id);
-
+ Vector<Ref<Shape2D> > shapes = tile_set->tile_get_shapes(c.id);
- for(int i=0;i<shapes.size();i++) {
+ for (int i = 0; i < shapes.size(); i++) {
Ref<Shape2D> shape = shapes[i];
if (shape.is_valid()) {
@@ -479,21 +461,19 @@ void TileMap::_update_dirty_quadrants() {
Transform2D xform;
xform.set_origin(offset.floor());
- _fix_cell_transform(xform,c,shape_ofs+center_ofs,s);
+ _fix_cell_transform(xform, c, shape_ofs + center_ofs, s);
if (debug_canvas_item.is_valid()) {
- vs->canvas_item_add_set_transform(debug_canvas_item,xform);
- shape->draw(debug_canvas_item,debug_collision_color);
-
+ vs->canvas_item_add_set_transform(debug_canvas_item, xform);
+ shape->draw(debug_canvas_item, debug_collision_color);
}
- ps->body_add_shape(q.body,shape->get_rid(),xform);
- ps->body_set_shape_metadata(q.body,shape_idx++,Vector2(E->key().x,E->key().y));
-
+ ps->body_add_shape(q.body, shape->get_rid(), xform);
+ ps->body_set_shape_metadata(q.body, shape_idx++, Vector2(E->key().x, E->key().y));
}
}
if (debug_canvas_item.is_valid()) {
- vs->canvas_item_add_set_transform(debug_canvas_item,Transform2D());
+ vs->canvas_item_add_set_transform(debug_canvas_item, Transform2D());
}
if (navigation) {
@@ -501,145 +481,134 @@ void TileMap::_update_dirty_quadrants() {
if (navpoly.is_valid()) {
Vector2 npoly_ofs = tile_set->tile_get_navigation_polygon_offset(c.id);
Transform2D xform;
- xform.set_origin(offset.floor()+q.pos);
- _fix_cell_transform(xform,c,npoly_ofs+center_ofs,s);
+ xform.set_origin(offset.floor() + q.pos);
+ _fix_cell_transform(xform, c, npoly_ofs + center_ofs, s);
-
- int pid = navigation->navpoly_create(navpoly,nav_rel * xform);
+ int pid = navigation->navpoly_create(navpoly, nav_rel * xform);
Quadrant::NavPoly np;
- np.id=pid;
- np.xform=xform;
- q.navpoly_ids[E->key()]=np;
+ np.id = pid;
+ np.xform = xform;
+ q.navpoly_ids[E->key()] = np;
}
}
-
- Ref<OccluderPolygon2D> occluder=tile_set->tile_get_light_occluder(c.id);
+ Ref<OccluderPolygon2D> occluder = tile_set->tile_get_light_occluder(c.id);
if (occluder.is_valid()) {
Vector2 occluder_ofs = tile_set->tile_get_occluder_offset(c.id);
Transform2D xform;
- xform.set_origin(offset.floor()+q.pos);
- _fix_cell_transform(xform,c,occluder_ofs+center_ofs,s);
+ xform.set_origin(offset.floor() + q.pos);
+ _fix_cell_transform(xform, c, occluder_ofs + center_ofs, s);
RID orid = VS::get_singleton()->canvas_light_occluder_create();
- VS::get_singleton()->canvas_light_occluder_set_transform(orid,get_global_transform() * xform);
- VS::get_singleton()->canvas_light_occluder_set_polygon(orid,occluder->get_rid());
- VS::get_singleton()->canvas_light_occluder_attach_to_canvas(orid,get_canvas());
- VS::get_singleton()->canvas_light_occluder_set_light_mask(orid,occluder_light_mask);
+ VS::get_singleton()->canvas_light_occluder_set_transform(orid, get_global_transform() * xform);
+ VS::get_singleton()->canvas_light_occluder_set_polygon(orid, occluder->get_rid());
+ VS::get_singleton()->canvas_light_occluder_attach_to_canvas(orid, get_canvas());
+ VS::get_singleton()->canvas_light_occluder_set_light_mask(orid, occluder_light_mask);
Quadrant::Occluder oc;
- oc.xform=xform;
- oc.id=orid;
- q.occluder_instances[E->key()]=oc;
+ oc.xform = xform;
+ oc.id = orid;
+ q.occluder_instances[E->key()] = oc;
}
}
- dirty_quadrant_list.remove( dirty_quadrant_list.first() );
- quadrant_order_dirty=true;
+ dirty_quadrant_list.remove(dirty_quadrant_list.first());
+ quadrant_order_dirty = true;
}
-
-
- pending_update=false;
+ pending_update = false;
if (quadrant_order_dirty) {
- int index=-0x80000000; //always must be drawn below children
- for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) {
+ int index = -0x80000000; //always must be drawn below children
+ for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
- Quadrant &q=E->get();
- for (List<RID>::Element *E=q.canvas_items.front();E;E=E->next()) {
+ Quadrant &q = E->get();
+ for (List<RID>::Element *E = q.canvas_items.front(); E; E = E->next()) {
- VS::get_singleton()->canvas_item_set_draw_index(E->get(),index++);
+ VS::get_singleton()->canvas_item_set_draw_index(E->get(), index++);
}
}
- quadrant_order_dirty=false;
+ quadrant_order_dirty = false;
}
_recompute_rect_cache();
-
}
void TileMap::_recompute_rect_cache() {
-
#ifdef DEBUG_ENABLED
if (!rect_cache_dirty)
return;
Rect2 r_total;
- for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) {
-
+ for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
Rect2 r;
- r.pos=_map_to_world(E->key().x*_get_quadrant_size(), E->key().y*_get_quadrant_size());
- r.expand_to( _map_to_world(E->key().x*_get_quadrant_size()+_get_quadrant_size(), E->key().y*_get_quadrant_size()) );
- r.expand_to( _map_to_world(E->key().x*_get_quadrant_size()+_get_quadrant_size(), E->key().y*_get_quadrant_size()+_get_quadrant_size()) );
- r.expand_to( _map_to_world(E->key().x*_get_quadrant_size(), E->key().y*_get_quadrant_size()+_get_quadrant_size()) );
- if (E==quadrant_map.front())
- r_total=r;
+ r.pos = _map_to_world(E->key().x * _get_quadrant_size(), E->key().y * _get_quadrant_size());
+ r.expand_to(_map_to_world(E->key().x * _get_quadrant_size() + _get_quadrant_size(), E->key().y * _get_quadrant_size()));
+ r.expand_to(_map_to_world(E->key().x * _get_quadrant_size() + _get_quadrant_size(), E->key().y * _get_quadrant_size() + _get_quadrant_size()));
+ r.expand_to(_map_to_world(E->key().x * _get_quadrant_size(), E->key().y * _get_quadrant_size() + _get_quadrant_size()));
+ if (E == quadrant_map.front())
+ r_total = r;
else
- r_total=r_total.merge(r);
-
+ r_total = r_total.merge(r);
}
- if (r_total==Rect2()) {
- rect_cache=Rect2(-10,-10,20,20);
+ if (r_total == Rect2()) {
+ rect_cache = Rect2(-10, -10, 20, 20);
} else {
- rect_cache=r_total.grow(MAX(cell_size.x,cell_size.y)*_get_quadrant_size());
+ rect_cache = r_total.grow(MAX(cell_size.x, cell_size.y) * _get_quadrant_size());
}
item_rect_changed();
- rect_cache_dirty=false;
+ rect_cache_dirty = false;
#endif
-
-
}
-Map<TileMap::PosKey,TileMap::Quadrant>::Element *TileMap::_create_quadrant(const PosKey& p_qk) {
+Map<TileMap::PosKey, TileMap::Quadrant>::Element *TileMap::_create_quadrant(const PosKey &p_qk) {
Transform2D xform;
//xform.set_origin(Point2(p_qk.x,p_qk.y)*cell_size*quadrant_size);
Quadrant q;
- q.pos = _map_to_world(p_qk.x*_get_quadrant_size(),p_qk.y*_get_quadrant_size());
- q.pos+=get_cell_draw_offset();
- if (tile_origin==TILE_ORIGIN_CENTER)
- q.pos+=cell_size/2;
- else if (tile_origin==TILE_ORIGIN_BOTTOM_LEFT)
- q.pos.y+=cell_size.y;
-
-
- xform.set_origin( q.pos );
+ q.pos = _map_to_world(p_qk.x * _get_quadrant_size(), p_qk.y * _get_quadrant_size());
+ q.pos += get_cell_draw_offset();
+ if (tile_origin == TILE_ORIGIN_CENTER)
+ q.pos += cell_size / 2;
+ else if (tile_origin == TILE_ORIGIN_BOTTOM_LEFT)
+ q.pos.y += cell_size.y;
+
+ xform.set_origin(q.pos);
//q.canvas_item = VisualServer::get_singleton()->canvas_item_create();
- q.body=Physics2DServer::get_singleton()->body_create(use_kinematic?Physics2DServer::BODY_MODE_KINEMATIC:Physics2DServer::BODY_MODE_STATIC);
- Physics2DServer::get_singleton()->body_attach_object_instance_ID(q.body,get_instance_ID());
- Physics2DServer::get_singleton()->body_set_layer_mask(q.body,collision_layer);
- Physics2DServer::get_singleton()->body_set_collision_mask(q.body,collision_mask);
- Physics2DServer::get_singleton()->body_set_param(q.body,Physics2DServer::BODY_PARAM_FRICTION,friction);
- Physics2DServer::get_singleton()->body_set_param(q.body,Physics2DServer::BODY_PARAM_BOUNCE,bounce);
+ q.body = Physics2DServer::get_singleton()->body_create(use_kinematic ? Physics2DServer::BODY_MODE_KINEMATIC : Physics2DServer::BODY_MODE_STATIC);
+ Physics2DServer::get_singleton()->body_attach_object_instance_ID(q.body, get_instance_ID());
+ Physics2DServer::get_singleton()->body_set_layer_mask(q.body, collision_layer);
+ Physics2DServer::get_singleton()->body_set_collision_mask(q.body, collision_mask);
+ Physics2DServer::get_singleton()->body_set_param(q.body, Physics2DServer::BODY_PARAM_FRICTION, friction);
+ Physics2DServer::get_singleton()->body_set_param(q.body, Physics2DServer::BODY_PARAM_BOUNCE, bounce);
if (is_inside_tree()) {
xform = get_global_transform() * xform;
RID space = get_world_2d()->get_space();
- Physics2DServer::get_singleton()->body_set_space(q.body,space);
+ Physics2DServer::get_singleton()->body_set_space(q.body, space);
}
- Physics2DServer::get_singleton()->body_set_state(q.body,Physics2DServer::BODY_STATE_TRANSFORM,xform);
+ Physics2DServer::get_singleton()->body_set_state(q.body, Physics2DServer::BODY_STATE_TRANSFORM, xform);
- rect_cache_dirty=true;
- quadrant_order_dirty=true;
- return quadrant_map.insert(p_qk,q);
+ rect_cache_dirty = true;
+ quadrant_order_dirty = true;
+ return quadrant_map.insert(p_qk, q);
}
-void TileMap::_erase_quadrant(Map<PosKey,Quadrant>::Element *Q) {
+void TileMap::_erase_quadrant(Map<PosKey, Quadrant>::Element *Q) {
- Quadrant &q=Q->get();
+ Quadrant &q = Q->get();
Physics2DServer::get_singleton()->free(q.body);
- for (List<RID>::Element *E=q.canvas_items.front();E;E=E->next()) {
+ for (List<RID>::Element *E = q.canvas_items.front(); E; E = E->next()) {
VisualServer::get_singleton()->free(E->get());
}
@@ -648,58 +617,58 @@ void TileMap::_erase_quadrant(Map<PosKey,Quadrant>::Element *Q) {
dirty_quadrant_list.remove(&q.dirty_list);
if (navigation) {
- for(Map<PosKey,Quadrant::NavPoly>::Element *E=q.navpoly_ids.front();E;E=E->next()) {
+ for (Map<PosKey, Quadrant::NavPoly>::Element *E = q.navpoly_ids.front(); E; E = E->next()) {
navigation->navpoly_remove(E->get().id);
}
q.navpoly_ids.clear();
}
- for(Map<PosKey,Quadrant::Occluder>::Element *E=q.occluder_instances.front();E;E=E->next()) {
+ for (Map<PosKey, Quadrant::Occluder>::Element *E = q.occluder_instances.front(); E; E = E->next()) {
VS::get_singleton()->free(E->get().id);
}
q.occluder_instances.clear();
quadrant_map.erase(Q);
- rect_cache_dirty=true;
+ rect_cache_dirty = true;
}
-void TileMap::_make_quadrant_dirty(Map<PosKey,Quadrant>::Element *Q) {
+void TileMap::_make_quadrant_dirty(Map<PosKey, Quadrant>::Element *Q) {
- Quadrant &q=Q->get();
+ Quadrant &q = Q->get();
if (!q.dirty_list.in_list())
dirty_quadrant_list.add(&q.dirty_list);
if (pending_update)
return;
- pending_update=true;
+ pending_update = true;
if (!is_inside_tree())
return;
call_deferred("_update_dirty_quadrants");
}
-void TileMap::set_cellv(const Vector2& p_pos,int p_tile,bool p_flip_x,bool p_flip_y,bool p_transpose) {
+void TileMap::set_cellv(const Vector2 &p_pos, int p_tile, bool p_flip_x, bool p_flip_y, bool p_transpose) {
- set_cell(p_pos.x,p_pos.y,p_tile,p_flip_x,p_flip_y,p_transpose);
+ set_cell(p_pos.x, p_pos.y, p_tile, p_flip_x, p_flip_y, p_transpose);
}
-void TileMap::set_cell(int p_x,int p_y,int p_tile,bool p_flip_x,bool p_flip_y,bool p_transpose) {
+void TileMap::set_cell(int p_x, int p_y, int p_tile, bool p_flip_x, bool p_flip_y, bool p_transpose) {
- PosKey pk(p_x,p_y);
+ PosKey pk(p_x, p_y);
- Map<PosKey,Cell>::Element *E=tile_map.find(pk);
- if (!E && p_tile==INVALID_CELL)
+ Map<PosKey, Cell>::Element *E = tile_map.find(pk);
+ if (!E && p_tile == INVALID_CELL)
return; //nothing to do
- PosKey qk(p_x/_get_quadrant_size(),p_y/_get_quadrant_size());
- if (p_tile==INVALID_CELL) {
+ PosKey qk(p_x / _get_quadrant_size(), p_y / _get_quadrant_size());
+ if (p_tile == INVALID_CELL) {
//erase existing
tile_map.erase(pk);
- Map<PosKey,Quadrant>::Element *Q = quadrant_map.find(qk);
+ Map<PosKey, Quadrant>::Element *Q = quadrant_map.find(qk);
ERR_FAIL_COND(!Q);
- Quadrant &q=Q->get();
+ Quadrant &q = Q->get();
q.cells.erase(pk);
- if (q.cells.size()==0)
+ if (q.cells.size() == 0)
_erase_quadrant(Q);
else
_make_quadrant_dirty(Q);
@@ -707,79 +676,75 @@ void TileMap::set_cell(int p_x,int p_y,int p_tile,bool p_flip_x,bool p_flip_y,bo
return;
}
- Map<PosKey,Quadrant>::Element *Q = quadrant_map.find(qk);
+ Map<PosKey, Quadrant>::Element *Q = quadrant_map.find(qk);
if (!E) {
- E=tile_map.insert(pk,Cell());
+ E = tile_map.insert(pk, Cell());
if (!Q) {
- Q=_create_quadrant(qk);
+ Q = _create_quadrant(qk);
}
- Quadrant &q=Q->get();
+ Quadrant &q = Q->get();
q.cells.insert(pk);
} else {
ERR_FAIL_COND(!Q); // quadrant should exist...
- if (E->get().id==p_tile && E->get().flip_h==p_flip_x && E->get().flip_v==p_flip_y && E->get().transpose==p_transpose)
+ if (E->get().id == p_tile && E->get().flip_h == p_flip_x && E->get().flip_v == p_flip_y && E->get().transpose == p_transpose)
return; //nothing changed
-
}
-
Cell &c = E->get();
- c.id=p_tile;
- c.flip_h=p_flip_x;
- c.flip_v=p_flip_y;
- c.transpose=p_transpose;
+ c.id = p_tile;
+ c.flip_h = p_flip_x;
+ c.flip_v = p_flip_y;
+ c.transpose = p_transpose;
_make_quadrant_dirty(Q);
- used_size_cache_dirty=true;
-
+ used_size_cache_dirty = true;
}
-int TileMap::get_cellv(const Vector2& p_pos) const {
- return get_cell(p_pos.x,p_pos.y);
+int TileMap::get_cellv(const Vector2 &p_pos) const {
+ return get_cell(p_pos.x, p_pos.y);
}
-int TileMap::get_cell(int p_x,int p_y) const {
+int TileMap::get_cell(int p_x, int p_y) const {
- PosKey pk(p_x,p_y);
+ PosKey pk(p_x, p_y);
- const Map<PosKey,Cell>::Element *E=tile_map.find(pk);
+ const Map<PosKey, Cell>::Element *E = tile_map.find(pk);
if (!E)
return INVALID_CELL;
return E->get().id;
-
}
-bool TileMap::is_cell_x_flipped(int p_x,int p_y) const {
+bool TileMap::is_cell_x_flipped(int p_x, int p_y) const {
- PosKey pk(p_x,p_y);
+ PosKey pk(p_x, p_y);
- const Map<PosKey,Cell>::Element *E=tile_map.find(pk);
+ const Map<PosKey, Cell>::Element *E = tile_map.find(pk);
if (!E)
return false;
return E->get().flip_h;
}
-bool TileMap::is_cell_y_flipped(int p_x,int p_y) const {
+bool TileMap::is_cell_y_flipped(int p_x, int p_y) const {
- PosKey pk(p_x,p_y);
+ PosKey pk(p_x, p_y);
- const Map<PosKey,Cell>::Element *E=tile_map.find(pk);
+ const Map<PosKey, Cell>::Element *E = tile_map.find(pk);
if (!E)
return false;
return E->get().flip_v;
}
-bool TileMap::is_cell_transposed(int p_x,int p_y) const {
+bool TileMap::is_cell_transposed(int p_x, int p_y) const {
- PosKey pk(p_x,p_y);
+ PosKey pk(p_x, p_y);
- const Map<PosKey,Cell>::Element *E=tile_map.find(pk);
+ const Map<PosKey, Cell>::Element *E = tile_map.find(pk);
if (!E)
return false;
@@ -787,34 +752,29 @@ bool TileMap::is_cell_transposed(int p_x,int p_y) const {
return E->get().transpose;
}
-
void TileMap::_recreate_quadrants() {
_clear_quadrants();
- for (Map<PosKey,Cell>::Element *E=tile_map.front();E;E=E->next()) {
+ for (Map<PosKey, Cell>::Element *E = tile_map.front(); E; E = E->next()) {
- PosKey qk(E->key().x/_get_quadrant_size(),E->key().y/_get_quadrant_size());
+ PosKey qk(E->key().x / _get_quadrant_size(), E->key().y / _get_quadrant_size());
- Map<PosKey,Quadrant>::Element *Q=quadrant_map.find(qk);
+ Map<PosKey, Quadrant>::Element *Q = quadrant_map.find(qk);
if (!Q) {
- Q=_create_quadrant(qk);
+ Q = _create_quadrant(qk);
dirty_quadrant_list.add(&Q->get().dirty_list);
}
Q->get().cells.insert(E->key());
_make_quadrant_dirty(Q);
}
-
-
-
}
-
void TileMap::_clear_quadrants() {
while (quadrant_map.size()) {
- _erase_quadrant( quadrant_map.front() );
+ _erase_quadrant(quadrant_map.front());
}
}
@@ -822,107 +782,101 @@ void TileMap::clear() {
_clear_quadrants();
tile_map.clear();
- used_size_cache_dirty=true;
+ used_size_cache_dirty = true;
}
-void TileMap::_set_tile_data(const PoolVector<int>& p_data) {
+void TileMap::_set_tile_data(const PoolVector<int> &p_data) {
- int c=p_data.size();
+ int c = p_data.size();
PoolVector<int>::Read r = p_data.read();
+ for (int i = 0; i < c; i += 2) {
- for(int i=0;i<c;i+=2) {
-
- const uint8_t *ptr=(const uint8_t*)&r[i];
+ const uint8_t *ptr = (const uint8_t *)&r[i];
uint8_t local[8];
- for(int j=0;j<8;j++)
- local[j]=ptr[j];
+ for (int j = 0; j < 8; j++)
+ local[j] = ptr[j];
#ifdef BIG_ENDIAN_ENABLED
-
- SWAP(local[0],local[3]);
- SWAP(local[1],local[2]);
- SWAP(local[4],local[7]);
- SWAP(local[5],local[6]);
+ SWAP(local[0], local[3]);
+ SWAP(local[1], local[2]);
+ SWAP(local[4], local[7]);
+ SWAP(local[5], local[6]);
#endif
int16_t x = decode_uint16(&local[0]);
int16_t y = decode_uint16(&local[2]);
uint32_t v = decode_uint32(&local[4]);
- bool flip_h = v&(1<<29);
- bool flip_v = v&(1<<30);
- bool transpose = v&(1<<31);
- v&=(1<<29)-1;
+ bool flip_h = v & (1 << 29);
+ bool flip_v = v & (1 << 30);
+ bool transpose = v & (1 << 31);
+ v &= (1 << 29) - 1;
/*
if (x<-20 || y <-20 || x>4000 || y>4000)
continue;
*/
- set_cell(x,y,v,flip_h,flip_v,transpose);
-
+ set_cell(x, y, v, flip_h, flip_v, transpose);
}
-
}
PoolVector<int> TileMap::_get_tile_data() const {
PoolVector<int> data;
- data.resize(tile_map.size()*2);
+ data.resize(tile_map.size() * 2);
PoolVector<int>::Write w = data.write();
- int idx=0;
- for(const Map<PosKey,Cell>::Element *E=tile_map.front();E;E=E->next()) {
+ int idx = 0;
+ for (const Map<PosKey, Cell>::Element *E = tile_map.front(); E; E = E->next()) {
- uint8_t *ptr = (uint8_t*)&w[idx];
- encode_uint16(E->key().x,&ptr[0]);
- encode_uint16(E->key().y,&ptr[2]);
+ uint8_t *ptr = (uint8_t *)&w[idx];
+ encode_uint16(E->key().x, &ptr[0]);
+ encode_uint16(E->key().y, &ptr[2]);
uint32_t val = E->get().id;
if (E->get().flip_h)
- val|=(1<<29);
+ val |= (1 << 29);
if (E->get().flip_v)
- val|=(1<<30);
+ val |= (1 << 30);
if (E->get().transpose)
- val|=(1<<31);
+ val |= (1 << 31);
- encode_uint32(val,&ptr[4]);
- idx+=2;
+ encode_uint32(val, &ptr[4]);
+ idx += 2;
}
-
w = PoolVector<int>::Write();
return data;
-
}
Rect2 TileMap::get_item_rect() const {
- const_cast<TileMap*>(this)->_update_dirty_quadrants();
+ const_cast<TileMap *>(this)->_update_dirty_quadrants();
return rect_cache;
}
void TileMap::set_collision_layer(uint32_t p_layer) {
- collision_layer=p_layer;
- for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) {
+ collision_layer = p_layer;
+ for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
- Quadrant &q=E->get();
- Physics2DServer::get_singleton()->body_set_layer_mask(q.body,collision_layer);
+ Quadrant &q = E->get();
+ Physics2DServer::get_singleton()->body_set_layer_mask(q.body, collision_layer);
}
}
void TileMap::set_collision_mask(uint32_t p_mask) {
- collision_mask=p_mask;
- for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) {
+ collision_mask = p_mask;
+ for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
- Quadrant &q=E->get();
- Physics2DServer::get_singleton()->body_set_collision_mask(q.body,collision_mask);
+ Quadrant &q = E->get();
+ Physics2DServer::get_singleton()->body_set_collision_mask(q.body, collision_mask);
}
}
-bool TileMap::get_collision_use_kinematic() const{
+bool TileMap::get_collision_use_kinematic() const {
return use_kinematic;
}
@@ -930,42 +884,39 @@ bool TileMap::get_collision_use_kinematic() const{
void TileMap::set_collision_use_kinematic(bool p_use_kinematic) {
_clear_quadrants();
- use_kinematic=p_use_kinematic;
+ use_kinematic = p_use_kinematic;
_recreate_quadrants();
}
void TileMap::set_collision_friction(float p_friction) {
- friction=p_friction;
- for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) {
+ friction = p_friction;
+ for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
- Quadrant &q=E->get();
- Physics2DServer::get_singleton()->body_set_param(q.body,Physics2DServer::BODY_PARAM_FRICTION,p_friction);
+ Quadrant &q = E->get();
+ Physics2DServer::get_singleton()->body_set_param(q.body, Physics2DServer::BODY_PARAM_FRICTION, p_friction);
}
-
}
-float TileMap::get_collision_friction() const{
+float TileMap::get_collision_friction() const {
return friction;
}
-void TileMap::set_collision_bounce(float p_bounce){
+void TileMap::set_collision_bounce(float p_bounce) {
- bounce=p_bounce;
- for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) {
+ bounce = p_bounce;
+ for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
- Quadrant &q=E->get();
- Physics2DServer::get_singleton()->body_set_param(q.body,Physics2DServer::BODY_PARAM_BOUNCE,p_bounce);
+ Quadrant &q = E->get();
+ Physics2DServer::get_singleton()->body_set_param(q.body, Physics2DServer::BODY_PARAM_BOUNCE, p_bounce);
}
-
}
-float TileMap::get_collision_bounce() const{
+float TileMap::get_collision_bounce() const {
return bounce;
}
-
uint32_t TileMap::get_collision_layer() const {
return collision_layer;
@@ -979,7 +930,7 @@ uint32_t TileMap::get_collision_mask() const {
void TileMap::set_mode(Mode p_mode) {
_clear_quadrants();
- mode=p_mode;
+ mode = p_mode;
_recreate_quadrants();
emit_signal("settings_changed");
}
@@ -991,7 +942,7 @@ TileMap::Mode TileMap::get_mode() const {
void TileMap::set_half_offset(HalfOffset p_half_offset) {
_clear_quadrants();
- half_offset=p_half_offset;
+ half_offset = p_half_offset;
_recreate_quadrants();
emit_signal("settings_changed");
}
@@ -999,20 +950,19 @@ void TileMap::set_half_offset(HalfOffset p_half_offset) {
void TileMap::set_tile_origin(TileOrigin p_tile_origin) {
_clear_quadrants();
- tile_origin=p_tile_origin;
+ tile_origin = p_tile_origin;
_recreate_quadrants();
emit_signal("settings_changed");
}
-TileMap::TileOrigin TileMap::get_tile_origin() const{
+TileMap::TileOrigin TileMap::get_tile_origin() const {
return tile_origin;
}
-
Vector2 TileMap::get_cell_draw_offset() const {
- switch(mode) {
+ switch (mode) {
case MODE_SQUARE: {
@@ -1020,22 +970,21 @@ Vector2 TileMap::get_cell_draw_offset() const {
} break;
case MODE_ISOMETRIC: {
- return Vector2(-cell_size.x*0.5,0);
+ return Vector2(-cell_size.x * 0.5, 0);
} break;
case MODE_CUSTOM: {
Vector2 min;
- min.x = MIN(custom_transform[0].x,min.x);
- min.y = MIN(custom_transform[0].y,min.y);
- min.x = MIN(custom_transform[1].x,min.x);
- min.y = MIN(custom_transform[1].y,min.y);
+ min.x = MIN(custom_transform[0].x, min.x);
+ min.y = MIN(custom_transform[0].y, min.y);
+ min.x = MIN(custom_transform[1].x, min.x);
+ min.y = MIN(custom_transform[1].y, min.y);
return min;
} break;
}
return Vector2();
-
}
TileMap::HalfOffset TileMap::get_half_offset() const {
@@ -1044,13 +993,13 @@ TileMap::HalfOffset TileMap::get_half_offset() const {
Transform2D TileMap::get_cell_transform() const {
- switch(mode) {
+ switch (mode) {
case MODE_SQUARE: {
Transform2D m;
- m[0]*=cell_size.x;
- m[1]*=cell_size.y;
+ m[0] *= cell_size.x;
+ m[1] *= cell_size.y;
return m;
} break;
case MODE_ISOMETRIC: {
@@ -1058,8 +1007,8 @@ Transform2D TileMap::get_cell_transform() const {
//isometric only makes sense when y is positive in both x and y vectors, otherwise
//the drawing of tiles will overlap
Transform2D m;
- m[0]=Vector2(cell_size.x*0.5,cell_size.y*0.5);
- m[1]=Vector2(-cell_size.x*0.5,cell_size.y*0.5);
+ m[0] = Vector2(cell_size.x * 0.5, cell_size.y * 0.5);
+ m[1] = Vector2(-cell_size.x * 0.5, cell_size.y * 0.5);
return m;
} break;
@@ -1072,35 +1021,34 @@ Transform2D TileMap::get_cell_transform() const {
return Transform2D();
}
-void TileMap::set_custom_transform(const Transform2D& p_xform) {
+void TileMap::set_custom_transform(const Transform2D &p_xform) {
_clear_quadrants();
- custom_transform=p_xform;
+ custom_transform = p_xform;
_recreate_quadrants();
emit_signal("settings_changed");
-
}
-Transform2D TileMap::get_custom_transform() const{
+Transform2D TileMap::get_custom_transform() const {
return custom_transform;
}
-Vector2 TileMap::_map_to_world(int x,int y,bool p_ignore_ofs) const {
+Vector2 TileMap::_map_to_world(int x, int y, bool p_ignore_ofs) const {
- Vector2 ret = get_cell_transform().xform(Vector2(x,y));
+ Vector2 ret = get_cell_transform().xform(Vector2(x, y));
if (!p_ignore_ofs) {
- switch(half_offset) {
+ switch (half_offset) {
case HALF_OFFSET_X: {
- if (ABS(y)&1) {
+ if (ABS(y) & 1) {
- ret+=get_cell_transform()[0]*0.5;
+ ret += get_cell_transform()[0] * 0.5;
}
} break;
case HALF_OFFSET_Y: {
- if (ABS(x)&1) {
- ret+=get_cell_transform()[1]*0.5;
+ if (ABS(x) & 1) {
+ ret += get_cell_transform()[1] * 0.5;
}
} break;
default: {}
@@ -1108,25 +1056,24 @@ Vector2 TileMap::_map_to_world(int x,int y,bool p_ignore_ofs) const {
}
return ret;
}
-Vector2 TileMap::map_to_world(const Vector2& p_pos,bool p_ignore_ofs) const {
+Vector2 TileMap::map_to_world(const Vector2 &p_pos, bool p_ignore_ofs) const {
- return _map_to_world(p_pos.x,p_pos.y,p_ignore_ofs);
+ return _map_to_world(p_pos.x, p_pos.y, p_ignore_ofs);
}
-Vector2 TileMap::world_to_map(const Vector2& p_pos) const{
+Vector2 TileMap::world_to_map(const Vector2 &p_pos) const {
Vector2 ret = get_cell_transform().affine_inverse().xform(p_pos);
-
- switch(half_offset) {
+ switch (half_offset) {
case HALF_OFFSET_X: {
- if ( ret.y > 0 ? int(ret.y)&1 : (int(ret.y)-1)&1 ) {
- ret.x-=0.5;
+ if (ret.y > 0 ? int(ret.y) & 1 : (int(ret.y) - 1) & 1) {
+ ret.x -= 0.5;
}
} break;
case HALF_OFFSET_Y: {
- if ( ret.x > 0 ? int(ret.x)&1 : (int(ret.x)-1)&1) {
- ret.y-=0.5;
+ if (ret.x > 0 ? int(ret.x) & 1 : (int(ret.x) - 1) & 1) {
+ ret.y -= 0.5;
}
} break;
default: {}
@@ -1138,11 +1085,10 @@ Vector2 TileMap::world_to_map(const Vector2& p_pos) const{
void TileMap::set_y_sort_mode(bool p_enable) {
_clear_quadrants();
- y_sort_mode=p_enable;
- VS::get_singleton()->canvas_item_set_sort_children_by_y(get_canvas_item(),y_sort_mode);
+ y_sort_mode = p_enable;
+ VS::get_singleton()->canvas_item_set_sort_children_by_y(get_canvas_item(), y_sort_mode);
_recreate_quadrants();
emit_signal("settings_changed");
-
}
bool TileMap::is_y_sort_mode_enabled() const {
@@ -1154,11 +1100,11 @@ Array TileMap::get_used_cells() const {
Array a;
a.resize(tile_map.size());
- int i=0;
- for (Map<PosKey,Cell>::Element *E=tile_map.front();E;E=E->next()) {
+ int i = 0;
+ for (Map<PosKey, Cell>::Element *E = tile_map.front(); E; E = E->next()) {
- Vector2 p (E->key().x,E->key().y);
- a[i++]=p;
+ Vector2 p(E->key().x, E->key().y);
+ a[i++] = p;
}
return a;
@@ -1167,14 +1113,14 @@ Array TileMap::get_used_cells() const {
Rect2 TileMap::get_used_rect() { // Not const because of cache
if (used_size_cache_dirty) {
- if(tile_map.size() > 0) {
+ if (tile_map.size() > 0) {
used_size_cache = Rect2(tile_map.front()->key().x, tile_map.front()->key().y, 0, 0);
- for (Map<PosKey,Cell>::Element *E=tile_map.front();E;E=E->next()) {
+ for (Map<PosKey, Cell>::Element *E = tile_map.front(); E; E = E->next()) {
used_size_cache.expand_to(Vector2(E->key().x, E->key().y));
}
- used_size_cache.size += Vector2(1,1);
+ used_size_cache.size += Vector2(1, 1);
} else {
used_size_cache = Rect2();
}
@@ -1185,19 +1131,18 @@ Rect2 TileMap::get_used_rect() { // Not const because of cache
return used_size_cache;
}
-
void TileMap::set_occluder_light_mask(int p_mask) {
- occluder_light_mask=p_mask;
- for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) {
+ occluder_light_mask = p_mask;
+ for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
- for (Map<PosKey,Quadrant::Occluder>::Element *F=E->get().occluder_instances.front();F;F=F->next()) {
- VisualServer::get_singleton()->canvas_light_occluder_set_light_mask(F->get().id,occluder_light_mask);
+ for (Map<PosKey, Quadrant::Occluder>::Element *F = E->get().occluder_instances.front(); F; F = F->next()) {
+ VisualServer::get_singleton()->canvas_light_occluder_set_light_mask(F->get().id, occluder_light_mask);
}
}
}
-int TileMap::get_occluder_light_mask() const{
+int TileMap::get_occluder_light_mask() const {
return occluder_light_mask;
}
@@ -1205,154 +1150,150 @@ int TileMap::get_occluder_light_mask() const{
void TileMap::set_light_mask(int p_light_mask) {
CanvasItem::set_light_mask(p_light_mask);
- for (Map<PosKey,Quadrant>::Element *E=quadrant_map.front();E;E=E->next()) {
+ for (Map<PosKey, Quadrant>::Element *E = quadrant_map.front(); E; E = E->next()) {
- for (List<RID>::Element *F=E->get().canvas_items.front();F;F=F->next()) {
- VisualServer::get_singleton()->canvas_item_set_light_mask(F->get(),get_light_mask());
+ for (List<RID>::Element *F = E->get().canvas_items.front(); F; F = F->next()) {
+ VisualServer::get_singleton()->canvas_item_set_light_mask(F->get(), get_light_mask());
}
}
}
void TileMap::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_tileset", "tileset:TileSet"), &TileMap::set_tileset);
+ ClassDB::bind_method(D_METHOD("get_tileset:TileSet"), &TileMap::get_tileset);
- ClassDB::bind_method(D_METHOD("set_tileset","tileset:TileSet"),&TileMap::set_tileset);
- ClassDB::bind_method(D_METHOD("get_tileset:TileSet"),&TileMap::get_tileset);
-
- ClassDB::bind_method(D_METHOD("set_mode","mode"),&TileMap::set_mode);
- ClassDB::bind_method(D_METHOD("get_mode"),&TileMap::get_mode);
+ ClassDB::bind_method(D_METHOD("set_mode", "mode"), &TileMap::set_mode);
+ ClassDB::bind_method(D_METHOD("get_mode"), &TileMap::get_mode);
- ClassDB::bind_method(D_METHOD("set_half_offset","half_offset"),&TileMap::set_half_offset);
- ClassDB::bind_method(D_METHOD("get_half_offset"),&TileMap::get_half_offset);
+ ClassDB::bind_method(D_METHOD("set_half_offset", "half_offset"), &TileMap::set_half_offset);
+ ClassDB::bind_method(D_METHOD("get_half_offset"), &TileMap::get_half_offset);
- ClassDB::bind_method(D_METHOD("set_custom_transform","custom_transform"),&TileMap::set_custom_transform);
- ClassDB::bind_method(D_METHOD("get_custom_transform"),&TileMap::get_custom_transform);
+ ClassDB::bind_method(D_METHOD("set_custom_transform", "custom_transform"), &TileMap::set_custom_transform);
+ ClassDB::bind_method(D_METHOD("get_custom_transform"), &TileMap::get_custom_transform);
- ClassDB::bind_method(D_METHOD("set_cell_size","size"),&TileMap::set_cell_size);
- ClassDB::bind_method(D_METHOD("get_cell_size"),&TileMap::get_cell_size);
+ ClassDB::bind_method(D_METHOD("set_cell_size", "size"), &TileMap::set_cell_size);
+ ClassDB::bind_method(D_METHOD("get_cell_size"), &TileMap::get_cell_size);
- ClassDB::bind_method(D_METHOD("_set_old_cell_size","size"),&TileMap::_set_old_cell_size);
- ClassDB::bind_method(D_METHOD("_get_old_cell_size"),&TileMap::_get_old_cell_size);
+ ClassDB::bind_method(D_METHOD("_set_old_cell_size", "size"), &TileMap::_set_old_cell_size);
+ ClassDB::bind_method(D_METHOD("_get_old_cell_size"), &TileMap::_get_old_cell_size);
- ClassDB::bind_method(D_METHOD("set_quadrant_size","size"),&TileMap::set_quadrant_size);
- ClassDB::bind_method(D_METHOD("get_quadrant_size"),&TileMap::get_quadrant_size);
+ ClassDB::bind_method(D_METHOD("set_quadrant_size", "size"), &TileMap::set_quadrant_size);
+ ClassDB::bind_method(D_METHOD("get_quadrant_size"), &TileMap::get_quadrant_size);
- ClassDB::bind_method(D_METHOD("set_tile_origin","origin"),&TileMap::set_tile_origin);
- ClassDB::bind_method(D_METHOD("get_tile_origin"),&TileMap::get_tile_origin);
+ ClassDB::bind_method(D_METHOD("set_tile_origin", "origin"), &TileMap::set_tile_origin);
+ ClassDB::bind_method(D_METHOD("get_tile_origin"), &TileMap::get_tile_origin);
- ClassDB::bind_method(D_METHOD("set_center_x","enable"),&TileMap::set_center_x);
- ClassDB::bind_method(D_METHOD("get_center_x"),&TileMap::get_center_x);
+ ClassDB::bind_method(D_METHOD("set_center_x", "enable"), &TileMap::set_center_x);
+ ClassDB::bind_method(D_METHOD("get_center_x"), &TileMap::get_center_x);
- ClassDB::bind_method(D_METHOD("set_center_y","enable"),&TileMap::set_center_y);
- ClassDB::bind_method(D_METHOD("get_center_y"),&TileMap::get_center_y);
+ ClassDB::bind_method(D_METHOD("set_center_y", "enable"), &TileMap::set_center_y);
+ ClassDB::bind_method(D_METHOD("get_center_y"), &TileMap::get_center_y);
- ClassDB::bind_method(D_METHOD("set_y_sort_mode","enable"),&TileMap::set_y_sort_mode);
- ClassDB::bind_method(D_METHOD("is_y_sort_mode_enabled"),&TileMap::is_y_sort_mode_enabled);
+ ClassDB::bind_method(D_METHOD("set_y_sort_mode", "enable"), &TileMap::set_y_sort_mode);
+ ClassDB::bind_method(D_METHOD("is_y_sort_mode_enabled"), &TileMap::is_y_sort_mode_enabled);
- ClassDB::bind_method(D_METHOD("set_collision_use_kinematic","use_kinematic"),&TileMap::set_collision_use_kinematic);
- ClassDB::bind_method(D_METHOD("get_collision_use_kinematic"),&TileMap::get_collision_use_kinematic);
+ ClassDB::bind_method(D_METHOD("set_collision_use_kinematic", "use_kinematic"), &TileMap::set_collision_use_kinematic);
+ ClassDB::bind_method(D_METHOD("get_collision_use_kinematic"), &TileMap::get_collision_use_kinematic);
- ClassDB::bind_method(D_METHOD("set_collision_layer","mask"),&TileMap::set_collision_layer);
- ClassDB::bind_method(D_METHOD("get_collision_layer"),&TileMap::get_collision_layer);
+ ClassDB::bind_method(D_METHOD("set_collision_layer", "mask"), &TileMap::set_collision_layer);
+ ClassDB::bind_method(D_METHOD("get_collision_layer"), &TileMap::get_collision_layer);
- ClassDB::bind_method(D_METHOD("set_collision_mask","mask"),&TileMap::set_collision_mask);
- ClassDB::bind_method(D_METHOD("get_collision_mask"),&TileMap::get_collision_mask);
+ ClassDB::bind_method(D_METHOD("set_collision_mask", "mask"), &TileMap::set_collision_mask);
+ ClassDB::bind_method(D_METHOD("get_collision_mask"), &TileMap::get_collision_mask);
- ClassDB::bind_method(D_METHOD("set_collision_friction","value"),&TileMap::set_collision_friction);
- ClassDB::bind_method(D_METHOD("get_collision_friction"),&TileMap::get_collision_friction);
+ ClassDB::bind_method(D_METHOD("set_collision_friction", "value"), &TileMap::set_collision_friction);
+ ClassDB::bind_method(D_METHOD("get_collision_friction"), &TileMap::get_collision_friction);
- ClassDB::bind_method(D_METHOD("set_collision_bounce","value"),&TileMap::set_collision_bounce);
- ClassDB::bind_method(D_METHOD("get_collision_bounce"),&TileMap::get_collision_bounce);
+ ClassDB::bind_method(D_METHOD("set_collision_bounce", "value"), &TileMap::set_collision_bounce);
+ ClassDB::bind_method(D_METHOD("get_collision_bounce"), &TileMap::get_collision_bounce);
- ClassDB::bind_method(D_METHOD("set_occluder_light_mask","mask"),&TileMap::set_occluder_light_mask);
- ClassDB::bind_method(D_METHOD("get_occluder_light_mask"),&TileMap::get_occluder_light_mask);
+ ClassDB::bind_method(D_METHOD("set_occluder_light_mask", "mask"), &TileMap::set_occluder_light_mask);
+ ClassDB::bind_method(D_METHOD("get_occluder_light_mask"), &TileMap::get_occluder_light_mask);
- ClassDB::bind_method(D_METHOD("set_cell","x","y","tile","flip_x","flip_y","transpose"),&TileMap::set_cell,DEFVAL(false),DEFVAL(false),DEFVAL(false));
- ClassDB::bind_method(D_METHOD("set_cellv","pos","tile","flip_x","flip_y","transpose"),&TileMap::set_cellv,DEFVAL(false),DEFVAL(false),DEFVAL(false));
- ClassDB::bind_method(D_METHOD("get_cell","x","y"),&TileMap::get_cell);
- ClassDB::bind_method(D_METHOD("get_cellv","pos"),&TileMap::get_cellv);
- ClassDB::bind_method(D_METHOD("is_cell_x_flipped","x","y"),&TileMap::is_cell_x_flipped);
- ClassDB::bind_method(D_METHOD("is_cell_y_flipped","x","y"),&TileMap::is_cell_y_flipped);
- ClassDB::bind_method(D_METHOD("is_cell_transposed","x","y"),&TileMap::is_cell_transposed);
+ ClassDB::bind_method(D_METHOD("set_cell", "x", "y", "tile", "flip_x", "flip_y", "transpose"), &TileMap::set_cell, DEFVAL(false), DEFVAL(false), DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("set_cellv", "pos", "tile", "flip_x", "flip_y", "transpose"), &TileMap::set_cellv, DEFVAL(false), DEFVAL(false), DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("get_cell", "x", "y"), &TileMap::get_cell);
+ ClassDB::bind_method(D_METHOD("get_cellv", "pos"), &TileMap::get_cellv);
+ ClassDB::bind_method(D_METHOD("is_cell_x_flipped", "x", "y"), &TileMap::is_cell_x_flipped);
+ ClassDB::bind_method(D_METHOD("is_cell_y_flipped", "x", "y"), &TileMap::is_cell_y_flipped);
+ ClassDB::bind_method(D_METHOD("is_cell_transposed", "x", "y"), &TileMap::is_cell_transposed);
- ClassDB::bind_method(D_METHOD("clear"),&TileMap::clear);
+ ClassDB::bind_method(D_METHOD("clear"), &TileMap::clear);
- ClassDB::bind_method(D_METHOD("get_used_cells"),&TileMap::get_used_cells);
- ClassDB::bind_method(D_METHOD("get_used_rect"),&TileMap::get_used_rect);
+ ClassDB::bind_method(D_METHOD("get_used_cells"), &TileMap::get_used_cells);
+ ClassDB::bind_method(D_METHOD("get_used_rect"), &TileMap::get_used_rect);
- ClassDB::bind_method(D_METHOD("map_to_world","mappos","ignore_half_ofs"),&TileMap::map_to_world,DEFVAL(false));
- ClassDB::bind_method(D_METHOD("world_to_map","worldpos"),&TileMap::world_to_map);
+ ClassDB::bind_method(D_METHOD("map_to_world", "mappos", "ignore_half_ofs"), &TileMap::map_to_world, DEFVAL(false));
+ ClassDB::bind_method(D_METHOD("world_to_map", "worldpos"), &TileMap::world_to_map);
- ClassDB::bind_method(D_METHOD("_clear_quadrants"),&TileMap::_clear_quadrants);
- ClassDB::bind_method(D_METHOD("_recreate_quadrants"),&TileMap::_recreate_quadrants);
- ClassDB::bind_method(D_METHOD("_update_dirty_quadrants"),&TileMap::_update_dirty_quadrants);
+ ClassDB::bind_method(D_METHOD("_clear_quadrants"), &TileMap::_clear_quadrants);
+ ClassDB::bind_method(D_METHOD("_recreate_quadrants"), &TileMap::_recreate_quadrants);
+ ClassDB::bind_method(D_METHOD("_update_dirty_quadrants"), &TileMap::_update_dirty_quadrants);
- ClassDB::bind_method(D_METHOD("_set_tile_data"),&TileMap::_set_tile_data);
- ClassDB::bind_method(D_METHOD("_get_tile_data"),&TileMap::_get_tile_data);
+ ClassDB::bind_method(D_METHOD("_set_tile_data"), &TileMap::_set_tile_data);
+ ClassDB::bind_method(D_METHOD("_get_tile_data"), &TileMap::_get_tile_data);
- ADD_PROPERTY( PropertyInfo(Variant::INT,"mode",PROPERTY_HINT_ENUM,"Square,Isometric,Custom"),"set_mode","get_mode");
- ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"tile_set",PROPERTY_HINT_RESOURCE_TYPE,"TileSet"),"set_tileset","get_tileset");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Square,Isometric,Custom"), "set_mode", "get_mode");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "tile_set", PROPERTY_HINT_RESOURCE_TYPE, "TileSet"), "set_tileset", "get_tileset");
- ADD_GROUP("Cell","cell_");
- ADD_PROPERTY( PropertyInfo(Variant::VECTOR2,"cell_size",PROPERTY_HINT_RANGE,"1,8192,1"),"set_cell_size","get_cell_size");
- ADD_PROPERTY( PropertyInfo(Variant::INT,"cell_quadrant_size",PROPERTY_HINT_RANGE,"1,128,1"),"set_quadrant_size","get_quadrant_size");
- ADD_PROPERTY( PropertyInfo(Variant::TRANSFORM2D,"cell_custom_transform"),"set_custom_transform","get_custom_transform");
- ADD_PROPERTY( PropertyInfo(Variant::INT,"cell_half_offset",PROPERTY_HINT_ENUM,"Offset X,Offset Y,Disabled"),"set_half_offset","get_half_offset");
- ADD_PROPERTY( PropertyInfo(Variant::INT,"cell_tile_origin",PROPERTY_HINT_ENUM,"Top Left,Center,Bottom Left"),"set_tile_origin","get_tile_origin");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"cell_y_sort"),"set_y_sort_mode","is_y_sort_mode_enabled");
+ ADD_GROUP("Cell", "cell_");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "cell_size", PROPERTY_HINT_RANGE, "1,8192,1"), "set_cell_size", "get_cell_size");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "cell_quadrant_size", PROPERTY_HINT_RANGE, "1,128,1"), "set_quadrant_size", "get_quadrant_size");
+ ADD_PROPERTY(PropertyInfo(Variant::TRANSFORM2D, "cell_custom_transform"), "set_custom_transform", "get_custom_transform");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "cell_half_offset", PROPERTY_HINT_ENUM, "Offset X,Offset Y,Disabled"), "set_half_offset", "get_half_offset");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "cell_tile_origin", PROPERTY_HINT_ENUM, "Top Left,Center,Bottom Left"), "set_tile_origin", "get_tile_origin");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "cell_y_sort"), "set_y_sort_mode", "is_y_sort_mode_enabled");
- ADD_GROUP("Collision","collision_");
- ADD_PROPERTY( PropertyInfo(Variant::BOOL,"collision_use_kinematic",PROPERTY_HINT_NONE,""),"set_collision_use_kinematic","get_collision_use_kinematic");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"collision_friction",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_collision_friction","get_collision_friction");
- ADD_PROPERTY( PropertyInfo(Variant::REAL,"collision_bounce",PROPERTY_HINT_RANGE,"0,1,0.01"),"set_collision_bounce","get_collision_bounce");
- ADD_PROPERTY( PropertyInfo(Variant::INT,"collision_layers",PROPERTY_HINT_LAYERS_2D_PHYSICS),"set_collision_layer","get_collision_layer");
- ADD_PROPERTY( PropertyInfo(Variant::INT,"collision_mask",PROPERTY_HINT_LAYERS_2D_PHYSICS),"set_collision_mask","get_collision_mask");
+ ADD_GROUP("Collision", "collision_");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "collision_use_kinematic", PROPERTY_HINT_NONE, ""), "set_collision_use_kinematic", "get_collision_use_kinematic");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "collision_friction", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_collision_friction", "get_collision_friction");
+ ADD_PROPERTY(PropertyInfo(Variant::REAL, "collision_bounce", PROPERTY_HINT_RANGE, "0,1,0.01"), "set_collision_bounce", "get_collision_bounce");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_layers", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_collision_layer", "get_collision_layer");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_2D_PHYSICS), "set_collision_mask", "get_collision_mask");
- ADD_GROUP("Occluder","occluder_");
- ADD_PROPERTY( PropertyInfo(Variant::INT,"occluder_light_mask",PROPERTY_HINT_LAYERS_2D_RENDER),"set_occluder_light_mask","get_occluder_light_mask");
- ADD_GROUP("","");
- ADD_PROPERTY( PropertyInfo(Variant::OBJECT,"tile_data",PROPERTY_HINT_NONE,"",PROPERTY_USAGE_NOEDITOR),"_set_tile_data","_get_tile_data");
+ ADD_GROUP("Occluder", "occluder_");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "occluder_light_mask", PROPERTY_HINT_LAYERS_2D_RENDER), "set_occluder_light_mask", "get_occluder_light_mask");
+ ADD_GROUP("", "");
+ ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "tile_data", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR), "_set_tile_data", "_get_tile_data");
ADD_SIGNAL(MethodInfo("settings_changed"));
- BIND_CONSTANT( INVALID_CELL );
- BIND_CONSTANT( MODE_SQUARE );
- BIND_CONSTANT( MODE_ISOMETRIC );
- BIND_CONSTANT( MODE_CUSTOM );
- BIND_CONSTANT( HALF_OFFSET_X );
- BIND_CONSTANT( HALF_OFFSET_Y );
- BIND_CONSTANT( HALF_OFFSET_DISABLED );
- BIND_CONSTANT( TILE_ORIGIN_TOP_LEFT );
- BIND_CONSTANT( TILE_ORIGIN_CENTER );
- BIND_CONSTANT( TILE_ORIGIN_BOTTOM_LEFT );
-
+ BIND_CONSTANT(INVALID_CELL);
+ BIND_CONSTANT(MODE_SQUARE);
+ BIND_CONSTANT(MODE_ISOMETRIC);
+ BIND_CONSTANT(MODE_CUSTOM);
+ BIND_CONSTANT(HALF_OFFSET_X);
+ BIND_CONSTANT(HALF_OFFSET_Y);
+ BIND_CONSTANT(HALF_OFFSET_DISABLED);
+ BIND_CONSTANT(TILE_ORIGIN_TOP_LEFT);
+ BIND_CONSTANT(TILE_ORIGIN_CENTER);
+ BIND_CONSTANT(TILE_ORIGIN_BOTTOM_LEFT);
}
TileMap::TileMap() {
-
-
- rect_cache_dirty=true;
- used_size_cache_dirty=true;
- pending_update=false;
- quadrant_order_dirty=false;
- quadrant_size=16;
- cell_size=Size2(64,64);
- center_x=false;
- center_y=false;
- collision_layer=1;
- collision_mask=1;
- friction=1;
- bounce=0;
- mode=MODE_SQUARE;
- half_offset=HALF_OFFSET_DISABLED;
- use_kinematic=false;
- navigation=NULL;
- y_sort_mode=false;
- occluder_light_mask=1;
-
- fp_adjust=0.00001;
- tile_origin=TILE_ORIGIN_TOP_LEFT;
+ rect_cache_dirty = true;
+ used_size_cache_dirty = true;
+ pending_update = false;
+ quadrant_order_dirty = false;
+ quadrant_size = 16;
+ cell_size = Size2(64, 64);
+ center_x = false;
+ center_y = false;
+ collision_layer = 1;
+ collision_mask = 1;
+ friction = 1;
+ bounce = 0;
+ mode = MODE_SQUARE;
+ half_offset = HALF_OFFSET_DISABLED;
+ use_kinematic = false;
+ navigation = NULL;
+ y_sort_mode = false;
+ occluder_light_mask = 1;
+
+ fp_adjust = 0.00001;
+ tile_origin = TILE_ORIGIN_TOP_LEFT;
set_notify_transform(true);
}
diff --git a/scene/2d/tile_map.h b/scene/2d/tile_map.h
index c581aa8056..f52adcd510 100644
--- a/scene/2d/tile_map.h
+++ b/scene/2d/tile_map.h
@@ -29,17 +29,17 @@
#ifndef TILE_MAP_H
#define TILE_MAP_H
-#include "scene/2d/node_2d.h"
#include "scene/2d/navigation2d.h"
+#include "scene/2d/node_2d.h"
#include "scene/resources/tile_set.h"
#include "self_list.h"
#include "vset.h"
class TileMap : public Node2D {
- GDCLASS( TileMap, Node2D );
-public:
+ GDCLASS(TileMap, Node2D);
+public:
enum Mode {
MODE_SQUARE,
MODE_ISOMETRIC,
@@ -58,20 +58,17 @@ public:
TILE_ORIGIN_BOTTOM_LEFT
};
-
private:
-
Ref<TileSet> tile_set;
Size2i cell_size;
int quadrant_size;
- bool center_x,center_y;
+ bool center_x, center_y;
Mode mode;
Transform2D custom_transform;
HalfOffset half_offset;
bool use_kinematic;
Navigation2D *navigation;
-
union PosKey {
struct {
@@ -81,29 +78,32 @@ private:
uint32_t key;
//using a more precise comparison so the regions can be sorted later
- bool operator<(const PosKey& p_k) const { return (y==p_k.y) ? x < p_k.x : y < p_k.y; }
-
- PosKey(int16_t p_x, int16_t p_y) { x=p_x; y=p_y; }
- PosKey() { x=0; y=0; }
-
+ bool operator<(const PosKey &p_k) const { return (y == p_k.y) ? x < p_k.x : y < p_k.y; }
+
+ PosKey(int16_t p_x, int16_t p_y) {
+ x = p_x;
+ y = p_y;
+ }
+ PosKey() {
+ x = 0;
+ y = 0;
+ }
};
-
union Cell {
struct {
- int32_t id:24;
- bool flip_h:1;
- bool flip_v:1;
- bool transpose:1;
+ int32_t id : 24;
+ bool flip_h : 1;
+ bool flip_v : 1;
+ bool transpose : 1;
};
uint32_t _u32t;
- Cell() { _u32t=0; }
+ Cell() { _u32t = 0; }
};
-
- Map<PosKey,Cell> tile_map;
+ Map<PosKey, Cell> tile_map;
struct Quadrant {
Vector2 pos;
@@ -122,18 +122,33 @@ private:
Transform2D xform;
};
-
- Map<PosKey,NavPoly> navpoly_ids;
- Map<PosKey,Occluder> occluder_instances;
+ Map<PosKey, NavPoly> navpoly_ids;
+ Map<PosKey, Occluder> occluder_instances;
VSet<PosKey> cells;
- void operator=(const Quadrant& q) { pos=q.pos; canvas_items=q.canvas_items; body=q.body; cells=q.cells; navpoly_ids=q.navpoly_ids; occluder_instances=q.occluder_instances; }
- Quadrant(const Quadrant& q) : dirty_list(this) { pos=q.pos; canvas_items=q.canvas_items; body=q.body; cells=q.cells; occluder_instances=q.occluder_instances; navpoly_ids=q.navpoly_ids;}
- Quadrant() : dirty_list(this) {}
+ void operator=(const Quadrant &q) {
+ pos = q.pos;
+ canvas_items = q.canvas_items;
+ body = q.body;
+ cells = q.cells;
+ navpoly_ids = q.navpoly_ids;
+ occluder_instances = q.occluder_instances;
+ }
+ Quadrant(const Quadrant &q)
+ : dirty_list(this) {
+ pos = q.pos;
+ canvas_items = q.canvas_items;
+ body = q.body;
+ cells = q.cells;
+ occluder_instances = q.occluder_instances;
+ navpoly_ids = q.navpoly_ids;
+ }
+ Quadrant()
+ : dirty_list(this) {}
};
- Map<PosKey,Quadrant> quadrant_map;
+ Map<PosKey, Quadrant> quadrant_map;
SelfList<Quadrant>::List dirty_quadrant_list;
@@ -155,43 +170,38 @@ private:
int occluder_light_mask;
- void _fix_cell_transform(Transform2D& xform, const Cell& p_cell, const Vector2 &p_offset, const Size2 &p_sc);
+ void _fix_cell_transform(Transform2D &xform, const Cell &p_cell, const Vector2 &p_offset, const Size2 &p_sc);
- Map<PosKey,Quadrant>::Element *_create_quadrant(const PosKey& p_qk);
- void _erase_quadrant(Map<PosKey,Quadrant>::Element *Q);
- void _make_quadrant_dirty(Map<PosKey,Quadrant>::Element *Q);
+ Map<PosKey, Quadrant>::Element *_create_quadrant(const PosKey &p_qk);
+ void _erase_quadrant(Map<PosKey, Quadrant>::Element *Q);
+ void _make_quadrant_dirty(Map<PosKey, Quadrant>::Element *Q);
void _recreate_quadrants();
void _clear_quadrants();
void _update_dirty_quadrants();
- void _update_quadrant_space(const RID& p_space);
+ void _update_quadrant_space(const RID &p_space);
void _update_quadrant_transform();
void _recompute_rect_cache();
_FORCE_INLINE_ int _get_quadrant_size() const;
-
- void _set_tile_data(const PoolVector<int>& p_data);
+ void _set_tile_data(const PoolVector<int> &p_data);
PoolVector<int> _get_tile_data() const;
- void _set_old_cell_size(int p_size) { set_cell_size(Size2(p_size,p_size)); }
+ void _set_old_cell_size(int p_size) { set_cell_size(Size2(p_size, p_size)); }
int _get_old_cell_size() const { return cell_size.x; }
- _FORCE_INLINE_ Vector2 _map_to_world(int p_x,int p_y,bool p_ignore_ofs=false) const;
+ _FORCE_INLINE_ Vector2 _map_to_world(int p_x, int p_y, bool p_ignore_ofs = false) const;
protected:
-
-
void _notification(int p_what);
static void _bind_methods();
public:
-
enum {
- INVALID_CELL=-1
+ INVALID_CELL = -1
};
-
- void set_tileset(const Ref<TileSet>& p_tileset);
+ void set_tileset(const Ref<TileSet> &p_tileset);
Ref<TileSet> get_tileset() const;
void set_cell_size(Size2 p_size);
@@ -205,14 +215,14 @@ public:
void set_center_y(bool p_enable);
bool get_center_y() const;
- void set_cell(int p_x,int p_y,int p_tile,bool p_flip_x=false,bool p_flip_y=false,bool p_transpose=false);
- int get_cell(int p_x,int p_y) const;
- bool is_cell_x_flipped(int p_x,int p_y) const;
- bool is_cell_y_flipped(int p_x,int p_y) const;
- bool is_cell_transposed(int p_x,int p_y) const;
+ void set_cell(int p_x, int p_y, int p_tile, bool p_flip_x = false, bool p_flip_y = false, bool p_transpose = false);
+ int get_cell(int p_x, int p_y) const;
+ bool is_cell_x_flipped(int p_x, int p_y) const;
+ bool is_cell_y_flipped(int p_x, int p_y) const;
+ bool is_cell_transposed(int p_x, int p_y) const;
- void set_cellv(const Vector2& p_pos,int p_tile,bool p_flip_x=false,bool p_flip_y=false,bool p_transpose=false);
- int get_cellv(const Vector2& p_pos) const;
+ void set_cellv(const Vector2 &p_pos, int p_tile, bool p_flip_x = false, bool p_flip_y = false, bool p_transpose = false);
+ int get_cellv(const Vector2 &p_pos) const;
Rect2 get_item_rect() const;
@@ -240,14 +250,14 @@ public:
void set_tile_origin(TileOrigin p_tile_origin);
TileOrigin get_tile_origin() const;
- void set_custom_transform(const Transform2D& p_xform);
+ void set_custom_transform(const Transform2D &p_xform);
Transform2D get_custom_transform() const;
Transform2D get_cell_transform() const;
Vector2 get_cell_draw_offset() const;
- Vector2 map_to_world(const Vector2& p_pos, bool p_ignore_ofs=false) const;
- Vector2 world_to_map(const Vector2& p_pos) const;
+ Vector2 map_to_world(const Vector2 &p_pos, bool p_ignore_ofs = false) const;
+ Vector2 world_to_map(const Vector2 &p_pos) const;
void set_y_sort_mode(bool p_enable);
bool is_y_sort_mode_enabled() const;
diff --git a/scene/2d/visibility_notifier_2d.cpp b/scene/2d/visibility_notifier_2d.cpp
index 64ab333e48..f20a995d5f 100644
--- a/scene/2d/visibility_notifier_2d.cpp
+++ b/scene/2d/visibility_notifier_2d.cpp
@@ -28,14 +28,14 @@
/*************************************************************************/
#include "visibility_notifier_2d.h"
-#include "scene/scene_string_names.h"
-#include "scene/2d/physics_body_2d.h"
+#include "particles_2d.h"
#include "scene/2d/animated_sprite.h"
+#include "scene/2d/physics_body_2d.h"
#include "scene/animation/animation_player.h"
#include "scene/scene_string_names.h"
-#include "particles_2d.h"
+#include "scene/scene_string_names.h"
-void VisibilityNotifier2D::_enter_viewport(Viewport* p_viewport) {
+void VisibilityNotifier2D::_enter_viewport(Viewport *p_viewport) {
ERR_FAIL_COND(viewports.has(p_viewport));
viewports.insert(p_viewport);
@@ -43,16 +43,15 @@ void VisibilityNotifier2D::_enter_viewport(Viewport* p_viewport) {
if (is_inside_tree() && get_tree()->is_editor_hint())
return;
- if (viewports.size()==1) {
+ if (viewports.size() == 1) {
emit_signal(SceneStringNames::get_singleton()->screen_entered);
_screen_enter();
}
- emit_signal(SceneStringNames::get_singleton()->viewport_entered,p_viewport);
-
+ emit_signal(SceneStringNames::get_singleton()->viewport_entered, p_viewport);
}
-void VisibilityNotifier2D::_exit_viewport(Viewport* p_viewport){
+void VisibilityNotifier2D::_exit_viewport(Viewport *p_viewport) {
ERR_FAIL_COND(!viewports.has(p_viewport));
viewports.erase(p_viewport);
@@ -60,20 +59,19 @@ void VisibilityNotifier2D::_exit_viewport(Viewport* p_viewport){
if (is_inside_tree() && get_tree()->is_editor_hint())
return;
- emit_signal(SceneStringNames::get_singleton()->viewport_exited,p_viewport);
- if (viewports.size()==0) {
+ emit_signal(SceneStringNames::get_singleton()->viewport_exited, p_viewport);
+ if (viewports.size() == 0) {
emit_signal(SceneStringNames::get_singleton()->screen_exited);
_screen_exit();
}
}
+void VisibilityNotifier2D::set_rect(const Rect2 &p_rect) {
-void VisibilityNotifier2D::set_rect(const Rect2& p_rect){
-
- rect=p_rect;
+ rect = p_rect;
if (is_inside_tree()) {
- get_world_2d()->_update_notifier(this,get_global_transform().xform(rect));
+ get_world_2d()->_update_notifier(this, get_global_transform().xform(rect));
if (get_tree()->is_editor_hint()) {
update();
item_rect_changed();
@@ -88,31 +86,29 @@ Rect2 VisibilityNotifier2D::get_item_rect() const {
return rect;
}
-Rect2 VisibilityNotifier2D::get_rect() const{
+Rect2 VisibilityNotifier2D::get_rect() const {
return rect;
}
-
void VisibilityNotifier2D::_notification(int p_what) {
-
- switch(p_what) {
+ switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
//get_world_2d()->
- get_world_2d()->_register_notifier(this,get_global_transform().xform(rect));
+ get_world_2d()->_register_notifier(this, get_global_transform().xform(rect));
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
//get_world_2d()->
- get_world_2d()->_update_notifier(this,get_global_transform().xform(rect));
+ get_world_2d()->_update_notifier(this, get_global_transform().xform(rect));
} break;
case NOTIFICATION_DRAW: {
if (get_tree()->is_editor_hint()) {
- draw_rect(rect,Color(1,0.5,1,0.2));
+ draw_rect(rect, Color(1, 0.5, 1, 0.2));
}
} break;
case NOTIFICATION_EXIT_TREE: {
@@ -124,43 +120,36 @@ void VisibilityNotifier2D::_notification(int p_what) {
bool VisibilityNotifier2D::is_on_screen() const {
- return viewports.size()>0;
+ return viewports.size() > 0;
}
-void VisibilityNotifier2D::_bind_methods(){
+void VisibilityNotifier2D::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_rect","rect"),&VisibilityNotifier2D::set_rect);
- ClassDB::bind_method(D_METHOD("get_rect"),&VisibilityNotifier2D::get_rect);
- ClassDB::bind_method(D_METHOD("is_on_screen"),&VisibilityNotifier2D::is_on_screen);
+ ClassDB::bind_method(D_METHOD("set_rect", "rect"), &VisibilityNotifier2D::set_rect);
+ ClassDB::bind_method(D_METHOD("get_rect"), &VisibilityNotifier2D::get_rect);
+ ClassDB::bind_method(D_METHOD("is_on_screen"), &VisibilityNotifier2D::is_on_screen);
- ADD_PROPERTY( PropertyInfo(Variant::RECT2,"rect"),"set_rect","get_rect");
+ ADD_PROPERTY(PropertyInfo(Variant::RECT2, "rect"), "set_rect", "get_rect");
- ADD_SIGNAL( MethodInfo("viewport_entered",PropertyInfo(Variant::OBJECT,"viewport",PROPERTY_HINT_RESOURCE_TYPE,"Viewport")) );
- ADD_SIGNAL( MethodInfo("viewport_exited",PropertyInfo(Variant::OBJECT,"viewport",PROPERTY_HINT_RESOURCE_TYPE,"Viewport")) );
- ADD_SIGNAL( MethodInfo("screen_entered"));
- ADD_SIGNAL( MethodInfo("screen_exited"));
+ ADD_SIGNAL(MethodInfo("viewport_entered", PropertyInfo(Variant::OBJECT, "viewport", PROPERTY_HINT_RESOURCE_TYPE, "Viewport")));
+ ADD_SIGNAL(MethodInfo("viewport_exited", PropertyInfo(Variant::OBJECT, "viewport", PROPERTY_HINT_RESOURCE_TYPE, "Viewport")));
+ ADD_SIGNAL(MethodInfo("screen_entered"));
+ ADD_SIGNAL(MethodInfo("screen_exited"));
}
-
VisibilityNotifier2D::VisibilityNotifier2D() {
- rect=Rect2(-10,-10,20,20);
+ rect = Rect2(-10, -10, 20, 20);
set_notify_transform(true);
}
-
-
-
-
//////////////////////////////////////
-
void VisibilityEnabler2D::_screen_enter() {
+ for (Map<Node *, Variant>::Element *E = nodes.front(); E; E = E->next()) {
- for(Map<Node*,Variant>::Element *E=nodes.front();E;E=E->next()) {
-
- _change_node_state(E->key(),true);
+ _change_node_state(E->key(), true);
}
if (enabler[ENABLER_PARENT_FIXED_PROCESS] && get_parent())
@@ -168,14 +157,14 @@ void VisibilityEnabler2D::_screen_enter() {
if (enabler[ENABLER_PARENT_PROCESS] && get_parent())
get_parent()->set_process(true);
- visible=true;
+ visible = true;
}
-void VisibilityEnabler2D::_screen_exit(){
+void VisibilityEnabler2D::_screen_exit() {
- for(Map<Node*,Variant>::Element *E=nodes.front();E;E=E->next()) {
+ for (Map<Node *, Variant>::Element *E = nodes.front(); E; E = E->next()) {
- _change_node_state(E->key(),false);
+ _change_node_state(E->key(), false);
}
if (enabler[ENABLER_PARENT_FIXED_PROCESS] && get_parent())
@@ -183,23 +172,21 @@ void VisibilityEnabler2D::_screen_exit(){
if (enabler[ENABLER_PARENT_PROCESS] && get_parent())
get_parent()->set_process(false);
- visible=false;
+ visible = false;
}
-void VisibilityEnabler2D::_find_nodes(Node* p_node) {
+void VisibilityEnabler2D::_find_nodes(Node *p_node) {
-
- bool add=false;
+ bool add = false;
Variant meta;
if (enabler[ENABLER_FREEZE_BODIES]) {
RigidBody2D *rb2d = p_node->cast_to<RigidBody2D>();
- if (rb2d && ((rb2d->get_mode()==RigidBody2D::MODE_CHARACTER || (rb2d->get_mode()==RigidBody2D::MODE_RIGID && !rb2d->is_able_to_sleep())))) {
-
+ if (rb2d && ((rb2d->get_mode() == RigidBody2D::MODE_CHARACTER || (rb2d->get_mode() == RigidBody2D::MODE_RIGID && !rb2d->is_able_to_sleep())))) {
- add=true;
- meta=rb2d->get_mode();
+ add = true;
+ meta = rb2d->get_mode();
}
}
@@ -207,59 +194,53 @@ void VisibilityEnabler2D::_find_nodes(Node* p_node) {
AnimationPlayer *ap = p_node->cast_to<AnimationPlayer>();
if (ap) {
- add=true;
+ add = true;
}
-
}
if (enabler[ENABLER_PAUSE_ANIMATED_SPRITES]) {
AnimatedSprite *as = p_node->cast_to<AnimatedSprite>();
if (as) {
- add=true;
+ add = true;
}
-
}
-
if (enabler[ENABLER_PAUSE_PARTICLES]) {
Particles2D *ps = p_node->cast_to<Particles2D>();
if (ps) {
- add=true;
+ add = true;
}
-
}
if (add) {
- p_node->connect(SceneStringNames::get_singleton()->tree_exited,this,"_node_removed",varray(p_node),CONNECT_ONESHOT);
- nodes[p_node]=meta;
- _change_node_state(p_node,false);
+ p_node->connect(SceneStringNames::get_singleton()->tree_exited, this, "_node_removed", varray(p_node), CONNECT_ONESHOT);
+ nodes[p_node] = meta;
+ _change_node_state(p_node, false);
}
- 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->get_filename()!=String())
+ if (c->get_filename() != String())
continue; //skip, instance
_find_nodes(c);
}
-
}
-void VisibilityEnabler2D::_notification(int p_what){
+void VisibilityEnabler2D::_notification(int p_what) {
- if (p_what==NOTIFICATION_ENTER_TREE) {
+ if (p_what == NOTIFICATION_ENTER_TREE) {
if (get_tree()->is_editor_hint())
return;
-
Node *from = this;
//find where current scene starts
- while(from->get_parent() && from->get_filename()==String())
- from=from->get_parent();
+ while (from->get_parent() && from->get_filename() == String())
+ from = from->get_parent();
_find_nodes(from);
@@ -267,29 +248,25 @@ void VisibilityEnabler2D::_notification(int p_what){
get_parent()->set_fixed_process(false);
if (enabler[ENABLER_PARENT_PROCESS] && get_parent())
get_parent()->set_process(false);
-
-
}
- if (p_what==NOTIFICATION_EXIT_TREE) {
+ if (p_what == NOTIFICATION_EXIT_TREE) {
if (get_tree()->is_editor_hint())
return;
-
- for (Map<Node*,Variant>::Element *E=nodes.front();E;E=E->next()) {
+ for (Map<Node *, Variant>::Element *E = nodes.front(); E; E = E->next()) {
if (!visible)
- _change_node_state(E->key(),true);
- E->key()->disconnect(SceneStringNames::get_singleton()->tree_exited,this,"_node_removed");
+ _change_node_state(E->key(), true);
+ E->key()->disconnect(SceneStringNames::get_singleton()->tree_exited, this, "_node_removed");
}
nodes.clear();
-
}
}
-void VisibilityEnabler2D::_change_node_state(Node* p_node,bool p_enabled) {
+void VisibilityEnabler2D::_change_node_state(Node *p_node, bool p_enabled) {
ERR_FAIL_COND(!nodes.has(p_node));
@@ -302,7 +279,7 @@ void VisibilityEnabler2D::_change_node_state(Node* p_node,bool p_enabled) {
}
{
- AnimationPlayer *ap=p_node->cast_to<AnimationPlayer>();
+ AnimationPlayer *ap = p_node->cast_to<AnimationPlayer>();
if (ap) {
@@ -310,7 +287,7 @@ void VisibilityEnabler2D::_change_node_state(Node* p_node,bool p_enabled) {
}
}
{
- AnimatedSprite *as=p_node->cast_to<AnimatedSprite>();
+ AnimatedSprite *as = p_node->cast_to<AnimatedSprite>();
if (as) {
@@ -322,81 +299,72 @@ void VisibilityEnabler2D::_change_node_state(Node* p_node,bool p_enabled) {
}
{
- Particles2D *ps=p_node->cast_to<Particles2D>();
+ Particles2D *ps = p_node->cast_to<Particles2D>();
if (ps) {
ps->set_emitting(p_enabled);
}
}
-
}
-
-void VisibilityEnabler2D::_node_removed(Node* p_node) {
+void VisibilityEnabler2D::_node_removed(Node *p_node) {
if (!visible)
- _change_node_state(p_node,true);
+ _change_node_state(p_node, true);
//changed to one shot, not needed
//p_node->disconnect(SceneStringNames::get_singleton()->exit_scene,this,"_node_removed");
nodes.erase(p_node);
-
}
String VisibilityEnabler2D::get_configuration_warning() const {
#ifdef TOOLS_ENABLED
- if (is_inside_tree() && get_parent() && (get_parent()->get_filename()==String() && get_parent()!=get_tree()->get_edited_scene_root())) {
+ if (is_inside_tree() && get_parent() && (get_parent()->get_filename() == String() && get_parent() != get_tree()->get_edited_scene_root())) {
return TTR("VisibilityEnable2D works best when used with the edited scene root directly as parent.");
}
#endif
return String();
}
-
-void VisibilityEnabler2D::_bind_methods(){
-
- ClassDB::bind_method(D_METHOD("set_enabler","enabler","enabled"),&VisibilityEnabler2D::set_enabler);
- ClassDB::bind_method(D_METHOD("is_enabler_enabled","enabler"),&VisibilityEnabler2D::is_enabler_enabled);
- ClassDB::bind_method(D_METHOD("_node_removed"),&VisibilityEnabler2D::_node_removed);
-
- ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"pause_animations"),"set_enabler","is_enabler_enabled", ENABLER_PAUSE_ANIMATIONS );
- ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"freeze_bodies"),"set_enabler","is_enabler_enabled", ENABLER_FREEZE_BODIES);
- ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"pause_particles"),"set_enabler","is_enabler_enabled", ENABLER_PAUSE_PARTICLES);
- ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"pause_animated_sprites"),"set_enabler","is_enabler_enabled", ENABLER_PAUSE_ANIMATED_SPRITES);
- ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"process_parent"),"set_enabler","is_enabler_enabled", ENABLER_PARENT_PROCESS);
- ADD_PROPERTYI( PropertyInfo(Variant::BOOL,"fixed_process_parent"),"set_enabler","is_enabler_enabled", ENABLER_PARENT_FIXED_PROCESS);
-
- BIND_CONSTANT( ENABLER_FREEZE_BODIES );
- BIND_CONSTANT( ENABLER_PAUSE_ANIMATIONS );
- BIND_CONSTANT( ENABLER_PAUSE_PARTICLES );
- BIND_CONSTANT( ENABLER_PAUSE_ANIMATED_SPRITES );
- BIND_CONSTANT( ENABLER_PARENT_PROCESS );
- BIND_CONSTANT( ENABLER_PARENT_FIXED_PROCESS );
- BIND_CONSTANT( ENABLER_MAX);
+void VisibilityEnabler2D::_bind_methods() {
+
+ ClassDB::bind_method(D_METHOD("set_enabler", "enabler", "enabled"), &VisibilityEnabler2D::set_enabler);
+ ClassDB::bind_method(D_METHOD("is_enabler_enabled", "enabler"), &VisibilityEnabler2D::is_enabler_enabled);
+ ClassDB::bind_method(D_METHOD("_node_removed"), &VisibilityEnabler2D::_node_removed);
+
+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "pause_animations"), "set_enabler", "is_enabler_enabled", ENABLER_PAUSE_ANIMATIONS);
+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "freeze_bodies"), "set_enabler", "is_enabler_enabled", ENABLER_FREEZE_BODIES);
+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "pause_particles"), "set_enabler", "is_enabler_enabled", ENABLER_PAUSE_PARTICLES);
+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "pause_animated_sprites"), "set_enabler", "is_enabler_enabled", ENABLER_PAUSE_ANIMATED_SPRITES);
+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "process_parent"), "set_enabler", "is_enabler_enabled", ENABLER_PARENT_PROCESS);
+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "fixed_process_parent"), "set_enabler", "is_enabler_enabled", ENABLER_PARENT_FIXED_PROCESS);
+
+ BIND_CONSTANT(ENABLER_FREEZE_BODIES);
+ BIND_CONSTANT(ENABLER_PAUSE_ANIMATIONS);
+ BIND_CONSTANT(ENABLER_PAUSE_PARTICLES);
+ BIND_CONSTANT(ENABLER_PAUSE_ANIMATED_SPRITES);
+ BIND_CONSTANT(ENABLER_PARENT_PROCESS);
+ BIND_CONSTANT(ENABLER_PARENT_FIXED_PROCESS);
+ BIND_CONSTANT(ENABLER_MAX);
}
-void VisibilityEnabler2D::set_enabler(Enabler p_enabler,bool p_enable){
-
- ERR_FAIL_INDEX(p_enabler,ENABLER_MAX);
- enabler[p_enabler]=p_enable;
+void VisibilityEnabler2D::set_enabler(Enabler p_enabler, bool p_enable) {
+ ERR_FAIL_INDEX(p_enabler, ENABLER_MAX);
+ enabler[p_enabler] = p_enable;
}
-bool VisibilityEnabler2D::is_enabler_enabled(Enabler p_enabler) const{
+bool VisibilityEnabler2D::is_enabler_enabled(Enabler p_enabler) const {
- ERR_FAIL_INDEX_V(p_enabler,ENABLER_MAX,false);
+ ERR_FAIL_INDEX_V(p_enabler, ENABLER_MAX, false);
return enabler[p_enabler];
-
}
VisibilityEnabler2D::VisibilityEnabler2D() {
- for(int i=0;i<ENABLER_MAX;i++)
- enabler[i]=true;
- enabler[ENABLER_PARENT_PROCESS]=false;
- enabler[ENABLER_PARENT_FIXED_PROCESS]=false;
-
- visible=false;
+ for (int i = 0; i < ENABLER_MAX; i++)
+ enabler[i] = true;
+ enabler[ENABLER_PARENT_PROCESS] = false;
+ enabler[ENABLER_PARENT_FIXED_PROCESS] = false;
+ visible = false;
}
-
-
diff --git a/scene/2d/visibility_notifier_2d.h b/scene/2d/visibility_notifier_2d.h
index a896e270fe..aa49497404 100644
--- a/scene/2d/visibility_notifier_2d.h
+++ b/scene/2d/visibility_notifier_2d.h
@@ -34,27 +34,26 @@
class Viewport;
class VisibilityNotifier2D : public Node2D {
- GDCLASS(VisibilityNotifier2D,Node2D);
+ GDCLASS(VisibilityNotifier2D, Node2D);
- Set<Viewport*> viewports;
+ Set<Viewport *> viewports;
Rect2 rect;
protected:
-friend class SpatialIndexer2D;
-
- void _enter_viewport(Viewport* p_viewport);
- void _exit_viewport(Viewport* p_viewport);
+ friend class SpatialIndexer2D;
+ void _enter_viewport(Viewport *p_viewport);
+ void _exit_viewport(Viewport *p_viewport);
virtual void _screen_enter() {}
virtual void _screen_exit() {}
void _notification(int p_what);
static void _bind_methods();
-public:
- void set_rect(const Rect2& p_rect);
+public:
+ void set_rect(const Rect2 &p_rect);
Rect2 get_rect() const;
bool is_on_screen() const;
@@ -64,12 +63,11 @@ public:
VisibilityNotifier2D();
};
-
class VisibilityEnabler2D : public VisibilityNotifier2D {
- GDCLASS(VisibilityEnabler2D,VisibilityNotifier2D);
-public:
+ GDCLASS(VisibilityEnabler2D, VisibilityNotifier2D);
+public:
enum Enabler {
ENABLER_PAUSE_ANIMATIONS,
ENABLER_FREEZE_BODIES,
@@ -81,35 +79,31 @@ public:
};
protected:
-
virtual void _screen_enter();
virtual void _screen_exit();
bool visible;
- void _find_nodes(Node* p_node);
+ void _find_nodes(Node *p_node);
- Map<Node*,Variant> nodes;
- void _node_removed(Node* p_node);
+ Map<Node *, Variant> nodes;
+ void _node_removed(Node *p_node);
bool enabler[ENABLER_MAX];
- void _change_node_state(Node* p_node,bool p_enabled);
+ void _change_node_state(Node *p_node, bool p_enabled);
void _notification(int p_what);
static void _bind_methods();
public:
-
- void set_enabler(Enabler p_enabler,bool p_enable);
+ void set_enabler(Enabler p_enabler, bool p_enable);
bool is_enabler_enabled(Enabler p_enabler) const;
String get_configuration_warning() const;
VisibilityEnabler2D();
-
};
VARIANT_ENUM_CAST(VisibilityEnabler2D::Enabler);
-
#endif // VISIBILITY_NOTIFIER_2D_H
diff --git a/scene/2d/y_sort.cpp b/scene/2d/y_sort.cpp
index cb9a494e87..760139287c 100644
--- a/scene/2d/y_sort.cpp
+++ b/scene/2d/y_sort.cpp
@@ -28,12 +28,10 @@
/*************************************************************************/
#include "y_sort.h"
-
-
void YSort::set_sort_enabled(bool p_enabled) {
- sort_enabled=p_enabled;
- VS::get_singleton()->canvas_item_set_sort_children_by_y(get_canvas_item(),sort_enabled);
+ sort_enabled = p_enabled;
+ VS::get_singleton()->canvas_item_set_sort_children_by_y(get_canvas_item(), sort_enabled);
}
bool YSort::is_sort_enabled() const {
@@ -43,16 +41,15 @@ bool YSort::is_sort_enabled() const {
void YSort::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_sort_enabled","enabled"),&YSort::set_sort_enabled);
- ClassDB::bind_method(D_METHOD("is_sort_enabled"),&YSort::is_sort_enabled);
+ ClassDB::bind_method(D_METHOD("set_sort_enabled", "enabled"), &YSort::set_sort_enabled);
+ ClassDB::bind_method(D_METHOD("is_sort_enabled"), &YSort::is_sort_enabled);
- ADD_GROUP("Sort","sort_");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL,"sort_enabled"),"set_sort_enabled","is_sort_enabled");
+ ADD_GROUP("Sort", "sort_");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "sort_enabled"), "set_sort_enabled", "is_sort_enabled");
}
-
YSort::YSort() {
- sort_enabled=true;
- VS::get_singleton()->canvas_item_set_sort_children_by_y(get_canvas_item(),true);
+ sort_enabled = true;
+ VS::get_singleton()->canvas_item_set_sort_children_by_y(get_canvas_item(), true);
}
diff --git a/scene/2d/y_sort.h b/scene/2d/y_sort.h
index ebfe695da1..c919788498 100644
--- a/scene/2d/y_sort.h
+++ b/scene/2d/y_sort.h
@@ -32,11 +32,11 @@
#include "scene/2d/node_2d.h"
class YSort : public Node2D {
- GDCLASS(YSort,Node2D);
+ GDCLASS(YSort, Node2D);
bool sort_enabled;
static void _bind_methods();
-public:
+public:
void set_sort_enabled(bool p_enabled);
bool is_sort_enabled() const;
YSort();