From a60ff16ed53671bc5b53b5918903b0027231a2e5 Mon Sep 17 00:00:00 2001 From: bruvzg <7645683+bruvzg@users.noreply.github.com> Date: Fri, 10 Feb 2023 20:38:17 +0200 Subject: [PATCH] Support iPadOS --- main/main.cpp | 19 ++++++++++++++++++ platform/ios/godot_view_renderer.mm | 10 +++++++++- platform/ios/os_ios.h | 10 +++++++--- platform/ios/os_ios.mm | 31 +++++++++++++++++++++++++++-- 4 files changed, 64 insertions(+), 6 deletions(-) diff --git a/main/main.cpp b/main/main.cpp index 4c9c159f47d..0dddec2b3e9 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -902,6 +902,16 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph for (const String &arg : platform_args) { args.push_back(arg); } +#if defined(IOS_ENABLED) && defined(TOOLS_ENABLED) + String _cmd_path = OS::get_singleton()->get_user_data_dir().path_join("_cmd"); + String _cmd_args_str = FileAccess::get_file_as_string(_cmd_path); + Vector _cmd_args = _cmd_args_str.split("\n"); + for (int i = 0; i < _cmd_args.size(); i++) { + args.push_back(_cmd_args[i]); + } + Ref dir_access = DirAccess::create(DirAccess::ACCESS_FILESYSTEM); + dir_access->remove(_cmd_path); +#endif List::Element *I = args.front(); @@ -2004,12 +2014,21 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph if (default_renderer_mobile.is_empty()) { default_renderer_mobile = "gl_compatibility"; } +#ifndef IOS_ENABLED // Default to Compatibility when using the project manager. if (rendering_driver.is_empty() && rendering_method.is_empty() && project_manager) { rendering_driver = "opengl3"; rendering_method = "gl_compatibility"; default_renderer_mobile = "gl_compatibility"; } +#else + if (rendering_driver.is_empty() && rendering_method.is_empty() && project_manager) { + rendering_driver = "vulkan"; + rendering_method = "mobile"; + default_renderer_mobile = "mobile"; + } +#endif + #endif if (renderer_hints.is_empty()) { ERR_PRINT("No renderers available."); diff --git a/platform/ios/godot_view_renderer.mm b/platform/ios/godot_view_renderer.mm index 9c56ca342fb..bfa2a429225 100644 --- a/platform/ios/godot_view_renderer.mm +++ b/platform/ios/godot_view_renderer.mm @@ -44,6 +44,8 @@ #import #import +extern void ios_finish(); + @interface GodotViewRenderer () @property(assign, nonatomic) BOOL hasFinishedProjectDataSetup; @@ -113,7 +115,13 @@ - (void)renderOnView:(UIView *)view { return; } - OS_IOS::get_singleton()->iterate(); + if (OS_IOS::get_singleton()->iterate()) { + OS_IOS::get_singleton()->delete_main_loop(); + ios_finish(); +#ifdef TOOLS_ENABLED + exit(0); +#endif + } } @end diff --git a/platform/ios/os_ios.h b/platform/ios/os_ios.h index 10ecd08a89d..5754d879747 100644 --- a/platform/ios/os_ios.h +++ b/platform/ios/os_ios.h @@ -71,8 +71,6 @@ class OS_IOS : public OS_Unix { virtual void set_main_loop(MainLoop *p_main_loop) override; virtual MainLoop *get_main_loop() const override; - virtual void delete_main_loop() override; - virtual void finalize() override; bool is_focused = false; @@ -98,11 +96,16 @@ class OS_IOS : public OS_Unix { void start(); virtual void alert(const String &p_alert, const String &p_title = "ALERT!") override; + virtual void delete_main_loop() override; virtual Vector get_system_fonts() const override; virtual Vector get_system_font_path_for_text(const String &p_font_name, const String &p_text, const String &p_locale = String(), const String &p_script = String(), int p_weight = 400, int p_stretch = 100, bool p_italic = false) const override; virtual String get_system_font_path(const String &p_font_name, int p_weight = 400, int p_stretch = 100, bool p_italic = false) const override; +#ifdef TOOLS_ENABLED + virtual Error create_instance(const List &p_arguments, ProcessID *r_child_id) override; +#endif + virtual Error open_dynamic_library(const String &p_path, void *&p_library_handle, bool p_also_set_library_path = false, String *r_resolved_path = nullptr) override; virtual Error close_dynamic_library(void *p_library_handle) override; virtual Error get_dynamic_library_symbol_handle(void *p_library_handle, const String &p_name, void *&p_symbol_handle, bool p_optional = false) override; @@ -115,7 +118,8 @@ class OS_IOS : public OS_Unix { virtual Error shell_open(const String &p_uri) override; virtual String get_user_data_dir() const override; - + virtual String get_data_path() const override; + virtual String get_config_path() const override; virtual String get_cache_path() const override; virtual String get_locale() const override; diff --git a/platform/ios/os_ios.mm b/platform/ios/os_ios.mm index 23614af3663..405b1b8af8f 100644 --- a/platform/ios/os_ios.mm +++ b/platform/ios/os_ios.mm @@ -190,10 +190,22 @@ void register_dynamic_symbol(char *name, void *address) { void OS_IOS::finalize() { deinitialize_modules(); +} - // Already gets called - //delete_main_loop(); +#ifdef TOOLS_ENABLED +Error OS_IOS::create_instance(const List &p_arguments, ProcessID *r_child_id) { + String _cmd_path = OS::get_singleton()->get_user_data_dir().path_join("_cmd"); + { + Ref f = FileAccess::open(_cmd_path, FileAccess::WRITE); + if (f.is_valid()) { + for (const String &arg : p_arguments) { + f->store_line(arg); + } + } + } + return OK; } +#endif // MARK: Dynamic Libraries @@ -320,6 +332,21 @@ void register_dynamic_symbol(char *name, void *address) { return OK; } +String OS_IOS::get_config_path() const { + static String ret; + if (ret.is_empty()) { + NSArray *paths = NSSearchPathForDirectoriesInDomains(NSApplicationSupportDirectory, NSUserDomainMask, YES); + if (paths && [paths count] >= 1) { + ret.parse_utf8([[paths firstObject] UTF8String]); + } + } + return ret; +} + +String OS_IOS::get_data_path() const { + return get_config_path(); +} + String OS_IOS::get_user_data_dir() const { static String ret; if (ret.is_empty()) {