os_android.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  1. /*************************************************************************/
  2. /* os_android.cpp */
  3. /*************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* http://www.godotengine.org */
  7. /*************************************************************************/
  8. /* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
  9. /* */
  10. /* Permission is hereby granted, free of charge, to any person obtaining */
  11. /* a copy of this software and associated documentation files (the */
  12. /* "Software"), to deal in the Software without restriction, including */
  13. /* without limitation the rights to use, copy, modify, merge, publish, */
  14. /* distribute, sublicense, and/or sell copies of the Software, and to */
  15. /* permit persons to whom the Software is furnished to do so, subject to */
  16. /* the following conditions: */
  17. /* */
  18. /* The above copyright notice and this permission notice shall be */
  19. /* included in all copies or substantial portions of the Software. */
  20. /* */
  21. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  22. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  23. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
  24. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  25. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  26. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  27. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  28. /*************************************************************************/
  29. #include "os_android.h"
  30. #include "drivers/gles2/rasterizer_gles2.h"
  31. #include "core/io/file_access_buffered_fa.h"
  32. #include "drivers/unix/file_access_unix.h"
  33. #include "drivers/unix/dir_access_unix.h"
  34. #include "servers/visual/visual_server_raster.h"
  35. #include "servers/visual/visual_server_wrap_mt.h"
  36. #include "main/main.h"
  37. #include "file_access_android.h"
  38. #include "core/globals.h"
  39. #ifdef ANDROID_NATIVE_ACTIVITY
  40. #include "file_access_android.h"
  41. #include "dir_access_android.h"
  42. #else
  43. #include "file_access_jandroid.h"
  44. #include "dir_access_jandroid.h"
  45. #endif
  46. int OS_Android::get_video_driver_count() const {
  47. return 1;
  48. }
  49. const char * OS_Android::get_video_driver_name(int p_driver) const {
  50. return "GLES2";
  51. }
  52. OS::VideoMode OS_Android::get_default_video_mode() const {
  53. return OS::VideoMode();
  54. }
  55. int OS_Android::get_audio_driver_count() const {
  56. return 1;
  57. }
  58. const char * OS_Android::get_audio_driver_name(int p_driver) const {
  59. return "Android";
  60. }
  61. void OS_Android::initialize_core() {
  62. OS_Unix::initialize_core();
  63. #ifdef ANDROID_NATIVE_ACTIVITY
  64. FileAccess::make_default<FileAccessAndroid>(FileAccess::ACCESS_RESOURCES);
  65. FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_USERDATA);
  66. FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_FILESYSTEM);
  67. //FileAccessBufferedFA<FileAccessUnix>::make_default();
  68. DirAccess::make_default<DirAccessAndroid>(DirAccess::ACCESS_RESOURCES);
  69. DirAccess::make_default<DirAccessUnix>(DirAccess::ACCESS_USERDATA);
  70. DirAccess::make_default<DirAccessUnix>(DirAccess::ACCESS_FILESYSTEM);
  71. #else
  72. if (use_apk_expansion)
  73. FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_RESOURCES);
  74. else {
  75. #ifdef USE_JAVA_FILE_ACCESS
  76. FileAccess::make_default<FileAccessBufferedFA<FileAccessJAndroid> >(FileAccess::ACCESS_RESOURCES);
  77. #else
  78. //FileAccess::make_default<FileAccessBufferedFA<FileAccessAndroid> >(FileAccess::ACCESS_RESOURCES);
  79. FileAccess::make_default<FileAccessAndroid>(FileAccess::ACCESS_RESOURCES);
  80. #endif
  81. }
  82. FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_USERDATA);
  83. FileAccess::make_default<FileAccessUnix>(FileAccess::ACCESS_FILESYSTEM);
  84. //FileAccessBufferedFA<FileAccessUnix>::make_default();
  85. if (use_apk_expansion)
  86. DirAccess::make_default<DirAccessUnix>(DirAccess::ACCESS_RESOURCES);
  87. else
  88. DirAccess::make_default<DirAccessJAndroid>(DirAccess::ACCESS_RESOURCES);
  89. DirAccess::make_default<DirAccessUnix>(DirAccess::ACCESS_USERDATA);
  90. DirAccess::make_default<DirAccessUnix>(DirAccess::ACCESS_FILESYSTEM);
  91. #endif
  92. }
  93. void OS_Android::set_opengl_extensions(const char* p_gl_extensions) {
  94. ERR_FAIL_COND(!p_gl_extensions);
  95. gl_extensions=p_gl_extensions;
  96. }
  97. void OS_Android::initialize(const VideoMode& p_desired,int p_video_driver,int p_audio_driver) {
  98. use_gl2=p_video_driver!=1;
  99. if (gfx_init_func)
  100. gfx_init_func(gfx_init_ud,use_gl2);
  101. AudioDriverManagerSW::add_driver(&audio_driver_android);
  102. if (true) {
  103. RasterizerGLES2 *rasterizer_gles22=memnew( RasterizerGLES2(false,use_reload_hooks,false,use_reload_hooks ) );
  104. if (gl_extensions)
  105. rasterizer_gles22->set_extensions(gl_extensions);
  106. rasterizer = rasterizer_gles22;
  107. } else {
  108. //rasterizer = memnew( RasterizerGLES1(use_reload_hooks, use_reload_hooks) );
  109. }
  110. rasterizer->set_force_16_bits_fbo(use_16bits_fbo);
  111. visual_server = memnew( VisualServerRaster(rasterizer) );
  112. if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) {
  113. visual_server = memnew(VisualServerWrapMT(visual_server, false));
  114. };
  115. visual_server->init();
  116. visual_server->cursor_set_visible(false, 0);
  117. AudioDriverManagerSW::get_driver(p_audio_driver)->set_singleton();
  118. if (AudioDriverManagerSW::get_driver(p_audio_driver)->init()!=OK) {
  119. ERR_PRINT("Initializing audio failed.");
  120. }
  121. sample_manager = memnew( SampleManagerMallocSW );
  122. audio_server = memnew( AudioServerSW(sample_manager) );
  123. audio_server->set_mixer_params(AudioMixerSW::INTERPOLATION_LINEAR,true);
  124. audio_server->init();
  125. spatial_sound_server = memnew( SpatialSoundServerSW );
  126. spatial_sound_server->init();
  127. spatial_sound_2d_server = memnew( SpatialSound2DServerSW );
  128. spatial_sound_2d_server->init();
  129. //
  130. physics_server = memnew( PhysicsServerSW );
  131. physics_server->init();
  132. //physics_2d_server = memnew( Physics2DServerSW );
  133. physics_2d_server = Physics2DServerWrapMT::init_server<Physics2DServerSW>();
  134. physics_2d_server->init();
  135. input = memnew( InputDefault );
  136. input->set_fallback_mapping("Default Android Gamepad");
  137. }
  138. void OS_Android::set_main_loop( MainLoop * p_main_loop ) {
  139. main_loop=p_main_loop;
  140. input->set_main_loop(p_main_loop);
  141. #if 0
  142. print_line("preGS");
  143. FileAccess *f=memnew( FileAccessAndroid );
  144. print("made f %p\n",f);
  145. Error err = f->open("AndroidManifest.xml",FileAccess::READ);
  146. if (err) {
  147. print("************NO FILE!!\n");
  148. } else {
  149. print("************YES FILE!!\n");
  150. }
  151. f->close();
  152. print_line("end");
  153. AAssetDir* aad = AAssetManager_openDir(FileAccessAndroid::asset_manager,".");
  154. if (aad) {
  155. print_line("DIR OPEN OK");
  156. const char *fn= AAssetDir_getNextFileName(aad);
  157. while(fn) {
  158. print_line("FNAME: "+String(fn));
  159. fn= AAssetDir_getNextFileName(aad);
  160. }
  161. AAssetDir_close(aad);
  162. } else {
  163. print_line("DIR NO OPEN");
  164. }
  165. #endif
  166. }
  167. void OS_Android::delete_main_loop() {
  168. memdelete( main_loop );
  169. }
  170. void OS_Android::finalize() {
  171. memdelete(input);
  172. }
  173. void OS_Android::vprint(const char* p_format, va_list p_list, bool p_stderr) {
  174. __android_log_vprint(p_stderr?ANDROID_LOG_ERROR:ANDROID_LOG_INFO,"godot",p_format,p_list);
  175. }
  176. void OS_Android::print(const char *p_format, ... ) {
  177. va_list argp;
  178. va_start(argp, p_format);
  179. __android_log_vprint(ANDROID_LOG_INFO,"godot",p_format,argp);
  180. va_end(argp);
  181. }
  182. void OS_Android::alert(const String& p_alert) {
  183. print("ALERT: %s\n",p_alert.utf8().get_data());
  184. }
  185. void OS_Android::set_mouse_show(bool p_show) {
  186. //android has no mouse...
  187. }
  188. void OS_Android::set_mouse_grab(bool p_grab) {
  189. //it really has no mouse...!
  190. }
  191. bool OS_Android::is_mouse_grab_enabled() const {
  192. //*sigh* technology has evolved so much since i was a kid..
  193. return false;
  194. }
  195. Point2 OS_Android::get_mouse_pos() const {
  196. return Point2();
  197. }
  198. int OS_Android::get_mouse_button_state() const {
  199. return 0;
  200. }
  201. void OS_Android::set_window_title(const String& p_title) {
  202. }
  203. //interesting byt not yet
  204. //void set_clipboard(const String& p_text);
  205. //String get_clipboard() const;
  206. void OS_Android::set_video_mode(const VideoMode& p_video_mode,int p_screen) {
  207. }
  208. OS::VideoMode OS_Android::get_video_mode(int p_screen) const {
  209. return default_videomode;
  210. }
  211. void OS_Android::get_fullscreen_mode_list(List<VideoMode> *p_list,int p_screen) const {
  212. p_list->push_back(default_videomode);
  213. }
  214. void OS_Android::set_keep_screen_on(bool p_enabled) {
  215. OS::set_keep_screen_on(p_enabled);
  216. if (set_keep_screen_on_func) {
  217. set_keep_screen_on_func(p_enabled);
  218. }
  219. }
  220. Size2 OS_Android::get_window_size() const {
  221. return Vector2(default_videomode.width,default_videomode.height);
  222. }
  223. String OS_Android::get_name() {
  224. return "Android";
  225. }
  226. MainLoop *OS_Android::get_main_loop() const {
  227. return main_loop;
  228. }
  229. bool OS_Android::can_draw() const {
  230. return true; //always?
  231. }
  232. void OS_Android::set_cursor_shape(CursorShape p_shape) {
  233. //android really really really has no mouse.. how amazing..
  234. }
  235. void OS_Android::main_loop_begin() {
  236. if (main_loop)
  237. main_loop->init();
  238. }
  239. bool OS_Android::main_loop_iterate() {
  240. if (!main_loop)
  241. return false;
  242. return Main::iteration();
  243. }
  244. void OS_Android::main_loop_end() {
  245. if (main_loop)
  246. main_loop->finish();
  247. }
  248. void OS_Android::main_loop_focusout() {
  249. if (main_loop)
  250. main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT);
  251. audio_driver_android.set_pause(true);
  252. }
  253. void OS_Android::main_loop_focusin(){
  254. if (main_loop)
  255. main_loop->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN);
  256. audio_driver_android.set_pause(false);
  257. }
  258. void OS_Android::process_joy_event(OS_Android::JoystickEvent p_event) {
  259. switch (p_event.type) {
  260. case JOY_EVENT_BUTTON:
  261. last_id = input->joy_button(last_id, p_event.device, p_event.index, p_event.pressed);
  262. break;
  263. case JOY_EVENT_AXIS:
  264. InputDefault::JoyAxis value;
  265. value.min = -1;
  266. value.value = p_event.value;
  267. last_id = input->joy_axis(last_id, p_event.device, p_event.index, value);
  268. break;
  269. case JOY_EVENT_HAT:
  270. last_id = input->joy_hat(last_id, p_event.device, p_event.hat);
  271. break;
  272. default:
  273. return;
  274. }
  275. }
  276. void OS_Android::process_event(InputEvent p_event) {
  277. p_event.ID = last_id++;
  278. input->parse_input_event(p_event);
  279. };
  280. void OS_Android::process_touch(int p_what,int p_pointer, const Vector<TouchPos>& p_points) {
  281. // print_line("ev: "+itos(p_what)+" pnt: "+itos(p_pointer)+" pointc: "+itos(p_points.size()));
  282. switch(p_what) {
  283. case 0: { //gesture begin
  284. if (touch.size()) {
  285. //end all if exist
  286. InputEvent ev;
  287. ev.type=InputEvent::MOUSE_BUTTON;
  288. ev.ID=last_id++;
  289. ev.mouse_button.button_index=BUTTON_LEFT;
  290. ev.mouse_button.button_mask=BUTTON_MASK_LEFT;
  291. ev.mouse_button.pressed=false;
  292. ev.mouse_button.x=touch[0].pos.x;
  293. ev.mouse_button.y=touch[0].pos.y;
  294. ev.mouse_button.global_x=touch[0].pos.x;
  295. ev.mouse_button.global_y=touch[0].pos.y;
  296. input->parse_input_event(ev);
  297. for(int i=0;i<touch.size();i++) {
  298. InputEvent ev;
  299. ev.type=InputEvent::SCREEN_TOUCH;
  300. ev.ID=last_id++;
  301. ev.screen_touch.index=touch[i].id;
  302. ev.screen_touch.pressed=false;
  303. ev.screen_touch.x=touch[i].pos.x;
  304. ev.screen_touch.y=touch[i].pos.y;
  305. input->parse_input_event(ev);
  306. }
  307. }
  308. touch.resize(p_points.size());
  309. for(int i=0;i<p_points.size();i++) {
  310. touch[i].id=p_points[i].id;
  311. touch[i].pos=p_points[i].pos;
  312. }
  313. {
  314. //send mouse
  315. InputEvent ev;
  316. ev.type=InputEvent::MOUSE_BUTTON;
  317. ev.ID=last_id++;
  318. ev.mouse_button.button_index=BUTTON_LEFT;
  319. ev.mouse_button.button_mask=BUTTON_MASK_LEFT;
  320. ev.mouse_button.pressed=true;
  321. ev.mouse_button.x=touch[0].pos.x;
  322. ev.mouse_button.y=touch[0].pos.y;
  323. ev.mouse_button.global_x=touch[0].pos.x;
  324. ev.mouse_button.global_y=touch[0].pos.y;
  325. last_mouse=touch[0].pos;
  326. input->parse_input_event(ev);
  327. }
  328. //send touch
  329. for(int i=0;i<touch.size();i++) {
  330. InputEvent ev;
  331. ev.type=InputEvent::SCREEN_TOUCH;
  332. ev.ID=last_id++;
  333. ev.screen_touch.index=touch[i].id;
  334. ev.screen_touch.pressed=true;
  335. ev.screen_touch.x=touch[i].pos.x;
  336. ev.screen_touch.y=touch[i].pos.y;
  337. input->parse_input_event(ev);
  338. }
  339. } break;
  340. case 1: { //motion
  341. if (p_points.size()) {
  342. //send mouse, should look for point 0?
  343. InputEvent ev;
  344. ev.type=InputEvent::MOUSE_MOTION;
  345. ev.ID=last_id++;
  346. ev.mouse_motion.button_mask=BUTTON_MASK_LEFT;
  347. ev.mouse_motion.x=p_points[0].pos.x;
  348. ev.mouse_motion.y=p_points[0].pos.y;
  349. input->set_mouse_pos(Point2(ev.mouse_motion.x,ev.mouse_motion.y));
  350. ev.mouse_motion.speed_x=input->get_mouse_speed().x;
  351. ev.mouse_motion.speed_y=input->get_mouse_speed().y;
  352. ev.mouse_motion.relative_x=p_points[0].pos.x-last_mouse.x;
  353. ev.mouse_motion.relative_y=p_points[0].pos.y-last_mouse.y;
  354. last_mouse=p_points[0].pos;
  355. input->parse_input_event(ev);
  356. }
  357. ERR_FAIL_COND(touch.size()!=p_points.size());
  358. for(int i=0;i<touch.size();i++) {
  359. int idx=-1;
  360. for(int j=0;j<p_points.size();j++) {
  361. if (touch[i].id==p_points[j].id) {
  362. idx=j;
  363. break;
  364. }
  365. }
  366. ERR_CONTINUE(idx==-1);
  367. if (touch[i].pos==p_points[idx].pos)
  368. continue; //no move unncesearily
  369. InputEvent ev;
  370. ev.type=InputEvent::SCREEN_DRAG;
  371. ev.ID=last_id++;
  372. ev.screen_drag.index=touch[i].id;
  373. ev.screen_drag.x=p_points[idx].pos.x;
  374. ev.screen_drag.y=p_points[idx].pos.y;
  375. ev.screen_drag.relative_x=p_points[idx].pos.x - touch[i].pos.x;
  376. ev.screen_drag.relative_y=p_points[idx].pos.y - touch[i].pos.y;
  377. input->parse_input_event(ev);
  378. touch[i].pos=p_points[idx].pos;
  379. }
  380. } break;
  381. case 2: { //release
  382. if (touch.size()) {
  383. //end all if exist
  384. InputEvent ev;
  385. ev.type=InputEvent::MOUSE_BUTTON;
  386. ev.ID=last_id++;
  387. ev.mouse_button.button_index=BUTTON_LEFT;
  388. ev.mouse_button.button_mask=BUTTON_MASK_LEFT;
  389. ev.mouse_button.pressed=false;
  390. ev.mouse_button.x=touch[0].pos.x;
  391. ev.mouse_button.y=touch[0].pos.y;
  392. ev.mouse_button.global_x=touch[0].pos.x;
  393. ev.mouse_button.global_y=touch[0].pos.y;
  394. input->parse_input_event(ev);
  395. for(int i=0;i<touch.size();i++) {
  396. InputEvent ev;
  397. ev.type=InputEvent::SCREEN_TOUCH;
  398. ev.ID=last_id++;
  399. ev.screen_touch.index=touch[i].id;
  400. ev.screen_touch.pressed=false;
  401. ev.screen_touch.x=touch[i].pos.x;
  402. ev.screen_touch.y=touch[i].pos.y;
  403. input->parse_input_event(ev);
  404. }
  405. touch.clear();
  406. }
  407. } break;
  408. case 3: { // add tuchi
  409. ERR_FAIL_INDEX(p_pointer,p_points.size());
  410. TouchPos tp=p_points[p_pointer];
  411. touch.push_back(tp);
  412. InputEvent ev;
  413. ev.type=InputEvent::SCREEN_TOUCH;
  414. ev.ID=last_id++;
  415. ev.screen_touch.index=tp.id;
  416. ev.screen_touch.pressed=true;
  417. ev.screen_touch.x=tp.pos.x;
  418. ev.screen_touch.y=tp.pos.y;
  419. input->parse_input_event(ev);
  420. } break;
  421. case 4: {
  422. for(int i=0;i<touch.size();i++) {
  423. if (touch[i].id==p_pointer) {
  424. InputEvent ev;
  425. ev.type=InputEvent::SCREEN_TOUCH;
  426. ev.ID=last_id++;
  427. ev.screen_touch.index=touch[i].id;
  428. ev.screen_touch.pressed=false;
  429. ev.screen_touch.x=touch[i].pos.x;
  430. ev.screen_touch.y=touch[i].pos.y;
  431. input->parse_input_event(ev);
  432. touch.remove(i);
  433. i--;
  434. }
  435. }
  436. } break;
  437. }
  438. }
  439. void OS_Android::process_accelerometer(const Vector3& p_accelerometer) {
  440. input->set_accelerometer(p_accelerometer);
  441. }
  442. void OS_Android::process_magnetometer(const Vector3& p_magnetometer) {
  443. input->set_magnetometer(p_magnetometer);
  444. }
  445. void OS_Android::process_gyroscope(const Vector3& p_gyroscope) {
  446. input->set_gyroscope(p_gyroscope);
  447. }
  448. bool OS_Android::has_touchscreen_ui_hint() const {
  449. return true;
  450. }
  451. bool OS_Android::has_virtual_keyboard() const {
  452. return true;
  453. };
  454. void OS_Android::show_virtual_keyboard(const String& p_existing_text,const Rect2& p_screen_rect) {
  455. if (show_virtual_keyboard_func) {
  456. show_virtual_keyboard_func(p_existing_text);
  457. } else {
  458. ERR_PRINT("Virtual keyboard not available");
  459. };
  460. };
  461. void OS_Android::hide_virtual_keyboard() {
  462. if (hide_virtual_keyboard_func) {
  463. hide_virtual_keyboard_func();
  464. } else {
  465. ERR_PRINT("Virtual keyboard not available");
  466. };
  467. };
  468. void OS_Android::init_video_mode(int p_video_width,int p_video_height) {
  469. default_videomode.width=p_video_width;
  470. default_videomode.height=p_video_height;
  471. default_videomode.fullscreen=true;
  472. default_videomode.resizable=false;
  473. }
  474. void OS_Android::main_loop_request_quit() {
  475. if (main_loop)
  476. main_loop->notification(MainLoop::NOTIFICATION_WM_QUIT_REQUEST);
  477. }
  478. void OS_Android::set_display_size(Size2 p_size) {
  479. default_videomode.width=p_size.x;
  480. default_videomode.height=p_size.y;
  481. }
  482. void OS_Android::reload_gfx() {
  483. if (gfx_init_func)
  484. gfx_init_func(gfx_init_ud,use_gl2);
  485. if (rasterizer)
  486. rasterizer->reload_vram();
  487. }
  488. Error OS_Android::shell_open(String p_uri) {
  489. if (open_uri_func)
  490. return open_uri_func(p_uri)?ERR_CANT_OPEN:OK;
  491. return ERR_UNAVAILABLE;
  492. };
  493. String OS_Android::get_resource_dir() const {
  494. return "/"; //android has it's own filesystem for resources inside the APK
  495. }
  496. String OS_Android::get_locale() const {
  497. if (get_locale_func)
  498. return get_locale_func();
  499. return OS_Unix::get_locale();
  500. }
  501. String OS_Android::get_model_name() const {
  502. if (get_model_func)
  503. return get_model_func();
  504. return OS_Unix::get_model_name();
  505. }
  506. int OS_Android::get_screen_dpi(int p_screen) const {
  507. if (get_screen_dpi_func) {
  508. return get_screen_dpi_func();
  509. }
  510. return 160;
  511. }
  512. void OS_Android::set_need_reload_hooks(bool p_needs_them) {
  513. use_reload_hooks=p_needs_them;
  514. }
  515. String OS_Android::get_data_dir() const {
  516. if (data_dir_cache!=String())
  517. return data_dir_cache;
  518. if (get_data_dir_func) {
  519. String data_dir=get_data_dir_func();
  520. //store current dir
  521. char real_current_dir_name[2048];
  522. getcwd(real_current_dir_name,2048);
  523. //go to data dir
  524. chdir(data_dir.utf8().get_data());
  525. //get actual data dir, so we resolve potential symlink (Android 6.0+ seems to use symlink)
  526. char data_current_dir_name[2048];
  527. getcwd(data_current_dir_name,2048);
  528. //cache by parsing utf8
  529. data_dir_cache.parse_utf8(data_current_dir_name);
  530. //restore original dir so we don't mess things up
  531. chdir(real_current_dir_name);
  532. return data_dir_cache;
  533. }
  534. return ".";
  535. //return Globals::get_singleton()->get_singleton_object("GodotOS")->call("get_data_dir");
  536. };
  537. void OS_Android::set_screen_orientation(ScreenOrientation p_orientation) {
  538. if (set_screen_orientation_func)
  539. set_screen_orientation_func(p_orientation);
  540. }
  541. String OS_Android::get_unique_ID() const {
  542. if (get_unique_id_func)
  543. return get_unique_id_func();
  544. return OS::get_unique_ID();
  545. }
  546. Error OS_Android::native_video_play(String p_path, float p_volume) {
  547. if (video_play_func)
  548. video_play_func(p_path);
  549. return OK;
  550. }
  551. bool OS_Android::native_video_is_playing() {
  552. if (video_is_playing_func)
  553. return video_is_playing_func();
  554. return false;
  555. }
  556. void OS_Android::native_video_pause() {
  557. if (video_pause_func)
  558. video_pause_func();
  559. }
  560. String OS_Android::get_system_dir(SystemDir p_dir) const {
  561. if (get_system_dir_func)
  562. return get_system_dir_func(p_dir);
  563. return String(".");
  564. }
  565. void OS_Android::native_video_stop() {
  566. if (video_stop_func)
  567. video_stop_func();
  568. }
  569. void OS_Android::set_context_is_16_bits(bool p_is_16) {
  570. use_16bits_fbo=p_is_16;
  571. if (rasterizer)
  572. rasterizer->set_force_16_bits_fbo(p_is_16);
  573. }
  574. void OS_Android::joy_connection_changed(int p_device, bool p_connected, String p_name) {
  575. return input->joy_connection_changed(p_device, p_connected, p_name, "");
  576. }
  577. bool OS_Android::is_joy_known(int p_device) {
  578. return input->is_joy_mapped(p_device);
  579. }
  580. String OS_Android::get_joy_guid(int p_device) const {
  581. return input->get_joy_guid_remapped(p_device);
  582. }
  583. OS_Android::OS_Android(GFXInitFunc p_gfx_init_func,void*p_gfx_init_ud, OpenURIFunc p_open_uri_func, GetDataDirFunc p_get_data_dir_func,GetLocaleFunc p_get_locale_func,GetModelFunc p_get_model_func, GetScreenDPIFunc p_get_screen_dpi_func, ShowVirtualKeyboardFunc p_show_vk, HideVirtualKeyboardFunc p_hide_vk, SetScreenOrientationFunc p_screen_orient,GetUniqueIDFunc p_get_unique_id,GetSystemDirFunc p_get_sdir_func, VideoPlayFunc p_video_play_func, VideoIsPlayingFunc p_video_is_playing_func, VideoPauseFunc p_video_pause_func, VideoStopFunc p_video_stop_func, SetKeepScreenOnFunc p_set_keep_screen_on_func, bool p_use_apk_expansion) {
  584. use_apk_expansion=p_use_apk_expansion;
  585. default_videomode.width=800;
  586. default_videomode.height=600;
  587. default_videomode.fullscreen=true;
  588. default_videomode.resizable=false;
  589. gfx_init_func=p_gfx_init_func;
  590. gfx_init_ud=p_gfx_init_ud;
  591. main_loop=NULL;
  592. last_id=1;
  593. gl_extensions=NULL;
  594. rasterizer=NULL;
  595. use_gl2=false;
  596. open_uri_func=p_open_uri_func;
  597. get_data_dir_func=p_get_data_dir_func;
  598. get_locale_func=p_get_locale_func;
  599. get_model_func=p_get_model_func;
  600. get_screen_dpi_func = p_get_screen_dpi_func;
  601. get_unique_id_func=p_get_unique_id;
  602. get_system_dir_func=p_get_sdir_func;
  603. video_play_func = p_video_play_func;
  604. video_is_playing_func = p_video_is_playing_func;
  605. video_pause_func = p_video_pause_func;
  606. video_stop_func = p_video_stop_func;
  607. show_virtual_keyboard_func = p_show_vk;
  608. hide_virtual_keyboard_func = p_hide_vk;
  609. set_screen_orientation_func=p_screen_orient;
  610. set_keep_screen_on_func = p_set_keep_screen_on_func;
  611. use_reload_hooks=false;
  612. }
  613. OS_Android::~OS_Android() {
  614. }