Skip to content

Commit

Permalink
Implement the ability to disable classes
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
reduz committed Jul 13, 2021
1 parent fc00a83 commit 5ad4f26
Show file tree
Hide file tree
Showing 44 changed files with 822 additions and 790 deletions.
2 changes: 2 additions & 0 deletions SConstruct
Original file line number Diff line number Diff line change
Expand Up @@ -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)", "")
Expand Down Expand Up @@ -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(
Expand Down
11 changes: 11 additions & 0 deletions core/object/class_db.h
Original file line number Diff line number Diff line change
Expand Up @@ -434,4 +434,15 @@ class ClassDB {

#endif

#define GDREGISTER_CLASS(m_class) \
if (!GD_IS_DEFINED(ClassDB_Disable_##m_class)) { \
ClassDB::register_class<m_class>(); \
}
#define GDREGISTER_VIRTUAL_CLASS(m_class) \
if (!GD_IS_DEFINED(ClassDB_Disable_##m_class)) { \
ClassDB::register_virtual_class<m_class>(); \
}

#include "core/disabled_classes.gen.h"

#endif // CLASS_DB_H
158 changes: 79 additions & 79 deletions core/register_core_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,50 +131,50 @@ void register_core_types() {
resource_format_image.instantiate();
ResourceLoader::add_resource_format_loader(resource_format_image);

ClassDB::register_class<Object>();

ClassDB::register_virtual_class<Script>();

ClassDB::register_class<RefCounted>();
ClassDB::register_class<WeakRef>();
ClassDB::register_class<Resource>();
ClassDB::register_class<Image>();

ClassDB::register_virtual_class<InputEvent>();
ClassDB::register_virtual_class<InputEventWithModifiers>();
ClassDB::register_virtual_class<InputEventFromWindow>();
ClassDB::register_class<InputEventKey>();
ClassDB::register_virtual_class<InputEventMouse>();
ClassDB::register_class<InputEventMouseButton>();
ClassDB::register_class<InputEventMouseMotion>();
ClassDB::register_class<InputEventJoypadButton>();
ClassDB::register_class<InputEventJoypadMotion>();
ClassDB::register_class<InputEventScreenDrag>();
ClassDB::register_class<InputEventScreenTouch>();
ClassDB::register_class<InputEventAction>();
ClassDB::register_virtual_class<InputEventGesture>();
ClassDB::register_class<InputEventMagnifyGesture>();
ClassDB::register_class<InputEventPanGesture>();
ClassDB::register_class<InputEventMIDI>();
GDREGISTER_CLASS(Object);

GDREGISTER_VIRTUAL_CLASS(Script);

GDREGISTER_CLASS(RefCounted);
GDREGISTER_CLASS(WeakRef);
GDREGISTER_CLASS(Resource);
GDREGISTER_CLASS(Image);

GDREGISTER_VIRTUAL_CLASS(InputEvent);
GDREGISTER_VIRTUAL_CLASS(InputEventWithModifiers);
GDREGISTER_VIRTUAL_CLASS(InputEventFromWindow);
GDREGISTER_CLASS(InputEventKey);
GDREGISTER_VIRTUAL_CLASS(InputEventMouse);
GDREGISTER_CLASS(InputEventMouseButton);
GDREGISTER_CLASS(InputEventMouseMotion);
GDREGISTER_CLASS(InputEventJoypadButton);
GDREGISTER_CLASS(InputEventJoypadMotion);
GDREGISTER_CLASS(InputEventScreenDrag);
GDREGISTER_CLASS(InputEventScreenTouch);
GDREGISTER_CLASS(InputEventAction);
GDREGISTER_VIRTUAL_CLASS(InputEventGesture);
GDREGISTER_CLASS(InputEventMagnifyGesture);
GDREGISTER_CLASS(InputEventPanGesture);
GDREGISTER_CLASS(InputEventMIDI);

// Network
ClassDB::register_virtual_class<IP>();
GDREGISTER_VIRTUAL_CLASS(IP);

ClassDB::register_virtual_class<StreamPeer>();
ClassDB::register_class<StreamPeerBuffer>();
ClassDB::register_class<StreamPeerTCP>();
ClassDB::register_class<TCPServer>();
GDREGISTER_VIRTUAL_CLASS(StreamPeer);
GDREGISTER_CLASS(StreamPeerBuffer);
GDREGISTER_CLASS(StreamPeerTCP);
GDREGISTER_CLASS(TCPServer);

ClassDB::register_virtual_class<PacketPeer>();
ClassDB::register_class<PacketPeerStream>();
ClassDB::register_class<PacketPeerUDP>();
ClassDB::register_class<UDPServer>();
GDREGISTER_VIRTUAL_CLASS(PacketPeer);
GDREGISTER_CLASS(PacketPeerStream);
GDREGISTER_CLASS(PacketPeerUDP);
GDREGISTER_CLASS(UDPServer);

ClassDB::register_custom_instance_class<HTTPClient>();

// Crypto
ClassDB::register_class<HashingContext>();
ClassDB::register_class<AESContext>();
GDREGISTER_CLASS(HashingContext);
GDREGISTER_CLASS(AESContext);
ClassDB::register_custom_instance_class<X509Certificate>();
ClassDB::register_custom_instance_class<CryptoKey>();
ClassDB::register_custom_instance_class<HMACContext>();
Expand All @@ -188,42 +188,42 @@ void register_core_types() {
resource_format_loader_crypto.instantiate();
ResourceLoader::add_resource_format_loader(resource_format_loader_crypto);

ClassDB::register_virtual_class<MultiplayerPeer>();
ClassDB::register_class<MultiplayerAPI>();
ClassDB::register_class<MainLoop>();
ClassDB::register_class<Translation>();
ClassDB::register_class<OptimizedTranslation>();
ClassDB::register_class<UndoRedo>();
ClassDB::register_class<TriangleMesh>();
GDREGISTER_VIRTUAL_CLASS(MultiplayerPeer);
GDREGISTER_CLASS(MultiplayerAPI);
GDREGISTER_CLASS(MainLoop);
GDREGISTER_CLASS(Translation);
GDREGISTER_CLASS(OptimizedTranslation);
GDREGISTER_CLASS(UndoRedo);
GDREGISTER_CLASS(TriangleMesh);

ClassDB::register_class<ResourceFormatLoader>();
ClassDB::register_class<ResourceFormatSaver>();
GDREGISTER_CLASS(ResourceFormatLoader);
GDREGISTER_CLASS(ResourceFormatSaver);

ClassDB::register_class<_File>();
ClassDB::register_class<_Directory>();
ClassDB::register_class<_Thread>();
ClassDB::register_class<_Mutex>();
ClassDB::register_class<_Semaphore>();
GDREGISTER_CLASS(_File);
GDREGISTER_CLASS(_Directory);
GDREGISTER_CLASS(_Thread);
GDREGISTER_CLASS(_Mutex);
GDREGISTER_CLASS(_Semaphore);

ClassDB::register_class<XMLParser>();
ClassDB::register_class<JSON>();
GDREGISTER_CLASS(XMLParser);
GDREGISTER_CLASS(JSON);

ClassDB::register_class<ConfigFile>();
GDREGISTER_CLASS(ConfigFile);

ClassDB::register_class<PCKPacker>();
GDREGISTER_CLASS(PCKPacker);

ClassDB::register_class<PackedDataContainer>();
ClassDB::register_virtual_class<PackedDataContainerRef>();
ClassDB::register_class<AStar>();
ClassDB::register_class<AStar2D>();
ClassDB::register_class<EncodedObjectAsID>();
ClassDB::register_class<RandomNumberGenerator>();
GDREGISTER_CLASS(PackedDataContainer);
GDREGISTER_VIRTUAL_CLASS(PackedDataContainerRef);
GDREGISTER_CLASS(AStar);
GDREGISTER_CLASS(AStar2D);
GDREGISTER_CLASS(EncodedObjectAsID);
GDREGISTER_CLASS(RandomNumberGenerator);

ClassDB::register_virtual_class<ResourceImporter>();
GDREGISTER_VIRTUAL_CLASS(ResourceImporter);

ClassDB::register_class<NativeExtension>();
GDREGISTER_CLASS(NativeExtension);

ClassDB::register_virtual_class<NativeExtensionManager>();
GDREGISTER_VIRTUAL_CLASS(NativeExtensionManager);

native_extension_manager = memnew(NativeExtensionManager);

Expand Down Expand Up @@ -253,22 +253,22 @@ void register_core_settings() {
}

void register_core_singletons() {
ClassDB::register_class<ProjectSettings>();
ClassDB::register_virtual_class<IP>();
ClassDB::register_class<_Geometry2D>();
ClassDB::register_class<_Geometry3D>();
ClassDB::register_class<_ResourceLoader>();
ClassDB::register_class<_ResourceSaver>();
ClassDB::register_class<_OS>();
ClassDB::register_class<_Engine>();
ClassDB::register_class<_ClassDB>();
ClassDB::register_class<_Marshalls>();
ClassDB::register_class<TranslationServer>();
ClassDB::register_virtual_class<Input>();
ClassDB::register_class<InputMap>();
ClassDB::register_class<Expression>();
ClassDB::register_class<_EngineDebugger>();
ClassDB::register_class<Time>();
GDREGISTER_CLASS(ProjectSettings);
GDREGISTER_VIRTUAL_CLASS(IP);
GDREGISTER_CLASS(_Geometry2D);
GDREGISTER_CLASS(_Geometry3D);
GDREGISTER_CLASS(_ResourceLoader);
GDREGISTER_CLASS(_ResourceSaver);
GDREGISTER_CLASS(_OS);
GDREGISTER_CLASS(_Engine);
GDREGISTER_CLASS(_ClassDB);
GDREGISTER_CLASS(_Marshalls);
GDREGISTER_CLASS(TranslationServer);
GDREGISTER_VIRTUAL_CLASS(Input);
GDREGISTER_CLASS(InputMap);
GDREGISTER_CLASS(Expression);
GDREGISTER_CLASS(_EngineDebugger);
GDREGISTER_CLASS(Time);

Engine::get_singleton()->add_singleton(Engine::Singleton("ProjectSettings", ProjectSettings::get_singleton()));
Engine::get_singleton()->add_singleton(Engine::Singleton("IP", IP::get_singleton(), "IP"));
Expand Down
7 changes: 7 additions & 0 deletions core/typedefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,11 @@ struct BuildIndexSequence<0, Is...> : IndexSequence<Is...> {};
#define DEBUG_METHODS_ENABLED
#endif

// Macro GD_IS_DEFINED() allows to check if a macro is defined. It needs to be defined to anything (say 1) to work.
#define __GDARG_PLACEHOLDER_1 0,
#define __gd_take_second_arg(__ignored, val, ...) val
#define ____gd_is_defined(arg1_or_junk) __gd_take_second_arg(arg1_or_junk 1, 0)
#define ___gd_is_defined(val) ____gd_is_defined(__GDARG_PLACEHOLDER_##val)
#define GD_IS_DEFINED(x) ___gd_is_defined(x)

#endif // TYPEDEFS_H
74 changes: 37 additions & 37 deletions editor/editor_node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3736,46 +3736,46 @@ void EditorNode::register_editor_types() {
ResourceLoader::set_timestamp_on_load(true);
ResourceSaver::set_timestamp_on_save(true);

ClassDB::register_class<EditorPaths>();
ClassDB::register_class<EditorPlugin>();
ClassDB::register_class<EditorTranslationParserPlugin>();
ClassDB::register_class<EditorImportPlugin>();
ClassDB::register_class<EditorScript>();
ClassDB::register_class<EditorSelection>();
ClassDB::register_class<EditorFileDialog>();
ClassDB::register_virtual_class<EditorSettings>();
ClassDB::register_class<EditorNode3DGizmo>();
ClassDB::register_class<EditorNode3DGizmoPlugin>();
ClassDB::register_virtual_class<EditorResourcePreview>();
ClassDB::register_class<EditorResourcePreviewGenerator>();
ClassDB::register_virtual_class<EditorFileSystem>();
ClassDB::register_class<EditorFileSystemDirectory>();
ClassDB::register_class<EditorVCSInterface>();
ClassDB::register_virtual_class<ScriptEditor>();
ClassDB::register_virtual_class<ScriptEditorBase>();
ClassDB::register_class<EditorSyntaxHighlighter>();
ClassDB::register_virtual_class<EditorInterface>();
ClassDB::register_class<EditorExportPlugin>();
ClassDB::register_class<EditorResourceConversionPlugin>();
ClassDB::register_class<EditorSceneImporter>();
ClassDB::register_class<EditorInspector>();
ClassDB::register_class<EditorInspectorPlugin>();
ClassDB::register_class<EditorProperty>();
ClassDB::register_class<AnimationTrackEditPlugin>();
ClassDB::register_class<ScriptCreateDialog>();
ClassDB::register_class<EditorFeatureProfile>();
ClassDB::register_class<EditorSpinSlider>();
ClassDB::register_class<EditorResourcePicker>();
ClassDB::register_class<EditorScriptPicker>();
ClassDB::register_class<EditorSceneImporterMesh>();
ClassDB::register_class<EditorSceneImporterMeshNode3D>();

ClassDB::register_virtual_class<FileSystemDock>();
GDREGISTER_CLASS(EditorPaths);
GDREGISTER_CLASS(EditorPlugin);
GDREGISTER_CLASS(EditorTranslationParserPlugin);
GDREGISTER_CLASS(EditorImportPlugin);
GDREGISTER_CLASS(EditorScript);
GDREGISTER_CLASS(EditorSelection);
GDREGISTER_CLASS(EditorFileDialog);
GDREGISTER_VIRTUAL_CLASS(EditorSettings);
GDREGISTER_CLASS(EditorNode3DGizmo);
GDREGISTER_CLASS(EditorNode3DGizmoPlugin);
GDREGISTER_VIRTUAL_CLASS(EditorResourcePreview);
GDREGISTER_CLASS(EditorResourcePreviewGenerator);
GDREGISTER_VIRTUAL_CLASS(EditorFileSystem);
GDREGISTER_CLASS(EditorFileSystemDirectory);
GDREGISTER_CLASS(EditorVCSInterface);
GDREGISTER_VIRTUAL_CLASS(ScriptEditor);
GDREGISTER_VIRTUAL_CLASS(ScriptEditorBase);
GDREGISTER_CLASS(EditorSyntaxHighlighter);
GDREGISTER_VIRTUAL_CLASS(EditorInterface);
GDREGISTER_CLASS(EditorExportPlugin);
GDREGISTER_CLASS(EditorResourceConversionPlugin);
GDREGISTER_CLASS(EditorSceneImporter);
GDREGISTER_CLASS(EditorInspector);
GDREGISTER_CLASS(EditorInspectorPlugin);
GDREGISTER_CLASS(EditorProperty);
GDREGISTER_CLASS(AnimationTrackEditPlugin);
GDREGISTER_CLASS(ScriptCreateDialog);
GDREGISTER_CLASS(EditorFeatureProfile);
GDREGISTER_CLASS(EditorSpinSlider);
GDREGISTER_CLASS(EditorResourcePicker);
GDREGISTER_CLASS(EditorScriptPicker);
GDREGISTER_CLASS(EditorSceneImporterMesh);
GDREGISTER_CLASS(EditorSceneImporterMeshNode3D);

GDREGISTER_VIRTUAL_CLASS(FileSystemDock);

// FIXME: Is this stuff obsolete, or should it be ported to new APIs?
ClassDB::register_class<EditorScenePostImport>();
GDREGISTER_CLASS(EditorScenePostImport);
//ClassDB::register_type<EditorImportExport>();
ClassDB::register_class<EditorDebuggerPlugin>();
GDREGISTER_CLASS(EditorDebuggerPlugin);

NativeExtensionManager::get_singleton()->initialize_extensions(NativeExtension::INITIALIZATION_LEVEL_EDITOR);
}
Expand Down
2 changes: 1 addition & 1 deletion editor/editor_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ void EditorSettings::create() {
return;
}

ClassDB::register_class<EditorSettings>(); // Otherwise it can't be unserialized.
GDREGISTER_CLASS(EditorSettings); // Otherwise it can't be unserialized.

String config_file_path;
Ref<ConfigFile> extra_config = memnew(ConfigFile);
Expand Down
2 changes: 1 addition & 1 deletion main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph

translation_server = memnew(TranslationServer);
performance = memnew(Performance);
ClassDB::register_class<Performance>();
GDREGISTER_CLASS(Performance);
engine->add_singleton(Engine::Singleton("Performance", performance));

// Only flush stdout in debug builds by default, as spamming `print()` will
Expand Down
12 changes: 12 additions & 0 deletions methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,18 @@ def is_module(path):
return True


def write_disabled_classes(class_list):
f = open("core/disabled_classes.gen.h", "w")
f.write("/* THIS FILE IS GENERATED DO NOT EDIT */\n")
f.write("#ifndef DISABLED_CLASSES_GEN_H\n")
f.write("#define DISABLED_CLASSES_GEN_H\n\n")
for c in class_list:
cs = c.strip()
if cs != "":
f.write("#define ClassDB_Disable_" + cs + " 1\n")
f.write("\n#endif\n")


def write_modules(modules):
includes_cpp = ""
preregister_cpp = ""
Expand Down
2 changes: 1 addition & 1 deletion modules/basis_universal/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ void register_basis_universal_types() {
Image::basis_universal_packer = basis_universal_packer;
#endif
Image::basis_universal_unpacker = basis_universal_unpacker;
//ClassDB::register_class<TextureBasisU>();
//GDREGISTER_CLASS(TextureBasisU);
}

void unregister_basis_universal_types() {
Expand Down
18 changes: 9 additions & 9 deletions modules/csg/register_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@
void register_csg_types() {
#ifndef _3D_DISABLED

ClassDB::register_virtual_class<CSGShape3D>();
ClassDB::register_virtual_class<CSGPrimitive3D>();
ClassDB::register_class<CSGMesh3D>();
ClassDB::register_class<CSGSphere3D>();
ClassDB::register_class<CSGBox3D>();
ClassDB::register_class<CSGCylinder3D>();
ClassDB::register_class<CSGTorus3D>();
ClassDB::register_class<CSGPolygon3D>();
ClassDB::register_class<CSGCombiner3D>();
GDREGISTER_VIRTUAL_CLASS(CSGShape3D);
GDREGISTER_VIRTUAL_CLASS(CSGPrimitive3D);
GDREGISTER_CLASS(CSGMesh3D);
GDREGISTER_CLASS(CSGSphere3D);
GDREGISTER_CLASS(CSGBox3D);
GDREGISTER_CLASS(CSGCylinder3D);
GDREGISTER_CLASS(CSGTorus3D);
GDREGISTER_CLASS(CSGPolygon3D);
GDREGISTER_CLASS(CSGCombiner3D);

#ifdef TOOLS_ENABLED
EditorPlugins::add_by_type<EditorPluginCSG>();
Expand Down
Loading

0 comments on commit 5ad4f26

Please sign in to comment.