From 5dbf1809c6e3e905b94b8764e99491e608122261 Mon Sep 17 00:00:00 2001 From: Rémi Verschelde Date: Sun, 5 Mar 2017 16:44:50 +0100 Subject: 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 --- scene/2d/navigation_polygon.cpp | 291 ++++++++++++++++++---------------------- 1 file changed, 133 insertions(+), 158 deletions(-) (limited to 'scene/2d/navigation_polygon.cpp') diff --git a/scene/2d/navigation_polygon.cpp b/scene/2d/navigation_polygon.cpp index 9dbbd34ae..570bd00a5 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& p_vertices) { +void NavigationPolygon::set_vertices(const PoolVector &p_vertices) { - vertices=p_vertices; + vertices = p_vertices; } -PoolVector NavigationPolygon::get_vertices() const{ +PoolVector 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_polygon){ +void NavigationPolygon::add_polygon(const Vector &p_polygon) { Polygon polygon; - polygon.indices=p_polygon; + polygon.indices = p_polygon; polygons.push_back(polygon); - } -void NavigationPolygon::add_outline_at_index(const PoolVector& p_outline,int p_index) { +void NavigationPolygon::add_outline_at_index(const PoolVector &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 NavigationPolygon::get_polygon(int p_idx){ +Vector NavigationPolygon::get_polygon(int p_idx) { - ERR_FAIL_INDEX_V(p_idx,polygons.size(),Vector()); + ERR_FAIL_INDEX_V(p_idx, polygons.size(), Vector()); return polygons[p_idx].indices; } -void NavigationPolygon::clear_polygons(){ +void NavigationPolygon::clear_polygons() { polygons.clear(); } -void NavigationPolygon::add_outline(const PoolVector& p_outline) { +void NavigationPolygon::add_outline(const PoolVector &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& p_outline) { - ERR_FAIL_INDEX(p_idx,outlines.size()); - outlines[p_idx]=p_outline; +void NavigationPolygon::set_outline(int p_idx, const PoolVector &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 NavigationPolygon::get_outline(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx,outlines.size(),PoolVector()); + ERR_FAIL_INDEX_V(p_idx, outlines.size(), PoolVector()); 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 in_poly,out_poly; + List in_poly, out_poly; - Vector2 outside_point(-1e10,-1e10); + Vector2 outside_point(-1e10, -1e10); - for(int i=0;i ol = outlines[i]; int olsize = ol.size(); - if (olsize<3) + if (olsize < 3) continue; - PoolVector::Read r=ol.read(); - for(int j=0;j::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 ol = outlines[i]; int olsize = ol.size(); - if (olsize<3) + if (olsize < 3) continue; - PoolVector::Read r=ol.read(); + PoolVector::Read r = ol.read(); - int interscount=0; + int interscount = 0; //test if this is an outer outline - for(int k=0;k ol2 = outlines[k]; int olsize2 = ol2.size(); - if (olsize2<3) + if (olsize2 < 3) continue; - PoolVector::Read r2=ol2.read(); + PoolVector::Read r2 = ol2.read(); - for(int l=0;l points; - for(List::Element*I = out_poly.front();I;I=I->next()) { + Map points; + for (List::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::Element *E=points.find(tp[i]); + Map::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(); + navigation = c->cast_to(); 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(); + c = c->get_parent()->cast_to(); } } 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 verts=navpoly->get_vertices(); + PoolVector 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 colors; Vector vertices; @@ -386,66 +368,61 @@ void NavigationPolygonInstance::_notification(int p_what) { colors.resize(vsize); { PoolVector::Read vr = verts.read(); - for(int i=0;i indices; - - for(int i=0;iget_polygon_count();i++) { + for (int i = 0; i < navpoly->get_polygon_count(); i++) { Vector polygon = navpoly->get_polygon(i); - for(int j=2;jcanvas_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 &p_navpoly) { -void NavigationPolygonInstance::set_navigation_polygon(const Ref& 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 NavigationPolygonInstance::get_navigation_polygon() const{ +Ref 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()) { return String(); } - c=c->get_parent()->cast_to(); + c = c->get_parent()->cast_to(); } 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); - } -- cgit v1.2.3-70-g09d2