nav_map_iteration_3d.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /**************************************************************************/
  2. /* nav_map_iteration_3d.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef NAV_MAP_ITERATION_3D_H
  31. #define NAV_MAP_ITERATION_3D_H
  32. #include "../nav_rid.h"
  33. #include "../nav_utils.h"
  34. #include "nav_mesh_queries_3d.h"
  35. #include "core/math/math_defs.h"
  36. #include "core/os/semaphore.h"
  37. struct NavLinkIteration;
  38. class NavRegion;
  39. struct NavRegionIteration;
  40. struct NavMapIteration;
  41. struct NavMapIterationBuild {
  42. Vector3 merge_rasterizer_cell_size;
  43. bool use_edge_connections = true;
  44. real_t edge_connection_margin;
  45. real_t link_connection_radius;
  46. gd::PerformanceData performance_data;
  47. int polygon_count = 0;
  48. int free_edge_count = 0;
  49. HashMap<gd::EdgeKey, gd::EdgeConnectionPair, gd::EdgeKey> iter_connection_pairs_map;
  50. LocalVector<gd::Edge::Connection> iter_free_edges;
  51. NavMapIteration *map_iteration = nullptr;
  52. int navmesh_polygon_count = 0;
  53. int link_polygon_count = 0;
  54. void reset() {
  55. performance_data.reset();
  56. iter_connection_pairs_map.clear();
  57. iter_free_edges.clear();
  58. polygon_count = 0;
  59. free_edge_count = 0;
  60. navmesh_polygon_count = 0;
  61. link_polygon_count = 0;
  62. }
  63. };
  64. struct NavMapIteration {
  65. mutable SafeNumeric<uint32_t> users;
  66. RWLock rwlock;
  67. Vector3 map_up;
  68. LocalVector<gd::Polygon> link_polygons;
  69. LocalVector<NavRegionIteration> region_iterations;
  70. LocalVector<NavLinkIteration> link_iterations;
  71. int navmesh_polygon_count = 0;
  72. int link_polygon_count = 0;
  73. // The edge connections that the map builds on top with the edge connection margin.
  74. HashMap<uint32_t, LocalVector<gd::Edge::Connection>> external_region_connections;
  75. HashMap<NavRegion *, uint32_t> region_ptr_to_region_id;
  76. LocalVector<NavMeshQueries3D::PathQuerySlot> path_query_slots;
  77. Mutex path_query_slots_mutex;
  78. Semaphore path_query_slots_semaphore;
  79. };
  80. class NavMapIterationRead {
  81. const NavMapIteration &map_iteration;
  82. public:
  83. _ALWAYS_INLINE_ NavMapIterationRead(const NavMapIteration &p_iteration) :
  84. map_iteration(p_iteration) {
  85. map_iteration.rwlock.read_lock();
  86. map_iteration.users.increment();
  87. }
  88. _ALWAYS_INLINE_ ~NavMapIterationRead() {
  89. map_iteration.users.decrement();
  90. map_iteration.rwlock.read_unlock();
  91. }
  92. };
  93. #endif // NAV_MAP_ITERATION_3D_H