From a75f5f039e31e20d985937f63cb2c8b90734160c Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Wed, 14 Sep 2016 19:37:37 -0300 Subject: Added API version and hashing to ObjectTypeDB --- core/object_type_db.cpp | 174 ++++++++++++++++++++++++++++++++++++++++++++++++ core/object_type_db.h | 15 ++++- 2 files changed, 188 insertions(+), 1 deletion(-) (limited to 'core') diff --git a/core/object_type_db.cpp b/core/object_type_db.cpp index aa641923e6..e121dc9e98 100644 --- a/core/object_type_db.cpp +++ b/core/object_type_db.cpp @@ -189,6 +189,14 @@ MethodDefinition _MD(const char* p_name,const char *p_arg1,const char *p_arg2,co #endif + +ObjectTypeDB::APIType ObjectTypeDB::current_api=API_CORE; + +void ObjectTypeDB::set_current_api(APIType p_api) { + + current_api=p_api; +} + HashMap ObjectTypeDB::types; HashMap ObjectTypeDB::resource_base_extensions; HashMap ObjectTypeDB::compat_types; @@ -258,6 +266,171 @@ StringName ObjectTypeDB::type_inherits_from(const StringName& p_type) { return ti->inherits; } +ObjectTypeDB::APIType ObjectTypeDB::get_api_type(const StringName &p_type) { + + OBJTYPE_LOCK; + + TypeInfo *ti = types.getptr(p_type); + ERR_FAIL_COND_V(!ti,API_NONE); + return ti->api; +} + +uint64_t ObjectTypeDB::get_api_hash(APIType p_api) { + +#ifdef DEBUG_METHODS_ENABLED + + uint64_t hash = hash_djb2_one_64(HashMapHahserDefault::hash(VERSION_FULL_NAME)); + + List names; + + const StringName *k=NULL; + + while((k=types.next(k))) { + + names.push_back(*k); + } + //must be alphabetically sorted for hash to compute + names.sort_custom(); + + for (List::Element *E=names.front();E;E=E->next()) { + + TypeInfo *t = types.getptr(E->get()); + ERR_FAIL_COND_V(!t,0); + if (t->api!=p_api) + continue; + hash = hash_djb2_one_64(t->name.hash(),hash); + hash = hash_djb2_one_64(t->inherits.hash(),hash); + + { //methods + + List snames; + + k=NULL; + + while((k=t->method_map.next(k))) { + + snames.push_back(*k); + } + + snames.sort_custom(); + + for (List::Element *F=snames.front();F;F=F->next()) { + + MethodBind *mb = t->method_map[F->get()]; + hash = hash_djb2_one_64( mb->get_name().hash(), hash); + hash = hash_djb2_one_64( mb->get_argument_count(), hash); + hash = hash_djb2_one_64( mb->get_argument_type(-1), hash); //return + + for(int i=0;iget_argument_count();i++) { + hash = hash_djb2_one_64( mb->get_argument_info(i).type, hash ); + hash = hash_djb2_one_64( mb->get_argument_info(i).name.hash(), hash ); + hash = hash_djb2_one_64( mb->get_argument_info(i).hint, hash ); + hash = hash_djb2_one_64( mb->get_argument_info(i).hint_string.hash(), hash ); + } + + hash = hash_djb2_one_64( mb->get_default_argument_count(), hash); + + for(int i=0;iget_default_argument_count();i++) { + //hash should not change, i hope for tis + Variant da = mb->get_default_argument(i); + hash = hash_djb2_one_64( da.hash(), hash ); + } + + hash = hash_djb2_one_64( mb->get_hint_flags(), hash); + + } + } + + + { //constants + + List snames; + + k=NULL; + + while((k=t->constant_map.next(k))) { + + snames.push_back(*k); + } + + snames.sort_custom(); + + for (List::Element *F=snames.front();F;F=F->next()) { + + hash = hash_djb2_one_64(F->get().hash(), hash); + hash = hash_djb2_one_64( t->constant_map[F->get()], hash); + } + } + + + { //signals + + List snames; + + k=NULL; + + while((k=t->signal_map.next(k))) { + + snames.push_back(*k); + } + + snames.sort_custom(); + + for (List::Element *F=snames.front();F;F=F->next()) { + + MethodInfo &mi = t->signal_map[F->get()]; + hash = hash_djb2_one_64( F->get().hash(), hash); + for(int i=0;i snames; + + k=NULL; + + while((k=t->property_setget.next(k))) { + + snames.push_back(*k); + } + + snames.sort_custom(); + + for (List::Element *F=snames.front();F;F=F->next()) { + + PropertySetGet *psg=t->property_setget.getptr(F->get()); + + hash = hash_djb2_one_64( F->get().hash(), hash); + hash = hash_djb2_one_64( psg->setter.hash(), hash); + hash = hash_djb2_one_64( psg->getter.hash(), hash); + + } + } + + //property list + for (List::Element *F=t->property_list.front();F;F=F->next()) { + + hash = hash_djb2_one_64( F->get().name.hash(), hash); + hash = hash_djb2_one_64( F->get().type, hash); + hash = hash_djb2_one_64( F->get().hint, hash); + hash = hash_djb2_one_64( F->get().hint_string.hash(), hash); + hash = hash_djb2_one_64( F->get().usage, hash); + } + + + } + + + return hash; +#else + return 0; +#endif + +} + bool ObjectTypeDB::type_exists(const StringName &p_type) { OBJTYPE_LOCK; @@ -309,6 +482,7 @@ void ObjectTypeDB::_add_type2(const StringName& p_type, const StringName& p_inhe TypeInfo &ti=types[name]; ti.name=name; ti.inherits=p_inherits; + ti.api=current_api; if (ti.inherits) { diff --git a/core/object_type_db.h b/core/object_type_db.h index 725b424c9a..9e9029ff2f 100644 --- a/core/object_type_db.h +++ b/core/object_type_db.h @@ -109,7 +109,13 @@ static _FORCE_INLINE_ const char* _MD(const char* m_name, ...) { return m_name; #endif class ObjectTypeDB { - +public: + enum APIType { + API_CORE, + API_EDITOR, + API_NONE + }; +public: struct PropertySetGet { int index; @@ -122,6 +128,7 @@ class ObjectTypeDB { struct TypeInfo { + APIType api; TypeInfo *inherits_ptr; HashMap method_map; HashMap constant_map; @@ -161,6 +168,7 @@ class ObjectTypeDB { #endif + static APIType current_api; static void _add_type2(const StringName& p_type, const StringName& p_inherits); public: @@ -236,6 +244,9 @@ public: static bool is_type(const StringName &p_type,const StringName& p_inherits); static bool can_instance(const StringName &p_type); static Object *instance(const StringName &p_type); + static APIType get_api_type(const StringName &p_type); + + static uint64_t get_api_hash(APIType p_api); #if 0 template @@ -499,6 +510,8 @@ public: static void add_compatibility_type(const StringName& p_type,const StringName& p_fallback); static void init(); + + static void set_current_api(APIType p_api); static void cleanup(); }; -- cgit v1.2.3