core_bind.cpp 88 KB

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