Skip to content

Commit

Permalink
Patch navigation map async synchronization
Browse files Browse the repository at this point in the history
Patches navigation map async synchronization.
  • Loading branch information
smix8 committed Dec 26, 2024
1 parent 0f95e9f commit 849f25a
Show file tree
Hide file tree
Showing 12 changed files with 749 additions and 425 deletions.
9 changes: 9 additions & 0 deletions modules/navigation/3d/nav_base_iteration_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ struct NavBaseIteration {
ObjectID owner_object_id;
RID owner_rid;
bool owner_use_edge_connections = false;

bool get_enabled() const { return enabled; }
NavigationUtilities::PathSegmentType get_type() const { return owner_type; }
RID get_self() const { return owner_rid; }
ObjectID get_owner_id() const { return owner_object_id; }
uint32_t get_navigation_layers() const { return navigation_layers; }
real_t get_enter_cost() const { return enter_cost; }
real_t get_travel_cost() const { return travel_cost; }
bool get_use_edge_connections() const { return owner_use_edge_connections; }
};

#endif // NAV_BASE_ITERATION_3D_H
627 changes: 479 additions & 148 deletions modules/navigation/3d/nav_map_builder_3d.cpp

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions modules/navigation/3d/nav_map_iteration_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ struct NavMapIteration {

Vector3 map_up;
LocalVector<gd::Polygon> navmesh_polygons;
LocalVector<gd::Polygon> link_polygons;

LocalVector<NavRegionIteration> region_iterations;
LocalVector<NavLinkIteration> link_iterations;
Expand Down
412 changes: 180 additions & 232 deletions modules/navigation/3d/nav_mesh_queries_3d.cpp

Large diffs are not rendered by default.

16 changes: 14 additions & 2 deletions modules/navigation/3d/nav_mesh_queries_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ class NavMeshQueries3D {
Vector3 map_up;
NavMap *map = nullptr;
PathQuerySlot *path_query_slot = nullptr;
uint32_t link_polygons_size = 0;

// Path points.
LocalVector<Vector3> path_points;
Expand All @@ -94,6 +93,20 @@ class NavMeshQueries3D {
Ref<NavigationPathQueryResult3D> query_result;
Callable callback;
NavMeshPathQueryTask3D::TaskStatus status = NavMeshPathQueryTask3D::TaskStatus::QUERY_STARTED;

void path_clear() {
path_points.clear();
path_meta_point_types.clear();
path_meta_point_rids.clear();
path_meta_point_owners.clear();
}

void path_reverse() {
path_points.invert();
path_meta_point_types.invert();
path_meta_point_rids.invert();
path_meta_point_owners.invert();
}
};

static bool emit_callback(const Callable &p_callback);
Expand All @@ -109,7 +122,6 @@ class NavMeshQueries3D {
static void map_query_path(NavMap *map, const Ref<NavigationPathQueryParameters3D> &p_query_parameters, Ref<NavigationPathQueryResult3D> p_query_result, const Callable &p_callback);

static void query_task_polygons_get_path(NavMeshPathQueryTask3D &p_query_task, const LocalVector<gd::Polygon> &p_polygons);
static void _query_task_create_same_polygon_two_point_path(NavMeshPathQueryTask3D &p_query_task, const gd::Polygon *p_begin_polygon, const gd::Polygon *p_end_polygon);
static void _query_task_push_back_point_with_metadata(NavMeshPathQueryTask3D &p_query_task, const Vector3 &p_point, const gd::Polygon *p_point_polygon);
static void _query_task_find_start_end_positions(NavMeshPathQueryTask3D &p_query_task, const LocalVector<gd::Polygon> &p_polygons);
static void _query_task_build_path_corridor(NavMeshPathQueryTask3D &p_query_task, const LocalVector<gd::Polygon> &p_polygons);
Expand Down
5 changes: 5 additions & 0 deletions modules/navigation/3d/nav_region_iteration_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ struct NavRegionIteration : NavBaseIteration {
LocalVector<gd::Polygon> navmesh_polygons;
real_t surface_area = 0.0;
AABB bounds;

const Transform3D &get_transform() const { return transform; }
const LocalVector<gd::Polygon> &get_navmesh_polygons() const { return navmesh_polygons; }
real_t get_surface_area() const { return surface_area; }
AABB get_bounds() const { return bounds; }
};

#endif // NAV_REGION_ITERATION_3D_H
8 changes: 5 additions & 3 deletions modules/navigation/nav_link.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,10 @@ void NavLink::get_iteration_update(NavLinkIteration &r_iteration) {
r_iteration.travel_cost = get_travel_cost();
r_iteration.owner_object_id = get_owner_id();
r_iteration.owner_type = get_type();
r_iteration.owner_rid = get_self();

r_iteration.enabled = enabled;
r_iteration.start_position = start_position;
r_iteration.end_position = end_position;
r_iteration.enabled = get_enabled();
r_iteration.start_position = get_start_position();
r_iteration.end_position = get_end_position();
r_iteration.bidirectional = is_bidirectional();
}
4 changes: 4 additions & 0 deletions modules/navigation/nav_link.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ struct NavLinkIteration : NavBaseIteration {
Vector3 start_position;
Vector3 end_position;
LocalVector<gd::Polygon> navmesh_polygons;

Vector3 get_start_position() const { return start_position; }
Vector3 get_end_position() const { return end_position; }
bool is_bidirectional() const { return bidirectional; }
};

#include "core/templates/self_list.h"
Expand Down
1 change: 0 additions & 1 deletion modules/navigation/nav_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ void NavMap::query_path(NavMeshQueries3D::NavMeshPathQueryTask3D &p_query_task)
}

p_query_task.map_up = map_iteration.map_up;
p_query_task.link_polygons_size = map_iteration.link_polygon_count;

NavMeshQueries3D::query_task_polygons_get_path(p_query_task, map_iteration.navmesh_polygons);

Expand Down
48 changes: 9 additions & 39 deletions modules/navigation/nav_region.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,51 +250,21 @@ void NavRegion::get_iteration_update(NavRegionIteration &r_iteration) {
r_iteration.travel_cost = get_travel_cost();
r_iteration.owner_object_id = get_owner_id();
r_iteration.owner_type = get_type();
r_iteration.owner_rid = get_self();

r_iteration.enabled = enabled;
r_iteration.transform = transform;
r_iteration.owner_use_edge_connections = use_edge_connections;
r_iteration.enabled = get_enabled();
r_iteration.transform = get_transform();
r_iteration.owner_use_edge_connections = get_use_edge_connections();
r_iteration.bounds = get_bounds();
r_iteration.surface_area = get_surface_area();

r_iteration.navmesh_polygons.clear();
r_iteration.navmesh_polygons.resize(navmesh_polygons.size());

for (uint32_t i = 0; i < navmesh_polygons.size(); i++) {
const gd::Polygon &from_polygon = navmesh_polygons[i];
gd::Polygon &to_polygon = r_iteration.navmesh_polygons[i];

to_polygon.surface_area = from_polygon.surface_area;
to_polygon.owner = &r_iteration;
to_polygon.points.resize(from_polygon.points.size());

const LocalVector<gd::Point> &from_points = from_polygon.points;
LocalVector<gd::Point> &to_points = to_polygon.points;

to_points.resize(from_points.size());

for (uint32_t j = 0; j < from_points.size(); j++) {
to_points[j].pos = from_points[j].pos;
to_points[j].key = from_points[j].key;
}

const LocalVector<gd::Edge> &from_edges = from_polygon.edges;
LocalVector<gd::Edge> &to_edges = to_polygon.edges;

to_edges.resize(from_edges.size());

for (uint32_t j = 0; j < from_edges.size(); j++) {
const LocalVector<gd::Edge::Connection> &from_connections = from_edges[j].connections;
LocalVector<gd::Edge::Connection> &to_connections = to_edges[j].connections;

to_connections.resize(from_connections.size());

for (uint32_t k = 0; k < from_connections.size(); k++) {
to_connections[k] = from_connections[k];
}
}
gd::Polygon &navmesh_polygon = navmesh_polygons[i];
navmesh_polygon.owner = &r_iteration;
r_iteration.navmesh_polygons[i] = navmesh_polygon;
}

r_iteration.surface_area = surface_area;
r_iteration.owner_rid = get_self();
}

void NavRegion::request_sync() {
Expand Down
41 changes: 41 additions & 0 deletions servers/navigation/navigation_path_query_result_3d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,47 @@ void NavigationPathQueryResult3D::reset() {
path_owner_ids.clear();
}

void NavigationPathQueryResult3D::set_data(const LocalVector<Vector3> &p_path, const LocalVector<int32_t> &p_path_types, const LocalVector<RID> &p_path_rids, const LocalVector<int64_t> &p_path_owner_ids) {
path.clear();
path_types.clear();
path_rids.clear();
path_owner_ids.clear();

{
path.resize(p_path.size());
Vector3 *w = path.ptrw();
const Vector3 *r = p_path.ptr();
for (uint32_t i = 0; i < p_path.size(); i++) {
w[i] = r[i];
}
}

{
path_types.resize(p_path_types.size());
int32_t *w = path_types.ptrw();
const int32_t *r = p_path_types.ptr();
for (uint32_t i = 0; i < p_path_types.size(); i++) {
w[i] = r[i];
}
}

{
path_rids.resize(p_path_rids.size());
for (uint32_t i = 0; i < p_path_rids.size(); i++) {
path_rids[i] = p_path_rids[i];
}
}

{
path_owner_ids.resize(p_path_owner_ids.size());
int64_t *w = path_owner_ids.ptrw();
const int64_t *r = p_path_owner_ids.ptr();
for (uint32_t i = 0; i < p_path_owner_ids.size(); i++) {
w[i] = r[i];
}
}
}

void NavigationPathQueryResult3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_path", "path"), &NavigationPathQueryResult3D::set_path);
ClassDB::bind_method(D_METHOD("get_path"), &NavigationPathQueryResult3D::get_path);
Expand Down
2 changes: 2 additions & 0 deletions servers/navigation/navigation_path_query_result_3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ class NavigationPathQueryResult3D : public RefCounted {
const Vector<int64_t> &get_path_owner_ids() const;

void reset();

void set_data(const LocalVector<Vector3> &p_path, const LocalVector<int32_t> &p_path_types, const LocalVector<RID> &p_path_rids, const LocalVector<int64_t> &p_path_owner_ids);
};

VARIANT_ENUM_CAST(NavigationPathQueryResult3D::PathSegmentType);
Expand Down

0 comments on commit 849f25a

Please sign in to comment.