core_bind.cpp 87 KB

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