core_bind.cpp 107 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306
  1. /*************************************************************************/
  2. /* core_bind.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2021 Juan Linietsky, Ariel Manzur. */
  9. /* Copyright (c) 2014-2021 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/crypto/crypto_core.h"
  32. #include "core/io/file_access_compressed.h"
  33. #include "core/io/file_access_encrypted.h"
  34. #include "core/io/json.h"
  35. #include "core/io/marshalls.h"
  36. #include "core/math/geometry.h"
  37. #include "core/os/keyboard.h"
  38. #include "core/os/os.h"
  39. #include "core/project_settings.h"
  40. /**
  41. * Time constants borrowed from loc_time.h
  42. */
  43. #define EPOCH_YR 1970 /* EPOCH = Jan 1 1970 00:00:00 */
  44. #define SECS_DAY (24L * 60L * 60L)
  45. #define LEAPYEAR(year) (!((year) % 4) && (((year) % 100) || !((year) % 400)))
  46. #define YEARSIZE(year) (LEAPYEAR(year) ? 366 : 365)
  47. #define SECOND_KEY "second"
  48. #define MINUTE_KEY "minute"
  49. #define HOUR_KEY "hour"
  50. #define DAY_KEY "day"
  51. #define MONTH_KEY "month"
  52. #define YEAR_KEY "year"
  53. #define WEEKDAY_KEY "weekday"
  54. #define DST_KEY "dst"
  55. /// Table of number of days in each month (for regular year and leap year)
  56. static const unsigned int MONTH_DAYS_TABLE[2][12] = {
  57. { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
  58. { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
  59. };
  60. _ResourceLoader *_ResourceLoader::singleton = NULL;
  61. Ref<ResourceInteractiveLoader> _ResourceLoader::load_interactive(const String &p_path, const String &p_type_hint) {
  62. return ResourceLoader::load_interactive(p_path, p_type_hint);
  63. }
  64. RES _ResourceLoader::load(const String &p_path, const String &p_type_hint, bool p_no_cache) {
  65. Error err = OK;
  66. RES ret = ResourceLoader::load(p_path, p_type_hint, p_no_cache, &err);
  67. ERR_FAIL_COND_V_MSG(err != OK, ret, "Error loading resource: '" + p_path + "'.");
  68. return ret;
  69. }
  70. PoolVector<String> _ResourceLoader::get_recognized_extensions_for_type(const String &p_type) {
  71. List<String> exts;
  72. ResourceLoader::get_recognized_extensions_for_type(p_type, &exts);
  73. PoolVector<String> ret;
  74. for (List<String>::Element *E = exts.front(); E; E = E->next()) {
  75. ret.push_back(E->get());
  76. }
  77. return ret;
  78. }
  79. void _ResourceLoader::set_abort_on_missing_resources(bool p_abort) {
  80. ResourceLoader::set_abort_on_missing_resources(p_abort);
  81. }
  82. PoolStringArray _ResourceLoader::get_dependencies(const String &p_path) {
  83. List<String> deps;
  84. ResourceLoader::get_dependencies(p_path, &deps);
  85. PoolStringArray ret;
  86. for (List<String>::Element *E = deps.front(); E; E = E->next()) {
  87. ret.push_back(E->get());
  88. }
  89. return ret;
  90. };
  91. #ifndef DISABLE_DEPRECATED
  92. bool _ResourceLoader::has(const String &p_path) {
  93. WARN_PRINTS("ResourceLoader.has() is deprecated, please replace it with the equivalent has_cached() or the new exists().");
  94. return has_cached(p_path);
  95. }
  96. #endif // DISABLE_DEPRECATED
  97. bool _ResourceLoader::has_cached(const String &p_path) {
  98. String local_path = ProjectSettings::get_singleton()->localize_path(p_path);
  99. return ResourceCache::has(local_path);
  100. }
  101. bool _ResourceLoader::exists(const String &p_path, const String &p_type_hint) {
  102. return ResourceLoader::exists(p_path, p_type_hint);
  103. }
  104. void _ResourceLoader::_bind_methods() {
  105. ClassDB::bind_method(D_METHOD("load_interactive", "path", "type_hint"), &_ResourceLoader::load_interactive, DEFVAL(""));
  106. ClassDB::bind_method(D_METHOD("load", "path", "type_hint", "no_cache"), &_ResourceLoader::load, DEFVAL(""), DEFVAL(false));
  107. ClassDB::bind_method(D_METHOD("get_recognized_extensions_for_type", "type"), &_ResourceLoader::get_recognized_extensions_for_type);
  108. ClassDB::bind_method(D_METHOD("set_abort_on_missing_resources", "abort"), &_ResourceLoader::set_abort_on_missing_resources);
  109. ClassDB::bind_method(D_METHOD("get_dependencies", "path"), &_ResourceLoader::get_dependencies);
  110. ClassDB::bind_method(D_METHOD("has_cached", "path"), &_ResourceLoader::has_cached);
  111. ClassDB::bind_method(D_METHOD("exists", "path", "type_hint"), &_ResourceLoader::exists, DEFVAL(""));
  112. #ifndef DISABLE_DEPRECATED
  113. ClassDB::bind_method(D_METHOD("has", "path"), &_ResourceLoader::has);
  114. #endif // DISABLE_DEPRECATED
  115. }
  116. _ResourceLoader::_ResourceLoader() {
  117. singleton = this;
  118. }
  119. Error _ResourceSaver::save(const String &p_path, const RES &p_resource, SaverFlags p_flags) {
  120. ERR_FAIL_COND_V_MSG(p_resource.is_null(), ERR_INVALID_PARAMETER, "Can't save empty resource to path '" + String(p_path) + "'.");
  121. return ResourceSaver::save(p_path, p_resource, p_flags);
  122. }
  123. PoolVector<String> _ResourceSaver::get_recognized_extensions(const RES &p_resource) {
  124. ERR_FAIL_COND_V_MSG(p_resource.is_null(), PoolVector<String>(), "It's not a reference to a valid Resource object.");
  125. List<String> exts;
  126. ResourceSaver::get_recognized_extensions(p_resource, &exts);
  127. PoolVector<String> ret;
  128. for (List<String>::Element *E = exts.front(); E; E = E->next()) {
  129. ret.push_back(E->get());
  130. }
  131. return ret;
  132. }
  133. _ResourceSaver *_ResourceSaver::singleton = NULL;
  134. void _ResourceSaver::_bind_methods() {
  135. ClassDB::bind_method(D_METHOD("save", "path", "resource", "flags"), &_ResourceSaver::save, DEFVAL(0));
  136. ClassDB::bind_method(D_METHOD("get_recognized_extensions", "type"), &_ResourceSaver::get_recognized_extensions);
  137. BIND_ENUM_CONSTANT(FLAG_RELATIVE_PATHS);
  138. BIND_ENUM_CONSTANT(FLAG_BUNDLE_RESOURCES);
  139. BIND_ENUM_CONSTANT(FLAG_CHANGE_PATH);
  140. BIND_ENUM_CONSTANT(FLAG_OMIT_EDITOR_PROPERTIES);
  141. BIND_ENUM_CONSTANT(FLAG_SAVE_BIG_ENDIAN);
  142. BIND_ENUM_CONSTANT(FLAG_COMPRESS);
  143. BIND_ENUM_CONSTANT(FLAG_REPLACE_SUBRESOURCE_PATHS);
  144. }
  145. _ResourceSaver::_ResourceSaver() {
  146. singleton = this;
  147. }
  148. /////////////////OS
  149. void _OS::global_menu_add_item(const String &p_menu, const String &p_label, const Variant &p_signal, const Variant &p_meta) {
  150. OS::get_singleton()->global_menu_add_item(p_menu, p_label, p_signal, p_meta);
  151. }
  152. void _OS::global_menu_add_separator(const String &p_menu) {
  153. OS::get_singleton()->global_menu_add_separator(p_menu);
  154. }
  155. void _OS::global_menu_remove_item(const String &p_menu, int p_idx) {
  156. OS::get_singleton()->global_menu_remove_item(p_menu, p_idx);
  157. }
  158. void _OS::global_menu_clear(const String &p_menu) {
  159. OS::get_singleton()->global_menu_clear(p_menu);
  160. }
  161. Point2 _OS::get_mouse_position() const {
  162. return OS::get_singleton()->get_mouse_position();
  163. }
  164. void _OS::set_window_title(const String &p_title) {
  165. OS::get_singleton()->set_window_title(p_title);
  166. }
  167. void _OS::set_window_mouse_passthrough(const PoolVector2Array &p_region) {
  168. OS::get_singleton()->set_window_mouse_passthrough(p_region);
  169. }
  170. int _OS::get_mouse_button_state() const {
  171. return OS::get_singleton()->get_mouse_button_state();
  172. }
  173. String _OS::get_unique_id() const {
  174. return OS::get_singleton()->get_unique_id();
  175. }
  176. bool _OS::has_touchscreen_ui_hint() const {
  177. return OS::get_singleton()->has_touchscreen_ui_hint();
  178. }
  179. void _OS::set_clipboard(const String &p_text) {
  180. OS::get_singleton()->set_clipboard(p_text);
  181. }
  182. String _OS::get_clipboard() const {
  183. return OS::get_singleton()->get_clipboard();
  184. }
  185. int _OS::get_video_driver_count() const {
  186. return OS::get_singleton()->get_video_driver_count();
  187. }
  188. String _OS::get_video_driver_name(VideoDriver p_driver) const {
  189. return OS::get_singleton()->get_video_driver_name((int)p_driver);
  190. }
  191. _OS::VideoDriver _OS::get_current_video_driver() const {
  192. return (VideoDriver)OS::get_singleton()->get_current_video_driver();
  193. }
  194. int _OS::get_audio_driver_count() const {
  195. return OS::get_singleton()->get_audio_driver_count();
  196. }
  197. String _OS::get_audio_driver_name(int p_driver) const {
  198. return OS::get_singleton()->get_audio_driver_name(p_driver);
  199. }
  200. PoolStringArray _OS::get_connected_midi_inputs() {
  201. return OS::get_singleton()->get_connected_midi_inputs();
  202. }
  203. void _OS::open_midi_inputs() {
  204. OS::get_singleton()->open_midi_inputs();
  205. }
  206. void _OS::close_midi_inputs() {
  207. OS::get_singleton()->close_midi_inputs();
  208. }
  209. void _OS::set_video_mode(const Size2 &p_size, bool p_fullscreen, bool p_resizeable, int p_screen) {
  210. OS::VideoMode vm;
  211. vm.width = p_size.width;
  212. vm.height = p_size.height;
  213. vm.fullscreen = p_fullscreen;
  214. vm.resizable = p_resizeable;
  215. OS::get_singleton()->set_video_mode(vm, p_screen);
  216. }
  217. Size2 _OS::get_video_mode(int p_screen) const {
  218. OS::VideoMode vm;
  219. vm = OS::get_singleton()->get_video_mode(p_screen);
  220. return Size2(vm.width, vm.height);
  221. }
  222. bool _OS::is_video_mode_fullscreen(int p_screen) const {
  223. OS::VideoMode vm;
  224. vm = OS::get_singleton()->get_video_mode(p_screen);
  225. return vm.fullscreen;
  226. }
  227. int _OS::get_screen_count() const {
  228. return OS::get_singleton()->get_screen_count();
  229. }
  230. int _OS::get_current_screen() const {
  231. return OS::get_singleton()->get_current_screen();
  232. }
  233. void _OS::set_current_screen(int p_screen) {
  234. OS::get_singleton()->set_current_screen(p_screen);
  235. }
  236. Point2 _OS::get_screen_position(int p_screen) const {
  237. return OS::get_singleton()->get_screen_position(p_screen);
  238. }
  239. Size2 _OS::get_screen_size(int p_screen) const {
  240. return OS::get_singleton()->get_screen_size(p_screen);
  241. }
  242. int _OS::get_screen_dpi(int p_screen) const {
  243. return OS::get_singleton()->get_screen_dpi(p_screen);
  244. }
  245. float _OS::get_screen_scale(int p_screen) const {
  246. return OS::get_singleton()->get_screen_scale(p_screen);
  247. }
  248. float _OS::get_screen_max_scale() const {
  249. return OS::get_singleton()->get_screen_max_scale();
  250. }
  251. Point2 _OS::get_window_position() const {
  252. return OS::get_singleton()->get_window_position();
  253. }
  254. void _OS::set_window_position(const Point2 &p_position) {
  255. OS::get_singleton()->set_window_position(p_position);
  256. }
  257. Size2 _OS::get_max_window_size() const {
  258. return OS::get_singleton()->get_max_window_size();
  259. }
  260. Size2 _OS::get_min_window_size() const {
  261. return OS::get_singleton()->get_min_window_size();
  262. }
  263. Size2 _OS::get_window_size() const {
  264. return OS::get_singleton()->get_window_size();
  265. }
  266. Size2 _OS::get_real_window_size() const {
  267. return OS::get_singleton()->get_real_window_size();
  268. }
  269. void _OS::set_max_window_size(const Size2 &p_size) {
  270. OS::get_singleton()->set_max_window_size(p_size);
  271. }
  272. void _OS::set_min_window_size(const Size2 &p_size) {
  273. OS::get_singleton()->set_min_window_size(p_size);
  274. }
  275. void _OS::set_window_size(const Size2 &p_size) {
  276. OS::get_singleton()->set_window_size(p_size);
  277. }
  278. Rect2 _OS::get_window_safe_area() const {
  279. return OS::get_singleton()->get_window_safe_area();
  280. }
  281. void _OS::set_window_fullscreen(bool p_enabled) {
  282. OS::get_singleton()->set_window_fullscreen(p_enabled);
  283. }
  284. bool _OS::is_window_fullscreen() const {
  285. return OS::get_singleton()->is_window_fullscreen();
  286. }
  287. void _OS::set_window_resizable(bool p_enabled) {
  288. OS::get_singleton()->set_window_resizable(p_enabled);
  289. }
  290. bool _OS::is_window_resizable() const {
  291. return OS::get_singleton()->is_window_resizable();
  292. }
  293. void _OS::set_window_minimized(bool p_enabled) {
  294. OS::get_singleton()->set_window_minimized(p_enabled);
  295. }
  296. bool _OS::is_window_minimized() const {
  297. return OS::get_singleton()->is_window_minimized();
  298. }
  299. void _OS::set_window_maximized(bool p_enabled) {
  300. OS::get_singleton()->set_window_maximized(p_enabled);
  301. }
  302. bool _OS::is_window_maximized() const {
  303. return OS::get_singleton()->is_window_maximized();
  304. }
  305. void _OS::set_window_always_on_top(bool p_enabled) {
  306. OS::get_singleton()->set_window_always_on_top(p_enabled);
  307. }
  308. bool _OS::is_window_always_on_top() const {
  309. return OS::get_singleton()->is_window_always_on_top();
  310. }
  311. bool _OS::is_window_focused() const {
  312. return OS::get_singleton()->is_window_focused();
  313. }
  314. void _OS::set_borderless_window(bool p_borderless) {
  315. OS::get_singleton()->set_borderless_window(p_borderless);
  316. }
  317. bool _OS::get_window_per_pixel_transparency_enabled() const {
  318. return OS::get_singleton()->get_window_per_pixel_transparency_enabled();
  319. }
  320. void _OS::set_window_per_pixel_transparency_enabled(bool p_enabled) {
  321. OS::get_singleton()->set_window_per_pixel_transparency_enabled(p_enabled);
  322. }
  323. bool _OS::get_borderless_window() const {
  324. return OS::get_singleton()->get_borderless_window();
  325. }
  326. void _OS::set_ime_active(const bool p_active) {
  327. OS::get_singleton()->set_ime_active(p_active);
  328. }
  329. void _OS::set_ime_position(const Point2 &p_pos) {
  330. OS::get_singleton()->set_ime_position(p_pos);
  331. }
  332. Point2 _OS::get_ime_selection() const {
  333. return OS::get_singleton()->get_ime_selection();
  334. }
  335. String _OS::get_ime_text() const {
  336. return OS::get_singleton()->get_ime_text();
  337. }
  338. void _OS::set_use_file_access_save_and_swap(bool p_enable) {
  339. FileAccess::set_backup_save(p_enable);
  340. }
  341. bool _OS::is_video_mode_resizable(int p_screen) const {
  342. OS::VideoMode vm;
  343. vm = OS::get_singleton()->get_video_mode(p_screen);
  344. return vm.resizable;
  345. }
  346. Array _OS::get_fullscreen_mode_list(int p_screen) const {
  347. List<OS::VideoMode> vmlist;
  348. OS::get_singleton()->get_fullscreen_mode_list(&vmlist, p_screen);
  349. Array vmarr;
  350. for (List<OS::VideoMode>::Element *E = vmlist.front(); E; E = E->next()) {
  351. vmarr.push_back(Size2(E->get().width, E->get().height));
  352. }
  353. return vmarr;
  354. }
  355. void _OS::set_low_processor_usage_mode(bool p_enabled) {
  356. OS::get_singleton()->set_low_processor_usage_mode(p_enabled);
  357. }
  358. bool _OS::is_in_low_processor_usage_mode() const {
  359. return OS::get_singleton()->is_in_low_processor_usage_mode();
  360. }
  361. void _OS::set_low_processor_usage_mode_sleep_usec(int p_usec) {
  362. OS::get_singleton()->set_low_processor_usage_mode_sleep_usec(p_usec);
  363. }
  364. int _OS::get_low_processor_usage_mode_sleep_usec() const {
  365. return OS::get_singleton()->get_low_processor_usage_mode_sleep_usec();
  366. }
  367. String _OS::get_executable_path() const {
  368. return OS::get_singleton()->get_executable_path();
  369. }
  370. Error _OS::shell_open(String p_uri) {
  371. if (p_uri.begins_with("res://")) {
  372. 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()`.");
  373. } else if (p_uri.begins_with("user://")) {
  374. 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()`.");
  375. }
  376. return OS::get_singleton()->shell_open(p_uri);
  377. };
  378. int _OS::execute(const String &p_path, const Vector<String> &p_arguments, bool p_blocking, Array p_output, bool p_read_stderr) {
  379. OS::ProcessID pid = -2;
  380. int exitcode = 0;
  381. List<String> args;
  382. for (int i = 0; i < p_arguments.size(); i++)
  383. args.push_back(p_arguments[i]);
  384. String pipe;
  385. Error err = OS::get_singleton()->execute(p_path, args, p_blocking, &pid, &pipe, &exitcode, p_read_stderr);
  386. p_output.clear();
  387. p_output.push_back(pipe);
  388. if (err != OK)
  389. return -1;
  390. else if (p_blocking)
  391. return exitcode;
  392. else
  393. return pid;
  394. }
  395. Error _OS::kill(int p_pid) {
  396. return OS::get_singleton()->kill(p_pid);
  397. }
  398. int _OS::get_process_id() const {
  399. return OS::get_singleton()->get_process_id();
  400. };
  401. bool _OS::has_environment(const String &p_var) const {
  402. return OS::get_singleton()->has_environment(p_var);
  403. }
  404. String _OS::get_environment(const String &p_var) const {
  405. return OS::get_singleton()->get_environment(p_var);
  406. }
  407. bool _OS::set_environment(const String &p_var, const String &p_value) const {
  408. return OS::get_singleton()->set_environment(p_var, p_value);
  409. }
  410. String _OS::get_name() const {
  411. return OS::get_singleton()->get_name();
  412. }
  413. Vector<String> _OS::get_cmdline_args() {
  414. List<String> cmdline = OS::get_singleton()->get_cmdline_args();
  415. Vector<String> cmdlinev;
  416. for (List<String>::Element *E = cmdline.front(); E; E = E->next()) {
  417. cmdlinev.push_back(E->get());
  418. }
  419. return cmdlinev;
  420. }
  421. String _OS::get_locale() const {
  422. return OS::get_singleton()->get_locale();
  423. }
  424. String _OS::get_latin_keyboard_variant() const {
  425. switch (OS::get_singleton()->get_latin_keyboard_variant()) {
  426. case OS::LATIN_KEYBOARD_QWERTY: return "QWERTY";
  427. case OS::LATIN_KEYBOARD_QWERTZ: return "QWERTZ";
  428. case OS::LATIN_KEYBOARD_AZERTY: return "AZERTY";
  429. case OS::LATIN_KEYBOARD_QZERTY: return "QZERTY";
  430. case OS::LATIN_KEYBOARD_DVORAK: return "DVORAK";
  431. case OS::LATIN_KEYBOARD_NEO: return "NEO";
  432. case OS::LATIN_KEYBOARD_COLEMAK: return "COLEMAK";
  433. default: return "ERROR";
  434. }
  435. }
  436. int _OS::keyboard_get_layout_count() const {
  437. return OS::get_singleton()->keyboard_get_layout_count();
  438. }
  439. int _OS::keyboard_get_current_layout() const {
  440. return OS::get_singleton()->keyboard_get_current_layout();
  441. }
  442. void _OS::keyboard_set_current_layout(int p_index) {
  443. OS::get_singleton()->keyboard_set_current_layout(p_index);
  444. }
  445. String _OS::keyboard_get_layout_language(int p_index) const {
  446. return OS::get_singleton()->keyboard_get_layout_language(p_index);
  447. }
  448. String _OS::keyboard_get_layout_name(int p_index) const {
  449. return OS::get_singleton()->keyboard_get_layout_name(p_index);
  450. }
  451. String _OS::get_model_name() const {
  452. return OS::get_singleton()->get_model_name();
  453. }
  454. bool _OS::is_ok_left_and_cancel_right() const {
  455. return OS::get_singleton()->get_swap_ok_cancel();
  456. }
  457. Error _OS::set_thread_name(const String &p_name) {
  458. return Thread::set_name(p_name);
  459. };
  460. void _OS::set_use_vsync(bool p_enable) {
  461. OS::get_singleton()->set_use_vsync(p_enable);
  462. }
  463. bool _OS::is_vsync_enabled() const {
  464. return OS::get_singleton()->is_vsync_enabled();
  465. }
  466. void _OS::set_vsync_via_compositor(bool p_enable) {
  467. OS::get_singleton()->set_vsync_via_compositor(p_enable);
  468. }
  469. bool _OS::is_vsync_via_compositor_enabled() const {
  470. return OS::get_singleton()->is_vsync_via_compositor_enabled();
  471. }
  472. _OS::PowerState _OS::get_power_state() {
  473. return _OS::PowerState(OS::get_singleton()->get_power_state());
  474. }
  475. int _OS::get_power_seconds_left() {
  476. return OS::get_singleton()->get_power_seconds_left();
  477. }
  478. int _OS::get_power_percent_left() {
  479. return OS::get_singleton()->get_power_percent_left();
  480. }
  481. Thread::ID _OS::get_thread_caller_id() const {
  482. return Thread::get_caller_id();
  483. };
  484. bool _OS::has_feature(const String &p_feature) const {
  485. return OS::get_singleton()->has_feature(p_feature);
  486. }
  487. /*
  488. enum Weekday {
  489. DAY_SUNDAY,
  490. DAY_MONDAY,
  491. DAY_TUESDAY,
  492. DAY_WEDNESDAY,
  493. DAY_THURSDAY,
  494. DAY_FRIDAY,
  495. DAY_SATURDAY
  496. };
  497. enum Month {
  498. MONTH_JANUARY,
  499. MONTH_FEBRUARY,
  500. MONTH_MARCH,
  501. MONTH_APRIL,
  502. MONTH_MAY,
  503. MONTH_JUNE,
  504. MONTH_JULY,
  505. MONTH_AUGUST,
  506. MONTH_SEPTEMBER,
  507. MONTH_OCTOBER,
  508. MONTH_NOVEMBER,
  509. MONTH_DECEMBER
  510. };
  511. */
  512. /*
  513. struct Date {
  514. int year;
  515. Month month;
  516. int day;
  517. Weekday weekday;
  518. bool dst;
  519. };
  520. struct Time {
  521. int hour;
  522. int min;
  523. int sec;
  524. };
  525. */
  526. uint64_t _OS::get_static_memory_usage() const {
  527. return OS::get_singleton()->get_static_memory_usage();
  528. }
  529. uint64_t _OS::get_static_memory_peak_usage() const {
  530. return OS::get_singleton()->get_static_memory_peak_usage();
  531. }
  532. uint64_t _OS::get_dynamic_memory_usage() const {
  533. return OS::get_singleton()->get_dynamic_memory_usage();
  534. }
  535. void _OS::set_native_icon(const String &p_filename) {
  536. OS::get_singleton()->set_native_icon(p_filename);
  537. }
  538. void _OS::set_icon(const Ref<Image> &p_icon) {
  539. OS::get_singleton()->set_icon(p_icon);
  540. }
  541. int _OS::get_exit_code() const {
  542. return OS::get_singleton()->get_exit_code();
  543. }
  544. void _OS::set_exit_code(int p_code) {
  545. if (p_code < 0 || p_code > 125) {
  546. WARN_PRINT("For portability reasons, the exit code should be set between 0 and 125 (inclusive).");
  547. }
  548. OS::get_singleton()->set_exit_code(p_code);
  549. }
  550. /**
  551. * Get current datetime with consideration for utc and
  552. * dst
  553. */
  554. Dictionary _OS::get_datetime(bool utc) const {
  555. Dictionary dated = get_date(utc);
  556. Dictionary timed = get_time(utc);
  557. List<Variant> keys;
  558. timed.get_key_list(&keys);
  559. for (int i = 0; i < keys.size(); i++) {
  560. dated[keys[i]] = timed[keys[i]];
  561. }
  562. return dated;
  563. }
  564. Dictionary _OS::get_date(bool utc) const {
  565. OS::Date date = OS::get_singleton()->get_date(utc);
  566. Dictionary dated;
  567. dated[YEAR_KEY] = date.year;
  568. dated[MONTH_KEY] = date.month;
  569. dated[DAY_KEY] = date.day;
  570. dated[WEEKDAY_KEY] = date.weekday;
  571. dated[DST_KEY] = date.dst;
  572. return dated;
  573. }
  574. Dictionary _OS::get_time(bool utc) const {
  575. OS::Time time = OS::get_singleton()->get_time(utc);
  576. Dictionary timed;
  577. timed[HOUR_KEY] = time.hour;
  578. timed[MINUTE_KEY] = time.min;
  579. timed[SECOND_KEY] = time.sec;
  580. return timed;
  581. }
  582. /**
  583. * Get an epoch time value from a dictionary of time values
  584. * @p datetime must be populated with the following keys:
  585. * day, hour, minute, month, second, year. (dst is ignored).
  586. *
  587. * You can pass the output from
  588. * get_datetime_from_unix_time directly into this function
  589. *
  590. * @param datetime dictionary of date and time values to convert
  591. *
  592. * @return epoch calculated
  593. */
  594. int64_t _OS::get_unix_time_from_datetime(Dictionary datetime) const {
  595. // if datetime is an empty Dictionary throws an error
  596. ERR_FAIL_COND_V_MSG(datetime.empty(), 0, "Invalid datetime Dictionary: Dictionary is empty");
  597. // Bunch of conversion constants
  598. static const unsigned int SECONDS_PER_MINUTE = 60;
  599. static const unsigned int MINUTES_PER_HOUR = 60;
  600. static const unsigned int HOURS_PER_DAY = 24;
  601. static const unsigned int SECONDS_PER_HOUR = MINUTES_PER_HOUR * SECONDS_PER_MINUTE;
  602. static const unsigned int SECONDS_PER_DAY = SECONDS_PER_HOUR * HOURS_PER_DAY;
  603. // Get all time values from the dictionary, set to zero if it doesn't exist.
  604. // Risk incorrect calculation over throwing errors
  605. unsigned int second = ((datetime.has(SECOND_KEY)) ? static_cast<unsigned int>(datetime[SECOND_KEY]) : 0);
  606. unsigned int minute = ((datetime.has(MINUTE_KEY)) ? static_cast<unsigned int>(datetime[MINUTE_KEY]) : 0);
  607. unsigned int hour = ((datetime.has(HOUR_KEY)) ? static_cast<unsigned int>(datetime[HOUR_KEY]) : 0);
  608. unsigned int day = ((datetime.has(DAY_KEY)) ? static_cast<unsigned int>(datetime[DAY_KEY]) : 1);
  609. unsigned int month = ((datetime.has(MONTH_KEY)) ? static_cast<unsigned int>(datetime[MONTH_KEY]) : 1);
  610. unsigned int year = ((datetime.has(YEAR_KEY)) ? static_cast<unsigned int>(datetime[YEAR_KEY]) : 1970);
  611. /// How many days come before each month (0-12)
  612. static const unsigned short int DAYS_PAST_THIS_YEAR_TABLE[2][13] = {
  613. /* Normal years. */
  614. { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
  615. /* Leap years. */
  616. { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
  617. };
  618. ERR_FAIL_COND_V_MSG(second > 59, 0, "Invalid second value of: " + itos(second) + ".");
  619. ERR_FAIL_COND_V_MSG(minute > 59, 0, "Invalid minute value of: " + itos(minute) + ".");
  620. ERR_FAIL_COND_V_MSG(hour > 23, 0, "Invalid hour value of: " + itos(hour) + ".");
  621. ERR_FAIL_COND_V_MSG(year == 0, 0, "Years before 1 AD are not supported. Value passed: " + itos(year) + ".");
  622. ERR_FAIL_COND_V_MSG(month > 12 || month == 0, 0, "Invalid month value of: " + itos(month) + ".");
  623. // Do this check after month is tested as valid
  624. unsigned int days_in_month = MONTH_DAYS_TABLE[LEAPYEAR(year)][month - 1];
  625. ERR_FAIL_COND_V_MSG(day == 0 || day > days_in_month, 0, "Invalid day value of: " + itos(day) + ". It should be comprised between 1 and " + itos(days_in_month) + " for month " + itos(month) + ".");
  626. // Calculate all the seconds from months past in this year
  627. uint64_t SECONDS_FROM_MONTHS_PAST_THIS_YEAR = DAYS_PAST_THIS_YEAR_TABLE[LEAPYEAR(year)][month - 1] * SECONDS_PER_DAY;
  628. int64_t SECONDS_FROM_YEARS_PAST = 0;
  629. if (year >= EPOCH_YR) {
  630. for (unsigned int iyear = EPOCH_YR; iyear < year; iyear++) {
  631. SECONDS_FROM_YEARS_PAST += YEARSIZE(iyear) * SECONDS_PER_DAY;
  632. }
  633. } else {
  634. for (unsigned int iyear = EPOCH_YR - 1; iyear >= year; iyear--) {
  635. SECONDS_FROM_YEARS_PAST -= YEARSIZE(iyear) * SECONDS_PER_DAY;
  636. }
  637. }
  638. int64_t epoch =
  639. second +
  640. minute * SECONDS_PER_MINUTE +
  641. hour * SECONDS_PER_HOUR +
  642. // Subtract 1 from day, since the current day isn't over yet
  643. // and we cannot count all 24 hours.
  644. (day - 1) * SECONDS_PER_DAY +
  645. SECONDS_FROM_MONTHS_PAST_THIS_YEAR +
  646. SECONDS_FROM_YEARS_PAST;
  647. return epoch;
  648. }
  649. /**
  650. * Get a dictionary of time values when given epoch time
  651. *
  652. * Dictionary Time values will be a union if values from #get_time
  653. * and #get_date dictionaries (with the exception of dst =
  654. * day light standard time, as it cannot be determined from epoch)
  655. *
  656. * @param unix_time_val epoch time to convert
  657. *
  658. * @return dictionary of date and time values
  659. */
  660. Dictionary _OS::get_datetime_from_unix_time(int64_t unix_time_val) const {
  661. OS::Date date;
  662. OS::Time time;
  663. long dayclock, dayno;
  664. int year = EPOCH_YR;
  665. if (unix_time_val >= 0) {
  666. dayno = unix_time_val / SECS_DAY;
  667. dayclock = unix_time_val % SECS_DAY;
  668. /* day 0 was a thursday */
  669. date.weekday = static_cast<OS::Weekday>((dayno + 4) % 7);
  670. while (dayno >= YEARSIZE(year)) {
  671. dayno -= YEARSIZE(year);
  672. year++;
  673. }
  674. } else {
  675. dayno = (unix_time_val - SECS_DAY + 1) / SECS_DAY;
  676. dayclock = unix_time_val - dayno * SECS_DAY;
  677. date.weekday = static_cast<OS::Weekday>(((dayno % 7) + 11) % 7);
  678. do {
  679. year--;
  680. dayno += YEARSIZE(year);
  681. } while (dayno < 0);
  682. }
  683. time.sec = dayclock % 60;
  684. time.min = (dayclock % 3600) / 60;
  685. time.hour = dayclock / 3600;
  686. date.year = year;
  687. size_t imonth = 0;
  688. while ((unsigned long)dayno >= MONTH_DAYS_TABLE[LEAPYEAR(year)][imonth]) {
  689. dayno -= MONTH_DAYS_TABLE[LEAPYEAR(year)][imonth];
  690. imonth++;
  691. }
  692. /// Add 1 to month to make sure months are indexed starting at 1
  693. date.month = static_cast<OS::Month>(imonth + 1);
  694. date.day = dayno + 1;
  695. Dictionary timed;
  696. timed[HOUR_KEY] = time.hour;
  697. timed[MINUTE_KEY] = time.min;
  698. timed[SECOND_KEY] = time.sec;
  699. timed[YEAR_KEY] = date.year;
  700. timed[MONTH_KEY] = date.month;
  701. timed[DAY_KEY] = date.day;
  702. timed[WEEKDAY_KEY] = date.weekday;
  703. return timed;
  704. }
  705. Dictionary _OS::get_time_zone_info() const {
  706. OS::TimeZoneInfo info = OS::get_singleton()->get_time_zone_info();
  707. Dictionary infod;
  708. infod["bias"] = info.bias;
  709. infod["name"] = info.name;
  710. return infod;
  711. }
  712. uint64_t _OS::get_unix_time() const {
  713. return OS::get_singleton()->get_unix_time();
  714. }
  715. uint64_t _OS::get_system_time_secs() const {
  716. return OS::get_singleton()->get_system_time_secs();
  717. }
  718. uint64_t _OS::get_system_time_msecs() const {
  719. return OS::get_singleton()->get_system_time_msecs();
  720. }
  721. /** This method uses a signed argument for better error reporting as it's used from the scripting API. */
  722. void _OS::delay_usec(int p_usec) const {
  723. ERR_FAIL_COND_MSG(
  724. p_usec < 0,
  725. vformat("Can't sleep for %d microseconds. The delay provided must be greater than or equal to 0 microseconds.", p_usec));
  726. OS::get_singleton()->delay_usec(p_usec);
  727. }
  728. /** This method uses a signed argument for better error reporting as it's used from the scripting API. */
  729. void _OS::delay_msec(int p_msec) const {
  730. ERR_FAIL_COND_MSG(
  731. p_msec < 0,
  732. vformat("Can't sleep for %d milliseconds. The delay provided must be greater than or equal to 0 milliseconds.", p_msec));
  733. OS::get_singleton()->delay_usec(int64_t(p_msec) * 1000);
  734. }
  735. uint32_t _OS::get_ticks_msec() const {
  736. return OS::get_singleton()->get_ticks_msec();
  737. }
  738. uint64_t _OS::get_ticks_usec() const {
  739. return OS::get_singleton()->get_ticks_usec();
  740. }
  741. uint32_t _OS::get_splash_tick_msec() const {
  742. return OS::get_singleton()->get_splash_tick_msec();
  743. }
  744. bool _OS::can_use_threads() const {
  745. return OS::get_singleton()->can_use_threads();
  746. }
  747. bool _OS::can_draw() const {
  748. return OS::get_singleton()->can_draw();
  749. }
  750. bool _OS::is_userfs_persistent() const {
  751. return OS::get_singleton()->is_userfs_persistent();
  752. }
  753. int _OS::get_processor_count() const {
  754. return OS::get_singleton()->get_processor_count();
  755. }
  756. bool _OS::is_stdout_verbose() const {
  757. return OS::get_singleton()->is_stdout_verbose();
  758. }
  759. void _OS::dump_memory_to_file(const String &p_file) {
  760. OS::get_singleton()->dump_memory_to_file(p_file.utf8().get_data());
  761. }
  762. struct _OSCoreBindImg {
  763. String path;
  764. Size2 size;
  765. int fmt;
  766. ObjectID id;
  767. int vram;
  768. bool operator<(const _OSCoreBindImg &p_img) const { return vram == p_img.vram ? id < p_img.id : vram > p_img.vram; }
  769. };
  770. void _OS::print_all_textures_by_size() {
  771. // HACK: This is broken, was fixed in 3.4+, we don't bother here.
  772. // Just comment out to silence warnings.
  773. /*
  774. List<_OSCoreBindImg> imgs;
  775. uint64_t total = 0;
  776. {
  777. List<Ref<Resource> > rsrc;
  778. ResourceCache::get_cached_resources(&rsrc);
  779. for (List<Ref<Resource> >::Element *E = rsrc.front(); E; E = E->next()) {
  780. if (!E->get()->is_class("ImageTexture"))
  781. continue;
  782. Size2 size = E->get()->call("get_size");
  783. int fmt = E->get()->call("get_format");
  784. _OSCoreBindImg img;
  785. img.size = size;
  786. img.fmt = fmt;
  787. img.path = E->get()->get_path();
  788. img.vram = Image::get_image_data_size(img.size.width, img.size.height, Image::Format(img.fmt));
  789. img.id = E->get()->get_instance_id();
  790. total += img.vram;
  791. imgs.push_back(img);
  792. }
  793. }
  794. imgs.sort();
  795. for (List<_OSCoreBindImg>::Element *E = imgs.front(); E; E = E->next()) {
  796. total -= E->get().vram;
  797. }
  798. */
  799. }
  800. void _OS::print_resources_by_type(const Vector<String> &p_types) {
  801. Map<String, int> type_count;
  802. List<Ref<Resource> > resources;
  803. ResourceCache::get_cached_resources(&resources);
  804. for (List<Ref<Resource> >::Element *E = resources.front(); E; E = E->next()) {
  805. Ref<Resource> r = E->get();
  806. bool found = false;
  807. for (int i = 0; i < p_types.size(); i++) {
  808. if (r->is_class(p_types[i]))
  809. found = true;
  810. }
  811. if (!found)
  812. continue;
  813. if (!type_count.has(r->get_class())) {
  814. type_count[r->get_class()] = 0;
  815. }
  816. type_count[r->get_class()]++;
  817. }
  818. };
  819. bool _OS::has_virtual_keyboard() const {
  820. return OS::get_singleton()->has_virtual_keyboard();
  821. }
  822. void _OS::show_virtual_keyboard(const String &p_existing_text, bool p_multiline) {
  823. OS::get_singleton()->show_virtual_keyboard(p_existing_text, Rect2(), p_multiline);
  824. }
  825. void _OS::hide_virtual_keyboard() {
  826. OS::get_singleton()->hide_virtual_keyboard();
  827. }
  828. int _OS::get_virtual_keyboard_height() {
  829. return OS::get_singleton()->get_virtual_keyboard_height();
  830. }
  831. void _OS::print_all_resources(const String &p_to_file) {
  832. OS::get_singleton()->print_all_resources(p_to_file);
  833. }
  834. void _OS::print_resources_in_use(bool p_short) {
  835. OS::get_singleton()->print_resources_in_use(p_short);
  836. }
  837. void _OS::dump_resources_to_file(const String &p_file) {
  838. OS::get_singleton()->dump_resources_to_file(p_file.utf8().get_data());
  839. }
  840. String _OS::get_user_data_dir() const {
  841. return OS::get_singleton()->get_user_data_dir();
  842. };
  843. Error _OS::native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track) {
  844. return OS::get_singleton()->native_video_play(p_path, p_volume, p_audio_track, p_subtitle_track);
  845. };
  846. bool _OS::native_video_is_playing() {
  847. return OS::get_singleton()->native_video_is_playing();
  848. };
  849. void _OS::native_video_pause() {
  850. OS::get_singleton()->native_video_pause();
  851. };
  852. void _OS::native_video_unpause() {
  853. OS::get_singleton()->native_video_unpause();
  854. };
  855. void _OS::native_video_stop() {
  856. OS::get_singleton()->native_video_stop();
  857. };
  858. void _OS::request_attention() {
  859. OS::get_singleton()->request_attention();
  860. }
  861. void _OS::center_window() {
  862. OS::get_singleton()->center_window();
  863. }
  864. void _OS::move_window_to_foreground() {
  865. OS::get_singleton()->move_window_to_foreground();
  866. }
  867. int64_t _OS::get_native_handle(HandleType p_handle_type) {
  868. return (int64_t)OS::get_singleton()->get_native_handle(p_handle_type);
  869. }
  870. bool _OS::is_debug_build() const {
  871. #ifdef DEBUG_ENABLED
  872. return true;
  873. #else
  874. return false;
  875. #endif
  876. }
  877. void _OS::set_screen_orientation(ScreenOrientation p_orientation) {
  878. OS::get_singleton()->set_screen_orientation(OS::ScreenOrientation(p_orientation));
  879. }
  880. _OS::ScreenOrientation _OS::get_screen_orientation() const {
  881. return ScreenOrientation(OS::get_singleton()->get_screen_orientation());
  882. }
  883. void _OS::set_keep_screen_on(bool p_enabled) {
  884. OS::get_singleton()->set_keep_screen_on(p_enabled);
  885. }
  886. bool _OS::is_keep_screen_on() const {
  887. return OS::get_singleton()->is_keep_screen_on();
  888. }
  889. String _OS::get_system_dir(SystemDir p_dir, bool p_shared_storage) const {
  890. return OS::get_singleton()->get_system_dir(OS::SystemDir(p_dir), p_shared_storage);
  891. }
  892. String _OS::get_scancode_string(uint32_t p_code) const {
  893. return keycode_get_string(p_code);
  894. }
  895. bool _OS::is_scancode_unicode(uint32_t p_unicode) const {
  896. return keycode_has_unicode(p_unicode);
  897. }
  898. int _OS::find_scancode_from_string(const String &p_code) const {
  899. return find_keycode(p_code);
  900. }
  901. void _OS::alert(const String &p_alert, const String &p_title) {
  902. OS::get_singleton()->alert(p_alert, p_title);
  903. }
  904. bool _OS::request_permission(const String &p_name) {
  905. return OS::get_singleton()->request_permission(p_name);
  906. }
  907. bool _OS::request_permissions() {
  908. return OS::get_singleton()->request_permissions();
  909. }
  910. Vector<String> _OS::get_granted_permissions() const {
  911. return OS::get_singleton()->get_granted_permissions();
  912. }
  913. int _OS::get_tablet_driver_count() const {
  914. return OS::get_singleton()->get_tablet_driver_count();
  915. }
  916. String _OS::get_tablet_driver_name(int p_driver) const {
  917. return OS::get_singleton()->get_tablet_driver_name(p_driver);
  918. }
  919. String _OS::get_current_tablet_driver() const {
  920. return OS::get_singleton()->get_current_tablet_driver();
  921. }
  922. void _OS::set_current_tablet_driver(const String &p_driver) {
  923. OS::get_singleton()->set_current_tablet_driver(p_driver);
  924. }
  925. _OS *_OS::singleton = NULL;
  926. void _OS::_bind_methods() {
  927. //ClassDB::bind_method(D_METHOD("get_mouse_position"),&_OS::get_mouse_position);
  928. //ClassDB::bind_method(D_METHOD("is_mouse_grab_enabled"),&_OS::is_mouse_grab_enabled);
  929. ClassDB::bind_method(D_METHOD("set_clipboard", "clipboard"), &_OS::set_clipboard);
  930. ClassDB::bind_method(D_METHOD("get_clipboard"), &_OS::get_clipboard);
  931. //will not delete for now, just unexpose
  932. //ClassDB::bind_method(D_METHOD("set_video_mode","size","fullscreen","resizable","screen"),&_OS::set_video_mode,DEFVAL(0));
  933. //ClassDB::bind_method(D_METHOD("get_video_mode_size","screen"),&_OS::get_video_mode,DEFVAL(0));
  934. //ClassDB::bind_method(D_METHOD("is_video_mode_fullscreen","screen"),&_OS::is_video_mode_fullscreen,DEFVAL(0));
  935. //ClassDB::bind_method(D_METHOD("is_video_mode_resizable","screen"),&_OS::is_video_mode_resizable,DEFVAL(0));
  936. //ClassDB::bind_method(D_METHOD("get_fullscreen_mode_list","screen"),&_OS::get_fullscreen_mode_list,DEFVAL(0));
  937. ClassDB::bind_method(D_METHOD("global_menu_add_item", "menu", "label", "id", "meta"), &_OS::global_menu_add_item);
  938. ClassDB::bind_method(D_METHOD("global_menu_add_separator", "menu"), &_OS::global_menu_add_separator);
  939. ClassDB::bind_method(D_METHOD("global_menu_remove_item", "menu", "idx"), &_OS::global_menu_remove_item);
  940. ClassDB::bind_method(D_METHOD("global_menu_clear", "menu"), &_OS::global_menu_clear);
  941. ClassDB::bind_method(D_METHOD("get_video_driver_count"), &_OS::get_video_driver_count);
  942. ClassDB::bind_method(D_METHOD("get_video_driver_name", "driver"), &_OS::get_video_driver_name);
  943. ClassDB::bind_method(D_METHOD("get_current_video_driver"), &_OS::get_current_video_driver);
  944. ClassDB::bind_method(D_METHOD("get_audio_driver_count"), &_OS::get_audio_driver_count);
  945. ClassDB::bind_method(D_METHOD("get_audio_driver_name", "driver"), &_OS::get_audio_driver_name);
  946. ClassDB::bind_method(D_METHOD("get_connected_midi_inputs"), &_OS::get_connected_midi_inputs);
  947. ClassDB::bind_method(D_METHOD("open_midi_inputs"), &_OS::open_midi_inputs);
  948. ClassDB::bind_method(D_METHOD("close_midi_inputs"), &_OS::close_midi_inputs);
  949. ClassDB::bind_method(D_METHOD("get_screen_count"), &_OS::get_screen_count);
  950. ClassDB::bind_method(D_METHOD("get_current_screen"), &_OS::get_current_screen);
  951. ClassDB::bind_method(D_METHOD("set_current_screen", "screen"), &_OS::set_current_screen);
  952. ClassDB::bind_method(D_METHOD("get_screen_position", "screen"), &_OS::get_screen_position, DEFVAL(-1));
  953. ClassDB::bind_method(D_METHOD("get_screen_size", "screen"), &_OS::get_screen_size, DEFVAL(-1));
  954. ClassDB::bind_method(D_METHOD("get_screen_dpi", "screen"), &_OS::get_screen_dpi, DEFVAL(-1));
  955. ClassDB::bind_method(D_METHOD("get_screen_scale", "screen"), &_OS::get_screen_scale, DEFVAL(-1));
  956. ClassDB::bind_method(D_METHOD("get_screen_max_scale"), &_OS::get_screen_max_scale);
  957. ClassDB::bind_method(D_METHOD("get_window_position"), &_OS::get_window_position);
  958. ClassDB::bind_method(D_METHOD("set_window_position", "position"), &_OS::set_window_position);
  959. ClassDB::bind_method(D_METHOD("get_window_size"), &_OS::get_window_size);
  960. ClassDB::bind_method(D_METHOD("get_max_window_size"), &_OS::get_max_window_size);
  961. ClassDB::bind_method(D_METHOD("get_min_window_size"), &_OS::get_min_window_size);
  962. ClassDB::bind_method(D_METHOD("set_max_window_size", "size"), &_OS::set_max_window_size);
  963. ClassDB::bind_method(D_METHOD("set_min_window_size", "size"), &_OS::set_min_window_size);
  964. ClassDB::bind_method(D_METHOD("set_window_size", "size"), &_OS::set_window_size);
  965. ClassDB::bind_method(D_METHOD("get_window_safe_area"), &_OS::get_window_safe_area);
  966. ClassDB::bind_method(D_METHOD("set_window_fullscreen", "enabled"), &_OS::set_window_fullscreen);
  967. ClassDB::bind_method(D_METHOD("is_window_fullscreen"), &_OS::is_window_fullscreen);
  968. ClassDB::bind_method(D_METHOD("set_window_resizable", "enabled"), &_OS::set_window_resizable);
  969. ClassDB::bind_method(D_METHOD("is_window_resizable"), &_OS::is_window_resizable);
  970. ClassDB::bind_method(D_METHOD("set_window_minimized", "enabled"), &_OS::set_window_minimized);
  971. ClassDB::bind_method(D_METHOD("is_window_minimized"), &_OS::is_window_minimized);
  972. ClassDB::bind_method(D_METHOD("set_window_maximized", "enabled"), &_OS::set_window_maximized);
  973. ClassDB::bind_method(D_METHOD("is_window_maximized"), &_OS::is_window_maximized);
  974. ClassDB::bind_method(D_METHOD("set_window_always_on_top", "enabled"), &_OS::set_window_always_on_top);
  975. ClassDB::bind_method(D_METHOD("is_window_always_on_top"), &_OS::is_window_always_on_top);
  976. ClassDB::bind_method(D_METHOD("is_window_focused"), &_OS::is_window_focused);
  977. ClassDB::bind_method(D_METHOD("request_attention"), &_OS::request_attention);
  978. ClassDB::bind_method(D_METHOD("get_real_window_size"), &_OS::get_real_window_size);
  979. ClassDB::bind_method(D_METHOD("center_window"), &_OS::center_window);
  980. ClassDB::bind_method(D_METHOD("move_window_to_foreground"), &_OS::move_window_to_foreground);
  981. ClassDB::bind_method(D_METHOD("get_native_handle", "handle_type"), &_OS::get_native_handle);
  982. ClassDB::bind_method(D_METHOD("set_borderless_window", "borderless"), &_OS::set_borderless_window);
  983. ClassDB::bind_method(D_METHOD("get_borderless_window"), &_OS::get_borderless_window);
  984. ClassDB::bind_method(D_METHOD("get_window_per_pixel_transparency_enabled"), &_OS::get_window_per_pixel_transparency_enabled);
  985. ClassDB::bind_method(D_METHOD("set_window_per_pixel_transparency_enabled", "enabled"), &_OS::set_window_per_pixel_transparency_enabled);
  986. ClassDB::bind_method(D_METHOD("set_ime_active", "active"), &_OS::set_ime_active);
  987. ClassDB::bind_method(D_METHOD("set_ime_position", "position"), &_OS::set_ime_position);
  988. ClassDB::bind_method(D_METHOD("get_ime_selection"), &_OS::get_ime_selection);
  989. ClassDB::bind_method(D_METHOD("get_ime_text"), &_OS::get_ime_text);
  990. ClassDB::bind_method(D_METHOD("set_screen_orientation", "orientation"), &_OS::set_screen_orientation);
  991. ClassDB::bind_method(D_METHOD("get_screen_orientation"), &_OS::get_screen_orientation);
  992. ClassDB::bind_method(D_METHOD("set_keep_screen_on", "enabled"), &_OS::set_keep_screen_on);
  993. ClassDB::bind_method(D_METHOD("is_keep_screen_on"), &_OS::is_keep_screen_on);
  994. ClassDB::bind_method(D_METHOD("has_touchscreen_ui_hint"), &_OS::has_touchscreen_ui_hint);
  995. ClassDB::bind_method(D_METHOD("set_window_title", "title"), &_OS::set_window_title);
  996. ClassDB::bind_method(D_METHOD("set_window_mouse_passthrough", "region"), &_OS::set_window_mouse_passthrough);
  997. ClassDB::bind_method(D_METHOD("set_low_processor_usage_mode", "enable"), &_OS::set_low_processor_usage_mode);
  998. ClassDB::bind_method(D_METHOD("is_in_low_processor_usage_mode"), &_OS::is_in_low_processor_usage_mode);
  999. ClassDB::bind_method(D_METHOD("set_low_processor_usage_mode_sleep_usec", "usec"), &_OS::set_low_processor_usage_mode_sleep_usec);
  1000. ClassDB::bind_method(D_METHOD("get_low_processor_usage_mode_sleep_usec"), &_OS::get_low_processor_usage_mode_sleep_usec);
  1001. ClassDB::bind_method(D_METHOD("get_processor_count"), &_OS::get_processor_count);
  1002. ClassDB::bind_method(D_METHOD("get_executable_path"), &_OS::get_executable_path);
  1003. ClassDB::bind_method(D_METHOD("execute", "path", "arguments", "blocking", "output", "read_stderr"), &_OS::execute, DEFVAL(true), DEFVAL(Array()), DEFVAL(false));
  1004. ClassDB::bind_method(D_METHOD("kill", "pid"), &_OS::kill);
  1005. ClassDB::bind_method(D_METHOD("shell_open", "uri"), &_OS::shell_open);
  1006. ClassDB::bind_method(D_METHOD("get_process_id"), &_OS::get_process_id);
  1007. ClassDB::bind_method(D_METHOD("get_environment", "variable"), &_OS::get_environment);
  1008. ClassDB::bind_method(D_METHOD("set_environment", "variable", "value"), &_OS::set_environment);
  1009. ClassDB::bind_method(D_METHOD("has_environment", "variable"), &_OS::has_environment);
  1010. ClassDB::bind_method(D_METHOD("get_name"), &_OS::get_name);
  1011. ClassDB::bind_method(D_METHOD("get_cmdline_args"), &_OS::get_cmdline_args);
  1012. ClassDB::bind_method(D_METHOD("get_datetime", "utc"), &_OS::get_datetime, DEFVAL(false));
  1013. ClassDB::bind_method(D_METHOD("get_date", "utc"), &_OS::get_date, DEFVAL(false));
  1014. ClassDB::bind_method(D_METHOD("get_time", "utc"), &_OS::get_time, DEFVAL(false));
  1015. ClassDB::bind_method(D_METHOD("get_time_zone_info"), &_OS::get_time_zone_info);
  1016. ClassDB::bind_method(D_METHOD("get_unix_time"), &_OS::get_unix_time);
  1017. ClassDB::bind_method(D_METHOD("get_datetime_from_unix_time", "unix_time_val"), &_OS::get_datetime_from_unix_time);
  1018. ClassDB::bind_method(D_METHOD("get_unix_time_from_datetime", "datetime"), &_OS::get_unix_time_from_datetime);
  1019. ClassDB::bind_method(D_METHOD("get_system_time_secs"), &_OS::get_system_time_secs);
  1020. ClassDB::bind_method(D_METHOD("get_system_time_msecs"), &_OS::get_system_time_msecs);
  1021. ClassDB::bind_method(D_METHOD("set_native_icon", "filename"), &_OS::set_native_icon);
  1022. ClassDB::bind_method(D_METHOD("set_icon", "icon"), &_OS::set_icon);
  1023. ClassDB::bind_method(D_METHOD("get_exit_code"), &_OS::get_exit_code);
  1024. ClassDB::bind_method(D_METHOD("set_exit_code", "code"), &_OS::set_exit_code);
  1025. ClassDB::bind_method(D_METHOD("delay_usec", "usec"), &_OS::delay_usec);
  1026. ClassDB::bind_method(D_METHOD("delay_msec", "msec"), &_OS::delay_msec);
  1027. ClassDB::bind_method(D_METHOD("get_ticks_msec"), &_OS::get_ticks_msec);
  1028. ClassDB::bind_method(D_METHOD("get_ticks_usec"), &_OS::get_ticks_usec);
  1029. ClassDB::bind_method(D_METHOD("get_splash_tick_msec"), &_OS::get_splash_tick_msec);
  1030. ClassDB::bind_method(D_METHOD("get_locale"), &_OS::get_locale);
  1031. ClassDB::bind_method(D_METHOD("get_latin_keyboard_variant"), &_OS::get_latin_keyboard_variant);
  1032. ClassDB::bind_method(D_METHOD("get_model_name"), &_OS::get_model_name);
  1033. ClassDB::bind_method(D_METHOD("keyboard_get_layout_count"), &_OS::keyboard_get_layout_count);
  1034. ClassDB::bind_method(D_METHOD("keyboard_get_current_layout"), &_OS::keyboard_get_current_layout);
  1035. ClassDB::bind_method(D_METHOD("keyboard_set_current_layout", "index"), &_OS::keyboard_set_current_layout);
  1036. ClassDB::bind_method(D_METHOD("keyboard_get_layout_language", "index"), &_OS::keyboard_get_layout_language);
  1037. ClassDB::bind_method(D_METHOD("keyboard_get_layout_name", "index"), &_OS::keyboard_get_layout_name);
  1038. ClassDB::bind_method(D_METHOD("can_draw"), &_OS::can_draw);
  1039. ClassDB::bind_method(D_METHOD("is_userfs_persistent"), &_OS::is_userfs_persistent);
  1040. ClassDB::bind_method(D_METHOD("is_stdout_verbose"), &_OS::is_stdout_verbose);
  1041. ClassDB::bind_method(D_METHOD("can_use_threads"), &_OS::can_use_threads);
  1042. ClassDB::bind_method(D_METHOD("is_debug_build"), &_OS::is_debug_build);
  1043. //ClassDB::bind_method(D_METHOD("get_mouse_button_state"),&_OS::get_mouse_button_state);
  1044. ClassDB::bind_method(D_METHOD("dump_memory_to_file", "file"), &_OS::dump_memory_to_file);
  1045. ClassDB::bind_method(D_METHOD("dump_resources_to_file", "file"), &_OS::dump_resources_to_file);
  1046. ClassDB::bind_method(D_METHOD("has_virtual_keyboard"), &_OS::has_virtual_keyboard);
  1047. ClassDB::bind_method(D_METHOD("show_virtual_keyboard", "existing_text", "multiline"), &_OS::show_virtual_keyboard, DEFVAL(""), DEFVAL(false));
  1048. ClassDB::bind_method(D_METHOD("hide_virtual_keyboard"), &_OS::hide_virtual_keyboard);
  1049. ClassDB::bind_method(D_METHOD("get_virtual_keyboard_height"), &_OS::get_virtual_keyboard_height);
  1050. ClassDB::bind_method(D_METHOD("print_resources_in_use", "short"), &_OS::print_resources_in_use, DEFVAL(false));
  1051. ClassDB::bind_method(D_METHOD("print_all_resources", "tofile"), &_OS::print_all_resources, DEFVAL(""));
  1052. ClassDB::bind_method(D_METHOD("get_static_memory_usage"), &_OS::get_static_memory_usage);
  1053. ClassDB::bind_method(D_METHOD("get_static_memory_peak_usage"), &_OS::get_static_memory_peak_usage);
  1054. ClassDB::bind_method(D_METHOD("get_dynamic_memory_usage"), &_OS::get_dynamic_memory_usage);
  1055. ClassDB::bind_method(D_METHOD("get_user_data_dir"), &_OS::get_user_data_dir);
  1056. ClassDB::bind_method(D_METHOD("get_system_dir", "dir", "shared_storage"), &_OS::get_system_dir, DEFVAL(true));
  1057. ClassDB::bind_method(D_METHOD("get_unique_id"), &_OS::get_unique_id);
  1058. ClassDB::bind_method(D_METHOD("is_ok_left_and_cancel_right"), &_OS::is_ok_left_and_cancel_right);
  1059. ClassDB::bind_method(D_METHOD("print_all_textures_by_size"), &_OS::print_all_textures_by_size);
  1060. ClassDB::bind_method(D_METHOD("print_resources_by_type", "types"), &_OS::print_resources_by_type);
  1061. ClassDB::bind_method(D_METHOD("native_video_play", "path", "volume", "audio_track", "subtitle_track"), &_OS::native_video_play);
  1062. ClassDB::bind_method(D_METHOD("native_video_is_playing"), &_OS::native_video_is_playing);
  1063. ClassDB::bind_method(D_METHOD("native_video_stop"), &_OS::native_video_stop);
  1064. ClassDB::bind_method(D_METHOD("native_video_pause"), &_OS::native_video_pause);
  1065. ClassDB::bind_method(D_METHOD("native_video_unpause"), &_OS::native_video_unpause);
  1066. ClassDB::bind_method(D_METHOD("get_scancode_string", "code"), &_OS::get_scancode_string);
  1067. ClassDB::bind_method(D_METHOD("is_scancode_unicode", "code"), &_OS::is_scancode_unicode);
  1068. ClassDB::bind_method(D_METHOD("find_scancode_from_string", "string"), &_OS::find_scancode_from_string);
  1069. ClassDB::bind_method(D_METHOD("set_use_file_access_save_and_swap", "enabled"), &_OS::set_use_file_access_save_and_swap);
  1070. ClassDB::bind_method(D_METHOD("alert", "text", "title"), &_OS::alert, DEFVAL("Alert!"));
  1071. ClassDB::bind_method(D_METHOD("set_thread_name", "name"), &_OS::set_thread_name);
  1072. ClassDB::bind_method(D_METHOD("get_thread_caller_id"), &_OS::get_thread_caller_id);
  1073. ClassDB::bind_method(D_METHOD("set_use_vsync", "enable"), &_OS::set_use_vsync);
  1074. ClassDB::bind_method(D_METHOD("is_vsync_enabled"), &_OS::is_vsync_enabled);
  1075. ClassDB::bind_method(D_METHOD("set_vsync_via_compositor", "enable"), &_OS::set_vsync_via_compositor);
  1076. ClassDB::bind_method(D_METHOD("is_vsync_via_compositor_enabled"), &_OS::is_vsync_via_compositor_enabled);
  1077. ClassDB::bind_method(D_METHOD("has_feature", "tag_name"), &_OS::has_feature);
  1078. ClassDB::bind_method(D_METHOD("get_power_state"), &_OS::get_power_state);
  1079. ClassDB::bind_method(D_METHOD("get_power_seconds_left"), &_OS::get_power_seconds_left);
  1080. ClassDB::bind_method(D_METHOD("get_power_percent_left"), &_OS::get_power_percent_left);
  1081. ClassDB::bind_method(D_METHOD("request_permission", "name"), &_OS::request_permission);
  1082. ClassDB::bind_method(D_METHOD("request_permissions"), &_OS::request_permissions);
  1083. ClassDB::bind_method(D_METHOD("get_granted_permissions"), &_OS::get_granted_permissions);
  1084. ClassDB::bind_method(D_METHOD("get_tablet_driver_count"), &_OS::get_tablet_driver_count);
  1085. ClassDB::bind_method(D_METHOD("get_tablet_driver_name", "idx"), &_OS::get_tablet_driver_name);
  1086. ClassDB::bind_method(D_METHOD("get_current_tablet_driver"), &_OS::get_current_tablet_driver);
  1087. ClassDB::bind_method(D_METHOD("set_current_tablet_driver", "name"), &_OS::set_current_tablet_driver);
  1088. ADD_PROPERTY(PropertyInfo(Variant::STRING, "tablet_driver"), "set_current_tablet_driver", "get_current_tablet_driver");
  1089. ADD_PROPERTY(PropertyInfo(Variant::STRING, "clipboard"), "set_clipboard", "get_clipboard");
  1090. ADD_PROPERTY(PropertyInfo(Variant::INT, "current_screen"), "set_current_screen", "get_current_screen");
  1091. ADD_PROPERTY(PropertyInfo(Variant::INT, "exit_code"), "set_exit_code", "get_exit_code");
  1092. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "vsync_enabled"), "set_use_vsync", "is_vsync_enabled");
  1093. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "vsync_via_compositor"), "set_vsync_via_compositor", "is_vsync_via_compositor_enabled");
  1094. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "low_processor_usage_mode"), "set_low_processor_usage_mode", "is_in_low_processor_usage_mode");
  1095. 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");
  1096. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "keep_screen_on"), "set_keep_screen_on", "is_keep_screen_on");
  1097. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "min_window_size"), "set_min_window_size", "get_min_window_size");
  1098. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "max_window_size"), "set_max_window_size", "get_max_window_size");
  1099. ADD_PROPERTY(PropertyInfo(Variant::INT, "screen_orientation", PROPERTY_HINT_ENUM, "Landscape,Portrait,Reverse Landscape,Reverse Portrait,Sensor Landscape,Sensor Portrait,Sensor"), "set_screen_orientation", "get_screen_orientation");
  1100. ADD_GROUP("Window", "window_");
  1101. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_borderless"), "set_borderless_window", "get_borderless_window");
  1102. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_per_pixel_transparency_enabled"), "set_window_per_pixel_transparency_enabled", "get_window_per_pixel_transparency_enabled");
  1103. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_fullscreen"), "set_window_fullscreen", "is_window_fullscreen");
  1104. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_maximized"), "set_window_maximized", "is_window_maximized");
  1105. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_minimized"), "set_window_minimized", "is_window_minimized");
  1106. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "window_resizable"), "set_window_resizable", "is_window_resizable");
  1107. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "window_position"), "set_window_position", "get_window_position");
  1108. ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "window_size"), "set_window_size", "get_window_size");
  1109. // Those default values need to be specified for the docs generator,
  1110. // to avoid using values from the documentation writer's own OS instance.
  1111. ADD_PROPERTY_DEFAULT("clipboard", "");
  1112. ADD_PROPERTY_DEFAULT("current_screen", 0);
  1113. ADD_PROPERTY_DEFAULT("exit_code", 0);
  1114. ADD_PROPERTY_DEFAULT("vsync_enabled", true);
  1115. ADD_PROPERTY_DEFAULT("vsync_via_compositor", false);
  1116. ADD_PROPERTY_DEFAULT("low_processor_usage_mode", false);
  1117. ADD_PROPERTY_DEFAULT("low_processor_usage_mode_sleep_usec", 6900);
  1118. ADD_PROPERTY_DEFAULT("keep_screen_on", true);
  1119. ADD_PROPERTY_DEFAULT("min_window_size", Vector2());
  1120. ADD_PROPERTY_DEFAULT("max_window_size", Vector2());
  1121. ADD_PROPERTY_DEFAULT("screen_orientation", 0);
  1122. ADD_PROPERTY_DEFAULT("window_borderless", false);
  1123. ADD_PROPERTY_DEFAULT("window_per_pixel_transparency_enabled", false);
  1124. ADD_PROPERTY_DEFAULT("window_fullscreen", false);
  1125. ADD_PROPERTY_DEFAULT("window_maximized", false);
  1126. ADD_PROPERTY_DEFAULT("window_minimized", false);
  1127. ADD_PROPERTY_DEFAULT("window_resizable", true);
  1128. ADD_PROPERTY_DEFAULT("window_position", Vector2());
  1129. ADD_PROPERTY_DEFAULT("window_size", Vector2());
  1130. BIND_ENUM_CONSTANT(VIDEO_DRIVER_GLES2);
  1131. BIND_ENUM_CONSTANT(VIDEO_DRIVER_GLES3);
  1132. BIND_ENUM_CONSTANT(DAY_SUNDAY);
  1133. BIND_ENUM_CONSTANT(DAY_MONDAY);
  1134. BIND_ENUM_CONSTANT(DAY_TUESDAY);
  1135. BIND_ENUM_CONSTANT(DAY_WEDNESDAY);
  1136. BIND_ENUM_CONSTANT(DAY_THURSDAY);
  1137. BIND_ENUM_CONSTANT(DAY_FRIDAY);
  1138. BIND_ENUM_CONSTANT(DAY_SATURDAY);
  1139. BIND_ENUM_CONSTANT(MONTH_JANUARY);
  1140. BIND_ENUM_CONSTANT(MONTH_FEBRUARY);
  1141. BIND_ENUM_CONSTANT(MONTH_MARCH);
  1142. BIND_ENUM_CONSTANT(MONTH_APRIL);
  1143. BIND_ENUM_CONSTANT(MONTH_MAY);
  1144. BIND_ENUM_CONSTANT(MONTH_JUNE);
  1145. BIND_ENUM_CONSTANT(MONTH_JULY);
  1146. BIND_ENUM_CONSTANT(MONTH_AUGUST);
  1147. BIND_ENUM_CONSTANT(MONTH_SEPTEMBER);
  1148. BIND_ENUM_CONSTANT(MONTH_OCTOBER);
  1149. BIND_ENUM_CONSTANT(MONTH_NOVEMBER);
  1150. BIND_ENUM_CONSTANT(MONTH_DECEMBER);
  1151. BIND_ENUM_CONSTANT(APPLICATION_HANDLE);
  1152. BIND_ENUM_CONSTANT(DISPLAY_HANDLE);
  1153. BIND_ENUM_CONSTANT(WINDOW_HANDLE);
  1154. BIND_ENUM_CONSTANT(WINDOW_VIEW);
  1155. BIND_ENUM_CONSTANT(OPENGL_CONTEXT);
  1156. BIND_ENUM_CONSTANT(SCREEN_ORIENTATION_LANDSCAPE);
  1157. BIND_ENUM_CONSTANT(SCREEN_ORIENTATION_PORTRAIT);
  1158. BIND_ENUM_CONSTANT(SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
  1159. BIND_ENUM_CONSTANT(SCREEN_ORIENTATION_REVERSE_PORTRAIT);
  1160. BIND_ENUM_CONSTANT(SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
  1161. BIND_ENUM_CONSTANT(SCREEN_ORIENTATION_SENSOR_PORTRAIT);
  1162. BIND_ENUM_CONSTANT(SCREEN_ORIENTATION_SENSOR);
  1163. BIND_ENUM_CONSTANT(SYSTEM_DIR_DESKTOP);
  1164. BIND_ENUM_CONSTANT(SYSTEM_DIR_DCIM);
  1165. BIND_ENUM_CONSTANT(SYSTEM_DIR_DOCUMENTS);
  1166. BIND_ENUM_CONSTANT(SYSTEM_DIR_DOWNLOADS);
  1167. BIND_ENUM_CONSTANT(SYSTEM_DIR_MOVIES);
  1168. BIND_ENUM_CONSTANT(SYSTEM_DIR_MUSIC);
  1169. BIND_ENUM_CONSTANT(SYSTEM_DIR_PICTURES);
  1170. BIND_ENUM_CONSTANT(SYSTEM_DIR_RINGTONES);
  1171. BIND_ENUM_CONSTANT(POWERSTATE_UNKNOWN);
  1172. BIND_ENUM_CONSTANT(POWERSTATE_ON_BATTERY);
  1173. BIND_ENUM_CONSTANT(POWERSTATE_NO_BATTERY);
  1174. BIND_ENUM_CONSTANT(POWERSTATE_CHARGING);
  1175. BIND_ENUM_CONSTANT(POWERSTATE_CHARGED);
  1176. }
  1177. _OS::_OS() {
  1178. singleton = this;
  1179. }
  1180. ///////////////////// GEOMETRY
  1181. _Geometry *_Geometry::singleton = NULL;
  1182. _Geometry *_Geometry::get_singleton() {
  1183. return singleton;
  1184. }
  1185. PoolVector<Plane> _Geometry::build_box_planes(const Vector3 &p_extents) {
  1186. return Geometry::build_box_planes(p_extents);
  1187. }
  1188. PoolVector<Plane> _Geometry::build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis) {
  1189. return Geometry::build_cylinder_planes(p_radius, p_height, p_sides, p_axis);
  1190. }
  1191. PoolVector<Plane> _Geometry::build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis) {
  1192. return Geometry::build_capsule_planes(p_radius, p_height, p_sides, p_lats, p_axis);
  1193. }
  1194. bool _Geometry::is_point_in_circle(const Vector2 &p_point, const Vector2 &p_circle_pos, real_t p_circle_radius) {
  1195. return Geometry::is_point_in_circle(p_point, p_circle_pos, p_circle_radius);
  1196. }
  1197. real_t _Geometry::segment_intersects_circle(const Vector2 &p_from, const Vector2 &p_to, const Vector2 &p_circle_pos, real_t p_circle_radius) {
  1198. return Geometry::segment_intersects_circle(p_from, p_to, p_circle_pos, p_circle_radius);
  1199. }
  1200. Variant _Geometry::segment_intersects_segment_2d(const Vector2 &p_from_a, const Vector2 &p_to_a, const Vector2 &p_from_b, const Vector2 &p_to_b) {
  1201. Vector2 result;
  1202. if (Geometry::segment_intersects_segment_2d(p_from_a, p_to_a, p_from_b, p_to_b, &result)) {
  1203. return result;
  1204. } else {
  1205. return Variant();
  1206. };
  1207. };
  1208. Variant _Geometry::line_intersects_line_2d(const Vector2 &p_from_a, const Vector2 &p_dir_a, const Vector2 &p_from_b, const Vector2 &p_dir_b) {
  1209. Vector2 result;
  1210. if (Geometry::line_intersects_line_2d(p_from_a, p_dir_a, p_from_b, p_dir_b, result)) {
  1211. return result;
  1212. } else {
  1213. return Variant();
  1214. }
  1215. }
  1216. PoolVector<Vector2> _Geometry::get_closest_points_between_segments_2d(const Vector2 &p1, const Vector2 &q1, const Vector2 &p2, const Vector2 &q2) {
  1217. Vector2 r1, r2;
  1218. Geometry::get_closest_points_between_segments(p1, q1, p2, q2, r1, r2);
  1219. PoolVector<Vector2> r;
  1220. r.resize(2);
  1221. r.set(0, r1);
  1222. r.set(1, r2);
  1223. return r;
  1224. }
  1225. PoolVector<Vector3> _Geometry::get_closest_points_between_segments(const Vector3 &p1, const Vector3 &p2, const Vector3 &q1, const Vector3 &q2) {
  1226. Vector3 r1, r2;
  1227. Geometry::get_closest_points_between_segments(p1, p2, q1, q2, r1, r2);
  1228. PoolVector<Vector3> r;
  1229. r.resize(2);
  1230. r.set(0, r1);
  1231. r.set(1, r2);
  1232. return r;
  1233. }
  1234. Vector2 _Geometry::get_closest_point_to_segment_2d(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b) {
  1235. Vector2 s[2] = { p_a, p_b };
  1236. return Geometry::get_closest_point_to_segment_2d(p_point, s);
  1237. }
  1238. Vector3 _Geometry::get_closest_point_to_segment(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b) {
  1239. Vector3 s[2] = { p_a, p_b };
  1240. return Geometry::get_closest_point_to_segment(p_point, s);
  1241. }
  1242. Vector2 _Geometry::get_closest_point_to_segment_uncapped_2d(const Vector2 &p_point, const Vector2 &p_a, const Vector2 &p_b) {
  1243. Vector2 s[2] = { p_a, p_b };
  1244. return Geometry::get_closest_point_to_segment_uncapped_2d(p_point, s);
  1245. }
  1246. Vector3 _Geometry::get_closest_point_to_segment_uncapped(const Vector3 &p_point, const Vector3 &p_a, const Vector3 &p_b) {
  1247. Vector3 s[2] = { p_a, p_b };
  1248. return Geometry::get_closest_point_to_segment_uncapped(p_point, s);
  1249. }
  1250. Variant _Geometry::ray_intersects_triangle(const Vector3 &p_from, const Vector3 &p_dir, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2) {
  1251. Vector3 res;
  1252. if (Geometry::ray_intersects_triangle(p_from, p_dir, p_v0, p_v1, p_v2, &res))
  1253. return res;
  1254. else
  1255. return Variant();
  1256. }
  1257. Variant _Geometry::segment_intersects_triangle(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_v0, const Vector3 &p_v1, const Vector3 &p_v2) {
  1258. Vector3 res;
  1259. if (Geometry::segment_intersects_triangle(p_from, p_to, p_v0, p_v1, p_v2, &res))
  1260. return res;
  1261. else
  1262. return Variant();
  1263. }
  1264. bool _Geometry::point_is_inside_triangle(const Vector2 &s, const Vector2 &a, const Vector2 &b, const Vector2 &c) const {
  1265. return Geometry::is_point_in_triangle(s, a, b, c);
  1266. }
  1267. PoolVector<Vector3> _Geometry::segment_intersects_sphere(const Vector3 &p_from, const Vector3 &p_to, const Vector3 &p_sphere_pos, real_t p_sphere_radius) {
  1268. PoolVector<Vector3> r;
  1269. Vector3 res, norm;
  1270. if (!Geometry::segment_intersects_sphere(p_from, p_to, p_sphere_pos, p_sphere_radius, &res, &norm))
  1271. return r;
  1272. r.resize(2);
  1273. r.set(0, res);
  1274. r.set(1, norm);
  1275. return r;
  1276. }
  1277. PoolVector<Vector3> _Geometry::segment_intersects_cylinder(const Vector3 &p_from, const Vector3 &p_to, float p_height, float p_radius) {
  1278. PoolVector<Vector3> r;
  1279. Vector3 res, norm;
  1280. if (!Geometry::segment_intersects_cylinder(p_from, p_to, p_height, p_radius, &res, &norm))
  1281. return r;
  1282. r.resize(2);
  1283. r.set(0, res);
  1284. r.set(1, norm);
  1285. return r;
  1286. }
  1287. PoolVector<Vector3> _Geometry::segment_intersects_convex(const Vector3 &p_from, const Vector3 &p_to, const Vector<Plane> &p_planes) {
  1288. PoolVector<Vector3> r;
  1289. Vector3 res, norm;
  1290. if (!Geometry::segment_intersects_convex(p_from, p_to, p_planes.ptr(), p_planes.size(), &res, &norm))
  1291. return r;
  1292. r.resize(2);
  1293. r.set(0, res);
  1294. r.set(1, norm);
  1295. return r;
  1296. }
  1297. bool _Geometry::is_polygon_clockwise(const Vector<Vector2> &p_polygon) {
  1298. return Geometry::is_polygon_clockwise(p_polygon);
  1299. }
  1300. bool _Geometry::is_point_in_polygon(const Point2 &p_point, const Vector<Vector2> &p_polygon) {
  1301. return Geometry::is_point_in_polygon(p_point, p_polygon);
  1302. }
  1303. Vector<int> _Geometry::triangulate_polygon(const Vector<Vector2> &p_polygon) {
  1304. return Geometry::triangulate_polygon(p_polygon);
  1305. }
  1306. Vector<int> _Geometry::triangulate_delaunay_2d(const Vector<Vector2> &p_points) {
  1307. return Geometry::triangulate_delaunay_2d(p_points);
  1308. }
  1309. Vector<Point2> _Geometry::convex_hull_2d(const Vector<Point2> &p_points) {
  1310. return Geometry::convex_hull_2d(p_points);
  1311. }
  1312. Vector<Vector3> _Geometry::clip_polygon(const Vector<Vector3> &p_points, const Plane &p_plane) {
  1313. return Geometry::clip_polygon(p_points, p_plane);
  1314. }
  1315. Array _Geometry::merge_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
  1316. Vector<Vector<Point2> > polys = Geometry::merge_polygons_2d(p_polygon_a, p_polygon_b);
  1317. Array ret;
  1318. for (int i = 0; i < polys.size(); ++i) {
  1319. ret.push_back(polys[i]);
  1320. }
  1321. return ret;
  1322. }
  1323. Array _Geometry::clip_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
  1324. Vector<Vector<Point2> > polys = Geometry::clip_polygons_2d(p_polygon_a, p_polygon_b);
  1325. Array ret;
  1326. for (int i = 0; i < polys.size(); ++i) {
  1327. ret.push_back(polys[i]);
  1328. }
  1329. return ret;
  1330. }
  1331. Array _Geometry::intersect_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
  1332. Vector<Vector<Point2> > polys = Geometry::intersect_polygons_2d(p_polygon_a, p_polygon_b);
  1333. Array ret;
  1334. for (int i = 0; i < polys.size(); ++i) {
  1335. ret.push_back(polys[i]);
  1336. }
  1337. return ret;
  1338. }
  1339. Array _Geometry::exclude_polygons_2d(const Vector<Vector2> &p_polygon_a, const Vector<Vector2> &p_polygon_b) {
  1340. Vector<Vector<Point2> > polys = Geometry::exclude_polygons_2d(p_polygon_a, p_polygon_b);
  1341. Array ret;
  1342. for (int i = 0; i < polys.size(); ++i) {
  1343. ret.push_back(polys[i]);
  1344. }
  1345. return ret;
  1346. }
  1347. Array _Geometry::clip_polyline_with_polygon_2d(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) {
  1348. Vector<Vector<Point2> > polys = Geometry::clip_polyline_with_polygon_2d(p_polyline, p_polygon);
  1349. Array ret;
  1350. for (int i = 0; i < polys.size(); ++i) {
  1351. ret.push_back(polys[i]);
  1352. }
  1353. return ret;
  1354. }
  1355. Array _Geometry::intersect_polyline_with_polygon_2d(const Vector<Vector2> &p_polyline, const Vector<Vector2> &p_polygon) {
  1356. Vector<Vector<Point2> > polys = Geometry::intersect_polyline_with_polygon_2d(p_polyline, p_polygon);
  1357. Array ret;
  1358. for (int i = 0; i < polys.size(); ++i) {
  1359. ret.push_back(polys[i]);
  1360. }
  1361. return ret;
  1362. }
  1363. Array _Geometry::offset_polygon_2d(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type) {
  1364. Vector<Vector<Point2> > polys = Geometry::offset_polygon_2d(p_polygon, p_delta, Geometry::PolyJoinType(p_join_type));
  1365. Array ret;
  1366. for (int i = 0; i < polys.size(); ++i) {
  1367. ret.push_back(polys[i]);
  1368. }
  1369. return ret;
  1370. }
  1371. Array _Geometry::offset_polyline_2d(const Vector<Vector2> &p_polygon, real_t p_delta, PolyJoinType p_join_type, PolyEndType p_end_type) {
  1372. Vector<Vector<Point2> > polys = Geometry::offset_polyline_2d(p_polygon, p_delta, Geometry::PolyJoinType(p_join_type), Geometry::PolyEndType(p_end_type));
  1373. Array ret;
  1374. for (int i = 0; i < polys.size(); ++i) {
  1375. ret.push_back(polys[i]);
  1376. }
  1377. return ret;
  1378. }
  1379. Dictionary _Geometry::make_atlas(const Vector<Size2> &p_rects) {
  1380. Dictionary ret;
  1381. Vector<Size2i> rects;
  1382. for (int i = 0; i < p_rects.size(); i++) {
  1383. rects.push_back(p_rects[i]);
  1384. };
  1385. Vector<Point2i> result;
  1386. Size2i size;
  1387. Geometry::make_atlas(rects, result, size);
  1388. Size2 r_size = size;
  1389. Vector<Point2> r_result;
  1390. for (int i = 0; i < result.size(); i++) {
  1391. r_result.push_back(result[i]);
  1392. };
  1393. ret["points"] = r_result;
  1394. ret["size"] = r_size;
  1395. return ret;
  1396. };
  1397. int _Geometry::get_uv84_normal_bit(const Vector3 &p_vector) {
  1398. return Geometry::get_uv84_normal_bit(p_vector);
  1399. }
  1400. void _Geometry::_bind_methods() {
  1401. ClassDB::bind_method(D_METHOD("build_box_planes", "extents"), &_Geometry::build_box_planes);
  1402. ClassDB::bind_method(D_METHOD("build_cylinder_planes", "radius", "height", "sides", "axis"), &_Geometry::build_cylinder_planes, DEFVAL(Vector3::AXIS_Z));
  1403. ClassDB::bind_method(D_METHOD("build_capsule_planes", "radius", "height", "sides", "lats", "axis"), &_Geometry::build_capsule_planes, DEFVAL(Vector3::AXIS_Z));
  1404. ClassDB::bind_method(D_METHOD("is_point_in_circle", "point", "circle_position", "circle_radius"), &_Geometry::is_point_in_circle);
  1405. ClassDB::bind_method(D_METHOD("segment_intersects_circle", "segment_from", "segment_to", "circle_position", "circle_radius"), &_Geometry::segment_intersects_circle);
  1406. ClassDB::bind_method(D_METHOD("segment_intersects_segment_2d", "from_a", "to_a", "from_b", "to_b"), &_Geometry::segment_intersects_segment_2d);
  1407. ClassDB::bind_method(D_METHOD("line_intersects_line_2d", "from_a", "dir_a", "from_b", "dir_b"), &_Geometry::line_intersects_line_2d);
  1408. ClassDB::bind_method(D_METHOD("get_closest_points_between_segments_2d", "p1", "q1", "p2", "q2"), &_Geometry::get_closest_points_between_segments_2d);
  1409. ClassDB::bind_method(D_METHOD("get_closest_points_between_segments", "p1", "p2", "q1", "q2"), &_Geometry::get_closest_points_between_segments);
  1410. ClassDB::bind_method(D_METHOD("get_closest_point_to_segment_2d", "point", "s1", "s2"), &_Geometry::get_closest_point_to_segment_2d);
  1411. ClassDB::bind_method(D_METHOD("get_closest_point_to_segment", "point", "s1", "s2"), &_Geometry::get_closest_point_to_segment);
  1412. ClassDB::bind_method(D_METHOD("get_closest_point_to_segment_uncapped_2d", "point", "s1", "s2"), &_Geometry::get_closest_point_to_segment_uncapped_2d);
  1413. ClassDB::bind_method(D_METHOD("get_closest_point_to_segment_uncapped", "point", "s1", "s2"), &_Geometry::get_closest_point_to_segment_uncapped);
  1414. ClassDB::bind_method(D_METHOD("get_uv84_normal_bit", "normal"), &_Geometry::get_uv84_normal_bit);
  1415. ClassDB::bind_method(D_METHOD("ray_intersects_triangle", "from", "dir", "a", "b", "c"), &_Geometry::ray_intersects_triangle);
  1416. ClassDB::bind_method(D_METHOD("segment_intersects_triangle", "from", "to", "a", "b", "c"), &_Geometry::segment_intersects_triangle);
  1417. ClassDB::bind_method(D_METHOD("segment_intersects_sphere", "from", "to", "sphere_position", "sphere_radius"), &_Geometry::segment_intersects_sphere);
  1418. ClassDB::bind_method(D_METHOD("segment_intersects_cylinder", "from", "to", "height", "radius"), &_Geometry::segment_intersects_cylinder);
  1419. ClassDB::bind_method(D_METHOD("segment_intersects_convex", "from", "to", "planes"), &_Geometry::segment_intersects_convex);
  1420. ClassDB::bind_method(D_METHOD("point_is_inside_triangle", "point", "a", "b", "c"), &_Geometry::point_is_inside_triangle);
  1421. ClassDB::bind_method(D_METHOD("is_polygon_clockwise", "polygon"), &_Geometry::is_polygon_clockwise);
  1422. ClassDB::bind_method(D_METHOD("is_point_in_polygon", "point", "polygon"), &_Geometry::is_point_in_polygon);
  1423. ClassDB::bind_method(D_METHOD("triangulate_polygon", "polygon"), &_Geometry::triangulate_polygon);
  1424. ClassDB::bind_method(D_METHOD("triangulate_delaunay_2d", "points"), &_Geometry::triangulate_delaunay_2d);
  1425. ClassDB::bind_method(D_METHOD("convex_hull_2d", "points"), &_Geometry::convex_hull_2d);
  1426. ClassDB::bind_method(D_METHOD("clip_polygon", "points", "plane"), &_Geometry::clip_polygon);
  1427. ClassDB::bind_method(D_METHOD("merge_polygons_2d", "polygon_a", "polygon_b"), &_Geometry::merge_polygons_2d);
  1428. ClassDB::bind_method(D_METHOD("clip_polygons_2d", "polygon_a", "polygon_b"), &_Geometry::clip_polygons_2d);
  1429. ClassDB::bind_method(D_METHOD("intersect_polygons_2d", "polygon_a", "polygon_b"), &_Geometry::intersect_polygons_2d);
  1430. ClassDB::bind_method(D_METHOD("exclude_polygons_2d", "polygon_a", "polygon_b"), &_Geometry::exclude_polygons_2d);
  1431. ClassDB::bind_method(D_METHOD("clip_polyline_with_polygon_2d", "polyline", "polygon"), &_Geometry::clip_polyline_with_polygon_2d);
  1432. ClassDB::bind_method(D_METHOD("intersect_polyline_with_polygon_2d", "polyline", "polygon"), &_Geometry::intersect_polyline_with_polygon_2d);
  1433. ClassDB::bind_method(D_METHOD("offset_polygon_2d", "polygon", "delta", "join_type"), &_Geometry::offset_polygon_2d, DEFVAL(JOIN_SQUARE));
  1434. ClassDB::bind_method(D_METHOD("offset_polyline_2d", "polyline", "delta", "join_type", "end_type"), &_Geometry::offset_polyline_2d, DEFVAL(JOIN_SQUARE), DEFVAL(END_SQUARE));
  1435. ClassDB::bind_method(D_METHOD("make_atlas", "sizes"), &_Geometry::make_atlas);
  1436. BIND_ENUM_CONSTANT(OPERATION_UNION);
  1437. BIND_ENUM_CONSTANT(OPERATION_DIFFERENCE);
  1438. BIND_ENUM_CONSTANT(OPERATION_INTERSECTION);
  1439. BIND_ENUM_CONSTANT(OPERATION_XOR);
  1440. BIND_ENUM_CONSTANT(JOIN_SQUARE);
  1441. BIND_ENUM_CONSTANT(JOIN_ROUND);
  1442. BIND_ENUM_CONSTANT(JOIN_MITER);
  1443. BIND_ENUM_CONSTANT(END_POLYGON);
  1444. BIND_ENUM_CONSTANT(END_JOINED);
  1445. BIND_ENUM_CONSTANT(END_BUTT);
  1446. BIND_ENUM_CONSTANT(END_SQUARE);
  1447. BIND_ENUM_CONSTANT(END_ROUND);
  1448. }
  1449. _Geometry::_Geometry() {
  1450. singleton = this;
  1451. }
  1452. ///////////////////////// FILE
  1453. Error _File::open_encrypted(const String &p_path, ModeFlags p_mode_flags, const Vector<uint8_t> &p_key) {
  1454. Error err = open(p_path, p_mode_flags);
  1455. if (err)
  1456. return err;
  1457. FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
  1458. err = fae->open_and_parse(f, p_key, (p_mode_flags == WRITE) ? FileAccessEncrypted::MODE_WRITE_AES256 : FileAccessEncrypted::MODE_READ);
  1459. if (err) {
  1460. memdelete(fae);
  1461. close();
  1462. return err;
  1463. }
  1464. f = fae;
  1465. return OK;
  1466. }
  1467. Error _File::open_encrypted_pass(const String &p_path, ModeFlags p_mode_flags, const String &p_pass) {
  1468. Error err = open(p_path, p_mode_flags);
  1469. if (err)
  1470. return err;
  1471. FileAccessEncrypted *fae = memnew(FileAccessEncrypted);
  1472. err = fae->open_and_parse_password(f, p_pass, (p_mode_flags == WRITE) ? FileAccessEncrypted::MODE_WRITE_AES256 : FileAccessEncrypted::MODE_READ);
  1473. if (err) {
  1474. memdelete(fae);
  1475. close();
  1476. return err;
  1477. }
  1478. f = fae;
  1479. return OK;
  1480. }
  1481. Error _File::open_compressed(const String &p_path, ModeFlags p_mode_flags, CompressionMode p_compress_mode) {
  1482. FileAccessCompressed *fac = memnew(FileAccessCompressed);
  1483. fac->configure("GCPF", (Compression::Mode)p_compress_mode);
  1484. Error err = fac->_open(p_path, p_mode_flags);
  1485. if (err) {
  1486. memdelete(fac);
  1487. return err;
  1488. }
  1489. f = fac;
  1490. return OK;
  1491. }
  1492. Error _File::open(const String &p_path, ModeFlags p_mode_flags) {
  1493. close();
  1494. Error err;
  1495. f = FileAccess::open(p_path, p_mode_flags, &err);
  1496. if (f)
  1497. f->set_endian_swap(eswap);
  1498. return err;
  1499. }
  1500. void _File::flush() {
  1501. ERR_FAIL_COND_MSG(!f, "File must be opened before flushing.");
  1502. f->flush();
  1503. }
  1504. void _File::close() {
  1505. if (f)
  1506. memdelete(f);
  1507. f = NULL;
  1508. }
  1509. bool _File::is_open() const {
  1510. return f != NULL;
  1511. }
  1512. String _File::get_path() const {
  1513. ERR_FAIL_COND_V_MSG(!f, "", "File must be opened before use.");
  1514. return f->get_path();
  1515. }
  1516. String _File::get_path_absolute() const {
  1517. ERR_FAIL_COND_V_MSG(!f, "", "File must be opened before use.");
  1518. return f->get_path_absolute();
  1519. }
  1520. void _File::seek(int64_t p_position) {
  1521. ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
  1522. f->seek(p_position);
  1523. }
  1524. void _File::seek_end(int64_t p_position) {
  1525. ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
  1526. f->seek_end(p_position);
  1527. }
  1528. int64_t _File::get_position() const {
  1529. ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
  1530. return f->get_position();
  1531. }
  1532. int64_t _File::get_len() const {
  1533. ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
  1534. return f->get_len();
  1535. }
  1536. bool _File::eof_reached() const {
  1537. ERR_FAIL_COND_V_MSG(!f, false, "File must be opened before use.");
  1538. return f->eof_reached();
  1539. }
  1540. uint8_t _File::get_8() const {
  1541. ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
  1542. return f->get_8();
  1543. }
  1544. uint16_t _File::get_16() const {
  1545. ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
  1546. return f->get_16();
  1547. }
  1548. uint32_t _File::get_32() const {
  1549. ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
  1550. return f->get_32();
  1551. }
  1552. uint64_t _File::get_64() const {
  1553. ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
  1554. return f->get_64();
  1555. }
  1556. float _File::get_float() const {
  1557. ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
  1558. return f->get_float();
  1559. }
  1560. double _File::get_double() const {
  1561. ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
  1562. return f->get_double();
  1563. }
  1564. real_t _File::get_real() const {
  1565. ERR_FAIL_COND_V_MSG(!f, 0, "File must be opened before use.");
  1566. return f->get_real();
  1567. }
  1568. PoolVector<uint8_t> _File::get_buffer(int p_length) const {
  1569. PoolVector<uint8_t> data;
  1570. ERR_FAIL_COND_V_MSG(!f, data, "File must be opened before use.");
  1571. ERR_FAIL_COND_V_MSG(p_length < 0, data, "Length of buffer cannot be smaller than 0.");
  1572. if (p_length == 0)
  1573. return data;
  1574. Error err = data.resize(p_length);
  1575. ERR_FAIL_COND_V_MSG(err != OK, data, "Can't resize data to " + itos(p_length) + " elements.");
  1576. PoolVector<uint8_t>::Write w = data.write();
  1577. int len = f->get_buffer(&w[0], p_length);
  1578. ERR_FAIL_COND_V(len < 0, PoolVector<uint8_t>());
  1579. w.release();
  1580. if (len < p_length)
  1581. data.resize(p_length);
  1582. return data;
  1583. }
  1584. String _File::get_as_text() const {
  1585. ERR_FAIL_COND_V_MSG(!f, String(), "File must be opened before use.");
  1586. String text;
  1587. size_t original_pos = f->get_position();
  1588. f->seek(0);
  1589. String l = get_line();
  1590. while (!eof_reached()) {
  1591. text += l + "\n";
  1592. l = get_line();
  1593. }
  1594. text += l;
  1595. f->seek(original_pos);
  1596. return text;
  1597. }
  1598. String _File::get_md5(const String &p_path) const {
  1599. return FileAccess::get_md5(p_path);
  1600. }
  1601. String _File::get_sha256(const String &p_path) const {
  1602. return FileAccess::get_sha256(p_path);
  1603. }
  1604. String _File::get_line() const {
  1605. ERR_FAIL_COND_V_MSG(!f, String(), "File must be opened before use.");
  1606. return f->get_line();
  1607. }
  1608. Vector<String> _File::get_csv_line(const String &p_delim) const {
  1609. ERR_FAIL_COND_V_MSG(!f, Vector<String>(), "File must be opened before use.");
  1610. return f->get_csv_line(p_delim);
  1611. }
  1612. /**< use this for files WRITTEN in _big_ endian machines (ie, amiga/mac)
  1613. * It's not about the current CPU type but file formats.
  1614. * this flags get reset to false (little endian) on each open
  1615. */
  1616. void _File::set_endian_swap(bool p_swap) {
  1617. eswap = p_swap;
  1618. if (f)
  1619. f->set_endian_swap(p_swap);
  1620. }
  1621. bool _File::get_endian_swap() {
  1622. return eswap;
  1623. }
  1624. Error _File::get_error() const {
  1625. if (!f)
  1626. return ERR_UNCONFIGURED;
  1627. return f->get_error();
  1628. }
  1629. void _File::store_8(uint8_t p_dest) {
  1630. ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
  1631. f->store_8(p_dest);
  1632. }
  1633. void _File::store_16(uint16_t p_dest) {
  1634. ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
  1635. f->store_16(p_dest);
  1636. }
  1637. void _File::store_32(uint32_t p_dest) {
  1638. ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
  1639. f->store_32(p_dest);
  1640. }
  1641. void _File::store_64(uint64_t p_dest) {
  1642. ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
  1643. f->store_64(p_dest);
  1644. }
  1645. void _File::store_float(float p_dest) {
  1646. ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
  1647. f->store_float(p_dest);
  1648. }
  1649. void _File::store_double(double p_dest) {
  1650. ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
  1651. f->store_double(p_dest);
  1652. }
  1653. void _File::store_real(real_t p_real) {
  1654. ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
  1655. f->store_real(p_real);
  1656. }
  1657. void _File::store_string(const String &p_string) {
  1658. ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
  1659. f->store_string(p_string);
  1660. }
  1661. void _File::store_pascal_string(const String &p_string) {
  1662. ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
  1663. f->store_pascal_string(p_string);
  1664. };
  1665. String _File::get_pascal_string() {
  1666. ERR_FAIL_COND_V_MSG(!f, "", "File must be opened before use.");
  1667. return f->get_pascal_string();
  1668. };
  1669. void _File::store_line(const String &p_string) {
  1670. ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
  1671. f->store_line(p_string);
  1672. }
  1673. void _File::store_csv_line(const Vector<String> &p_values, const String &p_delim) {
  1674. ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
  1675. f->store_csv_line(p_values, p_delim);
  1676. }
  1677. void _File::store_buffer(const PoolVector<uint8_t> &p_buffer) {
  1678. ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
  1679. int len = p_buffer.size();
  1680. if (len == 0)
  1681. return;
  1682. PoolVector<uint8_t>::Read r = p_buffer.read();
  1683. f->store_buffer(&r[0], len);
  1684. }
  1685. bool _File::file_exists(const String &p_name) const {
  1686. return FileAccess::exists(p_name);
  1687. }
  1688. void _File::store_var(const Variant &p_var, bool p_full_objects) {
  1689. ERR_FAIL_COND_MSG(!f, "File must be opened before use.");
  1690. int len;
  1691. Error err = encode_variant(p_var, NULL, len, p_full_objects);
  1692. ERR_FAIL_COND_MSG(err != OK, "Error when trying to encode Variant.");
  1693. PoolVector<uint8_t> buff;
  1694. buff.resize(len);
  1695. PoolVector<uint8_t>::Write w = buff.write();
  1696. err = encode_variant(p_var, &w[0], len, p_full_objects);
  1697. ERR_FAIL_COND_MSG(err != OK, "Error when trying to encode Variant.");
  1698. w.release();
  1699. store_32(len);
  1700. store_buffer(buff);
  1701. }
  1702. Variant _File::get_var(bool p_allow_objects) const {
  1703. ERR_FAIL_COND_V_MSG(!f, Variant(), "File must be opened before use.");
  1704. uint32_t len = get_32();
  1705. PoolVector<uint8_t> buff = get_buffer(len);
  1706. ERR_FAIL_COND_V((uint32_t)buff.size() != len, Variant());
  1707. PoolVector<uint8_t>::Read r = buff.read();
  1708. Variant v;
  1709. Error err = decode_variant(v, &r[0], len, NULL, p_allow_objects);
  1710. ERR_FAIL_COND_V_MSG(err != OK, Variant(), "Error when trying to encode Variant.");
  1711. return v;
  1712. }
  1713. uint64_t _File::get_modified_time(const String &p_file) const {
  1714. return FileAccess::get_modified_time(p_file);
  1715. }
  1716. void _File::_bind_methods() {
  1717. ClassDB::bind_method(D_METHOD("open_encrypted", "path", "mode_flags", "key"), &_File::open_encrypted);
  1718. ClassDB::bind_method(D_METHOD("open_encrypted_with_pass", "path", "mode_flags", "pass"), &_File::open_encrypted_pass);
  1719. ClassDB::bind_method(D_METHOD("open_compressed", "path", "mode_flags", "compression_mode"), &_File::open_compressed, DEFVAL(0));
  1720. ClassDB::bind_method(D_METHOD("open", "path", "flags"), &_File::open);
  1721. ClassDB::bind_method(D_METHOD("flush"), &_File::flush);
  1722. ClassDB::bind_method(D_METHOD("close"), &_File::close);
  1723. ClassDB::bind_method(D_METHOD("get_path"), &_File::get_path);
  1724. ClassDB::bind_method(D_METHOD("get_path_absolute"), &_File::get_path_absolute);
  1725. ClassDB::bind_method(D_METHOD("is_open"), &_File::is_open);
  1726. ClassDB::bind_method(D_METHOD("seek", "position"), &_File::seek);
  1727. ClassDB::bind_method(D_METHOD("seek_end", "position"), &_File::seek_end, DEFVAL(0));
  1728. ClassDB::bind_method(D_METHOD("get_position"), &_File::get_position);
  1729. ClassDB::bind_method(D_METHOD("get_len"), &_File::get_len);
  1730. ClassDB::bind_method(D_METHOD("eof_reached"), &_File::eof_reached);
  1731. ClassDB::bind_method(D_METHOD("get_8"), &_File::get_8);
  1732. ClassDB::bind_method(D_METHOD("get_16"), &_File::get_16);
  1733. ClassDB::bind_method(D_METHOD("get_32"), &_File::get_32);
  1734. ClassDB::bind_method(D_METHOD("get_64"), &_File::get_64);
  1735. ClassDB::bind_method(D_METHOD("get_float"), &_File::get_float);
  1736. ClassDB::bind_method(D_METHOD("get_double"), &_File::get_double);
  1737. ClassDB::bind_method(D_METHOD("get_real"), &_File::get_real);
  1738. ClassDB::bind_method(D_METHOD("get_buffer", "len"), &_File::get_buffer);
  1739. ClassDB::bind_method(D_METHOD("get_line"), &_File::get_line);
  1740. ClassDB::bind_method(D_METHOD("get_csv_line", "delim"), &_File::get_csv_line, DEFVAL(","));
  1741. ClassDB::bind_method(D_METHOD("get_as_text"), &_File::get_as_text);
  1742. ClassDB::bind_method(D_METHOD("get_md5", "path"), &_File::get_md5);
  1743. ClassDB::bind_method(D_METHOD("get_sha256", "path"), &_File::get_sha256);
  1744. ClassDB::bind_method(D_METHOD("get_endian_swap"), &_File::get_endian_swap);
  1745. ClassDB::bind_method(D_METHOD("set_endian_swap", "enable"), &_File::set_endian_swap);
  1746. ClassDB::bind_method(D_METHOD("get_error"), &_File::get_error);
  1747. ClassDB::bind_method(D_METHOD("get_var", "allow_objects"), &_File::get_var, DEFVAL(false));
  1748. ClassDB::bind_method(D_METHOD("store_8", "value"), &_File::store_8);
  1749. ClassDB::bind_method(D_METHOD("store_16", "value"), &_File::store_16);
  1750. ClassDB::bind_method(D_METHOD("store_32", "value"), &_File::store_32);
  1751. ClassDB::bind_method(D_METHOD("store_64", "value"), &_File::store_64);
  1752. ClassDB::bind_method(D_METHOD("store_float", "value"), &_File::store_float);
  1753. ClassDB::bind_method(D_METHOD("store_double", "value"), &_File::store_double);
  1754. ClassDB::bind_method(D_METHOD("store_real", "value"), &_File::store_real);
  1755. ClassDB::bind_method(D_METHOD("store_buffer", "buffer"), &_File::store_buffer);
  1756. ClassDB::bind_method(D_METHOD("store_line", "line"), &_File::store_line);
  1757. ClassDB::bind_method(D_METHOD("store_csv_line", "values", "delim"), &_File::store_csv_line, DEFVAL(","));
  1758. ClassDB::bind_method(D_METHOD("store_string", "string"), &_File::store_string);
  1759. ClassDB::bind_method(D_METHOD("store_var", "value", "full_objects"), &_File::store_var, DEFVAL(false));
  1760. ClassDB::bind_method(D_METHOD("store_pascal_string", "string"), &_File::store_pascal_string);
  1761. ClassDB::bind_method(D_METHOD("get_pascal_string"), &_File::get_pascal_string);
  1762. ClassDB::bind_method(D_METHOD("file_exists", "path"), &_File::file_exists);
  1763. ClassDB::bind_method(D_METHOD("get_modified_time", "file"), &_File::get_modified_time);
  1764. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "endian_swap"), "set_endian_swap", "get_endian_swap");
  1765. BIND_ENUM_CONSTANT(READ);
  1766. BIND_ENUM_CONSTANT(WRITE);
  1767. BIND_ENUM_CONSTANT(READ_WRITE);
  1768. BIND_ENUM_CONSTANT(WRITE_READ);
  1769. BIND_ENUM_CONSTANT(COMPRESSION_FASTLZ);
  1770. BIND_ENUM_CONSTANT(COMPRESSION_DEFLATE);
  1771. BIND_ENUM_CONSTANT(COMPRESSION_ZSTD);
  1772. BIND_ENUM_CONSTANT(COMPRESSION_GZIP);
  1773. }
  1774. _File::_File() {
  1775. f = NULL;
  1776. eswap = false;
  1777. }
  1778. _File::~_File() {
  1779. if (f)
  1780. memdelete(f);
  1781. }
  1782. ///////////////////////////////////////////////////////
  1783. Error _Directory::open(const String &p_path) {
  1784. Error err;
  1785. DirAccess *alt = DirAccess::open(p_path, &err);
  1786. if (!alt)
  1787. return err;
  1788. if (d)
  1789. memdelete(d);
  1790. d = alt;
  1791. return OK;
  1792. }
  1793. Error _Directory::list_dir_begin(bool p_skip_navigational, bool p_skip_hidden) {
  1794. ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
  1795. _list_skip_navigational = p_skip_navigational;
  1796. _list_skip_hidden = p_skip_hidden;
  1797. return d->list_dir_begin();
  1798. }
  1799. String _Directory::get_next() {
  1800. ERR_FAIL_COND_V_MSG(!d, "", "Directory must be opened before use.");
  1801. String next = d->get_next();
  1802. while (next != "" && ((_list_skip_navigational && (next == "." || next == "..")) || (_list_skip_hidden && d->current_is_hidden()))) {
  1803. next = d->get_next();
  1804. }
  1805. return next;
  1806. }
  1807. bool _Directory::current_is_dir() const {
  1808. ERR_FAIL_COND_V_MSG(!d, false, "Directory must be opened before use.");
  1809. return d->current_is_dir();
  1810. }
  1811. void _Directory::list_dir_end() {
  1812. ERR_FAIL_COND_MSG(!d, "Directory must be opened before use.");
  1813. d->list_dir_end();
  1814. }
  1815. int _Directory::get_drive_count() {
  1816. ERR_FAIL_COND_V_MSG(!d, 0, "Directory must be opened before use.");
  1817. return d->get_drive_count();
  1818. }
  1819. String _Directory::get_drive(int p_drive) {
  1820. ERR_FAIL_COND_V_MSG(!d, "", "Directory must be opened before use.");
  1821. return d->get_drive(p_drive);
  1822. }
  1823. int _Directory::get_current_drive() {
  1824. ERR_FAIL_COND_V_MSG(!d, 0, "Directory must be opened before use.");
  1825. return d->get_current_drive();
  1826. }
  1827. Error _Directory::change_dir(String p_dir) {
  1828. ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
  1829. return d->change_dir(p_dir);
  1830. }
  1831. String _Directory::get_current_dir() {
  1832. ERR_FAIL_COND_V_MSG(!d, "", "Directory must be opened before use.");
  1833. return d->get_current_dir();
  1834. }
  1835. Error _Directory::make_dir(String p_dir) {
  1836. ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
  1837. if (!p_dir.is_rel_path()) {
  1838. DirAccess *d = DirAccess::create_for_path(p_dir);
  1839. Error err = d->make_dir(p_dir);
  1840. memdelete(d);
  1841. return err;
  1842. }
  1843. return d->make_dir(p_dir);
  1844. }
  1845. Error _Directory::make_dir_recursive(String p_dir) {
  1846. ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
  1847. if (!p_dir.is_rel_path()) {
  1848. DirAccess *d = DirAccess::create_for_path(p_dir);
  1849. Error err = d->make_dir_recursive(p_dir);
  1850. memdelete(d);
  1851. return err;
  1852. }
  1853. return d->make_dir_recursive(p_dir);
  1854. }
  1855. bool _Directory::file_exists(String p_file) {
  1856. ERR_FAIL_COND_V_MSG(!d, false, "Directory must be opened before use.");
  1857. if (!p_file.is_rel_path()) {
  1858. return FileAccess::exists(p_file);
  1859. }
  1860. return d->file_exists(p_file);
  1861. }
  1862. bool _Directory::dir_exists(String p_dir) {
  1863. ERR_FAIL_COND_V_MSG(!d, false, "Directory must be opened before use.");
  1864. if (!p_dir.is_rel_path()) {
  1865. DirAccess *d = DirAccess::create_for_path(p_dir);
  1866. bool exists = d->dir_exists(p_dir);
  1867. memdelete(d);
  1868. return exists;
  1869. } else {
  1870. return d->dir_exists(p_dir);
  1871. }
  1872. }
  1873. int _Directory::get_space_left() {
  1874. ERR_FAIL_COND_V_MSG(!d, 0, "Directory must be opened before use.");
  1875. return d->get_space_left() / 1024 * 1024; //return value in megabytes, given binding is int
  1876. }
  1877. Error _Directory::copy(String p_from, String p_to) {
  1878. ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
  1879. return d->copy(p_from, p_to);
  1880. }
  1881. Error _Directory::rename(String p_from, String p_to) {
  1882. ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
  1883. ERR_FAIL_COND_V_MSG(p_from.empty() || p_from == "." || p_from == "..", ERR_INVALID_PARAMETER, "Invalid path to rename.");
  1884. if (!p_from.is_rel_path()) {
  1885. DirAccess *d = DirAccess::create_for_path(p_from);
  1886. 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.");
  1887. Error err = d->rename(p_from, p_to);
  1888. memdelete(d);
  1889. return err;
  1890. }
  1891. 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.");
  1892. return d->rename(p_from, p_to);
  1893. }
  1894. Error _Directory::remove(String p_name) {
  1895. ERR_FAIL_COND_V_MSG(!d, ERR_UNCONFIGURED, "Directory must be opened before use.");
  1896. if (!p_name.is_rel_path()) {
  1897. DirAccess *d = DirAccess::create_for_path(p_name);
  1898. Error err = d->remove(p_name);
  1899. memdelete(d);
  1900. return err;
  1901. }
  1902. return d->remove(p_name);
  1903. }
  1904. void _Directory::_bind_methods() {
  1905. ClassDB::bind_method(D_METHOD("open", "path"), &_Directory::open);
  1906. ClassDB::bind_method(D_METHOD("list_dir_begin", "skip_navigational", "skip_hidden"), &_Directory::list_dir_begin, DEFVAL(false), DEFVAL(false));
  1907. ClassDB::bind_method(D_METHOD("get_next"), &_Directory::get_next);
  1908. ClassDB::bind_method(D_METHOD("current_is_dir"), &_Directory::current_is_dir);
  1909. ClassDB::bind_method(D_METHOD("list_dir_end"), &_Directory::list_dir_end);
  1910. ClassDB::bind_method(D_METHOD("get_drive_count"), &_Directory::get_drive_count);
  1911. ClassDB::bind_method(D_METHOD("get_drive", "idx"), &_Directory::get_drive);
  1912. ClassDB::bind_method(D_METHOD("get_current_drive"), &_Directory::get_current_drive);
  1913. ClassDB::bind_method(D_METHOD("change_dir", "todir"), &_Directory::change_dir);
  1914. ClassDB::bind_method(D_METHOD("get_current_dir"), &_Directory::get_current_dir);
  1915. ClassDB::bind_method(D_METHOD("make_dir", "path"), &_Directory::make_dir);
  1916. ClassDB::bind_method(D_METHOD("make_dir_recursive", "path"), &_Directory::make_dir_recursive);
  1917. ClassDB::bind_method(D_METHOD("file_exists", "path"), &_Directory::file_exists);
  1918. ClassDB::bind_method(D_METHOD("dir_exists", "path"), &_Directory::dir_exists);
  1919. //ClassDB::bind_method(D_METHOD("get_modified_time","file"),&_Directory::get_modified_time);
  1920. ClassDB::bind_method(D_METHOD("get_space_left"), &_Directory::get_space_left);
  1921. ClassDB::bind_method(D_METHOD("copy", "from", "to"), &_Directory::copy);
  1922. ClassDB::bind_method(D_METHOD("rename", "from", "to"), &_Directory::rename);
  1923. ClassDB::bind_method(D_METHOD("remove", "path"), &_Directory::remove);
  1924. }
  1925. _Directory::_Directory() {
  1926. d = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  1927. }
  1928. _Directory::~_Directory() {
  1929. if (d)
  1930. memdelete(d);
  1931. }
  1932. _Marshalls *_Marshalls::singleton = NULL;
  1933. _Marshalls *_Marshalls::get_singleton() {
  1934. return singleton;
  1935. }
  1936. String _Marshalls::variant_to_base64(const Variant &p_var, bool p_full_objects) {
  1937. int len;
  1938. Error err = encode_variant(p_var, NULL, len, p_full_objects);
  1939. ERR_FAIL_COND_V_MSG(err != OK, "", "Error when trying to encode Variant.");
  1940. PoolVector<uint8_t> buff;
  1941. buff.resize(len);
  1942. PoolVector<uint8_t>::Write w = buff.write();
  1943. err = encode_variant(p_var, &w[0], len, p_full_objects);
  1944. ERR_FAIL_COND_V_MSG(err != OK, "", "Error when trying to encode Variant.");
  1945. String ret = CryptoCore::b64_encode_str(&w[0], len);
  1946. ERR_FAIL_COND_V(ret == "", ret);
  1947. return ret;
  1948. };
  1949. Variant _Marshalls::base64_to_variant(const String &p_str, bool p_allow_objects) {
  1950. int strlen = p_str.length();
  1951. CharString cstr = p_str.ascii();
  1952. PoolVector<uint8_t> buf;
  1953. buf.resize(strlen / 4 * 3 + 1);
  1954. PoolVector<uint8_t>::Write w = buf.write();
  1955. size_t len = 0;
  1956. ERR_FAIL_COND_V(CryptoCore::b64_decode(&w[0], buf.size(), &len, (unsigned char *)cstr.get_data(), strlen) != OK, Variant());
  1957. Variant v;
  1958. Error err = decode_variant(v, &w[0], len, NULL, p_allow_objects);
  1959. ERR_FAIL_COND_V_MSG(err != OK, Variant(), "Error when trying to decode Variant.");
  1960. return v;
  1961. };
  1962. String _Marshalls::raw_to_base64(const PoolVector<uint8_t> &p_arr) {
  1963. String ret = CryptoCore::b64_encode_str(p_arr.read().ptr(), p_arr.size());
  1964. ERR_FAIL_COND_V(ret == "", ret);
  1965. return ret;
  1966. };
  1967. PoolVector<uint8_t> _Marshalls::base64_to_raw(const String &p_str) {
  1968. int strlen = p_str.length();
  1969. CharString cstr = p_str.ascii();
  1970. size_t arr_len = 0;
  1971. PoolVector<uint8_t> buf;
  1972. {
  1973. buf.resize(strlen / 4 * 3 + 1);
  1974. PoolVector<uint8_t>::Write w = buf.write();
  1975. ERR_FAIL_COND_V(CryptoCore::b64_decode(&w[0], buf.size(), &arr_len, (unsigned char *)cstr.get_data(), strlen) != OK, PoolVector<uint8_t>());
  1976. }
  1977. buf.resize(arr_len);
  1978. return buf;
  1979. };
  1980. String _Marshalls::utf8_to_base64(const String &p_str) {
  1981. CharString cstr = p_str.utf8();
  1982. String ret = CryptoCore::b64_encode_str((unsigned char *)cstr.get_data(), cstr.length());
  1983. ERR_FAIL_COND_V(ret == "", ret);
  1984. return ret;
  1985. };
  1986. String _Marshalls::base64_to_utf8(const String &p_str) {
  1987. int strlen = p_str.length();
  1988. CharString cstr = p_str.ascii();
  1989. PoolVector<uint8_t> buf;
  1990. buf.resize(strlen / 4 * 3 + 1 + 1);
  1991. PoolVector<uint8_t>::Write w = buf.write();
  1992. size_t len = 0;
  1993. ERR_FAIL_COND_V(CryptoCore::b64_decode(&w[0], buf.size(), &len, (unsigned char *)cstr.get_data(), strlen) != OK, String());
  1994. w[len] = 0;
  1995. String ret = String::utf8((char *)&w[0]);
  1996. return ret;
  1997. };
  1998. void _Marshalls::_bind_methods() {
  1999. ClassDB::bind_method(D_METHOD("variant_to_base64", "variant", "full_objects"), &_Marshalls::variant_to_base64, DEFVAL(false));
  2000. ClassDB::bind_method(D_METHOD("base64_to_variant", "base64_str", "allow_objects"), &_Marshalls::base64_to_variant, DEFVAL(false));
  2001. ClassDB::bind_method(D_METHOD("raw_to_base64", "array"), &_Marshalls::raw_to_base64);
  2002. ClassDB::bind_method(D_METHOD("base64_to_raw", "base64_str"), &_Marshalls::base64_to_raw);
  2003. ClassDB::bind_method(D_METHOD("utf8_to_base64", "utf8_str"), &_Marshalls::utf8_to_base64);
  2004. ClassDB::bind_method(D_METHOD("base64_to_utf8", "base64_str"), &_Marshalls::base64_to_utf8);
  2005. };
  2006. ////////////////
  2007. Error _Semaphore::wait() {
  2008. semaphore.wait();
  2009. return OK; // Can't fail anymore; keep compat
  2010. }
  2011. Error _Semaphore::post() {
  2012. semaphore.post();
  2013. return OK; // Can't fail anymore; keep compat
  2014. }
  2015. void _Semaphore::_bind_methods() {
  2016. ClassDB::bind_method(D_METHOD("wait"), &_Semaphore::wait);
  2017. ClassDB::bind_method(D_METHOD("post"), &_Semaphore::post);
  2018. }
  2019. ///////////////
  2020. void _Mutex::lock() {
  2021. mutex.lock();
  2022. }
  2023. Error _Mutex::try_lock() {
  2024. return mutex.try_lock();
  2025. }
  2026. void _Mutex::unlock() {
  2027. mutex.unlock();
  2028. }
  2029. void _Mutex::_bind_methods() {
  2030. ClassDB::bind_method(D_METHOD("lock"), &_Mutex::lock);
  2031. ClassDB::bind_method(D_METHOD("try_lock"), &_Mutex::try_lock);
  2032. ClassDB::bind_method(D_METHOD("unlock"), &_Mutex::unlock);
  2033. }
  2034. ///////////////
  2035. void _Thread::_start_func(void *ud) {
  2036. Ref<_Thread> *tud = (Ref<_Thread> *)ud;
  2037. Ref<_Thread> t = *tud;
  2038. memdelete(tud);
  2039. Variant::CallError ce;
  2040. const Variant *arg[1] = { &t->userdata };
  2041. Thread::set_name(t->target_method);
  2042. t->ret = t->target_instance->call(t->target_method, arg, 1, ce);
  2043. if (ce.error != Variant::CallError::CALL_OK) {
  2044. String reason;
  2045. switch (ce.error) {
  2046. case Variant::CallError::CALL_ERROR_INVALID_ARGUMENT: {
  2047. reason = "Invalid Argument #" + itos(ce.argument);
  2048. } break;
  2049. case Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS: {
  2050. reason = "Too Many Arguments";
  2051. } break;
  2052. case Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS: {
  2053. reason = "Too Few Arguments";
  2054. } break;
  2055. case Variant::CallError::CALL_ERROR_INVALID_METHOD: {
  2056. reason = "Method Not Found";
  2057. } break;
  2058. default: {
  2059. }
  2060. }
  2061. ERR_FAIL_MSG("Could not call function '" + t->target_method.operator String() + "' to start thread " + t->get_id() + ": " + reason + ".");
  2062. }
  2063. }
  2064. Error _Thread::start(Object *p_instance, const StringName &p_method, const Variant &p_userdata, Priority p_priority) {
  2065. ERR_FAIL_COND_V_MSG(active.is_set(), ERR_ALREADY_IN_USE, "Thread already started.");
  2066. ERR_FAIL_COND_V(!p_instance, ERR_INVALID_PARAMETER);
  2067. ERR_FAIL_COND_V(p_method == StringName(), ERR_INVALID_PARAMETER);
  2068. ERR_FAIL_INDEX_V(p_priority, PRIORITY_MAX, ERR_INVALID_PARAMETER);
  2069. ret = Variant();
  2070. target_method = p_method;
  2071. target_instance = p_instance;
  2072. userdata = p_userdata;
  2073. active.set();
  2074. Ref<_Thread> *ud = memnew(Ref<_Thread>(this));
  2075. Thread::Settings s;
  2076. s.priority = (Thread::Priority)p_priority;
  2077. thread.start(_start_func, ud, s);
  2078. return OK;
  2079. }
  2080. String _Thread::get_id() const {
  2081. return itos(thread.get_id());
  2082. }
  2083. bool _Thread::is_active() const {
  2084. return active.is_set();
  2085. }
  2086. Variant _Thread::wait_to_finish() {
  2087. ERR_FAIL_COND_V_MSG(!active.is_set(), Variant(), "Thread must be active to wait for its completion.");
  2088. thread.wait_to_finish();
  2089. Variant r = ret;
  2090. target_method = StringName();
  2091. target_instance = NULL;
  2092. userdata = Variant();
  2093. active.clear();
  2094. return r;
  2095. }
  2096. void _Thread::_bind_methods() {
  2097. ClassDB::bind_method(D_METHOD("start", "instance", "method", "userdata", "priority"), &_Thread::start, DEFVAL(Variant()), DEFVAL(PRIORITY_NORMAL));
  2098. ClassDB::bind_method(D_METHOD("get_id"), &_Thread::get_id);
  2099. ClassDB::bind_method(D_METHOD("is_active"), &_Thread::is_active);
  2100. ClassDB::bind_method(D_METHOD("wait_to_finish"), &_Thread::wait_to_finish);
  2101. BIND_ENUM_CONSTANT(PRIORITY_LOW);
  2102. BIND_ENUM_CONSTANT(PRIORITY_NORMAL);
  2103. BIND_ENUM_CONSTANT(PRIORITY_HIGH);
  2104. }
  2105. _Thread::_Thread() {
  2106. target_instance = NULL;
  2107. }
  2108. _Thread::~_Thread() {
  2109. ERR_FAIL_COND_MSG(active.is_set(), "Reference to a Thread object was lost while the thread is still running...");
  2110. }
  2111. /////////////////////////////////////
  2112. PoolStringArray _ClassDB::get_class_list() const {
  2113. List<StringName> classes;
  2114. ClassDB::get_class_list(&classes);
  2115. PoolStringArray ret;
  2116. ret.resize(classes.size());
  2117. int idx = 0;
  2118. for (List<StringName>::Element *E = classes.front(); E; E = E->next()) {
  2119. ret.set(idx++, E->get());
  2120. }
  2121. return ret;
  2122. }
  2123. PoolStringArray _ClassDB::get_inheriters_from_class(const StringName &p_class) const {
  2124. List<StringName> classes;
  2125. ClassDB::get_inheriters_from_class(p_class, &classes);
  2126. PoolStringArray ret;
  2127. ret.resize(classes.size());
  2128. int idx = 0;
  2129. for (List<StringName>::Element *E = classes.front(); E; E = E->next()) {
  2130. ret.set(idx++, E->get());
  2131. }
  2132. return ret;
  2133. }
  2134. StringName _ClassDB::get_parent_class(const StringName &p_class) const {
  2135. return ClassDB::get_parent_class(p_class);
  2136. }
  2137. bool _ClassDB::class_exists(const StringName &p_class) const {
  2138. return ClassDB::class_exists(p_class);
  2139. }
  2140. bool _ClassDB::is_parent_class(const StringName &p_class, const StringName &p_inherits) const {
  2141. return ClassDB::is_parent_class(p_class, p_inherits);
  2142. }
  2143. bool _ClassDB::can_instance(const StringName &p_class) const {
  2144. return ClassDB::can_instance(p_class);
  2145. }
  2146. Variant _ClassDB::instance(const StringName &p_class) const {
  2147. Object *obj = ClassDB::instance(p_class);
  2148. if (!obj)
  2149. return Variant();
  2150. Reference *r = Object::cast_to<Reference>(obj);
  2151. if (r) {
  2152. return REF(r);
  2153. } else {
  2154. return obj;
  2155. }
  2156. }
  2157. bool _ClassDB::has_signal(StringName p_class, StringName p_signal) const {
  2158. return ClassDB::has_signal(p_class, p_signal);
  2159. }
  2160. Dictionary _ClassDB::get_signal(StringName p_class, StringName p_signal) const {
  2161. MethodInfo signal;
  2162. if (ClassDB::get_signal(p_class, p_signal, &signal)) {
  2163. return signal.operator Dictionary();
  2164. } else {
  2165. return Dictionary();
  2166. }
  2167. }
  2168. Array _ClassDB::get_signal_list(StringName p_class, bool p_no_inheritance) const {
  2169. List<MethodInfo> signals;
  2170. ClassDB::get_signal_list(p_class, &signals, p_no_inheritance);
  2171. Array ret;
  2172. for (List<MethodInfo>::Element *E = signals.front(); E; E = E->next()) {
  2173. ret.push_back(E->get().operator Dictionary());
  2174. }
  2175. return ret;
  2176. }
  2177. Array _ClassDB::get_property_list(StringName p_class, bool p_no_inheritance) const {
  2178. List<PropertyInfo> plist;
  2179. ClassDB::get_property_list(p_class, &plist, p_no_inheritance);
  2180. Array ret;
  2181. for (List<PropertyInfo>::Element *E = plist.front(); E; E = E->next()) {
  2182. ret.push_back(E->get().operator Dictionary());
  2183. }
  2184. return ret;
  2185. }
  2186. Variant _ClassDB::get_property(Object *p_object, const StringName &p_property) const {
  2187. Variant ret;
  2188. ClassDB::get_property(p_object, p_property, ret);
  2189. return ret;
  2190. }
  2191. Error _ClassDB::set_property(Object *p_object, const StringName &p_property, const Variant &p_value) const {
  2192. Variant ret;
  2193. bool valid;
  2194. if (!ClassDB::set_property(p_object, p_property, p_value, &valid)) {
  2195. return ERR_UNAVAILABLE;
  2196. } else if (!valid) {
  2197. return ERR_INVALID_DATA;
  2198. }
  2199. return OK;
  2200. }
  2201. bool _ClassDB::has_method(StringName p_class, StringName p_method, bool p_no_inheritance) const {
  2202. return ClassDB::has_method(p_class, p_method, p_no_inheritance);
  2203. }
  2204. Array _ClassDB::get_method_list(StringName p_class, bool p_no_inheritance) const {
  2205. List<MethodInfo> methods;
  2206. ClassDB::get_method_list(p_class, &methods, p_no_inheritance);
  2207. Array ret;
  2208. for (List<MethodInfo>::Element *E = methods.front(); E; E = E->next()) {
  2209. #ifdef DEBUG_METHODS_ENABLED
  2210. ret.push_back(E->get().operator Dictionary());
  2211. #else
  2212. Dictionary dict;
  2213. dict["name"] = E->get().name;
  2214. ret.push_back(dict);
  2215. #endif
  2216. }
  2217. return ret;
  2218. }
  2219. PoolStringArray _ClassDB::get_integer_constant_list(const StringName &p_class, bool p_no_inheritance) const {
  2220. List<String> constants;
  2221. ClassDB::get_integer_constant_list(p_class, &constants, p_no_inheritance);
  2222. PoolStringArray ret;
  2223. ret.resize(constants.size());
  2224. int idx = 0;
  2225. for (List<String>::Element *E = constants.front(); E; E = E->next()) {
  2226. ret.set(idx++, E->get());
  2227. }
  2228. return ret;
  2229. }
  2230. bool _ClassDB::has_integer_constant(const StringName &p_class, const StringName &p_name) const {
  2231. bool success;
  2232. ClassDB::get_integer_constant(p_class, p_name, &success);
  2233. return success;
  2234. }
  2235. int _ClassDB::get_integer_constant(const StringName &p_class, const StringName &p_name) const {
  2236. bool found;
  2237. int c = ClassDB::get_integer_constant(p_class, p_name, &found);
  2238. ERR_FAIL_COND_V(!found, 0);
  2239. return c;
  2240. }
  2241. StringName _ClassDB::get_category(const StringName &p_node) const {
  2242. return ClassDB::get_category(p_node);
  2243. }
  2244. bool _ClassDB::is_class_enabled(StringName p_class) const {
  2245. return ClassDB::is_class_enabled(p_class);
  2246. }
  2247. void _ClassDB::_bind_methods() {
  2248. ClassDB::bind_method(D_METHOD("get_class_list"), &_ClassDB::get_class_list);
  2249. ClassDB::bind_method(D_METHOD("get_inheriters_from_class", "class"), &_ClassDB::get_inheriters_from_class);
  2250. ClassDB::bind_method(D_METHOD("get_parent_class", "class"), &_ClassDB::get_parent_class);
  2251. ClassDB::bind_method(D_METHOD("class_exists", "class"), &_ClassDB::class_exists);
  2252. ClassDB::bind_method(D_METHOD("is_parent_class", "class", "inherits"), &_ClassDB::is_parent_class);
  2253. ClassDB::bind_method(D_METHOD("can_instance", "class"), &_ClassDB::can_instance);
  2254. ClassDB::bind_method(D_METHOD("instance", "class"), &_ClassDB::instance);
  2255. ClassDB::bind_method(D_METHOD("class_has_signal", "class", "signal"), &_ClassDB::has_signal);
  2256. ClassDB::bind_method(D_METHOD("class_get_signal", "class", "signal"), &_ClassDB::get_signal);
  2257. ClassDB::bind_method(D_METHOD("class_get_signal_list", "class", "no_inheritance"), &_ClassDB::get_signal_list, DEFVAL(false));
  2258. ClassDB::bind_method(D_METHOD("class_get_property_list", "class", "no_inheritance"), &_ClassDB::get_property_list, DEFVAL(false));
  2259. ClassDB::bind_method(D_METHOD("class_get_property", "object", "property"), &_ClassDB::get_property);
  2260. ClassDB::bind_method(D_METHOD("class_set_property", "object", "property", "value"), &_ClassDB::set_property);
  2261. ClassDB::bind_method(D_METHOD("class_has_method", "class", "method", "no_inheritance"), &_ClassDB::has_method, DEFVAL(false));
  2262. ClassDB::bind_method(D_METHOD("class_get_method_list", "class", "no_inheritance"), &_ClassDB::get_method_list, DEFVAL(false));
  2263. ClassDB::bind_method(D_METHOD("class_get_integer_constant_list", "class", "no_inheritance"), &_ClassDB::get_integer_constant_list, DEFVAL(false));
  2264. ClassDB::bind_method(D_METHOD("class_has_integer_constant", "class", "name"), &_ClassDB::has_integer_constant);
  2265. ClassDB::bind_method(D_METHOD("class_get_integer_constant", "class", "name"), &_ClassDB::get_integer_constant);
  2266. ClassDB::bind_method(D_METHOD("class_get_category", "class"), &_ClassDB::get_category);
  2267. ClassDB::bind_method(D_METHOD("is_class_enabled", "class"), &_ClassDB::is_class_enabled);
  2268. }
  2269. _ClassDB::_ClassDB() {
  2270. }
  2271. _ClassDB::~_ClassDB() {
  2272. }
  2273. ///////////////////////////////
  2274. void _Engine::set_iterations_per_second(int p_ips) {
  2275. Engine::get_singleton()->set_iterations_per_second(p_ips);
  2276. }
  2277. int _Engine::get_iterations_per_second() const {
  2278. return Engine::get_singleton()->get_iterations_per_second();
  2279. }
  2280. void _Engine::set_physics_jitter_fix(float p_threshold) {
  2281. Engine::get_singleton()->set_physics_jitter_fix(p_threshold);
  2282. }
  2283. float _Engine::get_physics_jitter_fix() const {
  2284. return Engine::get_singleton()->get_physics_jitter_fix();
  2285. }
  2286. float _Engine::get_physics_interpolation_fraction() const {
  2287. return Engine::get_singleton()->get_physics_interpolation_fraction();
  2288. }
  2289. void _Engine::set_target_fps(int p_fps) {
  2290. Engine::get_singleton()->set_target_fps(p_fps);
  2291. }
  2292. int _Engine::get_target_fps() const {
  2293. return Engine::get_singleton()->get_target_fps();
  2294. }
  2295. float _Engine::get_frames_per_second() const {
  2296. return Engine::get_singleton()->get_frames_per_second();
  2297. }
  2298. uint64_t _Engine::get_physics_frames() const {
  2299. return Engine::get_singleton()->get_physics_frames();
  2300. }
  2301. uint64_t _Engine::get_idle_frames() const {
  2302. return Engine::get_singleton()->get_idle_frames();
  2303. }
  2304. void _Engine::set_time_scale(float p_scale) {
  2305. Engine::get_singleton()->set_time_scale(p_scale);
  2306. }
  2307. float _Engine::get_time_scale() {
  2308. return Engine::get_singleton()->get_time_scale();
  2309. }
  2310. int _Engine::get_frames_drawn() {
  2311. return Engine::get_singleton()->get_frames_drawn();
  2312. }
  2313. MainLoop *_Engine::get_main_loop() const {
  2314. //needs to remain in OS, since it's actually OS that interacts with it, but it's better exposed here
  2315. return OS::get_singleton()->get_main_loop();
  2316. }
  2317. Dictionary _Engine::get_version_info() const {
  2318. return Engine::get_singleton()->get_version_info();
  2319. }
  2320. Dictionary _Engine::get_author_info() const {
  2321. return Engine::get_singleton()->get_author_info();
  2322. }
  2323. Array _Engine::get_copyright_info() const {
  2324. return Engine::get_singleton()->get_copyright_info();
  2325. }
  2326. Dictionary _Engine::get_donor_info() const {
  2327. return Engine::get_singleton()->get_donor_info();
  2328. }
  2329. Dictionary _Engine::get_license_info() const {
  2330. return Engine::get_singleton()->get_license_info();
  2331. }
  2332. String _Engine::get_license_text() const {
  2333. return Engine::get_singleton()->get_license_text();
  2334. }
  2335. bool _Engine::is_in_physics_frame() const {
  2336. return Engine::get_singleton()->is_in_physics_frame();
  2337. }
  2338. bool _Engine::has_singleton(const String &p_name) const {
  2339. return Engine::get_singleton()->has_singleton(p_name);
  2340. }
  2341. Object *_Engine::get_singleton_object(const String &p_name) const {
  2342. return Engine::get_singleton()->get_singleton_object(p_name);
  2343. }
  2344. void _Engine::set_editor_hint(bool p_enabled) {
  2345. Engine::get_singleton()->set_editor_hint(p_enabled);
  2346. }
  2347. bool _Engine::is_editor_hint() const {
  2348. return Engine::get_singleton()->is_editor_hint();
  2349. }
  2350. void _Engine::_bind_methods() {
  2351. ClassDB::bind_method(D_METHOD("set_iterations_per_second", "iterations_per_second"), &_Engine::set_iterations_per_second);
  2352. ClassDB::bind_method(D_METHOD("get_iterations_per_second"), &_Engine::get_iterations_per_second);
  2353. ClassDB::bind_method(D_METHOD("set_physics_jitter_fix", "physics_jitter_fix"), &_Engine::set_physics_jitter_fix);
  2354. ClassDB::bind_method(D_METHOD("get_physics_jitter_fix"), &_Engine::get_physics_jitter_fix);
  2355. ClassDB::bind_method(D_METHOD("get_physics_interpolation_fraction"), &_Engine::get_physics_interpolation_fraction);
  2356. ClassDB::bind_method(D_METHOD("set_target_fps", "target_fps"), &_Engine::set_target_fps);
  2357. ClassDB::bind_method(D_METHOD("get_target_fps"), &_Engine::get_target_fps);
  2358. ClassDB::bind_method(D_METHOD("set_time_scale", "time_scale"), &_Engine::set_time_scale);
  2359. ClassDB::bind_method(D_METHOD("get_time_scale"), &_Engine::get_time_scale);
  2360. ClassDB::bind_method(D_METHOD("get_frames_drawn"), &_Engine::get_frames_drawn);
  2361. ClassDB::bind_method(D_METHOD("get_frames_per_second"), &_Engine::get_frames_per_second);
  2362. ClassDB::bind_method(D_METHOD("get_physics_frames"), &_Engine::get_physics_frames);
  2363. ClassDB::bind_method(D_METHOD("get_idle_frames"), &_Engine::get_idle_frames);
  2364. ClassDB::bind_method(D_METHOD("get_main_loop"), &_Engine::get_main_loop);
  2365. ClassDB::bind_method(D_METHOD("get_version_info"), &_Engine::get_version_info);
  2366. ClassDB::bind_method(D_METHOD("get_author_info"), &_Engine::get_author_info);
  2367. ClassDB::bind_method(D_METHOD("get_copyright_info"), &_Engine::get_copyright_info);
  2368. ClassDB::bind_method(D_METHOD("get_donor_info"), &_Engine::get_donor_info);
  2369. ClassDB::bind_method(D_METHOD("get_license_info"), &_Engine::get_license_info);
  2370. ClassDB::bind_method(D_METHOD("get_license_text"), &_Engine::get_license_text);
  2371. ClassDB::bind_method(D_METHOD("is_in_physics_frame"), &_Engine::is_in_physics_frame);
  2372. ClassDB::bind_method(D_METHOD("has_singleton", "name"), &_Engine::has_singleton);
  2373. ClassDB::bind_method(D_METHOD("get_singleton", "name"), &_Engine::get_singleton_object);
  2374. ClassDB::bind_method(D_METHOD("set_editor_hint", "enabled"), &_Engine::set_editor_hint);
  2375. ClassDB::bind_method(D_METHOD("is_editor_hint"), &_Engine::is_editor_hint);
  2376. ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editor_hint"), "set_editor_hint", "is_editor_hint");
  2377. ADD_PROPERTY(PropertyInfo(Variant::INT, "iterations_per_second"), "set_iterations_per_second", "get_iterations_per_second");
  2378. ADD_PROPERTY(PropertyInfo(Variant::INT, "target_fps"), "set_target_fps", "get_target_fps");
  2379. ADD_PROPERTY(PropertyInfo(Variant::REAL, "time_scale"), "set_time_scale", "get_time_scale");
  2380. ADD_PROPERTY(PropertyInfo(Variant::REAL, "physics_jitter_fix"), "set_physics_jitter_fix", "get_physics_jitter_fix");
  2381. }
  2382. _Engine *_Engine::singleton = NULL;
  2383. _Engine::_Engine() {
  2384. singleton = this;
  2385. }
  2386. void JSONParseResult::_bind_methods() {
  2387. ClassDB::bind_method(D_METHOD("get_error"), &JSONParseResult::get_error);
  2388. ClassDB::bind_method(D_METHOD("get_error_string"), &JSONParseResult::get_error_string);
  2389. ClassDB::bind_method(D_METHOD("get_error_line"), &JSONParseResult::get_error_line);
  2390. ClassDB::bind_method(D_METHOD("get_result"), &JSONParseResult::get_result);
  2391. ClassDB::bind_method(D_METHOD("set_error", "error"), &JSONParseResult::set_error);
  2392. ClassDB::bind_method(D_METHOD("set_error_string", "error_string"), &JSONParseResult::set_error_string);
  2393. ClassDB::bind_method(D_METHOD("set_error_line", "error_line"), &JSONParseResult::set_error_line);
  2394. ClassDB::bind_method(D_METHOD("set_result", "result"), &JSONParseResult::set_result);
  2395. ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "error", PROPERTY_HINT_NONE, "Error", PROPERTY_USAGE_CLASS_IS_ENUM), "set_error", "get_error");
  2396. ADD_PROPERTY(PropertyInfo(Variant::STRING, "error_string"), "set_error_string", "get_error_string");
  2397. ADD_PROPERTY(PropertyInfo(Variant::INT, "error_line"), "set_error_line", "get_error_line");
  2398. ADD_PROPERTY(PropertyInfo(Variant::NIL, "result", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT), "set_result", "get_result");
  2399. }
  2400. void JSONParseResult::set_error(Error p_error) {
  2401. error = p_error;
  2402. }
  2403. Error JSONParseResult::get_error() const {
  2404. return error;
  2405. }
  2406. void JSONParseResult::set_error_string(const String &p_error_string) {
  2407. error_string = p_error_string;
  2408. }
  2409. String JSONParseResult::get_error_string() const {
  2410. return error_string;
  2411. }
  2412. void JSONParseResult::set_error_line(int p_error_line) {
  2413. error_line = p_error_line;
  2414. }
  2415. int JSONParseResult::get_error_line() const {
  2416. return error_line;
  2417. }
  2418. void JSONParseResult::set_result(const Variant &p_result) {
  2419. result = p_result;
  2420. }
  2421. Variant JSONParseResult::get_result() const {
  2422. return result;
  2423. }
  2424. void _JSON::_bind_methods() {
  2425. ClassDB::bind_method(D_METHOD("print", "value", "indent", "sort_keys"), &_JSON::print, DEFVAL(String()), DEFVAL(false));
  2426. ClassDB::bind_method(D_METHOD("parse", "json"), &_JSON::parse);
  2427. }
  2428. String _JSON::print(const Variant &p_value, const String &p_indent, bool p_sort_keys) {
  2429. return JSON::print(p_value, p_indent, p_sort_keys);
  2430. }
  2431. Ref<JSONParseResult> _JSON::parse(const String &p_json) {
  2432. Ref<JSONParseResult> result;
  2433. result.instance();
  2434. result->error = JSON::parse(p_json, result->result, result->error_string, result->error_line);
  2435. if (result->error != OK) {
  2436. ERR_PRINTS(vformat("Error parsing JSON at line %s: %s", result->error_line, result->error_string));
  2437. }
  2438. return result;
  2439. }
  2440. _JSON *_JSON::singleton = NULL;
  2441. _JSON::_JSON() {
  2442. singleton = this;
  2443. }