Merge pull request #105071 from smix8/map_changed

Make navigation maps emit map_changed directly
This commit is contained in:
Thaddeus Crews
2025-04-14 19:39:52 -05:00
6 changed files with 6 additions and 26 deletions

View File

@@ -293,13 +293,11 @@ COMMAND_2(map_set_active, RID, p_map, bool, p_active) {
if (p_active) {
if (!map_is_active(p_map)) {
active_maps.push_back(map);
active_maps_iteration_id.push_back(map->get_iteration_id());
}
} else {
int map_index = active_maps.find(map);
ERR_FAIL_COND(map_index < 0);
active_maps.remove_at(map_index);
active_maps_iteration_id.remove_at(map_index);
}
}
@@ -1192,7 +1190,6 @@ COMMAND_1(free, RID, p_object) {
int map_index = active_maps.find(map);
if (map_index >= 0) {
active_maps.remove_at(map_index);
active_maps_iteration_id.remove_at(map_index);
}
map_owner.free(p_object);
@@ -1290,8 +1287,6 @@ void GodotNavigationServer2D::physics_process(double p_delta_time) {
int _new_pm_edge_free_count = 0;
int _new_pm_obstacle_count = 0;
// In c++ we can't be sure that this is performed in the main thread
// even with mutable functions.
MutexLock lock(operations_mutex);
for (uint32_t i(0); i < active_maps.size(); i++) {
active_maps[i]->sync();
@@ -1307,13 +1302,6 @@ void GodotNavigationServer2D::physics_process(double p_delta_time) {
_new_pm_edge_connection_count += active_maps[i]->get_pm_edge_connection_count();
_new_pm_edge_free_count += active_maps[i]->get_pm_edge_free_count();
_new_pm_obstacle_count += active_maps[i]->get_pm_obstacle_count();
// Emit a signal if a map changed.
const uint32_t new_map_iteration_id = active_maps[i]->get_iteration_id();
if (new_map_iteration_id != active_maps_iteration_id[i]) {
emit_signal(SNAME("map_changed"), active_maps[i]->get_self());
active_maps_iteration_id[i] = new_map_iteration_id;
}
}
pm_region_count = _new_pm_region_count;

View File

@@ -84,7 +84,6 @@ class GodotNavigationServer2D : public NavigationServer2D {
bool active = true;
LocalVector<NavMap2D *> active_maps;
LocalVector<uint32_t> active_maps_iteration_id;
#ifdef CLIPPER2_ENABLED
NavMeshGenerator2D *navmesh_generator_2d = nullptr;

View File

@@ -40,6 +40,7 @@
#include "core/config/project_settings.h"
#include "core/object/worker_thread_pool.h"
#include "servers/navigation_server_2d.h"
#include <Obstacle2d.h>
@@ -418,6 +419,8 @@ void NavMap2D::sync() {
}
if (iteration_ready) {
_sync_iteration();
NavigationServer2D::get_singleton()->emit_signal(SNAME("map_changed"), get_self());
}
map_settings_dirty = false;