core_bind.cpp 71 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860
  1. /**************************************************************************/
  2. /* core_bind.cpp */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #include "core_bind.h"
  31. #include "core/config/project_settings.h"
  32. #include "core/crypto/crypto_core.h"
  33. #include "core/debugger/engine_debugger.h"
  34. #include "core/io/file_access_compressed.h"
  35. #include "core/io/file_access_encrypted.h"
  36. #include "core/io/marshalls.h"
  37. #include "core/math/geometry_2d.h"
  38. #include "core/math/geometry_3d.h"
  39. #include "core/os/keyboard.h"
  40. #include "core/os/thread_safe.h"
  41. #include "core/variant/typed_array.h"
  42. namespace core_bind {
  43. ////// ResourceLoader //////
  44. ResourceLoader *ResourceLoader::singleton = nullptr;
  45. Error ResourceLoader::load_threaded_request(const String &p_path, const String &p_type_hint, bool p_use_sub_threads, CacheMode p_cache_mode) {
  46. return ::ResourceLoader::load_threaded_request(p_path, p_type_hint, p_use_sub_threads, ResourceFormatLoader::CacheMode(p_cache_mode));
  47. }
  48. ResourceLoader::ThreadLoadStatus ResourceLoader::load_threaded_get_status(const String &p_path, Array r_progress) {
  49. float progress = 0;
  50. ::ResourceLoader::ThreadLoadStatus tls = ::ResourceLoader::load_threaded_get_status(p_path, &progress);
  51. r_progress.resize(1);
  52. r_progress[0] = progress;
  53. return (ThreadLoadStatus)tls;
  54. }
  55. Ref<Resource> ResourceLoader::load_threaded_get(const String &p_path) {
  56. Error error;
  57. Ref<Resource> res = ::ResourceLoader::load_threaded_get(p_path, &error);
  58. return res;
  59. }
  60. Ref<Resource> ResourceLoader::load(const String &p_path, const String &p_type_hint, CacheMode p_cache_mode) {
  61. Error err = OK;
  62. Ref<Resource> ret = ::ResourceLoader::load(p_path, p_type_hint, ResourceFormatLoader::CacheMode(p_cache_mode), &err);
  63. ERR_FAIL_COND_V_MSG(err != OK, ret, "Error loading resource: '" + p_path + "'.");
  64. return ret;
  65. }
  66. Vector<String> ResourceLoader::get_recognized_extensions_for_type(const String &p_type) {
  67. List<String> exts;
  68. ::ResourceLoader::get_recognized_extensions_for_type(p_type, &exts);
  69. Vector<String> ret;
  70. for (const String &E : exts) {
  71. ret.push_back(E);
  72. }
  73. return ret;
  74. }
  75. void ResourceLoader::add_resource_format_loader(Ref<ResourceFormatLoader> p_format_loader, bool p_at_front) {
  76. ::ResourceLoader::add_resource_format_loader(p_format_loader, p_at_front);
  77. }
  78. void ResourceLoader::remove_resource_format_loader(Ref<ResourceFormatLoader> p_format_loader) {
  79. ::ResourceLoader::remove_resource_format_loader(p_format_loader);
  80. }
  81. void ResourceLoader::set_abort_on_missing_resources(bool p_abort) {
  82. ::ResourceLoader::set_abort_on_missing_resources(p_abort);
  83. }
  84. PackedStringArray ResourceLoader::get_dependencies(const String &p_path) {
  85. List<String> deps;
  86. ::ResourceLoader::get_dependencies(p_path, &deps);
  87. PackedStringArray ret;
  88. for (const String &E : deps) {
  89. ret.push_back(E);
  90. }
  91. return ret;
  92. }
  93. bool ResourceLoader::has_cached(const String &p_path) {
  94. String local_path = ProjectSettings::get_singleton()->localize_path(p_path);
  95. return ResourceCache::has(local_path);
  96. }
  97. bool ResourceLoader::exists(const String &p_path, const String &p_type_hint) {
  98. return ::ResourceLoader::exists(p_path, p_type_hint);
  99. }
  100. ResourceUID::ID ResourceLoader::get_resource_uid(const String &p_path) {
  101. return ::ResourceLoader::get_resource_uid(p_path);
  102. }
  103. void ResourceLoader::_bind_methods() {
  104. ClassDB::bind_method(D_METHOD("load_threaded_request", "path", "type_hint", "use_sub_threads", "cache_mode"), &ResourceLoader::load_threaded_request, DEFVAL(""), DEFVAL(false), DEFVAL(CACHE_MODE_REUSE));
  105. ClassDB::bind_method(D_METHOD("load_threaded_get_status", "path", "progress"), &ResourceLoader::load_threaded_get_status, DEFVAL(Array()));
  106. ClassDB::bind_method(D_METHOD("load_threaded_get", "path"), &ResourceLoader::load_threaded_get);
  107. ClassDB::bind_method(D_METHOD("load", "path", "type_hint", "cache_mode"), &ResourceLoader::load, DEFVAL(""), DEFVAL(CACHE_MODE_REUSE));
  108. ClassDB::bind_method(D_METHOD("get_recognized_extensions_for_type", "type"), &ResourceLoader::get_recognized_extensions_for_type);
  109. ClassDB::bind_method(D_METHOD("add_resource_format_loader", "format_loader", "at_front"), &ResourceLoader::add_resource_format_loader, DEFVAL(false));
  110. ClassDB::bind_method(D_METHOD("remove_resource_format_loader", "format_loader"), &ResourceLoader::remove_resource_format_loader);
  111. ClassDB::bind_method(D_METHOD("set_abort_on_missing_resources", "abort"), &ResourceLoader::set_abort_on_missing_resources);
  112. ClassDB::bind_method(D_METHOD("get_dependencies", "path"), &ResourceLoader::get_dependencies);
  113. ClassDB::bind_method(D_METHOD("has_cached", "path"), &ResourceLoader::has_cached);
  114. ClassDB::bind_method(D_METHOD("exists", "path", "type_hint"), &ResourceLoader::exists, DEFVAL(""));
  115. ClassDB::bind_method(D_METHOD("get_resource_uid", "path"), &ResourceLoader::get_resource_uid);
  116. BIND_ENUM_CONSTANT(THREAD_LOAD_INVALID_RESOURCE);
  117. BIND_ENUM_CONSTANT(THREAD_LOAD_IN_PROGRESS);
  118. BIND_ENUM_CONSTANT(THREAD_LOAD_FAILED);
  119. BIND_ENUM_CONSTANT(THREAD_LOAD_LOADED);
  120. BIND_ENUM_CONSTANT(CACHE_MODE_IGNORE);
  121. BIND_ENUM_CONSTANT(CACHE_MODE_REUSE);
  122. BIND_ENUM_CONSTANT(CACHE_MODE_REPLACE);
  123. }
  124. ////// ResourceSaver //////
  125. Error ResourceSaver::save(const Ref<Resource> &p_resource, const String &p_path, BitField<SaverFlags> p_flags) {
  126. ERR_FAIL_COND_V_MSG(p_resource.is_null(), ERR_INVALID_PARAMETER, "Can't save empty resource to path '" + p_path + "'.");
  127. return ::ResourceSaver::save(p_resource, p_path, p_flags);
  128. }
  129. Vector<String> ResourceSaver::get_recognized_extensions(const Ref<Resource> &p_resource) {
  130. ERR_FAIL_COND_V_MSG(p_resource.is_null(), Vector<String>(), "It's not a reference to a valid Resource object.");
  131. List<String> exts;
  132. ::ResourceSaver::get_recognized_extensions(p_resource, &exts);
  133. Vector<String> ret;
  134. for (const String &E : exts) {
  135. ret.push_back(E);
  136. }
  137. return ret;
  138. }
  139. void ResourceSaver::add_resource_format_saver(Ref<ResourceFormatSaver> p_format_saver, bool p_at_front) {
  140. ::ResourceSaver::add_resource_format_saver(p_format_saver, p_at_front);
  141. }
  142. void ResourceSaver::remove_resource_format_saver(Ref<ResourceFormatSaver> p_format_saver) {
  143. ::ResourceSaver::remove_resource_format_saver(p_format_saver);
  144. }
  145. ResourceSaver *ResourceSaver::singleton = nullptr;
  146. void ResourceSaver::_bind_methods() {
  147. ClassDB::bind_method(D_METHOD("save", "resource", "path", "flags"), &ResourceSaver::save, DEFVAL(""), DEFVAL((uint32_t)FLAG_NONE));
  148. ClassDB::bind_method(D_METHOD("get_recognized_extensions", "type"), &ResourceSaver::get_recognized_extensions);
  149. ClassDB::bind_method(D_METHOD("add_resource_format_saver", "format_saver", "at_front"), &ResourceSaver::add_resource_format_saver, DEFVAL(false));
  150. ClassDB::bind_method(D_METHOD("remove_resource_format_saver", "format_saver"), &ResourceSaver::remove_resource_format_saver);
  151. BIND_BITFIELD_FLAG(FLAG_NONE);
  152. BIND_BITFIELD_FLAG(FLAG_RELATIVE_PATHS);
  153. BIND_BITFIELD_FLAG(FLAG_BUNDLE_RESOURCES);
  154. BIND_BITFIELD_FLAG(FLAG_CHANGE_PATH);
  155. BIND_BITFIELD_FLAG(FLAG_OMIT_EDITOR_PROPERTIES);
  156. BIND_BITFIELD_FLAG(FLAG_SAVE_BIG_ENDIAN);
  157. BIND_BITFIELD_FLAG(FLAG_COMPRESS);
  158. BIND_BITFIELD_FLAG(FLAG_REPLACE_SUBRESOURCE_PATHS);
  159. }
  160. ////// OS //////
  161. PackedStringArray OS::get_connected_midi_inputs() {
  162. return ::OS::get_singleton()->get_connected_midi_inputs();
  163. }
  164. void OS::open_midi_inputs() {
  165. ::OS::get_singleton()->open_midi_inputs();
  166. }
  167. void OS::close_midi_inputs() {
  168. ::OS::get_singleton()->close_midi_inputs();
  169. }
  170. void OS::set_use_file_access_save_and_swap(bool p_enable) {
  171. FileAccess::set_backup_save(p_enable);
  172. }
  173. void OS::set_low_processor_usage_mode(bool p_enabled) {
  174. ::OS::get_singleton()->set_low_processor_usage_mode(p_enabled);
  175. }
  176. bool OS::is_in_low_processor_usage_mode() const {
  177. return ::OS::get_singleton()->is_in_low_processor_usage_mode();
  178. }
  179. void OS::set_low_processor_usage_mode_sleep_usec(int p_usec) {
  180. ::OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(p_usec);
  181. }
  182. int OS::get_low_processor_usage_mode_sleep_usec() const {
  183. return ::OS::get_singleton()->get_low_processor_usage_mode_sleep_usec();
  184. }
  185. void OS::set_delta_smoothing(bool p_enabled) {
  186. ::OS::get_singleton()->set_delta_smoothing(p_enabled);
  187. }
  188. bool OS::is_delta_smoothing_enabled() const {
  189. return ::OS::get_singleton()->is_delta_smoothing_enabled();
  190. }
  191. void OS::alert(const String &p_alert, const String &p_title) {
  192. ::OS::get_singleton()->alert(p_alert, p_title);
  193. }
  194. void OS::crash(const String &p_message) {
  195. CRASH_NOW_MSG(p_message);
  196. }
  197. Vector<String> OS::get_system_fonts() const {
  198. return ::OS::get_singleton()->get_system_fonts();
  199. }
  200. String OS::get_system_font_path(const String &p_font_name, int p_weight, int p_stretch, bool p_italic) const {
  201. return ::OS::get_singleton()->get_system_font_path(p_font_name, p_weight, p_stretch, p_italic);
  202. }
  203. Vector<String> OS::get_system_font_path_for_text(const String &p_font_name, const String &p_text, const String &p_locale, const String &p_script, int p_weight, int p_stretch, bool p_italic) const {
  204. return ::OS::get_singleton()->get_system_font_path_for_text(p_font_name, p_text, p_locale, p_script, p_weight, p_stretch, p_italic);
  205. }
  206. String OS::get_executable_path() const {
  207. return ::OS::get_singleton()->get_executable_path();
  208. }
  209. Error OS::shell_open(String p_uri) {
  210. if (p_uri.begins_with("res://")) {
  211. 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()`.");
  212. } else if (p_uri.begins_with("user://")) {
  213. 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()`.");
  214. }
  215. return ::OS::get_singleton()->shell_open(p_uri);
  216. }
  217. Error OS::shell_show_in_file_manager(String p_path, bool p_open_folder) {
  218. if (p_path.begins_with("res://")) {
  219. WARN_PRINT("Attempting to explore file path with the \"res://\" protocol. Use `ProjectSettings.globalize_path()` to convert a Godot-specific path to a system path before opening it with `OS.shell_show_in_file_manager()`.");
  220. } else if (p_path.begins_with("user://")) {
  221. WARN_PRINT("Attempting to explore file path with the \"user://\" protocol. Use `ProjectSettings.globalize_path()` to convert a Godot-specific path to a system path before opening it with `OS.shell_show_in_file_manager()`.");
  222. }
  223. return ::OS::get_singleton()->shell_show_in_file_manager(p_path, p_open_folder);
  224. }
  225. String OS::read_string_from_stdin() {
  226. return ::OS::get_singleton()->get_stdin_string();
  227. }
  228. int OS::execute(const String &p_path, const Vector<String> &p_arguments, Array r_output, bool p_read_stderr, bool p_open_console) {
  229. List<String> args;
  230. for (int i = 0; i < p_arguments.size(); i++) {
  231. args.push_back(p_arguments[i]);
  232. }
  233. String pipe;
  234. int exitcode = 0;
  235. Error err = ::OS::get_singleton()->execute(p_path, args, &pipe, &exitcode, p_read_stderr, nullptr, p_open_console);
  236. r_output.push_back(pipe);
  237. if (err != OK) {
  238. return -1;
  239. }
  240. return exitcode;
  241. }
  242. int OS::create_instance(const Vector<String> &p_arguments) {
  243. List<String> args;
  244. for (int i = 0; i < p_arguments.size(); i++) {
  245. args.push_back(p_arguments[i]);
  246. }
  247. ::OS::ProcessID pid = 0;
  248. Error err = ::OS::get_singleton()->create_instance(args, &pid);
  249. if (err != OK) {
  250. return -1;
  251. }
  252. return pid;
  253. }
  254. int OS::create_process(const String &p_path, const Vector<String> &p_arguments, bool p_open_console) {
  255. List<String> args;
  256. for (int i = 0; i < p_arguments.size(); i++) {
  257. args.push_back(p_arguments[i]);
  258. }
  259. ::OS::ProcessID pid = 0;
  260. Error err = ::OS::get_singleton()->create_process(p_path, args, &pid, p_open_console);
  261. if (err != OK) {
  262. return -1;
  263. }
  264. return pid;
  265. }
  266. Error OS::kill(int p_pid) {
  267. return ::OS::get_singleton()->kill(p_pid);
  268. }
  269. bool OS::is_process_running(int p_pid) const {
  270. return ::OS::get_singleton()->is_process_running(p_pid);
  271. }
  272. int OS::get_process_id() const {
  273. return ::OS::get_singleton()->get_process_id();
  274. }
  275. bool OS::has_environment(const String &p_var) const {
  276. return ::OS::get_singleton()->has_environment(p_var);
  277. }
  278. String OS::get_environment(const String &p_var) const {
  279. return ::OS::get_singleton()->get_environment(p_var);
  280. }
  281. void OS::set_environment(const String &p_var, const String &p_value) const {
  282. ::OS::get_singleton()->set_environment(p_var, p_value);
  283. }
  284. void OS::unset_environment(const String &p_var) const {
  285. ::OS::get_singleton()->unset_environment(p_var);
  286. }
  287. String OS::get_name() const {
  288. return ::OS::get_singleton()->get_name();
  289. }
  290. String OS::get_distribution_name() const {
  291. return ::OS::get_singleton()->get_distribution_name();
  292. }
  293. String OS::get_version() const {
  294. return ::OS::get_singleton()->get_version();
  295. }
  296. Vector<String> OS::get_video_adapter_driver_info() const {
  297. return ::OS::get_singleton()->get_video_adapter_driver_info();
  298. }
  299. Vector<String> OS::get_cmdline_args() {
  300. List<String> cmdline = ::OS::get_singleton()->get_cmdline_args();
  301. Vector<String> cmdlinev;
  302. for (const String &E : cmdline) {
  303. cmdlinev.push_back(E);
  304. }
  305. return cmdlinev;
  306. }
  307. Vector<String> OS::get_cmdline_user_args() {
  308. List<String> cmdline = ::OS::get_singleton()->get_cmdline_user_args();
  309. Vector<String> cmdlinev;
  310. for (const String &E : cmdline) {
  311. cmdlinev.push_back(E);
  312. }
  313. return cmdlinev;
  314. }
  315. void OS::set_restart_on_exit(bool p_restart, const Vector<String> &p_restart_arguments) {
  316. List<String> args_list;
  317. for (const String &restart_argument : p_restart_arguments) {
  318. args_list.push_back(restart_argument);
  319. }
  320. ::OS::get_singleton()->set_restart_on_exit(p_restart, args_list);
  321. }
  322. bool OS::is_restart_on_exit_set() const {
  323. return ::OS::get_singleton()->is_restart_on_exit_set();
  324. }
  325. Vector<String> OS::get_restart_on_exit_arguments() const {
  326. List<String> args = ::OS::get_singleton()->get_restart_on_exit_arguments();
  327. Vector<String> args_vector;
  328. for (List<String>::Element *E = args.front(); E; E = E->next()) {
  329. args_vector.push_back(E->get());
  330. }
  331. return args_vector;
  332. }
  333. String OS::get_locale() const {
  334. return ::OS::get_singleton()->get_locale();
  335. }
  336. String OS::get_locale_language() const {
  337. return ::OS::get_singleton()->get_locale_language();
  338. }
  339. String OS::get_model_name() const {
  340. return ::OS::get_singleton()->get_model_name();
  341. }
  342. Error OS::set_thread_name(const String &p_name) {
  343. return ::Thread::set_name(p_name);
  344. }
  345. ::Thread::ID OS::get_thread_caller_id() const {
  346. return ::Thread::get_caller_id();
  347. };
  348. ::Thread::ID OS::get_main_thread_id() const {
  349. return ::Thread::get_main_id();
  350. };
  351. bool OS::has_feature(const String &p_feature) const {
  352. const bool *value_ptr = feature_cache.getptr(p_feature);
  353. if (value_ptr) {
  354. return *value_ptr;
  355. } else {
  356. const bool has = ::OS::get_singleton()->has_feature(p_feature);
  357. feature_cache[p_feature] = has;
  358. return has;
  359. }
  360. }
  361. uint64_t OS::get_static_memory_usage() const {
  362. return ::OS::get_singleton()->get_static_memory_usage();
  363. }
  364. uint64_t OS::get_static_memory_peak_usage() const {
  365. return ::OS::get_singleton()->get_static_memory_peak_usage();
  366. }
  367. Dictionary OS::get_memory_info() const {
  368. return ::OS::get_singleton()->get_memory_info();
  369. }
  370. /** This method uses a signed argument for better error reporting as it's used from the scripting API. */
  371. void OS::delay_usec(int p_usec) const {
  372. ERR_FAIL_COND_MSG(
  373. p_usec < 0,
  374. vformat("Can't sleep for %d microseconds. The delay provided must be greater than or equal to 0 microseconds.", p_usec));
  375. ::OS::get_singleton()->delay_usec(p_usec);
  376. }
  377. /** This method uses a signed argument for better error reporting as it's used from the scripting API. */
  378. void OS::delay_msec(int p_msec) const {
  379. ERR_FAIL_COND_MSG(
  380. p_msec < 0,
  381. vformat("Can't sleep for %d milliseconds. The delay provided must be greater than or equal to 0 milliseconds.", p_msec));
  382. ::OS::get_singleton()->delay_usec(int64_t(p_msec) * 1000);
  383. }
  384. bool OS::is_userfs_persistent() const {
  385. return ::OS::get_singleton()->is_userfs_persistent();
  386. }
  387. int OS::get_processor_count() const {
  388. return ::OS::get_singleton()->get_processor_count();
  389. }
  390. String OS::get_processor_name() const {
  391. return ::OS::get_singleton()->get_processor_name();
  392. }
  393. bool OS::is_stdout_verbose() const {
  394. return ::OS::get_singleton()->is_stdout_verbose();
  395. }
  396. Error OS::move_to_trash(const String &p_path) const {
  397. return ::OS::get_singleton()->move_to_trash(p_path);
  398. }
  399. String OS::get_user_data_dir() const {
  400. return ::OS::get_singleton()->get_user_data_dir();
  401. }
  402. String OS::get_config_dir() const {
  403. // Exposed as `get_config_dir()` instead of `get_config_path()` for consistency with other exposed OS methods.
  404. return ::OS::get_singleton()->get_config_path();
  405. }
  406. String OS::get_data_dir() const {
  407. // Exposed as `get_data_dir()` instead of `get_data_path()` for consistency with other exposed OS methods.
  408. return ::OS::get_singleton()->get_data_path();
  409. }
  410. String OS::get_cache_dir() const {
  411. // Exposed as `get_cache_dir()` instead of `get_cache_path()` for consistency with other exposed OS methods.
  412. return ::OS::get_singleton()->get_cache_path();
  413. }
  414. bool OS::is_debug_build() const {
  415. #ifdef DEBUG_ENABLED
  416. return true;
  417. #else
  418. return false;
  419. #endif
  420. }
  421. String OS::get_system_dir(SystemDir p_dir, bool p_shared_storage) const {
  422. return ::OS::get_singleton()->get_system_dir(::OS::SystemDir(p_dir), p_shared_storage);
  423. }
  424. String OS::get_keycode_string(Key p_code) const {
  425. return ::keycode_get_string(p_code);
  426. }
  427. bool OS::is_keycode_unicode(char32_t p_unicode) const {
  428. return ::keycode_has_unicode((Key)p_unicode);
  429. }
  430. Key OS::find_keycode_from_string(const String &p_code) const {
  431. return find_keycode(p_code);
  432. }
  433. bool OS::request_permission(const String &p_name) {
  434. return ::OS::get_singleton()->request_permission(p_name);
  435. }
  436. bool OS::request_permissions() {
  437. return ::OS::get_singleton()->request_permissions();
  438. }
  439. Vector<String> OS::get_granted_permissions() const {
  440. return ::OS::get_singleton()->get_granted_permissions();
  441. }
  442. String OS::get_unique_id() const {
  443. return ::OS::get_singleton()->get_unique_id();
  444. }
  445. OS *OS::singleton = nullptr;
  446. void OS::_bind_methods() {
  447. ClassDB::bind_method(D_METHOD("get_connected_midi_inputs"), &OS::get_connected_midi_inputs);
  448. ClassDB::bind_method(D_METHOD("open_midi_inputs"), &OS::open_midi_inputs);
  449. ClassDB::bind_method(D_METHOD("close_midi_inputs"), &OS::close_midi_inputs);
  450. ClassDB::bind_method(D_METHOD("alert", "text", "title"), &OS::alert, DEFVAL("Alert!"));
  451. ClassDB::bind_method(D_METHOD("crash", "message"), &OS::crash);
  452. ClassDB::bind_method(D_METHOD("set_low_processor_usage_mode", "enable"), &OS::set_low_processor_usage_mode);
  453. ClassDB::bind_method(D_METHOD("is_in_low_processor_usage_mode"), &OS::is_in_low_processor_usage_mode);
  454. ClassDB::bind_method(D_METHOD("set_low_processor_usage_mode_sleep_usec", "usec"), &OS::set_low_processor_usage_mode_sleep_usec);
  455. ClassDB::bind_method(D_METHOD("get_low_processor_usage_mode_sleep_usec"), &OS::get_low_processor_usage_mode_sleep_usec);
  456. ClassDB::bind_method(D_METHOD("set_delta_smoothing", "delta_smoothing_enabled"), &OS::set_delta_smoothing);
  457. ClassDB::bind_method(D_METHOD("is_delta_smoothing_enabled"), &OS::is_delta_smoothing_enabled);
  458. ClassDB::bind_method(D_METHOD("get_processor_count"), &OS::get_processor_count);
  459. ClassDB::bind_method(D_METHOD("get_processor_name"), &OS::get_processor_name);
  460. ClassDB::bind_method(D_METHOD("get_system_fonts"), &OS::get_system_fonts);
  461. ClassDB::bind_method(D_METHOD("get_system_font_path", "font_name", "weight", "stretch", "italic"), &OS::get_system_font_path, DEFVAL(400), DEFVAL(100), DEFVAL(false));
  462. ClassDB::bind_method(D_METHOD("get_system_font_path_for_text", "font_name", "text", "locale", "script", "weight", "stretch", "italic"), &OS::get_system_font_path_for_text, DEFVAL(String()), DEFVAL(String()), DEFVAL(400), DEFVAL(100), DEFVAL(false));
  463. ClassDB::bind_method(D_METHOD("get_executable_path"), &OS::get_executable_path);
  464. ClassDB::bind_method(D_METHOD("read_string_from_stdin"), &OS::read_string_from_stdin);
  465. ClassDB::bind_method(D_METHOD("execute", "path", "arguments", "output", "read_stderr", "open_console"), &OS::execute, DEFVAL(Array()), DEFVAL(false), DEFVAL(false));
  466. ClassDB::bind_method(D_METHOD("create_process", "path", "arguments", "open_console"), &OS::create_process, DEFVAL(false));
  467. ClassDB::bind_method(D_METHOD("create_instance", "arguments"), &OS::create_instance);
  468. ClassDB::bind_method(D_METHOD("kill", "pid"), &OS::kill);
  469. ClassDB::bind_method(D_METHOD("shell_open", "uri"), &OS::shell_open);
  470. ClassDB::bind_method(D_METHOD("shell_show_in_file_manager", "file_or_dir_path", "open_folder"), &OS::shell_show_in_file_manager, DEFVAL(true));
  471. ClassDB::bind_method(D_METHOD("is_process_running", "pid"), &OS::is_process_running);
  472. ClassDB::bind_method(D_METHOD("get_process_id"), &OS::get_process_id);
  473. ClassDB::bind_method(D_METHOD("has_environment", "variable"), &OS::has_environment);
  474. ClassDB::bind_method(D_METHOD("get_environment", "variable"), &OS::get_environment);
  475. ClassDB::bind_method(D_METHOD("set_environment", "variable", "value"), &OS::set_environment);
  476. ClassDB::bind_method(D_METHOD("unset_environment", "variable"), &OS::unset_environment);
  477. ClassDB::bind_method(D_METHOD("get_name"), &OS::get_name);
  478. ClassDB::bind_method(D_METHOD("get_distribution_name"), &OS::get_distribution_name);
  479. ClassDB::bind_method(D_METHOD("get_version"), &OS::get_version);
  480. ClassDB::bind_method(D_METHOD("get_cmdline_args"), &OS::get_cmdline_args);
  481. ClassDB::bind_method(D_METHOD("get_cmdline_user_args"), &OS::get_cmdline_user_args);
  482. ClassDB::bind_method(D_METHOD("get_video_adapter_driver_info"), &OS::get_video_adapter_driver_info);
  483. ClassDB::bind_method(D_METHOD("set_restart_on_exit", "restart", "arguments"), &OS::set_restart_on_exit, DEFVAL(Vector<String>()));
  484. ClassDB::bind_method(D_METHOD("is_restart_on_exit_set"), &OS::is_restart_on_exit_set);
  485. ClassDB::bind_method(D_METHOD("get_restart_on_exit_arguments"), &OS::get_restart_on_exit_arguments);
  486. ClassDB::bind_method(D_METHOD("delay_usec", "usec"), &OS::delay_usec);
  487. ClassDB::bind_method(D_METHOD("delay_msec", "msec"), &OS::delay_msec);
  488. ClassDB::bind_method(D_METHOD("get_locale"), &OS::get_locale);
  489. ClassDB::bind_method(D_METHOD("get_locale_language"), &OS::get_locale_language);
  490. ClassDB::bind_method(D_METHOD("get_model_name"), &OS::get_model_name);
  491. ClassDB::bind_method(D_METHOD("is_userfs_persistent"), &OS::is_userfs_persistent);
  492. ClassDB::bind_method(D_METHOD("is_stdout_verbose"), &OS::is_stdout_verbose);
  493. ClassDB::bind_method(D_METHOD("is_debug_build"), &OS::is_debug_build);
  494. ClassDB::bind_method(D_METHOD("get_static_memory_usage"), &OS::get_static_memory_usage);
  495. ClassDB::bind_method(D_METHOD("get_static_memory_peak_usage"), &OS::get_static_memory_peak_usage);
  496. ClassDB::bind_method(D_METHOD("get_memory_info"), &OS::get_memory_info);
  497. ClassDB::bind_method(D_METHOD("move_to_trash", "path"), &OS::move_to_trash);
  498. ClassDB::bind_method(D_METHOD("get_user_data_dir"), &OS::get_user_data_dir);
  499. ClassDB::bind_method(D_METHOD("get_system_dir", "dir", "shared_storage"), &OS::get_system_dir, DEFVAL(true));
  500. ClassDB::bind_method(D_METHOD("get_config_dir"), &OS::get_config_dir);
  501. ClassDB::bind_method(D_METHOD("get_data_dir"), &OS::get_data_dir);
  502. ClassDB::bind_method(D_METHOD("get_cache_dir"), &OS::get_cache_dir);
  503. ClassDB::bind_method(D_METHOD("get_unique_id"), &OS::get_unique_id);
  504. ClassDB::bind_method(D_METHOD("get_keycode_string", "code"), &OS::get_keycode_string);
  505. ClassDB::bind_method(D_METHOD("is_keycode_unicode", "code"), &OS::is_keycode_unicode);
  506. ClassDB::bind_method(D_METHOD("find_keycode_from_string", "string"), &OS::find_keycode_from_string);
  507. ClassDB::bind_method(D_METHOD("set_use_file_access_save_and_swap", "enabled"), &OS::set_use_file_access_save_and_swap);
  508. ClassDB::bind_method(D_METHOD("set_thread_name", "name"), &OS::set_thread_name);
  509. ClassDB::bind_method(D_METHOD("get_thread_caller_id"), &OS::get_thread_caller_id);
  510. ClassDB::bind_method(D_METHOD("get_main_thread_id"), &OS::get_main_thread_id);
  511. ClassDB::bind_method(D_METHOD("has_feature", "tag_name"), &OS::has_feature);
  512. ClassDB::bind_method(D_METHOD("request_permission", "name"), &OS::request_permission);
  513. ClassDB::bind_method(D_METHOD("request_permissions"), &OS::request_permissions);
  514. ClassDB::bind_method(D_METHOD("get_granted_permissions"), &OS::get_granted_permissions);
  515. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "low_processor_usage_mode"), "set_low_processor_usage_mode", "is_in_low_processor_usage_mode");
  516. 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");
  517. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "delta_smoothing"), "set_delta_smoothing", "is_delta_smoothing_enabled");
  518. // Those default values need to be specified for the docs generator,
  519. // to avoid using values from the documentation writer's own OS instance.
  520. ADD_PROPERTY_DEFAULT("low_processor_usage_mode", false);
  521. ADD_PROPERTY_DEFAULT("low_processor_usage_mode_sleep_usec", 6900);
  522. BIND_ENUM_CONSTANT(RENDERING_DRIVER_VULKAN);
  523. BIND_ENUM_CONSTANT(RENDERING_DRIVER_OPENGL3);
  524. BIND_ENUM_CONSTANT(SYSTEM_DIR_DESKTOP);
  525. BIND_ENUM_CONSTANT(SYSTEM_DIR_DCIM);
  526. BIND_ENUM_CONSTANT(SYSTEM_DIR_DOCUMENTS);
  527. BIND_ENUM_CONSTANT(SYSTEM_DIR_DOWNLOADS);
  528. BIND_ENUM_CONSTANT(SYSTEM_DIR_MOVIES);
  529. BIND_ENUM_CONSTANT(SYSTEM_DIR_MUSIC);
  530. BIND_ENUM_CONSTANT(SYSTEM_DIR_PICTURES);
  531. BIND_ENUM_CONSTANT(SYSTEM_DIR_RINGTONES);
  532. }
  533. ////// Geometry2D //////
  534. Geometry2D *Geometry2D::singleton = nullptr;
  535. Geometry2D *Geometry2D::get_singleton() {
  536. return singleton;
  537. }
  538. bool Geometry2D::is_point_in_circle(const Vector2 &p_point, const Vector2 &p_circle_pos, real_t p_circle_radius) {
  539. return ::Geometry2D::is_point_in_circle(p_point, p_circle_pos, p_circle_radius);
  540. }
  541. real_t Geometry2D::segment_intersects_circle(const Vector2 &p_from, const Vector2 &p_to, const Vector2 &p_circle_pos, real_t p_circle_radius) {
  542. return ::Geometry2D::segment_intersects_circle(p_from, p_to, p_circle_pos, p_circle_radius);
  543. }
  544. 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) {
  545. Vector2 result;
  546. if (::Geometry2D::segment_intersects_segment(p_from_a, p_to_a, p_from_b, p_to_b, &result)) {
  547. return result;
  548. } else {
  549. return Variant();
  550. }
  551. }
  552. 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) {
  553. Vector2 result;
  554. if (::Geometry2D::line_intersects_line(p_from_a, p_dir_a, p_from_b, p_dir_b, result)) {
  555. return result;
  556. } else {
  557. return Variant();
  558. }
  559. }
  560. Vector<Vector2> Geometry2D::get_closest_points_between_segments(const Vector2 &p1, const Vector2 &q1, const Vector2 &p2, const Vector2 &q2) {
  561. Vector2 r1, r2;
  562. ::Geometry2D::get_closest_points_between_segments(p1, q1, p2, q2, r1, r2);
  563. Vector<Vector2> r = { r1, r2 };
  564. return r;
  565. }
  566. Vector2 Geometry2D::get_closest_point_to_segment(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b) {
  567. Vector2 s[2] = { p_a, p_b };
  568. return ::Geometry2D::get_closest_point_to_segment(p_point, s);
  569. }
  570. Vector2 Geometry2D::get_closest_point_to_segment_uncapped(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b) {
  571. Vector2 s[2] = { p_a, p_b };
  572. return ::Geometry2D::get_closest_point_to_segment_uncapped(p_point, s);
  573. }
  574. bool Geometry2D::point_is_inside_triangle(const Vector2 &s, const Vector2 &a, const Vector2 &b, const Vector2 &c) const {
  575. return ::Geometry2D::is_point_in_triangle(s, a, b, c);
  576. }
  577. bool Geometry2D::is_polygon_clockwise(const Vector<Vector2> &p_polygon) {
  578. return ::Geometry2D::is_polygon_clockwise(p_polygon);
  579. }
  580. bool Geometry2D::is_point_in_polygon(const Point2 &p_point, const Vector<Vector2> &p_polygon) {
  581. return ::Geometry2D::is_point_in_polygon(p_point, p_polygon);
  582. }
  583. Vector<int> Geometry2D::triangulate_polygon(const Vector<Vector2> &p_polygon) {
  584. return ::Geometry2D::triangulate_polygon(p_polygon);
  585. }
  586. Vector<int> Geometry2D::triangulate_delaunay(const Vector<Vector2> &p_points) {
  587. return ::Geometry2D::triangulate_delaunay(p_points);
  588. }
  589. Vector<Point2> Geometry2D::convex_hull(const Vector<Point2> &p_points) {
  590. return ::Geometry2D::convex_hull(p_points);
  591. }
  592. TypedArray<PackedVector2Array> Geometry2D::decompose_polygon_in_convex(const Vector<Vector2> &p_polygon) {
  593. Vector<Vector<Point2>> decomp = ::Geometry2D::decompose_polygon_in_convex(p_polygon);
  594. TypedArray<PackedVector2Array> ret;
  595. for (int i = 0; i < decomp.size(); ++i) {
  596. ret.push_back(decomp[i]);
  597. }
  598. return ret;
  599. }
  600. TypedArray<PackedVector2Array> Geometry2D::merge_polygons(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
  601. Vector<Vector<Point2>> polys = ::Geometry2D::merge_polygons(p_polygon_a, p_polygon_b);
  602. TypedArray<PackedVector2Array> ret;
  603. for (int i = 0; i < polys.size(); ++i) {
  604. ret.push_back(polys[i]);
  605. }
  606. return ret;
  607. }
  608. TypedArray<PackedVector2Array> Geometry2D::clip_polygons(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
  609. Vector<Vector<Point2>> polys = ::Geometry2D::clip_polygons(p_polygon_a, p_polygon_b);
  610. TypedArray<PackedVector2Array> ret;
  611. for (int i = 0; i < polys.size(); ++i) {
  612. ret.push_back(polys[i]);
  613. }
  614. return ret;
  615. }
  616. TypedArray<PackedVector2Array> Geometry2D::intersect_polygons(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
  617. Vector<Vector<Point2>> polys = ::Geometry2D::intersect_polygons(p_polygon_a, p_polygon_b);
  618. TypedArray<PackedVector2Array> ret;
  619. for (int i = 0; i < polys.size(); ++i) {
  620. ret.push_back(polys[i]);
  621. }
  622. return ret;
  623. }
  624. TypedArray<PackedVector2Array> Geometry2D::exclude_polygons(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
  625. Vector<Vector<Point2>> polys = ::Geometry2D::exclude_polygons(p_polygon_a, p_polygon_b);
  626. TypedArray<PackedVector2Array> ret;
  627. for (int i = 0; i < polys.size(); ++i) {
  628. ret.push_back(polys[i]);
  629. }
  630. return ret;
  631. }
  632. TypedArray<PackedVector2Array> Geometry2D::clip_polyline_with_polygon(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) {
  633. Vector<Vector<Point2>> polys = ::Geometry2D::clip_polyline_with_polygon(p_polyline, p_polygon);
  634. TypedArray<PackedVector2Array> ret;
  635. for (int i = 0; i < polys.size(); ++i) {
  636. ret.push_back(polys[i]);
  637. }
  638. return ret;
  639. }
  640. TypedArray<PackedVector2Array> Geometry2D::intersect_polyline_with_polygon(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) {
  641. Vector<Vector<Point2>> polys = ::Geometry2D::intersect_polyline_with_polygon(p_polyline, p_polygon);
  642. TypedArray<PackedVector2Array> ret;
  643. for (int i = 0; i < polys.size(); ++i) {
  644. ret.push_back(polys[i]);
  645. }
  646. return ret;
  647. }
  648. TypedArray<PackedVector2Array> Geometry2D::offset_polygon(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type) {
  649. Vector<Vector<Point2>> polys = ::Geometry2D::offset_polygon(p_polygon, p_delta, ::Geometry2D::PolyJoinType(p_join_type));
  650. TypedArray<PackedVector2Array> ret;
  651. for (int i = 0; i < polys.size(); ++i) {
  652. ret.push_back(polys[i]);
  653. }
  654. return ret;
  655. }
  656. TypedArray<PackedVector2Array> Geometry2D::offset_polyline(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type, PolyEndType p_end_type) {
  657. Vector<Vector<Point2>> polys = ::Geometry2D::offset_polyline(p_polygon, p_delta, ::Geometry2D::PolyJoinType(p_join_type), ::Geometry2D::PolyEndType(p_end_type));
  658. TypedArray<PackedVector2Array> ret;
  659. for (int i = 0; i < polys.size(); ++i) {
  660. ret.push_back(polys[i]);
  661. }
  662. return ret;
  663. }
  664. Dictionary Geometry2D::make_atlas(const Vector<Size2> &p_rects) {
  665. Dictionary ret;
  666. Vector<Size2i> rects;
  667. for (int i = 0; i < p_rects.size(); i++) {
  668. rects.push_back(p_rects[i]);
  669. }
  670. Vector<Point2i> result;
  671. Size2i size;
  672. ::Geometry2D::make_atlas(rects, result, size);
  673. Vector<Point2> r_result;
  674. for (int i = 0; i < result.size(); i++) {
  675. r_result.push_back(result[i]);
  676. }
  677. ret["points"] = r_result;
  678. ret["size"] = size;
  679. return ret;
  680. }
  681. void Geometry2D::_bind_methods() {
  682. ClassDB::bind_method(D_METHOD("is_point_in_circle", "point", "circle_position", "circle_radius"), &Geometry2D::is_point_in_circle);
  683. ClassDB::bind_method(D_METHOD("segment_intersects_circle", "segment_from", "segment_to", "circle_position", "circle_radius"), &Geometry2D::segment_intersects_circle);
  684. ClassDB::bind_method(D_METHOD("segment_intersects_segment", "from_a", "to_a", "from_b", "to_b"), &Geometry2D::segment_intersects_segment);
  685. ClassDB::bind_method(D_METHOD("line_intersects_line", "from_a", "dir_a", "from_b", "dir_b"), &Geometry2D::line_intersects_line);
  686. ClassDB::bind_method(D_METHOD("get_closest_points_between_segments", "p1", "q1", "p2", "q2"), &Geometry2D::get_closest_points_between_segments);
  687. ClassDB::bind_method(D_METHOD("get_closest_point_to_segment", "point", "s1", "s2"), &Geometry2D::get_closest_point_to_segment);
  688. ClassDB::bind_method(D_METHOD("get_closest_point_to_segment_uncapped", "point", "s1", "s2"), &Geometry2D::get_closest_point_to_segment_uncapped);
  689. ClassDB::bind_method(D_METHOD("point_is_inside_triangle", "point", "a", "b", "c"), &Geometry2D::point_is_inside_triangle);
  690. ClassDB::bind_method(D_METHOD("is_polygon_clockwise", "polygon"), &Geometry2D::is_polygon_clockwise);
  691. ClassDB::bind_method(D_METHOD("is_point_in_polygon", "point", "polygon"), &Geometry2D::is_point_in_polygon);
  692. ClassDB::bind_method(D_METHOD("triangulate_polygon", "polygon"), &Geometry2D::triangulate_polygon);
  693. ClassDB::bind_method(D_METHOD("triangulate_delaunay", "points"), &Geometry2D::triangulate_delaunay);
  694. ClassDB::bind_method(D_METHOD("convex_hull", "points"), &Geometry2D::convex_hull);
  695. ClassDB::bind_method(D_METHOD("decompose_polygon_in_convex", "polygon"), &Geometry2D::decompose_polygon_in_convex);
  696. ClassDB::bind_method(D_METHOD("merge_polygons", "polygon_a", "polygon_b"), &Geometry2D::merge_polygons);
  697. ClassDB::bind_method(D_METHOD("clip_polygons", "polygon_a", "polygon_b"), &Geometry2D::clip_polygons);
  698. ClassDB::bind_method(D_METHOD("intersect_polygons", "polygon_a", "polygon_b"), &Geometry2D::intersect_polygons);
  699. ClassDB::bind_method(D_METHOD("exclude_polygons", "polygon_a", "polygon_b"), &Geometry2D::exclude_polygons);
  700. ClassDB::bind_method(D_METHOD("clip_polyline_with_polygon", "polyline", "polygon"), &Geometry2D::clip_polyline_with_polygon);
  701. ClassDB::bind_method(D_METHOD("intersect_polyline_with_polygon", "polyline", "polygon"), &Geometry2D::intersect_polyline_with_polygon);
  702. ClassDB::bind_method(D_METHOD("offset_polygon", "polygon", "delta", "join_type"), &Geometry2D::offset_polygon, DEFVAL(JOIN_SQUARE));
  703. ClassDB::bind_method(D_METHOD("offset_polyline", "polyline", "delta", "join_type", "end_type"), &Geometry2D::offset_polyline, DEFVAL(JOIN_SQUARE), DEFVAL(END_SQUARE));
  704. ClassDB::bind_method(D_METHOD("make_atlas", "sizes"), &Geometry2D::make_atlas);
  705. BIND_ENUM_CONSTANT(OPERATION_UNION);
  706. BIND_ENUM_CONSTANT(OPERATION_DIFFERENCE);
  707. BIND_ENUM_CONSTANT(OPERATION_INTERSECTION);
  708. BIND_ENUM_CONSTANT(OPERATION_XOR);
  709. BIND_ENUM_CONSTANT(JOIN_SQUARE);
  710. BIND_ENUM_CONSTANT(JOIN_ROUND);
  711. BIND_ENUM_CONSTANT(JOIN_MITER);
  712. BIND_ENUM_CONSTANT(END_POLYGON);
  713. BIND_ENUM_CONSTANT(END_JOINED);
  714. BIND_ENUM_CONSTANT(END_BUTT);
  715. BIND_ENUM_CONSTANT(END_SQUARE);
  716. BIND_ENUM_CONSTANT(END_ROUND);
  717. }
  718. ////// Geometry3D //////
  719. Geometry3D *Geometry3D::singleton = nullptr;
  720. Geometry3D *Geometry3D::get_singleton() {
  721. return singleton;
  722. }
  723. TypedArray<Plane> Geometry3D::build_box_planes(const Vector3 &p_extents) {
  724. Variant ret = ::Geometry3D::build_box_planes(p_extents);
  725. return ret;
  726. }
  727. TypedArray<Plane> Geometry3D::build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis) {
  728. Variant ret = ::Geometry3D::build_cylinder_planes(p_radius, p_height, p_sides, p_axis);
  729. return ret;
  730. }
  731. TypedArray<Plane> Geometry3D::build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis) {
  732. Variant ret = ::Geometry3D::build_capsule_planes(p_radius, p_height, p_sides, p_lats, p_axis);
  733. return ret;
  734. }
  735. Vector<Vector3> Geometry3D::get_closest_points_between_segments(const Vector3 &p1, const Vector3 &p2, const Vector3 &q1, const Vector3 &q2) {
  736. Vector3 r1, r2;
  737. ::Geometry3D::get_closest_points_between_segments(p1, p2, q1, q2, r1, r2);
  738. Vector<Vector3> r = { r1, r2 };
  739. return r;
  740. }
  741. Vector3 Geometry3D::get_closest_point_to_segment(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b) {
  742. Vector3 s[2] = { p_a, p_b };
  743. return ::Geometry3D::get_closest_point_to_segment(p_point, s);
  744. }
  745. Vector3 Geometry3D::get_closest_point_to_segment_uncapped(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b) {
  746. Vector3 s[2] = { p_a, p_b };
  747. return ::Geometry3D::get_closest_point_to_segment_uncapped(p_point, s);
  748. }
  749. 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) {
  750. Vector3 res;
  751. if (::Geometry3D::ray_intersects_triangle(p_from, p_dir, p_v0, p_v1, p_v2, &res)) {
  752. return res;
  753. } else {
  754. return Variant();
  755. }
  756. }
  757. 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) {
  758. Vector3 res;
  759. if (::Geometry3D::segment_intersects_triangle(p_from, p_to, p_v0, p_v1, p_v2, &res)) {
  760. return res;
  761. } else {
  762. return Variant();
  763. }
  764. }
  765. Vector<Vector3> Geometry3D::segment_intersects_sphere(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_sphere_pos, real_t p_sphere_radius) {
  766. Vector<Vector3> r;
  767. Vector3 res, norm;
  768. if (!::Geometry3D::segment_intersects_sphere(p_from, p_to, p_sphere_pos, p_sphere_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_cylinder(const Vector3 &p_from, const Vector3 &p_to, float p_height, float p_radius) {
  777. Vector<Vector3> r;
  778. Vector3 res, norm;
  779. if (!::Geometry3D::segment_intersects_cylinder(p_from, p_to, p_height, p_radius, &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::segment_intersects_convex(const Vector3 &p_from, const Vector3 &p_to, const TypedArray<Plane> &p_planes) {
  788. Vector<Vector3> r;
  789. Vector3 res, norm;
  790. Vector<Plane> planes = Variant(p_planes);
  791. if (!::Geometry3D::segment_intersects_convex(p_from, p_to, planes.ptr(), planes.size(), &res, &norm)) {
  792. return r;
  793. }
  794. r.resize(2);
  795. r.set(0, res);
  796. r.set(1, norm);
  797. return r;
  798. }
  799. Vector<Vector3> Geometry3D::clip_polygon(const Vector<Vector3> &p_points, const Plane &p_plane) {
  800. return ::Geometry3D::clip_polygon(p_points, p_plane);
  801. }
  802. void Geometry3D::_bind_methods() {
  803. ClassDB::bind_method(D_METHOD("build_box_planes", "extents"), &Geometry3D::build_box_planes);
  804. ClassDB::bind_method(D_METHOD("build_cylinder_planes", "radius", "height", "sides", "axis"), &Geometry3D::build_cylinder_planes, DEFVAL(Vector3::AXIS_Z));
  805. ClassDB::bind_method(D_METHOD("build_capsule_planes", "radius", "height", "sides", "lats", "axis"), &Geometry3D::build_capsule_planes, DEFVAL(Vector3::AXIS_Z));
  806. ClassDB::bind_method(D_METHOD("get_closest_points_between_segments", "p1", "p2", "q1", "q2"), &Geometry3D::get_closest_points_between_segments);
  807. ClassDB::bind_method(D_METHOD("get_closest_point_to_segment", "point", "s1", "s2"), &Geometry3D::get_closest_point_to_segment);
  808. ClassDB::bind_method(D_METHOD("get_closest_point_to_segment_uncapped", "point", "s1", "s2"), &Geometry3D::get_closest_point_to_segment_uncapped);
  809. ClassDB::bind_method(D_METHOD("ray_intersects_triangle", "from", "dir", "a", "b", "c"), &Geometry3D::ray_intersects_triangle);
  810. ClassDB::bind_method(D_METHOD("segment_intersects_triangle", "from", "to", "a", "b", "c"), &Geometry3D::segment_intersects_triangle);
  811. ClassDB::bind_method(D_METHOD("segment_intersects_sphere", "from", "to", "sphere_position", "sphere_radius"), &Geometry3D::segment_intersects_sphere);
  812. ClassDB::bind_method(D_METHOD("segment_intersects_cylinder", "from", "to", "height", "radius"), &Geometry3D::segment_intersects_cylinder);
  813. ClassDB::bind_method(D_METHOD("segment_intersects_convex", "from", "to", "planes"), &Geometry3D::segment_intersects_convex);
  814. ClassDB::bind_method(D_METHOD("clip_polygon", "points", "plane"), &Geometry3D::clip_polygon);
  815. }
  816. ////// Marshalls //////
  817. Marshalls *Marshalls::singleton = nullptr;
  818. Marshalls *Marshalls::get_singleton() {
  819. return singleton;
  820. }
  821. String Marshalls::variant_to_base64(const Variant &p_var, bool p_full_objects) {
  822. int len;
  823. Error err = encode_variant(p_var, nullptr, len, p_full_objects);
  824. ERR_FAIL_COND_V_MSG(err != OK, "", "Error when trying to encode Variant.");
  825. Vector<uint8_t> buff;
  826. buff.resize(len);
  827. uint8_t *w = buff.ptrw();
  828. err = encode_variant(p_var, &w[0], len, p_full_objects);
  829. ERR_FAIL_COND_V_MSG(err != OK, "", "Error when trying to encode Variant.");
  830. String ret = CryptoCore::b64_encode_str(&w[0], len);
  831. ERR_FAIL_COND_V(ret.is_empty(), ret);
  832. return ret;
  833. }
  834. Variant Marshalls::base64_to_variant(const String &p_str, bool p_allow_objects) {
  835. int strlen = p_str.length();
  836. CharString cstr = p_str.ascii();
  837. Vector<uint8_t> buf;
  838. buf.resize(strlen / 4 * 3 + 1);
  839. uint8_t *w = buf.ptrw();
  840. size_t len = 0;
  841. ERR_FAIL_COND_V(CryptoCore::b64_decode(&w[0], buf.size(), &len, (unsigned char *)cstr.get_data(), strlen) != OK, Variant());
  842. Variant v;
  843. Error err = decode_variant(v, &w[0], len, nullptr, p_allow_objects);
  844. ERR_FAIL_COND_V_MSG(err != OK, Variant(), "Error when trying to decode Variant.");
  845. return v;
  846. }
  847. String Marshalls::raw_to_base64(const Vector<uint8_t> &p_arr) {
  848. String ret = CryptoCore::b64_encode_str(p_arr.ptr(), p_arr.size());
  849. ERR_FAIL_COND_V(ret.is_empty(), ret);
  850. return ret;
  851. }
  852. Vector<uint8_t> Marshalls::base64_to_raw(const String &p_str) {
  853. int strlen = p_str.length();
  854. CharString cstr = p_str.ascii();
  855. size_t arr_len = 0;
  856. Vector<uint8_t> buf;
  857. {
  858. buf.resize(strlen / 4 * 3 + 1);
  859. uint8_t *w = buf.ptrw();
  860. ERR_FAIL_COND_V(CryptoCore::b64_decode(&w[0], buf.size(), &arr_len, (unsigned char *)cstr.get_data(), strlen) != OK, Vector<uint8_t>());
  861. }
  862. buf.resize(arr_len);
  863. return buf;
  864. }
  865. String Marshalls::utf8_to_base64(const String &p_str) {
  866. CharString cstr = p_str.utf8();
  867. String ret = CryptoCore::b64_encode_str((unsigned char *)cstr.get_data(), cstr.length());
  868. ERR_FAIL_COND_V(ret.is_empty(), ret);
  869. return ret;
  870. }
  871. String Marshalls::base64_to_utf8(const String &p_str) {
  872. int strlen = p_str.length();
  873. CharString cstr = p_str.ascii();
  874. Vector<uint8_t> buf;
  875. buf.resize(strlen / 4 * 3 + 1 + 1);
  876. uint8_t *w = buf.ptrw();
  877. size_t len = 0;
  878. ERR_FAIL_COND_V(CryptoCore::b64_decode(&w[0], buf.size(), &len, (unsigned char *)cstr.get_data(), strlen) != OK, String());
  879. w[len] = 0;
  880. String ret = String::utf8((char *)&w[0]);
  881. return ret;
  882. }
  883. void Marshalls::_bind_methods() {
  884. ClassDB::bind_method(D_METHOD("variant_to_base64", "variant", "full_objects"), &Marshalls::variant_to_base64, DEFVAL(false));
  885. ClassDB::bind_method(D_METHOD("base64_to_variant", "base64_str", "allow_objects"), &Marshalls::base64_to_variant, DEFVAL(false));
  886. ClassDB::bind_method(D_METHOD("raw_to_base64", "array"), &Marshalls::raw_to_base64);
  887. ClassDB::bind_method(D_METHOD("base64_to_raw", "base64_str"), &Marshalls::base64_to_raw);
  888. ClassDB::bind_method(D_METHOD("utf8_to_base64", "utf8_str"), &Marshalls::utf8_to_base64);
  889. ClassDB::bind_method(D_METHOD("base64_to_utf8", "base64_str"), &Marshalls::base64_to_utf8);
  890. }
  891. ////// Semaphore //////
  892. void Semaphore::wait() {
  893. semaphore.wait();
  894. }
  895. bool Semaphore::try_wait() {
  896. return semaphore.try_wait();
  897. }
  898. void Semaphore::post() {
  899. semaphore.post();
  900. }
  901. void Semaphore::_bind_methods() {
  902. ClassDB::bind_method(D_METHOD("wait"), &Semaphore::wait);
  903. ClassDB::bind_method(D_METHOD("try_wait"), &Semaphore::try_wait);
  904. ClassDB::bind_method(D_METHOD("post"), &Semaphore::post);
  905. }
  906. ////// Mutex //////
  907. void Mutex::lock() {
  908. mutex.lock();
  909. }
  910. bool Mutex::try_lock() {
  911. return mutex.try_lock();
  912. }
  913. void Mutex::unlock() {
  914. mutex.unlock();
  915. }
  916. void Mutex::_bind_methods() {
  917. ClassDB::bind_method(D_METHOD("lock"), &Mutex::lock);
  918. ClassDB::bind_method(D_METHOD("try_lock"), &Mutex::try_lock);
  919. ClassDB::bind_method(D_METHOD("unlock"), &Mutex::unlock);
  920. }
  921. ////// Thread //////
  922. void Thread::_start_func(void *ud) {
  923. Ref<Thread> *tud = (Ref<Thread> *)ud;
  924. Ref<Thread> t = *tud;
  925. memdelete(tud);
  926. Object *target_instance = t->target_callable.get_object();
  927. if (!target_instance) {
  928. t->running.clear();
  929. 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()));
  930. }
  931. // Finding out a suitable name for the thread can involve querying a node, if the target is one.
  932. // We know this is safe (unless the user is causing life cycle race conditions, which would be a bug on their part).
  933. set_current_thread_safe_for_nodes(true);
  934. String func_name = t->target_callable.is_custom() ? t->target_callable.get_custom()->get_as_text() : String(t->target_callable.get_method());
  935. set_current_thread_safe_for_nodes(false);
  936. ::Thread::set_name(func_name);
  937. // To avoid a circular reference between the thread and the script which can possibly contain a reference
  938. // to the thread, we will do the call (keeping a reference up to that point) and then break chains with it.
  939. // When the call returns, we will reference the thread again if possible.
  940. ObjectID th_instance_id = t->get_instance_id();
  941. Callable target_callable = t->target_callable;
  942. t = Ref<Thread>();
  943. Callable::CallError ce;
  944. Variant ret;
  945. target_callable.callp(nullptr, 0, ret, ce);
  946. // If script properly kept a reference to the thread, we should be able to re-reference it now
  947. // (well, or if the call failed, since we had to break chains anyway because the outcome isn't known upfront).
  948. t = Ref<Thread>(ObjectDB::get_instance(th_instance_id));
  949. if (t.is_valid()) {
  950. t->ret = ret;
  951. t->running.clear();
  952. } else {
  953. // We could print a warning here, but the Thread object will be eventually destroyed
  954. // noticing wait_to_finish() hasn't been called on it, and it will print a warning itself.
  955. }
  956. if (ce.error != Callable::CallError::CALL_OK) {
  957. ERR_FAIL_MSG("Could not call function '" + func_name + "' to start thread " + t->get_id() + ": " + Variant::get_callable_error_text(t->target_callable, nullptr, 0, ce) + ".");
  958. }
  959. }
  960. Error Thread::start(const Callable &p_callable, Priority p_priority) {
  961. ERR_FAIL_COND_V_MSG(is_started(), ERR_ALREADY_IN_USE, "Thread already started.");
  962. ERR_FAIL_COND_V(!p_callable.is_valid(), ERR_INVALID_PARAMETER);
  963. ERR_FAIL_INDEX_V(p_priority, PRIORITY_MAX, ERR_INVALID_PARAMETER);
  964. ret = Variant();
  965. target_callable = p_callable;
  966. running.set();
  967. Ref<Thread> *ud = memnew(Ref<Thread>(this));
  968. ::Thread::Settings s;
  969. s.priority = (::Thread::Priority)p_priority;
  970. thread.start(_start_func, ud, s);
  971. return OK;
  972. }
  973. String Thread::get_id() const {
  974. return itos(thread.get_id());
  975. }
  976. bool Thread::is_started() const {
  977. return thread.is_started();
  978. }
  979. bool Thread::is_alive() const {
  980. return running.is_set();
  981. }
  982. Variant Thread::wait_to_finish() {
  983. ERR_FAIL_COND_V_MSG(!is_started(), Variant(), "Thread must have been started to wait for its completion.");
  984. thread.wait_to_finish();
  985. Variant r = ret;
  986. target_callable = Callable();
  987. return r;
  988. }
  989. void Thread::set_thread_safety_checks_enabled(bool p_enabled) {
  990. ERR_FAIL_COND_MSG(::Thread::is_main_thread(), "This call is forbidden on the main thread.");
  991. set_current_thread_safe_for_nodes(!p_enabled);
  992. }
  993. void Thread::_bind_methods() {
  994. ClassDB::bind_method(D_METHOD("start", "callable", "priority"), &Thread::start, DEFVAL(PRIORITY_NORMAL));
  995. ClassDB::bind_method(D_METHOD("get_id"), &Thread::get_id);
  996. ClassDB::bind_method(D_METHOD("is_started"), &Thread::is_started);
  997. ClassDB::bind_method(D_METHOD("is_alive"), &Thread::is_alive);
  998. ClassDB::bind_method(D_METHOD("wait_to_finish"), &Thread::wait_to_finish);
  999. ClassDB::bind_static_method("Thread", D_METHOD("set_thread_safety_checks_enabled", "enabled"), &Thread::set_thread_safety_checks_enabled);
  1000. BIND_ENUM_CONSTANT(PRIORITY_LOW);
  1001. BIND_ENUM_CONSTANT(PRIORITY_NORMAL);
  1002. BIND_ENUM_CONSTANT(PRIORITY_HIGH);
  1003. }
  1004. namespace special {
  1005. ////// ClassDB //////
  1006. PackedStringArray ClassDB::get_class_list() const {
  1007. List<StringName> classes;
  1008. ::ClassDB::get_class_list(&classes);
  1009. PackedStringArray ret;
  1010. ret.resize(classes.size());
  1011. int idx = 0;
  1012. for (const StringName &E : classes) {
  1013. ret.set(idx++, E);
  1014. }
  1015. return ret;
  1016. }
  1017. PackedStringArray ClassDB::get_inheriters_from_class(const StringName &p_class) const {
  1018. List<StringName> classes;
  1019. ::ClassDB::get_inheriters_from_class(p_class, &classes);
  1020. PackedStringArray ret;
  1021. ret.resize(classes.size());
  1022. int idx = 0;
  1023. for (const StringName &E : classes) {
  1024. ret.set(idx++, E);
  1025. }
  1026. return ret;
  1027. }
  1028. StringName ClassDB::get_parent_class(const StringName &p_class) const {
  1029. return ::ClassDB::get_parent_class(p_class);
  1030. }
  1031. bool ClassDB::class_exists(const StringName &p_class) const {
  1032. return ::ClassDB::class_exists(p_class);
  1033. }
  1034. bool ClassDB::is_parent_class(const StringName &p_class, const StringName &p_inherits) const {
  1035. return ::ClassDB::is_parent_class(p_class, p_inherits);
  1036. }
  1037. bool ClassDB::can_instantiate(const StringName &p_class) const {
  1038. return ::ClassDB::can_instantiate(p_class);
  1039. }
  1040. Variant ClassDB::instantiate(const StringName &p_class) const {
  1041. Object *obj = ::ClassDB::instantiate(p_class);
  1042. if (!obj) {
  1043. return Variant();
  1044. }
  1045. RefCounted *r = Object::cast_to<RefCounted>(obj);
  1046. if (r) {
  1047. return Ref<RefCounted>(r);
  1048. } else {
  1049. return obj;
  1050. }
  1051. }
  1052. bool ClassDB::class_has_signal(StringName p_class, StringName p_signal) const {
  1053. return ::ClassDB::has_signal(p_class, p_signal);
  1054. }
  1055. Dictionary ClassDB::class_get_signal(StringName p_class, StringName p_signal) const {
  1056. MethodInfo signal;
  1057. if (::ClassDB::get_signal(p_class, p_signal, &signal)) {
  1058. return signal.operator Dictionary();
  1059. } else {
  1060. return Dictionary();
  1061. }
  1062. }
  1063. TypedArray<Dictionary> ClassDB::class_get_signal_list(StringName p_class, bool p_no_inheritance) const {
  1064. List<MethodInfo> signals;
  1065. ::ClassDB::get_signal_list(p_class, &signals, p_no_inheritance);
  1066. TypedArray<Dictionary> ret;
  1067. for (const MethodInfo &E : signals) {
  1068. ret.push_back(E.operator Dictionary());
  1069. }
  1070. return ret;
  1071. }
  1072. TypedArray<Dictionary> ClassDB::class_get_property_list(StringName p_class, bool p_no_inheritance) const {
  1073. List<PropertyInfo> plist;
  1074. ::ClassDB::get_property_list(p_class, &plist, p_no_inheritance);
  1075. TypedArray<Dictionary> ret;
  1076. for (const PropertyInfo &E : plist) {
  1077. ret.push_back(E.operator Dictionary());
  1078. }
  1079. return ret;
  1080. }
  1081. Variant ClassDB::class_get_property(Object *p_object, const StringName &p_property) const {
  1082. Variant ret;
  1083. ::ClassDB::get_property(p_object, p_property, ret);
  1084. return ret;
  1085. }
  1086. Error ClassDB::class_set_property(Object *p_object, const StringName &p_property, const Variant &p_value) const {
  1087. Variant ret;
  1088. bool valid;
  1089. if (!::ClassDB::set_property(p_object, p_property, p_value, &valid)) {
  1090. return ERR_UNAVAILABLE;
  1091. } else if (!valid) {
  1092. return ERR_INVALID_DATA;
  1093. }
  1094. return OK;
  1095. }
  1096. bool ClassDB::class_has_method(StringName p_class, StringName p_method, bool p_no_inheritance) const {
  1097. return ::ClassDB::has_method(p_class, p_method, p_no_inheritance);
  1098. }
  1099. TypedArray<Dictionary> ClassDB::class_get_method_list(StringName p_class, bool p_no_inheritance) const {
  1100. List<MethodInfo> methods;
  1101. ::ClassDB::get_method_list(p_class, &methods, p_no_inheritance);
  1102. TypedArray<Dictionary> ret;
  1103. for (const MethodInfo &E : methods) {
  1104. #ifdef DEBUG_METHODS_ENABLED
  1105. ret.push_back(E.operator Dictionary());
  1106. #else
  1107. Dictionary dict;
  1108. dict["name"] = E.name;
  1109. ret.push_back(dict);
  1110. #endif
  1111. }
  1112. return ret;
  1113. }
  1114. PackedStringArray ClassDB::class_get_integer_constant_list(const StringName &p_class, bool p_no_inheritance) const {
  1115. List<String> constants;
  1116. ::ClassDB::get_integer_constant_list(p_class, &constants, p_no_inheritance);
  1117. PackedStringArray ret;
  1118. ret.resize(constants.size());
  1119. int idx = 0;
  1120. for (const String &E : constants) {
  1121. ret.set(idx++, E);
  1122. }
  1123. return ret;
  1124. }
  1125. bool ClassDB::class_has_integer_constant(const StringName &p_class, const StringName &p_name) const {
  1126. bool success;
  1127. ::ClassDB::get_integer_constant(p_class, p_name, &success);
  1128. return success;
  1129. }
  1130. int64_t ClassDB::class_get_integer_constant(const StringName &p_class, const StringName &p_name) const {
  1131. bool found;
  1132. int64_t c = ::ClassDB::get_integer_constant(p_class, p_name, &found);
  1133. ERR_FAIL_COND_V(!found, 0);
  1134. return c;
  1135. }
  1136. bool ClassDB::class_has_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance) const {
  1137. return ::ClassDB::has_enum(p_class, p_name, p_no_inheritance);
  1138. }
  1139. PackedStringArray ClassDB::class_get_enum_list(const StringName &p_class, bool p_no_inheritance) const {
  1140. List<StringName> enums;
  1141. ::ClassDB::get_enum_list(p_class, &enums, p_no_inheritance);
  1142. PackedStringArray ret;
  1143. ret.resize(enums.size());
  1144. int idx = 0;
  1145. for (const StringName &E : enums) {
  1146. ret.set(idx++, E);
  1147. }
  1148. return ret;
  1149. }
  1150. PackedStringArray ClassDB::class_get_enum_constants(const StringName &p_class, const StringName &p_enum, bool p_no_inheritance) const {
  1151. List<StringName> constants;
  1152. ::ClassDB::get_enum_constants(p_class, p_enum, &constants, p_no_inheritance);
  1153. PackedStringArray ret;
  1154. ret.resize(constants.size());
  1155. int idx = 0;
  1156. for (const StringName &E : constants) {
  1157. ret.set(idx++, E);
  1158. }
  1159. return ret;
  1160. }
  1161. StringName ClassDB::class_get_integer_constant_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance) const {
  1162. return ::ClassDB::get_integer_constant_enum(p_class, p_name, p_no_inheritance);
  1163. }
  1164. bool ClassDB::is_class_enabled(StringName p_class) const {
  1165. return ::ClassDB::is_class_enabled(p_class);
  1166. }
  1167. void ClassDB::_bind_methods() {
  1168. ::ClassDB::bind_method(D_METHOD("get_class_list"), &ClassDB::get_class_list);
  1169. ::ClassDB::bind_method(D_METHOD("get_inheriters_from_class", "class"), &ClassDB::get_inheriters_from_class);
  1170. ::ClassDB::bind_method(D_METHOD("get_parent_class", "class"), &ClassDB::get_parent_class);
  1171. ::ClassDB::bind_method(D_METHOD("class_exists", "class"), &ClassDB::class_exists);
  1172. ::ClassDB::bind_method(D_METHOD("is_parent_class", "class", "inherits"), &ClassDB::is_parent_class);
  1173. ::ClassDB::bind_method(D_METHOD("can_instantiate", "class"), &ClassDB::can_instantiate);
  1174. ::ClassDB::bind_method(D_METHOD("instantiate", "class"), &ClassDB::instantiate);
  1175. ::ClassDB::bind_method(D_METHOD("class_has_signal", "class", "signal"), &ClassDB::class_has_signal);
  1176. ::ClassDB::bind_method(D_METHOD("class_get_signal", "class", "signal"), &ClassDB::class_get_signal);
  1177. ::ClassDB::bind_method(D_METHOD("class_get_signal_list", "class", "no_inheritance"), &ClassDB::class_get_signal_list, DEFVAL(false));
  1178. ::ClassDB::bind_method(D_METHOD("class_get_property_list", "class", "no_inheritance"), &ClassDB::class_get_property_list, DEFVAL(false));
  1179. ::ClassDB::bind_method(D_METHOD("class_get_property", "object", "property"), &ClassDB::class_get_property);
  1180. ::ClassDB::bind_method(D_METHOD("class_set_property", "object", "property", "value"), &ClassDB::class_set_property);
  1181. ::ClassDB::bind_method(D_METHOD("class_has_method", "class", "method", "no_inheritance"), &ClassDB::class_has_method, DEFVAL(false));
  1182. ::ClassDB::bind_method(D_METHOD("class_get_method_list", "class", "no_inheritance"), &ClassDB::class_get_method_list, DEFVAL(false));
  1183. ::ClassDB::bind_method(D_METHOD("class_get_integer_constant_list", "class", "no_inheritance"), &ClassDB::class_get_integer_constant_list, DEFVAL(false));
  1184. ::ClassDB::bind_method(D_METHOD("class_has_integer_constant", "class", "name"), &ClassDB::class_has_integer_constant);
  1185. ::ClassDB::bind_method(D_METHOD("class_get_integer_constant", "class", "name"), &ClassDB::class_get_integer_constant);
  1186. ::ClassDB::bind_method(D_METHOD("class_has_enum", "class", "name", "no_inheritance"), &ClassDB::class_has_enum, DEFVAL(false));
  1187. ::ClassDB::bind_method(D_METHOD("class_get_enum_list", "class", "no_inheritance"), &ClassDB::class_get_enum_list, DEFVAL(false));
  1188. ::ClassDB::bind_method(D_METHOD("class_get_enum_constants", "class", "enum", "no_inheritance"), &ClassDB::class_get_enum_constants, DEFVAL(false));
  1189. ::ClassDB::bind_method(D_METHOD("class_get_integer_constant_enum", "class", "name", "no_inheritance"), &ClassDB::class_get_integer_constant_enum, DEFVAL(false));
  1190. ::ClassDB::bind_method(D_METHOD("is_class_enabled", "class"), &ClassDB::is_class_enabled);
  1191. }
  1192. } // namespace special
  1193. ////// Engine //////
  1194. void Engine::set_physics_ticks_per_second(int p_ips) {
  1195. ::Engine::get_singleton()->set_physics_ticks_per_second(p_ips);
  1196. }
  1197. int Engine::get_physics_ticks_per_second() const {
  1198. return ::Engine::get_singleton()->get_physics_ticks_per_second();
  1199. }
  1200. void Engine::set_max_physics_steps_per_frame(int p_max_physics_steps) {
  1201. ::Engine::get_singleton()->set_max_physics_steps_per_frame(p_max_physics_steps);
  1202. }
  1203. int Engine::get_max_physics_steps_per_frame() const {
  1204. return ::Engine::get_singleton()->get_max_physics_steps_per_frame();
  1205. }
  1206. void Engine::set_physics_jitter_fix(double p_threshold) {
  1207. ::Engine::get_singleton()->set_physics_jitter_fix(p_threshold);
  1208. }
  1209. double Engine::get_physics_jitter_fix() const {
  1210. return ::Engine::get_singleton()->get_physics_jitter_fix();
  1211. }
  1212. double Engine::get_physics_interpolation_fraction() const {
  1213. return ::Engine::get_singleton()->get_physics_interpolation_fraction();
  1214. }
  1215. void Engine::set_max_fps(int p_fps) {
  1216. ::Engine::get_singleton()->set_max_fps(p_fps);
  1217. }
  1218. int Engine::get_max_fps() const {
  1219. return ::Engine::get_singleton()->get_max_fps();
  1220. }
  1221. double Engine::get_frames_per_second() const {
  1222. return ::Engine::get_singleton()->get_frames_per_second();
  1223. }
  1224. uint64_t Engine::get_physics_frames() const {
  1225. return ::Engine::get_singleton()->get_physics_frames();
  1226. }
  1227. uint64_t Engine::get_process_frames() const {
  1228. return ::Engine::get_singleton()->get_process_frames();
  1229. }
  1230. void Engine::set_time_scale(double p_scale) {
  1231. ::Engine::get_singleton()->set_time_scale(p_scale);
  1232. }
  1233. double Engine::get_time_scale() {
  1234. return ::Engine::get_singleton()->get_time_scale();
  1235. }
  1236. int Engine::get_frames_drawn() {
  1237. return ::Engine::get_singleton()->get_frames_drawn();
  1238. }
  1239. MainLoop *Engine::get_main_loop() const {
  1240. // Needs to remain in OS, since it's actually OS that interacts with it, but it's better exposed here
  1241. return ::OS::get_singleton()->get_main_loop();
  1242. }
  1243. Dictionary Engine::get_version_info() const {
  1244. return ::Engine::get_singleton()->get_version_info();
  1245. }
  1246. Dictionary Engine::get_author_info() const {
  1247. return ::Engine::get_singleton()->get_author_info();
  1248. }
  1249. TypedArray<Dictionary> Engine::get_copyright_info() const {
  1250. return ::Engine::get_singleton()->get_copyright_info();
  1251. }
  1252. Dictionary Engine::get_donor_info() const {
  1253. return ::Engine::get_singleton()->get_donor_info();
  1254. }
  1255. Dictionary Engine::get_license_info() const {
  1256. return ::Engine::get_singleton()->get_license_info();
  1257. }
  1258. String Engine::get_license_text() const {
  1259. return ::Engine::get_singleton()->get_license_text();
  1260. }
  1261. String Engine::get_architecture_name() const {
  1262. return ::Engine::get_singleton()->get_architecture_name();
  1263. }
  1264. bool Engine::is_in_physics_frame() const {
  1265. return ::Engine::get_singleton()->is_in_physics_frame();
  1266. }
  1267. bool Engine::has_singleton(const StringName &p_name) const {
  1268. return ::Engine::get_singleton()->has_singleton(p_name);
  1269. }
  1270. Object *Engine::get_singleton_object(const StringName &p_name) const {
  1271. return ::Engine::get_singleton()->get_singleton_object(p_name);
  1272. }
  1273. void Engine::register_singleton(const StringName &p_name, Object *p_object) {
  1274. ERR_FAIL_COND_MSG(has_singleton(p_name), "Singleton already registered: " + String(p_name));
  1275. ERR_FAIL_COND_MSG(!String(p_name).is_valid_identifier(), "Singleton name is not a valid identifier: " + p_name);
  1276. ::Engine::Singleton s;
  1277. s.class_name = p_name;
  1278. s.name = p_name;
  1279. s.ptr = p_object;
  1280. s.user_created = true;
  1281. ::Engine::get_singleton()->add_singleton(s);
  1282. }
  1283. void Engine::unregister_singleton(const StringName &p_name) {
  1284. ERR_FAIL_COND_MSG(!has_singleton(p_name), "Attempt to remove unregistered singleton: " + String(p_name));
  1285. ERR_FAIL_COND_MSG(!::Engine::get_singleton()->is_singleton_user_created(p_name), "Attempt to remove non-user created singleton: " + String(p_name));
  1286. ::Engine::get_singleton()->remove_singleton(p_name);
  1287. }
  1288. Vector<String> Engine::get_singleton_list() const {
  1289. List<::Engine::Singleton> singletons;
  1290. ::Engine::get_singleton()->get_singletons(&singletons);
  1291. Vector<String> ret;
  1292. for (List<::Engine::Singleton>::Element *E = singletons.front(); E; E = E->next()) {
  1293. ret.push_back(E->get().name);
  1294. }
  1295. return ret;
  1296. }
  1297. Error Engine::register_script_language(ScriptLanguage *p_language) {
  1298. return ScriptServer::register_language(p_language);
  1299. }
  1300. Error Engine::unregister_script_language(const ScriptLanguage *p_language) {
  1301. return ScriptServer::unregister_language(p_language);
  1302. }
  1303. int Engine::get_script_language_count() {
  1304. return ScriptServer::get_language_count();
  1305. }
  1306. ScriptLanguage *Engine::get_script_language(int p_index) const {
  1307. return ScriptServer::get_language(p_index);
  1308. }
  1309. void Engine::set_editor_hint(bool p_enabled) {
  1310. ::Engine::get_singleton()->set_editor_hint(p_enabled);
  1311. }
  1312. bool Engine::is_editor_hint() const {
  1313. return ::Engine::get_singleton()->is_editor_hint();
  1314. }
  1315. String Engine::get_write_movie_path() const {
  1316. return ::Engine::get_singleton()->get_write_movie_path();
  1317. }
  1318. void Engine::set_print_error_messages(bool p_enabled) {
  1319. ::Engine::get_singleton()->set_print_error_messages(p_enabled);
  1320. }
  1321. bool Engine::is_printing_error_messages() const {
  1322. return ::Engine::get_singleton()->is_printing_error_messages();
  1323. }
  1324. void Engine::_bind_methods() {
  1325. ClassDB::bind_method(D_METHOD("set_physics_ticks_per_second", "physics_ticks_per_second"), &Engine::set_physics_ticks_per_second);
  1326. ClassDB::bind_method(D_METHOD("get_physics_ticks_per_second"), &Engine::get_physics_ticks_per_second);
  1327. ClassDB::bind_method(D_METHOD("set_max_physics_steps_per_frame", "max_physics_steps"), &Engine::set_max_physics_steps_per_frame);
  1328. ClassDB::bind_method(D_METHOD("get_max_physics_steps_per_frame"), &Engine::get_max_physics_steps_per_frame);
  1329. ClassDB::bind_method(D_METHOD("set_physics_jitter_fix", "physics_jitter_fix"), &Engine::set_physics_jitter_fix);
  1330. ClassDB::bind_method(D_METHOD("get_physics_jitter_fix"), &Engine::get_physics_jitter_fix);
  1331. ClassDB::bind_method(D_METHOD("get_physics_interpolation_fraction"), &Engine::get_physics_interpolation_fraction);
  1332. ClassDB::bind_method(D_METHOD("set_max_fps", "max_fps"), &Engine::set_max_fps);
  1333. ClassDB::bind_method(D_METHOD("get_max_fps"), &Engine::get_max_fps);
  1334. ClassDB::bind_method(D_METHOD("set_time_scale", "time_scale"), &Engine::set_time_scale);
  1335. ClassDB::bind_method(D_METHOD("get_time_scale"), &Engine::get_time_scale);
  1336. ClassDB::bind_method(D_METHOD("get_frames_drawn"), &Engine::get_frames_drawn);
  1337. ClassDB::bind_method(D_METHOD("get_frames_per_second"), &Engine::get_frames_per_second);
  1338. ClassDB::bind_method(D_METHOD("get_physics_frames"), &Engine::get_physics_frames);
  1339. ClassDB::bind_method(D_METHOD("get_process_frames"), &Engine::get_process_frames);
  1340. ClassDB::bind_method(D_METHOD("get_main_loop"), &Engine::get_main_loop);
  1341. ClassDB::bind_method(D_METHOD("get_version_info"), &Engine::get_version_info);
  1342. ClassDB::bind_method(D_METHOD("get_author_info"), &Engine::get_author_info);
  1343. ClassDB::bind_method(D_METHOD("get_copyright_info"), &Engine::get_copyright_info);
  1344. ClassDB::bind_method(D_METHOD("get_donor_info"), &Engine::get_donor_info);
  1345. ClassDB::bind_method(D_METHOD("get_license_info"), &Engine::get_license_info);
  1346. ClassDB::bind_method(D_METHOD("get_license_text"), &Engine::get_license_text);
  1347. ClassDB::bind_method(D_METHOD("get_architecture_name"), &Engine::get_architecture_name);
  1348. ClassDB::bind_method(D_METHOD("is_in_physics_frame"), &Engine::is_in_physics_frame);
  1349. ClassDB::bind_method(D_METHOD("has_singleton", "name"), &Engine::has_singleton);
  1350. ClassDB::bind_method(D_METHOD("get_singleton", "name"), &Engine::get_singleton_object);
  1351. ClassDB::bind_method(D_METHOD("register_singleton", "name", "instance"), &Engine::register_singleton);
  1352. ClassDB::bind_method(D_METHOD("unregister_singleton", "name"), &Engine::unregister_singleton);
  1353. ClassDB::bind_method(D_METHOD("get_singleton_list"), &Engine::get_singleton_list);
  1354. ClassDB::bind_method(D_METHOD("register_script_language", "language"), &Engine::register_script_language);
  1355. ClassDB::bind_method(D_METHOD("unregister_script_language", "language"), &Engine::unregister_script_language);
  1356. ClassDB::bind_method(D_METHOD("get_script_language_count"), &Engine::get_script_language_count);
  1357. ClassDB::bind_method(D_METHOD("get_script_language", "index"), &Engine::get_script_language);
  1358. ClassDB::bind_method(D_METHOD("is_editor_hint"), &Engine::is_editor_hint);
  1359. ClassDB::bind_method(D_METHOD("get_write_movie_path"), &Engine::get_write_movie_path);
  1360. ClassDB::bind_method(D_METHOD("set_print_error_messages", "enabled"), &Engine::set_print_error_messages);
  1361. ClassDB::bind_method(D_METHOD("is_printing_error_messages"), &Engine::is_printing_error_messages);
  1362. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "print_error_messages"), "set_print_error_messages", "is_printing_error_messages");
  1363. ADD_PROPERTY(PropertyInfo(Variant::INT, "physics_ticks_per_second"), "set_physics_ticks_per_second", "get_physics_ticks_per_second");
  1364. ADD_PROPERTY(PropertyInfo(Variant::INT, "max_physics_steps_per_frame"), "set_max_physics_steps_per_frame", "get_max_physics_steps_per_frame");
  1365. ADD_PROPERTY(PropertyInfo(Variant::INT, "max_fps"), "set_max_fps", "get_max_fps");
  1366. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "time_scale"), "set_time_scale", "get_time_scale");
  1367. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "physics_jitter_fix"), "set_physics_jitter_fix", "get_physics_jitter_fix");
  1368. }
  1369. Engine *Engine::singleton = nullptr;
  1370. ////// EngineDebugger //////
  1371. bool EngineDebugger::is_active() {
  1372. return ::EngineDebugger::is_active();
  1373. }
  1374. void EngineDebugger::register_profiler(const StringName &p_name, Ref<EngineProfiler> p_profiler) {
  1375. ERR_FAIL_COND(p_profiler.is_null());
  1376. ERR_FAIL_COND_MSG(p_profiler->is_bound(), "Profiler already registered.");
  1377. ERR_FAIL_COND_MSG(profilers.has(p_name) || has_profiler(p_name), "Profiler name already in use: " + p_name);
  1378. Error err = p_profiler->bind(p_name);
  1379. ERR_FAIL_COND_MSG(err != OK, "Profiler failed to register with error: " + itos(err));
  1380. profilers.insert(p_name, p_profiler);
  1381. }
  1382. void EngineDebugger::unregister_profiler(const StringName &p_name) {
  1383. ERR_FAIL_COND_MSG(!profilers.has(p_name), "Profiler not registered: " + p_name);
  1384. profilers[p_name]->unbind();
  1385. profilers.erase(p_name);
  1386. }
  1387. bool EngineDebugger::is_profiling(const StringName &p_name) {
  1388. return ::EngineDebugger::is_profiling(p_name);
  1389. }
  1390. bool EngineDebugger::has_profiler(const StringName &p_name) {
  1391. return ::EngineDebugger::has_profiler(p_name);
  1392. }
  1393. void EngineDebugger::profiler_add_frame_data(const StringName &p_name, const Array &p_data) {
  1394. ::EngineDebugger::profiler_add_frame_data(p_name, p_data);
  1395. }
  1396. void EngineDebugger::profiler_enable(const StringName &p_name, bool p_enabled, const Array &p_opts) {
  1397. if (::EngineDebugger::get_singleton()) {
  1398. ::EngineDebugger::get_singleton()->profiler_enable(p_name, p_enabled, p_opts);
  1399. }
  1400. }
  1401. void EngineDebugger::register_message_capture(const StringName &p_name, const Callable &p_callable) {
  1402. ERR_FAIL_COND_MSG(captures.has(p_name) || has_capture(p_name), "Capture already registered: " + p_name);
  1403. captures.insert(p_name, p_callable);
  1404. Callable &c = captures[p_name];
  1405. ::EngineDebugger::Capture capture(&c, &EngineDebugger::call_capture);
  1406. ::EngineDebugger::register_message_capture(p_name, capture);
  1407. }
  1408. void EngineDebugger::unregister_message_capture(const StringName &p_name) {
  1409. ERR_FAIL_COND_MSG(!captures.has(p_name), "Capture not registered: " + p_name);
  1410. ::EngineDebugger::unregister_message_capture(p_name);
  1411. captures.erase(p_name);
  1412. }
  1413. bool EngineDebugger::has_capture(const StringName &p_name) {
  1414. return ::EngineDebugger::has_capture(p_name);
  1415. }
  1416. void EngineDebugger::send_message(const String &p_msg, const Array &p_data) {
  1417. ERR_FAIL_COND_MSG(!::EngineDebugger::is_active(), "Can't send message. No active debugger");
  1418. ::EngineDebugger::get_singleton()->send_message(p_msg, p_data);
  1419. }
  1420. Error EngineDebugger::call_capture(void *p_user, const String &p_cmd, const Array &p_data, bool &r_captured) {
  1421. Callable &capture = *(Callable *)p_user;
  1422. if (capture.is_null()) {
  1423. return FAILED;
  1424. }
  1425. Variant cmd = p_cmd, data = p_data;
  1426. const Variant *args[2] = { &cmd, &data };
  1427. Variant retval;
  1428. Callable::CallError err;
  1429. capture.callp(args, 2, retval, err);
  1430. 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));
  1431. ERR_FAIL_COND_V_MSG(retval.get_type() != Variant::BOOL, FAILED, "Error calling 'capture' to callable: " + String(capture) + ". Return type is not bool.");
  1432. r_captured = retval;
  1433. return OK;
  1434. }
  1435. EngineDebugger::~EngineDebugger() {
  1436. for (const KeyValue<StringName, Callable> &E : captures) {
  1437. ::EngineDebugger::unregister_message_capture(E.key);
  1438. }
  1439. captures.clear();
  1440. }
  1441. EngineDebugger *EngineDebugger::singleton = nullptr;
  1442. void EngineDebugger::_bind_methods() {
  1443. ClassDB::bind_method(D_METHOD("is_active"), &EngineDebugger::is_active);
  1444. ClassDB::bind_method(D_METHOD("register_profiler", "name", "profiler"), &EngineDebugger::register_profiler);
  1445. ClassDB::bind_method(D_METHOD("unregister_profiler", "name"), &EngineDebugger::unregister_profiler);
  1446. ClassDB::bind_method(D_METHOD("is_profiling", "name"), &EngineDebugger::is_profiling);
  1447. ClassDB::bind_method(D_METHOD("has_profiler", "name"), &EngineDebugger::has_profiler);
  1448. ClassDB::bind_method(D_METHOD("profiler_add_frame_data", "name", "data"), &EngineDebugger::profiler_add_frame_data);
  1449. ClassDB::bind_method(D_METHOD("profiler_enable", "name", "enable", "arguments"), &EngineDebugger::profiler_enable, DEFVAL(Array()));
  1450. ClassDB::bind_method(D_METHOD("register_message_capture", "name", "callable"), &EngineDebugger::register_message_capture);
  1451. ClassDB::bind_method(D_METHOD("unregister_message_capture", "name"), &EngineDebugger::unregister_message_capture);
  1452. ClassDB::bind_method(D_METHOD("has_capture", "name"), &EngineDebugger::has_capture);
  1453. ClassDB::bind_method(D_METHOD("send_message", "message", "data"), &EngineDebugger::send_message);
  1454. }
  1455. } // namespace core_bind