core_bind.cpp 69 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629
  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. {
  454. /* Normal years. */
  455. { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 },
  456. /* Leap years. */
  457. { 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335, 366 }
  458. };
  459. ERR_EXPLAIN("Invalid second value of: " + itos(second));
  460. ERR_FAIL_COND_V( second > 59, 0);
  461. ERR_EXPLAIN("Invalid minute value of: " + itos(minute));
  462. ERR_FAIL_COND_V( minute > 59, 0);
  463. ERR_EXPLAIN("Invalid hour value of: " + itos(hour));
  464. ERR_FAIL_COND_V( hour > 23, 0);
  465. ERR_EXPLAIN("Invalid month value of: " + itos(month+1));
  466. ERR_FAIL_COND_V( month+1 > 12, 0);
  467. // Do this check after month is tested as valid
  468. ERR_EXPLAIN("Invalid day value of: " + itos(day) + " which is larger "
  469. "than "+ itos(MONTH_DAYS_TABLE[LEAPYEAR(year)][month]));
  470. ERR_FAIL_COND_V( day > MONTH_DAYS_TABLE[LEAPYEAR(year)][month], 0);
  471. // Calculate all the seconds from months past in this year
  472. uint64_t SECONDS_FROM_MONTHS_PAST_THIS_YEAR =
  473. DAYS_PAST_THIS_YEAR_TABLE[LEAPYEAR(year)][month] * SECONDS_PER_DAY;
  474. uint64_t SECONDS_FROM_YEARS_PAST = 0;
  475. for(unsigned int iyear = EPOCH_YR; iyear < year; iyear++) {
  476. SECONDS_FROM_YEARS_PAST += YEARSIZE(iyear) *
  477. SECONDS_PER_DAY;
  478. }
  479. uint64_t epoch =
  480. second +
  481. minute * SECONDS_PER_MINUTE +
  482. hour * SECONDS_PER_HOUR +
  483. // Subtract 1 from day, since the current day isn't over yet
  484. // and we cannot count all 24 hours.
  485. (day-1) * SECONDS_PER_DAY +
  486. SECONDS_FROM_MONTHS_PAST_THIS_YEAR +
  487. SECONDS_FROM_YEARS_PAST;
  488. return epoch;
  489. }
  490. /**
  491. * Get a dictionary of time values when given epoch time
  492. *
  493. * Dictionary Time values will be a union if values from #get_time
  494. * and #get_date dictionaries (with the exception of dst =
  495. * day light standard time, as it cannot be determined from epoch)
  496. *
  497. * @param unix_time_val epoch time to convert
  498. *
  499. * @return dictionary of date and time values
  500. */
  501. Dictionary _OS::get_datetime_from_unix_time( uint64_t unix_time_val) const {
  502. // Just fail if unix time is negative (when interpreted as an int).
  503. // This means the user passed in a negative value by accident
  504. ERR_EXPLAIN("unix_time_val was really huge!"+ itos(unix_time_val) +
  505. " You probably passed in a negative value!");
  506. ERR_FAIL_COND_V( (int64_t)unix_time_val < 0, Dictionary());
  507. OS::Date date;
  508. OS::Time time;
  509. unsigned long dayclock, dayno;
  510. int year = EPOCH_YR;
  511. dayclock = (unsigned long)unix_time_val % SECS_DAY;
  512. dayno = (unsigned long)unix_time_val / SECS_DAY;
  513. time.sec = dayclock % 60;
  514. time.min = (dayclock % 3600) / 60;
  515. time.hour = dayclock / 3600;
  516. /* day 0 was a thursday */
  517. date.weekday = static_cast<OS::Weekday>((dayno + 4) % 7);
  518. while (dayno >= YEARSIZE(year)) {
  519. dayno -= YEARSIZE(year);
  520. year++;
  521. }
  522. date.year = year;
  523. size_t imonth = 0;
  524. while (dayno >= MONTH_DAYS_TABLE[LEAPYEAR(year)][imonth]) {
  525. dayno -= MONTH_DAYS_TABLE[LEAPYEAR(year)][imonth];
  526. imonth++;
  527. }
  528. /// Add 1 to month to make sure months are indexed starting at 1
  529. date.month = static_cast<OS::Month>(imonth+1);
  530. date.day = dayno + 1;
  531. Dictionary timed;
  532. timed[HOUR_KEY]=time.hour;
  533. timed[MINUTE_KEY]=time.min;
  534. timed[SECOND_KEY]=time.sec;
  535. timed[YEAR_KEY]=date.year;
  536. timed[MONTH_KEY]=date.month;
  537. timed[DAY_KEY]=date.day;
  538. timed[WEEKDAY_KEY]=date.weekday;
  539. return timed;
  540. }
  541. Dictionary _OS::get_time_zone_info() const {
  542. OS::TimeZoneInfo info = OS::get_singleton()->get_time_zone_info();
  543. Dictionary infod;
  544. infod["bias"] = info.bias;
  545. infod["name"] = info.name;
  546. return infod;
  547. }
  548. uint64_t _OS::get_unix_time() const {
  549. return OS::get_singleton()->get_unix_time();
  550. }
  551. uint64_t _OS::get_system_time_secs() const {
  552. return OS::get_singleton()->get_system_time_secs();
  553. }
  554. void _OS::delay_usec(uint32_t p_usec) const {
  555. OS::get_singleton()->delay_usec(p_usec);
  556. }
  557. void _OS::delay_msec(uint32_t p_msec) const {
  558. OS::get_singleton()->delay_usec(int64_t(p_msec)*1000);
  559. }
  560. uint32_t _OS::get_ticks_msec() const {
  561. return OS::get_singleton()->get_ticks_msec();
  562. }
  563. uint32_t _OS::get_splash_tick_msec() const {
  564. return OS::get_singleton()->get_splash_tick_msec();
  565. }
  566. bool _OS::can_use_threads() const {
  567. return OS::get_singleton()->can_use_threads();
  568. }
  569. bool _OS::can_draw() const {
  570. return OS::get_singleton()->can_draw();
  571. }
  572. int _OS::get_processor_count() const {
  573. return OS::get_singleton()->get_processor_count();
  574. }
  575. bool _OS::is_stdout_verbose() const {
  576. return OS::get_singleton()->is_stdout_verbose();
  577. }
  578. void _OS::dump_memory_to_file(const String& p_file) {
  579. OS::get_singleton()->dump_memory_to_file(p_file.utf8().get_data());
  580. }
  581. struct _OSCoreBindImg {
  582. String path;
  583. Size2 size;
  584. int fmt;
  585. ObjectID id;
  586. int vram;
  587. bool operator<(const _OSCoreBindImg& p_img) const { return vram==p_img.vram ? id<p_img.id : vram > p_img.vram; }
  588. };
  589. void _OS::print_all_textures_by_size() {
  590. List<_OSCoreBindImg> imgs;
  591. int total=0;
  592. {
  593. List<Ref<Resource> > rsrc;
  594. ResourceCache::get_cached_resources(&rsrc);
  595. for (List<Ref<Resource> >::Element *E=rsrc.front();E;E=E->next()) {
  596. if (!E->get()->is_class("ImageTexture"))
  597. continue;
  598. Size2 size = E->get()->call("get_size");
  599. int fmt = E->get()->call("get_format");
  600. _OSCoreBindImg img;
  601. img.size=size;
  602. img.fmt=fmt;
  603. img.path=E->get()->get_path();
  604. img.vram=Image::get_image_data_size(img.size.width,img.size.height,Image::Format(img.fmt));
  605. img.id=E->get()->get_instance_ID();
  606. total+=img.vram;
  607. imgs.push_back(img);
  608. }
  609. }
  610. imgs.sort();
  611. for(List<_OSCoreBindImg>::Element *E=imgs.front();E;E=E->next()) {
  612. total-=E->get().vram;
  613. }
  614. }
  615. void _OS::print_resources_by_type(const Vector<String>& p_types) {
  616. Map<String,int> type_count;
  617. List<Ref<Resource> > resources;
  618. ResourceCache::get_cached_resources(&resources);
  619. List<Ref<Resource> > rsrc;
  620. ResourceCache::get_cached_resources(&rsrc);
  621. for (List<Ref<Resource> >::Element *E=rsrc.front();E;E=E->next()) {
  622. Ref<Resource> r = E->get();
  623. bool found = false;
  624. for (int i=0; i<p_types.size(); i++) {
  625. if (r->is_class(p_types[i]))
  626. found = true;
  627. }
  628. if (!found)
  629. continue;
  630. if (!type_count.has(r->get_class())) {
  631. type_count[r->get_class()]=0;
  632. }
  633. type_count[r->get_class()]++;
  634. }
  635. };
  636. bool _OS::has_virtual_keyboard() const {
  637. return OS::get_singleton()->has_virtual_keyboard();
  638. }
  639. void _OS::show_virtual_keyboard(const String& p_existing_text) {
  640. OS::get_singleton()->show_virtual_keyboard(p_existing_text, Rect2());
  641. }
  642. void _OS::hide_virtual_keyboard() {
  643. OS::get_singleton()->hide_virtual_keyboard();
  644. }
  645. void _OS::print_all_resources(const String& p_to_file ) {
  646. OS::get_singleton()->print_all_resources(p_to_file);
  647. }
  648. void _OS::print_resources_in_use(bool p_short) {
  649. OS::get_singleton()->print_resources_in_use(p_short);
  650. }
  651. void _OS::dump_resources_to_file(const String& p_file) {
  652. OS::get_singleton()->dump_resources_to_file(p_file.utf8().get_data());
  653. }
  654. String _OS::get_data_dir() const {
  655. return OS::get_singleton()->get_data_dir();
  656. };
  657. Error _OS::native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track) {
  658. return OS::get_singleton()->native_video_play(p_path, p_volume, p_audio_track, p_subtitle_track);
  659. };
  660. bool _OS::native_video_is_playing() {
  661. return OS::get_singleton()->native_video_is_playing();
  662. };
  663. void _OS::native_video_pause() {
  664. OS::get_singleton()->native_video_pause();
  665. };
  666. void _OS::native_video_unpause() {
  667. OS::get_singleton()->native_video_unpause();
  668. };
  669. void _OS::native_video_stop() {
  670. OS::get_singleton()->native_video_stop();
  671. };
  672. void _OS::request_attention() {
  673. OS::get_singleton()->request_attention();
  674. }
  675. bool _OS::is_debug_build() const {
  676. #ifdef DEBUG_ENABLED
  677. return true;
  678. #else
  679. return false;
  680. #endif
  681. }
  682. void _OS::set_screen_orientation(ScreenOrientation p_orientation) {
  683. OS::get_singleton()->set_screen_orientation(OS::ScreenOrientation(p_orientation));
  684. }
  685. _OS::ScreenOrientation _OS::get_screen_orientation() const {
  686. return ScreenOrientation(OS::get_singleton()->get_screen_orientation());
  687. }
  688. void _OS::set_keep_screen_on(bool p_enabled) {
  689. OS::get_singleton()->set_keep_screen_on(p_enabled);
  690. }
  691. bool _OS::is_keep_screen_on() const {
  692. return OS::get_singleton()->is_keep_screen_on();
  693. }
  694. String _OS::get_system_dir(SystemDir p_dir) const {
  695. return OS::get_singleton()->get_system_dir(OS::SystemDir(p_dir));
  696. }
  697. String _OS::get_scancode_string(uint32_t p_code) const {
  698. return keycode_get_string(p_code);
  699. }
  700. bool _OS::is_scancode_unicode(uint32_t p_unicode) const {
  701. return keycode_has_unicode(p_unicode);
  702. }
  703. int _OS::find_scancode_from_string(const String& p_code) const {
  704. return find_keycode(p_code);
  705. }
  706. void _OS::alert(const String& p_alert,const String& p_title) {
  707. OS::get_singleton()->alert(p_alert,p_title);
  708. }
  709. _OS *_OS::singleton=NULL;
  710. void _OS::_bind_methods() {
  711. //ClassDB::bind_method(_MD("get_mouse_pos"),&_OS::get_mouse_pos);
  712. //ClassDB::bind_method(_MD("is_mouse_grab_enabled"),&_OS::is_mouse_grab_enabled);
  713. ClassDB::bind_method(_MD("set_clipboard","clipboard"),&_OS::set_clipboard);
  714. ClassDB::bind_method(_MD("get_clipboard"),&_OS::get_clipboard);
  715. //will not delete for now, just unexpose
  716. //ClassDB::bind_method(_MD("set_video_mode","size","fullscreen","resizable","screen"),&_OS::set_video_mode,DEFVAL(0));
  717. //ClassDB::bind_method(_MD("get_video_mode_size","screen"),&_OS::get_video_mode,DEFVAL(0));
  718. //ClassDB::bind_method(_MD("is_video_mode_fullscreen","screen"),&_OS::is_video_mode_fullscreen,DEFVAL(0));
  719. //ClassDB::bind_method(_MD("is_video_mode_resizable","screen"),&_OS::is_video_mode_resizable,DEFVAL(0));
  720. //ClassDB::bind_method(_MD("get_fullscreen_mode_list","screen"),&_OS::get_fullscreen_mode_list,DEFVAL(0));
  721. ClassDB::bind_method(_MD("get_screen_count"),&_OS::get_screen_count);
  722. ClassDB::bind_method(_MD("get_current_screen"),&_OS::get_current_screen);
  723. ClassDB::bind_method(_MD("set_current_screen","screen"),&_OS::set_current_screen);
  724. ClassDB::bind_method(_MD("get_screen_position","screen"),&_OS::get_screen_position,DEFVAL(0));
  725. ClassDB::bind_method(_MD("get_screen_size","screen"),&_OS::get_screen_size,DEFVAL(0));
  726. ClassDB::bind_method(_MD("get_screen_dpi","screen"),&_OS::get_screen_dpi,DEFVAL(0));
  727. ClassDB::bind_method(_MD("get_window_position"),&_OS::get_window_position);
  728. ClassDB::bind_method(_MD("set_window_position","position"),&_OS::set_window_position);
  729. ClassDB::bind_method(_MD("get_window_size"),&_OS::get_window_size);
  730. ClassDB::bind_method(_MD("set_window_size","size"),&_OS::set_window_size);
  731. ClassDB::bind_method(_MD("set_window_fullscreen","enabled"),&_OS::set_window_fullscreen);
  732. ClassDB::bind_method(_MD("is_window_fullscreen"),&_OS::is_window_fullscreen);
  733. ClassDB::bind_method(_MD("set_window_resizable","enabled"),&_OS::set_window_resizable);
  734. ClassDB::bind_method(_MD("is_window_resizable"),&_OS::is_window_resizable);
  735. ClassDB::bind_method(_MD("set_window_minimized", "enabled"),&_OS::set_window_minimized);
  736. ClassDB::bind_method(_MD("is_window_minimized"),&_OS::is_window_minimized);
  737. ClassDB::bind_method(_MD("set_window_maximized", "enabled"),&_OS::set_window_maximized);
  738. ClassDB::bind_method(_MD("is_window_maximized"),&_OS::is_window_maximized);
  739. ClassDB::bind_method(_MD("request_attention"), &_OS::request_attention);
  740. ClassDB::bind_method(_MD("set_borderless_window", "borderless"), &_OS::set_borderless_window);
  741. ClassDB::bind_method(_MD("get_borderless_window"), &_OS::get_borderless_window);
  742. ClassDB::bind_method(_MD("set_screen_orientation","orientation"),&_OS::set_screen_orientation);
  743. ClassDB::bind_method(_MD("get_screen_orientation"),&_OS::get_screen_orientation);
  744. ClassDB::bind_method(_MD("set_keep_screen_on","enabled"),&_OS::set_keep_screen_on);
  745. ClassDB::bind_method(_MD("is_keep_screen_on"),&_OS::is_keep_screen_on);
  746. ClassDB::bind_method(_MD("has_touchscreen_ui_hint"),&_OS::has_touchscreen_ui_hint);
  747. ClassDB::bind_method(_MD("set_window_title","title"),&_OS::set_window_title);
  748. ClassDB::bind_method(_MD("set_low_processor_usage_mode","enable"),&_OS::set_low_processor_usage_mode);
  749. ClassDB::bind_method(_MD("is_in_low_processor_usage_mode"),&_OS::is_in_low_processor_usage_mode);
  750. ClassDB::bind_method(_MD("get_processor_count"),&_OS::get_processor_count);
  751. ClassDB::bind_method(_MD("get_executable_path"),&_OS::get_executable_path);
  752. ClassDB::bind_method(_MD("execute","path","arguments","blocking","output"),&_OS::execute,DEFVAL(Array()));
  753. ClassDB::bind_method(_MD("kill","pid"),&_OS::kill);
  754. ClassDB::bind_method(_MD("shell_open","uri"),&_OS::shell_open);
  755. ClassDB::bind_method(_MD("get_process_ID"),&_OS::get_process_ID);
  756. ClassDB::bind_method(_MD("get_environment","environment"),&_OS::get_environment);
  757. ClassDB::bind_method(_MD("has_environment","environment"),&_OS::has_environment);
  758. ClassDB::bind_method(_MD("get_name"),&_OS::get_name);
  759. ClassDB::bind_method(_MD("get_cmdline_args"),&_OS::get_cmdline_args);
  760. ClassDB::bind_method(_MD("get_datetime","utc"),&_OS::get_datetime,DEFVAL(false));
  761. ClassDB::bind_method(_MD("get_date","utc"),&_OS::get_date,DEFVAL(false));
  762. ClassDB::bind_method(_MD("get_time","utc"),&_OS::get_time,DEFVAL(false));
  763. ClassDB::bind_method(_MD("get_time_zone_info"),&_OS::get_time_zone_info);
  764. ClassDB::bind_method(_MD("get_unix_time"),&_OS::get_unix_time);
  765. ClassDB::bind_method(_MD("get_datetime_from_unix_time", "unix_time_val"),
  766. &_OS::get_datetime_from_unix_time);
  767. ClassDB::bind_method(_MD("get_unix_time_from_datetime", "datetime"),
  768. &_OS::get_unix_time_from_datetime);
  769. ClassDB::bind_method(_MD("get_system_time_secs"), &_OS::get_system_time_secs);
  770. ClassDB::bind_method(_MD("set_icon","icon"),&_OS::set_icon);
  771. ClassDB::bind_method(_MD("get_exit_code"),&_OS::get_exit_code);
  772. ClassDB::bind_method(_MD("set_exit_code","code"),&_OS::set_exit_code);
  773. ClassDB::bind_method(_MD("delay_usec","usec"),&_OS::delay_usec);
  774. ClassDB::bind_method(_MD("delay_msec","msec"),&_OS::delay_msec);
  775. ClassDB::bind_method(_MD("get_ticks_msec"),&_OS::get_ticks_msec);
  776. ClassDB::bind_method(_MD("get_splash_tick_msec"),&_OS::get_splash_tick_msec);
  777. ClassDB::bind_method(_MD("get_locale"),&_OS::get_locale);
  778. ClassDB::bind_method(_MD("get_latin_keyboard_variant"),&_OS::get_latin_keyboard_variant);
  779. ClassDB::bind_method(_MD("get_model_name"),&_OS::get_model_name);
  780. ClassDB::bind_method(_MD("can_draw"),&_OS::can_draw);
  781. ClassDB::bind_method(_MD("is_stdout_verbose"),&_OS::is_stdout_verbose);
  782. ClassDB::bind_method(_MD("can_use_threads"),&_OS::can_use_threads);
  783. ClassDB::bind_method(_MD("is_debug_build"),&_OS::is_debug_build);
  784. //ClassDB::bind_method(_MD("get_mouse_button_state"),&_OS::get_mouse_button_state);
  785. ClassDB::bind_method(_MD("dump_memory_to_file","file"),&_OS::dump_memory_to_file);
  786. ClassDB::bind_method(_MD("dump_resources_to_file","file"),&_OS::dump_resources_to_file);
  787. ClassDB::bind_method(_MD("has_virtual_keyboard"),&_OS::has_virtual_keyboard);
  788. ClassDB::bind_method(_MD("show_virtual_keyboard", "existing_text"),&_OS::show_virtual_keyboard,DEFVAL(""));
  789. ClassDB::bind_method(_MD("hide_virtual_keyboard"),&_OS::hide_virtual_keyboard);
  790. ClassDB::bind_method(_MD("print_resources_in_use","short"),&_OS::print_resources_in_use,DEFVAL(false));
  791. ClassDB::bind_method(_MD("print_all_resources","tofile"),&_OS::print_all_resources,DEFVAL(""));
  792. ClassDB::bind_method(_MD("get_static_memory_usage"),&_OS::get_static_memory_usage);
  793. ClassDB::bind_method(_MD("get_static_memory_peak_usage"),&_OS::get_static_memory_peak_usage);
  794. ClassDB::bind_method(_MD("get_dynamic_memory_usage"),&_OS::get_dynamic_memory_usage);
  795. ClassDB::bind_method(_MD("get_data_dir"),&_OS::get_data_dir);
  796. ClassDB::bind_method(_MD("get_system_dir","dir"),&_OS::get_system_dir);
  797. ClassDB::bind_method(_MD("get_unique_ID"),&_OS::get_unique_ID);
  798. ClassDB::bind_method(_MD("is_ok_left_and_cancel_right"),&_OS::is_ok_left_and_cancel_right);
  799. ClassDB::bind_method(_MD("print_all_textures_by_size"),&_OS::print_all_textures_by_size);
  800. ClassDB::bind_method(_MD("print_resources_by_type","types"),&_OS::print_resources_by_type);
  801. ClassDB::bind_method(_MD("native_video_play","path","volume","audio_track","subtitle_track"),&_OS::native_video_play);
  802. ClassDB::bind_method(_MD("native_video_is_playing"),&_OS::native_video_is_playing);
  803. ClassDB::bind_method(_MD("native_video_stop"),&_OS::native_video_stop);
  804. ClassDB::bind_method(_MD("native_video_pause"),&_OS::native_video_pause);
  805. ClassDB::bind_method(_MD("native_video_unpause"),&_OS::native_video_unpause);
  806. ClassDB::bind_method(_MD("get_scancode_string","code"),&_OS::get_scancode_string);
  807. ClassDB::bind_method(_MD("is_scancode_unicode","code"),&_OS::is_scancode_unicode);
  808. ClassDB::bind_method(_MD("find_scancode_from_string","string"),&_OS::find_scancode_from_string);
  809. ClassDB::bind_method(_MD("set_use_file_access_save_and_swap","enabled"),&_OS::set_use_file_access_save_and_swap);
  810. ClassDB::bind_method(_MD("alert","text","title"),&_OS::alert,DEFVAL("Alert!"));
  811. ClassDB::bind_method(_MD("set_thread_name","name"),&_OS::set_thread_name);
  812. ClassDB::bind_method(_MD("set_use_vsync","enable"),&_OS::set_use_vsync);
  813. ClassDB::bind_method(_MD("is_vsync_enabled"),&_OS::is_vsync_enabled);
  814. BIND_CONSTANT( DAY_SUNDAY );
  815. BIND_CONSTANT( DAY_MONDAY );
  816. BIND_CONSTANT( DAY_TUESDAY );
  817. BIND_CONSTANT( DAY_WEDNESDAY );
  818. BIND_CONSTANT( DAY_THURSDAY );
  819. BIND_CONSTANT( DAY_FRIDAY );
  820. BIND_CONSTANT( DAY_SATURDAY );
  821. BIND_CONSTANT( MONTH_JANUARY );
  822. BIND_CONSTANT( MONTH_FEBRUARY );
  823. BIND_CONSTANT( MONTH_MARCH );
  824. BIND_CONSTANT( MONTH_APRIL );
  825. BIND_CONSTANT( MONTH_MAY );
  826. BIND_CONSTANT( MONTH_JUNE );
  827. BIND_CONSTANT( MONTH_JULY );
  828. BIND_CONSTANT( MONTH_AUGUST );
  829. BIND_CONSTANT( MONTH_SEPTEMBER );
  830. BIND_CONSTANT( MONTH_OCTOBER );
  831. BIND_CONSTANT( MONTH_NOVEMBER );
  832. BIND_CONSTANT( MONTH_DECEMBER );
  833. BIND_CONSTANT( SCREEN_ORIENTATION_LANDSCAPE );
  834. BIND_CONSTANT( SCREEN_ORIENTATION_PORTRAIT );
  835. BIND_CONSTANT( SCREEN_ORIENTATION_REVERSE_LANDSCAPE );
  836. BIND_CONSTANT( SCREEN_ORIENTATION_REVERSE_PORTRAIT );
  837. BIND_CONSTANT( SCREEN_ORIENTATION_SENSOR_LANDSCAPE );
  838. BIND_CONSTANT( SCREEN_ORIENTATION_SENSOR_PORTRAIT );
  839. BIND_CONSTANT( SCREEN_ORIENTATION_SENSOR );
  840. BIND_CONSTANT( SYSTEM_DIR_DESKTOP);
  841. BIND_CONSTANT( SYSTEM_DIR_DCIM );
  842. BIND_CONSTANT( SYSTEM_DIR_DOCUMENTS );
  843. BIND_CONSTANT( SYSTEM_DIR_DOWNLOADS );
  844. BIND_CONSTANT( SYSTEM_DIR_MOVIES );
  845. BIND_CONSTANT( SYSTEM_DIR_MUSIC );
  846. BIND_CONSTANT( SYSTEM_DIR_PICTURES );
  847. BIND_CONSTANT( SYSTEM_DIR_RINGTONES );
  848. }
  849. _OS::_OS() {
  850. singleton=this;
  851. }
  852. ///////////////////// GEOMETRY
  853. _Geometry *_Geometry::singleton=NULL;
  854. _Geometry *_Geometry::get_singleton() {
  855. return singleton;
  856. }
  857. PoolVector<Plane> _Geometry::build_box_planes(const Vector3& p_extents) {
  858. return Geometry::build_box_planes(p_extents);
  859. }
  860. PoolVector<Plane> _Geometry::build_cylinder_planes(float p_radius, float p_height, int p_sides, Vector3::Axis p_axis) {
  861. return Geometry::build_cylinder_planes(p_radius,p_height,p_sides,p_axis);
  862. }
  863. PoolVector<Plane> _Geometry::build_capsule_planes(float p_radius, float p_height, int p_sides, int p_lats, Vector3::Axis p_axis) {
  864. return Geometry::build_capsule_planes(p_radius,p_height,p_sides,p_lats,p_axis);
  865. }
  866. real_t _Geometry::segment_intersects_circle(const Vector2& p_from, const Vector2& p_to, const Vector2& p_circle_pos, real_t p_circle_radius) {
  867. return Geometry::segment_intersects_circle(p_from,p_to,p_circle_pos,p_circle_radius);
  868. }
  869. 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) {
  870. Vector2 result;
  871. if (Geometry::segment_intersects_segment_2d(p_from_a, p_to_a, p_from_b, p_to_b, &result)) {
  872. return result;
  873. } else {
  874. return Variant();
  875. };
  876. };
  877. PoolVector<Vector2> _Geometry::get_closest_points_between_segments_2d( const Vector2& p1,const Vector2& q1, const Vector2& p2,const Vector2& q2) {
  878. Vector2 r1, r2;
  879. Geometry::get_closest_points_between_segments(p1,q1,p2,q2,r1,r2);
  880. PoolVector<Vector2> r;
  881. r.resize(2);
  882. r.set(0,r1);
  883. r.set(1,r2);
  884. return r;
  885. }
  886. PoolVector<Vector3> _Geometry::get_closest_points_between_segments(const Vector3& p1,const Vector3& p2,const Vector3& q1,const Vector3& q2) {
  887. Vector3 r1, r2;
  888. Geometry::get_closest_points_between_segments(p1,p2,q1,q2,r1,r2);
  889. PoolVector<Vector3> r;
  890. r.resize(2);
  891. r.set(0,r1);
  892. r.set(1,r2);
  893. return r;
  894. }
  895. Vector3 _Geometry::get_closest_point_to_segment(const Vector3& p_point, const Vector3& p_a,const Vector3& p_b) {
  896. Vector3 s[2]={p_a,p_b};
  897. return Geometry::get_closest_point_to_segment(p_point,s);
  898. }
  899. 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) {
  900. Vector3 res;
  901. if (Geometry::ray_intersects_triangle(p_from,p_dir,p_v0,p_v1,p_v2,&res))
  902. return res;
  903. else
  904. return Variant();
  905. }
  906. 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) {
  907. Vector3 res;
  908. if (Geometry::segment_intersects_triangle(p_from,p_to,p_v0,p_v1,p_v2,&res))
  909. return res;
  910. else
  911. return Variant();
  912. }
  913. bool _Geometry::point_is_inside_triangle(const Vector2& s, const Vector2& a, const Vector2& b, const Vector2& c) const {
  914. return Geometry::is_point_in_triangle(s,a,b,c);
  915. }
  916. PoolVector<Vector3> _Geometry::segment_intersects_sphere( const Vector3& p_from, const Vector3& p_to, const Vector3& p_sphere_pos,real_t p_sphere_radius) {
  917. PoolVector<Vector3> r;
  918. Vector3 res,norm;
  919. if (!Geometry::segment_intersects_sphere(p_from,p_to,p_sphere_pos,p_sphere_radius,&res,&norm))
  920. return r;
  921. r.resize(2);
  922. r.set(0,res);
  923. r.set(1,norm);
  924. return r;
  925. }
  926. PoolVector<Vector3> _Geometry::segment_intersects_cylinder( const Vector3& p_from, const Vector3& p_to, float p_height,float p_radius) {
  927. PoolVector<Vector3> r;
  928. Vector3 res,norm;
  929. if (!Geometry::segment_intersects_cylinder(p_from,p_to,p_height,p_radius,&res,&norm))
  930. return r;
  931. r.resize(2);
  932. r.set(0,res);
  933. r.set(1,norm);
  934. return r;
  935. }
  936. PoolVector<Vector3> _Geometry::segment_intersects_convex(const Vector3& p_from, const Vector3& p_to,const Vector<Plane>& p_planes) {
  937. PoolVector<Vector3> r;
  938. Vector3 res,norm;
  939. if (!Geometry::segment_intersects_convex(p_from,p_to,p_planes.ptr(),p_planes.size(),&res,&norm))
  940. return r;
  941. r.resize(2);
  942. r.set(0,res);
  943. r.set(1,norm);
  944. return r;
  945. }
  946. Vector<int> _Geometry::triangulate_polygon(const Vector<Vector2>& p_polygon) {
  947. return Geometry::triangulate_polygon(p_polygon);
  948. }
  949. Dictionary _Geometry::make_atlas(const Vector<Size2>& p_rects) {
  950. Dictionary ret;
  951. Vector<Size2i> rects;
  952. for (int i=0; i<p_rects.size(); i++) {
  953. rects.push_back(p_rects[i]);
  954. };
  955. Vector<Point2i> result;
  956. Size2i size;
  957. Geometry::make_atlas(rects, result, size);
  958. Size2 r_size = size;
  959. Vector<Point2> r_result;
  960. for (int i=0; i<result.size(); i++) {
  961. r_result.push_back(result[i]);
  962. };
  963. ret["points"] = r_result;
  964. ret["size"] = r_size;
  965. return ret;
  966. };
  967. int _Geometry::get_uv84_normal_bit(const Vector3& p_vector) {
  968. return Geometry::get_uv84_normal_bit(p_vector);
  969. }
  970. void _Geometry::_bind_methods() {
  971. ClassDB::bind_method(_MD("build_box_planes","extents"),&_Geometry::build_box_planes);
  972. ClassDB::bind_method(_MD("build_cylinder_planes","radius","height","sides","axis"),&_Geometry::build_cylinder_planes,DEFVAL(Vector3::AXIS_Z));
  973. ClassDB::bind_method(_MD("build_capsule_planes","radius","height","sides","lats","axis"),&_Geometry::build_capsule_planes,DEFVAL(Vector3::AXIS_Z));
  974. ClassDB::bind_method(_MD("segment_intersects_circle","segment_from","segment_to","circle_pos","circle_radius"),&_Geometry::segment_intersects_circle);
  975. ClassDB::bind_method(_MD("segment_intersects_segment_2d","from_a","to_a","from_b","to_b"),&_Geometry::segment_intersects_segment_2d);
  976. ClassDB::bind_method(_MD("get_closest_points_between_segments_2d","p1","q1","p2","q2"),&_Geometry::get_closest_points_between_segments_2d);
  977. ClassDB::bind_method(_MD("get_closest_points_between_segments","p1","p2","q1","q2"),&_Geometry::get_closest_points_between_segments);
  978. ClassDB::bind_method(_MD("get_closest_point_to_segment","point","s1","s2"),&_Geometry::get_closest_point_to_segment);
  979. ClassDB::bind_method(_MD("get_uv84_normal_bit","normal"),&_Geometry::get_uv84_normal_bit);
  980. ClassDB::bind_method(_MD("ray_intersects_triangle","from","dir","a","b","c"),&_Geometry::ray_intersects_triangle);
  981. ClassDB::bind_method(_MD("segment_intersects_triangle","from","to","a","b","c"),&_Geometry::segment_intersects_triangle);
  982. ClassDB::bind_method(_MD("segment_intersects_sphere","from","to","spos","sradius"),&_Geometry::segment_intersects_sphere);
  983. ClassDB::bind_method(_MD("segment_intersects_cylinder","from","to","height","radius"),&_Geometry::segment_intersects_cylinder);
  984. ClassDB::bind_method(_MD("segment_intersects_convex","from","to","planes"),&_Geometry::segment_intersects_convex);
  985. ClassDB::bind_method(_MD("point_is_inside_triangle","point","a","b","c"),&_Geometry::point_is_inside_triangle);
  986. ClassDB::bind_method(_MD("triangulate_polygon","polygon"),&_Geometry::triangulate_polygon);
  987. ClassDB::bind_method(_MD("make_atlas","sizes"),&_Geometry::make_atlas);
  988. }
  989. _Geometry::_Geometry() {
  990. singleton=this;
  991. }
  992. ///////////////////////// FILE
  993. Error _File::open_encrypted(const String& p_path, int p_mode_flags,const Vector<uint8_t>& p_key) {
  994. Error err = open(p_path,p_mode_flags);
  995. if (err)
  996. return err;
  997. FileAccessEncrypted *fae = memnew( FileAccessEncrypted );
  998. err = fae->open_and_parse(f,p_key,(p_mode_flags==WRITE)?FileAccessEncrypted::MODE_WRITE_AES256:FileAccessEncrypted::MODE_READ);
  999. if (err) {
  1000. memdelete(fae);
  1001. close();
  1002. return err;
  1003. }
  1004. f=fae;
  1005. return OK;
  1006. }
  1007. Error _File::open_encrypted_pass(const String& p_path, int p_mode_flags,const String& p_pass) {
  1008. Error err = open(p_path,p_mode_flags);
  1009. if (err)
  1010. return err;
  1011. FileAccessEncrypted *fae = memnew( FileAccessEncrypted );
  1012. err = fae->open_and_parse_password(f,p_pass,(p_mode_flags==WRITE)?FileAccessEncrypted::MODE_WRITE_AES256:FileAccessEncrypted::MODE_READ);
  1013. if (err) {
  1014. memdelete(fae);
  1015. close();
  1016. return err;
  1017. }
  1018. f=fae;
  1019. return OK;
  1020. }
  1021. Error _File::open(const String& p_path, int p_mode_flags) {
  1022. close();
  1023. Error err;
  1024. f = FileAccess::open(p_path,p_mode_flags,&err);
  1025. if (f)
  1026. f->set_endian_swap(eswap);
  1027. return err;
  1028. }
  1029. void _File::close(){
  1030. if (f)
  1031. memdelete(f);
  1032. f=NULL;
  1033. }
  1034. bool _File::is_open() const{
  1035. return f!=NULL;
  1036. }
  1037. void _File::seek(int64_t p_position){
  1038. ERR_FAIL_COND(!f);
  1039. f->seek(p_position);
  1040. }
  1041. void _File::seek_end(int64_t p_position){
  1042. ERR_FAIL_COND(!f);
  1043. f->seek_end(p_position);
  1044. }
  1045. int64_t _File::get_pos() const{
  1046. ERR_FAIL_COND_V(!f,0);
  1047. return f->get_pos();
  1048. }
  1049. int64_t _File::get_len() const{
  1050. ERR_FAIL_COND_V(!f,0);
  1051. return f->get_len();
  1052. }
  1053. bool _File::eof_reached() const{
  1054. ERR_FAIL_COND_V(!f,false);
  1055. return f->eof_reached();
  1056. }
  1057. uint8_t _File::get_8() const{
  1058. ERR_FAIL_COND_V(!f,0);
  1059. return f->get_8();
  1060. }
  1061. uint16_t _File::get_16() const{
  1062. ERR_FAIL_COND_V(!f,0);
  1063. return f->get_16();
  1064. }
  1065. uint32_t _File::get_32() const{
  1066. ERR_FAIL_COND_V(!f,0);
  1067. return f->get_32();
  1068. }
  1069. uint64_t _File::get_64() const{
  1070. ERR_FAIL_COND_V(!f,0);
  1071. return f->get_64();
  1072. }
  1073. float _File::get_float() const{
  1074. ERR_FAIL_COND_V(!f,0);
  1075. return f->get_float();
  1076. }
  1077. double _File::get_double() const{
  1078. ERR_FAIL_COND_V(!f,0);
  1079. return f->get_double();
  1080. }
  1081. real_t _File::get_real() const{
  1082. ERR_FAIL_COND_V(!f,0);
  1083. return f->get_real();
  1084. }
  1085. PoolVector<uint8_t> _File::get_buffer(int p_length) const{
  1086. PoolVector<uint8_t> data;
  1087. ERR_FAIL_COND_V(!f,data);
  1088. ERR_FAIL_COND_V(p_length<0,data);
  1089. if (p_length==0)
  1090. return data;
  1091. Error err = data.resize(p_length);
  1092. ERR_FAIL_COND_V(err!=OK,data);
  1093. PoolVector<uint8_t>::Write w = data.write();
  1094. int len = f->get_buffer(&w[0],p_length);
  1095. ERR_FAIL_COND_V( len < 0 , PoolVector<uint8_t>());
  1096. w = PoolVector<uint8_t>::Write();
  1097. if (len < p_length)
  1098. data.resize(p_length);
  1099. return data;
  1100. }
  1101. String _File::get_as_text() const {
  1102. ERR_FAIL_COND_V(!f, String());
  1103. String text;
  1104. size_t original_pos = f->get_pos();
  1105. f->seek(0);
  1106. String l = get_line();
  1107. while(!eof_reached()) {
  1108. text+=l+"\n";
  1109. l = get_line();
  1110. }
  1111. text+=l;
  1112. f->seek(original_pos);
  1113. return text;
  1114. }
  1115. String _File::get_md5(const String& p_path) const {
  1116. return FileAccess::get_md5(p_path);
  1117. }
  1118. String _File::get_sha256(const String& p_path) const {
  1119. return FileAccess::get_sha256(p_path);
  1120. }
  1121. String _File::get_line() const{
  1122. ERR_FAIL_COND_V(!f,String());
  1123. return f->get_line();
  1124. }
  1125. Vector<String> _File::get_csv_line(String delim) const {
  1126. ERR_FAIL_COND_V(!f,Vector<String>());
  1127. return f->get_csv_line(delim);
  1128. }
  1129. /**< use this for files WRITTEN in _big_ endian machines (ie, amiga/mac)
  1130. * It's not about the current CPU type but file formats.
  1131. * this flags get reset to false (little endian) on each open
  1132. */
  1133. void _File::set_endian_swap(bool p_swap){
  1134. eswap=p_swap;
  1135. if (f)
  1136. f->set_endian_swap(p_swap);
  1137. }
  1138. bool _File::get_endian_swap(){
  1139. return eswap;
  1140. }
  1141. Error _File::get_error() const{
  1142. if (!f)
  1143. return ERR_UNCONFIGURED;
  1144. return f->get_error();
  1145. }
  1146. void _File::store_8(uint8_t p_dest){
  1147. ERR_FAIL_COND(!f);
  1148. f->store_8(p_dest);
  1149. }
  1150. void _File::store_16(uint16_t p_dest){
  1151. ERR_FAIL_COND(!f);
  1152. f->store_16(p_dest);
  1153. }
  1154. void _File::store_32(uint32_t p_dest){
  1155. ERR_FAIL_COND(!f);
  1156. f->store_32(p_dest);
  1157. }
  1158. void _File::store_64(uint64_t p_dest){
  1159. ERR_FAIL_COND(!f);
  1160. f->store_64(p_dest);
  1161. }
  1162. void _File::store_float(float p_dest){
  1163. ERR_FAIL_COND(!f);
  1164. f->store_float(p_dest);
  1165. }
  1166. void _File::store_double(double p_dest){
  1167. ERR_FAIL_COND(!f);
  1168. f->store_double(p_dest);
  1169. }
  1170. void _File::store_real(real_t p_real){
  1171. ERR_FAIL_COND(!f);
  1172. f->store_real(p_real);
  1173. }
  1174. void _File::store_string(const String& p_string){
  1175. ERR_FAIL_COND(!f);
  1176. f->store_string(p_string);
  1177. }
  1178. void _File::store_pascal_string(const String& p_string) {
  1179. ERR_FAIL_COND(!f);
  1180. f->store_pascal_string(p_string);
  1181. };
  1182. String _File::get_pascal_string() {
  1183. ERR_FAIL_COND_V(!f, "");
  1184. return f->get_pascal_string();
  1185. };
  1186. void _File::store_line(const String& p_string){
  1187. ERR_FAIL_COND(!f);
  1188. f->store_line(p_string);
  1189. }
  1190. void _File::store_buffer(const PoolVector<uint8_t>& p_buffer){
  1191. ERR_FAIL_COND(!f);
  1192. int len = p_buffer.size();
  1193. if (len==0)
  1194. return;
  1195. PoolVector<uint8_t>::Read r = p_buffer.read();
  1196. f->store_buffer(&r[0],len);
  1197. }
  1198. bool _File::file_exists(const String& p_name) const{
  1199. return FileAccess::exists(p_name);
  1200. }
  1201. void _File::store_var(const Variant& p_var) {
  1202. ERR_FAIL_COND(!f);
  1203. int len;
  1204. Error err = encode_variant(p_var,NULL,len);
  1205. ERR_FAIL_COND( err != OK );
  1206. PoolVector<uint8_t> buff;
  1207. buff.resize(len);
  1208. PoolVector<uint8_t>::Write w = buff.write();
  1209. err = encode_variant(p_var,&w[0],len);
  1210. ERR_FAIL_COND( err != OK );
  1211. w=PoolVector<uint8_t>::Write();
  1212. store_32(len);
  1213. store_buffer(buff);
  1214. }
  1215. Variant _File::get_var() const {
  1216. ERR_FAIL_COND_V(!f,Variant());
  1217. uint32_t len = get_32();
  1218. PoolVector<uint8_t> buff = get_buffer(len);
  1219. ERR_FAIL_COND_V(buff.size() != len, Variant());
  1220. PoolVector<uint8_t>::Read r = buff.read();
  1221. Variant v;
  1222. Error err = decode_variant(v,&r[0],len);
  1223. ERR_FAIL_COND_V( err!=OK, Variant() );
  1224. return v;
  1225. }
  1226. void _File::_bind_methods() {
  1227. ClassDB::bind_method(_MD("open_encrypted","path","mode_flags","key"),&_File::open_encrypted);
  1228. ClassDB::bind_method(_MD("open_encrypted_with_pass","path","mode_flags","pass"),&_File::open_encrypted_pass);
  1229. ClassDB::bind_method(_MD("open","path","flags"),&_File::open);
  1230. ClassDB::bind_method(_MD("close"),&_File::close);
  1231. ClassDB::bind_method(_MD("is_open"),&_File::is_open);
  1232. ClassDB::bind_method(_MD("seek","pos"),&_File::seek);
  1233. ClassDB::bind_method(_MD("seek_end","pos"),&_File::seek_end,DEFVAL(0));
  1234. ClassDB::bind_method(_MD("get_pos"),&_File::get_pos);
  1235. ClassDB::bind_method(_MD("get_len"),&_File::get_len);
  1236. ClassDB::bind_method(_MD("eof_reached"),&_File::eof_reached);
  1237. ClassDB::bind_method(_MD("get_8"),&_File::get_8);
  1238. ClassDB::bind_method(_MD("get_16"),&_File::get_16);
  1239. ClassDB::bind_method(_MD("get_32"),&_File::get_32);
  1240. ClassDB::bind_method(_MD("get_64"),&_File::get_64);
  1241. ClassDB::bind_method(_MD("get_float"),&_File::get_float);
  1242. ClassDB::bind_method(_MD("get_double"),&_File::get_double);
  1243. ClassDB::bind_method(_MD("get_real"),&_File::get_real);
  1244. ClassDB::bind_method(_MD("get_buffer","len"),&_File::get_buffer);
  1245. ClassDB::bind_method(_MD("get_line"),&_File::get_line);
  1246. ClassDB::bind_method(_MD("get_as_text"),&_File::get_as_text);
  1247. ClassDB::bind_method(_MD("get_md5","path"),&_File::get_md5);
  1248. ClassDB::bind_method(_MD("get_sha256","path"),&_File::get_sha256);
  1249. ClassDB::bind_method(_MD("get_endian_swap"),&_File::get_endian_swap);
  1250. ClassDB::bind_method(_MD("set_endian_swap","enable"),&_File::set_endian_swap);
  1251. ClassDB::bind_method(_MD("get_error:Error"),&_File::get_error);
  1252. ClassDB::bind_method(_MD("get_var"),&_File::get_var);
  1253. ClassDB::bind_method(_MD("get_csv_line","delim"),&_File::get_csv_line,DEFVAL(","));
  1254. ClassDB::bind_method(_MD("store_8","value"),&_File::store_8);
  1255. ClassDB::bind_method(_MD("store_16","value"),&_File::store_16);
  1256. ClassDB::bind_method(_MD("store_32","value"),&_File::store_32);
  1257. ClassDB::bind_method(_MD("store_64","value"),&_File::store_64);
  1258. ClassDB::bind_method(_MD("store_float","value"),&_File::store_float);
  1259. ClassDB::bind_method(_MD("store_double","value"),&_File::store_double);
  1260. ClassDB::bind_method(_MD("store_real","value"),&_File::store_real);
  1261. ClassDB::bind_method(_MD("store_buffer","buffer"),&_File::store_buffer);
  1262. ClassDB::bind_method(_MD("store_line","line"),&_File::store_line);
  1263. ClassDB::bind_method(_MD("store_string","string"),&_File::store_string);
  1264. ClassDB::bind_method(_MD("store_var","value"),&_File::store_var);
  1265. ClassDB::bind_method(_MD("store_pascal_string","string"),&_File::store_pascal_string);
  1266. ClassDB::bind_method(_MD("get_pascal_string"),&_File::get_pascal_string);
  1267. ClassDB::bind_method(_MD("file_exists","path"),&_File::file_exists);
  1268. BIND_CONSTANT( READ );
  1269. BIND_CONSTANT( WRITE );
  1270. BIND_CONSTANT( READ_WRITE );
  1271. BIND_CONSTANT( WRITE_READ );
  1272. }
  1273. _File::_File(){
  1274. f = NULL;
  1275. eswap=false;
  1276. }
  1277. _File::~_File(){
  1278. if (f)
  1279. memdelete(f);
  1280. }
  1281. ///////////////////////////////////////////////////////
  1282. Error _Directory::open(const String& p_path) {
  1283. Error err;
  1284. DirAccess *alt=DirAccess::open(p_path,&err);
  1285. if (!alt)
  1286. return err;
  1287. if (d)
  1288. memdelete(d);
  1289. d=alt;
  1290. return OK;
  1291. }
  1292. Error _Directory::list_dir_begin() {
  1293. ERR_FAIL_COND_V(!d,ERR_UNCONFIGURED);
  1294. return d->list_dir_begin();
  1295. }
  1296. String _Directory::get_next(){
  1297. ERR_FAIL_COND_V(!d,"");
  1298. return d->get_next();
  1299. }
  1300. bool _Directory::current_is_dir() const{
  1301. ERR_FAIL_COND_V(!d,false);
  1302. return d->current_is_dir();
  1303. }
  1304. void _Directory::list_dir_end(){
  1305. ERR_FAIL_COND(!d);
  1306. return d->list_dir_end();
  1307. }
  1308. int _Directory::get_drive_count(){
  1309. ERR_FAIL_COND_V(!d,0);
  1310. return d->get_drive_count();
  1311. }
  1312. String _Directory::get_drive(int p_drive){
  1313. ERR_FAIL_COND_V(!d,"");
  1314. return d->get_drive(p_drive);
  1315. }
  1316. int _Directory::get_current_drive() {
  1317. ERR_FAIL_COND_V(!d,0);
  1318. return d->get_current_drive();
  1319. }
  1320. Error _Directory::change_dir(String p_dir){
  1321. ERR_FAIL_COND_V(!d,ERR_UNCONFIGURED);
  1322. return d->change_dir(p_dir);
  1323. }
  1324. String _Directory::get_current_dir() {
  1325. ERR_FAIL_COND_V(!d,"");
  1326. return d->get_current_dir();
  1327. }
  1328. Error _Directory::make_dir(String p_dir){
  1329. ERR_FAIL_COND_V(!d,ERR_UNCONFIGURED);
  1330. if (!p_dir.is_rel_path()) {
  1331. DirAccess *d = DirAccess::create_for_path(p_dir);
  1332. Error err = d->make_dir(p_dir);
  1333. memdelete(d);
  1334. return err;
  1335. }
  1336. return d->make_dir(p_dir);
  1337. }
  1338. Error _Directory::make_dir_recursive(String p_dir){
  1339. ERR_FAIL_COND_V(!d,ERR_UNCONFIGURED);
  1340. if (!p_dir.is_rel_path()) {
  1341. DirAccess *d = DirAccess::create_for_path(p_dir);
  1342. Error err = d->make_dir_recursive(p_dir);
  1343. memdelete(d);
  1344. return err;
  1345. }
  1346. return d->make_dir_recursive(p_dir);
  1347. }
  1348. bool _Directory::file_exists(String p_file){
  1349. ERR_FAIL_COND_V(!d,false);
  1350. if (!p_file.is_rel_path()) {
  1351. return FileAccess::exists(p_file);
  1352. }
  1353. return d->file_exists(p_file);
  1354. }
  1355. bool _Directory::dir_exists(String p_dir) {
  1356. ERR_FAIL_COND_V(!d,false);
  1357. if (!p_dir.is_rel_path()) {
  1358. DirAccess *d = DirAccess::create_for_path(p_dir);
  1359. bool exists = d->dir_exists(p_dir);
  1360. memdelete(d);
  1361. return exists;
  1362. } else {
  1363. return d->dir_exists(p_dir);
  1364. }
  1365. }
  1366. int _Directory::get_space_left(){
  1367. ERR_FAIL_COND_V(!d,0);
  1368. return d->get_space_left()/1024*1024; //return value in megabytes, given binding is int
  1369. }
  1370. Error _Directory::copy(String p_from,String p_to){
  1371. ERR_FAIL_COND_V(!d,ERR_UNCONFIGURED);
  1372. return d->copy(p_from,p_to);
  1373. }
  1374. Error _Directory::rename(String p_from, String p_to){
  1375. ERR_FAIL_COND_V(!d,ERR_UNCONFIGURED);
  1376. if (!p_from.is_rel_path()) {
  1377. DirAccess *d = DirAccess::create_for_path(p_from);
  1378. Error err = d->rename(p_from,p_to);
  1379. memdelete(d);
  1380. return err;
  1381. }
  1382. return d->rename(p_from,p_to);
  1383. }
  1384. Error _Directory::remove(String p_name){
  1385. ERR_FAIL_COND_V(!d,ERR_UNCONFIGURED);
  1386. if (!p_name.is_rel_path()) {
  1387. DirAccess *d = DirAccess::create_for_path(p_name);
  1388. Error err = d->remove(p_name);
  1389. memdelete(d);
  1390. return err;
  1391. }
  1392. return d->remove(p_name);
  1393. }
  1394. void _Directory::_bind_methods() {
  1395. ClassDB::bind_method(_MD("open:Error","path"),&_Directory::open);
  1396. ClassDB::bind_method(_MD("list_dir_begin"),&_Directory::list_dir_begin);
  1397. ClassDB::bind_method(_MD("get_next"),&_Directory::get_next);
  1398. ClassDB::bind_method(_MD("current_is_dir"),&_Directory::current_is_dir);
  1399. ClassDB::bind_method(_MD("list_dir_end"),&_Directory::list_dir_end);
  1400. ClassDB::bind_method(_MD("get_drive_count"),&_Directory::get_drive_count);
  1401. ClassDB::bind_method(_MD("get_drive","idx"),&_Directory::get_drive);
  1402. ClassDB::bind_method(_MD("get_current_drive"),&_Directory::get_current_drive);
  1403. ClassDB::bind_method(_MD("change_dir:Error","todir"),&_Directory::change_dir);
  1404. ClassDB::bind_method(_MD("get_current_dir"),&_Directory::get_current_dir);
  1405. ClassDB::bind_method(_MD("make_dir:Error","path"),&_Directory::make_dir);
  1406. ClassDB::bind_method(_MD("make_dir_recursive:Error","path"),&_Directory::make_dir_recursive);
  1407. ClassDB::bind_method(_MD("file_exists","path"),&_Directory::file_exists);
  1408. ClassDB::bind_method(_MD("dir_exists","path"),&_Directory::dir_exists);
  1409. //ClassDB::bind_method(_MD("get_modified_time","file"),&_Directory::get_modified_time);
  1410. ClassDB::bind_method(_MD("get_space_left"),&_Directory::get_space_left);
  1411. ClassDB::bind_method(_MD("copy:Error","from","to"),&_Directory::copy);
  1412. ClassDB::bind_method(_MD("rename:Error","from","to"),&_Directory::rename);
  1413. ClassDB::bind_method(_MD("remove:Error","path"),&_Directory::remove);
  1414. }
  1415. _Directory::_Directory() {
  1416. d = DirAccess::create(DirAccess::ACCESS_RESOURCES);
  1417. }
  1418. _Directory::~_Directory() {
  1419. if (d)
  1420. memdelete(d);
  1421. }
  1422. _Marshalls* _Marshalls::singleton=NULL;
  1423. _Marshalls *_Marshalls::get_singleton()
  1424. {
  1425. return singleton;
  1426. }
  1427. String _Marshalls::variant_to_base64(const Variant& p_var) {
  1428. int len;
  1429. Error err = encode_variant(p_var,NULL,len);
  1430. ERR_FAIL_COND_V( err != OK, "" );
  1431. PoolVector<uint8_t> buff;
  1432. buff.resize(len);
  1433. PoolVector<uint8_t>::Write w = buff.write();
  1434. err = encode_variant(p_var,&w[0],len);
  1435. ERR_FAIL_COND_V( err != OK, "" );
  1436. int b64len = len / 3 * 4 + 4 + 1;
  1437. PoolVector<uint8_t> b64buff;
  1438. b64buff.resize(b64len);
  1439. PoolVector<uint8_t>::Write w64 = b64buff.write();
  1440. int strlen = base64_encode((char*)(&w64[0]), (char*)(&w[0]), len);
  1441. //OS::get_singleton()->print("len is %i, vector size is %i\n", b64len, strlen);
  1442. w64[strlen] = 0;
  1443. String ret = (char*)&w64[0];
  1444. return ret;
  1445. };
  1446. Variant _Marshalls::base64_to_variant(const String& p_str) {
  1447. int strlen = p_str.length();
  1448. CharString cstr = p_str.ascii();
  1449. PoolVector<uint8_t> buf;
  1450. buf.resize(strlen / 4 * 3 + 1);
  1451. PoolVector<uint8_t>::Write w = buf.write();
  1452. int len = base64_decode((char*)(&w[0]), (char*)cstr.get_data(), strlen);
  1453. Variant v;
  1454. Error err = decode_variant(v, &w[0], len);
  1455. ERR_FAIL_COND_V( err!=OK, Variant() );
  1456. return v;
  1457. };
  1458. String _Marshalls::raw_to_base64(const PoolVector<uint8_t> &p_arr) {
  1459. int len = p_arr.size();
  1460. PoolVector<uint8_t>::Read r = p_arr.read();
  1461. int b64len = len / 3 * 4 + 4 + 1;
  1462. PoolVector<uint8_t> b64buff;
  1463. b64buff.resize(b64len);
  1464. PoolVector<uint8_t>::Write w64 = b64buff.write();
  1465. int strlen = base64_encode((char*)(&w64[0]), (char*)(&r[0]), len);
  1466. w64[strlen] = 0;
  1467. String ret = (char*)&w64[0];
  1468. return ret;
  1469. };
  1470. PoolVector<uint8_t> _Marshalls::base64_to_raw(const String &p_str) {
  1471. int strlen = p_str.length();
  1472. CharString cstr = p_str.ascii();
  1473. int arr_len;
  1474. PoolVector<uint8_t> buf;
  1475. {
  1476. buf.resize(strlen / 4 * 3 + 1);
  1477. PoolVector<uint8_t>::Write w = buf.write();
  1478. arr_len = base64_decode((char*)(&w[0]), (char*)cstr.get_data(), strlen);
  1479. };
  1480. buf.resize(arr_len);
  1481. // conversion from PoolVector<uint8_t> to raw array?
  1482. return buf;
  1483. };
  1484. String _Marshalls::utf8_to_base64(const String& p_str) {
  1485. CharString cstr = p_str.utf8();
  1486. int len = cstr.length();
  1487. int b64len = len / 3 * 4 + 4 + 1;
  1488. PoolVector<uint8_t> b64buff;
  1489. b64buff.resize(b64len);
  1490. PoolVector<uint8_t>::Write w64 = b64buff.write();
  1491. int strlen = base64_encode((char*)(&w64[0]), (char*)cstr.get_data(), len);
  1492. w64[strlen] = 0;
  1493. String ret = (char*)&w64[0];
  1494. return ret;
  1495. };
  1496. String _Marshalls::base64_to_utf8(const String& p_str) {
  1497. int strlen = p_str.length();
  1498. CharString cstr = p_str.ascii();
  1499. PoolVector<uint8_t> buf;
  1500. buf.resize(strlen / 4 * 3 + 1 + 1);
  1501. PoolVector<uint8_t>::Write w = buf.write();
  1502. int len = base64_decode((char*)(&w[0]), (char*)cstr.get_data(), strlen);
  1503. w[len] = 0;
  1504. String ret = String::utf8((char*)&w[0]);
  1505. return ret;
  1506. };
  1507. void _Marshalls::_bind_methods() {
  1508. ClassDB::bind_method(_MD("variant_to_base64:String","variant"),&_Marshalls::variant_to_base64);
  1509. ClassDB::bind_method(_MD("base64_to_variant:Variant","base64_str"),&_Marshalls::base64_to_variant);
  1510. ClassDB::bind_method(_MD("raw_to_base64:String","array"),&_Marshalls::raw_to_base64);
  1511. ClassDB::bind_method(_MD("base64_to_raw:RawArray","base64_str"),&_Marshalls::base64_to_raw);
  1512. ClassDB::bind_method(_MD("utf8_to_base64:String","utf8_str"),&_Marshalls::utf8_to_base64);
  1513. ClassDB::bind_method(_MD("base64_to_utf8:String","base64_str"),&_Marshalls::base64_to_utf8);
  1514. };
  1515. ////////////////
  1516. Error _Semaphore::wait() {
  1517. return semaphore->wait();
  1518. }
  1519. Error _Semaphore::post() {
  1520. return semaphore->post();
  1521. }
  1522. void _Semaphore::_bind_methods() {
  1523. ClassDB::bind_method(_MD("wait:Error"),&_Semaphore::wait);
  1524. ClassDB::bind_method(_MD("post:Error"),&_Semaphore::post);
  1525. }
  1526. _Semaphore::_Semaphore() {
  1527. semaphore =Semaphore::create();
  1528. }
  1529. _Semaphore::~_Semaphore(){
  1530. memdelete(semaphore);
  1531. }
  1532. ///////////////
  1533. void _Mutex::lock() {
  1534. mutex->lock();
  1535. }
  1536. Error _Mutex::try_lock(){
  1537. return mutex->try_lock();
  1538. }
  1539. void _Mutex::unlock(){
  1540. mutex->unlock();
  1541. }
  1542. void _Mutex::_bind_methods() {
  1543. ClassDB::bind_method(_MD("lock"),&_Mutex::lock);
  1544. ClassDB::bind_method(_MD("try_lock:Error"),&_Mutex::try_lock);
  1545. ClassDB::bind_method(_MD("unlock"),&_Mutex::unlock);
  1546. }
  1547. _Mutex::_Mutex() {
  1548. mutex =Mutex::create();
  1549. }
  1550. _Mutex::~_Mutex(){
  1551. memdelete(mutex);
  1552. }
  1553. ///////////////
  1554. void _Thread::_start_func(void *ud) {
  1555. Ref<_Thread>* tud=(Ref<_Thread>*)ud;
  1556. Ref<_Thread> t=*tud;
  1557. memdelete(tud);
  1558. Variant::CallError ce;
  1559. const Variant* arg[1]={&t->userdata};
  1560. Thread::set_name(t->target_method);
  1561. t->ret=t->target_instance->call(t->target_method,arg,1,ce);
  1562. if (ce.error!=Variant::CallError::CALL_OK) {
  1563. String reason;
  1564. switch(ce.error) {
  1565. case Variant::CallError::CALL_ERROR_INVALID_ARGUMENT: {
  1566. reason="Invalid Argument #"+itos(ce.argument);
  1567. } break;
  1568. case Variant::CallError::CALL_ERROR_TOO_MANY_ARGUMENTS: {
  1569. reason="Too Many Arguments";
  1570. } break;
  1571. case Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS: {
  1572. reason="Too Many Arguments";
  1573. } break;
  1574. case Variant::CallError::CALL_ERROR_INVALID_METHOD: {
  1575. reason="Method Not Found";
  1576. } break;
  1577. default: {}
  1578. }
  1579. ERR_EXPLAIN("Could not call function '"+t->target_method.operator String()+"'' starting thread ID: "+t->get_id()+" Reason: "+reason);
  1580. ERR_FAIL();
  1581. }
  1582. }
  1583. Error _Thread::start(Object *p_instance,const StringName& p_method,const Variant& p_userdata,int p_priority) {
  1584. ERR_FAIL_COND_V(active,ERR_ALREADY_IN_USE);
  1585. ERR_FAIL_COND_V(!p_instance,ERR_INVALID_PARAMETER);
  1586. ERR_FAIL_COND_V(p_method==StringName(),ERR_INVALID_PARAMETER);
  1587. ERR_FAIL_INDEX_V(p_priority,3,ERR_INVALID_PARAMETER);
  1588. ret=Variant();
  1589. target_method=p_method;
  1590. target_instance=p_instance;
  1591. userdata=p_userdata;
  1592. active=true;
  1593. Ref<_Thread> *ud = memnew( Ref<_Thread>(this) );
  1594. Thread::Settings s;
  1595. s.priority=(Thread::Priority)p_priority;
  1596. thread = Thread::create(_start_func,ud,s);
  1597. if (!thread) {
  1598. active=false;
  1599. target_method=StringName();
  1600. target_instance=NULL;
  1601. userdata=Variant();
  1602. return ERR_CANT_CREATE;
  1603. }
  1604. return OK;
  1605. }
  1606. String _Thread::get_id() const {
  1607. if (!thread)
  1608. return String();
  1609. return itos(thread->get_ID());
  1610. }
  1611. bool _Thread::is_active() const {
  1612. return active;
  1613. }
  1614. Variant _Thread::wait_to_finish() {
  1615. ERR_FAIL_COND_V(!thread,Variant());
  1616. ERR_FAIL_COND_V(!active,Variant());
  1617. Thread::wait_to_finish(thread);
  1618. Variant r = ret;
  1619. active=false;
  1620. target_method=StringName();
  1621. target_instance=NULL;
  1622. userdata=Variant();
  1623. thread=NULL;
  1624. return r;
  1625. }
  1626. void _Thread::_bind_methods() {
  1627. ClassDB::bind_method(_MD("start:Error","instance","method","userdata","priority"),&_Thread::start,DEFVAL(Variant()),DEFVAL(PRIORITY_NORMAL));
  1628. ClassDB::bind_method(_MD("get_id"),&_Thread::get_id);
  1629. ClassDB::bind_method(_MD("is_active"),&_Thread::is_active);
  1630. ClassDB::bind_method(_MD("wait_to_finish:Variant"),&_Thread::wait_to_finish);
  1631. BIND_CONSTANT( PRIORITY_LOW );
  1632. BIND_CONSTANT( PRIORITY_NORMAL );
  1633. BIND_CONSTANT( PRIORITY_HIGH );
  1634. }
  1635. _Thread::_Thread() {
  1636. active=false;
  1637. thread=NULL;
  1638. target_instance=NULL;
  1639. }
  1640. _Thread::~_Thread() {
  1641. if (active) {
  1642. ERR_EXPLAIN("Reference to a Thread object object was lost while the thread is still running..");
  1643. }
  1644. ERR_FAIL_COND(active==true);
  1645. }
  1646. /////////////////////////////////////
  1647. PoolStringArray _ClassDB::get_class_list() const {
  1648. List<StringName> classes;
  1649. ClassDB::get_class_list(&classes);
  1650. PoolStringArray ret;
  1651. ret.resize(classes.size());
  1652. int idx=0;
  1653. for (List<StringName>::Element *E=classes.front();E;E=E->next()) {
  1654. ret.set(idx++,E->get());
  1655. }
  1656. return ret;
  1657. }
  1658. PoolStringArray _ClassDB::get_inheriters_from_class( const StringName& p_class) const {
  1659. List<StringName> classes;
  1660. ClassDB::get_inheriters_from_class(p_class,&classes);
  1661. PoolStringArray ret;
  1662. ret.resize(classes.size());
  1663. int idx=0;
  1664. for (List<StringName>::Element *E=classes.front();E;E=E->next()) {
  1665. ret.set(idx++,E->get());
  1666. }
  1667. return ret;
  1668. }
  1669. StringName _ClassDB::get_parent_class(const StringName& p_class) const {
  1670. return ClassDB::get_parent_class(p_class);
  1671. }
  1672. bool _ClassDB::class_exists(const StringName &p_class) const {
  1673. return ClassDB::class_exists(p_class);
  1674. }
  1675. bool _ClassDB::is_parent_class(const StringName &p_class,const StringName& p_inherits) const {
  1676. return ClassDB::is_parent_class(p_class,p_inherits);
  1677. }
  1678. bool _ClassDB::can_instance(const StringName &p_class) const {
  1679. return ClassDB::can_instance(p_class);
  1680. }
  1681. Variant _ClassDB::instance(const StringName &p_class) const {
  1682. Object *obj = ClassDB::instance(p_class);
  1683. if (!obj)
  1684. return Variant();
  1685. Reference *r = obj->cast_to<Reference>();
  1686. if (r) {
  1687. return REF(r);
  1688. } else {
  1689. return obj;
  1690. }
  1691. }
  1692. bool _ClassDB::has_signal(StringName p_class,StringName p_signal) const {
  1693. return ClassDB::has_signal(p_class,p_signal);
  1694. }
  1695. Dictionary _ClassDB::get_signal(StringName p_class,StringName p_signal) const {
  1696. MethodInfo signal;
  1697. if (ClassDB::get_signal(p_class,p_signal,&signal)) {
  1698. return signal.operator Dictionary();
  1699. } else {
  1700. return Dictionary();
  1701. }
  1702. }
  1703. Array _ClassDB::get_signal_list(StringName p_class,bool p_no_inheritance) const {
  1704. List<MethodInfo> signals;
  1705. ClassDB::get_signal_list(p_class,&signals,p_no_inheritance);
  1706. Array ret;
  1707. for (List<MethodInfo>::Element *E=signals.front();E;E=E->next()) {
  1708. ret.push_back(E->get().operator Dictionary());
  1709. }
  1710. return ret;
  1711. }
  1712. Array _ClassDB::get_property_list(StringName p_class, bool p_no_inheritance) const {
  1713. List<PropertyInfo> plist;
  1714. ClassDB::get_property_list(p_class,&plist,p_no_inheritance);
  1715. Array ret;
  1716. for (List<PropertyInfo>::Element *E=plist.front();E;E=E->next()) {
  1717. ret.push_back(E->get().operator Dictionary());
  1718. }
  1719. return ret;
  1720. }
  1721. bool _ClassDB::has_method(StringName p_class,StringName p_method,bool p_no_inheritance) const {
  1722. return ClassDB::has_method(p_class,p_method,p_no_inheritance);
  1723. }
  1724. Array _ClassDB::get_method_list(StringName p_class,bool p_no_inheritance) const {
  1725. List<MethodInfo> methods;
  1726. ClassDB::get_method_list(p_class,&methods,p_no_inheritance);
  1727. Array ret;
  1728. for (List<MethodInfo>::Element *E=methods.front();E;E=E->next()) {
  1729. ret.push_back(E->get().operator Dictionary());
  1730. }
  1731. return ret;
  1732. }
  1733. PoolStringArray _ClassDB::get_integer_constant_list(const StringName& p_class, bool p_no_inheritance) const {
  1734. List<String> constants;
  1735. ClassDB::get_integer_constant_list(p_class,&constants,p_no_inheritance);
  1736. PoolStringArray ret;
  1737. ret.resize(constants.size());
  1738. int idx=0;
  1739. for (List<String>::Element *E=constants.front();E;E=E->next()) {
  1740. ret.set(idx++,E->get());
  1741. }
  1742. return ret;
  1743. }
  1744. bool _ClassDB::has_integer_constant(const StringName& p_class, const StringName &p_name) const {
  1745. bool success;
  1746. ClassDB::get_integer_constant(p_class,p_name,&success);
  1747. return success;
  1748. }
  1749. int _ClassDB::get_integer_constant(const StringName& p_class, const StringName &p_name) const {
  1750. bool found;
  1751. int c = ClassDB::get_integer_constant(p_class,p_name,&found);
  1752. ERR_FAIL_COND_V(!found,0);
  1753. return c;
  1754. }
  1755. StringName _ClassDB::get_category(const StringName& p_node) const {
  1756. return ClassDB::get_category(p_node);
  1757. }
  1758. bool _ClassDB::is_class_enabled(StringName p_class) const {
  1759. return ClassDB::is_class_enabled(p_class);
  1760. }
  1761. void _ClassDB::_bind_methods() {
  1762. ClassDB::bind_method(_MD("get_class_list"),&_ClassDB::get_class_list);
  1763. ClassDB::bind_method(_MD("get_inheriters_from_class","class"),&_ClassDB::get_inheriters_from_class);
  1764. ClassDB::bind_method(_MD("get_parent_class","class"),&_ClassDB::get_parent_class);
  1765. ClassDB::bind_method(_MD("class_exists","class"),&_ClassDB::class_exists);
  1766. ClassDB::bind_method(_MD("is_parent_class","class","inherits"),&_ClassDB::is_parent_class);
  1767. ClassDB::bind_method(_MD("can_instance","class"),&_ClassDB::can_instance);
  1768. ClassDB::bind_method(_MD("instance","class"),&_ClassDB::instance);
  1769. ClassDB::bind_method(_MD("class_has_signal","class","signal"),&_ClassDB::has_signal);
  1770. ClassDB::bind_method(_MD("class_get_signal","class","signal"),&_ClassDB::get_signal);
  1771. ClassDB::bind_method(_MD("class_get_signal_list","class","no_inheritance"),&_ClassDB::get_signal_list,DEFVAL(false));
  1772. ClassDB::bind_method(_MD("class_get_property_list","class","no_inheritance"),&_ClassDB::get_property_list,DEFVAL(false));
  1773. ClassDB::bind_method(_MD("class_has_method","class","method","no_inheritance"),&_ClassDB::has_method,DEFVAL(false));
  1774. ClassDB::bind_method(_MD("class_get_method_list","class","no_inheritance"),&_ClassDB::get_method_list,DEFVAL(false));
  1775. ClassDB::bind_method(_MD("class_get_integer_constant_list","class","no_inheritance"),&_ClassDB::get_integer_constant_list,DEFVAL(false));
  1776. ClassDB::bind_method(_MD("class_has_integer_constant","class","name"),&_ClassDB::has_integer_constant);
  1777. ClassDB::bind_method(_MD("class_get_integer_constant","class","name"),&_ClassDB::get_integer_constant);
  1778. ClassDB::bind_method(_MD("class_get_category","class"),&_ClassDB::get_category);
  1779. ClassDB::bind_method(_MD("is_class_enabled","class"),&_ClassDB::is_class_enabled);
  1780. }
  1781. _ClassDB::_ClassDB(){
  1782. }
  1783. _ClassDB::~_ClassDB(){
  1784. }
  1785. ///////////////////////////////
  1786. void _Engine::set_iterations_per_second(int p_ips) {
  1787. Engine::get_singleton()->set_iterations_per_second(p_ips);
  1788. }
  1789. int _Engine::get_iterations_per_second() const {
  1790. return Engine::get_singleton()->get_iterations_per_second();
  1791. }
  1792. void _Engine::set_target_fps(int p_fps) {
  1793. Engine::get_singleton()->set_target_fps(p_fps);
  1794. }
  1795. float _Engine::get_target_fps() const {
  1796. return Engine::get_singleton()->get_target_fps();
  1797. }
  1798. float _Engine::get_frames_per_second() const {
  1799. return Engine::get_singleton()->get_frames_per_second();
  1800. }
  1801. String _Engine::get_custom_level() const {
  1802. return Engine::get_singleton()->get_custom_level();
  1803. }
  1804. void _Engine::set_time_scale(float p_scale) {
  1805. Engine::get_singleton()->set_time_scale(p_scale);
  1806. }
  1807. float _Engine::get_time_scale() {
  1808. return Engine::get_singleton()->get_time_scale();
  1809. }
  1810. int _Engine::get_frames_drawn() {
  1811. return Engine::get_singleton()->get_frames_drawn();
  1812. }
  1813. MainLoop *_Engine::get_main_loop() const {
  1814. //needs to remain in OS, since it's actually OS that interacts with it, but it's better exposed here
  1815. return OS::get_singleton()->get_main_loop();
  1816. }
  1817. Dictionary _Engine::get_version_info() const {
  1818. return Engine::get_singleton()->get_version_info();
  1819. }
  1820. void _Engine::_bind_methods() {
  1821. ClassDB::bind_method(_MD("set_iterations_per_second","iterations_per_second"),&_Engine::set_iterations_per_second);
  1822. ClassDB::bind_method(_MD("get_iterations_per_second"),&_Engine::get_iterations_per_second);
  1823. ClassDB::bind_method(_MD("set_target_fps","target_fps"),&_Engine::set_target_fps);
  1824. ClassDB::bind_method(_MD("get_target_fps"),&_Engine::get_target_fps);
  1825. ClassDB::bind_method(_MD("set_time_scale","time_scale"),&_Engine::set_time_scale);
  1826. ClassDB::bind_method(_MD("get_time_scale"),&_Engine::get_time_scale);
  1827. ClassDB::bind_method(_MD("get_custom_level"),&_Engine::get_custom_level);
  1828. ClassDB::bind_method(_MD("get_frames_drawn"),&_Engine::get_frames_drawn);
  1829. ClassDB::bind_method(_MD("get_frames_per_second"),&_Engine::get_frames_per_second);
  1830. ClassDB::bind_method(_MD("get_main_loop:MainLoop"),&_Engine::get_main_loop);
  1831. ClassDB::bind_method(_MD("get_version_info"),&_Engine::get_version_info);
  1832. }
  1833. _Engine *_Engine::singleton = NULL;
  1834. _Engine::_Engine() {
  1835. singleton=this;
  1836. }