| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*  os_iphone.cpp                                                        */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							|  |  |  | /*                       This file is part of:                           */ | 
					
						
							|  |  |  | /*                           GODOT ENGINE                                */ | 
					
						
							| 
									
										
										
										
											2017-08-27 14:16:55 +02:00
										 |  |  | /*                      https://godotengine.org                          */ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2019-01-01 12:53:14 +01:00
										 |  |  | /* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur.                 */ | 
					
						
							|  |  |  | /* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md)    */ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* Permission is hereby granted, free of charge, to any person obtaining */ | 
					
						
							|  |  |  | /* a copy of this software and associated documentation files (the       */ | 
					
						
							|  |  |  | /* "Software"), to deal in the Software without restriction, including   */ | 
					
						
							|  |  |  | /* without limitation the rights to use, copy, modify, merge, publish,   */ | 
					
						
							|  |  |  | /* distribute, sublicense, and/or sell copies of the Software, and to    */ | 
					
						
							|  |  |  | /* permit persons to whom the Software is furnished to do so, subject to */ | 
					
						
							|  |  |  | /* the following conditions:                                             */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* The above copyright notice and this permission notice shall be        */ | 
					
						
							|  |  |  | /* included in all copies or substantial portions of the Software.       */ | 
					
						
							|  |  |  | /*                                                                       */ | 
					
						
							|  |  |  | /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,       */ | 
					
						
							|  |  |  | /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF    */ | 
					
						
							|  |  |  | /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/ | 
					
						
							|  |  |  | /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY  */ | 
					
						
							|  |  |  | /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,  */ | 
					
						
							|  |  |  | /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE     */ | 
					
						
							|  |  |  | /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.                */ | 
					
						
							|  |  |  | /*************************************************************************/ | 
					
						
							| 
									
										
										
										
											2018-01-05 00:50:27 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | #ifdef IPHONE_ENABLED
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "os_iphone.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-11 22:49:34 +09:00
										 |  |  | #include "drivers/gles2/rasterizer_gles2.h"
 | 
					
						
							| 
									
										
										
										
											2017-01-07 19:33:11 +11:00
										 |  |  | #include "drivers/gles3/rasterizer_gles3.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | #include "servers/visual/visual_server_raster.h"
 | 
					
						
							| 
									
										
										
										
											2018-11-01 10:27:04 -03:00
										 |  |  | #include "servers/visual/visual_server_wrap_mt.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | #include "main/main.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | #include "core/io/file_access_pack.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | #include "core/os/dir_access.h"
 | 
					
						
							| 
									
										
										
										
											2014-12-02 14:02:41 -03:00
										 |  |  | #include "core/os/file_access.h"
 | 
					
						
							| 
									
										
										
										
											2017-07-19 17:00:46 -03:00
										 |  |  | #include "core/project_settings.h"
 | 
					
						
							| 
									
										
										
										
											2017-09-22 12:56:02 +07:00
										 |  |  | #include "drivers/unix/syslog_logger.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-12 15:43:54 +01:00
										 |  |  | #include "semaphore_iphone.h"
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-04-29 10:50:56 -03:00
										 |  |  | #include "ios.h"
 | 
					
						
							| 
									
										
										
										
											2019-02-12 15:43:54 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-02 22:01:43 +07:00
										 |  |  | #include <dlfcn.h>
 | 
					
						
							| 
									
										
										
										
											2016-04-29 10:50:56 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | int OSIPhone::get_video_driver_count() const { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-11 22:49:34 +09:00
										 |  |  | 	return 2; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | const char *OSIPhone::get_video_driver_name(int p_driver) const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-11 22:49:34 +09:00
										 |  |  | 	switch (p_driver) { | 
					
						
							|  |  |  | 		case VIDEO_DRIVER_GLES3: | 
					
						
							|  |  |  | 			return "GLES3"; | 
					
						
							|  |  |  | 		case VIDEO_DRIVER_GLES2: | 
					
						
							|  |  |  | 			return "GLES2"; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	ERR_EXPLAIN("Invalid video driver index " + itos(p_driver)); | 
					
						
							|  |  |  | 	ERR_FAIL_V(NULL); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | OSIPhone *OSIPhone::get_singleton() { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	return (OSIPhone *)OS::get_singleton(); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | extern int gl_view_base_fb; // from gl_view.mm
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void OSIPhone::set_data_dir(String p_dir) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	DirAccess *da = DirAccess::open(p_dir); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	data_dir = da->get_current_dir(); | 
					
						
							| 
									
										
										
										
											2014-12-02 14:02:41 -03:00
										 |  |  | 	printf("setting data dir to %ls from %ls\n", data_dir.c_str(), p_dir.c_str()); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	memdelete(da); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-07 17:17:31 +07:00
										 |  |  | void OSIPhone::set_unique_id(String p_ID) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	unique_ID = p_ID; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-08-07 17:17:31 +07:00
										 |  |  | String OSIPhone::get_unique_id() const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return unique_ID; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void OSIPhone::initialize_core() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	OS_Unix::initialize_core(); | 
					
						
							|  |  |  | 	SemaphoreIphone::make_default(); | 
					
						
							| 
									
										
										
										
											2017-10-04 16:11:57 +07:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	set_data_dir(data_dir); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-07-19 18:58:15 -03:00
										 |  |  | int OSIPhone::get_current_video_driver() const { | 
					
						
							|  |  |  | 	return video_driver_index; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-11 22:49:34 +09:00
										 |  |  | extern bool gles3_available; // from gl_view.mm
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-01-03 18:26:44 +01:00
										 |  |  | Error OSIPhone::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-11 22:49:34 +09:00
										 |  |  | 	bool use_gl3 = GLOBAL_GET("rendering/quality/driver/driver_name") == "GLES3"; | 
					
						
							|  |  |  | 	bool gl_initialization_error = false; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while (true) { | 
					
						
							|  |  |  | 		if (use_gl3) { | 
					
						
							|  |  |  | 			if (RasterizerGLES3::is_viable() == OK && gles3_available) { | 
					
						
							|  |  |  | 				RasterizerGLES3::register_config(); | 
					
						
							|  |  |  | 				RasterizerGLES3::make_current(); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				if (GLOBAL_GET("rendering/quality/driver/driver_fallback") == "Best") { | 
					
						
							|  |  |  | 					p_video_driver = VIDEO_DRIVER_GLES2; | 
					
						
							|  |  |  | 					use_gl3 = false; | 
					
						
							|  |  |  | 					continue; | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					gl_initialization_error = true; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			if (RasterizerGLES2::is_viable() == OK) { | 
					
						
							|  |  |  | 				RasterizerGLES2::register_config(); | 
					
						
							|  |  |  | 				RasterizerGLES2::make_current(); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				gl_initialization_error = true; | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2018-07-19 18:58:15 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-11 22:49:34 +09:00
										 |  |  | 	if (gl_initialization_error) { | 
					
						
							|  |  |  | 		OS::get_singleton()->alert("Your device does not support any of the supported OpenGL versions.", | 
					
						
							|  |  |  | 				"Unable to initialize Video driver"); | 
					
						
							| 
									
										
										
										
											2018-08-25 00:04:25 +02:00
										 |  |  | 		return ERR_UNAVAILABLE; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-12-11 22:49:34 +09:00
										 |  |  | 	video_driver_index = p_video_driver; | 
					
						
							| 
									
										
										
										
											2018-11-01 19:22:15 +01:00
										 |  |  | 	visual_server = memnew(VisualServerRaster); | 
					
						
							|  |  |  | 	// FIXME: Reimplement threaded rendering
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) { | 
					
						
							|  |  |  | 		visual_server = memnew(VisualServerWrapMT(visual_server, false)); | 
					
						
							| 
									
										
										
										
											2018-11-01 10:27:04 -03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	visual_server->init(); | 
					
						
							| 
									
										
										
										
											2017-12-06 21:36:34 +01:00
										 |  |  | 	//visual_server->cursor_set_visible(false, 0);
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-25 08:29:48 +10:00
										 |  |  | 	// reset this to what it should be, it will have been set to 0 after visual_server->init() is called
 | 
					
						
							| 
									
										
										
										
											2018-12-11 22:49:34 +09:00
										 |  |  | 	if (use_gl3) | 
					
						
							|  |  |  | 		RasterizerStorageGLES3::system_fbo = gl_view_base_fb; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		RasterizerStorageGLES2::system_fbo = gl_view_base_fb; | 
					
						
							| 
									
										
										
										
											2017-07-25 08:29:48 +10:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-29 15:22:42 -03:00
										 |  |  | 	AudioDriverManager::initialize(p_audio_driver); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	input = memnew(InputDefault); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef GAME_CENTER_ENABLED
 | 
					
						
							|  |  |  | 	game_center = memnew(GameCenter); | 
					
						
							| 
									
										
										
										
											2017-11-13 21:46:57 +01:00
										 |  |  | 	Engine::get_singleton()->add_singleton(Engine::Singleton("GameCenter", game_center)); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	game_center->connect(); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef STOREKIT_ENABLED
 | 
					
						
							|  |  |  | 	store_kit = memnew(InAppStore); | 
					
						
							| 
									
										
										
										
											2017-11-13 21:46:57 +01:00
										 |  |  | 	Engine::get_singleton()->add_singleton(Engine::Singleton("InAppStore", store_kit)); | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2015-09-27 16:54:20 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | #ifdef ICLOUD_ENABLED
 | 
					
						
							|  |  |  | 	icloud = memnew(ICloud); | 
					
						
							| 
									
										
										
										
											2017-11-13 21:46:57 +01:00
										 |  |  | 	Engine::get_singleton()->add_singleton(Engine::Singleton("ICloud", icloud)); | 
					
						
							| 
									
										
										
										
											2017-12-06 21:36:34 +01:00
										 |  |  | 	//icloud->connect();
 | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2017-11-13 21:46:57 +01:00
										 |  |  | 	Engine::get_singleton()->add_singleton(Engine::Singleton("iOS", memnew(iOS))); | 
					
						
							| 
									
										
										
										
											2018-01-03 18:26:44 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return OK; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | MainLoop *OSIPhone::get_main_loop() const { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return main_loop; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void OSIPhone::set_main_loop(MainLoop *p_main_loop) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	main_loop = p_main_loop; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (main_loop) { | 
					
						
							|  |  |  | 		input->set_main_loop(p_main_loop); | 
					
						
							|  |  |  | 		main_loop->init(); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool OSIPhone::iterate() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!main_loop) | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (main_loop) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		for (int i = 0; i < event_count; i++) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			input->parse_input_event(event_queue[i]); | 
					
						
							|  |  |  | 		}; | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	event_count = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return Main::iteration(); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void OSIPhone::key(uint32_t p_key, bool p_pressed) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 	Ref<InputEventKey> ev; | 
					
						
							| 
									
										
										
										
											2017-05-13 13:51:40 +10:00
										 |  |  | 	ev.instance(); | 
					
						
							|  |  |  | 	ev->set_echo(false); | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 	ev->set_pressed(p_pressed); | 
					
						
							|  |  |  | 	ev->set_scancode(p_key); | 
					
						
							|  |  |  | 	ev->set_unicode(p_key); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	queue_event(ev); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-24 03:04:30 +01:00
										 |  |  | void OSIPhone::touch_press(int p_idx, int p_x, int p_y, bool p_pressed, bool p_doubleclick) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-02 14:02:41 -03:00
										 |  |  | 	if (!GLOBAL_DEF("debug/disable_touch", false)) { | 
					
						
							| 
									
										
										
										
											2017-05-13 13:51:40 +10:00
										 |  |  | 		Ref<InputEventScreenTouch> ev; | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 		ev.instance(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		ev->set_index(p_idx); | 
					
						
							|  |  |  | 		ev->set_pressed(p_pressed); | 
					
						
							| 
									
										
										
										
											2017-06-03 10:54:24 +02:00
										 |  |  | 		ev->set_position(Vector2(p_x, p_y)); | 
					
						
							| 
									
										
										
										
											2014-12-02 14:02:41 -03:00
										 |  |  | 		queue_event(ev); | 
					
						
							|  |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-24 03:04:30 +01:00
										 |  |  | 	touch_list.pressed[p_idx] = p_pressed; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-24 03:04:30 +01:00
										 |  |  | void OSIPhone::touch_drag(int p_idx, int p_prev_x, int p_prev_y, int p_x, int p_y) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-02 14:02:41 -03:00
										 |  |  | 	if (!GLOBAL_DEF("debug/disable_touch", false)) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 		Ref<InputEventScreenDrag> ev; | 
					
						
							|  |  |  | 		ev.instance(); | 
					
						
							|  |  |  | 		ev->set_index(p_idx); | 
					
						
							| 
									
										
										
										
											2017-06-03 10:54:24 +02:00
										 |  |  | 		ev->set_position(Vector2(p_x, p_y)); | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | 		ev->set_relative(Vector2(p_x - p_prev_x, p_y - p_prev_y)); | 
					
						
							| 
									
										
										
										
											2014-12-02 14:02:41 -03:00
										 |  |  | 		queue_event(ev); | 
					
						
							|  |  |  | 	}; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-20 12:38:03 -03:00
										 |  |  | void OSIPhone::queue_event(const Ref<InputEvent> &p_event) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	ERR_FAIL_INDEX(event_count, MAX_EVENTS); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 	event_queue[event_count++] = p_event; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void OSIPhone::touches_cancelled() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	for (int i = 0; i < MAX_MOUSE_COUNT; i++) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-24 03:04:30 +01:00
										 |  |  | 		if (touch_list.pressed[i]) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 			// send a mouse_up outside the screen
 | 
					
						
							| 
									
										
										
										
											2018-02-24 03:04:30 +01:00
										 |  |  | 			touch_press(i, -1, -1, false, false); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		}; | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static const float ACCEL_RANGE = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-23 23:32:44 +11:00
										 |  |  | void OSIPhone::update_gravity(float p_x, float p_y, float p_z) { | 
					
						
							|  |  |  | 	input->set_gravity(Vector3(p_x, p_y, p_z)); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | void OSIPhone::update_accelerometer(float p_x, float p_y, float p_z) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-19 23:04:06 +11:00
										 |  |  | 	// Found out the Z should not be negated! Pass as is!
 | 
					
						
							|  |  |  | 	input->set_accelerometer(Vector3(p_x / (float)ACCEL_RANGE, p_y / (float)ACCEL_RANGE, p_z / (float)ACCEL_RANGE)); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/*
 | 
					
						
							|  |  |  | 	if (p_x != last_accel.x) { | 
					
						
							|  |  |  | 		//printf("updating accel x %f\n", p_x);
 | 
					
						
							|  |  |  | 		InputEvent ev; | 
					
						
							| 
									
										
										
										
											2017-01-08 17:05:51 -03:00
										 |  |  | 		ev.type = InputEvent::JOYPAD_MOTION; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		ev.device = 0; | 
					
						
							| 
									
										
										
										
											2017-03-24 17:33:52 +01:00
										 |  |  | 		ev.joy_motion.axis = JOY_ANALOG_0; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		ev.joy_motion.axis_value = (p_x / (float)ACCEL_RANGE); | 
					
						
							|  |  |  | 		last_accel.x = p_x; | 
					
						
							|  |  |  | 		queue_event(ev); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	if (p_y != last_accel.y) { | 
					
						
							|  |  |  | 		//printf("updating accel y %f\n", p_y);
 | 
					
						
							|  |  |  | 		InputEvent ev; | 
					
						
							| 
									
										
										
										
											2017-01-08 17:05:51 -03:00
										 |  |  | 		ev.type = InputEvent::JOYPAD_MOTION; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		ev.device = 0; | 
					
						
							| 
									
										
										
										
											2017-03-24 17:33:52 +01:00
										 |  |  | 		ev.joy_motion.axis = JOY_ANALOG_1; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		ev.joy_motion.axis_value = (p_y / (float)ACCEL_RANGE); | 
					
						
							|  |  |  | 		last_accel.y = p_y; | 
					
						
							|  |  |  | 		queue_event(ev); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	if (p_z != last_accel.z) { | 
					
						
							|  |  |  | 		//printf("updating accel z %f\n", p_z);
 | 
					
						
							|  |  |  | 		InputEvent ev; | 
					
						
							| 
									
										
										
										
											2017-01-08 17:05:51 -03:00
										 |  |  | 		ev.type = InputEvent::JOYPAD_MOTION; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		ev.device = 0; | 
					
						
							| 
									
										
										
										
											2017-03-24 17:33:52 +01:00
										 |  |  | 		ev.joy_motion.axis = JOY_ANALOG_2; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		ev.joy_motion.axis_value = ( (1.0 - p_z) / (float)ACCEL_RANGE); | 
					
						
							|  |  |  | 		last_accel.z = p_z; | 
					
						
							|  |  |  | 		queue_event(ev); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	*/ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-13 22:11:00 +11:00
										 |  |  | void OSIPhone::update_magnetometer(float p_x, float p_y, float p_z) { | 
					
						
							| 
									
										
										
										
											2016-11-19 23:04:06 +11:00
										 |  |  | 	input->set_magnetometer(Vector3(p_x, p_y, p_z)); | 
					
						
							| 
									
										
										
										
											2016-11-13 22:11:00 +11:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-11-13 22:11:00 +11:00
										 |  |  | void OSIPhone::update_gyroscope(float p_x, float p_y, float p_z) { | 
					
						
							| 
									
										
										
										
											2016-11-16 21:54:51 +11:00
										 |  |  | 	input->set_gyroscope(Vector3(p_x, p_y, p_z)); | 
					
						
							| 
									
										
										
										
											2016-11-13 22:11:00 +11:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-14 17:28:59 +10:00
										 |  |  | int OSIPhone::get_unused_joy_id() { | 
					
						
							|  |  |  | 	return input->get_unused_joy_id(); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void OSIPhone::joy_connection_changed(int p_idx, bool p_connected, String p_name) { | 
					
						
							|  |  |  | 	input->joy_connection_changed(p_idx, p_connected, p_name); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void OSIPhone::joy_button(int p_device, int p_button, bool p_pressed) { | 
					
						
							|  |  |  | 	input->joy_button(p_device, p_button, p_pressed); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void OSIPhone::joy_axis(int p_device, int p_axis, const InputDefault::JoyAxis &p_value) { | 
					
						
							|  |  |  | 	input->joy_axis(p_device, p_axis, p_value); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | void OSIPhone::delete_main_loop() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (main_loop) { | 
					
						
							|  |  |  | 		main_loop->finish(); | 
					
						
							|  |  |  | 		memdelete(main_loop); | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	main_loop = NULL; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void OSIPhone::finalize() { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (main_loop) // should not happen?
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 		memdelete(main_loop); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	visual_server->finish(); | 
					
						
							|  |  |  | 	memdelete(visual_server); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	//	memdelete(rasterizer);
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	memdelete(input); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void OSIPhone::set_mouse_show(bool p_show){}; | 
					
						
							|  |  |  | void OSIPhone::set_mouse_grab(bool p_grab){}; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | bool OSIPhone::is_mouse_grab_enabled() const { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-29 11:29:38 -04:00
										 |  |  | Point2 OSIPhone::get_mouse_position() const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return Point2(); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int OSIPhone::get_mouse_button_state() const { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-02-24 03:04:30 +01:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void OSIPhone::set_window_title(const String &p_title){}; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-05-25 17:30:36 +02:00
										 |  |  | void OSIPhone::alert(const String &p_alert, const String &p_title) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	const CharString utf8_alert = p_alert.utf8(); | 
					
						
							|  |  |  | 	const CharString utf8_title = p_title.utf8(); | 
					
						
							|  |  |  | 	iOS::alert(utf8_alert.get_data(), utf8_title.get_data()); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-03 14:49:12 +07:00
										 |  |  | Error OSIPhone::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path) { | 
					
						
							| 
									
										
										
										
											2017-10-02 22:01:43 +07:00
										 |  |  | 	if (p_path.length() == 0) { | 
					
						
							|  |  |  | 		p_library_handle = RTLD_SELF; | 
					
						
							|  |  |  | 		return OK; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2017-12-03 14:49:12 +07:00
										 |  |  | 	return OS_Unix::open_dynamic_library(p_path, p_library_handle, p_also_set_library_path); | 
					
						
							| 
									
										
										
										
											2017-10-02 22:01:43 +07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Error OSIPhone::close_dynamic_library(void *p_library_handle) { | 
					
						
							|  |  |  | 	if (p_library_handle == RTLD_SELF) { | 
					
						
							|  |  |  | 		return OK; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return OS_Unix::close_dynamic_library(p_library_handle); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | HashMap<String, void *> OSIPhone::dynamic_symbol_lookup_table; | 
					
						
							|  |  |  | void register_dynamic_symbol(char *name, void *address) { | 
					
						
							|  |  |  | 	OSIPhone::dynamic_symbol_lookup_table[String(name)] = address; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Error OSIPhone::get_dynamic_library_symbol_handle(void *p_library_handle, const String p_name, void *&p_symbol_handle, bool p_optional) { | 
					
						
							|  |  |  | 	if (p_library_handle == RTLD_SELF) { | 
					
						
							|  |  |  | 		void **ptr = OSIPhone::dynamic_symbol_lookup_table.getptr(p_name); | 
					
						
							|  |  |  | 		if (ptr) { | 
					
						
							|  |  |  | 			p_symbol_handle = *ptr; | 
					
						
							|  |  |  | 			return OK; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return OS_Unix::get_dynamic_library_symbol_handle(p_library_handle, p_name, p_symbol_handle, p_optional); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void OSIPhone::set_video_mode(const VideoMode &p_video_mode, int p_screen) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	video_mode = p_video_mode; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | OS::VideoMode OSIPhone::get_video_mode(int p_screen) const { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return video_mode; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void OSIPhone::get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen) const { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	p_list->push_back(video_mode); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool OSIPhone::can_draw() const { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-13 22:57:24 -03:00
										 |  |  | 	if (native_video_is_playing()) | 
					
						
							|  |  |  | 		return false; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	return true; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int OSIPhone::set_base_framebuffer(int p_fb) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-25 08:29:48 +10:00
										 |  |  | 	// gl_view_base_fb has not been updated yet
 | 
					
						
							|  |  |  | 	RasterizerStorageGLES3::system_fbo = p_fb; | 
					
						
							| 
									
										
										
										
											2017-01-07 19:33:11 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool OSIPhone::has_virtual_keyboard() const { | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | extern void _show_keyboard(String p_existing); | 
					
						
							|  |  |  | extern void _hide_keyboard(); | 
					
						
							|  |  |  | extern Error _shell_open(String p_uri); | 
					
						
							| 
									
										
										
										
											2015-11-29 13:18:21 +09:00
										 |  |  | extern void _set_keep_screen_on(bool p_enabled); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void OSIPhone::show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	_show_keyboard(p_existing_text); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void OSIPhone::hide_virtual_keyboard() { | 
					
						
							|  |  |  | 	_hide_keyboard(); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-04 15:39:31 +07:00
										 |  |  | void OSIPhone::set_virtual_keyboard_height(int p_height) { | 
					
						
							|  |  |  | 	virtual_keyboard_height = p_height; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int OSIPhone::get_virtual_keyboard_height() const { | 
					
						
							|  |  |  | 	return virtual_keyboard_height; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | Error OSIPhone::shell_open(String p_uri) { | 
					
						
							|  |  |  | 	return _shell_open(p_uri); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-11-29 13:18:21 +09:00
										 |  |  | void OSIPhone::set_keep_screen_on(bool p_enabled) { | 
					
						
							|  |  |  | 	OS::set_keep_screen_on(p_enabled); | 
					
						
							|  |  |  | 	_set_keep_screen_on(p_enabled); | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void OSIPhone::set_cursor_shape(CursorShape p_shape){ | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-17 15:25:22 +01:00
										 |  |  | String OSIPhone::get_user_data_dir() const { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return data_dir; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-10 08:50:11 -02:00
										 |  |  | void OSIPhone::set_custom_mouse_cursor(const RES &p_cursor, CursorShape p_shape, const Vector2 &p_hotspot){}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | String OSIPhone::get_name() { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return "iOS"; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-23 18:55:45 -07:00
										 |  |  | Size2 OSIPhone::get_window_size() const { | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-03-23 18:55:45 -07:00
										 |  |  | 	return Vector2(video_mode.width, video_mode.height); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-04-10 17:35:30 +07:00
										 |  |  | extern Rect2 _get_ios_window_safe_area(float p_window_width, float p_window_height); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | Rect2 OSIPhone::get_window_safe_area() const { | 
					
						
							|  |  |  | 	return _get_ios_window_safe_area(video_mode.width, video_mode.height); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | bool OSIPhone::has_touchscreen_ui_hint() const { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | void OSIPhone::set_locale(String p_locale) { | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 	locale_code = p_locale; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | String OSIPhone::get_locale() const { | 
					
						
							|  |  |  | 	return locale_code; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-17 07:46:11 -03:00
										 |  |  | extern bool _play_video(String p_path, float p_volume, String p_audio_track, String p_subtitle_track); | 
					
						
							| 
									
										
										
										
											2014-03-13 22:57:24 -03:00
										 |  |  | extern bool _is_video_playing(); | 
					
						
							|  |  |  | extern void _pause_video(); | 
					
						
							| 
									
										
										
										
											2014-11-26 14:24:13 -03:00
										 |  |  | extern void _unpause_video(); | 
					
						
							| 
									
										
										
										
											2014-03-13 22:57:24 -03:00
										 |  |  | extern void _stop_video(); | 
					
						
							| 
									
										
										
										
											2014-12-02 14:02:41 -03:00
										 |  |  | extern void _focus_out_video(); | 
					
						
							| 
									
										
										
										
											2014-03-13 22:57:24 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-17 07:46:11 -03:00
										 |  |  | Error OSIPhone::native_video_play(String p_path, float p_volume, String p_audio_track, String p_subtitle_track) { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	FileAccess *f = FileAccess::open(p_path, FileAccess::READ); | 
					
						
							| 
									
										
										
										
											2014-12-02 14:02:41 -03:00
										 |  |  | 	bool exists = f && f->is_open(); | 
					
						
							| 
									
										
										
										
											2016-02-19 15:09:06 +11:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-17 15:25:22 +01:00
										 |  |  | 	String tempFile = get_user_data_dir(); | 
					
						
							| 
									
										
										
										
											2014-12-02 14:02:41 -03:00
										 |  |  | 	if (!exists) | 
					
						
							|  |  |  | 		return FAILED; | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-02-19 15:09:06 +11:00
										 |  |  | 	if (p_path.begins_with("res://")) { | 
					
						
							|  |  |  | 		if (PackedData::get_singleton()->has_path(p_path)) { | 
					
						
							|  |  |  | 			print("Unable to play %S using the native player as it resides in a .pck file\n", p_path.c_str()); | 
					
						
							|  |  |  | 			return ERR_INVALID_PARAMETER; | 
					
						
							|  |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2017-07-19 17:00:46 -03:00
										 |  |  | 			p_path = p_path.replace("res:/", ProjectSettings::get_singleton()->get_resource_path()); | 
					
						
							| 
									
										
										
										
											2016-02-19 15:09:06 +11:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} else if (p_path.begins_with("user://")) | 
					
						
							| 
									
										
										
										
											2017-11-17 15:25:22 +01:00
										 |  |  | 		p_path = p_path.replace("user:/", get_user_data_dir()); | 
					
						
							| 
									
										
										
										
											2016-02-19 15:09:06 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	memdelete(f); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-03-09 00:00:52 +01:00
										 |  |  | 	print("Playing video: %S\n", p_path.c_str()); | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	if (_play_video(p_path, p_volume, p_audio_track, p_subtitle_track)) | 
					
						
							| 
									
										
										
										
											2014-03-13 22:57:24 -03:00
										 |  |  | 		return OK; | 
					
						
							|  |  |  | 	return FAILED; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool OSIPhone::native_video_is_playing() const { | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 	return _is_video_playing(); | 
					
						
							| 
									
										
										
										
											2014-03-13 22:57:24 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void OSIPhone::native_video_pause() { | 
					
						
							|  |  |  | 	if (native_video_is_playing()) | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		_pause_video(); | 
					
						
							| 
									
										
										
										
											2014-03-13 22:57:24 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-11-26 14:24:13 -03:00
										 |  |  | void OSIPhone::native_video_unpause() { | 
					
						
							|  |  |  | 	_unpause_video(); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-12-02 14:02:41 -03:00
										 |  |  | void OSIPhone::native_video_focus_out() { | 
					
						
							|  |  |  | 	_focus_out_video(); | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2014-11-26 14:24:13 -03:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-03-13 22:57:24 -03:00
										 |  |  | void OSIPhone::native_video_stop() { | 
					
						
							|  |  |  | 	if (native_video_is_playing()) | 
					
						
							| 
									
										
										
										
											2017-03-05 16:44:50 +01:00
										 |  |  | 		_stop_video(); | 
					
						
							| 
									
										
										
										
											2014-03-13 22:57:24 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-07-19 17:00:46 -03:00
										 |  |  | bool OSIPhone::_check_internal_feature_support(const String &p_feature) { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-02-26 11:58:47 -03:00
										 |  |  | 	return p_feature == "mobile"; | 
					
						
							| 
									
										
										
										
											2017-07-19 17:00:46 -03:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-02 22:01:43 +07:00
										 |  |  | // Initialization order between compilation units is not guaranteed,
 | 
					
						
							|  |  |  | // so we use this as a hack to ensure certain code is called before
 | 
					
						
							|  |  |  | // everything else, but after all units are initialized.
 | 
					
						
							|  |  |  | typedef void (*init_callback)(); | 
					
						
							|  |  |  | static init_callback *ios_init_callbacks = NULL; | 
					
						
							|  |  |  | static int ios_init_callbacks_count = 0; | 
					
						
							|  |  |  | static int ios_init_callbacks_capacity = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void add_ios_init_callback(init_callback cb) { | 
					
						
							|  |  |  | 	if (ios_init_callbacks_count == ios_init_callbacks_capacity) { | 
					
						
							|  |  |  | 		void *new_ptr = realloc(ios_init_callbacks, sizeof(cb) * 32); | 
					
						
							|  |  |  | 		if (new_ptr) { | 
					
						
							|  |  |  | 			ios_init_callbacks = (init_callback *)(new_ptr); | 
					
						
							|  |  |  | 			ios_init_callbacks_capacity += 32; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (ios_init_callbacks_capacity > ios_init_callbacks_count) { | 
					
						
							|  |  |  | 		ios_init_callbacks[ios_init_callbacks_count] = cb; | 
					
						
							|  |  |  | 		++ios_init_callbacks_count; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-04 16:11:57 +07:00
										 |  |  | OSIPhone::OSIPhone(int width, int height, String p_data_dir) { | 
					
						
							| 
									
										
										
										
											2017-10-02 22:01:43 +07:00
										 |  |  | 	for (int i = 0; i < ios_init_callbacks_count; ++i) { | 
					
						
							|  |  |  | 		ios_init_callbacks[i](); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	free(ios_init_callbacks); | 
					
						
							|  |  |  | 	ios_init_callbacks = NULL; | 
					
						
							|  |  |  | 	ios_init_callbacks_count = 0; | 
					
						
							|  |  |  | 	ios_init_callbacks_capacity = 0; | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	main_loop = NULL; | 
					
						
							|  |  |  | 	visual_server = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	VideoMode vm; | 
					
						
							|  |  |  | 	vm.fullscreen = true; | 
					
						
							|  |  |  | 	vm.width = width; | 
					
						
							|  |  |  | 	vm.height = height; | 
					
						
							|  |  |  | 	vm.resizable = false; | 
					
						
							|  |  |  | 	set_video_mode(vm); | 
					
						
							|  |  |  | 	event_count = 0; | 
					
						
							| 
									
										
										
										
											2017-10-04 15:39:31 +07:00
										 |  |  | 	virtual_keyboard_height = 0; | 
					
						
							| 
									
										
										
										
											2017-09-22 12:56:02 +07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-04 16:11:57 +07:00
										 |  |  | 	// can't call set_data_dir from here, since it requires DirAccess
 | 
					
						
							|  |  |  | 	// which is initialized in initialize_core
 | 
					
						
							|  |  |  | 	data_dir = p_data_dir; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-21 16:35:01 +07:00
										 |  |  | 	Vector<Logger *> loggers; | 
					
						
							|  |  |  | 	loggers.push_back(memnew(SyslogLogger)); | 
					
						
							|  |  |  | #ifdef DEBUG_ENABLED
 | 
					
						
							|  |  |  | 	// it seems iOS app's stdout/stderr is only obtainable if you launch it from Xcode
 | 
					
						
							|  |  |  | 	loggers.push_back(memnew(StdLogger)); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	_set_logger(memnew(CompositeLogger(loggers))); | 
					
						
							| 
									
										
										
										
											2018-03-04 14:18:05 -03:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	AudioDriverManager::add_driver(&audio_driver); | 
					
						
							| 
									
										
										
										
											2014-02-09 22:10:30 -03:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | OSIPhone::~OSIPhone() { | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 |