From aeb4d3fbe28892d2902ef5c40dfb93eec524e4f3 Mon Sep 17 00:00:00 2001 From: Relintai Date: Mon, 4 Sep 2023 19:04:29 +0200 Subject: [PATCH] Backported from godot4: Add agent pause mode to NavigationServer Adds agent pause mode to NavigationServer. - smix8 https://github.com/godotengine/godot/commit/ae9dd47d0c1c237d0733439862aa5ff651dcac2 --- doc/classes/Navigation2DServer.xml | 30 +++++++++++++++++++ doc/classes/NavigationServer.xml | 30 +++++++++++++++++++ modules/navigation/nav_agent.cpp | 21 +++++++++++++ modules/navigation/nav_agent.h | 4 +++ modules/navigation/nav_map.cpp | 11 +++++++ modules/navigation/nav_obstacle.cpp | 22 ++++++++++++++ modules/navigation/nav_obstacle.h | 6 +++- .../pandemonium_navigation_2d_server.cpp | 5 ++++ .../pandemonium_navigation_2d_server.h | 7 +++++ .../pandemonium_navigation_server.cpp | 28 +++++++++++++++++ .../pandemonium_navigation_server.h | 6 +++- .../dummy_navigation_2d_server.h | 4 +++ .../dummy_navigation_server.h | 4 +++ scene/2d/navigation_agent_2d.cpp | 16 +++------- scene/2d/navigation_agent_2d.h | 1 - scene/2d/navigation_obstacle_2d.cpp | 2 ++ scene/3d/navigation_agent.cpp | 16 +++------- scene/3d/navigation_agent.h | 1 - scene/3d/navigation_obstacle.cpp | 2 ++ servers/navigation_2d_server.cpp | 4 +++ servers/navigation_2d_server.h | 7 +++++ servers/navigation_server.cpp | 6 +++- servers/navigation_server.h | 7 +++++ 23 files changed, 211 insertions(+), 29 deletions(-) diff --git a/doc/classes/Navigation2DServer.xml b/doc/classes/Navigation2DServer.xml index 6c7d57af4..8b579923e 100644 --- a/doc/classes/Navigation2DServer.xml +++ b/doc/classes/Navigation2DServer.xml @@ -37,6 +37,13 @@ Returns the navigation map [RID] the requested [code]agent[/code] is currently assigned to. + + + + + Returns [code]true[/code] if the specified [param agent] is paused. + + @@ -120,6 +127,14 @@ Sets the maximum distance to other agents this agent takes into account in the navigation. The larger this number, the longer the running time of the simulation. If the number is too low, the simulation will not be safe. + + + + + + If [param paused] is true the specified [param agent] will not be processed, e.g. calculate avoidance velocities or receive avoidance callbacks. + + @@ -487,6 +502,13 @@ Returns the navigation map [RID] the requested [param obstacle] is currently assigned to. + + + + + Returns [code]true[/code] if the specified [param obstacle] is paused. + + @@ -502,6 +524,14 @@ Sets the navigation map [RID] for the obstacle. + + + + + + If [param paused] is true the specified [param obstacle] will not be processed, e.g. affect avoidance velocities. + + diff --git a/doc/classes/NavigationServer.xml b/doc/classes/NavigationServer.xml index e50559095..05250d8f4 100644 --- a/doc/classes/NavigationServer.xml +++ b/doc/classes/NavigationServer.xml @@ -37,6 +37,13 @@ Returns the navigation map [RID] the requested [code]agent[/code] is currently assigned to. + + + + + Returns [code]true[/code] if the specified [param agent] is paused. + + @@ -135,6 +142,14 @@ Sets the maximum distance to other agents this agent takes into account in the navigation. The larger this number, the longer the running time of the simulation. If the number is too low, the simulation will not be safe. + + + + + + If [param paused] is true the specified [param agent] will not be processed, e.g. calculate avoidance velocities or receive avoidance callbacks. + + @@ -551,6 +566,13 @@ Returns the navigation map [RID] the requested [param obstacle] is currently assigned to. + + + + + Returns [code]true[/code] if the specified [param obstacle] is paused. + + @@ -575,6 +597,14 @@ Assigns the [param obstacle] to a navigation map. + + + + + + If [param paused] is true the specified [param obstacle] will not be processed, e.g. affect avoidance velocities. + + diff --git a/modules/navigation/nav_agent.cpp b/modules/navigation/nav_agent.cpp index 3447a0398..8e45ef244 100644 --- a/modules/navigation/nav_agent.cpp +++ b/modules/navigation/nav_agent.cpp @@ -55,6 +55,7 @@ NavAgent::NavAgent() { agent_dirty = true; map_update_id = 0; + paused = false; } void NavAgent::set_avoidance_enabled(bool p_enabled) { @@ -331,6 +332,26 @@ const Dictionary NavAgent::get_avoidance_data() const { return _avoidance_data; } +void NavAgent::set_paused(bool p_paused) { + if (paused == p_paused) { + return; + } + + paused = p_paused; + + if (map) { + if (paused) { + map->remove_agent_as_controlled(this); + } else { + map->set_agent_as_controlled(this); + } + } +} + +bool NavAgent::get_paused() const { + return paused; +} + void NavAgent::set_avoidance_callback(ObjectID p_id, const StringName p_method, const Variant p_udata) { avoidance_callback.id = p_id; avoidance_callback.method = p_method; diff --git a/modules/navigation/nav_agent.h b/modules/navigation/nav_agent.h index 0027de626..3c5b5d4e5 100644 --- a/modules/navigation/nav_agent.h +++ b/modules/navigation/nav_agent.h @@ -80,6 +80,7 @@ class NavAgent : public NavRid { bool agent_dirty; uint32_t map_update_id; + bool paused; public: NavAgent(); @@ -140,6 +141,9 @@ public: void set_avoidance_priority(real_t p_priority); real_t get_avoidance_priority() const { return avoidance_priority; }; + void set_paused(bool p_paused); + bool get_paused() const; + bool check_dirty(); // Updates this agent with rvo data after the rvo simulation avoidance step. diff --git a/modules/navigation/nav_map.cpp b/modules/navigation/nav_map.cpp index ed0f50c57..bd0adaa3d 100644 --- a/modules/navigation/nav_map.cpp +++ b/modules/navigation/nav_map.cpp @@ -738,6 +738,11 @@ bool NavMap::has_obstacle(NavObstacle *obstacle) const { } void NavMap::add_obstacle(NavObstacle *obstacle) { + if (obstacle->get_paused()) { + // No point in adding a paused obstacle, it will add itself when unpaused again. + return; + } + if (!has_obstacle(obstacle)) { obstacles.push_back(obstacle); obstacles_dirty = true; @@ -754,6 +759,12 @@ void NavMap::remove_obstacle(NavObstacle *obstacle) { void NavMap::set_agent_as_controlled(NavAgent *agent) { remove_agent_as_controlled(agent); + + if (agent->get_paused()) { + // No point in adding a paused agent, it will add itself when unpaused again. + return; + } + if (agent->get_use_3d_avoidance()) { int64_t agent_3d_index = active_3d_avoidance_agents.find(agent); if (agent_3d_index < 0) { diff --git a/modules/navigation/nav_obstacle.cpp b/modules/navigation/nav_obstacle.cpp index 558933075..e69d7697f 100644 --- a/modules/navigation/nav_obstacle.cpp +++ b/modules/navigation/nav_obstacle.cpp @@ -38,6 +38,7 @@ NavObstacle::NavObstacle() { avoidance_layers = 1; obstacle_dirty = true; map_update_id = 0; + paused = false; } NavObstacle::~NavObstacle() {} @@ -88,3 +89,24 @@ bool NavObstacle::check_dirty() { obstacle_dirty = false; return was_dirty; } + +void NavObstacle::set_paused(bool p_paused) { + if (paused == p_paused) { + return; + } + + paused = p_paused; + + if (map) { + if (paused) { + map->remove_obstacle(this); + } else { + map->add_obstacle(this); + } + } + //internal_update_agent(); +} + +bool NavObstacle::get_paused() const { + return paused; +} \ No newline at end of file diff --git a/modules/navigation/nav_obstacle.h b/modules/navigation/nav_obstacle.h index 1e01ab2f9..cfd868fd3 100644 --- a/modules/navigation/nav_obstacle.h +++ b/modules/navigation/nav_obstacle.h @@ -32,8 +32,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ -#include "core/object/class_db.h" #include "core/containers/local_vector.h" +#include "core/object/class_db.h" #include "nav_agent.h" #include "nav_rid.h" @@ -51,6 +51,7 @@ class NavObstacle : public NavRid { bool obstacle_dirty; uint32_t map_update_id; + bool paused; public: NavObstacle(); @@ -73,6 +74,9 @@ public: void set_avoidance_layers(uint32_t p_layers); uint32_t get_avoidance_layers() const { return avoidance_layers; }; + void set_paused(bool p_paused); + bool get_paused() const; + bool check_dirty(); }; diff --git a/modules/navigation/pandemonium_navigation_2d_server.cpp b/modules/navigation/pandemonium_navigation_2d_server.cpp index bff9bae0f..e823cb227 100644 --- a/modules/navigation/pandemonium_navigation_2d_server.cpp +++ b/modules/navigation/pandemonium_navigation_2d_server.cpp @@ -342,6 +342,9 @@ void FORWARD_2(agent_set_position, RID, p_agent, Vector2, p_position, rid_to_rid bool FORWARD_1_C(agent_is_map_changed, RID, p_agent, rid_to_rid); +void FORWARD_2(agent_set_paused, RID, p_agent, bool, p_paused, rid_to_rid, bool_to_bool); +bool FORWARD_1_C(agent_get_paused, RID, p_agent, rid_to_rid); + void FORWARD_1(free, RID, p_object, rid_to_rid); void FORWARD_4(agent_set_avoidance_callback, RID, p_agent, ObjectID, p_object_id, StringName, p_method, Variant, p_udata, rid_to_rid, id_to_id, sn_to_sn, var_to_var); @@ -356,6 +359,8 @@ RID PandemoniumNavigation2DServer::obstacle_create() { } void FORWARD_2(obstacle_set_map, RID, p_obstacle, RID, p_map, rid_to_rid, rid_to_rid); RID FORWARD_1_C(obstacle_get_map, RID, p_obstacle, rid_to_rid); +void FORWARD_2(obstacle_set_paused, RID, p_obstacle, bool, p_paused, rid_to_rid, bool_to_bool); +bool FORWARD_1_C(obstacle_get_paused, RID, p_obstacle, rid_to_rid); void FORWARD_2(obstacle_set_position, RID, p_obstacle, Vector2, p_position, rid_to_rid, v2_to_v3); void FORWARD_2(obstacle_set_avoidance_layers, RID, p_obstacle, uint32_t, p_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 74c41f2c0..4e3c781d7 100644 --- a/modules/navigation/pandemonium_navigation_2d_server.h +++ b/modules/navigation/pandemonium_navigation_2d_server.h @@ -176,6 +176,9 @@ public: virtual void agent_set_map(RID p_agent, RID p_map); virtual RID agent_get_map(RID p_agent) const; + virtual void agent_set_paused(RID p_agent, bool p_paused); + virtual bool agent_get_paused(RID p_agent) const; + virtual void agent_set_avoidance_enabled(RID p_agent, bool p_enabled); virtual bool agent_get_avoidance_enabled(RID p_agent) const; @@ -239,6 +242,10 @@ public: virtual RID obstacle_create(); virtual void obstacle_set_map(RID p_obstacle, RID p_map); virtual RID obstacle_get_map(RID p_obstacle) const; + + virtual void obstacle_set_paused(RID p_obstacle, bool p_paused); + virtual bool obstacle_get_paused(RID p_obstacle) const; + virtual void obstacle_set_position(RID p_obstacle, Vector2 p_position); virtual void obstacle_set_vertices(RID p_obstacle, const Vector &p_vertices); virtual void obstacle_set_avoidance_layers(RID p_obstacle, uint32_t p_layers); diff --git a/modules/navigation/pandemonium_navigation_server.cpp b/modules/navigation/pandemonium_navigation_server.cpp index 19088d537..ceeecf09c 100644 --- a/modules/navigation/pandemonium_navigation_server.cpp +++ b/modules/navigation/pandemonium_navigation_server.cpp @@ -730,6 +730,20 @@ COMMAND_2(agent_set_map, RID, p_agent, RID, p_map) { } } +COMMAND_2(agent_set_paused, RID, p_agent, bool, p_paused) { + NavAgent *agent = agent_owner.getornull(p_agent); + ERR_FAIL_COND(agent == nullptr); + + agent->set_paused(p_paused); +} + +bool PandemoniumNavigationServer::agent_get_paused(RID p_agent) const { + NavAgent *agent = agent_owner.getornull(p_agent); + ERR_FAIL_COND_V(agent == nullptr, false); + + return agent->get_paused(); +} + COMMAND_2(agent_set_neighbor_distance, RID, p_agent, real_t, p_dist) { NavAgent *agent = agent_owner.getornull(p_agent); ERR_FAIL_COND(agent == nullptr); @@ -888,6 +902,20 @@ RID PandemoniumNavigationServer::obstacle_get_map(RID p_obstacle) const { return RID(); } +COMMAND_2(obstacle_set_paused, RID, p_obstacle, bool, p_paused) { + NavObstacle *obstacle = obstacle_owner.getornull(p_obstacle); + ERR_FAIL_COND(obstacle == nullptr); + + obstacle->set_paused(p_paused); +} + +bool PandemoniumNavigationServer::obstacle_get_paused(RID p_obstacle) const { + NavObstacle *obstacle = obstacle_owner.getornull(p_obstacle); + ERR_FAIL_COND_V(obstacle == nullptr, false); + + return obstacle->get_paused(); +} + COMMAND_2(obstacle_set_height, RID, p_obstacle, real_t, p_height) { NavObstacle *obstacle = obstacle_owner.getornull(p_obstacle); ERR_FAIL_COND(obstacle == nullptr); diff --git a/modules/navigation/pandemonium_navigation_server.h b/modules/navigation/pandemonium_navigation_server.h index 5f3d891c0..1b53c8808 100644 --- a/modules/navigation/pandemonium_navigation_server.h +++ b/modules/navigation/pandemonium_navigation_server.h @@ -37,8 +37,8 @@ #include "nav_agent.h" #include "nav_link.h" #include "nav_map.h" -#include "nav_region.h" #include "nav_obstacle.h" +#include "nav_region.h" /// The commands are functions executed during the `sync` phase. @@ -185,6 +185,8 @@ public: virtual bool agent_get_use_3d_avoidance(RID p_agent) const; COMMAND_2(agent_set_map, RID, p_agent, RID, p_map); virtual RID agent_get_map(RID p_agent) const; + COMMAND_2(agent_set_paused, RID, p_agent, bool, p_paused); + virtual bool agent_get_paused(RID p_agent) const; COMMAND_2(agent_set_neighbor_distance, RID, p_agent, real_t, p_dist); COMMAND_2(agent_set_max_neighbors, RID, p_agent, int, p_count); COMMAND_2(agent_set_time_horizon_agents, RID, p_agent, real_t, p_time_horizon); @@ -205,6 +207,8 @@ public: virtual RID obstacle_create(); COMMAND_2(obstacle_set_map, RID, p_obstacle, RID, p_map); virtual RID obstacle_get_map(RID p_obstacle) const; + COMMAND_2(obstacle_set_paused, RID, p_obstacle, bool, p_paused); + virtual bool obstacle_get_paused(RID p_obstacle) const; COMMAND_2(obstacle_set_position, RID, p_obstacle, Vector3, p_position); COMMAND_2(obstacle_set_height, RID, p_obstacle, real_t, p_height); virtual void obstacle_set_vertices(RID p_obstacle, const Vector &p_vertices); diff --git a/modules/navigation_dummy/dummy_navigation_2d_server.h b/modules/navigation_dummy/dummy_navigation_2d_server.h index d81e0a3f9..d397ac617 100644 --- a/modules/navigation_dummy/dummy_navigation_2d_server.h +++ b/modules/navigation_dummy/dummy_navigation_2d_server.h @@ -77,6 +77,8 @@ public: virtual RID agent_create() { return RID(); } virtual void agent_set_map(RID p_agent, RID p_map) {} virtual RID agent_get_map(RID p_agent) const { return RID(); } + virtual void agent_set_paused(RID p_agent, bool p_paused) {} + virtual bool agent_get_paused(RID p_agent) const { return false; } virtual void agent_set_avoidance_enabled(RID p_agent, bool p_enabled) {} virtual bool agent_get_avoidance_enabled(RID p_agent) const { return false; } virtual void agent_set_neighbor_distance(RID p_agent, real_t p_dist) {} @@ -99,6 +101,8 @@ public: virtual RID obstacle_create() { return RID(); } virtual void obstacle_set_map(RID p_obstacle, RID p_map) {} virtual RID obstacle_get_map(RID p_obstacle) const { return RID(); } + virtual void obstacle_set_paused(RID p_obstacle, bool p_paused) {} + virtual bool obstacle_get_paused(RID p_obstacle) const { return false; } virtual void obstacle_set_position(RID p_obstacle, Vector2 p_position) {} virtual void obstacle_set_vertices(RID p_obstacle, const Vector &p_vertices) {} virtual void obstacle_set_avoidance_layers(RID p_obstacle, uint32_t p_layers) {} diff --git a/modules/navigation_dummy/dummy_navigation_server.h b/modules/navigation_dummy/dummy_navigation_server.h index 47e047076..2f8747a7a 100644 --- a/modules/navigation_dummy/dummy_navigation_server.h +++ b/modules/navigation_dummy/dummy_navigation_server.h @@ -79,6 +79,8 @@ public: virtual RID agent_create() { return RID(); } virtual void agent_set_map(RID p_agent, RID p_map) {} virtual RID agent_get_map(RID p_agent) const { return RID(); } + virtual void agent_set_paused(RID p_agent, bool p_paused) {} + virtual bool agent_get_paused(RID p_agent) const { return false; } virtual void agent_set_avoidance_enabled(RID p_agent, bool p_enabled) {} virtual bool agent_get_avoidance_enabled(RID p_agent) const { return false; } virtual void agent_set_use_3d_avoidance(RID p_agent, bool p_enabled) {} @@ -103,6 +105,8 @@ public: virtual RID obstacle_create() { return RID(); } virtual void obstacle_set_map(RID p_obstacle, RID p_map) {} virtual RID obstacle_get_map(RID p_obstacle) const { return RID(); } + virtual void obstacle_set_paused(RID p_obstacle, bool p_paused) {} + virtual bool obstacle_get_paused(RID p_obstacle) const { return false; } virtual void obstacle_set_height(RID p_obstacle, real_t p_height) {} virtual void obstacle_set_position(RID p_obstacle, Vector3 p_position) {} virtual void obstacle_set_vertices(RID p_obstacle, const Vector &p_vertices) {} diff --git a/scene/2d/navigation_agent_2d.cpp b/scene/2d/navigation_agent_2d.cpp index f6029ef68..c69839603 100644 --- a/scene/2d/navigation_agent_2d.cpp +++ b/scene/2d/navigation_agent_2d.cpp @@ -226,21 +226,13 @@ void NavigationAgent2D::_notification(int p_what) { set_physics_process_internal(false); } break; case NOTIFICATION_PAUSED: { - if (agent_parent && !agent_parent->can_process()) { - map_before_pause = Navigation2DServer::get_singleton()->agent_get_map(get_rid()); - Navigation2DServer::get_singleton()->agent_set_map(get_rid(), RID()); - } else if (agent_parent && agent_parent->can_process() && !(map_before_pause == RID())) { - Navigation2DServer::get_singleton()->agent_set_map(get_rid(), map_before_pause); - map_before_pause = RID(); + if (agent_parent) { + Navigation2DServer::get_singleton()->agent_set_paused(get_rid(), !agent_parent->can_process()); } } break; case NOTIFICATION_UNPAUSED: { - if (agent_parent && !agent_parent->can_process()) { - map_before_pause = Navigation2DServer::get_singleton()->agent_get_map(get_rid()); - Navigation2DServer::get_singleton()->agent_set_map(get_rid(), RID()); - } else if (agent_parent && agent_parent->can_process() && !(map_before_pause == RID())) { - Navigation2DServer::get_singleton()->agent_set_map(get_rid(), map_before_pause); - map_before_pause = RID(); + if (agent_parent) { + Navigation2DServer::get_singleton()->agent_set_paused(get_rid(), !agent_parent->can_process()); } } break; case NOTIFICATION_EXIT_TREE: { diff --git a/scene/2d/navigation_agent_2d.h b/scene/2d/navigation_agent_2d.h index 6470c3c2c..bfd6d8aff 100644 --- a/scene/2d/navigation_agent_2d.h +++ b/scene/2d/navigation_agent_2d.h @@ -46,7 +46,6 @@ class NavigationAgent2D : public Node { Navigation2D *navigation; RID agent; - RID map_before_pause; RID map_override; bool avoidance_enabled; diff --git a/scene/2d/navigation_obstacle_2d.cpp b/scene/2d/navigation_obstacle_2d.cpp index cccc540aa..f7c43f9d9 100644 --- a/scene/2d/navigation_obstacle_2d.cpp +++ b/scene/2d/navigation_obstacle_2d.cpp @@ -112,6 +112,7 @@ void NavigationObstacle2D::_notification(int p_what) { _update_map(map_before_pause); map_before_pause = RID(); } + Navigation2DServer::get_singleton()->obstacle_set_paused(obstacle, !can_process()); } break; case NOTIFICATION_UNPAUSED: { if (!can_process()) { @@ -121,6 +122,7 @@ void NavigationObstacle2D::_notification(int p_what) { _update_map(map_before_pause); map_before_pause = RID(); } + Navigation2DServer::get_singleton()->obstacle_set_paused(obstacle, !can_process()); } break; case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { if (is_inside_tree()) { diff --git a/scene/3d/navigation_agent.cpp b/scene/3d/navigation_agent.cpp index 01b0b8c7b..1c5b762de 100644 --- a/scene/3d/navigation_agent.cpp +++ b/scene/3d/navigation_agent.cpp @@ -249,21 +249,13 @@ void NavigationAgent::_notification(int p_what) { #endif // DEBUG_ENABLED } break; case NOTIFICATION_PAUSED: { - if (agent_parent && !agent_parent->can_process()) { - map_before_pause = NavigationServer::get_singleton()->agent_get_map(get_rid()); - NavigationServer::get_singleton()->agent_set_map(get_rid(), RID()); - } else if (agent_parent && agent_parent->can_process() && !(map_before_pause == RID())) { - NavigationServer::get_singleton()->agent_set_map(get_rid(), map_before_pause); - map_before_pause = RID(); + if (agent_parent) { + NavigationServer::get_singleton()->agent_set_paused(get_rid(), !agent_parent->can_process()); } } break; case NOTIFICATION_UNPAUSED: { - if (agent_parent && !agent_parent->can_process()) { - map_before_pause = NavigationServer::get_singleton()->agent_get_map(get_rid()); - NavigationServer::get_singleton()->agent_set_map(get_rid(), RID()); - } else if (agent_parent && agent_parent->can_process() && !(map_before_pause == RID())) { - NavigationServer::get_singleton()->agent_set_map(get_rid(), map_before_pause); - map_before_pause = RID(); + if (agent_parent) { + NavigationServer::get_singleton()->agent_set_paused(get_rid(), !agent_parent->can_process()); } } break; case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: { diff --git a/scene/3d/navigation_agent.h b/scene/3d/navigation_agent.h index 0d79a86c5..ff97a9d25 100644 --- a/scene/3d/navigation_agent.h +++ b/scene/3d/navigation_agent.h @@ -49,7 +49,6 @@ class NavigationAgent : public Node { Navigation *navigation; RID agent; - RID map_before_pause; RID map_override; bool avoidance_enabled; diff --git a/scene/3d/navigation_obstacle.cpp b/scene/3d/navigation_obstacle.cpp index 0f32bcedb..1ad10b4ee 100644 --- a/scene/3d/navigation_obstacle.cpp +++ b/scene/3d/navigation_obstacle.cpp @@ -131,6 +131,7 @@ void NavigationObstacle::_notification(int p_what) { _update_map(map_before_pause); map_before_pause = RID(); } + NavigationServer::get_singleton()->obstacle_set_paused(obstacle, !can_process()); } break; case NOTIFICATION_UNPAUSED: { if (!can_process()) { @@ -140,6 +141,7 @@ void NavigationObstacle::_notification(int p_what) { _update_map(map_before_pause); map_before_pause = RID(); } + NavigationServer::get_singleton()->obstacle_set_paused(obstacle, !can_process()); } break; case NOTIFICATION_EXIT_TREE: { set_navigation(nullptr); diff --git a/servers/navigation_2d_server.cpp b/servers/navigation_2d_server.cpp index 083264112..087c73687 100644 --- a/servers/navigation_2d_server.cpp +++ b/servers/navigation_2d_server.cpp @@ -106,6 +106,8 @@ void Navigation2DServer::_bind_methods() { ClassDB::bind_method(D_METHOD("agent_get_avoidance_enabled", "agent"), &Navigation2DServer::agent_get_avoidance_enabled); ClassDB::bind_method(D_METHOD("agent_set_map", "agent", "map"), &Navigation2DServer::agent_set_map); ClassDB::bind_method(D_METHOD("agent_get_map", "agent"), &Navigation2DServer::agent_get_map); + ClassDB::bind_method(D_METHOD("agent_set_paused", "agent", "paused"), &Navigation2DServer::agent_set_paused); + ClassDB::bind_method(D_METHOD("agent_get_paused", "agent"), &Navigation2DServer::agent_get_paused); ClassDB::bind_method(D_METHOD("agent_set_neighbor_distance", "agent", "dist"), &Navigation2DServer::agent_set_neighbor_distance); ClassDB::bind_method(D_METHOD("agent_set_max_neighbors", "agent", "count"), &Navigation2DServer::agent_set_max_neighbors); ClassDB::bind_method(D_METHOD("agent_set_time_horizon_agents", "agent", "time_horizon"), &Navigation2DServer::agent_set_time_horizon_agents); @@ -124,6 +126,8 @@ void Navigation2DServer::_bind_methods() { ClassDB::bind_method(D_METHOD("obstacle_create"), &Navigation2DServer::obstacle_create); ClassDB::bind_method(D_METHOD("obstacle_set_map", "obstacle", "map"), &Navigation2DServer::obstacle_set_map); ClassDB::bind_method(D_METHOD("obstacle_get_map", "obstacle"), &Navigation2DServer::obstacle_get_map); + ClassDB::bind_method(D_METHOD("obstacle_set_paused", "obstacle", "paused"), &Navigation2DServer::obstacle_set_paused); + ClassDB::bind_method(D_METHOD("obstacle_get_paused", "obstacle"), &Navigation2DServer::obstacle_get_paused); ClassDB::bind_method(D_METHOD("obstacle_set_position", "obstacle", "position"), &Navigation2DServer::obstacle_set_position); ClassDB::bind_method(D_METHOD("obstacle_set_vertices", "obstacle", "vertices"), &Navigation2DServer::obstacle_set_vertices); ClassDB::bind_method(D_METHOD("obstacle_set_avoidance_layers", "obstacle", "layers"), &Navigation2DServer::obstacle_set_avoidance_layers); diff --git a/servers/navigation_2d_server.h b/servers/navigation_2d_server.h index 40be2a391..8a01e090a 100644 --- a/servers/navigation_2d_server.h +++ b/servers/navigation_2d_server.h @@ -183,6 +183,9 @@ public: virtual void agent_set_map(RID p_agent, RID p_map) = 0; virtual RID agent_get_map(RID p_agent) const = 0; + virtual void agent_set_paused(RID p_agent, bool p_paused) = 0; + virtual bool agent_get_paused(RID p_agent) const = 0; + virtual void agent_set_avoidance_enabled(RID p_agent, bool p_enabled) = 0; virtual bool agent_get_avoidance_enabled(RID p_agent) const = 0; @@ -246,6 +249,10 @@ public: virtual RID obstacle_create() = 0; virtual void obstacle_set_map(RID p_obstacle, RID p_map) = 0; virtual RID obstacle_get_map(RID p_obstacle) const = 0; + + virtual void obstacle_set_paused(RID p_obstacle, bool p_paused) = 0; + virtual bool obstacle_get_paused(RID p_obstacle) const = 0; + virtual void obstacle_set_position(RID p_obstacle, Vector2 p_position) = 0; virtual void obstacle_set_vertices(RID p_obstacle, const Vector &p_vertices) = 0; virtual void obstacle_set_avoidance_layers(RID p_obstacle, uint32_t p_layers) = 0; diff --git a/servers/navigation_server.cpp b/servers/navigation_server.cpp index 526a449a0..783300841 100644 --- a/servers/navigation_server.cpp +++ b/servers/navigation_server.cpp @@ -131,6 +131,8 @@ void NavigationServer::_bind_methods() { ClassDB::bind_method(D_METHOD("agent_set_map", "agent", "map"), &NavigationServer::agent_set_map); ClassDB::bind_method(D_METHOD("agent_get_map", "agent"), &NavigationServer::agent_get_map); + ClassDB::bind_method(D_METHOD("agent_set_paused", "agent", "paused"), &NavigationServer::agent_set_paused); + ClassDB::bind_method(D_METHOD("agent_get_paused", "agent"), &NavigationServer::agent_get_paused); ClassDB::bind_method(D_METHOD("agent_set_neighbor_distance", "agent", "dist"), &NavigationServer::agent_set_neighbor_distance); ClassDB::bind_method(D_METHOD("agent_set_max_neighbors", "agent", "count"), &NavigationServer::agent_set_max_neighbors); ClassDB::bind_method(D_METHOD("agent_set_time_horizon_agents", "agent", "time_horizon"), &NavigationServer::agent_set_time_horizon_agents); @@ -151,6 +153,8 @@ void NavigationServer::_bind_methods() { ClassDB::bind_method(D_METHOD("obstacle_create"), &NavigationServer::obstacle_create); ClassDB::bind_method(D_METHOD("obstacle_set_map", "obstacle", "map"), &NavigationServer::obstacle_set_map); ClassDB::bind_method(D_METHOD("obstacle_get_map", "obstacle"), &NavigationServer::obstacle_get_map); + ClassDB::bind_method(D_METHOD("obstacle_set_paused", "obstacle", "paused"), &NavigationServer::obstacle_set_paused); + ClassDB::bind_method(D_METHOD("obstacle_get_paused", "obstacle"), &NavigationServer::obstacle_get_paused); ClassDB::bind_method(D_METHOD("obstacle_set_height", "obstacle", "height"), &NavigationServer::obstacle_set_height); ClassDB::bind_method(D_METHOD("obstacle_set_position", "obstacle", "position"), &NavigationServer::obstacle_set_position); ClassDB::bind_method(D_METHOD("obstacle_set_vertices", "obstacle", "vertices"), &NavigationServer::obstacle_set_vertices); @@ -159,7 +163,7 @@ void NavigationServer::_bind_methods() { ClassDB::bind_method(D_METHOD("free_rid", "rid"), &NavigationServer::free); ClassDB::bind_method(D_METHOD("set_active", "active"), &NavigationServer::set_active); - + ClassDB::bind_method(D_METHOD("get_process_info", "process_info"), &NavigationServer::get_process_info); ClassDB::bind_method(D_METHOD("set_debug_enabled", "enabled"), &NavigationServer::set_debug_enabled); diff --git a/servers/navigation_server.h b/servers/navigation_server.h index 12c7603e7..a685017e3 100644 --- a/servers/navigation_server.h +++ b/servers/navigation_server.h @@ -199,6 +199,9 @@ public: virtual void agent_set_map(RID p_agent, RID p_map) = 0; virtual RID agent_get_map(RID p_agent) const = 0; + virtual void agent_set_paused(RID p_agent, bool p_paused) = 0; + virtual bool agent_get_paused(RID p_agent) const = 0; + virtual void agent_set_avoidance_enabled(RID p_agent, bool p_enabled) = 0; virtual bool agent_get_avoidance_enabled(RID p_agent) const = 0; @@ -265,6 +268,10 @@ public: virtual RID obstacle_create() = 0; virtual void obstacle_set_map(RID p_obstacle, RID p_map) = 0; virtual RID obstacle_get_map(RID p_obstacle) const = 0; + + virtual void obstacle_set_paused(RID p_obstacle, bool p_paused) = 0; + virtual bool obstacle_get_paused(RID p_obstacle) const = 0; + virtual void obstacle_set_height(RID p_obstacle, real_t p_height) = 0; virtual void obstacle_set_position(RID p_obstacle, Vector3 p_position) = 0; virtual void obstacle_set_vertices(RID p_obstacle, const Vector &p_vertices) = 0;