nav_link_3d.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /**************************************************************************/
  2. /* nav_link_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. #pragma once
  31. #include "3d/nav_base_iteration_3d.h"
  32. #include "nav_base_3d.h"
  33. #include "nav_utils_3d.h"
  34. class NavLinkIteration3D : public NavBaseIteration3D {
  35. GDCLASS(NavLinkIteration3D, NavBaseIteration3D);
  36. public:
  37. bool bidirectional = true;
  38. Vector3 start_position;
  39. Vector3 end_position;
  40. Vector3 get_start_position() const { return start_position; }
  41. Vector3 get_end_position() const { return end_position; }
  42. bool is_bidirectional() const { return bidirectional; }
  43. virtual ~NavLinkIteration3D() override {
  44. navmesh_polygons.clear();
  45. internal_connections.clear();
  46. }
  47. };
  48. #include "core/templates/self_list.h"
  49. class NavLink3D : public NavBase3D {
  50. NavMap3D *map = nullptr;
  51. bool bidirectional = true;
  52. Vector3 start_position;
  53. Vector3 end_position;
  54. bool enabled = true;
  55. SelfList<NavLink3D> sync_dirty_request_list_element;
  56. uint32_t iteration_id = 0;
  57. mutable RWLock iteration_rwlock;
  58. Ref<NavLinkIteration3D> iteration;
  59. bool iteration_dirty = true;
  60. bool iteration_building = false;
  61. bool iteration_ready = false;
  62. void _build_iteration();
  63. void _sync_iteration();
  64. public:
  65. NavLink3D();
  66. ~NavLink3D();
  67. uint32_t get_iteration_id() const { return iteration_id; }
  68. void set_map(NavMap3D *p_map);
  69. NavMap3D *get_map() const {
  70. return map;
  71. }
  72. void set_enabled(bool p_enabled);
  73. bool get_enabled() const { return enabled; }
  74. void set_bidirectional(bool p_bidirectional);
  75. bool is_bidirectional() const {
  76. return bidirectional;
  77. }
  78. void set_start_position(Vector3 p_position);
  79. Vector3 get_start_position() const {
  80. return start_position;
  81. }
  82. void set_end_position(Vector3 p_position);
  83. Vector3 get_end_position() const {
  84. return end_position;
  85. }
  86. // NavBase properties.
  87. virtual void set_navigation_layers(uint32_t p_navigation_layers) override;
  88. virtual void set_enter_cost(real_t p_enter_cost) override;
  89. virtual void set_travel_cost(real_t p_travel_cost) override;
  90. virtual void set_owner_id(ObjectID p_owner_id) override;
  91. bool sync();
  92. void request_sync();
  93. void cancel_sync_request();
  94. Ref<NavLinkIteration3D> get_iteration();
  95. };