Skip to content
0.2.0-dev Download ZIP
122 lines ·4.6 KB Raw
1/**************************************************************************/
2/* nav_map_iteration_3d.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_utils_3d.h"
34#include "nav_mesh_queries_3d.h"
35
36#include "core/math/math_defs.h"
37#include "core/os/rw_lock.h"
38#include "core/os/semaphore.h"
39
40class NavLinkIteration3D;
41class NavRegion3D;
42class NavRegionIteration3D;
43struct NavMapIteration3D;
44
45struct NavMapIterationBuild3D {
46 Vector3 merge_rasterizer_cell_size;
47 bool use_edge_connections = true;
48 real_t edge_connection_margin;
49 real_t link_connection_radius;
50 Nav3D::PerformanceData performance_data;
51 int polygon_count = 0;
52 int free_edge_count = 0;
53
54 HashMap<Nav3D::EdgeKey, Nav3D::EdgeConnectionPair, Nav3D::EdgeKey> iter_connection_pairs_map;
55 LocalVector<Nav3D::Connection> iter_free_edges;
56
57 NavMapIteration3D *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
73struct NavMapIteration3D {
74 mutable SafeNumeric<uint32_t> users;
75 RWLock rwlock;
76
77 Vector3 map_up;
78
79 LocalVector<Ref<NavRegionIteration3D>> region_iterations;
80 LocalVector<Ref<NavLinkIteration3D>> link_iterations;
81
82 int navmesh_polygon_count = 0;
83
84 // The edge connections that the map builds on top with the edge connection margin.
85 HashMap<const NavBaseIteration3D *, LocalVector<Nav3D::Connection>> external_region_connections;
86 HashMap<const NavBaseIteration3D *, LocalVector<LocalVector<Nav3D::Connection>>> navbases_polygons_external_connections;
87
88 LocalVector<Nav3D::Polygon> navlink_polygons;
89
90 HashMap<NavRegion3D *, Ref<NavRegionIteration3D>> region_ptr_to_region_iteration;
91
92 LocalVector<NavMeshQueries3D::PathQuerySlot> path_query_slots;
93 Mutex path_query_slots_mutex;
94 Semaphore path_query_slots_semaphore;
95
96 void clear() {
97 map_up = Vector3();
98 navmesh_polygon_count = 0;
99
100 region_iterations.clear();
101 link_iterations.clear();
102 external_region_connections.clear();
103 navbases_polygons_external_connections.clear();
104 navlink_polygons.clear();
105 region_ptr_to_region_iteration.clear();
106 }
107};
108
109class NavMapIterationRead3D {
110 const NavMapIteration3D &map_iteration;
111
112public:
113 _ALWAYS_INLINE_ NavMapIterationRead3D(const NavMapIteration3D &p_iteration) :
114 map_iteration(p_iteration) {
115 map_iteration.rwlock.read_lock();
116 map_iteration.users.increment();
117 }
118 _ALWAYS_INLINE_ ~NavMapIterationRead3D() {
119 map_iteration.users.decrement();
120 map_iteration.rwlock.read_unlock();
121 }
122};