Skip to content

Commit 74f5b86

Browse files
committed
Merge pull request #106670 from smix8/ref_iterations
Change navigation region and link updates to an async process
2 parents ef089f2 + 877da26 commit 74f5b86

24 files changed

+1057
-446
lines changed

core/config/project_settings.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1707,6 +1707,7 @@ ProjectSettings::ProjectSettings() {
17071707

17081708
#if !defined(NAVIGATION_2D_DISABLED) || !defined(NAVIGATION_3D_DISABLED)
17091709
GLOBAL_DEF("navigation/world/map_use_async_iterations", true);
1710+
GLOBAL_DEF("navigation/world/region_use_async_iterations", true);
17101711

17111712
GLOBAL_DEF("navigation/avoidance/thread_model/avoidance_use_multiple_threads", true);
17121713
GLOBAL_DEF("navigation/avoidance/thread_model/avoidance_use_high_priority_threads", true);

doc/classes/NavigationServer3D.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,13 @@
10581058
Returns the travel cost of this [param region].
10591059
</description>
10601060
</method>
1061+
<method name="region_get_use_async_iterations" qualifiers="const">
1062+
<return type="bool" />
1063+
<param index="0" name="region" type="RID" />
1064+
<description>
1065+
Returns [code]true[/code] if the [param region] uses an async synchronization process that runs on a background thread.
1066+
</description>
1067+
</method>
10611068
<method name="region_get_use_edge_connections" qualifiers="const">
10621069
<return type="bool" />
10631070
<param index="0" name="region" type="RID" />
@@ -1139,6 +1146,14 @@
11391146
Sets the [param travel_cost] for this [param region].
11401147
</description>
11411148
</method>
1149+
<method name="region_set_use_async_iterations">
1150+
<return type="void" />
1151+
<param index="0" name="region" type="RID" />
1152+
<param index="1" name="enabled" type="bool" />
1153+
<description>
1154+
If [param enabled] is [code]true[/code] the [param region] uses an async synchronization process that runs on a background thread.
1155+
</description>
1156+
</method>
11421157
<method name="region_set_use_edge_connections">
11431158
<return type="void" />
11441159
<param index="0" name="region" type="RID" />

doc/classes/ProjectSettings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2341,6 +2341,9 @@
23412341
<member name="navigation/world/map_use_async_iterations" type="bool" setter="" getter="" default="true">
23422342
If enabled, navigation map synchronization uses an async process that runs on a background thread. This avoids stalling the main thread but adds an additional delay to any navigation map change.
23432343
</member>
2344+
<member name="navigation/world/region_use_async_iterations" type="bool" setter="" getter="" default="true">
2345+
If enabled, navigation region synchronization uses an async process that runs on a background thread. This avoids stalling the main thread but adds an additional delay to any navigation region change.
2346+
</member>
23442347
<member name="network/limits/debugger/max_chars_per_second" type="int" setter="" getter="" default="32768">
23452348
Maximum number of characters allowed to send as output from the debugger. Over this value, content is dropped. This helps not to stall the debugger connection.
23462349
</member>

modules/navigation_3d/3d/godot_navigation_server_3d.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,19 @@ uint32_t GodotNavigationServer3D::region_get_iteration_id(RID p_region) const {
397397
return region->get_iteration_id();
398398
}
399399

400+
COMMAND_2(region_set_use_async_iterations, RID, p_region, bool, p_enabled) {
401+
NavRegion3D *region = region_owner.get_or_null(p_region);
402+
ERR_FAIL_NULL(region);
403+
region->set_use_async_iterations(p_enabled);
404+
}
405+
406+
bool GodotNavigationServer3D::region_get_use_async_iterations(RID p_region) const {
407+
NavRegion3D *region = region_owner.get_or_null(p_region);
408+
ERR_FAIL_NULL_V(region, false);
409+
410+
return region->get_use_async_iterations();
411+
}
412+
400413
COMMAND_2(region_set_enabled, RID, p_region, bool, p_enabled) {
401414
NavRegion3D *region = region_owner.get_or_null(p_region);
402415
ERR_FAIL_NULL(region);

modules/navigation_3d/3d/godot_navigation_server_3d.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,9 @@ class GodotNavigationServer3D : public NavigationServer3D {
149149
virtual RID region_create() override;
150150
virtual uint32_t region_get_iteration_id(RID p_region) const override;
151151

152+
COMMAND_2(region_set_use_async_iterations, RID, p_region, bool, p_enabled);
153+
virtual bool region_get_use_async_iterations(RID p_region) const override;
154+
152155
COMMAND_2(region_set_enabled, RID, p_region, bool, p_enabled);
153156
virtual bool region_get_enabled(RID p_region) const override;
154157

modules/navigation_3d/3d/nav_base_iteration_3d.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,13 @@
3232

3333
#include "../nav_utils_3d.h"
3434

35+
#include "core/object/ref_counted.h"
3536
#include "servers/navigation/navigation_utilities.h"
3637

37-
struct NavBaseIteration3D {
38-
uint32_t id = UINT32_MAX;
38+
class NavBaseIteration3D : public RefCounted {
39+
GDCLASS(NavBaseIteration3D, RefCounted);
40+
41+
public:
3942
bool enabled = true;
4043
uint32_t navigation_layers = 1;
4144
real_t enter_cost = 0.0;
@@ -45,6 +48,7 @@ struct NavBaseIteration3D {
4548
RID owner_rid;
4649
bool owner_use_edge_connections = false;
4750
LocalVector<Nav3D::Polygon> navmesh_polygons;
51+
LocalVector<LocalVector<Nav3D::Connection>> internal_connections;
4852

4953
bool get_enabled() const { return enabled; }
5054
NavigationUtilities::PathSegmentType get_type() const { return owner_type; }
@@ -55,4 +59,10 @@ struct NavBaseIteration3D {
5559
real_t get_travel_cost() const { return travel_cost; }
5660
bool get_use_edge_connections() const { return owner_use_edge_connections; }
5761
const LocalVector<Nav3D::Polygon> &get_navmesh_polygons() const { return navmesh_polygons; }
62+
const LocalVector<LocalVector<Nav3D::Connection>> &get_internal_connections() const { return internal_connections; }
63+
64+
virtual ~NavBaseIteration3D() {
65+
navmesh_polygons.clear();
66+
internal_connections.clear();
67+
}
5868
};

0 commit comments

Comments
 (0)