0.2.0-dev Download ZIP
120 lines ·4.2 KB Raw
| 1 | /**************************************************************************/ |
| 2 | /* nav_link_2d.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 | |
| 31 | #pragma once |
| 32 | |
| 33 | #include "2d/nav_base_iteration_2d.h" |
| 34 | #include "nav_base_2d.h" |
| 35 | #include "nav_utils_2d.h" |
| 36 | |
| 37 | #include "core/os/rw_lock.h" |
| 38 | |
| 39 | class NavLinkIteration2D : public NavBaseIteration2D { |
| 40 | GDCLASS(NavLinkIteration2D, NavBaseIteration2D); |
| 41 | |
| 42 | public: |
| 43 | bool bidirectional = true; |
| 44 | Vector2 start_position; |
| 45 | Vector2 end_position; |
| 46 | |
| 47 | Vector2 get_start_position() const { return start_position; } |
| 48 | Vector2 get_end_position() const { return end_position; } |
| 49 | bool is_bidirectional() const { return bidirectional; } |
| 50 | |
| 51 | virtual ~NavLinkIteration2D() override { |
| 52 | navmesh_polygons.clear(); |
| 53 | internal_connections.clear(); |
| 54 | } |
| 55 | }; |
| 56 | |
| 57 | #include "core/templates/self_list.h" |
| 58 | |
| 59 | class NavLink2D : public NavBase2D { |
| 60 | NavMap2D *map = nullptr; |
| 61 | bool bidirectional = true; |
| 62 | Vector2 start_position; |
| 63 | Vector2 end_position; |
| 64 | bool enabled = true; |
| 65 | |
| 66 | SelfList<NavLink2D> sync_dirty_request_list_element; |
| 67 | |
| 68 | uint32_t iteration_id = 0; |
| 69 | |
| 70 | mutable RWLock iteration_rwlock; |
| 71 | Ref<NavLinkIteration2D> iteration; |
| 72 | |
| 73 | bool iteration_dirty = true; |
| 74 | bool iteration_building = false; |
| 75 | bool iteration_ready = false; |
| 76 | |
| 77 | void _build_iteration(); |
| 78 | void _sync_iteration(); |
| 79 | |
| 80 | public: |
| 81 | NavLink2D(); |
| 82 | ~NavLink2D(); |
| 83 | |
| 84 | uint32_t get_iteration_id() const { return iteration_id; } |
| 85 | |
| 86 | void set_map(NavMap2D *p_map); |
| 87 | NavMap2D *get_map() const { |
| 88 | return map; |
| 89 | } |
| 90 | |
| 91 | void set_enabled(bool p_enabled); |
| 92 | bool get_enabled() const { return enabled; } |
| 93 | |
| 94 | void set_bidirectional(bool p_bidirectional); |
| 95 | bool is_bidirectional() const { |
| 96 | return bidirectional; |
| 97 | } |
| 98 | |
| 99 | void set_start_position(Vector2 p_position); |
| 100 | Vector2 get_start_position() const { |
| 101 | return start_position; |
| 102 | } |
| 103 | |
| 104 | void set_end_position(Vector2 p_position); |
| 105 | Vector2 get_end_position() const { |
| 106 | return end_position; |
| 107 | } |
| 108 | |
| 109 | // NavBase properties. |
| 110 | virtual void set_navigation_layers(uint32_t p_navigation_layers) override; |
| 111 | virtual void set_enter_cost(real_t p_enter_cost) override; |
| 112 | virtual void set_travel_cost(real_t p_travel_cost) override; |
| 113 | virtual void set_owner_id(ObjectID p_owner_id) override; |
| 114 | |
| 115 | bool sync(); |
| 116 | void request_sync(); |
| 117 | void cancel_sync_request(); |
| 118 | |
| 119 | Ref<NavLinkIteration2D> get_iteration(); |
| 120 | }; |