core_bind.cpp 85 KB

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