Skip to content

Commit

Permalink
Expose NavigationServer3D to GDExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
DarkKilauea committed Feb 19, 2023
1 parent 9f68d06 commit debee64
Show file tree
Hide file tree
Showing 14 changed files with 1,017 additions and 22 deletions.
3 changes: 3 additions & 0 deletions doc/classes/@GlobalScope.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,9 @@
<member name="NavigationServer3D" type="NavigationServer3D" setter="" getter="">
The [NavigationServer2D] singleton.
</member>
<member name="NavigationServer3DManager" type="NavigationServer3DManager" setter="" getter="">
The [NavigationServer3DManager] singleton.
</member>
<member name="OS" type="OS" setter="" getter="">
The [OS] singleton.
</member>
Expand Down
583 changes: 583 additions & 0 deletions doc/classes/NavigationServer3DExtension.xml

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions doc/classes/NavigationServer3DManager.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="UTF-8" ?>
<class name="NavigationServer3DManager" inherits="Object" is_experimental="true" version="4.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../class.xsd">
<brief_description>
Manager for 3D navigation server implementations.
</brief_description>
<description>
[NavigationServer3DManager] is the API for registering [NavigationServer3D] implementations and for setting the default implementation.
[b]Note:[/b] It is not possible to switch navigation servers at runtime. This class is only used on startup at the server initialization level, by Godot itself and possibly by GDExtensions.
</description>
<tutorials>
</tutorials>
<methods>
<method name="register_server">
<return type="void" />
<param index="0" name="name" type="String" />
<param index="1" name="create_callback" type="Callable" />
<description>
Register a [NavigationServer3D] implementation by passing a [param name] and a [Callable] that returns a [NavigationServer3D] instance.
</description>
</method>
<method name="set_default_server">
<return type="void" />
<param index="0" name="name" type="String" />
<param index="1" name="priority" type="int" />
<description>
Set the default [NavigationServer3D] implementation to the one identified by [param name] if [param priority] is greater than the priority of the current default implementation.
</description>
</method>
</methods>
</class>
4 changes: 4 additions & 0 deletions doc/classes/ProjectSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1729,6 +1729,10 @@
<member name="navigation/3d/default_link_connection_radius" type="float" setter="" getter="" default="1.0">
Default link connection radius for 3D navigation maps. See [method NavigationServer3D.map_set_link_connection_radius].
</member>
<member name="navigation/3d/navigation_server" type="String" setter="" getter="" default="&quot;DEFAULT&quot;">
Sets which navigation server implementation to use.
"DEFAULT" is usually the same as "GodotNavigation3D" unless another module or extension overrides it.
</member>
<member name="network/limits/debugger/max_chars_per_second" type="int" setter="" getter="" default="32768">
Maximum number of characters allowed to send as output from the debugger. Over this value, content is dropped. This helps not to stall the debugger connection.
</member>
Expand Down
25 changes: 20 additions & 5 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ static PhysicsServer3DManager *physics_server_3d_manager = nullptr;
static PhysicsServer3D *physics_server_3d = nullptr;
static PhysicsServer2DManager *physics_server_2d_manager = nullptr;
static PhysicsServer2D *physics_server_2d = nullptr;
static NavigationServer3DManager *navigation_server_3d_manager = nullptr;
static NavigationServer3D *navigation_server_3d = nullptr;
static NavigationServer2D *navigation_server_2d = nullptr;
static ThemeDB *theme_db = nullptr;
Expand Down Expand Up @@ -283,18 +284,22 @@ void finalize_display() {
}

void initialize_navigation_server() {
ERR_FAIL_COND(navigation_server_3d != nullptr);
// Init chosen 3D Navigation Server
const String &server_name = GLOBAL_GET(NavigationServer3DManager::setting_property_name);
navigation_server_3d = NavigationServer3DManager::get_singleton()->new_server(server_name);

// Init 3D Navigation Server
navigation_server_3d = NavigationServer3DManager::new_default_server();
// Fall back to default if not found
if (!navigation_server_3d) {
// Navigation server not found, so use the default.
navigation_server_3d = NavigationServer3DManager::get_singleton()->new_default_server();
}

// Fall back to dummy if no default server has been registered.
if (!navigation_server_3d) {
WARN_PRINT_ONCE("No NavigationServer3D implementation has been registered! Falling back to a dummy implementation: navigation features will be unavailable.");
ERR_PRINT("No NavigationServer3D implementation has been registered! Falling back to a dummy implementation: navigation features will be unavailable.");
navigation_server_3d = memnew(NavigationServer3DDummy);
}

// Should be impossible, but make sure it's not null.
ERR_FAIL_NULL_MSG(navigation_server_3d, "Failed to initialize NavigationServer3D.");

// Init 2D Navigation Server
Expand Down Expand Up @@ -492,6 +497,8 @@ Error Main::test_setup() {
physics_server_3d_manager = memnew(PhysicsServer3DManager);
physics_server_2d_manager = memnew(PhysicsServer2DManager);

navigation_server_3d_manager = memnew(NavigationServer3DManager);

// From `Main::setup2()`.
initialize_modules(MODULE_INITIALIZATION_LEVEL_CORE);
register_core_extensions();
Expand Down Expand Up @@ -605,6 +612,9 @@ void Main::test_cleanup() {
if (tsman) {
memdelete(tsman);
}
if (navigation_server_3d_manager) {
memdelete(navigation_server_3d_manager);
}
if (physics_server_3d_manager) {
memdelete(physics_server_3d_manager);
}
Expand Down Expand Up @@ -1949,6 +1959,8 @@ Error Main::setup2(Thread::ID p_main_tid_override) {
physics_server_3d_manager = memnew(PhysicsServer3DManager);
physics_server_2d_manager = memnew(PhysicsServer2DManager);

navigation_server_3d_manager = memnew(NavigationServer3DManager);

register_server_types();
initialize_modules(MODULE_INITIALIZATION_LEVEL_SERVERS);
GDExtensionManager::get_singleton()->initialize_extensions(GDExtension::INITIALIZATION_LEVEL_SERVERS);
Expand Down Expand Up @@ -3384,6 +3396,9 @@ void Main::cleanup(bool p_force) {
if (tsman) {
memdelete(tsman);
}
if (navigation_server_3d_manager) {
memdelete(navigation_server_3d_manager);
}
if (physics_server_3d_manager) {
memdelete(physics_server_3d_manager);
}
Expand Down
2 changes: 1 addition & 1 deletion modules/mono/editor/bindings_generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ StringBuilder &operator<<(StringBuilder &r_sb, const char *p_cstring) {
#define C_METHOD_MANAGED_FROM_SIGNAL C_NS_MONOMARSHAL ".ConvertSignalToManaged"

// Types that will be ignored by the generator and won't be available in C#.
const Vector<String> ignored_types = { "PhysicsServer2DExtension", "PhysicsServer3DExtension" };
const Vector<String> ignored_types = { "PhysicsServer2DExtension", "PhysicsServer3DExtension", "NavigationServer3DExtension" };

void BindingsGenerator::TypeInterface::postsetup_enum_type(BindingsGenerator::TypeInterface &r_enum_itype) {
// C interface for enums is the same as that of 'uint32_t'. Remember to apply
Expand Down
3 changes: 2 additions & 1 deletion modules/navigation/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ NavigationServer3D *new_server() {

void initialize_navigation_module(ModuleInitializationLevel p_level) {
if (p_level == MODULE_INITIALIZATION_LEVEL_SERVERS) {
NavigationServer3DManager::set_default_server(new_server);
NavigationServer3DManager::get_singleton()->register_server("GodotNavigation3D", callable_mp_static(new_server));
NavigationServer3DManager::get_singleton()->set_default_server("GodotNavigation3D");

#ifndef _3D_DISABLED
_nav_mesh_generator = memnew(NavigationMeshGenerator);
Expand Down
113 changes: 113 additions & 0 deletions servers/extensions/navigation_server_3d_extension.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/**************************************************************************/
/* navigation_server_3d_extension.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_server_3d_extension.h"

void NavigationServer3DExtension::_bind_methods() {
GDVIRTUAL_BIND(_get_maps)
GDVIRTUAL_BIND(_map_create)
GDVIRTUAL_BIND(_map_set_active, "map", "active")
GDVIRTUAL_BIND(_map_is_active, "map")
GDVIRTUAL_BIND(_map_set_up, "map", "up")
GDVIRTUAL_BIND(_map_get_up, "map")
GDVIRTUAL_BIND(_map_set_cell_size, "map", "cell_size")
GDVIRTUAL_BIND(_map_get_cell_size, "map")
GDVIRTUAL_BIND(_map_set_edge_connection_margin, "map", "margin")
GDVIRTUAL_BIND(_map_get_edge_connection_margin, "map")
GDVIRTUAL_BIND(_map_set_link_connection_radius, "map", "radius")
GDVIRTUAL_BIND(_map_get_link_connection_radius, "map")
GDVIRTUAL_BIND(_map_get_path, "map", "origin", "destination", "optimize", "navigation_layers")
GDVIRTUAL_BIND(_map_get_closest_point_to_segment, "map", "start", "end", "use_collision")
GDVIRTUAL_BIND(_map_get_closest_point, "map", "to_point")
GDVIRTUAL_BIND(_map_get_closest_point_normal, "map", "to_point")
GDVIRTUAL_BIND(_map_get_closest_point_owner, "map", "to_point")
GDVIRTUAL_BIND(_map_get_links, "map")
GDVIRTUAL_BIND(_map_get_regions, "map")
GDVIRTUAL_BIND(_map_get_agents, "map")
GDVIRTUAL_BIND(_map_force_update, "map")
GDVIRTUAL_BIND(_query_path_extension, "parameters", "result")

GDVIRTUAL_BIND(_region_create)
GDVIRTUAL_BIND(_region_set_enter_cost, "region", "enter_cost")
GDVIRTUAL_BIND(_region_get_enter_cost, "region")
GDVIRTUAL_BIND(_region_set_travel_cost, "region", "travel_cost")
GDVIRTUAL_BIND(_region_get_travel_cost, "region")
GDVIRTUAL_BIND(_region_set_owner_id, "region", "owner_id")
GDVIRTUAL_BIND(_region_get_owner_id, "region")
GDVIRTUAL_BIND(_region_owns_point, "region", "point")
GDVIRTUAL_BIND(_region_set_map, "region", "map")
GDVIRTUAL_BIND(_region_get_map, "region")
GDVIRTUAL_BIND(_region_set_navigation_layers, "region", "navigation_layers")
GDVIRTUAL_BIND(_region_get_navigation_layers, "region")
GDVIRTUAL_BIND(_region_set_transform, "region", "transform")
GDVIRTUAL_BIND(_region_set_navigation_mesh, "region", "navigation_mesh")
GDVIRTUAL_BIND(_region_bake_navigation_mesh, "navigation_mesh", "root_node")
GDVIRTUAL_BIND(_region_get_connections_count, "region")
GDVIRTUAL_BIND(_region_get_connection_pathway_start, "region", "connection")
GDVIRTUAL_BIND(_region_get_connection_pathway_end, "region", "connection")

GDVIRTUAL_BIND(_link_create)
GDVIRTUAL_BIND(_link_set_map, "link", "map")
GDVIRTUAL_BIND(_link_get_map, "link")
GDVIRTUAL_BIND(_link_set_bidirectional, "link", "bidirectional")
GDVIRTUAL_BIND(_link_is_bidirectional, "link")
GDVIRTUAL_BIND(_link_set_navigation_layers, "link", "navigation_layers")
GDVIRTUAL_BIND(_link_get_navigation_layers, "link")
GDVIRTUAL_BIND(_link_set_start_position, "link", "position")
GDVIRTUAL_BIND(_link_get_start_position, "link")
GDVIRTUAL_BIND(_link_set_end_position, "link", "position")
GDVIRTUAL_BIND(_link_get_end_position, "link")
GDVIRTUAL_BIND(_link_set_enter_cost, "link", "enter_cost")
GDVIRTUAL_BIND(_link_get_enter_cost, "link")
GDVIRTUAL_BIND(_link_set_travel_cost, "link", "travel_cost")
GDVIRTUAL_BIND(_link_get_travel_cost, "link")
GDVIRTUAL_BIND(_link_set_owner_id, "link", "owner_id")
GDVIRTUAL_BIND(_link_get_owner_id, "link")

GDVIRTUAL_BIND(_agent_create)
GDVIRTUAL_BIND(_agent_set_map, "agent", "map")
GDVIRTUAL_BIND(_agent_get_map, "agent")
GDVIRTUAL_BIND(_agent_set_neighbor_distance, "agent", "distance")
GDVIRTUAL_BIND(_agent_set_max_neighbors, "agent", "count")
GDVIRTUAL_BIND(_agent_set_time_horizon, "agent", "time")
GDVIRTUAL_BIND(_agent_set_radius, "agent", "radius")
GDVIRTUAL_BIND(_agent_set_max_speed, "agent", "max_speed")
GDVIRTUAL_BIND(_agent_set_velocity, "agent", "velocity")
GDVIRTUAL_BIND(_agent_set_target_velocity, "agent", "target_velocity")
GDVIRTUAL_BIND(_agent_set_position, "agent", "position")
GDVIRTUAL_BIND(_agent_set_ignore_y, "agent", "ignore_y")
GDVIRTUAL_BIND(_agent_is_map_changed, "agent")
GDVIRTUAL_BIND(_agent_set_callback, "agent", "callback")

GDVIRTUAL_BIND(_free, "rid")
GDVIRTUAL_BIND(_set_active, "active")
GDVIRTUAL_BIND(_process, "delta_time")
GDVIRTUAL_BIND(_get_process_info, "info")
}
Loading

0 comments on commit debee64

Please sign in to comment.