core_bind.cpp 86 KB

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