core_bind.cpp 90 KB

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