| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
#pragma once |
| 32 |
|
| 33 |
#include "../nav_rid_2d.h" |
| 34 |
#include "../nav_utils_2d.h" |
| 35 |
#include "nav_mesh_queries_2d.h" |
| 36 |
|
| 37 |
#include "core/math/math_defs.h" |
| 38 |
#include "core/os/semaphore.h" |
| 39 |
|
| 40 |
class NavLinkIteration2D; |
| 41 |
class NavRegion2D; |
| 42 |
class NavRegionIteration2D; |
| 43 |
struct NavMapIteration2D; |
| 44 |
|
| 45 |
struct NavMapIterationBuild2D { |
| 46 |
Vector2 merge_rasterizer_cell_size; |
| 47 |
bool use_edge_connections = true; |
| 48 |
real_t edge_connection_margin; |
| 49 |
real_t link_connection_radius; |
| 50 |
Nav2D::PerformanceData performance_data; |
| 51 |
int polygon_count = 0; |
| 52 |
int free_edge_count = 0; |
| 53 |
|
| 54 |
HashMap<Nav2D::EdgeKey, Nav2D::EdgeConnectionPair, Nav2D::EdgeKey> iter_connection_pairs_map; |
| 55 |
LocalVector<Nav2D::Connection> iter_free_edges; |
| 56 |
|
| 57 |
NavMapIteration2D *map_iteration = nullptr; |
| 58 |
|
| 59 |
int navmesh_polygon_count = 0; |
| 60 |
|
| 61 |
void reset() { |
| 62 |
performance_data.reset(); |
| 63 |
|
| 64 |
iter_connection_pairs_map.clear(); |
| 65 |
iter_free_edges.clear(); |
| 66 |
polygon_count = 0; |
| 67 |
free_edge_count = 0; |
| 68 |
|
| 69 |
navmesh_polygon_count = 0; |
| 70 |
} |
| 71 |
}; |
| 72 |
|
| 73 |
struct NavMapIteration2D { |
| 74 |
mutable SafeNumeric<uint32_t> users; |
| 75 |
RWLock rwlock; |
| 76 |
|
| 77 |
LocalVector<Ref<NavRegionIteration2D>> region_iterations; |
| 78 |
LocalVector<Ref<NavLinkIteration2D>> link_iterations; |
| 79 |
|
| 80 |
int navmesh_polygon_count = 0; |
| 81 |
|
| 82 |
|
| 83 |
HashMap<const NavBaseIteration2D *, LocalVector<Nav2D::Connection>> external_region_connections; |
| 84 |
HashMap<const NavBaseIteration2D *, LocalVector<LocalVector<Nav2D::Connection>>> navbases_polygons_external_connections; |
| 85 |
|
| 86 |
LocalVector<Nav2D::Polygon> navlink_polygons; |
| 87 |
|
| 88 |
HashMap<NavRegion2D *, Ref<NavRegionIteration2D>> region_ptr_to_region_iteration; |
| 89 |
|
| 90 |
LocalVector<NavMeshQueries2D::PathQuerySlot> path_query_slots; |
| 91 |
Mutex path_query_slots_mutex; |
| 92 |
Semaphore path_query_slots_semaphore; |
| 93 |
|
| 94 |
void clear() { |
| 95 |
navmesh_polygon_count = 0; |
| 96 |
|
| 97 |
region_iterations.clear(); |
| 98 |
link_iterations.clear(); |
| 99 |
external_region_connections.clear(); |
| 100 |
navbases_polygons_external_connections.clear(); |
| 101 |
navlink_polygons.clear(); |
| 102 |
region_ptr_to_region_iteration.clear(); |
| 103 |
} |
| 104 |
}; |
| 105 |
|
| 106 |
class NavMapIterationRead2D { |
| 107 |
const NavMapIteration2D &map_iteration; |
| 108 |
|
| 109 |
public: |
| 110 |
_ALWAYS_INLINE_ NavMapIterationRead2D(const NavMapIteration2D &p_iteration) : |
| 111 |
map_iteration(p_iteration) { |
| 112 |
map_iteration.rwlock.read_lock(); |
| 113 |
map_iteration.users.increment(); |
| 114 |
} |
| 115 |
_ALWAYS_INLINE_ ~NavMapIterationRead2D() { |
| 116 |
map_iteration.users.decrement(); |
| 117 |
map_iteration.rwlock.read_unlock(); |
| 118 |
} |
| 119 |
}; |