diff options
Diffstat (limited to 'core/object.h')
-rw-r--r-- | core/object.h | 658 |
1 files changed, 329 insertions, 329 deletions
diff --git a/core/object.h b/core/object.h index 3fe31bee6b..a5836b74ff 100644 --- a/core/object.h +++ b/core/object.h @@ -30,19 +30,19 @@ #define OBJECT_H #include "list.h" -#include "variant.h" -#include "set.h" #include "map.h" -#include "vmap.h" #include "os/rw_lock.h" +#include "set.h" +#include "variant.h" +#include "vmap.h" -#define VARIANT_ARG_LIST const Variant& p_arg1=Variant(),const Variant& p_arg2=Variant(),const Variant& p_arg3=Variant(),const Variant& p_arg4=Variant(),const Variant& p_arg5=Variant() -#define VARIANT_ARG_PASS p_arg1,p_arg2,p_arg3,p_arg4,p_arg5 -#define VARIANT_ARG_DECLARE const Variant& p_arg1,const Variant& p_arg2,const Variant& p_arg3,const Variant& p_arg4,const Variant& p_arg5 +#define VARIANT_ARG_LIST const Variant &p_arg1 = Variant(), const Variant &p_arg2 = Variant(), const Variant &p_arg3 = Variant(), const Variant &p_arg4 = Variant(), const Variant &p_arg5 = Variant() +#define VARIANT_ARG_PASS p_arg1, p_arg2, p_arg3, p_arg4, p_arg5 +#define VARIANT_ARG_DECLARE const Variant &p_arg1, const Variant &p_arg2, const Variant &p_arg3, const Variant &p_arg4, const Variant &p_arg5 #define VARIANT_ARG_MAX 5 -#define VARIANT_ARGPTRS const Variant *argptr[5]={&p_arg1,&p_arg2,&p_arg3,&p_arg4,&p_arg5}; -#define VARIANT_ARGPTRS_PASS *argptr[0],*argptr[1],*argptr[2],*argptr[3],*argptr[4] -#define VARIANT_ARGS_FROM_ARRAY(m_arr) m_arr[0],m_arr[1],m_arr[2],m_arr[3],m_arr[4] +#define VARIANT_ARGPTRS const Variant *argptr[5] = { &p_arg1, &p_arg2, &p_arg3, &p_arg4, &p_arg5 }; +#define VARIANT_ARGPTRS_PASS *argptr[0], *argptr[1], *argptr[2], *argptr[3], *argptr[4] +#define VARIANT_ARGS_FROM_ARRAY(m_arr) m_arr[0], m_arr[1], m_arr[2], m_arr[3], m_arr[4] /** @author Juan Linietsky <reduzio@gmail.com> @@ -87,40 +87,37 @@ enum PropertyHint { enum PropertyUsageFlags { - PROPERTY_USAGE_STORAGE=1, - PROPERTY_USAGE_EDITOR=2, - PROPERTY_USAGE_NETWORK=4, - PROPERTY_USAGE_EDITOR_HELPER=8, - PROPERTY_USAGE_CHECKABLE=16, //used for editing global variables - PROPERTY_USAGE_CHECKED=32, //used for editing global variables - PROPERTY_USAGE_INTERNATIONALIZED=64, //hint for internationalized strings - PROPERTY_USAGE_GROUP=128, //used for grouping props in the editor - PROPERTY_USAGE_CATEGORY=256, - PROPERTY_USAGE_STORE_IF_NONZERO=512, //only store if nonzero - PROPERTY_USAGE_STORE_IF_NONONE=1024, //only store if false - PROPERTY_USAGE_NO_INSTANCE_STATE=2048, - PROPERTY_USAGE_RESTART_IF_CHANGED=4096, - PROPERTY_USAGE_SCRIPT_VARIABLE=8192, - PROPERTY_USAGE_STORE_IF_NULL=16384, - PROPERTY_USAGE_ANIMATE_AS_TRIGGER=32768, - PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED=65536, - - PROPERTY_USAGE_DEFAULT=PROPERTY_USAGE_STORAGE|PROPERTY_USAGE_EDITOR|PROPERTY_USAGE_NETWORK, - PROPERTY_USAGE_DEFAULT_INTL=PROPERTY_USAGE_STORAGE|PROPERTY_USAGE_EDITOR|PROPERTY_USAGE_NETWORK|PROPERTY_USAGE_INTERNATIONALIZED, - PROPERTY_USAGE_NOEDITOR=PROPERTY_USAGE_STORAGE|PROPERTY_USAGE_NETWORK, + PROPERTY_USAGE_STORAGE = 1, + PROPERTY_USAGE_EDITOR = 2, + PROPERTY_USAGE_NETWORK = 4, + PROPERTY_USAGE_EDITOR_HELPER = 8, + PROPERTY_USAGE_CHECKABLE = 16, //used for editing global variables + PROPERTY_USAGE_CHECKED = 32, //used for editing global variables + PROPERTY_USAGE_INTERNATIONALIZED = 64, //hint for internationalized strings + PROPERTY_USAGE_GROUP = 128, //used for grouping props in the editor + PROPERTY_USAGE_CATEGORY = 256, + PROPERTY_USAGE_STORE_IF_NONZERO = 512, //only store if nonzero + PROPERTY_USAGE_STORE_IF_NONONE = 1024, //only store if false + PROPERTY_USAGE_NO_INSTANCE_STATE = 2048, + PROPERTY_USAGE_RESTART_IF_CHANGED = 4096, + PROPERTY_USAGE_SCRIPT_VARIABLE = 8192, + PROPERTY_USAGE_STORE_IF_NULL = 16384, + PROPERTY_USAGE_ANIMATE_AS_TRIGGER = 32768, + PROPERTY_USAGE_UPDATE_ALL_IF_MODIFIED = 65536, + + PROPERTY_USAGE_DEFAULT = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_NETWORK, + PROPERTY_USAGE_DEFAULT_INTL = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_NETWORK | PROPERTY_USAGE_INTERNATIONALIZED, + PROPERTY_USAGE_NOEDITOR = PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_NETWORK, }; - - - -#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 ) -#define ADD_PROPERTYNZ( m_property, m_setter, m_getter ) ClassDB::add_property( get_class_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONZERO), _scs_create(m_setter), _scs_create(m_getter) ) -#define ADD_PROPERTYINZ( m_property, m_setter, m_getter, m_index ) ClassDB::add_property( get_class_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONZERO), _scs_create(m_setter), _scs_create(m_getter), m_index ) -#define ADD_PROPERTYNO( m_property, m_setter, m_getter ) ClassDB::add_property( get_class_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONONE), _scs_create(m_setter), _scs_create(m_getter) ) -#define ADD_PROPERTYINO( m_property, m_setter, m_getter, m_index ) ClassDB::add_property( get_class_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONONE), _scs_create(m_setter), _scs_create(m_getter), m_index ) -#define ADD_GROUP( m_name, m_prefix ) ClassDB::add_property_group( get_class_static(), m_name, m_prefix ) +#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) +#define ADD_PROPERTYNZ(m_property, m_setter, m_getter) ClassDB::add_property(get_class_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONZERO), _scs_create(m_setter), _scs_create(m_getter)) +#define ADD_PROPERTYINZ(m_property, m_setter, m_getter, m_index) ClassDB::add_property(get_class_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONZERO), _scs_create(m_setter), _scs_create(m_getter), m_index) +#define ADD_PROPERTYNO(m_property, m_setter, m_getter) ClassDB::add_property(get_class_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONONE), _scs_create(m_setter), _scs_create(m_getter)) +#define ADD_PROPERTYINO(m_property, m_setter, m_getter, m_index) ClassDB::add_property(get_class_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONONE), _scs_create(m_setter), _scs_create(m_getter), m_index) +#define ADD_GROUP(m_name, m_prefix) ClassDB::add_property_group(get_class_static(), m_name, m_prefix) struct PropertyInfo { @@ -130,25 +127,34 @@ struct PropertyInfo { String hint_string; uint32_t usage; - _FORCE_INLINE_ PropertyInfo added_usage(int p_fl) const { PropertyInfo pi=*this; pi.usage|=p_fl; return pi; } - + _FORCE_INLINE_ PropertyInfo added_usage(int p_fl) const { + PropertyInfo pi = *this; + pi.usage |= p_fl; + return pi; + } operator Dictionary() const; - static PropertyInfo from_dict(const Dictionary& p_dict); + static PropertyInfo from_dict(const Dictionary &p_dict); - PropertyInfo() { type=Variant::NIL; hint=PROPERTY_HINT_NONE; usage = PROPERTY_USAGE_DEFAULT; } - PropertyInfo( Variant::Type p_type, const String p_name, PropertyHint p_hint=PROPERTY_HINT_NONE, const String& p_hint_string="",uint32_t p_usage=PROPERTY_USAGE_DEFAULT) { - type=p_type; name=p_name; hint=p_hint; hint_string=p_hint_string; usage=p_usage; + PropertyInfo() { + type = Variant::NIL; + hint = PROPERTY_HINT_NONE; + usage = PROPERTY_USAGE_DEFAULT; + } + PropertyInfo(Variant::Type p_type, const String p_name, PropertyHint p_hint = PROPERTY_HINT_NONE, const String &p_hint_string = "", uint32_t p_usage = PROPERTY_USAGE_DEFAULT) { + type = p_type; + name = p_name; + hint = p_hint; + hint_string = p_hint_string; + usage = p_usage; } - bool operator<(const PropertyInfo& p_info) const { - return name<p_info.name; + bool operator<(const PropertyInfo &p_info) const { + return name < p_info.name; } }; - - -Array convert_property_list(const List<PropertyInfo> * p_list); +Array convert_property_list(const List<PropertyInfo> *p_list); struct MethodInfo { @@ -159,25 +165,25 @@ struct MethodInfo { uint32_t flags; int id; - inline bool operator<(const MethodInfo& p_method) const { return id==p_method.id?(name < p_method.name):(id<p_method.id); } + inline bool operator<(const MethodInfo &p_method) const { return id == p_method.id ? (name < p_method.name) : (id < p_method.id); } operator Dictionary() const; - static MethodInfo from_dict(const Dictionary& p_dict); + static MethodInfo from_dict(const Dictionary &p_dict); MethodInfo(); - MethodInfo(const String& p_name); - MethodInfo(const String& p_name, const PropertyInfo& p_param1); - MethodInfo(const String& p_name, const PropertyInfo& p_param1,const PropertyInfo& p_param2); - MethodInfo(const String& p_name, const PropertyInfo& p_param1,const PropertyInfo& p_param2,const PropertyInfo& p_param3); - MethodInfo(const String& p_name, const PropertyInfo& p_param1,const PropertyInfo& p_param2,const PropertyInfo& p_param3,const PropertyInfo& p_param4); - MethodInfo(const String& p_name, const PropertyInfo& p_param1,const PropertyInfo& p_param2,const PropertyInfo& p_param3,const PropertyInfo& p_param4,const PropertyInfo& p_param5); + MethodInfo(const String &p_name); + MethodInfo(const String &p_name, const PropertyInfo &p_param1); + MethodInfo(const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2); + MethodInfo(const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3); + MethodInfo(const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3, const PropertyInfo &p_param4); + MethodInfo(const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3, const PropertyInfo &p_param4, const PropertyInfo &p_param5); MethodInfo(Variant::Type ret); - MethodInfo(Variant::Type ret,const String& p_name); - MethodInfo(Variant::Type ret,const String& p_name, const PropertyInfo& p_param1); - MethodInfo(Variant::Type ret,const String& p_name, const PropertyInfo& p_param1,const PropertyInfo& p_param2); - MethodInfo(Variant::Type ret,const String& p_name, const PropertyInfo& p_param1,const PropertyInfo& p_param2,const PropertyInfo& p_param3); - MethodInfo(Variant::Type ret,const String& p_name, const PropertyInfo& p_param1,const PropertyInfo& p_param2,const PropertyInfo& p_param3,const PropertyInfo& p_param4); - MethodInfo(Variant::Type ret,const String& p_name, const PropertyInfo& p_param1,const PropertyInfo& p_param2,const PropertyInfo& p_param3,const PropertyInfo& p_param4,const PropertyInfo& p_param5); + MethodInfo(Variant::Type ret, const String &p_name); + MethodInfo(Variant::Type ret, const String &p_name, const PropertyInfo &p_param1); + MethodInfo(Variant::Type ret, const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2); + MethodInfo(Variant::Type ret, const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3); + MethodInfo(Variant::Type ret, const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3, const PropertyInfo &p_param4); + MethodInfo(Variant::Type ret, const String &p_name, const PropertyInfo &p_param1, const PropertyInfo &p_param2, const PropertyInfo &p_param3, const PropertyInfo &p_param4, const PropertyInfo &p_param5); }; // old cast_to @@ -190,154 +196,156 @@ struct MethodInfo { the following is an uncomprehensible blob of hacks and workarounds to compensate for many of the fallencies in C++. As a plus, this macro pretty much alone defines the object model. */ -#define REVERSE_GET_PROPERTY_LIST \ -public:\ -_FORCE_INLINE_ bool _is_gpl_reversed() const { return true; };\ +#define REVERSE_GET_PROPERTY_LIST \ +public: \ + _FORCE_INLINE_ bool _is_gpl_reversed() const { return true; }; \ + \ private: -#define UNREVERSE_GET_PROPERTY_LIST \ -public:\ -_FORCE_INLINE_ bool _is_gpl_reversed() const { return false; };\ +#define UNREVERSE_GET_PROPERTY_LIST \ +public: \ + _FORCE_INLINE_ bool _is_gpl_reversed() const { return false; }; \ + \ private: - - -#define GDCLASS( m_class, m_inherits )\ -private:\ - void operator=(const m_class& p_rval) {}\ - mutable StringName _class_name;\ - friend class ClassDB;\ -public:\ -virtual String get_class() const { \ - return String(#m_class);\ -}\ -virtual const StringName* _get_class_namev() const { \ - if (!_class_name)\ - _class_name=get_class_static();\ - return &_class_name;\ -}\ -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));\ -}\ -static String get_category_static() { \ - String category = m_inherits::get_category_static();\ - if (_get_category!=m_inherits::_get_category) {\ - if (category!="")\ - category+="/";\ - category+=_get_category();\ - }\ - return category;\ -}\ -static String inherits_static() {\ - return String(#m_inherits);\ -}\ -virtual bool is_class(const String& p_class) const { return (p_class==(#m_class))?true:m_inherits::is_class(p_class); }\ -virtual bool is_class_ptr(void *p_ptr) const { 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:\ -_FORCE_INLINE_ static void (*_get_bind_methods())() {\ - return &m_class::_bind_methods;\ -}\ -public:\ -static void initialize_class() {\ - static bool initialized=false;\ - if (initialized)\ - return;\ - m_inherits::initialize_class();\ - ClassDB::_add_class<m_class>();\ - if (m_class::_get_bind_methods() != m_inherits::_get_bind_methods())\ - _bind_methods();\ - initialized=true;\ -}\ -protected:\ -virtual void _initialize_classv() {\ - 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;\ -}\ -virtual bool _getv(const StringName& p_name, Variant& r_ret) const { \ - if (m_class::_get_get() != m_inherits::_get_get()) {\ - if (_get(p_name,r_ret))\ - return true;\ - }\ - 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;\ -}\ -virtual bool _setv(const StringName& p_name,const Variant &p_property) { \ - if (m_inherits::_setv(p_name,p_property)) return true;\ - if (m_class::_get_set() != m_inherits::_get_set()) {\ - return _set(p_name,p_property);\ - \ - }\ - 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;\ -}\ -virtual void _get_property_listv(List<PropertyInfo> *p_list,bool p_reversed) const { \ - 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,String(),PROPERTY_USAGE_CATEGORY));\ - if (!_is_gpl_reversed())\ - ClassDB::get_property_list(#m_class,p_list,true,this);\ - if (m_class::_get_get_property_list() != m_inherits::_get_get_property_list()) {\ - _get_property_list(p_list);\ - }\ - if (_is_gpl_reversed())\ - ClassDB::get_property_list(#m_class,p_list,true,this);\ - if (p_reversed) {\ - m_inherits::_get_property_listv(p_list,p_reversed);\ - }\ -\ -}\ -_FORCE_INLINE_ void (Object::* (_get_notification() const))(int){\ - return (void (Object::*)(int)) &m_class::_notification;\ -}\ -virtual void _notificationv(int p_notification,bool p_reversed) { \ - if (!p_reversed) \ - m_inherits::_notificationv(p_notification,p_reversed);\ - if (m_class::_get_notification() != m_inherits::_get_notification()) {\ - _notification(p_notification);\ - }\ - if (p_reversed)\ - m_inherits::_notificationv(p_notification,p_reversed);\ -}\ -\ +#define GDCLASS(m_class, m_inherits) \ +private: \ + void operator=(const m_class &p_rval) {} \ + mutable StringName _class_name; \ + friend class ClassDB; \ + \ +public: \ + virtual String get_class() const { \ + return String(#m_class); \ + } \ + virtual const StringName *_get_class_namev() const { \ + if (!_class_name) \ + _class_name = get_class_static(); \ + return &_class_name; \ + } \ + 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)); \ + } \ + static String get_category_static() { \ + String category = m_inherits::get_category_static(); \ + if (_get_category != m_inherits::_get_category) { \ + if (category != "") \ + category += "/"; \ + category += _get_category(); \ + } \ + return category; \ + } \ + static String inherits_static() { \ + return String(#m_inherits); \ + } \ + virtual bool is_class(const String &p_class) const { return (p_class == (#m_class)) ? true : m_inherits::is_class(p_class); } \ + virtual bool is_class_ptr(void *p_ptr) const { 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: \ + _FORCE_INLINE_ static void (*_get_bind_methods())() { \ + return &m_class::_bind_methods; \ + } \ + \ +public: \ + static void initialize_class() { \ + static bool initialized = false; \ + if (initialized) \ + return; \ + m_inherits::initialize_class(); \ + ClassDB::_add_class<m_class>(); \ + if (m_class::_get_bind_methods() != m_inherits::_get_bind_methods()) \ + _bind_methods(); \ + initialized = true; \ + } \ + \ +protected: \ + virtual void _initialize_classv() { \ + 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; \ + } \ + virtual bool _getv(const StringName &p_name, Variant &r_ret) const { \ + if (m_class::_get_get() != m_inherits::_get_get()) { \ + if (_get(p_name, r_ret)) \ + return true; \ + } \ + 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; \ + } \ + virtual bool _setv(const StringName &p_name, const Variant &p_property) { \ + if (m_inherits::_setv(p_name, p_property)) return true; \ + if (m_class::_get_set() != m_inherits::_get_set()) { \ + return _set(p_name, p_property); \ + } \ + 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; \ + } \ + virtual void _get_property_listv(List<PropertyInfo> *p_list, bool p_reversed) const { \ + 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, String(), PROPERTY_USAGE_CATEGORY)); \ + if (!_is_gpl_reversed()) \ + ClassDB::get_property_list(#m_class, p_list, true, this); \ + if (m_class::_get_get_property_list() != m_inherits::_get_get_property_list()) { \ + _get_property_list(p_list); \ + } \ + if (_is_gpl_reversed()) \ + ClassDB::get_property_list(#m_class, p_list, true, this); \ + if (p_reversed) { \ + m_inherits::_get_property_listv(p_list, p_reversed); \ + } \ + } \ + _FORCE_INLINE_ void (Object::*(_get_notification() const))(int) { \ + return (void (Object::*)(int)) & m_class::_notification; \ + } \ + virtual void _notificationv(int p_notification, bool p_reversed) { \ + if (!p_reversed) \ + m_inherits::_notificationv(p_notification, p_reversed); \ + if (m_class::_get_notification() != m_inherits::_get_notification()) { \ + _notification(p_notification); \ + } \ + if (p_reversed) \ + m_inherits::_notificationv(p_notification, p_reversed); \ + } \ + \ private: - -#define OBJ_CATEGORY(m_category)\ -protected:\ -_FORCE_INLINE_ static String _get_category() { return m_category; }\ +#define OBJ_CATEGORY(m_category) \ +protected: \ + _FORCE_INLINE_ static String _get_category() { return m_category; } \ + \ private: -#define OBJ_SAVE_TYPE(m_class) \ -public: \ -virtual String get_save_class() const { return #m_class; }\ +#define OBJ_SAVE_TYPE(m_class) \ +public: \ + virtual String get_save_class() const { return #m_class; } \ + \ private: class ScriptInstance; @@ -345,12 +353,11 @@ typedef uint32_t ObjectID; class Object { public: - enum ConnectFlags { - CONNECT_DEFERRED=1, - CONNECT_PERSIST=2, // hint for scene to save this connection - CONNECT_ONESHOT=4 + CONNECT_DEFERRED = 1, + CONNECT_PERSIST = 2, // hint for scene to save this connection + CONNECT_ONESHOT = 4 }; struct Connection { @@ -361,19 +368,23 @@ public: StringName method; uint32_t flags; Vector<Variant> binds; - bool operator<(const Connection& p_conn) const; + bool operator<(const Connection &p_conn) const; operator Variant() const; - Connection() { source=NULL; target=NULL; flags=0; } - Connection(const Variant& p_variant); + Connection() { + source = NULL; + target = NULL; + flags = 0; + } + Connection(const Variant &p_variant); }; + private: #ifdef DEBUG_ENABLED -friend class _ObjectDebugLock; + friend class _ObjectDebugLock; #endif -friend bool predelete_handler(Object*); -friend void postinitialize_handler(Object*); - + friend bool predelete_handler(Object *); + friend void postinitialize_handler(Object *); struct Signal { @@ -382,10 +393,13 @@ friend void postinitialize_handler(Object*); ObjectID _id; StringName method; - _FORCE_INLINE_ bool operator<(const Target& p_target) const { return (_id==p_target._id)?(method<p_target.method):(_id<p_target._id); } + _FORCE_INLINE_ bool operator<(const Target &p_target) const { return (_id == p_target._id) ? (method < p_target.method) : (_id < p_target._id); } - Target(const ObjectID& p_id, const StringName& p_method) { _id=p_id; method=p_method; } - Target() { _id=0; } + Target(const ObjectID &p_id, const StringName &p_method) { + _id = p_id; + method = p_method; + } + Target() { _id = 0; } }; struct Slot { @@ -395,21 +409,19 @@ friend void postinitialize_handler(Object*); }; MethodInfo user; - VMap<Target,Slot> slot_map; + VMap<Target, Slot> slot_map; int lock; - Signal() { lock=0; } - + Signal() { lock = 0; } }; - - HashMap< StringName, Signal, StringNameHasher> signal_map; + HashMap<StringName, Signal, StringNameHasher> signal_map; List<Connection> connections; #ifdef DEBUG_ENABLED SafeRefCount _lock_index; #endif bool _block_signals; int _predelete_ok; - Set<Object*> change_receptors; + Set<Object *> change_receptors; uint32_t _instance_ID; bool _predelete(); void _postinitialize(); @@ -422,67 +434,63 @@ friend void postinitialize_handler(Object*); RefPtr script; Dictionary metadata; mutable StringName _class_name; - mutable const StringName* _class_ptr; + mutable const StringName *_class_ptr; - void _add_user_signal(const String& p_name, const Array& p_pargs=Array()); - bool _has_user_signal(const StringName& p_name) const; - Variant _emit_signal(const Variant** p_args, int p_argcount, Variant::CallError& r_error); + void _add_user_signal(const String &p_name, const Array &p_pargs = Array()); + bool _has_user_signal(const StringName &p_name) const; + Variant _emit_signal(const Variant **p_args, int p_argcount, Variant::CallError &r_error); Array _get_signal_list() const; - Array _get_signal_connection_list(const String& p_signal) const; - void _set_bind(const String& p_set,const Variant& p_value); - Variant _get_bind(const String& p_name) const; + Array _get_signal_connection_list(const String &p_signal) const; + void _set_bind(const String &p_set, const Variant &p_value); + Variant _get_bind(const String &p_name) const; void property_list_changed_notify(); protected: - - virtual void _initialize_classv() { initialize_class(); } - virtual bool _setv(const StringName& p_name,const Variant &p_property) { return false; }; - virtual bool _getv(const StringName& p_name,Variant &r_property) const { return false; }; - virtual void _get_property_listv(List<PropertyInfo> *p_list,bool p_reversed) const {}; - virtual void _notificationv(int p_notification,bool p_reversed) {}; + virtual bool _setv(const StringName &p_name, const Variant &p_property) { return false; }; + virtual bool _getv(const StringName &p_name, Variant &r_property) const { return false; }; + virtual void _get_property_listv(List<PropertyInfo> *p_list, bool p_reversed) const {}; + virtual void _notificationv(int p_notification, bool p_reversed){}; static String _get_category() { return ""; } static void _bind_methods(); - bool _set(const StringName& p_name,const Variant &p_property) { return false; }; - bool _get(const StringName& p_name,Variant &r_property) const { return false; }; + bool _set(const StringName &p_name, const Variant &p_property) { return false; }; + bool _get(const StringName &p_name, Variant &r_property) const { return false; }; void _get_property_list(List<PropertyInfo> *p_list) const {}; - void _notification(int p_notification) {}; + void _notification(int p_notification){}; _FORCE_INLINE_ static void (*_get_bind_methods())() { return &Object::_bind_methods; } - _FORCE_INLINE_ bool (Object::* (_get_get() const))(const StringName& p_name,Variant &r_ret) const { + _FORCE_INLINE_ bool (Object::*(_get_get() const))(const StringName &p_name, Variant &r_ret) const { return &Object::_get; } - _FORCE_INLINE_ bool (Object::* (_get_set() const))(const StringName& p_name,const Variant &p_property) { - return &Object::_set; + _FORCE_INLINE_ bool (Object::*(_get_set() const))(const StringName &p_name, const Variant &p_property) { + return &Object::_set; } - _FORCE_INLINE_ void (Object::* (_get_get_property_list() const))(List<PropertyInfo> *p_list) const{ - return &Object::_get_property_list; + _FORCE_INLINE_ void (Object::*(_get_get_property_list() const))(List<PropertyInfo> *p_list) const { + return &Object::_get_property_list; } - _FORCE_INLINE_ void (Object::* (_get_notification() const))(int){ - return &Object::_notification; + _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); - void cancel_delete(); - virtual void _changed_callback(Object *p_changed,const char *p_prop); + virtual void _changed_callback(Object *p_changed, const char *p_prop); //Variant _call_bind(const StringName& p_name, const Variant& p_arg1 = Variant(), const Variant& p_arg2 = Variant(), const Variant& p_arg3 = Variant(), const Variant& p_arg4 = Variant()); //void _call_deferred_bind(const StringName& p_name, const Variant& p_arg1 = Variant(), const Variant& p_arg2 = Variant(), const Variant& p_arg3 = Variant(), const Variant& p_arg4 = Variant()); - Variant _call_bind(const Variant** p_args, int p_argcount, Variant::CallError& r_error); - Variant _call_deferred_bind(const Variant** p_args, int p_argcount, Variant::CallError& r_error); - + Variant _call_bind(const Variant **p_args, int p_argcount, Variant::CallError &r_error); + Variant _call_deferred_bind(const Variant **p_args, int p_argcount, Variant::CallError &r_error); - virtual const StringName* _get_class_namev() const { + virtual const StringName *_get_class_namev() const { if (!_class_name) - _class_name=get_class_static(); + _class_name = get_class_static(); return &_class_name; } @@ -492,21 +500,24 @@ protected: void _clear_internal_resource_paths(const Variant &p_var); -friend class ClassDB; - virtual void _validate_property(PropertyInfo& property) const; + friend class ClassDB; + virtual void _validate_property(PropertyInfo &property) const; public: //should be protected, but bug in clang++ static void initialize_class(); - _FORCE_INLINE_ static void register_custom_data_to_otdb() {}; + _FORCE_INLINE_ static void register_custom_data_to_otdb(){}; public: - #ifdef TOOLS_ENABLED - _FORCE_INLINE_ void _change_notify(const char *p_property="") { _edited=true; for(Set<Object*>::Element *E=change_receptors.front();E;E=E->next()) ((Object*)(E->get()))->_changed_callback(this,p_property); } + _FORCE_INLINE_ void _change_notify(const char *p_property = "") { + _edited = true; + for (Set<Object *>::Element *E = change_receptors.front(); E; E = E->next()) + ((Object *)(E->get()))->_changed_callback(this, p_property); + } #else - _FORCE_INLINE_ void _change_notify(const char *p_what="") { } + _FORCE_INLINE_ void _change_notify(const char *p_what = "") {} #endif - static void* get_class_ptr_static() { + static void *get_class_ptr_static() { static int ptr; return &ptr; } @@ -516,34 +527,34 @@ public: _FORCE_INLINE_ ObjectID get_instance_ID() const { return _instance_ID; } // this is used for editors - void add_change_receptor( Object *p_receptor ); - void remove_change_receptor( Object *p_receptor ); + void add_change_receptor(Object *p_receptor); + void remove_change_receptor(Object *p_receptor); - template<class T> + template <class T> T *cast_to() { #ifndef NO_SAFE_CAST - return SAFE_CAST<T*>(this); + return SAFE_CAST<T *>(this); #else if (!this) return NULL; if (is_class_ptr(T::get_class_ptr_static())) - return static_cast<T*>(this); + return static_cast<T *>(this); else return NULL; #endif } - template<class T> + template <class T> const T *cast_to() const { #ifndef NO_SAFE_CAST - return SAFE_CAST<const T*>(this); + return SAFE_CAST<const T *>(this); #else if (!this) return NULL; if (is_class_ptr(T::get_class_ptr_static())) - return static_cast<const T*>(this); + return static_cast<const T *>(this); else return NULL; #endif @@ -551,27 +562,24 @@ public: enum { - NOTIFICATION_POSTINITIALIZE=0, - NOTIFICATION_PREDELETE=1 + NOTIFICATION_POSTINITIALIZE = 0, + NOTIFICATION_PREDELETE = 1 }; /* TYPE API */ - static void get_inheritance_list_static(List<String>* p_inheritance_list) { p_inheritance_list->push_back("Object"); } + 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(); } static String get_category_static() { return String(); } - virtual String get_class() const { return "Object"; } virtual String get_save_class() const { return get_class(); } //class stored when saving + virtual bool is_class(const String &p_class) const { return (p_class == "Object"); } + virtual bool is_class_ptr(void *p_ptr) const { return get_class_ptr_static() == p_ptr; } - - virtual bool is_class(const String& p_class) const { return (p_class=="Object"); } - virtual bool is_class_ptr(void *p_ptr) const { return get_class_ptr_static()==p_ptr; } - - _FORCE_INLINE_ const StringName& get_class_name() const { + _FORCE_INLINE_ const StringName &get_class_name() const { if (!_class_ptr) { return *_get_class_namev(); } else { @@ -583,36 +591,36 @@ public: //void set(const String& p_name, const Variant& p_value); //Variant get(const String& p_name) const; - void set(const StringName& p_name, const Variant& p_value, bool *r_valid=NULL); - Variant get(const StringName& p_name, bool *r_valid=NULL) const; + void set(const StringName &p_name, const Variant &p_value, bool *r_valid = NULL); + Variant get(const StringName &p_name, bool *r_valid = NULL) const; - void get_property_list(List<PropertyInfo> *p_list,bool p_reversed=false) const; + void get_property_list(List<PropertyInfo> *p_list, bool p_reversed = false) const; - bool has_method(const StringName& p_method) const; + bool has_method(const StringName &p_method) const; void get_method_list(List<MethodInfo> *p_list) const; - Variant callv(const StringName& p_method,const Array& p_args); - virtual Variant call(const StringName& p_method,const Variant** p_args,int p_argcount,Variant::CallError &r_error); - virtual void call_multilevel(const StringName& p_method,const Variant** p_args,int p_argcount); - virtual void call_multilevel_reversed(const StringName& p_method,const Variant** p_args,int p_argcount); - Variant call(const StringName& p_name, VARIANT_ARG_LIST); // C++ helper - void call_multilevel(const StringName& p_name, VARIANT_ARG_LIST); // C++ helper + Variant callv(const StringName &p_method, const Array &p_args); + virtual Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error); + virtual void call_multilevel(const StringName &p_method, const Variant **p_args, int p_argcount); + virtual void call_multilevel_reversed(const StringName &p_method, const Variant **p_args, int p_argcount); + Variant call(const StringName &p_name, VARIANT_ARG_LIST); // C++ helper + void call_multilevel(const StringName &p_name, VARIANT_ARG_LIST); // C++ helper - void notification(int p_notification,bool p_reversed=false); + void notification(int p_notification, bool p_reversed = false); //used mainly by script, get and set all INCLUDING string - virtual Variant getvar(const Variant& p_key, bool *r_valid=NULL) const; - virtual void setvar(const Variant& p_key, const Variant& p_value,bool *r_valid=NULL); + virtual Variant getvar(const Variant &p_key, bool *r_valid = NULL) const; + virtual void setvar(const Variant &p_key, const Variant &p_value, bool *r_valid = NULL); /* SCRIPT */ - void set_script(const RefPtr& p_script); + void set_script(const RefPtr &p_script); RefPtr get_script() const; /* SCRIPT */ - bool has_meta(const String& p_name) const; - void set_meta(const String& p_name, const Variant& p_value ); - Variant get_meta(const String& p_name) const; + bool has_meta(const String &p_name) const; + void set_meta(const String &p_name, const Variant &p_value); + Variant get_meta(const String &p_name) const; void get_meta_list(List<String> *p_list) const; #ifdef TOOLS_ENABLED @@ -622,50 +630,47 @@ public: #endif void set_script_instance(ScriptInstance *p_instance); - _FORCE_INLINE_ ScriptInstance* get_script_instance() const { return script_instance; } - + _FORCE_INLINE_ ScriptInstance *get_script_instance() const { return script_instance; } - void add_user_signal(const MethodInfo& p_signal); - void emit_signal(const StringName& p_name,VARIANT_ARG_LIST); - void emit_signal(const StringName& p_name, const Variant** p_args, int p_argcount); - void get_signal_list(List<MethodInfo> *p_signals ) const; - void get_signal_connection_list(const StringName& p_signal,List<Connection> *p_connections) const; + void add_user_signal(const MethodInfo &p_signal); + void emit_signal(const StringName &p_name, VARIANT_ARG_LIST); + void emit_signal(const StringName &p_name, const Variant **p_args, int p_argcount); + void get_signal_list(List<MethodInfo> *p_signals) const; + void get_signal_connection_list(const StringName &p_signal, List<Connection> *p_connections) const; void get_all_signal_connections(List<Connection> *p_connections) const; bool has_persistent_signal_connections() const; void get_signals_connected_to_this(List<Connection> *p_connections) const; - Error connect(const StringName& p_signal, Object *p_to_object, const StringName& p_to_method,const Vector<Variant>& p_binds=Vector<Variant>(),uint32_t p_flags=0); - void disconnect(const StringName& p_signal, Object *p_to_object, const StringName& p_to_method); - bool is_connected(const StringName& p_signal, Object *p_to_object, const StringName& p_to_method) const; + Error connect(const StringName &p_signal, Object *p_to_object, const StringName &p_to_method, const Vector<Variant> &p_binds = Vector<Variant>(), uint32_t p_flags = 0); + void disconnect(const StringName &p_signal, Object *p_to_object, const StringName &p_to_method); + bool is_connected(const StringName &p_signal, Object *p_to_object, const StringName &p_to_method) const; - void call_deferred(const StringName& p_method,VARIANT_ARG_LIST); + void call_deferred(const StringName &p_method, VARIANT_ARG_LIST); void set_block_signals(bool p_block); bool is_blocking_signals() const; - Variant::Type get_static_property_type(const StringName& p_property,bool *r_valid=NULL) const; + Variant::Type get_static_property_type(const StringName &p_property, bool *r_valid = NULL) const; virtual void get_translatable_strings(List<String> *p_strings) const; - virtual void get_argument_options(const StringName& p_function,int p_idx,List<String>*r_options) const; + virtual void get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const; - StringName XL_MESSAGE(const StringName& p_message) const; //translate message (internationalization) - StringName tr(const StringName& p_message) const; //translate message (alternative) + StringName XL_MESSAGE(const StringName &p_message) const; //translate message (internationalization) + StringName tr(const StringName &p_message) const; //translate message (alternative) bool _is_queued_for_deletion; // set to true by SceneTree::queue_delete() bool is_queued_for_deletion() const; - _FORCE_INLINE_ void set_message_translation(bool p_enable) { _can_translate=p_enable; } + _FORCE_INLINE_ void set_message_translation(bool p_enable) { _can_translate = p_enable; } _FORCE_INLINE_ bool can_translate_messages() const { return _can_translate; } void clear_internal_resource_paths(); Object(); virtual ~Object(); - }; - bool predelete_handler(Object *p_object); void postinitialize_handler(Object *p_object); @@ -676,31 +681,29 @@ class ObjectDB { static _FORCE_INLINE_ uint32_t hash(const Object *p_obj) { union { - const Object*p; + const Object *p; unsigned long i; } u; - u.p=p_obj; + u.p = p_obj; return HashMapHasherDefault::hash((uint64_t)u.i); } }; - static HashMap<uint32_t,Object*> instances; - static HashMap<Object*,ObjectID,ObjectPtrHash> instance_checks; + static HashMap<uint32_t, Object *> instances; + static HashMap<Object *, ObjectID, ObjectPtrHash> instance_checks; static uint32_t instance_counter; -friend class Object; -friend void unregister_core_types(); - + friend class Object; + friend void unregister_core_types(); static RWLock *rw_lock; static void cleanup(); static uint32_t add_instance(Object *p_object); static void remove_instance(Object *p_object); -friend void register_core_types(); + friend void register_core_types(); static void setup(); public: - typedef void (*DebugFunc)(Object *p_obj); static Object *get_instance(uint32_t p_instance_ID); @@ -708,17 +711,14 @@ public: static int get_object_count(); #ifdef DEBUG_ENABLED - _FORCE_INLINE_ static bool instance_validate(Object* p_ptr) { + _FORCE_INLINE_ static bool instance_validate(Object *p_ptr) { return instance_checks.has(p_ptr); } #else - _FORCE_INLINE_ static bool instance_validate(Object* p_ptr) { return true; } + _FORCE_INLINE_ static bool instance_validate(Object *p_ptr) { return true; } #endif - - - }; //needed by macros |