Skip to content

Commit e1509d5

Browse files
committed
Merge pull request #105071 from smix8/map_changed
Make navigation maps emit map_changed directly
2 parents 034e614 + 4d76c19 commit e1509d5

File tree

6 files changed

+6
-26
lines changed

6 files changed

+6
-26
lines changed

modules/navigation_2d/2d/godot_navigation_server_2d.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,11 @@ COMMAND_2(map_set_active, RID, p_map, bool, p_active) {
293293
if (p_active) {
294294
if (!map_is_active(p_map)) {
295295
active_maps.push_back(map);
296-
active_maps_iteration_id.push_back(map->get_iteration_id());
297296
}
298297
} else {
299298
int map_index = active_maps.find(map);
300299
ERR_FAIL_COND(map_index < 0);
301300
active_maps.remove_at(map_index);
302-
active_maps_iteration_id.remove_at(map_index);
303301
}
304302
}
305303

@@ -1192,7 +1190,6 @@ COMMAND_1(free, RID, p_object) {
11921190
int map_index = active_maps.find(map);
11931191
if (map_index >= 0) {
11941192
active_maps.remove_at(map_index);
1195-
active_maps_iteration_id.remove_at(map_index);
11961193
}
11971194
map_owner.free(p_object);
11981195

@@ -1290,8 +1287,6 @@ void GodotNavigationServer2D::physics_process(double p_delta_time) {
12901287
int _new_pm_edge_free_count = 0;
12911288
int _new_pm_obstacle_count = 0;
12921289

1293-
// In c++ we can't be sure that this is performed in the main thread
1294-
// even with mutable functions.
12951290
MutexLock lock(operations_mutex);
12961291
for (uint32_t i(0); i < active_maps.size(); i++) {
12971292
active_maps[i]->sync();
@@ -1307,13 +1302,6 @@ void GodotNavigationServer2D::physics_process(double p_delta_time) {
13071302
_new_pm_edge_connection_count += active_maps[i]->get_pm_edge_connection_count();
13081303
_new_pm_edge_free_count += active_maps[i]->get_pm_edge_free_count();
13091304
_new_pm_obstacle_count += active_maps[i]->get_pm_obstacle_count();
1310-
1311-
// Emit a signal if a map changed.
1312-
const uint32_t new_map_iteration_id = active_maps[i]->get_iteration_id();
1313-
if (new_map_iteration_id != active_maps_iteration_id[i]) {
1314-
emit_signal(SNAME("map_changed"), active_maps[i]->get_self());
1315-
active_maps_iteration_id[i] = new_map_iteration_id;
1316-
}
13171305
}
13181306

13191307
pm_region_count = _new_pm_region_count;

modules/navigation_2d/2d/godot_navigation_server_2d.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ class GodotNavigationServer2D : public NavigationServer2D {
8484

8585
bool active = true;
8686
LocalVector<NavMap2D *> active_maps;
87-
LocalVector<uint32_t> active_maps_iteration_id;
8887

8988
#ifdef CLIPPER2_ENABLED
9089
NavMeshGenerator2D *navmesh_generator_2d = nullptr;

modules/navigation_2d/nav_map_2d.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
#include "core/config/project_settings.h"
4242
#include "core/object/worker_thread_pool.h"
43+
#include "servers/navigation_server_2d.h"
4344

4445
#include <Obstacle2d.h>
4546

@@ -418,6 +419,8 @@ void NavMap2D::sync() {
418419
}
419420
if (iteration_ready) {
420421
_sync_iteration();
422+
423+
NavigationServer2D::get_singleton()->emit_signal(SNAME("map_changed"), get_self());
421424
}
422425

423426
map_settings_dirty = false;

modules/navigation_3d/3d/godot_navigation_server_3d.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,11 @@ COMMAND_2(map_set_active, RID, p_map, bool, p_active) {
120120
if (p_active) {
121121
if (!map_is_active(p_map)) {
122122
active_maps.push_back(map);
123-
active_maps_iteration_id.push_back(map->get_iteration_id());
124123
}
125124
} else {
126125
int map_index = active_maps.find(map);
127126
ERR_FAIL_COND(map_index < 0);
128127
active_maps.remove_at(map_index);
129-
active_maps_iteration_id.remove_at(map_index);
130128
}
131129
}
132130

@@ -1224,7 +1222,6 @@ COMMAND_1(free, RID, p_object) {
12241222
int map_index = active_maps.find(map);
12251223
if (map_index >= 0) {
12261224
active_maps.remove_at(map_index);
1227-
active_maps_iteration_id.remove_at(map_index);
12281225
}
12291226
map_owner.free(p_object);
12301227

@@ -1371,8 +1368,6 @@ void GodotNavigationServer3D::physics_process(double p_delta_time) {
13711368
int _new_pm_edge_free_count = 0;
13721369
int _new_pm_obstacle_count = 0;
13731370

1374-
// In c++ we can't be sure that this is performed in the main thread
1375-
// even with mutable functions.
13761371
MutexLock lock(operations_mutex);
13771372
for (uint32_t i(0); i < active_maps.size(); i++) {
13781373
active_maps[i]->sync();
@@ -1388,13 +1383,6 @@ void GodotNavigationServer3D::physics_process(double p_delta_time) {
13881383
_new_pm_edge_connection_count += active_maps[i]->get_pm_edge_connection_count();
13891384
_new_pm_edge_free_count += active_maps[i]->get_pm_edge_free_count();
13901385
_new_pm_obstacle_count += active_maps[i]->get_pm_obstacle_count();
1391-
1392-
// Emit a signal if a map changed.
1393-
const uint32_t new_map_iteration_id = active_maps[i]->get_iteration_id();
1394-
if (new_map_iteration_id != active_maps_iteration_id[i]) {
1395-
emit_signal(SNAME("map_changed"), active_maps[i]->get_self());
1396-
active_maps_iteration_id[i] = new_map_iteration_id;
1397-
}
13981386
}
13991387

14001388
pm_region_count = _new_pm_region_count;

modules/navigation_3d/3d/godot_navigation_server_3d.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ class GodotNavigationServer3D : public NavigationServer3D {
7979

8080
bool active = true;
8181
LocalVector<NavMap3D *> active_maps;
82-
LocalVector<uint32_t> active_maps_iteration_id;
8382

8483
NavMeshGenerator3D *navmesh_generator_3d = nullptr;
8584

modules/navigation_3d/nav_map_3d.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040

4141
#include "core/config/project_settings.h"
4242
#include "core/object/worker_thread_pool.h"
43+
#include "servers/navigation_server_3d.h"
4344

4445
#include <Obstacle2d.h>
4546

@@ -474,6 +475,8 @@ void NavMap3D::sync() {
474475
}
475476
if (iteration_ready) {
476477
_sync_iteration();
478+
479+
NavigationServer3D::get_singleton()->emit_signal(SNAME("map_changed"), get_self());
477480
}
478481

479482
map_settings_dirty = false;

0 commit comments

Comments
 (0)