core_bind.cpp 69 KB

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