Created
September 23, 2023 20:23
-
-
Save nlupugla/4329eb191830d0a01833fb4cb140d784 to your computer and use it in GitHub Desktop.
GDSTRUCT macro rough draft
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define GDSTRUCT(m_struct) \ | |
private: \ | |
friend class ::ClassDB; \ | |
\ | |
public: \ | |
typedef m_struct self_type; \ | |
static constexpr bool _class_is_enabled = !bool(GD_IS_DEFINED(ClassDB_Disable_##m_struct)); \ | |
virtual String get_class() const override { \ | |
return String(#m_struct); \ | |
} \ | |
virtual const StringName *_get_class_namev() const override { \ | |
static StringName _class_name_static; \ | |
if (unlikely(!_class_name_static)) { \ | |
StringName::assign_static_unique_class_name(&_class_name_static, #m_struct); \ | |
} \ | |
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_struct); \ | |
} \ | |
virtual bool is_class(const String &p_class) const override { \ | |
return (p_class == (#m_struct)); \ | |
} \ | |
virtual bool is_class_ptr(void *p_ptr) const override { return (p_ptr == get_class_ptr_static()); } \ | |
\ | |
protected: \ | |
_FORCE_INLINE_ static void (*_get_bind_methods())() { \ | |
return &m_struct::_bind_methods; \ | |
} \ | |
\ | |
public: \ | |
static void initialize_class() { \ | |
static bool initialized = false; \ | |
if (initialized) { \ | |
return; \ | |
} \ | |
::ClassDB::_add_class<m_struct>(); \ | |
_bind_methods(); \ | |
_bind_compatibility_methods(); \ | |
initialized = true; \ | |
} \ | |
\ | |
protected: \ | |
virtual void _initialize_classv() override { \ | |
initialize_class(); \ | |
} \ | |
\ | |
public: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment