1/**************************************************************************/
2/* navigation_server_2d.cpp */
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#include "servers/navigation_server_2d.h"
32
33#include "core/math/transform_2d.h"
34#include "core/math/transform_3d.h"
35#include "servers/navigation_server_3d.h"
36
37NavigationServer2D *NavigationServer2D::singleton = nullptr;
38
39#define FORWARD_0(FUNC_NAME) \
40 NavigationServer2D::FUNC_NAME() { \
41 return NavigationServer3D::get_singleton()->FUNC_NAME(); \
42 }
43
44#define FORWARD_0_C(FUNC_NAME) \
45 NavigationServer2D::FUNC_NAME() \
46 const { \
47 return NavigationServer3D::get_singleton()->FUNC_NAME(); \
48 }
49
50#define FORWARD_1(FUNC_NAME, T_0, D_0, CONV_0) \
51 NavigationServer2D::FUNC_NAME(T_0 D_0) { \
52 return NavigationServer3D::get_singleton()->FUNC_NAME(CONV_0(D_0)); \
53 }
54
55#define FORWARD_1_C(FUNC_NAME, T_0, D_0, CONV_0) \
56 NavigationServer2D::FUNC_NAME(T_0 D_0) \
57 const { \
58 return NavigationServer3D::get_singleton()->FUNC_NAME(CONV_0(D_0)); \
59 }
60
61#define FORWARD_1_R_C(CONV_R, FUNC_NAME, T_0, D_0, CONV_0) \
62 NavigationServer2D::FUNC_NAME(T_0 D_0) \
63 const { \
64 return CONV_R(NavigationServer3D::get_singleton()->FUNC_NAME(CONV_0(D_0))); \
65 }
66
67#define FORWARD_2(FUNC_NAME, T_0, D_0, T_1, D_1, CONV_0, CONV_1) \
68 NavigationServer2D::FUNC_NAME(T_0 D_0, T_1 D_1) { \
69 return NavigationServer3D::get_singleton()->FUNC_NAME(CONV_0(D_0), CONV_1(D_1)); \
70 }
71
72#define FORWARD_2_C(FUNC_NAME, T_0, D_0, T_1, D_1, CONV_0, CONV_1) \
73 NavigationServer2D::FUNC_NAME(T_0 D_0, T_1 D_1) \
74 const { \
75 return NavigationServer3D::get_singleton()->FUNC_NAME(CONV_0(D_0), CONV_1(D_1)); \
76 }
77
78#define FORWARD_2_R_C(CONV_R, FUNC_NAME, T_0, D_0, T_1, D_1, CONV_0, CONV_1) \
79 NavigationServer2D::FUNC_NAME(T_0 D_0, T_1 D_1) \
80 const { \
81 return CONV_R(NavigationServer3D::get_singleton()->FUNC_NAME(CONV_0(D_0), CONV_1(D_1))); \
82 }
83
84#define FORWARD_5_R_C(CONV_R, FUNC_NAME, T_0, D_0, T_1, D_1, T_2, D_2, T_3, D_3, T_4, D_4, CONV_0, CONV_1, CONV_2, CONV_3, CONV_4) \
85 NavigationServer2D::FUNC_NAME(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3, T_4 D_4) \
86 const { \
87 return CONV_R(NavigationServer3D::get_singleton()->FUNC_NAME(CONV_0(D_0), CONV_1(D_1), CONV_2(D_2), CONV_3(D_3), CONV_4(D_4))); \
88 }
89
90static RID rid_to_rid(const RID d) {
91 return d;
92}
93
94static bool bool_to_bool(const bool d) {
95 return d;
96}
97
98static int int_to_int(const int d) {
99 return d;
100}
101
102static uint32_t uint32_to_uint32(const uint32_t d) {
103 return d;
104}
105
106static real_t real_to_real(const real_t d) {
107 return d;
108}
109
110static Vector3 v2_to_v3(const Vector2 d) {
111 return Vector3(d.x, 0.0, d.y);
112}
113
114static Vector2 v3_to_v2(const Vector3 &d) {
115 return Vector2(d.x, d.z);
116}
117
118static Vector<Vector3> vector_v2_to_v3(const Vector<Vector2> &d) {
119 Vector<Vector3> nd;
120 nd.resize(d.size());
121 for (int i(0); i < nd.size(); i++) {
122 nd.write[i] = v2_to_v3(d[i]);
123 }
124 return nd;
125}
126
127static Vector<Vector2> vector_v3_to_v2(const Vector<Vector3> &d) {
128 Vector<Vector2> nd;
129 nd.resize(d.size());
130 for (int i(0); i < nd.size(); i++) {
131 nd.write[i] = v3_to_v2(d[i]);
132 }
133 return nd;
134}
135
136static Transform3D trf2_to_trf3(const Transform2D &d) {
137 Vector3 o(v2_to_v3(d.get_origin()));
138 Basis b;
139 b.rotate(Vector3(0, -1, 0), d.get_rotation());
140 b.scale(v2_to_v3(d.get_scale()));
141 return Transform3D(b, o);
142}
143
144static ObjectID id_to_id(const ObjectID &id) {
145 return id;
146}
147
148static Callable callable_to_callable(const Callable &c) {
149 return c;
150}
151
152static Ref<NavigationMesh> poly_to_mesh(Ref<NavigationPolygon> d) {
153 if (d.is_valid()) {
154 return d->get_navigation_mesh();
155 } else {
156 return Ref<NavigationMesh>();
157 }
158}
159
160void NavigationServer2D::_emit_map_changed(RID p_map) {
161 emit_signal(SNAME("map_changed"), p_map);
162}
163
164void NavigationServer2D::set_debug_enabled(bool p_enabled) {
165 NavigationServer3D::get_singleton()->set_debug_enabled(p_enabled);
166}
167
168bool NavigationServer2D::get_debug_enabled() const {
169 return NavigationServer3D::get_singleton()->get_debug_enabled();
170}
171
172#ifdef DEBUG_ENABLED
173void NavigationServer2D::set_debug_navigation_enabled(bool p_enabled) {
174 NavigationServer3D::get_singleton()->set_debug_navigation_enabled(p_enabled);
175}
176
177bool NavigationServer2D::get_debug_navigation_enabled() const {
178 return NavigationServer3D::get_singleton()->get_debug_navigation_enabled();
179}
180
181void NavigationServer2D::set_debug_avoidance_enabled(bool p_enabled) {
182 NavigationServer3D::get_singleton()->set_debug_avoidance_enabled(p_enabled);
183}
184
185bool NavigationServer2D::get_debug_avoidance_enabled() const {
186 return NavigationServer3D::get_singleton()->get_debug_avoidance_enabled();
187}
188
189void NavigationServer2D::set_debug_navigation_edge_connection_color(const Color &p_color) {
190 NavigationServer3D::get_singleton()->set_debug_navigation_edge_connection_color(p_color);
191}
192
193Color NavigationServer2D::get_debug_navigation_edge_connection_color() const {
194 return NavigationServer3D::get_singleton()->get_debug_navigation_edge_connection_color();
195}
196
197void NavigationServer2D::set_debug_navigation_geometry_face_color(const Color &p_color) {
198 NavigationServer3D::get_singleton()->set_debug_navigation_geometry_face_color(p_color);
199}
200
201Color NavigationServer2D::get_debug_navigation_geometry_face_color() const {
202 return NavigationServer3D::get_singleton()->get_debug_navigation_geometry_face_color();
203}
204
205void NavigationServer2D::set_debug_navigation_geometry_face_disabled_color(const Color &p_color) {
206 NavigationServer3D::get_singleton()->set_debug_navigation_geometry_face_disabled_color(p_color);
207}
208
209Color NavigationServer2D::get_debug_navigation_geometry_face_disabled_color() const {
210 return NavigationServer3D::get_singleton()->get_debug_navigation_geometry_face_disabled_color();
211}
212
213void NavigationServer2D::set_debug_navigation_link_connection_color(const Color &p_color) {
214 NavigationServer3D::get_singleton()->set_debug_navigation_link_connection_color(p_color);
215}
216
217Color NavigationServer2D::get_debug_navigation_link_connection_color() const {
218 return NavigationServer3D::get_singleton()->get_debug_navigation_link_connection_color();
219}
220
221void NavigationServer2D::set_debug_navigation_link_connection_disabled_color(const Color &p_color) {
222 NavigationServer3D::get_singleton()->set_debug_navigation_link_connection_disabled_color(p_color);
223}
224
225Color NavigationServer2D::get_debug_navigation_link_connection_disabled_color() const {
226 return NavigationServer3D::get_singleton()->get_debug_navigation_link_connection_disabled_color();
227}
228
229void NavigationServer2D::set_debug_navigation_geometry_edge_color(const Color &p_color) {
230 NavigationServer3D::get_singleton()->set_debug_navigation_geometry_edge_color(p_color);
231}
232
233Color NavigationServer2D::get_debug_navigation_geometry_edge_color() const {
234 return NavigationServer3D::get_singleton()->get_debug_navigation_geometry_edge_color();
235}
236
237void NavigationServer2D::set_debug_navigation_geometry_edge_disabled_color(const Color &p_color) {
238 NavigationServer3D::get_singleton()->set_debug_navigation_geometry_edge_disabled_color(p_color);
239}
240
241Color NavigationServer2D::get_debug_navigation_geometry_edge_disabled_color() const {
242 return NavigationServer3D::get_singleton()->get_debug_navigation_geometry_edge_disabled_color();
243}
244
245void NavigationServer2D::set_debug_navigation_enable_edge_connections(const bool p_value) {
246 NavigationServer3D::get_singleton()->set_debug_navigation_enable_edge_connections(p_value);
247}
248
249bool NavigationServer2D::get_debug_navigation_enable_edge_connections() const {
250 return NavigationServer3D::get_singleton()->get_debug_navigation_enable_edge_connections();
251}
252
253void NavigationServer2D::set_debug_navigation_enable_geometry_face_random_color(const bool p_value) {
254 NavigationServer3D::get_singleton()->set_debug_navigation_enable_geometry_face_random_color(p_value);
255}
256
257bool NavigationServer2D::get_debug_navigation_enable_geometry_face_random_color() const {
258 return NavigationServer3D::get_singleton()->get_debug_navigation_enable_geometry_face_random_color();
259}
260
261void NavigationServer2D::set_debug_navigation_enable_edge_lines(const bool p_value) {
262 NavigationServer3D::get_singleton()->set_debug_navigation_enable_edge_lines(p_value);
263}
264
265bool NavigationServer2D::get_debug_navigation_enable_edge_lines() const {
266 return NavigationServer3D::get_singleton()->get_debug_navigation_enable_edge_lines();
267}
268
269void NavigationServer2D::set_debug_navigation_agent_path_color(const Color &p_color) {
270 NavigationServer3D::get_singleton()->set_debug_navigation_agent_path_color(p_color);
271}
272
273Color NavigationServer2D::get_debug_navigation_agent_path_color() const {
274 return NavigationServer3D::get_singleton()->get_debug_navigation_agent_path_color();
275}
276
277void NavigationServer2D::set_debug_navigation_enable_agent_paths(const bool p_value) {
278 NavigationServer3D::get_singleton()->set_debug_navigation_enable_agent_paths(p_value);
279}
280
281bool NavigationServer2D::get_debug_navigation_enable_agent_paths() const {
282 return NavigationServer3D::get_singleton()->get_debug_navigation_enable_agent_paths();
283}
284
285void NavigationServer2D::set_debug_navigation_agent_path_point_size(real_t p_point_size) {
286 NavigationServer3D::get_singleton()->set_debug_navigation_agent_path_point_size(p_point_size);
287}
288
289real_t NavigationServer2D::get_debug_navigation_agent_path_point_size() const {
290 return NavigationServer3D::get_singleton()->get_debug_navigation_agent_path_point_size();
291}
292
293void NavigationServer2D::set_debug_navigation_avoidance_enable_agents_radius(const bool p_value) {
294 NavigationServer3D::get_singleton()->set_debug_navigation_avoidance_enable_agents_radius(p_value);
295}
296
297bool NavigationServer2D::get_debug_navigation_avoidance_enable_agents_radius() const {
298 return NavigationServer3D::get_singleton()->get_debug_navigation_avoidance_enable_agents_radius();
299}
300
301void NavigationServer2D::set_debug_navigation_avoidance_enable_obstacles_radius(const bool p_value) {
302 NavigationServer3D::get_singleton()->set_debug_navigation_avoidance_enable_obstacles_radius(p_value);
303}
304
305bool NavigationServer2D::get_debug_navigation_avoidance_enable_obstacles_radius() const {
306 return NavigationServer3D::get_singleton()->get_debug_navigation_avoidance_enable_obstacles_radius();
307}
308
309void NavigationServer2D::set_debug_navigation_avoidance_agents_radius_color(const Color &p_color) {
310 NavigationServer3D::get_singleton()->set_debug_navigation_avoidance_agents_radius_color(p_color);
311}
312
313Color NavigationServer2D::get_debug_navigation_avoidance_agents_radius_color() const {
314 return NavigationServer3D::get_singleton()->get_debug_navigation_avoidance_agents_radius_color();
315}
316
317void NavigationServer2D::set_debug_navigation_avoidance_obstacles_radius_color(const Color &p_color) {
318 NavigationServer3D::get_singleton()->set_debug_navigation_avoidance_obstacles_radius_color(p_color);
319}
320
321Color NavigationServer2D::get_debug_navigation_avoidance_obstacles_radius_color() const {
322 return NavigationServer3D::get_singleton()->get_debug_navigation_avoidance_obstacles_radius_color();
323}
324
325void NavigationServer2D::set_debug_navigation_avoidance_static_obstacle_pushin_face_color(const Color &p_color) {
326 NavigationServer3D::get_singleton()->set_debug_navigation_avoidance_static_obstacle_pushin_face_color(p_color);
327}
328
329Color NavigationServer2D::get_debug_navigation_avoidance_static_obstacle_pushin_face_color() const {
330 return NavigationServer3D::get_singleton()->get_debug_navigation_avoidance_static_obstacle_pushin_face_color();
331}
332
333void NavigationServer2D::set_debug_navigation_avoidance_static_obstacle_pushout_face_color(const Color &p_color) {
334 NavigationServer3D::get_singleton()->set_debug_navigation_avoidance_static_obstacle_pushout_face_color(p_color);
335}
336
337Color NavigationServer2D::get_debug_navigation_avoidance_static_obstacle_pushout_face_color() const {
338 return NavigationServer3D::get_singleton()->get_debug_navigation_avoidance_static_obstacle_pushout_face_color();
339}
340
341void NavigationServer2D::set_debug_navigation_avoidance_static_obstacle_pushin_edge_color(const Color &p_color) {
342 NavigationServer3D::get_singleton()->set_debug_navigation_avoidance_static_obstacle_pushin_edge_color(p_color);
343}
344
345Color NavigationServer2D::get_debug_navigation_avoidance_static_obstacle_pushin_edge_color() const {
346 return NavigationServer3D::get_singleton()->get_debug_navigation_avoidance_static_obstacle_pushin_edge_color();
347}
348
349void NavigationServer2D::set_debug_navigation_avoidance_static_obstacle_pushout_edge_color(const Color &p_color) {
350 NavigationServer3D::get_singleton()->set_debug_navigation_avoidance_static_obstacle_pushout_edge_color(p_color);
351}
352
353Color NavigationServer2D::get_debug_navigation_avoidance_static_obstacle_pushout_edge_color() const {
354 return NavigationServer3D::get_singleton()->get_debug_navigation_avoidance_static_obstacle_pushout_edge_color();
355}
356
357void NavigationServer2D::set_debug_navigation_avoidance_enable_obstacles_static(const bool p_value) {
358 NavigationServer3D::get_singleton()->set_debug_navigation_avoidance_enable_obstacles_static(p_value);
359}
360
361bool NavigationServer2D::get_debug_navigation_avoidance_enable_obstacles_static() const {
362 return NavigationServer3D::get_singleton()->get_debug_navigation_avoidance_enable_obstacles_static();
363}
364#endif // DEBUG_ENABLED
365
366void NavigationServer2D::_bind_methods() {
367 ClassDB::bind_method(D_METHOD("get_maps"), &NavigationServer2D::get_maps);
368
369 ClassDB::bind_method(D_METHOD("map_create"), &NavigationServer2D::map_create);
370 ClassDB::bind_method(D_METHOD("map_set_active", "map", "active"), &NavigationServer2D::map_set_active);
371 ClassDB::bind_method(D_METHOD("map_is_active", "map"), &NavigationServer2D::map_is_active);
372 ClassDB::bind_method(D_METHOD("map_set_cell_size", "map", "cell_size"), &NavigationServer2D::map_set_cell_size);
373 ClassDB::bind_method(D_METHOD("map_get_cell_size", "map"), &NavigationServer2D::map_get_cell_size);
374 ClassDB::bind_method(D_METHOD("map_set_use_edge_connections", "map", "enabled"), &NavigationServer2D::map_set_use_edge_connections);
375 ClassDB::bind_method(D_METHOD("map_get_use_edge_connections", "map"), &NavigationServer2D::map_get_use_edge_connections);
376 ClassDB::bind_method(D_METHOD("map_set_edge_connection_margin", "map", "margin"), &NavigationServer2D::map_set_edge_connection_margin);
377 ClassDB::bind_method(D_METHOD("map_get_edge_connection_margin", "map"), &NavigationServer2D::map_get_edge_connection_margin);
378 ClassDB::bind_method(D_METHOD("map_set_link_connection_radius", "map", "radius"), &NavigationServer2D::map_set_link_connection_radius);
379 ClassDB::bind_method(D_METHOD("map_get_link_connection_radius", "map"), &NavigationServer2D::map_get_link_connection_radius);
380 ClassDB::bind_method(D_METHOD("map_get_path", "map", "origin", "destination", "optimize", "navigation_layers"), &NavigationServer2D::map_get_path, DEFVAL(1));
381 ClassDB::bind_method(D_METHOD("map_get_closest_point", "map", "to_point"), &NavigationServer2D::map_get_closest_point);
382 ClassDB::bind_method(D_METHOD("map_get_closest_point_owner", "map", "to_point"), &NavigationServer2D::map_get_closest_point_owner);
383
384 ClassDB::bind_method(D_METHOD("map_get_links", "map"), &NavigationServer2D::map_get_links);
385 ClassDB::bind_method(D_METHOD("map_get_regions", "map"), &NavigationServer2D::map_get_regions);
386 ClassDB::bind_method(D_METHOD("map_get_agents", "map"), &NavigationServer2D::map_get_agents);
387 ClassDB::bind_method(D_METHOD("map_get_obstacles", "map"), &NavigationServer2D::map_get_obstacles);
388
389 ClassDB::bind_method(D_METHOD("map_force_update", "map"), &NavigationServer2D::map_force_update);
390
391 ClassDB::bind_method(D_METHOD("query_path", "parameters", "result"), &NavigationServer2D::query_path);
392
393 ClassDB::bind_method(D_METHOD("region_create"), &NavigationServer2D::region_create);
394 ClassDB::bind_method(D_METHOD("region_set_enabled", "region", "enabled"), &NavigationServer2D::region_set_enabled);
395 ClassDB::bind_method(D_METHOD("region_get_enabled", "region"), &NavigationServer2D::region_get_enabled);
396 ClassDB::bind_method(D_METHOD("region_set_use_edge_connections", "region", "enabled"), &NavigationServer2D::region_set_use_edge_connections);
397 ClassDB::bind_method(D_METHOD("region_get_use_edge_connections", "region"), &NavigationServer2D::region_get_use_edge_connections);
398 ClassDB::bind_method(D_METHOD("region_set_enter_cost", "region", "enter_cost"), &NavigationServer2D::region_set_enter_cost);
399 ClassDB::bind_method(D_METHOD("region_get_enter_cost", "region"), &NavigationServer2D::region_get_enter_cost);
400 ClassDB::bind_method(D_METHOD("region_set_travel_cost", "region", "travel_cost"), &NavigationServer2D::region_set_travel_cost);
401 ClassDB::bind_method(D_METHOD("region_get_travel_cost", "region"), &NavigationServer2D::region_get_travel_cost);
402 ClassDB::bind_method(D_METHOD("region_set_owner_id", "region", "owner_id"), &NavigationServer2D::region_set_owner_id);
403 ClassDB::bind_method(D_METHOD("region_get_owner_id", "region"), &NavigationServer2D::region_get_owner_id);
404 ClassDB::bind_method(D_METHOD("region_owns_point", "region", "point"), &NavigationServer2D::region_owns_point);
405 ClassDB::bind_method(D_METHOD("region_set_map", "region", "map"), &NavigationServer2D::region_set_map);
406 ClassDB::bind_method(D_METHOD("region_get_map", "region"), &NavigationServer2D::region_get_map);
407 ClassDB::bind_method(D_METHOD("region_set_navigation_layers", "region", "navigation_layers"), &NavigationServer2D::region_set_navigation_layers);
408 ClassDB::bind_method(D_METHOD("region_get_navigation_layers", "region"), &NavigationServer2D::region_get_navigation_layers);
409 ClassDB::bind_method(D_METHOD("region_set_transform", "region", "transform"), &NavigationServer2D::region_set_transform);
410 ClassDB::bind_method(D_METHOD("region_set_navigation_polygon", "region", "navigation_polygon"), &NavigationServer2D::region_set_navigation_polygon);
411 ClassDB::bind_method(D_METHOD("region_get_connections_count", "region"), &NavigationServer2D::region_get_connections_count);
412 ClassDB::bind_method(D_METHOD("region_get_connection_pathway_start", "region", "connection"), &NavigationServer2D::region_get_connection_pathway_start);
413 ClassDB::bind_method(D_METHOD("region_get_connection_pathway_end", "region", "connection"), &NavigationServer2D::region_get_connection_pathway_end);
414
415 ClassDB::bind_method(D_METHOD("link_create"), &NavigationServer2D::link_create);
416 ClassDB::bind_method(D_METHOD("link_set_map", "link", "map"), &NavigationServer2D::link_set_map);
417 ClassDB::bind_method(D_METHOD("link_get_map", "link"), &NavigationServer2D::link_get_map);
418 ClassDB::bind_method(D_METHOD("link_set_enabled", "link", "enabled"), &NavigationServer2D::link_set_enabled);
419 ClassDB::bind_method(D_METHOD("link_get_enabled", "link"), &NavigationServer2D::link_get_enabled);
420 ClassDB::bind_method(D_METHOD("link_set_bidirectional", "link", "bidirectional"), &NavigationServer2D::link_set_bidirectional);
421 ClassDB::bind_method(D_METHOD("link_is_bidirectional", "link"), &NavigationServer2D::link_is_bidirectional);
422 ClassDB::bind_method(D_METHOD("link_set_navigation_layers", "link", "navigation_layers"), &NavigationServer2D::link_set_navigation_layers);
423 ClassDB::bind_method(D_METHOD("link_get_navigation_layers", "link"), &NavigationServer2D::link_get_navigation_layers);
424 ClassDB::bind_method(D_METHOD("link_set_start_position", "link", "position"), &NavigationServer2D::link_set_start_position);
425 ClassDB::bind_method(D_METHOD("link_get_start_position", "link"), &NavigationServer2D::link_get_start_position);
426 ClassDB::bind_method(D_METHOD("link_set_end_position", "link", "position"), &NavigationServer2D::link_set_end_position);
427 ClassDB::bind_method(D_METHOD("link_get_end_position", "link"), &NavigationServer2D::link_get_end_position);
428 ClassDB::bind_method(D_METHOD("link_set_enter_cost", "link", "enter_cost"), &NavigationServer2D::link_set_enter_cost);
429 ClassDB::bind_method(D_METHOD("link_get_enter_cost", "link"), &NavigationServer2D::link_get_enter_cost);
430 ClassDB::bind_method(D_METHOD("link_set_travel_cost", "link", "travel_cost"), &NavigationServer2D::link_set_travel_cost);
431 ClassDB::bind_method(D_METHOD("link_get_travel_cost", "link"), &NavigationServer2D::link_get_travel_cost);
432 ClassDB::bind_method(D_METHOD("link_set_owner_id", "link", "owner_id"), &NavigationServer2D::link_set_owner_id);
433 ClassDB::bind_method(D_METHOD("link_get_owner_id", "link"), &NavigationServer2D::link_get_owner_id);
434
435 ClassDB::bind_method(D_METHOD("agent_create"), &NavigationServer2D::agent_create);
436 ClassDB::bind_method(D_METHOD("agent_set_avoidance_enabled", "agent", "enabled"), &NavigationServer2D::agent_set_avoidance_enabled);
437 ClassDB::bind_method(D_METHOD("agent_get_avoidance_enabled", "agent"), &NavigationServer2D::agent_get_avoidance_enabled);
438 ClassDB::bind_method(D_METHOD("agent_set_map", "agent", "map"), &NavigationServer2D::agent_set_map);
439 ClassDB::bind_method(D_METHOD("agent_get_map", "agent"), &NavigationServer2D::agent_get_map);
440 ClassDB::bind_method(D_METHOD("agent_set_paused", "agent", "paused"), &NavigationServer2D::agent_set_paused);
441 ClassDB::bind_method(D_METHOD("agent_get_paused", "agent"), &NavigationServer2D::agent_get_paused);
442 ClassDB::bind_method(D_METHOD("agent_set_neighbor_distance", "agent", "distance"), &NavigationServer2D::agent_set_neighbor_distance);
443 ClassDB::bind_method(D_METHOD("agent_set_max_neighbors", "agent", "count"), &NavigationServer2D::agent_set_max_neighbors);
444 ClassDB::bind_method(D_METHOD("agent_set_time_horizon_agents", "agent", "time_horizon"), &NavigationServer2D::agent_set_time_horizon_agents);
445 ClassDB::bind_method(D_METHOD("agent_set_time_horizon_obstacles", "agent", "time_horizon"), &NavigationServer2D::agent_set_time_horizon_obstacles);
446 ClassDB::bind_method(D_METHOD("agent_set_radius", "agent", "radius"), &NavigationServer2D::agent_set_radius);
447 ClassDB::bind_method(D_METHOD("agent_set_max_speed", "agent", "max_speed"), &NavigationServer2D::agent_set_max_speed);
448 ClassDB::bind_method(D_METHOD("agent_set_velocity_forced", "agent", "velocity"), &NavigationServer2D::agent_set_velocity_forced);
449 ClassDB::bind_method(D_METHOD("agent_set_velocity", "agent", "velocity"), &NavigationServer2D::agent_set_velocity);
450 ClassDB::bind_method(D_METHOD("agent_set_position", "agent", "position"), &NavigationServer2D::agent_set_position);
451 ClassDB::bind_method(D_METHOD("agent_is_map_changed", "agent"), &NavigationServer2D::agent_is_map_changed);
452 ClassDB::bind_method(D_METHOD("agent_set_avoidance_callback", "agent", "callback"), &NavigationServer2D::agent_set_avoidance_callback);
453 ClassDB::bind_method(D_METHOD("agent_set_avoidance_layers", "agent", "layers"), &NavigationServer2D::agent_set_avoidance_layers);
454 ClassDB::bind_method(D_METHOD("agent_set_avoidance_mask", "agent", "mask"), &NavigationServer2D::agent_set_avoidance_mask);
455 ClassDB::bind_method(D_METHOD("agent_set_avoidance_priority", "agent", "priority"), &NavigationServer2D::agent_set_avoidance_priority);
456
457 ClassDB::bind_method(D_METHOD("obstacle_create"), &NavigationServer2D::obstacle_create);
458 ClassDB::bind_method(D_METHOD("obstacle_set_avoidance_enabled", "obstacle", "enabled"), &NavigationServer2D::obstacle_set_avoidance_enabled);
459 ClassDB::bind_method(D_METHOD("obstacle_get_avoidance_enabled", "obstacle"), &NavigationServer2D::obstacle_get_avoidance_enabled);
460 ClassDB::bind_method(D_METHOD("obstacle_set_map", "obstacle", "map"), &NavigationServer2D::obstacle_set_map);
461 ClassDB::bind_method(D_METHOD("obstacle_get_map", "obstacle"), &NavigationServer2D::obstacle_get_map);
462 ClassDB::bind_method(D_METHOD("obstacle_set_paused", "obstacle", "paused"), &NavigationServer2D::obstacle_set_paused);
463 ClassDB::bind_method(D_METHOD("obstacle_get_paused", "obstacle"), &NavigationServer2D::obstacle_get_paused);
464 ClassDB::bind_method(D_METHOD("obstacle_set_radius", "obstacle", "radius"), &NavigationServer2D::obstacle_set_radius);
465 ClassDB::bind_method(D_METHOD("obstacle_set_velocity", "obstacle", "velocity"), &NavigationServer2D::obstacle_set_velocity);
466 ClassDB::bind_method(D_METHOD("obstacle_set_position", "obstacle", "position"), &NavigationServer2D::obstacle_set_position);
467 ClassDB::bind_method(D_METHOD("obstacle_set_vertices", "obstacle", "vertices"), &NavigationServer2D::obstacle_set_vertices);
468 ClassDB::bind_method(D_METHOD("obstacle_set_avoidance_layers", "obstacle", "layers"), &NavigationServer2D::obstacle_set_avoidance_layers);
469
470 ClassDB::bind_method(D_METHOD("free_rid", "rid"), &NavigationServer2D::free);
471
472 ClassDB::bind_method(D_METHOD("set_debug_enabled", "enabled"), &NavigationServer2D::set_debug_enabled);
473 ClassDB::bind_method(D_METHOD("get_debug_enabled"), &NavigationServer2D::get_debug_enabled);
474
475 ADD_SIGNAL(MethodInfo("map_changed", PropertyInfo(Variant::RID, "map")));
476
477 ADD_SIGNAL(MethodInfo("navigation_debug_changed"));
478}
479
480NavigationServer2D::NavigationServer2D() {
481 singleton = this;
482 ERR_FAIL_COND_MSG(!NavigationServer3D::get_singleton(), "The Navigation3D singleton should be initialized before the 2D one.");
483 NavigationServer3D::get_singleton()->connect("map_changed", callable_mp(this, &NavigationServer2D::_emit_map_changed));
484
485#ifdef DEBUG_ENABLED
486 NavigationServer3D::get_singleton()->connect(SNAME("navigation_debug_changed"), callable_mp(this, &NavigationServer2D::_emit_navigation_debug_changed_signal));
487#endif // DEBUG_ENABLED
488}
489
490#ifdef DEBUG_ENABLED
491void NavigationServer2D::_emit_navigation_debug_changed_signal() {
492 emit_signal(SNAME("navigation_debug_changed"));
493}
494#endif // DEBUG_ENABLED
495
496NavigationServer2D::~NavigationServer2D() {
497 singleton = nullptr;
498}
499
500TypedArray<RID> FORWARD_0_C(get_maps);
501
502TypedArray<RID> FORWARD_1_C(map_get_links, RID, p_map, rid_to_rid);
503
504TypedArray<RID> FORWARD_1_C(map_get_regions, RID, p_map, rid_to_rid);
505
506TypedArray<RID> FORWARD_1_C(map_get_agents, RID, p_map, rid_to_rid);
507
508TypedArray<RID> FORWARD_1_C(map_get_obstacles, RID, p_map, rid_to_rid);
509
510RID FORWARD_1_C(region_get_map, RID, p_region, rid_to_rid);
511
512RID FORWARD_1_C(agent_get_map, RID, p_agent, rid_to_rid);
513
514RID FORWARD_0(map_create);
515
516void FORWARD_2(map_set_active, RID, p_map, bool, p_active, rid_to_rid, bool_to_bool);
517
518bool FORWARD_1_C(map_is_active, RID, p_map, rid_to_rid);
519
520void NavigationServer2D::map_force_update(RID p_map) {
521 NavigationServer3D::get_singleton()->map_force_update(p_map);
522}
523
524void FORWARD_2(map_set_cell_size, RID, p_map, real_t, p_cell_size, rid_to_rid, real_to_real);
525real_t FORWARD_1_C(map_get_cell_size, RID, p_map, rid_to_rid);
526
527void FORWARD_2(map_set_use_edge_connections, RID, p_map, bool, p_enabled, rid_to_rid, bool_to_bool);
528bool FORWARD_1_C(map_get_use_edge_connections, RID, p_map, rid_to_rid);
529
530void FORWARD_2(map_set_edge_connection_margin, RID, p_map, real_t, p_connection_margin, rid_to_rid, real_to_real);
531real_t FORWARD_1_C(map_get_edge_connection_margin, RID, p_map, rid_to_rid);
532
533void FORWARD_2(map_set_link_connection_radius, RID, p_map, real_t, p_connection_radius, rid_to_rid, real_to_real);
534real_t FORWARD_1_C(map_get_link_connection_radius, RID, p_map, rid_to_rid);
535
536Vector<Vector2> FORWARD_5_R_C(vector_v3_to_v2, map_get_path, RID, p_map, Vector2, p_origin, Vector2, p_destination, bool, p_optimize, uint32_t, p_layers, rid_to_rid, v2_to_v3, v2_to_v3, bool_to_bool, uint32_to_uint32);
537
538Vector2 FORWARD_2_R_C(v3_to_v2, map_get_closest_point, RID, p_map, const Vector2 &, p_point, rid_to_rid, v2_to_v3);
539RID FORWARD_2_C(map_get_closest_point_owner, RID, p_map, const Vector2 &, p_point, rid_to_rid, v2_to_v3);
540
541RID FORWARD_0(region_create);
542
543void FORWARD_2(region_set_enabled, RID, p_region, bool, p_enabled, rid_to_rid, bool_to_bool);
544bool FORWARD_1_C(region_get_enabled, RID, p_region, rid_to_rid);
545void FORWARD_2(region_set_use_edge_connections, RID, p_region, bool, p_enabled, rid_to_rid, bool_to_bool);
546bool FORWARD_1_C(region_get_use_edge_connections, RID, p_region, rid_to_rid);
547
548void FORWARD_2(region_set_enter_cost, RID, p_region, real_t, p_enter_cost, rid_to_rid, real_to_real);
549real_t FORWARD_1_C(region_get_enter_cost, RID, p_region, rid_to_rid);
550void FORWARD_2(region_set_travel_cost, RID, p_region, real_t, p_travel_cost, rid_to_rid, real_to_real);
551real_t FORWARD_1_C(region_get_travel_cost, RID, p_region, rid_to_rid);
552void FORWARD_2(region_set_owner_id, RID, p_region, ObjectID, p_owner_id, rid_to_rid, id_to_id);
553ObjectID FORWARD_1_C(region_get_owner_id, RID, p_region, rid_to_rid);
554bool FORWARD_2_C(region_owns_point, RID, p_region, const Vector2 &, p_point, rid_to_rid, v2_to_v3);
555
556void FORWARD_2(region_set_map, RID, p_region, RID, p_map, rid_to_rid, rid_to_rid);
557void FORWARD_2(region_set_navigation_layers, RID, p_region, uint32_t, p_navigation_layers, rid_to_rid, uint32_to_uint32);
558uint32_t FORWARD_1_C(region_get_navigation_layers, RID, p_region, rid_to_rid);
559void FORWARD_2(region_set_transform, RID, p_region, Transform2D, p_transform, rid_to_rid, trf2_to_trf3);
560
561void NavigationServer2D::region_set_navigation_polygon(RID p_region, Ref<NavigationPolygon> p_navigation_polygon) {
562 NavigationServer3D::get_singleton()->region_set_navigation_mesh(p_region, poly_to_mesh(p_navigation_polygon));
563}
564
565int FORWARD_1_C(region_get_connections_count, RID, p_region, rid_to_rid);
566Vector2 FORWARD_2_R_C(v3_to_v2, region_get_connection_pathway_start, RID, p_region, int, p_connection_id, rid_to_rid, int_to_int);
567Vector2 FORWARD_2_R_C(v3_to_v2, region_get_connection_pathway_end, RID, p_region, int, p_connection_id, rid_to_rid, int_to_int);
568
569RID FORWARD_0(link_create);
570
571void FORWARD_2(link_set_map, RID, p_link, RID, p_map, rid_to_rid, rid_to_rid);
572RID FORWARD_1_C(link_get_map, RID, p_link, rid_to_rid);
573void FORWARD_2(link_set_enabled, RID, p_link, bool, p_enabled, rid_to_rid, bool_to_bool);
574bool FORWARD_1_C(link_get_enabled, RID, p_link, rid_to_rid);
575void FORWARD_2(link_set_bidirectional, RID, p_link, bool, p_bidirectional, rid_to_rid, bool_to_bool);
576bool FORWARD_1_C(link_is_bidirectional, RID, p_link, rid_to_rid);
577void FORWARD_2(link_set_navigation_layers, RID, p_link, uint32_t, p_navigation_layers, rid_to_rid, uint32_to_uint32);
578uint32_t FORWARD_1_C(link_get_navigation_layers, RID, p_link, rid_to_rid);
579void FORWARD_2(link_set_start_position, RID, p_link, Vector2, p_position, rid_to_rid, v2_to_v3);
580Vector2 FORWARD_1_R_C(v3_to_v2, link_get_start_position, RID, p_link, rid_to_rid);
581void FORWARD_2(link_set_end_position, RID, p_link, Vector2, p_position, rid_to_rid, v2_to_v3);
582Vector2 FORWARD_1_R_C(v3_to_v2, link_get_end_position, RID, p_link, rid_to_rid);
583void FORWARD_2(link_set_enter_cost, RID, p_link, real_t, p_enter_cost, rid_to_rid, real_to_real);
584real_t FORWARD_1_C(link_get_enter_cost, RID, p_link, rid_to_rid);
585void FORWARD_2(link_set_travel_cost, RID, p_link, real_t, p_travel_cost, rid_to_rid, real_to_real);
586real_t FORWARD_1_C(link_get_travel_cost, RID, p_link, rid_to_rid);
587void FORWARD_2(link_set_owner_id, RID, p_link, ObjectID, p_owner_id, rid_to_rid, id_to_id);
588ObjectID FORWARD_1_C(link_get_owner_id, RID, p_link, rid_to_rid);
589
590RID NavigationServer2D::agent_create() {
591 RID agent = NavigationServer3D::get_singleton()->agent_create();
592 return agent;
593}
594
595void FORWARD_2(agent_set_avoidance_enabled, RID, p_agent, bool, p_enabled, rid_to_rid, bool_to_bool);
596bool FORWARD_1_C(agent_get_avoidance_enabled, RID, p_agent, rid_to_rid);
597void FORWARD_2(agent_set_map, RID, p_agent, RID, p_map, rid_to_rid, rid_to_rid);
598void FORWARD_2(agent_set_neighbor_distance, RID, p_agent, real_t, p_dist, rid_to_rid, real_to_real);
599void FORWARD_2(agent_set_max_neighbors, RID, p_agent, int, p_count, rid_to_rid, int_to_int);
600void FORWARD_2(agent_set_time_horizon_agents, RID, p_agent, real_t, p_time_horizon, rid_to_rid, real_to_real);
601void FORWARD_2(agent_set_time_horizon_obstacles, RID, p_agent, real_t, p_time_horizon, rid_to_rid, real_to_real);
602void FORWARD_2(agent_set_radius, RID, p_agent, real_t, p_radius, rid_to_rid, real_to_real);
603void FORWARD_2(agent_set_max_speed, RID, p_agent, real_t, p_max_speed, rid_to_rid, real_to_real);
604void FORWARD_2(agent_set_velocity_forced, RID, p_agent, Vector2, p_velocity, rid_to_rid, v2_to_v3);
605void FORWARD_2(agent_set_velocity, RID, p_agent, Vector2, p_velocity, rid_to_rid, v2_to_v3);
606void FORWARD_2(agent_set_position, RID, p_agent, Vector2, p_position, rid_to_rid, v2_to_v3);
607
608bool FORWARD_1_C(agent_is_map_changed, RID, p_agent, rid_to_rid);
609void FORWARD_2(agent_set_paused, RID, p_agent, bool, p_paused, rid_to_rid, bool_to_bool);
610bool FORWARD_1_C(agent_get_paused, RID, p_agent, rid_to_rid);
611
612void FORWARD_1(free, RID, p_object, rid_to_rid);
613void FORWARD_2(agent_set_avoidance_callback, RID, p_agent, Callable, p_callback, rid_to_rid, callable_to_callable);
614
615void FORWARD_2(agent_set_avoidance_layers, RID, p_agent, uint32_t, p_layers, rid_to_rid, uint32_to_uint32);
616void FORWARD_2(agent_set_avoidance_mask, RID, p_agent, uint32_t, p_mask, rid_to_rid, uint32_to_uint32);
617void FORWARD_2(agent_set_avoidance_priority, RID, p_agent, real_t, p_priority, rid_to_rid, real_to_real);
618
619RID NavigationServer2D::obstacle_create() {
620 RID obstacle = NavigationServer3D::get_singleton()->obstacle_create();
621 return obstacle;
622}
623void FORWARD_2(obstacle_set_avoidance_enabled, RID, p_obstacle, bool, p_enabled, rid_to_rid, bool_to_bool);
624bool FORWARD_1_C(obstacle_get_avoidance_enabled, RID, p_obstacle, rid_to_rid);
625void FORWARD_2(obstacle_set_map, RID, p_obstacle, RID, p_map, rid_to_rid, rid_to_rid);
626RID FORWARD_1_C(obstacle_get_map, RID, p_obstacle, rid_to_rid);
627void FORWARD_2(obstacle_set_paused, RID, p_obstacle, bool, p_paused, rid_to_rid, bool_to_bool);
628bool FORWARD_1_C(obstacle_get_paused, RID, p_obstacle, rid_to_rid);
629void FORWARD_2(obstacle_set_radius, RID, p_obstacle, real_t, p_radius, rid_to_rid, real_to_real);
630void FORWARD_2(obstacle_set_velocity, RID, p_obstacle, Vector2, p_velocity, rid_to_rid, v2_to_v3);
631void FORWARD_2(obstacle_set_position, RID, p_obstacle, Vector2, p_position, rid_to_rid, v2_to_v3);
632void FORWARD_2(obstacle_set_avoidance_layers, RID, p_obstacle, uint32_t, p_layers, rid_to_rid, uint32_to_uint32);
633
634void NavigationServer2D::obstacle_set_vertices(RID p_obstacle, const Vector<Vector2> &p_vertices) {
635 NavigationServer3D::get_singleton()->obstacle_set_vertices(p_obstacle, vector_v2_to_v3(p_vertices));
636}
637
638void NavigationServer2D::query_path(const Ref<NavigationPathQueryParameters2D> &p_query_parameters, Ref<NavigationPathQueryResult2D> p_query_result) const {
639 ERR_FAIL_COND(!p_query_parameters.is_valid());
640 ERR_FAIL_COND(!p_query_result.is_valid());
641
642 const NavigationUtilities::PathQueryResult _query_result = NavigationServer3D::get_singleton()->_query_path(p_query_parameters->get_parameters());
643
644 p_query_result->set_path(vector_v3_to_v2(_query_result.path));
645 p_query_result->set_path_types(_query_result.path_types);
646 p_query_result->set_path_rids(_query_result.path_rids);
647 p_query_result->set_path_owner_ids(_query_result.path_owner_ids);
648}
649