From 2114b2239b6d6078a2a3e9e7a082150293d4ecb4 Mon Sep 17 00:00:00 2001 From: Relintai Date: Sat, 3 Jun 2023 16:54:48 +0200 Subject: [PATCH] Split NavigationPolygon and NavigationPolygonInstance into 2 files. Also renamedNavigationPolygonInstance to NavigationRegion2D. --- doc/classes/Navigation2D.xml | 4 +- doc/classes/NavigationPolygonInstance.xml | 6 +- ...tionPolygon.xml => NavigationRegion2D.xml} | 4 +- doc/translations/classes.pot | 28 +- doc/translations/hu.po | 28 +- .../navigation_polygon_editor_plugin.cpp | 7 +- .../navigation_polygon_editor_plugin.h | 4 +- .../pandemonium_navigation_2d_server.h | 2 +- .../dummy_navigation_2d_server.cpp | 2 +- modules/tile_map/tile_set.h | 3 +- modules/tile_map/tile_set_editor_plugin.cpp | 4 +- scene/2d/navigation_2d.cpp | 3 +- scene/2d/navigation_region_2d.cpp | 328 ++++++++++++++++++ scene/2d/navigation_region_2d.h | 90 +++++ scene/register_scene_types.cpp | 5 +- .../{2d => resources}/navigation_polygon.cpp | 288 +-------------- scene/{2d => resources}/navigation_polygon.h | 51 --- servers/navigation_2d_server.h | 4 +- 18 files changed, 474 insertions(+), 387 deletions(-) rename doc/classes/{NavigationPolygon.xml => NavigationRegion2D.xml} (98%) create mode 100644 scene/2d/navigation_region_2d.cpp create mode 100644 scene/2d/navigation_region_2d.h rename scene/{2d => resources}/navigation_polygon.cpp (53%) rename scene/{2d => resources}/navigation_polygon.h (76%) diff --git a/doc/classes/Navigation2D.xml b/doc/classes/Navigation2D.xml index 8c8f8bbe9..1dfe7317f 100644 --- a/doc/classes/Navigation2D.xml +++ b/doc/classes/Navigation2D.xml @@ -4,7 +4,7 @@ 2D navigation and pathfinding node. - Navigation2D provides navigation and pathfinding within a 2D area, specified as a collection of [NavigationPolygon] resources. By default, these are automatically collected from child [NavigationPolygonInstance] nodes. + Navigation2D provides navigation and pathfinding within a 2D area, specified as a collection of [NavigationPolygon] resources. By default, these are automatically collected from child [NavigationRegion2D] nodes. https://godotengine.org/asset-library/asset/117 @@ -21,7 +21,7 @@ - Returns the owner of the [NavigationPolygon] which contains the navigation point closest to the point given. This is usually a [NavigationPolygonInstance]. + Returns the owner of the [NavigationPolygon] which contains the navigation point closest to the point given. This is usually a [NavigationRegion2D]. diff --git a/doc/classes/NavigationPolygonInstance.xml b/doc/classes/NavigationPolygonInstance.xml index acf8d813c..669e4e23a 100644 --- a/doc/classes/NavigationPolygonInstance.xml +++ b/doc/classes/NavigationPolygonInstance.xml @@ -1,5 +1,5 @@ - + A region of the 2D navigation map. @@ -18,13 +18,13 @@ - Returns the [RID] of this region on the [Navigation2DServer]. Combined with [method Navigation2DServer.map_get_closest_point_owner] can be used to identify the [NavigationPolygonInstance] closest to a point on the merged navigation map. + Returns the [RID] of this region on the [Navigation2DServer]. Combined with [method Navigation2DServer.map_get_closest_point_owner] can be used to identify the [NavigationRegion2D] closest to a point on the merged navigation map. - Determines if the [NavigationPolygonInstance] is enabled or disabled. + Determines if the [NavigationRegion2D] is enabled or disabled. When pathfinding enters this regions navmesh from another regions navmesh the [code]enter_cost[/code] value is added to the path distance for determining the shortest path. diff --git a/doc/classes/NavigationPolygon.xml b/doc/classes/NavigationRegion2D.xml similarity index 98% rename from doc/classes/NavigationPolygon.xml rename to doc/classes/NavigationRegion2D.xml index 6c1fab3b5..6c972689f 100644 --- a/doc/classes/NavigationPolygon.xml +++ b/doc/classes/NavigationRegion2D.xml @@ -11,7 +11,7 @@ var outline = PoolVector2Array([Vector2(0, 0), Vector2(0, 50), Vector2(50, 50), Vector2(50, 0)]) polygon.add_outline(outline) polygon.make_polygons_from_outlines() - $NavigationPolygonInstance.navpoly = polygon + $NavigationRegion2D.navpoly = polygon [/codeblock] Using [method add_polygon] and indices of the vertices array. [codeblock] @@ -20,7 +20,7 @@ polygon.set_vertices(vertices) var indices = PoolIntArray([0, 1, 2, 3]) polygon.add_polygon(indices) - $NavigationPolygonInstance.navpoly = polygon + $NavigationRegion2D.navpoly = polygon [/codeblock] diff --git a/doc/translations/classes.pot b/doc/translations/classes.pot index 5e3adb9b9..a66212324 100644 --- a/doc/translations/classes.pot +++ b/doc/translations/classes.pot @@ -35748,7 +35748,7 @@ msgid "" "Navigation2DServer.map_get_path] instead.\n" "Navigation2D provides navigation and pathfinding within a 2D area, specified " "as a collection of [NavigationPolygon] resources. By default, these are " -"automatically collected from child [NavigationPolygonInstance] nodes." +"automatically collected from child [NavigationRegion2D] nodes." msgstr "" #: doc/classes/Navigation2D.xml doc/classes/Navigation2DServer.xml @@ -35760,7 +35760,7 @@ msgstr "" msgid "" "Returns the owner of the [NavigationPolygon] which contains the navigation " "point closest to the point given. This is usually a " -"[NavigationPolygonInstance]." +"[NavigationRegion2D]." msgstr "" #: doc/classes/Navigation2D.xml @@ -36781,7 +36781,7 @@ msgid "Determines if the [NavigationMeshInstance] is enabled or disabled." msgstr "" #: doc/classes/NavigationMeshInstance.xml -#: doc/classes/NavigationPolygonInstance.xml +#: doc/classes/NavigationRegion2D.xml msgid "" "When pathfinding enters this region's navmesh from another regions navmesh " "the [code]enter_cost[/code] value is added to the path distance for " @@ -36801,7 +36801,7 @@ msgid "The [NavigationMesh] resource to use." msgstr "" #: doc/classes/NavigationMeshInstance.xml -#: doc/classes/NavigationPolygonInstance.xml +#: doc/classes/NavigationRegion2D.xml msgid "" "When pathfinding moves inside this region's navmesh the traveled distances " "are multiplied with [code]travel_cost[/code] for determining the shortest " @@ -36905,7 +36905,7 @@ msgid "" "50), Vector2(50, 0)])\n" "polygon.add_outline(outline)\n" "polygon.make_polygons_from_outlines()\n" -"$NavigationPolygonInstance.navpoly = polygon\n" +"$NavigationRegion2D.navpoly = polygon\n" "[/codeblock]\n" "Using [method add_polygon] and indices of the vertices array.\n" "[codeblock]\n" @@ -36915,7 +36915,7 @@ msgid "" "polygon.set_vertices(vertices)\n" "var indices = PoolIntArray([0, 1, 2, 3])\n" "polygon.add_polygon(indices)\n" -"$NavigationPolygonInstance.navpoly = polygon\n" +"$NavigationRegion2D.navpoly = polygon\n" "[/codeblock]" msgstr "" @@ -36992,11 +36992,11 @@ msgid "" "[method make_polygons_from_outlines] for the polygons to update." msgstr "" -#: doc/classes/NavigationPolygonInstance.xml +#: doc/classes/NavigationRegion2D.xml msgid "A region of the 2D navigation map." msgstr "" -#: doc/classes/NavigationPolygonInstance.xml +#: doc/classes/NavigationRegion2D.xml msgid "" "A region of the navigation map. It tells the [Navigation2DServer] what can " "be navigated and what cannot, based on its [NavigationPolygon] resource.\n" @@ -37016,19 +37016,19 @@ msgid "" "controlled with the [member travel_cost] multiplier." msgstr "" -#: doc/classes/NavigationPolygonInstance.xml +#: doc/classes/NavigationRegion2D.xml msgid "" "Returns the [RID] of this region on the [Navigation2DServer]. Combined with " "[method Navigation2DServer.map_get_closest_point_owner] can be used to " -"identify the [NavigationPolygonInstance] closest to a point on the merged " +"identify the [NavigationRegion2D] closest to a point on the merged " "navigation map." msgstr "" -#: doc/classes/NavigationPolygonInstance.xml -msgid "Determines if the [NavigationPolygonInstance] is enabled or disabled." +#: doc/classes/NavigationRegion2D.xml +msgid "Determines if the [NavigationRegion2D] is enabled or disabled." msgstr "" -#: doc/classes/NavigationPolygonInstance.xml +#: doc/classes/NavigationRegion2D.xml msgid "" "A bitfield determining all navigation map layers the [NavigationPolygon] " "belongs to. On path requests with [method Navigation2DServer.map_get_path] " @@ -37036,7 +37036,7 @@ msgid "" "will only proximity merge different navmeshes with matching layers." msgstr "" -#: doc/classes/NavigationPolygonInstance.xml +#: doc/classes/NavigationRegion2D.xml msgid "The [NavigationPolygon] resource to use." msgstr "" diff --git a/doc/translations/hu.po b/doc/translations/hu.po index d7273a09d..252e067e4 100644 --- a/doc/translations/hu.po +++ b/doc/translations/hu.po @@ -35825,7 +35825,7 @@ msgid "" "Navigation2DServer.map_get_path] instead.\n" "Navigation2D provides navigation and pathfinding within a 2D area, specified " "as a collection of [NavigationPolygon] resources. By default, these are " -"automatically collected from child [NavigationPolygonInstance] nodes." +"automatically collected from child [NavigationRegion2D] nodes." msgstr "" #: doc/classes/Navigation2D.xml doc/classes/Navigation2DServer.xml @@ -35837,7 +35837,7 @@ msgstr "" msgid "" "Returns the owner of the [NavigationPolygon] which contains the navigation " "point closest to the point given. This is usually a " -"[NavigationPolygonInstance]." +"[NavigationRegion2D]." msgstr "" #: doc/classes/Navigation2D.xml @@ -36864,7 +36864,7 @@ msgid "Determines if the [NavigationMeshInstance] is enabled or disabled." msgstr "" #: doc/classes/NavigationMeshInstance.xml -#: doc/classes/NavigationPolygonInstance.xml +#: doc/classes/NavigationRegion2D.xml msgid "" "When pathfinding enters this region's navmesh from another regions navmesh " "the [code]enter_cost[/code] value is added to the path distance for " @@ -36884,7 +36884,7 @@ msgid "The [NavigationMesh] resource to use." msgstr "" #: doc/classes/NavigationMeshInstance.xml -#: doc/classes/NavigationPolygonInstance.xml +#: doc/classes/NavigationRegion2D.xml msgid "" "When pathfinding moves inside this region's navmesh the traveled distances " "are multiplied with [code]travel_cost[/code] for determining the shortest " @@ -36988,7 +36988,7 @@ msgid "" "50), Vector2(50, 0)])\n" "polygon.add_outline(outline)\n" "polygon.make_polygons_from_outlines()\n" -"$NavigationPolygonInstance.navpoly = polygon\n" +"$NavigationRegion2D.navpoly = polygon\n" "[/codeblock]\n" "Using [method add_polygon] and indices of the vertices array.\n" "[codeblock]\n" @@ -36998,7 +36998,7 @@ msgid "" "polygon.set_vertices(vertices)\n" "var indices = PoolIntArray([0, 1, 2, 3])\n" "polygon.add_polygon(indices)\n" -"$NavigationPolygonInstance.navpoly = polygon\n" +"$NavigationRegion2D.navpoly = polygon\n" "[/codeblock]" msgstr "" @@ -37075,11 +37075,11 @@ msgid "" "[method make_polygons_from_outlines] for the polygons to update." msgstr "" -#: doc/classes/NavigationPolygonInstance.xml +#: doc/classes/NavigationRegion2D.xml msgid "A region of the 2D navigation map." msgstr "" -#: doc/classes/NavigationPolygonInstance.xml +#: doc/classes/NavigationRegion2D.xml msgid "" "A region of the navigation map. It tells the [Navigation2DServer] what can " "be navigated and what cannot, based on its [NavigationPolygon] resource.\n" @@ -37099,19 +37099,19 @@ msgid "" "controlled with the [member travel_cost] multiplier." msgstr "" -#: doc/classes/NavigationPolygonInstance.xml +#: doc/classes/NavigationRegion2D.xml msgid "" "Returns the [RID] of this region on the [Navigation2DServer]. Combined with " "[method Navigation2DServer.map_get_closest_point_owner] can be used to " -"identify the [NavigationPolygonInstance] closest to a point on the merged " +"identify the [NavigationRegion2D] closest to a point on the merged " "navigation map." msgstr "" -#: doc/classes/NavigationPolygonInstance.xml -msgid "Determines if the [NavigationPolygonInstance] is enabled or disabled." +#: doc/classes/NavigationRegion2D.xml +msgid "Determines if the [NavigationRegion2D] is enabled or disabled." msgstr "" -#: doc/classes/NavigationPolygonInstance.xml +#: doc/classes/NavigationRegion2D.xml msgid "" "A bitfield determining all navigation map layers the [NavigationPolygon] " "belongs to. On path requests with [method Navigation2DServer.map_get_path] " @@ -37119,7 +37119,7 @@ msgid "" "will only proximity merge different navmeshes with matching layers." msgstr "" -#: doc/classes/NavigationPolygonInstance.xml +#: doc/classes/NavigationRegion2D.xml msgid "The [NavigationPolygon] resource to use." msgstr "" diff --git a/editor/plugins/navigation_polygon_editor_plugin.cpp b/editor/plugins/navigation_polygon_editor_plugin.cpp index a319baace..1034eed35 100644 --- a/editor/plugins/navigation_polygon_editor_plugin.cpp +++ b/editor/plugins/navigation_polygon_editor_plugin.cpp @@ -35,7 +35,8 @@ #include "core/object/undo_redo.h" #include "core/string/ustring.h" #include "core/containers/vector.h" -#include "scene/2d/navigation_polygon.h" +#include "scene/2d/navigation_region_2d.h" +#include "scene/resources/navigation_polygon.h" #include "scene/main/node.h" class EditorNode; @@ -55,7 +56,7 @@ Node2D *NavigationPolygonEditor::_get_node() const { } void NavigationPolygonEditor::_set_node(Node *p_polygon) { - node = Object::cast_to(p_polygon); + node = Object::cast_to(p_polygon); } int NavigationPolygonEditor::_get_polygon_count() const { @@ -129,5 +130,5 @@ NavigationPolygonEditor::NavigationPolygonEditor(EditorNode *p_editor) : } NavigationPolygonEditorPlugin::NavigationPolygonEditorPlugin(EditorNode *p_node) : - AbstractPolygon2DEditorPlugin(p_node, memnew(NavigationPolygonEditor(p_node)), "NavigationPolygonInstance") { + AbstractPolygon2DEditorPlugin(p_node, memnew(NavigationPolygonEditor(p_node)), "NavigationRegion2D") { } diff --git a/editor/plugins/navigation_polygon_editor_plugin.h b/editor/plugins/navigation_polygon_editor_plugin.h index 62be87ced..4e6e624cd 100644 --- a/editor/plugins/navigation_polygon_editor_plugin.h +++ b/editor/plugins/navigation_polygon_editor_plugin.h @@ -38,14 +38,14 @@ class EditorNode; class NavigationPolygon; -class NavigationPolygonInstance; +class NavigationRegion2D; class Node2D; class Node; class NavigationPolygonEditor : public AbstractPolygon2DEditor { GDCLASS(NavigationPolygonEditor, AbstractPolygon2DEditor); - NavigationPolygonInstance *node; + NavigationRegion2D *node; Ref _ensure_navpoly() const; diff --git a/modules/navigation/pandemonium_navigation_2d_server.h b/modules/navigation/pandemonium_navigation_2d_server.h index 731790cbb..4f3ba22fa 100644 --- a/modules/navigation/pandemonium_navigation_2d_server.h +++ b/modules/navigation/pandemonium_navigation_2d_server.h @@ -33,7 +33,7 @@ #include "core/object/object.h" #include "core/containers/rid.h" -#include "scene/2d/navigation_polygon.h" +#include "scene/resources/navigation_polygon.h" #include "servers/navigation_2d_server.h" // This server exposes the 3D `NavigationServer` features in the 2D world. diff --git a/modules/navigation_dummy/dummy_navigation_2d_server.cpp b/modules/navigation_dummy/dummy_navigation_2d_server.cpp index 3e79025e4..a21b54b91 100644 --- a/modules/navigation_dummy/dummy_navigation_2d_server.cpp +++ b/modules/navigation_dummy/dummy_navigation_2d_server.cpp @@ -30,7 +30,7 @@ #include "dummy_navigation_2d_server.h" -#include "scene/2d/navigation_polygon.h" +#include "scene/resources/navigation_polygon.h" void DummyNavigation2DServer::region_set_navpoly(RID p_region, Ref p_nav_mesh) const { } diff --git a/modules/tile_map/tile_set.h b/modules/tile_map/tile_set.h index fd132d125..91beb2a3b 100644 --- a/modules/tile_map/tile_set.h +++ b/modules/tile_map/tile_set.h @@ -35,7 +35,8 @@ #include "core/variant/array.h" #include "core/object/resource.h" #include "scene/2d/light_occluder_2d.h" -#include "scene/2d/navigation_polygon.h" +#include "scene/2d/navigation_region_2d.h" +#include "scene/resources/navigation_polygon.h" #include "scene/resources/convex_polygon_shape_2d.h" #include "scene/resources/shape_2d.h" #include "scene/resources/texture.h" diff --git a/modules/tile_map/tile_set_editor_plugin.cpp b/modules/tile_map/tile_set_editor_plugin.cpp index cf1b3f22f..cad5da442 100644 --- a/modules/tile_map/tile_set_editor_plugin.cpp +++ b/modules/tile_map/tile_set_editor_plugin.cpp @@ -123,8 +123,8 @@ void TileSetEditor::_import_node(Node *p_node, Ref p_library) { for (int j = 0; j < mi->get_child_count(); j++) { Node *child2 = mi->get_child(j); - if (Object::cast_to(child2)) { - nav_poly = Object::cast_to(child2)->get_navigation_polygon(); + if (Object::cast_to(child2)) { + nav_poly = Object::cast_to(child2)->get_navigation_polygon(); } if (Object::cast_to(child2)) { diff --git a/scene/2d/navigation_2d.cpp b/scene/2d/navigation_2d.cpp index 81339319a..d8b1454e0 100644 --- a/scene/2d/navigation_2d.cpp +++ b/scene/2d/navigation_2d.cpp @@ -30,7 +30,8 @@ #include "navigation_2d.h" -#include "scene/2d/navigation_polygon.h" +#include "scene/2d/navigation_region_2d.h" +#include "scene/resources/navigation_polygon.h" #include "servers/navigation_2d_server.h" void Navigation2D::_bind_methods() { diff --git a/scene/2d/navigation_region_2d.cpp b/scene/2d/navigation_region_2d.cpp new file mode 100644 index 000000000..583853f2b --- /dev/null +++ b/scene/2d/navigation_region_2d.cpp @@ -0,0 +1,328 @@ +/*************************************************************************/ +/* navigation_polygon.cpp */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "navigation_region_2d.h" + +#include "core/core_string_names.h" +#include "core/config/engine.h" +#include "core/os/mutex.h" +#include "navigation_2d.h" +#include "scene/resources/navigation_mesh.h" +#include "scene/resources/world_2d.h" +#include "servers/navigation_2d_server.h" +#include "scene/resources/navigation_polygon.h" + +#include "thirdparty/misc/triangulator.h" + +void NavigationRegion2D::set_enabled(bool p_enabled) { + if (enabled == p_enabled) { + return; + } + enabled = p_enabled; + + if (!is_inside_tree()) { + return; + } + + if (!enabled) { + Navigation2DServer::get_singleton()->region_set_map(region, RID()); + Navigation2DServer::get_singleton_mut()->disconnect("map_changed", this, "_map_changed"); + } else { + if (navigation != nullptr) { + Navigation2DServer::get_singleton()->region_set_map(region, navigation->get_rid()); + } else { + Navigation2DServer::get_singleton()->region_set_map(region, get_world_2d()->get_navigation_map()); + } + Navigation2DServer::get_singleton_mut()->connect("map_changed", this, "_map_changed"); + } + + if (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_navigation_hint()) { + update(); + } +} + +bool NavigationRegion2D::is_enabled() const { + return enabled; +} + +void NavigationRegion2D::set_navigation_layers(uint32_t p_navigation_layers) { + navigation_layers = p_navigation_layers; + Navigation2DServer::get_singleton()->region_set_navigation_layers(region, navigation_layers); +} + +uint32_t NavigationRegion2D::get_navigation_layers() const { + return navigation_layers; +} + +void NavigationRegion2D::set_enter_cost(real_t p_enter_cost) { + ERR_FAIL_COND_MSG(p_enter_cost < 0.0, "The enter_cost must be positive."); + enter_cost = MAX(p_enter_cost, 0.0); + Navigation2DServer::get_singleton()->region_set_enter_cost(region, p_enter_cost); +} + +real_t NavigationRegion2D::get_enter_cost() const { + return enter_cost; +} + +void NavigationRegion2D::set_travel_cost(real_t p_travel_cost) { + ERR_FAIL_COND_MSG(p_travel_cost < 0.0, "The travel_cost must be positive."); + travel_cost = MAX(p_travel_cost, 0.0); + Navigation2DServer::get_singleton()->region_set_enter_cost(region, travel_cost); +} + +real_t NavigationRegion2D::get_travel_cost() const { + return travel_cost; +} + +RID NavigationRegion2D::get_region_rid() const { + return region; +} + +///////////////////////////// +#ifdef TOOLS_ENABLED +Rect2 NavigationRegion2D::_edit_get_rect() const { + return navpoly.is_valid() ? navpoly->_edit_get_rect() : Rect2(); +} + +bool NavigationRegion2D::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { + return navpoly.is_valid() ? navpoly->_edit_is_selected_on_click(p_point, p_tolerance) : false; +} +#endif + +void NavigationRegion2D::_notification(int p_what) { + switch (p_what) { + case NOTIFICATION_ENTER_TREE: { + Node2D *c = this; + while (c) { + navigation = Object::cast_to(c); + + if (navigation) { + if (enabled) { + Navigation2DServer::get_singleton()->region_set_map(region, navigation->get_rid()); + } + break; + } + + c = Object::cast_to(c->get_parent()); + } + + if (enabled && navigation == nullptr) { + // did not find a valid navigation node parent, fallback to default navigation map on world resource + Navigation2DServer::get_singleton()->region_set_map(region, get_world_2d()->get_navigation_map()); + } + if (enabled) { + Navigation2DServer::get_singleton_mut()->connect("map_changed", this, "_map_changed"); + } + } break; + case NOTIFICATION_TRANSFORM_CHANGED: { + Navigation2DServer::get_singleton()->region_set_transform(region, get_global_transform()); + } break; + case NOTIFICATION_EXIT_TREE: { + if (navigation) { + Navigation2DServer::get_singleton()->region_set_map(region, RID()); + } + navigation = nullptr; + + if (enabled) { + Navigation2DServer::get_singleton_mut()->disconnect("map_changed", this, "_map_changed"); + } + } break; + case NOTIFICATION_DRAW: { + if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_navigation_hint()) && navpoly.is_valid()) { + PoolVector verts = navpoly->get_vertices(); + if (verts.size() < 3) { + return; + } + + Color color; + if (enabled) { + color = get_tree()->get_debug_navigation_color(); + } else { + color = get_tree()->get_debug_navigation_disabled_color(); + } + + Color doors_color = color.lightened(0.2); + + RandomPCG rand; + + for (int i = 0; i < navpoly->get_polygon_count(); i++) { + // An array of vertices for this polygon. + Vector polygon = navpoly->get_polygon(i); + + Vector vertices; + vertices.resize(polygon.size()); + for (int j = 0; j < polygon.size(); j++) { + ERR_FAIL_INDEX(polygon[j], verts.size()); + vertices.write[j] = verts[polygon[j]]; + } + // Generate the polygon color, slightly randomly modified from the settings one. + Color random_variation_color; + random_variation_color.set_hsv(color.get_h() + rand.random(-1.0, 1.0) * 0.05, color.get_s(), color.get_v() + rand.random(-1.0, 1.0) * 0.1); + random_variation_color.a = color.a; + Vector colors; + colors.push_back(random_variation_color); + + RS::get_singleton()->canvas_item_add_polygon(get_canvas_item(), vertices, colors); + } + + // Draw the region + Transform2D xform = get_global_transform(); + const Navigation2DServer *ns = Navigation2DServer::get_singleton(); + real_t radius = 1.0; + if (navigation != nullptr) { + radius = Navigation2DServer::get_singleton()->map_get_edge_connection_margin(navigation->get_rid()); + } else { + radius = Navigation2DServer::get_singleton()->map_get_edge_connection_margin(get_world_2d()->get_navigation_map()); + } + radius = radius * 0.5; + for (int i = 0; i < ns->region_get_connections_count(region); i++) { + // Two main points + Vector2 a = ns->region_get_connection_pathway_start(region, i); + a = xform.affine_inverse().xform(a); + Vector2 b = ns->region_get_connection_pathway_end(region, i); + b = xform.affine_inverse().xform(b); + draw_line(a, b, doors_color); + + // Draw a circle to illustrate the margins. + real_t angle = a.angle_to_point(b); + draw_arc(a, radius, angle + Math_PI / 2.0, angle - Math_PI / 2.0 + Math_TAU, 10, doors_color); + draw_arc(b, radius, angle - Math_PI / 2.0, angle + Math_PI / 2.0, 10, doors_color); + } + } + } break; + } +} + +void NavigationRegion2D::set_navigation_polygon(const Ref &p_navpoly) { + if (p_navpoly == navpoly) { + return; + } + + if (navpoly.is_valid()) { + navpoly->disconnect(CoreStringNames::get_singleton()->changed, this, "_navpoly_changed"); + } + + navpoly = p_navpoly; + Navigation2DServer::get_singleton()->region_set_navpoly(region, p_navpoly); + + if (navpoly.is_valid()) { + navpoly->connect(CoreStringNames::get_singleton()->changed, this, "_navpoly_changed"); + } + _navpoly_changed(); + + _change_notify("navpoly"); + update_configuration_warning(); +} + +Ref NavigationRegion2D::get_navigation_polygon() const { + return navpoly; +} + +void NavigationRegion2D::_navpoly_changed() { + if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_navigation_hint())) { + update(); + } + if (navpoly.is_valid()) { + Navigation2DServer::get_singleton()->region_set_navpoly(region, navpoly); + } +} + +void NavigationRegion2D::_map_changed(RID p_map) { + if (navigation != nullptr && enabled && (navigation->get_rid() == p_map)) { + update(); + } else if (is_inside_tree() && enabled && (get_world_2d()->get_navigation_map() == p_map)) { + update(); + } +} + +String NavigationRegion2D::get_configuration_warning() const { + if (!is_visible_in_tree() || !is_inside_tree()) { + return String(); + } + + String warning = Node2D::get_configuration_warning(); + if (!navpoly.is_valid()) { + if (warning != String()) { + warning += "\n\n"; + } + warning += TTR("A NavigationPolygon resource must be set or created for this node to work. Please set a property or draw a polygon."); + } + + return warning; +} + +void NavigationRegion2D::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_navigation_polygon", "navpoly"), &NavigationRegion2D::set_navigation_polygon); + ClassDB::bind_method(D_METHOD("get_navigation_polygon"), &NavigationRegion2D::get_navigation_polygon); + + ClassDB::bind_method(D_METHOD("set_enabled", "enabled"), &NavigationRegion2D::set_enabled); + ClassDB::bind_method(D_METHOD("is_enabled"), &NavigationRegion2D::is_enabled); + + ClassDB::bind_method(D_METHOD("set_navigation_layers", "navigation_layers"), &NavigationRegion2D::set_navigation_layers); + ClassDB::bind_method(D_METHOD("get_navigation_layers"), &NavigationRegion2D::get_navigation_layers); + + ClassDB::bind_method(D_METHOD("get_region_rid"), &NavigationRegion2D::get_region_rid); + + ClassDB::bind_method(D_METHOD("set_enter_cost", "enter_cost"), &NavigationRegion2D::set_enter_cost); + ClassDB::bind_method(D_METHOD("get_enter_cost"), &NavigationRegion2D::get_enter_cost); + + ClassDB::bind_method(D_METHOD("set_travel_cost", "travel_cost"), &NavigationRegion2D::set_travel_cost); + ClassDB::bind_method(D_METHOD("get_travel_cost"), &NavigationRegion2D::get_travel_cost); + + ClassDB::bind_method(D_METHOD("_navpoly_changed"), &NavigationRegion2D::_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::INT, "navigation_layers", PROPERTY_HINT_LAYERS_2D_NAVIGATION), "set_navigation_layers", "get_navigation_layers"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "enter_cost"), "set_enter_cost", "get_enter_cost"); + ADD_PROPERTY(PropertyInfo(Variant::REAL, "travel_cost"), "set_travel_cost", "get_travel_cost"); + + ClassDB::bind_method(D_METHOD("_map_changed"), &NavigationRegion2D::_map_changed); +} + +NavigationRegion2D::NavigationRegion2D() { + enabled = true; + set_notify_transform(true); + region = Navigation2DServer::get_singleton()->region_create(); + + navigation = nullptr; + + enter_cost = 0.0; + travel_cost = 1.0; + + navigation_layers = 1; + + Navigation2DServer::get_singleton()->region_set_enter_cost(region, get_enter_cost()); + Navigation2DServer::get_singleton()->region_set_travel_cost(region, get_travel_cost()); +} + +NavigationRegion2D::~NavigationRegion2D() { + Navigation2DServer::get_singleton()->free(region); +} diff --git a/scene/2d/navigation_region_2d.h b/scene/2d/navigation_region_2d.h new file mode 100644 index 000000000..3f4cef068 --- /dev/null +++ b/scene/2d/navigation_region_2d.h @@ -0,0 +1,90 @@ +#ifndef NAVIGATION_REGION_2D_H +#define NAVIGATION_REGION_2D_H + +/*************************************************************************/ +/* navigation_polygon.h */ +/*************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/*************************************************************************/ +/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ +/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/*************************************************************************/ + +#include "core/object/resource.h" +#include "scene/2d/node_2d.h" + +class NavigationMesh; +class Navigation2D; +class NavigationPolygon; + +class NavigationRegion2D : public Node2D { + GDCLASS(NavigationRegion2D, Node2D); + + bool enabled; + RID region; + Navigation2D *navigation; + Ref navpoly; + + real_t enter_cost; + real_t travel_cost; + + uint32_t navigation_layers; + + void _navpoly_changed(); + void _map_changed(RID p_map); + +protected: + void _notification(int p_what); + static void _bind_methods(); + +public: +#ifdef TOOLS_ENABLED + virtual Rect2 _edit_get_rect() const; + virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const; +#endif + + void set_enabled(bool p_enabled); + bool is_enabled() const; + + void set_navigation_layers(uint32_t p_navigation_layers); + uint32_t get_navigation_layers() const; + + RID get_region_rid() const; + + void set_enter_cost(real_t p_enter_cost); + real_t get_enter_cost() const; + + void set_travel_cost(real_t p_travel_cost); + real_t get_travel_cost() const; + + void set_navigation_polygon(const Ref &p_navpoly); + Ref get_navigation_polygon() const; + + String get_configuration_warning() const; + + NavigationRegion2D(); + ~NavigationRegion2D(); +}; + +#endif // NAVIGATIONPOLYGON_H diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index b330046d7..b5a9b7457 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -54,7 +54,8 @@ #include "scene/2d/navigation_2d.h" #include "scene/2d/navigation_agent_2d.h" #include "scene/2d/navigation_obstacle_2d.h" -#include "scene/2d/navigation_polygon.h" +#include "scene/2d/navigation_region_2d.h" +#include "scene/resources/navigation_polygon.h" #include "scene/2d/parallax_background.h" #include "scene/2d/parallax_layer.h" #include "scene/2d/path_2d.h" @@ -681,7 +682,7 @@ void register_scene_types() { ClassDB::register_class(); ClassDB::register_class(); - ClassDB::register_class(); + ClassDB::register_class(); ClassDB::register_class(); ClassDB::register_class(); diff --git a/scene/2d/navigation_polygon.cpp b/scene/resources/navigation_polygon.cpp similarity index 53% rename from scene/2d/navigation_polygon.cpp rename to scene/resources/navigation_polygon.cpp index cd296982e..5795f2867 100644 --- a/scene/2d/navigation_polygon.cpp +++ b/scene/resources/navigation_polygon.cpp @@ -33,7 +33,7 @@ #include "core/core_string_names.h" #include "core/config/engine.h" #include "core/os/mutex.h" -#include "navigation_2d.h" +#include "scene/2d/navigation_2d.h" #include "scene/resources/navigation_mesh.h" #include "scene/resources/world_2d.h" #include "servers/navigation_2d_server.h" @@ -362,289 +362,3 @@ NavigationPolygon::NavigationPolygon() { NavigationPolygon::~NavigationPolygon() { } - -void NavigationPolygonInstance::set_enabled(bool p_enabled) { - if (enabled == p_enabled) { - return; - } - enabled = p_enabled; - - if (!is_inside_tree()) { - return; - } - - if (!enabled) { - Navigation2DServer::get_singleton()->region_set_map(region, RID()); - Navigation2DServer::get_singleton_mut()->disconnect("map_changed", this, "_map_changed"); - } else { - if (navigation != nullptr) { - Navigation2DServer::get_singleton()->region_set_map(region, navigation->get_rid()); - } else { - Navigation2DServer::get_singleton()->region_set_map(region, get_world_2d()->get_navigation_map()); - } - Navigation2DServer::get_singleton_mut()->connect("map_changed", this, "_map_changed"); - } - - if (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_navigation_hint()) { - update(); - } -} - -bool NavigationPolygonInstance::is_enabled() const { - return enabled; -} - -void NavigationPolygonInstance::set_navigation_layers(uint32_t p_navigation_layers) { - navigation_layers = p_navigation_layers; - Navigation2DServer::get_singleton()->region_set_navigation_layers(region, navigation_layers); -} - -uint32_t NavigationPolygonInstance::get_navigation_layers() const { - return navigation_layers; -} - -void NavigationPolygonInstance::set_enter_cost(real_t p_enter_cost) { - ERR_FAIL_COND_MSG(p_enter_cost < 0.0, "The enter_cost must be positive."); - enter_cost = MAX(p_enter_cost, 0.0); - Navigation2DServer::get_singleton()->region_set_enter_cost(region, p_enter_cost); -} - -real_t NavigationPolygonInstance::get_enter_cost() const { - return enter_cost; -} - -void NavigationPolygonInstance::set_travel_cost(real_t p_travel_cost) { - ERR_FAIL_COND_MSG(p_travel_cost < 0.0, "The travel_cost must be positive."); - travel_cost = MAX(p_travel_cost, 0.0); - Navigation2DServer::get_singleton()->region_set_enter_cost(region, travel_cost); -} - -real_t NavigationPolygonInstance::get_travel_cost() const { - return travel_cost; -} - -RID NavigationPolygonInstance::get_region_rid() const { - return region; -} - -///////////////////////////// -#ifdef TOOLS_ENABLED -Rect2 NavigationPolygonInstance::_edit_get_rect() const { - return navpoly.is_valid() ? navpoly->_edit_get_rect() : Rect2(); -} - -bool NavigationPolygonInstance::_edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const { - return navpoly.is_valid() ? navpoly->_edit_is_selected_on_click(p_point, p_tolerance) : false; -} -#endif - -void NavigationPolygonInstance::_notification(int p_what) { - switch (p_what) { - case NOTIFICATION_ENTER_TREE: { - Node2D *c = this; - while (c) { - navigation = Object::cast_to(c); - - if (navigation) { - if (enabled) { - Navigation2DServer::get_singleton()->region_set_map(region, navigation->get_rid()); - } - break; - } - - c = Object::cast_to(c->get_parent()); - } - - if (enabled && navigation == nullptr) { - // did not find a valid navigation node parent, fallback to default navigation map on world resource - Navigation2DServer::get_singleton()->region_set_map(region, get_world_2d()->get_navigation_map()); - } - if (enabled) { - Navigation2DServer::get_singleton_mut()->connect("map_changed", this, "_map_changed"); - } - } break; - case NOTIFICATION_TRANSFORM_CHANGED: { - Navigation2DServer::get_singleton()->region_set_transform(region, get_global_transform()); - } break; - case NOTIFICATION_EXIT_TREE: { - if (navigation) { - Navigation2DServer::get_singleton()->region_set_map(region, RID()); - } - navigation = nullptr; - - if (enabled) { - Navigation2DServer::get_singleton_mut()->disconnect("map_changed", this, "_map_changed"); - } - } break; - case NOTIFICATION_DRAW: { - if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_navigation_hint()) && navpoly.is_valid()) { - PoolVector verts = navpoly->get_vertices(); - if (verts.size() < 3) { - return; - } - - Color color; - if (enabled) { - color = get_tree()->get_debug_navigation_color(); - } else { - color = get_tree()->get_debug_navigation_disabled_color(); - } - - Color doors_color = color.lightened(0.2); - - RandomPCG rand; - - for (int i = 0; i < navpoly->get_polygon_count(); i++) { - // An array of vertices for this polygon. - Vector polygon = navpoly->get_polygon(i); - - Vector vertices; - vertices.resize(polygon.size()); - for (int j = 0; j < polygon.size(); j++) { - ERR_FAIL_INDEX(polygon[j], verts.size()); - vertices.write[j] = verts[polygon[j]]; - } - // Generate the polygon color, slightly randomly modified from the settings one. - Color random_variation_color; - random_variation_color.set_hsv(color.get_h() + rand.random(-1.0, 1.0) * 0.05, color.get_s(), color.get_v() + rand.random(-1.0, 1.0) * 0.1); - random_variation_color.a = color.a; - Vector colors; - colors.push_back(random_variation_color); - - RS::get_singleton()->canvas_item_add_polygon(get_canvas_item(), vertices, colors); - } - - // Draw the region - Transform2D xform = get_global_transform(); - const Navigation2DServer *ns = Navigation2DServer::get_singleton(); - real_t radius = 1.0; - if (navigation != nullptr) { - radius = Navigation2DServer::get_singleton()->map_get_edge_connection_margin(navigation->get_rid()); - } else { - radius = Navigation2DServer::get_singleton()->map_get_edge_connection_margin(get_world_2d()->get_navigation_map()); - } - radius = radius * 0.5; - for (int i = 0; i < ns->region_get_connections_count(region); i++) { - // Two main points - Vector2 a = ns->region_get_connection_pathway_start(region, i); - a = xform.affine_inverse().xform(a); - Vector2 b = ns->region_get_connection_pathway_end(region, i); - b = xform.affine_inverse().xform(b); - draw_line(a, b, doors_color); - - // Draw a circle to illustrate the margins. - real_t angle = a.angle_to_point(b); - draw_arc(a, radius, angle + Math_PI / 2.0, angle - Math_PI / 2.0 + Math_TAU, 10, doors_color); - draw_arc(b, radius, angle - Math_PI / 2.0, angle + Math_PI / 2.0, 10, doors_color); - } - } - } break; - } -} - -void NavigationPolygonInstance::set_navigation_polygon(const Ref &p_navpoly) { - if (p_navpoly == navpoly) { - return; - } - - if (navpoly.is_valid()) { - navpoly->disconnect(CoreStringNames::get_singleton()->changed, this, "_navpoly_changed"); - } - - navpoly = p_navpoly; - Navigation2DServer::get_singleton()->region_set_navpoly(region, p_navpoly); - - if (navpoly.is_valid()) { - navpoly->connect(CoreStringNames::get_singleton()->changed, this, "_navpoly_changed"); - } - _navpoly_changed(); - - _change_notify("navpoly"); - update_configuration_warning(); -} - -Ref NavigationPolygonInstance::get_navigation_polygon() const { - return navpoly; -} - -void NavigationPolygonInstance::_navpoly_changed() { - if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_navigation_hint())) { - update(); - } - if (navpoly.is_valid()) { - Navigation2DServer::get_singleton()->region_set_navpoly(region, navpoly); - } -} - -void NavigationPolygonInstance::_map_changed(RID p_map) { - if (navigation != nullptr && enabled && (navigation->get_rid() == p_map)) { - update(); - } else if (is_inside_tree() && enabled && (get_world_2d()->get_navigation_map() == p_map)) { - update(); - } -} - -String NavigationPolygonInstance::get_configuration_warning() const { - if (!is_visible_in_tree() || !is_inside_tree()) { - return String(); - } - - String warning = Node2D::get_configuration_warning(); - if (!navpoly.is_valid()) { - if (warning != String()) { - warning += "\n\n"; - } - warning += TTR("A NavigationPolygon resource must be set or created for this node to work. Please set a property or draw a polygon."); - } - - return warning; -} - -void NavigationPolygonInstance::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_navigation_polygon", "navpoly"), &NavigationPolygonInstance::set_navigation_polygon); - ClassDB::bind_method(D_METHOD("get_navigation_polygon"), &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_navigation_layers", "navigation_layers"), &NavigationPolygonInstance::set_navigation_layers); - ClassDB::bind_method(D_METHOD("get_navigation_layers"), &NavigationPolygonInstance::get_navigation_layers); - - ClassDB::bind_method(D_METHOD("get_region_rid"), &NavigationPolygonInstance::get_region_rid); - - ClassDB::bind_method(D_METHOD("set_enter_cost", "enter_cost"), &NavigationPolygonInstance::set_enter_cost); - ClassDB::bind_method(D_METHOD("get_enter_cost"), &NavigationPolygonInstance::get_enter_cost); - - ClassDB::bind_method(D_METHOD("set_travel_cost", "travel_cost"), &NavigationPolygonInstance::set_travel_cost); - ClassDB::bind_method(D_METHOD("get_travel_cost"), &NavigationPolygonInstance::get_travel_cost); - - 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::INT, "navigation_layers", PROPERTY_HINT_LAYERS_2D_NAVIGATION), "set_navigation_layers", "get_navigation_layers"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "enter_cost"), "set_enter_cost", "get_enter_cost"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "travel_cost"), "set_travel_cost", "get_travel_cost"); - - ClassDB::bind_method(D_METHOD("_map_changed"), &NavigationPolygonInstance::_map_changed); -} - -NavigationPolygonInstance::NavigationPolygonInstance() { - enabled = true; - set_notify_transform(true); - region = Navigation2DServer::get_singleton()->region_create(); - - navigation = nullptr; - - enter_cost = 0.0; - travel_cost = 1.0; - - navigation_layers = 1; - - Navigation2DServer::get_singleton()->region_set_enter_cost(region, get_enter_cost()); - Navigation2DServer::get_singleton()->region_set_travel_cost(region, get_travel_cost()); -} - -NavigationPolygonInstance::~NavigationPolygonInstance() { - Navigation2DServer::get_singleton()->free(region); -} diff --git a/scene/2d/navigation_polygon.h b/scene/resources/navigation_polygon.h similarity index 76% rename from scene/2d/navigation_polygon.h rename to scene/resources/navigation_polygon.h index 80ddb3742..ae35ec031 100644 --- a/scene/2d/navigation_polygon.h +++ b/scene/resources/navigation_polygon.h @@ -92,55 +92,4 @@ public: ~NavigationPolygon(); }; -class Navigation2D; - -class NavigationPolygonInstance : public Node2D { - GDCLASS(NavigationPolygonInstance, Node2D); - - bool enabled; - RID region; - Navigation2D *navigation; - Ref navpoly; - - real_t enter_cost; - real_t travel_cost; - - uint32_t navigation_layers; - - void _navpoly_changed(); - void _map_changed(RID p_map); - -protected: - void _notification(int p_what); - static void _bind_methods(); - -public: -#ifdef TOOLS_ENABLED - virtual Rect2 _edit_get_rect() const; - virtual bool _edit_is_selected_on_click(const Point2 &p_point, double p_tolerance) const; -#endif - - void set_enabled(bool p_enabled); - bool is_enabled() const; - - void set_navigation_layers(uint32_t p_navigation_layers); - uint32_t get_navigation_layers() const; - - RID get_region_rid() const; - - void set_enter_cost(real_t p_enter_cost); - real_t get_enter_cost() const; - - void set_travel_cost(real_t p_travel_cost); - real_t get_travel_cost() const; - - void set_navigation_polygon(const Ref &p_navpoly); - Ref get_navigation_polygon() const; - - String get_configuration_warning() const; - - NavigationPolygonInstance(); - ~NavigationPolygonInstance(); -}; - #endif // NAVIGATIONPOLYGON_H diff --git a/servers/navigation_2d_server.h b/servers/navigation_2d_server.h index a052fe696..652242209 100644 --- a/servers/navigation_2d_server.h +++ b/servers/navigation_2d_server.h @@ -33,7 +33,9 @@ #include "core/containers/rid.h" #include "core/object/object.h" -#include "scene/2d/navigation_polygon.h" + +#include "scene/2d/navigation_region_2d.h" +#include "scene/resources/navigation_polygon.h" // This server exposes the 3D `NavigationServer` features in the 2D world. class Navigation2DServer : public Object {