summaryrefslogtreecommitdiff
path: root/core/object.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/object.h')
-rw-r--r--core/object.h164
1 files changed, 87 insertions, 77 deletions
diff --git a/core/object.h b/core/object.h
index ac3fc51b3e..6ce579ea99 100644
--- a/core/object.h
+++ b/core/object.h
@@ -5,7 +5,7 @@
/* GODOT ENGINE */
/* http://www.godotengine.org */
/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2007-2017 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
@@ -34,6 +34,7 @@
#include "set.h"
#include "map.h"
#include "vmap.h"
+#include "os/rw_lock.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
@@ -57,7 +58,10 @@ enum PropertyHint {
PROPERTY_HINT_SPRITE_FRAME,
PROPERTY_HINT_KEY_ACCEL, ///< hint_text= "length" (as integer)
PROPERTY_HINT_FLAGS, ///< hint_text= "flag1,flag2,etc" (as bit flags)
- PROPERTY_HINT_ALL_FLAGS,
+ PROPERTY_HINT_LAYERS_2D_RENDER,
+ PROPERTY_HINT_LAYERS_2D_PHYSICS,
+ PROPERTY_HINT_LAYERS_3D_RENDER,
+ PROPERTY_HINT_LAYERS_3D_PHYSICS,
PROPERTY_HINT_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc,"
PROPERTY_HINT_DIR, ///< a directort path must be passed
PROPERTY_HINT_GLOBAL_FILE, ///< a file path must be passed, hint_text (optionally) is a filter "*.png,*.wav,*.doc,"
@@ -90,7 +94,7 @@ enum PropertyUsageFlags {
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_BUNDLE=128, //used for optimized bundles
+ 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
@@ -108,13 +112,14 @@ enum PropertyUsageFlags {
-#define ADD_SIGNAL( m_signal ) ObjectTypeDB::add_signal( get_type_static(), m_signal )
-#define ADD_PROPERTY( m_property, m_setter, m_getter ) ObjectTypeDB::add_property( get_type_static(), m_property, m_setter, m_getter )
-#define ADD_PROPERTYI( m_property, m_setter, m_getter, m_index ) ObjectTypeDB::add_property( get_type_static(), m_property, m_setter, m_getter, m_index )
-#define ADD_PROPERTYNZ( m_property, m_setter, m_getter ) ObjectTypeDB::add_property( get_type_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONZERO), m_setter, m_getter )
-#define ADD_PROPERTYINZ( m_property, m_setter, m_getter, m_index ) ObjectTypeDB::add_property( get_type_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONZERO), m_setter, m_getter, m_index )
-#define ADD_PROPERTYNO( m_property, m_setter, m_getter ) ObjectTypeDB::add_property( get_type_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONONE), m_setter, m_getter )
-#define ADD_PROPERTYINO( m_property, m_setter, m_getter, m_index ) ObjectTypeDB::add_property( get_type_static(), (m_property).added_usage(PROPERTY_USAGE_STORE_IF_NONONE), m_setter, m_getter, m_index )
+#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, m_setter, m_getter )
+#define ADD_PROPERTYI( m_property, m_setter, m_getter, m_index ) ClassDB::add_property( get_class_static(), m_property, m_setter, 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), m_setter, 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), m_setter, 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), m_setter, 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), m_setter, m_getter, m_index )
+#define ADD_GROUP( m_name, m_prefix ) ClassDB::add_property_group( get_class_static(), m_name, m_prefix )
struct PropertyInfo {
@@ -175,7 +180,7 @@ struct MethodInfo {
};
// old cast_to
-//if ( is_type(T::get_type_static()) )
+//if ( is_type(T::get_class_static()) )
//return static_cast<T*>(this);
////else
//return NULL;
@@ -196,33 +201,33 @@ private:
-#define OBJ_TYPE( m_type, m_inherits )\
+#define GDCLASS( m_class, m_inherits )\
private:\
- void operator=(const m_type& p_rval) {}\
- mutable StringName _type_name;\
- friend class ObjectTypeDB;\
+ void operator=(const m_class& p_rval) {}\
+ mutable StringName _class_name;\
+ friend class ClassDB;\
public:\
-virtual String get_type() const { \
- return String(#m_type);\
+virtual String get_class() const { \
+ return String(#m_class);\
}\
-virtual const StringName* _get_type_namev() const { \
- if (!_type_name)\
- _type_name=get_type_static();\
- return &_type_name;\
+virtual const StringName* _get_class_namev() const { \
+ if (!_class_name)\
+ _class_name=get_class_static();\
+ return &_class_name;\
}\
-static _FORCE_INLINE_ void* get_type_ptr_static() { \
+static _FORCE_INLINE_ void* get_class_ptr_static() { \
static int ptr;\
return &ptr;\
}\
-static _FORCE_INLINE_ String get_type_static() { \
- return String(#m_type);\
+static _FORCE_INLINE_ String get_class_static() { \
+ return String(#m_class);\
}\
-static _FORCE_INLINE_ String get_parent_type_static() { \
- return m_inherits::get_type_static();\
+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_type));\
+ p_inheritance_list->push_back(String(#m_class));\
}\
static String get_category_static() { \
String category = m_inherits::get_category_static();\
@@ -236,85 +241,85 @@ static String get_category_static() { \
static String inherits_static() {\
return String(#m_inherits);\
}\
-virtual bool is_type(const String& p_type) const { return (p_type==(#m_type))?true:m_inherits::is_type(p_type); }\
-virtual bool is_type_ptr(void *p_ptr) const { return (p_ptr==get_type_ptr_static())?true:m_inherits::is_type_ptr(p_ptr); }\
+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_type::_get_valid_parents_static!=m_inherits::_get_valid_parents_static) { \
- m_type::_get_valid_parents_static(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_type::_bind_methods;\
+ return &m_class::_bind_methods;\
}\
public:\
-static void initialize_type() {\
+static void initialize_class() {\
static bool initialized=false;\
if (initialized)\
return;\
- m_inherits::initialize_type();\
- ObjectTypeDB::_add_type<m_type>();\
- if (m_type::_get_bind_methods() != m_inherits::_get_bind_methods())\
+ 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_typev() {\
- initialize_type();\
+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_type::_get;\
+ return (bool (Object::*)(const StringName&,Variant&)const) &m_class::_get;\
}\
virtual bool _getv(const StringName& p_name, Variant& r_ret) const { \
- if (m_type::_get_get() != m_inherits::_get_get()) {\
+ 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_type::_set;\
+ 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_type::_get_set() != m_inherits::_get_set()) {\
+ 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_type::_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 { \
if (!p_reversed) {\
m_inherits::_get_property_listv(p_list,p_reversed);\
}\
- p_list->push_back( PropertyInfo(Variant::NIL,get_type_static(),PROPERTY_HINT_NONE,String(),PROPERTY_USAGE_CATEGORY));\
+ p_list->push_back( PropertyInfo(Variant::NIL,get_class_static(),PROPERTY_HINT_NONE,String(),PROPERTY_USAGE_CATEGORY));\
if (!_is_gpl_reversed())\
- ObjectTypeDB::get_property_list(#m_type,p_list,true,this);\
- if (m_type::_get_get_property_list() != m_inherits::_get_get_property_list()) {\
+ 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())\
- ObjectTypeDB::get_property_list(#m_type,p_list,true,this);\
+ 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_type::_notification;\
+ 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_type::_get_notification() != m_inherits::_get_notification()) {\
+ if (m_class::_get_notification() != m_inherits::_get_notification()) {\
_notification(p_notification);\
}\
if (p_reversed)\
@@ -329,9 +334,9 @@ protected:\
_FORCE_INLINE_ static String _get_category() { return m_category; }\
private:
-#define OBJ_SAVE_TYPE(m_type) \
+#define OBJ_SAVE_TYPE(m_class) \
public: \
-virtual String get_save_type() const { return #m_type; }\
+virtual String get_save_class() const { return #m_class; }\
private:
class ScriptInstance;
@@ -415,8 +420,8 @@ friend void postinitialize_handler(Object*);
ScriptInstance *script_instance;
RefPtr script;
Dictionary metadata;
- mutable StringName _type_name;
- mutable const StringName* _type_ptr;
+ mutable StringName _class_name;
+ 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;
@@ -430,8 +435,8 @@ friend void postinitialize_handler(Object*);
protected:
- virtual bool _use_builtin_script() const { return false; }
- virtual void _initialize_typev() { initialize_type(); }
+
+ 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 {};
@@ -474,23 +479,23 @@ protected:
Variant _call_deferred_bind(const Variant** p_args, int p_argcount, Variant::CallError& r_error);
- virtual const StringName* _get_type_namev() const {
- if (!_type_name)
- _type_name=get_type_static();
- return &_type_name;
+ virtual const StringName* _get_class_namev() const {
+ if (!_class_name)
+ _class_name=get_class_static();
+ return &_class_name;
}
- DVector<String> _get_meta_list_bind() const;
+ PoolVector<String> _get_meta_list_bind() const;
Array _get_property_list_bind() const;
Array _get_method_list_bind() const;
void _clear_internal_resource_paths(const Variant &p_var);
-friend class ObjectTypeDB;
+friend class ClassDB;
virtual void _validate_property(PropertyInfo& property) const;
public: //should be protected, but bug in clang++
- static void initialize_type();
+ static void initialize_class();
_FORCE_INLINE_ static void register_custom_data_to_otdb() {};
public:
@@ -500,7 +505,7 @@ public:
#else
_FORCE_INLINE_ void _change_notify(const char *p_what="") { }
#endif
- static void* get_type_ptr_static() {
+ static void* get_class_ptr_static() {
static int ptr;
return &ptr;
}
@@ -521,7 +526,7 @@ public:
#else
if (!this)
return NULL;
- if (is_type_ptr(T::get_type_ptr_static()))
+ if (is_class_ptr(T::get_class_ptr_static()))
return static_cast<T*>(this);
else
return NULL;
@@ -536,7 +541,7 @@ public:
#else
if (!this)
return NULL;
- if (is_type_ptr(T::get_type_ptr_static()))
+ if (is_class_ptr(T::get_class_ptr_static()))
return static_cast<const T*>(this);
else
return NULL;
@@ -552,30 +557,30 @@ public:
/* TYPE API */
static void get_inheritance_list_static(List<String>* p_inheritance_list) { p_inheritance_list->push_back("Object"); }
- static String get_type_static() { return "Object"; }
- static String get_parent_type_static() { return String(); }
+ 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_type() const { return "Object"; }
- virtual String get_save_type() const { return get_type(); } //type stored when saving
+ virtual String get_class() const { return "Object"; }
+ virtual String get_save_class() const { return get_class(); } //class stored when saving
- virtual bool is_type(const String& p_type) const { return (p_type=="Object"); }
- virtual bool is_type_ptr(void *p_ptr) const { return get_type_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_type_name() const {
- if (!_type_ptr) {
- return *_get_type_namev();
+ _FORCE_INLINE_ const StringName& get_class_name() const {
+ if (!_class_ptr) {
+ return *_get_class_namev();
} else {
- return *_type_ptr;
+ return *_class_ptr;
}
}
/* IAPI */
-// void set(const String& p_name, const Variant& p_value);
-// Variant get(const String& p_name) const;
+ //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;
@@ -685,9 +690,14 @@ class ObjectDB {
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();
+ static void setup();
+
public:
typedef void (*DebugFunc)(Object *p_obj);