Simplify some logic NavigationObstacle2D.

This commit is contained in:
Relintai 2023-09-02 12:16:31 +02:00
parent 4d23b861d5
commit 569c2e9f85
2 changed files with 11 additions and 24 deletions

View File

@ -85,15 +85,8 @@ void NavigationObstacle2D::_notification(int p_what) {
navigation = nav; navigation = nav;
} }
if (navigation) { _update_map(get_navigation_map());
_update_map(navigation->get_rid());
} else if (map_override.is_valid()) {
_update_map(map_override);
} else if (is_inside_tree()) {
_update_map(get_world_2d()->get_navigation_map());
} else {
_update_map(RID());
}
previous_transform = get_global_transform(); previous_transform = get_global_transform();
// need to trigger map controlled agent assignment somehow for the fake_agent since obstacles use no callback like regular agents // need to trigger map controlled agent assignment somehow for the fake_agent since obstacles use no callback like regular agents
Navigation2DServer::get_singleton()->agent_set_avoidance_enabled(fake_agent, radius > 0); Navigation2DServer::get_singleton()->agent_set_avoidance_enabled(fake_agent, radius > 0);
@ -162,7 +155,7 @@ void NavigationObstacle2D::_notification(int p_what) {
} }
NavigationObstacle2D::NavigationObstacle2D() { NavigationObstacle2D::NavigationObstacle2D() {
navigation = nullptr; navigation = NULL;
obstacle = Navigation2DServer::get_singleton()->obstacle_create(); obstacle = Navigation2DServer::get_singleton()->obstacle_create();
fake_agent = Navigation2DServer::get_singleton()->agent_create(); fake_agent = Navigation2DServer::get_singleton()->agent_create();
@ -198,15 +191,7 @@ void NavigationObstacle2D::set_navigation(Navigation2D *p_nav) {
navigation = p_nav; navigation = p_nav;
if (navigation) { _update_map(get_navigation_map());
_update_map(navigation->get_rid());
} else if (map_override.is_valid()) {
_update_map(map_override);
} else if (is_inside_tree()) {
_update_map(get_world_2d()->get_navigation_map());
} else {
_update_map(RID());
}
} }
void NavigationObstacle2D::set_navigation_node(Node *p_nav) { void NavigationObstacle2D::set_navigation_node(Node *p_nav) {
@ -231,15 +216,17 @@ void NavigationObstacle2D::set_navigation_map(RID p_navigation_map) {
if (map_override == p_navigation_map) { if (map_override == p_navigation_map) {
return; return;
} }
map_override = p_navigation_map; map_override = p_navigation_map;
_update_map(map_override);
_update_map(get_navigation_map());
} }
RID NavigationObstacle2D::get_navigation_map() const { RID NavigationObstacle2D::get_navigation_map() const {
if (navigation) { if (map_override.is_valid()) {
return navigation->get_rid();
} else if (map_override.is_valid()) {
return map_override; return map_override;
} else if (navigation) {
return navigation->get_rid();
} else if (is_inside_tree()) { } else if (is_inside_tree()) {
return get_world_2d()->get_navigation_map(); return get_world_2d()->get_navigation_map();
} }

View File

@ -42,7 +42,7 @@ class NavigationObstacle2D : public Node2D {
RID obstacle; RID obstacle;
RID map_before_pause; RID map_before_pause;
RID map_override; //!!! RID map_override;
RID map_current; RID map_current;
real_t radius = 0.0; real_t radius = 0.0;