nav_link.cpp 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. /**************************************************************************/
  2. /* nav_link.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 "nav_link.h"
  31. #include "nav_map.h"
  32. void NavLink::set_map(NavMap *p_map) {
  33. if (map == p_map) {
  34. return;
  35. }
  36. cancel_sync_request();
  37. if (map) {
  38. map->remove_link(this);
  39. }
  40. map = p_map;
  41. link_dirty = true;
  42. if (map) {
  43. map->add_link(this);
  44. request_sync();
  45. }
  46. }
  47. void NavLink::set_enabled(bool p_enabled) {
  48. if (enabled == p_enabled) {
  49. return;
  50. }
  51. enabled = p_enabled;
  52. // TODO: This should not require a full rebuild as the link has not really changed.
  53. link_dirty = true;
  54. request_sync();
  55. }
  56. void NavLink::set_bidirectional(bool p_bidirectional) {
  57. if (bidirectional == p_bidirectional) {
  58. return;
  59. }
  60. bidirectional = p_bidirectional;
  61. link_dirty = true;
  62. request_sync();
  63. }
  64. void NavLink::set_start_position(const Vector3 p_position) {
  65. if (start_position == p_position) {
  66. return;
  67. }
  68. start_position = p_position;
  69. link_dirty = true;
  70. request_sync();
  71. }
  72. void NavLink::set_end_position(const Vector3 p_position) {
  73. if (end_position == p_position) {
  74. return;
  75. }
  76. end_position = p_position;
  77. link_dirty = true;
  78. request_sync();
  79. }
  80. bool NavLink::is_dirty() const {
  81. return link_dirty;
  82. }
  83. void NavLink::sync() {
  84. link_dirty = false;
  85. }
  86. void NavLink::request_sync() {
  87. if (map && !sync_dirty_request_list_element.in_list()) {
  88. map->add_link_sync_dirty_request(&sync_dirty_request_list_element);
  89. }
  90. }
  91. void NavLink::cancel_sync_request() {
  92. if (map && sync_dirty_request_list_element.in_list()) {
  93. map->remove_link_sync_dirty_request(&sync_dirty_request_list_element);
  94. }
  95. }
  96. NavLink::NavLink() :
  97. sync_dirty_request_list_element(this) {
  98. type = NavigationUtilities::PathSegmentType::PATH_SEGMENT_TYPE_LINK;
  99. }
  100. NavLink::~NavLink() {
  101. cancel_sync_request();
  102. }
  103. void NavLink::get_iteration_update(NavLinkIteration &r_iteration) {
  104. r_iteration.navigation_layers = get_navigation_layers();
  105. r_iteration.enter_cost = get_enter_cost();
  106. r_iteration.travel_cost = get_travel_cost();
  107. r_iteration.owner_object_id = get_owner_id();
  108. r_iteration.owner_type = get_type();
  109. r_iteration.owner_rid = get_self();
  110. r_iteration.enabled = get_enabled();
  111. r_iteration.start_position = get_start_position();
  112. r_iteration.end_position = get_end_position();
  113. r_iteration.bidirectional = is_bidirectional();
  114. }