Skip to content

Commit

Permalink
[POC] iOS editor support.
Browse files Browse the repository at this point in the history
  • Loading branch information
bruvzg committed Feb 10, 2023
1 parent 5ca1123 commit a8de536
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 6 deletions.
19 changes: 19 additions & 0 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -700,6 +700,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<String> _cmd_args = _cmd_args_str.split("\n");
for (int i = 0; i < _cmd_args.size(); i++) {
args.push_back(_cmd_args[i]);
}
Ref<DirAccess> dir_access = DirAccess::create(DirAccess::ACCESS_FILESYSTEM);
dir_access->remove(_cmd_path);
#endif

List<String>::Element *I = args.front();

Expand Down Expand Up @@ -1520,12 +1530,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.");
Expand Down
10 changes: 9 additions & 1 deletion platform/ios/godot_view_renderer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
#import <QuartzCore/QuartzCore.h>
#import <UIKit/UIKit.h>

extern void ios_finish();

@interface GodotViewRenderer ()

@property(assign, nonatomic) BOOL hasFinishedProjectDataSetup;
Expand Down Expand Up @@ -112,7 +114,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
10 changes: 7 additions & 3 deletions platform/ios/os_ios.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,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;
Expand All @@ -94,11 +92,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<String> get_system_fonts() const override;
virtual Vector<String> 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<String> &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;
Expand All @@ -111,7 +114,8 @@ class OS_IOS : public OS_Unix {
virtual Error shell_open(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;
Expand Down
31 changes: 29 additions & 2 deletions platform/ios/os_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -191,10 +191,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<String> &p_arguments, ProcessID *r_child_id) {
String _cmd_path = OS::get_singleton()->get_user_data_dir().path_join("_cmd");
{
Ref<FileAccess> 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

Expand Down Expand Up @@ -309,6 +321,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()) {
Expand Down

0 comments on commit a8de536

Please sign in to comment.