feat: modules moved and engine moved to submodule

This commit is contained in:
Jan van der Weide 2025-04-12 18:40:44 +02:00
parent dfb5e645cd
commit c33d2130cc
5136 changed files with 225275 additions and 64485 deletions

View file

@ -28,9 +28,9 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
#ifndef OBJECT_H
#define OBJECT_H
#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"
@ -47,6 +47,9 @@
template <typename T>
class TypedArray;
template <typename T>
class Ref;
enum PropertyHint {
PROPERTY_HINT_NONE, ///< no hint provided.
PROPERTY_HINT_RANGE, ///< hint_text = "min,max[,step][,or_greater][,or_less][,hide_slider][,radians_as_degrees][,degrees][,exp][,suffix:<keyword>] range.
@ -129,6 +132,9 @@ 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, _scs_create(m_setter), _scs_create(m_getter))
#define ADD_PROPERTYI(m_property, m_setter, m_getter, m_index) ::ClassDB::add_property(get_class_static(), m_property, _scs_create(m_setter), _scs_create(m_getter), m_index)
@ -209,6 +215,7 @@ struct PropertyInfo {
};
TypedArray<Dictionary> convert_property_list(const List<PropertyInfo> *p_list);
TypedArray<Dictionary> convert_property_list(const Vector<PropertyInfo> &p_vector);
enum MethodFlags {
METHOD_FLAG_NORMAL = 1,
@ -227,7 +234,7 @@ struct MethodInfo {
PropertyInfo return_val;
uint32_t flags = METHOD_FLAGS_DEFAULT;
int id = 0;
List<PropertyInfo> arguments;
Vector<PropertyInfo> arguments;
Vector<Variant> default_arguments;
int return_val_metadata = 0;
Vector<int> arguments_metadata;
@ -256,8 +263,8 @@ struct MethodInfo {
return_val(PropertyInfo(pinfo.return_value)),
flags(pinfo.flags),
id(pinfo.id) {
for (uint32_t j = 0; j < pinfo.argument_count; j++) {
arguments.push_back(PropertyInfo(pinfo.arguments[j]));
for (uint32_t i = 0; i < pinfo.argument_count; i++) {
arguments.push_back(PropertyInfo(pinfo.arguments[i]));
}
const Variant *def_values = (const Variant *)pinfo.default_arguments;
for (uint32_t j = 0; j < pinfo.default_argument_count; j++) {
@ -265,22 +272,12 @@ struct MethodInfo {
}
}
void _push_params(const PropertyInfo &p_param) {
arguments.push_back(p_param);
}
template <typename... VarArgs>
void _push_params(const PropertyInfo &p_param, VarArgs... p_params) {
arguments.push_back(p_param);
_push_params(p_params...);
}
MethodInfo(const String &p_name) { name = p_name; }
template <typename... VarArgs>
MethodInfo(const String &p_name, VarArgs... p_params) {
name = p_name;
_push_params(p_params...);
arguments = Vector<PropertyInfo>{ p_params... };
}
MethodInfo(Variant::Type ret) { return_val.type = ret; }
@ -293,7 +290,7 @@ struct MethodInfo {
MethodInfo(Variant::Type ret, const String &p_name, VarArgs... p_params) {
name = p_name;
return_val.type = ret;
_push_params(p_params...);
arguments = Vector<PropertyInfo>{ p_params... };
}
MethodInfo(const PropertyInfo &p_ret, const String &p_name) {
@ -305,7 +302,7 @@ struct MethodInfo {
MethodInfo(const PropertyInfo &p_ret, const String &p_name, VarArgs... p_params) {
return_val = p_ret;
name = p_name;
_push_params(p_params...);
arguments = Vector<PropertyInfo>{ p_params... };
}
};
@ -396,57 +393,46 @@ struct ObjectGDExtension {
* much alone defines the object model.
*/
// This is a barebones version of GDCLASS,
// only intended for simple classes deriving from Object
// so that they can support the `Object::cast_to()` method.
#define GDSOFTCLASS(m_class, m_inherits) \
public: \
using self_type = m_class; \
using super_type = m_inherits; \
static _FORCE_INLINE_ void *get_class_ptr_static() { \
static int ptr; \
return &ptr; \
} \
virtual bool is_class_ptr(void *p_ptr) const override { \
return (p_ptr == get_class_ptr_static()) || m_inherits::is_class_ptr(p_ptr); \
} \
\
private:
#define GDCLASS(m_class, m_inherits) \
GDSOFTCLASS(m_class, m_inherits) \
private: \
void operator=(const m_class &p_rval) {} \
friend class ::ClassDB; \
\
public: \
typedef m_class self_type; \
static constexpr bool _class_is_enabled = !bool(GD_IS_DEFINED(ClassDB_Disable_##m_class)) && m_inherits::_class_is_enabled; \
virtual String get_class() const override { \
if (_get_extension()) { \
return _get_extension()->class_name.operator String(); \
} \
return String(#m_class); \
} \
virtual const StringName *_get_class_namev() const override { \
return &get_class_static(); \
} \
static const StringName &get_class_static() { \
static StringName _class_name_static; \
if (unlikely(!_class_name_static)) { \
StringName::assign_static_unique_class_name(&_class_name_static, #m_class); \
} \
return &_class_name_static; \
} \
static _FORCE_INLINE_ void *get_class_ptr_static() { \
static int ptr; \
return &ptr; \
} \
static _FORCE_INLINE_ String get_class_static() { \
return String(#m_class); \
} \
static _FORCE_INLINE_ String get_parent_class_static() { \
return m_inherits::get_class_static(); \
} \
static void get_inheritance_list_static(List<String> *p_inheritance_list) { \
m_inherits::get_inheritance_list_static(p_inheritance_list); \
p_inheritance_list->push_back(String(#m_class)); \
return _class_name_static; \
} \
virtual bool is_class(const String &p_class) const override { \
if (_get_extension() && _get_extension()->is_class(p_class)) { \
return true; \
} \
return (p_class == (#m_class)) ? true : m_inherits::is_class(p_class); \
} \
virtual bool is_class_ptr(void *p_ptr) const override { \
return (p_ptr == get_class_ptr_static()) ? true : m_inherits::is_class_ptr(p_ptr); \
} \
\
static void get_valid_parents_static(List<String> *p_parents) { \
if (m_class::_get_valid_parents_static != m_inherits::_get_valid_parents_static) { \
m_class::_get_valid_parents_static(p_parents); \
} \
\
m_inherits::get_valid_parents_static(p_parents); \
} \
\
protected: \
@ -464,7 +450,7 @@ public:
return; \
} \
m_inherits::initialize_class(); \
::ClassDB::_add_class<m_class>(); \
_add_class_to_classdb(get_class_static(), super_type::get_class_static()); \
if (m_class::_get_bind_methods() != m_inherits::_get_bind_methods()) { \
_bind_methods(); \
} \
@ -479,7 +465,7 @@ protected:
initialize_class(); \
} \
_FORCE_INLINE_ bool (Object::*_get_get() const)(const StringName &p_name, Variant &) const { \
return (bool(Object::*)(const StringName &, Variant &) const) & m_class::_get; \
return (bool (Object::*)(const StringName &, Variant &) const) & m_class::_get; \
} \
virtual bool _getv(const StringName &p_name, Variant &r_ret) const override { \
if (m_class::_get_get() != m_inherits::_get_get()) { \
@ -490,7 +476,7 @@ protected:
return m_inherits::_getv(p_name, r_ret); \
} \
_FORCE_INLINE_ bool (Object::*_get_set() const)(const StringName &p_name, const Variant &p_property) { \
return (bool(Object::*)(const StringName &, const Variant &)) & m_class::_set; \
return (bool (Object::*)(const StringName &, const Variant &)) & m_class::_set; \
} \
virtual bool _setv(const StringName &p_name, const Variant &p_property) override { \
if (m_inherits::_setv(p_name, p_property)) { \
@ -502,14 +488,14 @@ protected:
return false; \
} \
_FORCE_INLINE_ void (Object::*_get_get_property_list() const)(List<PropertyInfo> * p_list) const { \
return (void(Object::*)(List<PropertyInfo> *) const) & m_class::_get_property_list; \
return (void (Object::*)(List<PropertyInfo> *) const) & m_class::_get_property_list; \
} \
virtual void _get_property_listv(List<PropertyInfo> *p_list, bool p_reversed) const override { \
if (!p_reversed) { \
m_inherits::_get_property_listv(p_list, p_reversed); \
} \
p_list->push_back(PropertyInfo(Variant::NIL, get_class_static(), PROPERTY_HINT_NONE, get_class_static(), PROPERTY_USAGE_CATEGORY)); \
::ClassDB::get_property_list(#m_class, p_list, true, this); \
_get_property_list_from_classdb(#m_class, p_list, true, this); \
if (m_class::_get_get_property_list() != m_inherits::_get_get_property_list()) { \
_get_property_list(p_list); \
} \
@ -518,7 +504,7 @@ protected:
} \
} \
_FORCE_INLINE_ void (Object::*_get_validate_property() const)(PropertyInfo & p_property) const { \
return (void(Object::*)(PropertyInfo &) const) & m_class::_validate_property; \
return (void (Object::*)(PropertyInfo &) const) & m_class::_validate_property; \
} \
virtual void _validate_propertyv(PropertyInfo &p_property) const override { \
m_inherits::_validate_propertyv(p_property); \
@ -527,7 +513,7 @@ protected:
} \
} \
_FORCE_INLINE_ bool (Object::*_get_property_can_revert() const)(const StringName &p_name) const { \
return (bool(Object::*)(const StringName &) const) & m_class::_property_can_revert; \
return (bool (Object::*)(const StringName &) const) & m_class::_property_can_revert; \
} \
virtual bool _property_can_revertv(const StringName &p_name) const override { \
if (m_class::_get_property_can_revert() != m_inherits::_get_property_can_revert()) { \
@ -538,7 +524,7 @@ protected:
return m_inherits::_property_can_revertv(p_name); \
} \
_FORCE_INLINE_ bool (Object::*_get_property_get_revert() const)(const StringName &p_name, Variant &) const { \
return (bool(Object::*)(const StringName &, Variant &) const) & m_class::_property_get_revert; \
return (bool (Object::*)(const StringName &, Variant &) const) & m_class::_property_get_revert; \
} \
virtual bool _property_get_revertv(const StringName &p_name, Variant &r_ret) const override { \
if (m_class::_get_property_get_revert() != m_inherits::_get_property_get_revert()) { \
@ -549,18 +535,19 @@ protected:
return m_inherits::_property_get_revertv(p_name, r_ret); \
} \
_FORCE_INLINE_ void (Object::*_get_notification() const)(int) { \
return (void(Object::*)(int)) & m_class::_notification; \
return (void (Object::*)(int)) & m_class::_notification; \
} \
virtual void _notificationv(int p_notification, bool p_reversed) override { \
if (!p_reversed) { \
m_inherits::_notificationv(p_notification, p_reversed); \
} \
virtual void _notification_forwardv(int p_notification) override { \
m_inherits::_notification_forwardv(p_notification); \
if (m_class::_get_notification() != m_inherits::_get_notification()) { \
_notification(p_notification); \
} \
if (p_reversed) { \
m_inherits::_notificationv(p_notification, p_reversed); \
} \
virtual void _notification_backwardv(int p_notification) override { \
if (m_class::_get_notification() != m_inherits::_get_notification()) { \
_notification(p_notification); \
} \
m_inherits::_notification_backwardv(p_notification); \
} \
\
private:
@ -704,7 +691,11 @@ protected:
virtual void _validate_propertyv(PropertyInfo &p_property) const {}
virtual bool _property_can_revertv(const StringName &p_name) const { return false; }
virtual bool _property_get_revertv(const StringName &p_name, Variant &r_property) const { return false; }
virtual void _notificationv(int p_notification, bool p_reversed) {}
void _notification_forward(int p_notification);
void _notification_backward(int p_notification);
virtual void _notification_forwardv(int p_notification) {}
virtual void _notification_backwardv(int p_notification) {}
static void _bind_methods();
static void _bind_compatibility_methods() {}
@ -743,18 +734,12 @@ protected:
_FORCE_INLINE_ void (Object::*_get_notification() const)(int) {
return &Object::_notification;
}
static void get_valid_parents_static(List<String> *p_parents);
static void _get_valid_parents_static(List<String> *p_parents);
Variant _call_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error);
Variant _call_deferred_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error);
virtual const StringName *_get_class_namev() const {
static StringName _class_name_static;
if (unlikely(!_class_name_static)) {
StringName::assign_static_unique_class_name(&_class_name_static, "Object");
}
return &_class_name_static;
return &get_class_static();
}
TypedArray<StringName> _get_meta_list_bind() const;
@ -766,12 +751,14 @@ protected:
friend class ClassDB;
friend class PlaceholderExtensionInstance;
static void _add_class_to_classdb(const StringName &p_class, const StringName &p_inherits);
static void _get_property_list_from_classdb(const StringName &p_class, List<PropertyInfo> *p_list, bool p_no_inheritance, const Object *p_validator);
bool _disconnect(const StringName &p_signal, const Callable &p_callable, bool p_force = false);
#ifdef TOOLS_ENABLED
struct VirtualMethodTracker {
void **method;
bool *initialized;
VirtualMethodTracker *next;
};
@ -797,12 +784,18 @@ public:
template <typename T>
static T *cast_to(Object *p_object) {
return p_object ? dynamic_cast<T *>(p_object) : nullptr;
// This is like dynamic_cast, but faster.
// The reason is that we can assume no virtual and multiple inheritance.
static_assert(std::is_base_of_v<Object, T>, "T must be derived from Object");
static_assert(std::is_same_v<std::decay_t<T>, typename T::self_type>, "T must use GDCLASS or GDSOFTCLASS");
return p_object && p_object->is_class_ptr(T::get_class_ptr_static()) ? static_cast<T *>(p_object) : nullptr;
}
template <typename T>
static const T *cast_to(const Object *p_object) {
return p_object ? dynamic_cast<const T *>(p_object) : nullptr;
static_assert(std::is_base_of_v<Object, T>, "T must be derived from Object");
static_assert(std::is_same_v<std::decay_t<T>, typename T::self_type>, "T must use GDCLASS or GDSOFTCLASS");
return p_object && p_object->is_class_ptr(T::get_class_ptr_static()) ? static_cast<const T *>(p_object) : nullptr;
}
enum {
@ -814,17 +807,16 @@ public:
};
/* TYPE API */
static void get_inheritance_list_static(List<String> *p_inheritance_list) { p_inheritance_list->push_back("Object"); }
static String get_class_static() { return "Object"; }
static String get_parent_class_static() { return String(); }
virtual String get_class() const {
if (_extension) {
return _extension->class_name.operator String();
static const StringName &get_class_static() {
static StringName _class_name_static;
if (unlikely(!_class_name_static)) {
StringName::assign_static_unique_class_name(&_class_name_static, "Object");
}
return "Object";
return _class_name_static;
}
_FORCE_INLINE_ String get_class() const { return get_class_name(); }
virtual String get_save_class() const { return get_class(); } //class stored when saving
virtual bool is_class(const String &p_class) const {
@ -835,19 +827,7 @@ public:
}
virtual bool is_class_ptr(void *p_ptr) const { return get_class_ptr_static() == p_ptr; }
_FORCE_INLINE_ const StringName &get_class_name() const {
if (_extension) {
// Can't put inside the unlikely as constructor can run it
return _extension->class_name;
}
if (unlikely(!_class_name_ptr)) {
// While class is initializing / deinitializing, constructors and destructurs
// need access to the proper class at the proper stage.
return *_get_class_namev();
}
return *_class_name_ptr;
}
const StringName &get_class_name() const;
StringName get_class_name_for_extension(const GDExtension *p_library) const;
@ -882,7 +862,17 @@ public:
return (cerr.error == Callable::CallError::CALL_OK) ? ret : Variant();
}
void notification(int p_notification, bool p_reversed = false);
// Depending on the boolean, we call either the virtual function _notification_backward or _notification_forward.
// - Forward calls subclasses in descending order (e.g. Object -> Node -> Node3D -> extension -> script).
// Backward calls subclasses in descending order (e.g. script -> extension -> Node3D -> Node -> Object).
_FORCE_INLINE_ void notification(int p_notification, bool p_reversed = false) {
if (p_reversed) {
_notification_backward(p_notification);
} else {
_notification_forward(p_notification);
}
}
virtual String to_string();
// Used mainly by script, get and set all INCLUDING string.
@ -974,7 +964,7 @@ public:
#ifdef TOOLS_ENABLED
virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const;
void editor_set_section_unfold(const String &p_section, bool p_unfolded);
void editor_set_section_unfold(const String &p_section, bool p_unfolded, bool p_initializing = false);
bool editor_is_section_unfolded(const String &p_section);
const HashSet<String> &editor_get_section_folding() const { return editor_section_folding; }
void editor_clear_section_folding() { editor_section_folding.clear(); }
@ -1062,8 +1052,15 @@ public:
return object;
}
template <typename T>
_ALWAYS_INLINE_ static T *get_instance(ObjectID p_instance_id) {
return Object::cast_to<T>(get_instance(p_instance_id));
}
template <typename T>
_ALWAYS_INLINE_ static Ref<T> get_ref(ObjectID p_instance_id); // Defined in ref_counted.h
static void debug_objects(DebugFunc p_func);
static int get_object_count();
};
#endif // OBJECT_H