2023-01-10 15:26:54 +01:00
|
|
|
/**************************************************************************/
|
|
|
|
/* os_iphone.mm */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* 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-10 02:10:30 +01:00
|
|
|
#ifdef IPHONE_ENABLED
|
|
|
|
|
|
|
|
#include "os_iphone.h"
|
|
|
|
|
2018-12-11 14:49:34 +01:00
|
|
|
#include "drivers/gles2/rasterizer_gles2.h"
|
2017-01-07 09:33:11 +01:00
|
|
|
#include "drivers/gles3/rasterizer_gles3.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "servers/visual/visual_server_raster.h"
|
2018-11-01 14:27:04 +01:00
|
|
|
#include "servers/visual/visual_server_wrap_mt.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "main/main.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
#include "core/io/file_access_pack.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
#include "core/os/dir_access.h"
|
2014-12-02 18:02:41 +01:00
|
|
|
#include "core/os/file_access.h"
|
2017-07-19 22:00:46 +02:00
|
|
|
#include "core/project_settings.h"
|
2017-09-22 07:56:02 +02:00
|
|
|
#include "drivers/unix/syslog_logger.h"
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-10-05 21:19:38 +02:00
|
|
|
#import "app_delegate.h"
|
|
|
|
#import "device_metrics.h"
|
|
|
|
#import "godot_view.h"
|
2020-11-15 13:11:25 +01:00
|
|
|
#import "keyboard_input_view.h"
|
2020-10-05 21:19:38 +02:00
|
|
|
#import "native_video_view.h"
|
|
|
|
#import "view_controller.h"
|
|
|
|
|
2022-05-23 14:02:12 +02:00
|
|
|
#include "tts_ios.h"
|
|
|
|
|
2020-10-05 21:19:38 +02:00
|
|
|
#import <UIKit/UIKit.h>
|
|
|
|
#include <dlfcn.h>
|
2022-02-15 22:25:51 +01:00
|
|
|
#include <sys/sysctl.h>
|
2020-10-05 21:19:38 +02:00
|
|
|
#import <sys/utsname.h>
|
|
|
|
|
|
|
|
extern int gl_view_base_fb; // from gl_view.mm
|
|
|
|
extern bool gles3_available; // from gl_view.mm
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
HashMap<String, void *> OSIPhone::dynamic_symbol_lookup_table;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-10-05 21:19:38 +02:00
|
|
|
int OSIPhone::get_video_driver_count() const {
|
2018-12-11 14:49:34 +01:00
|
|
|
return 2;
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
const char *OSIPhone::get_video_driver_name(int p_driver) const {
|
2018-12-11 14:49:34 +01:00
|
|
|
switch (p_driver) {
|
|
|
|
case VIDEO_DRIVER_GLES3:
|
|
|
|
return "GLES3";
|
|
|
|
case VIDEO_DRIVER_GLES2:
|
|
|
|
return "GLES2";
|
|
|
|
}
|
2019-08-09 06:49:33 +02:00
|
|
|
ERR_FAIL_V_MSG(NULL, "Invalid video driver index: " + itos(p_driver) + ".");
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
OSIPhone *OSIPhone::get_singleton() {
|
|
|
|
return (OSIPhone *)OS::get_singleton();
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2022-05-23 14:02:12 +02:00
|
|
|
bool OSIPhone::tts_is_speaking() const {
|
2023-05-22 15:41:09 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tts, false, "Enable the \"audio/general/text_to_speech\" project setting to use text-to-speech.");
|
2022-05-23 14:02:12 +02:00
|
|
|
ERR_FAIL_COND_V(!tts, false);
|
|
|
|
return [tts isSpeaking];
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OSIPhone::tts_is_paused() const {
|
2023-05-22 15:41:09 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tts, false, "Enable the \"audio/general/text_to_speech\" project setting to use text-to-speech.");
|
2022-05-23 14:02:12 +02:00
|
|
|
ERR_FAIL_COND_V(!tts, false);
|
|
|
|
return [tts isPaused];
|
|
|
|
}
|
|
|
|
|
|
|
|
Array OSIPhone::tts_get_voices() const {
|
2023-05-22 15:41:09 +02:00
|
|
|
ERR_FAIL_COND_V_MSG(!tts, Array(), "Enable the \"audio/general/text_to_speech\" project setting to use text-to-speech.");
|
2022-05-23 14:02:12 +02:00
|
|
|
ERR_FAIL_COND_V(!tts, Array());
|
|
|
|
return [tts getVoices];
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSIPhone::tts_speak(const String &p_text, const String &p_voice, int p_volume, float p_pitch, float p_rate, int p_utterance_id, bool p_interrupt) {
|
2023-05-22 15:41:09 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tts, "Enable the \"audio/general/text_to_speech\" project setting to use text-to-speech.");
|
2022-05-23 14:02:12 +02:00
|
|
|
ERR_FAIL_COND(!tts);
|
|
|
|
[tts speak:p_text voice:p_voice volume:p_volume pitch:p_pitch rate:p_rate utterance_id:p_utterance_id interrupt:p_interrupt];
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSIPhone::tts_pause() {
|
2023-05-22 15:41:09 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tts, "Enable the \"audio/general/text_to_speech\" project setting to use text-to-speech.");
|
2022-05-23 14:02:12 +02:00
|
|
|
ERR_FAIL_COND(!tts);
|
|
|
|
[tts pauseSpeaking];
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSIPhone::tts_resume() {
|
2023-05-22 15:41:09 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tts, "Enable the \"audio/general/text_to_speech\" project setting to use text-to-speech.");
|
2022-05-23 14:02:12 +02:00
|
|
|
ERR_FAIL_COND(!tts);
|
|
|
|
[tts resumeSpeaking];
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSIPhone::tts_stop() {
|
2023-05-22 15:41:09 +02:00
|
|
|
ERR_FAIL_COND_MSG(!tts, "Enable the \"audio/general/text_to_speech\" project setting to use text-to-speech.");
|
2022-05-23 14:02:12 +02:00
|
|
|
ERR_FAIL_COND(!tts);
|
|
|
|
[tts stopSpeaking];
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void OSIPhone::set_data_dir(String p_dir) {
|
2017-03-05 16:44:50 +01:00
|
|
|
DirAccess *da = DirAccess::open(p_dir);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
data_dir = da->get_current_dir();
|
2014-12-02 18:02:41 +01:00
|
|
|
printf("setting data dir to %ls from %ls\n", data_dir.c_str(), p_dir.c_str());
|
2014-02-10 02:10:30 +01:00
|
|
|
memdelete(da);
|
|
|
|
};
|
|
|
|
|
2017-08-07 12:17:31 +02:00
|
|
|
String OSIPhone::get_unique_id() const {
|
2020-08-10 15:16:13 +02:00
|
|
|
NSString *uuid = [UIDevice currentDevice].identifierForVendor.UUIDString;
|
|
|
|
return String::utf8([uuid UTF8String]);
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void OSIPhone::initialize_core() {
|
|
|
|
OS_Unix::initialize_core();
|
2017-10-04 11:11:57 +02:00
|
|
|
|
|
|
|
set_data_dir(data_dir);
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2018-07-19 23:58:15 +02:00
|
|
|
int OSIPhone::get_current_video_driver() const {
|
|
|
|
return video_driver_index;
|
|
|
|
}
|
|
|
|
|
2020-10-05 21:19:38 +02:00
|
|
|
void OSIPhone::start() {
|
|
|
|
Main::start();
|
|
|
|
|
|
|
|
if (joypad_iphone) {
|
|
|
|
joypad_iphone->start_processing();
|
|
|
|
}
|
|
|
|
}
|
2018-12-11 14:49:34 +01:00
|
|
|
|
2018-01-03 18:26:44 +01:00
|
|
|
Error OSIPhone::initialize(const VideoMode &p_desired, int p_video_driver, int p_audio_driver) {
|
2018-12-11 14:49:34 +01: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 {
|
2019-03-05 13:46:51 +01:00
|
|
|
if (GLOBAL_GET("rendering/quality/driver/fallback_to_gles2")) {
|
2018-12-11 14:49:34 +01:00
|
|
|
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 23:58:15 +02:00
|
|
|
|
2018-12-11 14:49:34 +01: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-10 02:10:30 +01:00
|
|
|
|
2018-12-11 14:49:34 +01: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-10 02:10:30 +01:00
|
|
|
if (get_render_thread_mode() != RENDER_THREAD_UNSAFE) {
|
|
|
|
visual_server = memnew(VisualServerWrapMT(visual_server, false));
|
2018-11-01 14:27:04 +01:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-05-23 14:02:12 +02:00
|
|
|
// Init TTS
|
2023-05-22 15:41:09 +02:00
|
|
|
bool tts_enabled = GLOBAL_GET("audio/general/text_to_speech");
|
|
|
|
if (tts_enabled) {
|
|
|
|
tts = [[TTS_IOS alloc] init];
|
|
|
|
}
|
2022-05-23 14:02:12 +02:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
visual_server->init();
|
2017-12-06 21:36:34 +01:00
|
|
|
//visual_server->cursor_set_visible(false, 0);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-07-25 00:29:48 +02:00
|
|
|
// reset this to what it should be, it will have been set to 0 after visual_server->init() is called
|
2020-10-05 21:19:38 +02:00
|
|
|
if (use_gl3) {
|
2018-12-11 14:49:34 +01:00
|
|
|
RasterizerStorageGLES3::system_fbo = gl_view_base_fb;
|
2020-10-05 21:19:38 +02:00
|
|
|
} else {
|
2018-12-11 14:49:34 +01:00
|
|
|
RasterizerStorageGLES2::system_fbo = gl_view_base_fb;
|
2020-10-05 21:19:38 +02:00
|
|
|
}
|
2017-07-25 00:29:48 +02:00
|
|
|
|
2017-09-29 20:22:42 +02:00
|
|
|
AudioDriverManager::initialize(p_audio_driver);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-05 16:44:50 +01:00
|
|
|
input = memnew(InputDefault);
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2019-09-24 09:29:02 +02:00
|
|
|
ios = memnew(iOS);
|
|
|
|
Engine::get_singleton()->add_singleton(Engine::Singleton("iOS", ios));
|
2018-01-03 18:26:44 +01:00
|
|
|
|
2020-10-05 21:19:38 +02:00
|
|
|
joypad_iphone = memnew(JoypadIPhone);
|
|
|
|
|
2018-01-03 18:26:44 +01:00
|
|
|
return OK;
|
2014-02-10 02:10:30 +01: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-10 02:10:30 +01:00
|
|
|
main_loop = p_main_loop;
|
|
|
|
|
|
|
|
if (main_loop) {
|
|
|
|
input->set_main_loop(p_main_loop);
|
|
|
|
main_loop->init();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
bool OSIPhone::iterate() {
|
2020-10-05 21:19:38 +02:00
|
|
|
if (!main_loop) {
|
2014-02-10 02:10:30 +01:00
|
|
|
return true;
|
2020-10-05 21:19:38 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2022-07-08 20:01:19 +02:00
|
|
|
input->flush_buffered_events();
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
return Main::iteration();
|
|
|
|
};
|
|
|
|
|
|
|
|
void OSIPhone::key(uint32_t p_key, bool p_pressed) {
|
2017-05-20 17:38:03 +02:00
|
|
|
Ref<InputEventKey> ev;
|
2017-05-13 05:51:40 +02:00
|
|
|
ev.instance();
|
|
|
|
ev->set_echo(false);
|
2017-05-20 17:38:03 +02:00
|
|
|
ev->set_pressed(p_pressed);
|
|
|
|
ev->set_scancode(p_key);
|
2021-03-07 16:16:42 +01:00
|
|
|
ev->set_physical_scancode(p_key);
|
2017-05-20 17:38:03 +02:00
|
|
|
ev->set_unicode(p_key);
|
2020-10-05 21:19:38 +02:00
|
|
|
perform_event(ev);
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2021-03-30 18:42:28 +02:00
|
|
|
void OSIPhone::pencil_press(int p_idx, int p_x, int p_y, bool p_pressed, bool p_doubleclick) {
|
|
|
|
Ref<InputEventMouseButton> ev;
|
|
|
|
ev.instance();
|
|
|
|
ev->set_button_index(1);
|
|
|
|
ev->set_pressed(p_pressed);
|
|
|
|
ev->set_position(Vector2(p_x, p_y));
|
|
|
|
ev->set_global_position(Vector2(p_x, p_y));
|
|
|
|
ev->set_doubleclick(p_doubleclick);
|
|
|
|
perform_event(ev);
|
|
|
|
};
|
|
|
|
|
|
|
|
void OSIPhone::pencil_drag(int p_idx, int p_prev_x, int p_prev_y, int p_x, int p_y, float p_force) {
|
|
|
|
Ref<InputEventMouseMotion> ev;
|
|
|
|
ev.instance();
|
|
|
|
ev->set_pressure(p_force);
|
|
|
|
ev->set_position(Vector2(p_x, p_y));
|
|
|
|
ev->set_global_position(Vector2(p_x, p_y));
|
|
|
|
ev->set_relative(Vector2(p_x - p_prev_x, p_y - p_prev_y));
|
|
|
|
perform_event(ev);
|
|
|
|
};
|
|
|
|
|
|
|
|
void OSIPhone::pencil_cancelled(int p_idx) {
|
|
|
|
pencil_press(p_idx, -1, -1, false, false);
|
|
|
|
}
|
|
|
|
|
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) {
|
2020-10-05 21:19:38 +02:00
|
|
|
if (GLOBAL_DEF("debug/disable_touch", false)) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-10-05 21:19:38 +02:00
|
|
|
Ref<InputEventScreenTouch> ev;
|
|
|
|
ev.instance();
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-10-05 21:19:38 +02:00
|
|
|
ev->set_index(p_idx);
|
|
|
|
ev->set_pressed(p_pressed);
|
|
|
|
ev->set_position(Vector2(p_x, p_y));
|
2022-10-19 05:03:31 +02:00
|
|
|
ev->set_double_tap(p_doubleclick);
|
2020-10-05 21:19:38 +02:00
|
|
|
perform_event(ev);
|
2014-02-10 02:10:30 +01: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) {
|
2020-10-05 21:19:38 +02:00
|
|
|
if (GLOBAL_DEF("debug/disable_touch", false)) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-10-05 21:19:38 +02:00
|
|
|
Ref<InputEventScreenDrag> ev;
|
|
|
|
ev.instance();
|
|
|
|
ev->set_index(p_idx);
|
|
|
|
ev->set_position(Vector2(p_x, p_y));
|
|
|
|
ev->set_relative(Vector2(p_x - p_prev_x, p_y - p_prev_y));
|
|
|
|
perform_event(ev);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-10-05 21:19:38 +02:00
|
|
|
void OSIPhone::perform_event(const Ref<InputEvent> &p_event) {
|
|
|
|
input->parse_input_event(p_event);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-10-05 21:19:38 +02:00
|
|
|
void OSIPhone::touches_cancelled(int p_idx) {
|
|
|
|
touch_press(p_idx, -1, -1, false, false);
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
static const float ACCEL_RANGE = 1;
|
|
|
|
|
2016-11-23 13:32:44 +01: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-10 02:10:30 +01:00
|
|
|
void OSIPhone::update_accelerometer(float p_x, float p_y, float p_z) {
|
2016-11-19 13:04:06 +01: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-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
2016-11-13 12:11:00 +01:00
|
|
|
void OSIPhone::update_magnetometer(float p_x, float p_y, float p_z) {
|
2016-11-19 13:04:06 +01:00
|
|
|
input->set_magnetometer(Vector3(p_x, p_y, p_z));
|
2016-11-13 12:11:00 +01:00
|
|
|
};
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2016-11-13 12:11:00 +01:00
|
|
|
void OSIPhone::update_gyroscope(float p_x, float p_y, float p_z) {
|
2016-11-16 11:54:51 +01:00
|
|
|
input->set_gyroscope(Vector3(p_x, p_y, p_z));
|
2016-11-13 12:11:00 +01:00
|
|
|
};
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-05-14 09:28:59 +02: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);
|
|
|
|
};
|
|
|
|
|
2021-12-25 09:45:37 +01:00
|
|
|
void OSIPhone::joy_axis(int p_device, int p_axis, float p_value) {
|
2017-05-14 09:28:59 +02:00
|
|
|
input->joy_axis(p_device, p_axis, p_value);
|
|
|
|
};
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
void OSIPhone::delete_main_loop() {
|
|
|
|
if (main_loop) {
|
|
|
|
main_loop->finish();
|
|
|
|
memdelete(main_loop);
|
|
|
|
};
|
|
|
|
|
|
|
|
main_loop = NULL;
|
|
|
|
};
|
|
|
|
|
|
|
|
void OSIPhone::finalize() {
|
2020-01-18 08:43:54 +01:00
|
|
|
delete_main_loop();
|
|
|
|
|
2020-10-05 21:19:38 +02:00
|
|
|
if (joypad_iphone) {
|
|
|
|
memdelete(joypad_iphone);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (input) {
|
|
|
|
memdelete(input);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ios) {
|
|
|
|
memdelete(ios);
|
|
|
|
}
|
2020-01-18 08:43:54 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
visual_server->finish();
|
|
|
|
memdelete(visual_server);
|
2017-03-05 16:44:50 +01:00
|
|
|
// memdelete(rasterizer);
|
2020-10-05 21:19:38 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-10-05 21:19:38 +02:00
|
|
|
void OSIPhone::set_mouse_show(bool p_show) {
|
|
|
|
// Not supported for iOS
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-10-05 21:19:38 +02:00
|
|
|
void OSIPhone::set_mouse_grab(bool p_grab) {
|
|
|
|
// Not supported for iOS
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
bool OSIPhone::is_mouse_grab_enabled() const {
|
2020-10-05 21:19:38 +02:00
|
|
|
// Not supported for iOS
|
2014-02-10 02:10:30 +01:00
|
|
|
return true;
|
2020-10-05 21:19:38 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-03-29 17:29:38 +02:00
|
|
|
Point2 OSIPhone::get_mouse_position() const {
|
2020-10-05 21:19:38 +02:00
|
|
|
// Not supported for iOS
|
2014-02-10 02:10:30 +01:00
|
|
|
return Point2();
|
2020-10-05 21:19:38 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
int OSIPhone::get_mouse_button_state() const {
|
2020-10-05 21:19:38 +02:00
|
|
|
// Not supported for iOS
|
2018-02-24 03:04:30 +01:00
|
|
|
return 0;
|
2020-10-05 21:19:38 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2020-10-05 21:19:38 +02:00
|
|
|
void OSIPhone::set_window_title(const String &p_title) {
|
|
|
|
// Not supported for iOS
|
|
|
|
}
|
2014-02-10 02:10:30 +01: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());
|
|
|
|
}
|
|
|
|
|
2020-10-05 21:19:38 +02:00
|
|
|
// MARK: Dynamic Libraries
|
|
|
|
|
2017-12-03 08:49:12 +01:00
|
|
|
Error OSIPhone::open_dynamic_library(const String p_path, void *&p_library_handle, bool p_also_set_library_path) {
|
2017-10-02 17:01:43 +02:00
|
|
|
if (p_path.length() == 0) {
|
|
|
|
p_library_handle = RTLD_SELF;
|
|
|
|
return OK;
|
|
|
|
}
|
2017-12-03 08:49:12 +01:00
|
|
|
return OS_Unix::open_dynamic_library(p_path, p_library_handle, p_also_set_library_path);
|
2017-10-02 17:01:43 +02: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);
|
|
|
|
}
|
|
|
|
|
|
|
|
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-10 02:10:30 +01:00
|
|
|
video_mode = p_video_mode;
|
2020-10-05 21:19:38 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
OS::VideoMode OSIPhone::get_video_mode(int p_screen) const {
|
|
|
|
return video_mode;
|
2020-10-05 21:19:38 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
void OSIPhone::get_fullscreen_mode_list(List<VideoMode> *p_list, int p_screen) const {
|
|
|
|
p_list->push_back(video_mode);
|
2020-10-05 21:19:38 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2021-09-24 14:07:44 +02:00
|
|
|
void OSIPhone::set_offscreen_gl_context(EAGLContext *p_context) {
|
|
|
|
offscreen_gl_context = p_context;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OSIPhone::is_offscreen_gl_available() const {
|
|
|
|
return offscreen_gl_context;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSIPhone::set_offscreen_gl_current(bool p_current) {
|
|
|
|
if (p_current) {
|
|
|
|
[EAGLContext setCurrentContext:offscreen_gl_context];
|
|
|
|
} else {
|
|
|
|
[EAGLContext setCurrentContext:nil];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
bool OSIPhone::can_draw() const {
|
2014-03-14 02:57:24 +01:00
|
|
|
if (native_video_is_playing())
|
|
|
|
return false;
|
2014-02-10 02:10:30 +01:00
|
|
|
return true;
|
2020-10-05 21:19:38 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
int OSIPhone::set_base_framebuffer(int p_fb) {
|
2017-07-25 00:29:48 +02:00
|
|
|
// gl_view_base_fb has not been updated yet
|
|
|
|
RasterizerStorageGLES3::system_fbo = p_fb;
|
2017-01-07 09:33:11 +01:00
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
return 0;
|
2020-10-05 21:19:38 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
|
|
|
bool OSIPhone::has_virtual_keyboard() const {
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
2022-07-07 20:22:28 +02:00
|
|
|
void OSIPhone::show_virtual_keyboard(const String &p_existing_text, const Rect2 &p_screen_rect, VirtualKeyboardType p_type, int p_max_input_length, int p_cursor_start, int p_cursor_end) {
|
2020-11-15 13:11:25 +01:00
|
|
|
NSString *existingString = [[NSString alloc] initWithUTF8String:p_existing_text.utf8().get_data()];
|
|
|
|
|
2022-07-07 20:22:28 +02:00
|
|
|
AppDelegate.viewController.keyboardView.keyboardType = UIKeyboardTypeDefault;
|
|
|
|
AppDelegate.viewController.keyboardView.textContentType = nil;
|
|
|
|
switch (p_type) {
|
|
|
|
case KEYBOARD_TYPE_DEFAULT: {
|
|
|
|
AppDelegate.viewController.keyboardView.keyboardType = UIKeyboardTypeDefault;
|
|
|
|
} break;
|
|
|
|
case KEYBOARD_TYPE_MULTILINE: {
|
|
|
|
AppDelegate.viewController.keyboardView.keyboardType = UIKeyboardTypeDefault;
|
|
|
|
} break;
|
|
|
|
case KEYBOARD_TYPE_NUMBER: {
|
|
|
|
AppDelegate.viewController.keyboardView.keyboardType = UIKeyboardTypeNumberPad;
|
|
|
|
} break;
|
|
|
|
case KEYBOARD_TYPE_NUMBER_DECIMAL: {
|
|
|
|
AppDelegate.viewController.keyboardView.keyboardType = UIKeyboardTypeDecimalPad;
|
|
|
|
} break;
|
|
|
|
case KEYBOARD_TYPE_PHONE: {
|
|
|
|
AppDelegate.viewController.keyboardView.keyboardType = UIKeyboardTypePhonePad;
|
|
|
|
AppDelegate.viewController.keyboardView.textContentType = UITextContentTypeTelephoneNumber;
|
|
|
|
} break;
|
|
|
|
case KEYBOARD_TYPE_EMAIL_ADDRESS: {
|
|
|
|
AppDelegate.viewController.keyboardView.keyboardType = UIKeyboardTypeEmailAddress;
|
|
|
|
AppDelegate.viewController.keyboardView.textContentType = UITextContentTypeEmailAddress;
|
|
|
|
} break;
|
|
|
|
case KEYBOARD_TYPE_PASSWORD: {
|
|
|
|
AppDelegate.viewController.keyboardView.keyboardType = UIKeyboardTypeDefault;
|
|
|
|
if (@available(iOS 11.0, *)) {
|
|
|
|
AppDelegate.viewController.keyboardView.textContentType = UITextContentTypePassword;
|
|
|
|
}
|
|
|
|
} break;
|
|
|
|
case KEYBOARD_TYPE_URL: {
|
|
|
|
AppDelegate.viewController.keyboardView.keyboardType = UIKeyboardTypeWebSearch;
|
|
|
|
AppDelegate.viewController.keyboardView.textContentType = UITextContentTypeURL;
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
|
2020-11-15 13:11:25 +01:00
|
|
|
[AppDelegate.viewController.keyboardView
|
|
|
|
becomeFirstResponderWithString:existingString
|
|
|
|
cursorStart:p_cursor_start
|
|
|
|
cursorEnd:p_cursor_end];
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
void OSIPhone::hide_virtual_keyboard() {
|
2020-11-15 13:11:25 +01:00
|
|
|
[AppDelegate.viewController.keyboardView resignFirstResponder];
|
2020-10-05 21:19:38 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-10-04 10:39:31 +02:00
|
|
|
void OSIPhone::set_virtual_keyboard_height(int p_height) {
|
2020-10-05 21:19:38 +02:00
|
|
|
virtual_keyboard_height = p_height * [UIScreen mainScreen].nativeScale;
|
2017-10-04 10:39:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int OSIPhone::get_virtual_keyboard_height() const {
|
|
|
|
return virtual_keyboard_height;
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
Error OSIPhone::shell_open(String p_uri) {
|
2020-10-05 21:19:38 +02:00
|
|
|
NSString *urlPath = [[NSString alloc] initWithUTF8String:p_uri.utf8().get_data()];
|
|
|
|
NSURL *url = [NSURL URLWithString:urlPath];
|
|
|
|
|
|
|
|
if (![[UIApplication sharedApplication] canOpenURL:url]) {
|
|
|
|
return ERR_CANT_OPEN;
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("opening url %s\n", p_uri.utf8().get_data());
|
|
|
|
|
|
|
|
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2015-11-29 05:18:21 +01:00
|
|
|
void OSIPhone::set_keep_screen_on(bool p_enabled) {
|
|
|
|
OS::set_keep_screen_on(p_enabled);
|
2020-10-05 21:19:38 +02:00
|
|
|
[UIApplication sharedApplication].idleTimerDisabled = p_enabled;
|
2015-11-29 05:18:21 +01:00
|
|
|
};
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-11-17 15:25:22 +01:00
|
|
|
String OSIPhone::get_user_data_dir() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
return data_dir;
|
2020-10-05 21:19:38 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2019-05-20 19:36:24 +02:00
|
|
|
String OSIPhone::get_name() const {
|
2014-02-10 02:10:30 +01:00
|
|
|
return "iOS";
|
2020-10-05 21:19:38 +02:00
|
|
|
}
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2021-08-30 11:12:45 +02:00
|
|
|
void OSIPhone::set_clipboard(const String &p_text) {
|
|
|
|
[UIPasteboard generalPasteboard].string = [NSString stringWithUTF8String:p_text.utf8()];
|
|
|
|
}
|
|
|
|
|
|
|
|
String OSIPhone::get_clipboard() const {
|
|
|
|
NSString *text = [UIPasteboard generalPasteboard].string;
|
|
|
|
|
|
|
|
return String::utf8([text UTF8String]);
|
|
|
|
}
|
|
|
|
|
2021-02-22 22:54:12 +01:00
|
|
|
String OSIPhone::get_cache_path() const {
|
|
|
|
return cache_dir;
|
|
|
|
}
|
|
|
|
|
2019-09-24 09:29:02 +02:00
|
|
|
String OSIPhone::get_model_name() const {
|
|
|
|
String model = ios->get_model();
|
2020-10-05 21:19:38 +02:00
|
|
|
if (model != "") {
|
2019-09-24 09:29:02 +02:00
|
|
|
return model;
|
2020-10-05 21:19:38 +02:00
|
|
|
}
|
2019-09-24 09:29:02 +02:00
|
|
|
|
|
|
|
return OS_Unix::get_model_name();
|
|
|
|
}
|
|
|
|
|
2015-03-24 02:55:45 +01:00
|
|
|
Size2 OSIPhone::get_window_size() const {
|
|
|
|
return Vector2(video_mode.width, video_mode.height);
|
|
|
|
}
|
|
|
|
|
2020-10-05 21:19:38 +02:00
|
|
|
int OSIPhone::get_screen_dpi(int p_screen) const {
|
|
|
|
struct utsname systemInfo;
|
|
|
|
uname(&systemInfo);
|
|
|
|
|
|
|
|
NSString *string = [NSString stringWithCString:systemInfo.machine encoding:NSUTF8StringEncoding];
|
|
|
|
|
|
|
|
NSDictionary *iOSModelToDPI = [GodotDeviceMetrics dpiList];
|
|
|
|
|
|
|
|
for (NSArray *keyArray in iOSModelToDPI) {
|
|
|
|
if ([keyArray containsObject:string]) {
|
|
|
|
NSNumber *value = iOSModelToDPI[keyArray];
|
|
|
|
return [value intValue];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// If device wasn't found in dictionary
|
|
|
|
// make a best guess from device metrics.
|
|
|
|
CGFloat scale = [UIScreen mainScreen].scale;
|
|
|
|
|
|
|
|
UIUserInterfaceIdiom idiom = [UIDevice currentDevice].userInterfaceIdiom;
|
|
|
|
|
|
|
|
switch (idiom) {
|
|
|
|
case UIUserInterfaceIdiomPad:
|
|
|
|
return scale == 2 ? 264 : 132;
|
|
|
|
case UIUserInterfaceIdiomPhone: {
|
|
|
|
if (scale == 3) {
|
|
|
|
CGFloat nativeScale = [UIScreen mainScreen].nativeScale;
|
|
|
|
return nativeScale == 3 ? 458 : 401;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 326;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
return 72;
|
|
|
|
}
|
|
|
|
}
|
2018-04-10 12:35:30 +02:00
|
|
|
|
2022-03-06 00:34:56 +01:00
|
|
|
float OSIPhone::get_screen_refresh_rate(int p_screen) const {
|
|
|
|
return [UIScreen mainScreen].maximumFramesPerSecond;
|
|
|
|
}
|
|
|
|
|
2018-04-10 12:35:30 +02:00
|
|
|
Rect2 OSIPhone::get_window_safe_area() const {
|
2020-10-05 21:19:38 +02:00
|
|
|
if (@available(iOS 11, *)) {
|
|
|
|
UIEdgeInsets insets = UIEdgeInsetsZero;
|
|
|
|
UIView *view = AppDelegate.viewController.godotView;
|
|
|
|
|
|
|
|
if ([view respondsToSelector:@selector(safeAreaInsets)]) {
|
|
|
|
insets = [view safeAreaInsets];
|
|
|
|
}
|
|
|
|
|
|
|
|
float scale = [UIScreen mainScreen].nativeScale;
|
|
|
|
Size2i insets_position = Size2i(insets.left, insets.top) * scale;
|
|
|
|
Size2i insets_size = Size2i(insets.left + insets.right, insets.top + insets.bottom) * scale;
|
|
|
|
|
|
|
|
return Rect2i(insets_position, get_window_size() - insets_size);
|
|
|
|
} else {
|
|
|
|
return Rect2i(Size2i(0, 0), get_window_size());
|
|
|
|
}
|
2018-04-10 12:35:30 +02:00
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
bool OSIPhone::has_touchscreen_ui_hint() const {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
String OSIPhone::get_locale() const {
|
2020-08-10 15:16:13 +02:00
|
|
|
NSString *preferedLanguage = [NSLocale preferredLanguages].firstObject;
|
|
|
|
|
|
|
|
if (preferedLanguage) {
|
|
|
|
return String::utf8([preferedLanguage UTF8String]).replace("-", "_");
|
|
|
|
}
|
|
|
|
|
|
|
|
NSString *localeIdentifier = [[NSLocale currentLocale] localeIdentifier];
|
|
|
|
return String::utf8([localeIdentifier UTF8String]).replace("-", "_");
|
2014-02-10 02:10:30 +01:00
|
|
|
}
|
|
|
|
|
2014-11-17 11:46:11 +01: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 18:02:41 +01:00
|
|
|
bool exists = f && f->is_open();
|
2016-02-19 05:09:06 +01:00
|
|
|
|
2020-10-05 21:19:38 +02:00
|
|
|
String user_data_dir = OSIPhone::get_singleton()->get_user_data_dir();
|
|
|
|
|
|
|
|
if (!exists) {
|
2014-12-02 18:02:41 +01:00
|
|
|
return FAILED;
|
2020-10-05 21:19:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
String tempFile = OSIPhone::get_singleton()->get_user_data_dir();
|
2016-03-09 00:00:52 +01:00
|
|
|
|
2016-02-19 05:09:06 +01:00
|
|
|
if (p_path.begins_with("res://")) {
|
|
|
|
if (PackedData::get_singleton()->has_path(p_path)) {
|
2020-10-05 21:19:38 +02:00
|
|
|
printf("Unable to play %s using the native player as it resides in a .pck file\n", p_path.utf8().get_data());
|
2016-02-19 05:09:06 +01:00
|
|
|
return ERR_INVALID_PARAMETER;
|
|
|
|
} else {
|
2017-07-19 22:00:46 +02:00
|
|
|
p_path = p_path.replace("res:/", ProjectSettings::get_singleton()->get_resource_path());
|
2016-02-19 05:09:06 +01:00
|
|
|
}
|
2020-10-05 21:19:38 +02:00
|
|
|
} else if (p_path.begins_with("user://")) {
|
|
|
|
p_path = p_path.replace("user:/", user_data_dir);
|
|
|
|
}
|
2016-02-19 05:09:06 +01:00
|
|
|
|
|
|
|
memdelete(f);
|
|
|
|
|
2020-10-05 21:19:38 +02:00
|
|
|
printf("Playing video: %s\n", p_path.utf8().get_data());
|
|
|
|
|
|
|
|
String file_path = ProjectSettings::get_singleton()->globalize_path(p_path);
|
|
|
|
|
|
|
|
NSString *filePath = [[NSString alloc] initWithUTF8String:file_path.utf8().get_data()];
|
|
|
|
NSString *audioTrack = [NSString stringWithUTF8String:p_audio_track.utf8()];
|
|
|
|
NSString *subtitleTrack = [NSString stringWithUTF8String:p_subtitle_track.utf8()];
|
|
|
|
|
|
|
|
if (![AppDelegate.viewController playVideoAtPath:filePath
|
|
|
|
volume:p_volume
|
|
|
|
audio:audioTrack
|
|
|
|
subtitle:subtitleTrack]) {
|
2014-03-14 02:57:24 +01:00
|
|
|
return OK;
|
2020-10-05 21:19:38 +02:00
|
|
|
}
|
|
|
|
|
2014-03-14 02:57:24 +01:00
|
|
|
return FAILED;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool OSIPhone::native_video_is_playing() const {
|
2020-10-05 21:19:38 +02:00
|
|
|
return [AppDelegate.viewController.videoView isVideoPlaying];
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void OSIPhone::native_video_pause() {
|
2020-10-05 21:19:38 +02:00
|
|
|
if (native_video_is_playing()) {
|
|
|
|
[AppDelegate.viewController.videoView pauseVideo];
|
|
|
|
}
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
2014-11-26 18:24:13 +01:00
|
|
|
void OSIPhone::native_video_unpause() {
|
2020-10-05 21:19:38 +02:00
|
|
|
[AppDelegate.viewController.videoView unpauseVideo];
|
|
|
|
}
|
2014-11-26 18:24:13 +01:00
|
|
|
|
2014-12-02 18:02:41 +01:00
|
|
|
void OSIPhone::native_video_focus_out() {
|
2020-10-05 21:19:38 +02:00
|
|
|
[AppDelegate.viewController.videoView unfocusVideo];
|
|
|
|
}
|
2014-11-26 18:24:13 +01:00
|
|
|
|
2014-03-14 02:57:24 +01:00
|
|
|
void OSIPhone::native_video_stop() {
|
2020-10-05 21:19:38 +02:00
|
|
|
if (native_video_is_playing()) {
|
|
|
|
[AppDelegate.viewController.videoView stopVideo];
|
|
|
|
}
|
2014-03-14 02:57:24 +01:00
|
|
|
}
|
|
|
|
|
2022-02-15 22:25:51 +01:00
|
|
|
String OSIPhone::get_processor_name() const {
|
|
|
|
char buffer[256];
|
|
|
|
size_t buffer_len = 256;
|
|
|
|
if (sysctlbyname("machdep.cpu.brand_string", &buffer, &buffer_len, NULL, 0) == 0) {
|
|
|
|
return String::utf8(buffer, buffer_len);
|
|
|
|
}
|
|
|
|
ERR_FAIL_V_MSG("", String("Couldn't get the CPU model name. Returning an empty string."));
|
|
|
|
}
|
|
|
|
|
2019-08-17 17:27:29 +02:00
|
|
|
void OSIPhone::vibrate_handheld(int p_duration_ms) {
|
2022-04-20 18:37:36 +02:00
|
|
|
if (ios->supports_haptic_engine()) {
|
|
|
|
ios->vibrate_haptic_engine((float)p_duration_ms / 1000.f);
|
|
|
|
} else {
|
|
|
|
// iOS <13 does not support duration for vibration
|
|
|
|
AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);
|
|
|
|
}
|
2019-08-17 17:27:29 +02:00
|
|
|
}
|
|
|
|
|
2017-07-19 22:00:46 +02:00
|
|
|
bool OSIPhone::_check_internal_feature_support(const String &p_feature) {
|
2019-02-26 15:58:47 +01:00
|
|
|
return p_feature == "mobile";
|
2017-07-19 22:00:46 +02:00
|
|
|
}
|
|
|
|
|
2017-10-02 17:01:43 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-22 22:54:12 +01:00
|
|
|
OSIPhone::OSIPhone(String p_data_dir, String p_cache_dir) {
|
2017-10-02 17:01:43 +02: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-10 02:10:30 +01:00
|
|
|
|
|
|
|
main_loop = NULL;
|
|
|
|
visual_server = NULL;
|
2021-09-24 14:07:44 +02:00
|
|
|
offscreen_gl_context = NULL;
|
2014-02-10 02:10:30 +01:00
|
|
|
|
2017-10-04 11:11:57 +02:00
|
|
|
// can't call set_data_dir from here, since it requires DirAccess
|
|
|
|
// which is initialized in initialize_core
|
|
|
|
data_dir = p_data_dir;
|
2021-02-22 22:54:12 +01:00
|
|
|
cache_dir = p_cache_dir;
|
2017-10-04 11:11:57 +02:00
|
|
|
|
2017-11-21 10:35:01 +01: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 18:18:05 +01:00
|
|
|
|
|
|
|
AudioDriverManager::add_driver(&audio_driver);
|
2014-02-10 02:10:30 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
OSIPhone::~OSIPhone() {
|
|
|
|
}
|
|
|
|
|
2020-10-05 21:19:38 +02:00
|
|
|
void OSIPhone::on_focus_out() {
|
|
|
|
if (is_focused) {
|
|
|
|
is_focused = false;
|
|
|
|
|
|
|
|
if (get_main_loop()) {
|
|
|
|
get_main_loop()->notification(MainLoop::NOTIFICATION_WM_FOCUS_OUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
[AppDelegate.viewController.godotView stopRendering];
|
|
|
|
|
|
|
|
if (native_video_is_playing()) {
|
|
|
|
native_video_focus_out();
|
|
|
|
}
|
|
|
|
|
|
|
|
audio_driver.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OSIPhone::on_focus_in() {
|
|
|
|
if (!is_focused) {
|
|
|
|
is_focused = true;
|
|
|
|
|
|
|
|
if (get_main_loop()) {
|
|
|
|
get_main_loop()->notification(MainLoop::NOTIFICATION_WM_FOCUS_IN);
|
|
|
|
}
|
|
|
|
|
|
|
|
[AppDelegate.viewController.godotView startRendering];
|
|
|
|
|
|
|
|
if (native_video_is_playing()) {
|
|
|
|
native_video_unpause();
|
|
|
|
}
|
|
|
|
|
|
|
|
audio_driver.start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-10 02:10:30 +01:00
|
|
|
#endif
|