class_db.cpp 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394
  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. api = API_NONE;
  219. creation_func = NULL;
  220. inherits_ptr = NULL;
  221. disabled = false;
  222. exposed = false;
  223. }
  224. ClassDB::ClassInfo::~ClassInfo() {
  225. }
  226. bool ClassDB::is_parent_class(const StringName &p_class, const StringName &p_inherits) {
  227. OBJTYPE_RLOCK;
  228. StringName inherits = p_class;
  229. while (inherits.operator String().length()) {
  230. if (inherits == p_inherits)
  231. return true;
  232. inherits = get_parent_class(inherits);
  233. }
  234. return false;
  235. }
  236. void ClassDB::get_class_list(List<StringName> *p_classes) {
  237. OBJTYPE_RLOCK;
  238. const StringName *k = NULL;
  239. while ((k = classes.next(k))) {
  240. p_classes->push_back(*k);
  241. }
  242. p_classes->sort();
  243. }
  244. void ClassDB::get_inheriters_from_class(const StringName &p_class, List<StringName> *p_classes) {
  245. OBJTYPE_RLOCK;
  246. const StringName *k = NULL;
  247. while ((k = classes.next(k))) {
  248. if (*k != p_class && is_parent_class(*k, p_class))
  249. p_classes->push_back(*k);
  250. }
  251. }
  252. StringName ClassDB::get_parent_class_nocheck(const StringName &p_class) {
  253. OBJTYPE_RLOCK;
  254. ClassInfo *ti = classes.getptr(p_class);
  255. if (!ti)
  256. return StringName();
  257. return ti->inherits;
  258. }
  259. StringName ClassDB::get_parent_class(const StringName &p_class) {
  260. OBJTYPE_RLOCK;
  261. ClassInfo *ti = classes.getptr(p_class);
  262. ERR_FAIL_COND_V(!ti, StringName());
  263. return ti->inherits;
  264. }
  265. ClassDB::APIType ClassDB::get_api_type(const StringName &p_class) {
  266. OBJTYPE_RLOCK;
  267. ClassInfo *ti = classes.getptr(p_class);
  268. ERR_FAIL_COND_V(!ti, API_NONE);
  269. return ti->api;
  270. }
  271. uint64_t ClassDB::get_api_hash(APIType p_api) {
  272. OBJTYPE_RLOCK;
  273. #ifdef DEBUG_METHODS_ENABLED
  274. uint64_t hash = hash_djb2_one_64(HashMapHasherDefault::hash(VERSION_FULL_CONFIG));
  275. List<StringName> names;
  276. const StringName *k = NULL;
  277. while ((k = classes.next(k))) {
  278. names.push_back(*k);
  279. }
  280. //must be alphabetically sorted for hash to compute
  281. names.sort_custom<StringName::AlphCompare>();
  282. for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
  283. ClassInfo *t = classes.getptr(E->get());
  284. ERR_FAIL_COND_V(!t, 0);
  285. if (t->api != p_api)
  286. continue;
  287. hash = hash_djb2_one_64(t->name.hash(), hash);
  288. hash = hash_djb2_one_64(t->inherits.hash(), hash);
  289. { //methods
  290. List<StringName> snames;
  291. k = NULL;
  292. while ((k = t->method_map.next(k))) {
  293. snames.push_back(*k);
  294. }
  295. snames.sort_custom<StringName::AlphCompare>();
  296. for (List<StringName>::Element *F = snames.front(); F; F = F->next()) {
  297. MethodBind *mb = t->method_map[F->get()];
  298. hash = hash_djb2_one_64(mb->get_name().hash(), hash);
  299. hash = hash_djb2_one_64(mb->get_argument_count(), hash);
  300. hash = hash_djb2_one_64(mb->get_argument_type(-1), hash); //return
  301. for (int i = 0; i < mb->get_argument_count(); i++) {
  302. const PropertyInfo info = mb->get_argument_info(i);
  303. hash = hash_djb2_one_64(info.type, hash);
  304. hash = hash_djb2_one_64(info.name.hash(), hash);
  305. hash = hash_djb2_one_64(info.hint, hash);
  306. hash = hash_djb2_one_64(info.hint_string.hash(), hash);
  307. }
  308. hash = hash_djb2_one_64(mb->get_default_argument_count(), hash);
  309. for (int i = 0; i < mb->get_default_argument_count(); i++) {
  310. //hash should not change, i hope for tis
  311. Variant da = mb->get_default_argument(i);
  312. hash = hash_djb2_one_64(da.hash(), hash);
  313. }
  314. hash = hash_djb2_one_64(mb->get_hint_flags(), hash);
  315. }
  316. }
  317. { //constants
  318. List<StringName> snames;
  319. k = NULL;
  320. while ((k = t->constant_map.next(k))) {
  321. snames.push_back(*k);
  322. }
  323. snames.sort_custom<StringName::AlphCompare>();
  324. for (List<StringName>::Element *F = snames.front(); F; F = F->next()) {
  325. hash = hash_djb2_one_64(F->get().hash(), hash);
  326. hash = hash_djb2_one_64(t->constant_map[F->get()], hash);
  327. }
  328. }
  329. { //signals
  330. List<StringName> snames;
  331. k = NULL;
  332. while ((k = t->signal_map.next(k))) {
  333. snames.push_back(*k);
  334. }
  335. snames.sort_custom<StringName::AlphCompare>();
  336. for (List<StringName>::Element *F = snames.front(); F; F = F->next()) {
  337. MethodInfo &mi = t->signal_map[F->get()];
  338. hash = hash_djb2_one_64(F->get().hash(), hash);
  339. for (int i = 0; i < mi.arguments.size(); i++) {
  340. hash = hash_djb2_one_64(mi.arguments[i].type, hash);
  341. }
  342. }
  343. }
  344. { //properties
  345. List<StringName> snames;
  346. k = NULL;
  347. while ((k = t->property_setget.next(k))) {
  348. snames.push_back(*k);
  349. }
  350. snames.sort_custom<StringName::AlphCompare>();
  351. for (List<StringName>::Element *F = snames.front(); F; F = F->next()) {
  352. PropertySetGet *psg = t->property_setget.getptr(F->get());
  353. hash = hash_djb2_one_64(F->get().hash(), hash);
  354. hash = hash_djb2_one_64(psg->setter.hash(), hash);
  355. hash = hash_djb2_one_64(psg->getter.hash(), hash);
  356. }
  357. }
  358. //property list
  359. for (List<PropertyInfo>::Element *F = t->property_list.front(); F; F = F->next()) {
  360. hash = hash_djb2_one_64(F->get().name.hash(), hash);
  361. hash = hash_djb2_one_64(F->get().type, hash);
  362. hash = hash_djb2_one_64(F->get().hint, hash);
  363. hash = hash_djb2_one_64(F->get().hint_string.hash(), hash);
  364. hash = hash_djb2_one_64(F->get().usage, hash);
  365. }
  366. }
  367. return hash;
  368. #else
  369. return 0;
  370. #endif
  371. }
  372. bool ClassDB::class_exists(const StringName &p_class) {
  373. OBJTYPE_RLOCK;
  374. return classes.has(p_class);
  375. }
  376. void ClassDB::add_compatibility_class(const StringName &p_class, const StringName &p_fallback) {
  377. OBJTYPE_WLOCK;
  378. compat_classes[p_class] = p_fallback;
  379. }
  380. Object *ClassDB::instance(const StringName &p_class) {
  381. ClassInfo *ti;
  382. {
  383. OBJTYPE_RLOCK;
  384. ti = classes.getptr(p_class);
  385. if (!ti || ti->disabled || !ti->creation_func) {
  386. if (compat_classes.has(p_class)) {
  387. ti = classes.getptr(compat_classes[p_class]);
  388. }
  389. }
  390. ERR_FAIL_COND_V(!ti, NULL);
  391. ERR_FAIL_COND_V(ti->disabled, NULL);
  392. ERR_FAIL_COND_V(!ti->creation_func, NULL);
  393. }
  394. return ti->creation_func();
  395. }
  396. bool ClassDB::can_instance(const StringName &p_class) {
  397. OBJTYPE_RLOCK;
  398. ClassInfo *ti = classes.getptr(p_class);
  399. ERR_FAIL_COND_V(!ti, false);
  400. return (!ti->disabled && ti->creation_func != NULL);
  401. }
  402. void ClassDB::_add_class2(const StringName &p_class, const StringName &p_inherits) {
  403. OBJTYPE_WLOCK;
  404. StringName name = p_class;
  405. ERR_FAIL_COND(classes.has(name));
  406. classes[name] = ClassInfo();
  407. ClassInfo &ti = classes[name];
  408. ti.name = name;
  409. ti.inherits = p_inherits;
  410. ti.api = current_api;
  411. if (ti.inherits) {
  412. ERR_FAIL_COND(!classes.has(ti.inherits)); //it MUST be registered.
  413. ti.inherits_ptr = &classes[ti.inherits];
  414. } else {
  415. ti.inherits_ptr = NULL;
  416. }
  417. }
  418. void ClassDB::get_method_list(StringName p_class, List<MethodInfo> *p_methods, bool p_no_inheritance, bool p_exclude_from_properties) {
  419. OBJTYPE_RLOCK;
  420. ClassInfo *type = classes.getptr(p_class);
  421. while (type) {
  422. if (type->disabled) {
  423. if (p_no_inheritance)
  424. break;
  425. type = type->inherits_ptr;
  426. continue;
  427. }
  428. #ifdef DEBUG_METHODS_ENABLED
  429. for (List<MethodInfo>::Element *E = type->virtual_methods.front(); E; E = E->next()) {
  430. p_methods->push_back(E->get());
  431. }
  432. for (List<StringName>::Element *E = type->method_order.front(); E; E = E->next()) {
  433. MethodBind *method = type->method_map.get(E->get());
  434. MethodInfo minfo;
  435. minfo.name = E->get();
  436. minfo.id = method->get_method_id();
  437. if (p_exclude_from_properties && type->methods_in_properties.has(minfo.name))
  438. continue;
  439. for (int i = 0; i < method->get_argument_count(); i++) {
  440. //Variant::Type t=method->get_argument_type(i);
  441. minfo.arguments.push_back(method->get_argument_info(i));
  442. }
  443. minfo.return_val = method->get_return_info();
  444. minfo.flags = method->get_hint_flags();
  445. for (int i = 0; i < method->get_argument_count(); i++) {
  446. if (method->has_default_argument(i))
  447. minfo.default_arguments.push_back(method->get_default_argument(i));
  448. }
  449. p_methods->push_back(minfo);
  450. }
  451. #else
  452. const StringName *K = NULL;
  453. while ((K = type->method_map.next(K))) {
  454. MethodBind *m = type->method_map[*K];
  455. MethodInfo mi;
  456. mi.name = m->get_name();
  457. p_methods->push_back(mi);
  458. }
  459. #endif
  460. if (p_no_inheritance)
  461. break;
  462. type = type->inherits_ptr;
  463. }
  464. }
  465. MethodBind *ClassDB::get_method(StringName p_class, StringName p_name) {
  466. OBJTYPE_RLOCK;
  467. ClassInfo *type = classes.getptr(p_class);
  468. while (type) {
  469. MethodBind **method = type->method_map.getptr(p_name);
  470. if (method && *method)
  471. return *method;
  472. type = type->inherits_ptr;
  473. }
  474. return NULL;
  475. }
  476. void ClassDB::bind_integer_constant(const StringName &p_class, const StringName &p_enum, const StringName &p_name, int p_constant) {
  477. OBJTYPE_WLOCK;
  478. ClassInfo *type = classes.getptr(p_class);
  479. if (!type) {
  480. ERR_FAIL_COND(!type);
  481. }
  482. if (type->constant_map.has(p_name)) {
  483. ERR_FAIL();
  484. }
  485. type->constant_map[p_name] = p_constant;
  486. String enum_name = p_enum;
  487. if (enum_name != String()) {
  488. if (enum_name.find(".") != -1) {
  489. enum_name = enum_name.get_slicec('.', 1);
  490. }
  491. List<StringName> *constants_list = type->enum_map.getptr(enum_name);
  492. if (constants_list) {
  493. constants_list->push_back(p_name);
  494. } else {
  495. List<StringName> new_list;
  496. new_list.push_back(p_name);
  497. type->enum_map[enum_name] = new_list;
  498. }
  499. }
  500. #ifdef DEBUG_METHODS_ENABLED
  501. type->constant_order.push_back(p_name);
  502. #endif
  503. }
  504. void ClassDB::get_integer_constant_list(const StringName &p_class, List<String> *p_constants, bool p_no_inheritance) {
  505. OBJTYPE_RLOCK;
  506. ClassInfo *type = classes.getptr(p_class);
  507. while (type) {
  508. #ifdef DEBUG_METHODS_ENABLED
  509. for (List<StringName>::Element *E = type->constant_order.front(); E; E = E->next())
  510. p_constants->push_back(E->get());
  511. #else
  512. const StringName *K = NULL;
  513. while ((K = type->constant_map.next(K))) {
  514. p_constants->push_back(*K);
  515. }
  516. #endif
  517. if (p_no_inheritance)
  518. break;
  519. type = type->inherits_ptr;
  520. }
  521. }
  522. int ClassDB::get_integer_constant(const StringName &p_class, const StringName &p_name, bool *p_success) {
  523. OBJTYPE_RLOCK;
  524. ClassInfo *type = classes.getptr(p_class);
  525. while (type) {
  526. int *constant = type->constant_map.getptr(p_name);
  527. if (constant) {
  528. if (p_success)
  529. *p_success = true;
  530. return *constant;
  531. }
  532. type = type->inherits_ptr;
  533. }
  534. if (p_success)
  535. *p_success = false;
  536. return 0;
  537. }
  538. StringName ClassDB::get_integer_constant_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance) {
  539. OBJTYPE_RLOCK;
  540. ClassInfo *type = classes.getptr(p_class);
  541. while (type) {
  542. const StringName *k = NULL;
  543. while ((k = type->enum_map.next(k))) {
  544. List<StringName> &constants_list = type->enum_map.get(*k);
  545. const List<StringName>::Element *found = constants_list.find(p_name);
  546. if (found)
  547. return *k;
  548. }
  549. if (p_no_inheritance)
  550. break;
  551. type = type->inherits_ptr;
  552. }
  553. return StringName();
  554. }
  555. void ClassDB::get_enum_list(const StringName &p_class, List<StringName> *p_enums, bool p_no_inheritance) {
  556. OBJTYPE_RLOCK;
  557. ClassInfo *type = classes.getptr(p_class);
  558. while (type) {
  559. const StringName *k = NULL;
  560. while ((k = type->enum_map.next(k))) {
  561. p_enums->push_back(*k);
  562. }
  563. if (p_no_inheritance)
  564. break;
  565. type = type->inherits_ptr;
  566. }
  567. }
  568. void ClassDB::get_enum_constants(const StringName &p_class, const StringName &p_enum, List<StringName> *p_constants, bool p_no_inheritance) {
  569. OBJTYPE_RLOCK;
  570. ClassInfo *type = classes.getptr(p_class);
  571. while (type) {
  572. const List<StringName> *constants = type->enum_map.getptr(p_enum);
  573. if (constants) {
  574. for (const List<StringName>::Element *E = constants->front(); E; E = E->next()) {
  575. p_constants->push_back(E->get());
  576. }
  577. }
  578. if (p_no_inheritance)
  579. break;
  580. type = type->inherits_ptr;
  581. }
  582. }
  583. void ClassDB::add_signal(StringName p_class, const MethodInfo &p_signal) {
  584. OBJTYPE_WLOCK;
  585. ClassInfo *type = classes.getptr(p_class);
  586. ERR_FAIL_COND(!type);
  587. ClassInfo *check = type;
  588. StringName sname = p_signal.name;
  589. #ifdef DEBUG_METHODS_ENABLED
  590. while (check) {
  591. if (check->signal_map.has(sname)) {
  592. ERR_EXPLAIN("Type " + String(p_class) + " already has signal: " + String(sname));
  593. ERR_FAIL();
  594. }
  595. check = check->inherits_ptr;
  596. }
  597. #endif
  598. type->signal_map[sname] = p_signal;
  599. }
  600. void ClassDB::get_signal_list(StringName p_class, List<MethodInfo> *p_signals, bool p_no_inheritance) {
  601. OBJTYPE_RLOCK;
  602. ClassInfo *type = classes.getptr(p_class);
  603. ERR_FAIL_COND(!type);
  604. ClassInfo *check = type;
  605. while (check) {
  606. const StringName *S = NULL;
  607. while ((S = check->signal_map.next(S))) {
  608. p_signals->push_back(check->signal_map[*S]);
  609. }
  610. if (p_no_inheritance)
  611. return;
  612. check = check->inherits_ptr;
  613. }
  614. }
  615. bool ClassDB::has_signal(StringName p_class, StringName p_signal) {
  616. OBJTYPE_RLOCK;
  617. ClassInfo *type = classes.getptr(p_class);
  618. ClassInfo *check = type;
  619. while (check) {
  620. if (check->signal_map.has(p_signal))
  621. return true;
  622. check = check->inherits_ptr;
  623. }
  624. return false;
  625. }
  626. bool ClassDB::get_signal(StringName p_class, StringName p_signal, MethodInfo *r_signal) {
  627. OBJTYPE_RLOCK;
  628. ClassInfo *type = classes.getptr(p_class);
  629. ClassInfo *check = type;
  630. while (check) {
  631. if (check->signal_map.has(p_signal)) {
  632. if (r_signal) {
  633. *r_signal = check->signal_map[p_signal];
  634. }
  635. return true;
  636. }
  637. check = check->inherits_ptr;
  638. }
  639. return false;
  640. }
  641. void ClassDB::add_property_group(StringName p_class, const String &p_name, const String &p_prefix) {
  642. OBJTYPE_WLOCK;
  643. ClassInfo *type = classes.getptr(p_class);
  644. ERR_FAIL_COND(!type);
  645. type->property_list.push_back(PropertyInfo(Variant::NIL, p_name, PROPERTY_HINT_NONE, p_prefix, PROPERTY_USAGE_GROUP));
  646. }
  647. void ClassDB::add_property(StringName p_class, const PropertyInfo &p_pinfo, const StringName &p_setter, const StringName &p_getter, int p_index) {
  648. lock->read_lock();
  649. ClassInfo *type = classes.getptr(p_class);
  650. lock->read_unlock();
  651. ERR_FAIL_COND(!type);
  652. MethodBind *mb_set = NULL;
  653. if (p_setter) {
  654. mb_set = get_method(p_class, p_setter);
  655. #ifdef DEBUG_METHODS_ENABLED
  656. if (!mb_set) {
  657. ERR_EXPLAIN("Invalid Setter: " + p_class + "::" + p_setter + " for property: " + p_pinfo.name);
  658. ERR_FAIL_COND(!mb_set);
  659. } else {
  660. int exp_args = 1 + (p_index >= 0 ? 1 : 0);
  661. if (mb_set->get_argument_count() != exp_args) {
  662. ERR_EXPLAIN("Invalid Function for Setter: " + p_class + "::" + p_setter + " for property: " + p_pinfo.name);
  663. ERR_FAIL();
  664. }
  665. }
  666. #endif
  667. }
  668. MethodBind *mb_get = NULL;
  669. if (p_getter) {
  670. mb_get = get_method(p_class, p_getter);
  671. #ifdef DEBUG_METHODS_ENABLED
  672. if (!mb_get) {
  673. ERR_EXPLAIN("Invalid Getter: " + p_class + "::" + p_getter + " for property: " + p_pinfo.name);
  674. ERR_FAIL_COND(!mb_get);
  675. } else {
  676. int exp_args = 0 + (p_index >= 0 ? 1 : 0);
  677. if (mb_get->get_argument_count() != exp_args) {
  678. ERR_EXPLAIN("Invalid Function for Getter: " + p_class + "::" + p_getter + " for property: " + p_pinfo.name);
  679. ERR_FAIL();
  680. }
  681. }
  682. #endif
  683. }
  684. #ifdef DEBUG_METHODS_ENABLED
  685. if (type->property_setget.has(p_pinfo.name)) {
  686. ERR_EXPLAIN("Object already has property: " + p_class);
  687. ERR_FAIL();
  688. }
  689. #endif
  690. OBJTYPE_WLOCK
  691. type->property_list.push_back(p_pinfo);
  692. #ifdef DEBUG_METHODS_ENABLED
  693. if (mb_get) {
  694. type->methods_in_properties.insert(p_getter);
  695. }
  696. if (mb_set) {
  697. type->methods_in_properties.insert(p_setter);
  698. }
  699. #endif
  700. PropertySetGet psg;
  701. psg.setter = p_setter;
  702. psg.getter = p_getter;
  703. psg._setptr = mb_set;
  704. psg._getptr = mb_get;
  705. psg.index = p_index;
  706. psg.type = p_pinfo.type;
  707. type->property_setget[p_pinfo.name] = psg;
  708. }
  709. void ClassDB::get_property_list(StringName p_class, List<PropertyInfo> *p_list, bool p_no_inheritance, const Object *p_validator) {
  710. OBJTYPE_RLOCK;
  711. ClassInfo *type = classes.getptr(p_class);
  712. ClassInfo *check = type;
  713. while (check) {
  714. for (List<PropertyInfo>::Element *E = check->property_list.front(); E; E = E->next()) {
  715. if (p_validator) {
  716. PropertyInfo pi = E->get();
  717. p_validator->_validate_property(pi);
  718. p_list->push_back(pi);
  719. } else {
  720. p_list->push_back(E->get());
  721. }
  722. }
  723. if (p_no_inheritance)
  724. return;
  725. check = check->inherits_ptr;
  726. }
  727. }
  728. bool ClassDB::set_property(Object *p_object, const StringName &p_property, const Variant &p_value, bool *r_valid) {
  729. ClassInfo *type = classes.getptr(p_object->get_class_name());
  730. ClassInfo *check = type;
  731. while (check) {
  732. const PropertySetGet *psg = check->property_setget.getptr(p_property);
  733. if (psg) {
  734. if (!psg->setter) {
  735. if (r_valid)
  736. *r_valid = false;
  737. return true; //return true but do nothing
  738. }
  739. Variant::CallError ce;
  740. if (psg->index >= 0) {
  741. Variant index = psg->index;
  742. const Variant *arg[2] = { &index, &p_value };
  743. //p_object->call(psg->setter,arg,2,ce);
  744. if (psg->_setptr) {
  745. psg->_setptr->call(p_object, arg, 2, ce);
  746. } else {
  747. p_object->call(psg->setter, arg, 2, ce);
  748. }
  749. } else {
  750. const Variant *arg[1] = { &p_value };
  751. if (psg->_setptr) {
  752. psg->_setptr->call(p_object, arg, 1, ce);
  753. } else {
  754. p_object->call(psg->setter, arg, 1, ce);
  755. }
  756. }
  757. if (r_valid)
  758. *r_valid = ce.error == Variant::CallError::CALL_OK;
  759. return true;
  760. }
  761. check = check->inherits_ptr;
  762. }
  763. return false;
  764. }
  765. bool ClassDB::get_property(Object *p_object, const StringName &p_property, Variant &r_value) {
  766. ClassInfo *type = classes.getptr(p_object->get_class_name());
  767. ClassInfo *check = type;
  768. while (check) {
  769. const PropertySetGet *psg = check->property_setget.getptr(p_property);
  770. if (psg) {
  771. if (!psg->getter)
  772. return true; //return true but do nothing
  773. if (psg->index >= 0) {
  774. Variant index = psg->index;
  775. const Variant *arg[1] = { &index };
  776. Variant::CallError ce;
  777. r_value = p_object->call(psg->getter, arg, 1, ce);
  778. } else {
  779. Variant::CallError ce;
  780. if (psg->_getptr) {
  781. r_value = psg->_getptr->call(p_object, NULL, 0, ce);
  782. } else {
  783. r_value = p_object->call(psg->getter, NULL, 0, ce);
  784. }
  785. }
  786. return true;
  787. }
  788. const int *c = check->constant_map.getptr(p_property);
  789. if (c) {
  790. r_value = *c;
  791. return true;
  792. }
  793. check = check->inherits_ptr;
  794. }
  795. return false;
  796. }
  797. int ClassDB::get_property_index(const StringName &p_class, const StringName &p_property, bool *r_is_valid) {
  798. ClassInfo *type = classes.getptr(p_class);
  799. ClassInfo *check = type;
  800. while (check) {
  801. const PropertySetGet *psg = check->property_setget.getptr(p_property);
  802. if (psg) {
  803. if (r_is_valid)
  804. *r_is_valid = true;
  805. return psg->index;
  806. }
  807. check = check->inherits_ptr;
  808. }
  809. if (r_is_valid)
  810. *r_is_valid = false;
  811. return -1;
  812. }
  813. Variant::Type ClassDB::get_property_type(const StringName &p_class, const StringName &p_property, bool *r_is_valid) {
  814. ClassInfo *type = classes.getptr(p_class);
  815. ClassInfo *check = type;
  816. while (check) {
  817. const PropertySetGet *psg = check->property_setget.getptr(p_property);
  818. if (psg) {
  819. if (r_is_valid)
  820. *r_is_valid = true;
  821. return psg->type;
  822. }
  823. check = check->inherits_ptr;
  824. }
  825. if (r_is_valid)
  826. *r_is_valid = false;
  827. return Variant::NIL;
  828. }
  829. StringName ClassDB::get_property_setter(StringName p_class, const StringName p_property) {
  830. ClassInfo *type = classes.getptr(p_class);
  831. ClassInfo *check = type;
  832. while (check) {
  833. const PropertySetGet *psg = check->property_setget.getptr(p_property);
  834. if (psg) {
  835. return psg->setter;
  836. }
  837. check = check->inherits_ptr;
  838. }
  839. return StringName();
  840. }
  841. StringName ClassDB::get_property_getter(StringName p_class, const StringName p_property) {
  842. ClassInfo *type = classes.getptr(p_class);
  843. ClassInfo *check = type;
  844. while (check) {
  845. const PropertySetGet *psg = check->property_setget.getptr(p_property);
  846. if (psg) {
  847. return psg->getter;
  848. }
  849. check = check->inherits_ptr;
  850. }
  851. return StringName();
  852. }
  853. bool ClassDB::has_property(const StringName &p_class, const StringName &p_property, bool p_no_inheritance) {
  854. ClassInfo *type = classes.getptr(p_class);
  855. ClassInfo *check = type;
  856. while (check) {
  857. if (check->property_setget.has(p_property))
  858. return true;
  859. if (p_no_inheritance)
  860. break;
  861. check = check->inherits_ptr;
  862. }
  863. return false;
  864. }
  865. void ClassDB::set_method_flags(StringName p_class, StringName p_method, int p_flags) {
  866. OBJTYPE_WLOCK;
  867. ClassInfo *type = classes.getptr(p_class);
  868. ClassInfo *check = type;
  869. ERR_FAIL_COND(!check);
  870. ERR_FAIL_COND(!check->method_map.has(p_method));
  871. check->method_map[p_method]->set_hint_flags(p_flags);
  872. }
  873. bool ClassDB::has_method(StringName p_class, StringName p_method, bool p_no_inheritance) {
  874. ClassInfo *type = classes.getptr(p_class);
  875. ClassInfo *check = type;
  876. while (check) {
  877. if (check->method_map.has(p_method))
  878. return true;
  879. if (p_no_inheritance)
  880. return false;
  881. check = check->inherits_ptr;
  882. }
  883. return false;
  884. }
  885. #ifdef DEBUG_METHODS_ENABLED
  886. MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const MethodDefinition &method_name, const Variant **p_defs, int p_defcount) {
  887. StringName mdname = method_name.name;
  888. #else
  889. MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const char *method_name, const Variant **p_defs, int p_defcount) {
  890. StringName mdname = StaticCString::create(method_name);
  891. #endif
  892. OBJTYPE_WLOCK;
  893. ERR_FAIL_COND_V(!p_bind, NULL);
  894. p_bind->set_name(mdname);
  895. String instance_type = p_bind->get_instance_class();
  896. #ifdef DEBUG_ENABLED
  897. if (has_method(instance_type, mdname)) {
  898. ERR_EXPLAIN("Class " + String(instance_type) + " already has a method " + String(mdname));
  899. ERR_FAIL_V(NULL);
  900. }
  901. #endif
  902. ClassInfo *type = classes.getptr(instance_type);
  903. if (!type) {
  904. ERR_PRINTS("Couldn't bind method '" + mdname + "' for instance: " + instance_type);
  905. memdelete(p_bind);
  906. ERR_FAIL_V(NULL);
  907. }
  908. if (type->method_map.has(mdname)) {
  909. memdelete(p_bind);
  910. // overloading not supported
  911. ERR_EXPLAIN("Method already bound: " + instance_type + "::" + mdname);
  912. ERR_FAIL_V(NULL);
  913. }
  914. #ifdef DEBUG_METHODS_ENABLED
  915. if (method_name.args.size() > p_bind->get_argument_count()) {
  916. memdelete(p_bind);
  917. ERR_EXPLAIN("Method definition provides more arguments than the method actually has: " + instance_type + "::" + mdname);
  918. ERR_FAIL_V(NULL);
  919. }
  920. p_bind->set_argument_names(method_name.args);
  921. type->method_order.push_back(mdname);
  922. #endif
  923. type->method_map[mdname] = p_bind;
  924. Vector<Variant> defvals;
  925. defvals.resize(p_defcount);
  926. for (int i = 0; i < p_defcount; i++) {
  927. defvals[i] = *p_defs[p_defcount - i - 1];
  928. }
  929. p_bind->set_default_arguments(defvals);
  930. p_bind->set_hint_flags(p_flags);
  931. return p_bind;
  932. }
  933. void ClassDB::add_virtual_method(const StringName &p_class, const MethodInfo &p_method, bool p_virtual) {
  934. ERR_FAIL_COND(!classes.has(p_class));
  935. OBJTYPE_WLOCK;
  936. #ifdef DEBUG_METHODS_ENABLED
  937. MethodInfo mi = p_method;
  938. if (p_virtual)
  939. mi.flags |= METHOD_FLAG_VIRTUAL;
  940. classes[p_class].virtual_methods.push_back(mi);
  941. #endif
  942. }
  943. void ClassDB::get_virtual_methods(const StringName &p_class, List<MethodInfo> *p_methods, bool p_no_inheritance) {
  944. ERR_FAIL_COND(!classes.has(p_class));
  945. #ifdef DEBUG_METHODS_ENABLED
  946. ClassInfo *type = classes.getptr(p_class);
  947. ClassInfo *check = type;
  948. while (check) {
  949. for (List<MethodInfo>::Element *E = check->virtual_methods.front(); E; E = E->next()) {
  950. p_methods->push_back(E->get());
  951. }
  952. if (p_no_inheritance)
  953. return;
  954. check = check->inherits_ptr;
  955. }
  956. #endif
  957. }
  958. void ClassDB::set_class_enabled(StringName p_class, bool p_enable) {
  959. OBJTYPE_WLOCK;
  960. ERR_FAIL_COND(!classes.has(p_class));
  961. classes[p_class].disabled = !p_enable;
  962. }
  963. bool ClassDB::is_class_enabled(StringName p_class) {
  964. OBJTYPE_RLOCK;
  965. ClassInfo *ti = classes.getptr(p_class);
  966. if (!ti || !ti->creation_func) {
  967. if (compat_classes.has(p_class)) {
  968. ti = classes.getptr(compat_classes[p_class]);
  969. }
  970. }
  971. ERR_FAIL_COND_V(!ti, false);
  972. return !ti->disabled;
  973. }
  974. bool ClassDB::is_class_exposed(StringName p_class) {
  975. OBJTYPE_RLOCK;
  976. ClassInfo *ti = classes.getptr(p_class);
  977. ERR_FAIL_COND_V(!ti, false);
  978. return ti->exposed;
  979. }
  980. StringName ClassDB::get_category(const StringName &p_node) {
  981. ERR_FAIL_COND_V(!classes.has(p_node), StringName());
  982. #ifdef DEBUG_ENABLED
  983. return classes[p_node].category;
  984. #else
  985. return StringName();
  986. #endif
  987. }
  988. void ClassDB::add_resource_base_extension(const StringName &p_extension, const StringName &p_class) {
  989. if (resource_base_extensions.has(p_extension))
  990. return;
  991. resource_base_extensions[p_extension] = p_class;
  992. }
  993. void ClassDB::get_resource_base_extensions(List<String> *p_extensions) {
  994. const StringName *K = NULL;
  995. while ((K = resource_base_extensions.next(K))) {
  996. p_extensions->push_back(*K);
  997. }
  998. }
  999. void ClassDB::get_extensions_for_type(const StringName &p_class, List<String> *p_extensions) {
  1000. const StringName *K = NULL;
  1001. while ((K = resource_base_extensions.next(K))) {
  1002. StringName cmp = resource_base_extensions[*K];
  1003. if (is_parent_class(p_class, cmp) || is_parent_class(cmp, p_class))
  1004. p_extensions->push_back(*K);
  1005. }
  1006. }
  1007. RWLock *ClassDB::lock = NULL;
  1008. void ClassDB::init() {
  1009. lock = RWLock::create();
  1010. }
  1011. void ClassDB::cleanup() {
  1012. //OBJTYPE_LOCK; hah not here
  1013. const StringName *k = NULL;
  1014. while ((k = classes.next(k))) {
  1015. ClassInfo &ti = classes[*k];
  1016. const StringName *m = NULL;
  1017. while ((m = ti.method_map.next(m))) {
  1018. memdelete(ti.method_map[*m]);
  1019. }
  1020. }
  1021. classes.clear();
  1022. resource_base_extensions.clear();
  1023. compat_classes.clear();
  1024. memdelete(lock);
  1025. }
  1026. //