Merge pull request #75678 from smix8/navregion_update_guards_4.x
Prevent unnecessary navigation map synchronizations
This commit is contained in:
commit
f78c2dd82f
11 changed files with 126 additions and 44 deletions
|
@ -33,21 +33,33 @@
|
||||||
#include "nav_map.h"
|
#include "nav_map.h"
|
||||||
|
|
||||||
void NavLink::set_map(NavMap *p_map) {
|
void NavLink::set_map(NavMap *p_map) {
|
||||||
|
if (map == p_map) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
map = p_map;
|
map = p_map;
|
||||||
link_dirty = true;
|
link_dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavLink::set_bidirectional(bool p_bidirectional) {
|
void NavLink::set_bidirectional(bool p_bidirectional) {
|
||||||
|
if (bidirectional == p_bidirectional) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
bidirectional = p_bidirectional;
|
bidirectional = p_bidirectional;
|
||||||
link_dirty = true;
|
link_dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavLink::set_start_position(const Vector3 p_position) {
|
void NavLink::set_start_position(const Vector3 p_position) {
|
||||||
|
if (start_position == p_position) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
start_position = p_position;
|
start_position = p_position;
|
||||||
link_dirty = true;
|
link_dirty = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavLink::set_end_position(const Vector3 p_position) {
|
void NavLink::set_end_position(const Vector3 p_position) {
|
||||||
|
if (end_position == p_position) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
end_position = p_position;
|
end_position = p_position;
|
||||||
link_dirty = true;
|
link_dirty = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,21 +54,33 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavMap::set_up(Vector3 p_up) {
|
void NavMap::set_up(Vector3 p_up) {
|
||||||
|
if (up == p_up) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
up = p_up;
|
up = p_up;
|
||||||
regenerate_polygons = true;
|
regenerate_polygons = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavMap::set_cell_size(real_t p_cell_size) {
|
void NavMap::set_cell_size(real_t p_cell_size) {
|
||||||
|
if (cell_size == p_cell_size) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
cell_size = p_cell_size;
|
cell_size = p_cell_size;
|
||||||
regenerate_polygons = true;
|
regenerate_polygons = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavMap::set_edge_connection_margin(real_t p_edge_connection_margin) {
|
void NavMap::set_edge_connection_margin(real_t p_edge_connection_margin) {
|
||||||
|
if (edge_connection_margin == p_edge_connection_margin) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
edge_connection_margin = p_edge_connection_margin;
|
edge_connection_margin = p_edge_connection_margin;
|
||||||
regenerate_links = true;
|
regenerate_links = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavMap::set_link_connection_radius(real_t p_link_connection_radius) {
|
void NavMap::set_link_connection_radius(real_t p_link_connection_radius) {
|
||||||
|
if (link_connection_radius == p_link_connection_radius) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
link_connection_radius = p_link_connection_radius;
|
link_connection_radius = p_link_connection_radius;
|
||||||
regenerate_links = true;
|
regenerate_links = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,6 +33,9 @@
|
||||||
#include "nav_map.h"
|
#include "nav_map.h"
|
||||||
|
|
||||||
void NavRegion::set_map(NavMap *p_map) {
|
void NavRegion::set_map(NavMap *p_map) {
|
||||||
|
if (map == p_map) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
map = p_map;
|
map = p_map;
|
||||||
polygons_dirty = true;
|
polygons_dirty = true;
|
||||||
if (!map) {
|
if (!map) {
|
||||||
|
@ -41,6 +44,9 @@ void NavRegion::set_map(NavMap *p_map) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NavRegion::set_transform(Transform3D p_transform) {
|
void NavRegion::set_transform(Transform3D p_transform) {
|
||||||
|
if (transform == p_transform) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
transform = p_transform;
|
transform = p_transform;
|
||||||
polygons_dirty = true;
|
polygons_dirty = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,19 +106,29 @@ void NavigationLink2D::_notification(int p_what) {
|
||||||
case NOTIFICATION_ENTER_TREE: {
|
case NOTIFICATION_ENTER_TREE: {
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
NavigationServer2D::get_singleton()->link_set_map(link, get_world_2d()->get_navigation_map());
|
NavigationServer2D::get_singleton()->link_set_map(link, get_world_2d()->get_navigation_map());
|
||||||
|
}
|
||||||
|
current_global_transform = get_global_transform();
|
||||||
|
NavigationServer2D::get_singleton()->link_set_start_position(link, current_global_transform.xform(start_position));
|
||||||
|
NavigationServer2D::get_singleton()->link_set_end_position(link, current_global_transform.xform(end_position));
|
||||||
|
} break;
|
||||||
|
|
||||||
// Update global positions for the link.
|
case NOTIFICATION_TRANSFORM_CHANGED: {
|
||||||
Transform2D gt = get_global_transform();
|
set_physics_process_internal(true);
|
||||||
NavigationServer2D::get_singleton()->link_set_start_position(link, gt.xform(start_position));
|
} break;
|
||||||
NavigationServer2D::get_singleton()->link_set_end_position(link, gt.xform(end_position));
|
|
||||||
|
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()->link_set_start_position(link, current_global_transform.xform(start_position));
|
||||||
|
NavigationServer2D::get_singleton()->link_set_end_position(link, current_global_transform.xform(end_position));
|
||||||
|
queue_redraw();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case NOTIFICATION_TRANSFORM_CHANGED: {
|
|
||||||
// Update global positions for the link.
|
|
||||||
Transform2D gt = get_global_transform();
|
|
||||||
NavigationServer2D::get_singleton()->link_set_start_position(link, gt.xform(start_position));
|
|
||||||
NavigationServer2D::get_singleton()->link_set_end_position(link, gt.xform(end_position));
|
|
||||||
} break;
|
|
||||||
case NOTIFICATION_EXIT_TREE: {
|
case NOTIFICATION_EXIT_TREE: {
|
||||||
NavigationServer2D::get_singleton()->link_set_map(link, RID());
|
NavigationServer2D::get_singleton()->link_set_map(link, RID());
|
||||||
} break;
|
} break;
|
||||||
|
@ -242,8 +252,7 @@ void NavigationLink2D::set_start_position(Vector2 p_position) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Transform2D gt = get_global_transform();
|
NavigationServer2D::get_singleton()->link_set_start_position(link, current_global_transform.xform(start_position));
|
||||||
NavigationServer2D::get_singleton()->link_set_start_position(link, gt.xform(start_position));
|
|
||||||
|
|
||||||
update_configuration_warnings();
|
update_configuration_warnings();
|
||||||
|
|
||||||
|
@ -265,8 +274,7 @@ void NavigationLink2D::set_end_position(Vector2 p_position) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Transform2D gt = get_global_transform();
|
NavigationServer2D::get_singleton()->link_set_end_position(link, current_global_transform.xform(end_position));
|
||||||
NavigationServer2D::get_singleton()->link_set_end_position(link, gt.xform(end_position));
|
|
||||||
|
|
||||||
update_configuration_warnings();
|
update_configuration_warnings();
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,8 @@ class NavigationLink2D : public Node2D {
|
||||||
real_t enter_cost = 0.0;
|
real_t enter_cost = 0.0;
|
||||||
real_t travel_cost = 1.0;
|
real_t travel_cost = 1.0;
|
||||||
|
|
||||||
|
Transform2D current_global_transform;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
void _notification(int p_what);
|
void _notification(int p_what);
|
||||||
|
|
|
@ -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;
|
} break;
|
||||||
|
|
||||||
case NOTIFICATION_TRANSFORM_CHANGED: {
|
case NOTIFICATION_TRANSFORM_CHANGED: {
|
||||||
NavigationServer2D::get_singleton()->region_set_transform(region, get_global_transform());
|
set_physics_process_internal(true);
|
||||||
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;
|
} break;
|
||||||
|
|
||||||
case NOTIFICATION_EXIT_TREE: {
|
case NOTIFICATION_EXIT_TREE: {
|
||||||
|
@ -183,6 +180,24 @@ void NavigationRegion2D::_notification(int p_what) {
|
||||||
}
|
}
|
||||||
} break;
|
} 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: {
|
case NOTIFICATION_DRAW: {
|
||||||
#ifdef DEBUG_ENABLED
|
#ifdef DEBUG_ENABLED
|
||||||
if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || NavigationServer2D::get_singleton()->get_debug_enabled()) && navigation_polygon.is_valid()) {
|
if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || NavigationServer2D::get_singleton()->get_debug_enabled()) && navigation_polygon.is_valid()) {
|
||||||
|
|
|
@ -47,6 +47,8 @@ class NavigationRegion2D : public Node2D {
|
||||||
LocalVector<RID> constrain_avoidance_obstacles;
|
LocalVector<RID> constrain_avoidance_obstacles;
|
||||||
uint32_t avoidance_layers = 1;
|
uint32_t avoidance_layers = 1;
|
||||||
|
|
||||||
|
Transform2D current_global_transform;
|
||||||
|
|
||||||
void _navigation_polygon_changed();
|
void _navigation_polygon_changed();
|
||||||
void _map_changed(RID p_RID);
|
void _map_changed(RID p_RID);
|
||||||
|
|
||||||
|
|
|
@ -141,6 +141,8 @@ void NavigationLink3D::_update_debug_mesh() {
|
||||||
} else {
|
} else {
|
||||||
RS::get_singleton()->instance_set_surface_override_material(debug_instance, 0, disabled_link_material->get_rid());
|
RS::get_singleton()->instance_set_surface_override_material(debug_instance, 0, disabled_link_material->get_rid());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RS::get_singleton()->instance_set_transform(debug_instance, current_global_transform);
|
||||||
}
|
}
|
||||||
#endif // DEBUG_ENABLED
|
#endif // DEBUG_ENABLED
|
||||||
|
|
||||||
|
@ -215,29 +217,37 @@ void NavigationLink3D::_notification(int p_what) {
|
||||||
case NOTIFICATION_ENTER_TREE: {
|
case NOTIFICATION_ENTER_TREE: {
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
NavigationServer3D::get_singleton()->link_set_map(link, get_world_3d()->get_navigation_map());
|
NavigationServer3D::get_singleton()->link_set_map(link, get_world_3d()->get_navigation_map());
|
||||||
|
|
||||||
// Update global positions for the link.
|
|
||||||
Transform3D gt = get_global_transform();
|
|
||||||
NavigationServer3D::get_singleton()->link_set_start_position(link, gt.xform(start_position));
|
|
||||||
NavigationServer3D::get_singleton()->link_set_end_position(link, gt.xform(end_position));
|
|
||||||
}
|
}
|
||||||
|
current_global_transform = get_global_transform();
|
||||||
|
NavigationServer3D::get_singleton()->link_set_start_position(link, current_global_transform.xform(start_position));
|
||||||
|
NavigationServer3D::get_singleton()->link_set_end_position(link, current_global_transform.xform(end_position));
|
||||||
|
|
||||||
#ifdef DEBUG_ENABLED
|
#ifdef DEBUG_ENABLED
|
||||||
_update_debug_mesh();
|
_update_debug_mesh();
|
||||||
#endif // DEBUG_ENABLED
|
#endif // DEBUG_ENABLED
|
||||||
} break;
|
} break;
|
||||||
case NOTIFICATION_TRANSFORM_CHANGED: {
|
|
||||||
// Update global positions for the link.
|
|
||||||
Transform3D gt = get_global_transform();
|
|
||||||
NavigationServer3D::get_singleton()->link_set_start_position(link, gt.xform(start_position));
|
|
||||||
NavigationServer3D::get_singleton()->link_set_end_position(link, gt.xform(end_position));
|
|
||||||
|
|
||||||
#ifdef DEBUG_ENABLED
|
case NOTIFICATION_TRANSFORM_CHANGED: {
|
||||||
if (is_inside_tree() && debug_instance.is_valid()) {
|
set_physics_process_internal(true);
|
||||||
RS::get_singleton()->instance_set_transform(debug_instance, get_global_transform());
|
|
||||||
}
|
|
||||||
#endif // DEBUG_ENABLED
|
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
|
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
|
||||||
|
set_physics_process_internal(false);
|
||||||
|
if (is_inside_tree()) {
|
||||||
|
Transform3D new_global_transform = get_global_transform();
|
||||||
|
if (current_global_transform != new_global_transform) {
|
||||||
|
current_global_transform = new_global_transform;
|
||||||
|
NavigationServer3D::get_singleton()->link_set_start_position(link, current_global_transform.xform(start_position));
|
||||||
|
NavigationServer3D::get_singleton()->link_set_end_position(link, current_global_transform.xform(end_position));
|
||||||
|
#ifdef DEBUG_ENABLED
|
||||||
|
if (debug_instance.is_valid()) {
|
||||||
|
RS::get_singleton()->instance_set_transform(debug_instance, current_global_transform);
|
||||||
|
}
|
||||||
|
#endif // DEBUG_ENABLED
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} break;
|
||||||
|
|
||||||
case NOTIFICATION_EXIT_TREE: {
|
case NOTIFICATION_EXIT_TREE: {
|
||||||
NavigationServer3D::get_singleton()->link_set_map(link, RID());
|
NavigationServer3D::get_singleton()->link_set_map(link, RID());
|
||||||
|
|
||||||
|
@ -359,8 +369,7 @@ void NavigationLink3D::set_start_position(Vector3 p_position) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Transform3D gt = get_global_transform();
|
NavigationServer3D::get_singleton()->link_set_start_position(link, current_global_transform.xform(start_position));
|
||||||
NavigationServer3D::get_singleton()->link_set_start_position(link, gt.xform(start_position));
|
|
||||||
|
|
||||||
#ifdef DEBUG_ENABLED
|
#ifdef DEBUG_ENABLED
|
||||||
_update_debug_mesh();
|
_update_debug_mesh();
|
||||||
|
@ -381,8 +390,7 @@ void NavigationLink3D::set_end_position(Vector3 p_position) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Transform3D gt = get_global_transform();
|
NavigationServer3D::get_singleton()->link_set_end_position(link, current_global_transform.xform(end_position));
|
||||||
NavigationServer3D::get_singleton()->link_set_end_position(link, gt.xform(end_position));
|
|
||||||
|
|
||||||
#ifdef DEBUG_ENABLED
|
#ifdef DEBUG_ENABLED
|
||||||
_update_debug_mesh();
|
_update_debug_mesh();
|
||||||
|
|
|
@ -45,6 +45,8 @@ class NavigationLink3D : public Node3D {
|
||||||
real_t enter_cost = 0.0;
|
real_t enter_cost = 0.0;
|
||||||
real_t travel_cost = 1.0;
|
real_t travel_cost = 1.0;
|
||||||
|
|
||||||
|
Transform3D current_global_transform;
|
||||||
|
|
||||||
#ifdef DEBUG_ENABLED
|
#ifdef DEBUG_ENABLED
|
||||||
RID debug_instance;
|
RID debug_instance;
|
||||||
Ref<ArrayMesh> debug_mesh;
|
Ref<ArrayMesh> debug_mesh;
|
||||||
|
|
|
@ -157,6 +157,8 @@ void NavigationRegion3D::_notification(int p_what) {
|
||||||
if (enabled) {
|
if (enabled) {
|
||||||
NavigationServer3D::get_singleton()->region_set_map(region, get_world_3d()->get_navigation_map());
|
NavigationServer3D::get_singleton()->region_set_map(region, get_world_3d()->get_navigation_map());
|
||||||
}
|
}
|
||||||
|
current_global_transform = get_global_transform();
|
||||||
|
NavigationServer3D::get_singleton()->region_set_transform(region, current_global_transform);
|
||||||
|
|
||||||
#ifdef DEBUG_ENABLED
|
#ifdef DEBUG_ENABLED
|
||||||
if (NavigationServer3D::get_singleton()->get_debug_navigation_enabled()) {
|
if (NavigationServer3D::get_singleton()->get_debug_navigation_enabled()) {
|
||||||
|
@ -167,14 +169,24 @@ void NavigationRegion3D::_notification(int p_what) {
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case NOTIFICATION_TRANSFORM_CHANGED: {
|
case NOTIFICATION_TRANSFORM_CHANGED: {
|
||||||
NavigationServer3D::get_singleton()->region_set_transform(region, get_global_transform());
|
set_physics_process_internal(true);
|
||||||
|
|
||||||
|
} break;
|
||||||
|
|
||||||
|
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
|
||||||
|
set_physics_process_internal(false);
|
||||||
|
if (is_inside_tree()) {
|
||||||
|
Transform3D new_global_transform = get_global_transform();
|
||||||
|
if (current_global_transform != new_global_transform) {
|
||||||
|
current_global_transform = new_global_transform;
|
||||||
|
NavigationServer3D::get_singleton()->region_set_transform(region, current_global_transform);
|
||||||
#ifdef DEBUG_ENABLED
|
#ifdef DEBUG_ENABLED
|
||||||
if (is_inside_tree() && debug_instance.is_valid()) {
|
if (debug_instance.is_valid()) {
|
||||||
RS::get_singleton()->instance_set_transform(debug_instance, get_global_transform());
|
RS::get_singleton()->instance_set_transform(debug_instance, current_global_transform);
|
||||||
}
|
}
|
||||||
#endif // DEBUG_ENABLED
|
#endif // DEBUG_ENABLED
|
||||||
|
}
|
||||||
|
}
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
case NOTIFICATION_EXIT_TREE: {
|
case NOTIFICATION_EXIT_TREE: {
|
||||||
|
@ -552,6 +564,7 @@ void NavigationRegion3D::_update_debug_mesh() {
|
||||||
RS::get_singleton()->instance_set_base(debug_instance, debug_mesh->get_rid());
|
RS::get_singleton()->instance_set_base(debug_instance, debug_mesh->get_rid());
|
||||||
if (is_inside_tree()) {
|
if (is_inside_tree()) {
|
||||||
RS::get_singleton()->instance_set_scenario(debug_instance, get_world_3d()->get_scenario());
|
RS::get_singleton()->instance_set_scenario(debug_instance, get_world_3d()->get_scenario());
|
||||||
|
RS::get_singleton()->instance_set_transform(debug_instance, current_global_transform);
|
||||||
RS::get_singleton()->instance_set_visible(debug_instance, is_visible_in_tree());
|
RS::get_singleton()->instance_set_visible(debug_instance, is_visible_in_tree());
|
||||||
}
|
}
|
||||||
if (!is_enabled()) {
|
if (!is_enabled()) {
|
||||||
|
|
|
@ -44,6 +44,8 @@ class NavigationRegion3D : public Node3D {
|
||||||
real_t travel_cost = 1.0;
|
real_t travel_cost = 1.0;
|
||||||
Ref<NavigationMesh> navigation_mesh;
|
Ref<NavigationMesh> navigation_mesh;
|
||||||
|
|
||||||
|
Transform3D current_global_transform;
|
||||||
|
|
||||||
Thread bake_thread;
|
Thread bake_thread;
|
||||||
|
|
||||||
void _navigation_changed();
|
void _navigation_changed();
|
||||||
|
|
Loading…
Reference in a new issue