core_bind.cpp 86 KB

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