Skip to content

Commit 0110048

Browse files
committed
Merge pull request #104826 from smix8/navregion_iteration_id
Add function to get navigation region iteration id from NavigationServer
2 parents 7d4ba07 + 2b8531d commit 0110048

16 files changed

+54
-0
lines changed

doc/classes/NavigationServer2D.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,14 @@
843843
Returns the enter cost of this [param region].
844844
</description>
845845
</method>
846+
<method name="region_get_iteration_id" qualifiers="const">
847+
<return type="int" />
848+
<param index="0" name="region" type="RID" />
849+
<description>
850+
Returns the current iteration ID of the navigation region. Every time the navigation region changes and synchronizes, the iteration ID increases. An iteration ID of [code]0[/code] means the navigation region has never synchronized.
851+
[b]Note:[/b] The iteration ID will wrap around to [code]1[/code] after reaching its range limit.
852+
</description>
853+
</method>
846854
<method name="region_get_map" qualifiers="const">
847855
<return type="RID" />
848856
<param index="0" name="region" type="RID" />

doc/classes/NavigationServer3D.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -996,6 +996,14 @@
996996
Returns the enter cost of this [param region].
997997
</description>
998998
</method>
999+
<method name="region_get_iteration_id" qualifiers="const">
1000+
<return type="int" />
1001+
<param index="0" name="region" type="RID" />
1002+
<description>
1003+
Returns the current iteration ID of the navigation region. Every time the navigation region changes and synchronizes, the iteration ID increases. An iteration ID of [code]0[/code] means the navigation region has never synchronized.
1004+
[b]Note:[/b] The iteration ID will wrap around to [code]1[/code] after reaching its range limit.
1005+
</description>
1006+
</method>
9991007
<method name="region_get_map" qualifiers="const">
10001008
<return type="RID" />
10011009
<param index="0" name="region" type="RID" />

modules/navigation_2d/2d/godot_navigation_server_2d.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,13 @@ RID GodotNavigationServer2D::region_create() {
448448
return rid;
449449
}
450450

451+
uint32_t GodotNavigationServer2D::region_get_iteration_id(RID p_region) const {
452+
NavRegion2D *region = region_owner.get_or_null(p_region);
453+
ERR_FAIL_NULL_V(region, 0);
454+
455+
return region->get_iteration_id();
456+
}
457+
451458
COMMAND_2(region_set_enabled, RID, p_region, bool, p_enabled) {
452459
NavRegion2D *region = region_owner.get_or_null(p_region);
453460
ERR_FAIL_NULL(region);

modules/navigation_2d/2d/godot_navigation_server_2d.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ class GodotNavigationServer2D : public NavigationServer2D {
144144
virtual Vector2 map_get_random_point(RID p_map, uint32_t p_navigation_layers, bool p_uniformly) const override;
145145

146146
virtual RID region_create() override;
147+
virtual uint32_t region_get_iteration_id(RID p_region) const override;
147148

148149
COMMAND_2(region_set_enabled, RID, p_region, bool, p_enabled);
149150
virtual bool region_get_enabled(RID p_region) const override;

modules/navigation_2d/nav_region_2d.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ bool NavRegion2D::sync() {
178178

179179
update_polygons();
180180

181+
if (something_changed) {
182+
iteration_id = iteration_id % UINT32_MAX + 1;
183+
}
184+
181185
return something_changed;
182186
}
183187

modules/navigation_2d/nav_region_2d.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,16 @@ class NavRegion2D : public NavBase2D {
5959
Vector<Vector2> pending_navmesh_vertices;
6060
Vector<Vector<int>> pending_navmesh_polygons;
6161

62+
uint32_t iteration_id = 0;
63+
6264
SelfList<NavRegion2D> sync_dirty_request_list_element;
6365

6466
public:
6567
NavRegion2D();
6668
~NavRegion2D();
6769

70+
uint32_t get_iteration_id() const { return iteration_id; }
71+
6872
void scratch_polygons() {
6973
polygons_dirty = true;
7074
}

modules/navigation_3d/3d/godot_navigation_server_3d.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,13 @@ RID GodotNavigationServer3D::region_create() {
389389
return rid;
390390
}
391391

392+
uint32_t GodotNavigationServer3D::region_get_iteration_id(RID p_region) const {
393+
NavRegion3D *region = region_owner.get_or_null(p_region);
394+
ERR_FAIL_NULL_V(region, 0);
395+
396+
return region->get_iteration_id();
397+
}
398+
392399
COMMAND_2(region_set_enabled, RID, p_region, bool, p_enabled) {
393400
NavRegion3D *region = region_owner.get_or_null(p_region);
394401
ERR_FAIL_NULL(region);

modules/navigation_3d/3d/godot_navigation_server_3d.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ class GodotNavigationServer3D : public NavigationServer3D {
147147
virtual Vector3 map_get_random_point(RID p_map, uint32_t p_navigation_layers, bool p_uniformly) const override;
148148

149149
virtual RID region_create() override;
150+
virtual uint32_t region_get_iteration_id(RID p_region) const override;
150151

151152
COMMAND_2(region_set_enabled, RID, p_region, bool, p_enabled);
152153
virtual bool region_get_enabled(RID p_region) const override;

modules/navigation_3d/nav_region_3d.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,10 @@ bool NavRegion3D::sync() {
194194

195195
update_polygons();
196196

197+
if (something_changed) {
198+
iteration_id = iteration_id % UINT32_MAX + 1;
199+
}
200+
197201
return something_changed;
198202
}
199203

modules/navigation_3d/nav_region_3d.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,12 +59,16 @@ class NavRegion3D : public NavBase3D {
5959
Vector<Vector3> pending_navmesh_vertices;
6060
Vector<Vector<int>> pending_navmesh_polygons;
6161

62+
uint32_t iteration_id = 0;
63+
6264
SelfList<NavRegion3D> sync_dirty_request_list_element;
6365

6466
public:
6567
NavRegion3D();
6668
~NavRegion3D();
6769

70+
uint32_t get_iteration_id() const { return iteration_id; }
71+
6872
void scratch_polygons() {
6973
polygons_dirty = true;
7074
}

0 commit comments

Comments
 (0)