From a222159442a5bd95e81ca745dce0356f06dfb53a Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 4 Sep 2023 20:22:28 +0200 Subject: [PATCH] Backported from godot4: Add NavigationServer API to enable regions and links Adds NavigationServer API to enable regions and links. - smix8 https://github.com/godotengine/godot/commit/69fad39cf5437b45bac2039d864605b2b63b9950 --- doc/classes/Navigation2DServer.xml | 30 +++++++++++++++++++ doc/classes/NavigationServer.xml | 30 +++++++++++++++++++ modules/navigation/nav_link.cpp | 10 +++++++ modules/navigation/nav_link.h | 5 ++++ modules/navigation/nav_map.cpp | 18 +++++++++-- modules/navigation/nav_region.cpp | 11 +++++++ modules/navigation/nav_region.h | 4 +++ .../pandemonium_navigation_2d_server.cpp | 4 +++ .../pandemonium_navigation_2d_server.h | 6 ++++ .../pandemonium_navigation_server.cpp | 28 +++++++++++++++++ .../pandemonium_navigation_server.h | 5 ++++ .../dummy_navigation_2d_server.h | 12 +++++--- .../dummy_navigation_server.h | 12 +++++--- scene/2d/navigation_link_2d.cpp | 10 +------ scene/2d/navigation_polygon_instance.cpp | 4 +-- scene/3d/navigation_link_3d.cpp | 12 ++------ scene/3d/navigation_mesh_instance.cpp | 18 +---------- servers/navigation_2d_server.cpp | 4 +++ servers/navigation_2d_server.h | 6 ++++ servers/navigation_server.cpp | 3 ++ servers/navigation_server.h | 6 ++++ 21 files changed, 188 insertions(+), 50 deletions(-) diff --git a/doc/classes/Navigation2DServer.xml b/doc/classes/Navigation2DServer.xml index 5e9c65cab..088ad404a 100644 --- a/doc/classes/Navigation2DServer.xml +++ b/doc/classes/Navigation2DServer.xml @@ -208,6 +208,13 @@ Create a new link between two positions on a map. + + + + + Returns [code]true[/code] if the specified [param link] is enabled. + + @@ -272,6 +279,14 @@ Sets whether this [code]link[/code] can be travelled in both directions. + + + + + + If [param enabled] is [code]true[/code] the specified [param link] will contribute to its current navigation map. + + @@ -609,6 +624,13 @@ Returns how many connections this [code]region[/code] has with other regions in the map. + + + + + Returns [code]true[/code] if the specified [param region] is enabled. + + @@ -661,6 +683,14 @@ [b]Note:[/b] If navigation meshes from different navigation regions overlap (which should be avoided in general) the result might not be what is expected. + + + + + + If [param enabled] is [code]true[/code] the specified [param region] will contribute to its current navigation map. + + diff --git a/doc/classes/NavigationServer.xml b/doc/classes/NavigationServer.xml index 0056cf3bd..17e7cefa5 100644 --- a/doc/classes/NavigationServer.xml +++ b/doc/classes/NavigationServer.xml @@ -239,6 +239,13 @@ Create a new link between two positions on a map. + + + + + Returns [code]true[/code] if the specified [param link] is enabled. + + @@ -303,6 +310,14 @@ Sets whether this [code]link[/code] can be travelled in both directions. + + + + + + If [param enabled] is [code]true[/code] the specified [param link] will contribute to its current navigation map. + + @@ -704,6 +719,13 @@ Returns how many connections this [code]region[/code] has with other regions in the map. + + + + + Returns [code]true[/code] if the specified [param region] is enabled. + + @@ -756,6 +778,14 @@ [b]Note:[/b] If navigation meshes from different navigation regions overlap (which should be avoided in general) the result might not be what is expected. + + + + + + If [param enabled] is [code]true[/code] the specified [param region] will contribute to its current navigation map. + + diff --git a/modules/navigation/nav_link.cpp b/modules/navigation/nav_link.cpp index 5607a3253..e7aa160c6 100644 --- a/modules/navigation/nav_link.cpp +++ b/modules/navigation/nav_link.cpp @@ -40,6 +40,16 @@ void NavLink::set_map(NavMap *p_map) { link_dirty = true; } +void NavLink::set_enabled(bool p_enabled) { + if (enabled == p_enabled) { + return; + } + enabled = p_enabled; + + // TODO: This should not require a full rebuild as the link has not really changed. + link_dirty = true; +}; + void NavLink::set_bidirectional(bool p_bidirectional) { if (bidirectional == p_bidirectional) { return; diff --git a/modules/navigation/nav_link.h b/modules/navigation/nav_link.h index 986e9943f..fdd120bf4 100644 --- a/modules/navigation/nav_link.h +++ b/modules/navigation/nav_link.h @@ -40,6 +40,7 @@ class NavLink : public NavBase { bool bidirectional; Vector3 start_position; Vector3 end_position; + bool enabled; bool link_dirty; @@ -48,6 +49,7 @@ public: type = NavigationUtilities::PathSegmentType::PATH_SEGMENT_TYPE_LINK; map = nullptr; bidirectional = true; + enabled = true; link_dirty = true; } @@ -56,6 +58,9 @@ public: return map; } + void set_enabled(bool p_enabled); + bool get_enabled() const { return enabled; } + void set_bidirectional(bool p_bidirectional); bool is_bidirectional() const { return bidirectional; diff --git a/modules/navigation/nav_map.cpp b/modules/navigation/nav_map.cpp index bd0adaa3d..225a44bc6 100644 --- a/modules/navigation/nav_map.cpp +++ b/modules/navigation/nav_map.cpp @@ -839,7 +839,13 @@ void NavMap::sync() { // Resize the polygon count. int count = 0; for (uint32_t r = 0; r < regions.size(); r++) { - count += regions[r]->get_polygons().size(); + NavRegion *region = regions[r]; + + if (!region->get_enabled()) { + continue; + } + + count += region->get_polygons().size(); } polygons.resize(count); @@ -847,12 +853,18 @@ void NavMap::sync() { // Copy all region polygons in the map. count = 0; for (uint32_t r = 0; r < regions.size(); r++) { - const LocalVector &polygons_source = regions[r]->get_polygons(); + NavRegion *region = regions[r]; + + if (!region->get_enabled()) { + continue; + } + + const LocalVector &polygons_source = region->get_polygons(); for (uint32_t n = 0; n < polygons_source.size(); n++) { polygons[count + n] = polygons_source[n]; } - count += regions[r]->get_polygons().size(); + count += region->get_polygons().size(); } _new_pm_polygon_count = polygons.size(); diff --git a/modules/navigation/nav_region.cpp b/modules/navigation/nav_region.cpp index 00f2fe011..c4b92c0e1 100644 --- a/modules/navigation/nav_region.cpp +++ b/modules/navigation/nav_region.cpp @@ -45,6 +45,16 @@ void NavRegion::set_map(NavMap *p_map) { } } +void NavRegion::set_enabled(bool p_enabled) { + if (enabled == p_enabled) { + return; + } + enabled = p_enabled; + + // TODO: This should not require a full rebuild as the region has not really changed. + polygons_dirty = true; +}; + void NavRegion::set_use_edge_connections(bool p_enabled) { if (use_edge_connections != p_enabled) { use_edge_connections = p_enabled; @@ -184,6 +194,7 @@ NavRegion::NavRegion() { enter_cost = 0.0; travel_cost = 1.0; polygons_dirty = true; + enabled = true; use_edge_connections = true; } diff --git a/modules/navigation/nav_region.h b/modules/navigation/nav_region.h index f0164847a..a66004d71 100644 --- a/modules/navigation/nav_region.h +++ b/modules/navigation/nav_region.h @@ -42,6 +42,7 @@ class NavRegion : public NavBase { Transform transform; Ref mesh; Vector connections; + bool enabled; bool use_edge_connections; @@ -55,6 +56,9 @@ public: polygons_dirty = true; } + void set_enabled(bool p_enabled); + bool get_enabled() const { return enabled; } + void set_map(NavMap *p_map); NavMap *get_map() const { return map; diff --git a/modules/navigation/pandemonium_navigation_2d_server.cpp b/modules/navigation/pandemonium_navigation_2d_server.cpp index b46f1d311..7575017c1 100644 --- a/modules/navigation/pandemonium_navigation_2d_server.cpp +++ b/modules/navigation/pandemonium_navigation_2d_server.cpp @@ -268,6 +268,8 @@ RID FORWARD_2_C(map_get_closest_point_owner, RID, p_map, const Vector2 &, p_poin RID FORWARD_0(region_create); +void FORWARD_2(region_set_enabled, RID, p_region, bool, p_enabled, rid_to_rid, bool_to_bool); +bool FORWARD_1_C(region_get_enabled, RID, p_region, rid_to_rid); void FORWARD_2(region_set_use_edge_connections, RID, p_region, bool, p_enabled, rid_to_rid, bool_to_bool); bool FORWARD_1_C(region_get_use_edge_connections, RID, p_region, rid_to_rid); @@ -296,6 +298,8 @@ RID FORWARD_0(link_create); void FORWARD_2(link_set_map, RID, p_link, RID, p_map, rid_to_rid, rid_to_rid); RID FORWARD_1_C(link_get_map, RID, p_link, rid_to_rid); +void FORWARD_2(link_set_enabled, RID, p_link, bool, p_enabled, rid_to_rid, bool_to_bool); +bool FORWARD_1_C(link_get_enabled, RID, p_link, rid_to_rid); void FORWARD_2(link_set_bidirectional, RID, p_link, bool, p_bidirectional, rid_to_rid, bool_to_bool); bool FORWARD_1_C(link_is_bidirectional, RID, p_link, rid_to_rid); void FORWARD_2(link_set_navigation_layers, RID, p_link, uint32_t, p_navigation_layers, rid_to_rid, uint32_to_uint32); diff --git a/modules/navigation/pandemonium_navigation_2d_server.h b/modules/navigation/pandemonium_navigation_2d_server.h index 832755b3b..02660a299 100644 --- a/modules/navigation/pandemonium_navigation_2d_server.h +++ b/modules/navigation/pandemonium_navigation_2d_server.h @@ -98,6 +98,9 @@ public: /// Creates a new region. virtual RID region_create(); + virtual void region_set_enabled(RID p_region, bool p_enabled); + virtual bool region_get_enabled(RID p_region) const; + virtual void region_set_use_edge_connections(RID p_region, bool p_enabled); virtual bool region_get_use_edge_connections(RID p_region) const; @@ -141,6 +144,9 @@ public: virtual void link_set_map(RID p_link, RID p_map); virtual RID link_get_map(RID p_link) const; + virtual void link_set_enabled(RID p_link, bool p_enabled); + virtual bool link_get_enabled(RID p_link) const; + /// Set whether this link travels in both directions. virtual void link_set_bidirectional(RID p_link, bool p_bidirectional); virtual bool link_is_bidirectional(RID p_link) const; diff --git a/modules/navigation/pandemonium_navigation_server.cpp b/modules/navigation/pandemonium_navigation_server.cpp index c17bc116e..08c6ec49c 100644 --- a/modules/navigation/pandemonium_navigation_server.cpp +++ b/modules/navigation/pandemonium_navigation_server.cpp @@ -388,6 +388,20 @@ RID PandemoniumNavigationServer::region_create() { return rid; } +COMMAND_2(region_set_enabled, RID, p_region, bool, p_enabled) { + NavRegion *region = region_owner.getornull(p_region); + ERR_FAIL_COND(region == nullptr); + + region->set_enabled(p_enabled); +} + +bool PandemoniumNavigationServer::region_get_enabled(RID p_region) const { + const NavRegion *region = region_owner.getornull(p_region); + ERR_FAIL_COND_V(region == nullptr, false); + + return region->get_enabled(); +} + COMMAND_2(region_set_use_edge_connections, RID, p_region, bool, p_enabled) { NavRegion *region = region_owner.getornull(p_region); ERR_FAIL_COND(region == nullptr); @@ -568,6 +582,20 @@ RID PandemoniumNavigationServer::link_get_map(const RID p_link) const { return RID(); } +COMMAND_2(link_set_enabled, RID, p_link, bool, p_enabled) { + NavLink *link = link_owner.getornull(p_link); + ERR_FAIL_COND(link == nullptr); + + link->set_enabled(p_enabled); +} + +bool PandemoniumNavigationServer::link_get_enabled(RID p_link) const { + const NavLink *link = link_owner.getornull(p_link); + ERR_FAIL_COND_V(link == nullptr, false); + + return link->get_enabled(); +} + COMMAND_2(link_set_bidirectional, RID, p_link, bool, p_bidirectional) { NavLink *link = link_owner.getornull(p_link); ERR_FAIL_COND(link == nullptr); diff --git a/modules/navigation/pandemonium_navigation_server.h b/modules/navigation/pandemonium_navigation_server.h index cd67c9d6d..1abfc82d1 100644 --- a/modules/navigation/pandemonium_navigation_server.h +++ b/modules/navigation/pandemonium_navigation_server.h @@ -137,6 +137,9 @@ public: virtual RID region_create(); + COMMAND_2(region_set_enabled, RID, p_region, bool, p_enabled); + virtual bool region_get_enabled(RID p_region) const; + COMMAND_2(region_set_use_edge_connections, RID, p_region, bool, p_enabled); virtual bool region_get_use_edge_connections(RID p_region) const; @@ -163,6 +166,8 @@ public: virtual RID link_create(); COMMAND_2(link_set_map, RID, p_link, RID, p_map); virtual RID link_get_map(RID p_link) const; + COMMAND_2(link_set_enabled, RID, p_link, bool, p_enabled); + virtual bool link_get_enabled(RID p_link) const; COMMAND_2(link_set_bidirectional, RID, p_link, bool, p_bidirectional); virtual bool link_is_bidirectional(RID p_link) const; COMMAND_2(link_set_navigation_layers, RID, p_link, uint32_t, p_navigation_layers); diff --git a/modules/navigation_dummy/dummy_navigation_2d_server.h b/modules/navigation_dummy/dummy_navigation_2d_server.h index e416fe64a..73037c3d2 100644 --- a/modules/navigation_dummy/dummy_navigation_2d_server.h +++ b/modules/navigation_dummy/dummy_navigation_2d_server.h @@ -18,8 +18,8 @@ public: virtual real_t map_get_cell_size(RID p_map) const { return 0; } virtual void map_set_cell_height(RID p_map, real_t p_cell_height) {} virtual real_t map_get_cell_height(RID p_map) const { return 0; } - void map_set_use_edge_connections(RID p_map, bool p_enabled) {} - bool map_get_use_edge_connections(RID p_map) const { return false; } + virtual void map_set_use_edge_connections(RID p_map, bool p_enabled) {} + virtual bool map_get_use_edge_connections(RID p_map) const { return false; } virtual void map_set_edge_connection_margin(RID p_map, real_t p_connection_margin) {} virtual real_t map_get_edge_connection_margin(RID p_map) const { return 0; } @@ -37,8 +37,10 @@ public: virtual void map_force_update(RID p_map) {} virtual RID region_create() { return RID(); } - void region_set_use_edge_connections(RID p_region, bool p_enabled) {} - bool region_get_use_edge_connections(RID p_region) const { return false; } + virtual void region_set_enabled(RID p_region, bool p_enabled) {} + virtual bool region_get_enabled(RID p_region) const { return false; } + virtual void region_set_use_edge_connections(RID p_region, bool p_enabled) {} + virtual bool region_get_use_edge_connections(RID p_region) const { return false; } virtual void region_set_enter_cost(RID p_region, real_t p_enter_cost) {} virtual real_t region_get_enter_cost(RID p_region) const { return 0; } virtual void region_set_travel_cost(RID p_region, real_t p_travel_cost) {} @@ -59,6 +61,8 @@ public: virtual RID link_create() { return RID(); } virtual void link_set_map(RID p_link, RID p_map) {} virtual RID link_get_map(RID p_link) const { return RID(); } + virtual void link_set_enabled(RID p_link, bool p_enabled) {} + virtual bool link_get_enabled(RID p_link) const { return false; } virtual void link_set_bidirectional(RID p_link, bool p_bidirectional) {} virtual bool link_is_bidirectional(RID p_link) const { return false; } virtual void link_set_navigation_layers(RID p_link, uint32_t p_navigation_layers) {} diff --git a/modules/navigation_dummy/dummy_navigation_server.h b/modules/navigation_dummy/dummy_navigation_server.h index e0ea11a92..c2b6e09fd 100644 --- a/modules/navigation_dummy/dummy_navigation_server.h +++ b/modules/navigation_dummy/dummy_navigation_server.h @@ -19,8 +19,8 @@ public: virtual real_t map_get_cell_size(RID p_map) const { return 0; } virtual void map_set_cell_height(RID p_map, real_t p_cell_height) {} virtual real_t map_get_cell_height(RID p_map) const { return 0; } - void map_set_use_edge_connections(RID p_map, bool p_enabled) {} - bool map_get_use_edge_connections(RID p_map) const { return false; } + virtual void map_set_use_edge_connections(RID p_map, bool p_enabled) {} + virtual bool map_get_use_edge_connections(RID p_map) const { return false; } virtual void map_set_edge_connection_margin(RID p_map, real_t p_connection_margin) {} virtual real_t map_get_edge_connection_margin(RID p_map) const { return 0; } virtual void map_set_link_connection_radius(RID p_map, real_t p_connection_radius) {} @@ -39,8 +39,10 @@ public: virtual void map_force_update(RID p_map) {} virtual RID region_create() { return RID(); } - void region_set_use_edge_connections(RID p_region, bool p_enabled) {} - bool region_get_use_edge_connections(RID p_region) const { return false; } + virtual void region_set_enabled(RID p_region, bool p_enabled) {} + virtual bool region_get_enabled(RID p_region) const { return false; } + virtual void region_set_use_edge_connections(RID p_region, bool p_enabled) {} + virtual bool region_get_use_edge_connections(RID p_region) const { return false; } virtual void region_set_enter_cost(RID p_region, real_t p_enter_cost) {} virtual real_t region_get_enter_cost(RID p_region) const { return 0; } virtual void region_set_travel_cost(RID p_region, real_t p_travel_cost) {} @@ -61,6 +63,8 @@ public: virtual RID link_create() { return RID(); } virtual void link_set_map(RID p_link, RID p_map) {} virtual RID link_get_map(RID p_link) const { return RID(); } + virtual void link_set_enabled(RID p_link, bool p_enabled) {} + virtual bool link_get_enabled(RID p_link) const { return false; } virtual void link_set_bidirectional(RID p_link, bool p_bidirectional) {} virtual bool link_is_bidirectional(RID p_link) const { return false; } virtual void link_set_navigation_layers(RID p_link, uint32_t p_navigation_layers) {} diff --git a/scene/2d/navigation_link_2d.cpp b/scene/2d/navigation_link_2d.cpp index 33cc65dcc..0667edc3d 100644 --- a/scene/2d/navigation_link_2d.cpp +++ b/scene/2d/navigation_link_2d.cpp @@ -157,15 +157,7 @@ void NavigationLink2D::set_enabled(bool p_enabled) { enabled = p_enabled; - if (!is_inside_tree()) { - return; - } - - if (!enabled) { - Navigation2DServer::get_singleton()->link_set_map(link, RID()); - } else { - Navigation2DServer::get_singleton()->link_set_map(link, get_world_2d()->get_navigation_map()); - } + Navigation2DServer::get_singleton()->link_set_enabled(link, enabled); #ifdef DEBUG_ENABLED if (Engine::get_singleton()->is_editor_hint() || Navigation2DServer::get_singleton()->get_debug_navigation_enabled()) { diff --git a/scene/2d/navigation_polygon_instance.cpp b/scene/2d/navigation_polygon_instance.cpp index 2e858d4e4..f6a4e5d5c 100644 --- a/scene/2d/navigation_polygon_instance.cpp +++ b/scene/2d/navigation_polygon_instance.cpp @@ -54,9 +54,7 @@ void NavigationPolygonInstance::set_enabled(bool p_enabled) { } enabled = p_enabled; - if (!is_inside_tree()) { - return; - } + Navigation2DServer::get_singleton()->region_set_enabled(region, enabled); if (!enabled) { Navigation2DServer::get_singleton()->region_set_map(region, RID()); diff --git a/scene/3d/navigation_link_3d.cpp b/scene/3d/navigation_link_3d.cpp index e5b78a1da..4ac964e7f 100644 --- a/scene/3d/navigation_link_3d.cpp +++ b/scene/3d/navigation_link_3d.cpp @@ -31,9 +31,9 @@ #include "navigation_link_3d.h" #include "core/config/engine.h" +#include "mesh_instance.h" #include "scene/resources/mesh.h" #include "scene/resources/world_3d.h" -#include "mesh_instance.h" #include "servers/navigation_server.h" #ifdef DEBUG_ENABLED @@ -268,15 +268,7 @@ void NavigationLink3D::set_enabled(bool p_enabled) { enabled = p_enabled; - if (!is_inside_tree()) { - return; - } - - if (enabled) { - NavigationServer::get_singleton()->link_set_map(link, get_world_3d()->get_navigation_map()); - } else { - NavigationServer::get_singleton()->link_set_map(link, RID()); - } + NavigationServer::get_singleton()->link_set_enabled(link, enabled); #ifdef DEBUG_ENABLED if (debug_instance.is_valid() && debug_mesh.is_valid()) { diff --git a/scene/3d/navigation_mesh_instance.cpp b/scene/3d/navigation_mesh_instance.cpp index 917baefb3..309576c55 100644 --- a/scene/3d/navigation_mesh_instance.cpp +++ b/scene/3d/navigation_mesh_instance.cpp @@ -47,23 +47,7 @@ void NavigationMeshInstance::set_enabled(bool p_enabled) { } enabled = p_enabled; - if (!is_inside_tree()) { - return; - } - - if (!enabled) { - NavigationServer::get_singleton()->region_set_map(region, RID()); - } else { - if (navigation) { - NavigationServer::get_singleton()->region_set_map(region, navigation->get_rid()); - } else { - if (map_override.is_valid()) { - NavigationServer::get_singleton()->region_set_map(region, map_override); - } else { - NavigationServer::get_singleton()->region_set_map(region, get_world_3d()->get_navigation_map()); - } - } - } + NavigationServer::get_singleton()->region_set_enabled(region, enabled); #ifdef DEBUG_ENABLED if (debug_instance.is_valid()) { diff --git a/servers/navigation_2d_server.cpp b/servers/navigation_2d_server.cpp index 8c3a924e2..40dd6eed7 100644 --- a/servers/navigation_2d_server.cpp +++ b/servers/navigation_2d_server.cpp @@ -64,6 +64,8 @@ void Navigation2DServer::_bind_methods() { ClassDB::bind_method(D_METHOD("map_force_update", "map"), &Navigation2DServer::map_force_update); ClassDB::bind_method(D_METHOD("region_create"), &Navigation2DServer::region_create); + ClassDB::bind_method(D_METHOD("region_set_enabled", "region", "enabled"), &Navigation2DServer::region_set_enabled); + ClassDB::bind_method(D_METHOD("region_get_enabled", "region"), &Navigation2DServer::region_get_enabled); ClassDB::bind_method(D_METHOD("region_set_use_edge_connections", "region", "enabled"), &Navigation2DServer::region_set_use_edge_connections); ClassDB::bind_method(D_METHOD("region_get_use_edge_connections", "region"), &Navigation2DServer::region_get_use_edge_connections); ClassDB::bind_method(D_METHOD("region_set_enter_cost", "region", "enter_cost"), &Navigation2DServer::region_set_enter_cost); @@ -86,6 +88,8 @@ void Navigation2DServer::_bind_methods() { ClassDB::bind_method(D_METHOD("link_create"), &Navigation2DServer::link_create); ClassDB::bind_method(D_METHOD("link_set_map", "link", "map"), &Navigation2DServer::link_set_map); ClassDB::bind_method(D_METHOD("link_get_map", "link"), &Navigation2DServer::link_get_map); + ClassDB::bind_method(D_METHOD("link_set_enabled", "link", "enabled"), &Navigation2DServer::link_set_enabled); + ClassDB::bind_method(D_METHOD("link_get_enabled", "link"), &Navigation2DServer::link_get_enabled); ClassDB::bind_method(D_METHOD("link_set_bidirectional", "link", "bidirectional"), &Navigation2DServer::link_set_bidirectional); ClassDB::bind_method(D_METHOD("link_is_bidirectional", "link"), &Navigation2DServer::link_is_bidirectional); ClassDB::bind_method(D_METHOD("link_set_navigation_layers", "link", "navigation_layers"), &Navigation2DServer::link_set_navigation_layers); diff --git a/servers/navigation_2d_server.h b/servers/navigation_2d_server.h index c3577e11f..994b57e6d 100644 --- a/servers/navigation_2d_server.h +++ b/servers/navigation_2d_server.h @@ -105,6 +105,9 @@ public: /// Creates a new region. virtual RID region_create() = 0; + virtual void region_set_enabled(RID p_region, bool p_enabled) = 0; + virtual bool region_get_enabled(RID p_region) const = 0; + virtual void region_set_use_edge_connections(RID p_region, bool p_enabled) = 0; virtual bool region_get_use_edge_connections(RID p_region) const = 0; @@ -148,6 +151,9 @@ public: virtual void link_set_map(RID p_link, RID p_map) = 0; virtual RID link_get_map(RID p_link) const = 0; + virtual void link_set_enabled(RID p_link, bool p_enabled) = 0; + virtual bool link_get_enabled(RID p_link) const = 0; + /// Set whether this link travels in both directions. virtual void link_set_bidirectional(RID p_link, bool p_bidirectional) = 0; virtual bool link_is_bidirectional(RID p_link) const = 0; diff --git a/servers/navigation_server.cpp b/servers/navigation_server.cpp index 150ec62f0..362b9692f 100644 --- a/servers/navigation_server.cpp +++ b/servers/navigation_server.cpp @@ -83,6 +83,7 @@ void NavigationServer::_bind_methods() { ClassDB::bind_method(D_METHOD("query_path", "parameters", "result"), &NavigationServer::query_path); ClassDB::bind_method(D_METHOD("region_create"), &NavigationServer::region_create); + ClassDB::bind_method(D_METHOD("region_set_enabled", "region", "enabled"), &NavigationServer::region_set_enabled); ClassDB::bind_method(D_METHOD("region_set_use_edge_connections", "region", "enabled"), &NavigationServer::region_set_use_edge_connections); ClassDB::bind_method(D_METHOD("region_get_use_edge_connections", "region"), &NavigationServer::region_get_use_edge_connections); ClassDB::bind_method(D_METHOD("region_set_enter_cost", "region", "enter_cost"), &NavigationServer::region_set_enter_cost); @@ -108,6 +109,8 @@ void NavigationServer::_bind_methods() { ClassDB::bind_method(D_METHOD("link_create"), &NavigationServer::link_create); ClassDB::bind_method(D_METHOD("link_set_map", "link", "map"), &NavigationServer::link_set_map); ClassDB::bind_method(D_METHOD("link_get_map", "link"), &NavigationServer::link_get_map); + ClassDB::bind_method(D_METHOD("link_set_enabled", "link", "enabled"), &NavigationServer::link_set_enabled); + ClassDB::bind_method(D_METHOD("link_get_enabled", "link"), &NavigationServer::link_get_enabled); ClassDB::bind_method(D_METHOD("link_set_bidirectional", "link", "bidirectional"), &NavigationServer::link_set_bidirectional); ClassDB::bind_method(D_METHOD("link_is_bidirectional", "link"), &NavigationServer::link_is_bidirectional); ClassDB::bind_method(D_METHOD("link_set_navigation_layers", "link", "navigation_layers"), &NavigationServer::link_set_navigation_layers); diff --git a/servers/navigation_server.h b/servers/navigation_server.h index 821f6f78d..592145e8e 100644 --- a/servers/navigation_server.h +++ b/servers/navigation_server.h @@ -121,6 +121,9 @@ public: /// Creates a new region. virtual RID region_create() = 0; + virtual void region_set_enabled(RID p_region, bool p_enabled) = 0; + virtual bool region_get_enabled(RID p_region) const = 0; + virtual void region_set_use_edge_connections(RID p_region, bool p_enabled) = 0; virtual bool region_get_use_edge_connections(RID p_region) const = 0; @@ -164,6 +167,9 @@ public: virtual void link_set_map(RID p_link, RID p_map) = 0; virtual RID link_get_map(RID p_link) const = 0; + virtual void link_set_enabled(RID p_link, bool p_enabled) = 0; + virtual bool link_get_enabled(RID p_link) const = 0; + /// Set whether this link travels in both directions. virtual void link_set_bidirectional(RID p_link, bool p_bidirectional) = 0; virtual bool link_is_bidirectional(RID p_link) const = 0;