Path: blob/master/servers/navigation/navigation_path_query_parameters_2d.cpp
10277 views
/**************************************************************************/1/* navigation_path_query_parameters_2d.cpp */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#include "navigation_path_query_parameters_2d.h"3132void NavigationPathQueryParameters2D::set_pathfinding_algorithm(const NavigationPathQueryParameters2D::PathfindingAlgorithm p_pathfinding_algorithm) {33pathfinding_algorithm = p_pathfinding_algorithm;34}3536NavigationPathQueryParameters2D::PathfindingAlgorithm NavigationPathQueryParameters2D::get_pathfinding_algorithm() const {37return pathfinding_algorithm;38}3940void NavigationPathQueryParameters2D::set_path_postprocessing(const NavigationPathQueryParameters2D::PathPostProcessing p_path_postprocessing) {41path_postprocessing = p_path_postprocessing;42}4344NavigationPathQueryParameters2D::PathPostProcessing NavigationPathQueryParameters2D::get_path_postprocessing() const {45return path_postprocessing;46}4748void NavigationPathQueryParameters2D::set_map(RID p_map) {49map = p_map;50}5152RID NavigationPathQueryParameters2D::get_map() const {53return map;54}5556void NavigationPathQueryParameters2D::set_start_position(Vector2 p_start_position) {57start_position = p_start_position;58}5960Vector2 NavigationPathQueryParameters2D::get_start_position() const {61return start_position;62}6364void NavigationPathQueryParameters2D::set_target_position(Vector2 p_target_position) {65target_position = p_target_position;66}6768Vector2 NavigationPathQueryParameters2D::get_target_position() const {69return target_position;70}7172void NavigationPathQueryParameters2D::set_navigation_layers(uint32_t p_navigation_layers) {73navigation_layers = p_navigation_layers;74}7576uint32_t NavigationPathQueryParameters2D::get_navigation_layers() const {77return navigation_layers;78}7980void NavigationPathQueryParameters2D::set_metadata_flags(BitField<NavigationPathQueryParameters2D::PathMetadataFlags> p_flags) {81metadata_flags = (int64_t)p_flags;82}8384BitField<NavigationPathQueryParameters2D::PathMetadataFlags> NavigationPathQueryParameters2D::get_metadata_flags() const {85return (int64_t)metadata_flags;86}8788void NavigationPathQueryParameters2D::set_simplify_path(bool p_enabled) {89simplify_path = p_enabled;90}9192bool NavigationPathQueryParameters2D::get_simplify_path() const {93return simplify_path;94}9596void NavigationPathQueryParameters2D::set_simplify_epsilon(real_t p_epsilon) {97simplify_epsilon = MAX(0.0, p_epsilon);98}99100real_t NavigationPathQueryParameters2D::get_simplify_epsilon() const {101return simplify_epsilon;102}103104void NavigationPathQueryParameters2D::set_included_regions(const TypedArray<RID> &p_regions) {105_included_regions.resize(p_regions.size());106for (uint32_t i = 0; i < _included_regions.size(); i++) {107_included_regions[i] = p_regions[i];108}109}110111TypedArray<RID> NavigationPathQueryParameters2D::get_included_regions() const {112TypedArray<RID> r_regions;113r_regions.resize(_included_regions.size());114for (uint32_t i = 0; i < _included_regions.size(); i++) {115r_regions[i] = _included_regions[i];116}117return r_regions;118}119120void NavigationPathQueryParameters2D::set_excluded_regions(const TypedArray<RID> &p_regions) {121_excluded_regions.resize(p_regions.size());122for (uint32_t i = 0; i < _excluded_regions.size(); i++) {123_excluded_regions[i] = p_regions[i];124}125}126127TypedArray<RID> NavigationPathQueryParameters2D::get_excluded_regions() const {128TypedArray<RID> r_regions;129r_regions.resize(_excluded_regions.size());130for (uint32_t i = 0; i < _excluded_regions.size(); i++) {131r_regions[i] = _excluded_regions[i];132}133return r_regions;134}135136void NavigationPathQueryParameters2D::set_path_return_max_length(float p_length) {137path_return_max_length = MAX(0.0, p_length);138}139140float NavigationPathQueryParameters2D::get_path_return_max_length() const {141return path_return_max_length;142}143144void NavigationPathQueryParameters2D::set_path_return_max_radius(float p_radius) {145path_return_max_radius = MAX(0.0, p_radius);146}147148float NavigationPathQueryParameters2D::get_path_return_max_radius() const {149return path_return_max_radius;150}151152void NavigationPathQueryParameters2D::set_path_search_max_polygons(int p_max_polygons) {153path_search_max_polygons = p_max_polygons;154}155156int NavigationPathQueryParameters2D::get_path_search_max_polygons() const {157return path_search_max_polygons;158}159160void NavigationPathQueryParameters2D::set_path_search_max_distance(float p_distance) {161path_search_max_distance = MAX(0.0, p_distance);162}163164float NavigationPathQueryParameters2D::get_path_search_max_distance() const {165return path_search_max_distance;166}167168void NavigationPathQueryParameters2D::_bind_methods() {169ClassDB::bind_method(D_METHOD("set_pathfinding_algorithm", "pathfinding_algorithm"), &NavigationPathQueryParameters2D::set_pathfinding_algorithm);170ClassDB::bind_method(D_METHOD("get_pathfinding_algorithm"), &NavigationPathQueryParameters2D::get_pathfinding_algorithm);171172ClassDB::bind_method(D_METHOD("set_path_postprocessing", "path_postprocessing"), &NavigationPathQueryParameters2D::set_path_postprocessing);173ClassDB::bind_method(D_METHOD("get_path_postprocessing"), &NavigationPathQueryParameters2D::get_path_postprocessing);174175ClassDB::bind_method(D_METHOD("set_map", "map"), &NavigationPathQueryParameters2D::set_map);176ClassDB::bind_method(D_METHOD("get_map"), &NavigationPathQueryParameters2D::get_map);177178ClassDB::bind_method(D_METHOD("set_start_position", "start_position"), &NavigationPathQueryParameters2D::set_start_position);179ClassDB::bind_method(D_METHOD("get_start_position"), &NavigationPathQueryParameters2D::get_start_position);180181ClassDB::bind_method(D_METHOD("set_target_position", "target_position"), &NavigationPathQueryParameters2D::set_target_position);182ClassDB::bind_method(D_METHOD("get_target_position"), &NavigationPathQueryParameters2D::get_target_position);183184ClassDB::bind_method(D_METHOD("set_navigation_layers", "navigation_layers"), &NavigationPathQueryParameters2D::set_navigation_layers);185ClassDB::bind_method(D_METHOD("get_navigation_layers"), &NavigationPathQueryParameters2D::get_navigation_layers);186187ClassDB::bind_method(D_METHOD("set_metadata_flags", "flags"), &NavigationPathQueryParameters2D::set_metadata_flags);188ClassDB::bind_method(D_METHOD("get_metadata_flags"), &NavigationPathQueryParameters2D::get_metadata_flags);189190ClassDB::bind_method(D_METHOD("set_simplify_path", "enabled"), &NavigationPathQueryParameters2D::set_simplify_path);191ClassDB::bind_method(D_METHOD("get_simplify_path"), &NavigationPathQueryParameters2D::get_simplify_path);192193ClassDB::bind_method(D_METHOD("set_simplify_epsilon", "epsilon"), &NavigationPathQueryParameters2D::set_simplify_epsilon);194ClassDB::bind_method(D_METHOD("get_simplify_epsilon"), &NavigationPathQueryParameters2D::get_simplify_epsilon);195196ClassDB::bind_method(D_METHOD("set_included_regions", "regions"), &NavigationPathQueryParameters2D::set_included_regions);197ClassDB::bind_method(D_METHOD("get_included_regions"), &NavigationPathQueryParameters2D::get_included_regions);198199ClassDB::bind_method(D_METHOD("set_excluded_regions", "regions"), &NavigationPathQueryParameters2D::set_excluded_regions);200ClassDB::bind_method(D_METHOD("get_excluded_regions"), &NavigationPathQueryParameters2D::get_excluded_regions);201202ClassDB::bind_method(D_METHOD("set_path_return_max_length", "length"), &NavigationPathQueryParameters2D::set_path_return_max_length);203ClassDB::bind_method(D_METHOD("get_path_return_max_length"), &NavigationPathQueryParameters2D::get_path_return_max_length);204205ClassDB::bind_method(D_METHOD("set_path_return_max_radius", "radius"), &NavigationPathQueryParameters2D::set_path_return_max_radius);206ClassDB::bind_method(D_METHOD("get_path_return_max_radius"), &NavigationPathQueryParameters2D::get_path_return_max_radius);207208ClassDB::bind_method(D_METHOD("set_path_search_max_polygons", "max_polygons"), &NavigationPathQueryParameters2D::set_path_search_max_polygons);209ClassDB::bind_method(D_METHOD("get_path_search_max_polygons"), &NavigationPathQueryParameters2D::get_path_search_max_polygons);210211ClassDB::bind_method(D_METHOD("set_path_search_max_distance", "distance"), &NavigationPathQueryParameters2D::set_path_search_max_distance);212ClassDB::bind_method(D_METHOD("get_path_search_max_distance"), &NavigationPathQueryParameters2D::get_path_search_max_distance);213214ADD_PROPERTY(PropertyInfo(Variant::RID, "map"), "set_map", "get_map");215ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "start_position"), "set_start_position", "get_start_position");216ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "target_position"), "set_target_position", "get_target_position");217ADD_PROPERTY(PropertyInfo(Variant::INT, "navigation_layers", PROPERTY_HINT_LAYERS_2D_NAVIGATION), "set_navigation_layers", "get_navigation_layers");218ADD_PROPERTY(PropertyInfo(Variant::INT, "pathfinding_algorithm", PROPERTY_HINT_ENUM, "AStar"), "set_pathfinding_algorithm", "get_pathfinding_algorithm");219ADD_PROPERTY(PropertyInfo(Variant::INT, "path_postprocessing", PROPERTY_HINT_ENUM, "Corridorfunnel,Edgecentered,None"), "set_path_postprocessing", "get_path_postprocessing");220ADD_PROPERTY(PropertyInfo(Variant::INT, "metadata_flags", PROPERTY_HINT_FLAGS, "Include Types,Include RIDs,Include Owners"), "set_metadata_flags", "get_metadata_flags");221ADD_PROPERTY(PropertyInfo(Variant::BOOL, "simplify_path"), "set_simplify_path", "get_simplify_path");222ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "simplify_epsilon"), "set_simplify_epsilon", "get_simplify_epsilon");223ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "excluded_regions", PROPERTY_HINT_ARRAY_TYPE, "RID"), "set_excluded_regions", "get_excluded_regions");224ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "included_regions", PROPERTY_HINT_ARRAY_TYPE, "RID"), "set_included_regions", "get_included_regions");225ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "path_return_max_length"), "set_path_return_max_length", "get_path_return_max_length");226ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "path_return_max_radius"), "set_path_return_max_radius", "get_path_return_max_radius");227ADD_PROPERTY(PropertyInfo(Variant::INT, "path_search_max_polygons"), "set_path_search_max_polygons", "get_path_search_max_polygons");228ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "path_search_max_distance"), "set_path_search_max_distance", "get_path_search_max_distance");229230BIND_ENUM_CONSTANT(PATHFINDING_ALGORITHM_ASTAR);231232BIND_ENUM_CONSTANT(PATH_POSTPROCESSING_CORRIDORFUNNEL);233BIND_ENUM_CONSTANT(PATH_POSTPROCESSING_EDGECENTERED);234BIND_ENUM_CONSTANT(PATH_POSTPROCESSING_NONE);235236BIND_BITFIELD_FLAG(PATH_METADATA_INCLUDE_NONE);237BIND_BITFIELD_FLAG(PATH_METADATA_INCLUDE_TYPES);238BIND_BITFIELD_FLAG(PATH_METADATA_INCLUDE_RIDS);239BIND_BITFIELD_FLAG(PATH_METADATA_INCLUDE_OWNERS);240BIND_BITFIELD_FLAG(PATH_METADATA_INCLUDE_ALL);241}242243244