Debian Codegraph @

modules/navigation_2d/nav_region_2d.h

raw symbols SCIP
1 /**************************************************************************/
2 /* nav_region_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_base_2d.h"
34 #include "nav_utils_2d.h"
35
36 #include "core/os/rw_lock.h"
37 #include "scene/resources/2d/navigation_polygon.h"
38
39 #include "2d/nav_region_iteration_2d.h"
40
41 class NavRegion2D : public NavBase2D {
42 RWLock region_rwlock;
43
44 NavMap2D *map = nullptr;
45 Transform2D transform;
46 bool enabled = true;
47
48 bool use_edge_connections = true;
49
50 Rect2 bounds;
51
52 Ref<NavigationPolygon> navmesh;
53
54 Nav2D::PerformanceData performance_data;
55
56 uint32_t iteration_id = 0;
57
58 SelfList<NavRegion2D> sync_dirty_request_list_element;
59 mutable RWLock iteration_rwlock;
60 Ref<NavRegionIteration2D> iteration;
61
62 NavRegionIterationBuild2D iteration_build;
63 bool use_async_iterations = true;
64 SelfList<NavRegion2D> 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 NavRegion2D();
77 ~NavRegion2D();
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(NavMap2D *p_map);
87 NavMap2D *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(Transform2D transform);
95 const Transform2D &get_transform() const {
96 return transform;
97 }
98
99 void set_navigation_mesh(Ref<NavigationPolygon> p_navigation_mesh);
100 Ref<NavigationPolygon> get_navigation_mesh() const { return navmesh; }
101
102 LocalVector<Nav2D::Polygon> const &get_polygons() const;
103
104 Nav2D::ClosestPointQueryResult get_closest_point_info(const Vector2 &p_point) const;
105 Vector2 get_random_point(uint32_t p_navigation_layers, bool p_uniformly) const;
106
107 real_t get_surface_area() const;
108 Rect2 get_bounds() const;
109
110 // NavBase properties.
111 virtual void set_navigation_layers(uint32_t p_navigation_layers) override;
112 virtual void set_enter_cost(real_t p_enter_cost) override;
113 virtual void set_travel_cost(real_t p_travel_cost) override;
114 virtual void set_owner_id(ObjectID p_owner_id) override;
115
116 bool sync();
117 void request_sync();
118 void cancel_sync_request();
119
120 void sync_async_tasks();
121 void request_async_thread_join();
122 void cancel_async_thread_join();
123
124 Ref<NavRegionIteration2D> get_iteration();
125
126 // Performance Monitor
127 int get_pm_polygon_count() const { return performance_data.pm_polygon_count; }
128 int get_pm_edge_count() const { return performance_data.pm_edge_count; }
129 int get_pm_edge_merge_count() const { return performance_data.pm_edge_merge_count; }
130
131 void set_use_async_iterations(bool p_enabled);
132 bool get_use_async_iterations() const;
133 };