Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/navigation_2d/2d/nav_map_iteration_2d.h
10278 views
1
/**************************************************************************/
2
/* nav_map_iteration_2d.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
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
// The edge connections that the map builds on top with the edge connection margin.
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
};
120
121