summaryrefslogtreecommitdiffstats
path: root/scene/2d/navigation_region_2d.cpp
diff options
context:
space:
mode:
authorsmix8 <52464204+smix8@users.noreply.github.com>2023-04-05 02:15:25 +0200
committersmix8 <52464204+smix8@users.noreply.github.com>2023-05-11 07:38:16 +0200
commit7e1a261cc661ddbefb90208b94a6828c50750237 (patch)
tree648741a5ffdbc28fab4268aa9ecc9fba9800b290 /scene/2d/navigation_region_2d.cpp
parentc80a2b4fe99dcd0bba6fc24ed2748b1474b24448 (diff)
downloadredot-engine-7e1a261cc661ddbefb90208b94a6828c50750237.tar.gz
Prevent unnecessary navigation map synchronizations
Prevents unnecessary navigation map synchronizations triggered by redundant calls to setters of e.g. region, link or map properties.
Diffstat (limited to 'scene/2d/navigation_region_2d.cpp')
-rw-r--r--scene/2d/navigation_region_2d.cpp27
1 files changed, 21 insertions, 6 deletions
diff --git a/scene/2d/navigation_region_2d.cpp b/scene/2d/navigation_region_2d.cpp
index edce9c94fd..cbcdb9f88e 100644
--- a/scene/2d/navigation_region_2d.cpp
+++ b/scene/2d/navigation_region_2d.cpp
@@ -160,15 +160,12 @@ void NavigationRegion2D::_notification(int p_what) {
}
}
}
+ current_global_transform = get_global_transform();
+ NavigationServer2D::get_singleton()->region_set_transform(region, current_global_transform);
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
- NavigationServer2D::get_singleton()->region_set_transform(region, get_global_transform());
- for (uint32_t i = 0; i < constrain_avoidance_obstacles.size(); i++) {
- if (constrain_avoidance_obstacles[i].is_valid()) {
- NavigationServer2D::get_singleton()->obstacle_set_position(constrain_avoidance_obstacles[i], get_global_position());
- }
- }
+ set_physics_process_internal(true);
} break;
case NOTIFICATION_EXIT_TREE: {
@@ -183,6 +180,24 @@ void NavigationRegion2D::_notification(int p_what) {
}
} break;
+ case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
+ set_physics_process_internal(false);
+ if (is_inside_tree()) {
+ Transform2D new_global_transform = get_global_transform();
+ if (current_global_transform != new_global_transform) {
+ current_global_transform = new_global_transform;
+ NavigationServer2D::get_singleton()->region_set_transform(region, current_global_transform);
+ queue_redraw();
+
+ for (uint32_t i = 0; i < constrain_avoidance_obstacles.size(); i++) {
+ if (constrain_avoidance_obstacles[i].is_valid()) {
+ NavigationServer2D::get_singleton()->obstacle_set_position(constrain_avoidance_obstacles[i], get_global_position());
+ }
+ }
+ }
+ }
+ } break;
+
case NOTIFICATION_DRAW: {
#ifdef DEBUG_ENABLED
if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || NavigationServer2D::get_singleton()->get_debug_enabled()) && navigation_polygon.is_valid()) {