core_bind.cpp 87 KB

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