Skip to content

Commit

Permalink
Merge pull request godotengine#100497 from smix8/navmap_async_build
Browse files Browse the repository at this point in the history
Change navigation map synchronization to an async process
  • Loading branch information
akien-mga authored Dec 22, 2024
2 parents 0454122 + d51615b commit 216b330
Show file tree
Hide file tree
Showing 29 changed files with 1,266 additions and 481 deletions.
15 changes: 15 additions & 0 deletions doc/classes/NavigationServer2D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,13 @@
Returns all navigation regions [RID]s that are currently assigned to the requested navigation [param map].
</description>
</method>
<method name="map_get_use_async_iterations" qualifiers="const">
<return type="bool" />
<param index="0" name="map" type="RID" />
<description>
Returns [code]true[/code] if the [param map] synchronization uses an async process that runs on a background thread.
</description>
</method>
<method name="map_get_use_edge_connections" qualifiers="const">
<return type="bool" />
<param index="0" name="map" type="RID" />
Expand Down Expand Up @@ -608,6 +615,14 @@
Set the map's link connection radius used to connect links to navigation polygons.
</description>
</method>
<method name="map_set_use_async_iterations">
<return type="void" />
<param index="0" name="map" type="RID" />
<param index="1" name="enabled" type="bool" />
<description>
If [param enabled] is [code]true[/code] the [param map] synchronization uses an async process that runs on a background thread.
</description>
</method>
<method name="map_set_use_edge_connections">
<return type="void" />
<param index="0" name="map" type="RID" />
Expand Down
15 changes: 15 additions & 0 deletions doc/classes/NavigationServer3D.xml
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,13 @@
Returns the map's up direction.
</description>
</method>
<method name="map_get_use_async_iterations" qualifiers="const">
<return type="bool" />
<param index="0" name="map" type="RID" />
<description>
Returns [code]true[/code] if the [param map] synchronization uses an async process that runs on a background thread.
</description>
</method>
<method name="map_get_use_edge_connections" qualifiers="const">
<return type="bool" />
<param index="0" name="map" type="RID" />
Expand Down Expand Up @@ -711,6 +718,14 @@
Sets the map up direction.
</description>
</method>
<method name="map_set_use_async_iterations">
<return type="void" />
<param index="0" name="map" type="RID" />
<param index="1" name="enabled" type="bool" />
<description>
If [param enabled] is [code]true[/code] the [param map] synchronization uses an async process that runs on a background thread.
</description>
</method>
<method name="map_set_use_edge_connections">
<return type="void" />
<param index="0" name="map" type="RID" />
Expand Down
3 changes: 3 additions & 0 deletions doc/classes/ProjectSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2165,6 +2165,9 @@
<member name="navigation/pathfinding/max_threads" type="int" setter="" getter="" default="4">
Maximum number of threads that can run pathfinding queries simultaneously on the same pathfinding graph, for example the same navigation map. Additional threads increase memory consumption and synchronization time due to the need for extra data copies prepared for each thread. A value of [code]-1[/code] means unlimited and the maximum available OS processor count is used. Defaults to [code]1[/code] when the OS does not support threads.
</member>
<member name="navigation/world/map_use_async_iterations" type="bool" setter="" getter="" default="true">
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.
</member>
<member name="network/limits/debugger/max_chars_per_second" type="int" setter="" getter="" default="32768">
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.
</member>
Expand Down
8 changes: 8 additions & 0 deletions modules/navigation/2d/godot_navigation_server_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,14 @@ uint32_t GodotNavigationServer2D::map_get_iteration_id(RID p_map) const {
return NavigationServer3D::get_singleton()->map_get_iteration_id(p_map);
}

void GodotNavigationServer2D::map_set_use_async_iterations(RID p_map, bool p_enabled) {
return NavigationServer3D::get_singleton()->map_set_use_async_iterations(p_map, p_enabled);
}

bool GodotNavigationServer2D::map_get_use_async_iterations(RID p_map) const {
return NavigationServer3D::get_singleton()->map_get_use_async_iterations(p_map);
}

void FORWARD_2(map_set_cell_size, RID, p_map, real_t, p_cell_size, rid_to_rid, real_to_real);
real_t FORWARD_1_C(map_get_cell_size, RID, p_map, rid_to_rid);

Expand Down
2 changes: 2 additions & 0 deletions modules/navigation/2d/godot_navigation_server_2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ class GodotNavigationServer2D : public NavigationServer2D {
virtual void map_force_update(RID p_map) override;
virtual Vector2 map_get_random_point(RID p_map, uint32_t p_navigation_layers, bool p_uniformly) const override;
virtual uint32_t map_get_iteration_id(RID p_map) const override;
virtual void map_set_use_async_iterations(RID p_map, bool p_enabled) override;
virtual bool map_get_use_async_iterations(RID p_map) const override;

virtual RID region_create() override;
virtual void region_set_enabled(RID p_region, bool p_enabled) override;
Expand Down
13 changes: 13 additions & 0 deletions modules/navigation/3d/godot_navigation_server_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,19 @@ RID GodotNavigationServer3D::agent_get_map(RID p_agent) const {
return RID();
}

COMMAND_2(map_set_use_async_iterations, RID, p_map, bool, p_enabled) {
NavMap *map = map_owner.get_or_null(p_map);
ERR_FAIL_NULL(map);
map->set_use_async_iterations(p_enabled);
}

bool GodotNavigationServer3D::map_get_use_async_iterations(RID p_map) const {
const NavMap *map = map_owner.get_or_null(p_map);
ERR_FAIL_NULL_V(map, false);

return map->get_use_async_iterations();
}

Vector3 GodotNavigationServer3D::map_get_random_point(RID p_map, uint32_t p_navigation_layers, bool p_uniformly) const {
const NavMap *map = map_owner.get_or_null(p_map);
ERR_FAIL_NULL_V(map, Vector3());
Expand Down
3 changes: 3 additions & 0 deletions modules/navigation/3d/godot_navigation_server_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,9 @@ class GodotNavigationServer3D : public NavigationServer3D {
virtual void map_force_update(RID p_map) override;
virtual uint32_t map_get_iteration_id(RID p_map) const override;

COMMAND_2(map_set_use_async_iterations, RID, p_map, bool, p_enabled);
virtual bool map_get_use_async_iterations(RID p_map) const override;

virtual Vector3 map_get_random_point(RID p_map, uint32_t p_navigation_layers, bool p_uniformly) const override;

virtual RID region_create() override;
Expand Down
48 changes: 48 additions & 0 deletions modules/navigation/3d/nav_base_iteration_3d.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**************************************************************************/
/* nav_base_iteration_3d.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#ifndef NAV_BASE_ITERATION_3D_H
#define NAV_BASE_ITERATION_3D_H

#include "servers/navigation/navigation_utilities.h"

struct NavBaseIteration {
uint32_t id = UINT32_MAX;
bool enabled = true;
uint32_t navigation_layers = 1;
real_t enter_cost = 0.0;
real_t travel_cost = 1.0;
NavigationUtilities::PathSegmentType owner_type;
ObjectID owner_object_id;
RID owner_rid;
bool owner_use_edge_connections = false;
};

#endif // NAV_BASE_ITERATION_3D_H
Loading

0 comments on commit 216b330

Please sign in to comment.