| 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 "core/math/vector3.h" |
| 34 |
#include "core/object/ref_counted.h" |
| 35 |
#include "core/templates/hash_map.h" |
| 36 |
#include "core/templates/hashfuncs.h" |
| 37 |
#include "core/templates/local_vector.h" |
| 38 |
#include "servers/navigation_2d/navigation_constants_2d.h" |
| 39 |
|
| 40 |
class NavBaseIteration2D; |
| 41 |
|
| 42 |
namespace Nav2D { |
| 43 |
struct Polygon; |
| 44 |
|
| 45 |
union PointKey { |
| 46 |
struct { |
| 47 |
int64_t x : 32; |
| 48 |
int64_t y : 32; |
| 49 |
}; |
| 50 |
|
| 51 |
uint64_t key = 0; |
| 52 |
}; |
| 53 |
|
| 54 |
struct EdgeKey { |
| 55 |
PointKey a; |
| 56 |
PointKey b; |
| 57 |
|
| 58 |
static uint32_t hash(const EdgeKey &p_val) { |
| 59 |
return hash_one_uint64(p_val.a.key) ^ hash_one_uint64(p_val.b.key); |
| 60 |
} |
| 61 |
|
| 62 |
bool operator==(const EdgeKey &p_key) const { |
| 63 |
return (a.key == p_key.a.key) && (b.key == p_key.b.key); |
| 64 |
} |
| 65 |
|
| 66 |
EdgeKey(const PointKey &p_a = PointKey(), const PointKey &p_b = PointKey()) : |
| 67 |
a(p_a), |
| 68 |
b(p_b) { |
| 69 |
if (a.key > b.key) { |
| 70 |
SWAP(a, b); |
| 71 |
} |
| 72 |
} |
| 73 |
}; |
| 74 |
|
| 75 |
struct ConnectableEdge { |
| 76 |
EdgeKey ek; |
| 77 |
uint32_t polygon_index; |
| 78 |
int edge = -1; |
| 79 |
Vector2 pathway_start; |
| 80 |
Vector2 pathway_end; |
| 81 |
}; |
| 82 |
|
| 83 |
struct Connection { |
| 84 |
|
| 85 |
Polygon *polygon = nullptr; |
| 86 |
|
| 87 |
|
| 88 |
int edge = -1; |
| 89 |
|
| 90 |
|
| 91 |
Vector2 pathway_start; |
| 92 |
|
| 93 |
|
| 94 |
Vector2 pathway_end; |
| 95 |
}; |
| 96 |
|
| 97 |
struct Polygon { |
| 98 |
uint32_t id = UINT32_MAX; |
| 99 |
|
| 100 |
|
| 101 |
const NavBaseIteration2D *owner = nullptr; |
| 102 |
|
| 103 |
LocalVector<Vector2> vertices; |
| 104 |
|
| 105 |
real_t surface_area = 0.0; |
| 106 |
}; |
| 107 |
|
| 108 |
struct NavigationPoly { |
| 109 |
|
| 110 |
const Polygon *poly = nullptr; |
| 111 |
|
| 112 |
|
| 113 |
uint32_t traversable_poly_index = UINT32_MAX; |
| 114 |
|
| 115 |
|
| 116 |
int back_navigation_poly_id = -1; |
| 117 |
int back_navigation_edge = -1; |
| 118 |
Vector2 back_navigation_edge_pathway_start; |
| 119 |
Vector2 back_navigation_edge_pathway_end; |
| 120 |
|
| 121 |
|
| 122 |
Vector2 entry; |
| 123 |
|
| 124 |
real_t traveled_distance = 0.0; |
| 125 |
|
| 126 |
real_t distance_to_destination = 0.0; |
| 127 |
|
| 128 |
|
| 129 |
real_t total_travel_cost() const { |
| 130 |
return traveled_distance + distance_to_destination; |
| 131 |
} |
| 132 |
|
| 133 |
bool operator==(const NavigationPoly &p_other) const { |
| 134 |
return poly == p_other.poly; |
| 135 |
} |
| 136 |
|
| 137 |
bool operator!=(const NavigationPoly &p_other) const { |
| 138 |
return !(*this == p_other); |
| 139 |
} |
| 140 |
|
| 141 |
void reset() { |
| 142 |
poly = nullptr; |
| 143 |
traversable_poly_index = UINT32_MAX; |
| 144 |
back_navigation_poly_id = -1; |
| 145 |
back_navigation_edge = -1; |
| 146 |
traveled_distance = FLT_MAX; |
| 147 |
distance_to_destination = 0.0; |
| 148 |
} |
| 149 |
}; |
| 150 |
|
| 151 |
struct NavPolyTravelCostGreaterThan { |
| 152 |
|
| 153 |
bool operator()(const NavigationPoly *p_poly_a, const NavigationPoly *p_poly_b) const { |
| 154 |
real_t f_cost_a = p_poly_a->total_travel_cost(); |
| 155 |
real_t h_cost_a = p_poly_a->distance_to_destination; |
| 156 |
real_t f_cost_b = p_poly_b->total_travel_cost(); |
| 157 |
real_t h_cost_b = p_poly_b->distance_to_destination; |
| 158 |
|
| 159 |
if (f_cost_a != f_cost_b) { |
| 160 |
return f_cost_a > f_cost_b; |
| 161 |
} else { |
| 162 |
return h_cost_a > h_cost_b; |
| 163 |
} |
| 164 |
} |
| 165 |
}; |
| 166 |
|
| 167 |
struct NavPolyHeapIndexer { |
| 168 |
void operator()(NavigationPoly *p_poly, uint32_t p_heap_index) const { |
| 169 |
p_poly->traversable_poly_index = p_heap_index; |
| 170 |
} |
| 171 |
}; |
| 172 |
|
| 173 |
struct ClosestPointQueryResult { |
| 174 |
Vector2 point; |
| 175 |
RID owner; |
| 176 |
}; |
| 177 |
|
| 178 |
struct EdgeConnectionPair { |
| 179 |
Connection connections[2]; |
| 180 |
int size = 0; |
| 181 |
}; |
| 182 |
|
| 183 |
struct PerformanceData { |
| 184 |
int pm_region_count = 0; |
| 185 |
int pm_agent_count = 0; |
| 186 |
int pm_link_count = 0; |
| 187 |
int pm_polygon_count = 0; |
| 188 |
int pm_edge_count = 0; |
| 189 |
int pm_edge_merge_count = 0; |
| 190 |
int pm_edge_connection_count = 0; |
| 191 |
int pm_edge_free_count = 0; |
| 192 |
int pm_obstacle_count = 0; |
| 193 |
|
| 194 |
void reset() { |
| 195 |
pm_region_count = 0; |
| 196 |
pm_agent_count = 0; |
| 197 |
pm_link_count = 0; |
| 198 |
pm_polygon_count = 0; |
| 199 |
pm_edge_count = 0; |
| 200 |
pm_edge_merge_count = 0; |
| 201 |
pm_edge_connection_count = 0; |
| 202 |
pm_edge_free_count = 0; |
| 203 |
pm_obstacle_count = 0; |
| 204 |
} |
| 205 |
}; |
| 206 |
|
| 207 |
} |