Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion drivers/apple_embedded/SCsub
Original file line number Diff line number Diff line change
@@ -1,16 +1,32 @@
#!/usr/bin/env python
from misc.utility.scons_hints import *

from SCons.Script import Glob

from platform_methods import setup_swift_builder

Import("env")

env_apple_embedded = env.Clone()

# Enable module support
env_apple_embedded.Append(CCFLAGS=["-fmodules", "-fcxx-modules"])

# Configure Swift builder
apple_platform = env["APPLE_PLATFORM"]
sdk_path = env["APPLE_SDK_PATH"]
current_path = Dir(".").abspath
bridging_header_filename = "bridging_header_apple_embedded.h"
swift_files = Glob("*.swift")
swift_file_names = list(map(lambda f: f.name, swift_files))
setup_swift_builder(
env_apple_embedded, apple_platform, sdk_path, current_path, bridging_header_filename, swift_file_names
)

# Use bundled Vulkan headers
vulkan_dir = "#thirdparty/vulkan"
env_apple_embedded.Prepend(CPPPATH=[vulkan_dir, vulkan_dir + "/include"])

# Driver source files
env_apple_embedded.add_source_files(env.drivers_sources, "*.mm")
env_apple_embedded.add_source_files(env_apple_embedded.drivers_sources, "*.mm")
env_apple_embedded.add_source_files(env_apple_embedded.drivers_sources, "*.swift")
79 changes: 79 additions & 0 deletions drivers/apple_embedded/app.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/**************************************************************************/
/* app.swift */
/**************************************************************************/
/* 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. */
/**************************************************************************/

import SwiftUI
import UIKit

struct GodotSwiftUIViewController: UIViewControllerRepresentable {

func makeUIViewController(context: Context) -> GDTViewController {
let viewController = GDTViewController()
GDTAppDelegateService.viewController = viewController
return viewController
}

func updateUIViewController(_ uiViewController: GDTViewController, context: Context) {
// NOOP
}

}

@main
struct SwiftUIApp: App {
@UIApplicationDelegateAdaptor(GDTApplicationDelegate.self) var appDelegate
@Environment(\.scenePhase) private var scenePhase

var body: some Scene {
WindowGroup {
GodotSwiftUIViewController()
.ignoresSafeArea()
// UIViewControllerRepresentable does not call viewWillDisappear() nor viewDidDisappear() when
// backgrounding the app, or closing the app's main window, update the renderer here.
.onChange(of: scenePhase) { phase in
// For some reason UIViewControllerRepresentable is not calling viewWillDisappear()
// nor viewDidDisappear when closing the app's main window, call it here so we
// stop the renderer.
switch phase {
case .active:
print("GodotSwiftUIViewController scene active")
GDTAppDelegateService.viewController?.godotView.startRendering()
case .inactive:
print("GodotSwiftUIViewController scene inactive")
GDTAppDelegateService.viewController?.godotView.stopRendering()
case .background:
print("GodotSwiftUIViewController scene backgrounded")
GDTAppDelegateService.viewController?.godotView.stopRendering()
@unknown default:
print("unknown default")
}
}
}
}
}
3 changes: 1 addition & 2 deletions drivers/apple_embedded/app_delegate_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@

@interface GDTAppDelegateService : NSObject <UIApplicationDelegate>

@property(strong, nonatomic) UIWindow *window;
@property(strong, class, readonly, nonatomic) GDTViewController *viewController;
@property(strong, class, nonatomic) GDTViewController *viewController;

@end
38 changes: 15 additions & 23 deletions drivers/apple_embedded/app_delegate_service.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@
#import "app_delegate_service.h"

#import "godot_view_apple_embedded.h"
#import "godot_view_controller.h"
#import "os_apple_embedded.h"
#import "view_controller.h"

#include "core/config/project_settings.h"
#import "drivers/coreaudio/audio_driver_coreaudio.h"
Expand All @@ -41,10 +41,8 @@
#import <AVFoundation/AVFoundation.h>
#import <AudioToolbox/AudioServices.h>

#define kRenderingFrequency 60

extern int gargc;
extern char **gargv;
int gargc;
char **gargv;

extern int apple_embedded_main(int, char **);
extern void apple_embedded_finish();
Expand All @@ -66,18 +64,23 @@ + (GDTViewController *)viewController {
return mainViewController;
}

+ (void)setViewController:(GDTViewController *)viewController {
mainViewController = viewController;
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// TODO: might be required to make an early return, so app wouldn't crash because of timeout.
// TODO: logo screen is not displayed while shaders are compiling
// DummyViewController(Splash/LoadingViewController) -> setup -> GodotViewController

#if !defined(VISIONOS_ENABLED)
// Create a full-screen window
CGRect windowBounds = [[UIScreen mainScreen] bounds];
self.window = [[UIWindow alloc] initWithFrame:windowBounds];
#else
self.window = [[UIWindow alloc] init];
#endif
// Fetch the command-line arguments from NSProcessInfo
NSArray *arguments = [[NSProcessInfo processInfo] arguments];
gargc = (int)[arguments count];
gargv = (char **)malloc(sizeof(char *) * gargc);
for (int i = 0; i < gargc; i++) {
NSString *arg = arguments[i];
gargv[i] = strdup([arg UTF8String]);
}

int err = apple_embedded_main(gargc, gargv);

Expand All @@ -87,23 +90,12 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
return NO;
}

GDTViewController *viewController = [[GDTViewController alloc] init];
viewController.godotView.useCADisplayLink = bool(GLOBAL_DEF("display.iOS/use_cadisplaylink", true)) ? YES : NO;
viewController.godotView.renderingInterval = 1.0 / kRenderingFrequency;

self.window.rootViewController = viewController;

// Show the window
[self.window makeKeyAndVisible];

[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(onAudioInterruption:)
name:AVAudioSessionInterruptionNotification
object:[AVAudioSession sharedInstance]];

mainViewController = viewController;

int sessionCategorySetting = GLOBAL_GET("audio/general/ios/session_category");

// Initialize with default Ambient category.
Expand Down
2 changes: 1 addition & 1 deletion drivers/apple_embedded/apple_embedded.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
#import "apple_embedded.h"

#import "app_delegate_service.h"
#import "view_controller.h"
#import "godot_view_controller.h"

#import <CoreHaptics/CoreHaptics.h>
#import <UIKit/UIKit.h>
Expand Down
36 changes: 36 additions & 0 deletions drivers/apple_embedded/bridging_header_apple_embedded.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/**************************************************************************/
/* bridging_header_apple_embedded.h */
/**************************************************************************/
/* 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. */
/**************************************************************************/

#pragma once

#import "app_delegate_service.h"
#import "godot_app_delegate.h"
#import "godot_view_apple_embedded.h"
#import "godot_view_controller.h"
9 changes: 4 additions & 5 deletions drivers/apple_embedded/display_server_apple_embedded.mm
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@

#import "app_delegate_service.h"
#import "apple_embedded.h"
#import "godot_keyboard_input_view.h"
#import "godot_view_apple_embedded.h"
#import "godot_view_controller.h"
#import "key_mapping_apple_embedded.h"
#import "keyboard_input_view.h"
#import "os_apple_embedded.h"
#import "tts_apple_embedded.h"
#import "view_controller.h"

#include "core/config/project_settings.h"
#include "core/io/file_access_pack.h"
Expand Down Expand Up @@ -612,9 +612,8 @@
}

Size2i DisplayServerAppleEmbedded::window_get_size(WindowID p_window) const {
id<UIApplicationDelegate> appDelegate = [[UIApplication sharedApplication] delegate];
CGRect windowBounds = appDelegate.window.bounds;
return Size2i(windowBounds.size.width, windowBounds.size.height) * screen_get_max_scale();
CGRect viewBounds = GDTAppDelegateService.viewController.view.bounds;
return Size2i(viewBounds.size.width, viewBounds.size.height) * screen_get_max_scale();
}

Size2i DisplayServerAppleEmbedded::window_get_size_with_decorations(WindowID p_window) const {
Expand Down
6 changes: 6 additions & 0 deletions drivers/apple_embedded/godot_app_delegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#import "godot_app_delegate.h"

#import "app_delegate_service.h"
#include "core/typedefs.h"

@implementation GDTApplicationDelegate

Expand Down Expand Up @@ -120,6 +121,9 @@ - (void)application:(UIApplication *)application didDiscardSceneSessions:(NSSet<

// MARK: Life-Cycle

// UIApplication lifecycle has become deprecated in favor of UIScene lifecycle
GODOT_CLANG_WARNING_PUSH_AND_IGNORE("-Wdeprecated-declarations")

- (void)applicationDidBecomeActive:(UIApplication *)application {
for (GDTAppDelegateServiceProtocol *service in services) {
if (![service respondsToSelector:_cmd]) {
Expand Down Expand Up @@ -461,3 +465,5 @@ - (UIInterfaceOrientationMask)application:(UIApplication *)application supported
*/

@end

GODOT_CLANG_WARNING_POP
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**************************************************************************/
/* keyboard_input_view.h */
/* godot_keyboard_input_view.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**************************************************************************/
/* keyboard_input_view.mm */
/* godot_keyboard_input_view.mm */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
Expand Down Expand Up @@ -28,7 +28,7 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#import "keyboard_input_view.h"
#import "godot_keyboard_input_view.h"

#import "display_server_apple_embedded.h"
#import "os_apple_embedded.h"
Expand Down
4 changes: 2 additions & 2 deletions drivers/apple_embedded/godot_view_apple_embedded.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,16 +55,16 @@ class String;
@property(strong, readonly, nonatomic) CALayer<GDTDisplayLayer> *renderingLayer;
@property(assign, readonly, nonatomic) BOOL canRender;

@property(assign, nonatomic) NSTimeInterval renderingInterval;
@property(assign, nonatomic) float preferredFrameRate;

// Can be extended by subclasses
- (void)godot_commonInit;

// Implemented in subclasses
- (CALayer<GDTDisplayLayer> *)initializeRenderingForDriver:(NSString *)driverName;

- (void)stopRendering;
- (void)startRendering;
- (void)stopRendering;

@end

Expand Down
Loading
Loading