From 39034e2445360555e222ac021ae75239506a0a44 Mon Sep 17 00:00:00 2001 From: A Thousand Ships <96648715+AThousandShips@users.noreply.github.com> Date: Thu, 22 Feb 2024 19:04:24 +0100 Subject: [PATCH] [Navigation] Restore 2D only navigation --- .../3d/godot_navigation_server_3d.cpp | 12 ++--------- .../3d/godot_navigation_server_3d.h | 2 ++ modules/navigation/SCsub | 3 +-- modules/navigation/config.py | 2 +- tests/test_main.cpp | 21 +++++++------------ 5 files changed, 14 insertions(+), 26 deletions(-) diff --git a/modules/navigation/3d/godot_navigation_server_3d.cpp b/modules/navigation/3d/godot_navigation_server_3d.cpp index 11a5de608b02..cf05828cbeef 100644 --- a/modules/navigation/3d/godot_navigation_server_3d.cpp +++ b/modules/navigation/3d/godot_navigation_server_3d.cpp @@ -1108,8 +1108,8 @@ uint32_t GodotNavigationServer3D::obstacle_get_avoidance_layers(RID p_obstacle) return obstacle->get_avoidance_layers(); } -void GodotNavigationServer3D::parse_source_geometry_data(const Ref &p_navigation_mesh, const Ref &p_source_geometry_data, Node *p_root_node, const Callable &p_callback) { #ifndef _3D_DISABLED +void GodotNavigationServer3D::parse_source_geometry_data(const Ref &p_navigation_mesh, const Ref &p_source_geometry_data, Node *p_root_node, const Callable &p_callback) { ERR_FAIL_COND_MSG(!Thread::is_main_thread(), "The SceneTree can only be parsed on the main thread. Call this function from the main thread or use call_deferred()."); ERR_FAIL_COND_MSG(!p_navigation_mesh.is_valid(), "Invalid navigation mesh."); ERR_FAIL_NULL_MSG(p_root_node, "No parsing root node specified."); @@ -1117,36 +1117,28 @@ void GodotNavigationServer3D::parse_source_geometry_data(const Refparse_source_geometry_data(p_navigation_mesh, p_source_geometry_data, p_root_node, p_callback); -#endif // _3D_DISABLED } void GodotNavigationServer3D::bake_from_source_geometry_data(const Ref &p_navigation_mesh, const Ref &p_source_geometry_data, const Callable &p_callback) { -#ifndef _3D_DISABLED ERR_FAIL_COND_MSG(!p_navigation_mesh.is_valid(), "Invalid navigation mesh."); ERR_FAIL_COND_MSG(!p_source_geometry_data.is_valid(), "Invalid NavigationMeshSourceGeometryData3D."); ERR_FAIL_NULL(NavMeshGenerator3D::get_singleton()); NavMeshGenerator3D::get_singleton()->bake_from_source_geometry_data(p_navigation_mesh, p_source_geometry_data, p_callback); -#endif // _3D_DISABLED } void GodotNavigationServer3D::bake_from_source_geometry_data_async(const Ref &p_navigation_mesh, const Ref &p_source_geometry_data, const Callable &p_callback) { -#ifndef _3D_DISABLED ERR_FAIL_COND_MSG(!p_navigation_mesh.is_valid(), "Invalid navigation mesh."); ERR_FAIL_COND_MSG(!p_source_geometry_data.is_valid(), "Invalid NavigationMeshSourceGeometryData3D."); ERR_FAIL_NULL(NavMeshGenerator3D::get_singleton()); NavMeshGenerator3D::get_singleton()->bake_from_source_geometry_data_async(p_navigation_mesh, p_source_geometry_data, p_callback); -#endif // _3D_DISABLED } bool GodotNavigationServer3D::is_baking_navigation_mesh(Ref p_navigation_mesh) const { -#ifdef _3D_DISABLED - return false; -#else return NavMeshGenerator3D::get_singleton()->is_baking(p_navigation_mesh); -#endif // _3D_DISABLED } +#endif // _3D_DISABLED COMMAND_1(free, RID, p_object) { if (map_owner.owns(p_object)) { diff --git a/modules/navigation/3d/godot_navigation_server_3d.h b/modules/navigation/3d/godot_navigation_server_3d.h index 12a1132f07b6..5fadfbaaa6a9 100644 --- a/modules/navigation/3d/godot_navigation_server_3d.h +++ b/modules/navigation/3d/godot_navigation_server_3d.h @@ -260,10 +260,12 @@ class GodotNavigationServer3D : public NavigationServer3D { COMMAND_2(obstacle_set_avoidance_layers, RID, p_obstacle, uint32_t, p_layers); virtual uint32_t obstacle_get_avoidance_layers(RID p_obstacle) const override; +#ifndef _3D_DISABLED virtual void parse_source_geometry_data(const Ref &p_navigation_mesh, const Ref &p_source_geometry_data, Node *p_root_node, const Callable &p_callback = Callable()) override; virtual void bake_from_source_geometry_data(const Ref &p_navigation_mesh, const Ref &p_source_geometry_data, const Callable &p_callback = Callable()) override; virtual void bake_from_source_geometry_data_async(const Ref &p_navigation_mesh, const Ref &p_source_geometry_data, const Callable &p_callback = Callable()) override; virtual bool is_baking_navigation_mesh(Ref p_navigation_mesh) const override; +#endif // _3D_DISABLED virtual RID source_geometry_parser_create() override; virtual void source_geometry_parser_set_callback(RID p_parser, const Callable &p_callback) override; diff --git a/modules/navigation/SCsub b/modules/navigation/SCsub index 02d3b7487e91..71ea11333083 100644 --- a/modules/navigation/SCsub +++ b/modules/navigation/SCsub @@ -75,8 +75,7 @@ module_obj = [] env_navigation.add_source_files(module_obj, "*.cpp") env_navigation.add_source_files(module_obj, "2d/*.cpp") -if not env["disable_3d"]: - env_navigation.add_source_files(module_obj, "3d/*.cpp") +env_navigation.add_source_files(module_obj, "3d/*.cpp") if env.editor_build: env_navigation.add_source_files(module_obj, "editor/*.cpp") env.modules_sources += module_obj diff --git a/modules/navigation/config.py b/modules/navigation/config.py index a42f27fbe122..d22f9454ed25 100644 --- a/modules/navigation/config.py +++ b/modules/navigation/config.py @@ -1,5 +1,5 @@ def can_build(env, platform): - return not env["disable_3d"] + return True def configure(env): diff --git a/tests/test_main.cpp b/tests/test_main.cpp index edadc52a1639..459ef0f37e15 100644 --- a/tests/test_main.cpp +++ b/tests/test_main.cpp @@ -135,18 +135,21 @@ #include "tests/scene/test_text_edit.h" #endif // ADVANCED_GUI_DISABLED -#ifndef _3D_DISABLED #ifdef MODULE_NAVIGATION_ENABLED #include "tests/scene/test_navigation_agent_2d.h" -#include "tests/scene/test_navigation_agent_3d.h" #include "tests/scene/test_navigation_obstacle_2d.h" -#include "tests/scene/test_navigation_obstacle_3d.h" #include "tests/scene/test_navigation_region_2d.h" -#include "tests/scene/test_navigation_region_3d.h" #include "tests/servers/test_navigation_server_2d.h" + +#ifndef _3D_DISABLED +#include "tests/scene/test_navigation_agent_3d.h" +#include "tests/scene/test_navigation_obstacle_3d.h" +#include "tests/scene/test_navigation_region_3d.h" #include "tests/servers/test_navigation_server_3d.h" +#endif // _3D_DISABLED #endif // MODULE_NAVIGATION_ENABLED +#ifndef _3D_DISABLED #include "tests/scene/test_arraymesh.h" #include "tests/scene/test_camera_3d.h" #include "tests/scene/test_path_3d.h" @@ -160,10 +163,8 @@ #include "tests/test_macros.h" #include "scene/theme/theme_db.h" -#ifndef _3D_DISABLED #include "servers/navigation_server_2d.h" #include "servers/navigation_server_3d.h" -#endif // _3D_DISABLED #include "servers/physics_server_2d.h" #ifndef _3D_DISABLED #include "servers/physics_server_3d.h" @@ -245,9 +246,9 @@ struct GodotTestCaseListener : public doctest::IReporter { PhysicsServer2D *physics_server_2d = nullptr; #ifndef _3D_DISABLED PhysicsServer3D *physics_server_3d = nullptr; +#endif // _3D_DISABLED NavigationServer3D *navigation_server_3d = nullptr; NavigationServer2D *navigation_server_2d = nullptr; -#endif // _3D_DISABLED void test_case_start(const doctest::TestCaseData &p_in) override { reinitialize(); @@ -287,12 +288,10 @@ struct GodotTestCaseListener : public doctest::IReporter { physics_server_2d = PhysicsServer2DManager::get_singleton()->new_default_server(); physics_server_2d->init(); -#ifndef _3D_DISABLED ERR_PRINT_OFF; navigation_server_3d = NavigationServer3DManager::new_default_server(); navigation_server_2d = NavigationServer2DManager::new_default_server(); ERR_PRINT_ON; -#endif // _3D_DISABLED memnew(InputMap); InputMap::get_singleton()->load_default(); @@ -323,7 +322,6 @@ struct GodotTestCaseListener : public doctest::IReporter { return; } -#ifndef _3D_DISABLED if (suite_name.contains("[Navigation]") && navigation_server_2d == nullptr && navigation_server_3d == nullptr) { ERR_PRINT_OFF; navigation_server_3d = NavigationServer3DManager::new_default_server(); @@ -331,7 +329,6 @@ struct GodotTestCaseListener : public doctest::IReporter { ERR_PRINT_ON; return; } -#endif // _3D_DISABLED } void test_case_end(const doctest::CurrentTestCaseStats &) override { @@ -355,7 +352,6 @@ struct GodotTestCaseListener : public doctest::IReporter { memdelete(SceneTree::get_singleton()); } -#ifndef _3D_DISABLED if (navigation_server_3d) { memdelete(navigation_server_3d); navigation_server_3d = nullptr; @@ -365,7 +361,6 @@ struct GodotTestCaseListener : public doctest::IReporter { memdelete(navigation_server_2d); navigation_server_2d = nullptr; } -#endif // _3D_DISABLED #ifndef _3D_DISABLED if (physics_server_3d) {