| 1 | /**************************************************************************/ |
| 2 | /* navigation_path_query_parameters_2d.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 | |
| 31 | #include "navigation_path_query_parameters_2d.h" |
| 32 | |
| 33 | #include "core/variant/typed_array.h" |
| 34 | |
| 35 | void NavigationPathQueryParameters2D::set_pathfinding_algorithm(const NavigationPathQueryParameters2D::PathfindingAlgorithm p_pathfinding_algorithm) { |
| 36 | pathfinding_algorithm = p_pathfinding_algorithm; |
| 37 | } |
| 38 | |
| 39 | NavigationPathQueryParameters2D::PathfindingAlgorithm NavigationPathQueryParameters2D::get_pathfinding_algorithm() const { |
| 40 | return pathfinding_algorithm; |
| 41 | } |
| 42 | |
| 43 | void NavigationPathQueryParameters2D::set_path_postprocessing(const NavigationPathQueryParameters2D::PathPostProcessing p_path_postprocessing) { |
| 44 | path_postprocessing = p_path_postprocessing; |
| 45 | } |
| 46 | |
| 47 | NavigationPathQueryParameters2D::PathPostProcessing NavigationPathQueryParameters2D::get_path_postprocessing() const { |
| 48 | return path_postprocessing; |
| 49 | } |
| 50 | |
| 51 | void NavigationPathQueryParameters2D::set_map(RID p_map) { |
| 52 | map = p_map; |
| 53 | } |
| 54 | |
| 55 | RID NavigationPathQueryParameters2D::get_map() const { |
| 56 | return map; |
| 57 | } |
| 58 | |
| 59 | void NavigationPathQueryParameters2D::set_start_position(Vector2 p_start_position) { |
| 60 | start_position = p_start_position; |
| 61 | } |
| 62 | |
| 63 | Vector2 NavigationPathQueryParameters2D::get_start_position() const { |
| 64 | return start_position; |
| 65 | } |
| 66 | |
| 67 | void NavigationPathQueryParameters2D::set_target_position(Vector2 p_target_position) { |
| 68 | target_position = p_target_position; |
| 69 | } |
| 70 | |
| 71 | Vector2 NavigationPathQueryParameters2D::get_target_position() const { |
| 72 | return target_position; |
| 73 | } |
| 74 | |
| 75 | void NavigationPathQueryParameters2D::set_navigation_layers(uint32_t p_navigation_layers) { |
| 76 | navigation_layers = p_navigation_layers; |
| 77 | } |
| 78 | |
| 79 | uint32_t NavigationPathQueryParameters2D::get_navigation_layers() const { |
| 80 | return navigation_layers; |
| 81 | } |
| 82 | |
| 83 | void NavigationPathQueryParameters2D::set_metadata_flags(BitField<NavigationPathQueryParameters2D::PathMetadataFlags> p_flags) { |
| 84 | metadata_flags = (int64_t)p_flags; |
| 85 | } |
| 86 | |
| 87 | BitField<NavigationPathQueryParameters2D::PathMetadataFlags> NavigationPathQueryParameters2D::get_metadata_flags() const { |
| 88 | return (int64_t)metadata_flags; |
| 89 | } |
| 90 | |
| 91 | void NavigationPathQueryParameters2D::set_simplify_path(bool p_enabled) { |
| 92 | simplify_path = p_enabled; |
| 93 | } |
| 94 | |
| 95 | bool NavigationPathQueryParameters2D::get_simplify_path() const { |
| 96 | return simplify_path; |
| 97 | } |
| 98 | |
| 99 | void NavigationPathQueryParameters2D::set_simplify_epsilon(real_t p_epsilon) { |
| 100 | simplify_epsilon = MAX(0.0, p_epsilon); |
| 101 | } |
| 102 | |
| 103 | real_t NavigationPathQueryParameters2D::get_simplify_epsilon() const { |
| 104 | return simplify_epsilon; |
| 105 | } |
| 106 | |
| 107 | void NavigationPathQueryParameters2D::set_included_regions(const TypedArray<RID> &p_regions) { |
| 108 | _included_regions.resize(p_regions.size()); |
| 109 | for (uint32_t i = 0; i < _included_regions.size(); i++) { |
| 110 | _included_regions[i] = p_regions[i]; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | TypedArray<RID> NavigationPathQueryParameters2D::get_included_regions() const { |
| 115 | TypedArray<RID> r_regions; |
| 116 | r_regions.resize(_included_regions.size()); |
| 117 | for (uint32_t i = 0; i < _included_regions.size(); i++) { |
| 118 | r_regions[i] = _included_regions[i]; |
| 119 | } |
| 120 | return r_regions; |
| 121 | } |
| 122 | |
| 123 | void NavigationPathQueryParameters2D::set_excluded_regions(const TypedArray<RID> &p_regions) { |
| 124 | _excluded_regions.resize(p_regions.size()); |
| 125 | for (uint32_t i = 0; i < _excluded_regions.size(); i++) { |
| 126 | _excluded_regions[i] = p_regions[i]; |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | TypedArray<RID> NavigationPathQueryParameters2D::get_excluded_regions() const { |
| 131 | TypedArray<RID> r_regions; |
| 132 | r_regions.resize(_excluded_regions.size()); |
| 133 | for (uint32_t i = 0; i < _excluded_regions.size(); i++) { |
| 134 | r_regions[i] = _excluded_regions[i]; |
| 135 | } |
| 136 | return r_regions; |
| 137 | } |
| 138 | |
| 139 | void NavigationPathQueryParameters2D::set_path_return_max_length(float p_length) { |
| 140 | path_return_max_length = MAX(0.0, p_length); |
| 141 | } |
| 142 | |
| 143 | float NavigationPathQueryParameters2D::get_path_return_max_length() const { |
| 144 | return path_return_max_length; |
| 145 | } |
| 146 | |
| 147 | void NavigationPathQueryParameters2D::set_path_return_max_radius(float p_radius) { |
| 148 | path_return_max_radius = MAX(0.0, p_radius); |
| 149 | } |
| 150 | |
| 151 | float NavigationPathQueryParameters2D::get_path_return_max_radius() const { |
| 152 | return path_return_max_radius; |
| 153 | } |
| 154 | |
| 155 | void NavigationPathQueryParameters2D::set_path_search_max_polygons(int p_max_polygons) { |
| 156 | path_search_max_polygons = p_max_polygons; |
| 157 | } |
| 158 | |
| 159 | int NavigationPathQueryParameters2D::get_path_search_max_polygons() const { |
| 160 | return path_search_max_polygons; |
| 161 | } |
| 162 | |
| 163 | void NavigationPathQueryParameters2D::set_path_search_max_distance(float p_distance) { |
| 164 | path_search_max_distance = MAX(0.0, p_distance); |
| 165 | } |
| 166 | |
| 167 | float NavigationPathQueryParameters2D::get_path_search_max_distance() const { |
| 168 | return path_search_max_distance; |
| 169 | } |
| 170 | |
| 171 | void NavigationPathQueryParameters2D::_bind_methods() { |
| 172 | ClassDB::bind_method(D_METHOD("set_pathfinding_algorithm", "pathfinding_algorithm"), &NavigationPathQueryParameters2D::set_pathfinding_algorithm); |
| 173 | ClassDB::bind_method(D_METHOD("get_pathfinding_algorithm"), &NavigationPathQueryParameters2D::get_pathfinding_algorithm); |
| 174 | |
| 175 | ClassDB::bind_method(D_METHOD("set_path_postprocessing", "path_postprocessing"), &NavigationPathQueryParameters2D::set_path_postprocessing); |
| 176 | ClassDB::bind_method(D_METHOD("get_path_postprocessing"), &NavigationPathQueryParameters2D::get_path_postprocessing); |
| 177 | |
| 178 | ClassDB::bind_method(D_METHOD("set_map", "map"), &NavigationPathQueryParameters2D::set_map); |
| 179 | ClassDB::bind_method(D_METHOD("get_map"), &NavigationPathQueryParameters2D::get_map); |
| 180 | |
| 181 | ClassDB::bind_method(D_METHOD("set_start_position", "start_position"), &NavigationPathQueryParameters2D::set_start_position); |
| 182 | ClassDB::bind_method(D_METHOD("get_start_position"), &NavigationPathQueryParameters2D::get_start_position); |
| 183 | |
| 184 | ClassDB::bind_method(D_METHOD("set_target_position", "target_position"), &NavigationPathQueryParameters2D::set_target_position); |
| 185 | ClassDB::bind_method(D_METHOD("get_target_position"), &NavigationPathQueryParameters2D::get_target_position); |
| 186 | |
| 187 | ClassDB::bind_method(D_METHOD("set_navigation_layers", "navigation_layers"), &NavigationPathQueryParameters2D::set_navigation_layers); |
| 188 | ClassDB::bind_method(D_METHOD("get_navigation_layers"), &NavigationPathQueryParameters2D::get_navigation_layers); |
| 189 | |
| 190 | ClassDB::bind_method(D_METHOD("set_metadata_flags", "flags"), &NavigationPathQueryParameters2D::set_metadata_flags); |
| 191 | ClassDB::bind_method(D_METHOD("get_metadata_flags"), &NavigationPathQueryParameters2D::get_metadata_flags); |
| 192 | |
| 193 | ClassDB::bind_method(D_METHOD("set_simplify_path", "enabled"), &NavigationPathQueryParameters2D::set_simplify_path); |
| 194 | ClassDB::bind_method(D_METHOD("get_simplify_path"), &NavigationPathQueryParameters2D::get_simplify_path); |
| 195 | |
| 196 | ClassDB::bind_method(D_METHOD("set_simplify_epsilon", "epsilon"), &NavigationPathQueryParameters2D::set_simplify_epsilon); |
| 197 | ClassDB::bind_method(D_METHOD("get_simplify_epsilon"), &NavigationPathQueryParameters2D::get_simplify_epsilon); |
| 198 | |
| 199 | ClassDB::bind_method(D_METHOD("set_included_regions", "regions"), &NavigationPathQueryParameters2D::set_included_regions); |
| 200 | ClassDB::bind_method(D_METHOD("get_included_regions"), &NavigationPathQueryParameters2D::get_included_regions); |
| 201 | |
| 202 | ClassDB::bind_method(D_METHOD("set_excluded_regions", "regions"), &NavigationPathQueryParameters2D::set_excluded_regions); |
| 203 | ClassDB::bind_method(D_METHOD("get_excluded_regions"), &NavigationPathQueryParameters2D::get_excluded_regions); |
| 204 | |
| 205 | ClassDB::bind_method(D_METHOD("set_path_return_max_length", "length"), &NavigationPathQueryParameters2D::set_path_return_max_length); |
| 206 | ClassDB::bind_method(D_METHOD("get_path_return_max_length"), &NavigationPathQueryParameters2D::get_path_return_max_length); |
| 207 | |
| 208 | ClassDB::bind_method(D_METHOD("set_path_return_max_radius", "radius"), &NavigationPathQueryParameters2D::set_path_return_max_radius); |
| 209 | ClassDB::bind_method(D_METHOD("get_path_return_max_radius"), &NavigationPathQueryParameters2D::get_path_return_max_radius); |
| 210 | |
| 211 | ClassDB::bind_method(D_METHOD("set_path_search_max_polygons", "max_polygons"), &NavigationPathQueryParameters2D::set_path_search_max_polygons); |
| 212 | ClassDB::bind_method(D_METHOD("get_path_search_max_polygons"), &NavigationPathQueryParameters2D::get_path_search_max_polygons); |
| 213 | |
| 214 | ClassDB::bind_method(D_METHOD("set_path_search_max_distance", "distance"), &NavigationPathQueryParameters2D::set_path_search_max_distance); |
| 215 | ClassDB::bind_method(D_METHOD("get_path_search_max_distance"), &NavigationPathQueryParameters2D::get_path_search_max_distance); |
| 216 | |
| 217 | ADD_PROPERTY(PropertyInfo(Variant::RID, "map"), "set_map", "get_map"); |
| 218 | ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "start_position"), "set_start_position", "get_start_position"); |
| 219 | ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "target_position"), "set_target_position", "get_target_position"); |
| 220 | ADD_PROPERTY(PropertyInfo(Variant::INT, "navigation_layers", PROPERTY_HINT_LAYERS_2D_NAVIGATION), "set_navigation_layers", "get_navigation_layers"); |
| 221 | ADD_PROPERTY(PropertyInfo(Variant::INT, "pathfinding_algorithm", PROPERTY_HINT_ENUM, "AStar"), "set_pathfinding_algorithm", "get_pathfinding_algorithm"); |
| 222 | ADD_PROPERTY(PropertyInfo(Variant::INT, "path_postprocessing", PROPERTY_HINT_ENUM, "Corridorfunnel,Edgecentered,None"), "set_path_postprocessing", "get_path_postprocessing"); |
| 223 | ADD_PROPERTY(PropertyInfo(Variant::INT, "metadata_flags", PROPERTY_HINT_FLAGS, "Include Types,Include RIDs,Include Owners"), "set_metadata_flags", "get_metadata_flags"); |
| 224 | ADD_PROPERTY(PropertyInfo(Variant::BOOL, "simplify_path"), "set_simplify_path", "get_simplify_path"); |
| 225 | ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "simplify_epsilon"), "set_simplify_epsilon", "get_simplify_epsilon"); |
| 226 | ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "excluded_regions", PROPERTY_HINT_ARRAY_TYPE, "RID"), "set_excluded_regions", "get_excluded_regions"); |
| 227 | ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "included_regions", PROPERTY_HINT_ARRAY_TYPE, "RID"), "set_included_regions", "get_included_regions"); |
| 228 | ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "path_return_max_length"), "set_path_return_max_length", "get_path_return_max_length"); |
| 229 | ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "path_return_max_radius"), "set_path_return_max_radius", "get_path_return_max_radius"); |
| 230 | ADD_PROPERTY(PropertyInfo(Variant::INT, "path_search_max_polygons"), "set_path_search_max_polygons", "get_path_search_max_polygons"); |
| 231 | ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "path_search_max_distance"), "set_path_search_max_distance", "get_path_search_max_distance"); |
| 232 | |
| 233 | BIND_ENUM_CONSTANT(PATHFINDING_ALGORITHM_ASTAR); |
| 234 | |
| 235 | BIND_ENUM_CONSTANT(PATH_POSTPROCESSING_CORRIDORFUNNEL); |
| 236 | BIND_ENUM_CONSTANT(PATH_POSTPROCESSING_EDGECENTERED); |
| 237 | BIND_ENUM_CONSTANT(PATH_POSTPROCESSING_NONE); |
| 238 | |
| 239 | BIND_BITFIELD_FLAG(PATH_METADATA_INCLUDE_NONE); |
| 240 | BIND_BITFIELD_FLAG(PATH_METADATA_INCLUDE_TYPES); |
| 241 | BIND_BITFIELD_FLAG(PATH_METADATA_INCLUDE_RIDS); |
| 242 | BIND_BITFIELD_FLAG(PATH_METADATA_INCLUDE_OWNERS); |
| 243 | BIND_BITFIELD_FLAG(PATH_METADATA_INCLUDE_ALL); |
| 244 | } |