core_bind.cpp 69 KB

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