Debian Codegraph @

modules/navigation_3d/nav_region_3d.h

raw symbols SCIP
1 /**************************************************************************/
2 /* nav_region_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_base_3d.h"
34 #include "nav_utils_3d.h"
35
36 #include "core/os/rw_lock.h"
37 #include "scene/resources/navigation_mesh.h"
38
39 #include "3d/nav_region_iteration_3d.h"
40
41 class NavRegion3D : public NavBase3D {
42 RWLock region_rwlock;
43
44 NavMap3D *map = nullptr;
45 Transform3D transform;
46 bool enabled = true;
47
48 bool use_edge_connections = true;
49
50 AABB bounds;
51
52 Ref<NavigationMesh> navmesh;
53
54 Nav3D::PerformanceData performance_data;
55
56 uint32_t iteration_id = 0;
57
58 SelfList<NavRegion3D> sync_dirty_request_list_element;
59 mutable RWLock iteration_rwlock;
60 Ref<NavRegionIteration3D> iteration;
61
62 NavRegionIterationBuild3D iteration_build;
63 bool use_async_iterations = true;
64 SelfList<NavRegion3D> async_list_element;
65 WorkerThreadPool::TaskID iteration_build_thread_task_id = WorkerThreadPool::INVALID_TASK_ID;
66 static void _build_iteration_threaded(void *p_arg);
67
68 bool iteration_dirty = true;
69 bool iteration_building = false;
70 bool iteration_ready = false;
71
72 void _build_iteration();
73 void _sync_iteration();
74
75 public:
76 NavRegion3D();
77 ~NavRegion3D();
78
79 uint32_t get_iteration_id() const { return iteration_id; }
80
81 void scratch_polygons();
82
83 void set_enabled(bool p_enabled);
84 bool get_enabled() const { return enabled; }
85
86 void set_map(NavMap3D *p_map);
87 NavMap3D *get_map() const {
88 return map;
89 }
90
91 virtual void set_use_edge_connections(bool p_enabled) override;
92 virtual bool get_use_edge_connections() const override { return use_edge_connections; }
93
94 void set_transform(Transform3D transform);
95 const Transform3D &get_transform() const {
96 return transform;
97 }
98
99 void set_navigation_mesh(Ref<NavigationMesh> p_navigation_mesh);
100 Ref<NavigationMesh> get_navigation_mesh() const { return navmesh; }
101
102 LocalVector<Nav3D::Polygon> const &get_polygons() const;
103
104 Vector3 get_closest_point_to_segment(const Vector3 &p_from, const Vector3 &p_to, bool p_use_collision) const;
105 Nav3D::ClosestPointQueryResult get_closest_point_info(const Vector3 &p_point) const;
106 Vector3 get_random_point(uint32_t p_navigation_layers, bool p_uniformly) const;
107
108 real_t get_surface_area() const;
109 AABB get_bounds() const;
110
111 // NavBase properties.
112 virtual void set_navigation_layers(uint32_t p_navigation_layers) override;
113 virtual void set_enter_cost(real_t p_enter_cost) override;
114 virtual void set_travel_cost(real_t p_travel_cost) override;
115 virtual void set_owner_id(ObjectID p_owner_id) override;
116
117 bool sync();
118 void request_sync();
119 void cancel_sync_request();
120
121 void sync_async_tasks();
122 void request_async_thread_join();
123 void cancel_async_thread_join();
124
125 Ref<NavRegionIteration3D> get_iteration();
126
127 // Performance Monitor
128 int get_pm_polygon_count() const { return performance_data.pm_polygon_count; }
129 int get_pm_edge_count() const { return performance_data.pm_edge_count; }
130 int get_pm_edge_merge_count() const { return performance_data.pm_edge_merge_count; }
131
132 void set_use_async_iterations(bool p_enabled);
133 bool get_use_async_iterations() const;
134 };