core_bind.cpp 90 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335
  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_bind.compat.inc"
  32. #include "core/config/project_settings.h"
  33. #include "core/crypto/crypto_core.h"
  34. #include "core/debugger/engine_debugger.h"
  35. #include "core/debugger/script_debugger.h"
  36. #include "core/io/file_access.h"
  37. #include "core/io/marshalls.h"
  38. #include "core/math/geometry_2d.h"
  39. #include "core/math/geometry_3d.h"
  40. #include "core/os/keyboard.h"
  41. #include "core/os/main_loop.h"
  42. #include "core/os/thread_safe.h"
  43. #include "core/variant/typed_array.h"
  44. namespace CoreBind {
  45. ////// ResourceLoader //////
  46. Error ResourceLoader::load_threaded_request(const String &p_path, const String &p_type_hint, bool p_use_sub_threads, CacheMode p_cache_mode) {
  47. return ::ResourceLoader::load_threaded_request(p_path, p_type_hint, p_use_sub_threads, ResourceFormatLoader::CacheMode(p_cache_mode));
  48. }
  49. ResourceLoader::ThreadLoadStatus ResourceLoader::load_threaded_get_status(const String &p_path, Array r_progress) {
  50. float progress = 0;
  51. ::ResourceLoader::ThreadLoadStatus tls = ::ResourceLoader::load_threaded_get_status(p_path, &progress);
  52. // Default array should never be modified, it causes the hash of the method to change.
  53. if (!ClassDB::is_default_array_arg(r_progress)) {
  54. r_progress.resize(1);
  55. r_progress[0] = progress;
  56. }
  57. return (ThreadLoadStatus)tls;
  58. }
  59. Ref<Resource> ResourceLoader::load_threaded_get(const String &p_path) {
  60. Error error;
  61. Ref<Resource> res = ::ResourceLoader::load_threaded_get(p_path, &error);
  62. return res;
  63. }
  64. Ref<Resource> ResourceLoader::load(const String &p_path, const String &p_type_hint, CacheMode p_cache_mode) {
  65. Error err = OK;
  66. Ref<Resource> ret = ::ResourceLoader::load(p_path, p_type_hint, ResourceFormatLoader::CacheMode(p_cache_mode), &err);
  67. ERR_FAIL_COND_V_MSG(err != OK, ret, vformat("Error loading resource: '%s'.", p_path));
  68. return ret;
  69. }
  70. Vector<String> ResourceLoader::get_recognized_extensions_for_type(const String &p_type) {
  71. List<String> exts;
  72. ::ResourceLoader::get_recognized_extensions_for_type(p_type, &exts);
  73. Vector<String> ret;
  74. for (const String &E : exts) {
  75. ret.push_back(E);
  76. }
  77. return ret;
  78. }
  79. void ResourceLoader::add_resource_format_loader(Ref<ResourceFormatLoader> p_format_loader, bool p_at_front) {
  80. ::ResourceLoader::add_resource_format_loader(p_format_loader, p_at_front);
  81. }
  82. void ResourceLoader::remove_resource_format_loader(Ref<ResourceFormatLoader> p_format_loader) {
  83. ::ResourceLoader::remove_resource_format_loader(p_format_loader);
  84. }
  85. void ResourceLoader::set_abort_on_missing_resources(bool p_abort) {
  86. ::ResourceLoader::set_abort_on_missing_resources(p_abort);
  87. }
  88. PackedStringArray ResourceLoader::get_dependencies(const String &p_path) {
  89. List<String> deps;
  90. ::ResourceLoader::get_dependencies(p_path, &deps);
  91. PackedStringArray ret;
  92. for (const String &E : deps) {
  93. ret.push_back(E);
  94. }
  95. return ret;
  96. }
  97. bool ResourceLoader::has_cached(const String &p_path) {
  98. String local_path = ::ResourceLoader::_validate_local_path(p_path);
  99. return ResourceCache::has(local_path);
  100. }
  101. Ref<Resource> ResourceLoader::get_cached_ref(const String &p_path) {
  102. String local_path = ::ResourceLoader::_validate_local_path(p_path);
  103. return ResourceCache::get_ref(local_path);
  104. }
  105. bool ResourceLoader::exists(const String &p_path, const String &p_type_hint) {
  106. return ::ResourceLoader::exists(p_path, p_type_hint);
  107. }
  108. ResourceUID::ID ResourceLoader::get_resource_uid(const String &p_path) {
  109. return ::ResourceLoader::get_resource_uid(p_path);
  110. }
  111. Vector<String> ResourceLoader::list_directory(const String &p_directory) {
  112. return ::ResourceLoader::list_directory(p_directory);
  113. }
  114. void ResourceLoader::_bind_methods() {
  115. 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));
  116. ClassDB::bind_method(D_METHOD("load_threaded_get_status", "path", "progress"), &ResourceLoader::load_threaded_get_status, DEFVAL_ARRAY);
  117. ClassDB::bind_method(D_METHOD("load_threaded_get", "path"), &ResourceLoader::load_threaded_get);
  118. ClassDB::bind_method(D_METHOD("load", "path", "type_hint", "cache_mode"), &ResourceLoader::load, DEFVAL(""), DEFVAL(CACHE_MODE_REUSE));
  119. ClassDB::bind_method(D_METHOD("get_recognized_extensions_for_type", "type"), &ResourceLoader::get_recognized_extensions_for_type);
  120. ClassDB::bind_method(D_METHOD("add_resource_format_loader", "format_loader", "at_front"), &ResourceLoader::add_resource_format_loader, DEFVAL(false));
  121. ClassDB::bind_method(D_METHOD("remove_resource_format_loader", "format_loader"), &ResourceLoader::remove_resource_format_loader);
  122. ClassDB::bind_method(D_METHOD("set_abort_on_missing_resources", "abort"), &ResourceLoader::set_abort_on_missing_resources);
  123. ClassDB::bind_method(D_METHOD("get_dependencies", "path"), &ResourceLoader::get_dependencies);
  124. ClassDB::bind_method(D_METHOD("has_cached", "path"), &ResourceLoader::has_cached);
  125. ClassDB::bind_method(D_METHOD("get_cached_ref", "path"), &ResourceLoader::get_cached_ref);
  126. ClassDB::bind_method(D_METHOD("exists", "path", "type_hint"), &ResourceLoader::exists, DEFVAL(""));
  127. ClassDB::bind_method(D_METHOD("get_resource_uid", "path"), &ResourceLoader::get_resource_uid);
  128. ClassDB::bind_method(D_METHOD("list_directory", "directory_path"), &ResourceLoader::list_directory);
  129. BIND_ENUM_CONSTANT(THREAD_LOAD_INVALID_RESOURCE);
  130. BIND_ENUM_CONSTANT(THREAD_LOAD_IN_PROGRESS);
  131. BIND_ENUM_CONSTANT(THREAD_LOAD_FAILED);
  132. BIND_ENUM_CONSTANT(THREAD_LOAD_LOADED);
  133. BIND_ENUM_CONSTANT(CACHE_MODE_IGNORE);
  134. BIND_ENUM_CONSTANT(CACHE_MODE_REUSE);
  135. BIND_ENUM_CONSTANT(CACHE_MODE_REPLACE);
  136. BIND_ENUM_CONSTANT(CACHE_MODE_IGNORE_DEEP);
  137. BIND_ENUM_CONSTANT(CACHE_MODE_REPLACE_DEEP);
  138. }
  139. ////// ResourceSaver //////
  140. Error ResourceSaver::save(const Ref<Resource> &p_resource, const String &p_path, BitField<SaverFlags> p_flags) {
  141. return ::ResourceSaver::save(p_resource, p_path, p_flags);
  142. }
  143. Error ResourceSaver::set_uid(const String &p_path, ResourceUID::ID p_uid) {
  144. return ::ResourceSaver::set_uid(p_path, p_uid);
  145. }
  146. Vector<String> ResourceSaver::get_recognized_extensions(const Ref<Resource> &p_resource) {
  147. List<String> exts;
  148. ::ResourceSaver::get_recognized_extensions(p_resource, &exts);
  149. Vector<String> ret;
  150. for (const String &E : exts) {
  151. ret.push_back(E);
  152. }
  153. return ret;
  154. }
  155. void ResourceSaver::add_resource_format_saver(Ref<ResourceFormatSaver> p_format_saver, bool p_at_front) {
  156. ::ResourceSaver::add_resource_format_saver(p_format_saver, p_at_front);
  157. }
  158. void ResourceSaver::remove_resource_format_saver(Ref<ResourceFormatSaver> p_format_saver) {
  159. ::ResourceSaver::remove_resource_format_saver(p_format_saver);
  160. }
  161. ResourceUID::ID ResourceSaver::get_resource_id_for_path(const String &p_path, bool p_generate) {
  162. return ::ResourceSaver::get_resource_id_for_path(p_path, p_generate);
  163. }
  164. void ResourceSaver::_bind_methods() {
  165. ClassDB::bind_method(D_METHOD("save", "resource", "path", "flags"), &ResourceSaver::save, DEFVAL(""), DEFVAL((uint32_t)FLAG_NONE));
  166. ClassDB::bind_method(D_METHOD("set_uid", "resource", "uid"), &ResourceSaver::set_uid);
  167. ClassDB::bind_method(D_METHOD("get_recognized_extensions", "type"), &ResourceSaver::get_recognized_extensions);
  168. ClassDB::bind_method(D_METHOD("add_resource_format_saver", "format_saver", "at_front"), &ResourceSaver::add_resource_format_saver, DEFVAL(false));
  169. ClassDB::bind_method(D_METHOD("remove_resource_format_saver", "format_saver"), &ResourceSaver::remove_resource_format_saver);
  170. ClassDB::bind_method(D_METHOD("get_resource_id_for_path", "path", "generate"), &ResourceSaver::get_resource_id_for_path, DEFVAL(false));
  171. BIND_BITFIELD_FLAG(FLAG_NONE);
  172. BIND_BITFIELD_FLAG(FLAG_RELATIVE_PATHS);
  173. BIND_BITFIELD_FLAG(FLAG_BUNDLE_RESOURCES);
  174. BIND_BITFIELD_FLAG(FLAG_CHANGE_PATH);
  175. BIND_BITFIELD_FLAG(FLAG_OMIT_EDITOR_PROPERTIES);
  176. BIND_BITFIELD_FLAG(FLAG_SAVE_BIG_ENDIAN);
  177. BIND_BITFIELD_FLAG(FLAG_COMPRESS);
  178. BIND_BITFIELD_FLAG(FLAG_REPLACE_SUBRESOURCE_PATHS);
  179. }
  180. ////// Logger ///////
  181. void Logger::_bind_methods() {
  182. GDVIRTUAL_BIND(_log_error, "function", "file", "line", "code", "rationale", "editor_notify", "error_type", "script_backtraces");
  183. GDVIRTUAL_BIND(_log_message, "message", "error");
  184. BIND_ENUM_CONSTANT(ERROR_TYPE_ERROR);
  185. BIND_ENUM_CONSTANT(ERROR_TYPE_WARNING);
  186. BIND_ENUM_CONSTANT(ERROR_TYPE_SCRIPT);
  187. BIND_ENUM_CONSTANT(ERROR_TYPE_SHADER);
  188. }
  189. void Logger::log_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, bool p_editor_notify, ErrorType p_type, const TypedArray<ScriptBacktrace> &p_script_backtraces) {
  190. GDVIRTUAL_CALL(_log_error, String::utf8(p_function), String::utf8(p_file), p_line, String::utf8(p_code), String::utf8(p_rationale), p_editor_notify, p_type, p_script_backtraces);
  191. }
  192. void Logger::log_message(const String &p_text, bool p_error) {
  193. GDVIRTUAL_CALL(_log_message, p_text, p_error);
  194. }
  195. ////// OS //////
  196. void OS::LoggerBind::logv(const char *p_format, va_list p_list, bool p_err) {
  197. if (!should_log(p_err)) {
  198. return;
  199. }
  200. constexpr int static_buf_size = 1024;
  201. char static_buf[static_buf_size] = { '\0' };
  202. char *buf = static_buf;
  203. va_list list_copy;
  204. va_copy(list_copy, p_list);
  205. int len = vsnprintf(buf, static_buf_size, p_format, p_list);
  206. if (len >= static_buf_size) {
  207. buf = (char *)Memory::alloc_static(len + 1);
  208. vsnprintf(buf, len + 1, p_format, list_copy);
  209. }
  210. va_end(list_copy);
  211. String str;
  212. str.append_utf8(buf, len);
  213. for (Ref<CoreBind::Logger> &logger : loggers) {
  214. logger->log_message(str, p_err);
  215. }
  216. if (len >= static_buf_size) {
  217. Memory::free_static(buf);
  218. }
  219. }
  220. void OS::LoggerBind::log_error(const char *p_function, const char *p_file, int p_line, const char *p_code, const char *p_rationale, bool p_editor_notify, ErrorType p_type, const Vector<Ref<ScriptBacktrace>> &p_script_backtraces) {
  221. if (!should_log(true)) {
  222. return;
  223. }
  224. TypedArray<ScriptBacktrace> backtraces;
  225. backtraces.resize(p_script_backtraces.size());
  226. for (int i = 0; i < p_script_backtraces.size(); i++) {
  227. backtraces[i] = p_script_backtraces[i];
  228. }
  229. for (Ref<CoreBind::Logger> &logger : loggers) {
  230. logger->log_error(p_function, p_file, p_line, p_code, p_rationale, p_editor_notify, CoreBind::Logger::ErrorType(p_type), backtraces);
  231. }
  232. }
  233. PackedByteArray OS::get_entropy(int p_bytes) {
  234. PackedByteArray pba;
  235. pba.resize(p_bytes);
  236. Error err = ::OS::get_singleton()->get_entropy(pba.ptrw(), p_bytes);
  237. ERR_FAIL_COND_V(err != OK, PackedByteArray());
  238. return pba;
  239. }
  240. String OS::get_system_ca_certificates() {
  241. return ::OS::get_singleton()->get_system_ca_certificates();
  242. }
  243. PackedStringArray OS::get_connected_midi_inputs() {
  244. return ::OS::get_singleton()->get_connected_midi_inputs();
  245. }
  246. void OS::open_midi_inputs() {
  247. ::OS::get_singleton()->open_midi_inputs();
  248. }
  249. void OS::close_midi_inputs() {
  250. ::OS::get_singleton()->close_midi_inputs();
  251. }
  252. void OS::set_use_file_access_save_and_swap(bool p_enable) {
  253. FileAccess::set_backup_save(p_enable);
  254. }
  255. void OS::set_low_processor_usage_mode(bool p_enabled) {
  256. ::OS::get_singleton()->set_low_processor_usage_mode(p_enabled);
  257. }
  258. bool OS::is_in_low_processor_usage_mode() const {
  259. return ::OS::get_singleton()->is_in_low_processor_usage_mode();
  260. }
  261. void OS::set_low_processor_usage_mode_sleep_usec(int p_usec) {
  262. ::OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(p_usec);
  263. }
  264. int OS::get_low_processor_usage_mode_sleep_usec() const {
  265. return ::OS::get_singleton()->get_low_processor_usage_mode_sleep_usec();
  266. }
  267. void OS::set_delta_smoothing(bool p_enabled) {
  268. ::OS::get_singleton()->set_delta_smoothing(p_enabled);
  269. }
  270. bool OS::is_delta_smoothing_enabled() const {
  271. return ::OS::get_singleton()->is_delta_smoothing_enabled();
  272. }
  273. void OS::alert(const String &p_alert, const String &p_title) {
  274. ::OS::get_singleton()->alert(p_alert, p_title);
  275. }
  276. void OS::crash(const String &p_message) {
  277. CRASH_NOW_MSG(p_message);
  278. }
  279. Vector<String> OS::get_system_fonts() const {
  280. return ::OS::get_singleton()->get_system_fonts();
  281. }
  282. String OS::get_system_font_path(const String &p_font_name, int p_weight, int p_stretch, bool p_italic) const {
  283. return ::OS::get_singleton()->get_system_font_path(p_font_name, p_weight, p_stretch, p_italic);
  284. }
  285. 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 {
  286. 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);
  287. }
  288. String OS::get_executable_path() const {
  289. return ::OS::get_singleton()->get_executable_path();
  290. }
  291. Error OS::shell_open(const String &p_uri) {
  292. if (p_uri.begins_with("res://")) {
  293. 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()`.");
  294. } else if (p_uri.begins_with("user://")) {
  295. 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()`.");
  296. }
  297. return ::OS::get_singleton()->shell_open(p_uri);
  298. }
  299. Error OS::shell_show_in_file_manager(const String &p_path, bool p_open_folder) {
  300. if (p_path.begins_with("res://")) {
  301. 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()`.");
  302. } else if (p_path.begins_with("user://")) {
  303. 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()`.");
  304. }
  305. return ::OS::get_singleton()->shell_show_in_file_manager(p_path, p_open_folder);
  306. }
  307. String OS::read_string_from_stdin(int64_t p_buffer_size) {
  308. return ::OS::get_singleton()->get_stdin_string(p_buffer_size);
  309. }
  310. PackedByteArray OS::read_buffer_from_stdin(int64_t p_buffer_size) {
  311. return ::OS::get_singleton()->get_stdin_buffer(p_buffer_size);
  312. }
  313. OS::StdHandleType OS::get_stdin_type() const {
  314. return (OS::StdHandleType)::OS::get_singleton()->get_stdin_type();
  315. }
  316. OS::StdHandleType OS::get_stdout_type() const {
  317. return (OS::StdHandleType)::OS::get_singleton()->get_stdout_type();
  318. }
  319. OS::StdHandleType OS::get_stderr_type() const {
  320. return (OS::StdHandleType)::OS::get_singleton()->get_stderr_type();
  321. }
  322. int OS::execute(const String &p_path, const Vector<String> &p_arguments, Array r_output, bool p_read_stderr, bool p_open_console) {
  323. List<String> args;
  324. for (const String &arg : p_arguments) {
  325. args.push_back(arg);
  326. }
  327. String pipe;
  328. int exitcode = 0;
  329. Error err = ::OS::get_singleton()->execute(p_path, args, &pipe, &exitcode, p_read_stderr, nullptr, p_open_console);
  330. // Default array should never be modified, it causes the hash of the method to change.
  331. if (!ClassDB::is_default_array_arg(r_output)) {
  332. r_output.push_back(pipe);
  333. }
  334. if (err != OK) {
  335. return -1;
  336. }
  337. return exitcode;
  338. }
  339. Dictionary OS::execute_with_pipe(const String &p_path, const Vector<String> &p_arguments, bool p_blocking) {
  340. List<String> args;
  341. for (const String &arg : p_arguments) {
  342. args.push_back(arg);
  343. }
  344. return ::OS::get_singleton()->execute_with_pipe(p_path, args, p_blocking);
  345. }
  346. int OS::create_instance(const Vector<String> &p_arguments) {
  347. List<String> args;
  348. for (const String &arg : p_arguments) {
  349. args.push_back(arg);
  350. }
  351. ::OS::ProcessID pid = 0;
  352. Error err = ::OS::get_singleton()->create_instance(args, &pid);
  353. if (err != OK) {
  354. return -1;
  355. }
  356. return pid;
  357. }
  358. Error OS::open_with_program(const String &p_program_path, const Vector<String> &p_paths) {
  359. List<String> paths;
  360. for (const String &path : p_paths) {
  361. paths.push_back(path);
  362. }
  363. return ::OS::get_singleton()->open_with_program(p_program_path, paths);
  364. }
  365. int OS::create_process(const String &p_path, const Vector<String> &p_arguments, bool p_open_console) {
  366. List<String> args;
  367. for (const String &arg : p_arguments) {
  368. args.push_back(arg);
  369. }
  370. ::OS::ProcessID pid = 0;
  371. Error err = ::OS::get_singleton()->create_process(p_path, args, &pid, p_open_console);
  372. if (err != OK) {
  373. return -1;
  374. }
  375. return pid;
  376. }
  377. Error OS::kill(int p_pid) {
  378. return ::OS::get_singleton()->kill(p_pid);
  379. }
  380. bool OS::is_process_running(int p_pid) const {
  381. return ::OS::get_singleton()->is_process_running(p_pid);
  382. }
  383. int OS::get_process_exit_code(int p_pid) const {
  384. return ::OS::get_singleton()->get_process_exit_code(p_pid);
  385. }
  386. int OS::get_process_id() const {
  387. return ::OS::get_singleton()->get_process_id();
  388. }
  389. bool OS::has_environment(const String &p_var) const {
  390. return ::OS::get_singleton()->has_environment(p_var);
  391. }
  392. String OS::get_environment(const String &p_var) const {
  393. return ::OS::get_singleton()->get_environment(p_var);
  394. }
  395. void OS::set_environment(const String &p_var, const String &p_value) const {
  396. ::OS::get_singleton()->set_environment(p_var, p_value);
  397. }
  398. void OS::unset_environment(const String &p_var) const {
  399. ::OS::get_singleton()->unset_environment(p_var);
  400. }
  401. String OS::get_name() const {
  402. return ::OS::get_singleton()->get_name();
  403. }
  404. String OS::get_distribution_name() const {
  405. return ::OS::get_singleton()->get_distribution_name();
  406. }
  407. String OS::get_version() const {
  408. return ::OS::get_singleton()->get_version();
  409. }
  410. String OS::get_version_alias() const {
  411. return ::OS::get_singleton()->get_version_alias();
  412. }
  413. Vector<String> OS::get_video_adapter_driver_info() const {
  414. return ::OS::get_singleton()->get_video_adapter_driver_info();
  415. }
  416. Vector<String> OS::get_cmdline_args() {
  417. List<String> cmdline = ::OS::get_singleton()->get_cmdline_args();
  418. Vector<String> cmdlinev;
  419. for (const String &E : cmdline) {
  420. cmdlinev.push_back(E);
  421. }
  422. return cmdlinev;
  423. }
  424. Vector<String> OS::get_cmdline_user_args() {
  425. List<String> cmdline = ::OS::get_singleton()->get_cmdline_user_args();
  426. Vector<String> cmdlinev;
  427. for (const String &E : cmdline) {
  428. cmdlinev.push_back(E);
  429. }
  430. return cmdlinev;
  431. }
  432. void OS::set_restart_on_exit(bool p_restart, const Vector<String> &p_restart_arguments) {
  433. List<String> args_list;
  434. for (const String &restart_argument : p_restart_arguments) {
  435. args_list.push_back(restart_argument);
  436. }
  437. ::OS::get_singleton()->set_restart_on_exit(p_restart, args_list);
  438. }
  439. bool OS::is_restart_on_exit_set() const {
  440. return ::OS::get_singleton()->is_restart_on_exit_set();
  441. }
  442. Vector<String> OS::get_restart_on_exit_arguments() const {
  443. List<String> args = ::OS::get_singleton()->get_restart_on_exit_arguments();
  444. Vector<String> args_vector;
  445. for (const String &arg : args) {
  446. args_vector.push_back(arg);
  447. }
  448. return args_vector;
  449. }
  450. String OS::get_locale() const {
  451. return ::OS::get_singleton()->get_locale();
  452. }
  453. String OS::get_locale_language() const {
  454. return ::OS::get_singleton()->get_locale_language();
  455. }
  456. String OS::get_model_name() const {
  457. return ::OS::get_singleton()->get_model_name();
  458. }
  459. Error OS::set_thread_name(const String &p_name) {
  460. return ::Thread::set_name(p_name);
  461. }
  462. ::Thread::ID OS::get_thread_caller_id() const {
  463. return ::Thread::get_caller_id();
  464. }
  465. ::Thread::ID OS::get_main_thread_id() const {
  466. return ::Thread::get_main_id();
  467. }
  468. bool OS::has_feature(const String &p_feature) const {
  469. const bool *value_ptr = feature_cache.getptr(p_feature);
  470. if (value_ptr) {
  471. return *value_ptr;
  472. } else {
  473. const bool has = ::OS::get_singleton()->has_feature(p_feature);
  474. feature_cache[p_feature] = has;
  475. return has;
  476. }
  477. }
  478. bool OS::is_sandboxed() const {
  479. return ::OS::get_singleton()->is_sandboxed();
  480. }
  481. uint64_t OS::get_static_memory_usage() const {
  482. return ::OS::get_singleton()->get_static_memory_usage();
  483. }
  484. uint64_t OS::get_static_memory_peak_usage() const {
  485. return ::OS::get_singleton()->get_static_memory_peak_usage();
  486. }
  487. Dictionary OS::get_memory_info() const {
  488. return ::OS::get_singleton()->get_memory_info();
  489. }
  490. /** This method uses a signed argument for better error reporting as it's used from the scripting API. */
  491. void OS::delay_usec(int p_usec) const {
  492. ERR_FAIL_COND_MSG(
  493. p_usec < 0,
  494. vformat("Can't sleep for %d microseconds. The delay provided must be greater than or equal to 0 microseconds.", p_usec));
  495. ::OS::get_singleton()->delay_usec(p_usec);
  496. }
  497. /** This method uses a signed argument for better error reporting as it's used from the scripting API. */
  498. void OS::delay_msec(int p_msec) const {
  499. ERR_FAIL_COND_MSG(
  500. p_msec < 0,
  501. vformat("Can't sleep for %d milliseconds. The delay provided must be greater than or equal to 0 milliseconds.", p_msec));
  502. ::OS::get_singleton()->delay_usec(int64_t(p_msec) * 1000);
  503. }
  504. bool OS::is_userfs_persistent() const {
  505. return ::OS::get_singleton()->is_userfs_persistent();
  506. }
  507. int OS::get_processor_count() const {
  508. return ::OS::get_singleton()->get_processor_count();
  509. }
  510. String OS::get_processor_name() const {
  511. return ::OS::get_singleton()->get_processor_name();
  512. }
  513. bool OS::is_stdout_verbose() const {
  514. return ::OS::get_singleton()->is_stdout_verbose();
  515. }
  516. Error OS::move_to_trash(const String &p_path) const {
  517. return ::OS::get_singleton()->move_to_trash(p_path);
  518. }
  519. String OS::get_user_data_dir() const {
  520. return ::OS::get_singleton()->get_user_data_dir();
  521. }
  522. String OS::get_config_dir() const {
  523. // Exposed as `get_config_dir()` instead of `get_config_path()` for consistency with other exposed OS methods.
  524. return ::OS::get_singleton()->get_config_path();
  525. }
  526. String OS::get_data_dir() const {
  527. // Exposed as `get_data_dir()` instead of `get_data_path()` for consistency with other exposed OS methods.
  528. return ::OS::get_singleton()->get_data_path();
  529. }
  530. String OS::get_cache_dir() const {
  531. // Exposed as `get_cache_dir()` instead of `get_cache_path()` for consistency with other exposed OS methods.
  532. return ::OS::get_singleton()->get_cache_path();
  533. }
  534. String OS::get_temp_dir() const {
  535. // Exposed as `get_temp_dir()` instead of `get_temp_path()` for consistency with other exposed OS methods.
  536. return ::OS::get_singleton()->get_temp_path();
  537. }
  538. bool OS::is_debug_build() const {
  539. #ifdef DEBUG_ENABLED
  540. return true;
  541. #else
  542. return false;
  543. #endif // DEBUG_ENABLED
  544. }
  545. String OS::get_system_dir(SystemDir p_dir, bool p_shared_storage) const {
  546. return ::OS::get_singleton()->get_system_dir(::OS::SystemDir(p_dir), p_shared_storage);
  547. }
  548. String OS::get_keycode_string(Key p_code) const {
  549. return ::keycode_get_string(p_code);
  550. }
  551. bool OS::is_keycode_unicode(char32_t p_unicode) const {
  552. return ::keycode_has_unicode((Key)p_unicode);
  553. }
  554. Key OS::find_keycode_from_string(const String &p_code) const {
  555. return find_keycode(p_code);
  556. }
  557. bool OS::request_permission(const String &p_name) {
  558. return ::OS::get_singleton()->request_permission(p_name);
  559. }
  560. bool OS::request_permissions() {
  561. return ::OS::get_singleton()->request_permissions();
  562. }
  563. Vector<String> OS::get_granted_permissions() const {
  564. return ::OS::get_singleton()->get_granted_permissions();
  565. }
  566. void OS::revoke_granted_permissions() {
  567. ::OS::get_singleton()->revoke_granted_permissions();
  568. }
  569. String OS::get_unique_id() const {
  570. return ::OS::get_singleton()->get_unique_id();
  571. }
  572. void OS::add_logger(const Ref<Logger> &p_logger) {
  573. ERR_FAIL_COND(p_logger.is_null());
  574. if (!logger_bind) {
  575. logger_bind = memnew(LoggerBind);
  576. ::OS::get_singleton()->add_logger(logger_bind);
  577. }
  578. ERR_FAIL_COND_MSG(logger_bind->loggers.find(p_logger) != -1, "Could not add logger, as it has already been added.");
  579. logger_bind->loggers.push_back(p_logger);
  580. }
  581. void OS::remove_logger(const Ref<Logger> &p_logger) {
  582. ERR_FAIL_COND(p_logger.is_null());
  583. ERR_FAIL_COND_MSG(!logger_bind || logger_bind->loggers.find(p_logger) == -1, "Could not remove logger, as it hasn't been added.");
  584. logger_bind->loggers.erase(p_logger);
  585. }
  586. void OS::remove_script_loggers(const ScriptLanguage *p_script) {
  587. if (logger_bind) {
  588. LocalVector<Ref<CoreBind::Logger>> to_remove;
  589. for (const Ref<CoreBind::Logger> &logger : logger_bind->loggers) {
  590. if (logger.is_null()) {
  591. continue;
  592. }
  593. ScriptInstance *si = logger->get_script_instance();
  594. if (!si) {
  595. continue;
  596. }
  597. if (si->get_language() == p_script) {
  598. to_remove.push_back(logger);
  599. }
  600. }
  601. for (const Ref<CoreBind::Logger> &logger : to_remove) {
  602. logger_bind->loggers.erase(logger);
  603. }
  604. }
  605. }
  606. void OS::_bind_methods() {
  607. ClassDB::bind_method(D_METHOD("get_entropy", "size"), &OS::get_entropy);
  608. ClassDB::bind_method(D_METHOD("get_system_ca_certificates"), &OS::get_system_ca_certificates);
  609. ClassDB::bind_method(D_METHOD("get_connected_midi_inputs"), &OS::get_connected_midi_inputs);
  610. ClassDB::bind_method(D_METHOD("open_midi_inputs"), &OS::open_midi_inputs);
  611. ClassDB::bind_method(D_METHOD("close_midi_inputs"), &OS::close_midi_inputs);
  612. ClassDB::bind_method(D_METHOD("alert", "text", "title"), &OS::alert, DEFVAL("Alert!"));
  613. ClassDB::bind_method(D_METHOD("crash", "message"), &OS::crash);
  614. ClassDB::bind_method(D_METHOD("set_low_processor_usage_mode", "enable"), &OS::set_low_processor_usage_mode);
  615. ClassDB::bind_method(D_METHOD("is_in_low_processor_usage_mode"), &OS::is_in_low_processor_usage_mode);
  616. ClassDB::bind_method(D_METHOD("set_low_processor_usage_mode_sleep_usec", "usec"), &OS::set_low_processor_usage_mode_sleep_usec);
  617. ClassDB::bind_method(D_METHOD("get_low_processor_usage_mode_sleep_usec"), &OS::get_low_processor_usage_mode_sleep_usec);
  618. ClassDB::bind_method(D_METHOD("set_delta_smoothing", "delta_smoothing_enabled"), &OS::set_delta_smoothing);
  619. ClassDB::bind_method(D_METHOD("is_delta_smoothing_enabled"), &OS::is_delta_smoothing_enabled);
  620. ClassDB::bind_method(D_METHOD("get_processor_count"), &OS::get_processor_count);
  621. ClassDB::bind_method(D_METHOD("get_processor_name"), &OS::get_processor_name);
  622. ClassDB::bind_method(D_METHOD("get_system_fonts"), &OS::get_system_fonts);
  623. 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));
  624. 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));
  625. ClassDB::bind_method(D_METHOD("get_executable_path"), &OS::get_executable_path);
  626. ClassDB::bind_method(D_METHOD("read_string_from_stdin", "buffer_size"), &OS::read_string_from_stdin, DEFVAL(1024));
  627. ClassDB::bind_method(D_METHOD("read_buffer_from_stdin", "buffer_size"), &OS::read_buffer_from_stdin, DEFVAL(1024));
  628. ClassDB::bind_method(D_METHOD("get_stdin_type"), &OS::get_stdin_type);
  629. ClassDB::bind_method(D_METHOD("get_stdout_type"), &OS::get_stdout_type);
  630. ClassDB::bind_method(D_METHOD("get_stderr_type"), &OS::get_stderr_type);
  631. ClassDB::bind_method(D_METHOD("execute", "path", "arguments", "output", "read_stderr", "open_console"), &OS::execute, DEFVAL_ARRAY, DEFVAL(false), DEFVAL(false));
  632. ClassDB::bind_method(D_METHOD("execute_with_pipe", "path", "arguments", "blocking"), &OS::execute_with_pipe, DEFVAL(true));
  633. ClassDB::bind_method(D_METHOD("create_process", "path", "arguments", "open_console"), &OS::create_process, DEFVAL(false));
  634. ClassDB::bind_method(D_METHOD("create_instance", "arguments"), &OS::create_instance);
  635. ClassDB::bind_method(D_METHOD("open_with_program", "program_path", "paths"), &OS::open_with_program);
  636. ClassDB::bind_method(D_METHOD("kill", "pid"), &OS::kill);
  637. ClassDB::bind_method(D_METHOD("shell_open", "uri"), &OS::shell_open);
  638. ClassDB::bind_method(D_METHOD("shell_show_in_file_manager", "file_or_dir_path", "open_folder"), &OS::shell_show_in_file_manager, DEFVAL(true));
  639. ClassDB::bind_method(D_METHOD("is_process_running", "pid"), &OS::is_process_running);
  640. ClassDB::bind_method(D_METHOD("get_process_exit_code", "pid"), &OS::get_process_exit_code);
  641. ClassDB::bind_method(D_METHOD("get_process_id"), &OS::get_process_id);
  642. ClassDB::bind_method(D_METHOD("has_environment", "variable"), &OS::has_environment);
  643. ClassDB::bind_method(D_METHOD("get_environment", "variable"), &OS::get_environment);
  644. ClassDB::bind_method(D_METHOD("set_environment", "variable", "value"), &OS::set_environment);
  645. ClassDB::bind_method(D_METHOD("unset_environment", "variable"), &OS::unset_environment);
  646. ClassDB::bind_method(D_METHOD("get_name"), &OS::get_name);
  647. ClassDB::bind_method(D_METHOD("get_distribution_name"), &OS::get_distribution_name);
  648. ClassDB::bind_method(D_METHOD("get_version"), &OS::get_version);
  649. ClassDB::bind_method(D_METHOD("get_version_alias"), &OS::get_version_alias);
  650. ClassDB::bind_method(D_METHOD("get_cmdline_args"), &OS::get_cmdline_args);
  651. ClassDB::bind_method(D_METHOD("get_cmdline_user_args"), &OS::get_cmdline_user_args);
  652. ClassDB::bind_method(D_METHOD("get_video_adapter_driver_info"), &OS::get_video_adapter_driver_info);
  653. ClassDB::bind_method(D_METHOD("set_restart_on_exit", "restart", "arguments"), &OS::set_restart_on_exit, DEFVAL(Vector<String>()));
  654. ClassDB::bind_method(D_METHOD("is_restart_on_exit_set"), &OS::is_restart_on_exit_set);
  655. ClassDB::bind_method(D_METHOD("get_restart_on_exit_arguments"), &OS::get_restart_on_exit_arguments);
  656. ClassDB::bind_method(D_METHOD("delay_usec", "usec"), &OS::delay_usec);
  657. ClassDB::bind_method(D_METHOD("delay_msec", "msec"), &OS::delay_msec);
  658. ClassDB::bind_method(D_METHOD("get_locale"), &OS::get_locale);
  659. ClassDB::bind_method(D_METHOD("get_locale_language"), &OS::get_locale_language);
  660. ClassDB::bind_method(D_METHOD("get_model_name"), &OS::get_model_name);
  661. ClassDB::bind_method(D_METHOD("is_userfs_persistent"), &OS::is_userfs_persistent);
  662. ClassDB::bind_method(D_METHOD("is_stdout_verbose"), &OS::is_stdout_verbose);
  663. ClassDB::bind_method(D_METHOD("is_debug_build"), &OS::is_debug_build);
  664. ClassDB::bind_method(D_METHOD("get_static_memory_usage"), &OS::get_static_memory_usage);
  665. ClassDB::bind_method(D_METHOD("get_static_memory_peak_usage"), &OS::get_static_memory_peak_usage);
  666. ClassDB::bind_method(D_METHOD("get_memory_info"), &OS::get_memory_info);
  667. ClassDB::bind_method(D_METHOD("move_to_trash", "path"), &OS::move_to_trash);
  668. ClassDB::bind_method(D_METHOD("get_user_data_dir"), &OS::get_user_data_dir);
  669. ClassDB::bind_method(D_METHOD("get_system_dir", "dir", "shared_storage"), &OS::get_system_dir, DEFVAL(true));
  670. ClassDB::bind_method(D_METHOD("get_config_dir"), &OS::get_config_dir);
  671. ClassDB::bind_method(D_METHOD("get_data_dir"), &OS::get_data_dir);
  672. ClassDB::bind_method(D_METHOD("get_cache_dir"), &OS::get_cache_dir);
  673. ClassDB::bind_method(D_METHOD("get_temp_dir"), &OS::get_temp_dir);
  674. ClassDB::bind_method(D_METHOD("get_unique_id"), &OS::get_unique_id);
  675. ClassDB::bind_method(D_METHOD("get_keycode_string", "code"), &OS::get_keycode_string);
  676. ClassDB::bind_method(D_METHOD("is_keycode_unicode", "code"), &OS::is_keycode_unicode);
  677. ClassDB::bind_method(D_METHOD("find_keycode_from_string", "string"), &OS::find_keycode_from_string);
  678. ClassDB::bind_method(D_METHOD("set_use_file_access_save_and_swap", "enabled"), &OS::set_use_file_access_save_and_swap);
  679. ClassDB::bind_method(D_METHOD("set_thread_name", "name"), &OS::set_thread_name);
  680. ClassDB::bind_method(D_METHOD("get_thread_caller_id"), &OS::get_thread_caller_id);
  681. ClassDB::bind_method(D_METHOD("get_main_thread_id"), &OS::get_main_thread_id);
  682. ClassDB::bind_method(D_METHOD("has_feature", "tag_name"), &OS::has_feature);
  683. ClassDB::bind_method(D_METHOD("is_sandboxed"), &OS::is_sandboxed);
  684. ClassDB::bind_method(D_METHOD("request_permission", "name"), &OS::request_permission);
  685. ClassDB::bind_method(D_METHOD("request_permissions"), &OS::request_permissions);
  686. ClassDB::bind_method(D_METHOD("get_granted_permissions"), &OS::get_granted_permissions);
  687. ClassDB::bind_method(D_METHOD("revoke_granted_permissions"), &OS::revoke_granted_permissions);
  688. ClassDB::bind_method(D_METHOD("add_logger", "logger"), &OS::add_logger);
  689. ClassDB::bind_method(D_METHOD("remove_logger", "logger"), &OS::remove_logger);
  690. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "low_processor_usage_mode"), "set_low_processor_usage_mode", "is_in_low_processor_usage_mode");
  691. 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");
  692. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "delta_smoothing"), "set_delta_smoothing", "is_delta_smoothing_enabled");
  693. // Those default values need to be specified for the docs generator,
  694. // to avoid using values from the documentation writer's own OS instance.
  695. ADD_PROPERTY_DEFAULT("low_processor_usage_mode", false);
  696. ADD_PROPERTY_DEFAULT("low_processor_usage_mode_sleep_usec", 6900);
  697. BIND_ENUM_CONSTANT(RENDERING_DRIVER_VULKAN);
  698. BIND_ENUM_CONSTANT(RENDERING_DRIVER_OPENGL3);
  699. BIND_ENUM_CONSTANT(RENDERING_DRIVER_D3D12);
  700. BIND_ENUM_CONSTANT(RENDERING_DRIVER_METAL);
  701. BIND_ENUM_CONSTANT(SYSTEM_DIR_DESKTOP);
  702. BIND_ENUM_CONSTANT(SYSTEM_DIR_DCIM);
  703. BIND_ENUM_CONSTANT(SYSTEM_DIR_DOCUMENTS);
  704. BIND_ENUM_CONSTANT(SYSTEM_DIR_DOWNLOADS);
  705. BIND_ENUM_CONSTANT(SYSTEM_DIR_MOVIES);
  706. BIND_ENUM_CONSTANT(SYSTEM_DIR_MUSIC);
  707. BIND_ENUM_CONSTANT(SYSTEM_DIR_PICTURES);
  708. BIND_ENUM_CONSTANT(SYSTEM_DIR_RINGTONES);
  709. BIND_ENUM_CONSTANT(STD_HANDLE_INVALID);
  710. BIND_ENUM_CONSTANT(STD_HANDLE_CONSOLE);
  711. BIND_ENUM_CONSTANT(STD_HANDLE_FILE);
  712. BIND_ENUM_CONSTANT(STD_HANDLE_PIPE);
  713. BIND_ENUM_CONSTANT(STD_HANDLE_UNKNOWN);
  714. }
  715. OS::OS() {
  716. singleton = this;
  717. }
  718. OS::~OS() {
  719. if (singleton == this) {
  720. singleton = nullptr;
  721. }
  722. if (logger_bind) {
  723. logger_bind->clear();
  724. }
  725. }
  726. ////// Geometry2D //////
  727. Geometry2D *Geometry2D::get_singleton() {
  728. return singleton;
  729. }
  730. bool Geometry2D::is_point_in_circle(const Vector2 &p_point, const Vector2 &p_circle_pos, real_t p_circle_radius) {
  731. return ::Geometry2D::is_point_in_circle(p_point, p_circle_pos, p_circle_radius);
  732. }
  733. real_t Geometry2D::segment_intersects_circle(const Vector2 &p_from, const Vector2 &p_to, const Vector2 &p_circle_pos, real_t p_circle_radius) {
  734. return ::Geometry2D::segment_intersects_circle(p_from, p_to, p_circle_pos, p_circle_radius);
  735. }
  736. 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) {
  737. Vector2 result;
  738. if (::Geometry2D::segment_intersects_segment(p_from_a, p_to_a, p_from_b, p_to_b, &result)) {
  739. return result;
  740. } else {
  741. return Variant();
  742. }
  743. }
  744. 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) {
  745. Vector2 result;
  746. if (::Geometry2D::line_intersects_line(p_from_a, p_dir_a, p_from_b, p_dir_b, result)) {
  747. return result;
  748. } else {
  749. return Variant();
  750. }
  751. }
  752. Vector<Vector2> Geometry2D::get_closest_points_between_segments(const Vector2 &p1, const Vector2 &q1, const Vector2 &p2, const Vector2 &q2) {
  753. Vector2 r1, r2;
  754. ::Geometry2D::get_closest_points_between_segments(p1, q1, p2, q2, r1, r2);
  755. Vector<Vector2> r = { r1, r2 };
  756. return r;
  757. }
  758. Vector2 Geometry2D::get_closest_point_to_segment(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b) {
  759. return ::Geometry2D::get_closest_point_to_segment(p_point, p_a, p_b);
  760. }
  761. Vector2 Geometry2D::get_closest_point_to_segment_uncapped(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b) {
  762. return ::Geometry2D::get_closest_point_to_segment_uncapped(p_point, p_a, p_b);
  763. }
  764. bool Geometry2D::point_is_inside_triangle(const Vector2 &s, const Vector2 &a, const Vector2 &b, const Vector2 &c) const {
  765. return ::Geometry2D::is_point_in_triangle(s, a, b, c);
  766. }
  767. bool Geometry2D::is_polygon_clockwise(const Vector<Vector2> &p_polygon) {
  768. return ::Geometry2D::is_polygon_clockwise(p_polygon);
  769. }
  770. bool Geometry2D::is_point_in_polygon(const Point2 &p_point, const Vector<Vector2> &p_polygon) {
  771. return ::Geometry2D::is_point_in_polygon(p_point, p_polygon);
  772. }
  773. Vector<int> Geometry2D::triangulate_polygon(const Vector<Vector2> &p_polygon) {
  774. return ::Geometry2D::triangulate_polygon(p_polygon);
  775. }
  776. Vector<int> Geometry2D::triangulate_delaunay(const Vector<Vector2> &p_points) {
  777. return ::Geometry2D::triangulate_delaunay(p_points);
  778. }
  779. Vector<Point2> Geometry2D::convex_hull(const Vector<Point2> &p_points) {
  780. return ::Geometry2D::convex_hull(p_points);
  781. }
  782. TypedArray<PackedVector2Array> Geometry2D::decompose_polygon_in_convex(const Vector<Vector2> &p_polygon) {
  783. Vector<Vector<Point2>> decomp = ::Geometry2D::decompose_polygon_in_convex(p_polygon);
  784. TypedArray<PackedVector2Array> ret;
  785. for (int i = 0; i < decomp.size(); ++i) {
  786. ret.push_back(decomp[i]);
  787. }
  788. return ret;
  789. }
  790. TypedArray<PackedVector2Array> Geometry2D::merge_polygons(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
  791. Vector<Vector<Point2>> polys = ::Geometry2D::merge_polygons(p_polygon_a, p_polygon_b);
  792. TypedArray<PackedVector2Array> ret;
  793. for (int i = 0; i < polys.size(); ++i) {
  794. ret.push_back(polys[i]);
  795. }
  796. return ret;
  797. }
  798. TypedArray<PackedVector2Array> Geometry2D::clip_polygons(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
  799. Vector<Vector<Point2>> polys = ::Geometry2D::clip_polygons(p_polygon_a, p_polygon_b);
  800. TypedArray<PackedVector2Array> ret;
  801. for (int i = 0; i < polys.size(); ++i) {
  802. ret.push_back(polys[i]);
  803. }
  804. return ret;
  805. }
  806. TypedArray<PackedVector2Array> Geometry2D::intersect_polygons(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
  807. Vector<Vector<Point2>> polys = ::Geometry2D::intersect_polygons(p_polygon_a, p_polygon_b);
  808. TypedArray<PackedVector2Array> ret;
  809. for (int i = 0; i < polys.size(); ++i) {
  810. ret.push_back(polys[i]);
  811. }
  812. return ret;
  813. }
  814. TypedArray<PackedVector2Array> Geometry2D::exclude_polygons(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
  815. Vector<Vector<Point2>> polys = ::Geometry2D::exclude_polygons(p_polygon_a, p_polygon_b);
  816. TypedArray<PackedVector2Array> ret;
  817. for (int i = 0; i < polys.size(); ++i) {
  818. ret.push_back(polys[i]);
  819. }
  820. return ret;
  821. }
  822. TypedArray<PackedVector2Array> Geometry2D::clip_polyline_with_polygon(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) {
  823. Vector<Vector<Point2>> polys = ::Geometry2D::clip_polyline_with_polygon(p_polyline, p_polygon);
  824. TypedArray<PackedVector2Array> ret;
  825. for (int i = 0; i < polys.size(); ++i) {
  826. ret.push_back(polys[i]);
  827. }
  828. return ret;
  829. }
  830. TypedArray<PackedVector2Array> Geometry2D::intersect_polyline_with_polygon(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) {
  831. Vector<Vector<Point2>> polys = ::Geometry2D::intersect_polyline_with_polygon(p_polyline, p_polygon);
  832. TypedArray<PackedVector2Array> ret;
  833. for (int i = 0; i < polys.size(); ++i) {
  834. ret.push_back(polys[i]);
  835. }
  836. return ret;
  837. }
  838. TypedArray<PackedVector2Array> Geometry2D::offset_polygon(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type) {
  839. Vector<Vector<Point2>> polys = ::Geometry2D::offset_polygon(p_polygon, p_delta, ::Geometry2D::PolyJoinType(p_join_type));
  840. TypedArray<PackedVector2Array> ret;
  841. for (int i = 0; i < polys.size(); ++i) {
  842. ret.push_back(polys[i]);
  843. }
  844. return ret;
  845. }
  846. TypedArray<PackedVector2Array> Geometry2D::offset_polyline(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type, PolyEndType p_end_type) {
  847. Vector<Vector<Point2>> polys = ::Geometry2D::offset_polyline(p_polygon, p_delta, ::Geometry2D::PolyJoinType(p_join_type), ::Geometry2D::PolyEndType(p_end_type));
  848. TypedArray<PackedVector2Array> ret;
  849. for (int i = 0; i < polys.size(); ++i) {
  850. ret.push_back(polys[i]);
  851. }
  852. return ret;
  853. }
  854. Dictionary Geometry2D::make_atlas(const Vector<Size2> &p_rects) {
  855. Dictionary ret;
  856. Vector<Size2i> rects;
  857. for (int i = 0; i < p_rects.size(); i++) {
  858. rects.push_back(p_rects[i]);
  859. }
  860. Vector<Point2i> result;
  861. Size2i size;
  862. ::Geometry2D::make_atlas(rects, result, size);
  863. Vector<Point2> r_result;
  864. for (int i = 0; i < result.size(); i++) {
  865. r_result.push_back(result[i]);
  866. }
  867. ret["points"] = r_result;
  868. ret["size"] = size;
  869. return ret;
  870. }
  871. TypedArray<Point2i> Geometry2D::bresenham_line(const Point2i &p_from, const Point2i &p_to) {
  872. Vector<Point2i> points = ::Geometry2D::bresenham_line(p_from, p_to);
  873. TypedArray<Point2i> result;
  874. result.resize(points.size());
  875. for (int i = 0; i < points.size(); i++) {
  876. result[i] = points[i];
  877. }
  878. return result;
  879. }
  880. void Geometry2D::_bind_methods() {
  881. ClassDB::bind_method(D_METHOD("is_point_in_circle", "point", "circle_position", "circle_radius"), &Geometry2D::is_point_in_circle);
  882. ClassDB::bind_method(D_METHOD("segment_intersects_circle", "segment_from", "segment_to", "circle_position", "circle_radius"), &Geometry2D::segment_intersects_circle);
  883. ClassDB::bind_method(D_METHOD("segment_intersects_segment", "from_a", "to_a", "from_b", "to_b"), &Geometry2D::segment_intersects_segment);
  884. ClassDB::bind_method(D_METHOD("line_intersects_line", "from_a", "dir_a", "from_b", "dir_b"), &Geometry2D::line_intersects_line);
  885. ClassDB::bind_method(D_METHOD("get_closest_points_between_segments", "p1", "q1", "p2", "q2"), &Geometry2D::get_closest_points_between_segments);
  886. ClassDB::bind_method(D_METHOD("get_closest_point_to_segment", "point", "s1", "s2"), &Geometry2D::get_closest_point_to_segment);
  887. ClassDB::bind_method(D_METHOD("get_closest_point_to_segment_uncapped", "point", "s1", "s2"), &Geometry2D::get_closest_point_to_segment_uncapped);
  888. ClassDB::bind_method(D_METHOD("point_is_inside_triangle", "point", "a", "b", "c"), &Geometry2D::point_is_inside_triangle);
  889. ClassDB::bind_method(D_METHOD("is_polygon_clockwise", "polygon"), &Geometry2D::is_polygon_clockwise);
  890. ClassDB::bind_method(D_METHOD("is_point_in_polygon", "point", "polygon"), &Geometry2D::is_point_in_polygon);
  891. ClassDB::bind_method(D_METHOD("triangulate_polygon", "polygon"), &Geometry2D::triangulate_polygon);
  892. ClassDB::bind_method(D_METHOD("triangulate_delaunay", "points"), &Geometry2D::triangulate_delaunay);
  893. ClassDB::bind_method(D_METHOD("convex_hull", "points"), &Geometry2D::convex_hull);
  894. ClassDB::bind_method(D_METHOD("decompose_polygon_in_convex", "polygon"), &Geometry2D::decompose_polygon_in_convex);
  895. ClassDB::bind_method(D_METHOD("merge_polygons", "polygon_a", "polygon_b"), &Geometry2D::merge_polygons);
  896. ClassDB::bind_method(D_METHOD("clip_polygons", "polygon_a", "polygon_b"), &Geometry2D::clip_polygons);
  897. ClassDB::bind_method(D_METHOD("intersect_polygons", "polygon_a", "polygon_b"), &Geometry2D::intersect_polygons);
  898. ClassDB::bind_method(D_METHOD("exclude_polygons", "polygon_a", "polygon_b"), &Geometry2D::exclude_polygons);
  899. ClassDB::bind_method(D_METHOD("clip_polyline_with_polygon", "polyline", "polygon"), &Geometry2D::clip_polyline_with_polygon);
  900. ClassDB::bind_method(D_METHOD("intersect_polyline_with_polygon", "polyline", "polygon"), &Geometry2D::intersect_polyline_with_polygon);
  901. ClassDB::bind_method(D_METHOD("offset_polygon", "polygon", "delta", "join_type"), &Geometry2D::offset_polygon, DEFVAL(JOIN_SQUARE));
  902. ClassDB::bind_method(D_METHOD("offset_polyline", "polyline", "delta", "join_type", "end_type"), &Geometry2D::offset_polyline, DEFVAL(JOIN_SQUARE), DEFVAL(END_SQUARE));
  903. ClassDB::bind_method(D_METHOD("make_atlas", "sizes"), &Geometry2D::make_atlas);
  904. ClassDB::bind_method(D_METHOD("bresenham_line", "from", "to"), &Geometry2D::bresenham_line);
  905. BIND_ENUM_CONSTANT(OPERATION_UNION);
  906. BIND_ENUM_CONSTANT(OPERATION_DIFFERENCE);
  907. BIND_ENUM_CONSTANT(OPERATION_INTERSECTION);
  908. BIND_ENUM_CONSTANT(OPERATION_XOR);
  909. BIND_ENUM_CONSTANT(JOIN_SQUARE);
  910. BIND_ENUM_CONSTANT(JOIN_ROUND);
  911. BIND_ENUM_CONSTANT(JOIN_MITER);
  912. BIND_ENUM_CONSTANT(END_POLYGON);
  913. BIND_ENUM_CONSTANT(END_JOINED);
  914. BIND_ENUM_CONSTANT(END_BUTT);
  915. BIND_ENUM_CONSTANT(END_SQUARE);
  916. BIND_ENUM_CONSTANT(END_ROUND);
  917. }
  918. ////// Geometry3D //////
  919. Geometry3D *Geometry3D::get_singleton() {
  920. return singleton;
  921. }
  922. Vector<Vector3> Geometry3D::compute_convex_mesh_points(const TypedArray<Plane> &p_planes) {
  923. Vector<Plane> planes_vec;
  924. int size = p_planes.size();
  925. planes_vec.resize(size);
  926. for (int i = 0; i < size; ++i) {
  927. planes_vec.set(i, p_planes[i]);
  928. }
  929. Variant ret = ::Geometry3D::compute_convex_mesh_points(planes_vec.ptr(), size);
  930. return ret;
  931. }
  932. TypedArray<Plane> Geometry3D::build_box_planes(const Vector3 &p_extents) {
  933. Variant ret = ::Geometry3D::build_box_planes(p_extents);
  934. return ret;
  935. }
  936. TypedArray<Plane> Geometry3D::build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis) {
  937. Variant ret = ::Geometry3D::build_cylinder_planes(p_radius, p_height, p_sides, p_axis);
  938. return ret;
  939. }
  940. TypedArray<Plane> Geometry3D::build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis) {
  941. Variant ret = ::Geometry3D::build_capsule_planes(p_radius, p_height, p_sides, p_lats, p_axis);
  942. return ret;
  943. }
  944. Vector<Vector3> Geometry3D::get_closest_points_between_segments(const Vector3 &p1, const Vector3 &p2, const Vector3 &q1, const Vector3 &q2) {
  945. Vector3 r1, r2;
  946. ::Geometry3D::get_closest_points_between_segments(p1, p2, q1, q2, r1, r2);
  947. Vector<Vector3> r = { r1, r2 };
  948. return r;
  949. }
  950. Vector3 Geometry3D::get_closest_point_to_segment(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b) {
  951. return ::Geometry3D::get_closest_point_to_segment(p_point, p_a, p_b);
  952. }
  953. Vector3 Geometry3D::get_closest_point_to_segment_uncapped(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b) {
  954. return ::Geometry3D::get_closest_point_to_segment_uncapped(p_point, p_a, p_b);
  955. }
  956. Vector3 Geometry3D::get_triangle_barycentric_coords(const Vector3 &p_point, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2) {
  957. Vector3 res = ::Geometry3D::triangle_get_barycentric_coords(p_v0, p_v1, p_v2, p_point);
  958. return res;
  959. }
  960. 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) {
  961. Vector3 res;
  962. if (::Geometry3D::ray_intersects_triangle(p_from, p_dir, p_v0, p_v1, p_v2, &res)) {
  963. return res;
  964. } else {
  965. return Variant();
  966. }
  967. }
  968. 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) {
  969. Vector3 res;
  970. if (::Geometry3D::segment_intersects_triangle(p_from, p_to, p_v0, p_v1, p_v2, &res)) {
  971. return res;
  972. } else {
  973. return Variant();
  974. }
  975. }
  976. Vector<Vector3> Geometry3D::segment_intersects_sphere(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_sphere_pos, real_t p_sphere_radius) {
  977. Vector<Vector3> r;
  978. Vector3 res, norm;
  979. if (!::Geometry3D::segment_intersects_sphere(p_from, p_to, p_sphere_pos, p_sphere_radius, &res, &norm)) {
  980. return r;
  981. }
  982. r.resize(2);
  983. r.set(0, res);
  984. r.set(1, norm);
  985. return r;
  986. }
  987. Vector<Vector3> Geometry3D::segment_intersects_cylinder(const Vector3 &p_from, const Vector3 &p_to, float p_height, float p_radius) {
  988. Vector<Vector3> r;
  989. Vector3 res, norm;
  990. if (!::Geometry3D::segment_intersects_cylinder(p_from, p_to, p_height, p_radius, &res, &norm)) {
  991. return r;
  992. }
  993. r.resize(2);
  994. r.set(0, res);
  995. r.set(1, norm);
  996. return r;
  997. }
  998. Vector<Vector3> Geometry3D::segment_intersects_convex(const Vector3 &p_from, const Vector3 &p_to, const TypedArray<Plane> &p_planes) {
  999. Vector<Vector3> r;
  1000. Vector3 res, norm;
  1001. Vector<Plane> planes = Variant(p_planes);
  1002. if (!::Geometry3D::segment_intersects_convex(p_from, p_to, planes.ptr(), planes.size(), &res, &norm)) {
  1003. return r;
  1004. }
  1005. r.resize(2);
  1006. r.set(0, res);
  1007. r.set(1, norm);
  1008. return r;
  1009. }
  1010. Vector<Vector3> Geometry3D::clip_polygon(const Vector<Vector3> &p_points, const Plane &p_plane) {
  1011. return ::Geometry3D::clip_polygon(p_points, p_plane);
  1012. }
  1013. Vector<int32_t> Geometry3D::tetrahedralize_delaunay(const Vector<Vector3> &p_points) {
  1014. return ::Geometry3D::tetrahedralize_delaunay(p_points);
  1015. }
  1016. void Geometry3D::_bind_methods() {
  1017. ClassDB::bind_method(D_METHOD("compute_convex_mesh_points", "planes"), &Geometry3D::compute_convex_mesh_points);
  1018. ClassDB::bind_method(D_METHOD("build_box_planes", "extents"), &Geometry3D::build_box_planes);
  1019. ClassDB::bind_method(D_METHOD("build_cylinder_planes", "radius", "height", "sides", "axis"), &Geometry3D::build_cylinder_planes, DEFVAL(Vector3::AXIS_Z));
  1020. ClassDB::bind_method(D_METHOD("build_capsule_planes", "radius", "height", "sides", "lats", "axis"), &Geometry3D::build_capsule_planes, DEFVAL(Vector3::AXIS_Z));
  1021. ClassDB::bind_method(D_METHOD("get_closest_points_between_segments", "p1", "p2", "q1", "q2"), &Geometry3D::get_closest_points_between_segments);
  1022. ClassDB::bind_method(D_METHOD("get_closest_point_to_segment", "point", "s1", "s2"), &Geometry3D::get_closest_point_to_segment);
  1023. ClassDB::bind_method(D_METHOD("get_closest_point_to_segment_uncapped", "point", "s1", "s2"), &Geometry3D::get_closest_point_to_segment_uncapped);
  1024. ClassDB::bind_method(D_METHOD("get_triangle_barycentric_coords", "point", "a", "b", "c"), &Geometry3D::get_triangle_barycentric_coords);
  1025. ClassDB::bind_method(D_METHOD("ray_intersects_triangle", "from", "dir", "a", "b", "c"), &Geometry3D::ray_intersects_triangle);
  1026. ClassDB::bind_method(D_METHOD("segment_intersects_triangle", "from", "to", "a", "b", "c"), &Geometry3D::segment_intersects_triangle);
  1027. ClassDB::bind_method(D_METHOD("segment_intersects_sphere", "from", "to", "sphere_position", "sphere_radius"), &Geometry3D::segment_intersects_sphere);
  1028. ClassDB::bind_method(D_METHOD("segment_intersects_cylinder", "from", "to", "height", "radius"), &Geometry3D::segment_intersects_cylinder);
  1029. ClassDB::bind_method(D_METHOD("segment_intersects_convex", "from", "to", "planes"), &Geometry3D::segment_intersects_convex);
  1030. ClassDB::bind_method(D_METHOD("clip_polygon", "points", "plane"), &Geometry3D::clip_polygon);
  1031. ClassDB::bind_method(D_METHOD("tetrahedralize_delaunay", "points"), &Geometry3D::tetrahedralize_delaunay);
  1032. }
  1033. ////// Marshalls //////
  1034. Marshalls *Marshalls::get_singleton() {
  1035. return singleton;
  1036. }
  1037. String Marshalls::variant_to_base64(const Variant &p_var, bool p_full_objects) {
  1038. int len;
  1039. Error err = encode_variant(p_var, nullptr, len, p_full_objects);
  1040. ERR_FAIL_COND_V_MSG(err != OK, "", "Error when trying to encode Variant.");
  1041. Vector<uint8_t> buff;
  1042. buff.resize(len);
  1043. uint8_t *w = buff.ptrw();
  1044. err = encode_variant(p_var, &w[0], len, p_full_objects);
  1045. ERR_FAIL_COND_V_MSG(err != OK, "", "Error when trying to encode Variant.");
  1046. String ret = CryptoCore::b64_encode_str(&w[0], len);
  1047. ERR_FAIL_COND_V(ret.is_empty(), ret);
  1048. return ret;
  1049. }
  1050. Variant Marshalls::base64_to_variant(const String &p_str, bool p_allow_objects) {
  1051. int strlen = p_str.length();
  1052. CharString cstr = p_str.ascii();
  1053. Vector<uint8_t> buf;
  1054. buf.resize(strlen / 4 * 3 + 1);
  1055. uint8_t *w = buf.ptrw();
  1056. size_t len = 0;
  1057. ERR_FAIL_COND_V(CryptoCore::b64_decode(&w[0], buf.size(), &len, (unsigned char *)cstr.get_data(), strlen) != OK, Variant());
  1058. Variant v;
  1059. Error err = decode_variant(v, &w[0], len, nullptr, p_allow_objects);
  1060. ERR_FAIL_COND_V_MSG(err != OK, Variant(), "Error when trying to decode Variant.");
  1061. return v;
  1062. }
  1063. String Marshalls::raw_to_base64(const Vector<uint8_t> &p_arr) {
  1064. String ret = CryptoCore::b64_encode_str(p_arr.ptr(), p_arr.size());
  1065. ERR_FAIL_COND_V(ret.is_empty(), ret);
  1066. return ret;
  1067. }
  1068. Vector<uint8_t> Marshalls::base64_to_raw(const String &p_str) {
  1069. int strlen = p_str.length();
  1070. CharString cstr = p_str.ascii();
  1071. size_t arr_len = 0;
  1072. Vector<uint8_t> buf;
  1073. {
  1074. buf.resize(strlen / 4 * 3 + 1);
  1075. uint8_t *w = buf.ptrw();
  1076. ERR_FAIL_COND_V(CryptoCore::b64_decode(&w[0], buf.size(), &arr_len, (unsigned char *)cstr.get_data(), strlen) != OK, Vector<uint8_t>());
  1077. }
  1078. buf.resize(arr_len);
  1079. return buf;
  1080. }
  1081. String Marshalls::utf8_to_base64(const String &p_str) {
  1082. if (p_str.is_empty()) {
  1083. return String();
  1084. }
  1085. CharString cstr = p_str.utf8();
  1086. String ret = CryptoCore::b64_encode_str((unsigned char *)cstr.get_data(), cstr.length());
  1087. ERR_FAIL_COND_V(ret.is_empty(), ret);
  1088. return ret;
  1089. }
  1090. String Marshalls::base64_to_utf8(const String &p_str) {
  1091. int strlen = p_str.length();
  1092. CharString cstr = p_str.ascii();
  1093. Vector<uint8_t> buf;
  1094. buf.resize(strlen / 4 * 3 + 1 + 1);
  1095. uint8_t *w = buf.ptrw();
  1096. size_t len = 0;
  1097. ERR_FAIL_COND_V(CryptoCore::b64_decode(&w[0], buf.size(), &len, (unsigned char *)cstr.get_data(), strlen) != OK, String());
  1098. w[len] = 0;
  1099. String ret = String::utf8((char *)&w[0]);
  1100. return ret;
  1101. }
  1102. void Marshalls::_bind_methods() {
  1103. ClassDB::bind_method(D_METHOD("variant_to_base64", "variant", "full_objects"), &Marshalls::variant_to_base64, DEFVAL(false));
  1104. ClassDB::bind_method(D_METHOD("base64_to_variant", "base64_str", "allow_objects"), &Marshalls::base64_to_variant, DEFVAL(false));
  1105. ClassDB::bind_method(D_METHOD("raw_to_base64", "array"), &Marshalls::raw_to_base64);
  1106. ClassDB::bind_method(D_METHOD("base64_to_raw", "base64_str"), &Marshalls::base64_to_raw);
  1107. ClassDB::bind_method(D_METHOD("utf8_to_base64", "utf8_str"), &Marshalls::utf8_to_base64);
  1108. ClassDB::bind_method(D_METHOD("base64_to_utf8", "base64_str"), &Marshalls::base64_to_utf8);
  1109. }
  1110. ////// Semaphore //////
  1111. void Semaphore::wait() {
  1112. semaphore.wait();
  1113. }
  1114. bool Semaphore::try_wait() {
  1115. return semaphore.try_wait();
  1116. }
  1117. void Semaphore::post(int p_count) {
  1118. ERR_FAIL_COND(p_count <= 0);
  1119. semaphore.post(p_count);
  1120. }
  1121. void Semaphore::_bind_methods() {
  1122. ClassDB::bind_method(D_METHOD("wait"), &Semaphore::wait);
  1123. ClassDB::bind_method(D_METHOD("try_wait"), &Semaphore::try_wait);
  1124. ClassDB::bind_method(D_METHOD("post", "count"), &Semaphore::post, DEFVAL(1));
  1125. }
  1126. ////// Mutex //////
  1127. void Mutex::lock() {
  1128. mutex.lock();
  1129. }
  1130. bool Mutex::try_lock() {
  1131. return mutex.try_lock();
  1132. }
  1133. void Mutex::unlock() {
  1134. mutex.unlock();
  1135. }
  1136. void Mutex::_bind_methods() {
  1137. ClassDB::bind_method(D_METHOD("lock"), &Mutex::lock);
  1138. ClassDB::bind_method(D_METHOD("try_lock"), &Mutex::try_lock);
  1139. ClassDB::bind_method(D_METHOD("unlock"), &Mutex::unlock);
  1140. }
  1141. ////// Thread //////
  1142. void Thread::_start_func(void *ud) {
  1143. Ref<Thread> *tud = (Ref<Thread> *)ud;
  1144. Ref<Thread> t = *tud;
  1145. memdelete(tud);
  1146. if (!t->target_callable.is_valid()) {
  1147. t->running.clear();
  1148. 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()));
  1149. }
  1150. // Finding out a suitable name for the thread can involve querying a node, if the target is one.
  1151. // We know this is safe (unless the user is causing life cycle race conditions, which would be a bug on their part).
  1152. set_current_thread_safe_for_nodes(true);
  1153. String func_name = t->target_callable.is_custom() ? t->target_callable.get_custom()->get_as_text() : String(t->target_callable.get_method());
  1154. set_current_thread_safe_for_nodes(false);
  1155. ::Thread::set_name(func_name);
  1156. // To avoid a circular reference between the thread and the script which can possibly contain a reference
  1157. // to the thread, we will do the call (keeping a reference up to that point) and then break chains with it.
  1158. // When the call returns, we will reference the thread again if possible.
  1159. ObjectID th_instance_id = t->get_instance_id();
  1160. Callable target_callable = t->target_callable;
  1161. String id = t->get_id();
  1162. t = Ref<Thread>();
  1163. Callable::CallError ce;
  1164. Variant ret;
  1165. target_callable.callp(nullptr, 0, ret, ce);
  1166. // If script properly kept a reference to the thread, we should be able to re-reference it now
  1167. // (well, or if the call failed, since we had to break chains anyway because the outcome isn't known upfront).
  1168. t = ObjectDB::get_ref<Thread>(th_instance_id);
  1169. if (t.is_valid()) {
  1170. t->ret = ret;
  1171. t->running.clear();
  1172. } else {
  1173. // We could print a warning here, but the Thread object will be eventually destroyed
  1174. // noticing wait_to_finish() hasn't been called on it, and it will print a warning itself.
  1175. }
  1176. if (ce.error != Callable::CallError::CALL_OK) {
  1177. ERR_FAIL_MSG(vformat("Could not call function '%s' to start thread %s: %s.", func_name, id, Variant::get_callable_error_text(target_callable, nullptr, 0, ce)));
  1178. }
  1179. }
  1180. Error Thread::start(const Callable &p_callable, Priority p_priority) {
  1181. ERR_FAIL_COND_V_MSG(is_started(), ERR_ALREADY_IN_USE, "Thread already started.");
  1182. ERR_FAIL_COND_V(!p_callable.is_valid(), ERR_INVALID_PARAMETER);
  1183. ERR_FAIL_INDEX_V(p_priority, PRIORITY_MAX, ERR_INVALID_PARAMETER);
  1184. ret = Variant();
  1185. target_callable = p_callable;
  1186. running.set();
  1187. Ref<Thread> *ud = memnew(Ref<Thread>(this));
  1188. ::Thread::Settings s;
  1189. s.priority = (::Thread::Priority)p_priority;
  1190. thread.start(_start_func, ud, s);
  1191. return OK;
  1192. }
  1193. String Thread::get_id() const {
  1194. return itos(thread.get_id());
  1195. }
  1196. bool Thread::is_started() const {
  1197. return thread.is_started();
  1198. }
  1199. bool Thread::is_alive() const {
  1200. return running.is_set();
  1201. }
  1202. Variant Thread::wait_to_finish() {
  1203. ERR_FAIL_COND_V_MSG(!is_started(), Variant(), "Thread must have been started to wait for its completion.");
  1204. thread.wait_to_finish();
  1205. Variant r = ret;
  1206. target_callable = Callable();
  1207. return r;
  1208. }
  1209. void Thread::set_thread_safety_checks_enabled(bool p_enabled) {
  1210. ERR_FAIL_COND_MSG(::Thread::is_main_thread(), "This call is forbidden on the main thread.");
  1211. set_current_thread_safe_for_nodes(!p_enabled);
  1212. }
  1213. bool Thread::is_main_thread() {
  1214. return ::Thread::is_main_thread();
  1215. }
  1216. void Thread::_bind_methods() {
  1217. ClassDB::bind_method(D_METHOD("start", "callable", "priority"), &Thread::start, DEFVAL(PRIORITY_NORMAL));
  1218. ClassDB::bind_method(D_METHOD("get_id"), &Thread::get_id);
  1219. ClassDB::bind_method(D_METHOD("is_started"), &Thread::is_started);
  1220. ClassDB::bind_method(D_METHOD("is_alive"), &Thread::is_alive);
  1221. ClassDB::bind_method(D_METHOD("wait_to_finish"), &Thread::wait_to_finish);
  1222. ClassDB::bind_static_method("Thread", D_METHOD("set_thread_safety_checks_enabled", "enabled"), &Thread::set_thread_safety_checks_enabled);
  1223. ClassDB::bind_static_method("Thread", D_METHOD("is_main_thread"), &Thread::is_main_thread);
  1224. BIND_ENUM_CONSTANT(PRIORITY_LOW);
  1225. BIND_ENUM_CONSTANT(PRIORITY_NORMAL);
  1226. BIND_ENUM_CONSTANT(PRIORITY_HIGH);
  1227. }
  1228. namespace Special {
  1229. ////// ClassDB //////
  1230. PackedStringArray ClassDB::get_class_list() const {
  1231. LocalVector<StringName> classes;
  1232. ::ClassDB::get_class_list(classes);
  1233. PackedStringArray ret;
  1234. ret.resize(classes.size());
  1235. String *ptrw = ret.ptrw();
  1236. int idx = 0;
  1237. for (const StringName &cls : classes) {
  1238. ptrw[idx] = cls;
  1239. idx++;
  1240. }
  1241. return ret;
  1242. }
  1243. PackedStringArray ClassDB::get_inheriters_from_class(const StringName &p_class) const {
  1244. LocalVector<StringName> classes;
  1245. ::ClassDB::get_inheriters_from_class(p_class, classes);
  1246. PackedStringArray ret;
  1247. ret.resize(classes.size());
  1248. int idx = 0;
  1249. for (const StringName &E : classes) {
  1250. ret.set(idx++, E);
  1251. }
  1252. return ret;
  1253. }
  1254. StringName ClassDB::get_parent_class(const StringName &p_class) const {
  1255. return ::ClassDB::get_parent_class(p_class);
  1256. }
  1257. bool ClassDB::class_exists(const StringName &p_class) const {
  1258. return ::ClassDB::class_exists(p_class);
  1259. }
  1260. bool ClassDB::is_parent_class(const StringName &p_class, const StringName &p_inherits) const {
  1261. return ::ClassDB::is_parent_class(p_class, p_inherits);
  1262. }
  1263. bool ClassDB::can_instantiate(const StringName &p_class) const {
  1264. return ::ClassDB::can_instantiate(p_class);
  1265. }
  1266. Variant ClassDB::instantiate(const StringName &p_class) const {
  1267. Object *obj = ::ClassDB::instantiate(p_class);
  1268. if (!obj) {
  1269. return Variant();
  1270. }
  1271. RefCounted *r = Object::cast_to<RefCounted>(obj);
  1272. if (r) {
  1273. return Ref<RefCounted>(r);
  1274. } else {
  1275. return obj;
  1276. }
  1277. }
  1278. ClassDB::APIType ClassDB::class_get_api_type(const StringName &p_class) const {
  1279. ::ClassDB::APIType api_type = ::ClassDB::get_api_type(p_class);
  1280. return (APIType)api_type;
  1281. }
  1282. bool ClassDB::class_has_signal(const StringName &p_class, const StringName &p_signal) const {
  1283. return ::ClassDB::has_signal(p_class, p_signal);
  1284. }
  1285. Dictionary ClassDB::class_get_signal(const StringName &p_class, const StringName &p_signal) const {
  1286. MethodInfo signal;
  1287. if (::ClassDB::get_signal(p_class, p_signal, &signal)) {
  1288. return signal.operator Dictionary();
  1289. } else {
  1290. return Dictionary();
  1291. }
  1292. }
  1293. TypedArray<Dictionary> ClassDB::class_get_signal_list(const StringName &p_class, bool p_no_inheritance) const {
  1294. List<MethodInfo> signals;
  1295. ::ClassDB::get_signal_list(p_class, &signals, p_no_inheritance);
  1296. TypedArray<Dictionary> ret;
  1297. for (const MethodInfo &E : signals) {
  1298. ret.push_back(E.operator Dictionary());
  1299. }
  1300. return ret;
  1301. }
  1302. TypedArray<Dictionary> ClassDB::class_get_property_list(const StringName &p_class, bool p_no_inheritance) const {
  1303. List<PropertyInfo> plist;
  1304. ::ClassDB::get_property_list(p_class, &plist, p_no_inheritance);
  1305. TypedArray<Dictionary> ret;
  1306. for (const PropertyInfo &E : plist) {
  1307. ret.push_back(E.operator Dictionary());
  1308. }
  1309. return ret;
  1310. }
  1311. StringName ClassDB::class_get_property_getter(const StringName &p_class, const StringName &p_property) {
  1312. return ::ClassDB::get_property_getter(p_class, p_property);
  1313. }
  1314. StringName ClassDB::class_get_property_setter(const StringName &p_class, const StringName &p_property) {
  1315. return ::ClassDB::get_property_setter(p_class, p_property);
  1316. }
  1317. Variant ClassDB::class_get_property(Object *p_object, const StringName &p_property) const {
  1318. Variant ret;
  1319. ::ClassDB::get_property(p_object, p_property, ret);
  1320. return ret;
  1321. }
  1322. Error ClassDB::class_set_property(Object *p_object, const StringName &p_property, const Variant &p_value) const {
  1323. Variant ret;
  1324. bool valid;
  1325. if (!::ClassDB::set_property(p_object, p_property, p_value, &valid)) {
  1326. return ERR_UNAVAILABLE;
  1327. } else if (!valid) {
  1328. return ERR_INVALID_DATA;
  1329. }
  1330. return OK;
  1331. }
  1332. Variant ClassDB::class_get_property_default_value(const StringName &p_class, const StringName &p_property) const {
  1333. bool valid;
  1334. Variant ret = ::ClassDB::class_get_default_property_value(p_class, p_property, &valid);
  1335. if (valid) {
  1336. return ret;
  1337. }
  1338. return Variant();
  1339. }
  1340. bool ClassDB::class_has_method(const StringName &p_class, const StringName &p_method, bool p_no_inheritance) const {
  1341. return ::ClassDB::has_method(p_class, p_method, p_no_inheritance);
  1342. }
  1343. int ClassDB::class_get_method_argument_count(const StringName &p_class, const StringName &p_method, bool p_no_inheritance) const {
  1344. return ::ClassDB::get_method_argument_count(p_class, p_method, nullptr, p_no_inheritance);
  1345. }
  1346. TypedArray<Dictionary> ClassDB::class_get_method_list(const StringName &p_class, bool p_no_inheritance) const {
  1347. List<MethodInfo> methods;
  1348. ::ClassDB::get_method_list(p_class, &methods, p_no_inheritance);
  1349. TypedArray<Dictionary> ret;
  1350. for (const MethodInfo &E : methods) {
  1351. #ifdef DEBUG_ENABLED
  1352. ret.push_back(E.operator Dictionary());
  1353. #else
  1354. Dictionary dict;
  1355. dict["name"] = E.name;
  1356. ret.push_back(dict);
  1357. #endif // DEBUG_ENABLED
  1358. }
  1359. return ret;
  1360. }
  1361. Variant ClassDB::class_call_static(const Variant **p_arguments, int p_argcount, Callable::CallError &r_call_error) {
  1362. if (p_argcount < 2) {
  1363. r_call_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS;
  1364. return Variant::NIL;
  1365. }
  1366. if (!p_arguments[0]->is_string() || !p_arguments[1]->is_string()) {
  1367. r_call_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
  1368. return Variant::NIL;
  1369. }
  1370. StringName class_ = *p_arguments[0];
  1371. StringName method = *p_arguments[1];
  1372. const MethodBind *bind = ::ClassDB::get_method(class_, method);
  1373. ERR_FAIL_NULL_V_MSG(bind, Variant::NIL, "Cannot find static method.");
  1374. ERR_FAIL_COND_V_MSG(!bind->is_static(), Variant::NIL, "Method is not static.");
  1375. return bind->call(nullptr, p_arguments + 2, p_argcount - 2, r_call_error);
  1376. }
  1377. PackedStringArray ClassDB::class_get_integer_constant_list(const StringName &p_class, bool p_no_inheritance) const {
  1378. List<String> constants;
  1379. ::ClassDB::get_integer_constant_list(p_class, &constants, p_no_inheritance);
  1380. PackedStringArray ret;
  1381. ret.resize(constants.size());
  1382. int idx = 0;
  1383. for (const String &E : constants) {
  1384. ret.set(idx++, E);
  1385. }
  1386. return ret;
  1387. }
  1388. bool ClassDB::class_has_integer_constant(const StringName &p_class, const StringName &p_name) const {
  1389. bool success;
  1390. ::ClassDB::get_integer_constant(p_class, p_name, &success);
  1391. return success;
  1392. }
  1393. int64_t ClassDB::class_get_integer_constant(const StringName &p_class, const StringName &p_name) const {
  1394. bool found;
  1395. int64_t c = ::ClassDB::get_integer_constant(p_class, p_name, &found);
  1396. ERR_FAIL_COND_V(!found, 0);
  1397. return c;
  1398. }
  1399. bool ClassDB::class_has_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance) const {
  1400. return ::ClassDB::has_enum(p_class, p_name, p_no_inheritance);
  1401. }
  1402. PackedStringArray ClassDB::class_get_enum_list(const StringName &p_class, bool p_no_inheritance) const {
  1403. List<StringName> enums;
  1404. ::ClassDB::get_enum_list(p_class, &enums, p_no_inheritance);
  1405. PackedStringArray ret;
  1406. ret.resize(enums.size());
  1407. int idx = 0;
  1408. for (const StringName &E : enums) {
  1409. ret.set(idx++, E);
  1410. }
  1411. return ret;
  1412. }
  1413. PackedStringArray ClassDB::class_get_enum_constants(const StringName &p_class, const StringName &p_enum, bool p_no_inheritance) const {
  1414. List<StringName> constants;
  1415. ::ClassDB::get_enum_constants(p_class, p_enum, &constants, p_no_inheritance);
  1416. PackedStringArray ret;
  1417. ret.resize(constants.size());
  1418. int idx = 0;
  1419. for (const StringName &E : constants) {
  1420. ret.set(idx++, E);
  1421. }
  1422. return ret;
  1423. }
  1424. StringName ClassDB::class_get_integer_constant_enum(const StringName &p_class, const StringName &p_name, bool p_no_inheritance) const {
  1425. return ::ClassDB::get_integer_constant_enum(p_class, p_name, p_no_inheritance);
  1426. }
  1427. bool ClassDB::is_class_enum_bitfield(const StringName &p_class, const StringName &p_enum, bool p_no_inheritance) const {
  1428. return ::ClassDB::is_enum_bitfield(p_class, p_enum, p_no_inheritance);
  1429. }
  1430. bool ClassDB::is_class_enabled(const StringName &p_class) const {
  1431. return ::ClassDB::is_class_enabled(p_class);
  1432. }
  1433. #ifdef TOOLS_ENABLED
  1434. void ClassDB::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
  1435. const String pf = p_function;
  1436. bool first_argument_is_class = false;
  1437. if (p_idx == 0) {
  1438. first_argument_is_class = (pf == "get_inheriters_from_class" || pf == "get_parent_class" ||
  1439. pf == "class_exists" || pf == "can_instantiate" || pf == "instantiate" ||
  1440. pf == "class_has_signal" || pf == "class_get_signal" || pf == "class_get_signal_list" ||
  1441. pf == "class_get_property_list" || pf == "class_get_property" || pf == "class_set_property" ||
  1442. pf == "class_has_method" || pf == "class_get_method_list" ||
  1443. pf == "class_get_integer_constant_list" || pf == "class_has_integer_constant" || pf == "class_get_integer_constant" ||
  1444. pf == "class_has_enum" || pf == "class_get_enum_list" || pf == "class_get_enum_constants" || pf == "class_get_integer_constant_enum" ||
  1445. pf == "is_class_enabled" || pf == "is_class_enum_bitfield" || pf == "class_get_api_type");
  1446. }
  1447. if (first_argument_is_class || pf == "is_parent_class") {
  1448. LocalVector<StringName> classes;
  1449. ::ClassDB::get_class_list(classes);
  1450. for (const StringName &E : classes) {
  1451. if (::ClassDB::is_class_exposed(E)) {
  1452. r_options->push_back(E.operator String().quote());
  1453. }
  1454. }
  1455. }
  1456. Object::get_argument_options(p_function, p_idx, r_options);
  1457. }
  1458. #endif
  1459. void ClassDB::_bind_methods() {
  1460. ::ClassDB::bind_method(D_METHOD("get_class_list"), &ClassDB::get_class_list);
  1461. ::ClassDB::bind_method(D_METHOD("get_inheriters_from_class", "class"), &ClassDB::get_inheriters_from_class);
  1462. ::ClassDB::bind_method(D_METHOD("get_parent_class", "class"), &ClassDB::get_parent_class);
  1463. ::ClassDB::bind_method(D_METHOD("class_exists", "class"), &ClassDB::class_exists);
  1464. ::ClassDB::bind_method(D_METHOD("is_parent_class", "class", "inherits"), &ClassDB::is_parent_class);
  1465. ::ClassDB::bind_method(D_METHOD("can_instantiate", "class"), &ClassDB::can_instantiate);
  1466. ::ClassDB::bind_method(D_METHOD("instantiate", "class"), &ClassDB::instantiate);
  1467. ::ClassDB::bind_method(D_METHOD("class_get_api_type", "class"), &ClassDB::class_get_api_type);
  1468. ::ClassDB::bind_method(D_METHOD("class_has_signal", "class", "signal"), &ClassDB::class_has_signal);
  1469. ::ClassDB::bind_method(D_METHOD("class_get_signal", "class", "signal"), &ClassDB::class_get_signal);
  1470. ::ClassDB::bind_method(D_METHOD("class_get_signal_list", "class", "no_inheritance"), &ClassDB::class_get_signal_list, DEFVAL(false));
  1471. ::ClassDB::bind_method(D_METHOD("class_get_property_list", "class", "no_inheritance"), &ClassDB::class_get_property_list, DEFVAL(false));
  1472. ::ClassDB::bind_method(D_METHOD("class_get_property_getter", "class", "property"), &ClassDB::class_get_property_getter);
  1473. ::ClassDB::bind_method(D_METHOD("class_get_property_setter", "class", "property"), &ClassDB::class_get_property_setter);
  1474. ::ClassDB::bind_method(D_METHOD("class_get_property", "object", "property"), &ClassDB::class_get_property);
  1475. ::ClassDB::bind_method(D_METHOD("class_set_property", "object", "property", "value"), &ClassDB::class_set_property);
  1476. ::ClassDB::bind_method(D_METHOD("class_get_property_default_value", "class", "property"), &ClassDB::class_get_property_default_value);
  1477. ::ClassDB::bind_method(D_METHOD("class_has_method", "class", "method", "no_inheritance"), &ClassDB::class_has_method, DEFVAL(false));
  1478. ::ClassDB::bind_method(D_METHOD("class_get_method_argument_count", "class", "method", "no_inheritance"), &ClassDB::class_get_method_argument_count, DEFVAL(false));
  1479. ::ClassDB::bind_method(D_METHOD("class_get_method_list", "class", "no_inheritance"), &ClassDB::class_get_method_list, DEFVAL(false));
  1480. ::ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "class_call_static", &ClassDB::class_call_static, MethodInfo("class_call_static", PropertyInfo(Variant::STRING_NAME, "class"), PropertyInfo(Variant::STRING_NAME, "method")));
  1481. ::ClassDB::bind_method(D_METHOD("class_get_integer_constant_list", "class", "no_inheritance"), &ClassDB::class_get_integer_constant_list, DEFVAL(false));
  1482. ::ClassDB::bind_method(D_METHOD("class_has_integer_constant", "class", "name"), &ClassDB::class_has_integer_constant);
  1483. ::ClassDB::bind_method(D_METHOD("class_get_integer_constant", "class", "name"), &ClassDB::class_get_integer_constant);
  1484. ::ClassDB::bind_method(D_METHOD("class_has_enum", "class", "name", "no_inheritance"), &ClassDB::class_has_enum, DEFVAL(false));
  1485. ::ClassDB::bind_method(D_METHOD("class_get_enum_list", "class", "no_inheritance"), &ClassDB::class_get_enum_list, DEFVAL(false));
  1486. ::ClassDB::bind_method(D_METHOD("class_get_enum_constants", "class", "enum", "no_inheritance"), &ClassDB::class_get_enum_constants, DEFVAL(false));
  1487. ::ClassDB::bind_method(D_METHOD("class_get_integer_constant_enum", "class", "name", "no_inheritance"), &ClassDB::class_get_integer_constant_enum, DEFVAL(false));
  1488. ::ClassDB::bind_method(D_METHOD("is_class_enum_bitfield", "class", "enum", "no_inheritance"), &ClassDB::is_class_enum_bitfield, DEFVAL(false));
  1489. ::ClassDB::bind_method(D_METHOD("is_class_enabled", "class"), &ClassDB::is_class_enabled);
  1490. BIND_ENUM_CONSTANT(API_CORE);
  1491. BIND_ENUM_CONSTANT(API_EDITOR);
  1492. BIND_ENUM_CONSTANT(API_EXTENSION);
  1493. BIND_ENUM_CONSTANT(API_EDITOR_EXTENSION);
  1494. BIND_ENUM_CONSTANT(API_NONE);
  1495. }
  1496. } // namespace Special
  1497. ////// Engine //////
  1498. void Engine::set_physics_ticks_per_second(int p_ips) {
  1499. ::Engine::get_singleton()->set_physics_ticks_per_second(p_ips);
  1500. }
  1501. int Engine::get_physics_ticks_per_second() const {
  1502. return ::Engine::get_singleton()->get_physics_ticks_per_second();
  1503. }
  1504. void Engine::set_max_physics_steps_per_frame(int p_max_physics_steps) {
  1505. ::Engine::get_singleton()->set_max_physics_steps_per_frame(p_max_physics_steps);
  1506. }
  1507. int Engine::get_max_physics_steps_per_frame() const {
  1508. return ::Engine::get_singleton()->get_max_physics_steps_per_frame();
  1509. }
  1510. void Engine::set_physics_jitter_fix(double p_threshold) {
  1511. ::Engine::get_singleton()->set_physics_jitter_fix(p_threshold);
  1512. }
  1513. double Engine::get_physics_jitter_fix() const {
  1514. return ::Engine::get_singleton()->get_physics_jitter_fix();
  1515. }
  1516. double Engine::get_physics_interpolation_fraction() const {
  1517. return ::Engine::get_singleton()->get_physics_interpolation_fraction();
  1518. }
  1519. void Engine::set_max_fps(int p_fps) {
  1520. ::Engine::get_singleton()->set_max_fps(p_fps);
  1521. }
  1522. int Engine::get_max_fps() const {
  1523. return ::Engine::get_singleton()->get_max_fps();
  1524. }
  1525. double Engine::get_frames_per_second() const {
  1526. return ::Engine::get_singleton()->get_frames_per_second();
  1527. }
  1528. uint64_t Engine::get_physics_frames() const {
  1529. return ::Engine::get_singleton()->get_physics_frames();
  1530. }
  1531. uint64_t Engine::get_process_frames() const {
  1532. return ::Engine::get_singleton()->get_process_frames();
  1533. }
  1534. void Engine::set_time_scale(double p_scale) {
  1535. ::Engine::get_singleton()->set_time_scale(p_scale);
  1536. }
  1537. double Engine::get_time_scale() {
  1538. return ::Engine::get_singleton()->get_time_scale();
  1539. }
  1540. int Engine::get_frames_drawn() {
  1541. return ::Engine::get_singleton()->get_frames_drawn();
  1542. }
  1543. MainLoop *Engine::get_main_loop() const {
  1544. // Needs to remain in OS, since it's actually OS that interacts with it, but it's better exposed here
  1545. return ::OS::get_singleton()->get_main_loop();
  1546. }
  1547. Dictionary Engine::get_version_info() const {
  1548. return ::Engine::get_singleton()->get_version_info();
  1549. }
  1550. Dictionary Engine::get_author_info() const {
  1551. return ::Engine::get_singleton()->get_author_info();
  1552. }
  1553. TypedArray<Dictionary> Engine::get_copyright_info() const {
  1554. return ::Engine::get_singleton()->get_copyright_info();
  1555. }
  1556. Dictionary Engine::get_donor_info() const {
  1557. return ::Engine::get_singleton()->get_donor_info();
  1558. }
  1559. Dictionary Engine::get_license_info() const {
  1560. return ::Engine::get_singleton()->get_license_info();
  1561. }
  1562. String Engine::get_license_text() const {
  1563. return ::Engine::get_singleton()->get_license_text();
  1564. }
  1565. String Engine::get_architecture_name() const {
  1566. return ::Engine::get_singleton()->get_architecture_name();
  1567. }
  1568. bool Engine::is_in_physics_frame() const {
  1569. return ::Engine::get_singleton()->is_in_physics_frame();
  1570. }
  1571. bool Engine::has_singleton(const StringName &p_name) const {
  1572. return ::Engine::get_singleton()->has_singleton(p_name);
  1573. }
  1574. Object *Engine::get_singleton_object(const StringName &p_name) const {
  1575. return ::Engine::get_singleton()->get_singleton_object(p_name);
  1576. }
  1577. void Engine::register_singleton(const StringName &p_name, Object *p_object) {
  1578. ERR_FAIL_COND_MSG(has_singleton(p_name), vformat("Singleton already registered: '%s'.", String(p_name)));
  1579. ERR_FAIL_COND_MSG(!String(p_name).is_valid_ascii_identifier(), vformat("Singleton name is not a valid identifier: '%s'.", p_name));
  1580. ::Engine::Singleton s;
  1581. s.class_name = p_name;
  1582. s.name = p_name;
  1583. s.ptr = p_object;
  1584. s.user_created = true;
  1585. ::Engine::get_singleton()->add_singleton(s);
  1586. }
  1587. void Engine::unregister_singleton(const StringName &p_name) {
  1588. ERR_FAIL_COND_MSG(!has_singleton(p_name), vformat("Attempt to remove unregistered singleton: '%s'.", String(p_name)));
  1589. ERR_FAIL_COND_MSG(!::Engine::get_singleton()->is_singleton_user_created(p_name), vformat("Attempt to remove non-user created singleton: '%s'.", String(p_name)));
  1590. ::Engine::get_singleton()->remove_singleton(p_name);
  1591. }
  1592. Vector<String> Engine::get_singleton_list() const {
  1593. List<::Engine::Singleton> singletons;
  1594. ::Engine::get_singleton()->get_singletons(&singletons);
  1595. Vector<String> ret;
  1596. for (const ::Engine::Singleton &E : singletons) {
  1597. ret.push_back(E.name);
  1598. }
  1599. return ret;
  1600. }
  1601. Error Engine::register_script_language(ScriptLanguage *p_language) {
  1602. return ScriptServer::register_language(p_language);
  1603. }
  1604. Error Engine::unregister_script_language(const ScriptLanguage *p_language) {
  1605. return ScriptServer::unregister_language(p_language);
  1606. }
  1607. int Engine::get_script_language_count() {
  1608. return ScriptServer::get_language_count();
  1609. }
  1610. ScriptLanguage *Engine::get_script_language(int p_index) const {
  1611. return ScriptServer::get_language(p_index);
  1612. }
  1613. TypedArray<ScriptBacktrace> Engine::capture_script_backtraces(bool p_include_variables) const {
  1614. Vector<Ref<ScriptBacktrace>> backtraces = ScriptServer::capture_script_backtraces(p_include_variables);
  1615. TypedArray<ScriptBacktrace> result;
  1616. result.resize(backtraces.size());
  1617. for (int i = 0; i < backtraces.size(); i++) {
  1618. result[i] = backtraces[i];
  1619. }
  1620. return result;
  1621. }
  1622. void Engine::set_editor_hint(bool p_enabled) {
  1623. ::Engine::get_singleton()->set_editor_hint(p_enabled);
  1624. }
  1625. bool Engine::is_editor_hint() const {
  1626. return ::Engine::get_singleton()->is_editor_hint();
  1627. }
  1628. bool Engine::is_embedded_in_editor() const {
  1629. return ::Engine::get_singleton()->is_embedded_in_editor();
  1630. }
  1631. String Engine::get_write_movie_path() const {
  1632. return ::Engine::get_singleton()->get_write_movie_path();
  1633. }
  1634. void Engine::set_print_to_stdout(bool p_enabled) {
  1635. ::Engine::get_singleton()->set_print_to_stdout(p_enabled);
  1636. }
  1637. bool Engine::is_printing_to_stdout() const {
  1638. return ::Engine::get_singleton()->is_printing_to_stdout();
  1639. }
  1640. void Engine::set_print_error_messages(bool p_enabled) {
  1641. ::Engine::get_singleton()->set_print_error_messages(p_enabled);
  1642. }
  1643. bool Engine::is_printing_error_messages() const {
  1644. return ::Engine::get_singleton()->is_printing_error_messages();
  1645. }
  1646. #ifdef TOOLS_ENABLED
  1647. void Engine::get_argument_options(const StringName &p_function, int p_idx, List<String> *r_options) const {
  1648. const String pf = p_function;
  1649. if (p_idx == 0 && (pf == "has_singleton" || pf == "get_singleton" || pf == "unregister_singleton")) {
  1650. for (const String &E : get_singleton_list()) {
  1651. r_options->push_back(E.quote());
  1652. }
  1653. }
  1654. Object::get_argument_options(p_function, p_idx, r_options);
  1655. }
  1656. #endif
  1657. void Engine::_bind_methods() {
  1658. ClassDB::bind_method(D_METHOD("set_physics_ticks_per_second", "physics_ticks_per_second"), &Engine::set_physics_ticks_per_second);
  1659. ClassDB::bind_method(D_METHOD("get_physics_ticks_per_second"), &Engine::get_physics_ticks_per_second);
  1660. ClassDB::bind_method(D_METHOD("set_max_physics_steps_per_frame", "max_physics_steps"), &Engine::set_max_physics_steps_per_frame);
  1661. ClassDB::bind_method(D_METHOD("get_max_physics_steps_per_frame"), &Engine::get_max_physics_steps_per_frame);
  1662. ClassDB::bind_method(D_METHOD("set_physics_jitter_fix", "physics_jitter_fix"), &Engine::set_physics_jitter_fix);
  1663. ClassDB::bind_method(D_METHOD("get_physics_jitter_fix"), &Engine::get_physics_jitter_fix);
  1664. ClassDB::bind_method(D_METHOD("get_physics_interpolation_fraction"), &Engine::get_physics_interpolation_fraction);
  1665. ClassDB::bind_method(D_METHOD("set_max_fps", "max_fps"), &Engine::set_max_fps);
  1666. ClassDB::bind_method(D_METHOD("get_max_fps"), &Engine::get_max_fps);
  1667. ClassDB::bind_method(D_METHOD("set_time_scale", "time_scale"), &Engine::set_time_scale);
  1668. ClassDB::bind_method(D_METHOD("get_time_scale"), &Engine::get_time_scale);
  1669. ClassDB::bind_method(D_METHOD("get_frames_drawn"), &Engine::get_frames_drawn);
  1670. ClassDB::bind_method(D_METHOD("get_frames_per_second"), &Engine::get_frames_per_second);
  1671. ClassDB::bind_method(D_METHOD("get_physics_frames"), &Engine::get_physics_frames);
  1672. ClassDB::bind_method(D_METHOD("get_process_frames"), &Engine::get_process_frames);
  1673. ClassDB::bind_method(D_METHOD("get_main_loop"), &Engine::get_main_loop);
  1674. ClassDB::bind_method(D_METHOD("get_version_info"), &Engine::get_version_info);
  1675. ClassDB::bind_method(D_METHOD("get_author_info"), &Engine::get_author_info);
  1676. ClassDB::bind_method(D_METHOD("get_copyright_info"), &Engine::get_copyright_info);
  1677. ClassDB::bind_method(D_METHOD("get_donor_info"), &Engine::get_donor_info);
  1678. ClassDB::bind_method(D_METHOD("get_license_info"), &Engine::get_license_info);
  1679. ClassDB::bind_method(D_METHOD("get_license_text"), &Engine::get_license_text);
  1680. ClassDB::bind_method(D_METHOD("get_architecture_name"), &Engine::get_architecture_name);
  1681. ClassDB::bind_method(D_METHOD("is_in_physics_frame"), &Engine::is_in_physics_frame);
  1682. ClassDB::bind_method(D_METHOD("has_singleton", "name"), &Engine::has_singleton);
  1683. ClassDB::bind_method(D_METHOD("get_singleton", "name"), &Engine::get_singleton_object);
  1684. ClassDB::bind_method(D_METHOD("register_singleton", "name", "instance"), &Engine::register_singleton);
  1685. ClassDB::bind_method(D_METHOD("unregister_singleton", "name"), &Engine::unregister_singleton);
  1686. ClassDB::bind_method(D_METHOD("get_singleton_list"), &Engine::get_singleton_list);
  1687. ClassDB::bind_method(D_METHOD("register_script_language", "language"), &Engine::register_script_language);
  1688. ClassDB::bind_method(D_METHOD("unregister_script_language", "language"), &Engine::unregister_script_language);
  1689. ClassDB::bind_method(D_METHOD("get_script_language_count"), &Engine::get_script_language_count);
  1690. ClassDB::bind_method(D_METHOD("get_script_language", "index"), &Engine::get_script_language);
  1691. ClassDB::bind_method(D_METHOD("capture_script_backtraces", "include_variables"), &Engine::capture_script_backtraces, DEFVAL(false));
  1692. ClassDB::bind_method(D_METHOD("is_editor_hint"), &Engine::is_editor_hint);
  1693. ClassDB::bind_method(D_METHOD("is_embedded_in_editor"), &Engine::is_embedded_in_editor);
  1694. ClassDB::bind_method(D_METHOD("get_write_movie_path"), &Engine::get_write_movie_path);
  1695. ClassDB::bind_method(D_METHOD("set_print_to_stdout", "enabled"), &Engine::set_print_to_stdout);
  1696. ClassDB::bind_method(D_METHOD("is_printing_to_stdout"), &Engine::is_printing_to_stdout);
  1697. ClassDB::bind_method(D_METHOD("set_print_error_messages", "enabled"), &Engine::set_print_error_messages);
  1698. ClassDB::bind_method(D_METHOD("is_printing_error_messages"), &Engine::is_printing_error_messages);
  1699. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "print_error_messages"), "set_print_error_messages", "is_printing_error_messages");
  1700. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "print_to_stdout"), "set_print_to_stdout", "is_printing_to_stdout");
  1701. ADD_PROPERTY(PropertyInfo(Variant::INT, "physics_ticks_per_second"), "set_physics_ticks_per_second", "get_physics_ticks_per_second");
  1702. ADD_PROPERTY(PropertyInfo(Variant::INT, "max_physics_steps_per_frame"), "set_max_physics_steps_per_frame", "get_max_physics_steps_per_frame");
  1703. ADD_PROPERTY(PropertyInfo(Variant::INT, "max_fps"), "set_max_fps", "get_max_fps");
  1704. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "time_scale"), "set_time_scale", "get_time_scale");
  1705. ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "physics_jitter_fix"), "set_physics_jitter_fix", "get_physics_jitter_fix");
  1706. }
  1707. ////// EngineDebugger //////
  1708. bool EngineDebugger::is_active() {
  1709. return ::EngineDebugger::is_active();
  1710. }
  1711. void EngineDebugger::register_profiler(const StringName &p_name, Ref<EngineProfiler> p_profiler) {
  1712. ERR_FAIL_COND(p_profiler.is_null());
  1713. ERR_FAIL_COND_MSG(p_profiler->is_bound(), "Profiler already registered.");
  1714. ERR_FAIL_COND_MSG(profilers.has(p_name) || has_profiler(p_name), vformat("Profiler name already in use: '%s'.", p_name));
  1715. Error err = p_profiler->bind(p_name);
  1716. ERR_FAIL_COND_MSG(err != OK, vformat("Profiler failed to register with error: %d.", err));
  1717. profilers.insert(p_name, p_profiler);
  1718. }
  1719. void EngineDebugger::unregister_profiler(const StringName &p_name) {
  1720. ERR_FAIL_COND_MSG(!profilers.has(p_name), vformat("Profiler not registered: '%s'.", p_name));
  1721. profilers[p_name]->unbind();
  1722. profilers.erase(p_name);
  1723. }
  1724. bool EngineDebugger::is_profiling(const StringName &p_name) {
  1725. return ::EngineDebugger::is_profiling(p_name);
  1726. }
  1727. bool EngineDebugger::has_profiler(const StringName &p_name) {
  1728. return ::EngineDebugger::has_profiler(p_name);
  1729. }
  1730. void EngineDebugger::profiler_add_frame_data(const StringName &p_name, const Array &p_data) {
  1731. ::EngineDebugger::profiler_add_frame_data(p_name, p_data);
  1732. }
  1733. void EngineDebugger::profiler_enable(const StringName &p_name, bool p_enabled, const Array &p_opts) {
  1734. if (::EngineDebugger::get_singleton()) {
  1735. ::EngineDebugger::get_singleton()->profiler_enable(p_name, p_enabled, p_opts);
  1736. }
  1737. }
  1738. void EngineDebugger::register_message_capture(const StringName &p_name, const Callable &p_callable) {
  1739. ERR_FAIL_COND_MSG(captures.has(p_name) || has_capture(p_name), vformat("Capture already registered: '%s'.", p_name));
  1740. captures.insert(p_name, p_callable);
  1741. Callable &c = captures[p_name];
  1742. ::EngineDebugger::Capture capture(&c, &EngineDebugger::call_capture);
  1743. ::EngineDebugger::register_message_capture(p_name, capture);
  1744. }
  1745. void EngineDebugger::unregister_message_capture(const StringName &p_name) {
  1746. ERR_FAIL_COND_MSG(!captures.has(p_name), vformat("Capture not registered: '%s'.", p_name));
  1747. ::EngineDebugger::unregister_message_capture(p_name);
  1748. captures.erase(p_name);
  1749. }
  1750. bool EngineDebugger::has_capture(const StringName &p_name) {
  1751. return ::EngineDebugger::has_capture(p_name);
  1752. }
  1753. void EngineDebugger::send_message(const String &p_msg, const Array &p_data) {
  1754. ERR_FAIL_COND_MSG(!::EngineDebugger::is_active(), "Can't send message. No active debugger");
  1755. ::EngineDebugger::get_singleton()->send_message(p_msg, p_data);
  1756. }
  1757. void EngineDebugger::debug(bool p_can_continue, bool p_is_error_breakpoint) {
  1758. ERR_FAIL_COND_MSG(!::EngineDebugger::is_active(), "Can't send debug. No active debugger");
  1759. ::EngineDebugger::get_singleton()->debug(p_can_continue, p_is_error_breakpoint);
  1760. }
  1761. void EngineDebugger::script_debug(ScriptLanguage *p_lang, bool p_can_continue, bool p_is_error_breakpoint) {
  1762. ERR_FAIL_COND_MSG(!::EngineDebugger::get_script_debugger(), "Can't send debug. No active debugger");
  1763. ::EngineDebugger::get_script_debugger()->debug(p_lang, p_can_continue, p_is_error_breakpoint);
  1764. }
  1765. Error EngineDebugger::call_capture(void *p_user, const String &p_cmd, const Array &p_data, bool &r_captured) {
  1766. Callable &capture = *(Callable *)p_user;
  1767. if (!capture.is_valid()) {
  1768. return FAILED;
  1769. }
  1770. Variant cmd = p_cmd, data = p_data;
  1771. const Variant *args[2] = { &cmd, &data };
  1772. Variant retval;
  1773. Callable::CallError err;
  1774. capture.callp(args, 2, retval, err);
  1775. ERR_FAIL_COND_V_MSG(err.error != Callable::CallError::CALL_OK, FAILED, vformat("Error calling 'capture' to callable: %s.", Variant::get_callable_error_text(capture, args, 2, err)));
  1776. ERR_FAIL_COND_V_MSG(retval.get_type() != Variant::BOOL, FAILED, vformat("Error calling 'capture' to callable: '%s'. Return type is not bool.", String(capture)));
  1777. r_captured = retval;
  1778. return OK;
  1779. }
  1780. void EngineDebugger::line_poll() {
  1781. ERR_FAIL_COND_MSG(!::EngineDebugger::is_active(), "Can't poll. No active debugger");
  1782. ::EngineDebugger::get_singleton()->line_poll();
  1783. }
  1784. void EngineDebugger::set_lines_left(int p_lines) {
  1785. ERR_FAIL_COND_MSG(!::EngineDebugger::get_script_debugger(), "Can't set lines left. No active debugger");
  1786. ::EngineDebugger::get_script_debugger()->set_lines_left(p_lines);
  1787. }
  1788. int EngineDebugger::get_lines_left() const {
  1789. ERR_FAIL_COND_V_MSG(!::EngineDebugger::get_script_debugger(), 0, "Can't get lines left. No active debugger");
  1790. return ::EngineDebugger::get_script_debugger()->get_lines_left();
  1791. }
  1792. void EngineDebugger::set_depth(int p_depth) {
  1793. ERR_FAIL_COND_MSG(!::EngineDebugger::get_script_debugger(), "Can't set depth. No active debugger");
  1794. ::EngineDebugger::get_script_debugger()->set_depth(p_depth);
  1795. }
  1796. int EngineDebugger::get_depth() const {
  1797. ERR_FAIL_COND_V_MSG(!::EngineDebugger::get_script_debugger(), 0, "Can't get depth. No active debugger");
  1798. return ::EngineDebugger::get_script_debugger()->get_depth();
  1799. }
  1800. bool EngineDebugger::is_breakpoint(int p_line, const StringName &p_source) const {
  1801. ERR_FAIL_COND_V_MSG(!::EngineDebugger::get_script_debugger(), false, "Can't check breakpoint. No active debugger");
  1802. return ::EngineDebugger::get_script_debugger()->is_breakpoint(p_line, p_source);
  1803. }
  1804. bool EngineDebugger::is_skipping_breakpoints() const {
  1805. ERR_FAIL_COND_V_MSG(!::EngineDebugger::get_script_debugger(), false, "Can't check skipping breakpoint. No active debugger");
  1806. return ::EngineDebugger::get_script_debugger()->is_skipping_breakpoints();
  1807. }
  1808. void EngineDebugger::insert_breakpoint(int p_line, const StringName &p_source) {
  1809. ERR_FAIL_COND_MSG(!::EngineDebugger::get_script_debugger(), "Can't insert breakpoint. No active debugger");
  1810. ::EngineDebugger::get_script_debugger()->insert_breakpoint(p_line, p_source);
  1811. }
  1812. void EngineDebugger::remove_breakpoint(int p_line, const StringName &p_source) {
  1813. ERR_FAIL_COND_MSG(!::EngineDebugger::get_script_debugger(), "Can't remove breakpoint. No active debugger");
  1814. ::EngineDebugger::get_script_debugger()->remove_breakpoint(p_line, p_source);
  1815. }
  1816. void EngineDebugger::clear_breakpoints() {
  1817. ERR_FAIL_COND_MSG(!::EngineDebugger::get_script_debugger(), "Can't clear breakpoints. No active debugger");
  1818. ::EngineDebugger::get_script_debugger()->clear_breakpoints();
  1819. }
  1820. EngineDebugger::~EngineDebugger() {
  1821. for (const KeyValue<StringName, Callable> &E : captures) {
  1822. ::EngineDebugger::unregister_message_capture(E.key);
  1823. }
  1824. captures.clear();
  1825. }
  1826. void EngineDebugger::_bind_methods() {
  1827. ClassDB::bind_method(D_METHOD("is_active"), &EngineDebugger::is_active);
  1828. ClassDB::bind_method(D_METHOD("register_profiler", "name", "profiler"), &EngineDebugger::register_profiler);
  1829. ClassDB::bind_method(D_METHOD("unregister_profiler", "name"), &EngineDebugger::unregister_profiler);
  1830. ClassDB::bind_method(D_METHOD("is_profiling", "name"), &EngineDebugger::is_profiling);
  1831. ClassDB::bind_method(D_METHOD("has_profiler", "name"), &EngineDebugger::has_profiler);
  1832. ClassDB::bind_method(D_METHOD("profiler_add_frame_data", "name", "data"), &EngineDebugger::profiler_add_frame_data);
  1833. ClassDB::bind_method(D_METHOD("profiler_enable", "name", "enable", "arguments"), &EngineDebugger::profiler_enable, DEFVAL(Array()));
  1834. ClassDB::bind_method(D_METHOD("register_message_capture", "name", "callable"), &EngineDebugger::register_message_capture);
  1835. ClassDB::bind_method(D_METHOD("unregister_message_capture", "name"), &EngineDebugger::unregister_message_capture);
  1836. ClassDB::bind_method(D_METHOD("has_capture", "name"), &EngineDebugger::has_capture);
  1837. ClassDB::bind_method(D_METHOD("line_poll"), &EngineDebugger::line_poll);
  1838. ClassDB::bind_method(D_METHOD("send_message", "message", "data"), &EngineDebugger::send_message);
  1839. ClassDB::bind_method(D_METHOD("debug", "can_continue", "is_error_breakpoint"), &EngineDebugger::debug, DEFVAL(true), DEFVAL(false));
  1840. ClassDB::bind_method(D_METHOD("script_debug", "language", "can_continue", "is_error_breakpoint"), &EngineDebugger::script_debug, DEFVAL(true), DEFVAL(false));
  1841. ClassDB::bind_method(D_METHOD("set_lines_left", "lines"), &EngineDebugger::set_lines_left);
  1842. ClassDB::bind_method(D_METHOD("get_lines_left"), &EngineDebugger::get_lines_left);
  1843. ClassDB::bind_method(D_METHOD("set_depth", "depth"), &EngineDebugger::set_depth);
  1844. ClassDB::bind_method(D_METHOD("get_depth"), &EngineDebugger::get_depth);
  1845. ClassDB::bind_method(D_METHOD("is_breakpoint", "line", "source"), &EngineDebugger::is_breakpoint);
  1846. ClassDB::bind_method(D_METHOD("is_skipping_breakpoints"), &EngineDebugger::is_skipping_breakpoints);
  1847. ClassDB::bind_method(D_METHOD("insert_breakpoint", "line", "source"), &EngineDebugger::insert_breakpoint);
  1848. ClassDB::bind_method(D_METHOD("remove_breakpoint", "line", "source"), &EngineDebugger::remove_breakpoint);
  1849. ClassDB::bind_method(D_METHOD("clear_breakpoints"), &EngineDebugger::clear_breakpoints);
  1850. }
  1851. } // namespace CoreBind