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
33void NavigationPathQueryParameters2D::set_pathfinding_algorithm(const NavigationPathQueryParameters2D::PathfindingAlgorithm p_pathfinding_algorithm) {
34 switch (p_pathfinding_algorithm) {
35 case PATHFINDING_ALGORITHM_ASTAR: {
36 parameters.pathfinding_algorithm = NavigationUtilities::PathfindingAlgorithm::PATHFINDING_ALGORITHM_ASTAR;
37 } break;
38 default: {
39 WARN_PRINT_ONCE("No match for used PathfindingAlgorithm - fallback to default");
40 parameters.pathfinding_algorithm = NavigationUtilities::PathfindingAlgorithm::PATHFINDING_ALGORITHM_ASTAR;
41 } break;
42 }
43}
44
45NavigationPathQueryParameters2D::PathfindingAlgorithm NavigationPathQueryParameters2D::get_pathfinding_algorithm() const {
46 switch (parameters.pathfinding_algorithm) {
47 case NavigationUtilities::PathfindingAlgorithm::PATHFINDING_ALGORITHM_ASTAR:
48 return PATHFINDING_ALGORITHM_ASTAR;
49 default:
50 WARN_PRINT_ONCE("No match for used PathfindingAlgorithm - fallback to default");
51 return PATHFINDING_ALGORITHM_ASTAR;
52 }
53}
54
55void NavigationPathQueryParameters2D::set_path_postprocessing(const NavigationPathQueryParameters2D::PathPostProcessing p_path_postprocessing) {
56 switch (p_path_postprocessing) {
57 case PATH_POSTPROCESSING_CORRIDORFUNNEL: {
58 parameters.path_postprocessing = NavigationUtilities::PathPostProcessing::PATH_POSTPROCESSING_CORRIDORFUNNEL;
59 } break;
60 case PATH_POSTPROCESSING_EDGECENTERED: {
61 parameters.path_postprocessing = NavigationUtilities::PathPostProcessing::PATH_POSTPROCESSING_EDGECENTERED;
62 } break;
63 default: {
64 WARN_PRINT_ONCE("No match for used PathPostProcessing - fallback to default");
65 parameters.path_postprocessing = NavigationUtilities::PathPostProcessing::PATH_POSTPROCESSING_CORRIDORFUNNEL;
66 } break;
67 }
68}
69
70NavigationPathQueryParameters2D::PathPostProcessing NavigationPathQueryParameters2D::get_path_postprocessing() const {
71 switch (parameters.path_postprocessing) {
72 case NavigationUtilities::PathPostProcessing::PATH_POSTPROCESSING_CORRIDORFUNNEL:
73 return PATH_POSTPROCESSING_CORRIDORFUNNEL;
74 case NavigationUtilities::PathPostProcessing::PATH_POSTPROCESSING_EDGECENTERED:
75 return PATH_POSTPROCESSING_EDGECENTERED;
76 default:
77 WARN_PRINT_ONCE("No match for used PathPostProcessing - fallback to default");
78 return PATH_POSTPROCESSING_CORRIDORFUNNEL;
79 }
80}
81
82void NavigationPathQueryParameters2D::set_map(const RID &p_map) {
83 parameters.map = p_map;
84}
85
86const RID &NavigationPathQueryParameters2D::get_map() const {
87 return parameters.map;
88}
89
90void NavigationPathQueryParameters2D::set_start_position(const Vector2 p_start_position) {
91 parameters.start_position = Vector3(p_start_position.x, 0.0, p_start_position.y);
92}
93
94Vector2 NavigationPathQueryParameters2D::get_start_position() const {
95 return Vector2(parameters.start_position.x, parameters.start_position.z);
96}
97
98void NavigationPathQueryParameters2D::set_target_position(const Vector2 p_target_position) {
99 parameters.target_position = Vector3(p_target_position.x, 0.0, p_target_position.y);
100}
101
102Vector2 NavigationPathQueryParameters2D::get_target_position() const {
103 return Vector2(parameters.target_position.x, parameters.target_position.z);
104}
105
106void NavigationPathQueryParameters2D::set_navigation_layers(uint32_t p_navigation_layers) {
107 parameters.navigation_layers = p_navigation_layers;
108}
109
110uint32_t NavigationPathQueryParameters2D::get_navigation_layers() const {
111 return parameters.navigation_layers;
112}
113
114void NavigationPathQueryParameters2D::set_metadata_flags(BitField<NavigationPathQueryParameters2D::PathMetadataFlags> p_flags) {
115 parameters.metadata_flags = (int64_t)p_flags;
116}
117
118BitField<NavigationPathQueryParameters2D::PathMetadataFlags> NavigationPathQueryParameters2D::get_metadata_flags() const {
119 return (int64_t)parameters.metadata_flags;
120}
121
122void NavigationPathQueryParameters2D::_bind_methods() {
123 ClassDB::bind_method(D_METHOD("set_pathfinding_algorithm", "pathfinding_algorithm"), &NavigationPathQueryParameters2D::set_pathfinding_algorithm);
124 ClassDB::bind_method(D_METHOD("get_pathfinding_algorithm"), &NavigationPathQueryParameters2D::get_pathfinding_algorithm);
125
126 ClassDB::bind_method(D_METHOD("set_path_postprocessing", "path_postprocessing"), &NavigationPathQueryParameters2D::set_path_postprocessing);
127 ClassDB::bind_method(D_METHOD("get_path_postprocessing"), &NavigationPathQueryParameters2D::get_path_postprocessing);
128
129 ClassDB::bind_method(D_METHOD("set_map", "map"), &NavigationPathQueryParameters2D::set_map);
130 ClassDB::bind_method(D_METHOD("get_map"), &NavigationPathQueryParameters2D::get_map);
131
132 ClassDB::bind_method(D_METHOD("set_start_position", "start_position"), &NavigationPathQueryParameters2D::set_start_position);
133 ClassDB::bind_method(D_METHOD("get_start_position"), &NavigationPathQueryParameters2D::get_start_position);
134
135 ClassDB::bind_method(D_METHOD("set_target_position", "target_position"), &NavigationPathQueryParameters2D::set_target_position);
136 ClassDB::bind_method(D_METHOD("get_target_position"), &NavigationPathQueryParameters2D::get_target_position);
137
138 ClassDB::bind_method(D_METHOD("set_navigation_layers", "navigation_layers"), &NavigationPathQueryParameters2D::set_navigation_layers);
139 ClassDB::bind_method(D_METHOD("get_navigation_layers"), &NavigationPathQueryParameters2D::get_navigation_layers);
140
141 ClassDB::bind_method(D_METHOD("set_metadata_flags", "flags"), &NavigationPathQueryParameters2D::set_metadata_flags);
142 ClassDB::bind_method(D_METHOD("get_metadata_flags"), &NavigationPathQueryParameters2D::get_metadata_flags);
143
144 ADD_PROPERTY(PropertyInfo(Variant::RID, "map"), "set_map", "get_map");
145 ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "start_position"), "set_start_position", "get_start_position");
146 ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "target_position"), "set_target_position", "get_target_position");
147 ADD_PROPERTY(PropertyInfo(Variant::INT, "navigation_layers", PROPERTY_HINT_LAYERS_2D_NAVIGATION), "set_navigation_layers", "get_navigation_layers");
148 ADD_PROPERTY(PropertyInfo(Variant::INT, "pathfinding_algorithm", PROPERTY_HINT_ENUM, "AStar"), "set_pathfinding_algorithm", "get_pathfinding_algorithm");
149 ADD_PROPERTY(PropertyInfo(Variant::INT, "path_postprocessing", PROPERTY_HINT_ENUM, "Corridorfunnel,Edgecentered"), "set_path_postprocessing", "get_path_postprocessing");
150 ADD_PROPERTY(PropertyInfo(Variant::INT, "metadata_flags", PROPERTY_HINT_FLAGS, "Include Types,Include RIDs,Include Owners"), "set_metadata_flags", "get_metadata_flags");
151
152 BIND_ENUM_CONSTANT(PATHFINDING_ALGORITHM_ASTAR);
153
154 BIND_ENUM_CONSTANT(PATH_POSTPROCESSING_CORRIDORFUNNEL);
155 BIND_ENUM_CONSTANT(PATH_POSTPROCESSING_EDGECENTERED);
156
157 BIND_BITFIELD_FLAG(PATH_METADATA_INCLUDE_NONE);
158 BIND_BITFIELD_FLAG(PATH_METADATA_INCLUDE_TYPES);
159 BIND_BITFIELD_FLAG(PATH_METADATA_INCLUDE_RIDS);
160 BIND_BITFIELD_FLAG(PATH_METADATA_INCLUDE_OWNERS);
161 BIND_BITFIELD_FLAG(PATH_METADATA_INCLUDE_ALL);
162}
163