class_db.cpp 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392
  1. /*************************************************************************/
  2. /* class_db.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "class_db.h"
  31. #include "os/mutex.h"
  32. #include "version.h"
  33. #define OBJTYPE_RLOCK RWLockRead _rw_lockr_(lock);
  34. #define OBJTYPE_WLOCK RWLockWrite _rw_lockw_(lock);
  35. #ifdef DEBUG_METHODS_ENABLED
  36. MethodDefinition D_METHOD(const char *p_name) {
  37. MethodDefinition md;
  38. md.name = StaticCString::create(p_name);
  39. return md;
  40. }
  41. MethodDefinition D_METHOD(const char *p_name, const char *p_arg1) {
  42. MethodDefinition md;
  43. md.name = StaticCString::create(p_name);
  44. md.args.push_back(StaticCString::create(p_arg1));
  45. return md;
  46. }
  47. MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2) {
  48. MethodDefinition md;
  49. md.name = StaticCString::create(p_name);
  50. md.args.resize(2);
  51. md.args[0] = StaticCString::create(p_arg1);
  52. md.args[1] = StaticCString::create(p_arg2);
  53. return md;
  54. }
  55. MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3) {
  56. MethodDefinition md;
  57. md.name = StaticCString::create(p_name);
  58. md.args.resize(3);
  59. md.args[0] = StaticCString::create(p_arg1);
  60. md.args[1] = StaticCString::create(p_arg2);
  61. md.args[2] = StaticCString::create(p_arg3);
  62. return md;
  63. }
  64. MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4) {
  65. MethodDefinition md;
  66. md.name = StaticCString::create(p_name);
  67. md.args.resize(4);
  68. md.args[0] = StaticCString::create(p_arg1);
  69. md.args[1] = StaticCString::create(p_arg2);
  70. md.args[2] = StaticCString::create(p_arg3);
  71. md.args[3] = StaticCString::create(p_arg4);
  72. return md;
  73. }
  74. MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5) {
  75. MethodDefinition md;
  76. md.name = StaticCString::create(p_name);
  77. md.args.resize(5);
  78. md.args[0] = StaticCString::create(p_arg1);
  79. md.args[1] = StaticCString::create(p_arg2);
  80. md.args[2] = StaticCString::create(p_arg3);
  81. md.args[3] = StaticCString::create(p_arg4);
  82. md.args[4] = StaticCString::create(p_arg5);
  83. return md;
  84. }
  85. MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6) {
  86. MethodDefinition md;
  87. md.name = StaticCString::create(p_name);
  88. md.args.resize(6);
  89. md.args[0] = StaticCString::create(p_arg1);
  90. md.args[1] = StaticCString::create(p_arg2);
  91. md.args[2] = StaticCString::create(p_arg3);
  92. md.args[3] = StaticCString::create(p_arg4);
  93. md.args[4] = StaticCString::create(p_arg5);
  94. md.args[5] = StaticCString::create(p_arg6);
  95. return md;
  96. }
  97. MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7) {
  98. MethodDefinition md;
  99. md.name = StaticCString::create(p_name);
  100. md.args.resize(7);
  101. md.args[0] = StaticCString::create(p_arg1);
  102. md.args[1] = StaticCString::create(p_arg2);
  103. md.args[2] = StaticCString::create(p_arg3);
  104. md.args[3] = StaticCString::create(p_arg4);
  105. md.args[4] = StaticCString::create(p_arg5);
  106. md.args[5] = StaticCString::create(p_arg6);
  107. md.args[6] = StaticCString::create(p_arg7);
  108. return md;
  109. }
  110. MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8) {
  111. MethodDefinition md;
  112. md.name = StaticCString::create(p_name);
  113. md.args.resize(8);
  114. md.args[0] = StaticCString::create(p_arg1);
  115. md.args[1] = StaticCString::create(p_arg2);
  116. md.args[2] = StaticCString::create(p_arg3);
  117. md.args[3] = StaticCString::create(p_arg4);
  118. md.args[4] = StaticCString::create(p_arg5);
  119. md.args[5] = StaticCString::create(p_arg6);
  120. md.args[6] = StaticCString::create(p_arg7);
  121. md.args[7] = StaticCString::create(p_arg8);
  122. return md;
  123. }
  124. MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9) {
  125. MethodDefinition md;
  126. md.name = StaticCString::create(p_name);
  127. md.args.resize(9);
  128. md.args[0] = StaticCString::create(p_arg1);
  129. md.args[1] = StaticCString::create(p_arg2);
  130. md.args[2] = StaticCString::create(p_arg3);
  131. md.args[3] = StaticCString::create(p_arg4);
  132. md.args[4] = StaticCString::create(p_arg5);
  133. md.args[5] = StaticCString::create(p_arg6);
  134. md.args[6] = StaticCString::create(p_arg7);
  135. md.args[7] = StaticCString::create(p_arg8);
  136. md.args[8] = StaticCString::create(p_arg9);
  137. return md;
  138. }
  139. MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10) {
  140. MethodDefinition md;
  141. md.name = StaticCString::create(p_name);
  142. md.args.resize(10);
  143. md.args[0] = StaticCString::create(p_arg1);
  144. md.args[1] = StaticCString::create(p_arg2);
  145. md.args[2] = StaticCString::create(p_arg3);
  146. md.args[3] = StaticCString::create(p_arg4);
  147. md.args[4] = StaticCString::create(p_arg5);
  148. md.args[5] = StaticCString::create(p_arg6);
  149. md.args[6] = StaticCString::create(p_arg7);
  150. md.args[7] = StaticCString::create(p_arg8);
  151. md.args[8] = StaticCString::create(p_arg9);
  152. md.args[9] = StaticCString::create(p_arg10);
  153. return md;
  154. }
  155. MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11) {
  156. MethodDefinition md;
  157. md.name = StaticCString::create(p_name);
  158. md.args.resize(11);
  159. md.args[0] = StaticCString::create(p_arg1);
  160. md.args[1] = StaticCString::create(p_arg2);
  161. md.args[2] = StaticCString::create(p_arg3);
  162. md.args[3] = StaticCString::create(p_arg4);
  163. md.args[4] = StaticCString::create(p_arg5);
  164. md.args[5] = StaticCString::create(p_arg6);
  165. md.args[6] = StaticCString::create(p_arg7);
  166. md.args[7] = StaticCString::create(p_arg8);
  167. md.args[8] = StaticCString::create(p_arg9);
  168. md.args[9] = StaticCString::create(p_arg10);
  169. md.args[10] = StaticCString::create(p_arg11);
  170. return md;
  171. }
  172. MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11, const char *p_arg12) {
  173. MethodDefinition md;
  174. md.name = StaticCString::create(p_name);
  175. md.args.resize(12);
  176. md.args[0] = StaticCString::create(p_arg1);
  177. md.args[1] = StaticCString::create(p_arg2);
  178. md.args[2] = StaticCString::create(p_arg3);
  179. md.args[3] = StaticCString::create(p_arg4);
  180. md.args[4] = StaticCString::create(p_arg5);
  181. md.args[5] = StaticCString::create(p_arg6);
  182. md.args[6] = StaticCString::create(p_arg7);
  183. md.args[7] = StaticCString::create(p_arg8);
  184. md.args[8] = StaticCString::create(p_arg9);
  185. md.args[9] = StaticCString::create(p_arg10);
  186. md.args[10] = StaticCString::create(p_arg11);
  187. md.args[11] = StaticCString::create(p_arg12);
  188. return md;
  189. }
  190. MethodDefinition D_METHOD(const char *p_name, const char *p_arg1, const char *p_arg2, const char *p_arg3, const char *p_arg4, const char *p_arg5, const char *p_arg6, const char *p_arg7, const char *p_arg8, const char *p_arg9, const char *p_arg10, const char *p_arg11, const char *p_arg12, const char *p_arg13) {
  191. MethodDefinition md;
  192. md.name = StaticCString::create(p_name);
  193. md.args.resize(13);
  194. md.args[0] = StaticCString::create(p_arg1);
  195. md.args[1] = StaticCString::create(p_arg2);
  196. md.args[2] = StaticCString::create(p_arg3);
  197. md.args[3] = StaticCString::create(p_arg4);
  198. md.args[4] = StaticCString::create(p_arg5);
  199. md.args[5] = StaticCString::create(p_arg6);
  200. md.args[6] = StaticCString::create(p_arg7);
  201. md.args[7] = StaticCString::create(p_arg8);
  202. md.args[8] = StaticCString::create(p_arg9);
  203. md.args[9] = StaticCString::create(p_arg10);
  204. md.args[10] = StaticCString::create(p_arg11);
  205. md.args[11] = StaticCString::create(p_arg12);
  206. md.args[12] = StaticCString::create(p_arg13);
  207. return md;
  208. }
  209. #endif
  210. ClassDB::APIType ClassDB::current_api = API_CORE;
  211. void ClassDB::set_current_api(APIType p_api) {
  212. current_api = p_api;
  213. }
  214. HashMap<StringName, ClassDB::ClassInfo, StringNameHasher> ClassDB::classes;
  215. HashMap<StringName, StringName, StringNameHasher> ClassDB::resource_base_extensions;
  216. HashMap<StringName, StringName, StringNameHasher> ClassDB::compat_classes;
  217. ClassDB::ClassInfo::ClassInfo() {
  218. creation_func = NULL;
  219. inherits_ptr = NULL;
  220. disabled = false;
  221. exposed = false;
  222. }
  223. ClassDB::ClassInfo::~ClassInfo() {
  224. }
  225. bool ClassDB::is_parent_class(const StringName &p_class, const StringName &p_inherits) {
  226. OBJTYPE_RLOCK;
  227. StringName inherits = p_class;
  228. while (inherits.operator String().length()) {
  229. if (inherits == p_inherits)
  230. return true;
  231. inherits = get_parent_class(inherits);
  232. }
  233. return false;
  234. }
  235. void ClassDB::get_class_list(List<StringName> *p_classes) {
  236. OBJTYPE_RLOCK;
  237. const StringName *k = NULL;
  238. while ((k = classes.next(k))) {
  239. p_classes->push_back(*k);
  240. }
  241. p_classes->sort();
  242. }
  243. void ClassDB::get_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes) {
  244. OBJTYPE_RLOCK;
  245. const StringName *k = NULL;
  246. while ((k = classes.next(k))) {
  247. if (*k != p_class && is_parent_class(*k, p_class))
  248. p_classes->push_back(*k);
  249. }
  250. }
  251. StringName ClassDB::get_parent_class_nocheck(const StringName &p_class) {
  252. OBJTYPE_RLOCK;
  253. ClassInfo *ti = classes.getptr(p_class);
  254. if (!ti)
  255. return StringName();
  256. return ti->inherits;
  257. }
  258. StringName ClassDB::get_parent_class(const StringName &p_class) {
  259. OBJTYPE_RLOCK;
  260. ClassInfo *ti = classes.getptr(p_class);
  261. ERR_FAIL_COND_V(!ti, StringName());
  262. return ti->inherits;
  263. }
  264. ClassDB::APIType ClassDB::get_api_type(const StringName &p_class) {
  265. OBJTYPE_RLOCK;
  266. ClassInfo *ti = classes.getptr(p_class);
  267. ERR_FAIL_COND_V(!ti, API_NONE);
  268. return ti->api;
  269. }
  270. uint64_t ClassDB::get_api_hash(APIType p_api) {
  271. OBJTYPE_RLOCK;
  272. #ifdef DEBUG_METHODS_ENABLED
  273. uint64_t hash = hash_djb2_one_64(HashMapHasherDefault::hash(VERSION_FULL_CONFIG));
  274. List<StringName> names;
  275. const StringName *k = NULL;
  276. while ((k = classes.next(k))) {
  277. names.push_back(*k);
  278. }
  279. //must be alphabetically sorted for hash to compute
  280. names.sort_custom<StringName::AlphCompare>();
  281. for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
  282. ClassInfo *t = classes.getptr(E->get());
  283. ERR_FAIL_COND_V(!t, 0);
  284. if (t->api != p_api)
  285. continue;
  286. hash = hash_djb2_one_64(t->name.hash(), hash);
  287. hash = hash_djb2_one_64(t->inherits.hash(), hash);
  288. { //methods
  289. List<StringName> snames;
  290. k = NULL;
  291. while ((k = t->method_map.next(k))) {
  292. snames.push_back(*k);
  293. }
  294. snames.sort_custom<StringName::AlphCompare>();
  295. for (List<StringName>::Element *F = snames.front(); F; F = F->next()) {
  296. MethodBind *mb = t->method_map[F->get()];
  297. hash = hash_djb2_one_64(mb->get_name().hash(), hash);
  298. hash = hash_djb2_one_64(mb->get_argument_count(), hash);
  299. hash = hash_djb2_one_64(mb->get_argument_type(-1), hash); //return
  300. for (int i = 0; i < mb->get_argument_count(); i++) {
  301. const PropertyInfo info = mb->get_argument_info(i);
  302. hash = hash_djb2_one_64(info.type, hash);
  303. hash = hash_djb2_one_64(info.name.hash(), hash);
  304. hash = hash_djb2_one_64(info.hint, hash);
  305. hash = hash_djb2_one_64(info.hint_string.hash(), hash);
  306. }
  307. hash = hash_djb2_one_64(mb->get_default_argument_count(), hash);
  308. for (int i = 0; i < mb->get_default_argument_count(); i++) {
  309. //hash should not change, i hope for tis
  310. Variant da = mb->get_default_argument(i);
  311. hash = hash_djb2_one_64(da.hash(), hash);
  312. }
  313. hash = hash_djb2_one_64(mb->get_hint_flags(), hash);
  314. }
  315. }
  316. { //constants
  317. List<StringName> snames;
  318. k = NULL;
  319. while ((k = t->constant_map.next(k))) {
  320. snames.push_back(*k);
  321. }
  322. snames.sort_custom<StringName::AlphCompare>();
  323. for (List<StringName>::Element *F = snames.front(); F; F = F->next()) {
  324. hash = hash_djb2_one_64(F->get().hash(), hash);
  325. hash = hash_djb2_one_64(t->constant_map[F->get()], hash);
  326. }
  327. }
  328. { //signals
  329. List<StringName> snames;
  330. k = NULL;
  331. while ((k = t->signal_map.next(k))) {
  332. snames.push_back(*k);
  333. }
  334. snames.sort_custom<StringName::AlphCompare>();
  335. for (List<StringName>::Element *F = snames.front(); F; F = F->next()) {
  336. MethodInfo &mi = t->signal_map[F->get()];
  337. hash = hash_djb2_one_64(F->get().hash(), hash);
  338. for (int i = 0; i < mi.arguments.size(); i++) {
  339. hash = hash_djb2_one_64(mi.arguments[i].type, hash);
  340. }
  341. }
  342. }
  343. { //properties
  344. List<StringName> snames;
  345. k = NULL;
  346. while ((k = t->property_setget.next(k))) {
  347. snames.push_back(*k);
  348. }
  349. snames.sort_custom<StringName::AlphCompare>();
  350. for (List<StringName>::Element *F = snames.front(); F; F = F->next()) {
  351. PropertySetGet *psg = t->property_setget.getptr(F->get());
  352. hash = hash_djb2_one_64(F->get().hash(), hash);
  353. hash = hash_djb2_one_64(psg->setter.hash(), hash);
  354. hash = hash_djb2_one_64(psg->getter.hash(), hash);
  355. }
  356. }
  357. //property list
  358. for (List<PropertyInfo>::Element *F = t->property_list.front(); F; F = F->next()) {
  359. hash = hash_djb2_one_64(F->get().name.hash(), hash);
  360. hash = hash_djb2_one_64(F->get().type, hash);
  361. hash = hash_djb2_one_64(F->get().hint, hash);
  362. hash = hash_djb2_one_64(F->get().hint_string.hash(), hash);
  363. hash = hash_djb2_one_64(F->get().usage, hash);
  364. }
  365. }
  366. return hash;
  367. #else
  368. return 0;
  369. #endif
  370. }
  371. bool ClassDB::class_exists(const StringName &p_class) {
  372. OBJTYPE_RLOCK;
  373. return classes.has(p_class);
  374. }
  375. void ClassDB::add_compatibility_class(const StringName &p_class, const StringName &p_fallback) {
  376. OBJTYPE_WLOCK;
  377. compat_classes[p_class] = p_fallback;
  378. }
  379. Object *ClassDB::instance(const StringName &p_class) {
  380. ClassInfo *ti;
  381. {
  382. OBJTYPE_RLOCK;
  383. ti = classes.getptr(p_class);
  384. if (!ti || ti->disabled || !ti->creation_func) {
  385. if (compat_classes.has(p_class)) {
  386. ti = classes.getptr(compat_classes[p_class]);
  387. }
  388. }
  389. ERR_FAIL_COND_V(!ti, NULL);
  390. ERR_FAIL_COND_V(ti->disabled, NULL);
  391. ERR_FAIL_COND_V(!ti->creation_func, NULL);
  392. }
  393. return ti->creation_func();
  394. }
  395. bool ClassDB::can_instance(const StringName &p_class) {
  396. OBJTYPE_RLOCK;
  397. ClassInfo *ti = classes.getptr(p_class);
  398. ERR_FAIL_COND_V(!ti, false);
  399. return (!ti->disabled && ti->creation_func != NULL);
  400. }
  401. void ClassDB::_add_class2(const StringName &p_class, const StringName &p_inherits) {
  402. OBJTYPE_WLOCK;
  403. StringName name = p_class;
  404. ERR_FAIL_COND(classes.has(name));
  405. classes[name] = ClassInfo();
  406. ClassInfo &ti = classes[name];
  407. ti.name = name;
  408. ti.inherits = p_inherits;
  409. ti.api = current_api;
  410. if (ti.inherits) {
  411. ERR_FAIL_COND(!classes.has(ti.inherits)); //it MUST be registered.
  412. ti.inherits_ptr = &classes[ti.inherits];
  413. } else {
  414. ti.inherits_ptr = NULL;
  415. }
  416. }
  417. void ClassDB::get_method_list(StringName p_class, List<MethodInfo> *p_methods, bool p_no_inheritance, bool p_exclude_from_properties) {
  418. OBJTYPE_RLOCK;
  419. ClassInfo *type = classes.getptr(p_class);
  420. while (type) {
  421. if (type->disabled) {
  422. if (p_no_inheritance)
  423. break;
  424. type = type->inherits_ptr;
  425. continue;
  426. }
  427. #ifdef DEBUG_METHODS_ENABLED
  428. for (List<MethodInfo>::Element *E = type->virtual_methods.front(); E; E = E->next()) {
  429. p_methods->push_back(E->get());
  430. }
  431. for (List<StringName>::Element *E = type->method_order.front(); E; E = E->next()) {
  432. MethodBind *method = type->method_map.get(E->get());
  433. MethodInfo minfo;
  434. minfo.name = E->get();
  435. minfo.id = method->get_method_id();
  436. if (p_exclude_from_properties && type->methods_in_properties.has(minfo.name))
  437. continue;
  438. for (int i = 0; i < method->get_argument_count(); i++) {
  439. //Variant::Type t=method->get_argument_type(i);
  440. minfo.arguments.push_back(method->get_argument_info(i));
  441. }
  442. minfo.return_val = method->get_return_info();
  443. minfo.flags = method->get_hint_flags();
  444. for (int i = 0; i < method->get_argument_count(); i++) {
  445. if (method->has_default_argument(i))
  446. minfo.default_arguments.push_back(method->get_default_argument(i));
  447. }
  448. p_methods->push_back(minfo);
  449. }
  450. #else
  451. const StringName *K = NULL;
  452. while ((K = type->method_map.next(K))) {
  453. MethodBind *m = type->method_map[*K];
  454. MethodInfo mi;
  455. mi.name = m->get_name();
  456. p_methods->push_back(mi);
  457. }
  458. #endif
  459. if (p_no_inheritance)
  460. break;
  461. type = type->inherits_ptr;
  462. }
  463. }
  464. MethodBind *ClassDB::get_method(StringName p_class, StringName p_name) {
  465. OBJTYPE_RLOCK;
  466. ClassInfo *type = classes.getptr(p_class);
  467. while (type) {
  468. MethodBind **method = type->method_map.getptr(p_name);
  469. if (method && *method)
  470. return *method;
  471. type = type->inherits_ptr;
  472. }
  473. return NULL;
  474. }
  475. void ClassDB::bind_integer_constant(const StringName &p_class, const StringName &p_enum, const StringName &p_name, int p_constant) {
  476. OBJTYPE_WLOCK;
  477. ClassInfo *type = classes.getptr(p_class);
  478. if (!type) {
  479. ERR_FAIL_COND(!type);
  480. }
  481. if (type->constant_map.has(p_name)) {
  482. ERR_FAIL();
  483. }
  484. type->constant_map[p_name] = p_constant;
  485. String enum_name = p_enum;
  486. if (enum_name != String()) {
  487. if (enum_name.find(".") != -1) {
  488. enum_name = enum_name.get_slicec('.', 1);
  489. }
  490. List<StringName> *constants_list = type->enum_map.getptr(enum_name);
  491. if (constants_list) {
  492. constants_list->push_back(p_name);
  493. } else {
  494. List<StringName> new_list;
  495. new_list.push_back(p_name);
  496. type->enum_map[enum_name] = new_list;
  497. }
  498. }
  499. #ifdef DEBUG_METHODS_ENABLED
  500. type->constant_order.push_back(p_name);
  501. #endif
  502. }
  503. void ClassDB::get_integer_constant_list(const StringName &p_class, List<String> *p_constants, bool p_no_inheritance) {
  504. OBJTYPE_RLOCK;
  505. ClassInfo *type = classes.getptr(p_class);
  506. while (type) {
  507. #ifdef DEBUG_METHODS_ENABLED
  508. for (List<StringName>::Element *E = type->constant_order.front(); E; E = E->next())
  509. p_constants->push_back(E->get());
  510. #else
  511. const StringName *K = NULL;
  512. while ((K = type->constant_map.next(K))) {
  513. p_constants->push_back(*K);
  514. }
  515. #endif
  516. if (p_no_inheritance)
  517. break;
  518. type = type->inherits_ptr;
  519. }
  520. }
  521. int ClassDB::get_integer_constant(const StringName &p_class, const StringName &p_name, bool *p_success) {
  522. OBJTYPE_RLOCK;
  523. ClassInfo *type = classes.getptr(p_class);
  524. while (type) {
  525. int *constant = type->constant_map.getptr(p_name);
  526. if (constant) {
  527. if (p_success)
  528. *p_success = true;
  529. return *constant;
  530. }
  531. type = type->inherits_ptr;
  532. }
  533. if (p_success)
  534. *p_success = false;
  535. return 0;
  536. }
  537. StringName ClassDB::get_integer_constant_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance) {
  538. OBJTYPE_RLOCK;
  539. ClassInfo *type = classes.getptr(p_class);
  540. while (type) {
  541. const StringName *k = NULL;
  542. while ((k = type->enum_map.next(k))) {
  543. List<StringName> &constants_list = type->enum_map.get(*k);
  544. const List<StringName>::Element *found = constants_list.find(p_name);
  545. if (found)
  546. return *k;
  547. }
  548. if (p_no_inheritance)
  549. break;
  550. type = type->inherits_ptr;
  551. }
  552. return StringName();
  553. }
  554. void ClassDB::get_enum_list(const StringName &p_class, List<StringName> *p_enums, bool p_no_inheritance) {
  555. OBJTYPE_RLOCK;
  556. ClassInfo *type = classes.getptr(p_class);
  557. while (type) {
  558. const StringName *k = NULL;
  559. while ((k = type->enum_map.next(k))) {
  560. p_enums->push_back(*k);
  561. }
  562. if (p_no_inheritance)
  563. break;
  564. type = type->inherits_ptr;
  565. }
  566. }
  567. void ClassDB::get_enum_constants(const StringName &p_class, const StringName &p_enum, List<StringName> *p_constants, bool p_no_inheritance) {
  568. OBJTYPE_RLOCK;
  569. ClassInfo *type = classes.getptr(p_class);
  570. while (type) {
  571. const List<StringName> *constants = type->enum_map.getptr(p_enum);
  572. if (constants) {
  573. for (const List<StringName>::Element *E = constants->front(); E; E = E->next()) {
  574. p_constants->push_back(E->get());
  575. }
  576. }
  577. if (p_no_inheritance)
  578. break;
  579. type = type->inherits_ptr;
  580. }
  581. }
  582. void ClassDB::add_signal(StringName p_class, const MethodInfo &p_signal) {
  583. OBJTYPE_WLOCK;
  584. ClassInfo *type = classes.getptr(p_class);
  585. ERR_FAIL_COND(!type);
  586. ClassInfo *check = type;
  587. StringName sname = p_signal.name;
  588. #ifdef DEBUG_METHODS_ENABLED
  589. while (check) {
  590. if (check->signal_map.has(sname)) {
  591. ERR_EXPLAIN("Type " + String(p_class) + " already has signal: " + String(sname));
  592. ERR_FAIL();
  593. }
  594. check = check->inherits_ptr;
  595. }
  596. #endif
  597. type->signal_map[sname] = p_signal;
  598. }
  599. void ClassDB::get_signal_list(StringName p_class, List<MethodInfo> *p_signals, bool p_no_inheritance) {
  600. OBJTYPE_RLOCK;
  601. ClassInfo *type = classes.getptr(p_class);
  602. ERR_FAIL_COND(!type);
  603. ClassInfo *check = type;
  604. while (check) {
  605. const StringName *S = NULL;
  606. while ((S = check->signal_map.next(S))) {
  607. p_signals->push_back(check->signal_map[*S]);
  608. }
  609. if (p_no_inheritance)
  610. return;
  611. check = check->inherits_ptr;
  612. }
  613. }
  614. bool ClassDB::has_signal(StringName p_class, StringName p_signal) {
  615. OBJTYPE_RLOCK;
  616. ClassInfo *type = classes.getptr(p_class);
  617. ClassInfo *check = type;
  618. while (check) {
  619. if (check->signal_map.has(p_signal))
  620. return true;
  621. check = check->inherits_ptr;
  622. }
  623. return false;
  624. }
  625. bool ClassDB::get_signal(StringName p_class, StringName p_signal, MethodInfo *r_signal) {
  626. OBJTYPE_RLOCK;
  627. ClassInfo *type = classes.getptr(p_class);
  628. ClassInfo *check = type;
  629. while (check) {
  630. if (check->signal_map.has(p_signal)) {
  631. if (r_signal) {
  632. *r_signal = check->signal_map[p_signal];
  633. }
  634. return true;
  635. }
  636. check = check->inherits_ptr;
  637. }
  638. return false;
  639. }
  640. void ClassDB::add_property_group(StringName p_class, const String &p_name, const String &p_prefix) {
  641. OBJTYPE_WLOCK;
  642. ClassInfo *type = classes.getptr(p_class);
  643. ERR_FAIL_COND(!type);
  644. type->property_list.push_back(PropertyInfo(Variant::NIL, p_name, PROPERTY_HINT_NONE, p_prefix, PROPERTY_USAGE_GROUP));
  645. }
  646. void ClassDB::add_property(StringName p_class, const PropertyInfo &p_pinfo, const StringName &p_setter, const StringName &p_getter, int p_index) {
  647. lock->read_lock();
  648. ClassInfo *type = classes.getptr(p_class);
  649. lock->read_unlock();
  650. ERR_FAIL_COND(!type);
  651. MethodBind *mb_set = NULL;
  652. if (p_setter) {
  653. mb_set = get_method(p_class, p_setter);
  654. #ifdef DEBUG_METHODS_ENABLED
  655. if (!mb_set) {
  656. ERR_EXPLAIN("Invalid Setter: " + p_class + "::" + p_setter + " for property: " + p_pinfo.name);
  657. ERR_FAIL_COND(!mb_set);
  658. } else {
  659. int exp_args = 1 + (p_index >= 0 ? 1 : 0);
  660. if (mb_set->get_argument_count() != exp_args) {
  661. ERR_EXPLAIN("Invalid Function for Setter: " + p_class + "::" + p_setter + " for property: " + p_pinfo.name);
  662. ERR_FAIL();
  663. }
  664. }
  665. #endif
  666. }
  667. MethodBind *mb_get = NULL;
  668. if (p_getter) {
  669. mb_get = get_method(p_class, p_getter);
  670. #ifdef DEBUG_METHODS_ENABLED
  671. if (!mb_get) {
  672. ERR_EXPLAIN("Invalid Getter: " + p_class + "::" + p_getter + " for property: " + p_pinfo.name);
  673. ERR_FAIL_COND(!mb_get);
  674. } else {
  675. int exp_args = 0 + (p_index >= 0 ? 1 : 0);
  676. if (mb_get->get_argument_count() != exp_args) {
  677. ERR_EXPLAIN("Invalid Function for Getter: " + p_class + "::" + p_getter + " for property: " + p_pinfo.name);
  678. ERR_FAIL();
  679. }
  680. }
  681. #endif
  682. }
  683. #ifdef DEBUG_METHODS_ENABLED
  684. if (type->property_setget.has(p_pinfo.name)) {
  685. ERR_EXPLAIN("Object already has property: " + p_class);
  686. ERR_FAIL();
  687. }
  688. #endif
  689. OBJTYPE_WLOCK
  690. type->property_list.push_back(p_pinfo);
  691. #ifdef DEBUG_METHODS_ENABLED
  692. if (mb_get) {
  693. type->methods_in_properties.insert(p_getter);
  694. }
  695. if (mb_set) {
  696. type->methods_in_properties.insert(p_setter);
  697. }
  698. #endif
  699. PropertySetGet psg;
  700. psg.setter = p_setter;
  701. psg.getter = p_getter;
  702. psg._setptr = mb_set;
  703. psg._getptr = mb_get;
  704. psg.index = p_index;
  705. psg.type = p_pinfo.type;
  706. type->property_setget[p_pinfo.name] = psg;
  707. }
  708. void ClassDB::get_property_list(StringName p_class, List<PropertyInfo> *p_list, bool p_no_inheritance, const Object *p_validator) {
  709. OBJTYPE_RLOCK;
  710. ClassInfo *type = classes.getptr(p_class);
  711. ClassInfo *check = type;
  712. while (check) {
  713. for (List<PropertyInfo>::Element *E = check->property_list.front(); E; E = E->next()) {
  714. if (p_validator) {
  715. PropertyInfo pi = E->get();
  716. p_validator->_validate_property(pi);
  717. p_list->push_back(pi);
  718. } else {
  719. p_list->push_back(E->get());
  720. }
  721. }
  722. if (p_no_inheritance)
  723. return;
  724. check = check->inherits_ptr;
  725. }
  726. }
  727. bool ClassDB::set_property(Object *p_object, const StringName &p_property, const Variant &p_value, bool *r_valid) {
  728. ClassInfo *type = classes.getptr(p_object->get_class_name());
  729. ClassInfo *check = type;
  730. while (check) {
  731. const PropertySetGet *psg = check->property_setget.getptr(p_property);
  732. if (psg) {
  733. if (!psg->setter) {
  734. if (r_valid)
  735. *r_valid = false;
  736. return true; //return true but do nothing
  737. }
  738. Variant::CallError ce;
  739. if (psg->index >= 0) {
  740. Variant index = psg->index;
  741. const Variant *arg[2] = { &index, &p_value };
  742. //p_object->call(psg->setter,arg,2,ce);
  743. if (psg->_setptr) {
  744. psg->_setptr->call(p_object, arg, 2, ce);
  745. } else {
  746. p_object->call(psg->setter, arg, 2, ce);
  747. }
  748. } else {
  749. const Variant *arg[1] = { &p_value };
  750. if (psg->_setptr) {
  751. psg->_setptr->call(p_object, arg, 1, ce);
  752. } else {
  753. p_object->call(psg->setter, arg, 1, ce);
  754. }
  755. }
  756. if (r_valid)
  757. *r_valid = ce.error == Variant::CallError::CALL_OK;
  758. return true;
  759. }
  760. check = check->inherits_ptr;
  761. }
  762. return false;
  763. }
  764. bool ClassDB::get_property(Object *p_object, const StringName &p_property, Variant &r_value) {
  765. ClassInfo *type = classes.getptr(p_object->get_class_name());
  766. ClassInfo *check = type;
  767. while (check) {
  768. const PropertySetGet *psg = check->property_setget.getptr(p_property);
  769. if (psg) {
  770. if (!psg->getter)
  771. return true; //return true but do nothing
  772. if (psg->index >= 0) {
  773. Variant index = psg->index;
  774. const Variant *arg[1] = { &index };
  775. Variant::CallError ce;
  776. r_value = p_object->call(psg->getter, arg, 1, ce);
  777. } else {
  778. Variant::CallError ce;
  779. if (psg->_getptr) {
  780. r_value = psg->_getptr->call(p_object, NULL, 0, ce);
  781. } else {
  782. r_value = p_object->call(psg->getter, NULL, 0, ce);
  783. }
  784. }
  785. return true;
  786. }
  787. const int *c = check->constant_map.getptr(p_property);
  788. if (c) {
  789. r_value = *c;
  790. return true;
  791. }
  792. check = check->inherits_ptr;
  793. }
  794. return false;
  795. }
  796. int ClassDB::get_property_index(const StringName &p_class, const StringName &p_property, bool *r_is_valid) {
  797. ClassInfo *type = classes.getptr(p_class);
  798. ClassInfo *check = type;
  799. while (check) {
  800. const PropertySetGet *psg = check->property_setget.getptr(p_property);
  801. if (psg) {
  802. if (r_is_valid)
  803. *r_is_valid = true;
  804. return psg->index;
  805. }
  806. check = check->inherits_ptr;
  807. }
  808. if (r_is_valid)
  809. *r_is_valid = false;
  810. return -1;
  811. }
  812. Variant::Type ClassDB::get_property_type(const StringName &p_class, const StringName &p_property, bool *r_is_valid) {
  813. ClassInfo *type = classes.getptr(p_class);
  814. ClassInfo *check = type;
  815. while (check) {
  816. const PropertySetGet *psg = check->property_setget.getptr(p_property);
  817. if (psg) {
  818. if (r_is_valid)
  819. *r_is_valid = true;
  820. return psg->type;
  821. }
  822. check = check->inherits_ptr;
  823. }
  824. if (r_is_valid)
  825. *r_is_valid = false;
  826. return Variant::NIL;
  827. }
  828. StringName ClassDB::get_property_setter(StringName p_class, const StringName p_property) {
  829. ClassInfo *type = classes.getptr(p_class);
  830. ClassInfo *check = type;
  831. while (check) {
  832. const PropertySetGet *psg = check->property_setget.getptr(p_property);
  833. if (psg) {
  834. return psg->setter;
  835. }
  836. check = check->inherits_ptr;
  837. }
  838. return StringName();
  839. }
  840. StringName ClassDB::get_property_getter(StringName p_class, const StringName p_property) {
  841. ClassInfo *type = classes.getptr(p_class);
  842. ClassInfo *check = type;
  843. while (check) {
  844. const PropertySetGet *psg = check->property_setget.getptr(p_property);
  845. if (psg) {
  846. return psg->getter;
  847. }
  848. check = check->inherits_ptr;
  849. }
  850. return StringName();
  851. }
  852. bool ClassDB::has_property(const StringName &p_class, const StringName &p_property, bool p_no_inheritance) {
  853. ClassInfo *type = classes.getptr(p_class);
  854. ClassInfo *check = type;
  855. while (check) {
  856. if (check->property_setget.has(p_property))
  857. return true;
  858. if (p_no_inheritance)
  859. break;
  860. check = check->inherits_ptr;
  861. }
  862. return false;
  863. }
  864. void ClassDB::set_method_flags(StringName p_class, StringName p_method, int p_flags) {
  865. OBJTYPE_WLOCK;
  866. ClassInfo *type = classes.getptr(p_class);
  867. ClassInfo *check = type;
  868. ERR_FAIL_COND(!check);
  869. ERR_FAIL_COND(!check->method_map.has(p_method));
  870. check->method_map[p_method]->set_hint_flags(p_flags);
  871. }
  872. bool ClassDB::has_method(StringName p_class, StringName p_method, bool p_no_inheritance) {
  873. ClassInfo *type = classes.getptr(p_class);
  874. ClassInfo *check = type;
  875. while (check) {
  876. if (check->method_map.has(p_method))
  877. return true;
  878. if (p_no_inheritance)
  879. return false;
  880. check = check->inherits_ptr;
  881. }
  882. return false;
  883. }
  884. #ifdef DEBUG_METHODS_ENABLED
  885. MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const MethodDefinition &method_name, const Variant **p_defs, int p_defcount) {
  886. StringName mdname = method_name.name;
  887. #else
  888. MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const char *method_name, const Variant **p_defs, int p_defcount) {
  889. StringName mdname = StaticCString::create(method_name);
  890. #endif
  891. OBJTYPE_WLOCK;
  892. ERR_FAIL_COND_V(!p_bind, NULL);
  893. p_bind->set_name(mdname);
  894. String instance_type = p_bind->get_instance_class();
  895. #ifdef DEBUG_ENABLED
  896. if (has_method(instance_type, mdname)) {
  897. ERR_EXPLAIN("Class " + String(instance_type) + " already has a method " + String(mdname));
  898. ERR_FAIL_V(NULL);
  899. }
  900. #endif
  901. ClassInfo *type = classes.getptr(instance_type);
  902. if (!type) {
  903. ERR_PRINTS("Couldn't bind method '" + mdname + "' for instance: " + instance_type);
  904. memdelete(p_bind);
  905. ERR_FAIL_V(NULL);
  906. }
  907. if (type->method_map.has(mdname)) {
  908. memdelete(p_bind);
  909. // overloading not supported
  910. ERR_EXPLAIN("Method already bound: " + instance_type + "::" + mdname);
  911. ERR_FAIL_V(NULL);
  912. }
  913. #ifdef DEBUG_METHODS_ENABLED
  914. if (method_name.args.size() > p_bind->get_argument_count()) {
  915. memdelete(p_bind);
  916. ERR_EXPLAIN("Method definition provides more arguments than the method actually has: " + instance_type + "::" + mdname);
  917. ERR_FAIL_V(NULL);
  918. }
  919. p_bind->set_argument_names(method_name.args);
  920. type->method_order.push_back(mdname);
  921. #endif
  922. type->method_map[mdname] = p_bind;
  923. Vector<Variant> defvals;
  924. defvals.resize(p_defcount);
  925. for (int i = 0; i < p_defcount; i++) {
  926. defvals[i] = *p_defs[p_defcount - i - 1];
  927. }
  928. p_bind->set_default_arguments(defvals);
  929. p_bind->set_hint_flags(p_flags);
  930. return p_bind;
  931. }
  932. void ClassDB::add_virtual_method(const StringName &p_class, const MethodInfo &p_method, bool p_virtual) {
  933. ERR_FAIL_COND(!classes.has(p_class));
  934. OBJTYPE_WLOCK;
  935. #ifdef DEBUG_METHODS_ENABLED
  936. MethodInfo mi = p_method;
  937. if (p_virtual)
  938. mi.flags |= METHOD_FLAG_VIRTUAL;
  939. classes[p_class].virtual_methods.push_back(mi);
  940. #endif
  941. }
  942. void ClassDB::get_virtual_methods(const StringName &p_class, List<MethodInfo> *p_methods, bool p_no_inheritance) {
  943. ERR_FAIL_COND(!classes.has(p_class));
  944. #ifdef DEBUG_METHODS_ENABLED
  945. ClassInfo *type = classes.getptr(p_class);
  946. ClassInfo *check = type;
  947. while (check) {
  948. for (List<MethodInfo>::Element *E = check->virtual_methods.front(); E; E = E->next()) {
  949. p_methods->push_back(E->get());
  950. }
  951. if (p_no_inheritance)
  952. return;
  953. check = check->inherits_ptr;
  954. }
  955. #endif
  956. }
  957. void ClassDB::set_class_enabled(StringName p_class, bool p_enable) {
  958. OBJTYPE_WLOCK;
  959. ERR_FAIL_COND(!classes.has(p_class));
  960. classes[p_class].disabled = !p_enable;
  961. }
  962. bool ClassDB::is_class_enabled(StringName p_class) {
  963. OBJTYPE_RLOCK;
  964. ClassInfo *ti = classes.getptr(p_class);
  965. if (!ti || !ti->creation_func) {
  966. if (compat_classes.has(p_class)) {
  967. ti = classes.getptr(compat_classes[p_class]);
  968. }
  969. }
  970. ERR_FAIL_COND_V(!ti, false);
  971. return !ti->disabled;
  972. }
  973. bool ClassDB::is_class_exposed(StringName p_class) {
  974. OBJTYPE_RLOCK;
  975. ClassInfo *ti = classes.getptr(p_class);
  976. ERR_FAIL_COND_V(!ti, false);
  977. return ti->exposed;
  978. }
  979. StringName ClassDB::get_category(const StringName &p_node) {
  980. ERR_FAIL_COND_V(!classes.has(p_node), StringName());
  981. #ifdef DEBUG_ENABLED
  982. return classes[p_node].category;
  983. #else
  984. return StringName();
  985. #endif
  986. }
  987. void ClassDB::add_resource_base_extension(const StringName &p_extension, const StringName &p_class) {
  988. if (resource_base_extensions.has(p_extension))
  989. return;
  990. resource_base_extensions[p_extension] = p_class;
  991. }
  992. void ClassDB::get_resource_base_extensions(List<String> *p_extensions) {
  993. const StringName *K = NULL;
  994. while ((K = resource_base_extensions.next(K))) {
  995. p_extensions->push_back(*K);
  996. }
  997. }
  998. void ClassDB::get_extensions_for_type(const StringName &p_class, List<String> *p_extensions) {
  999. const StringName *K = NULL;
  1000. while ((K = resource_base_extensions.next(K))) {
  1001. StringName cmp = resource_base_extensions[*K];
  1002. if (is_parent_class(p_class, cmp) || is_parent_class(cmp, p_class))
  1003. p_extensions->push_back(*K);
  1004. }
  1005. }
  1006. RWLock *ClassDB::lock = NULL;
  1007. void ClassDB::init() {
  1008. lock = RWLock::create();
  1009. }
  1010. void ClassDB::cleanup() {
  1011. //OBJTYPE_LOCK; hah not here
  1012. const StringName *k = NULL;
  1013. while ((k = classes.next(k))) {
  1014. ClassInfo &ti = classes[*k];
  1015. const StringName *m = NULL;
  1016. while ((m = ti.method_map.next(m))) {
  1017. memdelete(ti.method_map[*m]);
  1018. }
  1019. }
  1020. classes.clear();
  1021. resource_base_extensions.clear();
  1022. compat_classes.clear();
  1023. memdelete(lock);
  1024. }
  1025. //