From 41ac45d235f1ea4a05799ff43c58a23f4a44aec6 Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Sat, 1 Oct 2022 15:12:28 -0500 Subject: [PATCH] Allow disabling 2D when compiling export templates --- SConstruct | 7 ++++++ main/main.cpp | 31 +++++++++++++++++++++++++-- main/performance.cpp | 5 ++++- modules/gltf/gltf_document.cpp | 2 ++ modules/godot_physics_2d/config.py | 2 +- modules/navigation/SCsub | 3 ++- modules/navigation/register_types.cpp | 9 +++++++- scene/SCsub | 3 ++- scene/debugger/scene_debugger.cpp | 20 +++++++++++------ scene/main/canvas_item.cpp | 5 +++++ scene/main/scene_tree.cpp | 10 +++++++++ scene/main/viewport.cpp | 20 +++++++++++++++++ scene/main/viewport.h | 2 ++ scene/register_scene_types.cpp | 12 ++++++++++- scene/resources/SCsub | 3 ++- scene/resources/packed_scene.cpp | 14 ++++++++---- scene/resources/world_2d.cpp | 12 ++++++++--- scene/resources/world_2d.h | 7 ++++++ servers/SCsub | 8 ++++--- servers/extensions/SCsub | 3 ++- servers/physics_server_2d.cpp | 4 ++++ servers/physics_server_2d.h | 4 ++++ servers/physics_server_2d_wrap_mt.cpp | 4 ++++ servers/physics_server_2d_wrap_mt.h | 4 ++++ servers/register_server_types.cpp | 11 ++++++++-- 25 files changed, 177 insertions(+), 28 deletions(-) diff --git a/SConstruct b/SConstruct index 8d2d0b4eb8f3..cd3b33d4dab1 100644 --- a/SConstruct +++ b/SConstruct @@ -236,6 +236,7 @@ opts.Add("object_prefix", "Custom prefix added to the base filename of all gener opts.Add(BoolVariable("vsproj", "Generate a Visual Studio solution", False)) opts.Add("vsproj_name", "Name of the Visual Studio solution", "godot") opts.Add("import_env_vars", "A comma-separated list of environment variables to copy from the outer environment.", "") +opts.Add(BoolVariable("disable_2d", "Disable 2D nodes for a smaller executable", False)) opts.Add(BoolVariable("disable_3d", "Disable 3D nodes for a smaller executable", False)) opts.Add(BoolVariable("disable_advanced_gui", "Disable advanced GUI nodes and behaviors", False)) opts.Add("build_profile", "Path to a file containing a feature build profile", "") @@ -989,6 +990,12 @@ env["SHLIBSUFFIX"] = suffix + env["SHLIBSUFFIX"] env["OBJPREFIX"] = env["object_prefix"] env["SHOBJPREFIX"] = env["object_prefix"] +if env["disable_2d"]: + if env.editor_build: + print("Build option 'disable_2d=yes' cannot be used for editor builds, but only for export templates.") + Exit(255) + else: + env.Append(CPPDEFINES=["_2D_DISABLED"]) if env["disable_3d"]: if env.editor_build: print_error("Build option `disable_3d=yes` cannot be used for editor builds, only for export template builds.") diff --git a/main/main.cpp b/main/main.cpp index bab0dfebaf21..0adfafba04a4 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -79,11 +79,12 @@ #include "servers/text/text_server_dummy.h" #include "servers/text_server.h" -// 2D +#ifndef _2D_DISABLED #include "servers/navigation_server_2d.h" #include "servers/navigation_server_2d_dummy.h" #include "servers/physics_server_2d.h" #include "servers/physics_server_2d_dummy.h" +#endif // _2D_DISABLED #ifndef _3D_DISABLED #include "servers/physics_server_3d.h" @@ -164,9 +165,11 @@ static DisplayServer *display_server = nullptr; static RenderingServer *rendering_server = nullptr; static TextServerManager *tsman = nullptr; static ThemeDB *theme_db = nullptr; +#ifndef _2D_DISABLED static NavigationServer2D *navigation_server_2d = nullptr; static PhysicsServer2DManager *physics_server_2d_manager = nullptr; static PhysicsServer2D *physics_server_2d = nullptr; +#endif // _2D_DISABLED static NavigationServer3D *navigation_server_3d = nullptr; #ifndef _3D_DISABLED static PhysicsServer3DManager *physics_server_3d_manager = nullptr; @@ -339,6 +342,7 @@ void initialize_physics() { physics_server_3d->init(); #endif // _3D_DISABLED +#ifndef _2D_DISABLED // 2D Physics server physics_server_2d = PhysicsServer2DManager::get_singleton()->new_server( GLOBAL_GET(PhysicsServer2DManager::get_singleton()->setting_property_name)); @@ -356,6 +360,7 @@ void initialize_physics() { // Should be impossible, but make sure it's not null. ERR_FAIL_NULL_MSG(physics_server_2d, "Failed to initialize PhysicsServer2D."); physics_server_2d->init(); +#endif // _2D_DISABLED } void finalize_physics() { @@ -364,8 +369,10 @@ void finalize_physics() { memdelete(physics_server_3d); #endif // _3D_DISABLED +#ifndef _2D_DISABLED physics_server_2d->finish(); memdelete(physics_server_2d); +#endif // _2D_DISABLED } void finalize_display() { @@ -377,7 +384,6 @@ void finalize_display() { void initialize_navigation_server() { ERR_FAIL_COND(navigation_server_3d != nullptr); - ERR_FAIL_COND(navigation_server_2d != nullptr); // Init 3D Navigation Server navigation_server_3d = NavigationServer3DManager::new_default_server(); @@ -391,6 +397,8 @@ void initialize_navigation_server() { ERR_FAIL_NULL_MSG(navigation_server_3d, "Failed to initialize NavigationServer3D."); navigation_server_3d->init(); +#ifndef _2D_DISABLED + ERR_FAIL_COND(navigation_server_2d != nullptr); // Init 2D Navigation Server navigation_server_2d = NavigationServer2DManager::new_default_server(); if (!navigation_server_2d) { @@ -399,6 +407,7 @@ void initialize_navigation_server() { ERR_FAIL_NULL_MSG(navigation_server_2d, "Failed to initialize NavigationServer2D."); navigation_server_2d->init(); +#endif // _2D_DISABLED } void finalize_navigation_server() { @@ -407,10 +416,12 @@ void finalize_navigation_server() { memdelete(navigation_server_3d); navigation_server_3d = nullptr; +#ifndef _2D_DISABLED ERR_FAIL_NULL(navigation_server_2d); navigation_server_2d->finish(); memdelete(navigation_server_2d); navigation_server_2d = nullptr; +#endif // _2D_DISABLED } void initialize_theme_db() { @@ -738,7 +749,9 @@ Error Main::test_setup() { #ifndef _3D_DISABLED physics_server_3d_manager = memnew(PhysicsServer3DManager); #endif // _3D_DISABLED +#ifndef _2D_DISABLED physics_server_2d_manager = memnew(PhysicsServer2DManager); +#endif // _2D_DISABLED // From `Main::setup2()`. register_early_core_singletons(); @@ -2921,7 +2934,9 @@ Error Main::setup2(bool p_show_boot_logo) { #ifndef _3D_DISABLED physics_server_3d_manager = memnew(PhysicsServer3DManager); #endif // _3D_DISABLED +#ifndef _2D_DISABLED physics_server_2d_manager = memnew(PhysicsServer2DManager); +#endif // _2D_DISABLED register_server_types(); { @@ -3043,9 +3058,11 @@ Error Main::setup2(bool p_show_boot_logo) { memdelete(physics_server_3d_manager); } #endif // _3D_DISABLED +#ifndef _2D_DISABLED if (physics_server_2d_manager) { memdelete(physics_server_2d_manager); } +#endif // _2D_DISABLED return err; } @@ -4394,7 +4411,9 @@ bool Main::iteration() { XRServer::get_singleton()->_process(); #endif // _3D_DISABLED +#ifndef _2D_DISABLED NavigationServer2D::get_singleton()->sync(); +#endif // _2D_DISABLED NavigationServer3D::get_singleton()->sync(); for (int iters = 0; iters < advance.physics_steps; ++iters) { @@ -4417,14 +4436,18 @@ bool Main::iteration() { PhysicsServer3D::get_singleton()->flush_queries(); #endif // _3D_DISABLED +#ifndef _2D_DISABLED PhysicsServer2D::get_singleton()->sync(); PhysicsServer2D::get_singleton()->flush_queries(); +#endif // _2D_DISABLED if (OS::get_singleton()->get_main_loop()->physics_process(physics_step * time_scale)) { #ifndef _3D_DISABLED PhysicsServer3D::get_singleton()->end_sync(); #endif // _3D_DISABLED +#ifndef _2D_DISABLED PhysicsServer2D::get_singleton()->end_sync(); +#endif // _2D_DISABLED Engine::get_singleton()->_in_physics = false; exit = true; @@ -4445,8 +4468,10 @@ bool Main::iteration() { PhysicsServer3D::get_singleton()->step(physics_step * time_scale); #endif // _3D_DISABLED +#ifndef _2D_DISABLED PhysicsServer2D::get_singleton()->end_sync(); PhysicsServer2D::get_singleton()->step(physics_step * time_scale); +#endif // _2D_DISABLED message_queue->flush(); @@ -4725,9 +4750,11 @@ void Main::cleanup(bool p_force) { memdelete(physics_server_3d_manager); } #endif // _3D_DISABLED +#ifndef _2D_DISABLED if (physics_server_2d_manager) { memdelete(physics_server_2d_manager); } +#endif // _2D_DISABLED if (globals) { memdelete(globals); } diff --git a/main/performance.cpp b/main/performance.cpp index 398511995b01..d79652f072b6 100644 --- a/main/performance.cpp +++ b/main/performance.cpp @@ -38,8 +38,9 @@ #include "servers/navigation_server_3d.h" #include "servers/rendering_server.h" -// 2D +#ifndef _2D_DISABLED #include "servers/physics_server_2d.h" +#endif // _2D_DISABLED #ifndef _3D_DISABLED #include "servers/physics_server_3d.h" @@ -202,12 +203,14 @@ double Performance::get_monitor(Monitor p_monitor) const { return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_PIPELINE_COMPILATIONS_DRAW); case PIPELINE_COMPILATIONS_SPECIALIZATION: return RS::get_singleton()->get_rendering_info(RS::RENDERING_INFO_PIPELINE_COMPILATIONS_SPECIALIZATION); +#ifndef _2D_DISABLED case PHYSICS_2D_ACTIVE_OBJECTS: return PhysicsServer2D::get_singleton()->get_process_info(PhysicsServer2D::INFO_ACTIVE_OBJECTS); case PHYSICS_2D_COLLISION_PAIRS: return PhysicsServer2D::get_singleton()->get_process_info(PhysicsServer2D::INFO_COLLISION_PAIRS); case PHYSICS_2D_ISLAND_COUNT: return PhysicsServer2D::get_singleton()->get_process_info(PhysicsServer2D::INFO_ISLAND_COUNT); +#endif // _2D_DISABLED #ifdef _3D_DISABLED case PHYSICS_3D_ACTIVE_OBJECTS: return 0; diff --git a/modules/gltf/gltf_document.cpp b/modules/gltf/gltf_document.cpp index 7f70bd35d59e..264fbf27b137 100644 --- a/modules/gltf/gltf_document.cpp +++ b/modules/gltf/gltf_document.cpp @@ -5941,10 +5941,12 @@ void GLTFDocument::_convert_csg_shape_to_gltf(CSGShape3D *p_current, GLTFNodeInd void GLTFDocument::_check_visibility(Node *p_node, bool &r_retflag) { r_retflag = true; Node3D *spatial = Object::cast_to(p_node); +#ifndef _2D_DISABLED Node2D *node_2d = Object::cast_to(p_node); if (node_2d && !node_2d->is_visible()) { return; } +#endif // _2D_DISABLED if (spatial && !spatial->is_visible()) { return; } diff --git a/modules/godot_physics_2d/config.py b/modules/godot_physics_2d/config.py index d22f9454ed25..98b60edd862e 100644 --- a/modules/godot_physics_2d/config.py +++ b/modules/godot_physics_2d/config.py @@ -1,5 +1,5 @@ def can_build(env, platform): - return True + return not env["disable_2d"] def configure(env): diff --git a/modules/navigation/SCsub b/modules/navigation/SCsub index ab578252c198..c97212184167 100644 --- a/modules/navigation/SCsub +++ b/modules/navigation/SCsub @@ -75,7 +75,8 @@ env.modules_sources += thirdparty_obj module_obj = [] env_navigation.add_source_files(module_obj, "*.cpp") -env_navigation.add_source_files(module_obj, "2d/*.cpp") +if not env["disable_2d"]: + env_navigation.add_source_files(module_obj, "2d/*.cpp") if not env["disable_3d"]: env_navigation.add_source_files(module_obj, "3d/*.cpp") if env.editor_build: diff --git a/modules/navigation/register_types.cpp b/modules/navigation/register_types.cpp index dbc9e53035be..7b2d5f58bfa3 100644 --- a/modules/navigation/register_types.cpp +++ b/modules/navigation/register_types.cpp @@ -30,9 +30,12 @@ #include "register_types.h" -#include "2d/godot_navigation_server_2d.h" #include "3d/godot_navigation_server_3d.h" +#ifndef _2D_DISABLED +#include "2d/godot_navigation_server_2d.h" +#endif // _2D_DISABLED + #ifndef DISABLE_DEPRECATED #ifndef _3D_DISABLED #include "3d/navigation_mesh_generator.h" @@ -57,14 +60,18 @@ NavigationServer3D *new_navigation_server_3d() { return memnew(GodotNavigationServer3D); } +#ifndef _2D_DISABLED NavigationServer2D *new_navigation_server_2d() { return memnew(GodotNavigationServer2D); } +#endif // _2D_DISABLED void initialize_navigation_module(ModuleInitializationLevel p_level) { if (p_level == MODULE_INITIALIZATION_LEVEL_SERVERS) { NavigationServer3DManager::set_default_server(new_navigation_server_3d); +#ifndef _2D_DISABLED NavigationServer2DManager::set_default_server(new_navigation_server_2d); +#endif // _2D_DISABLED #ifndef DISABLE_DEPRECATED #ifndef _3D_DISABLED diff --git a/scene/SCsub b/scene/SCsub index 1eb4ffa53d16..026836181b47 100644 --- a/scene/SCsub +++ b/scene/SCsub @@ -11,9 +11,10 @@ env.add_source_files(env.scene_sources, "*.cpp") # Chain load SCsubs SConscript("main/SCsub") SConscript("gui/SCsub") +if not env["disable_2d"]: + SConscript("2d/SCsub") if not env["disable_3d"]: SConscript("3d/SCsub") -SConscript("2d/SCsub") SConscript("animation/SCsub") SConscript("audio/SCsub") SConscript("resources/SCsub") diff --git a/scene/debugger/scene_debugger.cpp b/scene/debugger/scene_debugger.cpp index 1bac94b4fa17..4677dd61abe5 100644 --- a/scene/debugger/scene_debugger.cpp +++ b/scene/debugger/scene_debugger.cpp @@ -35,9 +35,19 @@ #include "core/io/marshalls.h" #include "core/object/script_language.h" #include "core/templates/local_vector.h" +#include "scene/gui/popup_menu.h" +#include "scene/main/canvas_layer.h" +#include "scene/main/scene_tree.h" +#include "scene/main/window.h" +#include "scene/resources/packed_scene.h" +#include "scene/theme/theme_db.h" + +#ifndef _2D_DISABLED #include "scene/2d/physics/collision_object_2d.h" #include "scene/2d/physics/collision_polygon_2d.h" #include "scene/2d/physics/collision_shape_2d.h" +#endif // _2D_DISABLED + #ifndef _3D_DISABLED #include "scene/3d/label_3d.h" #include "scene/3d/mesh_instance_3d.h" @@ -46,12 +56,6 @@ #include "scene/3d/sprite_3d.h" #include "scene/resources/surface_tool.h" #endif // _3D_DISABLED -#include "scene/gui/popup_menu.h" -#include "scene/main/canvas_layer.h" -#include "scene/main/scene_tree.h" -#include "scene/main/window.h" -#include "scene/resources/packed_scene.h" -#include "scene/theme/theme_db.h" SceneDebugger::SceneDebugger() { singleton = this; @@ -1608,6 +1612,7 @@ void RuntimeNodeSelect::_update_selection() { if (ci->_edit_use_rect()) { rect = ci->_edit_get_rect(); } else { +#ifndef _2D_DISABLED CollisionShape2D *collision_shape = Object::cast_to(ci); if (collision_shape) { Ref shape = collision_shape->get_shape(); @@ -1615,6 +1620,7 @@ void RuntimeNodeSelect::_update_selection() { rect = shape->get_rect(); } } +#endif // _2D_DISABLED } RS::get_singleton()->canvas_item_set_visible(sbox_2d_ci, selection_visible); @@ -1801,6 +1807,7 @@ void RuntimeNodeSelect::_find_canvas_items_at_pos(const Point2 &p_pos, Node *p_n res.order = ci->get_effective_z_index() + ci->get_canvas_layer(); r_items.push_back(res); +#ifndef _2D_DISABLED // If it's a shape, get the collision object it's from. // FIXME: If the collision object has multiple shapes, only the topmost will be above it in the list. if (Object::cast_to(ci) || Object::cast_to(ci)) { @@ -1812,6 +1819,7 @@ void RuntimeNodeSelect::_find_canvas_items_at_pos(const Point2 &p_pos, Node *p_n r_items.push_back(res_col); } } +#endif // _2D_DISABLED } } } diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp index 2cbe9acb3e89..fca6b075ca1c 100644 --- a/scene/main/canvas_item.cpp +++ b/scene/main/canvas_item.cpp @@ -31,7 +31,9 @@ #include "canvas_item.h" #include "canvas_item.compat.inc" +#ifndef _2D_DISABLED #include "scene/2d/canvas_group.h" +#endif // _2D_DISABLED #include "scene/main/canvas_layer.h" #include "scene/main/window.h" #include "scene/resources/atlas_texture.h" @@ -1614,13 +1616,16 @@ void CanvasItem::set_clip_children_mode(ClipChildrenMode p_clip_mode) { } clip_children_mode = p_clip_mode; +#ifndef _2D_DISABLED if (Object::cast_to(this) != nullptr) { //avoid accidental bugs, make this not work on CanvasGroup return; } +#endif // _2D_DISABLED RS::get_singleton()->canvas_item_set_canvas_group_mode(get_canvas_item(), RS::CanvasGroupMode(clip_children_mode)); } + CanvasItem::ClipChildrenMode CanvasItem::get_clip_children_mode() const { ERR_READ_THREAD_GUARD_V(CLIP_CHILDREN_DISABLED); return clip_children_mode; diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index a6c438e4c72c..dda159ff0fe3 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -49,7 +49,11 @@ #include "scene/resources/mesh.h" #include "scene/resources/packed_scene.h" #include "scene/resources/world_2d.h" + +#ifndef _2D_DISABLED #include "servers/physics_server_2d.h" +#endif // _2D_DISABLED + #ifndef _3D_DISABLED #include "scene/3d/node_3d.h" #include "scene/resources/3d/world_3d.h" @@ -969,7 +973,9 @@ void SceneTree::set_pause(bool p_enabled) { #ifndef _3D_DISABLED PhysicsServer3D::get_singleton()->set_active(!p_enabled); #endif // _3D_DISABLED +#ifndef _2D_DISABLED PhysicsServer2D::get_singleton()->set_active(!p_enabled); +#endif // _2D_DISABLED if (get_root()) { get_root()->_propagate_pause_notification(p_enabled); } @@ -993,7 +999,9 @@ void SceneTree::set_suspend(bool p_enabled) { #ifndef _3D_DISABLED PhysicsServer3D::get_singleton()->set_active(!p_enabled && !paused); #endif // _3D_DISABLED +#ifndef _2D_DISABLED PhysicsServer2D::get_singleton()->set_active(!p_enabled && !paused); +#endif // _2D_DISABLED if (get_root()) { get_root()->_propagate_suspend_notification(p_enabled); } @@ -1868,7 +1876,9 @@ SceneTree::SceneTree() { // Initialize network state. set_multiplayer(MultiplayerAPI::create_default_interface()); +#ifndef _2D_DISABLED root->set_as_audio_listener_2d(true); +#endif // _2D_DISABLED current_scene = nullptr; const int msaa_mode_2d = GLOBAL_DEF_BASIC(PropertyInfo(Variant::INT, "rendering/anti_aliasing/quality/msaa_2d", PROPERTY_HINT_ENUM, String::utf8("Disabled (Fastest),2× (Average),4× (Slow),8× (Slowest)")), 0); diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 81778f62827f..e3fcac09c454 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -34,9 +34,11 @@ #include "core/debugger/engine_debugger.h" #include "core/templates/pair.h" #include "core/templates/sort_array.h" +#ifndef _2D_DISABLED #include "scene/2d/audio_listener_2d.h" #include "scene/2d/camera_2d.h" #include "scene/2d/physics/collision_object_2d.h" +#endif // _2D_DISABLED #ifndef _3D_DISABLED #include "scene/3d/audio_listener_3d.h" #include "scene/3d/camera_3d.h" @@ -535,7 +537,9 @@ void Viewport::_notification(int p_what) { add_to_group("_viewports"); if (get_tree()->is_debugging_collisions_hint()) { +#ifndef _2D_DISABLED PhysicsServer2D::get_singleton()->space_set_debug_contacts(find_world_2d()->get_space(), get_tree()->get_collision_debug_contact_count()); +#endif // _2D_DISABLED contact_2d_debug = RenderingServer::get_singleton()->canvas_item_create(); RenderingServer::get_singleton()->canvas_item_set_parent(contact_2d_debug, current_canvas); #ifndef _3D_DISABLED @@ -621,6 +625,7 @@ void Viewport::_notification(int p_what) { RenderingServer::get_singleton()->canvas_item_clear(contact_2d_debug); RenderingServer::get_singleton()->canvas_item_set_draw_index(contact_2d_debug, 0xFFFFF); //very high index +#ifndef _2D_DISABLED Vector points = PhysicsServer2D::get_singleton()->space_get_contacts(find_world_2d()->get_space()); int point_count = PhysicsServer2D::get_singleton()->space_get_contact_count(find_world_2d()->get_space()); Color ccol = get_tree()->get_debug_collision_contact_color(); @@ -628,6 +633,7 @@ void Viewport::_notification(int p_what) { for (int i = 0; i < point_count; i++) { RenderingServer::get_singleton()->canvas_item_add_rect(contact_2d_debug, Rect2(points[i] - Vector2(2, 2), Vector2(5, 5)), ccol); } +#endif // _2D_DISABLED } #ifndef _3D_DISABLED if (get_tree()->is_debugging_collisions_hint() && contact_3d_debug_multimesh.is_valid()) { @@ -714,7 +720,9 @@ void Viewport::_process_picking() { PhysicsDirectSpaceState3D::RayResult result; #endif // _3D_DISABLED +#ifndef _2D_DISABLED PhysicsDirectSpaceState2D *ss2d = PhysicsServer2D::get_singleton()->space_get_direct_state(find_world_2d()->get_space()); +#endif // _2D_DISABLED SubViewportContainer *parent_svc = Object::cast_to(get_parent()); bool parent_ignore_mouse = (parent_svc && parent_svc->get_mouse_filter() == Control::MOUSE_FILTER_IGNORE); @@ -794,6 +802,9 @@ void Viewport::_process_picking() { pos = st->get_position(); } + // Avoid unused variable warning if 2D and 3D are both disabled. + (void)is_mouse; +#ifndef _2D_DISABLED if (ss2d) { // Send to 2D. @@ -886,6 +897,7 @@ void Viewport::_process_picking() { _cleanup_mouseover_colliders(false, false, frame); } } +#endif // _2D_DISABLED #ifndef _3D_DISABLED if (physics_object_picking_first_only && is_input_handled()) { @@ -2550,7 +2562,9 @@ void Viewport::_drop_mouse_focus() { } void Viewport::_drop_physics_mouseover(bool p_paused_only) { +#ifndef _2D_DISABLED _cleanup_mouseover_colliders(true, p_paused_only); +#endif // _2D_DISABLED #ifndef _3D_DISABLED if (physics_object_over.is_valid()) { @@ -3963,6 +3977,7 @@ void Viewport::_update_audio_listener_2d() { } } +#ifndef _2D_DISABLED void Viewport::_audio_listener_2d_set(AudioListener2D *p_audio_listener) { if (audio_listener_2d == p_audio_listener) { return; @@ -4100,6 +4115,7 @@ void Viewport::assign_next_enabled_camera_2d(const StringName &p_camera_group) { set_canvas_transform(Transform2D()); } } +#endif // _2D_DISABLED #ifndef _3D_DISABLED AudioListener3D *Viewport::get_audio_listener_3d() const { @@ -4828,10 +4844,12 @@ void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("_process_picking"), &Viewport::_process_picking); +#ifndef _2D_DISABLED ClassDB::bind_method(D_METHOD("set_as_audio_listener_2d", "enable"), &Viewport::set_as_audio_listener_2d); ClassDB::bind_method(D_METHOD("is_audio_listener_2d"), &Viewport::is_audio_listener_2d); ClassDB::bind_method(D_METHOD("get_audio_listener_2d"), &Viewport::get_audio_listener_2d); ClassDB::bind_method(D_METHOD("get_camera_2d"), &Viewport::get_camera_2d); +#endif // _2D_DISABLED #ifndef _3D_DISABLED ClassDB::bind_method(D_METHOD("set_world_3d", "world_3d"), &Viewport::set_world_3d); @@ -4913,7 +4931,9 @@ void Viewport::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "canvas_item_default_texture_filter", PROPERTY_HINT_ENUM, "Nearest,Linear,Linear Mipmap,Nearest Mipmap"), "set_default_canvas_item_texture_filter", "get_default_canvas_item_texture_filter"); ADD_PROPERTY(PropertyInfo(Variant::INT, "canvas_item_default_texture_repeat", PROPERTY_HINT_ENUM, "Disabled,Enabled,Mirror"), "set_default_canvas_item_texture_repeat", "get_default_canvas_item_texture_repeat"); ADD_GROUP("Audio Listener", "audio_listener_"); +#ifndef _2D_DISABLED ADD_PROPERTY(PropertyInfo(Variant::BOOL, "audio_listener_enable_2d"), "set_as_audio_listener_2d", "is_audio_listener_2d"); +#endif // _2D_DISABLED #ifndef _3D_DISABLED ADD_PROPERTY(PropertyInfo(Variant::BOOL, "audio_listener_enable_3d"), "set_as_audio_listener_3d", "is_audio_listener_3d"); #endif // _3D_DISABLED diff --git a/scene/main/viewport.h b/scene/main/viewport.h index c308286d94be..02f52e252daa 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -699,6 +699,7 @@ class Viewport : public Node { virtual bool is_attached_in_viewport() const { return false; } virtual bool is_sub_viewport() const { return false; } +#ifndef _2D_DISABLED private: // 2D audio, camera, and physics. (don't put World2D here because World2D is needed for Control nodes). friend class AudioListener2D; // Needs _audio_listener_2d_set and _audio_listener_2d_remove @@ -718,6 +719,7 @@ class Viewport : public Node { HashMap, uint64_t, PairHash> physics_2d_shape_mouseover; // Cleans up colliders corresponding to old frames or all of them. void _cleanup_mouseover_colliders(bool p_clean_all_frames, bool p_paused_only, uint64_t p_frame_reference = 0); +#endif // _2D_DISABLED public: AudioListener2D *get_audio_listener_2d() const; diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp index 64bc90f88434..7f9b562c7079 100644 --- a/scene/register_scene_types.cpp +++ b/scene/register_scene_types.cpp @@ -160,7 +160,7 @@ #include "scene/resources/world_2d.h" #include "scene/theme/theme_db.h" -// 2D +#ifndef _2D_DISABLED #include "scene/2d/animated_sprite_2d.h" #include "scene/2d/audio_listener_2d.h" #include "scene/2d/audio_stream_player_2d.h" @@ -229,6 +229,7 @@ #include "scene/resources/2d/skeleton/skeleton_modification_stack_2d.h" #include "scene/resources/2d/tile_set.h" #include "scene/resources/2d/world_boundary_shape_2d.h" +#endif // _2D_DISABLED #ifndef _3D_DISABLED #include "scene/3d/audio_listener_3d.h" @@ -382,7 +383,10 @@ void register_scene_types() { GDREGISTER_CLASS(HTTPRequest); GDREGISTER_CLASS(Timer); GDREGISTER_CLASS(CanvasLayer); +#ifndef _2D_DISABLED + // CanvasModulate must be registered before BaseButton... for some reason. GDREGISTER_CLASS(CanvasModulate); +#endif // _2D_DISABLED GDREGISTER_CLASS(ResourcePreloader); GDREGISTER_CLASS(Window); @@ -482,7 +486,9 @@ void register_scene_types() { GDREGISTER_CLASS(GraphElement); GDREGISTER_CLASS(GraphNode); GDREGISTER_CLASS(GraphFrame); +#ifndef _2D_DISABLED GDREGISTER_CLASS(GraphEdit); +#endif // _2D_DISABLED OS::get_singleton()->yield(); // may take time to init @@ -785,6 +791,7 @@ void register_scene_types() { /* REGISTER 2D */ +#ifndef _2D_DISABLED GDREGISTER_CLASS(Node2D); GDREGISTER_CLASS(CanvasGroup); GDREGISTER_CLASS(CPUParticles2D); @@ -853,6 +860,7 @@ void register_scene_types() { GDREGISTER_CLASS(PhysicalBone2D); GDREGISTER_CLASS(SkeletonModification2DPhysicalBones); +#endif // _2D_DISABLED OS::get_singleton()->yield(); // may take time to init @@ -1004,6 +1012,7 @@ void register_scene_types() { OS::get_singleton()->yield(); // may take time to init +#ifndef _2D_DISABLED GDREGISTER_CLASS(AudioStreamPlayer2D); GDREGISTER_ABSTRACT_CLASS(Shape2D); GDREGISTER_CLASS(WorldBoundaryShape2D); @@ -1026,6 +1035,7 @@ void register_scene_types() { GDREGISTER_CLASS(NavigationAgent2D); GDREGISTER_CLASS(NavigationObstacle2D); GDREGISTER_CLASS(NavigationLink2D); +#endif // _2D_DISABLED OS::get_singleton()->yield(); // may take time to init diff --git a/scene/resources/SCsub b/scene/resources/SCsub index b779ab61c9bd..aaa0559fd16a 100644 --- a/scene/resources/SCsub +++ b/scene/resources/SCsub @@ -30,6 +30,7 @@ env.scene_sources += scene_obj # Needed to force rebuilding the scene files when the thirdparty code is updated. env.Depends(scene_obj, thirdparty_obj) -SConscript("2d/SCsub") +if not env["disable_2d"]: + SConscript("2d/SCsub") if not env["disable_3d"]: SConscript("3d/SCsub") diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index 7f170e0085ec..67d3e864627f 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -34,15 +34,19 @@ #include "core/io/missing_resource.h" #include "core/io/resource_loader.h" #include "core/templates/local_vector.h" -#include "scene/2d/node_2d.h" -#ifndef _3D_DISABLED -#include "scene/3d/node_3d.h" -#endif // _3D_DISABLED #include "scene/gui/control.h" #include "scene/main/instance_placeholder.h" #include "scene/main/missing_node.h" #include "scene/property_utils.h" +#ifndef _2D_DISABLED +#include "scene/2d/node_2d.h" +#endif // _2D_DISABLED + +#ifndef _3D_DISABLED +#include "scene/3d/node_3d.h" +#endif // _3D_DISABLED + #define PACKED_SCENE_VERSION 3 #ifdef TOOLS_ENABLED @@ -277,8 +281,10 @@ Node *SceneState::instantiate(GenEditState p_edit_state) const { if (n.parent >= 0 && n.parent < nc && ret_nodes[n.parent]) { if (Object::cast_to(ret_nodes[n.parent])) { obj = memnew(Control); +#ifndef _2D_DISABLED } else if (Object::cast_to(ret_nodes[n.parent])) { obj = memnew(Node2D); +#endif // _2D_DISABLED #ifndef _3D_DISABLED } else if (Object::cast_to(ret_nodes[n.parent])) { obj = memnew(Node3D); diff --git a/scene/resources/world_2d.cpp b/scene/resources/world_2d.cpp index 21bfc2959a57..488d4e3d0e85 100644 --- a/scene/resources/world_2d.cpp +++ b/scene/resources/world_2d.cpp @@ -40,6 +40,7 @@ RID World2D::get_canvas() const { return canvas; } +#ifndef _2D_DISABLED RID World2D::get_space() const { if (space.is_null()) { space = PhysicsServer2D::get_singleton()->space_create(); @@ -67,18 +68,21 @@ RID World2D::get_navigation_map() const { PhysicsDirectSpaceState2D *World2D::get_direct_space_state() { return PhysicsServer2D::get_singleton()->space_get_direct_state(get_space()); } +#endif // _2D_DISABLED void World2D::_bind_methods() { ClassDB::bind_method(D_METHOD("get_canvas"), &World2D::get_canvas); + ADD_PROPERTY(PropertyInfo(Variant::RID, "canvas", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "", "get_canvas"); + +#ifndef _2D_DISABLED ClassDB::bind_method(D_METHOD("get_space"), &World2D::get_space); ClassDB::bind_method(D_METHOD("get_navigation_map"), &World2D::get_navigation_map); - ClassDB::bind_method(D_METHOD("get_direct_space_state"), &World2D::get_direct_space_state); - ADD_PROPERTY(PropertyInfo(Variant::RID, "canvas", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "", "get_canvas"); ADD_PROPERTY(PropertyInfo(Variant::RID, "space", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "", "get_space"); ADD_PROPERTY(PropertyInfo(Variant::RID, "navigation_map", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "", "get_navigation_map"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "direct_space_state", PROPERTY_HINT_RESOURCE_TYPE, "PhysicsDirectSpaceState2D", PROPERTY_USAGE_NONE), "", "get_direct_space_state"); +#endif // _2D_DISABLED } void World2D::register_viewport(Viewport *p_viewport) { @@ -95,13 +99,15 @@ World2D::World2D() { World2D::~World2D() { ERR_FAIL_NULL(RenderingServer::get_singleton()); + RenderingServer::get_singleton()->free(canvas); +#ifndef _2D_DISABLED ERR_FAIL_NULL(PhysicsServer2D::get_singleton()); ERR_FAIL_NULL(NavigationServer2D::get_singleton()); - RenderingServer::get_singleton()->free(canvas); if (space.is_valid()) { PhysicsServer2D::get_singleton()->free(space); } if (navigation_map.is_valid()) { NavigationServer2D::get_singleton()->free(navigation_map); } +#endif // _2D_DISABLED } diff --git a/scene/resources/world_2d.h b/scene/resources/world_2d.h index 04a15b03816c..9ec9100a45ff 100644 --- a/scene/resources/world_2d.h +++ b/scene/resources/world_2d.h @@ -32,18 +32,23 @@ #define WORLD_2D_H #include "core/io/resource.h" +#ifndef _2D_DISABLED #include "servers/physics_server_2d.h" +#endif // _2D_DISABLED class VisibleOnScreenNotifier2D; class Viewport; struct SpatialIndexer2D; +// World2D is needed for Viewport for CanvasItem rendering even when 2D is disabled. class World2D : public Resource { GDCLASS(World2D, Resource); RID canvas; +#ifndef _2D_DISABLED mutable RID space; mutable RID navigation_map; +#endif // _2D_DISABLED HashSet viewports; @@ -53,10 +58,12 @@ class World2D : public Resource { public: RID get_canvas() const; +#ifndef _2D_DISABLED RID get_space() const; RID get_navigation_map() const; PhysicsDirectSpaceState2D *get_direct_space_state(); +#endif // _2D_DISABLED void register_viewport(Viewport *p_viewport); void remove_viewport(Viewport *p_viewport); diff --git a/servers/SCsub b/servers/SCsub index 7abe53b9e171..75358df1707e 100644 --- a/servers/SCsub +++ b/servers/SCsub @@ -8,10 +8,7 @@ env.servers_sources = [] env.add_source_files(env.servers_sources, "audio_server.cpp") env.add_source_files(env.servers_sources, "camera_server.cpp") env.add_source_files(env.servers_sources, "display_server.cpp") -env.add_source_files(env.servers_sources, "navigation_server_2d.cpp") env.add_source_files(env.servers_sources, "navigation_server_3d.cpp") -env.add_source_files(env.servers_sources, "physics_server_2d.cpp") -env.add_source_files(env.servers_sources, "physics_server_2d_wrap_mt.cpp") env.add_source_files(env.servers_sources, "register_server_types.cpp") env.add_source_files(env.servers_sources, "rendering_server.cpp") env.add_source_files(env.servers_sources, "text_server.cpp") @@ -26,6 +23,11 @@ SConscript("navigation/SCsub") SConscript("rendering/SCsub") SConscript("text/SCsub") +if not env["disable_2d"]: + env.add_source_files(env.servers_sources, "navigation_server_2d.cpp") + env.add_source_files(env.servers_sources, "physics_server_2d.cpp") + env.add_source_files(env.servers_sources, "physics_server_2d_wrap_mt.cpp") + if not env["disable_3d"]: env.add_source_files(env.servers_sources, "physics_server_3d.cpp") env.add_source_files(env.servers_sources, "physics_server_3d_wrap_mt.cpp") diff --git a/servers/extensions/SCsub b/servers/extensions/SCsub index e7bb57e9f3f6..f5835aef1fad 100644 --- a/servers/extensions/SCsub +++ b/servers/extensions/SCsub @@ -5,7 +5,8 @@ Import("env") env_object = env.Clone() -env_object.add_source_files(env.servers_sources, "physics_server_2d_extension.cpp") +if not env["disable_2d"]: + env_object.add_source_files(env.servers_sources, "physics_server_2d_extension.cpp") if not env["disable_3d"]: env_object.add_source_files(env.servers_sources, "physics_server_3d_extension.cpp") diff --git a/servers/physics_server_2d.cpp b/servers/physics_server_2d.cpp index 10244cc05800..23864f446d48 100644 --- a/servers/physics_server_2d.cpp +++ b/servers/physics_server_2d.cpp @@ -28,6 +28,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ +#ifndef _2D_DISABLED + #include "physics_server_2d.h" #include "core/config/project_settings.h" @@ -1002,3 +1004,5 @@ PhysicsServer2DManager::PhysicsServer2DManager() { PhysicsServer2DManager::~PhysicsServer2DManager() { singleton = nullptr; } + +#endif // _2D_DISABLED diff --git a/servers/physics_server_2d.h b/servers/physics_server_2d.h index 2e7839dd0a10..5465ee5670be 100644 --- a/servers/physics_server_2d.h +++ b/servers/physics_server_2d.h @@ -31,6 +31,8 @@ #ifndef PHYSICS_SERVER_2D_H #define PHYSICS_SERVER_2D_H +#ifndef _2D_DISABLED + #include "core/io/resource.h" #include "core/object/class_db.h" #include "core/object/ref_counted.h" @@ -846,4 +848,6 @@ VARIANT_ENUM_CAST(PhysicsServer2D::DampedSpringParam); VARIANT_ENUM_CAST(PhysicsServer2D::AreaBodyStatus); VARIANT_ENUM_CAST(PhysicsServer2D::ProcessInfo); +#endif // _2D_DISABLED + #endif // PHYSICS_SERVER_2D_H diff --git a/servers/physics_server_2d_wrap_mt.cpp b/servers/physics_server_2d_wrap_mt.cpp index 991bbfb6a0a6..9db64841b8a3 100644 --- a/servers/physics_server_2d_wrap_mt.cpp +++ b/servers/physics_server_2d_wrap_mt.cpp @@ -28,6 +28,8 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /**************************************************************************/ +#ifndef _2D_DISABLED + #include "physics_server_2d_wrap_mt.h" void PhysicsServer2DWrapMT::_assign_mt_ids(WorkerThreadPool::TaskID p_pump_task_id) { @@ -108,3 +110,5 @@ PhysicsServer2DWrapMT::PhysicsServer2DWrapMT(PhysicsServer2D *p_contained, bool PhysicsServer2DWrapMT::~PhysicsServer2DWrapMT() { memdelete(physics_server_2d); } + +#endif // _2D_DISABLED diff --git a/servers/physics_server_2d_wrap_mt.h b/servers/physics_server_2d_wrap_mt.h index 5e9d472789a7..9d682a1e69d3 100644 --- a/servers/physics_server_2d_wrap_mt.h +++ b/servers/physics_server_2d_wrap_mt.h @@ -31,6 +31,8 @@ #ifndef PHYSICS_SERVER_2D_WRAP_MT_H #define PHYSICS_SERVER_2D_WRAP_MT_H +#ifndef _2D_DISABLED + #include "core/object/worker_thread_pool.h" #include "core/os/thread.h" #include "core/templates/command_queue_mt.h" @@ -339,4 +341,6 @@ class PhysicsServer2DWrapMT : public PhysicsServer2D { #undef MAIN_THREAD_SYNC_WARN #endif +#endif // _2D_DISABLED + #endif // PHYSICS_SERVER_2D_WRAP_MT_H diff --git a/servers/register_server_types.cpp b/servers/register_server_types.cpp index e6326f2385b8..56b01709d2a2 100644 --- a/servers/register_server_types.cpp +++ b/servers/register_server_types.cpp @@ -80,10 +80,12 @@ #include "text_server.h" // 2D physics and navigation. +#ifndef _2D_DISABLED #include "navigation_server_2d.h" #include "physics_server_2d.h" #include "physics_server_2d_dummy.h" #include "servers/extensions/physics_server_2d_extension.h" +#endif // _2D_DISABLED // 3D physics and navigation (3D navigation is needed for 2D). #include "navigation_server_3d.h" @@ -109,9 +111,11 @@ static PhysicsServer3D *_create_dummy_physics_server_3d() { } #endif // _3D_DISABLED +#ifndef _2D_DISABLED static PhysicsServer2D *_create_dummy_physics_server_2d() { return memnew(PhysicsServer2DDummy); } +#endif // _2D_DISABLED static bool has_server_feature_callback(const String &p_feature) { if (RenderingServer::get_singleton()) { @@ -248,6 +252,7 @@ void register_server_types() { ServersDebugger::initialize(); +#ifndef _2D_DISABLED // Physics 2D GDREGISTER_CLASS(PhysicsServer2DManager); Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer2DManager", PhysicsServer2DManager::get_singleton(), "PhysicsServer2DManager")); @@ -277,6 +282,7 @@ void register_server_types() { GDREGISTER_ABSTRACT_CLASS(NavigationServer2D); GDREGISTER_CLASS(NavigationPathQueryParameters2D); GDREGISTER_CLASS(NavigationPathQueryResult2D); +#endif // _2D_DISABLED #ifndef _3D_DISABLED // Physics 3D @@ -351,11 +357,12 @@ void register_server_singletons() { Engine::get_singleton()->add_singleton(Engine::Singleton("CameraServer", CameraServer::get_singleton(), "CameraServer")); Engine::get_singleton()->add_singleton(Engine::Singleton("DisplayServer", DisplayServer::get_singleton(), "DisplayServer")); Engine::get_singleton()->add_singleton(Engine::Singleton("NativeMenu", NativeMenu::get_singleton(), "NativeMenu")); - Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationServer2D", NavigationServer2D::get_singleton(), "NavigationServer2D")); Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationServer3D", NavigationServer3D::get_singleton(), "NavigationServer3D")); Engine::get_singleton()->add_singleton(Engine::Singleton("RenderingServer", RenderingServer::get_singleton(), "RenderingServer")); - +#ifndef _2D_DISABLED + Engine::get_singleton()->add_singleton(Engine::Singleton("NavigationServer2D", NavigationServer2D::get_singleton(), "NavigationServer2D")); Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer2D", PhysicsServer2D::get_singleton(), "PhysicsServer2D")); +#endif // _2D_DISABLED #ifndef _3D_DISABLED Engine::get_singleton()->add_singleton(Engine::Singleton("PhysicsServer3D", PhysicsServer3D::get_singleton(), "PhysicsServer3D")); Engine::get_singleton()->add_singleton(Engine::Singleton("XRServer", XRServer::get_singleton(), "XRServer"));