godot_navigation_server.cpp 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164
  1. /**************************************************************************/
  2. /* godot_navigation_server.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. #include "godot_navigation_server.h"
  31. #ifndef _3D_DISABLED
  32. #include "navigation_mesh_generator.h"
  33. #endif
  34. #include "core/os/mutex.h"
  35. using namespace NavigationUtilities;
  36. /// Creates a struct for each function and a function that once called creates
  37. /// an instance of that struct with the submitted parameters.
  38. /// Then, that struct is stored in an array; the `sync` function consume that array.
  39. #define COMMAND_1(F_NAME, T_0, D_0) \
  40. struct MERGE(F_NAME, _command) : public SetCommand { \
  41. T_0 d_0; \
  42. MERGE(F_NAME, _command) \
  43. (T_0 p_d_0) : \
  44. d_0(p_d_0) {} \
  45. virtual void exec(GodotNavigationServer *server) override { \
  46. server->MERGE(_cmd_, F_NAME)(d_0); \
  47. } \
  48. }; \
  49. void GodotNavigationServer::F_NAME(T_0 D_0) { \
  50. auto cmd = memnew(MERGE(F_NAME, _command)( \
  51. D_0)); \
  52. add_command(cmd); \
  53. } \
  54. void GodotNavigationServer::MERGE(_cmd_, F_NAME)(T_0 D_0)
  55. #define COMMAND_2(F_NAME, T_0, D_0, T_1, D_1) \
  56. struct MERGE(F_NAME, _command) : public SetCommand { \
  57. T_0 d_0; \
  58. T_1 d_1; \
  59. MERGE(F_NAME, _command) \
  60. ( \
  61. T_0 p_d_0, \
  62. T_1 p_d_1) : \
  63. d_0(p_d_0), \
  64. d_1(p_d_1) {} \
  65. virtual void exec(GodotNavigationServer *server) override { \
  66. server->MERGE(_cmd_, F_NAME)(d_0, d_1); \
  67. } \
  68. }; \
  69. void GodotNavigationServer::F_NAME(T_0 D_0, T_1 D_1) { \
  70. auto cmd = memnew(MERGE(F_NAME, _command)( \
  71. D_0, \
  72. D_1)); \
  73. add_command(cmd); \
  74. } \
  75. void GodotNavigationServer::MERGE(_cmd_, F_NAME)(T_0 D_0, T_1 D_1)
  76. GodotNavigationServer::GodotNavigationServer() {}
  77. GodotNavigationServer::~GodotNavigationServer() {
  78. flush_queries();
  79. }
  80. void GodotNavigationServer::add_command(SetCommand *command) {
  81. MutexLock lock(commands_mutex);
  82. commands.push_back(command);
  83. }
  84. TypedArray<RID> GodotNavigationServer::get_maps() const {
  85. TypedArray<RID> all_map_rids;
  86. List<RID> maps_owned;
  87. map_owner.get_owned_list(&maps_owned);
  88. if (maps_owned.size()) {
  89. for (const RID &E : maps_owned) {
  90. all_map_rids.push_back(E);
  91. }
  92. }
  93. return all_map_rids;
  94. }
  95. RID GodotNavigationServer::map_create() {
  96. MutexLock lock(operations_mutex);
  97. RID rid = map_owner.make_rid();
  98. NavMap *map = map_owner.get_or_null(rid);
  99. map->set_self(rid);
  100. return rid;
  101. }
  102. COMMAND_2(map_set_active, RID, p_map, bool, p_active) {
  103. NavMap *map = map_owner.get_or_null(p_map);
  104. ERR_FAIL_COND(map == nullptr);
  105. if (p_active) {
  106. if (!map_is_active(p_map)) {
  107. active_maps.push_back(map);
  108. active_maps_update_id.push_back(map->get_map_update_id());
  109. }
  110. } else {
  111. int map_index = active_maps.find(map);
  112. ERR_FAIL_COND(map_index < 0);
  113. active_maps.remove_at(map_index);
  114. active_maps_update_id.remove_at(map_index);
  115. }
  116. }
  117. bool GodotNavigationServer::map_is_active(RID p_map) const {
  118. NavMap *map = map_owner.get_or_null(p_map);
  119. ERR_FAIL_COND_V(map == nullptr, false);
  120. return active_maps.find(map) >= 0;
  121. }
  122. COMMAND_2(map_set_up, RID, p_map, Vector3, p_up) {
  123. NavMap *map = map_owner.get_or_null(p_map);
  124. ERR_FAIL_COND(map == nullptr);
  125. map->set_up(p_up);
  126. }
  127. Vector3 GodotNavigationServer::map_get_up(RID p_map) const {
  128. const NavMap *map = map_owner.get_or_null(p_map);
  129. ERR_FAIL_COND_V(map == nullptr, Vector3());
  130. return map->get_up();
  131. }
  132. COMMAND_2(map_set_cell_size, RID, p_map, real_t, p_cell_size) {
  133. NavMap *map = map_owner.get_or_null(p_map);
  134. ERR_FAIL_COND(map == nullptr);
  135. map->set_cell_size(p_cell_size);
  136. }
  137. real_t GodotNavigationServer::map_get_cell_size(RID p_map) const {
  138. const NavMap *map = map_owner.get_or_null(p_map);
  139. ERR_FAIL_COND_V(map == nullptr, 0);
  140. return map->get_cell_size();
  141. }
  142. COMMAND_2(map_set_cell_height, RID, p_map, real_t, p_cell_height) {
  143. NavMap *map = map_owner.get_or_null(p_map);
  144. ERR_FAIL_COND(map == nullptr);
  145. map->set_cell_height(p_cell_height);
  146. }
  147. real_t GodotNavigationServer::map_get_cell_height(RID p_map) const {
  148. const NavMap *map = map_owner.get_or_null(p_map);
  149. ERR_FAIL_COND_V(map == nullptr, 0);
  150. return map->get_cell_height();
  151. }
  152. COMMAND_2(map_set_use_edge_connections, RID, p_map, bool, p_enabled) {
  153. NavMap *map = map_owner.get_or_null(p_map);
  154. ERR_FAIL_COND(map == nullptr);
  155. map->set_use_edge_connections(p_enabled);
  156. }
  157. bool GodotNavigationServer::map_get_use_edge_connections(RID p_map) const {
  158. NavMap *map = map_owner.get_or_null(p_map);
  159. ERR_FAIL_COND_V(map == nullptr, false);
  160. return map->get_use_edge_connections();
  161. }
  162. COMMAND_2(map_set_edge_connection_margin, RID, p_map, real_t, p_connection_margin) {
  163. NavMap *map = map_owner.get_or_null(p_map);
  164. ERR_FAIL_COND(map == nullptr);
  165. map->set_edge_connection_margin(p_connection_margin);
  166. }
  167. real_t GodotNavigationServer::map_get_edge_connection_margin(RID p_map) const {
  168. const NavMap *map = map_owner.get_or_null(p_map);
  169. ERR_FAIL_COND_V(map == nullptr, 0);
  170. return map->get_edge_connection_margin();
  171. }
  172. COMMAND_2(map_set_link_connection_radius, RID, p_map, real_t, p_connection_radius) {
  173. NavMap *map = map_owner.get_or_null(p_map);
  174. ERR_FAIL_COND(map == nullptr);
  175. map->set_link_connection_radius(p_connection_radius);
  176. }
  177. real_t GodotNavigationServer::map_get_link_connection_radius(RID p_map) const {
  178. const NavMap *map = map_owner.get_or_null(p_map);
  179. ERR_FAIL_COND_V(map == nullptr, 0);
  180. return map->get_link_connection_radius();
  181. }
  182. Vector<Vector3> GodotNavigationServer::map_get_path(RID p_map, Vector3 p_origin, Vector3 p_destination, bool p_optimize, uint32_t p_navigation_layers) const {
  183. const NavMap *map = map_owner.get_or_null(p_map);
  184. ERR_FAIL_COND_V(map == nullptr, Vector<Vector3>());
  185. return map->get_path(p_origin, p_destination, p_optimize, p_navigation_layers, nullptr, nullptr, nullptr);
  186. }
  187. Vector3 GodotNavigationServer::map_get_closest_point_to_segment(RID p_map, const Vector3 &p_from, const Vector3 &p_to, const bool p_use_collision) const {
  188. const NavMap *map = map_owner.get_or_null(p_map);
  189. ERR_FAIL_COND_V(map == nullptr, Vector3());
  190. return map->get_closest_point_to_segment(p_from, p_to, p_use_collision);
  191. }
  192. Vector3 GodotNavigationServer::map_get_closest_point(RID p_map, const Vector3 &p_point) const {
  193. const NavMap *map = map_owner.get_or_null(p_map);
  194. ERR_FAIL_COND_V(map == nullptr, Vector3());
  195. return map->get_closest_point(p_point);
  196. }
  197. Vector3 GodotNavigationServer::map_get_closest_point_normal(RID p_map, const Vector3 &p_point) const {
  198. const NavMap *map = map_owner.get_or_null(p_map);
  199. ERR_FAIL_COND_V(map == nullptr, Vector3());
  200. return map->get_closest_point_normal(p_point);
  201. }
  202. RID GodotNavigationServer::map_get_closest_point_owner(RID p_map, const Vector3 &p_point) const {
  203. const NavMap *map = map_owner.get_or_null(p_map);
  204. ERR_FAIL_COND_V(map == nullptr, RID());
  205. return map->get_closest_point_owner(p_point);
  206. }
  207. TypedArray<RID> GodotNavigationServer::map_get_links(RID p_map) const {
  208. TypedArray<RID> link_rids;
  209. const NavMap *map = map_owner.get_or_null(p_map);
  210. ERR_FAIL_COND_V(map == nullptr, link_rids);
  211. const LocalVector<NavLink *> &links = map->get_links();
  212. link_rids.resize(links.size());
  213. for (uint32_t i = 0; i < links.size(); i++) {
  214. link_rids[i] = links[i]->get_self();
  215. }
  216. return link_rids;
  217. }
  218. TypedArray<RID> GodotNavigationServer::map_get_regions(RID p_map) const {
  219. TypedArray<RID> regions_rids;
  220. const NavMap *map = map_owner.get_or_null(p_map);
  221. ERR_FAIL_COND_V(map == nullptr, regions_rids);
  222. const LocalVector<NavRegion *> &regions = map->get_regions();
  223. regions_rids.resize(regions.size());
  224. for (uint32_t i = 0; i < regions.size(); i++) {
  225. regions_rids[i] = regions[i]->get_self();
  226. }
  227. return regions_rids;
  228. }
  229. TypedArray<RID> GodotNavigationServer::map_get_agents(RID p_map) const {
  230. TypedArray<RID> agents_rids;
  231. const NavMap *map = map_owner.get_or_null(p_map);
  232. ERR_FAIL_COND_V(map == nullptr, agents_rids);
  233. const LocalVector<NavAgent *> &agents = map->get_agents();
  234. agents_rids.resize(agents.size());
  235. for (uint32_t i = 0; i < agents.size(); i++) {
  236. agents_rids[i] = agents[i]->get_self();
  237. }
  238. return agents_rids;
  239. }
  240. TypedArray<RID> GodotNavigationServer::map_get_obstacles(RID p_map) const {
  241. TypedArray<RID> obstacles_rids;
  242. const NavMap *map = map_owner.get_or_null(p_map);
  243. ERR_FAIL_COND_V(map == nullptr, obstacles_rids);
  244. const LocalVector<NavObstacle *> obstacles = map->get_obstacles();
  245. obstacles_rids.resize(obstacles.size());
  246. for (uint32_t i = 0; i < obstacles.size(); i++) {
  247. obstacles_rids[i] = obstacles[i]->get_self();
  248. }
  249. return obstacles_rids;
  250. }
  251. RID GodotNavigationServer::region_get_map(RID p_region) const {
  252. NavRegion *region = region_owner.get_or_null(p_region);
  253. ERR_FAIL_COND_V(region == nullptr, RID());
  254. if (region->get_map()) {
  255. return region->get_map()->get_self();
  256. }
  257. return RID();
  258. }
  259. RID GodotNavigationServer::agent_get_map(RID p_agent) const {
  260. NavAgent *agent = agent_owner.get_or_null(p_agent);
  261. ERR_FAIL_COND_V(agent == nullptr, RID());
  262. if (agent->get_map()) {
  263. return agent->get_map()->get_self();
  264. }
  265. return RID();
  266. }
  267. RID GodotNavigationServer::region_create() {
  268. MutexLock lock(operations_mutex);
  269. RID rid = region_owner.make_rid();
  270. NavRegion *reg = region_owner.get_or_null(rid);
  271. reg->set_self(rid);
  272. return rid;
  273. }
  274. COMMAND_2(region_set_use_edge_connections, RID, p_region, bool, p_enabled) {
  275. NavRegion *region = region_owner.get_or_null(p_region);
  276. ERR_FAIL_COND(region == nullptr);
  277. region->set_use_edge_connections(p_enabled);
  278. }
  279. bool GodotNavigationServer::region_get_use_edge_connections(RID p_region) const {
  280. NavRegion *region = region_owner.get_or_null(p_region);
  281. ERR_FAIL_COND_V(region == nullptr, false);
  282. return region->get_use_edge_connections();
  283. }
  284. COMMAND_2(region_set_map, RID, p_region, RID, p_map) {
  285. NavRegion *region = region_owner.get_or_null(p_region);
  286. ERR_FAIL_COND(region == nullptr);
  287. NavMap *map = map_owner.get_or_null(p_map);
  288. region->set_map(map);
  289. }
  290. COMMAND_2(region_set_transform, RID, p_region, Transform3D, p_transform) {
  291. NavRegion *region = region_owner.get_or_null(p_region);
  292. ERR_FAIL_COND(region == nullptr);
  293. region->set_transform(p_transform);
  294. }
  295. COMMAND_2(region_set_enter_cost, RID, p_region, real_t, p_enter_cost) {
  296. NavRegion *region = region_owner.get_or_null(p_region);
  297. ERR_FAIL_COND(region == nullptr);
  298. ERR_FAIL_COND(p_enter_cost < 0.0);
  299. region->set_enter_cost(p_enter_cost);
  300. }
  301. real_t GodotNavigationServer::region_get_enter_cost(RID p_region) const {
  302. NavRegion *region = region_owner.get_or_null(p_region);
  303. ERR_FAIL_COND_V(region == nullptr, 0);
  304. return region->get_enter_cost();
  305. }
  306. COMMAND_2(region_set_travel_cost, RID, p_region, real_t, p_travel_cost) {
  307. NavRegion *region = region_owner.get_or_null(p_region);
  308. ERR_FAIL_COND(region == nullptr);
  309. ERR_FAIL_COND(p_travel_cost < 0.0);
  310. region->set_travel_cost(p_travel_cost);
  311. }
  312. real_t GodotNavigationServer::region_get_travel_cost(RID p_region) const {
  313. NavRegion *region = region_owner.get_or_null(p_region);
  314. ERR_FAIL_COND_V(region == nullptr, 0);
  315. return region->get_travel_cost();
  316. }
  317. COMMAND_2(region_set_owner_id, RID, p_region, ObjectID, p_owner_id) {
  318. NavRegion *region = region_owner.get_or_null(p_region);
  319. ERR_FAIL_COND(region == nullptr);
  320. region->set_owner_id(p_owner_id);
  321. }
  322. ObjectID GodotNavigationServer::region_get_owner_id(RID p_region) const {
  323. const NavRegion *region = region_owner.get_or_null(p_region);
  324. ERR_FAIL_COND_V(region == nullptr, ObjectID());
  325. return region->get_owner_id();
  326. }
  327. bool GodotNavigationServer::region_owns_point(RID p_region, const Vector3 &p_point) const {
  328. const NavRegion *region = region_owner.get_or_null(p_region);
  329. ERR_FAIL_COND_V(region == nullptr, false);
  330. if (region->get_map()) {
  331. RID closest_point_owner = map_get_closest_point_owner(region->get_map()->get_self(), p_point);
  332. return closest_point_owner == region->get_self();
  333. }
  334. return false;
  335. }
  336. COMMAND_2(region_set_navigation_layers, RID, p_region, uint32_t, p_navigation_layers) {
  337. NavRegion *region = region_owner.get_or_null(p_region);
  338. ERR_FAIL_COND(region == nullptr);
  339. region->set_navigation_layers(p_navigation_layers);
  340. }
  341. uint32_t GodotNavigationServer::region_get_navigation_layers(RID p_region) const {
  342. NavRegion *region = region_owner.get_or_null(p_region);
  343. ERR_FAIL_COND_V(region == nullptr, 0);
  344. return region->get_navigation_layers();
  345. }
  346. COMMAND_2(region_set_navigation_mesh, RID, p_region, Ref<NavigationMesh>, p_navigation_mesh) {
  347. NavRegion *region = region_owner.get_or_null(p_region);
  348. ERR_FAIL_COND(region == nullptr);
  349. region->set_mesh(p_navigation_mesh);
  350. }
  351. void GodotNavigationServer::region_bake_navigation_mesh(Ref<NavigationMesh> p_navigation_mesh, Node *p_root_node) {
  352. ERR_FAIL_COND(p_navigation_mesh.is_null());
  353. ERR_FAIL_COND(p_root_node == nullptr);
  354. #ifndef _3D_DISABLED
  355. NavigationMeshGenerator::get_singleton()->clear(p_navigation_mesh);
  356. Ref<NavigationMeshSourceGeometryData3D> source_geometry_data;
  357. source_geometry_data.instantiate();
  358. NavigationMeshGenerator::get_singleton()->parse_source_geometry_data(p_navigation_mesh, source_geometry_data, p_root_node);
  359. NavigationMeshGenerator::get_singleton()->bake_from_source_geometry_data(p_navigation_mesh, source_geometry_data);
  360. #endif
  361. }
  362. int GodotNavigationServer::region_get_connections_count(RID p_region) const {
  363. NavRegion *region = region_owner.get_or_null(p_region);
  364. ERR_FAIL_COND_V(!region, 0);
  365. return region->get_connections_count();
  366. }
  367. Vector3 GodotNavigationServer::region_get_connection_pathway_start(RID p_region, int p_connection_id) const {
  368. NavRegion *region = region_owner.get_or_null(p_region);
  369. ERR_FAIL_COND_V(!region, Vector3());
  370. return region->get_connection_pathway_start(p_connection_id);
  371. }
  372. Vector3 GodotNavigationServer::region_get_connection_pathway_end(RID p_region, int p_connection_id) const {
  373. NavRegion *region = region_owner.get_or_null(p_region);
  374. ERR_FAIL_COND_V(!region, Vector3());
  375. return region->get_connection_pathway_end(p_connection_id);
  376. }
  377. RID GodotNavigationServer::link_create() {
  378. MutexLock lock(operations_mutex);
  379. RID rid = link_owner.make_rid();
  380. NavLink *link = link_owner.get_or_null(rid);
  381. link->set_self(rid);
  382. return rid;
  383. }
  384. COMMAND_2(link_set_map, RID, p_link, RID, p_map) {
  385. NavLink *link = link_owner.get_or_null(p_link);
  386. ERR_FAIL_COND(link == nullptr);
  387. NavMap *map = map_owner.get_or_null(p_map);
  388. link->set_map(map);
  389. }
  390. RID GodotNavigationServer::link_get_map(const RID p_link) const {
  391. const NavLink *link = link_owner.get_or_null(p_link);
  392. ERR_FAIL_COND_V(link == nullptr, RID());
  393. if (link->get_map()) {
  394. return link->get_map()->get_self();
  395. }
  396. return RID();
  397. }
  398. COMMAND_2(link_set_bidirectional, RID, p_link, bool, p_bidirectional) {
  399. NavLink *link = link_owner.get_or_null(p_link);
  400. ERR_FAIL_COND(link == nullptr);
  401. link->set_bidirectional(p_bidirectional);
  402. }
  403. bool GodotNavigationServer::link_is_bidirectional(RID p_link) const {
  404. const NavLink *link = link_owner.get_or_null(p_link);
  405. ERR_FAIL_COND_V(link == nullptr, false);
  406. return link->is_bidirectional();
  407. }
  408. COMMAND_2(link_set_navigation_layers, RID, p_link, uint32_t, p_navigation_layers) {
  409. NavLink *link = link_owner.get_or_null(p_link);
  410. ERR_FAIL_COND(link == nullptr);
  411. link->set_navigation_layers(p_navigation_layers);
  412. }
  413. uint32_t GodotNavigationServer::link_get_navigation_layers(const RID p_link) const {
  414. const NavLink *link = link_owner.get_or_null(p_link);
  415. ERR_FAIL_COND_V(link == nullptr, 0);
  416. return link->get_navigation_layers();
  417. }
  418. COMMAND_2(link_set_start_position, RID, p_link, Vector3, p_position) {
  419. NavLink *link = link_owner.get_or_null(p_link);
  420. ERR_FAIL_COND(link == nullptr);
  421. link->set_start_position(p_position);
  422. }
  423. Vector3 GodotNavigationServer::link_get_start_position(RID p_link) const {
  424. const NavLink *link = link_owner.get_or_null(p_link);
  425. ERR_FAIL_COND_V(link == nullptr, Vector3());
  426. return link->get_start_position();
  427. }
  428. COMMAND_2(link_set_end_position, RID, p_link, Vector3, p_position) {
  429. NavLink *link = link_owner.get_or_null(p_link);
  430. ERR_FAIL_COND(link == nullptr);
  431. link->set_end_position(p_position);
  432. }
  433. Vector3 GodotNavigationServer::link_get_end_position(RID p_link) const {
  434. const NavLink *link = link_owner.get_or_null(p_link);
  435. ERR_FAIL_COND_V(link == nullptr, Vector3());
  436. return link->get_end_position();
  437. }
  438. COMMAND_2(link_set_enter_cost, RID, p_link, real_t, p_enter_cost) {
  439. NavLink *link = link_owner.get_or_null(p_link);
  440. ERR_FAIL_COND(link == nullptr);
  441. link->set_enter_cost(p_enter_cost);
  442. }
  443. real_t GodotNavigationServer::link_get_enter_cost(const RID p_link) const {
  444. const NavLink *link = link_owner.get_or_null(p_link);
  445. ERR_FAIL_COND_V(link == nullptr, 0);
  446. return link->get_enter_cost();
  447. }
  448. COMMAND_2(link_set_travel_cost, RID, p_link, real_t, p_travel_cost) {
  449. NavLink *link = link_owner.get_or_null(p_link);
  450. ERR_FAIL_COND(link == nullptr);
  451. link->set_travel_cost(p_travel_cost);
  452. }
  453. real_t GodotNavigationServer::link_get_travel_cost(const RID p_link) const {
  454. const NavLink *link = link_owner.get_or_null(p_link);
  455. ERR_FAIL_COND_V(link == nullptr, 0);
  456. return link->get_travel_cost();
  457. }
  458. COMMAND_2(link_set_owner_id, RID, p_link, ObjectID, p_owner_id) {
  459. NavLink *link = link_owner.get_or_null(p_link);
  460. ERR_FAIL_COND(link == nullptr);
  461. link->set_owner_id(p_owner_id);
  462. }
  463. ObjectID GodotNavigationServer::link_get_owner_id(RID p_link) const {
  464. const NavLink *link = link_owner.get_or_null(p_link);
  465. ERR_FAIL_COND_V(link == nullptr, ObjectID());
  466. return link->get_owner_id();
  467. }
  468. RID GodotNavigationServer::agent_create() {
  469. MutexLock lock(operations_mutex);
  470. RID rid = agent_owner.make_rid();
  471. NavAgent *agent = agent_owner.get_or_null(rid);
  472. agent->set_self(rid);
  473. return rid;
  474. }
  475. COMMAND_2(agent_set_avoidance_enabled, RID, p_agent, bool, p_enabled) {
  476. NavAgent *agent = agent_owner.get_or_null(p_agent);
  477. ERR_FAIL_COND(agent == nullptr);
  478. agent->set_avoidance_enabled(p_enabled);
  479. }
  480. bool GodotNavigationServer::agent_get_avoidance_enabled(RID p_agent) const {
  481. NavAgent *agent = agent_owner.get_or_null(p_agent);
  482. ERR_FAIL_COND_V(agent == nullptr, false);
  483. return agent->is_avoidance_enabled();
  484. }
  485. COMMAND_2(agent_set_use_3d_avoidance, RID, p_agent, bool, p_enabled) {
  486. NavAgent *agent = agent_owner.get_or_null(p_agent);
  487. ERR_FAIL_COND(agent == nullptr);
  488. agent->set_use_3d_avoidance(p_enabled);
  489. }
  490. bool GodotNavigationServer::agent_get_use_3d_avoidance(RID p_agent) const {
  491. NavAgent *agent = agent_owner.get_or_null(p_agent);
  492. ERR_FAIL_COND_V(agent == nullptr, false);
  493. return agent->get_use_3d_avoidance();
  494. }
  495. COMMAND_2(agent_set_map, RID, p_agent, RID, p_map) {
  496. NavAgent *agent = agent_owner.get_or_null(p_agent);
  497. ERR_FAIL_COND(agent == nullptr);
  498. NavMap *map = map_owner.get_or_null(p_map);
  499. agent->set_map(map);
  500. }
  501. COMMAND_2(agent_set_paused, RID, p_agent, bool, p_paused) {
  502. NavAgent *agent = agent_owner.get_or_null(p_agent);
  503. ERR_FAIL_COND(agent == nullptr);
  504. agent->set_paused(p_paused);
  505. }
  506. bool GodotNavigationServer::agent_get_paused(RID p_agent) const {
  507. NavAgent *agent = agent_owner.get_or_null(p_agent);
  508. ERR_FAIL_COND_V(agent == nullptr, false);
  509. return agent->get_paused();
  510. }
  511. COMMAND_2(agent_set_neighbor_distance, RID, p_agent, real_t, p_distance) {
  512. NavAgent *agent = agent_owner.get_or_null(p_agent);
  513. ERR_FAIL_COND(agent == nullptr);
  514. agent->set_neighbor_distance(p_distance);
  515. }
  516. COMMAND_2(agent_set_max_neighbors, RID, p_agent, int, p_count) {
  517. NavAgent *agent = agent_owner.get_or_null(p_agent);
  518. ERR_FAIL_COND(agent == nullptr);
  519. agent->set_max_neighbors(p_count);
  520. }
  521. COMMAND_2(agent_set_time_horizon_agents, RID, p_agent, real_t, p_time_horizon) {
  522. ERR_FAIL_COND_MSG(p_time_horizon < 0.0, "Time horizion must be positive.");
  523. NavAgent *agent = agent_owner.get_or_null(p_agent);
  524. ERR_FAIL_COND(agent == nullptr);
  525. agent->set_time_horizon_agents(p_time_horizon);
  526. }
  527. COMMAND_2(agent_set_time_horizon_obstacles, RID, p_agent, real_t, p_time_horizon) {
  528. ERR_FAIL_COND_MSG(p_time_horizon < 0.0, "Time horizion must be positive.");
  529. NavAgent *agent = agent_owner.get_or_null(p_agent);
  530. ERR_FAIL_COND(agent == nullptr);
  531. agent->set_time_horizon_obstacles(p_time_horizon);
  532. }
  533. COMMAND_2(agent_set_radius, RID, p_agent, real_t, p_radius) {
  534. ERR_FAIL_COND_MSG(p_radius < 0.0, "Radius must be positive.");
  535. NavAgent *agent = agent_owner.get_or_null(p_agent);
  536. ERR_FAIL_COND(agent == nullptr);
  537. agent->set_radius(p_radius);
  538. }
  539. COMMAND_2(agent_set_height, RID, p_agent, real_t, p_height) {
  540. ERR_FAIL_COND_MSG(p_height < 0.0, "Height must be positive.");
  541. NavAgent *agent = agent_owner.get_or_null(p_agent);
  542. ERR_FAIL_COND(agent == nullptr);
  543. agent->set_height(p_height);
  544. }
  545. COMMAND_2(agent_set_max_speed, RID, p_agent, real_t, p_max_speed) {
  546. ERR_FAIL_COND_MSG(p_max_speed < 0.0, "Max speed must be positive.");
  547. NavAgent *agent = agent_owner.get_or_null(p_agent);
  548. ERR_FAIL_COND(agent == nullptr);
  549. agent->set_max_speed(p_max_speed);
  550. }
  551. COMMAND_2(agent_set_velocity, RID, p_agent, Vector3, p_velocity) {
  552. NavAgent *agent = agent_owner.get_or_null(p_agent);
  553. ERR_FAIL_COND(agent == nullptr);
  554. agent->set_velocity(p_velocity);
  555. }
  556. COMMAND_2(agent_set_velocity_forced, RID, p_agent, Vector3, p_velocity) {
  557. NavAgent *agent = agent_owner.get_or_null(p_agent);
  558. ERR_FAIL_COND(agent == nullptr);
  559. agent->set_velocity_forced(p_velocity);
  560. }
  561. COMMAND_2(agent_set_position, RID, p_agent, Vector3, p_position) {
  562. NavAgent *agent = agent_owner.get_or_null(p_agent);
  563. ERR_FAIL_COND(agent == nullptr);
  564. agent->set_position(p_position);
  565. }
  566. bool GodotNavigationServer::agent_is_map_changed(RID p_agent) const {
  567. NavAgent *agent = agent_owner.get_or_null(p_agent);
  568. ERR_FAIL_COND_V(agent == nullptr, false);
  569. return agent->is_map_changed();
  570. }
  571. COMMAND_2(agent_set_avoidance_callback, RID, p_agent, Callable, p_callback) {
  572. NavAgent *agent = agent_owner.get_or_null(p_agent);
  573. ERR_FAIL_COND(agent == nullptr);
  574. agent->set_avoidance_callback(p_callback);
  575. if (agent->get_map()) {
  576. if (p_callback.is_valid()) {
  577. agent->get_map()->set_agent_as_controlled(agent);
  578. } else {
  579. agent->get_map()->remove_agent_as_controlled(agent);
  580. }
  581. }
  582. }
  583. COMMAND_2(agent_set_avoidance_layers, RID, p_agent, uint32_t, p_layers) {
  584. NavAgent *agent = agent_owner.get_or_null(p_agent);
  585. ERR_FAIL_COND(agent == nullptr);
  586. agent->set_avoidance_layers(p_layers);
  587. }
  588. COMMAND_2(agent_set_avoidance_mask, RID, p_agent, uint32_t, p_mask) {
  589. NavAgent *agent = agent_owner.get_or_null(p_agent);
  590. ERR_FAIL_COND(agent == nullptr);
  591. agent->set_avoidance_mask(p_mask);
  592. }
  593. COMMAND_2(agent_set_avoidance_priority, RID, p_agent, real_t, p_priority) {
  594. ERR_FAIL_COND_MSG(p_priority < 0.0, "Avoidance priority must be between 0.0 and 1.0 inclusive.");
  595. ERR_FAIL_COND_MSG(p_priority > 1.0, "Avoidance priority must be between 0.0 and 1.0 inclusive.");
  596. NavAgent *agent = agent_owner.get_or_null(p_agent);
  597. ERR_FAIL_COND(agent == nullptr);
  598. agent->set_avoidance_priority(p_priority);
  599. }
  600. RID GodotNavigationServer::obstacle_create() {
  601. GodotNavigationServer *mut_this = const_cast<GodotNavigationServer *>(this);
  602. MutexLock lock(mut_this->operations_mutex);
  603. RID rid = obstacle_owner.make_rid();
  604. NavObstacle *obstacle = obstacle_owner.get_or_null(rid);
  605. obstacle->set_self(rid);
  606. RID agent_rid = agent_owner.make_rid();
  607. NavAgent *agent = agent_owner.get_or_null(agent_rid);
  608. agent->set_self(agent_rid);
  609. obstacle->set_agent(agent);
  610. return rid;
  611. }
  612. COMMAND_2(obstacle_set_avoidance_enabled, RID, p_obstacle, bool, p_enabled) {
  613. NavObstacle *obstacle = obstacle_owner.get_or_null(p_obstacle);
  614. ERR_FAIL_COND(obstacle == nullptr);
  615. obstacle->set_avoidance_enabled(p_enabled);
  616. }
  617. bool GodotNavigationServer::obstacle_get_avoidance_enabled(RID p_obstacle) const {
  618. NavObstacle *obstacle = obstacle_owner.get_or_null(p_obstacle);
  619. ERR_FAIL_COND_V(obstacle == nullptr, false);
  620. return obstacle->is_avoidance_enabled();
  621. }
  622. COMMAND_2(obstacle_set_use_3d_avoidance, RID, p_obstacle, bool, p_enabled) {
  623. NavObstacle *obstacle = obstacle_owner.get_or_null(p_obstacle);
  624. ERR_FAIL_COND(obstacle == nullptr);
  625. obstacle->set_use_3d_avoidance(p_enabled);
  626. }
  627. bool GodotNavigationServer::obstacle_get_use_3d_avoidance(RID p_obstacle) const {
  628. NavObstacle *obstacle = obstacle_owner.get_or_null(p_obstacle);
  629. ERR_FAIL_COND_V(obstacle == nullptr, false);
  630. return obstacle->get_use_3d_avoidance();
  631. }
  632. COMMAND_2(obstacle_set_map, RID, p_obstacle, RID, p_map) {
  633. NavObstacle *obstacle = obstacle_owner.get_or_null(p_obstacle);
  634. ERR_FAIL_COND(obstacle == nullptr);
  635. NavMap *map = map_owner.get_or_null(p_map);
  636. obstacle->set_map(map);
  637. }
  638. RID GodotNavigationServer::obstacle_get_map(RID p_obstacle) const {
  639. NavObstacle *obstacle = obstacle_owner.get_or_null(p_obstacle);
  640. ERR_FAIL_COND_V(obstacle == nullptr, RID());
  641. if (obstacle->get_map()) {
  642. return obstacle->get_map()->get_self();
  643. }
  644. return RID();
  645. }
  646. COMMAND_2(obstacle_set_paused, RID, p_obstacle, bool, p_paused) {
  647. NavObstacle *obstacle = obstacle_owner.get_or_null(p_obstacle);
  648. ERR_FAIL_COND(obstacle == nullptr);
  649. obstacle->set_paused(p_paused);
  650. }
  651. bool GodotNavigationServer::obstacle_get_paused(RID p_obstacle) const {
  652. NavObstacle *obstacle = obstacle_owner.get_or_null(p_obstacle);
  653. ERR_FAIL_COND_V(obstacle == nullptr, false);
  654. return obstacle->get_paused();
  655. }
  656. COMMAND_2(obstacle_set_radius, RID, p_obstacle, real_t, p_radius) {
  657. ERR_FAIL_COND_MSG(p_radius < 0.0, "Radius must be positive.");
  658. NavObstacle *obstacle = obstacle_owner.get_or_null(p_obstacle);
  659. ERR_FAIL_COND(obstacle == nullptr);
  660. obstacle->set_radius(p_radius);
  661. }
  662. COMMAND_2(obstacle_set_height, RID, p_obstacle, real_t, p_height) {
  663. NavObstacle *obstacle = obstacle_owner.get_or_null(p_obstacle);
  664. ERR_FAIL_COND(obstacle == nullptr);
  665. obstacle->set_height(p_height);
  666. }
  667. COMMAND_2(obstacle_set_velocity, RID, p_obstacle, Vector3, p_velocity) {
  668. NavObstacle *obstacle = obstacle_owner.get_or_null(p_obstacle);
  669. ERR_FAIL_COND(obstacle == nullptr);
  670. obstacle->set_velocity(p_velocity);
  671. }
  672. COMMAND_2(obstacle_set_position, RID, p_obstacle, Vector3, p_position) {
  673. NavObstacle *obstacle = obstacle_owner.get_or_null(p_obstacle);
  674. ERR_FAIL_COND(obstacle == nullptr);
  675. obstacle->set_position(p_position);
  676. }
  677. void GodotNavigationServer::obstacle_set_vertices(RID p_obstacle, const Vector<Vector3> &p_vertices) {
  678. NavObstacle *obstacle = obstacle_owner.get_or_null(p_obstacle);
  679. ERR_FAIL_COND(obstacle == nullptr);
  680. obstacle->set_vertices(p_vertices);
  681. }
  682. COMMAND_2(obstacle_set_avoidance_layers, RID, p_obstacle, uint32_t, p_layers) {
  683. NavObstacle *obstacle = obstacle_owner.get_or_null(p_obstacle);
  684. ERR_FAIL_COND(obstacle == nullptr);
  685. obstacle->set_avoidance_layers(p_layers);
  686. }
  687. void GodotNavigationServer::parse_source_geometry_data(const Ref<NavigationMesh> &p_navigation_mesh, Ref<NavigationMeshSourceGeometryData3D> p_source_geometry_data, Node *p_root_node, const Callable &p_callback) {
  688. #ifndef _3D_DISABLED
  689. NavigationMeshGenerator::get_singleton()->parse_source_geometry_data(p_navigation_mesh, p_source_geometry_data, p_root_node, p_callback);
  690. #endif
  691. }
  692. void GodotNavigationServer::bake_from_source_geometry_data(Ref<NavigationMesh> p_navigation_mesh, const Ref<NavigationMeshSourceGeometryData3D> &p_source_geometry_data, const Callable &p_callback) {
  693. #ifndef _3D_DISABLED
  694. NavigationMeshGenerator::get_singleton()->bake_from_source_geometry_data(p_navigation_mesh, p_source_geometry_data, p_callback);
  695. #endif
  696. }
  697. COMMAND_1(free, RID, p_object) {
  698. if (map_owner.owns(p_object)) {
  699. NavMap *map = map_owner.get_or_null(p_object);
  700. // Removes any assigned region
  701. for (NavRegion *region : map->get_regions()) {
  702. map->remove_region(region);
  703. region->set_map(nullptr);
  704. }
  705. // Removes any assigned links
  706. for (NavLink *link : map->get_links()) {
  707. map->remove_link(link);
  708. link->set_map(nullptr);
  709. }
  710. // Remove any assigned agent
  711. for (NavAgent *agent : map->get_agents()) {
  712. map->remove_agent(agent);
  713. agent->set_map(nullptr);
  714. }
  715. // Remove any assigned obstacles
  716. for (NavObstacle *obstacle : map->get_obstacles()) {
  717. map->remove_obstacle(obstacle);
  718. obstacle->set_map(nullptr);
  719. }
  720. int map_index = active_maps.find(map);
  721. if (map_index >= 0) {
  722. active_maps.remove_at(map_index);
  723. active_maps_update_id.remove_at(map_index);
  724. }
  725. map_owner.free(p_object);
  726. } else if (region_owner.owns(p_object)) {
  727. NavRegion *region = region_owner.get_or_null(p_object);
  728. // Removes this region from the map if assigned
  729. if (region->get_map() != nullptr) {
  730. region->get_map()->remove_region(region);
  731. region->set_map(nullptr);
  732. }
  733. region_owner.free(p_object);
  734. } else if (link_owner.owns(p_object)) {
  735. NavLink *link = link_owner.get_or_null(p_object);
  736. // Removes this link from the map if assigned
  737. if (link->get_map() != nullptr) {
  738. link->get_map()->remove_link(link);
  739. link->set_map(nullptr);
  740. }
  741. link_owner.free(p_object);
  742. } else if (agent_owner.owns(p_object)) {
  743. internal_free_agent(p_object);
  744. } else if (obstacle_owner.owns(p_object)) {
  745. internal_free_obstacle(p_object);
  746. } else {
  747. ERR_PRINT("Attempted to free a NavigationServer RID that did not exist (or was already freed).");
  748. }
  749. }
  750. void GodotNavigationServer::internal_free_agent(RID p_object) {
  751. NavAgent *agent = agent_owner.get_or_null(p_object);
  752. if (agent) {
  753. if (agent->get_map() != nullptr) {
  754. agent->get_map()->remove_agent(agent);
  755. agent->set_map(nullptr);
  756. }
  757. agent_owner.free(p_object);
  758. }
  759. }
  760. void GodotNavigationServer::internal_free_obstacle(RID p_object) {
  761. NavObstacle *obstacle = obstacle_owner.get_or_null(p_object);
  762. if (obstacle) {
  763. NavAgent *obstacle_agent = obstacle->get_agent();
  764. if (obstacle_agent) {
  765. RID _agent_rid = obstacle_agent->get_self();
  766. internal_free_agent(_agent_rid);
  767. obstacle->set_agent(nullptr);
  768. }
  769. if (obstacle->get_map() != nullptr) {
  770. obstacle->get_map()->remove_obstacle(obstacle);
  771. obstacle->set_map(nullptr);
  772. }
  773. obstacle_owner.free(p_object);
  774. }
  775. }
  776. void GodotNavigationServer::set_active(bool p_active) {
  777. MutexLock lock(operations_mutex);
  778. active = p_active;
  779. }
  780. void GodotNavigationServer::flush_queries() {
  781. // In c++ we can't be sure that this is performed in the main thread
  782. // even with mutable functions.
  783. MutexLock lock(commands_mutex);
  784. MutexLock lock2(operations_mutex);
  785. for (SetCommand *command : commands) {
  786. command->exec(this);
  787. memdelete(command);
  788. }
  789. commands.clear();
  790. }
  791. void GodotNavigationServer::map_force_update(RID p_map) {
  792. NavMap *map = map_owner.get_or_null(p_map);
  793. ERR_FAIL_COND(map == nullptr);
  794. flush_queries();
  795. map->sync();
  796. }
  797. void GodotNavigationServer::process(real_t p_delta_time) {
  798. flush_queries();
  799. if (!active) {
  800. return;
  801. }
  802. int _new_pm_region_count = 0;
  803. int _new_pm_agent_count = 0;
  804. int _new_pm_link_count = 0;
  805. int _new_pm_polygon_count = 0;
  806. int _new_pm_edge_count = 0;
  807. int _new_pm_edge_merge_count = 0;
  808. int _new_pm_edge_connection_count = 0;
  809. int _new_pm_edge_free_count = 0;
  810. // In c++ we can't be sure that this is performed in the main thread
  811. // even with mutable functions.
  812. MutexLock lock(operations_mutex);
  813. for (uint32_t i(0); i < active_maps.size(); i++) {
  814. active_maps[i]->sync();
  815. active_maps[i]->step(p_delta_time);
  816. active_maps[i]->dispatch_callbacks();
  817. _new_pm_region_count += active_maps[i]->get_pm_region_count();
  818. _new_pm_agent_count += active_maps[i]->get_pm_agent_count();
  819. _new_pm_link_count += active_maps[i]->get_pm_link_count();
  820. _new_pm_polygon_count += active_maps[i]->get_pm_polygon_count();
  821. _new_pm_edge_count += active_maps[i]->get_pm_edge_count();
  822. _new_pm_edge_merge_count += active_maps[i]->get_pm_edge_merge_count();
  823. _new_pm_edge_connection_count += active_maps[i]->get_pm_edge_connection_count();
  824. _new_pm_edge_free_count += active_maps[i]->get_pm_edge_free_count();
  825. // Emit a signal if a map changed.
  826. const uint32_t new_map_update_id = active_maps[i]->get_map_update_id();
  827. if (new_map_update_id != active_maps_update_id[i]) {
  828. emit_signal(SNAME("map_changed"), active_maps[i]->get_self());
  829. active_maps_update_id[i] = new_map_update_id;
  830. }
  831. }
  832. pm_region_count = _new_pm_region_count;
  833. pm_agent_count = _new_pm_agent_count;
  834. pm_link_count = _new_pm_link_count;
  835. pm_polygon_count = _new_pm_polygon_count;
  836. pm_edge_count = _new_pm_edge_count;
  837. pm_edge_merge_count = _new_pm_edge_merge_count;
  838. pm_edge_connection_count = _new_pm_edge_connection_count;
  839. pm_edge_free_count = _new_pm_edge_free_count;
  840. }
  841. PathQueryResult GodotNavigationServer::_query_path(const PathQueryParameters &p_parameters) const {
  842. PathQueryResult r_query_result;
  843. const NavMap *map = map_owner.get_or_null(p_parameters.map);
  844. ERR_FAIL_COND_V(map == nullptr, r_query_result);
  845. // run the pathfinding
  846. if (p_parameters.pathfinding_algorithm == PathfindingAlgorithm::PATHFINDING_ALGORITHM_ASTAR) {
  847. // while postprocessing is still part of map.get_path() need to check and route it here for the correct "optimize" post-processing
  848. if (p_parameters.path_postprocessing == PathPostProcessing::PATH_POSTPROCESSING_CORRIDORFUNNEL) {
  849. r_query_result.path = map->get_path(
  850. p_parameters.start_position,
  851. p_parameters.target_position,
  852. true,
  853. p_parameters.navigation_layers,
  854. p_parameters.metadata_flags.has_flag(PathMetadataFlags::PATH_INCLUDE_TYPES) ? &r_query_result.path_types : nullptr,
  855. p_parameters.metadata_flags.has_flag(PathMetadataFlags::PATH_INCLUDE_RIDS) ? &r_query_result.path_rids : nullptr,
  856. p_parameters.metadata_flags.has_flag(PathMetadataFlags::PATH_INCLUDE_OWNERS) ? &r_query_result.path_owner_ids : nullptr);
  857. } else if (p_parameters.path_postprocessing == PathPostProcessing::PATH_POSTPROCESSING_EDGECENTERED) {
  858. r_query_result.path = map->get_path(
  859. p_parameters.start_position,
  860. p_parameters.target_position,
  861. false,
  862. p_parameters.navigation_layers,
  863. p_parameters.metadata_flags.has_flag(PathMetadataFlags::PATH_INCLUDE_TYPES) ? &r_query_result.path_types : nullptr,
  864. p_parameters.metadata_flags.has_flag(PathMetadataFlags::PATH_INCLUDE_RIDS) ? &r_query_result.path_rids : nullptr,
  865. p_parameters.metadata_flags.has_flag(PathMetadataFlags::PATH_INCLUDE_OWNERS) ? &r_query_result.path_owner_ids : nullptr);
  866. }
  867. } else {
  868. return r_query_result;
  869. }
  870. // add path postprocessing
  871. // add path stats
  872. return r_query_result;
  873. }
  874. int GodotNavigationServer::get_process_info(ProcessInfo p_info) const {
  875. switch (p_info) {
  876. case INFO_ACTIVE_MAPS: {
  877. return active_maps.size();
  878. } break;
  879. case INFO_REGION_COUNT: {
  880. return pm_region_count;
  881. } break;
  882. case INFO_AGENT_COUNT: {
  883. return pm_agent_count;
  884. } break;
  885. case INFO_LINK_COUNT: {
  886. return pm_link_count;
  887. } break;
  888. case INFO_POLYGON_COUNT: {
  889. return pm_polygon_count;
  890. } break;
  891. case INFO_EDGE_COUNT: {
  892. return pm_edge_count;
  893. } break;
  894. case INFO_EDGE_MERGE_COUNT: {
  895. return pm_edge_merge_count;
  896. } break;
  897. case INFO_EDGE_CONNECTION_COUNT: {
  898. return pm_edge_connection_count;
  899. } break;
  900. case INFO_EDGE_FREE_COUNT: {
  901. return pm_edge_free_count;
  902. } break;
  903. }
  904. return 0;
  905. }
  906. #undef COMMAND_1
  907. #undef COMMAND_2