Skip to content

Commit 4d76c19

Browse files
committed
Make navigation maps emit map_changed directly
Makes navigation maps emit map_changed directly.
1 parent a210fe6 commit 4d76c19

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

@@ -1288,8 +1285,6 @@ void GodotNavigationServer2D::physics_process(double p_delta_time) {
12881285
int _new_pm_edge_free_count = 0;
12891286
int _new_pm_obstacle_count = 0;
12901287

1291-
// In c++ we can't be sure that this is performed in the main thread
1292-
// even with mutable functions.
12931288
MutexLock lock(operations_mutex);
12941289
for (uint32_t i(0); i < active_maps.size(); i++) {
12951290
active_maps[i]->sync();
@@ -1305,13 +1300,6 @@ void GodotNavigationServer2D::physics_process(double p_delta_time) {
13051300
_new_pm_edge_connection_count += active_maps[i]->get_pm_edge_connection_count();
13061301
_new_pm_edge_free_count += active_maps[i]->get_pm_edge_free_count();
13071302
_new_pm_obstacle_count += active_maps[i]->get_pm_obstacle_count();
1308-
1309-
// Emit a signal if a map changed.
1310-
const uint32_t new_map_iteration_id = active_maps[i]->get_iteration_id();
1311-
if (new_map_iteration_id != active_maps_iteration_id[i]) {
1312-
emit_signal(SNAME("map_changed"), active_maps[i]->get_self());
1313-
active_maps_iteration_id[i] = new_map_iteration_id;
1314-
}
13151303
}
13161304

13171305
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

@@ -1369,8 +1366,6 @@ void GodotNavigationServer3D::physics_process(double p_delta_time) {
13691366
int _new_pm_edge_free_count = 0;
13701367
int _new_pm_obstacle_count = 0;
13711368

1372-
// In c++ we can't be sure that this is performed in the main thread
1373-
// even with mutable functions.
13741369
MutexLock lock(operations_mutex);
13751370
for (uint32_t i(0); i < active_maps.size(); i++) {
13761371
active_maps[i]->sync();
@@ -1386,13 +1381,6 @@ void GodotNavigationServer3D::physics_process(double p_delta_time) {
13861381
_new_pm_edge_connection_count += active_maps[i]->get_pm_edge_connection_count();
13871382
_new_pm_edge_free_count += active_maps[i]->get_pm_edge_free_count();
13881383
_new_pm_obstacle_count += active_maps[i]->get_pm_obstacle_count();
1389-
1390-
// Emit a signal if a map changed.
1391-
const uint32_t new_map_iteration_id = active_maps[i]->get_iteration_id();
1392-
if (new_map_iteration_id != active_maps_iteration_id[i]) {
1393-
emit_signal(SNAME("map_changed"), active_maps[i]->get_self());
1394-
active_maps_iteration_id[i] = new_map_iteration_id;
1395-
}
13961384
}
13971385

13981386
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)