From f6e65112d725bdbf92b4e791ebbcc81117810384 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 8 Jun 2023 18:23:48 +0200 Subject: [PATCH] Backported from godot4: Add NavigationPathQuery Adds NavigationPathQueryParameters objects that can be used with NavigationServer.query_path() to query a customized navigation path. - smix8 https://github.com/godotengine/godot/commit/63dcb9aa80a2c77053033ed3c39b4fe5ed6f229b --- doc/classes/Navigation2DServer.xml | 8 + .../NavigationPathQueryParameters2D.xml | 61 +++++++ .../NavigationPathQueryParameters3D.xml | 61 +++++++ doc/classes/NavigationPathQueryResult2D.xml | 42 +++++ doc/classes/NavigationPathQueryResult3D.xml | 42 +++++ doc/classes/NavigationServer.xml | 8 + .../pandemonium_navigation_2d_server.cpp | 54 ++++-- .../pandemonium_navigation_2d_server.h | 2 + .../pandemonium_navigation_server.cpp | 37 ++++ .../pandemonium_navigation_server.h | 2 + .../dummy_navigation_2d_server.cpp | 4 + .../dummy_navigation_2d_server.h | 2 + .../dummy_navigation_server.cpp | 4 + .../dummy_navigation_server.h | 2 + .../navigation_path_query_parameters_2d.cpp | 162 ++++++++++++++++++ .../navigation_path_query_parameters_2d.h | 92 ++++++++++ .../navigation_path_query_parameters_3d.cpp | 162 ++++++++++++++++++ .../navigation_path_query_parameters_3d.h | 91 ++++++++++ .../navigation_path_query_result_2d.cpp | 94 ++++++++++ .../navigation_path_query_result_2d.h | 71 ++++++++ .../navigation_path_query_result_3d.cpp | 94 ++++++++++ .../navigation_path_query_result_3d.h | 72 ++++++++ servers/navigation/navigation_utilities.h | 100 +++++++++++ servers/navigation_2d_server.cpp | 11 ++ servers/navigation_2d_server.h | 9 + servers/navigation_server.cpp | 13 ++ servers/navigation_server.h | 9 + servers/register_server_types.cpp | 9 + 28 files changed, 1307 insertions(+), 11 deletions(-) create mode 100644 doc/classes/NavigationPathQueryParameters2D.xml create mode 100644 doc/classes/NavigationPathQueryParameters3D.xml create mode 100644 doc/classes/NavigationPathQueryResult2D.xml create mode 100644 doc/classes/NavigationPathQueryResult3D.xml create mode 100644 servers/navigation/navigation_path_query_parameters_2d.cpp create mode 100644 servers/navigation/navigation_path_query_parameters_2d.h create mode 100644 servers/navigation/navigation_path_query_parameters_3d.cpp create mode 100644 servers/navigation/navigation_path_query_parameters_3d.h create mode 100644 servers/navigation/navigation_path_query_result_2d.cpp create mode 100644 servers/navigation/navigation_path_query_result_2d.h create mode 100644 servers/navigation/navigation_path_query_result_3d.cpp create mode 100644 servers/navigation/navigation_path_query_result_3d.h create mode 100644 servers/navigation/navigation_utilities.h diff --git a/doc/classes/Navigation2DServer.xml b/doc/classes/Navigation2DServer.xml index a6f488ead..4d6abd7ef 100644 --- a/doc/classes/Navigation2DServer.xml +++ b/doc/classes/Navigation2DServer.xml @@ -250,6 +250,14 @@ Set the map edge connection margin used to weld the compatible region edges. + + + + + + Queries a path in a given navigation map. Start and target position and other parameters are defined through [NavigationPathQueryParameters2D]. Updates the provided [NavigationPathQueryResult2D] result object with the path among other results requested by the query. + + diff --git a/doc/classes/NavigationPathQueryParameters2D.xml b/doc/classes/NavigationPathQueryParameters2D.xml new file mode 100644 index 000000000..a17d560bd --- /dev/null +++ b/doc/classes/NavigationPathQueryParameters2D.xml @@ -0,0 +1,61 @@ + + + + Provides parameters for 2D navigation path queries. + + + By changing various properties of this object, such as the start and target position, you can configure path queries to the [NavigationServer2D]. + + + $DOCS_URL/tutorials/navigation/navigation_using_navigationpathqueryobjects.html + + + + The navigation [code]map[/code] [RID] used in the path query. + + + Additional information to include with the navigation path. + + + The navigation layers the query will use (as a bitmask). + + + The path postprocessing applied to the raw path corridor found by the [member pathfinding_algorithm]. + + + The pathfinding algorithm used in the path query. + + + The pathfinding start position in global coordinates. + + + The pathfinding target position in global coordinates. + + + + + The path query uses the default A* pathfinding algorithm. + + + Applies a funnel algorithm to the raw path corridor found by the pathfinding algorithm. This will result in the shortest path possible inside the path corridor. This postprocessing very much depends on the navigation mesh polygon layout and the created corridor. Especially tile- or gridbased layouts can face artificial corners with diagonal movement due to a jagged path corridor imposed by the cell shapes. + + + Centers every path position in the middle of the traveled navigation mesh polygon edge. This creates better paths for tile- or gridbased layouts that restrict the movement to the cells center. + + + Don't include any additional metadata about the returned path. + + + Include the type of navigation primitive (region or link) that each point of the path goes through. + + + Include the [RID]s of the regions and links that each point of the path goes through. + + + Include the [code]ObjectID[/code]s of the [Object]s which manage the regions and links each point of the path goes through. + + + Include all available metadata about the returned path. + + + diff --git a/doc/classes/NavigationPathQueryParameters3D.xml b/doc/classes/NavigationPathQueryParameters3D.xml new file mode 100644 index 000000000..8c5155a6b --- /dev/null +++ b/doc/classes/NavigationPathQueryParameters3D.xml @@ -0,0 +1,61 @@ + + + + Provides parameters for 3D navigation path queries. + + + By changing various properties of this object, such as the start and target position, you can configure path queries to the [NavigationServer3D]. + + + $DOCS_URL/tutorials/navigation/navigation_using_navigationpathqueryobjects.html + + + + The navigation [code]map[/code] [RID] used in the path query. + + + Additional information to include with the navigation path. + + + The navigation layers the query will use (as a bitmask). + + + The path postprocessing applied to the raw path corridor found by the [member pathfinding_algorithm]. + + + The pathfinding algorithm used in the path query. + + + The pathfinding start position in global coordinates. + + + The pathfinding target position in global coordinates. + + + + + The path query uses the default A* pathfinding algorithm. + + + Applies a funnel algorithm to the raw path corridor found by the pathfinding algorithm. This will result in the shortest path possible inside the path corridor. This postprocessing very much depends on the navigation mesh polygon layout and the created corridor. Especially tile- or gridbased layouts can face artificial corners with diagonal movement due to a jagged path corridor imposed by the cell shapes. + + + Centers every path position in the middle of the traveled navigation mesh polygon edge. This creates better paths for tile- or gridbased layouts that restrict the movement to the cells center. + + + Don't include any additional metadata about the returned path. + + + Include the type of navigation primitive (region or link) that each point of the path goes through. + + + Include the [RID]s of the regions and links that each point of the path goes through. + + + Include the [code]ObjectID[/code]s of the [Object]s which manage the regions and links each point of the path goes through. + + + Include all available metadata about the returned path. + + + diff --git a/doc/classes/NavigationPathQueryResult2D.xml b/doc/classes/NavigationPathQueryResult2D.xml new file mode 100644 index 000000000..c02cc4352 --- /dev/null +++ b/doc/classes/NavigationPathQueryResult2D.xml @@ -0,0 +1,42 @@ + + + + Represents the result of a 2D pathfinding query. + + + This class stores the result of a 2D navigation path query from the [NavigationServer2D]. + + + $DOCS_URL/tutorials/navigation/navigation_using_navigationpathqueryobjects.html + + + + + + Reset the result object to its initial state. This is useful to reuse the object across multiple queries. + + + + + + The resulting path array from the navigation query. All path array positions are in global coordinates. Without customized query parameters this is the same path as returned by [method NavigationServer2D.map_get_path]. + + + The [code]ObjectID[/code]s of the [Object]s which manage the regions and links each point of the path goes through. + + + The [RID]s of the regions and links that each point of the path goes through. + + + The type of navigation primitive (region or link) that each point of the path goes through. + + + + + This segment of the path goes through a region. + + + This segment of the path goes through a link. + + + diff --git a/doc/classes/NavigationPathQueryResult3D.xml b/doc/classes/NavigationPathQueryResult3D.xml new file mode 100644 index 000000000..e4de95fac --- /dev/null +++ b/doc/classes/NavigationPathQueryResult3D.xml @@ -0,0 +1,42 @@ + + + + Represents the result of a 3D pathfinding query. + + + This class stores the result of a 3D navigation path query from the [NavigationServer3D]. + + + $DOCS_URL/tutorials/navigation/navigation_using_navigationpathqueryobjects.html + + + + + + Reset the result object to its initial state. This is useful to reuse the object across multiple queries. + + + + + + The resulting path array from the navigation query. All path array positions are in global coordinates. Without customized query parameters this is the same path as returned by [method NavigationServer3D.map_get_path]. + + + The [code]ObjectID[/code]s of the [Object]s which manage the regions and links each point of the path goes through. + + + The [RID]s of the regions and links that each point of the path goes through. + + + The type of navigation primitive (region or link) that each point of the path goes through. + + + + + This segment of the path goes through a region. + + + This segment of the path goes through a link. + + + diff --git a/doc/classes/NavigationServer.xml b/doc/classes/NavigationServer.xml index 432e1a7d2..afda8c4e5 100644 --- a/doc/classes/NavigationServer.xml +++ b/doc/classes/NavigationServer.xml @@ -292,6 +292,14 @@ [b]Note:[/b] This function is not thread safe. + + + + + + Queries a path in a given navigation map. Start and target position and other parameters are defined through [NavigationPathQueryParameters3D]. Updates the provided [NavigationPathQueryResult3D] result object with the path among other results requested by the query. + + diff --git a/modules/navigation/pandemonium_navigation_2d_server.cpp b/modules/navigation/pandemonium_navigation_2d_server.cpp index 13d757728..a66c936fc 100644 --- a/modules/navigation/pandemonium_navigation_2d_server.cpp +++ b/modules/navigation/pandemonium_navigation_2d_server.cpp @@ -36,66 +36,66 @@ #include "servers/navigation_server.h" #define FORWARD_0_C(FUNC_NAME) \ - PandemoniumNavigation2DServer::FUNC_NAME() \ + PandemoniumNavigation2DServer::FUNC_NAME() \ const { \ return NavigationServer::get_singleton()->FUNC_NAME(); \ } #define FORWARD_1(FUNC_NAME, T_0, D_0, CONV_0) \ - PandemoniumNavigation2DServer::FUNC_NAME(T_0 D_0) { \ + PandemoniumNavigation2DServer::FUNC_NAME(T_0 D_0) { \ return NavigationServer::get_singleton_mut()->FUNC_NAME(CONV_0(D_0)); \ } #define FORWARD_1_C(FUNC_NAME, T_0, D_0, CONV_0) \ - PandemoniumNavigation2DServer::FUNC_NAME(T_0 D_0) \ + PandemoniumNavigation2DServer::FUNC_NAME(T_0 D_0) \ const { \ return NavigationServer::get_singleton()->FUNC_NAME(CONV_0(D_0)); \ } #define FORWARD_2_C(FUNC_NAME, T_0, D_0, T_1, D_1, CONV_0, CONV_1) \ - PandemoniumNavigation2DServer::FUNC_NAME(T_0 D_0, T_1 D_1) \ + PandemoniumNavigation2DServer::FUNC_NAME(T_0 D_0, T_1 D_1) \ const { \ return NavigationServer::get_singleton()->FUNC_NAME(CONV_0(D_0), CONV_1(D_1)); \ } #define FORWARD_2_R_C(CONV_R, FUNC_NAME, T_0, D_0, T_1, D_1, CONV_0, CONV_1) \ - PandemoniumNavigation2DServer::FUNC_NAME(T_0 D_0, T_1 D_1) \ + PandemoniumNavigation2DServer::FUNC_NAME(T_0 D_0, T_1 D_1) \ const { \ return CONV_R(NavigationServer::get_singleton()->FUNC_NAME(CONV_0(D_0), CONV_1(D_1))); \ } #define FORWARD_3_R_C(CONV_R, FUNC_NAME, T_0, D_0, T_1, D_1, T_2, D_2, CONV_0, CONV_1, CONV_2) \ - PandemoniumNavigation2DServer::FUNC_NAME(T_0 D_0, T_1 D_1, T_2 D_2) \ + PandemoniumNavigation2DServer::FUNC_NAME(T_0 D_0, T_1 D_1, T_2 D_2) \ const { \ return CONV_R(NavigationServer::get_singleton()->FUNC_NAME(CONV_0(D_0), CONV_1(D_1), CONV_2(D_2))); \ } #define FORWARD_3_C(FUNC_NAME, T_0, D_0, T_1, D_1, T_2, D_2, CONV_0, CONV_1, CONV_2) \ - PandemoniumNavigation2DServer::FUNC_NAME(T_0 D_0, T_1 D_1, T_2 D_2) \ + PandemoniumNavigation2DServer::FUNC_NAME(T_0 D_0, T_1 D_1, T_2 D_2) \ const { \ return NavigationServer::get_singleton()->FUNC_NAME(CONV_0(D_0), CONV_1(D_1), CONV_2(D_2)); \ } #define FORWARD_4_R_C(CONV_R, FUNC_NAME, T_0, D_0, T_1, D_1, T_2, D_2, T_3, D_3, CONV_0, CONV_1, CONV_2, CONV_3) \ - PandemoniumNavigation2DServer::FUNC_NAME(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3) \ + PandemoniumNavigation2DServer::FUNC_NAME(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3) \ const { \ return CONV_R(NavigationServer::get_singleton()->FUNC_NAME(CONV_0(D_0), CONV_1(D_1), CONV_2(D_2), CONV_3(D_3))); \ } #define FORWARD_4_C(FUNC_NAME, T_0, D_0, T_1, D_1, T_2, D_2, T_3, D_3, CONV_0, CONV_1, CONV_2, CONV_3) \ - PandemoniumNavigation2DServer::FUNC_NAME(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3) \ + PandemoniumNavigation2DServer::FUNC_NAME(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3) \ const { \ return NavigationServer::get_singleton()->FUNC_NAME(CONV_0(D_0), CONV_1(D_1), CONV_2(D_2), CONV_3(D_3)); \ } #define FORWARD_5_R_C(CONV_R, FUNC_NAME, T_0, D_0, T_1, D_1, T_2, D_2, T_3, D_3, T_4, D_4, CONV_0, CONV_1, CONV_2, CONV_3, CONV_4) \ - PandemoniumNavigation2DServer::FUNC_NAME(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3, T_4 D_4) \ + PandemoniumNavigation2DServer::FUNC_NAME(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3, T_4 D_4) \ const { \ return CONV_R(NavigationServer::get_singleton()->FUNC_NAME(CONV_0(D_0), CONV_1(D_1), CONV_2(D_2), CONV_3(D_3), CONV_4(D_4))); \ } #define FORWARD_5_C(FUNC_NAME, T_0, D_0, T_1, D_1, T_2, D_2, T_3, D_3, T_4, D_4, CONV_0, CONV_1, CONV_2, CONV_3, CONV_4) \ - PandemoniumNavigation2DServer::FUNC_NAME(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3, T_4 D_4) \ + PandemoniumNavigation2DServer::FUNC_NAME(T_0 D_0, T_1 D_1, T_2 D_2, T_3 D_3, T_4 D_4) \ const { \ return NavigationServer::get_singleton()->FUNC_NAME(CONV_0(D_0), CONV_1(D_1), CONV_2(D_2), CONV_3(D_3), CONV_4(D_4)); \ } @@ -137,6 +137,17 @@ Vector vector_v3_to_v2(const Vector &d) { return nd; } +PoolVector poolvector_v3_to_v2(const PoolVector &d) { + PoolVector nd; + nd.resize(d.size()); + PoolVector2Array::Write w = nd.write(); + Vector2 *wptr = w.ptr(); + for (int i(0); i < nd.size(); i++) { + wptr[i] = v3_to_v2(d[i]); + } + return nd; +} + Transform trf2_to_trf3(const Transform2D &d) { Vector3 o(v2_to_v3(d.get_origin())); Basis b; @@ -267,3 +278,24 @@ bool FORWARD_1_C(agent_is_map_changed, RID, p_agent, rid_to_rid); void FORWARD_4_C(agent_set_callback, RID, p_agent, ObjectID, p_object_id, StringName, p_method, Variant, p_udata, rid_to_rid, id_to_id, sn_to_sn, var_to_var); void FORWARD_1_C(free, RID, p_object, rid_to_rid); + +NavigationUtilities::PathQueryResult2D PandemoniumNavigation2DServer::_query_path(const NavigationUtilities::PathQueryParameters2D &p_parameters) const { + NavigationUtilities::PathQueryParameters params; + params.pathfinding_algorithm = p_parameters.pathfinding_algorithm; + params.path_postprocessing = p_parameters.path_postprocessing; + params.map = p_parameters.map; + params.start_position = Vector3(p_parameters.start_position.x, 0.0, p_parameters.start_position.y); + params.target_position = Vector3(p_parameters.target_position.x, 0.0, p_parameters.target_position.y); + params.navigation_layers = p_parameters.navigation_layers; + params.metadata_flags = p_parameters.metadata_flags; + + NavigationUtilities::PathQueryResult res = NavigationServer::get_singleton()->_query_path(params); + + NavigationUtilities::PathQueryResult2D resf; + resf.path = poolvector_v3_to_v2(res.path); + resf.path_types = res.path_types; + resf.path_rids = res.path_rids; + resf.path_owner_ids = res.path_owner_ids; + + return resf; +} \ No newline at end of file diff --git a/modules/navigation/pandemonium_navigation_2d_server.h b/modules/navigation/pandemonium_navigation_2d_server.h index 4f3ba22fa..bcc2cbd0e 100644 --- a/modules/navigation/pandemonium_navigation_2d_server.h +++ b/modules/navigation/pandemonium_navigation_2d_server.h @@ -179,6 +179,8 @@ public: /// Destroy the `RID` virtual void free(RID p_object) const; + virtual NavigationUtilities::PathQueryResult2D _query_path(const NavigationUtilities::PathQueryParameters2D &p_parameters) const; + PandemoniumNavigation2DServer(); virtual ~PandemoniumNavigation2DServer(); }; diff --git a/modules/navigation/pandemonium_navigation_server.cpp b/modules/navigation/pandemonium_navigation_server.cpp index 6433382f4..ad77225f7 100644 --- a/modules/navigation/pandemonium_navigation_server.cpp +++ b/modules/navigation/pandemonium_navigation_server.cpp @@ -664,6 +664,43 @@ void PandemoniumNavigationServer::process(real_t p_delta_time) { } } +NavigationUtilities::PathQueryResult PandemoniumNavigationServer::_query_path(const NavigationUtilities::PathQueryParameters &p_parameters) const { + NavigationUtilities::PathQueryResult r_query_result; + + const NavMap *map = map_owner.getornull(p_parameters.map); + ERR_FAIL_COND_V(map == nullptr, r_query_result); + + // run the pathfinding + + if (p_parameters.pathfinding_algorithm == NavigationUtilities::PathfindingAlgorithm::PATHFINDING_ALGORITHM_ASTAR) { + Vector path; + // while postprocessing is still part of map.get_path() need to check and route it here for the correct "optimize" post-processing + if (p_parameters.path_postprocessing == NavigationUtilities::PathPostProcessing::PATH_POSTPROCESSING_CORRIDORFUNNEL) { + path = map->get_path(p_parameters.start_position, p_parameters.target_position, true, p_parameters.navigation_layers); + } else if (p_parameters.path_postprocessing == NavigationUtilities::PathPostProcessing::PATH_POSTPROCESSING_EDGECENTERED) { + path = map->get_path(p_parameters.start_position, p_parameters.target_position, false, p_parameters.navigation_layers); + } + + r_query_result.path.resize(path.size()); + + PoolVector3Array::Write w = r_query_result.path.write(); + Vector3 *wptr = w.ptr(); + const Vector3 *pptr = path.ptr(); + + for (int i = 0; i < path.size(); ++i) { + wptr[i] = pptr[i]; + } + } else { + return r_query_result; + } + + // add path postprocessing + + // add path stats + + return r_query_result; +} + #undef COMMAND_1 #undef COMMAND_2 #undef COMMAND_4 diff --git a/modules/navigation/pandemonium_navigation_server.h b/modules/navigation/pandemonium_navigation_server.h index c436e1977..de98b8978 100644 --- a/modules/navigation/pandemonium_navigation_server.h +++ b/modules/navigation/pandemonium_navigation_server.h @@ -153,6 +153,8 @@ public: void flush_queries(); virtual void process(real_t p_delta_time); + + virtual NavigationUtilities::PathQueryResult _query_path(const NavigationUtilities::PathQueryParameters &p_parameters) const; }; #undef COMMAND_1 diff --git a/modules/navigation_dummy/dummy_navigation_2d_server.cpp b/modules/navigation_dummy/dummy_navigation_2d_server.cpp index a21b54b91..d60f790c7 100644 --- a/modules/navigation_dummy/dummy_navigation_2d_server.cpp +++ b/modules/navigation_dummy/dummy_navigation_2d_server.cpp @@ -35,6 +35,10 @@ void DummyNavigation2DServer::region_set_navpoly(RID p_region, Ref p_nav_mesh) const { } +NavigationUtilities::PathQueryResult2D DummyNavigation2DServer::_query_path(const NavigationUtilities::PathQueryParameters2D &p_parameters) const { + return NavigationUtilities::PathQueryResult2D(); +} + DummyNavigation2DServer::DummyNavigation2DServer() { } diff --git a/modules/navigation_dummy/dummy_navigation_2d_server.h b/modules/navigation_dummy/dummy_navigation_2d_server.h index f23106b24..e4569ba0f 100644 --- a/modules/navigation_dummy/dummy_navigation_2d_server.h +++ b/modules/navigation_dummy/dummy_navigation_2d_server.h @@ -60,6 +60,8 @@ public: virtual void free(RID p_object) const {} + virtual NavigationUtilities::PathQueryResult2D _query_path(const NavigationUtilities::PathQueryParameters2D &p_parameters) const; + DummyNavigation2DServer(); virtual ~DummyNavigation2DServer(); }; diff --git a/modules/navigation_dummy/dummy_navigation_server.cpp b/modules/navigation_dummy/dummy_navigation_server.cpp index c0934aa43..ab91dab90 100644 --- a/modules/navigation_dummy/dummy_navigation_server.cpp +++ b/modules/navigation_dummy/dummy_navigation_server.cpp @@ -6,6 +6,10 @@ void DummyNavigationServer::region_set_navmesh(RID p_region, Ref p_nav_mesh) const { } +NavigationUtilities::PathQueryResult DummyNavigationServer::_query_path(const NavigationUtilities::PathQueryParameters &p_parameters) const { + return NavigationUtilities::PathQueryResult(); +} + DummyNavigationServer::DummyNavigationServer() { } diff --git a/modules/navigation_dummy/dummy_navigation_server.h b/modules/navigation_dummy/dummy_navigation_server.h index d1667bc3b..7134abda8 100644 --- a/modules/navigation_dummy/dummy_navigation_server.h +++ b/modules/navigation_dummy/dummy_navigation_server.h @@ -67,6 +67,8 @@ public: virtual void process(real_t delta_time){}; + virtual NavigationUtilities::PathQueryResult _query_path(const NavigationUtilities::PathQueryParameters &p_parameters) const; + DummyNavigationServer(); virtual ~DummyNavigationServer(); }; diff --git a/servers/navigation/navigation_path_query_parameters_2d.cpp b/servers/navigation/navigation_path_query_parameters_2d.cpp new file mode 100644 index 000000000..5ddb50fcc --- /dev/null +++ b/servers/navigation/navigation_path_query_parameters_2d.cpp @@ -0,0 +1,162 @@ +/**************************************************************************/ +/* navigation_path_query_parameters_2d.cpp */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#include "navigation_path_query_parameters_2d.h" + +void NavigationPathQueryParameters2D::set_pathfinding_algorithm(const NavigationPathQueryParameters2D::PathfindingAlgorithm p_pathfinding_algorithm) { + switch (p_pathfinding_algorithm) { + case PATHFINDING_ALGORITHM_ASTAR: { + parameters.pathfinding_algorithm = NavigationUtilities::PathfindingAlgorithm::PATHFINDING_ALGORITHM_ASTAR; + } break; + default: { + WARN_PRINT_ONCE("No match for used PathfindingAlgorithm - fallback to default"); + parameters.pathfinding_algorithm = NavigationUtilities::PathfindingAlgorithm::PATHFINDING_ALGORITHM_ASTAR; + } break; + } +} + +NavigationPathQueryParameters2D::PathfindingAlgorithm NavigationPathQueryParameters2D::get_pathfinding_algorithm() const { + switch (parameters.pathfinding_algorithm) { + case NavigationUtilities::PathfindingAlgorithm::PATHFINDING_ALGORITHM_ASTAR: + return PATHFINDING_ALGORITHM_ASTAR; + default: + WARN_PRINT_ONCE("No match for used PathfindingAlgorithm - fallback to default"); + return PATHFINDING_ALGORITHM_ASTAR; + } +} + +void NavigationPathQueryParameters2D::set_path_postprocessing(const NavigationPathQueryParameters2D::PathPostProcessing p_path_postprocessing) { + switch (p_path_postprocessing) { + case PATH_POSTPROCESSING_CORRIDORFUNNEL: { + parameters.path_postprocessing = NavigationUtilities::PathPostProcessing::PATH_POSTPROCESSING_CORRIDORFUNNEL; + } break; + case PATH_POSTPROCESSING_EDGECENTERED: { + parameters.path_postprocessing = NavigationUtilities::PathPostProcessing::PATH_POSTPROCESSING_EDGECENTERED; + } break; + default: { + WARN_PRINT_ONCE("No match for used PathPostProcessing - fallback to default"); + parameters.path_postprocessing = NavigationUtilities::PathPostProcessing::PATH_POSTPROCESSING_CORRIDORFUNNEL; + } break; + } +} + +NavigationPathQueryParameters2D::PathPostProcessing NavigationPathQueryParameters2D::get_path_postprocessing() const { + switch (parameters.path_postprocessing) { + case NavigationUtilities::PathPostProcessing::PATH_POSTPROCESSING_CORRIDORFUNNEL: + return PATH_POSTPROCESSING_CORRIDORFUNNEL; + case NavigationUtilities::PathPostProcessing::PATH_POSTPROCESSING_EDGECENTERED: + return PATH_POSTPROCESSING_EDGECENTERED; + default: + WARN_PRINT_ONCE("No match for used PathPostProcessing - fallback to default"); + return PATH_POSTPROCESSING_CORRIDORFUNNEL; + } +} + +void NavigationPathQueryParameters2D::set_map(const RID &p_map) { + parameters.map = p_map; +} + +const RID &NavigationPathQueryParameters2D::get_map() const { + return parameters.map; +} + +void NavigationPathQueryParameters2D::set_start_position(const Vector2 p_start_position) { + parameters.start_position = p_start_position; +} + +Vector2 NavigationPathQueryParameters2D::get_start_position() const { + return parameters.start_position; +} + +void NavigationPathQueryParameters2D::set_target_position(const Vector2 p_target_position) { + parameters.target_position = p_target_position; +} + +Vector2 NavigationPathQueryParameters2D::get_target_position() const { + return parameters.target_position; +} + +void NavigationPathQueryParameters2D::set_navigation_layers(uint32_t p_navigation_layers) { + parameters.navigation_layers = p_navigation_layers; +} + +uint32_t NavigationPathQueryParameters2D::get_navigation_layers() const { + return parameters.navigation_layers; +} + +void NavigationPathQueryParameters2D::set_metadata_flags(const int p_flags) { + parameters.metadata_flags = (int64_t)p_flags; +} + +int NavigationPathQueryParameters2D::get_metadata_flags() const { + return (int64_t)parameters.metadata_flags; +} + +void NavigationPathQueryParameters2D::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_pathfinding_algorithm", "pathfinding_algorithm"), &NavigationPathQueryParameters2D::set_pathfinding_algorithm); + ClassDB::bind_method(D_METHOD("get_pathfinding_algorithm"), &NavigationPathQueryParameters2D::get_pathfinding_algorithm); + + ClassDB::bind_method(D_METHOD("set_path_postprocessing", "path_postprocessing"), &NavigationPathQueryParameters2D::set_path_postprocessing); + ClassDB::bind_method(D_METHOD("get_path_postprocessing"), &NavigationPathQueryParameters2D::get_path_postprocessing); + + ClassDB::bind_method(D_METHOD("set_map", "map"), &NavigationPathQueryParameters2D::set_map); + ClassDB::bind_method(D_METHOD("get_map"), &NavigationPathQueryParameters2D::get_map); + + ClassDB::bind_method(D_METHOD("set_start_position", "start_position"), &NavigationPathQueryParameters2D::set_start_position); + ClassDB::bind_method(D_METHOD("get_start_position"), &NavigationPathQueryParameters2D::get_start_position); + + ClassDB::bind_method(D_METHOD("set_target_position", "target_position"), &NavigationPathQueryParameters2D::set_target_position); + ClassDB::bind_method(D_METHOD("get_target_position"), &NavigationPathQueryParameters2D::get_target_position); + + ClassDB::bind_method(D_METHOD("set_navigation_layers", "navigation_layers"), &NavigationPathQueryParameters2D::set_navigation_layers); + ClassDB::bind_method(D_METHOD("get_navigation_layers"), &NavigationPathQueryParameters2D::get_navigation_layers); + + ClassDB::bind_method(D_METHOD("set_metadata_flags", "flags"), &NavigationPathQueryParameters2D::set_metadata_flags); + ClassDB::bind_method(D_METHOD("get_metadata_flags"), &NavigationPathQueryParameters2D::get_metadata_flags); + + ADD_PROPERTY(PropertyInfo(Variant::RID, "map"), "set_map", "get_map"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "start_position"), "set_start_position", "get_start_position"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "target_position"), "set_target_position", "get_target_position"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "navigation_layers", PROPERTY_HINT_LAYERS_2D_NAVIGATION), "set_navigation_layers", "get_navigation_layers"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "pathfinding_algorithm", PROPERTY_HINT_ENUM, "AStar"), "set_pathfinding_algorithm", "get_pathfinding_algorithm"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "path_postprocessing", PROPERTY_HINT_ENUM, "Corridorfunnel,Edgecentered"), "set_path_postprocessing", "get_path_postprocessing"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "metadata_flags", PROPERTY_HINT_FLAGS, "Include Types,Include RIDs,Include Owners"), "set_metadata_flags", "get_metadata_flags"); + + BIND_ENUM_CONSTANT(PATHFINDING_ALGORITHM_ASTAR); + + BIND_ENUM_CONSTANT(PATH_POSTPROCESSING_CORRIDORFUNNEL); + BIND_ENUM_CONSTANT(PATH_POSTPROCESSING_EDGECENTERED); + + BIND_ENUM_CONSTANT(PATH_METADATA_INCLUDE_NONE); + BIND_ENUM_CONSTANT(PATH_METADATA_INCLUDE_TYPES); + BIND_ENUM_CONSTANT(PATH_METADATA_INCLUDE_RIDS); + BIND_ENUM_CONSTANT(PATH_METADATA_INCLUDE_OWNERS); + BIND_ENUM_CONSTANT(PATH_METADATA_INCLUDE_ALL); +} diff --git a/servers/navigation/navigation_path_query_parameters_2d.h b/servers/navigation/navigation_path_query_parameters_2d.h new file mode 100644 index 000000000..938cbcfa2 --- /dev/null +++ b/servers/navigation/navigation_path_query_parameters_2d.h @@ -0,0 +1,92 @@ + +#ifndef NAVIGATION_PATH_QUERY_PARAMETERS_2D_H +#define NAVIGATION_PATH_QUERY_PARAMETERS_2D_H + +/**************************************************************************/ +/* navigation_path_query_parameters_2d.h */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#include "core/object/reference.h" +#include "servers/navigation/navigation_utilities.h" + +class NavigationPathQueryParameters2D : public Reference { + GDCLASS(NavigationPathQueryParameters2D, Reference); + + NavigationUtilities::PathQueryParameters2D parameters; + +protected: + static void _bind_methods(); + +public: + enum PathfindingAlgorithm { + PATHFINDING_ALGORITHM_ASTAR = 0, + }; + + enum PathPostProcessing { + PATH_POSTPROCESSING_CORRIDORFUNNEL = 0, + PATH_POSTPROCESSING_EDGECENTERED, + }; + + enum PathMetadataFlags { + PATH_METADATA_INCLUDE_NONE = NavigationUtilities::PathMetadataFlags::PATH_INCLUDE_NONE, + PATH_METADATA_INCLUDE_TYPES = NavigationUtilities::PathMetadataFlags::PATH_INCLUDE_TYPES, + PATH_METADATA_INCLUDE_RIDS = NavigationUtilities::PathMetadataFlags::PATH_INCLUDE_RIDS, + PATH_METADATA_INCLUDE_OWNERS = NavigationUtilities::PathMetadataFlags::PATH_INCLUDE_OWNERS, + PATH_METADATA_INCLUDE_ALL = NavigationUtilities::PathMetadataFlags::PATH_INCLUDE_ALL + }; + + const NavigationUtilities::PathQueryParameters2D &get_parameters() const { return parameters; } + + void set_pathfinding_algorithm(const PathfindingAlgorithm p_pathfinding_algorithm); + PathfindingAlgorithm get_pathfinding_algorithm() const; + + void set_path_postprocessing(const PathPostProcessing p_path_postprocessing); + PathPostProcessing get_path_postprocessing() const; + + void set_map(const RID &p_map); + const RID &get_map() const; + + void set_start_position(const Vector2 p_start_position); + Vector2 get_start_position() const; + + void set_target_position(const Vector2 p_target_position); + Vector2 get_target_position() const; + + void set_navigation_layers(uint32_t p_navigation_layers); + uint32_t get_navigation_layers() const; + + void set_metadata_flags(const int p_flags); + int get_metadata_flags() const; +}; + +VARIANT_ENUM_CAST(NavigationPathQueryParameters2D::PathfindingAlgorithm); +VARIANT_ENUM_CAST(NavigationPathQueryParameters2D::PathPostProcessing); +VARIANT_ENUM_CAST(NavigationPathQueryParameters2D::PathMetadataFlags); + +#endif // NAVIGATION_PATH_QUERY_PARAMETERS_2D_H diff --git a/servers/navigation/navigation_path_query_parameters_3d.cpp b/servers/navigation/navigation_path_query_parameters_3d.cpp new file mode 100644 index 000000000..856824131 --- /dev/null +++ b/servers/navigation/navigation_path_query_parameters_3d.cpp @@ -0,0 +1,162 @@ +/**************************************************************************/ +/* navigation_path_query_parameters_3d.cpp */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#include "navigation_path_query_parameters_3d.h" + +void NavigationPathQueryParameters3D::set_pathfinding_algorithm(const NavigationPathQueryParameters3D::PathfindingAlgorithm p_pathfinding_algorithm) { + switch (p_pathfinding_algorithm) { + case PATHFINDING_ALGORITHM_ASTAR: { + parameters.pathfinding_algorithm = NavigationUtilities::PathfindingAlgorithm::PATHFINDING_ALGORITHM_ASTAR; + } break; + default: { + WARN_PRINT_ONCE("No match for used PathfindingAlgorithm - fallback to default"); + parameters.pathfinding_algorithm = NavigationUtilities::PathfindingAlgorithm::PATHFINDING_ALGORITHM_ASTAR; + } break; + } +} + +NavigationPathQueryParameters3D::PathfindingAlgorithm NavigationPathQueryParameters3D::get_pathfinding_algorithm() const { + switch (parameters.pathfinding_algorithm) { + case NavigationUtilities::PathfindingAlgorithm::PATHFINDING_ALGORITHM_ASTAR: + return PATHFINDING_ALGORITHM_ASTAR; + default: + WARN_PRINT_ONCE("No match for used PathfindingAlgorithm - fallback to default"); + return PATHFINDING_ALGORITHM_ASTAR; + } +} + +void NavigationPathQueryParameters3D::set_path_postprocessing(const NavigationPathQueryParameters3D::PathPostProcessing p_path_postprocessing) { + switch (p_path_postprocessing) { + case PATH_POSTPROCESSING_CORRIDORFUNNEL: { + parameters.path_postprocessing = NavigationUtilities::PathPostProcessing::PATH_POSTPROCESSING_CORRIDORFUNNEL; + } break; + case PATH_POSTPROCESSING_EDGECENTERED: { + parameters.path_postprocessing = NavigationUtilities::PathPostProcessing::PATH_POSTPROCESSING_EDGECENTERED; + } break; + default: { + WARN_PRINT_ONCE("No match for used PathPostProcessing - fallback to default"); + parameters.path_postprocessing = NavigationUtilities::PathPostProcessing::PATH_POSTPROCESSING_CORRIDORFUNNEL; + } break; + } +} + +NavigationPathQueryParameters3D::PathPostProcessing NavigationPathQueryParameters3D::get_path_postprocessing() const { + switch (parameters.path_postprocessing) { + case NavigationUtilities::PathPostProcessing::PATH_POSTPROCESSING_CORRIDORFUNNEL: + return PATH_POSTPROCESSING_CORRIDORFUNNEL; + case NavigationUtilities::PathPostProcessing::PATH_POSTPROCESSING_EDGECENTERED: + return PATH_POSTPROCESSING_EDGECENTERED; + default: + WARN_PRINT_ONCE("No match for used PathPostProcessing - fallback to default"); + return PATH_POSTPROCESSING_CORRIDORFUNNEL; + } +} + +void NavigationPathQueryParameters3D::set_map(const RID &p_map) { + parameters.map = p_map; +} + +const RID &NavigationPathQueryParameters3D::get_map() const { + return parameters.map; +} + +void NavigationPathQueryParameters3D::set_start_position(const Vector3 &p_start_position) { + parameters.start_position = p_start_position; +} + +const Vector3 &NavigationPathQueryParameters3D::get_start_position() const { + return parameters.start_position; +} + +void NavigationPathQueryParameters3D::set_target_position(const Vector3 &p_target_position) { + parameters.target_position = p_target_position; +} + +const Vector3 &NavigationPathQueryParameters3D::get_target_position() const { + return parameters.target_position; +} + +void NavigationPathQueryParameters3D::set_navigation_layers(uint32_t p_navigation_layers) { + parameters.navigation_layers = p_navigation_layers; +} + +uint32_t NavigationPathQueryParameters3D::get_navigation_layers() const { + return parameters.navigation_layers; +} + +void NavigationPathQueryParameters3D::set_metadata_flags(const int p_flags) { + parameters.metadata_flags = p_flags; +} + +int NavigationPathQueryParameters3D::get_metadata_flags() const { + return parameters.metadata_flags; +} + +void NavigationPathQueryParameters3D::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_pathfinding_algorithm", "pathfinding_algorithm"), &NavigationPathQueryParameters3D::set_pathfinding_algorithm); + ClassDB::bind_method(D_METHOD("get_pathfinding_algorithm"), &NavigationPathQueryParameters3D::get_pathfinding_algorithm); + + ClassDB::bind_method(D_METHOD("set_path_postprocessing", "path_postprocessing"), &NavigationPathQueryParameters3D::set_path_postprocessing); + ClassDB::bind_method(D_METHOD("get_path_postprocessing"), &NavigationPathQueryParameters3D::get_path_postprocessing); + + ClassDB::bind_method(D_METHOD("set_map", "map"), &NavigationPathQueryParameters3D::set_map); + ClassDB::bind_method(D_METHOD("get_map"), &NavigationPathQueryParameters3D::get_map); + + ClassDB::bind_method(D_METHOD("set_start_position", "start_position"), &NavigationPathQueryParameters3D::set_start_position); + ClassDB::bind_method(D_METHOD("get_start_position"), &NavigationPathQueryParameters3D::get_start_position); + + ClassDB::bind_method(D_METHOD("set_target_position", "target_position"), &NavigationPathQueryParameters3D::set_target_position); + ClassDB::bind_method(D_METHOD("get_target_position"), &NavigationPathQueryParameters3D::get_target_position); + + ClassDB::bind_method(D_METHOD("set_navigation_layers", "navigation_layers"), &NavigationPathQueryParameters3D::set_navigation_layers); + ClassDB::bind_method(D_METHOD("get_navigation_layers"), &NavigationPathQueryParameters3D::get_navigation_layers); + + ClassDB::bind_method(D_METHOD("set_metadata_flags", "flags"), &NavigationPathQueryParameters3D::set_metadata_flags); + ClassDB::bind_method(D_METHOD("get_metadata_flags"), &NavigationPathQueryParameters3D::get_metadata_flags); + + ADD_PROPERTY(PropertyInfo(Variant::RID, "map"), "set_map", "get_map"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "start_position"), "set_start_position", "get_start_position"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "target_position"), "set_target_position", "get_target_position"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "navigation_layers", PROPERTY_HINT_LAYERS_3D_NAVIGATION), "set_navigation_layers", "get_navigation_layers"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "pathfinding_algorithm", PROPERTY_HINT_ENUM, "AStar"), "set_pathfinding_algorithm", "get_pathfinding_algorithm"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "path_postprocessing", PROPERTY_HINT_ENUM, "Corridorfunnel,Edgecentered"), "set_path_postprocessing", "get_path_postprocessing"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "metadata_flags", PROPERTY_HINT_FLAGS, "Include Types,Include RIDs,Include Owners"), "set_metadata_flags", "get_metadata_flags"); + + BIND_ENUM_CONSTANT(PATHFINDING_ALGORITHM_ASTAR); + + BIND_ENUM_CONSTANT(PATH_POSTPROCESSING_CORRIDORFUNNEL); + BIND_ENUM_CONSTANT(PATH_POSTPROCESSING_EDGECENTERED); + + BIND_ENUM_CONSTANT(PATH_METADATA_INCLUDE_NONE); + BIND_ENUM_CONSTANT(PATH_METADATA_INCLUDE_TYPES); + BIND_ENUM_CONSTANT(PATH_METADATA_INCLUDE_RIDS); + BIND_ENUM_CONSTANT(PATH_METADATA_INCLUDE_OWNERS); + BIND_ENUM_CONSTANT(PATH_METADATA_INCLUDE_ALL); +} diff --git a/servers/navigation/navigation_path_query_parameters_3d.h b/servers/navigation/navigation_path_query_parameters_3d.h new file mode 100644 index 000000000..089a79cd2 --- /dev/null +++ b/servers/navigation/navigation_path_query_parameters_3d.h @@ -0,0 +1,91 @@ +#ifndef NAVIGATION_PATH_QUERY_PARAMETERS_3D_H +#define NAVIGATION_PATH_QUERY_PARAMETERS_3D_H + +/**************************************************************************/ +/* navigation_path_query_parameters_3d.h */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#include "core/object/reference.h" +#include "servers/navigation/navigation_utilities.h" + +class NavigationPathQueryParameters3D : public Reference { + GDCLASS(NavigationPathQueryParameters3D, Reference); + + NavigationUtilities::PathQueryParameters parameters; + +protected: + static void _bind_methods(); + +public: + enum PathfindingAlgorithm { + PATHFINDING_ALGORITHM_ASTAR = 0, + }; + + enum PathPostProcessing { + PATH_POSTPROCESSING_CORRIDORFUNNEL = 0, + PATH_POSTPROCESSING_EDGECENTERED, + }; + + enum PathMetadataFlags { + PATH_METADATA_INCLUDE_NONE = NavigationUtilities::PathMetadataFlags::PATH_INCLUDE_NONE, + PATH_METADATA_INCLUDE_TYPES = NavigationUtilities::PathMetadataFlags::PATH_INCLUDE_TYPES, + PATH_METADATA_INCLUDE_RIDS = NavigationUtilities::PathMetadataFlags::PATH_INCLUDE_RIDS, + PATH_METADATA_INCLUDE_OWNERS = NavigationUtilities::PathMetadataFlags::PATH_INCLUDE_OWNERS, + PATH_METADATA_INCLUDE_ALL = NavigationUtilities::PathMetadataFlags::PATH_INCLUDE_ALL + }; + + const NavigationUtilities::PathQueryParameters &get_parameters() const { return parameters; } + + void set_pathfinding_algorithm(const PathfindingAlgorithm p_pathfinding_algorithm); + PathfindingAlgorithm get_pathfinding_algorithm() const; + + void set_path_postprocessing(const PathPostProcessing p_path_postprocessing); + PathPostProcessing get_path_postprocessing() const; + + void set_map(const RID &p_map); + const RID &get_map() const; + + void set_start_position(const Vector3 &p_start_position); + const Vector3 &get_start_position() const; + + void set_target_position(const Vector3 &p_target_position); + const Vector3 &get_target_position() const; + + void set_navigation_layers(uint32_t p_navigation_layers); + uint32_t get_navigation_layers() const; + + void set_metadata_flags(const int p_flags); + int get_metadata_flags() const; +}; + +VARIANT_ENUM_CAST(NavigationPathQueryParameters3D::PathfindingAlgorithm); +VARIANT_ENUM_CAST(NavigationPathQueryParameters3D::PathPostProcessing); +VARIANT_ENUM_CAST(NavigationPathQueryParameters3D::PathMetadataFlags); + +#endif // NAVIGATION_PATH_QUERY_PARAMETERS_3D_H diff --git a/servers/navigation/navigation_path_query_result_2d.cpp b/servers/navigation/navigation_path_query_result_2d.cpp new file mode 100644 index 000000000..9910eb693 --- /dev/null +++ b/servers/navigation/navigation_path_query_result_2d.cpp @@ -0,0 +1,94 @@ +/**************************************************************************/ +/* navigation_path_query_result_2d.cpp */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#include "navigation_path_query_result_2d.h" + +void NavigationPathQueryResult2D::set_path(const PoolVector &p_path) { + path = p_path; +} + +const PoolVector &NavigationPathQueryResult2D::get_path() const { + return path; +} + +void NavigationPathQueryResult2D::set_path_types(const PoolVector &p_path_types) { + path_types = p_path_types; +} + +const PoolVector &NavigationPathQueryResult2D::get_path_types() const { + return path_types; +} + +void NavigationPathQueryResult2D::set_path_rids(const Array &p_path_rids) { + path_rids = p_path_rids; +} + +Array NavigationPathQueryResult2D::get_path_rids() const { + return path_rids; +} + +void NavigationPathQueryResult2D::set_path_owner_ids(const PoolVector &p_path_owner_ids) { + path_owner_ids = p_path_owner_ids; +} + +const PoolVector &NavigationPathQueryResult2D::get_path_owner_ids() const { + return path_owner_ids; +} + +void NavigationPathQueryResult2D::reset() { + path.clear(); + path_types.clear(); + path_rids.clear(); + path_owner_ids.clear(); +} + +void NavigationPathQueryResult2D::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_path", "path"), &NavigationPathQueryResult2D::set_path); + ClassDB::bind_method(D_METHOD("get_path"), &NavigationPathQueryResult2D::get_path); + + ClassDB::bind_method(D_METHOD("set_path_types", "path_types"), &NavigationPathQueryResult2D::set_path_types); + ClassDB::bind_method(D_METHOD("get_path_types"), &NavigationPathQueryResult2D::get_path_types); + + ClassDB::bind_method(D_METHOD("set_path_rids", "path_rids"), &NavigationPathQueryResult2D::set_path_rids); + ClassDB::bind_method(D_METHOD("get_path_rids"), &NavigationPathQueryResult2D::get_path_rids); + + ClassDB::bind_method(D_METHOD("set_path_owner_ids", "path_owner_ids"), &NavigationPathQueryResult2D::set_path_owner_ids); + ClassDB::bind_method(D_METHOD("get_path_owner_ids"), &NavigationPathQueryResult2D::get_path_owner_ids); + + ClassDB::bind_method(D_METHOD("reset"), &NavigationPathQueryResult2D::reset); + + ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR2_ARRAY, "path"), "set_path", "get_path"); + ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "path_types"), "set_path_types", "get_path_types"); + ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "path_rids"), "set_path_rids", "get_path_rids"); + ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "path_owner_ids"), "set_path_owner_ids", "get_path_owner_ids"); + + BIND_ENUM_CONSTANT(PATH_SEGMENT_TYPE_REGION); + BIND_ENUM_CONSTANT(PATH_SEGMENT_TYPE_LINK); +} diff --git a/servers/navigation/navigation_path_query_result_2d.h b/servers/navigation/navigation_path_query_result_2d.h new file mode 100644 index 000000000..33466dcbe --- /dev/null +++ b/servers/navigation/navigation_path_query_result_2d.h @@ -0,0 +1,71 @@ +#ifndef NAVIGATION_PATH_QUERY_RESULT_2D_H +#define NAVIGATION_PATH_QUERY_RESULT_2D_H + +/**************************************************************************/ +/* navigation_path_query_result_2d.h */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#include "core/object/reference.h" +#include "servers/navigation/navigation_utilities.h" + +class NavigationPathQueryResult2D : public Reference { + GDCLASS(NavigationPathQueryResult2D, Reference); + + PoolVector path; + PoolVector path_types; + Array path_rids; + PoolVector path_owner_ids; + +protected: + static void _bind_methods(); + +public: + enum PathSegmentType { + PATH_SEGMENT_TYPE_REGION = 0, + PATH_SEGMENT_TYPE_LINK = 1, + }; + + void set_path(const PoolVector &p_path); + const PoolVector &get_path() const; + + void set_path_types(const PoolVector &p_path_types); + const PoolVector &get_path_types() const; + + void set_path_rids(const Array &p_path_rids); + Array get_path_rids() const; + + void set_path_owner_ids(const PoolVector &p_path_owner_ids); + const PoolVector &get_path_owner_ids() const; + + void reset(); +}; + +VARIANT_ENUM_CAST(NavigationPathQueryResult2D::PathSegmentType); + +#endif // NAVIGATION_PATH_QUERY_RESULT_2D_H diff --git a/servers/navigation/navigation_path_query_result_3d.cpp b/servers/navigation/navigation_path_query_result_3d.cpp new file mode 100644 index 000000000..c04353f4b --- /dev/null +++ b/servers/navigation/navigation_path_query_result_3d.cpp @@ -0,0 +1,94 @@ +/**************************************************************************/ +/* navigation_path_query_result_3d.cpp */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#include "navigation_path_query_result_3d.h" + +void NavigationPathQueryResult3D::set_path(const PoolVector &p_path) { + path = p_path; +} + +const PoolVector &NavigationPathQueryResult3D::get_path() const { + return path; +} + +void NavigationPathQueryResult3D::set_path_types(const PoolVector &p_path_types) { + path_types = p_path_types; +} + +const PoolVector &NavigationPathQueryResult3D::get_path_types() const { + return path_types; +} + +void NavigationPathQueryResult3D::set_path_rids(const Array &p_path_rids) { + path_rids = p_path_rids; +} + +Array NavigationPathQueryResult3D::get_path_rids() const { + return path_rids; +} + +void NavigationPathQueryResult3D::set_path_owner_ids(const PoolVector &p_path_owner_ids) { + path_owner_ids = p_path_owner_ids; +} + +const PoolVector &NavigationPathQueryResult3D::get_path_owner_ids() const { + return path_owner_ids; +} + +void NavigationPathQueryResult3D::reset() { + path.clear(); + path_types.clear(); + path_rids.clear(); + path_owner_ids.clear(); +} + +void NavigationPathQueryResult3D::_bind_methods() { + ClassDB::bind_method(D_METHOD("set_path", "path"), &NavigationPathQueryResult3D::set_path); + ClassDB::bind_method(D_METHOD("get_path"), &NavigationPathQueryResult3D::get_path); + + ClassDB::bind_method(D_METHOD("set_path_types", "path_types"), &NavigationPathQueryResult3D::set_path_types); + ClassDB::bind_method(D_METHOD("get_path_types"), &NavigationPathQueryResult3D::get_path_types); + + ClassDB::bind_method(D_METHOD("set_path_rids", "path_rids"), &NavigationPathQueryResult3D::set_path_rids); + ClassDB::bind_method(D_METHOD("get_path_rids"), &NavigationPathQueryResult3D::get_path_rids); + + ClassDB::bind_method(D_METHOD("set_path_owner_ids", "path_owner_ids"), &NavigationPathQueryResult3D::set_path_owner_ids); + ClassDB::bind_method(D_METHOD("get_path_owner_ids"), &NavigationPathQueryResult3D::get_path_owner_ids); + + ClassDB::bind_method(D_METHOD("reset"), &NavigationPathQueryResult3D::reset); + + ADD_PROPERTY(PropertyInfo(Variant::POOL_VECTOR3_ARRAY, "path"), "set_path", "get_path"); + ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "path_types"), "set_path_types", "get_path_types"); + ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "path_rids"), "set_path_rids", "get_path_rids"); + ADD_PROPERTY(PropertyInfo(Variant::POOL_INT_ARRAY, "path_owner_ids"), "set_path_owner_ids", "get_path_owner_ids"); + + BIND_ENUM_CONSTANT(PATH_SEGMENT_TYPE_REGION); + BIND_ENUM_CONSTANT(PATH_SEGMENT_TYPE_LINK); +} diff --git a/servers/navigation/navigation_path_query_result_3d.h b/servers/navigation/navigation_path_query_result_3d.h new file mode 100644 index 000000000..ed5601696 --- /dev/null +++ b/servers/navigation/navigation_path_query_result_3d.h @@ -0,0 +1,72 @@ +#ifndef NAVIGATION_PATH_QUERY_RESULT_3D_H +#define NAVIGATION_PATH_QUERY_RESULT_3D_H + +/**************************************************************************/ +/* navigation_path_query_result_3d.h */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#include "core/object/reference.h" +#include "core/variant/array.h" +#include "servers/navigation/navigation_utilities.h" + +class NavigationPathQueryResult3D : public Reference { + GDCLASS(NavigationPathQueryResult3D, Reference); + + PoolVector path; + PoolVector path_types; + Array path_rids; + PoolVector path_owner_ids; + +protected: + static void _bind_methods(); + +public: + enum PathSegmentType { + PATH_SEGMENT_TYPE_REGION = 0, + PATH_SEGMENT_TYPE_LINK = 1, + }; + + void set_path(const PoolVector &p_path); + const PoolVector &get_path() const; + + void set_path_types(const PoolVector &p_path_types); + const PoolVector &get_path_types() const; + + void set_path_rids(const Array &p_path_rids); + Array get_path_rids() const; + + void set_path_owner_ids(const PoolVector &p_path_owner_ids); + const PoolVector &get_path_owner_ids() const; + + void reset(); +}; + +VARIANT_ENUM_CAST(NavigationPathQueryResult3D::PathSegmentType); + +#endif // NAVIGATION_PATH_QUERY_RESULT_3D_H diff --git a/servers/navigation/navigation_utilities.h b/servers/navigation/navigation_utilities.h new file mode 100644 index 000000000..ccf68b4d0 --- /dev/null +++ b/servers/navigation/navigation_utilities.h @@ -0,0 +1,100 @@ + +#ifndef NAVIGATION_UTILITIES_H +#define NAVIGATION_UTILITIES_H + +/**************************************************************************/ +/* navigation_utilities.h */ +/**************************************************************************/ +/* This file is part of: */ +/* GODOT ENGINE */ +/* https://godotengine.org */ +/**************************************************************************/ +/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */ +/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */ +/* */ +/* Permission is hereby granted, free of charge, to any person obtaining */ +/* a copy of this software and associated documentation files (the */ +/* "Software"), to deal in the Software without restriction, including */ +/* without limitation the rights to use, copy, modify, merge, publish, */ +/* distribute, sublicense, and/or sell copies of the Software, and to */ +/* permit persons to whom the Software is furnished to do so, subject to */ +/* the following conditions: */ +/* */ +/* The above copyright notice and this permission notice shall be */ +/* included in all copies or substantial portions of the Software. */ +/* */ +/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */ +/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */ +/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */ +/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */ +/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */ +/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */ +/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/**************************************************************************/ + +#include "core/math/vector3.h" +#include "core/variant/array.h" +#include "core/containers/rid.h" +#include "core/variant/variant.h" + +namespace NavigationUtilities { + +enum PathfindingAlgorithm { + PATHFINDING_ALGORITHM_ASTAR = 0, +}; + +enum PathPostProcessing { + PATH_POSTPROCESSING_CORRIDORFUNNEL = 0, + PATH_POSTPROCESSING_EDGECENTERED, +}; + +enum PathSegmentType { + PATH_SEGMENT_TYPE_REGION = 0, + PATH_SEGMENT_TYPE_LINK +}; + +enum PathMetadataFlags { + PATH_INCLUDE_NONE = 0, + PATH_INCLUDE_TYPES = 1, + PATH_INCLUDE_RIDS = 2, + PATH_INCLUDE_OWNERS = 4, + PATH_INCLUDE_ALL = PATH_INCLUDE_TYPES | PATH_INCLUDE_RIDS | PATH_INCLUDE_OWNERS +}; + +struct PathQueryParameters { + PathfindingAlgorithm pathfinding_algorithm = PATHFINDING_ALGORITHM_ASTAR; + PathPostProcessing path_postprocessing = PATH_POSTPROCESSING_CORRIDORFUNNEL; + RID map; + Vector3 start_position; + Vector3 target_position; + uint32_t navigation_layers = 1; + int metadata_flags = PATH_INCLUDE_ALL; +}; + +struct PathQueryParameters2D { + PathfindingAlgorithm pathfinding_algorithm = PATHFINDING_ALGORITHM_ASTAR; + PathPostProcessing path_postprocessing = PATH_POSTPROCESSING_CORRIDORFUNNEL; + RID map; + Vector2 start_position; + Vector2 target_position; + uint32_t navigation_layers = 1; + int metadata_flags = PATH_INCLUDE_ALL; +}; + +struct PathQueryResult { + PoolVector3Array path; + PoolIntArray path_types; + Array path_rids; + PoolIntArray path_owner_ids; +}; + +struct PathQueryResult2D { + PoolVector2Array path; + PoolIntArray path_types; + Array path_rids; + PoolIntArray path_owner_ids; +}; + +} //namespace NavigationUtilities + +#endif // NAVIGATION_UTILITIES_H diff --git a/servers/navigation_2d_server.cpp b/servers/navigation_2d_server.cpp index a1b5dd820..1b24789e6 100644 --- a/servers/navigation_2d_server.cpp +++ b/servers/navigation_2d_server.cpp @@ -31,6 +31,8 @@ #include "servers/navigation_2d_server.h" #include "core/config/project_settings.h" +#include "navigation/navigation_path_query_parameters_2d.h" +#include "navigation/navigation_path_query_result_2d.h" #include "servers/navigation_server.h" Navigation2DServer *Navigation2DServer::singleton = nullptr; @@ -93,6 +95,15 @@ void Navigation2DServer::_bind_methods() { void Navigation2DServer::init() { } +void Navigation2DServer::query_path(const Ref &p_query_parameters, Ref p_query_result) const { + ERR_FAIL_COND(!p_query_parameters.is_valid()); + ERR_FAIL_COND(!p_query_result.is_valid()); + + const NavigationUtilities::PathQueryResult2D _query_result = _query_path(p_query_parameters->get_parameters()); + + p_query_result->set_path(_query_result.path); +} + Navigation2DServer::Navigation2DServer() { singleton = this; } diff --git a/servers/navigation_2d_server.h b/servers/navigation_2d_server.h index 98fe3048a..4fb763d38 100644 --- a/servers/navigation_2d_server.h +++ b/servers/navigation_2d_server.h @@ -34,9 +34,13 @@ #include "core/containers/rid.h" #include "core/object/object.h" +#include "navigation/navigation_utilities.h" #include "scene/2d/navigation_polygon_instance.h" #include "scene/resources/navigation_polygon.h" +class NavigationPathQueryParameters2D; +class NavigationPathQueryResult2D; + // This server exposes the 3D `NavigationServer` features in the 2D world. class Navigation2DServer : public Object { GDCLASS(Navigation2DServer, Object); @@ -186,6 +190,11 @@ public: /// Destroy the `RID` virtual void free(RID p_object) const = 0; + /// Returns a customized navigation path using a query parameters object + void query_path(const Ref &p_query_parameters, Ref p_query_result) const; + + virtual NavigationUtilities::PathQueryResult2D _query_path(const NavigationUtilities::PathQueryParameters2D &p_parameters) const = 0; + virtual void init(); Navigation2DServer(); diff --git a/servers/navigation_server.cpp b/servers/navigation_server.cpp index 4884af6d2..7ba1240b8 100644 --- a/servers/navigation_server.cpp +++ b/servers/navigation_server.cpp @@ -31,6 +31,8 @@ #include "navigation_server.h" #include "core/config/project_settings.h" +#include "navigation/navigation_path_query_parameters_3d.h" +#include "navigation/navigation_path_query_result_3d.h" #include "scene/3d/navigation_mesh_instance.h" #include "scene/resources/navigation_mesh.h" @@ -68,6 +70,8 @@ void NavigationServer::_bind_methods() { ClassDB::bind_method(D_METHOD("map_get_agents", "map"), &NavigationServer::map_get_agents); ClassDB::bind_method(D_METHOD("map_force_update", "map"), &NavigationServer::map_force_update); + ClassDB::bind_method(D_METHOD("query_path", "parameters", "result"), &NavigationServer::query_path); + ClassDB::bind_method(D_METHOD("region_create"), &NavigationServer::region_create); ClassDB::bind_method(D_METHOD("region_set_enter_cost", "region", "enter_cost"), &NavigationServer::region_set_enter_cost); ClassDB::bind_method(D_METHOD("region_get_enter_cost", "region"), &NavigationServer::region_get_enter_cost); @@ -384,6 +388,15 @@ bool NavigationServer::get_debug_enabled() const { } #endif // DEBUG_ENABLED +void NavigationServer::query_path(const Ref &p_query_parameters, Ref p_query_result) const { + ERR_FAIL_COND(!p_query_parameters.is_valid()); + ERR_FAIL_COND(!p_query_result.is_valid()); + + const NavigationUtilities::PathQueryResult _query_result = _query_path(p_query_parameters->get_parameters()); + + p_query_result->set_path(_query_result.path); +} + Vector NavigationServerManager::navigation_servers; int NavigationServerManager::default_server_id = -1; int NavigationServerManager::default_server_priority = -1; diff --git a/servers/navigation_server.h b/servers/navigation_server.h index 551a41453..abfb30599 100644 --- a/servers/navigation_server.h +++ b/servers/navigation_server.h @@ -33,10 +33,14 @@ #include "core/containers/rid.h" #include "core/object/object.h" +#include "navigation/navigation_utilities.h" + #include "core/object/reference.h" class NavigationMesh; class SpatialMaterial; +class NavigationPathQueryParameters3D; +class NavigationPathQueryResult3D; /// This server uses the concept of internal mutability. /// All the constant functions can be called in multithread because internally @@ -211,6 +215,11 @@ public: /// Note: This function is not thread safe. virtual void process(real_t delta_time) = 0; + /// Returns a customized navigation path using a query parameters object + void query_path(const Ref &p_query_parameters, Ref p_query_result) const; + + virtual NavigationUtilities::PathQueryResult _query_path(const NavigationUtilities::PathQueryParameters &p_parameters) const = 0; + virtual void init(); NavigationServer(); diff --git a/servers/register_server_types.cpp b/servers/register_server_types.cpp index fbf8d4a98..a7f57d3ec 100644 --- a/servers/register_server_types.cpp +++ b/servers/register_server_types.cpp @@ -53,6 +53,10 @@ #include "audio/effects/audio_stream_generator.h" #include "audio_server.h" #include "navigation/navigation_mesh_generator.h" +#include "navigation/navigation_path_query_parameters_2d.h" +#include "navigation/navigation_path_query_parameters_3d.h" +#include "navigation/navigation_path_query_result_2d.h" +#include "navigation/navigation_path_query_result_3d.h" #include "navigation_2d_server.h" #include "navigation_server.h" #include "physics/physics_server_sw.h" @@ -115,6 +119,11 @@ void register_server_types() { //ClassDB::register_class(); ClassDB::register_virtual_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + ClassDB::register_class(); + shader_types = memnew(ShaderTypes); ClassDB::register_virtual_class();