Move NavRegion connections to NavMap
Moves bookkeeping for connections from region to map where connections are actually made.
This commit is contained in:
parent
04bf7d4cad
commit
83bd8fa396
5 changed files with 58 additions and 37 deletions
|
@ -509,22 +509,31 @@ void GodotNavigationServer3D::region_bake_navigation_mesh(Ref<NavigationMesh> p_
|
|||
int GodotNavigationServer3D::region_get_connections_count(RID p_region) const {
|
||||
NavRegion *region = region_owner.get_or_null(p_region);
|
||||
ERR_FAIL_NULL_V(region, 0);
|
||||
|
||||
return region->get_connections_count();
|
||||
NavMap *map = region->get_map();
|
||||
if (map) {
|
||||
return map->get_region_connections_count(region);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Vector3 GodotNavigationServer3D::region_get_connection_pathway_start(RID p_region, int p_connection_id) const {
|
||||
NavRegion *region = region_owner.get_or_null(p_region);
|
||||
ERR_FAIL_NULL_V(region, Vector3());
|
||||
|
||||
return region->get_connection_pathway_start(p_connection_id);
|
||||
NavMap *map = region->get_map();
|
||||
if (map) {
|
||||
return map->get_region_connection_pathway_start(region, p_connection_id);
|
||||
}
|
||||
return Vector3();
|
||||
}
|
||||
|
||||
Vector3 GodotNavigationServer3D::region_get_connection_pathway_end(RID p_region, int p_connection_id) const {
|
||||
NavRegion *region = region_owner.get_or_null(p_region);
|
||||
ERR_FAIL_NULL_V(region, Vector3());
|
||||
|
||||
return region->get_connection_pathway_end(p_connection_id);
|
||||
NavMap *map = region->get_map();
|
||||
if (map) {
|
||||
return map->get_region_connection_pathway_end(region, p_connection_id);
|
||||
}
|
||||
return Vector3();
|
||||
}
|
||||
|
||||
Vector3 GodotNavigationServer3D::region_get_random_point(RID p_region, uint32_t p_navigation_layers, bool p_uniformly) const {
|
||||
|
|
|
@ -916,8 +916,9 @@ void NavMap::sync() {
|
|||
_new_pm_edge_free_count = 0;
|
||||
|
||||
// Remove regions connections.
|
||||
region_external_connections.clear();
|
||||
for (NavRegion *region : regions) {
|
||||
region->get_connections().clear();
|
||||
region_external_connections[region] = LocalVector<gd::Edge::Connection>();
|
||||
}
|
||||
|
||||
// Resize the polygon count.
|
||||
|
@ -1051,7 +1052,7 @@ void NavMap::sync() {
|
|||
free_edge.polygon->edges[free_edge.edge].connections.push_back(new_connection);
|
||||
|
||||
// Add the connection to the region_connection map.
|
||||
((NavRegion *)free_edge.polygon->owner)->get_connections().push_back(new_connection);
|
||||
region_external_connections[(NavRegion *)free_edge.polygon->owner].push_back(new_connection);
|
||||
_new_pm_edge_connection_count += 1;
|
||||
}
|
||||
}
|
||||
|
@ -1413,6 +1414,40 @@ void NavMap::_update_merge_rasterizer_cell_dimensions() {
|
|||
merge_rasterizer_cell_height = cell_height * merge_rasterizer_cell_scale;
|
||||
}
|
||||
|
||||
int NavMap::get_region_connections_count(NavRegion *p_region) const {
|
||||
ERR_FAIL_NULL_V(p_region, 0);
|
||||
|
||||
HashMap<NavRegion *, LocalVector<gd::Edge::Connection>>::ConstIterator found_connections = region_external_connections.find(p_region);
|
||||
if (found_connections) {
|
||||
return found_connections->value.size();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
Vector3 NavMap::get_region_connection_pathway_start(NavRegion *p_region, int p_connection_id) const {
|
||||
ERR_FAIL_NULL_V(p_region, Vector3());
|
||||
|
||||
HashMap<NavRegion *, LocalVector<gd::Edge::Connection>>::ConstIterator found_connections = region_external_connections.find(p_region);
|
||||
if (found_connections) {
|
||||
ERR_FAIL_INDEX_V(p_connection_id, int(found_connections->value.size()), Vector3());
|
||||
return found_connections->value[p_connection_id].pathway_start;
|
||||
}
|
||||
|
||||
return Vector3();
|
||||
}
|
||||
|
||||
Vector3 NavMap::get_region_connection_pathway_end(NavRegion *p_region, int p_connection_id) const {
|
||||
ERR_FAIL_NULL_V(p_region, Vector3());
|
||||
|
||||
HashMap<NavRegion *, LocalVector<gd::Edge::Connection>>::ConstIterator found_connections = region_external_connections.find(p_region);
|
||||
if (found_connections) {
|
||||
ERR_FAIL_INDEX_V(p_connection_id, int(found_connections->value.size()), Vector3());
|
||||
return found_connections->value[p_connection_id].pathway_end;
|
||||
}
|
||||
|
||||
return Vector3();
|
||||
}
|
||||
|
||||
NavMap::NavMap() {
|
||||
avoidance_use_multiple_threads = GLOBAL_GET("navigation/avoidance/thread_model/avoidance_use_multiple_threads");
|
||||
avoidance_use_high_priority_threads = GLOBAL_GET("navigation/avoidance/thread_model/avoidance_use_high_priority_threads");
|
||||
|
|
|
@ -124,6 +124,8 @@ class NavMap : public NavRid {
|
|||
int pm_edge_connection_count = 0;
|
||||
int pm_edge_free_count = 0;
|
||||
|
||||
HashMap<NavRegion *, LocalVector<gd::Edge::Connection>> region_external_connections;
|
||||
|
||||
public:
|
||||
NavMap();
|
||||
~NavMap();
|
||||
|
@ -217,6 +219,10 @@ public:
|
|||
int get_pm_edge_connection_count() const { return pm_edge_connection_count; }
|
||||
int get_pm_edge_free_count() const { return pm_edge_free_count; }
|
||||
|
||||
int get_region_connections_count(NavRegion *p_region) const;
|
||||
Vector3 get_region_connection_pathway_start(NavRegion *p_region, int p_connection_id) const;
|
||||
Vector3 get_region_connection_pathway_end(NavRegion *p_region, int p_connection_id) const;
|
||||
|
||||
private:
|
||||
void compute_single_step(uint32_t index, NavAgent **agent);
|
||||
|
||||
|
|
|
@ -44,8 +44,6 @@ void NavRegion::set_map(NavMap *p_map) {
|
|||
map = p_map;
|
||||
polygons_dirty = true;
|
||||
|
||||
connections.clear();
|
||||
|
||||
if (map) {
|
||||
map->add_region(this);
|
||||
}
|
||||
|
@ -105,25 +103,6 @@ void NavRegion::set_navigation_mesh(Ref<NavigationMesh> p_navigation_mesh) {
|
|||
polygons_dirty = true;
|
||||
}
|
||||
|
||||
int NavRegion::get_connections_count() const {
|
||||
if (!map) {
|
||||
return 0;
|
||||
}
|
||||
return connections.size();
|
||||
}
|
||||
|
||||
Vector3 NavRegion::get_connection_pathway_start(int p_connection_id) const {
|
||||
ERR_FAIL_NULL_V(map, Vector3());
|
||||
ERR_FAIL_INDEX_V(p_connection_id, connections.size(), Vector3());
|
||||
return connections[p_connection_id].pathway_start;
|
||||
}
|
||||
|
||||
Vector3 NavRegion::get_connection_pathway_end(int p_connection_id) const {
|
||||
ERR_FAIL_NULL_V(map, Vector3());
|
||||
ERR_FAIL_INDEX_V(p_connection_id, connections.size(), Vector3());
|
||||
return connections[p_connection_id].pathway_end;
|
||||
}
|
||||
|
||||
Vector3 NavRegion::get_random_point(uint32_t p_navigation_layers, bool p_uniformly) const {
|
||||
if (!get_enabled()) {
|
||||
return Vector3();
|
||||
|
|
|
@ -40,7 +40,6 @@
|
|||
class NavRegion : public NavBase {
|
||||
NavMap *map = nullptr;
|
||||
Transform3D transform;
|
||||
Vector<gd::Edge::Connection> connections;
|
||||
bool enabled = true;
|
||||
|
||||
bool use_edge_connections = true;
|
||||
|
@ -85,13 +84,6 @@ public:
|
|||
|
||||
void set_navigation_mesh(Ref<NavigationMesh> p_navigation_mesh);
|
||||
|
||||
Vector<gd::Edge::Connection> &get_connections() {
|
||||
return connections;
|
||||
}
|
||||
int get_connections_count() const;
|
||||
Vector3 get_connection_pathway_start(int p_connection_id) const;
|
||||
Vector3 get_connection_pathway_end(int p_connection_id) const;
|
||||
|
||||
LocalVector<gd::Polygon> const &get_polygons() const {
|
||||
return polygons;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue