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. 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. #ifdef DEBUG_METHODS_ENABLED
  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. 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. #ifdef DEBUG_METHODS_ENABLED
  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. #endif
  584. void ClassDB::add_signal(StringName p_class, const MethodInfo &p_signal) {
  585. OBJTYPE_WLOCK;
  586. ClassInfo *type = classes.getptr(p_class);
  587. ERR_FAIL_COND(!type);
  588. ClassInfo *check = type;
  589. StringName sname = p_signal.name;
  590. #ifdef DEBUG_METHODS_ENABLED
  591. while (check) {
  592. if (check->signal_map.has(sname)) {
  593. ERR_EXPLAIN("Type " + String(p_class) + " already has signal: " + String(sname));
  594. ERR_FAIL();
  595. }
  596. check = check->inherits_ptr;
  597. }
  598. #endif
  599. type->signal_map[sname] = p_signal;
  600. }
  601. void ClassDB::get_signal_list(StringName p_class, List<MethodInfo> *p_signals, bool p_no_inheritance) {
  602. OBJTYPE_RLOCK;
  603. ClassInfo *type = classes.getptr(p_class);
  604. ERR_FAIL_COND(!type);
  605. ClassInfo *check = type;
  606. while (check) {
  607. const StringName *S = NULL;
  608. while ((S = check->signal_map.next(S))) {
  609. p_signals->push_back(check->signal_map[*S]);
  610. }
  611. if (p_no_inheritance)
  612. return;
  613. check = check->inherits_ptr;
  614. }
  615. }
  616. bool ClassDB::has_signal(StringName p_class, StringName p_signal) {
  617. OBJTYPE_RLOCK;
  618. ClassInfo *type = classes.getptr(p_class);
  619. ClassInfo *check = type;
  620. while (check) {
  621. if (check->signal_map.has(p_signal))
  622. return true;
  623. check = check->inherits_ptr;
  624. }
  625. return false;
  626. }
  627. bool ClassDB::get_signal(StringName p_class, StringName p_signal, MethodInfo *r_signal) {
  628. OBJTYPE_RLOCK;
  629. ClassInfo *type = classes.getptr(p_class);
  630. ClassInfo *check = type;
  631. while (check) {
  632. if (check->signal_map.has(p_signal)) {
  633. if (r_signal) {
  634. *r_signal = check->signal_map[p_signal];
  635. }
  636. return true;
  637. }
  638. check = check->inherits_ptr;
  639. }
  640. return false;
  641. }
  642. void ClassDB::add_property_group(StringName p_class, const String &p_name, const String &p_prefix) {
  643. OBJTYPE_WLOCK;
  644. ClassInfo *type = classes.getptr(p_class);
  645. ERR_FAIL_COND(!type);
  646. type->property_list.push_back(PropertyInfo(Variant::NIL, p_name, PROPERTY_HINT_NONE, p_prefix, PROPERTY_USAGE_GROUP));
  647. }
  648. void ClassDB::add_property(StringName p_class, const PropertyInfo &p_pinfo, const StringName &p_setter, const StringName &p_getter, int p_index) {
  649. lock->read_lock();
  650. ClassInfo *type = classes.getptr(p_class);
  651. lock->read_unlock();
  652. ERR_FAIL_COND(!type);
  653. MethodBind *mb_set = NULL;
  654. if (p_setter) {
  655. mb_set = get_method(p_class, p_setter);
  656. #ifdef DEBUG_METHODS_ENABLED
  657. if (!mb_set) {
  658. ERR_EXPLAIN("Invalid Setter: " + p_class + "::" + p_setter + " for property: " + p_pinfo.name);
  659. ERR_FAIL_COND(!mb_set);
  660. } else {
  661. int exp_args = 1 + (p_index >= 0 ? 1 : 0);
  662. if (mb_set->get_argument_count() != exp_args) {
  663. ERR_EXPLAIN("Invalid Function for Setter: " + p_class + "::" + p_setter + " for property: " + p_pinfo.name);
  664. ERR_FAIL();
  665. }
  666. }
  667. #endif
  668. }
  669. MethodBind *mb_get = NULL;
  670. if (p_getter) {
  671. mb_get = get_method(p_class, p_getter);
  672. #ifdef DEBUG_METHODS_ENABLED
  673. if (!mb_get) {
  674. ERR_EXPLAIN("Invalid Getter: " + p_class + "::" + p_getter + " for property: " + p_pinfo.name);
  675. ERR_FAIL_COND(!mb_get);
  676. } else {
  677. int exp_args = 0 + (p_index >= 0 ? 1 : 0);
  678. if (mb_get->get_argument_count() != exp_args) {
  679. ERR_EXPLAIN("Invalid Function for Getter: " + p_class + "::" + p_getter + " for property: " + p_pinfo.name);
  680. ERR_FAIL();
  681. }
  682. }
  683. #endif
  684. }
  685. #ifdef DEBUG_METHODS_ENABLED
  686. if (type->property_setget.has(p_pinfo.name)) {
  687. ERR_EXPLAIN("Object already has property: " + p_class);
  688. ERR_FAIL();
  689. }
  690. #endif
  691. OBJTYPE_WLOCK
  692. type->property_list.push_back(p_pinfo);
  693. #ifdef DEBUG_METHODS_ENABLED
  694. if (mb_get) {
  695. type->methods_in_properties.insert(p_getter);
  696. }
  697. if (mb_set) {
  698. type->methods_in_properties.insert(p_setter);
  699. }
  700. #endif
  701. PropertySetGet psg;
  702. psg.setter = p_setter;
  703. psg.getter = p_getter;
  704. psg._setptr = mb_set;
  705. psg._getptr = mb_get;
  706. psg.index = p_index;
  707. psg.type = p_pinfo.type;
  708. type->property_setget[p_pinfo.name] = psg;
  709. }
  710. void ClassDB::get_property_list(StringName p_class, List<PropertyInfo> *p_list, bool p_no_inheritance, const Object *p_validator) {
  711. OBJTYPE_RLOCK;
  712. ClassInfo *type = classes.getptr(p_class);
  713. ClassInfo *check = type;
  714. while (check) {
  715. for (List<PropertyInfo>::Element *E = check->property_list.front(); E; E = E->next()) {
  716. if (p_validator) {
  717. PropertyInfo pi = E->get();
  718. p_validator->_validate_property(pi);
  719. p_list->push_back(pi);
  720. } else {
  721. p_list->push_back(E->get());
  722. }
  723. }
  724. if (p_no_inheritance)
  725. return;
  726. check = check->inherits_ptr;
  727. }
  728. }
  729. bool ClassDB::set_property(Object *p_object, const StringName &p_property, const Variant &p_value, bool *r_valid) {
  730. ClassInfo *type = classes.getptr(p_object->get_class_name());
  731. ClassInfo *check = type;
  732. while (check) {
  733. const PropertySetGet *psg = check->property_setget.getptr(p_property);
  734. if (psg) {
  735. if (!psg->setter) {
  736. if (r_valid)
  737. *r_valid = false;
  738. return true; //return true but do nothing
  739. }
  740. Variant::CallError ce;
  741. if (psg->index >= 0) {
  742. Variant index = psg->index;
  743. const Variant *arg[2] = { &index, &p_value };
  744. //p_object->call(psg->setter,arg,2,ce);
  745. if (psg->_setptr) {
  746. psg->_setptr->call(p_object, arg, 2, ce);
  747. } else {
  748. p_object->call(psg->setter, arg, 2, ce);
  749. }
  750. } else {
  751. const Variant *arg[1] = { &p_value };
  752. if (psg->_setptr) {
  753. psg->_setptr->call(p_object, arg, 1, ce);
  754. } else {
  755. p_object->call(psg->setter, arg, 1, ce);
  756. }
  757. }
  758. if (r_valid)
  759. *r_valid = ce.error == Variant::CallError::CALL_OK;
  760. return true;
  761. }
  762. check = check->inherits_ptr;
  763. }
  764. return false;
  765. }
  766. bool ClassDB::get_property(Object *p_object, const StringName &p_property, Variant &r_value) {
  767. ClassInfo *type = classes.getptr(p_object->get_class_name());
  768. ClassInfo *check = type;
  769. while (check) {
  770. const PropertySetGet *psg = check->property_setget.getptr(p_property);
  771. if (psg) {
  772. if (!psg->getter)
  773. return true; //return true but do nothing
  774. if (psg->index >= 0) {
  775. Variant index = psg->index;
  776. const Variant *arg[1] = { &index };
  777. Variant::CallError ce;
  778. r_value = p_object->call(psg->getter, arg, 1, ce);
  779. } else {
  780. Variant::CallError ce;
  781. if (psg->_getptr) {
  782. r_value = psg->_getptr->call(p_object, NULL, 0, ce);
  783. } else {
  784. r_value = p_object->call(psg->getter, NULL, 0, ce);
  785. }
  786. }
  787. return true;
  788. }
  789. const int *c = check->constant_map.getptr(p_property);
  790. if (c) {
  791. r_value = *c;
  792. return true;
  793. }
  794. check = check->inherits_ptr;
  795. }
  796. return false;
  797. }
  798. int ClassDB::get_property_index(const StringName &p_class, const StringName &p_property, bool *r_is_valid) {
  799. ClassInfo *type = classes.getptr(p_class);
  800. ClassInfo *check = type;
  801. while (check) {
  802. const PropertySetGet *psg = check->property_setget.getptr(p_property);
  803. if (psg) {
  804. if (r_is_valid)
  805. *r_is_valid = true;
  806. return psg->index;
  807. }
  808. check = check->inherits_ptr;
  809. }
  810. if (r_is_valid)
  811. *r_is_valid = false;
  812. return -1;
  813. }
  814. Variant::Type ClassDB::get_property_type(const StringName &p_class, const StringName &p_property, bool *r_is_valid) {
  815. ClassInfo *type = classes.getptr(p_class);
  816. ClassInfo *check = type;
  817. while (check) {
  818. const PropertySetGet *psg = check->property_setget.getptr(p_property);
  819. if (psg) {
  820. if (r_is_valid)
  821. *r_is_valid = true;
  822. return psg->type;
  823. }
  824. check = check->inherits_ptr;
  825. }
  826. if (r_is_valid)
  827. *r_is_valid = false;
  828. return Variant::NIL;
  829. }
  830. StringName ClassDB::get_property_setter(StringName p_class, const StringName p_property) {
  831. ClassInfo *type = classes.getptr(p_class);
  832. ClassInfo *check = type;
  833. while (check) {
  834. const PropertySetGet *psg = check->property_setget.getptr(p_property);
  835. if (psg) {
  836. return psg->setter;
  837. }
  838. check = check->inherits_ptr;
  839. }
  840. return StringName();
  841. }
  842. StringName ClassDB::get_property_getter(StringName p_class, const StringName p_property) {
  843. ClassInfo *type = classes.getptr(p_class);
  844. ClassInfo *check = type;
  845. while (check) {
  846. const PropertySetGet *psg = check->property_setget.getptr(p_property);
  847. if (psg) {
  848. return psg->getter;
  849. }
  850. check = check->inherits_ptr;
  851. }
  852. return StringName();
  853. }
  854. bool ClassDB::has_property(const StringName &p_class, const StringName &p_property, bool p_no_inheritance) {
  855. ClassInfo *type = classes.getptr(p_class);
  856. ClassInfo *check = type;
  857. while (check) {
  858. if (check->property_setget.has(p_property))
  859. return true;
  860. if (p_no_inheritance)
  861. break;
  862. check = check->inherits_ptr;
  863. }
  864. return false;
  865. }
  866. void ClassDB::set_method_flags(StringName p_class, StringName p_method, int p_flags) {
  867. OBJTYPE_WLOCK;
  868. ClassInfo *type = classes.getptr(p_class);
  869. ClassInfo *check = type;
  870. ERR_FAIL_COND(!check);
  871. ERR_FAIL_COND(!check->method_map.has(p_method));
  872. check->method_map[p_method]->set_hint_flags(p_flags);
  873. }
  874. bool ClassDB::has_method(StringName p_class, StringName p_method, bool p_no_inheritance) {
  875. ClassInfo *type = classes.getptr(p_class);
  876. ClassInfo *check = type;
  877. while (check) {
  878. if (check->method_map.has(p_method))
  879. return true;
  880. if (p_no_inheritance)
  881. return false;
  882. check = check->inherits_ptr;
  883. }
  884. return false;
  885. }
  886. #ifdef DEBUG_METHODS_ENABLED
  887. MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const MethodDefinition &method_name, const Variant **p_defs, int p_defcount) {
  888. StringName mdname = method_name.name;
  889. #else
  890. MethodBind *ClassDB::bind_methodfi(uint32_t p_flags, MethodBind *p_bind, const char *method_name, const Variant **p_defs, int p_defcount) {
  891. StringName mdname = StaticCString::create(method_name);
  892. #endif
  893. OBJTYPE_WLOCK;
  894. ERR_FAIL_COND_V(!p_bind, NULL);
  895. p_bind->set_name(mdname);
  896. String instance_type = p_bind->get_instance_class();
  897. #ifdef DEBUG_ENABLED
  898. if (has_method(instance_type, mdname)) {
  899. ERR_EXPLAIN("Class " + String(instance_type) + " already has a method " + String(mdname));
  900. ERR_FAIL_V(NULL);
  901. }
  902. #endif
  903. ClassInfo *type = classes.getptr(instance_type);
  904. if (!type) {
  905. ERR_PRINTS("Couldn't bind method '" + mdname + "' for instance: " + instance_type);
  906. memdelete(p_bind);
  907. ERR_FAIL_V(NULL);
  908. }
  909. if (type->method_map.has(mdname)) {
  910. memdelete(p_bind);
  911. // overloading not supported
  912. ERR_EXPLAIN("Method already bound: " + instance_type + "::" + mdname);
  913. ERR_FAIL_V(NULL);
  914. }
  915. #ifdef DEBUG_METHODS_ENABLED
  916. if (method_name.args.size() > p_bind->get_argument_count()) {
  917. memdelete(p_bind);
  918. ERR_EXPLAIN("Method definition provides more arguments than the method actually has: " + instance_type + "::" + mdname);
  919. ERR_FAIL_V(NULL);
  920. }
  921. p_bind->set_argument_names(method_name.args);
  922. type->method_order.push_back(mdname);
  923. #endif
  924. type->method_map[mdname] = p_bind;
  925. Vector<Variant> defvals;
  926. defvals.resize(p_defcount);
  927. for (int i = 0; i < p_defcount; i++) {
  928. defvals[i] = *p_defs[p_defcount - i - 1];
  929. }
  930. p_bind->set_default_arguments(defvals);
  931. p_bind->set_hint_flags(p_flags);
  932. return p_bind;
  933. }
  934. void ClassDB::add_virtual_method(const StringName &p_class, const MethodInfo &p_method, bool p_virtual) {
  935. ERR_FAIL_COND(!classes.has(p_class));
  936. OBJTYPE_WLOCK;
  937. #ifdef DEBUG_METHODS_ENABLED
  938. MethodInfo mi = p_method;
  939. if (p_virtual)
  940. mi.flags |= METHOD_FLAG_VIRTUAL;
  941. classes[p_class].virtual_methods.push_back(mi);
  942. #endif
  943. }
  944. void ClassDB::get_virtual_methods(const StringName &p_class, List<MethodInfo> *p_methods, bool p_no_inheritance) {
  945. ERR_FAIL_COND(!classes.has(p_class));
  946. #ifdef DEBUG_METHODS_ENABLED
  947. ClassInfo *type = classes.getptr(p_class);
  948. ClassInfo *check = type;
  949. while (check) {
  950. for (List<MethodInfo>::Element *E = check->virtual_methods.front(); E; E = E->next()) {
  951. p_methods->push_back(E->get());
  952. }
  953. if (p_no_inheritance)
  954. return;
  955. check = check->inherits_ptr;
  956. }
  957. #endif
  958. }
  959. void ClassDB::set_class_enabled(StringName p_class, bool p_enable) {
  960. OBJTYPE_WLOCK;
  961. ERR_FAIL_COND(!classes.has(p_class));
  962. classes[p_class].disabled = !p_enable;
  963. }
  964. bool ClassDB::is_class_enabled(StringName p_class) {
  965. OBJTYPE_RLOCK;
  966. ClassInfo *ti = classes.getptr(p_class);
  967. if (!ti || !ti->creation_func) {
  968. if (compat_classes.has(p_class)) {
  969. ti = classes.getptr(compat_classes[p_class]);
  970. }
  971. }
  972. ERR_FAIL_COND_V(!ti, false);
  973. return !ti->disabled;
  974. }
  975. bool ClassDB::is_class_exposed(StringName p_class) {
  976. OBJTYPE_RLOCK;
  977. ClassInfo *ti = classes.getptr(p_class);
  978. ERR_FAIL_COND_V(!ti, false);
  979. return ti->exposed;
  980. }
  981. StringName ClassDB::get_category(const StringName &p_node) {
  982. ERR_FAIL_COND_V(!classes.has(p_node), StringName());
  983. #ifdef DEBUG_ENABLED
  984. return classes[p_node].category;
  985. #else
  986. return StringName();
  987. #endif
  988. }
  989. void ClassDB::add_resource_base_extension(const StringName &p_extension, const StringName &p_class) {
  990. if (resource_base_extensions.has(p_extension))
  991. return;
  992. resource_base_extensions[p_extension] = p_class;
  993. }
  994. void ClassDB::get_resource_base_extensions(List<String> *p_extensions) {
  995. const StringName *K = NULL;
  996. while ((K = resource_base_extensions.next(K))) {
  997. p_extensions->push_back(*K);
  998. }
  999. }
  1000. void ClassDB::get_extensions_for_type(const StringName &p_class, List<String> *p_extensions) {
  1001. const StringName *K = NULL;
  1002. while ((K = resource_base_extensions.next(K))) {
  1003. StringName cmp = resource_base_extensions[*K];
  1004. if (is_parent_class(p_class, cmp) || is_parent_class(cmp, p_class))
  1005. p_extensions->push_back(*K);
  1006. }
  1007. }
  1008. RWLock *ClassDB::lock = NULL;
  1009. void ClassDB::init() {
  1010. lock = RWLock::create();
  1011. }
  1012. void ClassDB::cleanup() {
  1013. //OBJTYPE_LOCK; hah not here
  1014. const StringName *k = NULL;
  1015. while ((k = classes.next(k))) {
  1016. ClassInfo &ti = classes[*k];
  1017. const StringName *m = NULL;
  1018. while ((m = ti.method_map.next(m))) {
  1019. memdelete(ti.method_map[*m]);
  1020. }
  1021. }
  1022. classes.clear();
  1023. resource_base_extensions.clear();
  1024. compat_classes.clear();
  1025. memdelete(lock);
  1026. }
  1027. //