core_bind.cpp 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313
  1. /**************************************************************************/
  2. /* core_bind.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  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 "core_bind.h"
  31. #include "core_bind.compat.inc"
  32. #include "core/config/project_settings.h"
  33. #include "core/crypto/crypto_core.h"
  34. #include "core/debugger/engine_debugger.h"
  35. #include "core/debugger/script_debugger.h"
  36. #include "core/io/marshalls.h"
  37. #include "core/math/geometry_2d.h"
  38. #include "core/math/geometry_3d.h"
  39. #include "core/os/keyboard.h"
  40. #include "core/os/thread_safe.h"
  41. #include "core/variant/typed_array.h"
  42. namespace CoreBind {
  43. ////// ResourceLoader //////
  44. ResourceLoader *ResourceLoader::singleton = nullptr;
  45. Error ResourceLoader::load_threaded_request(const String &p_path, const String &p_type_hint, bool p_use_sub_threads, CacheMode p_cache_mode) {
  46. return ::ResourceLoader::load_threaded_request(p_path, p_type_hint, p_use_sub_threads, ResourceFormatLoader::CacheMode(p_cache_mode));
  47. }
  48. ResourceLoader::ThreadLoadStatus ResourceLoader::load_threaded_get_status(const String &p_path, Array r_progress) {
  49. float progress = 0;
  50. ::ResourceLoader::ThreadLoadStatus tls = ::ResourceLoader::load_threaded_get_status(p_path, &progress);
  51. // Default array should never be modified, it causes the hash of the method to change.
  52. if (!ClassDB::is_default_array_arg(r_progress)) {
  53. r_progress.resize(1);
  54. r_progress[0] = progress;
  55. }
  56. return (ThreadLoadStatus)tls;
  57. }
  58. Ref<Resource> ResourceLoader::load_threaded_get(const String &p_path) {
  59. Error error;
  60. Ref<Resource> res = ::ResourceLoader::load_threaded_get(p_path, &error);
  61. return res;
  62. }
  63. Ref<Resource> ResourceLoader::load(const String &p_path, const String &p_type_hint, CacheMode p_cache_mode) {
  64. Error err = OK;
  65. Ref<Resource> ret = ::ResourceLoader::load(p_path, p_type_hint, ResourceFormatLoader::CacheMode(p_cache_mode), &err);
  66. ERR_FAIL_COND_V_MSG(err != OK, ret, vformat("Error loading resource: '%s'.", p_path));
  67. return ret;
  68. }
  69. Vector<String> ResourceLoader::get_recognized_extensions_for_type(const String &p_type) {
  70. List<String> exts;
  71. ::ResourceLoader::get_recognized_extensions_for_type(p_type, &exts);
  72. Vector<String> ret;
  73. for (const String &E : exts) {
  74. ret.push_back(E);
  75. }
  76. return ret;
  77. }
  78. void ResourceLoader::add_resource_format_loader(Ref<ResourceFormatLoader> p_format_loader, bool p_at_front) {
  79. ::ResourceLoader::add_resource_format_loader(p_format_loader, p_at_front);
  80. }
  81. void ResourceLoader::remove_resource_format_loader(Ref<ResourceFormatLoader> p_format_loader) {
  82. ::ResourceLoader::remove_resource_format_loader(p_format_loader);
  83. }
  84. void ResourceLoader::set_abort_on_missing_resources(bool p_abort) {
  85. ::ResourceLoader::set_abort_on_missing_resources(p_abort);
  86. }
  87. PackedStringArray ResourceLoader::get_dependencies(const String &p_path) {
  88. List<String> deps;
  89. ::ResourceLoader::get_dependencies(p_path, &deps);
  90. PackedStringArray ret;
  91. for (const String &E : deps) {
  92. ret.push_back(E);
  93. }
  94. return ret;
  95. }
  96. bool ResourceLoader::has_cached(const String &p_path) {
  97. String local_path = ::ResourceLoader::_validate_local_path(p_path);
  98. return ResourceCache::has(local_path);
  99. }
  100. Ref<Resource> ResourceLoader::get_cached_ref(const String &p_path) {
  101. String local_path = ::ResourceLoader::_validate_local_path(p_path);
  102. return ResourceCache::get_ref(local_path);
  103. }
  104. bool ResourceLoader::exists(const String &p_path, const String &p_type_hint) {
  105. return ::ResourceLoader::exists(p_path, p_type_hint);
  106. }
  107. ResourceUID::ID ResourceLoader::get_resource_uid(const String &p_path) {
  108. return ::ResourceLoader::get_resource_uid(p_path);
  109. }
  110. Vector<String> ResourceLoader::list_directory(const String &p_directory) {
  111. return ::ResourceLoader::list_directory(p_directory);
  112. }
  113. void ResourceLoader::_bind_methods() {
  114. ClassDB::bind_method(D_METHOD("load_threaded_request", "path", "type_hint", "use_sub_threads", "cache_mode"), &ResourceLoader::load_threaded_request, DEFVAL(""), DEFVAL(false), DEFVAL(CACHE_MODE_REUSE));
  115. ClassDB::bind_method(D_METHOD("load_threaded_get_status", "path", "progress"), &ResourceLoader::load_threaded_get_status, DEFVAL_ARRAY);
  116. ClassDB::bind_method(D_METHOD("load_threaded_get", "path"), &ResourceLoader::load_threaded_get);
  117. ClassDB::bind_method(D_METHOD("load", "path", "type_hint", "cache_mode"), &ResourceLoader::load, DEFVAL(""), DEFVAL(CACHE_MODE_REUSE));
  118. ClassDB::bind_method(D_METHOD("get_recognized_extensions_for_type", "type"), &ResourceLoader::get_recognized_extensions_for_type);
  119. ClassDB::bind_method(D_METHOD("add_resource_format_loader", "format_loader", "at_front"), &ResourceLoader::add_resource_format_loader, DEFVAL(false));
  120. ClassDB::bind_method(D_METHOD("remove_resource_format_loader", "format_loader"), &ResourceLoader::remove_resource_format_loader);
  121. ClassDB::bind_method(D_METHOD("set_abort_on_missing_resources", "abort"), &ResourceLoader::set_abort_on_missing_resources);
  122. ClassDB::bind_method(D_METHOD("get_dependencies", "path"), &ResourceLoader::get_dependencies);
  123. ClassDB::bind_method(D_METHOD("has_cached", "path"), &ResourceLoader::has_cached);
  124. ClassDB::bind_method(D_METHOD("get_cached_ref", "path"), &ResourceLoader::get_cached_ref);
  125. ClassDB::bind_method(D_METHOD("exists", "path", "type_hint"), &ResourceLoader::exists, DEFVAL(""));
  126. ClassDB::bind_method(D_METHOD("get_resource_uid", "path"), &ResourceLoader::get_resource_uid);
  127. ClassDB::bind_method(D_METHOD("list_directory", "directory_path"), &ResourceLoader::list_directory);
  128. BIND_ENUM_CONSTANT(THREAD_LOAD_INVALID_RESOURCE);
  129. BIND_ENUM_CONSTANT(THREAD_LOAD_IN_PROGRESS);
  130. BIND_ENUM_CONSTANT(THREAD_LOAD_FAILED);
  131. BIND_ENUM_CONSTANT(THREAD_LOAD_LOADED);
  132. BIND_ENUM_CONSTANT(CACHE_MODE_IGNORE);
  133. BIND_ENUM_CONSTANT(CACHE_MODE_REUSE);
  134. BIND_ENUM_CONSTANT(CACHE_MODE_REPLACE);
  135. BIND_ENUM_CONSTANT(CACHE_MODE_IGNORE_DEEP);
  136. BIND_ENUM_CONSTANT(CACHE_MODE_REPLACE_DEEP);
  137. }
  138. ////// ResourceSaver //////
  139. Error ResourceSaver::save(const Ref<Resource> &p_resource, const String &p_path, BitField<SaverFlags> p_flags) {
  140. return ::ResourceSaver::save(p_resource, p_path, p_flags);
  141. }
  142. Vector<String> ResourceSaver::get_recognized_extensions(const Ref<Resource> &p_resource) {
  143. List<String> exts;
  144. ::ResourceSaver::get_recognized_extensions(p_resource, &exts);
  145. Vector<String> ret;
  146. for (const String &E : exts) {
  147. ret.push_back(E);
  148. }
  149. return ret;
  150. }
  151. void ResourceSaver::add_resource_format_saver(Ref<ResourceFormatSaver> p_format_saver, bool p_at_front) {
  152. ::ResourceSaver::add_resource_format_saver(p_format_saver, p_at_front);
  153. }
  154. void ResourceSaver::remove_resource_format_saver(Ref<ResourceFormatSaver> p_format_saver) {
  155. ::ResourceSaver::remove_resource_format_saver(p_format_saver);
  156. }
  157. ResourceUID::ID ResourceSaver::get_resource_id_for_path(const String &p_path, bool p_generate) {
  158. return ::ResourceSaver::get_resource_id_for_path(p_path, p_generate);
  159. }
  160. ResourceSaver *ResourceSaver::singleton = nullptr;
  161. void ResourceSaver::_bind_methods() {
  162. ClassDB::bind_method(D_METHOD("save", "resource", "path", "flags"), &ResourceSaver::save, DEFVAL(""), DEFVAL((uint32_t)FLAG_NONE));
  163. ClassDB::bind_method(D_METHOD("get_recognized_extensions", "type"), &ResourceSaver::get_recognized_extensions);
  164. ClassDB::bind_method(D_METHOD("add_resource_format_saver", "format_saver", "at_front"), &ResourceSaver::add_resource_format_saver, DEFVAL(false));
  165. ClassDB::bind_method(D_METHOD("remove_resource_format_saver", "format_saver"), &ResourceSaver::remove_resource_format_saver);
  166. ClassDB::bind_method(D_METHOD("get_resource_id_for_path", "path", "generate"), &ResourceSaver::get_resource_id_for_path, DEFVAL(false));
  167. BIND_BITFIELD_FLAG(FLAG_NONE);
  168. BIND_BITFIELD_FLAG(FLAG_RELATIVE_PATHS);
  169. BIND_BITFIELD_FLAG(FLAG_BUNDLE_RESOURCES);
  170. BIND_BITFIELD_FLAG(FLAG_CHANGE_PATH);
  171. BIND_BITFIELD_FLAG(FLAG_OMIT_EDITOR_PROPERTIES);
  172. BIND_BITFIELD_FLAG(FLAG_SAVE_BIG_ENDIAN);
  173. BIND_BITFIELD_FLAG(FLAG_COMPRESS);
  174. BIND_BITFIELD_FLAG(FLAG_REPLACE_SUBRESOURCE_PATHS);
  175. }
  176. ////// Logger ///////
  177. void Logger::_bind_methods() {
  178. GDVIRTUAL_BIND(_log_error, "function", "file", "line", "code", "rationale", "editor_notify", "error_type", "script_backtraces");
  179. GDVIRTUAL_BIND(_log_message, "message", "error");
  180. BIND_ENUM_CONSTANT(ERROR_TYPE_ERROR);
  181. BIND_ENUM_CONSTANT(ERROR_TYPE_WARNING);
  182. BIND_ENUM_CONSTANT(ERROR_TYPE_SCRIPT);
  183. BIND_ENUM_CONSTANT(ERROR_TYPE_SHADER);
  184. }
  185. void Logger::log_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, bool p_editor_notify, ErrorType p_type, const TypedArray<ScriptBacktrace> &p_script_backtraces) {
  186. GDVIRTUAL_CALL(_log_error, String::utf8(p_function), String::utf8(p_file), p_line, String::utf8(p_code), String::utf8(p_rationale), p_editor_notify, p_type, p_script_backtraces);
  187. }
  188. void Logger::log_message(const String &p_text, bool p_error) {
  189. GDVIRTUAL_CALL(_log_message, p_text, p_error);
  190. }
  191. ////// OS //////
  192. void OS::LoggerBind::logv(const char *p_format, va_list p_list, bool p_err) {
  193. if (!should_log(p_err) || is_logging) {
  194. return;
  195. }
  196. is_logging = true;
  197. constexpr int static_buf_size = 1024;
  198. char static_buf[static_buf_size] = { '\0' };
  199. char *buf = static_buf;
  200. va_list list_copy;
  201. va_copy(list_copy, p_list);
  202. int len = vsnprintf(buf, static_buf_size, p_format, p_list);
  203. if (len >= static_buf_size) {
  204. buf = (char *)Memory::alloc_static(len + 1);
  205. vsnprintf(buf, len + 1, p_format, list_copy);
  206. }
  207. va_end(list_copy);
  208. String str;
  209. str.append_utf8(buf, len);
  210. for (Ref<CoreBind::Logger> &logger : loggers) {
  211. logger->log_message(str, p_err);
  212. }
  213. if (len >= static_buf_size) {
  214. Memory::free_static(buf);
  215. }
  216. is_logging = false;
  217. }
  218. void OS::LoggerBind::log_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, bool p_editor_notify, ErrorType p_type, const Vector<Ref<ScriptBacktrace>> &p_script_backtraces) {
  219. if (!should_log(true) || is_logging) {
  220. return;
  221. }
  222. TypedArray<ScriptBacktrace> backtraces;
  223. backtraces.resize(p_script_backtraces.size());
  224. for (int i = 0; i < p_script_backtraces.size(); i++) {
  225. backtraces[i] = p_script_backtraces[i];
  226. }
  227. is_logging = true;
  228. for (Ref<CoreBind::Logger> &logger : loggers) {
  229. logger->log_error(p_function, p_file, p_line, p_code, p_rationale, p_editor_notify, CoreBind::Logger::ErrorType(p_type), backtraces);
  230. }
  231. is_logging = false;
  232. }
  233. PackedByteArray OS::get_entropy(int p_bytes) {
  234. PackedByteArray pba;
  235. pba.resize(p_bytes);
  236. Error err = ::OS::get_singleton()->get_entropy(pba.ptrw(), p_bytes);
  237. ERR_FAIL_COND_V(err != OK, PackedByteArray());
  238. return pba;
  239. }
  240. String OS::get_system_ca_certificates() {
  241. return ::OS::get_singleton()->get_system_ca_certificates();
  242. }
  243. PackedStringArray OS::get_connected_midi_inputs() {
  244. return ::OS::get_singleton()->get_connected_midi_inputs();
  245. }
  246. void OS::open_midi_inputs() {
  247. ::OS::get_singleton()->open_midi_inputs();
  248. }
  249. void OS::close_midi_inputs() {
  250. ::OS::get_singleton()->close_midi_inputs();
  251. }
  252. void OS::set_use_file_access_save_and_swap(bool p_enable) {
  253. FileAccess::set_backup_save(p_enable);
  254. }
  255. void OS::set_low_processor_usage_mode(bool p_enabled) {
  256. ::OS::get_singleton()->set_low_processor_usage_mode(p_enabled);
  257. }
  258. bool OS::is_in_low_processor_usage_mode() const {
  259. return ::OS::get_singleton()->is_in_low_processor_usage_mode();
  260. }
  261. void OS::set_low_processor_usage_mode_sleep_usec(int p_usec) {
  262. ::OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(p_usec);
  263. }
  264. int OS::get_low_processor_usage_mode_sleep_usec() const {
  265. return ::OS::get_singleton()->get_low_processor_usage_mode_sleep_usec();
  266. }
  267. void OS::set_delta_smoothing(bool p_enabled) {
  268. ::OS::get_singleton()->set_delta_smoothing(p_enabled);
  269. }
  270. bool OS::is_delta_smoothing_enabled() const {
  271. return ::OS::get_singleton()->is_delta_smoothing_enabled();
  272. }
  273. void OS::alert(const String &p_alert, const String &p_title) {
  274. ::OS::get_singleton()->alert(p_alert, p_title);
  275. }
  276. void OS::crash(const String &p_message) {
  277. CRASH_NOW_MSG(p_message);
  278. }
  279. Vector<String> OS::get_system_fonts() const {
  280. return ::OS::get_singleton()->get_system_fonts();
  281. }
  282. String OS::get_system_font_path(const String &p_font_name, int p_weight, int p_stretch, bool p_italic) const {
  283. return ::OS::get_singleton()->get_system_font_path(p_font_name, p_weight, p_stretch, p_italic);
  284. }
  285. Vector<String> OS::get_system_font_path_for_text(const String &p_font_name, const String &p_text, const String &p_locale, const String &p_script, int p_weight, int p_stretch, bool p_italic) const {
  286. return ::OS::get_singleton()->get_system_font_path_for_text(p_font_name, p_text, p_locale, p_script, p_weight, p_stretch, p_italic);
  287. }
  288. String OS::get_executable_path() const {
  289. return ::OS::get_singleton()->get_executable_path();
  290. }
  291. Error OS::shell_open(const String &p_uri) {
  292. if (p_uri.begins_with("res://")) {
  293. WARN_PRINT("Attempting to open an URL with the \"res://\" protocol. Use `ProjectSettings.globalize_path()` to convert a Godot-specific path to a system path before opening it with `OS.shell_open()`.");
  294. } else if (p_uri.begins_with("user://")) {
  295. WARN_PRINT("Attempting to open an URL with the \"user://\" protocol. Use `ProjectSettings.globalize_path()` to convert a Godot-specific path to a system path before opening it with `OS.shell_open()`.");
  296. }
  297. return ::OS::get_singleton()->shell_open(p_uri);
  298. }
  299. Error OS::shell_show_in_file_manager(const String &p_path, bool p_open_folder) {
  300. if (p_path.begins_with("res://")) {
  301. WARN_PRINT("Attempting to explore file path with the \"res://\" protocol. Use `ProjectSettings.globalize_path()` to convert a Godot-specific path to a system path before opening it with `OS.shell_show_in_file_manager()`.");
  302. } else if (p_path.begins_with("user://")) {
  303. WARN_PRINT("Attempting to explore file path with the \"user://\" protocol. Use `ProjectSettings.globalize_path()` to convert a Godot-specific path to a system path before opening it with `OS.shell_show_in_file_manager()`.");
  304. }
  305. return ::OS::get_singleton()->shell_show_in_file_manager(p_path, p_open_folder);
  306. }
  307. String OS::read_string_from_stdin(int64_t p_buffer_size) {
  308. return ::OS::get_singleton()->get_stdin_string(p_buffer_size);
  309. }
  310. PackedByteArray OS::read_buffer_from_stdin(int64_t p_buffer_size) {
  311. return ::OS::get_singleton()->get_stdin_buffer(p_buffer_size);
  312. }
  313. OS::StdHandleType OS::get_stdin_type() const {
  314. return (OS::StdHandleType)::OS::get_singleton()->get_stdin_type();
  315. }
  316. OS::StdHandleType OS::get_stdout_type() const {
  317. return (OS::StdHandleType)::OS::get_singleton()->get_stdout_type();
  318. }
  319. OS::StdHandleType OS::get_stderr_type() const {
  320. return (OS::StdHandleType)::OS::get_singleton()->get_stderr_type();
  321. }
  322. int OS::execute(const String &p_path, const Vector<String> &p_arguments, Array r_output, bool p_read_stderr, bool p_open_console) {
  323. List<String> args;
  324. for (const String &arg : p_arguments) {
  325. args.push_back(arg);
  326. }
  327. String pipe;
  328. int exitcode = 0;
  329. Error err = ::OS::get_singleton()->execute(p_path, args, &pipe, &exitcode, p_read_stderr, nullptr, p_open_console);
  330. // Default array should never be modified, it causes the hash of the method to change.
  331. if (!ClassDB::is_default_array_arg(r_output)) {
  332. r_output.push_back(pipe);
  333. }
  334. if (err != OK) {
  335. return -1;
  336. }
  337. return exitcode;
  338. }
  339. Dictionary OS::execute_with_pipe(const String &p_path, const Vector<String> &p_arguments, bool p_blocking) {
  340. List<String> args;
  341. for (const String &arg : p_arguments) {
  342. args.push_back(arg);
  343. }
  344. return ::OS::get_singleton()->execute_with_pipe(p_path, args, p_blocking);
  345. }
  346. int OS::create_instance(const Vector<String> &p_arguments) {
  347. List<String> args;
  348. for (const String &arg : p_arguments) {
  349. args.push_back(arg);
  350. }
  351. ::OS::ProcessID pid = 0;
  352. Error err = ::OS::get_singleton()->create_instance(args, &pid);
  353. if (err != OK) {
  354. return -1;
  355. }
  356. return pid;
  357. }
  358. int OS::create_process(const String &p_path, const Vector<String> &p_arguments, bool p_open_console) {
  359. List<String> args;
  360. for (const String &arg : p_arguments) {
  361. args.push_back(arg);
  362. }
  363. ::OS::ProcessID pid = 0;
  364. Error err = ::OS::get_singleton()->create_process(p_path, args, &pid, p_open_console);
  365. if (err != OK) {
  366. return -1;
  367. }
  368. return pid;
  369. }
  370. Error OS::kill(int p_pid) {
  371. return ::OS::get_singleton()->kill(p_pid);
  372. }
  373. bool OS::is_process_running(int p_pid) const {
  374. return ::OS::get_singleton()->is_process_running(p_pid);
  375. }
  376. int OS::get_process_exit_code(int p_pid) const {
  377. return ::OS::get_singleton()->get_process_exit_code(p_pid);
  378. }
  379. int OS::get_process_id() const {
  380. return ::OS::get_singleton()->get_process_id();
  381. }
  382. bool OS::has_environment(const String &p_var) const {
  383. return ::OS::get_singleton()->has_environment(p_var);
  384. }
  385. String OS::get_environment(const String &p_var) const {
  386. return ::OS::get_singleton()->get_environment(p_var);
  387. }
  388. void OS::set_environment(const String &p_var, const String &p_value) const {
  389. ::OS::get_singleton()->set_environment(p_var, p_value);
  390. }
  391. void OS::unset_environment(const String &p_var) const {
  392. ::OS::get_singleton()->unset_environment(p_var);
  393. }
  394. String OS::get_name() const {
  395. return ::OS::get_singleton()->get_name();
  396. }
  397. String OS::get_distribution_name() const {
  398. return ::OS::get_singleton()->get_distribution_name();
  399. }
  400. String OS::get_version() const {
  401. return ::OS::get_singleton()->get_version();
  402. }
  403. String OS::get_version_alias() const {
  404. return ::OS::get_singleton()->get_version_alias();
  405. }
  406. Vector<String> OS::get_video_adapter_driver_info() const {
  407. return ::OS::get_singleton()->get_video_adapter_driver_info();
  408. }
  409. Vector<String> OS::get_cmdline_args() {
  410. List<String> cmdline = ::OS::get_singleton()->get_cmdline_args();
  411. Vector<String> cmdlinev;
  412. for (const String &E : cmdline) {
  413. cmdlinev.push_back(E);
  414. }
  415. return cmdlinev;
  416. }
  417. Vector<String> OS::get_cmdline_user_args() {
  418. List<String> cmdline = ::OS::get_singleton()->get_cmdline_user_args();
  419. Vector<String> cmdlinev;
  420. for (const String &E : cmdline) {
  421. cmdlinev.push_back(E);
  422. }
  423. return cmdlinev;
  424. }
  425. void OS::set_restart_on_exit(bool p_restart, const Vector<String> &p_restart_arguments) {
  426. List<String> args_list;
  427. for (const String &restart_argument : p_restart_arguments) {
  428. args_list.push_back(restart_argument);
  429. }
  430. ::OS::get_singleton()->set_restart_on_exit(p_restart, args_list);
  431. }
  432. bool OS::is_restart_on_exit_set() const {
  433. return ::OS::get_singleton()->is_restart_on_exit_set();
  434. }
  435. Vector<String> OS::get_restart_on_exit_arguments() const {
  436. List<String> args = ::OS::get_singleton()->get_restart_on_exit_arguments();
  437. Vector<String> args_vector;
  438. for (const String &arg : args) {
  439. args_vector.push_back(arg);
  440. }
  441. return args_vector;
  442. }
  443. String OS::get_locale() const {
  444. return ::OS::get_singleton()->get_locale();
  445. }
  446. String OS::get_locale_language() const {
  447. return ::OS::get_singleton()->get_locale_language();
  448. }
  449. String OS::get_model_name() const {
  450. return ::OS::get_singleton()->get_model_name();
  451. }
  452. Error OS::set_thread_name(const String &p_name) {
  453. return ::Thread::set_name(p_name);
  454. }
  455. ::Thread::ID OS::get_thread_caller_id() const {
  456. return ::Thread::get_caller_id();
  457. }
  458. ::Thread::ID OS::get_main_thread_id() const {
  459. return ::Thread::get_main_id();
  460. }
  461. bool OS::has_feature(const String &p_feature) const {
  462. const bool *value_ptr = feature_cache.getptr(p_feature);
  463. if (value_ptr) {
  464. return *value_ptr;
  465. } else {
  466. const bool has = ::OS::get_singleton()->has_feature(p_feature);
  467. feature_cache[p_feature] = has;
  468. return has;
  469. }
  470. }
  471. bool OS::is_sandboxed() const {
  472. return ::OS::get_singleton()->is_sandboxed();
  473. }
  474. uint64_t OS::get_static_memory_usage() const {
  475. return ::OS::get_singleton()->get_static_memory_usage();
  476. }
  477. uint64_t OS::get_static_memory_peak_usage() const {
  478. return ::OS::get_singleton()->get_static_memory_peak_usage();
  479. }
  480. Dictionary OS::get_memory_info() const {
  481. return ::OS::get_singleton()->get_memory_info();
  482. }
  483. /** This method uses a signed argument for better error reporting as it's used from the scripting API. */
  484. void OS::delay_usec(int p_usec) const {
  485. ERR_FAIL_COND_MSG(
  486. p_usec < 0,
  487. vformat("Can't sleep for %d microseconds. The delay provided must be greater than or equal to 0 microseconds.", p_usec));
  488. ::OS::get_singleton()->delay_usec(p_usec);
  489. }
  490. /** This method uses a signed argument for better error reporting as it's used from the scripting API. */
  491. void OS::delay_msec(int p_msec) const {
  492. ERR_FAIL_COND_MSG(
  493. p_msec < 0,
  494. vformat("Can't sleep for %d milliseconds. The delay provided must be greater than or equal to 0 milliseconds.", p_msec));
  495. ::OS::get_singleton()->delay_usec(int64_t(p_msec) * 1000);
  496. }
  497. bool OS::is_userfs_persistent() const {
  498. return ::OS::get_singleton()->is_userfs_persistent();
  499. }
  500. int OS::get_processor_count() const {
  501. return ::OS::get_singleton()->get_processor_count();
  502. }
  503. String OS::get_processor_name() const {
  504. return ::OS::get_singleton()->get_processor_name();
  505. }
  506. bool OS::is_stdout_verbose() const {
  507. return ::OS::get_singleton()->is_stdout_verbose();
  508. }
  509. Error OS::move_to_trash(const String &p_path) const {
  510. return ::OS::get_singleton()->move_to_trash(p_path);
  511. }
  512. String OS::get_user_data_dir() const {
  513. return ::OS::get_singleton()->get_user_data_dir();
  514. }
  515. String OS::get_config_dir() const {
  516. // Exposed as `get_config_dir()` instead of `get_config_path()` for consistency with other exposed OS methods.
  517. return ::OS::get_singleton()->get_config_path();
  518. }
  519. String OS::get_data_dir() const {
  520. // Exposed as `get_data_dir()` instead of `get_data_path()` for consistency with other exposed OS methods.
  521. return ::OS::get_singleton()->get_data_path();
  522. }
  523. String OS::get_cache_dir() const {
  524. // Exposed as `get_cache_dir()` instead of `get_cache_path()` for consistency with other exposed OS methods.
  525. return ::OS::get_singleton()->get_cache_path();
  526. }
  527. String OS::get_temp_dir() const {
  528. // Exposed as `get_temp_dir()` instead of `get_temp_path()` for consistency with other exposed OS methods.
  529. return ::OS::get_singleton()->get_temp_path();
  530. }
  531. bool OS::is_debug_build() const {
  532. #ifdef DEBUG_ENABLED
  533. return true;
  534. #else
  535. return false;
  536. #endif
  537. }
  538. String OS::get_system_dir(SystemDir p_dir, bool p_shared_storage) const {
  539. return ::OS::get_singleton()->get_system_dir(::OS::SystemDir(p_dir), p_shared_storage);
  540. }
  541. String OS::get_keycode_string(Key p_code) const {
  542. return ::keycode_get_string(p_code);
  543. }
  544. bool OS::is_keycode_unicode(char32_t p_unicode) const {
  545. return ::keycode_has_unicode((Key)p_unicode);
  546. }
  547. Key OS::find_keycode_from_string(const String &p_code) const {
  548. return find_keycode(p_code);
  549. }
  550. bool OS::request_permission(const String &p_name) {
  551. return ::OS::get_singleton()->request_permission(p_name);
  552. }
  553. bool OS::request_permissions() {
  554. return ::OS::get_singleton()->request_permissions();
  555. }
  556. Vector<String> OS::get_granted_permissions() const {
  557. return ::OS::get_singleton()->get_granted_permissions();
  558. }
  559. void OS::revoke_granted_permissions() {
  560. ::OS::get_singleton()->revoke_granted_permissions();
  561. }
  562. String OS::get_unique_id() const {
  563. return ::OS::get_singleton()->get_unique_id();
  564. }
  565. void OS::add_logger(const Ref<Logger> &p_logger) {
  566. ERR_FAIL_COND(p_logger.is_null());
  567. if (!logger_bind) {
  568. logger_bind = memnew(LoggerBind);
  569. ::OS::get_singleton()->add_logger(logger_bind);
  570. }
  571. ERR_FAIL_COND_MSG(logger_bind->loggers.find(p_logger) != -1, "Could not add logger, as it has already been added.");
  572. logger_bind->loggers.push_back(p_logger);
  573. }
  574. void OS::remove_logger(const Ref<Logger> &p_logger) {
  575. ERR_FAIL_COND(p_logger.is_null());
  576. ERR_FAIL_COND_MSG(!logger_bind || logger_bind->loggers.find(p_logger) == -1, "Could not remove logger, as it hasn't been added.");
  577. logger_bind->loggers.erase(p_logger);
  578. }
  579. OS *OS::singleton = nullptr;
  580. void OS::_bind_methods() {
  581. ClassDB::bind_method(D_METHOD("get_entropy", "size"), &OS::get_entropy);
  582. ClassDB::bind_method(D_METHOD("get_system_ca_certificates"), &OS::get_system_ca_certificates);
  583. ClassDB::bind_method(D_METHOD("get_connected_midi_inputs"), &OS::get_connected_midi_inputs);
  584. ClassDB::bind_method(D_METHOD("open_midi_inputs"), &OS::open_midi_inputs);
  585. ClassDB::bind_method(D_METHOD("close_midi_inputs"), &OS::close_midi_inputs);
  586. ClassDB::bind_method(D_METHOD("alert", "text", "title"), &OS::alert, DEFVAL("Alert!"));
  587. ClassDB::bind_method(D_METHOD("crash", "message"), &OS::crash);
  588. ClassDB::bind_method(D_METHOD("set_low_processor_usage_mode", "enable"), &OS::set_low_processor_usage_mode);
  589. ClassDB::bind_method(D_METHOD("is_in_low_processor_usage_mode"), &OS::is_in_low_processor_usage_mode);
  590. ClassDB::bind_method(D_METHOD("set_low_processor_usage_mode_sleep_usec", "usec"), &OS::set_low_processor_usage_mode_sleep_usec);
  591. ClassDB::bind_method(D_METHOD("get_low_processor_usage_mode_sleep_usec"), &OS::get_low_processor_usage_mode_sleep_usec);
  592. ClassDB::bind_method(D_METHOD("set_delta_smoothing", "delta_smoothing_enabled"), &OS::set_delta_smoothing);
  593. ClassDB::bind_method(D_METHOD("is_delta_smoothing_enabled"), &OS::is_delta_smoothing_enabled);
  594. ClassDB::bind_method(D_METHOD("get_processor_count"), &OS::get_processor_count);
  595. ClassDB::bind_method(D_METHOD("get_processor_name"), &OS::get_processor_name);
  596. ClassDB::bind_method(D_METHOD("get_system_fonts"), &OS::get_system_fonts);
  597. ClassDB::bind_method(D_METHOD("get_system_font_path", "font_name", "weight", "stretch", "italic"), &OS::get_system_font_path, DEFVAL(400), DEFVAL(100), DEFVAL(false));
  598. ClassDB::bind_method(D_METHOD("get_system_font_path_for_text", "font_name", "text", "locale", "script", "weight", "stretch", "italic"), &OS::get_system_font_path_for_text, DEFVAL(String()), DEFVAL(String()), DEFVAL(400), DEFVAL(100), DEFVAL(false));
  599. ClassDB::bind_method(D_METHOD("get_executable_path"), &OS::get_executable_path);
  600. ClassDB::bind_method(D_METHOD("read_string_from_stdin", "buffer_size"), &OS::read_string_from_stdin, DEFVAL(1024));
  601. ClassDB::bind_method(D_METHOD("read_buffer_from_stdin", "buffer_size"), &OS::read_buffer_from_stdin, DEFVAL(1024));
  602. ClassDB::bind_method(D_METHOD("get_stdin_type"), &OS::get_stdin_type);
  603. ClassDB::bind_method(D_METHOD("get_stdout_type"), &OS::get_stdout_type);
  604. ClassDB::bind_method(D_METHOD("get_stderr_type"), &OS::get_stderr_type);
  605. ClassDB::bind_method(D_METHOD("execute", "path", "arguments", "output", "read_stderr", "open_console"), &OS::execute, DEFVAL_ARRAY, DEFVAL(false), DEFVAL(false));
  606. ClassDB::bind_method(D_METHOD("execute_with_pipe", "path", "arguments", "blocking"), &OS::execute_with_pipe, DEFVAL(true));
  607. ClassDB::bind_method(D_METHOD("create_process", "path", "arguments", "open_console"), &OS::create_process, DEFVAL(false));
  608. ClassDB::bind_method(D_METHOD("create_instance", "arguments"), &OS::create_instance);
  609. ClassDB::bind_method(D_METHOD("kill", "pid"), &OS::kill);
  610. ClassDB::bind_method(D_METHOD("shell_open", "uri"), &OS::shell_open);
  611. ClassDB::bind_method(D_METHOD("shell_show_in_file_manager", "file_or_dir_path", "open_folder"), &OS::shell_show_in_file_manager, DEFVAL(true));
  612. ClassDB::bind_method(D_METHOD("is_process_running", "pid"), &OS::is_process_running);
  613. ClassDB::bind_method(D_METHOD("get_process_exit_code", "pid"), &OS::get_process_exit_code);
  614. ClassDB::bind_method(D_METHOD("get_process_id"), &OS::get_process_id);
  615. ClassDB::bind_method(D_METHOD("has_environment", "variable"), &OS::has_environment);
  616. ClassDB::bind_method(D_METHOD("get_environment", "variable"), &OS::get_environment);
  617. ClassDB::bind_method(D_METHOD("set_environment", "variable", "value"), &OS::set_environment);
  618. ClassDB::bind_method(D_METHOD("unset_environment", "variable"), &OS::unset_environment);
  619. ClassDB::bind_method(D_METHOD("get_name"), &OS::get_name);
  620. ClassDB::bind_method(D_METHOD("get_distribution_name"), &OS::get_distribution_name);
  621. ClassDB::bind_method(D_METHOD("get_version"), &OS::get_version);
  622. ClassDB::bind_method(D_METHOD("get_version_alias"), &OS::get_version_alias);
  623. ClassDB::bind_method(D_METHOD("get_cmdline_args"), &OS::get_cmdline_args);
  624. ClassDB::bind_method(D_METHOD("get_cmdline_user_args"), &OS::get_cmdline_user_args);
  625. ClassDB::bind_method(D_METHOD("get_video_adapter_driver_info"), &OS::get_video_adapter_driver_info);
  626. ClassDB::bind_method(D_METHOD("set_restart_on_exit", "restart", "arguments"), &OS::set_restart_on_exit, DEFVAL(Vector<String>()));
  627. ClassDB::bind_method(D_METHOD("is_restart_on_exit_set"), &OS::is_restart_on_exit_set);
  628. ClassDB::bind_method(D_METHOD("get_restart_on_exit_arguments"), &OS::get_restart_on_exit_arguments);
  629. ClassDB::bind_method(D_METHOD("delay_usec", "usec"), &OS::delay_usec);
  630. ClassDB::bind_method(D_METHOD("delay_msec", "msec"), &OS::delay_msec);
  631. ClassDB::bind_method(D_METHOD("get_locale"), &OS::get_locale);
  632. ClassDB::bind_method(D_METHOD("get_locale_language"), &OS::get_locale_language);
  633. ClassDB::bind_method(D_METHOD("get_model_name"), &OS::get_model_name);
  634. ClassDB::bind_method(D_METHOD("is_userfs_persistent"), &OS::is_userfs_persistent);
  635. ClassDB::bind_method(D_METHOD("is_stdout_verbose"), &OS::is_stdout_verbose);
  636. ClassDB::bind_method(D_METHOD("is_debug_build"), &OS::is_debug_build);
  637. ClassDB::bind_method(D_METHOD("get_static_memory_usage"), &OS::get_static_memory_usage);
  638. ClassDB::bind_method(D_METHOD("get_static_memory_peak_usage"), &OS::get_static_memory_peak_usage);
  639. ClassDB::bind_method(D_METHOD("get_memory_info"), &OS::get_memory_info);
  640. ClassDB::bind_method(D_METHOD("move_to_trash", "path"), &OS::move_to_trash);
  641. ClassDB::bind_method(D_METHOD("get_user_data_dir"), &OS::get_user_data_dir);
  642. ClassDB::bind_method(D_METHOD("get_system_dir", "dir", "shared_storage"), &OS::get_system_dir, DEFVAL(true));
  643. ClassDB::bind_method(D_METHOD("get_config_dir"), &OS::get_config_dir);
  644. ClassDB::bind_method(D_METHOD("get_data_dir"), &OS::get_data_dir);
  645. ClassDB::bind_method(D_METHOD("get_cache_dir"), &OS::get_cache_dir);
  646. ClassDB::bind_method(D_METHOD("get_temp_dir"), &OS::get_temp_dir);
  647. ClassDB::bind_method(D_METHOD("get_unique_id"), &OS::get_unique_id);
  648. ClassDB::bind_method(D_METHOD("get_keycode_string", "code"), &OS::get_keycode_string);
  649. ClassDB::bind_method(D_METHOD("is_keycode_unicode", "code"), &OS::is_keycode_unicode);
  650. ClassDB::bind_method(D_METHOD("find_keycode_from_string", "string"), &OS::find_keycode_from_string);
  651. ClassDB::bind_method(D_METHOD("set_use_file_access_save_and_swap", "enabled"), &OS::set_use_file_access_save_and_swap);
  652. ClassDB::bind_method(D_METHOD("set_thread_name", "name"), &OS::set_thread_name);
  653. ClassDB::bind_method(D_METHOD("get_thread_caller_id"), &OS::get_thread_caller_id);
  654. ClassDB::bind_method(D_METHOD("get_main_thread_id"), &OS::get_main_thread_id);
  655. ClassDB::bind_method(D_METHOD("has_feature", "tag_name"), &OS::has_feature);
  656. ClassDB::bind_method(D_METHOD("is_sandboxed"), &OS::is_sandboxed);
  657. ClassDB::bind_method(D_METHOD("request_permission", "name"), &OS::request_permission);
  658. ClassDB::bind_method(D_METHOD("request_permissions"), &OS::request_permissions);
  659. ClassDB::bind_method(D_METHOD("get_granted_permissions"), &OS::get_granted_permissions);
  660. ClassDB::bind_method(D_METHOD("revoke_granted_permissions"), &OS::revoke_granted_permissions);
  661. ClassDB::bind_method(D_METHOD("add_logger", "logger"), &OS::add_logger);
  662. ClassDB::bind_method(D_METHOD("remove_logger", "logger"), &OS::remove_logger);
  663. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "low_processor_usage_mode"), "set_low_processor_usage_mode", "is_in_low_processor_usage_mode");
  664. ADD_PROPERTY(PropertyInfo(Variant::INT, "low_processor_usage_mode_sleep_usec"), "set_low_processor_usage_mode_sleep_usec", "get_low_processor_usage_mode_sleep_usec");
  665. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "delta_smoothing"), "set_delta_smoothing", "is_delta_smoothing_enabled");
  666. // Those default values need to be specified for the docs generator,
  667. // to avoid using values from the documentation writer's own OS instance.
  668. ADD_PROPERTY_DEFAULT("low_processor_usage_mode", false);
  669. ADD_PROPERTY_DEFAULT("low_processor_usage_mode_sleep_usec", 6900);
  670. BIND_ENUM_CONSTANT(RENDERING_DRIVER_VULKAN);
  671. BIND_ENUM_CONSTANT(RENDERING_DRIVER_OPENGL3);
  672. BIND_ENUM_CONSTANT(RENDERING_DRIVER_D3D12);
  673. BIND_ENUM_CONSTANT(RENDERING_DRIVER_METAL);
  674. BIND_ENUM_CONSTANT(SYSTEM_DIR_DESKTOP);
  675. BIND_ENUM_CONSTANT(SYSTEM_DIR_DCIM);
  676. BIND_ENUM_CONSTANT(SYSTEM_DIR_DOCUMENTS);
  677. BIND_ENUM_CONSTANT(SYSTEM_DIR_DOWNLOADS);
  678. BIND_ENUM_CONSTANT(SYSTEM_DIR_MOVIES);
  679. BIND_ENUM_CONSTANT(SYSTEM_DIR_MUSIC);
  680. BIND_ENUM_CONSTANT(SYSTEM_DIR_PICTURES);
  681. BIND_ENUM_CONSTANT(SYSTEM_DIR_RINGTONES);
  682. BIND_ENUM_CONSTANT(STD_HANDLE_INVALID);
  683. BIND_ENUM_CONSTANT(STD_HANDLE_CONSOLE);
  684. BIND_ENUM_CONSTANT(STD_HANDLE_FILE);
  685. BIND_ENUM_CONSTANT(STD_HANDLE_PIPE);
  686. BIND_ENUM_CONSTANT(STD_HANDLE_UNKNOWN);
  687. }
  688. OS::OS() {
  689. singleton = this;
  690. }
  691. OS::~OS() {
  692. if (singleton == this) {
  693. singleton = nullptr;
  694. }
  695. if (logger_bind) {
  696. logger_bind->clear();
  697. }
  698. }
  699. ////// Geometry2D //////
  700. Geometry2D *Geometry2D::singleton = nullptr;
  701. Geometry2D *Geometry2D::get_singleton() {
  702. return singleton;
  703. }
  704. bool Geometry2D::is_point_in_circle(const Vector2 &p_point, const Vector2 &p_circle_pos, real_t p_circle_radius) {
  705. return ::Geometry2D::is_point_in_circle(p_point, p_circle_pos, p_circle_radius);
  706. }
  707. real_t Geometry2D::segment_intersects_circle(const Vector2 &p_from, const Vector2 &p_to, const Vector2 &p_circle_pos, real_t p_circle_radius) {
  708. return ::Geometry2D::segment_intersects_circle(p_from, p_to, p_circle_pos, p_circle_radius);
  709. }
  710. Variant Geometry2D::segment_intersects_segment(const Vector2 &p_from_a, const Vector2 &p_to_a, const Vector2 &p_from_b, const Vector2 &p_to_b) {
  711. Vector2 result;
  712. if (::Geometry2D::segment_intersects_segment(p_from_a, p_to_a, p_from_b, p_to_b, &result)) {
  713. return result;
  714. } else {
  715. return Variant();
  716. }
  717. }
  718. Variant Geometry2D::line_intersects_line(const Vector2 &p_from_a, const Vector2 &p_dir_a, const Vector2 &p_from_b, const Vector2 &p_dir_b) {
  719. Vector2 result;
  720. if (::Geometry2D::line_intersects_line(p_from_a, p_dir_a, p_from_b, p_dir_b, result)) {
  721. return result;
  722. } else {
  723. return Variant();
  724. }
  725. }
  726. Vector<Vector2> Geometry2D::get_closest_points_between_segments(const Vector2 &p1, const Vector2 &q1, const Vector2 &p2, const Vector2 &q2) {
  727. Vector2 r1, r2;
  728. ::Geometry2D::get_closest_points_between_segments(p1, q1, p2, q2, r1, r2);
  729. Vector<Vector2> r = { r1, r2 };
  730. return r;
  731. }
  732. Vector2 Geometry2D::get_closest_point_to_segment(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b) {
  733. Vector2 s[2] = { p_a, p_b };
  734. return ::Geometry2D::get_closest_point_to_segment(p_point, s);
  735. }
  736. Vector2 Geometry2D::get_closest_point_to_segment_uncapped(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b) {
  737. Vector2 s[2] = { p_a, p_b };
  738. return ::Geometry2D::get_closest_point_to_segment_uncapped(p_point, s);
  739. }
  740. bool Geometry2D::point_is_inside_triangle(const Vector2 &s, const Vector2 &a, const Vector2 &b, const Vector2 &c) const {
  741. return ::Geometry2D::is_point_in_triangle(s, a, b, c);
  742. }
  743. bool Geometry2D::is_polygon_clockwise(const Vector<Vector2> &p_polygon) {
  744. return ::Geometry2D::is_polygon_clockwise(p_polygon);
  745. }
  746. bool Geometry2D::is_point_in_polygon(const Point2 &p_point, const Vector<Vector2> &p_polygon) {
  747. return ::Geometry2D::is_point_in_polygon(p_point, p_polygon);
  748. }
  749. Vector<int> Geometry2D::triangulate_polygon(const Vector<Vector2> &p_polygon) {
  750. return ::Geometry2D::triangulate_polygon(p_polygon);
  751. }
  752. Vector<int> Geometry2D::triangulate_delaunay(const Vector<Vector2> &p_points) {
  753. return ::Geometry2D::triangulate_delaunay(p_points);
  754. }
  755. Vector<Point2> Geometry2D::convex_hull(const Vector<Point2> &p_points) {
  756. return ::Geometry2D::convex_hull(p_points);
  757. }
  758. TypedArray<PackedVector2Array> Geometry2D::decompose_polygon_in_convex(const Vector<Vector2> &p_polygon) {
  759. Vector<Vector<Point2>> decomp = ::Geometry2D::decompose_polygon_in_convex(p_polygon);
  760. TypedArray<PackedVector2Array> ret;
  761. for (int i = 0; i < decomp.size(); ++i) {
  762. ret.push_back(decomp[i]);
  763. }
  764. return ret;
  765. }
  766. TypedArray<PackedVector2Array> Geometry2D::merge_polygons(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
  767. Vector<Vector<Point2>> polys = ::Geometry2D::merge_polygons(p_polygon_a, p_polygon_b);
  768. TypedArray<PackedVector2Array> ret;
  769. for (int i = 0; i < polys.size(); ++i) {
  770. ret.push_back(polys[i]);
  771. }
  772. return ret;
  773. }
  774. TypedArray<PackedVector2Array> Geometry2D::clip_polygons(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
  775. Vector<Vector<Point2>> polys = ::Geometry2D::clip_polygons(p_polygon_a, p_polygon_b);
  776. TypedArray<PackedVector2Array> ret;
  777. for (int i = 0; i < polys.size(); ++i) {
  778. ret.push_back(polys[i]);
  779. }
  780. return ret;
  781. }
  782. TypedArray<PackedVector2Array> Geometry2D::intersect_polygons(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
  783. Vector<Vector<Point2>> polys = ::Geometry2D::intersect_polygons(p_polygon_a, p_polygon_b);
  784. TypedArray<PackedVector2Array> ret;
  785. for (int i = 0; i < polys.size(); ++i) {
  786. ret.push_back(polys[i]);
  787. }
  788. return ret;
  789. }
  790. TypedArray<PackedVector2Array> Geometry2D::exclude_polygons(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
  791. Vector<Vector<Point2>> polys = ::Geometry2D::exclude_polygons(p_polygon_a, p_polygon_b);
  792. TypedArray<PackedVector2Array> ret;
  793. for (int i = 0; i < polys.size(); ++i) {
  794. ret.push_back(polys[i]);
  795. }
  796. return ret;
  797. }
  798. TypedArray<PackedVector2Array> Geometry2D::clip_polyline_with_polygon(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) {
  799. Vector<Vector<Point2>> polys = ::Geometry2D::clip_polyline_with_polygon(p_polyline, p_polygon);
  800. TypedArray<PackedVector2Array> ret;
  801. for (int i = 0; i < polys.size(); ++i) {
  802. ret.push_back(polys[i]);
  803. }
  804. return ret;
  805. }
  806. TypedArray<PackedVector2Array> Geometry2D::intersect_polyline_with_polygon(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) {
  807. Vector<Vector<Point2>> polys = ::Geometry2D::intersect_polyline_with_polygon(p_polyline, p_polygon);
  808. TypedArray<PackedVector2Array> ret;
  809. for (int i = 0; i < polys.size(); ++i) {
  810. ret.push_back(polys[i]);
  811. }
  812. return ret;
  813. }
  814. TypedArray<PackedVector2Array> Geometry2D::offset_polygon(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type) {
  815. Vector<Vector<Point2>> polys = ::Geometry2D::offset_polygon(p_polygon, p_delta, ::Geometry2D::PolyJoinType(p_join_type));
  816. TypedArray<PackedVector2Array> ret;
  817. for (int i = 0; i < polys.size(); ++i) {
  818. ret.push_back(polys[i]);
  819. }
  820. return ret;
  821. }
  822. TypedArray<PackedVector2Array> Geometry2D::offset_polyline(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type, PolyEndType p_end_type) {
  823. Vector<Vector<Point2>> polys = ::Geometry2D::offset_polyline(p_polygon, p_delta, ::Geometry2D::PolyJoinType(p_join_type), ::Geometry2D::PolyEndType(p_end_type));
  824. TypedArray<PackedVector2Array> ret;
  825. for (int i = 0; i < polys.size(); ++i) {
  826. ret.push_back(polys[i]);
  827. }
  828. return ret;
  829. }
  830. Dictionary Geometry2D::make_atlas(const Vector<Size2> &p_rects) {
  831. Dictionary ret;
  832. Vector<Size2i> rects;
  833. for (int i = 0; i < p_rects.size(); i++) {
  834. rects.push_back(p_rects[i]);
  835. }
  836. Vector<Point2i> result;
  837. Size2i size;
  838. ::Geometry2D::make_atlas(rects, result, size);
  839. Vector<Point2> r_result;
  840. for (int i = 0; i < result.size(); i++) {
  841. r_result.push_back(result[i]);
  842. }
  843. ret["points"] = r_result;
  844. ret["size"] = size;
  845. return ret;
  846. }
  847. TypedArray<Point2i> Geometry2D::bresenham_line(const Point2i &p_from, const Point2i &p_to) {
  848. Vector<Point2i> points = ::Geometry2D::bresenham_line(p_from, p_to);
  849. TypedArray<Point2i> result;
  850. result.resize(points.size());
  851. for (int i = 0; i < points.size(); i++) {
  852. result[i] = points[i];
  853. }
  854. return result;
  855. }
  856. void Geometry2D::_bind_methods() {
  857. ClassDB::bind_method(D_METHOD("is_point_in_circle", "point", "circle_position", "circle_radius"), &Geometry2D::is_point_in_circle);
  858. ClassDB::bind_method(D_METHOD("segment_intersects_circle", "segment_from", "segment_to", "circle_position", "circle_radius"), &Geometry2D::segment_intersects_circle);
  859. ClassDB::bind_method(D_METHOD("segment_intersects_segment", "from_a", "to_a", "from_b", "to_b"), &Geometry2D::segment_intersects_segment);
  860. ClassDB::bind_method(D_METHOD("line_intersects_line", "from_a", "dir_a", "from_b", "dir_b"), &Geometry2D::line_intersects_line);
  861. ClassDB::bind_method(D_METHOD("get_closest_points_between_segments", "p1", "q1", "p2", "q2"), &Geometry2D::get_closest_points_between_segments);
  862. ClassDB::bind_method(D_METHOD("get_closest_point_to_segment", "point", "s1", "s2"), &Geometry2D::get_closest_point_to_segment);
  863. ClassDB::bind_method(D_METHOD("get_closest_point_to_segment_uncapped", "point", "s1", "s2"), &Geometry2D::get_closest_point_to_segment_uncapped);
  864. ClassDB::bind_method(D_METHOD("point_is_inside_triangle", "point", "a", "b", "c"), &Geometry2D::point_is_inside_triangle);
  865. ClassDB::bind_method(D_METHOD("is_polygon_clockwise", "polygon"), &Geometry2D::is_polygon_clockwise);
  866. ClassDB::bind_method(D_METHOD("is_point_in_polygon", "point", "polygon"), &Geometry2D::is_point_in_polygon);
  867. ClassDB::bind_method(D_METHOD("triangulate_polygon", "polygon"), &Geometry2D::triangulate_polygon);
  868. ClassDB::bind_method(D_METHOD("triangulate_delaunay", "points"), &Geometry2D::triangulate_delaunay);
  869. ClassDB::bind_method(D_METHOD("convex_hull", "points"), &Geometry2D::convex_hull);
  870. ClassDB::bind_method(D_METHOD("decompose_polygon_in_convex", "polygon"), &Geometry2D::decompose_polygon_in_convex);
  871. ClassDB::bind_method(D_METHOD("merge_polygons", "polygon_a", "polygon_b"), &Geometry2D::merge_polygons);
  872. ClassDB::bind_method(D_METHOD("clip_polygons", "polygon_a", "polygon_b"), &Geometry2D::clip_polygons);
  873. ClassDB::bind_method(D_METHOD("intersect_polygons", "polygon_a", "polygon_b"), &Geometry2D::intersect_polygons);
  874. ClassDB::bind_method(D_METHOD("exclude_polygons", "polygon_a", "polygon_b"), &Geometry2D::exclude_polygons);
  875. ClassDB::bind_method(D_METHOD("clip_polyline_with_polygon", "polyline", "polygon"), &Geometry2D::clip_polyline_with_polygon);
  876. ClassDB::bind_method(D_METHOD("intersect_polyline_with_polygon", "polyline", "polygon"), &Geometry2D::intersect_polyline_with_polygon);
  877. ClassDB::bind_method(D_METHOD("offset_polygon", "polygon", "delta", "join_type"), &Geometry2D::offset_polygon, DEFVAL(JOIN_SQUARE));
  878. ClassDB::bind_method(D_METHOD("offset_polyline", "polyline", "delta", "join_type", "end_type"), &Geometry2D::offset_polyline, DEFVAL(JOIN_SQUARE), DEFVAL(END_SQUARE));
  879. ClassDB::bind_method(D_METHOD("make_atlas", "sizes"), &Geometry2D::make_atlas);
  880. ClassDB::bind_method(D_METHOD("bresenham_line", "from", "to"), &Geometry2D::bresenham_line);
  881. BIND_ENUM_CONSTANT(OPERATION_UNION);
  882. BIND_ENUM_CONSTANT(OPERATION_DIFFERENCE);
  883. BIND_ENUM_CONSTANT(OPERATION_INTERSECTION);
  884. BIND_ENUM_CONSTANT(OPERATION_XOR);
  885. BIND_ENUM_CONSTANT(JOIN_SQUARE);
  886. BIND_ENUM_CONSTANT(JOIN_ROUND);
  887. BIND_ENUM_CONSTANT(JOIN_MITER);
  888. BIND_ENUM_CONSTANT(END_POLYGON);
  889. BIND_ENUM_CONSTANT(END_JOINED);
  890. BIND_ENUM_CONSTANT(END_BUTT);
  891. BIND_ENUM_CONSTANT(END_SQUARE);
  892. BIND_ENUM_CONSTANT(END_ROUND);
  893. }
  894. ////// Geometry3D //////
  895. Geometry3D *Geometry3D::singleton = nullptr;
  896. Geometry3D *Geometry3D::get_singleton() {
  897. return singleton;
  898. }
  899. Vector<Vector3> Geometry3D::compute_convex_mesh_points(const TypedArray<Plane> &p_planes) {
  900. Vector<Plane> planes_vec;
  901. int size = p_planes.size();
  902. planes_vec.resize(size);
  903. for (int i = 0; i < size; ++i) {
  904. planes_vec.set(i, p_planes[i]);
  905. }
  906. Variant ret = ::Geometry3D::compute_convex_mesh_points(planes_vec.ptr(), size);
  907. return ret;
  908. }
  909. TypedArray<Plane> Geometry3D::build_box_planes(const Vector3 &p_extents) {
  910. Variant ret = ::Geometry3D::build_box_planes(p_extents);
  911. return ret;
  912. }
  913. TypedArray<Plane> Geometry3D::build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis) {
  914. Variant ret = ::Geometry3D::build_cylinder_planes(p_radius, p_height, p_sides, p_axis);
  915. return ret;
  916. }
  917. TypedArray<Plane> Geometry3D::build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis) {
  918. Variant ret = ::Geometry3D::build_capsule_planes(p_radius, p_height, p_sides, p_lats, p_axis);
  919. return ret;
  920. }
  921. Vector<Vector3> Geometry3D::get_closest_points_between_segments(const Vector3 &p1, const Vector3 &p2, const Vector3 &q1, const Vector3 &q2) {
  922. Vector3 r1, r2;
  923. ::Geometry3D::get_closest_points_between_segments(p1, p2, q1, q2, r1, r2);
  924. Vector<Vector3> r = { r1, r2 };
  925. return r;
  926. }
  927. Vector3 Geometry3D::get_closest_point_to_segment(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b) {
  928. Vector3 s[2] = { p_a, p_b };
  929. return ::Geometry3D::get_closest_point_to_segment(p_point, s);
  930. }
  931. Vector3 Geometry3D::get_closest_point_to_segment_uncapped(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b) {
  932. Vector3 s[2] = { p_a, p_b };
  933. return ::Geometry3D::get_closest_point_to_segment_uncapped(p_point, s);
  934. }
  935. Vector3 Geometry3D::get_triangle_barycentric_coords(const Vector3 &p_point, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2) {
  936. Vector3 res = ::Geometry3D::triangle_get_barycentric_coords(p_v0, p_v1, p_v2, p_point);
  937. return res;
  938. }
  939. Variant Geometry3D::ray_intersects_triangle(const Vector3 &p_from, const Vector3 &p_dir, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2) {
  940. Vector3 res;
  941. if (::Geometry3D::ray_intersects_triangle(p_from, p_dir, p_v0, p_v1, p_v2, &res)) {
  942. return res;
  943. } else {
  944. return Variant();
  945. }
  946. }
  947. Variant Geometry3D::segment_intersects_triangle(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2) {
  948. Vector3 res;
  949. if (::Geometry3D::segment_intersects_triangle(p_from, p_to, p_v0, p_v1, p_v2, &res)) {
  950. return res;
  951. } else {
  952. return Variant();
  953. }
  954. }
  955. Vector<Vector3> Geometry3D::segment_intersects_sphere(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_sphere_pos, real_t p_sphere_radius) {
  956. Vector<Vector3> r;
  957. Vector3 res, norm;
  958. if (!::Geometry3D::segment_intersects_sphere(p_from, p_to, p_sphere_pos, p_sphere_radius, &res, &norm)) {
  959. return r;
  960. }
  961. r.resize(2);
  962. r.set(0, res);
  963. r.set(1, norm);
  964. return r;
  965. }
  966. Vector<Vector3> Geometry3D::segment_intersects_cylinder(const Vector3 &p_from, const Vector3 &p_to, float p_height, float p_radius) {
  967. Vector<Vector3> r;
  968. Vector3 res, norm;
  969. if (!::Geometry3D::segment_intersects_cylinder(p_from, p_to, p_height, p_radius, &res, &norm)) {
  970. return r;
  971. }
  972. r.resize(2);
  973. r.set(0, res);
  974. r.set(1, norm);
  975. return r;
  976. }
  977. Vector<Vector3> Geometry3D::segment_intersects_convex(const Vector3 &p_from, const Vector3 &p_to, const TypedArray<Plane> &p_planes) {
  978. Vector<Vector3> r;
  979. Vector3 res, norm;
  980. Vector<Plane> planes = Variant(p_planes);
  981. if (!::Geometry3D::segment_intersects_convex(p_from, p_to, planes.ptr(), planes.size(), &res, &norm)) {
  982. return r;
  983. }
  984. r.resize(2);
  985. r.set(0, res);
  986. r.set(1, norm);
  987. return r;
  988. }
  989. Vector<Vector3> Geometry3D::clip_polygon(const Vector<Vector3> &p_points, const Plane &p_plane) {
  990. return ::Geometry3D::clip_polygon(p_points, p_plane);
  991. }
  992. Vector<int32_t> Geometry3D::tetrahedralize_delaunay(const Vector<Vector3> &p_points) {
  993. return ::Geometry3D::tetrahedralize_delaunay(p_points);
  994. }
  995. void Geometry3D::_bind_methods() {
  996. ClassDB::bind_method(D_METHOD("compute_convex_mesh_points", "planes"), &Geometry3D::compute_convex_mesh_points);
  997. ClassDB::bind_method(D_METHOD("build_box_planes", "extents"), &Geometry3D::build_box_planes);
  998. ClassDB::bind_method(D_METHOD("build_cylinder_planes", "radius", "height", "sides", "axis"), &Geometry3D::build_cylinder_planes, DEFVAL(Vector3::AXIS_Z));
  999. ClassDB::bind_method(D_METHOD("build_capsule_planes", "radius", "height", "sides", "lats", "axis"), &Geometry3D::build_capsule_planes, DEFVAL(Vector3::AXIS_Z));
  1000. ClassDB::bind_method(D_METHOD("get_closest_points_between_segments", "p1", "p2", "q1", "q2"), &Geometry3D::get_closest_points_between_segments);
  1001. ClassDB::bind_method(D_METHOD("get_closest_point_to_segment", "point", "s1", "s2"), &Geometry3D::get_closest_point_to_segment);
  1002. ClassDB::bind_method(D_METHOD("get_closest_point_to_segment_uncapped", "point", "s1", "s2"), &Geometry3D::get_closest_point_to_segment_uncapped);
  1003. ClassDB::bind_method(D_METHOD("get_triangle_barycentric_coords", "point", "a", "b", "c"), &Geometry3D::get_triangle_barycentric_coords);
  1004. ClassDB::bind_method(D_METHOD("ray_intersects_triangle", "from", "dir", "a", "b", "c"), &Geometry3D::ray_intersects_triangle);
  1005. ClassDB::bind_method(D_METHOD("segment_intersects_triangle", "from", "to", "a", "b", "c"), &Geometry3D::segment_intersects_triangle);
  1006. ClassDB::bind_method(D_METHOD("segment_intersects_sphere", "from", "to", "sphere_position", "sphere_radius"), &Geometry3D::segment_intersects_sphere);
  1007. ClassDB::bind_method(D_METHOD("segment_intersects_cylinder", "from", "to", "height", "radius"), &Geometry3D::segment_intersects_cylinder);
  1008. ClassDB::bind_method(D_METHOD("segment_intersects_convex", "from", "to", "planes"), &Geometry3D::segment_intersects_convex);
  1009. ClassDB::bind_method(D_METHOD("clip_polygon", "points", "plane"), &Geometry3D::clip_polygon);
  1010. ClassDB::bind_method(D_METHOD("tetrahedralize_delaunay", "points"), &Geometry3D::tetrahedralize_delaunay);
  1011. }
  1012. ////// Marshalls //////
  1013. Marshalls *Marshalls::singleton = nullptr;
  1014. Marshalls *Marshalls::get_singleton() {
  1015. return singleton;
  1016. }
  1017. String Marshalls::variant_to_base64(const Variant &p_var, bool p_full_objects) {
  1018. int len;
  1019. Error err = encode_variant(p_var, nullptr, len, p_full_objects);
  1020. ERR_FAIL_COND_V_MSG(err != OK, "", "Error when trying to encode Variant.");
  1021. Vector<uint8_t> buff;
  1022. buff.resize(len);
  1023. uint8_t *w = buff.ptrw();
  1024. err = encode_variant(p_var, &w[0], len, p_full_objects);
  1025. ERR_FAIL_COND_V_MSG(err != OK, "", "Error when trying to encode Variant.");
  1026. String ret = CryptoCore::b64_encode_str(&w[0], len);
  1027. ERR_FAIL_COND_V(ret.is_empty(), ret);
  1028. return ret;
  1029. }
  1030. Variant Marshalls::base64_to_variant(const String &p_str, bool p_allow_objects) {
  1031. int strlen = p_str.length();
  1032. CharString cstr = p_str.ascii();
  1033. Vector<uint8_t> buf;
  1034. buf.resize(strlen / 4 * 3 + 1);
  1035. uint8_t *w = buf.ptrw();
  1036. size_t len = 0;
  1037. ERR_FAIL_COND_V(CryptoCore::b64_decode(&w[0], buf.size(), &len, (unsigned char *)cstr.get_data(), strlen) != OK, Variant());
  1038. Variant v;
  1039. Error err = decode_variant(v, &w[0], len, nullptr, p_allow_objects);
  1040. ERR_FAIL_COND_V_MSG(err != OK, Variant(), "Error when trying to decode Variant.");
  1041. return v;
  1042. }
  1043. String Marshalls::raw_to_base64(const Vector<uint8_t> &p_arr) {
  1044. String ret = CryptoCore::b64_encode_str(p_arr.ptr(), p_arr.size());
  1045. ERR_FAIL_COND_V(ret.is_empty(), ret);
  1046. return ret;
  1047. }
  1048. Vector<uint8_t> Marshalls::base64_to_raw(const String &p_str) {
  1049. int strlen = p_str.length();
  1050. CharString cstr = p_str.ascii();
  1051. size_t arr_len = 0;
  1052. Vector<uint8_t> buf;
  1053. {
  1054. buf.resize(strlen / 4 * 3 + 1);
  1055. uint8_t *w = buf.ptrw();
  1056. ERR_FAIL_COND_V(CryptoCore::b64_decode(&w[0], buf.size(), &arr_len, (unsigned char *)cstr.get_data(), strlen) != OK, Vector<uint8_t>());
  1057. }
  1058. buf.resize(arr_len);
  1059. return buf;
  1060. }
  1061. String Marshalls::utf8_to_base64(const String &p_str) {
  1062. if (p_str.is_empty()) {
  1063. return String();
  1064. }
  1065. CharString cstr = p_str.utf8();
  1066. String ret = CryptoCore::b64_encode_str((unsigned char *)cstr.get_data(), cstr.length());
  1067. ERR_FAIL_COND_V(ret.is_empty(), ret);
  1068. return ret;
  1069. }
  1070. String Marshalls::base64_to_utf8(const String &p_str) {
  1071. int strlen = p_str.length();
  1072. CharString cstr = p_str.ascii();
  1073. Vector<uint8_t> buf;
  1074. buf.resize(strlen / 4 * 3 + 1 + 1);
  1075. uint8_t *w = buf.ptrw();
  1076. size_t len = 0;
  1077. ERR_FAIL_COND_V(CryptoCore::b64_decode(&w[0], buf.size(), &len, (unsigned char *)cstr.get_data(), strlen) != OK, String());
  1078. w[len] = 0;
  1079. String ret = String::utf8((char *)&w[0]);
  1080. return ret;
  1081. }
  1082. void Marshalls::_bind_methods() {
  1083. ClassDB::bind_method(D_METHOD("variant_to_base64", "variant", "full_objects"), &Marshalls::variant_to_base64, DEFVAL(false));
  1084. ClassDB::bind_method(D_METHOD("base64_to_variant", "base64_str", "allow_objects"), &Marshalls::base64_to_variant, DEFVAL(false));
  1085. ClassDB::bind_method(D_METHOD("raw_to_base64", "array"), &Marshalls::raw_to_base64);
  1086. ClassDB::bind_method(D_METHOD("base64_to_raw", "base64_str"), &Marshalls::base64_to_raw);
  1087. ClassDB::bind_method(D_METHOD("utf8_to_base64", "utf8_str"), &Marshalls::utf8_to_base64);
  1088. ClassDB::bind_method(D_METHOD("base64_to_utf8", "base64_str"), &Marshalls::base64_to_utf8);
  1089. }
  1090. ////// Semaphore //////
  1091. void Semaphore::wait() {
  1092. semaphore.wait();
  1093. }
  1094. bool Semaphore::try_wait() {
  1095. return semaphore.try_wait();
  1096. }
  1097. void Semaphore::post(int p_count) {
  1098. ERR_FAIL_COND(p_count <= 0);
  1099. semaphore.post(p_count);
  1100. }
  1101. void Semaphore::_bind_methods() {
  1102. ClassDB::bind_method(D_METHOD("wait"), &Semaphore::wait);
  1103. ClassDB::bind_method(D_METHOD("try_wait"), &Semaphore::try_wait);
  1104. ClassDB::bind_method(D_METHOD("post", "count"), &Semaphore::post, DEFVAL(1));
  1105. }
  1106. ////// Mutex //////
  1107. void Mutex::lock() {
  1108. mutex.lock();
  1109. }
  1110. bool Mutex::try_lock() {
  1111. return mutex.try_lock();
  1112. }
  1113. void Mutex::unlock() {
  1114. mutex.unlock();
  1115. }
  1116. void Mutex::_bind_methods() {
  1117. ClassDB::bind_method(D_METHOD("lock"), &Mutex::lock);
  1118. ClassDB::bind_method(D_METHOD("try_lock"), &Mutex::try_lock);
  1119. ClassDB::bind_method(D_METHOD("unlock"), &Mutex::unlock);
  1120. }
  1121. ////// Thread //////
  1122. void Thread::_start_func(void *ud) {
  1123. Ref<Thread> *tud = (Ref<Thread> *)ud;
  1124. Ref<Thread> t = *tud;
  1125. memdelete(tud);
  1126. if (!t->target_callable.is_valid()) {
  1127. t->running.clear();
  1128. ERR_FAIL_MSG(vformat("Could not call function '%s' on previously freed instance to start thread %s.", t->target_callable.get_method(), t->get_id()));
  1129. }
  1130. // Finding out a suitable name for the thread can involve querying a node, if the target is one.
  1131. // We know this is safe (unless the user is causing life cycle race conditions, which would be a bug on their part).
  1132. set_current_thread_safe_for_nodes(true);
  1133. String func_name = t->target_callable.is_custom() ? t->target_callable.get_custom()->get_as_text() : String(t->target_callable.get_method());
  1134. set_current_thread_safe_for_nodes(false);
  1135. ::Thread::set_name(func_name);
  1136. // To avoid a circular reference between the thread and the script which can possibly contain a reference
  1137. // to the thread, we will do the call (keeping a reference up to that point) and then break chains with it.
  1138. // When the call returns, we will reference the thread again if possible.
  1139. ObjectID th_instance_id = t->get_instance_id();
  1140. Callable target_callable = t->target_callable;
  1141. t = Ref<Thread>();
  1142. Callable::CallError ce;
  1143. Variant ret;
  1144. target_callable.callp(nullptr, 0, ret, ce);
  1145. // If script properly kept a reference to the thread, we should be able to re-reference it now
  1146. // (well, or if the call failed, since we had to break chains anyway because the outcome isn't known upfront).
  1147. t = Ref<Thread>(ObjectDB::get_instance(th_instance_id));
  1148. if (t.is_valid()) {
  1149. t->ret = ret;
  1150. t->running.clear();
  1151. } else {
  1152. // We could print a warning here, but the Thread object will be eventually destroyed
  1153. // noticing wait_to_finish() hasn't been called on it, and it will print a warning itself.
  1154. }
  1155. if (ce.error != Callable::CallError::CALL_OK) {
  1156. ERR_FAIL_MSG(vformat("Could not call function '%s' to start thread %d: %s.", func_name, t->get_id(), Variant::get_callable_error_text(t->target_callable, nullptr, 0, ce)));
  1157. }
  1158. }
  1159. Error Thread::start(const Callable &p_callable, Priority p_priority) {
  1160. ERR_FAIL_COND_V_MSG(is_started(), ERR_ALREADY_IN_USE, "Thread already started.");
  1161. ERR_FAIL_COND_V(!p_callable.is_valid(), ERR_INVALID_PARAMETER);
  1162. ERR_FAIL_INDEX_V(p_priority, PRIORITY_MAX, ERR_INVALID_PARAMETER);
  1163. ret = Variant();
  1164. target_callable = p_callable;
  1165. running.set();
  1166. Ref<Thread> *ud = memnew(Ref<Thread>(this));
  1167. ::Thread::Settings s;
  1168. s.priority = (::Thread::Priority)p_priority;
  1169. thread.start(_start_func, ud, s);
  1170. return OK;
  1171. }
  1172. String Thread::get_id() const {
  1173. return itos(thread.get_id());
  1174. }
  1175. bool Thread::is_started() const {
  1176. return thread.is_started();
  1177. }
  1178. bool Thread::is_alive() const {
  1179. return running.is_set();
  1180. }
  1181. Variant Thread::wait_to_finish() {
  1182. ERR_FAIL_COND_V_MSG(!is_started(), Variant(), "Thread must have been started to wait for its completion.");
  1183. thread.wait_to_finish();
  1184. Variant r = ret;
  1185. target_callable = Callable();
  1186. return r;
  1187. }
  1188. void Thread::set_thread_safety_checks_enabled(bool p_enabled) {
  1189. ERR_FAIL_COND_MSG(::Thread::is_main_thread(), "This call is forbidden on the main thread.");
  1190. set_current_thread_safe_for_nodes(!p_enabled);
  1191. }
  1192. void Thread::_bind_methods() {
  1193. ClassDB::bind_method(D_METHOD("start", "callable", "priority"), &Thread::start, DEFVAL(PRIORITY_NORMAL));
  1194. ClassDB::bind_method(D_METHOD("get_id"), &Thread::get_id);
  1195. ClassDB::bind_method(D_METHOD("is_started"), &Thread::is_started);
  1196. ClassDB::bind_method(D_METHOD("is_alive"), &Thread::is_alive);
  1197. ClassDB::bind_method(D_METHOD("wait_to_finish"), &Thread::wait_to_finish);
  1198. ClassDB::bind_static_method("Thread", D_METHOD("set_thread_safety_checks_enabled", "enabled"), &Thread::set_thread_safety_checks_enabled);
  1199. BIND_ENUM_CONSTANT(PRIORITY_LOW);
  1200. BIND_ENUM_CONSTANT(PRIORITY_NORMAL);
  1201. BIND_ENUM_CONSTANT(PRIORITY_HIGH);
  1202. }
  1203. namespace Special {
  1204. ////// ClassDB //////
  1205. PackedStringArray ClassDB::get_class_list() const {
  1206. List<StringName> classes;
  1207. ::ClassDB::get_class_list(&classes);
  1208. PackedStringArray ret;
  1209. ret.resize(classes.size());
  1210. int idx = 0;
  1211. for (const StringName &E : classes) {
  1212. ret.set(idx++, E);
  1213. }
  1214. return ret;
  1215. }
  1216. PackedStringArray ClassDB::get_inheriters_from_class(const StringName &p_class) const {
  1217. List<StringName> classes;
  1218. ::ClassDB::get_inheriters_from_class(p_class, &classes);
  1219. PackedStringArray ret;
  1220. ret.resize(classes.size());
  1221. int idx = 0;
  1222. for (const StringName &E : classes) {
  1223. ret.set(idx++, E);
  1224. }
  1225. return ret;
  1226. }
  1227. StringName ClassDB::get_parent_class(const StringName &p_class) const {
  1228. return ::ClassDB::get_parent_class(p_class);
  1229. }
  1230. bool ClassDB::class_exists(const StringName &p_class) const {
  1231. return ::ClassDB::class_exists(p_class);
  1232. }
  1233. bool ClassDB::is_parent_class(const StringName &p_class, const StringName &p_inherits) const {
  1234. return ::ClassDB::is_parent_class(p_class, p_inherits);
  1235. }
  1236. bool ClassDB::can_instantiate(const StringName &p_class) const {
  1237. return ::ClassDB::can_instantiate(p_class);
  1238. }
  1239. Variant ClassDB::instantiate(const StringName &p_class) const {
  1240. Object *obj = ::ClassDB::instantiate(p_class);
  1241. if (!obj) {
  1242. return Variant();
  1243. }
  1244. RefCounted *r = Object::cast_to<RefCounted>(obj);
  1245. if (r) {
  1246. return Ref<RefCounted>(r);
  1247. } else {
  1248. return obj;
  1249. }
  1250. }
  1251. ClassDB::APIType ClassDB::class_get_api_type(const StringName &p_class) const {
  1252. ::ClassDB::APIType api_type = ::ClassDB::get_api_type(p_class);
  1253. return (APIType)api_type;
  1254. }
  1255. bool ClassDB::class_has_signal(const StringName &p_class, const StringName &p_signal) const {
  1256. return ::ClassDB::has_signal(p_class, p_signal);
  1257. }
  1258. Dictionary ClassDB::class_get_signal(const StringName &p_class, const StringName &p_signal) const {
  1259. MethodInfo signal;
  1260. if (::ClassDB::get_signal(p_class, p_signal, &signal)) {
  1261. return signal.operator Dictionary();
  1262. } else {
  1263. return Dictionary();
  1264. }
  1265. }
  1266. TypedArray<Dictionary> ClassDB::class_get_signal_list(const StringName &p_class, bool p_no_inheritance) const {
  1267. List<MethodInfo> signals;
  1268. ::ClassDB::get_signal_list(p_class, &signals, p_no_inheritance);
  1269. TypedArray<Dictionary> ret;
  1270. for (const MethodInfo &E : signals) {
  1271. ret.push_back(E.operator Dictionary());
  1272. }
  1273. return ret;
  1274. }
  1275. TypedArray<Dictionary> ClassDB::class_get_property_list(const StringName &p_class, bool p_no_inheritance) const {
  1276. List<PropertyInfo> plist;
  1277. ::ClassDB::get_property_list(p_class, &plist, p_no_inheritance);
  1278. TypedArray<Dictionary> ret;
  1279. for (const PropertyInfo &E : plist) {
  1280. ret.push_back(E.operator Dictionary());
  1281. }
  1282. return ret;
  1283. }
  1284. StringName ClassDB::class_get_property_getter(const StringName &p_class, const StringName &p_property) {
  1285. return ::ClassDB::get_property_getter(p_class, p_property);
  1286. }
  1287. StringName ClassDB::class_get_property_setter(const StringName &p_class, const StringName &p_property) {
  1288. return ::ClassDB::get_property_setter(p_class, p_property);
  1289. }
  1290. Variant ClassDB::class_get_property(Object *p_object, const StringName &p_property) const {
  1291. Variant ret;
  1292. ::ClassDB::get_property(p_object, p_property, ret);
  1293. return ret;
  1294. }
  1295. Error ClassDB::class_set_property(Object *p_object, const StringName &p_property, const Variant &p_value) const {
  1296. Variant ret;
  1297. bool valid;
  1298. if (!::ClassDB::set_property(p_object, p_property, p_value, &valid)) {
  1299. return ERR_UNAVAILABLE;
  1300. } else if (!valid) {
  1301. return ERR_INVALID_DATA;
  1302. }
  1303. return OK;
  1304. }
  1305. Variant ClassDB::class_get_property_default_value(const StringName &p_class, const StringName &p_property) const {
  1306. bool valid;
  1307. Variant ret = ::ClassDB::class_get_default_property_value(p_class, p_property, &valid);
  1308. if (valid) {
  1309. return ret;
  1310. }
  1311. return Variant();
  1312. }
  1313. bool ClassDB::class_has_method(const StringName &p_class, const StringName &p_method, bool p_no_inheritance) const {
  1314. return ::ClassDB::has_method(p_class, p_method, p_no_inheritance);
  1315. }
  1316. int ClassDB::class_get_method_argument_count(const StringName &p_class, const StringName &p_method, bool p_no_inheritance) const {
  1317. return ::ClassDB::get_method_argument_count(p_class, p_method, nullptr, p_no_inheritance);
  1318. }
  1319. TypedArray<Dictionary> ClassDB::class_get_method_list(const StringName &p_class, bool p_no_inheritance) const {
  1320. List<MethodInfo> methods;
  1321. ::ClassDB::get_method_list(p_class, &methods, p_no_inheritance);
  1322. TypedArray<Dictionary> ret;
  1323. for (const MethodInfo &E : methods) {
  1324. #ifdef DEBUG_METHODS_ENABLED
  1325. ret.push_back(E.operator Dictionary());
  1326. #else
  1327. Dictionary dict;
  1328. dict["name"] = E.name;
  1329. ret.push_back(dict);
  1330. #endif
  1331. }
  1332. return ret;
  1333. }
  1334. Variant ClassDB::class_call_static(const Variant **p_arguments, int p_argcount, Callable::CallError &r_call_error) {
  1335. if (p_argcount < 2) {
  1336. r_call_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  1337. return Variant::NIL;
  1338. }
  1339. if (!p_arguments[0]->is_string() || !p_arguments[1]->is_string()) {
  1340. r_call_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
  1341. return Variant::NIL;
  1342. }
  1343. StringName class_ = *p_arguments[0];
  1344. StringName method = *p_arguments[1];
  1345. const MethodBind *bind = ::ClassDB::get_method(class_, method);
  1346. ERR_FAIL_NULL_V_MSG(bind, Variant::NIL, "Cannot find static method.");
  1347. ERR_FAIL_COND_V_MSG(!bind->is_static(), Variant::NIL, "Method is not static.");
  1348. return bind->call(nullptr, p_arguments + 2, p_argcount - 2, r_call_error);
  1349. }
  1350. PackedStringArray ClassDB::class_get_integer_constant_list(const StringName &p_class, bool p_no_inheritance) const {
  1351. List<String> constants;
  1352. ::ClassDB::get_integer_constant_list(p_class, &constants, p_no_inheritance);
  1353. PackedStringArray ret;
  1354. ret.resize(constants.size());
  1355. int idx = 0;
  1356. for (const String &E : constants) {
  1357. ret.set(idx++, E);
  1358. }
  1359. return ret;
  1360. }
  1361. bool ClassDB::class_has_integer_constant(const StringName &p_class, const StringName &p_name) const {
  1362. bool success;
  1363. ::ClassDB::get_integer_constant(p_class, p_name, &success);
  1364. return success;
  1365. }
  1366. int64_t ClassDB::class_get_integer_constant(const StringName &p_class, const StringName &p_name) const {
  1367. bool found;
  1368. int64_t c = ::ClassDB::get_integer_constant(p_class, p_name, &found);
  1369. ERR_FAIL_COND_V(!found, 0);
  1370. return c;
  1371. }
  1372. bool ClassDB::class_has_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance) const {
  1373. return ::ClassDB::has_enum(p_class, p_name, p_no_inheritance);
  1374. }
  1375. PackedStringArray ClassDB::class_get_enum_list(const StringName &p_class, bool p_no_inheritance) const {
  1376. List<StringName> enums;
  1377. ::ClassDB::get_enum_list(p_class, &enums, p_no_inheritance);
  1378. PackedStringArray ret;
  1379. ret.resize(enums.size());
  1380. int idx = 0;
  1381. for (const StringName &E : enums) {
  1382. ret.set(idx++, E);
  1383. }
  1384. return ret;
  1385. }
  1386. PackedStringArray ClassDB::class_get_enum_constants(const StringName &p_class, const StringName &p_enum, bool p_no_inheritance) const {
  1387. List<StringName> constants;
  1388. ::ClassDB::get_enum_constants(p_class, p_enum, &constants, p_no_inheritance);
  1389. PackedStringArray ret;
  1390. ret.resize(constants.size());
  1391. int idx = 0;
  1392. for (const StringName &E : constants) {
  1393. ret.set(idx++, E);
  1394. }
  1395. return ret;
  1396. }
  1397. StringName ClassDB::class_get_integer_constant_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance) const {
  1398. return ::ClassDB::get_integer_constant_enum(p_class, p_name, p_no_inheritance);
  1399. }
  1400. bool ClassDB::is_class_enum_bitfield(const StringName &p_class, const StringName &p_enum, bool p_no_inheritance) const {
  1401. return ::ClassDB::is_enum_bitfield(p_class, p_enum, p_no_inheritance);
  1402. }
  1403. bool ClassDB::is_class_enabled(const StringName &p_class) const {
  1404. return ::ClassDB::is_class_enabled(p_class);
  1405. }
  1406. #ifdef TOOLS_ENABLED
  1407. void ClassDB::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
  1408. const String pf = p_function;
  1409. bool first_argument_is_class = false;
  1410. if (p_idx == 0) {
  1411. first_argument_is_class = (pf == "get_inheriters_from_class" || pf == "get_parent_class" ||
  1412. pf == "class_exists" || pf == "can_instantiate" || pf == "instantiate" ||
  1413. pf == "class_has_signal" || pf == "class_get_signal" || pf == "class_get_signal_list" ||
  1414. pf == "class_get_property_list" || pf == "class_get_property" || pf == "class_set_property" ||
  1415. pf == "class_has_method" || pf == "class_get_method_list" ||
  1416. pf == "class_get_integer_constant_list" || pf == "class_has_integer_constant" || pf == "class_get_integer_constant" ||
  1417. pf == "class_has_enum" || pf == "class_get_enum_list" || pf == "class_get_enum_constants" || pf == "class_get_integer_constant_enum" ||
  1418. pf == "is_class_enabled" || pf == "is_class_enum_bitfield" || pf == "class_get_api_type");
  1419. }
  1420. if (first_argument_is_class || pf == "is_parent_class") {
  1421. for (const String &E : get_class_list()) {
  1422. r_options->push_back(E.quote());
  1423. }
  1424. }
  1425. Object::get_argument_options(p_function, p_idx, r_options);
  1426. }
  1427. #endif
  1428. void ClassDB::_bind_methods() {
  1429. ::ClassDB::bind_method(D_METHOD("get_class_list"), &ClassDB::get_class_list);
  1430. ::ClassDB::bind_method(D_METHOD("get_inheriters_from_class", "class"), &ClassDB::get_inheriters_from_class);
  1431. ::ClassDB::bind_method(D_METHOD("get_parent_class", "class"), &ClassDB::get_parent_class);
  1432. ::ClassDB::bind_method(D_METHOD("class_exists", "class"), &ClassDB::class_exists);
  1433. ::ClassDB::bind_method(D_METHOD("is_parent_class", "class", "inherits"), &ClassDB::is_parent_class);
  1434. ::ClassDB::bind_method(D_METHOD("can_instantiate", "class"), &ClassDB::can_instantiate);
  1435. ::ClassDB::bind_method(D_METHOD("instantiate", "class"), &ClassDB::instantiate);
  1436. ::ClassDB::bind_method(D_METHOD("class_get_api_type", "class"), &ClassDB::class_get_api_type);
  1437. ::ClassDB::bind_method(D_METHOD("class_has_signal", "class", "signal"), &ClassDB::class_has_signal);
  1438. ::ClassDB::bind_method(D_METHOD("class_get_signal", "class", "signal"), &ClassDB::class_get_signal);
  1439. ::ClassDB::bind_method(D_METHOD("class_get_signal_list", "class", "no_inheritance"), &ClassDB::class_get_signal_list, DEFVAL(false));
  1440. ::ClassDB::bind_method(D_METHOD("class_get_property_list", "class", "no_inheritance"), &ClassDB::class_get_property_list, DEFVAL(false));
  1441. ::ClassDB::bind_method(D_METHOD("class_get_property_getter", "class", "property"), &ClassDB::class_get_property_getter);
  1442. ::ClassDB::bind_method(D_METHOD("class_get_property_setter", "class", "property"), &ClassDB::class_get_property_setter);
  1443. ::ClassDB::bind_method(D_METHOD("class_get_property", "object", "property"), &ClassDB::class_get_property);
  1444. ::ClassDB::bind_method(D_METHOD("class_set_property", "object", "property", "value"), &ClassDB::class_set_property);
  1445. ::ClassDB::bind_method(D_METHOD("class_get_property_default_value", "class", "property"), &ClassDB::class_get_property_default_value);
  1446. ::ClassDB::bind_method(D_METHOD("class_has_method", "class", "method", "no_inheritance"), &ClassDB::class_has_method, DEFVAL(false));
  1447. ::ClassDB::bind_method(D_METHOD("class_get_method_argument_count", "class", "method", "no_inheritance"), &ClassDB::class_get_method_argument_count, DEFVAL(false));
  1448. ::ClassDB::bind_method(D_METHOD("class_get_method_list", "class", "no_inheritance"), &ClassDB::class_get_method_list, DEFVAL(false));
  1449. ::ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "class_call_static", &ClassDB::class_call_static, MethodInfo("class_call_static", PropertyInfo(Variant::STRING_NAME, "class"), PropertyInfo(Variant::STRING_NAME, "method")));
  1450. ::ClassDB::bind_method(D_METHOD("class_get_integer_constant_list", "class", "no_inheritance"), &ClassDB::class_get_integer_constant_list, DEFVAL(false));
  1451. ::ClassDB::bind_method(D_METHOD("class_has_integer_constant", "class", "name"), &ClassDB::class_has_integer_constant);
  1452. ::ClassDB::bind_method(D_METHOD("class_get_integer_constant", "class", "name"), &ClassDB::class_get_integer_constant);
  1453. ::ClassDB::bind_method(D_METHOD("class_has_enum", "class", "name", "no_inheritance"), &ClassDB::class_has_enum, DEFVAL(false));
  1454. ::ClassDB::bind_method(D_METHOD("class_get_enum_list", "class", "no_inheritance"), &ClassDB::class_get_enum_list, DEFVAL(false));
  1455. ::ClassDB::bind_method(D_METHOD("class_get_enum_constants", "class", "enum", "no_inheritance"), &ClassDB::class_get_enum_constants, DEFVAL(false));
  1456. ::ClassDB::bind_method(D_METHOD("class_get_integer_constant_enum", "class", "name", "no_inheritance"), &ClassDB::class_get_integer_constant_enum, DEFVAL(false));
  1457. ::ClassDB::bind_method(D_METHOD("is_class_enum_bitfield", "class", "enum", "no_inheritance"), &ClassDB::is_class_enum_bitfield, DEFVAL(false));
  1458. ::ClassDB::bind_method(D_METHOD("is_class_enabled", "class"), &ClassDB::is_class_enabled);
  1459. BIND_ENUM_CONSTANT(API_CORE);
  1460. BIND_ENUM_CONSTANT(API_EDITOR);
  1461. BIND_ENUM_CONSTANT(API_EXTENSION);
  1462. BIND_ENUM_CONSTANT(API_EDITOR_EXTENSION);
  1463. BIND_ENUM_CONSTANT(API_NONE);
  1464. }
  1465. } // namespace Special
  1466. ////// Engine //////
  1467. void Engine::set_physics_ticks_per_second(int p_ips) {
  1468. ::Engine::get_singleton()->set_physics_ticks_per_second(p_ips);
  1469. }
  1470. int Engine::get_physics_ticks_per_second() const {
  1471. return ::Engine::get_singleton()->get_physics_ticks_per_second();
  1472. }
  1473. void Engine::set_max_physics_steps_per_frame(int p_max_physics_steps) {
  1474. ::Engine::get_singleton()->set_max_physics_steps_per_frame(p_max_physics_steps);
  1475. }
  1476. int Engine::get_max_physics_steps_per_frame() const {
  1477. return ::Engine::get_singleton()->get_max_physics_steps_per_frame();
  1478. }
  1479. void Engine::set_physics_jitter_fix(double p_threshold) {
  1480. ::Engine::get_singleton()->set_physics_jitter_fix(p_threshold);
  1481. }
  1482. double Engine::get_physics_jitter_fix() const {
  1483. return ::Engine::get_singleton()->get_physics_jitter_fix();
  1484. }
  1485. double Engine::get_physics_interpolation_fraction() const {
  1486. return ::Engine::get_singleton()->get_physics_interpolation_fraction();
  1487. }
  1488. void Engine::set_max_fps(int p_fps) {
  1489. ::Engine::get_singleton()->set_max_fps(p_fps);
  1490. }
  1491. int Engine::get_max_fps() const {
  1492. return ::Engine::get_singleton()->get_max_fps();
  1493. }
  1494. double Engine::get_frames_per_second() const {
  1495. return ::Engine::get_singleton()->get_frames_per_second();
  1496. }
  1497. uint64_t Engine::get_physics_frames() const {
  1498. return ::Engine::get_singleton()->get_physics_frames();
  1499. }
  1500. uint64_t Engine::get_process_frames() const {
  1501. return ::Engine::get_singleton()->get_process_frames();
  1502. }
  1503. void Engine::set_time_scale(double p_scale) {
  1504. ::Engine::get_singleton()->set_time_scale(p_scale);
  1505. }
  1506. double Engine::get_time_scale() {
  1507. return ::Engine::get_singleton()->get_time_scale();
  1508. }
  1509. int Engine::get_frames_drawn() {
  1510. return ::Engine::get_singleton()->get_frames_drawn();
  1511. }
  1512. MainLoop *Engine::get_main_loop() const {
  1513. // Needs to remain in OS, since it's actually OS that interacts with it, but it's better exposed here
  1514. return ::OS::get_singleton()->get_main_loop();
  1515. }
  1516. Dictionary Engine::get_version_info() const {
  1517. return ::Engine::get_singleton()->get_version_info();
  1518. }
  1519. Dictionary Engine::get_author_info() const {
  1520. return ::Engine::get_singleton()->get_author_info();
  1521. }
  1522. TypedArray<Dictionary> Engine::get_copyright_info() const {
  1523. return ::Engine::get_singleton()->get_copyright_info();
  1524. }
  1525. Dictionary Engine::get_donor_info() const {
  1526. return ::Engine::get_singleton()->get_donor_info();
  1527. }
  1528. Dictionary Engine::get_license_info() const {
  1529. return ::Engine::get_singleton()->get_license_info();
  1530. }
  1531. String Engine::get_license_text() const {
  1532. return ::Engine::get_singleton()->get_license_text();
  1533. }
  1534. String Engine::get_architecture_name() const {
  1535. return ::Engine::get_singleton()->get_architecture_name();
  1536. }
  1537. bool Engine::is_in_physics_frame() const {
  1538. return ::Engine::get_singleton()->is_in_physics_frame();
  1539. }
  1540. bool Engine::has_singleton(const StringName &p_name) const {
  1541. return ::Engine::get_singleton()->has_singleton(p_name);
  1542. }
  1543. Object *Engine::get_singleton_object(const StringName &p_name) const {
  1544. return ::Engine::get_singleton()->get_singleton_object(p_name);
  1545. }
  1546. void Engine::register_singleton(const StringName &p_name, Object *p_object) {
  1547. ERR_FAIL_COND_MSG(has_singleton(p_name), vformat("Singleton already registered: '%s'.", String(p_name)));
  1548. ERR_FAIL_COND_MSG(!String(p_name).is_valid_ascii_identifier(), vformat("Singleton name is not a valid identifier: '%s'.", p_name));
  1549. ::Engine::Singleton s;
  1550. s.class_name = p_name;
  1551. s.name = p_name;
  1552. s.ptr = p_object;
  1553. s.user_created = true;
  1554. ::Engine::get_singleton()->add_singleton(s);
  1555. }
  1556. void Engine::unregister_singleton(const StringName &p_name) {
  1557. ERR_FAIL_COND_MSG(!has_singleton(p_name), vformat("Attempt to remove unregistered singleton: '%s'.", String(p_name)));
  1558. ERR_FAIL_COND_MSG(!::Engine::get_singleton()->is_singleton_user_created(p_name), vformat("Attempt to remove non-user created singleton: '%s'.", String(p_name)));
  1559. ::Engine::get_singleton()->remove_singleton(p_name);
  1560. }
  1561. Vector<String> Engine::get_singleton_list() const {
  1562. List<::Engine::Singleton> singletons;
  1563. ::Engine::get_singleton()->get_singletons(&singletons);
  1564. Vector<String> ret;
  1565. for (const ::Engine::Singleton &E : singletons) {
  1566. ret.push_back(E.name);
  1567. }
  1568. return ret;
  1569. }
  1570. Error Engine::register_script_language(ScriptLanguage *p_language) {
  1571. return ScriptServer::register_language(p_language);
  1572. }
  1573. Error Engine::unregister_script_language(const ScriptLanguage *p_language) {
  1574. return ScriptServer::unregister_language(p_language);
  1575. }
  1576. int Engine::get_script_language_count() {
  1577. return ScriptServer::get_language_count();
  1578. }
  1579. ScriptLanguage *Engine::get_script_language(int p_index) const {
  1580. return ScriptServer::get_language(p_index);
  1581. }
  1582. TypedArray<ScriptBacktrace> Engine::capture_script_backtraces(bool p_include_variables) const {
  1583. Vector<Ref<ScriptBacktrace>> backtraces = ScriptServer::capture_script_backtraces(p_include_variables);
  1584. TypedArray<ScriptBacktrace> result;
  1585. result.resize(backtraces.size());
  1586. for (int i = 0; i < backtraces.size(); i++) {
  1587. result[i] = backtraces[i];
  1588. }
  1589. return result;
  1590. }
  1591. void Engine::set_editor_hint(bool p_enabled) {
  1592. ::Engine::get_singleton()->set_editor_hint(p_enabled);
  1593. }
  1594. bool Engine::is_editor_hint() const {
  1595. return ::Engine::get_singleton()->is_editor_hint();
  1596. }
  1597. bool Engine::is_embedded_in_editor() const {
  1598. return ::Engine::get_singleton()->is_embedded_in_editor();
  1599. }
  1600. String Engine::get_write_movie_path() const {
  1601. return ::Engine::get_singleton()->get_write_movie_path();
  1602. }
  1603. void Engine::set_print_to_stdout(bool p_enabled) {
  1604. ::Engine::get_singleton()->set_print_to_stdout(p_enabled);
  1605. }
  1606. bool Engine::is_printing_to_stdout() const {
  1607. return ::Engine::get_singleton()->is_printing_to_stdout();
  1608. }
  1609. void Engine::set_print_error_messages(bool p_enabled) {
  1610. ::Engine::get_singleton()->set_print_error_messages(p_enabled);
  1611. }
  1612. bool Engine::is_printing_error_messages() const {
  1613. return ::Engine::get_singleton()->is_printing_error_messages();
  1614. }
  1615. #ifdef TOOLS_ENABLED
  1616. void Engine::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
  1617. const String pf = p_function;
  1618. if (p_idx == 0 && (pf == "has_singleton" || pf == "get_singleton" || pf == "unregister_singleton")) {
  1619. for (const String &E : get_singleton_list()) {
  1620. r_options->push_back(E.quote());
  1621. }
  1622. }
  1623. Object::get_argument_options(p_function, p_idx, r_options);
  1624. }
  1625. #endif
  1626. void Engine::_bind_methods() {
  1627. ClassDB::bind_method(D_METHOD("set_physics_ticks_per_second", "physics_ticks_per_second"), &Engine::set_physics_ticks_per_second);
  1628. ClassDB::bind_method(D_METHOD("get_physics_ticks_per_second"), &Engine::get_physics_ticks_per_second);
  1629. ClassDB::bind_method(D_METHOD("set_max_physics_steps_per_frame", "max_physics_steps"), &Engine::set_max_physics_steps_per_frame);
  1630. ClassDB::bind_method(D_METHOD("get_max_physics_steps_per_frame"), &Engine::get_max_physics_steps_per_frame);
  1631. ClassDB::bind_method(D_METHOD("set_physics_jitter_fix", "physics_jitter_fix"), &Engine::set_physics_jitter_fix);
  1632. ClassDB::bind_method(D_METHOD("get_physics_jitter_fix"), &Engine::get_physics_jitter_fix);
  1633. ClassDB::bind_method(D_METHOD("get_physics_interpolation_fraction"), &Engine::get_physics_interpolation_fraction);
  1634. ClassDB::bind_method(D_METHOD("set_max_fps", "max_fps"), &Engine::set_max_fps);
  1635. ClassDB::bind_method(D_METHOD("get_max_fps"), &Engine::get_max_fps);
  1636. ClassDB::bind_method(D_METHOD("set_time_scale", "time_scale"), &Engine::set_time_scale);
  1637. ClassDB::bind_method(D_METHOD("get_time_scale"), &Engine::get_time_scale);
  1638. ClassDB::bind_method(D_METHOD("get_frames_drawn"), &Engine::get_frames_drawn);
  1639. ClassDB::bind_method(D_METHOD("get_frames_per_second"), &Engine::get_frames_per_second);
  1640. ClassDB::bind_method(D_METHOD("get_physics_frames"), &Engine::get_physics_frames);
  1641. ClassDB::bind_method(D_METHOD("get_process_frames"), &Engine::get_process_frames);
  1642. ClassDB::bind_method(D_METHOD("get_main_loop"), &Engine::get_main_loop);
  1643. ClassDB::bind_method(D_METHOD("get_version_info"), &Engine::get_version_info);
  1644. ClassDB::bind_method(D_METHOD("get_author_info"), &Engine::get_author_info);
  1645. ClassDB::bind_method(D_METHOD("get_copyright_info"), &Engine::get_copyright_info);
  1646. ClassDB::bind_method(D_METHOD("get_donor_info"), &Engine::get_donor_info);
  1647. ClassDB::bind_method(D_METHOD("get_license_info"), &Engine::get_license_info);
  1648. ClassDB::bind_method(D_METHOD("get_license_text"), &Engine::get_license_text);
  1649. ClassDB::bind_method(D_METHOD("get_architecture_name"), &Engine::get_architecture_name);
  1650. ClassDB::bind_method(D_METHOD("is_in_physics_frame"), &Engine::is_in_physics_frame);
  1651. ClassDB::bind_method(D_METHOD("has_singleton", "name"), &Engine::has_singleton);
  1652. ClassDB::bind_method(D_METHOD("get_singleton", "name"), &Engine::get_singleton_object);
  1653. ClassDB::bind_method(D_METHOD("register_singleton", "name", "instance"), &Engine::register_singleton);
  1654. ClassDB::bind_method(D_METHOD("unregister_singleton", "name"), &Engine::unregister_singleton);
  1655. ClassDB::bind_method(D_METHOD("get_singleton_list"), &Engine::get_singleton_list);
  1656. ClassDB::bind_method(D_METHOD("register_script_language", "language"), &Engine::register_script_language);
  1657. ClassDB::bind_method(D_METHOD("unregister_script_language", "language"), &Engine::unregister_script_language);
  1658. ClassDB::bind_method(D_METHOD("get_script_language_count"), &Engine::get_script_language_count);
  1659. ClassDB::bind_method(D_METHOD("get_script_language", "index"), &Engine::get_script_language);
  1660. ClassDB::bind_method(D_METHOD("capture_script_backtraces", "include_variables"), &Engine::capture_script_backtraces, DEFVAL(false));
  1661. ClassDB::bind_method(D_METHOD("is_editor_hint"), &Engine::is_editor_hint);
  1662. ClassDB::bind_method(D_METHOD("is_embedded_in_editor"), &Engine::is_embedded_in_editor);
  1663. ClassDB::bind_method(D_METHOD("get_write_movie_path"), &Engine::get_write_movie_path);
  1664. ClassDB::bind_method(D_METHOD("set_print_to_stdout", "enabled"), &Engine::set_print_to_stdout);
  1665. ClassDB::bind_method(D_METHOD("is_printing_to_stdout"), &Engine::is_printing_to_stdout);
  1666. ClassDB::bind_method(D_METHOD("set_print_error_messages", "enabled"), &Engine::set_print_error_messages);
  1667. ClassDB::bind_method(D_METHOD("is_printing_error_messages"), &Engine::is_printing_error_messages);
  1668. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "print_error_messages"), "set_print_error_messages", "is_printing_error_messages");
  1669. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "print_to_stdout"), "set_print_to_stdout", "is_printing_to_stdout");
  1670. ADD_PROPERTY(PropertyInfo(Variant::INT, "physics_ticks_per_second"), "set_physics_ticks_per_second", "get_physics_ticks_per_second");
  1671. ADD_PROPERTY(PropertyInfo(Variant::INT, "max_physics_steps_per_frame"), "set_max_physics_steps_per_frame", "get_max_physics_steps_per_frame");
  1672. ADD_PROPERTY(PropertyInfo(Variant::INT, "max_fps"), "set_max_fps", "get_max_fps");
  1673. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "time_scale"), "set_time_scale", "get_time_scale");
  1674. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "physics_jitter_fix"), "set_physics_jitter_fix", "get_physics_jitter_fix");
  1675. }
  1676. Engine *Engine::singleton = nullptr;
  1677. ////// EngineDebugger //////
  1678. bool EngineDebugger::is_active() {
  1679. return ::EngineDebugger::is_active();
  1680. }
  1681. void EngineDebugger::register_profiler(const StringName &p_name, Ref<EngineProfiler> p_profiler) {
  1682. ERR_FAIL_COND(p_profiler.is_null());
  1683. ERR_FAIL_COND_MSG(p_profiler->is_bound(), "Profiler already registered.");
  1684. ERR_FAIL_COND_MSG(profilers.has(p_name) || has_profiler(p_name), vformat("Profiler name already in use: '%s'.", p_name));
  1685. Error err = p_profiler->bind(p_name);
  1686. ERR_FAIL_COND_MSG(err != OK, vformat("Profiler failed to register with error: %d.", err));
  1687. profilers.insert(p_name, p_profiler);
  1688. }
  1689. void EngineDebugger::unregister_profiler(const StringName &p_name) {
  1690. ERR_FAIL_COND_MSG(!profilers.has(p_name), vformat("Profiler not registered: '%s'.", p_name));
  1691. profilers[p_name]->unbind();
  1692. profilers.erase(p_name);
  1693. }
  1694. bool EngineDebugger::is_profiling(const StringName &p_name) {
  1695. return ::EngineDebugger::is_profiling(p_name);
  1696. }
  1697. bool EngineDebugger::has_profiler(const StringName &p_name) {
  1698. return ::EngineDebugger::has_profiler(p_name);
  1699. }
  1700. void EngineDebugger::profiler_add_frame_data(const StringName &p_name, const Array &p_data) {
  1701. ::EngineDebugger::profiler_add_frame_data(p_name, p_data);
  1702. }
  1703. void EngineDebugger::profiler_enable(const StringName &p_name, bool p_enabled, const Array &p_opts) {
  1704. if (::EngineDebugger::get_singleton()) {
  1705. ::EngineDebugger::get_singleton()->profiler_enable(p_name, p_enabled, p_opts);
  1706. }
  1707. }
  1708. void EngineDebugger::register_message_capture(const StringName &p_name, const Callable &p_callable) {
  1709. ERR_FAIL_COND_MSG(captures.has(p_name) || has_capture(p_name), vformat("Capture already registered: '%s'.", p_name));
  1710. captures.insert(p_name, p_callable);
  1711. Callable &c = captures[p_name];
  1712. ::EngineDebugger::Capture capture(&c, &EngineDebugger::call_capture);
  1713. ::EngineDebugger::register_message_capture(p_name, capture);
  1714. }
  1715. void EngineDebugger::unregister_message_capture(const StringName &p_name) {
  1716. ERR_FAIL_COND_MSG(!captures.has(p_name), vformat("Capture not registered: '%s'.", p_name));
  1717. ::EngineDebugger::unregister_message_capture(p_name);
  1718. captures.erase(p_name);
  1719. }
  1720. bool EngineDebugger::has_capture(const StringName &p_name) {
  1721. return ::EngineDebugger::has_capture(p_name);
  1722. }
  1723. void EngineDebugger::send_message(const String &p_msg, const Array &p_data) {
  1724. ERR_FAIL_COND_MSG(!::EngineDebugger::is_active(), "Can't send message. No active debugger");
  1725. ::EngineDebugger::get_singleton()->send_message(p_msg, p_data);
  1726. }
  1727. void EngineDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
  1728. ERR_FAIL_COND_MSG(!::EngineDebugger::is_active(), "Can't send debug. No active debugger");
  1729. ::EngineDebugger::get_singleton()->debug(p_can_continue, p_is_error_breakpoint);
  1730. }
  1731. void EngineDebugger::script_debug(ScriptLanguage *p_lang, bool p_can_continue, bool p_is_error_breakpoint) {
  1732. ERR_FAIL_COND_MSG(!::EngineDebugger::get_script_debugger(), "Can't send debug. No active debugger");
  1733. ::EngineDebugger::get_script_debugger()->debug(p_lang, p_can_continue, p_is_error_breakpoint);
  1734. }
  1735. Error EngineDebugger::call_capture(void *p_user, const String &p_cmd, const Array &p_data, bool &r_captured) {
  1736. Callable &capture = *(Callable *)p_user;
  1737. if (!capture.is_valid()) {
  1738. return FAILED;
  1739. }
  1740. Variant cmd = p_cmd, data = p_data;
  1741. const Variant *args[2] = { &cmd, &data };
  1742. Variant retval;
  1743. Callable::CallError err;
  1744. capture.callp(args, 2, retval, err);
  1745. ERR_FAIL_COND_V_MSG(err.error != Callable::CallError::CALL_OK, FAILED, vformat("Error calling 'capture' to callable: %s.", Variant::get_callable_error_text(capture, args, 2, err)));
  1746. ERR_FAIL_COND_V_MSG(retval.get_type() != Variant::BOOL, FAILED, vformat("Error calling 'capture' to callable: '%s'. Return type is not bool.", String(capture)));
  1747. r_captured = retval;
  1748. return OK;
  1749. }
  1750. void EngineDebugger::line_poll() {
  1751. ERR_FAIL_COND_MSG(!::EngineDebugger::is_active(), "Can't poll. No active debugger");
  1752. ::EngineDebugger::get_singleton()->line_poll();
  1753. }
  1754. void EngineDebugger::set_lines_left(int p_lines) {
  1755. ERR_FAIL_COND_MSG(!::EngineDebugger::get_script_debugger(), "Can't set lines left. No active debugger");
  1756. ::EngineDebugger::get_script_debugger()->set_lines_left(p_lines);
  1757. }
  1758. int EngineDebugger::get_lines_left() const {
  1759. ERR_FAIL_COND_V_MSG(!::EngineDebugger::get_script_debugger(), 0, "Can't get lines left. No active debugger");
  1760. return ::EngineDebugger::get_script_debugger()->get_lines_left();
  1761. }
  1762. void EngineDebugger::set_depth(int p_depth) {
  1763. ERR_FAIL_COND_MSG(!::EngineDebugger::get_script_debugger(), "Can't set depth. No active debugger");
  1764. ::EngineDebugger::get_script_debugger()->set_depth(p_depth);
  1765. }
  1766. int EngineDebugger::get_depth() const {
  1767. ERR_FAIL_COND_V_MSG(!::EngineDebugger::get_script_debugger(), 0, "Can't get depth. No active debugger");
  1768. return ::EngineDebugger::get_script_debugger()->get_depth();
  1769. }
  1770. bool EngineDebugger::is_breakpoint(int p_line, const StringName &p_source) const {
  1771. ERR_FAIL_COND_V_MSG(!::EngineDebugger::get_script_debugger(), false, "Can't check breakpoint. No active debugger");
  1772. return ::EngineDebugger::get_script_debugger()->is_breakpoint(p_line, p_source);
  1773. }
  1774. bool EngineDebugger::is_skipping_breakpoints() const {
  1775. ERR_FAIL_COND_V_MSG(!::EngineDebugger::get_script_debugger(), false, "Can't check skipping breakpoint. No active debugger");
  1776. return ::EngineDebugger::get_script_debugger()->is_skipping_breakpoints();
  1777. }
  1778. void EngineDebugger::insert_breakpoint(int p_line, const StringName &p_source) {
  1779. ERR_FAIL_COND_MSG(!::EngineDebugger::get_script_debugger(), "Can't insert breakpoint. No active debugger");
  1780. ::EngineDebugger::get_script_debugger()->insert_breakpoint(p_line, p_source);
  1781. }
  1782. void EngineDebugger::remove_breakpoint(int p_line, const StringName &p_source) {
  1783. ERR_FAIL_COND_MSG(!::EngineDebugger::get_script_debugger(), "Can't remove breakpoint. No active debugger");
  1784. ::EngineDebugger::get_script_debugger()->remove_breakpoint(p_line, p_source);
  1785. }
  1786. void EngineDebugger::clear_breakpoints() {
  1787. ERR_FAIL_COND_MSG(!::EngineDebugger::get_script_debugger(), "Can't clear breakpoints. No active debugger");
  1788. ::EngineDebugger::get_script_debugger()->clear_breakpoints();
  1789. }
  1790. EngineDebugger::~EngineDebugger() {
  1791. for (const KeyValue<StringName, Callable> &E : captures) {
  1792. ::EngineDebugger::unregister_message_capture(E.key);
  1793. }
  1794. captures.clear();
  1795. }
  1796. EngineDebugger *EngineDebugger::singleton = nullptr;
  1797. void EngineDebugger::_bind_methods() {
  1798. ClassDB::bind_method(D_METHOD("is_active"), &EngineDebugger::is_active);
  1799. ClassDB::bind_method(D_METHOD("register_profiler", "name", "profiler"), &EngineDebugger::register_profiler);
  1800. ClassDB::bind_method(D_METHOD("unregister_profiler", "name"), &EngineDebugger::unregister_profiler);
  1801. ClassDB::bind_method(D_METHOD("is_profiling", "name"), &EngineDebugger::is_profiling);
  1802. ClassDB::bind_method(D_METHOD("has_profiler", "name"), &EngineDebugger::has_profiler);
  1803. ClassDB::bind_method(D_METHOD("profiler_add_frame_data", "name", "data"), &EngineDebugger::profiler_add_frame_data);
  1804. ClassDB::bind_method(D_METHOD("profiler_enable", "name", "enable", "arguments"), &EngineDebugger::profiler_enable, DEFVAL(Array()));
  1805. ClassDB::bind_method(D_METHOD("register_message_capture", "name", "callable"), &EngineDebugger::register_message_capture);
  1806. ClassDB::bind_method(D_METHOD("unregister_message_capture", "name"), &EngineDebugger::unregister_message_capture);
  1807. ClassDB::bind_method(D_METHOD("has_capture", "name"), &EngineDebugger::has_capture);
  1808. ClassDB::bind_method(D_METHOD("line_poll"), &EngineDebugger::line_poll);
  1809. ClassDB::bind_method(D_METHOD("send_message", "message", "data"), &EngineDebugger::send_message);
  1810. ClassDB::bind_method(D_METHOD("debug", "can_continue", "is_error_breakpoint"), &EngineDebugger::debug, DEFVAL(true), DEFVAL(false));
  1811. ClassDB::bind_method(D_METHOD("script_debug", "language", "can_continue", "is_error_breakpoint"), &EngineDebugger::script_debug, DEFVAL(true), DEFVAL(false));
  1812. ClassDB::bind_method(D_METHOD("set_lines_left", "lines"), &EngineDebugger::set_lines_left);
  1813. ClassDB::bind_method(D_METHOD("get_lines_left"), &EngineDebugger::get_lines_left);
  1814. ClassDB::bind_method(D_METHOD("set_depth", "depth"), &EngineDebugger::set_depth);
  1815. ClassDB::bind_method(D_METHOD("get_depth"), &EngineDebugger::get_depth);
  1816. ClassDB::bind_method(D_METHOD("is_breakpoint", "line", "source"), &EngineDebugger::is_breakpoint);
  1817. ClassDB::bind_method(D_METHOD("is_skipping_breakpoints"), &EngineDebugger::is_skipping_breakpoints);
  1818. ClassDB::bind_method(D_METHOD("insert_breakpoint", "line", "source"), &EngineDebugger::insert_breakpoint);
  1819. ClassDB::bind_method(D_METHOD("remove_breakpoint", "line", "source"), &EngineDebugger::remove_breakpoint);
  1820. ClassDB::bind_method(D_METHOD("clear_breakpoints"), &EngineDebugger::clear_breakpoints);
  1821. }
  1822. } // namespace CoreBind