core_bind.cpp 86 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405
  1. /*************************************************************************/
  2. /* core_bind.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /*************************************************************************/
  30. #include "core_bind.h"
  31. #include "core/config/project_settings.h"
  32. #include "core/crypto/crypto_core.h"
  33. #include "core/debugger/engine_debugger.h"
  34. #include "core/io/file_access_compressed.h"
  35. #include "core/io/file_access_encrypted.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/variant/typed_array.h"
  41. namespace core_bind {
  42. ////// ResourceLoader //////
  43. ResourceLoader *ResourceLoader::singleton = nullptr;
  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. r_progress.resize(1);
  51. r_progress[0] = progress;
  52. return (ThreadLoadStatus)tls;
  53. }
  54. Ref<Resource> ResourceLoader::load_threaded_get(const String &p_path) {
  55. Error error;
  56. Ref<Resource> res = ::ResourceLoader::load_threaded_get(p_path, &error);
  57. return res;
  58. }
  59. Ref<Resource> ResourceLoader::load(const String &p_path, const String &p_type_hint, CacheMode p_cache_mode) {
  60. Error err = OK;
  61. Ref<Resource> ret = ::ResourceLoader::load(p_path, p_type_hint, ResourceFormatLoader::CacheMode(p_cache_mode), &err);
  62. ERR_FAIL_COND_V_MSG(err != OK, ret, "Error loading resource: '" + p_path + "'.");
  63. return ret;
  64. }
  65. Vector<String> ResourceLoader::get_recognized_extensions_for_type(const String &p_type) {
  66. List<String> exts;
  67. ::ResourceLoader::get_recognized_extensions_for_type(p_type, &exts);
  68. Vector<String> ret;
  69. for (const String &E : exts) {
  70. ret.push_back(E);
  71. }
  72. return ret;
  73. }
  74. void ResourceLoader::add_resource_format_loader(Ref<ResourceFormatLoader> p_format_loader, bool p_at_front) {
  75. ::ResourceLoader::add_resource_format_loader(p_format_loader, p_at_front);
  76. }
  77. void ResourceLoader::remove_resource_format_loader(Ref<ResourceFormatLoader> p_format_loader) {
  78. ::ResourceLoader::remove_resource_format_loader(p_format_loader);
  79. }
  80. void ResourceLoader::set_abort_on_missing_resources(bool p_abort) {
  81. ::ResourceLoader::set_abort_on_missing_resources(p_abort);
  82. }
  83. PackedStringArray ResourceLoader::get_dependencies(const String &p_path) {
  84. List<String> deps;
  85. ::ResourceLoader::get_dependencies(p_path, &deps);
  86. PackedStringArray ret;
  87. for (const String &E : deps) {
  88. ret.push_back(E);
  89. }
  90. return ret;
  91. }
  92. bool ResourceLoader::has_cached(const String &p_path) {
  93. String local_path = ProjectSettings::get_singleton()->localize_path(p_path);
  94. return ResourceCache::has(local_path);
  95. }
  96. bool ResourceLoader::exists(const String &p_path, const String &p_type_hint) {
  97. return ::ResourceLoader::exists(p_path, p_type_hint);
  98. }
  99. ResourceUID::ID ResourceLoader::get_resource_uid(const String &p_path) {
  100. return ::ResourceLoader::get_resource_uid(p_path);
  101. }
  102. void ResourceLoader::_bind_methods() {
  103. 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));
  104. ClassDB::bind_method(D_METHOD("load_threaded_get_status", "path", "progress"), &ResourceLoader::load_threaded_get_status, DEFVAL(Array()));
  105. ClassDB::bind_method(D_METHOD("load_threaded_get", "path"), &ResourceLoader::load_threaded_get);
  106. ClassDB::bind_method(D_METHOD("load", "path", "type_hint", "cache_mode"), &ResourceLoader::load, DEFVAL(""), DEFVAL(CACHE_MODE_REUSE));
  107. ClassDB::bind_method(D_METHOD("get_recognized_extensions_for_type", "type"), &ResourceLoader::get_recognized_extensions_for_type);
  108. ClassDB::bind_method(D_METHOD("add_resource_format_loader", "format_loader", "at_front"), &ResourceLoader::add_resource_format_loader, DEFVAL(false));
  109. ClassDB::bind_method(D_METHOD("remove_resource_format_loader", "format_loader"), &ResourceLoader::remove_resource_format_loader);
  110. ClassDB::bind_method(D_METHOD("set_abort_on_missing_resources", "abort"), &ResourceLoader::set_abort_on_missing_resources);
  111. ClassDB::bind_method(D_METHOD("get_dependencies", "path"), &ResourceLoader::get_dependencies);
  112. ClassDB::bind_method(D_METHOD("has_cached", "path"), &ResourceLoader::has_cached);
  113. ClassDB::bind_method(D_METHOD("exists", "path", "type_hint"), &ResourceLoader::exists, DEFVAL(""));
  114. ClassDB::bind_method(D_METHOD("get_resource_uid", "path"), &ResourceLoader::get_resource_uid);
  115. BIND_ENUM_CONSTANT(THREAD_LOAD_INVALID_RESOURCE);
  116. BIND_ENUM_CONSTANT(THREAD_LOAD_IN_PROGRESS);
  117. BIND_ENUM_CONSTANT(THREAD_LOAD_FAILED);
  118. BIND_ENUM_CONSTANT(THREAD_LOAD_LOADED);
  119. BIND_ENUM_CONSTANT(CACHE_MODE_IGNORE);
  120. BIND_ENUM_CONSTANT(CACHE_MODE_REUSE);
  121. BIND_ENUM_CONSTANT(CACHE_MODE_REPLACE);
  122. }
  123. ////// ResourceSaver //////
  124. Error ResourceSaver::save(const Ref<Resource> &p_resource, const String &p_path, BitField<SaverFlags> p_flags) {
  125. ERR_FAIL_COND_V_MSG(p_resource.is_null(), ERR_INVALID_PARAMETER, "Can't save empty resource to path '" + p_path + "'.");
  126. return ::ResourceSaver::save(p_resource, p_path, p_flags);
  127. }
  128. Vector<String> ResourceSaver::get_recognized_extensions(const Ref<Resource> &p_resource) {
  129. ERR_FAIL_COND_V_MSG(p_resource.is_null(), Vector<String>(), "It's not a reference to a valid Resource object.");
  130. List<String> exts;
  131. ::ResourceSaver::get_recognized_extensions(p_resource, &exts);
  132. Vector<String> ret;
  133. for (const String &E : exts) {
  134. ret.push_back(E);
  135. }
  136. return ret;
  137. }
  138. void ResourceSaver::add_resource_format_saver(Ref<ResourceFormatSaver> p_format_saver, bool p_at_front) {
  139. ::ResourceSaver::add_resource_format_saver(p_format_saver, p_at_front);
  140. }
  141. void ResourceSaver::remove_resource_format_saver(Ref<ResourceFormatSaver> p_format_saver) {
  142. ::ResourceSaver::remove_resource_format_saver(p_format_saver);
  143. }
  144. ResourceSaver *ResourceSaver::singleton = nullptr;
  145. void ResourceSaver::_bind_methods() {
  146. ClassDB::bind_method(D_METHOD("save", "resource", "path", "flags"), &ResourceSaver::save, DEFVAL(""), DEFVAL((uint32_t)FLAG_NONE));
  147. ClassDB::bind_method(D_METHOD("get_recognized_extensions", "type"), &ResourceSaver::get_recognized_extensions);
  148. ClassDB::bind_method(D_METHOD("add_resource_format_saver", "format_saver", "at_front"), &ResourceSaver::add_resource_format_saver, DEFVAL(false));
  149. ClassDB::bind_method(D_METHOD("remove_resource_format_saver", "format_saver"), &ResourceSaver::remove_resource_format_saver);
  150. BIND_BITFIELD_FLAG(FLAG_NONE);
  151. BIND_BITFIELD_FLAG(FLAG_RELATIVE_PATHS);
  152. BIND_BITFIELD_FLAG(FLAG_BUNDLE_RESOURCES);
  153. BIND_BITFIELD_FLAG(FLAG_CHANGE_PATH);
  154. BIND_BITFIELD_FLAG(FLAG_OMIT_EDITOR_PROPERTIES);
  155. BIND_BITFIELD_FLAG(FLAG_SAVE_BIG_ENDIAN);
  156. BIND_BITFIELD_FLAG(FLAG_COMPRESS);
  157. BIND_BITFIELD_FLAG(FLAG_REPLACE_SUBRESOURCE_PATHS);
  158. }
  159. ////// OS //////
  160. PackedStringArray OS::get_connected_midi_inputs() {
  161. return ::OS::get_singleton()->get_connected_midi_inputs();
  162. }
  163. void OS::open_midi_inputs() {
  164. ::OS::get_singleton()->open_midi_inputs();
  165. }
  166. void OS::close_midi_inputs() {
  167. ::OS::get_singleton()->close_midi_inputs();
  168. }
  169. void OS::set_use_file_access_save_and_swap(bool p_enable) {
  170. FileAccess::set_backup_save(p_enable);
  171. }
  172. void OS::set_low_processor_usage_mode(bool p_enabled) {
  173. ::OS::get_singleton()->set_low_processor_usage_mode(p_enabled);
  174. }
  175. bool OS::is_in_low_processor_usage_mode() const {
  176. return ::OS::get_singleton()->is_in_low_processor_usage_mode();
  177. }
  178. void OS::set_low_processor_usage_mode_sleep_usec(int p_usec) {
  179. ::OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(p_usec);
  180. }
  181. int OS::get_low_processor_usage_mode_sleep_usec() const {
  182. return ::OS::get_singleton()->get_low_processor_usage_mode_sleep_usec();
  183. }
  184. void OS::alert(const String &p_alert, const String &p_title) {
  185. ::OS::get_singleton()->alert(p_alert, p_title);
  186. }
  187. void OS::crash(const String &p_message) {
  188. CRASH_NOW_MSG(p_message);
  189. }
  190. Vector<String> OS::get_system_fonts() const {
  191. return ::OS::get_singleton()->get_system_fonts();
  192. }
  193. String OS::get_system_font_path(const String &p_font_name, bool p_bold, bool p_italic) const {
  194. return ::OS::get_singleton()->get_system_font_path(p_font_name, p_bold, p_italic);
  195. }
  196. String OS::get_executable_path() const {
  197. return ::OS::get_singleton()->get_executable_path();
  198. }
  199. Error OS::shell_open(String p_uri) {
  200. if (p_uri.begins_with("res://")) {
  201. 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()`.");
  202. } else if (p_uri.begins_with("user://")) {
  203. 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()`.");
  204. }
  205. return ::OS::get_singleton()->shell_open(p_uri);
  206. }
  207. int OS::execute(const String &p_path, const Vector<String> &p_arguments, Array r_output, bool p_read_stderr, bool p_open_console) {
  208. List<String> args;
  209. for (int i = 0; i < p_arguments.size(); i++) {
  210. args.push_back(p_arguments[i]);
  211. }
  212. String pipe;
  213. int exitcode = 0;
  214. Error err = ::OS::get_singleton()->execute(p_path, args, &pipe, &exitcode, p_read_stderr, nullptr, p_open_console);
  215. r_output.push_back(pipe);
  216. if (err != OK) {
  217. return -1;
  218. }
  219. return exitcode;
  220. }
  221. int OS::create_instance(const Vector<String> &p_arguments) {
  222. List<String> args;
  223. for (int i = 0; i < p_arguments.size(); i++) {
  224. args.push_back(p_arguments[i]);
  225. }
  226. ::OS::ProcessID pid = 0;
  227. Error err = ::OS::get_singleton()->create_instance(args, &pid);
  228. if (err != OK) {
  229. return -1;
  230. }
  231. return pid;
  232. }
  233. int OS::create_process(const String &p_path, const Vector<String> &p_arguments, bool p_open_console) {
  234. List<String> args;
  235. for (int i = 0; i < p_arguments.size(); i++) {
  236. args.push_back(p_arguments[i]);
  237. }
  238. ::OS::ProcessID pid = 0;
  239. Error err = ::OS::get_singleton()->create_process(p_path, args, &pid, p_open_console);
  240. if (err != OK) {
  241. return -1;
  242. }
  243. return pid;
  244. }
  245. Error OS::kill(int p_pid) {
  246. return ::OS::get_singleton()->kill(p_pid);
  247. }
  248. bool OS::is_process_running(int p_pid) const {
  249. return ::OS::get_singleton()->is_process_running(p_pid);
  250. }
  251. int OS::get_process_id() const {
  252. return ::OS::get_singleton()->get_process_id();
  253. }
  254. bool OS::has_environment(const String &p_var) const {
  255. return ::OS::get_singleton()->has_environment(p_var);
  256. }
  257. String OS::get_environment(const String &p_var) const {
  258. return ::OS::get_singleton()->get_environment(p_var);
  259. }
  260. bool OS::set_environment(const String &p_var, const String &p_value) const {
  261. return ::OS::get_singleton()->set_environment(p_var, p_value);
  262. }
  263. String OS::get_name() const {
  264. return ::OS::get_singleton()->get_name();
  265. }
  266. String OS::get_distribution_name() const {
  267. return ::OS::get_singleton()->get_distribution_name();
  268. }
  269. String OS::get_version() const {
  270. return ::OS::get_singleton()->get_version();
  271. }
  272. Vector<String> OS::get_cmdline_args() {
  273. List<String> cmdline = ::OS::get_singleton()->get_cmdline_args();
  274. Vector<String> cmdlinev;
  275. for (const String &E : cmdline) {
  276. cmdlinev.push_back(E);
  277. }
  278. return cmdlinev;
  279. }
  280. Vector<String> OS::get_cmdline_user_args() {
  281. List<String> cmdline = ::OS::get_singleton()->get_cmdline_user_args();
  282. Vector<String> cmdlinev;
  283. for (const String &E : cmdline) {
  284. cmdlinev.push_back(E);
  285. }
  286. return cmdlinev;
  287. }
  288. void OS::set_restart_on_exit(bool p_restart, const Vector<String> &p_restart_arguments) {
  289. List<String> args_list;
  290. for (const String &restart_argument : p_restart_arguments) {
  291. args_list.push_back(restart_argument);
  292. }
  293. ::OS::get_singleton()->set_restart_on_exit(p_restart, args_list);
  294. }
  295. bool OS::is_restart_on_exit_set() const {
  296. return ::OS::get_singleton()->is_restart_on_exit_set();
  297. }
  298. Vector<String> OS::get_restart_on_exit_arguments() const {
  299. List<String> args = ::OS::get_singleton()->get_restart_on_exit_arguments();
  300. Vector<String> args_vector;
  301. for (List<String>::Element *E = args.front(); E; E = E->next()) {
  302. args_vector.push_back(E->get());
  303. }
  304. return args_vector;
  305. }
  306. String OS::get_locale() const {
  307. return ::OS::get_singleton()->get_locale();
  308. }
  309. String OS::get_locale_language() const {
  310. return ::OS::get_singleton()->get_locale_language();
  311. }
  312. String OS::get_model_name() const {
  313. return ::OS::get_singleton()->get_model_name();
  314. }
  315. Error OS::set_thread_name(const String &p_name) {
  316. return ::Thread::set_name(p_name);
  317. }
  318. ::Thread::ID OS::get_thread_caller_id() const {
  319. return ::Thread::get_caller_id();
  320. };
  321. ::Thread::ID OS::get_main_thread_id() const {
  322. return ::Thread::get_main_id();
  323. };
  324. bool OS::has_feature(const String &p_feature) const {
  325. return ::OS::get_singleton()->has_feature(p_feature);
  326. }
  327. uint64_t OS::get_static_memory_usage() const {
  328. return ::OS::get_singleton()->get_static_memory_usage();
  329. }
  330. uint64_t OS::get_static_memory_peak_usage() const {
  331. return ::OS::get_singleton()->get_static_memory_peak_usage();
  332. }
  333. /** This method uses a signed argument for better error reporting as it's used from the scripting API. */
  334. void OS::delay_usec(int p_usec) const {
  335. ERR_FAIL_COND_MSG(
  336. p_usec < 0,
  337. vformat("Can't sleep for %d microseconds. The delay provided must be greater than or equal to 0 microseconds.", p_usec));
  338. ::OS::get_singleton()->delay_usec(p_usec);
  339. }
  340. /** This method uses a signed argument for better error reporting as it's used from the scripting API. */
  341. void OS::delay_msec(int p_msec) const {
  342. ERR_FAIL_COND_MSG(
  343. p_msec < 0,
  344. vformat("Can't sleep for %d milliseconds. The delay provided must be greater than or equal to 0 milliseconds.", p_msec));
  345. ::OS::get_singleton()->delay_usec(int64_t(p_msec) * 1000);
  346. }
  347. bool OS::can_use_threads() const {
  348. return ::OS::get_singleton()->can_use_threads();
  349. }
  350. bool OS::is_userfs_persistent() const {
  351. return ::OS::get_singleton()->is_userfs_persistent();
  352. }
  353. int OS::get_processor_count() const {
  354. return ::OS::get_singleton()->get_processor_count();
  355. }
  356. String OS::get_processor_name() const {
  357. return ::OS::get_singleton()->get_processor_name();
  358. }
  359. bool OS::is_stdout_verbose() const {
  360. return ::OS::get_singleton()->is_stdout_verbose();
  361. }
  362. Error OS::move_to_trash(const String &p_path) const {
  363. return ::OS::get_singleton()->move_to_trash(p_path);
  364. }
  365. String OS::get_user_data_dir() const {
  366. return ::OS::get_singleton()->get_user_data_dir();
  367. }
  368. String OS::get_config_dir() const {
  369. // Exposed as `get_config_dir()` instead of `get_config_path()` for consistency with other exposed OS methods.
  370. return ::OS::get_singleton()->get_config_path();
  371. }
  372. String OS::get_data_dir() const {
  373. // Exposed as `get_data_dir()` instead of `get_data_path()` for consistency with other exposed OS methods.
  374. return ::OS::get_singleton()->get_data_path();
  375. }
  376. String OS::get_cache_dir() const {
  377. // Exposed as `get_cache_dir()` instead of `get_cache_path()` for consistency with other exposed OS methods.
  378. return ::OS::get_singleton()->get_cache_path();
  379. }
  380. bool OS::is_debug_build() const {
  381. #ifdef DEBUG_ENABLED
  382. return true;
  383. #else
  384. return false;
  385. #endif
  386. }
  387. String OS::get_system_dir(SystemDir p_dir, bool p_shared_storage) const {
  388. return ::OS::get_singleton()->get_system_dir(::OS::SystemDir(p_dir), p_shared_storage);
  389. }
  390. String OS::get_keycode_string(Key p_code) const {
  391. return ::keycode_get_string(p_code);
  392. }
  393. bool OS::is_keycode_unicode(char32_t p_unicode) const {
  394. return ::keycode_has_unicode((Key)p_unicode);
  395. }
  396. Key OS::find_keycode_from_string(const String &p_code) const {
  397. return find_keycode(p_code);
  398. }
  399. bool OS::request_permission(const String &p_name) {
  400. return ::OS::get_singleton()->request_permission(p_name);
  401. }
  402. bool OS::request_permissions() {
  403. return ::OS::get_singleton()->request_permissions();
  404. }
  405. Vector<String> OS::get_granted_permissions() const {
  406. return ::OS::get_singleton()->get_granted_permissions();
  407. }
  408. String OS::get_unique_id() const {
  409. return ::OS::get_singleton()->get_unique_id();
  410. }
  411. OS *OS::singleton = nullptr;
  412. void OS::_bind_methods() {
  413. ClassDB::bind_method(D_METHOD("get_connected_midi_inputs"), &OS::get_connected_midi_inputs);
  414. ClassDB::bind_method(D_METHOD("open_midi_inputs"), &OS::open_midi_inputs);
  415. ClassDB::bind_method(D_METHOD("close_midi_inputs"), &OS::close_midi_inputs);
  416. ClassDB::bind_method(D_METHOD("alert", "text", "title"), &OS::alert, DEFVAL("Alert!"));
  417. ClassDB::bind_method(D_METHOD("crash", "message"), &OS::crash);
  418. ClassDB::bind_method(D_METHOD("set_low_processor_usage_mode", "enable"), &OS::set_low_processor_usage_mode);
  419. ClassDB::bind_method(D_METHOD("is_in_low_processor_usage_mode"), &OS::is_in_low_processor_usage_mode);
  420. ClassDB::bind_method(D_METHOD("set_low_processor_usage_mode_sleep_usec", "usec"), &OS::set_low_processor_usage_mode_sleep_usec);
  421. ClassDB::bind_method(D_METHOD("get_low_processor_usage_mode_sleep_usec"), &OS::get_low_processor_usage_mode_sleep_usec);
  422. ClassDB::bind_method(D_METHOD("get_processor_count"), &OS::get_processor_count);
  423. ClassDB::bind_method(D_METHOD("get_processor_name"), &OS::get_processor_name);
  424. ClassDB::bind_method(D_METHOD("get_system_fonts"), &OS::get_system_fonts);
  425. ClassDB::bind_method(D_METHOD("get_system_font_path", "font_name", "bold", "italic"), &OS::get_system_font_path, DEFVAL(false), DEFVAL(false));
  426. ClassDB::bind_method(D_METHOD("get_executable_path"), &OS::get_executable_path);
  427. ClassDB::bind_method(D_METHOD("execute", "path", "arguments", "output", "read_stderr", "open_console"), &OS::execute, DEFVAL(Array()), DEFVAL(false), DEFVAL(false));
  428. ClassDB::bind_method(D_METHOD("create_process", "path", "arguments", "open_console"), &OS::create_process, DEFVAL(false));
  429. ClassDB::bind_method(D_METHOD("create_instance", "arguments"), &OS::create_instance);
  430. ClassDB::bind_method(D_METHOD("kill", "pid"), &OS::kill);
  431. ClassDB::bind_method(D_METHOD("shell_open", "uri"), &OS::shell_open);
  432. ClassDB::bind_method(D_METHOD("is_process_running", "pid"), &OS::is_process_running);
  433. ClassDB::bind_method(D_METHOD("get_process_id"), &OS::get_process_id);
  434. ClassDB::bind_method(D_METHOD("get_environment", "variable"), &OS::get_environment);
  435. ClassDB::bind_method(D_METHOD("set_environment", "variable", "value"), &OS::set_environment);
  436. ClassDB::bind_method(D_METHOD("has_environment", "variable"), &OS::has_environment);
  437. ClassDB::bind_method(D_METHOD("get_name"), &OS::get_name);
  438. ClassDB::bind_method(D_METHOD("get_distribution_name"), &OS::get_distribution_name);
  439. ClassDB::bind_method(D_METHOD("get_version"), &OS::get_version);
  440. ClassDB::bind_method(D_METHOD("get_cmdline_args"), &OS::get_cmdline_args);
  441. ClassDB::bind_method(D_METHOD("get_cmdline_user_args"), &OS::get_cmdline_user_args);
  442. ClassDB::bind_method(D_METHOD("set_restart_on_exit", "restart", "arguments"), &OS::set_restart_on_exit, DEFVAL(Vector<String>()));
  443. ClassDB::bind_method(D_METHOD("is_restart_on_exit_set"), &OS::is_restart_on_exit_set);
  444. ClassDB::bind_method(D_METHOD("get_restart_on_exit_arguments"), &OS::get_restart_on_exit_arguments);
  445. ClassDB::bind_method(D_METHOD("delay_usec", "usec"), &OS::delay_usec);
  446. ClassDB::bind_method(D_METHOD("delay_msec", "msec"), &OS::delay_msec);
  447. ClassDB::bind_method(D_METHOD("get_locale"), &OS::get_locale);
  448. ClassDB::bind_method(D_METHOD("get_locale_language"), &OS::get_locale_language);
  449. ClassDB::bind_method(D_METHOD("get_model_name"), &OS::get_model_name);
  450. ClassDB::bind_method(D_METHOD("is_userfs_persistent"), &OS::is_userfs_persistent);
  451. ClassDB::bind_method(D_METHOD("is_stdout_verbose"), &OS::is_stdout_verbose);
  452. ClassDB::bind_method(D_METHOD("can_use_threads"), &OS::can_use_threads);
  453. ClassDB::bind_method(D_METHOD("is_debug_build"), &OS::is_debug_build);
  454. ClassDB::bind_method(D_METHOD("get_static_memory_usage"), &OS::get_static_memory_usage);
  455. ClassDB::bind_method(D_METHOD("get_static_memory_peak_usage"), &OS::get_static_memory_peak_usage);
  456. ClassDB::bind_method(D_METHOD("move_to_trash", "path"), &OS::move_to_trash);
  457. ClassDB::bind_method(D_METHOD("get_user_data_dir"), &OS::get_user_data_dir);
  458. ClassDB::bind_method(D_METHOD("get_system_dir", "dir", "shared_storage"), &OS::get_system_dir, DEFVAL(true));
  459. ClassDB::bind_method(D_METHOD("get_config_dir"), &OS::get_config_dir);
  460. ClassDB::bind_method(D_METHOD("get_data_dir"), &OS::get_data_dir);
  461. ClassDB::bind_method(D_METHOD("get_cache_dir"), &OS::get_cache_dir);
  462. ClassDB::bind_method(D_METHOD("get_unique_id"), &OS::get_unique_id);
  463. ClassDB::bind_method(D_METHOD("get_keycode_string", "code"), &OS::get_keycode_string);
  464. ClassDB::bind_method(D_METHOD("is_keycode_unicode", "code"), &OS::is_keycode_unicode);
  465. ClassDB::bind_method(D_METHOD("find_keycode_from_string", "string"), &OS::find_keycode_from_string);
  466. ClassDB::bind_method(D_METHOD("set_use_file_access_save_and_swap", "enabled"), &OS::set_use_file_access_save_and_swap);
  467. ClassDB::bind_method(D_METHOD("set_thread_name", "name"), &OS::set_thread_name);
  468. ClassDB::bind_method(D_METHOD("get_thread_caller_id"), &OS::get_thread_caller_id);
  469. ClassDB::bind_method(D_METHOD("get_main_thread_id"), &OS::get_main_thread_id);
  470. ClassDB::bind_method(D_METHOD("has_feature", "tag_name"), &OS::has_feature);
  471. ClassDB::bind_method(D_METHOD("request_permission", "name"), &OS::request_permission);
  472. ClassDB::bind_method(D_METHOD("request_permissions"), &OS::request_permissions);
  473. ClassDB::bind_method(D_METHOD("get_granted_permissions"), &OS::get_granted_permissions);
  474. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "low_processor_usage_mode"), "set_low_processor_usage_mode", "is_in_low_processor_usage_mode");
  475. 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");
  476. // Those default values need to be specified for the docs generator,
  477. // to avoid using values from the documentation writer's own OS instance.
  478. ADD_PROPERTY_DEFAULT("low_processor_usage_mode", false);
  479. ADD_PROPERTY_DEFAULT("low_processor_usage_mode_sleep_usec", 6900);
  480. BIND_ENUM_CONSTANT(VIDEO_DRIVER_VULKAN);
  481. BIND_ENUM_CONSTANT(VIDEO_DRIVER_OPENGL_3);
  482. BIND_ENUM_CONSTANT(DAY_SUNDAY);
  483. BIND_ENUM_CONSTANT(DAY_MONDAY);
  484. BIND_ENUM_CONSTANT(DAY_TUESDAY);
  485. BIND_ENUM_CONSTANT(DAY_WEDNESDAY);
  486. BIND_ENUM_CONSTANT(DAY_THURSDAY);
  487. BIND_ENUM_CONSTANT(DAY_FRIDAY);
  488. BIND_ENUM_CONSTANT(DAY_SATURDAY);
  489. BIND_ENUM_CONSTANT(MONTH_JANUARY);
  490. BIND_ENUM_CONSTANT(MONTH_FEBRUARY);
  491. BIND_ENUM_CONSTANT(MONTH_MARCH);
  492. BIND_ENUM_CONSTANT(MONTH_APRIL);
  493. BIND_ENUM_CONSTANT(MONTH_MAY);
  494. BIND_ENUM_CONSTANT(MONTH_JUNE);
  495. BIND_ENUM_CONSTANT(MONTH_JULY);
  496. BIND_ENUM_CONSTANT(MONTH_AUGUST);
  497. BIND_ENUM_CONSTANT(MONTH_SEPTEMBER);
  498. BIND_ENUM_CONSTANT(MONTH_OCTOBER);
  499. BIND_ENUM_CONSTANT(MONTH_NOVEMBER);
  500. BIND_ENUM_CONSTANT(MONTH_DECEMBER);
  501. BIND_ENUM_CONSTANT(SYSTEM_DIR_DESKTOP);
  502. BIND_ENUM_CONSTANT(SYSTEM_DIR_DCIM);
  503. BIND_ENUM_CONSTANT(SYSTEM_DIR_DOCUMENTS);
  504. BIND_ENUM_CONSTANT(SYSTEM_DIR_DOWNLOADS);
  505. BIND_ENUM_CONSTANT(SYSTEM_DIR_MOVIES);
  506. BIND_ENUM_CONSTANT(SYSTEM_DIR_MUSIC);
  507. BIND_ENUM_CONSTANT(SYSTEM_DIR_PICTURES);
  508. BIND_ENUM_CONSTANT(SYSTEM_DIR_RINGTONES);
  509. }
  510. ////// Geometry2D //////
  511. Geometry2D *Geometry2D::singleton = nullptr;
  512. Geometry2D *Geometry2D::get_singleton() {
  513. return singleton;
  514. }
  515. bool Geometry2D::is_point_in_circle(const Vector2 &p_point, const Vector2 &p_circle_pos, real_t p_circle_radius) {
  516. return ::Geometry2D::is_point_in_circle(p_point, p_circle_pos, p_circle_radius);
  517. }
  518. real_t Geometry2D::segment_intersects_circle(const Vector2 &p_from, const Vector2 &p_to, const Vector2 &p_circle_pos, real_t p_circle_radius) {
  519. return ::Geometry2D::segment_intersects_circle(p_from, p_to, p_circle_pos, p_circle_radius);
  520. }
  521. 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) {
  522. Vector2 result;
  523. if (::Geometry2D::segment_intersects_segment(p_from_a, p_to_a, p_from_b, p_to_b, &result)) {
  524. return result;
  525. } else {
  526. return Variant();
  527. }
  528. }
  529. 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) {
  530. Vector2 result;
  531. if (::Geometry2D::line_intersects_line(p_from_a, p_dir_a, p_from_b, p_dir_b, result)) {
  532. return result;
  533. } else {
  534. return Variant();
  535. }
  536. }
  537. Vector<Vector2> Geometry2D::get_closest_points_between_segments(const Vector2 &p1, const Vector2 &q1, const Vector2 &p2, const Vector2 &q2) {
  538. Vector2 r1, r2;
  539. ::Geometry2D::get_closest_points_between_segments(p1, q1, p2, q2, r1, r2);
  540. Vector<Vector2> r = { r1, r2 };
  541. return r;
  542. }
  543. Vector2 Geometry2D::get_closest_point_to_segment(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b) {
  544. Vector2 s[2] = { p_a, p_b };
  545. return ::Geometry2D::get_closest_point_to_segment(p_point, s);
  546. }
  547. Vector2 Geometry2D::get_closest_point_to_segment_uncapped(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b) {
  548. Vector2 s[2] = { p_a, p_b };
  549. return ::Geometry2D::get_closest_point_to_segment_uncapped(p_point, s);
  550. }
  551. bool Geometry2D::point_is_inside_triangle(const Vector2 &s, const Vector2 &a, const Vector2 &b, const Vector2 &c) const {
  552. return ::Geometry2D::is_point_in_triangle(s, a, b, c);
  553. }
  554. bool Geometry2D::is_polygon_clockwise(const Vector<Vector2> &p_polygon) {
  555. return ::Geometry2D::is_polygon_clockwise(p_polygon);
  556. }
  557. bool Geometry2D::is_point_in_polygon(const Point2 &p_point, const Vector<Vector2> &p_polygon) {
  558. return ::Geometry2D::is_point_in_polygon(p_point, p_polygon);
  559. }
  560. Vector<int> Geometry2D::triangulate_polygon(const Vector<Vector2> &p_polygon) {
  561. return ::Geometry2D::triangulate_polygon(p_polygon);
  562. }
  563. Vector<int> Geometry2D::triangulate_delaunay(const Vector<Vector2> &p_points) {
  564. return ::Geometry2D::triangulate_delaunay(p_points);
  565. }
  566. Vector<Point2> Geometry2D::convex_hull(const Vector<Point2> &p_points) {
  567. return ::Geometry2D::convex_hull(p_points);
  568. }
  569. TypedArray<PackedVector2Array> Geometry2D::merge_polygons(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
  570. Vector<Vector<Point2>> polys = ::Geometry2D::merge_polygons(p_polygon_a, p_polygon_b);
  571. Array ret;
  572. for (int i = 0; i < polys.size(); ++i) {
  573. ret.push_back(polys[i]);
  574. }
  575. return ret;
  576. }
  577. TypedArray<PackedVector2Array> Geometry2D::clip_polygons(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
  578. Vector<Vector<Point2>> polys = ::Geometry2D::clip_polygons(p_polygon_a, p_polygon_b);
  579. TypedArray<PackedVector2Array> ret;
  580. for (int i = 0; i < polys.size(); ++i) {
  581. ret.push_back(polys[i]);
  582. }
  583. return ret;
  584. }
  585. TypedArray<PackedVector2Array> Geometry2D::intersect_polygons(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
  586. Vector<Vector<Point2>> polys = ::Geometry2D::intersect_polygons(p_polygon_a, p_polygon_b);
  587. Array ret;
  588. for (int i = 0; i < polys.size(); ++i) {
  589. ret.push_back(polys[i]);
  590. }
  591. return ret;
  592. }
  593. TypedArray<PackedVector2Array> Geometry2D::exclude_polygons(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
  594. Vector<Vector<Point2>> polys = ::Geometry2D::exclude_polygons(p_polygon_a, p_polygon_b);
  595. Array ret;
  596. for (int i = 0; i < polys.size(); ++i) {
  597. ret.push_back(polys[i]);
  598. }
  599. return ret;
  600. }
  601. TypedArray<PackedVector2Array> Geometry2D::clip_polyline_with_polygon(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) {
  602. Vector<Vector<Point2>> polys = ::Geometry2D::clip_polyline_with_polygon(p_polyline, p_polygon);
  603. Array ret;
  604. for (int i = 0; i < polys.size(); ++i) {
  605. ret.push_back(polys[i]);
  606. }
  607. return ret;
  608. }
  609. TypedArray<PackedVector2Array> Geometry2D::intersect_polyline_with_polygon(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) {
  610. Vector<Vector<Point2>> polys = ::Geometry2D::intersect_polyline_with_polygon(p_polyline, p_polygon);
  611. Array ret;
  612. for (int i = 0; i < polys.size(); ++i) {
  613. ret.push_back(polys[i]);
  614. }
  615. return ret;
  616. }
  617. TypedArray<PackedVector2Array> Geometry2D::offset_polygon(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type) {
  618. Vector<Vector<Point2>> polys = ::Geometry2D::offset_polygon(p_polygon, p_delta, ::Geometry2D::PolyJoinType(p_join_type));
  619. Array ret;
  620. for (int i = 0; i < polys.size(); ++i) {
  621. ret.push_back(polys[i]);
  622. }
  623. return ret;
  624. }
  625. TypedArray<PackedVector2Array> Geometry2D::offset_polyline(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type, PolyEndType p_end_type) {
  626. Vector<Vector<Point2>> polys = ::Geometry2D::offset_polyline(p_polygon, p_delta, ::Geometry2D::PolyJoinType(p_join_type), ::Geometry2D::PolyEndType(p_end_type));
  627. Array ret;
  628. for (int i = 0; i < polys.size(); ++i) {
  629. ret.push_back(polys[i]);
  630. }
  631. return ret;
  632. }
  633. Dictionary Geometry2D::make_atlas(const Vector<Size2> &p_rects) {
  634. Dictionary ret;
  635. Vector<Size2i> rects;
  636. for (int i = 0; i < p_rects.size(); i++) {
  637. rects.push_back(p_rects[i]);
  638. }
  639. Vector<Point2i> result;
  640. Size2i size;
  641. ::Geometry2D::make_atlas(rects, result, size);
  642. Size2 r_size = size;
  643. Vector<Point2> r_result;
  644. for (int i = 0; i < result.size(); i++) {
  645. r_result.push_back(result[i]);
  646. }
  647. ret["points"] = r_result;
  648. ret["size"] = r_size;
  649. return ret;
  650. }
  651. void Geometry2D::_bind_methods() {
  652. ClassDB::bind_method(D_METHOD("is_point_in_circle", "point", "circle_position", "circle_radius"), &Geometry2D::is_point_in_circle);
  653. ClassDB::bind_method(D_METHOD("segment_intersects_circle", "segment_from", "segment_to", "circle_position", "circle_radius"), &Geometry2D::segment_intersects_circle);
  654. ClassDB::bind_method(D_METHOD("segment_intersects_segment", "from_a", "to_a", "from_b", "to_b"), &Geometry2D::segment_intersects_segment);
  655. ClassDB::bind_method(D_METHOD("line_intersects_line", "from_a", "dir_a", "from_b", "dir_b"), &Geometry2D::line_intersects_line);
  656. ClassDB::bind_method(D_METHOD("get_closest_points_between_segments", "p1", "q1", "p2", "q2"), &Geometry2D::get_closest_points_between_segments);
  657. ClassDB::bind_method(D_METHOD("get_closest_point_to_segment", "point", "s1", "s2"), &Geometry2D::get_closest_point_to_segment);
  658. ClassDB::bind_method(D_METHOD("get_closest_point_to_segment_uncapped", "point", "s1", "s2"), &Geometry2D::get_closest_point_to_segment_uncapped);
  659. ClassDB::bind_method(D_METHOD("point_is_inside_triangle", "point", "a", "b", "c"), &Geometry2D::point_is_inside_triangle);
  660. ClassDB::bind_method(D_METHOD("is_polygon_clockwise", "polygon"), &Geometry2D::is_polygon_clockwise);
  661. ClassDB::bind_method(D_METHOD("is_point_in_polygon", "point", "polygon"), &Geometry2D::is_point_in_polygon);
  662. ClassDB::bind_method(D_METHOD("triangulate_polygon", "polygon"), &Geometry2D::triangulate_polygon);
  663. ClassDB::bind_method(D_METHOD("triangulate_delaunay", "points"), &Geometry2D::triangulate_delaunay);
  664. ClassDB::bind_method(D_METHOD("convex_hull", "points"), &Geometry2D::convex_hull);
  665. ClassDB::bind_method(D_METHOD("merge_polygons", "polygon_a", "polygon_b"), &Geometry2D::merge_polygons);
  666. ClassDB::bind_method(D_METHOD("clip_polygons", "polygon_a", "polygon_b"), &Geometry2D::clip_polygons);
  667. ClassDB::bind_method(D_METHOD("intersect_polygons", "polygon_a", "polygon_b"), &Geometry2D::intersect_polygons);
  668. ClassDB::bind_method(D_METHOD("exclude_polygons", "polygon_a", "polygon_b"), &Geometry2D::exclude_polygons);
  669. ClassDB::bind_method(D_METHOD("clip_polyline_with_polygon", "polyline", "polygon"), &Geometry2D::clip_polyline_with_polygon);
  670. ClassDB::bind_method(D_METHOD("intersect_polyline_with_polygon", "polyline", "polygon"), &Geometry2D::intersect_polyline_with_polygon);
  671. ClassDB::bind_method(D_METHOD("offset_polygon", "polygon", "delta", "join_type"), &Geometry2D::offset_polygon, DEFVAL(JOIN_SQUARE));
  672. ClassDB::bind_method(D_METHOD("offset_polyline", "polyline", "delta", "join_type", "end_type"), &Geometry2D::offset_polyline, DEFVAL(JOIN_SQUARE), DEFVAL(END_SQUARE));
  673. ClassDB::bind_method(D_METHOD("make_atlas", "sizes"), &Geometry2D::make_atlas);
  674. BIND_ENUM_CONSTANT(OPERATION_UNION);
  675. BIND_ENUM_CONSTANT(OPERATION_DIFFERENCE);
  676. BIND_ENUM_CONSTANT(OPERATION_INTERSECTION);
  677. BIND_ENUM_CONSTANT(OPERATION_XOR);
  678. BIND_ENUM_CONSTANT(JOIN_SQUARE);
  679. BIND_ENUM_CONSTANT(JOIN_ROUND);
  680. BIND_ENUM_CONSTANT(JOIN_MITER);
  681. BIND_ENUM_CONSTANT(END_POLYGON);
  682. BIND_ENUM_CONSTANT(END_JOINED);
  683. BIND_ENUM_CONSTANT(END_BUTT);
  684. BIND_ENUM_CONSTANT(END_SQUARE);
  685. BIND_ENUM_CONSTANT(END_ROUND);
  686. }
  687. ////// Geometry3D //////
  688. Geometry3D *Geometry3D::singleton = nullptr;
  689. Geometry3D *Geometry3D::get_singleton() {
  690. return singleton;
  691. }
  692. TypedArray<Plane> Geometry3D::build_box_planes(const Vector3 &p_extents) {
  693. Variant ret = ::Geometry3D::build_box_planes(p_extents);
  694. return ret;
  695. }
  696. TypedArray<Plane> Geometry3D::build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis) {
  697. Variant ret = ::Geometry3D::build_cylinder_planes(p_radius, p_height, p_sides, p_axis);
  698. return ret;
  699. }
  700. TypedArray<Plane> Geometry3D::build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis) {
  701. Variant ret = ::Geometry3D::build_capsule_planes(p_radius, p_height, p_sides, p_lats, p_axis);
  702. return ret;
  703. }
  704. Vector<Vector3> Geometry3D::get_closest_points_between_segments(const Vector3 &p1, const Vector3 &p2, const Vector3 &q1, const Vector3 &q2) {
  705. Vector3 r1, r2;
  706. ::Geometry3D::get_closest_points_between_segments(p1, p2, q1, q2, r1, r2);
  707. Vector<Vector3> r = { r1, r2 };
  708. return r;
  709. }
  710. Vector3 Geometry3D::get_closest_point_to_segment(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b) {
  711. Vector3 s[2] = { p_a, p_b };
  712. return ::Geometry3D::get_closest_point_to_segment(p_point, s);
  713. }
  714. Vector3 Geometry3D::get_closest_point_to_segment_uncapped(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b) {
  715. Vector3 s[2] = { p_a, p_b };
  716. return ::Geometry3D::get_closest_point_to_segment_uncapped(p_point, s);
  717. }
  718. 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) {
  719. Vector3 res;
  720. if (::Geometry3D::ray_intersects_triangle(p_from, p_dir, p_v0, p_v1, p_v2, &res)) {
  721. return res;
  722. } else {
  723. return Variant();
  724. }
  725. }
  726. 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) {
  727. Vector3 res;
  728. if (::Geometry3D::segment_intersects_triangle(p_from, p_to, p_v0, p_v1, p_v2, &res)) {
  729. return res;
  730. } else {
  731. return Variant();
  732. }
  733. }
  734. Vector<Vector3> Geometry3D::segment_intersects_sphere(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_sphere_pos, real_t p_sphere_radius) {
  735. Vector<Vector3> r;
  736. Vector3 res, norm;
  737. if (!::Geometry3D::segment_intersects_sphere(p_from, p_to, p_sphere_pos, p_sphere_radius, &res, &norm)) {
  738. return r;
  739. }
  740. r.resize(2);
  741. r.set(0, res);
  742. r.set(1, norm);
  743. return r;
  744. }
  745. Vector<Vector3> Geometry3D::segment_intersects_cylinder(const Vector3 &p_from, const Vector3 &p_to, float p_height, float p_radius) {
  746. Vector<Vector3> r;
  747. Vector3 res, norm;
  748. if (!::Geometry3D::segment_intersects_cylinder(p_from, p_to, p_height, p_radius, &res, &norm)) {
  749. return r;
  750. }
  751. r.resize(2);
  752. r.set(0, res);
  753. r.set(1, norm);
  754. return r;
  755. }
  756. Vector<Vector3> Geometry3D::segment_intersects_convex(const Vector3 &p_from, const Vector3 &p_to, const Vector<Plane> &p_planes) {
  757. Vector<Vector3> r;
  758. Vector3 res, norm;
  759. if (!::Geometry3D::segment_intersects_convex(p_from, p_to, p_planes.ptr(), p_planes.size(), &res, &norm)) {
  760. return r;
  761. }
  762. r.resize(2);
  763. r.set(0, res);
  764. r.set(1, norm);
  765. return r;
  766. }
  767. Vector<Vector3> Geometry3D::clip_polygon(const Vector<Vector3> &p_points, const Plane &p_plane) {
  768. return ::Geometry3D::clip_polygon(p_points, p_plane);
  769. }
  770. void Geometry3D::_bind_methods() {
  771. ClassDB::bind_method(D_METHOD("build_box_planes", "extents"), &Geometry3D::build_box_planes);
  772. ClassDB::bind_method(D_METHOD("build_cylinder_planes", "radius", "height", "sides", "axis"), &Geometry3D::build_cylinder_planes, DEFVAL(Vector3::AXIS_Z));
  773. ClassDB::bind_method(D_METHOD("build_capsule_planes", "radius", "height", "sides", "lats", "axis"), &Geometry3D::build_capsule_planes, DEFVAL(Vector3::AXIS_Z));
  774. ClassDB::bind_method(D_METHOD("get_closest_points_between_segments", "p1", "p2", "q1", "q2"), &Geometry3D::get_closest_points_between_segments);
  775. ClassDB::bind_method(D_METHOD("get_closest_point_to_segment", "point", "s1", "s2"), &Geometry3D::get_closest_point_to_segment);
  776. ClassDB::bind_method(D_METHOD("get_closest_point_to_segment_uncapped", "point", "s1", "s2"), &Geometry3D::get_closest_point_to_segment_uncapped);
  777. ClassDB::bind_method(D_METHOD("ray_intersects_triangle", "from", "dir", "a", "b", "c"), &Geometry3D::ray_intersects_triangle);
  778. ClassDB::bind_method(D_METHOD("segment_intersects_triangle", "from", "to", "a", "b", "c"), &Geometry3D::segment_intersects_triangle);
  779. ClassDB::bind_method(D_METHOD("segment_intersects_sphere", "from", "to", "sphere_position", "sphere_radius"), &Geometry3D::segment_intersects_sphere);
  780. ClassDB::bind_method(D_METHOD("segment_intersects_cylinder", "from", "to", "height", "radius"), &Geometry3D::segment_intersects_cylinder);
  781. ClassDB::bind_method(D_METHOD("segment_intersects_convex", "from", "to", "planes"), &Geometry3D::segment_intersects_convex);
  782. ClassDB::bind_method(D_METHOD("clip_polygon", "points", "plane"), &Geometry3D::clip_polygon);
  783. }
  784. ////// File //////
  785. Error File::open_encrypted(const String &p_path, ModeFlags p_mode_flags, const Vector<uint8_t> &p_key) {
  786. Error err = open(p_path, p_mode_flags);
  787. if (err) {
  788. return err;
  789. }
  790. Ref<FileAccessEncrypted> fae;
  791. fae.instantiate();
  792. err = fae->open_and_parse(f, p_key, (p_mode_flags == WRITE) ? FileAccessEncrypted::MODE_WRITE_AES256 : FileAccessEncrypted::MODE_READ);
  793. if (err) {
  794. close();
  795. return err;
  796. }
  797. f = fae;
  798. return OK;
  799. }
  800. Error File::open_encrypted_pass(const String &p_path, ModeFlags p_mode_flags, const String &p_pass) {
  801. Error err = open(p_path, p_mode_flags);
  802. if (err) {
  803. return err;
  804. }
  805. Ref<FileAccessEncrypted> fae;
  806. fae.instantiate();
  807. err = fae->open_and_parse_password(f, p_pass, (p_mode_flags == WRITE) ? FileAccessEncrypted::MODE_WRITE_AES256 : FileAccessEncrypted::MODE_READ);
  808. if (err) {
  809. close();
  810. return err;
  811. }
  812. f = fae;
  813. return OK;
  814. }
  815. Error File::open_compressed(const String &p_path, ModeFlags p_mode_flags, CompressionMode p_compress_mode) {
  816. Ref<FileAccessCompressed> fac;
  817. fac.instantiate();
  818. fac->configure("GCPF", (Compression::Mode)p_compress_mode);
  819. Error err = fac->_open(p_path, p_mode_flags);
  820. if (err) {
  821. return err;
  822. }
  823. f = fac;
  824. return OK;
  825. }
  826. Error File::open(const String &p_path, ModeFlags p_mode_flags) {
  827. Error err;
  828. f = FileAccess::open(p_path, p_mode_flags, &err);
  829. if (f.is_valid()) {
  830. f->set_big_endian(big_endian);
  831. }
  832. return err;
  833. }
  834. void File::flush() {
  835. ERR_FAIL_COND_MSG(f.is_null(), "File must be opened before flushing.");
  836. f->flush();
  837. }
  838. void File::close() {
  839. ERR_FAIL_COND_MSG(f.is_null(), "File must be opened.");
  840. f.unref();
  841. }
  842. bool File::is_open() const {
  843. return f != nullptr;
  844. }
  845. String File::get_path() const {
  846. ERR_FAIL_COND_V_MSG(f.is_null(), "", "File must be opened before use, or is lacking read-write permission.");
  847. return f->get_path();
  848. }
  849. String File::get_path_absolute() const {
  850. ERR_FAIL_COND_V_MSG(f.is_null(), "", "File must be opened before use, or is lacking read-write permission.");
  851. return f->get_path_absolute();
  852. }
  853. void File::seek(int64_t p_position) {
  854. ERR_FAIL_COND_MSG(f.is_null(), "File must be opened before use, or is lacking read-write permission.");
  855. ERR_FAIL_COND_MSG(p_position < 0, "Seek position must be a positive integer.");
  856. f->seek(p_position);
  857. }
  858. void File::seek_end(int64_t p_position) {
  859. ERR_FAIL_COND_MSG(f.is_null(), "File must be opened before use, or is lacking read-write permission.");
  860. f->seek_end(p_position);
  861. }
  862. uint64_t File::get_position() const {
  863. ERR_FAIL_COND_V_MSG(f.is_null(), 0, "File must be opened before use, or is lacking read-write permission.");
  864. return f->get_position();
  865. }
  866. uint64_t File::get_length() const {
  867. ERR_FAIL_COND_V_MSG(f.is_null(), 0, "File must be opened before use, or is lacking read-write permission.");
  868. return f->get_length();
  869. }
  870. bool File::eof_reached() const {
  871. ERR_FAIL_COND_V_MSG(f.is_null(), false, "File must be opened before use, or is lacking read-write permission.");
  872. return f->eof_reached();
  873. }
  874. uint8_t File::get_8() const {
  875. ERR_FAIL_COND_V_MSG(f.is_null(), 0, "File must be opened before use, or is lacking read-write permission.");
  876. return f->get_8();
  877. }
  878. uint16_t File::get_16() const {
  879. ERR_FAIL_COND_V_MSG(f.is_null(), 0, "File must be opened before use, or is lacking read-write permission.");
  880. return f->get_16();
  881. }
  882. uint32_t File::get_32() const {
  883. ERR_FAIL_COND_V_MSG(f.is_null(), 0, "File must be opened before use, or is lacking read-write permission.");
  884. return f->get_32();
  885. }
  886. uint64_t File::get_64() const {
  887. ERR_FAIL_COND_V_MSG(f.is_null(), 0, "File must be opened before use, or is lacking read-write permission.");
  888. return f->get_64();
  889. }
  890. float File::get_float() const {
  891. ERR_FAIL_COND_V_MSG(f.is_null(), 0, "File must be opened before use, or is lacking read-write permission.");
  892. return f->get_float();
  893. }
  894. double File::get_double() const {
  895. ERR_FAIL_COND_V_MSG(f.is_null(), 0, "File must be opened before use, or is lacking read-write permission.");
  896. return f->get_double();
  897. }
  898. real_t File::get_real() const {
  899. ERR_FAIL_COND_V_MSG(f.is_null(), 0, "File must be opened before use, or is lacking read-write permission.");
  900. return f->get_real();
  901. }
  902. Vector<uint8_t> File::get_buffer(int64_t p_length) const {
  903. Vector<uint8_t> data;
  904. ERR_FAIL_COND_V_MSG(f.is_null(), data, "File must be opened before use, or is lacking read-write permission.");
  905. ERR_FAIL_COND_V_MSG(p_length < 0, data, "Length of buffer cannot be smaller than 0.");
  906. if (p_length == 0) {
  907. return data;
  908. }
  909. Error err = data.resize(p_length);
  910. ERR_FAIL_COND_V_MSG(err != OK, data, "Can't resize data to " + itos(p_length) + " elements.");
  911. uint8_t *w = data.ptrw();
  912. int64_t len = f->get_buffer(&w[0], p_length);
  913. if (len < p_length) {
  914. data.resize(len);
  915. }
  916. return data;
  917. }
  918. String File::get_as_text(bool p_skip_cr) const {
  919. ERR_FAIL_COND_V_MSG(f.is_null(), String(), "File must be opened before use, or is lacking read-write permission.");
  920. uint64_t original_pos = f->get_position();
  921. const_cast<FileAccess *>(*f)->seek(0);
  922. String text = f->get_as_utf8_string(p_skip_cr);
  923. const_cast<FileAccess *>(*f)->seek(original_pos);
  924. return text;
  925. }
  926. String File::get_md5(const String &p_path) const {
  927. return FileAccess::get_md5(p_path);
  928. }
  929. String File::get_sha256(const String &p_path) const {
  930. return FileAccess::get_sha256(p_path);
  931. }
  932. String File::get_line() const {
  933. ERR_FAIL_COND_V_MSG(f.is_null(), String(), "File must be opened before use, or is lacking read-write permission.");
  934. return f->get_line();
  935. }
  936. Vector<String> File::get_csv_line(const String &p_delim) const {
  937. ERR_FAIL_COND_V_MSG(f.is_null(), Vector<String>(), "File must be opened before use, or is lacking read-write permission.");
  938. return f->get_csv_line(p_delim);
  939. }
  940. /**< use this for files WRITTEN in _big_ endian machines (i.e. amiga/mac)
  941. * It's not about the current CPU type but file formats.
  942. * These flags get reset to false (little endian) on each open
  943. */
  944. void File::set_big_endian(bool p_big_endian) {
  945. big_endian = p_big_endian;
  946. if (f.is_valid()) {
  947. f->set_big_endian(p_big_endian);
  948. }
  949. }
  950. bool File::is_big_endian() {
  951. return big_endian;
  952. }
  953. Error File::get_error() const {
  954. if (f.is_null()) {
  955. return ERR_UNCONFIGURED;
  956. }
  957. return f->get_error();
  958. }
  959. void File::store_8(uint8_t p_dest) {
  960. ERR_FAIL_COND_MSG(f.is_null(), "File must be opened before use, or is lacking read-write permission.");
  961. f->store_8(p_dest);
  962. }
  963. void File::store_16(uint16_t p_dest) {
  964. ERR_FAIL_COND_MSG(f.is_null(), "File must be opened before use, or is lacking read-write permission.");
  965. f->store_16(p_dest);
  966. }
  967. void File::store_32(uint32_t p_dest) {
  968. ERR_FAIL_COND_MSG(f.is_null(), "File must be opened before use, or is lacking read-write permission.");
  969. f->store_32(p_dest);
  970. }
  971. void File::store_64(uint64_t p_dest) {
  972. ERR_FAIL_COND_MSG(f.is_null(), "File must be opened before use, or is lacking read-write permission.");
  973. f->store_64(p_dest);
  974. }
  975. void File::store_float(float p_dest) {
  976. ERR_FAIL_COND_MSG(f.is_null(), "File must be opened before use, or is lacking read-write permission.");
  977. f->store_float(p_dest);
  978. }
  979. void File::store_double(double p_dest) {
  980. ERR_FAIL_COND_MSG(f.is_null(), "File must be opened before use, or is lacking read-write permission.");
  981. f->store_double(p_dest);
  982. }
  983. void File::store_real(real_t p_real) {
  984. ERR_FAIL_COND_MSG(f.is_null(), "File must be opened before use, or is lacking read-write permission.");
  985. f->store_real(p_real);
  986. }
  987. void File::store_string(const String &p_string) {
  988. ERR_FAIL_COND_MSG(f.is_null(), "File must be opened before use, or is lacking read-write permission.");
  989. f->store_string(p_string);
  990. }
  991. void File::store_pascal_string(const String &p_string) {
  992. ERR_FAIL_COND_MSG(f.is_null(), "File must be opened before use, or is lacking read-write permission.");
  993. f->store_pascal_string(p_string);
  994. }
  995. String File::get_pascal_string() {
  996. ERR_FAIL_COND_V_MSG(f.is_null(), "", "File must be opened before use, or is lacking read-write permission.");
  997. return f->get_pascal_string();
  998. }
  999. void File::store_line(const String &p_string) {
  1000. ERR_FAIL_COND_MSG(f.is_null(), "File must be opened before use, or is lacking read-write permission.");
  1001. f->store_line(p_string);
  1002. }
  1003. void File::store_csv_line(const Vector<String> &p_values, const String &p_delim) {
  1004. ERR_FAIL_COND_MSG(f.is_null(), "File must be opened before use, or is lacking read-write permission.");
  1005. f->store_csv_line(p_values, p_delim);
  1006. }
  1007. void File::store_buffer(const Vector<uint8_t> &p_buffer) {
  1008. ERR_FAIL_COND_MSG(f.is_null(), "File must be opened before use, or is lacking read-write permission.");
  1009. uint64_t len = p_buffer.size();
  1010. if (len == 0) {
  1011. return;
  1012. }
  1013. const uint8_t *r = p_buffer.ptr();
  1014. f->store_buffer(&r[0], len);
  1015. }
  1016. bool File::file_exists(const String &p_name) {
  1017. return FileAccess::exists(p_name);
  1018. }
  1019. void File::store_var(const Variant &p_var, bool p_full_objects) {
  1020. ERR_FAIL_COND_MSG(f.is_null(), "File must be opened before use, or is lacking read-write permission.");
  1021. int len;
  1022. Error err = encode_variant(p_var, nullptr, len, p_full_objects);
  1023. ERR_FAIL_COND_MSG(err != OK, "Error when trying to encode Variant.");
  1024. Vector<uint8_t> buff;
  1025. buff.resize(len);
  1026. uint8_t *w = buff.ptrw();
  1027. err = encode_variant(p_var, &w[0], len, p_full_objects);
  1028. ERR_FAIL_COND_MSG(err != OK, "Error when trying to encode Variant.");
  1029. store_32(len);
  1030. store_buffer(buff);
  1031. }
  1032. Variant File::get_var(bool p_allow_objects) const {
  1033. ERR_FAIL_COND_V_MSG(f.is_null(), Variant(), "File must be opened before use, or is lacking read-write permission.");
  1034. uint32_t len = get_32();
  1035. Vector<uint8_t> buff = get_buffer(len);
  1036. ERR_FAIL_COND_V((uint32_t)buff.size() != len, Variant());
  1037. const uint8_t *r = buff.ptr();
  1038. Variant v;
  1039. Error err = decode_variant(v, &r[0], len, nullptr, p_allow_objects);
  1040. ERR_FAIL_COND_V_MSG(err != OK, Variant(), "Error when trying to encode Variant.");
  1041. return v;
  1042. }
  1043. uint64_t File::get_modified_time(const String &p_file) const {
  1044. return FileAccess::get_modified_time(p_file);
  1045. }
  1046. void File::_bind_methods() {
  1047. ClassDB::bind_method(D_METHOD("open_encrypted", "path", "mode_flags", "key"), &File::open_encrypted);
  1048. ClassDB::bind_method(D_METHOD("open_encrypted_with_pass", "path", "mode_flags", "pass"), &File::open_encrypted_pass);
  1049. ClassDB::bind_method(D_METHOD("open_compressed", "path", "mode_flags", "compression_mode"), &File::open_compressed, DEFVAL(0));
  1050. ClassDB::bind_method(D_METHOD("open", "path", "flags"), &File::open);
  1051. ClassDB::bind_method(D_METHOD("flush"), &File::flush);
  1052. ClassDB::bind_method(D_METHOD("close"), &File::close);
  1053. ClassDB::bind_method(D_METHOD("get_path"), &File::get_path);
  1054. ClassDB::bind_method(D_METHOD("get_path_absolute"), &File::get_path_absolute);
  1055. ClassDB::bind_method(D_METHOD("is_open"), &File::is_open);
  1056. ClassDB::bind_method(D_METHOD("seek", "position"), &File::seek);
  1057. ClassDB::bind_method(D_METHOD("seek_end", "position"), &File::seek_end, DEFVAL(0));
  1058. ClassDB::bind_method(D_METHOD("get_position"), &File::get_position);
  1059. ClassDB::bind_method(D_METHOD("get_length"), &File::get_length);
  1060. ClassDB::bind_method(D_METHOD("eof_reached"), &File::eof_reached);
  1061. ClassDB::bind_method(D_METHOD("get_8"), &File::get_8);
  1062. ClassDB::bind_method(D_METHOD("get_16"), &File::get_16);
  1063. ClassDB::bind_method(D_METHOD("get_32"), &File::get_32);
  1064. ClassDB::bind_method(D_METHOD("get_64"), &File::get_64);
  1065. ClassDB::bind_method(D_METHOD("get_float"), &File::get_float);
  1066. ClassDB::bind_method(D_METHOD("get_double"), &File::get_double);
  1067. ClassDB::bind_method(D_METHOD("get_real"), &File::get_real);
  1068. ClassDB::bind_method(D_METHOD("get_buffer", "length"), &File::get_buffer);
  1069. ClassDB::bind_method(D_METHOD("get_line"), &File::get_line);
  1070. ClassDB::bind_method(D_METHOD("get_csv_line", "delim"), &File::get_csv_line, DEFVAL(","));
  1071. ClassDB::bind_method(D_METHOD("get_as_text", "skip_cr"), &File::get_as_text, DEFVAL(false));
  1072. ClassDB::bind_method(D_METHOD("get_md5", "path"), &File::get_md5);
  1073. ClassDB::bind_method(D_METHOD("get_sha256", "path"), &File::get_sha256);
  1074. ClassDB::bind_method(D_METHOD("is_big_endian"), &File::is_big_endian);
  1075. ClassDB::bind_method(D_METHOD("set_big_endian", "big_endian"), &File::set_big_endian);
  1076. ClassDB::bind_method(D_METHOD("get_error"), &File::get_error);
  1077. ClassDB::bind_method(D_METHOD("get_var", "allow_objects"), &File::get_var, DEFVAL(false));
  1078. ClassDB::bind_method(D_METHOD("store_8", "value"), &File::store_8);
  1079. ClassDB::bind_method(D_METHOD("store_16", "value"), &File::store_16);
  1080. ClassDB::bind_method(D_METHOD("store_32", "value"), &File::store_32);
  1081. ClassDB::bind_method(D_METHOD("store_64", "value"), &File::store_64);
  1082. ClassDB::bind_method(D_METHOD("store_float", "value"), &File::store_float);
  1083. ClassDB::bind_method(D_METHOD("store_double", "value"), &File::store_double);
  1084. ClassDB::bind_method(D_METHOD("store_real", "value"), &File::store_real);
  1085. ClassDB::bind_method(D_METHOD("store_buffer", "buffer"), &File::store_buffer);
  1086. ClassDB::bind_method(D_METHOD("store_line", "line"), &File::store_line);
  1087. ClassDB::bind_method(D_METHOD("store_csv_line", "values", "delim"), &File::store_csv_line, DEFVAL(","));
  1088. ClassDB::bind_method(D_METHOD("store_string", "string"), &File::store_string);
  1089. ClassDB::bind_method(D_METHOD("store_var", "value", "full_objects"), &File::store_var, DEFVAL(false));
  1090. ClassDB::bind_method(D_METHOD("store_pascal_string", "string"), &File::store_pascal_string);
  1091. ClassDB::bind_method(D_METHOD("get_pascal_string"), &File::get_pascal_string);
  1092. ClassDB::bind_static_method("File", D_METHOD("file_exists", "path"), &File::file_exists);
  1093. ClassDB::bind_method(D_METHOD("get_modified_time", "file"), &File::get_modified_time);
  1094. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "big_endian"), "set_big_endian", "is_big_endian");
  1095. BIND_ENUM_CONSTANT(READ);
  1096. BIND_ENUM_CONSTANT(WRITE);
  1097. BIND_ENUM_CONSTANT(READ_WRITE);
  1098. BIND_ENUM_CONSTANT(WRITE_READ);
  1099. BIND_ENUM_CONSTANT(COMPRESSION_FASTLZ);
  1100. BIND_ENUM_CONSTANT(COMPRESSION_DEFLATE);
  1101. BIND_ENUM_CONSTANT(COMPRESSION_ZSTD);
  1102. BIND_ENUM_CONSTANT(COMPRESSION_GZIP);
  1103. }
  1104. ////// Directory //////
  1105. Error Directory::open(const String &p_path) {
  1106. Error err;
  1107. Ref<DirAccess> alt = DirAccess::open(p_path, &err);
  1108. if (alt.is_null()) {
  1109. return err;
  1110. }
  1111. d = alt;
  1112. dir_open = true;
  1113. return OK;
  1114. }
  1115. bool Directory::is_open() const {
  1116. return d.is_valid() && dir_open;
  1117. }
  1118. Error Directory::list_dir_begin() {
  1119. ERR_FAIL_COND_V_MSG(!is_open(), ERR_UNCONFIGURED, "Directory must be opened before use.");
  1120. return d->list_dir_begin();
  1121. }
  1122. String Directory::get_next() {
  1123. ERR_FAIL_COND_V_MSG(!is_open(), "", "Directory must be opened before use.");
  1124. String next = d->get_next();
  1125. while (!next.is_empty() && ((!include_navigational && (next == "." || next == "..")) || (!include_hidden && d->current_is_hidden()))) {
  1126. next = d->get_next();
  1127. }
  1128. return next;
  1129. }
  1130. bool Directory::current_is_dir() const {
  1131. ERR_FAIL_COND_V_MSG(!is_open(), false, "Directory must be opened before use.");
  1132. return d->current_is_dir();
  1133. }
  1134. void Directory::list_dir_end() {
  1135. ERR_FAIL_COND_MSG(!is_open(), "Directory must be opened before use.");
  1136. d->list_dir_end();
  1137. }
  1138. PackedStringArray Directory::get_files() {
  1139. return _get_contents(false);
  1140. }
  1141. PackedStringArray Directory::get_directories() {
  1142. return _get_contents(true);
  1143. }
  1144. PackedStringArray Directory::_get_contents(bool p_directories) {
  1145. PackedStringArray ret;
  1146. ERR_FAIL_COND_V_MSG(!is_open(), ret, "Directory must be opened before use.");
  1147. list_dir_begin();
  1148. String s = get_next();
  1149. while (!s.is_empty()) {
  1150. if (current_is_dir() == p_directories) {
  1151. ret.append(s);
  1152. }
  1153. s = get_next();
  1154. }
  1155. ret.sort();
  1156. return ret;
  1157. }
  1158. void Directory::set_include_navigational(bool p_enable) {
  1159. include_navigational = p_enable;
  1160. }
  1161. bool Directory::get_include_navigational() const {
  1162. return include_navigational;
  1163. }
  1164. void Directory::set_include_hidden(bool p_enable) {
  1165. include_hidden = p_enable;
  1166. }
  1167. bool Directory::get_include_hidden() const {
  1168. return include_hidden;
  1169. }
  1170. int Directory::get_drive_count() {
  1171. ERR_FAIL_COND_V_MSG(!is_open(), 0, "Directory must be opened before use.");
  1172. return d->get_drive_count();
  1173. }
  1174. String Directory::get_drive(int p_drive) {
  1175. ERR_FAIL_COND_V_MSG(!is_open(), "", "Directory must be opened before use.");
  1176. return d->get_drive(p_drive);
  1177. }
  1178. int Directory::get_current_drive() {
  1179. ERR_FAIL_COND_V_MSG(!is_open(), 0, "Directory must be opened before use.");
  1180. return d->get_current_drive();
  1181. }
  1182. Error Directory::change_dir(String p_dir) {
  1183. ERR_FAIL_COND_V_MSG(d.is_null(), ERR_UNCONFIGURED, "Directory is not configured properly.");
  1184. Error err = d->change_dir(p_dir);
  1185. if (err != OK) {
  1186. return err;
  1187. }
  1188. dir_open = true;
  1189. return OK;
  1190. }
  1191. String Directory::get_current_dir() {
  1192. ERR_FAIL_COND_V_MSG(!is_open(), "", "Directory must be opened before use.");
  1193. return d->get_current_dir();
  1194. }
  1195. Error Directory::make_dir(String p_dir) {
  1196. ERR_FAIL_COND_V_MSG(d.is_null(), ERR_UNCONFIGURED, "Directory is not configured properly.");
  1197. if (!p_dir.is_relative_path()) {
  1198. Ref<DirAccess> da = DirAccess::create_for_path(p_dir);
  1199. return da->make_dir(p_dir);
  1200. }
  1201. return d->make_dir(p_dir);
  1202. }
  1203. Error Directory::make_dir_recursive(String p_dir) {
  1204. ERR_FAIL_COND_V_MSG(d.is_null(), ERR_UNCONFIGURED, "Directory is not configured properly.");
  1205. if (!p_dir.is_relative_path()) {
  1206. Ref<DirAccess> da = DirAccess::create_for_path(p_dir);
  1207. return da->make_dir_recursive(p_dir);
  1208. }
  1209. return d->make_dir_recursive(p_dir);
  1210. }
  1211. bool Directory::file_exists(String p_file) {
  1212. ERR_FAIL_COND_V_MSG(d.is_null(), false, "Directory is not configured properly.");
  1213. if (!p_file.is_relative_path()) {
  1214. return FileAccess::exists(p_file);
  1215. }
  1216. return d->file_exists(p_file);
  1217. }
  1218. bool Directory::dir_exists(String p_dir) {
  1219. ERR_FAIL_COND_V_MSG(d.is_null(), false, "Directory is not configured properly.");
  1220. if (!p_dir.is_relative_path()) {
  1221. return DirAccess::exists(p_dir);
  1222. }
  1223. return d->dir_exists(p_dir);
  1224. }
  1225. uint64_t Directory::get_space_left() {
  1226. ERR_FAIL_COND_V_MSG(d.is_null(), 0, "Directory must be opened before use.");
  1227. return d->get_space_left() / 1024 * 1024; // Truncate to closest MiB.
  1228. }
  1229. Error Directory::copy(String p_from, String p_to) {
  1230. ERR_FAIL_COND_V_MSG(!is_open(), ERR_UNCONFIGURED, "Directory must be opened before use.");
  1231. return d->copy(p_from, p_to);
  1232. }
  1233. Error Directory::rename(String p_from, String p_to) {
  1234. ERR_FAIL_COND_V_MSG(!is_open(), ERR_UNCONFIGURED, "Directory must be opened before use.");
  1235. ERR_FAIL_COND_V_MSG(p_from.is_empty() || p_from == "." || p_from == "..", ERR_INVALID_PARAMETER, "Invalid path to rename.");
  1236. if (!p_from.is_relative_path()) {
  1237. Ref<DirAccess> da = DirAccess::create_for_path(p_from);
  1238. ERR_FAIL_COND_V_MSG(!da->file_exists(p_from) && !da->dir_exists(p_from), ERR_DOES_NOT_EXIST, "File or directory does not exist.");
  1239. return da->rename(p_from, p_to);
  1240. }
  1241. ERR_FAIL_COND_V_MSG(!d->file_exists(p_from) && !d->dir_exists(p_from), ERR_DOES_NOT_EXIST, "File or directory does not exist.");
  1242. return d->rename(p_from, p_to);
  1243. }
  1244. Error Directory::remove(String p_name) {
  1245. ERR_FAIL_COND_V_MSG(!is_open(), ERR_UNCONFIGURED, "Directory must be opened before use.");
  1246. if (!p_name.is_relative_path()) {
  1247. Ref<DirAccess> da = DirAccess::create_for_path(p_name);
  1248. return da->remove(p_name);
  1249. }
  1250. return d->remove(p_name);
  1251. }
  1252. void Directory::_bind_methods() {
  1253. ClassDB::bind_method(D_METHOD("open", "path"), &Directory::open);
  1254. ClassDB::bind_method(D_METHOD("list_dir_begin"), &Directory::list_dir_begin, DEFVAL(false), DEFVAL(false));
  1255. ClassDB::bind_method(D_METHOD("get_next"), &Directory::get_next);
  1256. ClassDB::bind_method(D_METHOD("current_is_dir"), &Directory::current_is_dir);
  1257. ClassDB::bind_method(D_METHOD("list_dir_end"), &Directory::list_dir_end);
  1258. ClassDB::bind_method(D_METHOD("get_files"), &Directory::get_files);
  1259. ClassDB::bind_method(D_METHOD("get_directories"), &Directory::get_directories);
  1260. ClassDB::bind_method(D_METHOD("get_drive_count"), &Directory::get_drive_count);
  1261. ClassDB::bind_method(D_METHOD("get_drive", "idx"), &Directory::get_drive);
  1262. ClassDB::bind_method(D_METHOD("get_current_drive"), &Directory::get_current_drive);
  1263. ClassDB::bind_method(D_METHOD("change_dir", "todir"), &Directory::change_dir);
  1264. ClassDB::bind_method(D_METHOD("get_current_dir"), &Directory::get_current_dir);
  1265. ClassDB::bind_method(D_METHOD("make_dir", "path"), &Directory::make_dir);
  1266. ClassDB::bind_method(D_METHOD("make_dir_recursive", "path"), &Directory::make_dir_recursive);
  1267. ClassDB::bind_method(D_METHOD("file_exists", "path"), &Directory::file_exists);
  1268. ClassDB::bind_method(D_METHOD("dir_exists", "path"), &Directory::dir_exists);
  1269. ClassDB::bind_method(D_METHOD("get_space_left"), &Directory::get_space_left);
  1270. ClassDB::bind_method(D_METHOD("copy", "from", "to"), &Directory::copy);
  1271. ClassDB::bind_method(D_METHOD("rename", "from", "to"), &Directory::rename);
  1272. ClassDB::bind_method(D_METHOD("remove", "path"), &Directory::remove);
  1273. ClassDB::bind_method(D_METHOD("set_include_navigational", "enable"), &Directory::set_include_navigational);
  1274. ClassDB::bind_method(D_METHOD("get_include_navigational"), &Directory::get_include_navigational);
  1275. ClassDB::bind_method(D_METHOD("set_include_hidden", "enable"), &Directory::set_include_hidden);
  1276. ClassDB::bind_method(D_METHOD("get_include_hidden"), &Directory::get_include_hidden);
  1277. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "include_navigational"), "set_include_navigational", "get_include_navigational");
  1278. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "include_hidden"), "set_include_hidden", "get_include_hidden");
  1279. }
  1280. Directory::Directory() {
  1281. d = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  1282. }
  1283. ////// Marshalls //////
  1284. Marshalls *Marshalls::singleton = nullptr;
  1285. Marshalls *Marshalls::get_singleton() {
  1286. return singleton;
  1287. }
  1288. String Marshalls::variant_to_base64(const Variant &p_var, bool p_full_objects) {
  1289. int len;
  1290. Error err = encode_variant(p_var, nullptr, len, p_full_objects);
  1291. ERR_FAIL_COND_V_MSG(err != OK, "", "Error when trying to encode Variant.");
  1292. Vector<uint8_t> buff;
  1293. buff.resize(len);
  1294. uint8_t *w = buff.ptrw();
  1295. err = encode_variant(p_var, &w[0], len, p_full_objects);
  1296. ERR_FAIL_COND_V_MSG(err != OK, "", "Error when trying to encode Variant.");
  1297. String ret = CryptoCore::b64_encode_str(&w[0], len);
  1298. ERR_FAIL_COND_V(ret.is_empty(), ret);
  1299. return ret;
  1300. }
  1301. Variant Marshalls::base64_to_variant(const String &p_str, bool p_allow_objects) {
  1302. int strlen = p_str.length();
  1303. CharString cstr = p_str.ascii();
  1304. Vector<uint8_t> buf;
  1305. buf.resize(strlen / 4 * 3 + 1);
  1306. uint8_t *w = buf.ptrw();
  1307. size_t len = 0;
  1308. ERR_FAIL_COND_V(CryptoCore::b64_decode(&w[0], buf.size(), &len, (unsigned char *)cstr.get_data(), strlen) != OK, Variant());
  1309. Variant v;
  1310. Error err = decode_variant(v, &w[0], len, nullptr, p_allow_objects);
  1311. ERR_FAIL_COND_V_MSG(err != OK, Variant(), "Error when trying to decode Variant.");
  1312. return v;
  1313. }
  1314. String Marshalls::raw_to_base64(const Vector<uint8_t> &p_arr) {
  1315. String ret = CryptoCore::b64_encode_str(p_arr.ptr(), p_arr.size());
  1316. ERR_FAIL_COND_V(ret.is_empty(), ret);
  1317. return ret;
  1318. }
  1319. Vector<uint8_t> Marshalls::base64_to_raw(const String &p_str) {
  1320. int strlen = p_str.length();
  1321. CharString cstr = p_str.ascii();
  1322. size_t arr_len = 0;
  1323. Vector<uint8_t> buf;
  1324. {
  1325. buf.resize(strlen / 4 * 3 + 1);
  1326. uint8_t *w = buf.ptrw();
  1327. ERR_FAIL_COND_V(CryptoCore::b64_decode(&w[0], buf.size(), &arr_len, (unsigned char *)cstr.get_data(), strlen) != OK, Vector<uint8_t>());
  1328. }
  1329. buf.resize(arr_len);
  1330. return buf;
  1331. }
  1332. String Marshalls::utf8_to_base64(const String &p_str) {
  1333. CharString cstr = p_str.utf8();
  1334. String ret = CryptoCore::b64_encode_str((unsigned char *)cstr.get_data(), cstr.length());
  1335. ERR_FAIL_COND_V(ret.is_empty(), ret);
  1336. return ret;
  1337. }
  1338. String Marshalls::base64_to_utf8(const String &p_str) {
  1339. int strlen = p_str.length();
  1340. CharString cstr = p_str.ascii();
  1341. Vector<uint8_t> buf;
  1342. buf.resize(strlen / 4 * 3 + 1 + 1);
  1343. uint8_t *w = buf.ptrw();
  1344. size_t len = 0;
  1345. ERR_FAIL_COND_V(CryptoCore::b64_decode(&w[0], buf.size(), &len, (unsigned char *)cstr.get_data(), strlen) != OK, String());
  1346. w[len] = 0;
  1347. String ret = String::utf8((char *)&w[0]);
  1348. return ret;
  1349. }
  1350. void Marshalls::_bind_methods() {
  1351. ClassDB::bind_method(D_METHOD("variant_to_base64", "variant", "full_objects"), &Marshalls::variant_to_base64, DEFVAL(false));
  1352. ClassDB::bind_method(D_METHOD("base64_to_variant", "base64_str", "allow_objects"), &Marshalls::base64_to_variant, DEFVAL(false));
  1353. ClassDB::bind_method(D_METHOD("raw_to_base64", "array"), &Marshalls::raw_to_base64);
  1354. ClassDB::bind_method(D_METHOD("base64_to_raw", "base64_str"), &Marshalls::base64_to_raw);
  1355. ClassDB::bind_method(D_METHOD("utf8_to_base64", "utf8_str"), &Marshalls::utf8_to_base64);
  1356. ClassDB::bind_method(D_METHOD("base64_to_utf8", "base64_str"), &Marshalls::base64_to_utf8);
  1357. }
  1358. ////// Semaphore //////
  1359. void Semaphore::wait() {
  1360. semaphore.wait();
  1361. }
  1362. Error Semaphore::try_wait() {
  1363. return semaphore.try_wait() ? OK : ERR_BUSY;
  1364. }
  1365. void Semaphore::post() {
  1366. semaphore.post();
  1367. }
  1368. void Semaphore::_bind_methods() {
  1369. ClassDB::bind_method(D_METHOD("wait"), &Semaphore::wait);
  1370. ClassDB::bind_method(D_METHOD("try_wait"), &Semaphore::try_wait);
  1371. ClassDB::bind_method(D_METHOD("post"), &Semaphore::post);
  1372. }
  1373. ////// Mutex //////
  1374. void Mutex::lock() {
  1375. mutex.lock();
  1376. }
  1377. Error Mutex::try_lock() {
  1378. return mutex.try_lock();
  1379. }
  1380. void Mutex::unlock() {
  1381. mutex.unlock();
  1382. }
  1383. void Mutex::_bind_methods() {
  1384. ClassDB::bind_method(D_METHOD("lock"), &Mutex::lock);
  1385. ClassDB::bind_method(D_METHOD("try_lock"), &Mutex::try_lock);
  1386. ClassDB::bind_method(D_METHOD("unlock"), &Mutex::unlock);
  1387. }
  1388. ////// Thread //////
  1389. void Thread::_start_func(void *ud) {
  1390. Ref<Thread> *tud = (Ref<Thread> *)ud;
  1391. Ref<Thread> t = *tud;
  1392. memdelete(tud);
  1393. Object *target_instance = t->target_callable.get_object();
  1394. if (!target_instance) {
  1395. t->running.clear();
  1396. 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()));
  1397. }
  1398. String func_name = t->target_callable.is_custom() ? t->target_callable.get_custom()->get_as_text() : String(t->target_callable.get_method());
  1399. ::Thread::set_name(func_name);
  1400. Callable::CallError ce;
  1401. t->target_callable.callp(nullptr, 0, t->ret, ce);
  1402. if (ce.error != Callable::CallError::CALL_OK) {
  1403. t->running.clear();
  1404. ERR_FAIL_MSG("Could not call function '" + func_name + "' to start thread " + t->get_id() + ": " + Variant::get_callable_error_text(t->target_callable, nullptr, 0, ce) + ".");
  1405. }
  1406. t->running.clear();
  1407. }
  1408. Error Thread::start(const Callable &p_callable, Priority p_priority) {
  1409. ERR_FAIL_COND_V_MSG(is_started(), ERR_ALREADY_IN_USE, "Thread already started.");
  1410. ERR_FAIL_COND_V(!p_callable.is_valid(), ERR_INVALID_PARAMETER);
  1411. ERR_FAIL_INDEX_V(p_priority, PRIORITY_MAX, ERR_INVALID_PARAMETER);
  1412. ret = Variant();
  1413. target_callable = p_callable;
  1414. running.set();
  1415. Ref<Thread> *ud = memnew(Ref<Thread>(this));
  1416. ::Thread::Settings s;
  1417. s.priority = (::Thread::Priority)p_priority;
  1418. thread.start(_start_func, ud, s);
  1419. return OK;
  1420. }
  1421. String Thread::get_id() const {
  1422. return itos(thread.get_id());
  1423. }
  1424. bool Thread::is_started() const {
  1425. return thread.is_started();
  1426. }
  1427. bool Thread::is_alive() const {
  1428. return running.is_set();
  1429. }
  1430. Variant Thread::wait_to_finish() {
  1431. ERR_FAIL_COND_V_MSG(!is_started(), Variant(), "Thread must have been started to wait for its completion.");
  1432. thread.wait_to_finish();
  1433. Variant r = ret;
  1434. target_callable = Callable();
  1435. return r;
  1436. }
  1437. void Thread::_bind_methods() {
  1438. ClassDB::bind_method(D_METHOD("start", "callable", "priority"), &Thread::start, DEFVAL(PRIORITY_NORMAL));
  1439. ClassDB::bind_method(D_METHOD("get_id"), &Thread::get_id);
  1440. ClassDB::bind_method(D_METHOD("is_started"), &Thread::is_started);
  1441. ClassDB::bind_method(D_METHOD("is_alive"), &Thread::is_alive);
  1442. ClassDB::bind_method(D_METHOD("wait_to_finish"), &Thread::wait_to_finish);
  1443. BIND_ENUM_CONSTANT(PRIORITY_LOW);
  1444. BIND_ENUM_CONSTANT(PRIORITY_NORMAL);
  1445. BIND_ENUM_CONSTANT(PRIORITY_HIGH);
  1446. }
  1447. namespace special {
  1448. ////// ClassDB //////
  1449. PackedStringArray ClassDB::get_class_list() const {
  1450. List<StringName> classes;
  1451. ::ClassDB::get_class_list(&classes);
  1452. PackedStringArray ret;
  1453. ret.resize(classes.size());
  1454. int idx = 0;
  1455. for (const StringName &E : classes) {
  1456. ret.set(idx++, E);
  1457. }
  1458. return ret;
  1459. }
  1460. PackedStringArray ClassDB::get_inheriters_from_class(const StringName &p_class) const {
  1461. List<StringName> classes;
  1462. ::ClassDB::get_inheriters_from_class(p_class, &classes);
  1463. PackedStringArray ret;
  1464. ret.resize(classes.size());
  1465. int idx = 0;
  1466. for (const StringName &E : classes) {
  1467. ret.set(idx++, E);
  1468. }
  1469. return ret;
  1470. }
  1471. StringName ClassDB::get_parent_class(const StringName &p_class) const {
  1472. return ::ClassDB::get_parent_class(p_class);
  1473. }
  1474. bool ClassDB::class_exists(const StringName &p_class) const {
  1475. return ::ClassDB::class_exists(p_class);
  1476. }
  1477. bool ClassDB::is_parent_class(const StringName &p_class, const StringName &p_inherits) const {
  1478. return ::ClassDB::is_parent_class(p_class, p_inherits);
  1479. }
  1480. bool ClassDB::can_instantiate(const StringName &p_class) const {
  1481. return ::ClassDB::can_instantiate(p_class);
  1482. }
  1483. Variant ClassDB::instantiate(const StringName &p_class) const {
  1484. Object *obj = ::ClassDB::instantiate(p_class);
  1485. if (!obj) {
  1486. return Variant();
  1487. }
  1488. RefCounted *r = Object::cast_to<RefCounted>(obj);
  1489. if (r) {
  1490. return Ref<RefCounted>(r);
  1491. } else {
  1492. return obj;
  1493. }
  1494. }
  1495. bool ClassDB::has_signal(StringName p_class, StringName p_signal) const {
  1496. return ::ClassDB::has_signal(p_class, p_signal);
  1497. }
  1498. Dictionary ClassDB::get_signal(StringName p_class, StringName p_signal) const {
  1499. MethodInfo signal;
  1500. if (::ClassDB::get_signal(p_class, p_signal, &signal)) {
  1501. return signal.operator Dictionary();
  1502. } else {
  1503. return Dictionary();
  1504. }
  1505. }
  1506. TypedArray<Dictionary> ClassDB::get_signal_list(StringName p_class, bool p_no_inheritance) const {
  1507. List<MethodInfo> signals;
  1508. ::ClassDB::get_signal_list(p_class, &signals, p_no_inheritance);
  1509. TypedArray<Dictionary> ret;
  1510. for (const MethodInfo &E : signals) {
  1511. ret.push_back(E.operator Dictionary());
  1512. }
  1513. return ret;
  1514. }
  1515. TypedArray<Dictionary> ClassDB::get_property_list(StringName p_class, bool p_no_inheritance) const {
  1516. List<PropertyInfo> plist;
  1517. ::ClassDB::get_property_list(p_class, &plist, p_no_inheritance);
  1518. TypedArray<Dictionary> ret;
  1519. for (const PropertyInfo &E : plist) {
  1520. ret.push_back(E.operator Dictionary());
  1521. }
  1522. return ret;
  1523. }
  1524. Variant ClassDB::get_property(Object *p_object, const StringName &p_property) const {
  1525. Variant ret;
  1526. ::ClassDB::get_property(p_object, p_property, ret);
  1527. return ret;
  1528. }
  1529. Error ClassDB::set_property(Object *p_object, const StringName &p_property, const Variant &p_value) const {
  1530. Variant ret;
  1531. bool valid;
  1532. if (!::ClassDB::set_property(p_object, p_property, p_value, &valid)) {
  1533. return ERR_UNAVAILABLE;
  1534. } else if (!valid) {
  1535. return ERR_INVALID_DATA;
  1536. }
  1537. return OK;
  1538. }
  1539. bool ClassDB::has_method(StringName p_class, StringName p_method, bool p_no_inheritance) const {
  1540. return ::ClassDB::has_method(p_class, p_method, p_no_inheritance);
  1541. }
  1542. TypedArray<Dictionary> ClassDB::get_method_list(StringName p_class, bool p_no_inheritance) const {
  1543. List<MethodInfo> methods;
  1544. ::ClassDB::get_method_list(p_class, &methods, p_no_inheritance);
  1545. TypedArray<Dictionary> ret;
  1546. for (const MethodInfo &E : methods) {
  1547. #ifdef DEBUG_METHODS_ENABLED
  1548. ret.push_back(E.operator Dictionary());
  1549. #else
  1550. Dictionary dict;
  1551. dict["name"] = E.name;
  1552. ret.push_back(dict);
  1553. #endif
  1554. }
  1555. return ret;
  1556. }
  1557. PackedStringArray ClassDB::get_integer_constant_list(const StringName &p_class, bool p_no_inheritance) const {
  1558. List<String> constants;
  1559. ::ClassDB::get_integer_constant_list(p_class, &constants, p_no_inheritance);
  1560. PackedStringArray ret;
  1561. ret.resize(constants.size());
  1562. int idx = 0;
  1563. for (const String &E : constants) {
  1564. ret.set(idx++, E);
  1565. }
  1566. return ret;
  1567. }
  1568. bool ClassDB::has_integer_constant(const StringName &p_class, const StringName &p_name) const {
  1569. bool success;
  1570. ::ClassDB::get_integer_constant(p_class, p_name, &success);
  1571. return success;
  1572. }
  1573. int64_t ClassDB::get_integer_constant(const StringName &p_class, const StringName &p_name) const {
  1574. bool found;
  1575. int64_t c = ::ClassDB::get_integer_constant(p_class, p_name, &found);
  1576. ERR_FAIL_COND_V(!found, 0);
  1577. return c;
  1578. }
  1579. bool ClassDB::has_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance) const {
  1580. return ::ClassDB::has_enum(p_class, p_name, p_no_inheritance);
  1581. }
  1582. PackedStringArray ClassDB::get_enum_list(const StringName &p_class, bool p_no_inheritance) const {
  1583. List<StringName> enums;
  1584. ::ClassDB::get_enum_list(p_class, &enums, p_no_inheritance);
  1585. PackedStringArray ret;
  1586. ret.resize(enums.size());
  1587. int idx = 0;
  1588. for (const StringName &E : enums) {
  1589. ret.set(idx++, E);
  1590. }
  1591. return ret;
  1592. }
  1593. PackedStringArray ClassDB::get_enum_constants(const StringName &p_class, const StringName &p_enum, bool p_no_inheritance) const {
  1594. List<StringName> constants;
  1595. ::ClassDB::get_enum_constants(p_class, p_enum, &constants, p_no_inheritance);
  1596. PackedStringArray ret;
  1597. ret.resize(constants.size());
  1598. int idx = 0;
  1599. for (const StringName &E : constants) {
  1600. ret.set(idx++, E);
  1601. }
  1602. return ret;
  1603. }
  1604. StringName ClassDB::get_integer_constant_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance) const {
  1605. return ::ClassDB::get_integer_constant_enum(p_class, p_name, p_no_inheritance);
  1606. }
  1607. bool ClassDB::is_class_enabled(StringName p_class) const {
  1608. return ::ClassDB::is_class_enabled(p_class);
  1609. }
  1610. void ClassDB::_bind_methods() {
  1611. ::ClassDB::bind_method(D_METHOD("get_class_list"), &ClassDB::get_class_list);
  1612. ::ClassDB::bind_method(D_METHOD("get_inheriters_from_class", "class"), &ClassDB::get_inheriters_from_class);
  1613. ::ClassDB::bind_method(D_METHOD("get_parent_class", "class"), &ClassDB::get_parent_class);
  1614. ::ClassDB::bind_method(D_METHOD("class_exists", "class"), &ClassDB::class_exists);
  1615. ::ClassDB::bind_method(D_METHOD("is_parent_class", "class", "inherits"), &ClassDB::is_parent_class);
  1616. ::ClassDB::bind_method(D_METHOD("can_instantiate", "class"), &ClassDB::can_instantiate);
  1617. ::ClassDB::bind_method(D_METHOD("instantiate", "class"), &ClassDB::instantiate);
  1618. ::ClassDB::bind_method(D_METHOD("class_has_signal", "class", "signal"), &ClassDB::has_signal);
  1619. ::ClassDB::bind_method(D_METHOD("class_get_signal", "class", "signal"), &ClassDB::get_signal);
  1620. ::ClassDB::bind_method(D_METHOD("class_get_signal_list", "class", "no_inheritance"), &ClassDB::get_signal_list, DEFVAL(false));
  1621. ::ClassDB::bind_method(D_METHOD("class_get_property_list", "class", "no_inheritance"), &ClassDB::get_property_list, DEFVAL(false));
  1622. ::ClassDB::bind_method(D_METHOD("class_get_property", "object", "property"), &ClassDB::get_property);
  1623. ::ClassDB::bind_method(D_METHOD("class_set_property", "object", "property", "value"), &ClassDB::set_property);
  1624. ::ClassDB::bind_method(D_METHOD("class_has_method", "class", "method", "no_inheritance"), &ClassDB::has_method, DEFVAL(false));
  1625. ::ClassDB::bind_method(D_METHOD("class_get_method_list", "class", "no_inheritance"), &ClassDB::get_method_list, DEFVAL(false));
  1626. ::ClassDB::bind_method(D_METHOD("class_get_integer_constant_list", "class", "no_inheritance"), &ClassDB::get_integer_constant_list, DEFVAL(false));
  1627. ::ClassDB::bind_method(D_METHOD("class_has_integer_constant", "class", "name"), &ClassDB::has_integer_constant);
  1628. ::ClassDB::bind_method(D_METHOD("class_get_integer_constant", "class", "name"), &ClassDB::get_integer_constant);
  1629. ::ClassDB::bind_method(D_METHOD("class_has_enum", "class", "name", "no_inheritance"), &ClassDB::has_enum, DEFVAL(false));
  1630. ::ClassDB::bind_method(D_METHOD("class_get_enum_list", "class", "no_inheritance"), &ClassDB::get_enum_list, DEFVAL(false));
  1631. ::ClassDB::bind_method(D_METHOD("class_get_enum_constants", "class", "enum", "no_inheritance"), &ClassDB::get_enum_constants, DEFVAL(false));
  1632. ::ClassDB::bind_method(D_METHOD("class_get_integer_constant_enum", "class", "name", "no_inheritance"), &ClassDB::get_integer_constant_enum, DEFVAL(false));
  1633. ::ClassDB::bind_method(D_METHOD("is_class_enabled", "class"), &ClassDB::is_class_enabled);
  1634. }
  1635. } // namespace special
  1636. ////// Engine //////
  1637. void Engine::set_physics_ticks_per_second(int p_ips) {
  1638. ::Engine::get_singleton()->set_physics_ticks_per_second(p_ips);
  1639. }
  1640. int Engine::get_physics_ticks_per_second() const {
  1641. return ::Engine::get_singleton()->get_physics_ticks_per_second();
  1642. }
  1643. void Engine::set_physics_jitter_fix(double p_threshold) {
  1644. ::Engine::get_singleton()->set_physics_jitter_fix(p_threshold);
  1645. }
  1646. double Engine::get_physics_jitter_fix() const {
  1647. return ::Engine::get_singleton()->get_physics_jitter_fix();
  1648. }
  1649. double Engine::get_physics_interpolation_fraction() const {
  1650. return ::Engine::get_singleton()->get_physics_interpolation_fraction();
  1651. }
  1652. void Engine::set_target_fps(int p_fps) {
  1653. ::Engine::get_singleton()->set_target_fps(p_fps);
  1654. }
  1655. int Engine::get_target_fps() const {
  1656. return ::Engine::get_singleton()->get_target_fps();
  1657. }
  1658. double Engine::get_frames_per_second() const {
  1659. return ::Engine::get_singleton()->get_frames_per_second();
  1660. }
  1661. uint64_t Engine::get_physics_frames() const {
  1662. return ::Engine::get_singleton()->get_physics_frames();
  1663. }
  1664. uint64_t Engine::get_process_frames() const {
  1665. return ::Engine::get_singleton()->get_process_frames();
  1666. }
  1667. void Engine::set_time_scale(double p_scale) {
  1668. ::Engine::get_singleton()->set_time_scale(p_scale);
  1669. }
  1670. double Engine::get_time_scale() {
  1671. return ::Engine::get_singleton()->get_time_scale();
  1672. }
  1673. int Engine::get_frames_drawn() {
  1674. return ::Engine::get_singleton()->get_frames_drawn();
  1675. }
  1676. MainLoop *Engine::get_main_loop() const {
  1677. // Needs to remain in OS, since it's actually OS that interacts with it, but it's better exposed here
  1678. return ::OS::get_singleton()->get_main_loop();
  1679. }
  1680. Dictionary Engine::get_version_info() const {
  1681. return ::Engine::get_singleton()->get_version_info();
  1682. }
  1683. Dictionary Engine::get_author_info() const {
  1684. return ::Engine::get_singleton()->get_author_info();
  1685. }
  1686. TypedArray<Dictionary> Engine::get_copyright_info() const {
  1687. return ::Engine::get_singleton()->get_copyright_info();
  1688. }
  1689. Dictionary Engine::get_donor_info() const {
  1690. return ::Engine::get_singleton()->get_donor_info();
  1691. }
  1692. Dictionary Engine::get_license_info() const {
  1693. return ::Engine::get_singleton()->get_license_info();
  1694. }
  1695. String Engine::get_license_text() const {
  1696. return ::Engine::get_singleton()->get_license_text();
  1697. }
  1698. String Engine::get_architecture_name() const {
  1699. return ::Engine::get_singleton()->get_architecture_name();
  1700. }
  1701. bool Engine::is_in_physics_frame() const {
  1702. return ::Engine::get_singleton()->is_in_physics_frame();
  1703. }
  1704. bool Engine::has_singleton(const StringName &p_name) const {
  1705. return ::Engine::get_singleton()->has_singleton(p_name);
  1706. }
  1707. Object *Engine::get_singleton_object(const StringName &p_name) const {
  1708. return ::Engine::get_singleton()->get_singleton_object(p_name);
  1709. }
  1710. void Engine::register_singleton(const StringName &p_name, Object *p_object) {
  1711. ERR_FAIL_COND_MSG(has_singleton(p_name), "Singleton already registered: " + String(p_name));
  1712. ERR_FAIL_COND_MSG(!String(p_name).is_valid_identifier(), "Singleton name is not a valid identifier: " + p_name);
  1713. ::Engine::Singleton s;
  1714. s.class_name = p_name;
  1715. s.name = p_name;
  1716. s.ptr = p_object;
  1717. s.user_created = true;
  1718. ::Engine::get_singleton()->add_singleton(s);
  1719. }
  1720. void Engine::unregister_singleton(const StringName &p_name) {
  1721. ERR_FAIL_COND_MSG(!has_singleton(p_name), "Attempt to remove unregistered singleton: " + String(p_name));
  1722. ERR_FAIL_COND_MSG(!::Engine::get_singleton()->is_singleton_user_created(p_name), "Attempt to remove non-user created singleton: " + String(p_name));
  1723. ::Engine::get_singleton()->remove_singleton(p_name);
  1724. }
  1725. Vector<String> Engine::get_singleton_list() const {
  1726. List<::Engine::Singleton> singletons;
  1727. ::Engine::get_singleton()->get_singletons(&singletons);
  1728. Vector<String> ret;
  1729. for (List<::Engine::Singleton>::Element *E = singletons.front(); E; E = E->next()) {
  1730. ret.push_back(E->get().name);
  1731. }
  1732. return ret;
  1733. }
  1734. void Engine::register_script_language(ScriptLanguage *p_language) {
  1735. ScriptServer::register_language(p_language);
  1736. }
  1737. int Engine::get_script_language_count() {
  1738. return ScriptServer::get_language_count();
  1739. }
  1740. ScriptLanguage *Engine::get_script_language(int p_index) const {
  1741. return ScriptServer::get_language(p_index);
  1742. }
  1743. void Engine::set_editor_hint(bool p_enabled) {
  1744. ::Engine::get_singleton()->set_editor_hint(p_enabled);
  1745. }
  1746. bool Engine::is_editor_hint() const {
  1747. return ::Engine::get_singleton()->is_editor_hint();
  1748. }
  1749. String Engine::get_write_movie_path() const {
  1750. return ::Engine::get_singleton()->get_write_movie_path();
  1751. }
  1752. void Engine::set_print_error_messages(bool p_enabled) {
  1753. ::Engine::get_singleton()->set_print_error_messages(p_enabled);
  1754. }
  1755. bool Engine::is_printing_error_messages() const {
  1756. return ::Engine::get_singleton()->is_printing_error_messages();
  1757. }
  1758. void Engine::_bind_methods() {
  1759. ClassDB::bind_method(D_METHOD("set_physics_ticks_per_second", "physics_ticks_per_second"), &Engine::set_physics_ticks_per_second);
  1760. ClassDB::bind_method(D_METHOD("get_physics_ticks_per_second"), &Engine::get_physics_ticks_per_second);
  1761. ClassDB::bind_method(D_METHOD("set_physics_jitter_fix", "physics_jitter_fix"), &Engine::set_physics_jitter_fix);
  1762. ClassDB::bind_method(D_METHOD("get_physics_jitter_fix"), &Engine::get_physics_jitter_fix);
  1763. ClassDB::bind_method(D_METHOD("get_physics_interpolation_fraction"), &Engine::get_physics_interpolation_fraction);
  1764. ClassDB::bind_method(D_METHOD("set_target_fps", "target_fps"), &Engine::set_target_fps);
  1765. ClassDB::bind_method(D_METHOD("get_target_fps"), &Engine::get_target_fps);
  1766. ClassDB::bind_method(D_METHOD("set_time_scale", "time_scale"), &Engine::set_time_scale);
  1767. ClassDB::bind_method(D_METHOD("get_time_scale"), &Engine::get_time_scale);
  1768. ClassDB::bind_method(D_METHOD("get_frames_drawn"), &Engine::get_frames_drawn);
  1769. ClassDB::bind_method(D_METHOD("get_frames_per_second"), &Engine::get_frames_per_second);
  1770. ClassDB::bind_method(D_METHOD("get_physics_frames"), &Engine::get_physics_frames);
  1771. ClassDB::bind_method(D_METHOD("get_process_frames"), &Engine::get_process_frames);
  1772. ClassDB::bind_method(D_METHOD("get_main_loop"), &Engine::get_main_loop);
  1773. ClassDB::bind_method(D_METHOD("get_version_info"), &Engine::get_version_info);
  1774. ClassDB::bind_method(D_METHOD("get_author_info"), &Engine::get_author_info);
  1775. ClassDB::bind_method(D_METHOD("get_copyright_info"), &Engine::get_copyright_info);
  1776. ClassDB::bind_method(D_METHOD("get_donor_info"), &Engine::get_donor_info);
  1777. ClassDB::bind_method(D_METHOD("get_license_info"), &Engine::get_license_info);
  1778. ClassDB::bind_method(D_METHOD("get_license_text"), &Engine::get_license_text);
  1779. ClassDB::bind_method(D_METHOD("get_architecture_name"), &Engine::get_architecture_name);
  1780. ClassDB::bind_method(D_METHOD("is_in_physics_frame"), &Engine::is_in_physics_frame);
  1781. ClassDB::bind_method(D_METHOD("has_singleton", "name"), &Engine::has_singleton);
  1782. ClassDB::bind_method(D_METHOD("get_singleton", "name"), &Engine::get_singleton_object);
  1783. ClassDB::bind_method(D_METHOD("register_singleton", "name", "instance"), &Engine::register_singleton);
  1784. ClassDB::bind_method(D_METHOD("unregister_singleton", "name"), &Engine::unregister_singleton);
  1785. ClassDB::bind_method(D_METHOD("get_singleton_list"), &Engine::get_singleton_list);
  1786. ClassDB::bind_method(D_METHOD("register_script_language", "language"), &Engine::register_script_language);
  1787. ClassDB::bind_method(D_METHOD("get_script_language_count"), &Engine::get_script_language_count);
  1788. ClassDB::bind_method(D_METHOD("get_script_language", "index"), &Engine::get_script_language);
  1789. ClassDB::bind_method(D_METHOD("is_editor_hint"), &Engine::is_editor_hint);
  1790. ClassDB::bind_method(D_METHOD("get_write_movie_path"), &Engine::get_write_movie_path);
  1791. ClassDB::bind_method(D_METHOD("set_print_error_messages", "enabled"), &Engine::set_print_error_messages);
  1792. ClassDB::bind_method(D_METHOD("is_printing_error_messages"), &Engine::is_printing_error_messages);
  1793. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "print_error_messages"), "set_print_error_messages", "is_printing_error_messages");
  1794. ADD_PROPERTY(PropertyInfo(Variant::INT, "physics_ticks_per_second"), "set_physics_ticks_per_second", "get_physics_ticks_per_second");
  1795. ADD_PROPERTY(PropertyInfo(Variant::INT, "target_fps"), "set_target_fps", "get_target_fps");
  1796. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "time_scale"), "set_time_scale", "get_time_scale");
  1797. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "physics_jitter_fix"), "set_physics_jitter_fix", "get_physics_jitter_fix");
  1798. }
  1799. Engine *Engine::singleton = nullptr;
  1800. ////// EngineDebugger //////
  1801. bool EngineDebugger::is_active() {
  1802. return ::EngineDebugger::is_active();
  1803. }
  1804. void EngineDebugger::register_profiler(const StringName &p_name, Ref<EngineProfiler> p_profiler) {
  1805. ERR_FAIL_COND(p_profiler.is_null());
  1806. ERR_FAIL_COND_MSG(p_profiler->is_bound(), "Profiler already registered.");
  1807. ERR_FAIL_COND_MSG(profilers.has(p_name) || has_profiler(p_name), "Profiler name already in use: " + p_name);
  1808. Error err = p_profiler->bind(p_name);
  1809. ERR_FAIL_COND_MSG(err != OK, "Profiler failed to register with error: " + itos(err));
  1810. profilers.insert(p_name, p_profiler);
  1811. }
  1812. void EngineDebugger::unregister_profiler(const StringName &p_name) {
  1813. ERR_FAIL_COND_MSG(!profilers.has(p_name), "Profiler not registered: " + p_name);
  1814. profilers[p_name]->unbind();
  1815. profilers.erase(p_name);
  1816. }
  1817. bool EngineDebugger::is_profiling(const StringName &p_name) {
  1818. return ::EngineDebugger::is_profiling(p_name);
  1819. }
  1820. bool EngineDebugger::has_profiler(const StringName &p_name) {
  1821. return ::EngineDebugger::has_profiler(p_name);
  1822. }
  1823. void EngineDebugger::profiler_add_frame_data(const StringName &p_name, const Array &p_data) {
  1824. ::EngineDebugger::profiler_add_frame_data(p_name, p_data);
  1825. }
  1826. void EngineDebugger::profiler_enable(const StringName &p_name, bool p_enabled, const Array &p_opts) {
  1827. if (::EngineDebugger::get_singleton()) {
  1828. ::EngineDebugger::get_singleton()->profiler_enable(p_name, p_enabled, p_opts);
  1829. }
  1830. }
  1831. void EngineDebugger::register_message_capture(const StringName &p_name, const Callable &p_callable) {
  1832. ERR_FAIL_COND_MSG(captures.has(p_name) || has_capture(p_name), "Capture already registered: " + p_name);
  1833. captures.insert(p_name, p_callable);
  1834. Callable &c = captures[p_name];
  1835. ::EngineDebugger::Capture capture(&c, &EngineDebugger::call_capture);
  1836. ::EngineDebugger::register_message_capture(p_name, capture);
  1837. }
  1838. void EngineDebugger::unregister_message_capture(const StringName &p_name) {
  1839. ERR_FAIL_COND_MSG(!captures.has(p_name), "Capture not registered: " + p_name);
  1840. ::EngineDebugger::unregister_message_capture(p_name);
  1841. captures.erase(p_name);
  1842. }
  1843. bool EngineDebugger::has_capture(const StringName &p_name) {
  1844. return ::EngineDebugger::has_capture(p_name);
  1845. }
  1846. void EngineDebugger::send_message(const String &p_msg, const Array &p_data) {
  1847. ERR_FAIL_COND_MSG(!::EngineDebugger::is_active(), "Can't send message. No active debugger");
  1848. ::EngineDebugger::get_singleton()->send_message(p_msg, p_data);
  1849. }
  1850. Error EngineDebugger::call_capture(void *p_user, const String &p_cmd, const Array &p_data, bool &r_captured) {
  1851. Callable &capture = *(Callable *)p_user;
  1852. if (capture.is_null()) {
  1853. return FAILED;
  1854. }
  1855. Variant cmd = p_cmd, data = p_data;
  1856. const Variant *args[2] = { &cmd, &data };
  1857. Variant retval;
  1858. Callable::CallError err;
  1859. capture.callp(args, 2, retval, err);
  1860. ERR_FAIL_COND_V_MSG(err.error != Callable::CallError::CALL_OK, FAILED, "Error calling 'capture' to callable: " + Variant::get_callable_error_text(capture, args, 2, err));
  1861. ERR_FAIL_COND_V_MSG(retval.get_type() != Variant::BOOL, FAILED, "Error calling 'capture' to callable: " + String(capture) + ". Return type is not bool.");
  1862. r_captured = retval;
  1863. return OK;
  1864. }
  1865. EngineDebugger::~EngineDebugger() {
  1866. for (const KeyValue<StringName, Callable> &E : captures) {
  1867. ::EngineDebugger::unregister_message_capture(E.key);
  1868. }
  1869. captures.clear();
  1870. }
  1871. EngineDebugger *EngineDebugger::singleton = nullptr;
  1872. void EngineDebugger::_bind_methods() {
  1873. ClassDB::bind_method(D_METHOD("is_active"), &EngineDebugger::is_active);
  1874. ClassDB::bind_method(D_METHOD("register_profiler", "name", "profiler"), &EngineDebugger::register_profiler);
  1875. ClassDB::bind_method(D_METHOD("unregister_profiler", "name"), &EngineDebugger::unregister_profiler);
  1876. ClassDB::bind_method(D_METHOD("is_profiling", "name"), &EngineDebugger::is_profiling);
  1877. ClassDB::bind_method(D_METHOD("has_profiler", "name"), &EngineDebugger::has_profiler);
  1878. ClassDB::bind_method(D_METHOD("profiler_add_frame_data", "name", "data"), &EngineDebugger::profiler_add_frame_data);
  1879. ClassDB::bind_method(D_METHOD("profiler_enable", "name", "enable", "arguments"), &EngineDebugger::profiler_enable, DEFVAL(Array()));
  1880. ClassDB::bind_method(D_METHOD("register_message_capture", "name", "callable"), &EngineDebugger::register_message_capture);
  1881. ClassDB::bind_method(D_METHOD("unregister_message_capture", "name"), &EngineDebugger::unregister_message_capture);
  1882. ClassDB::bind_method(D_METHOD("has_capture", "name"), &EngineDebugger::has_capture);
  1883. ClassDB::bind_method(D_METHOD("send_message", "message", "data"), &EngineDebugger::send_message);
  1884. }
  1885. } // namespace core_bind