Core: Handle disabled class detection in ClassDB
This commit is contained in:
@ -11,7 +11,7 @@ def disabled_class_builder(target, source, env):
|
||||
with methods.generated_wrapper(str(target[0])) as file:
|
||||
for c in source[0].read():
|
||||
if cs := c.strip():
|
||||
file.write(f"#define ClassDB_Disable_{cs} 1\n")
|
||||
file.write(f"class {cs}; template <> struct is_class_enabled<{cs}> : std::false_type {{}};\n")
|
||||
|
||||
|
||||
# Generate version info
|
||||
|
||||
@ -41,6 +41,24 @@
|
||||
|
||||
#include <type_traits>
|
||||
|
||||
template <typename T, typename = void>
|
||||
struct is_class_enabled;
|
||||
|
||||
template <>
|
||||
struct is_class_enabled<Object> : std::true_type {};
|
||||
|
||||
template <typename T>
|
||||
struct is_class_enabled<T, std::enable_if_t<std::is_base_of_v<Object, T>>> {
|
||||
static constexpr bool value = is_class_enabled<typename T::super_type>::value;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline constexpr bool is_class_enabled_v = is_class_enabled<T>::value;
|
||||
|
||||
#define GD_IS_CLASS_ENABLED(m_class) is_class_enabled_v<m_class>
|
||||
|
||||
#include "core/disabled_classes.gen.h"
|
||||
|
||||
#define DEFVAL(m_defval) (m_defval)
|
||||
#define DEFVAL_ARRAY DEFVAL(ClassDB::default_array_arg)
|
||||
|
||||
@ -551,25 +569,24 @@ public:
|
||||
|
||||
#endif // DEBUG_ENABLED
|
||||
|
||||
#define GDREGISTER_CLASS(m_class) \
|
||||
if (m_class::_class_is_enabled) { \
|
||||
::ClassDB::register_class<m_class>(); \
|
||||
#define GDREGISTER_CLASS(m_class) \
|
||||
if constexpr (GD_IS_CLASS_ENABLED(m_class)) { \
|
||||
::ClassDB::register_class<m_class>(); \
|
||||
}
|
||||
#define GDREGISTER_VIRTUAL_CLASS(m_class) \
|
||||
if (m_class::_class_is_enabled) { \
|
||||
if constexpr (GD_IS_CLASS_ENABLED(m_class)) { \
|
||||
::ClassDB::register_class<m_class>(true); \
|
||||
}
|
||||
#define GDREGISTER_ABSTRACT_CLASS(m_class) \
|
||||
if (m_class::_class_is_enabled) { \
|
||||
if constexpr (GD_IS_CLASS_ENABLED(m_class)) { \
|
||||
::ClassDB::register_abstract_class<m_class>(); \
|
||||
}
|
||||
#define GDREGISTER_INTERNAL_CLASS(m_class) \
|
||||
if (m_class::_class_is_enabled) { \
|
||||
if constexpr (GD_IS_CLASS_ENABLED(m_class)) { \
|
||||
::ClassDB::register_internal_class<m_class>(); \
|
||||
}
|
||||
|
||||
#define GDREGISTER_RUNTIME_CLASS(m_class) \
|
||||
if (m_class::_class_is_enabled) { \
|
||||
if constexpr (GD_IS_CLASS_ENABLED(m_class)) { \
|
||||
::ClassDB::register_runtime_class<m_class>(); \
|
||||
}
|
||||
|
||||
|
||||
@ -30,7 +30,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "core/disabled_classes.gen.h"
|
||||
#include "core/extension/gdextension_interface.h"
|
||||
#include "core/object/message_queue.h"
|
||||
#include "core/object/object_id.h"
|
||||
@ -135,9 +134,6 @@ enum PropertyUsageFlags {
|
||||
PROPERTY_USAGE_NO_EDITOR = PROPERTY_USAGE_STORAGE,
|
||||
};
|
||||
|
||||
// Respective values are defined by disabled_classes.gen.h
|
||||
#define GD_IS_CLASS_ENABLED(m_class) m_class::_class_is_enabled
|
||||
|
||||
#define ADD_SIGNAL(m_signal) ::ClassDB::add_signal(get_class_static(), m_signal)
|
||||
#define ADD_PROPERTY(m_property, m_setter, m_getter) ::ClassDB::add_property(get_class_static(), m_property, StringName(m_setter), StringName(m_getter))
|
||||
#define ADD_PROPERTYI(m_property, m_setter, m_getter, m_index) ::ClassDB::add_property(get_class_static(), m_property, StringName(m_setter), StringName(m_getter), m_index)
|
||||
@ -498,7 +494,6 @@ private:
|
||||
friend class ::ClassDB; \
|
||||
\
|
||||
public: \
|
||||
static constexpr bool _class_is_enabled = !bool(GD_IS_DEFINED(ClassDB_Disable_##m_class)) && m_inherits::_class_is_enabled; \
|
||||
virtual const StringName *_get_class_namev() const override { \
|
||||
return &get_class_static(); \
|
||||
} \
|
||||
@ -786,8 +781,6 @@ public: // Should be protected, but bug in clang++.
|
||||
_FORCE_INLINE_ static void register_custom_data_to_otdb() {}
|
||||
|
||||
public:
|
||||
static constexpr bool _class_is_enabled = true;
|
||||
|
||||
void notify_property_list_changed();
|
||||
|
||||
static void *get_class_ptr_static() {
|
||||
|
||||
@ -140,7 +140,7 @@ void register_core_types() {
|
||||
|
||||
CoreStringNames::create();
|
||||
|
||||
if (GD_IS_CLASS_ENABLED(Translation)) {
|
||||
if constexpr (GD_IS_CLASS_ENABLED(Translation)) {
|
||||
resource_format_po.instantiate();
|
||||
ResourceLoader::add_resource_format_loader(resource_format_po);
|
||||
}
|
||||
@ -156,7 +156,7 @@ void register_core_types() {
|
||||
resource_format_importer_saver.instantiate();
|
||||
ResourceSaver::add_resource_format_saver(resource_format_importer_saver);
|
||||
|
||||
if (GD_IS_CLASS_ENABLED(Image)) {
|
||||
if constexpr (GD_IS_CLASS_ENABLED(Image)) {
|
||||
resource_format_image.instantiate();
|
||||
ResourceLoader::add_resource_format_loader(resource_format_image);
|
||||
}
|
||||
@ -226,7 +226,7 @@ void register_core_types() {
|
||||
ClassDB::register_custom_instance_class<PacketPeerDTLS>();
|
||||
ClassDB::register_custom_instance_class<DTLSServer>();
|
||||
|
||||
if (GD_IS_CLASS_ENABLED(Crypto)) {
|
||||
if constexpr (GD_IS_CLASS_ENABLED(Crypto)) {
|
||||
resource_format_saver_crypto.instantiate();
|
||||
ResourceSaver::add_resource_format_saver(resource_format_saver_crypto);
|
||||
|
||||
@ -234,7 +234,7 @@ void register_core_types() {
|
||||
ResourceLoader::add_resource_format_loader(resource_format_loader_crypto);
|
||||
}
|
||||
|
||||
if (GD_IS_CLASS_ENABLED(JSON)) {
|
||||
if constexpr (GD_IS_CLASS_ENABLED(JSON)) {
|
||||
resource_saver_json.instantiate();
|
||||
ResourceSaver::add_resource_format_saver(resource_saver_json);
|
||||
|
||||
@ -292,7 +292,7 @@ void register_core_types() {
|
||||
|
||||
gdextension_manager = memnew(GDExtensionManager);
|
||||
|
||||
if (GD_IS_CLASS_ENABLED(GDExtension)) {
|
||||
if constexpr (GD_IS_CLASS_ENABLED(GDExtension)) {
|
||||
resource_loader_gdextension.instantiate();
|
||||
ResourceLoader::add_resource_format_loader(resource_loader_gdextension);
|
||||
}
|
||||
@ -426,7 +426,7 @@ void unregister_core_types() {
|
||||
memdelete(ip);
|
||||
}
|
||||
|
||||
if (GD_IS_CLASS_ENABLED(Image)) {
|
||||
if constexpr (GD_IS_CLASS_ENABLED(Image)) {
|
||||
ResourceLoader::remove_resource_format_loader(resource_format_image);
|
||||
resource_format_image.unref();
|
||||
}
|
||||
@ -443,12 +443,12 @@ void unregister_core_types() {
|
||||
ResourceSaver::remove_resource_format_saver(resource_format_importer_saver);
|
||||
resource_format_importer_saver.unref();
|
||||
|
||||
if (GD_IS_CLASS_ENABLED(Translation)) {
|
||||
if constexpr (GD_IS_CLASS_ENABLED(Translation)) {
|
||||
ResourceLoader::remove_resource_format_loader(resource_format_po);
|
||||
resource_format_po.unref();
|
||||
}
|
||||
|
||||
if (GD_IS_CLASS_ENABLED(Crypto)) {
|
||||
if constexpr (GD_IS_CLASS_ENABLED(Crypto)) {
|
||||
ResourceSaver::remove_resource_format_saver(resource_format_saver_crypto);
|
||||
resource_format_saver_crypto.unref();
|
||||
|
||||
@ -456,7 +456,7 @@ void unregister_core_types() {
|
||||
resource_format_loader_crypto.unref();
|
||||
}
|
||||
|
||||
if (GD_IS_CLASS_ENABLED(JSON)) {
|
||||
if constexpr (GD_IS_CLASS_ENABLED(JSON)) {
|
||||
ResourceSaver::remove_resource_format_saver(resource_saver_json);
|
||||
resource_saver_json.unref();
|
||||
|
||||
@ -464,7 +464,7 @@ void unregister_core_types() {
|
||||
resource_loader_json.unref();
|
||||
}
|
||||
|
||||
if (GD_IS_CLASS_ENABLED(GDExtension)) {
|
||||
if constexpr (GD_IS_CLASS_ENABLED(GDExtension)) {
|
||||
ResourceLoader::remove_resource_format_loader(resource_loader_gdextension);
|
||||
resource_loader_gdextension.unref();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user