mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-12-23 20:36:53 +01:00
Ported: Make Navigation Agents and Obstacles respect parent process mode
Temporarily removes agent from navigation map when parent node cannot process due to SceneTree pause and process_mode property. Normal process_mode does not work as other agents would still avoid the paused agents because they were still active on the navigation map and the rvo world. Also fixes potential crash when region_get_map or agent_get_map is called while no map is set.
- smix8
88acb5b798
This commit is contained in:
parent
85776387c5
commit
60b854d657
@ -275,13 +275,23 @@ Array PandemoniumNavigationServer::map_get_agents(RID p_map) const {
|
||||
RID PandemoniumNavigationServer::region_get_map(RID p_region) const {
|
||||
NavRegion *region = region_owner.getornull(p_region);
|
||||
ERR_FAIL_COND_V(region == nullptr, RID());
|
||||
return region->get_map()->get_self();
|
||||
|
||||
if (region->get_map()) {
|
||||
return region->get_map()->get_self();
|
||||
}
|
||||
|
||||
return RID();
|
||||
}
|
||||
|
||||
RID PandemoniumNavigationServer::agent_get_map(RID p_agent) const {
|
||||
RvoAgent *agent = agent_owner.getornull(p_agent);
|
||||
ERR_FAIL_COND_V(agent == nullptr, RID());
|
||||
return agent->get_map()->get_self();
|
||||
|
||||
if (agent->get_map()) {
|
||||
return agent->get_map()->get_self();
|
||||
}
|
||||
|
||||
return RID();
|
||||
}
|
||||
|
||||
RID PandemoniumNavigationServer::region_create() const {
|
||||
|
@ -115,6 +115,24 @@ void NavigationAgent2D::_notification(int p_what) {
|
||||
|
||||
set_physics_process_internal(true);
|
||||
} 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();
|
||||
}
|
||||
} 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();
|
||||
}
|
||||
} break;
|
||||
case NOTIFICATION_EXIT_TREE: {
|
||||
agent_parent = nullptr;
|
||||
set_navigation(nullptr);
|
||||
|
@ -42,6 +42,7 @@ class NavigationAgent2D : public Node {
|
||||
Navigation2D *navigation;
|
||||
|
||||
RID agent;
|
||||
RID map_before_pause;
|
||||
|
||||
real_t target_desired_distance;
|
||||
real_t radius;
|
||||
|
@ -95,6 +95,24 @@ void NavigationObstacle2D::_notification(int p_what) {
|
||||
case NOTIFICATION_UNPARENTED: {
|
||||
parent_node2d = nullptr;
|
||||
} break;
|
||||
case NOTIFICATION_PAUSED: {
|
||||
if (parent_node2d && !parent_node2d->can_process()) {
|
||||
map_before_pause = Navigation2DServer::get_singleton()->agent_get_map(get_rid());
|
||||
Navigation2DServer::get_singleton()->agent_set_map(get_rid(), RID());
|
||||
} else if (parent_node2d && parent_node2d->can_process() && !(map_before_pause == RID())) {
|
||||
Navigation2DServer::get_singleton()->agent_set_map(get_rid(), map_before_pause);
|
||||
map_before_pause = RID();
|
||||
}
|
||||
} break;
|
||||
case NOTIFICATION_UNPAUSED: {
|
||||
if (parent_node2d && !parent_node2d->can_process()) {
|
||||
map_before_pause = Navigation2DServer::get_singleton()->agent_get_map(get_rid());
|
||||
Navigation2DServer::get_singleton()->agent_set_map(get_rid(), RID());
|
||||
} else if (parent_node2d && parent_node2d->can_process() && !(map_before_pause == RID())) {
|
||||
Navigation2DServer::get_singleton()->agent_set_map(get_rid(), map_before_pause);
|
||||
map_before_pause = RID();
|
||||
}
|
||||
} break;
|
||||
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
|
||||
if (parent_node2d && parent_node2d->is_inside_tree()) {
|
||||
Navigation2DServer::get_singleton()->agent_set_position(agent, parent_node2d->get_global_transform().get_origin());
|
||||
|
@ -42,6 +42,8 @@ class NavigationObstacle2D : public Node {
|
||||
Node2D *parent_node2d = nullptr;
|
||||
|
||||
RID agent;
|
||||
RID map_before_pause;
|
||||
|
||||
bool estimate_radius = true;
|
||||
real_t radius = 1.0;
|
||||
|
||||
|
@ -131,6 +131,24 @@ void NavigationAgent::_notification(int p_what) {
|
||||
// the navigation map may not be ready at that time. This fixes issues with taking the agent out of the scene tree.
|
||||
request_ready();
|
||||
} 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();
|
||||
}
|
||||
} 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();
|
||||
}
|
||||
} break;
|
||||
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
|
||||
if (agent_parent) {
|
||||
NavigationServer::get_singleton()->agent_set_position(agent, agent_parent->get_global_transform().origin);
|
||||
|
@ -43,6 +43,7 @@ class NavigationAgent : public Node {
|
||||
Navigation *navigation;
|
||||
|
||||
RID agent;
|
||||
RID map_before_pause;
|
||||
|
||||
real_t target_desired_distance;
|
||||
real_t radius;
|
||||
|
@ -83,6 +83,24 @@ void NavigationObstacle::_notification(int p_what) {
|
||||
|
||||
set_physics_process_internal(true);
|
||||
} break;
|
||||
case NOTIFICATION_PAUSED: {
|
||||
if (parent_spatial && !parent_spatial->can_process()) {
|
||||
map_before_pause = NavigationServer::get_singleton()->agent_get_map(get_rid());
|
||||
NavigationServer::get_singleton()->agent_set_map(get_rid(), RID());
|
||||
} else if (parent_spatial && parent_spatial->can_process() && !(map_before_pause == RID())) {
|
||||
NavigationServer::get_singleton()->agent_set_map(get_rid(), map_before_pause);
|
||||
map_before_pause = RID();
|
||||
}
|
||||
} break;
|
||||
case NOTIFICATION_UNPAUSED: {
|
||||
if (parent_spatial && !parent_spatial->can_process()) {
|
||||
map_before_pause = NavigationServer::get_singleton()->agent_get_map(get_rid());
|
||||
NavigationServer::get_singleton()->agent_set_map(get_rid(), RID());
|
||||
} else if (parent_spatial && parent_spatial->can_process() && !(map_before_pause == RID())) {
|
||||
NavigationServer::get_singleton()->agent_set_map(get_rid(), map_before_pause);
|
||||
map_before_pause = RID();
|
||||
}
|
||||
} break;
|
||||
case NOTIFICATION_EXIT_TREE: {
|
||||
set_navigation(nullptr);
|
||||
set_physics_process_internal(false);
|
||||
|
@ -42,6 +42,8 @@ class NavigationObstacle : public Node {
|
||||
Navigation *navigation;
|
||||
|
||||
RID agent;
|
||||
RID map_before_pause;
|
||||
|
||||
bool estimate_radius = true;
|
||||
real_t radius = 1.0;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user