From 5ad4f26659b435add8c4d36009be6a2222a0a624 Mon Sep 17 00:00:00 2001 From: reduz Date: Sun, 11 Jul 2021 19:30:33 -0300 Subject: [PATCH] Implement the ability to disable classes * This PR adds the ability to disable classes when building. * For now it's only possible to do this via command like: `scons disable_classes=RayCast2D,Area3D` * Eventually, a proper UI will be implemented to create a build config file to do this at large scale, as well as detect what is used in the project. --- SConstruct | 2 + core/object/class_db.h | 11 + core/register_core_types.cpp | 152 +-- core/typedefs.h | 7 + editor/editor_node.cpp | 72 +- editor/editor_settings.cpp | 2 +- main/main.cpp | 2 +- methods.py | 12 + modules/basis_universal/register_types.cpp | 2 +- modules/csg/register_types.cpp | 18 +- modules/enet/register_types.cpp | 2 +- modules/fbx/register_types.cpp | 2 +- .../gdnative/nativescript/register_types.cpp | 2 +- modules/gdnative/net/register_types.cpp | 6 +- .../gdnative/pluginscript/register_types.cpp | 2 +- modules/gdnative/register_types.cpp | 4 +- .../gdnative/videodecoder/register_types.cpp | 2 +- modules/gdnative/xr/register_types.cpp | 2 +- .../gdscript_language_server.cpp | 6 +- modules/gdscript/register_types.cpp | 2 +- modules/gltf/register_types.cpp | 30 +- modules/gridmap/register_types.cpp | 2 +- modules/jsonrpc/register_types.cpp | 2 +- modules/lightmapper_rd/register_types.cpp | 2 +- modules/minimp3/register_types.cpp | 2 +- modules/mobile_vr/register_types.cpp | 2 +- modules/mono/register_types.cpp | 4 +- modules/navigation/register_types.cpp | 2 +- modules/opensimplex/register_types.cpp | 4 +- modules/regex/register_types.cpp | 4 +- modules/stb_vorbis/register_types.cpp | 2 +- modules/theora/register_types.cpp | 2 +- modules/upnp/register_types.cpp | 4 +- modules/visual_script/register_types.cpp | 96 +- modules/webm/register_types.cpp | 2 +- modules/webrtc/register_types.cpp | 8 +- modules/websocket/register_types.cpp | 2 +- modules/webxr/register_types.cpp | 2 +- platform/android/api/api.cpp | 6 +- platform/android/java_godot_lib_jni.cpp | 2 +- platform/javascript/api/api.cpp | 4 +- scene/register_scene_types.cpp | 894 +++++++++--------- servers/register_server_types.cpp | 154 +-- tests/test_object.h | 4 +- 44 files changed, 789 insertions(+), 757 deletions(-) diff --git a/SConstruct b/SConstruct index 8b37bb82854..601b2d6e800 100644 --- a/SConstruct +++ b/SConstruct @@ -142,6 +142,7 @@ opts.Add("extra_suffix", "Custom extra suffix added to the base filename of all opts.Add(BoolVariable("vsproj", "Generate a Visual Studio solution", 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("disable_classes", "Disable given classes (comma separated)", "") opts.Add(BoolVariable("modules_enabled_by_default", "If no, disable all modules except ones explicitly enabled", True)) opts.Add(BoolVariable("no_editor_splash", "Don't use the custom splash screen for the editor", False)) opts.Add("system_certs_path", "Use this path as SSL certificates default for editor (for package maintainers)", "") @@ -642,6 +643,7 @@ if selected_platform in platform_list: if env["tools"]: env.Append(CPPDEFINES=["TOOLS_ENABLED"]) + methods.write_disabled_classes(env["disable_classes"].split(",")) if env["disable_3d"]: if env["tools"]: print( diff --git a/core/object/class_db.h b/core/object/class_db.h index af528bfde70..e0cba1b8b52 100644 --- a/core/object/class_db.h +++ b/core/object/class_db.h @@ -434,4 +434,15 @@ public: #endif +#define GDREGISTER_CLASS(m_class) \ + if (!GD_IS_DEFINED(ClassDB_Disable_##m_class)) { \ + ClassDB::register_class(); \ + } +#define GDREGISTER_VIRTUAL_CLASS(m_class) \ + if (!GD_IS_DEFINED(ClassDB_Disable_##m_class)) { \ + ClassDB::register_virtual_class(); \ + } + +#include "core/disabled_classes.gen.h" + #endif // CLASS_DB_H diff --git a/core/register_core_types.cpp b/core/register_core_types.cpp index 0739a0336d9..eb372675461 100644 --- a/core/register_core_types.cpp +++ b/core/register_core_types.cpp @@ -131,50 +131,50 @@ void register_core_types() { resource_format_image.instantiate(); ResourceLoader::add_resource_format_loader(resource_format_image); - ClassDB::register_class(); + GDREGISTER_CLASS(Object); - ClassDB::register_virtual_class