core_bind.cpp 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876
  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. bool OS::is_sandboxed() const {
  362. return ::OS::get_singleton()->is_sandboxed();
  363. }
  364. uint64_t OS::get_static_memory_usage() const {
  365. return ::OS::get_singleton()->get_static_memory_usage();
  366. }
  367. uint64_t OS::get_static_memory_peak_usage() const {
  368. return ::OS::get_singleton()->get_static_memory_peak_usage();
  369. }
  370. Dictionary OS::get_memory_info() const {
  371. return ::OS::get_singleton()->get_memory_info();
  372. }
  373. /** This method uses a signed argument for better error reporting as it's used from the scripting API. */
  374. void OS::delay_usec(int p_usec) const {
  375. ERR_FAIL_COND_MSG(
  376. p_usec < 0,
  377. vformat("Can't sleep for %d microseconds. The delay provided must be greater than or equal to 0 microseconds.", p_usec));
  378. ::OS::get_singleton()->delay_usec(p_usec);
  379. }
  380. /** This method uses a signed argument for better error reporting as it's used from the scripting API. */
  381. void OS::delay_msec(int p_msec) const {
  382. ERR_FAIL_COND_MSG(
  383. p_msec < 0,
  384. vformat("Can't sleep for %d milliseconds. The delay provided must be greater than or equal to 0 milliseconds.", p_msec));
  385. ::OS::get_singleton()->delay_usec(int64_t(p_msec) * 1000);
  386. }
  387. bool OS::is_userfs_persistent() const {
  388. return ::OS::get_singleton()->is_userfs_persistent();
  389. }
  390. int OS::get_processor_count() const {
  391. return ::OS::get_singleton()->get_processor_count();
  392. }
  393. String OS::get_processor_name() const {
  394. return ::OS::get_singleton()->get_processor_name();
  395. }
  396. bool OS::is_stdout_verbose() const {
  397. return ::OS::get_singleton()->is_stdout_verbose();
  398. }
  399. Error OS::move_to_trash(const String &p_path) const {
  400. return ::OS::get_singleton()->move_to_trash(p_path);
  401. }
  402. String OS::get_user_data_dir() const {
  403. return ::OS::get_singleton()->get_user_data_dir();
  404. }
  405. String OS::get_config_dir() const {
  406. // Exposed as `get_config_dir()` instead of `get_config_path()` for consistency with other exposed OS methods.
  407. return ::OS::get_singleton()->get_config_path();
  408. }
  409. String OS::get_data_dir() const {
  410. // Exposed as `get_data_dir()` instead of `get_data_path()` for consistency with other exposed OS methods.
  411. return ::OS::get_singleton()->get_data_path();
  412. }
  413. String OS::get_cache_dir() const {
  414. // Exposed as `get_cache_dir()` instead of `get_cache_path()` for consistency with other exposed OS methods.
  415. return ::OS::get_singleton()->get_cache_path();
  416. }
  417. bool OS::is_debug_build() const {
  418. #ifdef DEBUG_ENABLED
  419. return true;
  420. #else
  421. return false;
  422. #endif
  423. }
  424. String OS::get_system_dir(SystemDir p_dir, bool p_shared_storage) const {
  425. return ::OS::get_singleton()->get_system_dir(::OS::SystemDir(p_dir), p_shared_storage);
  426. }
  427. String OS::get_keycode_string(Key p_code) const {
  428. return ::keycode_get_string(p_code);
  429. }
  430. bool OS::is_keycode_unicode(char32_t p_unicode) const {
  431. return ::keycode_has_unicode((Key)p_unicode);
  432. }
  433. Key OS::find_keycode_from_string(const String &p_code) const {
  434. return find_keycode(p_code);
  435. }
  436. bool OS::request_permission(const String &p_name) {
  437. return ::OS::get_singleton()->request_permission(p_name);
  438. }
  439. bool OS::request_permissions() {
  440. return ::OS::get_singleton()->request_permissions();
  441. }
  442. Vector<String> OS::get_granted_permissions() const {
  443. return ::OS::get_singleton()->get_granted_permissions();
  444. }
  445. void OS::revoke_granted_permissions() {
  446. ::OS::get_singleton()->revoke_granted_permissions();
  447. }
  448. String OS::get_unique_id() const {
  449. return ::OS::get_singleton()->get_unique_id();
  450. }
  451. OS *OS::singleton = nullptr;
  452. void OS::_bind_methods() {
  453. ClassDB::bind_method(D_METHOD("get_connected_midi_inputs"), &OS::get_connected_midi_inputs);
  454. ClassDB::bind_method(D_METHOD("open_midi_inputs"), &OS::open_midi_inputs);
  455. ClassDB::bind_method(D_METHOD("close_midi_inputs"), &OS::close_midi_inputs);
  456. ClassDB::bind_method(D_METHOD("alert", "text", "title"), &OS::alert, DEFVAL("Alert!"));
  457. ClassDB::bind_method(D_METHOD("crash", "message"), &OS::crash);
  458. ClassDB::bind_method(D_METHOD("set_low_processor_usage_mode", "enable"), &OS::set_low_processor_usage_mode);
  459. ClassDB::bind_method(D_METHOD("is_in_low_processor_usage_mode"), &OS::is_in_low_processor_usage_mode);
  460. ClassDB::bind_method(D_METHOD("set_low_processor_usage_mode_sleep_usec", "usec"), &OS::set_low_processor_usage_mode_sleep_usec);
  461. ClassDB::bind_method(D_METHOD("get_low_processor_usage_mode_sleep_usec"), &OS::get_low_processor_usage_mode_sleep_usec);
  462. ClassDB::bind_method(D_METHOD("set_delta_smoothing", "delta_smoothing_enabled"), &OS::set_delta_smoothing);
  463. ClassDB::bind_method(D_METHOD("is_delta_smoothing_enabled"), &OS::is_delta_smoothing_enabled);
  464. ClassDB::bind_method(D_METHOD("get_processor_count"), &OS::get_processor_count);
  465. ClassDB::bind_method(D_METHOD("get_processor_name"), &OS::get_processor_name);
  466. ClassDB::bind_method(D_METHOD("get_system_fonts"), &OS::get_system_fonts);
  467. 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));
  468. 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));
  469. ClassDB::bind_method(D_METHOD("get_executable_path"), &OS::get_executable_path);
  470. ClassDB::bind_method(D_METHOD("read_string_from_stdin"), &OS::read_string_from_stdin);
  471. ClassDB::bind_method(D_METHOD("execute", "path", "arguments", "output", "read_stderr", "open_console"), &OS::execute, DEFVAL(Array()), DEFVAL(false), DEFVAL(false));
  472. ClassDB::bind_method(D_METHOD("create_process", "path", "arguments", "open_console"), &OS::create_process, DEFVAL(false));
  473. ClassDB::bind_method(D_METHOD("create_instance", "arguments"), &OS::create_instance);
  474. ClassDB::bind_method(D_METHOD("kill", "pid"), &OS::kill);
  475. ClassDB::bind_method(D_METHOD("shell_open", "uri"), &OS::shell_open);
  476. ClassDB::bind_method(D_METHOD("shell_show_in_file_manager", "file_or_dir_path", "open_folder"), &OS::shell_show_in_file_manager, DEFVAL(true));
  477. ClassDB::bind_method(D_METHOD("is_process_running", "pid"), &OS::is_process_running);
  478. ClassDB::bind_method(D_METHOD("get_process_id"), &OS::get_process_id);
  479. ClassDB::bind_method(D_METHOD("has_environment", "variable"), &OS::has_environment);
  480. ClassDB::bind_method(D_METHOD("get_environment", "variable"), &OS::get_environment);
  481. ClassDB::bind_method(D_METHOD("set_environment", "variable", "value"), &OS::set_environment);
  482. ClassDB::bind_method(D_METHOD("unset_environment", "variable"), &OS::unset_environment);
  483. ClassDB::bind_method(D_METHOD("get_name"), &OS::get_name);
  484. ClassDB::bind_method(D_METHOD("get_distribution_name"), &OS::get_distribution_name);
  485. ClassDB::bind_method(D_METHOD("get_version"), &OS::get_version);
  486. ClassDB::bind_method(D_METHOD("get_cmdline_args"), &OS::get_cmdline_args);
  487. ClassDB::bind_method(D_METHOD("get_cmdline_user_args"), &OS::get_cmdline_user_args);
  488. ClassDB::bind_method(D_METHOD("get_video_adapter_driver_info"), &OS::get_video_adapter_driver_info);
  489. ClassDB::bind_method(D_METHOD("set_restart_on_exit", "restart", "arguments"), &OS::set_restart_on_exit, DEFVAL(Vector<String>()));
  490. ClassDB::bind_method(D_METHOD("is_restart_on_exit_set"), &OS::is_restart_on_exit_set);
  491. ClassDB::bind_method(D_METHOD("get_restart_on_exit_arguments"), &OS::get_restart_on_exit_arguments);
  492. ClassDB::bind_method(D_METHOD("delay_usec", "usec"), &OS::delay_usec);
  493. ClassDB::bind_method(D_METHOD("delay_msec", "msec"), &OS::delay_msec);
  494. ClassDB::bind_method(D_METHOD("get_locale"), &OS::get_locale);
  495. ClassDB::bind_method(D_METHOD("get_locale_language"), &OS::get_locale_language);
  496. ClassDB::bind_method(D_METHOD("get_model_name"), &OS::get_model_name);
  497. ClassDB::bind_method(D_METHOD("is_userfs_persistent"), &OS::is_userfs_persistent);
  498. ClassDB::bind_method(D_METHOD("is_stdout_verbose"), &OS::is_stdout_verbose);
  499. ClassDB::bind_method(D_METHOD("is_debug_build"), &OS::is_debug_build);
  500. ClassDB::bind_method(D_METHOD("get_static_memory_usage"), &OS::get_static_memory_usage);
  501. ClassDB::bind_method(D_METHOD("get_static_memory_peak_usage"), &OS::get_static_memory_peak_usage);
  502. ClassDB::bind_method(D_METHOD("get_memory_info"), &OS::get_memory_info);
  503. ClassDB::bind_method(D_METHOD("move_to_trash", "path"), &OS::move_to_trash);
  504. ClassDB::bind_method(D_METHOD("get_user_data_dir"), &OS::get_user_data_dir);
  505. ClassDB::bind_method(D_METHOD("get_system_dir", "dir", "shared_storage"), &OS::get_system_dir, DEFVAL(true));
  506. ClassDB::bind_method(D_METHOD("get_config_dir"), &OS::get_config_dir);
  507. ClassDB::bind_method(D_METHOD("get_data_dir"), &OS::get_data_dir);
  508. ClassDB::bind_method(D_METHOD("get_cache_dir"), &OS::get_cache_dir);
  509. ClassDB::bind_method(D_METHOD("get_unique_id"), &OS::get_unique_id);
  510. ClassDB::bind_method(D_METHOD("get_keycode_string", "code"), &OS::get_keycode_string);
  511. ClassDB::bind_method(D_METHOD("is_keycode_unicode", "code"), &OS::is_keycode_unicode);
  512. ClassDB::bind_method(D_METHOD("find_keycode_from_string", "string"), &OS::find_keycode_from_string);
  513. ClassDB::bind_method(D_METHOD("set_use_file_access_save_and_swap", "enabled"), &OS::set_use_file_access_save_and_swap);
  514. ClassDB::bind_method(D_METHOD("set_thread_name", "name"), &OS::set_thread_name);
  515. ClassDB::bind_method(D_METHOD("get_thread_caller_id"), &OS::get_thread_caller_id);
  516. ClassDB::bind_method(D_METHOD("get_main_thread_id"), &OS::get_main_thread_id);
  517. ClassDB::bind_method(D_METHOD("has_feature", "tag_name"), &OS::has_feature);
  518. ClassDB::bind_method(D_METHOD("is_sandboxed"), &OS::is_sandboxed);
  519. ClassDB::bind_method(D_METHOD("request_permission", "name"), &OS::request_permission);
  520. ClassDB::bind_method(D_METHOD("request_permissions"), &OS::request_permissions);
  521. ClassDB::bind_method(D_METHOD("get_granted_permissions"), &OS::get_granted_permissions);
  522. ClassDB::bind_method(D_METHOD("revoke_granted_permissions"), &OS::revoke_granted_permissions);
  523. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "low_processor_usage_mode"), "set_low_processor_usage_mode", "is_in_low_processor_usage_mode");
  524. 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");
  525. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "delta_smoothing"), "set_delta_smoothing", "is_delta_smoothing_enabled");
  526. // Those default values need to be specified for the docs generator,
  527. // to avoid using values from the documentation writer's own OS instance.
  528. ADD_PROPERTY_DEFAULT("low_processor_usage_mode", false);
  529. ADD_PROPERTY_DEFAULT("low_processor_usage_mode_sleep_usec", 6900);
  530. BIND_ENUM_CONSTANT(RENDERING_DRIVER_VULKAN);
  531. BIND_ENUM_CONSTANT(RENDERING_DRIVER_OPENGL3);
  532. BIND_ENUM_CONSTANT(SYSTEM_DIR_DESKTOP);
  533. BIND_ENUM_CONSTANT(SYSTEM_DIR_DCIM);
  534. BIND_ENUM_CONSTANT(SYSTEM_DIR_DOCUMENTS);
  535. BIND_ENUM_CONSTANT(SYSTEM_DIR_DOWNLOADS);
  536. BIND_ENUM_CONSTANT(SYSTEM_DIR_MOVIES);
  537. BIND_ENUM_CONSTANT(SYSTEM_DIR_MUSIC);
  538. BIND_ENUM_CONSTANT(SYSTEM_DIR_PICTURES);
  539. BIND_ENUM_CONSTANT(SYSTEM_DIR_RINGTONES);
  540. }
  541. ////// Geometry2D //////
  542. Geometry2D *Geometry2D::singleton = nullptr;
  543. Geometry2D *Geometry2D::get_singleton() {
  544. return singleton;
  545. }
  546. bool Geometry2D::is_point_in_circle(const Vector2 &p_point, const Vector2 &p_circle_pos, real_t p_circle_radius) {
  547. return ::Geometry2D::is_point_in_circle(p_point, p_circle_pos, p_circle_radius);
  548. }
  549. real_t Geometry2D::segment_intersects_circle(const Vector2 &p_from, const Vector2 &p_to, const Vector2 &p_circle_pos, real_t p_circle_radius) {
  550. return ::Geometry2D::segment_intersects_circle(p_from, p_to, p_circle_pos, p_circle_radius);
  551. }
  552. 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) {
  553. Vector2 result;
  554. if (::Geometry2D::segment_intersects_segment(p_from_a, p_to_a, p_from_b, p_to_b, &result)) {
  555. return result;
  556. } else {
  557. return Variant();
  558. }
  559. }
  560. 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) {
  561. Vector2 result;
  562. if (::Geometry2D::line_intersects_line(p_from_a, p_dir_a, p_from_b, p_dir_b, result)) {
  563. return result;
  564. } else {
  565. return Variant();
  566. }
  567. }
  568. Vector<Vector2> Geometry2D::get_closest_points_between_segments(const Vector2 &p1, const Vector2 &q1, const Vector2 &p2, const Vector2 &q2) {
  569. Vector2 r1, r2;
  570. ::Geometry2D::get_closest_points_between_segments(p1, q1, p2, q2, r1, r2);
  571. Vector<Vector2> r = { r1, r2 };
  572. return r;
  573. }
  574. Vector2 Geometry2D::get_closest_point_to_segment(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b) {
  575. Vector2 s[2] = { p_a, p_b };
  576. return ::Geometry2D::get_closest_point_to_segment(p_point, s);
  577. }
  578. Vector2 Geometry2D::get_closest_point_to_segment_uncapped(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b) {
  579. Vector2 s[2] = { p_a, p_b };
  580. return ::Geometry2D::get_closest_point_to_segment_uncapped(p_point, s);
  581. }
  582. bool Geometry2D::point_is_inside_triangle(const Vector2 &s, const Vector2 &a, const Vector2 &b, const Vector2 &c) const {
  583. return ::Geometry2D::is_point_in_triangle(s, a, b, c);
  584. }
  585. bool Geometry2D::is_polygon_clockwise(const Vector<Vector2> &p_polygon) {
  586. return ::Geometry2D::is_polygon_clockwise(p_polygon);
  587. }
  588. bool Geometry2D::is_point_in_polygon(const Point2 &p_point, const Vector<Vector2> &p_polygon) {
  589. return ::Geometry2D::is_point_in_polygon(p_point, p_polygon);
  590. }
  591. Vector<int> Geometry2D::triangulate_polygon(const Vector<Vector2> &p_polygon) {
  592. return ::Geometry2D::triangulate_polygon(p_polygon);
  593. }
  594. Vector<int> Geometry2D::triangulate_delaunay(const Vector<Vector2> &p_points) {
  595. return ::Geometry2D::triangulate_delaunay(p_points);
  596. }
  597. Vector<Point2> Geometry2D::convex_hull(const Vector<Point2> &p_points) {
  598. return ::Geometry2D::convex_hull(p_points);
  599. }
  600. TypedArray<PackedVector2Array> Geometry2D::decompose_polygon_in_convex(const Vector<Vector2> &p_polygon) {
  601. Vector<Vector<Point2>> decomp = ::Geometry2D::decompose_polygon_in_convex(p_polygon);
  602. TypedArray<PackedVector2Array> ret;
  603. for (int i = 0; i < decomp.size(); ++i) {
  604. ret.push_back(decomp[i]);
  605. }
  606. return ret;
  607. }
  608. TypedArray<PackedVector2Array> Geometry2D::merge_polygons(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
  609. Vector<Vector<Point2>> polys = ::Geometry2D::merge_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::clip_polygons(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
  617. Vector<Vector<Point2>> polys = ::Geometry2D::clip_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::intersect_polygons(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
  625. Vector<Vector<Point2>> polys = ::Geometry2D::intersect_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::exclude_polygons(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
  633. Vector<Vector<Point2>> polys = ::Geometry2D::exclude_polygons(p_polygon_a, p_polygon_b);
  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::clip_polyline_with_polygon(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) {
  641. Vector<Vector<Point2>> polys = ::Geometry2D::clip_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::intersect_polyline_with_polygon(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) {
  649. Vector<Vector<Point2>> polys = ::Geometry2D::intersect_polyline_with_polygon(p_polyline, p_polygon);
  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_polygon(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type) {
  657. Vector<Vector<Point2>> polys = ::Geometry2D::offset_polygon(p_polygon, p_delta, ::Geometry2D::PolyJoinType(p_join_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. TypedArray<PackedVector2Array> Geometry2D::offset_polyline(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type, PolyEndType p_end_type) {
  665. Vector<Vector<Point2>> polys = ::Geometry2D::offset_polyline(p_polygon, p_delta, ::Geometry2D::PolyJoinType(p_join_type), ::Geometry2D::PolyEndType(p_end_type));
  666. TypedArray<PackedVector2Array> ret;
  667. for (int i = 0; i < polys.size(); ++i) {
  668. ret.push_back(polys[i]);
  669. }
  670. return ret;
  671. }
  672. Dictionary Geometry2D::make_atlas(const Vector<Size2> &p_rects) {
  673. Dictionary ret;
  674. Vector<Size2i> rects;
  675. for (int i = 0; i < p_rects.size(); i++) {
  676. rects.push_back(p_rects[i]);
  677. }
  678. Vector<Point2i> result;
  679. Size2i size;
  680. ::Geometry2D::make_atlas(rects, result, size);
  681. Vector<Point2> r_result;
  682. for (int i = 0; i < result.size(); i++) {
  683. r_result.push_back(result[i]);
  684. }
  685. ret["points"] = r_result;
  686. ret["size"] = size;
  687. return ret;
  688. }
  689. void Geometry2D::_bind_methods() {
  690. ClassDB::bind_method(D_METHOD("is_point_in_circle", "point", "circle_position", "circle_radius"), &Geometry2D::is_point_in_circle);
  691. ClassDB::bind_method(D_METHOD("segment_intersects_circle", "segment_from", "segment_to", "circle_position", "circle_radius"), &Geometry2D::segment_intersects_circle);
  692. ClassDB::bind_method(D_METHOD("segment_intersects_segment", "from_a", "to_a", "from_b", "to_b"), &Geometry2D::segment_intersects_segment);
  693. ClassDB::bind_method(D_METHOD("line_intersects_line", "from_a", "dir_a", "from_b", "dir_b"), &Geometry2D::line_intersects_line);
  694. ClassDB::bind_method(D_METHOD("get_closest_points_between_segments", "p1", "q1", "p2", "q2"), &Geometry2D::get_closest_points_between_segments);
  695. ClassDB::bind_method(D_METHOD("get_closest_point_to_segment", "point", "s1", "s2"), &Geometry2D::get_closest_point_to_segment);
  696. ClassDB::bind_method(D_METHOD("get_closest_point_to_segment_uncapped", "point", "s1", "s2"), &Geometry2D::get_closest_point_to_segment_uncapped);
  697. ClassDB::bind_method(D_METHOD("point_is_inside_triangle", "point", "a", "b", "c"), &Geometry2D::point_is_inside_triangle);
  698. ClassDB::bind_method(D_METHOD("is_polygon_clockwise", "polygon"), &Geometry2D::is_polygon_clockwise);
  699. ClassDB::bind_method(D_METHOD("is_point_in_polygon", "point", "polygon"), &Geometry2D::is_point_in_polygon);
  700. ClassDB::bind_method(D_METHOD("triangulate_polygon", "polygon"), &Geometry2D::triangulate_polygon);
  701. ClassDB::bind_method(D_METHOD("triangulate_delaunay", "points"), &Geometry2D::triangulate_delaunay);
  702. ClassDB::bind_method(D_METHOD("convex_hull", "points"), &Geometry2D::convex_hull);
  703. ClassDB::bind_method(D_METHOD("decompose_polygon_in_convex", "polygon"), &Geometry2D::decompose_polygon_in_convex);
  704. ClassDB::bind_method(D_METHOD("merge_polygons", "polygon_a", "polygon_b"), &Geometry2D::merge_polygons);
  705. ClassDB::bind_method(D_METHOD("clip_polygons", "polygon_a", "polygon_b"), &Geometry2D::clip_polygons);
  706. ClassDB::bind_method(D_METHOD("intersect_polygons", "polygon_a", "polygon_b"), &Geometry2D::intersect_polygons);
  707. ClassDB::bind_method(D_METHOD("exclude_polygons", "polygon_a", "polygon_b"), &Geometry2D::exclude_polygons);
  708. ClassDB::bind_method(D_METHOD("clip_polyline_with_polygon", "polyline", "polygon"), &Geometry2D::clip_polyline_with_polygon);
  709. ClassDB::bind_method(D_METHOD("intersect_polyline_with_polygon", "polyline", "polygon"), &Geometry2D::intersect_polyline_with_polygon);
  710. ClassDB::bind_method(D_METHOD("offset_polygon", "polygon", "delta", "join_type"), &Geometry2D::offset_polygon, DEFVAL(JOIN_SQUARE));
  711. ClassDB::bind_method(D_METHOD("offset_polyline", "polyline", "delta", "join_type", "end_type"), &Geometry2D::offset_polyline, DEFVAL(JOIN_SQUARE), DEFVAL(END_SQUARE));
  712. ClassDB::bind_method(D_METHOD("make_atlas", "sizes"), &Geometry2D::make_atlas);
  713. BIND_ENUM_CONSTANT(OPERATION_UNION);
  714. BIND_ENUM_CONSTANT(OPERATION_DIFFERENCE);
  715. BIND_ENUM_CONSTANT(OPERATION_INTERSECTION);
  716. BIND_ENUM_CONSTANT(OPERATION_XOR);
  717. BIND_ENUM_CONSTANT(JOIN_SQUARE);
  718. BIND_ENUM_CONSTANT(JOIN_ROUND);
  719. BIND_ENUM_CONSTANT(JOIN_MITER);
  720. BIND_ENUM_CONSTANT(END_POLYGON);
  721. BIND_ENUM_CONSTANT(END_JOINED);
  722. BIND_ENUM_CONSTANT(END_BUTT);
  723. BIND_ENUM_CONSTANT(END_SQUARE);
  724. BIND_ENUM_CONSTANT(END_ROUND);
  725. }
  726. ////// Geometry3D //////
  727. Geometry3D *Geometry3D::singleton = nullptr;
  728. Geometry3D *Geometry3D::get_singleton() {
  729. return singleton;
  730. }
  731. TypedArray<Plane> Geometry3D::build_box_planes(const Vector3 &p_extents) {
  732. Variant ret = ::Geometry3D::build_box_planes(p_extents);
  733. return ret;
  734. }
  735. TypedArray<Plane> Geometry3D::build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis) {
  736. Variant ret = ::Geometry3D::build_cylinder_planes(p_radius, p_height, p_sides, p_axis);
  737. return ret;
  738. }
  739. TypedArray<Plane> Geometry3D::build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis) {
  740. Variant ret = ::Geometry3D::build_capsule_planes(p_radius, p_height, p_sides, p_lats, p_axis);
  741. return ret;
  742. }
  743. Vector<Vector3> Geometry3D::get_closest_points_between_segments(const Vector3 &p1, const Vector3 &p2, const Vector3 &q1, const Vector3 &q2) {
  744. Vector3 r1, r2;
  745. ::Geometry3D::get_closest_points_between_segments(p1, p2, q1, q2, r1, r2);
  746. Vector<Vector3> r = { r1, r2 };
  747. return r;
  748. }
  749. Vector3 Geometry3D::get_closest_point_to_segment(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b) {
  750. Vector3 s[2] = { p_a, p_b };
  751. return ::Geometry3D::get_closest_point_to_segment(p_point, s);
  752. }
  753. Vector3 Geometry3D::get_closest_point_to_segment_uncapped(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b) {
  754. Vector3 s[2] = { p_a, p_b };
  755. return ::Geometry3D::get_closest_point_to_segment_uncapped(p_point, s);
  756. }
  757. Vector3 Geometry3D::get_triangle_barycentric_coords(const Vector3 &p_point, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2) {
  758. Vector3 res = ::Geometry3D::triangle_get_barycentric_coords(p_v0, p_v1, p_v2, p_point);
  759. return res;
  760. }
  761. 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) {
  762. Vector3 res;
  763. if (::Geometry3D::ray_intersects_triangle(p_from, p_dir, p_v0, p_v1, p_v2, &res)) {
  764. return res;
  765. } else {
  766. return Variant();
  767. }
  768. }
  769. 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) {
  770. Vector3 res;
  771. if (::Geometry3D::segment_intersects_triangle(p_from, p_to, p_v0, p_v1, p_v2, &res)) {
  772. return res;
  773. } else {
  774. return Variant();
  775. }
  776. }
  777. Vector<Vector3> Geometry3D::segment_intersects_sphere(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_sphere_pos, real_t p_sphere_radius) {
  778. Vector<Vector3> r;
  779. Vector3 res, norm;
  780. if (!::Geometry3D::segment_intersects_sphere(p_from, p_to, p_sphere_pos, p_sphere_radius, &res, &norm)) {
  781. return r;
  782. }
  783. r.resize(2);
  784. r.set(0, res);
  785. r.set(1, norm);
  786. return r;
  787. }
  788. Vector<Vector3> Geometry3D::segment_intersects_cylinder(const Vector3 &p_from, const Vector3 &p_to, float p_height, float p_radius) {
  789. Vector<Vector3> r;
  790. Vector3 res, norm;
  791. if (!::Geometry3D::segment_intersects_cylinder(p_from, p_to, p_height, p_radius, &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::segment_intersects_convex(const Vector3 &p_from, const Vector3 &p_to, const TypedArray<Plane> &p_planes) {
  800. Vector<Vector3> r;
  801. Vector3 res, norm;
  802. Vector<Plane> planes = Variant(p_planes);
  803. if (!::Geometry3D::segment_intersects_convex(p_from, p_to, planes.ptr(), planes.size(), &res, &norm)) {
  804. return r;
  805. }
  806. r.resize(2);
  807. r.set(0, res);
  808. r.set(1, norm);
  809. return r;
  810. }
  811. Vector<Vector3> Geometry3D::clip_polygon(const Vector<Vector3> &p_points, const Plane &p_plane) {
  812. return ::Geometry3D::clip_polygon(p_points, p_plane);
  813. }
  814. void Geometry3D::_bind_methods() {
  815. ClassDB::bind_method(D_METHOD("build_box_planes", "extents"), &Geometry3D::build_box_planes);
  816. ClassDB::bind_method(D_METHOD("build_cylinder_planes", "radius", "height", "sides", "axis"), &Geometry3D::build_cylinder_planes, DEFVAL(Vector3::AXIS_Z));
  817. ClassDB::bind_method(D_METHOD("build_capsule_planes", "radius", "height", "sides", "lats", "axis"), &Geometry3D::build_capsule_planes, DEFVAL(Vector3::AXIS_Z));
  818. ClassDB::bind_method(D_METHOD("get_closest_points_between_segments", "p1", "p2", "q1", "q2"), &Geometry3D::get_closest_points_between_segments);
  819. ClassDB::bind_method(D_METHOD("get_closest_point_to_segment", "point", "s1", "s2"), &Geometry3D::get_closest_point_to_segment);
  820. ClassDB::bind_method(D_METHOD("get_closest_point_to_segment_uncapped", "point", "s1", "s2"), &Geometry3D::get_closest_point_to_segment_uncapped);
  821. ClassDB::bind_method(D_METHOD("get_triangle_barycentric_coords", "point", "a", "b", "c"), &Geometry3D::get_triangle_barycentric_coords);
  822. ClassDB::bind_method(D_METHOD("ray_intersects_triangle", "from", "dir", "a", "b", "c"), &Geometry3D::ray_intersects_triangle);
  823. ClassDB::bind_method(D_METHOD("segment_intersects_triangle", "from", "to", "a", "b", "c"), &Geometry3D::segment_intersects_triangle);
  824. ClassDB::bind_method(D_METHOD("segment_intersects_sphere", "from", "to", "sphere_position", "sphere_radius"), &Geometry3D::segment_intersects_sphere);
  825. ClassDB::bind_method(D_METHOD("segment_intersects_cylinder", "from", "to", "height", "radius"), &Geometry3D::segment_intersects_cylinder);
  826. ClassDB::bind_method(D_METHOD("segment_intersects_convex", "from", "to", "planes"), &Geometry3D::segment_intersects_convex);
  827. ClassDB::bind_method(D_METHOD("clip_polygon", "points", "plane"), &Geometry3D::clip_polygon);
  828. }
  829. ////// Marshalls //////
  830. Marshalls *Marshalls::singleton = nullptr;
  831. Marshalls *Marshalls::get_singleton() {
  832. return singleton;
  833. }
  834. String Marshalls::variant_to_base64(const Variant &p_var, bool p_full_objects) {
  835. int len;
  836. Error err = encode_variant(p_var, nullptr, len, p_full_objects);
  837. ERR_FAIL_COND_V_MSG(err != OK, "", "Error when trying to encode Variant.");
  838. Vector<uint8_t> buff;
  839. buff.resize(len);
  840. uint8_t *w = buff.ptrw();
  841. err = encode_variant(p_var, &w[0], len, p_full_objects);
  842. ERR_FAIL_COND_V_MSG(err != OK, "", "Error when trying to encode Variant.");
  843. String ret = CryptoCore::b64_encode_str(&w[0], len);
  844. ERR_FAIL_COND_V(ret.is_empty(), ret);
  845. return ret;
  846. }
  847. Variant Marshalls::base64_to_variant(const String &p_str, bool p_allow_objects) {
  848. int strlen = p_str.length();
  849. CharString cstr = p_str.ascii();
  850. Vector<uint8_t> buf;
  851. buf.resize(strlen / 4 * 3 + 1);
  852. uint8_t *w = buf.ptrw();
  853. size_t len = 0;
  854. ERR_FAIL_COND_V(CryptoCore::b64_decode(&w[0], buf.size(), &len, (unsigned char *)cstr.get_data(), strlen) != OK, Variant());
  855. Variant v;
  856. Error err = decode_variant(v, &w[0], len, nullptr, p_allow_objects);
  857. ERR_FAIL_COND_V_MSG(err != OK, Variant(), "Error when trying to decode Variant.");
  858. return v;
  859. }
  860. String Marshalls::raw_to_base64(const Vector<uint8_t> &p_arr) {
  861. String ret = CryptoCore::b64_encode_str(p_arr.ptr(), p_arr.size());
  862. ERR_FAIL_COND_V(ret.is_empty(), ret);
  863. return ret;
  864. }
  865. Vector<uint8_t> Marshalls::base64_to_raw(const String &p_str) {
  866. int strlen = p_str.length();
  867. CharString cstr = p_str.ascii();
  868. size_t arr_len = 0;
  869. Vector<uint8_t> buf;
  870. {
  871. buf.resize(strlen / 4 * 3 + 1);
  872. uint8_t *w = buf.ptrw();
  873. ERR_FAIL_COND_V(CryptoCore::b64_decode(&w[0], buf.size(), &arr_len, (unsigned char *)cstr.get_data(), strlen) != OK, Vector<uint8_t>());
  874. }
  875. buf.resize(arr_len);
  876. return buf;
  877. }
  878. String Marshalls::utf8_to_base64(const String &p_str) {
  879. CharString cstr = p_str.utf8();
  880. String ret = CryptoCore::b64_encode_str((unsigned char *)cstr.get_data(), cstr.length());
  881. ERR_FAIL_COND_V(ret.is_empty(), ret);
  882. return ret;
  883. }
  884. String Marshalls::base64_to_utf8(const String &p_str) {
  885. int strlen = p_str.length();
  886. CharString cstr = p_str.ascii();
  887. Vector<uint8_t> buf;
  888. buf.resize(strlen / 4 * 3 + 1 + 1);
  889. uint8_t *w = buf.ptrw();
  890. size_t len = 0;
  891. ERR_FAIL_COND_V(CryptoCore::b64_decode(&w[0], buf.size(), &len, (unsigned char *)cstr.get_data(), strlen) != OK, String());
  892. w[len] = 0;
  893. String ret = String::utf8((char *)&w[0]);
  894. return ret;
  895. }
  896. void Marshalls::_bind_methods() {
  897. ClassDB::bind_method(D_METHOD("variant_to_base64", "variant", "full_objects"), &Marshalls::variant_to_base64, DEFVAL(false));
  898. ClassDB::bind_method(D_METHOD("base64_to_variant", "base64_str", "allow_objects"), &Marshalls::base64_to_variant, DEFVAL(false));
  899. ClassDB::bind_method(D_METHOD("raw_to_base64", "array"), &Marshalls::raw_to_base64);
  900. ClassDB::bind_method(D_METHOD("base64_to_raw", "base64_str"), &Marshalls::base64_to_raw);
  901. ClassDB::bind_method(D_METHOD("utf8_to_base64", "utf8_str"), &Marshalls::utf8_to_base64);
  902. ClassDB::bind_method(D_METHOD("base64_to_utf8", "base64_str"), &Marshalls::base64_to_utf8);
  903. }
  904. ////// Semaphore //////
  905. void Semaphore::wait() {
  906. semaphore.wait();
  907. }
  908. bool Semaphore::try_wait() {
  909. return semaphore.try_wait();
  910. }
  911. void Semaphore::post() {
  912. semaphore.post();
  913. }
  914. void Semaphore::_bind_methods() {
  915. ClassDB::bind_method(D_METHOD("wait"), &Semaphore::wait);
  916. ClassDB::bind_method(D_METHOD("try_wait"), &Semaphore::try_wait);
  917. ClassDB::bind_method(D_METHOD("post"), &Semaphore::post);
  918. }
  919. ////// Mutex //////
  920. void Mutex::lock() {
  921. mutex.lock();
  922. }
  923. bool Mutex::try_lock() {
  924. return mutex.try_lock();
  925. }
  926. void Mutex::unlock() {
  927. mutex.unlock();
  928. }
  929. void Mutex::_bind_methods() {
  930. ClassDB::bind_method(D_METHOD("lock"), &Mutex::lock);
  931. ClassDB::bind_method(D_METHOD("try_lock"), &Mutex::try_lock);
  932. ClassDB::bind_method(D_METHOD("unlock"), &Mutex::unlock);
  933. }
  934. ////// Thread //////
  935. void Thread::_start_func(void *ud) {
  936. Ref<Thread> *tud = (Ref<Thread> *)ud;
  937. Ref<Thread> t = *tud;
  938. memdelete(tud);
  939. Object *target_instance = t->target_callable.get_object();
  940. if (!target_instance) {
  941. t->running.clear();
  942. 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()));
  943. }
  944. // Finding out a suitable name for the thread can involve querying a node, if the target is one.
  945. // We know this is safe (unless the user is causing life cycle race conditions, which would be a bug on their part).
  946. set_current_thread_safe_for_nodes(true);
  947. String func_name = t->target_callable.is_custom() ? t->target_callable.get_custom()->get_as_text() : String(t->target_callable.get_method());
  948. set_current_thread_safe_for_nodes(false);
  949. ::Thread::set_name(func_name);
  950. // To avoid a circular reference between the thread and the script which can possibly contain a reference
  951. // to the thread, we will do the call (keeping a reference up to that point) and then break chains with it.
  952. // When the call returns, we will reference the thread again if possible.
  953. ObjectID th_instance_id = t->get_instance_id();
  954. Callable target_callable = t->target_callable;
  955. t = Ref<Thread>();
  956. Callable::CallError ce;
  957. Variant ret;
  958. target_callable.callp(nullptr, 0, ret, ce);
  959. // If script properly kept a reference to the thread, we should be able to re-reference it now
  960. // (well, or if the call failed, since we had to break chains anyway because the outcome isn't known upfront).
  961. t = Ref<Thread>(ObjectDB::get_instance(th_instance_id));
  962. if (t.is_valid()) {
  963. t->ret = ret;
  964. t->running.clear();
  965. } else {
  966. // We could print a warning here, but the Thread object will be eventually destroyed
  967. // noticing wait_to_finish() hasn't been called on it, and it will print a warning itself.
  968. }
  969. if (ce.error != Callable::CallError::CALL_OK) {
  970. 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) + ".");
  971. }
  972. }
  973. Error Thread::start(const Callable &p_callable, Priority p_priority) {
  974. ERR_FAIL_COND_V_MSG(is_started(), ERR_ALREADY_IN_USE, "Thread already started.");
  975. ERR_FAIL_COND_V(!p_callable.is_valid(), ERR_INVALID_PARAMETER);
  976. ERR_FAIL_INDEX_V(p_priority, PRIORITY_MAX, ERR_INVALID_PARAMETER);
  977. ret = Variant();
  978. target_callable = p_callable;
  979. running.set();
  980. Ref<Thread> *ud = memnew(Ref<Thread>(this));
  981. ::Thread::Settings s;
  982. s.priority = (::Thread::Priority)p_priority;
  983. thread.start(_start_func, ud, s);
  984. return OK;
  985. }
  986. String Thread::get_id() const {
  987. return itos(thread.get_id());
  988. }
  989. bool Thread::is_started() const {
  990. return thread.is_started();
  991. }
  992. bool Thread::is_alive() const {
  993. return running.is_set();
  994. }
  995. Variant Thread::wait_to_finish() {
  996. ERR_FAIL_COND_V_MSG(!is_started(), Variant(), "Thread must have been started to wait for its completion.");
  997. thread.wait_to_finish();
  998. Variant r = ret;
  999. target_callable = Callable();
  1000. return r;
  1001. }
  1002. void Thread::set_thread_safety_checks_enabled(bool p_enabled) {
  1003. ERR_FAIL_COND_MSG(::Thread::is_main_thread(), "This call is forbidden on the main thread.");
  1004. set_current_thread_safe_for_nodes(!p_enabled);
  1005. }
  1006. void Thread::_bind_methods() {
  1007. ClassDB::bind_method(D_METHOD("start", "callable", "priority"), &Thread::start, DEFVAL(PRIORITY_NORMAL));
  1008. ClassDB::bind_method(D_METHOD("get_id"), &Thread::get_id);
  1009. ClassDB::bind_method(D_METHOD("is_started"), &Thread::is_started);
  1010. ClassDB::bind_method(D_METHOD("is_alive"), &Thread::is_alive);
  1011. ClassDB::bind_method(D_METHOD("wait_to_finish"), &Thread::wait_to_finish);
  1012. ClassDB::bind_static_method("Thread", D_METHOD("set_thread_safety_checks_enabled", "enabled"), &Thread::set_thread_safety_checks_enabled);
  1013. BIND_ENUM_CONSTANT(PRIORITY_LOW);
  1014. BIND_ENUM_CONSTANT(PRIORITY_NORMAL);
  1015. BIND_ENUM_CONSTANT(PRIORITY_HIGH);
  1016. }
  1017. namespace special {
  1018. ////// ClassDB //////
  1019. PackedStringArray ClassDB::get_class_list() const {
  1020. List<StringName> classes;
  1021. ::ClassDB::get_class_list(&classes);
  1022. PackedStringArray ret;
  1023. ret.resize(classes.size());
  1024. int idx = 0;
  1025. for (const StringName &E : classes) {
  1026. ret.set(idx++, E);
  1027. }
  1028. return ret;
  1029. }
  1030. PackedStringArray ClassDB::get_inheriters_from_class(const StringName &p_class) const {
  1031. List<StringName> classes;
  1032. ::ClassDB::get_inheriters_from_class(p_class, &classes);
  1033. PackedStringArray ret;
  1034. ret.resize(classes.size());
  1035. int idx = 0;
  1036. for (const StringName &E : classes) {
  1037. ret.set(idx++, E);
  1038. }
  1039. return ret;
  1040. }
  1041. StringName ClassDB::get_parent_class(const StringName &p_class) const {
  1042. return ::ClassDB::get_parent_class(p_class);
  1043. }
  1044. bool ClassDB::class_exists(const StringName &p_class) const {
  1045. return ::ClassDB::class_exists(p_class);
  1046. }
  1047. bool ClassDB::is_parent_class(const StringName &p_class, const StringName &p_inherits) const {
  1048. return ::ClassDB::is_parent_class(p_class, p_inherits);
  1049. }
  1050. bool ClassDB::can_instantiate(const StringName &p_class) const {
  1051. return ::ClassDB::can_instantiate(p_class);
  1052. }
  1053. Variant ClassDB::instantiate(const StringName &p_class) const {
  1054. Object *obj = ::ClassDB::instantiate(p_class);
  1055. if (!obj) {
  1056. return Variant();
  1057. }
  1058. RefCounted *r = Object::cast_to<RefCounted>(obj);
  1059. if (r) {
  1060. return Ref<RefCounted>(r);
  1061. } else {
  1062. return obj;
  1063. }
  1064. }
  1065. bool ClassDB::class_has_signal(StringName p_class, StringName p_signal) const {
  1066. return ::ClassDB::has_signal(p_class, p_signal);
  1067. }
  1068. Dictionary ClassDB::class_get_signal(StringName p_class, StringName p_signal) const {
  1069. MethodInfo signal;
  1070. if (::ClassDB::get_signal(p_class, p_signal, &signal)) {
  1071. return signal.operator Dictionary();
  1072. } else {
  1073. return Dictionary();
  1074. }
  1075. }
  1076. TypedArray<Dictionary> ClassDB::class_get_signal_list(StringName p_class, bool p_no_inheritance) const {
  1077. List<MethodInfo> signals;
  1078. ::ClassDB::get_signal_list(p_class, &signals, p_no_inheritance);
  1079. TypedArray<Dictionary> ret;
  1080. for (const MethodInfo &E : signals) {
  1081. ret.push_back(E.operator Dictionary());
  1082. }
  1083. return ret;
  1084. }
  1085. TypedArray<Dictionary> ClassDB::class_get_property_list(StringName p_class, bool p_no_inheritance) const {
  1086. List<PropertyInfo> plist;
  1087. ::ClassDB::get_property_list(p_class, &plist, p_no_inheritance);
  1088. TypedArray<Dictionary> ret;
  1089. for (const PropertyInfo &E : plist) {
  1090. ret.push_back(E.operator Dictionary());
  1091. }
  1092. return ret;
  1093. }
  1094. Variant ClassDB::class_get_property(Object *p_object, const StringName &p_property) const {
  1095. Variant ret;
  1096. ::ClassDB::get_property(p_object, p_property, ret);
  1097. return ret;
  1098. }
  1099. Error ClassDB::class_set_property(Object *p_object, const StringName &p_property, const Variant &p_value) const {
  1100. Variant ret;
  1101. bool valid;
  1102. if (!::ClassDB::set_property(p_object, p_property, p_value, &valid)) {
  1103. return ERR_UNAVAILABLE;
  1104. } else if (!valid) {
  1105. return ERR_INVALID_DATA;
  1106. }
  1107. return OK;
  1108. }
  1109. bool ClassDB::class_has_method(StringName p_class, StringName p_method, bool p_no_inheritance) const {
  1110. return ::ClassDB::has_method(p_class, p_method, p_no_inheritance);
  1111. }
  1112. TypedArray<Dictionary> ClassDB::class_get_method_list(StringName p_class, bool p_no_inheritance) const {
  1113. List<MethodInfo> methods;
  1114. ::ClassDB::get_method_list(p_class, &methods, p_no_inheritance);
  1115. TypedArray<Dictionary> ret;
  1116. for (const MethodInfo &E : methods) {
  1117. #ifdef DEBUG_METHODS_ENABLED
  1118. ret.push_back(E.operator Dictionary());
  1119. #else
  1120. Dictionary dict;
  1121. dict["name"] = E.name;
  1122. ret.push_back(dict);
  1123. #endif
  1124. }
  1125. return ret;
  1126. }
  1127. PackedStringArray ClassDB::class_get_integer_constant_list(const StringName &p_class, bool p_no_inheritance) const {
  1128. List<String> constants;
  1129. ::ClassDB::get_integer_constant_list(p_class, &constants, p_no_inheritance);
  1130. PackedStringArray ret;
  1131. ret.resize(constants.size());
  1132. int idx = 0;
  1133. for (const String &E : constants) {
  1134. ret.set(idx++, E);
  1135. }
  1136. return ret;
  1137. }
  1138. bool ClassDB::class_has_integer_constant(const StringName &p_class, const StringName &p_name) const {
  1139. bool success;
  1140. ::ClassDB::get_integer_constant(p_class, p_name, &success);
  1141. return success;
  1142. }
  1143. int64_t ClassDB::class_get_integer_constant(const StringName &p_class, const StringName &p_name) const {
  1144. bool found;
  1145. int64_t c = ::ClassDB::get_integer_constant(p_class, p_name, &found);
  1146. ERR_FAIL_COND_V(!found, 0);
  1147. return c;
  1148. }
  1149. bool ClassDB::class_has_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance) const {
  1150. return ::ClassDB::has_enum(p_class, p_name, p_no_inheritance);
  1151. }
  1152. PackedStringArray ClassDB::class_get_enum_list(const StringName &p_class, bool p_no_inheritance) const {
  1153. List<StringName> enums;
  1154. ::ClassDB::get_enum_list(p_class, &enums, p_no_inheritance);
  1155. PackedStringArray ret;
  1156. ret.resize(enums.size());
  1157. int idx = 0;
  1158. for (const StringName &E : enums) {
  1159. ret.set(idx++, E);
  1160. }
  1161. return ret;
  1162. }
  1163. PackedStringArray ClassDB::class_get_enum_constants(const StringName &p_class, const StringName &p_enum, bool p_no_inheritance) const {
  1164. List<StringName> constants;
  1165. ::ClassDB::get_enum_constants(p_class, p_enum, &constants, p_no_inheritance);
  1166. PackedStringArray ret;
  1167. ret.resize(constants.size());
  1168. int idx = 0;
  1169. for (const StringName &E : constants) {
  1170. ret.set(idx++, E);
  1171. }
  1172. return ret;
  1173. }
  1174. StringName ClassDB::class_get_integer_constant_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance) const {
  1175. return ::ClassDB::get_integer_constant_enum(p_class, p_name, p_no_inheritance);
  1176. }
  1177. bool ClassDB::is_class_enabled(StringName p_class) const {
  1178. return ::ClassDB::is_class_enabled(p_class);
  1179. }
  1180. void ClassDB::_bind_methods() {
  1181. ::ClassDB::bind_method(D_METHOD("get_class_list"), &ClassDB::get_class_list);
  1182. ::ClassDB::bind_method(D_METHOD("get_inheriters_from_class", "class"), &ClassDB::get_inheriters_from_class);
  1183. ::ClassDB::bind_method(D_METHOD("get_parent_class", "class"), &ClassDB::get_parent_class);
  1184. ::ClassDB::bind_method(D_METHOD("class_exists", "class"), &ClassDB::class_exists);
  1185. ::ClassDB::bind_method(D_METHOD("is_parent_class", "class", "inherits"), &ClassDB::is_parent_class);
  1186. ::ClassDB::bind_method(D_METHOD("can_instantiate", "class"), &ClassDB::can_instantiate);
  1187. ::ClassDB::bind_method(D_METHOD("instantiate", "class"), &ClassDB::instantiate);
  1188. ::ClassDB::bind_method(D_METHOD("class_has_signal", "class", "signal"), &ClassDB::class_has_signal);
  1189. ::ClassDB::bind_method(D_METHOD("class_get_signal", "class", "signal"), &ClassDB::class_get_signal);
  1190. ::ClassDB::bind_method(D_METHOD("class_get_signal_list", "class", "no_inheritance"), &ClassDB::class_get_signal_list, DEFVAL(false));
  1191. ::ClassDB::bind_method(D_METHOD("class_get_property_list", "class", "no_inheritance"), &ClassDB::class_get_property_list, DEFVAL(false));
  1192. ::ClassDB::bind_method(D_METHOD("class_get_property", "object", "property"), &ClassDB::class_get_property);
  1193. ::ClassDB::bind_method(D_METHOD("class_set_property", "object", "property", "value"), &ClassDB::class_set_property);
  1194. ::ClassDB::bind_method(D_METHOD("class_has_method", "class", "method", "no_inheritance"), &ClassDB::class_has_method, DEFVAL(false));
  1195. ::ClassDB::bind_method(D_METHOD("class_get_method_list", "class", "no_inheritance"), &ClassDB::class_get_method_list, DEFVAL(false));
  1196. ::ClassDB::bind_method(D_METHOD("class_get_integer_constant_list", "class", "no_inheritance"), &ClassDB::class_get_integer_constant_list, DEFVAL(false));
  1197. ::ClassDB::bind_method(D_METHOD("class_has_integer_constant", "class", "name"), &ClassDB::class_has_integer_constant);
  1198. ::ClassDB::bind_method(D_METHOD("class_get_integer_constant", "class", "name"), &ClassDB::class_get_integer_constant);
  1199. ::ClassDB::bind_method(D_METHOD("class_has_enum", "class", "name", "no_inheritance"), &ClassDB::class_has_enum, DEFVAL(false));
  1200. ::ClassDB::bind_method(D_METHOD("class_get_enum_list", "class", "no_inheritance"), &ClassDB::class_get_enum_list, DEFVAL(false));
  1201. ::ClassDB::bind_method(D_METHOD("class_get_enum_constants", "class", "enum", "no_inheritance"), &ClassDB::class_get_enum_constants, DEFVAL(false));
  1202. ::ClassDB::bind_method(D_METHOD("class_get_integer_constant_enum", "class", "name", "no_inheritance"), &ClassDB::class_get_integer_constant_enum, DEFVAL(false));
  1203. ::ClassDB::bind_method(D_METHOD("is_class_enabled", "class"), &ClassDB::is_class_enabled);
  1204. }
  1205. } // namespace special
  1206. ////// Engine //////
  1207. void Engine::set_physics_ticks_per_second(int p_ips) {
  1208. ::Engine::get_singleton()->set_physics_ticks_per_second(p_ips);
  1209. }
  1210. int Engine::get_physics_ticks_per_second() const {
  1211. return ::Engine::get_singleton()->get_physics_ticks_per_second();
  1212. }
  1213. void Engine::set_max_physics_steps_per_frame(int p_max_physics_steps) {
  1214. ::Engine::get_singleton()->set_max_physics_steps_per_frame(p_max_physics_steps);
  1215. }
  1216. int Engine::get_max_physics_steps_per_frame() const {
  1217. return ::Engine::get_singleton()->get_max_physics_steps_per_frame();
  1218. }
  1219. void Engine::set_physics_jitter_fix(double p_threshold) {
  1220. ::Engine::get_singleton()->set_physics_jitter_fix(p_threshold);
  1221. }
  1222. double Engine::get_physics_jitter_fix() const {
  1223. return ::Engine::get_singleton()->get_physics_jitter_fix();
  1224. }
  1225. double Engine::get_physics_interpolation_fraction() const {
  1226. return ::Engine::get_singleton()->get_physics_interpolation_fraction();
  1227. }
  1228. void Engine::set_max_fps(int p_fps) {
  1229. ::Engine::get_singleton()->set_max_fps(p_fps);
  1230. }
  1231. int Engine::get_max_fps() const {
  1232. return ::Engine::get_singleton()->get_max_fps();
  1233. }
  1234. double Engine::get_frames_per_second() const {
  1235. return ::Engine::get_singleton()->get_frames_per_second();
  1236. }
  1237. uint64_t Engine::get_physics_frames() const {
  1238. return ::Engine::get_singleton()->get_physics_frames();
  1239. }
  1240. uint64_t Engine::get_process_frames() const {
  1241. return ::Engine::get_singleton()->get_process_frames();
  1242. }
  1243. void Engine::set_time_scale(double p_scale) {
  1244. ::Engine::get_singleton()->set_time_scale(p_scale);
  1245. }
  1246. double Engine::get_time_scale() {
  1247. return ::Engine::get_singleton()->get_time_scale();
  1248. }
  1249. int Engine::get_frames_drawn() {
  1250. return ::Engine::get_singleton()->get_frames_drawn();
  1251. }
  1252. MainLoop *Engine::get_main_loop() const {
  1253. // Needs to remain in OS, since it's actually OS that interacts with it, but it's better exposed here
  1254. return ::OS::get_singleton()->get_main_loop();
  1255. }
  1256. Dictionary Engine::get_version_info() const {
  1257. return ::Engine::get_singleton()->get_version_info();
  1258. }
  1259. Dictionary Engine::get_author_info() const {
  1260. return ::Engine::get_singleton()->get_author_info();
  1261. }
  1262. TypedArray<Dictionary> Engine::get_copyright_info() const {
  1263. return ::Engine::get_singleton()->get_copyright_info();
  1264. }
  1265. Dictionary Engine::get_donor_info() const {
  1266. return ::Engine::get_singleton()->get_donor_info();
  1267. }
  1268. Dictionary Engine::get_license_info() const {
  1269. return ::Engine::get_singleton()->get_license_info();
  1270. }
  1271. String Engine::get_license_text() const {
  1272. return ::Engine::get_singleton()->get_license_text();
  1273. }
  1274. String Engine::get_architecture_name() const {
  1275. return ::Engine::get_singleton()->get_architecture_name();
  1276. }
  1277. bool Engine::is_in_physics_frame() const {
  1278. return ::Engine::get_singleton()->is_in_physics_frame();
  1279. }
  1280. bool Engine::has_singleton(const StringName &p_name) const {
  1281. return ::Engine::get_singleton()->has_singleton(p_name);
  1282. }
  1283. Object *Engine::get_singleton_object(const StringName &p_name) const {
  1284. return ::Engine::get_singleton()->get_singleton_object(p_name);
  1285. }
  1286. void Engine::register_singleton(const StringName &p_name, Object *p_object) {
  1287. ERR_FAIL_COND_MSG(has_singleton(p_name), "Singleton already registered: " + String(p_name));
  1288. ERR_FAIL_COND_MSG(!String(p_name).is_valid_identifier(), "Singleton name is not a valid identifier: " + p_name);
  1289. ::Engine::Singleton s;
  1290. s.class_name = p_name;
  1291. s.name = p_name;
  1292. s.ptr = p_object;
  1293. s.user_created = true;
  1294. ::Engine::get_singleton()->add_singleton(s);
  1295. }
  1296. void Engine::unregister_singleton(const StringName &p_name) {
  1297. ERR_FAIL_COND_MSG(!has_singleton(p_name), "Attempt to remove unregistered singleton: " + String(p_name));
  1298. ERR_FAIL_COND_MSG(!::Engine::get_singleton()->is_singleton_user_created(p_name), "Attempt to remove non-user created singleton: " + String(p_name));
  1299. ::Engine::get_singleton()->remove_singleton(p_name);
  1300. }
  1301. Vector<String> Engine::get_singleton_list() const {
  1302. List<::Engine::Singleton> singletons;
  1303. ::Engine::get_singleton()->get_singletons(&singletons);
  1304. Vector<String> ret;
  1305. for (List<::Engine::Singleton>::Element *E = singletons.front(); E; E = E->next()) {
  1306. ret.push_back(E->get().name);
  1307. }
  1308. return ret;
  1309. }
  1310. Error Engine::register_script_language(ScriptLanguage *p_language) {
  1311. return ScriptServer::register_language(p_language);
  1312. }
  1313. Error Engine::unregister_script_language(const ScriptLanguage *p_language) {
  1314. return ScriptServer::unregister_language(p_language);
  1315. }
  1316. int Engine::get_script_language_count() {
  1317. return ScriptServer::get_language_count();
  1318. }
  1319. ScriptLanguage *Engine::get_script_language(int p_index) const {
  1320. return ScriptServer::get_language(p_index);
  1321. }
  1322. void Engine::set_editor_hint(bool p_enabled) {
  1323. ::Engine::get_singleton()->set_editor_hint(p_enabled);
  1324. }
  1325. bool Engine::is_editor_hint() const {
  1326. return ::Engine::get_singleton()->is_editor_hint();
  1327. }
  1328. String Engine::get_write_movie_path() const {
  1329. return ::Engine::get_singleton()->get_write_movie_path();
  1330. }
  1331. void Engine::set_print_error_messages(bool p_enabled) {
  1332. ::Engine::get_singleton()->set_print_error_messages(p_enabled);
  1333. }
  1334. bool Engine::is_printing_error_messages() const {
  1335. return ::Engine::get_singleton()->is_printing_error_messages();
  1336. }
  1337. void Engine::_bind_methods() {
  1338. ClassDB::bind_method(D_METHOD("set_physics_ticks_per_second", "physics_ticks_per_second"), &Engine::set_physics_ticks_per_second);
  1339. ClassDB::bind_method(D_METHOD("get_physics_ticks_per_second"), &Engine::get_physics_ticks_per_second);
  1340. ClassDB::bind_method(D_METHOD("set_max_physics_steps_per_frame", "max_physics_steps"), &Engine::set_max_physics_steps_per_frame);
  1341. ClassDB::bind_method(D_METHOD("get_max_physics_steps_per_frame"), &Engine::get_max_physics_steps_per_frame);
  1342. ClassDB::bind_method(D_METHOD("set_physics_jitter_fix", "physics_jitter_fix"), &Engine::set_physics_jitter_fix);
  1343. ClassDB::bind_method(D_METHOD("get_physics_jitter_fix"), &Engine::get_physics_jitter_fix);
  1344. ClassDB::bind_method(D_METHOD("get_physics_interpolation_fraction"), &Engine::get_physics_interpolation_fraction);
  1345. ClassDB::bind_method(D_METHOD("set_max_fps", "max_fps"), &Engine::set_max_fps);
  1346. ClassDB::bind_method(D_METHOD("get_max_fps"), &Engine::get_max_fps);
  1347. ClassDB::bind_method(D_METHOD("set_time_scale", "time_scale"), &Engine::set_time_scale);
  1348. ClassDB::bind_method(D_METHOD("get_time_scale"), &Engine::get_time_scale);
  1349. ClassDB::bind_method(D_METHOD("get_frames_drawn"), &Engine::get_frames_drawn);
  1350. ClassDB::bind_method(D_METHOD("get_frames_per_second"), &Engine::get_frames_per_second);
  1351. ClassDB::bind_method(D_METHOD("get_physics_frames"), &Engine::get_physics_frames);
  1352. ClassDB::bind_method(D_METHOD("get_process_frames"), &Engine::get_process_frames);
  1353. ClassDB::bind_method(D_METHOD("get_main_loop"), &Engine::get_main_loop);
  1354. ClassDB::bind_method(D_METHOD("get_version_info"), &Engine::get_version_info);
  1355. ClassDB::bind_method(D_METHOD("get_author_info"), &Engine::get_author_info);
  1356. ClassDB::bind_method(D_METHOD("get_copyright_info"), &Engine::get_copyright_info);
  1357. ClassDB::bind_method(D_METHOD("get_donor_info"), &Engine::get_donor_info);
  1358. ClassDB::bind_method(D_METHOD("get_license_info"), &Engine::get_license_info);
  1359. ClassDB::bind_method(D_METHOD("get_license_text"), &Engine::get_license_text);
  1360. ClassDB::bind_method(D_METHOD("get_architecture_name"), &Engine::get_architecture_name);
  1361. ClassDB::bind_method(D_METHOD("is_in_physics_frame"), &Engine::is_in_physics_frame);
  1362. ClassDB::bind_method(D_METHOD("has_singleton", "name"), &Engine::has_singleton);
  1363. ClassDB::bind_method(D_METHOD("get_singleton", "name"), &Engine::get_singleton_object);
  1364. ClassDB::bind_method(D_METHOD("register_singleton", "name", "instance"), &Engine::register_singleton);
  1365. ClassDB::bind_method(D_METHOD("unregister_singleton", "name"), &Engine::unregister_singleton);
  1366. ClassDB::bind_method(D_METHOD("get_singleton_list"), &Engine::get_singleton_list);
  1367. ClassDB::bind_method(D_METHOD("register_script_language", "language"), &Engine::register_script_language);
  1368. ClassDB::bind_method(D_METHOD("unregister_script_language", "language"), &Engine::unregister_script_language);
  1369. ClassDB::bind_method(D_METHOD("get_script_language_count"), &Engine::get_script_language_count);
  1370. ClassDB::bind_method(D_METHOD("get_script_language", "index"), &Engine::get_script_language);
  1371. ClassDB::bind_method(D_METHOD("is_editor_hint"), &Engine::is_editor_hint);
  1372. ClassDB::bind_method(D_METHOD("get_write_movie_path"), &Engine::get_write_movie_path);
  1373. ClassDB::bind_method(D_METHOD("set_print_error_messages", "enabled"), &Engine::set_print_error_messages);
  1374. ClassDB::bind_method(D_METHOD("is_printing_error_messages"), &Engine::is_printing_error_messages);
  1375. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "print_error_messages"), "set_print_error_messages", "is_printing_error_messages");
  1376. ADD_PROPERTY(PropertyInfo(Variant::INT, "physics_ticks_per_second"), "set_physics_ticks_per_second", "get_physics_ticks_per_second");
  1377. ADD_PROPERTY(PropertyInfo(Variant::INT, "max_physics_steps_per_frame"), "set_max_physics_steps_per_frame", "get_max_physics_steps_per_frame");
  1378. ADD_PROPERTY(PropertyInfo(Variant::INT, "max_fps"), "set_max_fps", "get_max_fps");
  1379. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "time_scale"), "set_time_scale", "get_time_scale");
  1380. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "physics_jitter_fix"), "set_physics_jitter_fix", "get_physics_jitter_fix");
  1381. }
  1382. Engine *Engine::singleton = nullptr;
  1383. ////// EngineDebugger //////
  1384. bool EngineDebugger::is_active() {
  1385. return ::EngineDebugger::is_active();
  1386. }
  1387. void EngineDebugger::register_profiler(const StringName &p_name, Ref<EngineProfiler> p_profiler) {
  1388. ERR_FAIL_COND(p_profiler.is_null());
  1389. ERR_FAIL_COND_MSG(p_profiler->is_bound(), "Profiler already registered.");
  1390. ERR_FAIL_COND_MSG(profilers.has(p_name) || has_profiler(p_name), "Profiler name already in use: " + p_name);
  1391. Error err = p_profiler->bind(p_name);
  1392. ERR_FAIL_COND_MSG(err != OK, "Profiler failed to register with error: " + itos(err));
  1393. profilers.insert(p_name, p_profiler);
  1394. }
  1395. void EngineDebugger::unregister_profiler(const StringName &p_name) {
  1396. ERR_FAIL_COND_MSG(!profilers.has(p_name), "Profiler not registered: " + p_name);
  1397. profilers[p_name]->unbind();
  1398. profilers.erase(p_name);
  1399. }
  1400. bool EngineDebugger::is_profiling(const StringName &p_name) {
  1401. return ::EngineDebugger::is_profiling(p_name);
  1402. }
  1403. bool EngineDebugger::has_profiler(const StringName &p_name) {
  1404. return ::EngineDebugger::has_profiler(p_name);
  1405. }
  1406. void EngineDebugger::profiler_add_frame_data(const StringName &p_name, const Array &p_data) {
  1407. ::EngineDebugger::profiler_add_frame_data(p_name, p_data);
  1408. }
  1409. void EngineDebugger::profiler_enable(const StringName &p_name, bool p_enabled, const Array &p_opts) {
  1410. if (::EngineDebugger::get_singleton()) {
  1411. ::EngineDebugger::get_singleton()->profiler_enable(p_name, p_enabled, p_opts);
  1412. }
  1413. }
  1414. void EngineDebugger::register_message_capture(const StringName &p_name, const Callable &p_callable) {
  1415. ERR_FAIL_COND_MSG(captures.has(p_name) || has_capture(p_name), "Capture already registered: " + p_name);
  1416. captures.insert(p_name, p_callable);
  1417. Callable &c = captures[p_name];
  1418. ::EngineDebugger::Capture capture(&c, &EngineDebugger::call_capture);
  1419. ::EngineDebugger::register_message_capture(p_name, capture);
  1420. }
  1421. void EngineDebugger::unregister_message_capture(const StringName &p_name) {
  1422. ERR_FAIL_COND_MSG(!captures.has(p_name), "Capture not registered: " + p_name);
  1423. ::EngineDebugger::unregister_message_capture(p_name);
  1424. captures.erase(p_name);
  1425. }
  1426. bool EngineDebugger::has_capture(const StringName &p_name) {
  1427. return ::EngineDebugger::has_capture(p_name);
  1428. }
  1429. void EngineDebugger::send_message(const String &p_msg, const Array &p_data) {
  1430. ERR_FAIL_COND_MSG(!::EngineDebugger::is_active(), "Can't send message. No active debugger");
  1431. ::EngineDebugger::get_singleton()->send_message(p_msg, p_data);
  1432. }
  1433. Error EngineDebugger::call_capture(void *p_user, const String &p_cmd, const Array &p_data, bool &r_captured) {
  1434. Callable &capture = *(Callable *)p_user;
  1435. if (capture.is_null()) {
  1436. return FAILED;
  1437. }
  1438. Variant cmd = p_cmd, data = p_data;
  1439. const Variant *args[2] = { &cmd, &data };
  1440. Variant retval;
  1441. Callable::CallError err;
  1442. capture.callp(args, 2, retval, err);
  1443. 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));
  1444. ERR_FAIL_COND_V_MSG(retval.get_type() != Variant::BOOL, FAILED, "Error calling 'capture' to callable: " + String(capture) + ". Return type is not bool.");
  1445. r_captured = retval;
  1446. return OK;
  1447. }
  1448. EngineDebugger::~EngineDebugger() {
  1449. for (const KeyValue<StringName, Callable> &E : captures) {
  1450. ::EngineDebugger::unregister_message_capture(E.key);
  1451. }
  1452. captures.clear();
  1453. }
  1454. EngineDebugger *EngineDebugger::singleton = nullptr;
  1455. void EngineDebugger::_bind_methods() {
  1456. ClassDB::bind_method(D_METHOD("is_active"), &EngineDebugger::is_active);
  1457. ClassDB::bind_method(D_METHOD("register_profiler", "name", "profiler"), &EngineDebugger::register_profiler);
  1458. ClassDB::bind_method(D_METHOD("unregister_profiler", "name"), &EngineDebugger::unregister_profiler);
  1459. ClassDB::bind_method(D_METHOD("is_profiling", "name"), &EngineDebugger::is_profiling);
  1460. ClassDB::bind_method(D_METHOD("has_profiler", "name"), &EngineDebugger::has_profiler);
  1461. ClassDB::bind_method(D_METHOD("profiler_add_frame_data", "name", "data"), &EngineDebugger::profiler_add_frame_data);
  1462. ClassDB::bind_method(D_METHOD("profiler_enable", "name", "enable", "arguments"), &EngineDebugger::profiler_enable, DEFVAL(Array()));
  1463. ClassDB::bind_method(D_METHOD("register_message_capture", "name", "callable"), &EngineDebugger::register_message_capture);
  1464. ClassDB::bind_method(D_METHOD("unregister_message_capture", "name"), &EngineDebugger::unregister_message_capture);
  1465. ClassDB::bind_method(D_METHOD("has_capture", "name"), &EngineDebugger::has_capture);
  1466. ClassDB::bind_method(D_METHOD("send_message", "message", "data"), &EngineDebugger::send_message);
  1467. }
  1468. } // namespace core_bind