diff options
Diffstat (limited to 'scene/2d/navigation2d.h')
-rw-r--r-- | scene/2d/navigation2d.h | 79 |
1 files changed, 37 insertions, 42 deletions
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 |