Skip to content
Open
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
28 changes: 28 additions & 0 deletions COPYRIGHT.txt
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,34 @@ Comment: ProcessPhoenix
Copyright: 2015, Jake Wharton
License: Apache-2.0

Files: drivers/apple_embedded/*
editor/export/editor_export_platform_apple_embedded.*
Comment: Apple embedded platform
Copyright: 2025, Apple Inc.
2014-present, Godot Engine contributors
2007-2014, Juan Linietsky, Ariel Manzur
License: Expat

Files: metal/metal_objects.*
metal/rendering_context_driver.*
metal/rendering_device_driver.*
platform/ios/*
servers/rendering/renderer_rd/forward_mobile/render_forward_mobile.*
servers/rendering/rendering_device.*
servers/rendering/rendering_device_driver.*
servers/rendering/rendering_device_graph.*
Comment: Other files modified by Apple to improve platform support
Copyright: 2025, Apple Inc.
2014-present, Godot Engine contributors
2007-2014, Juan Linietsky, Ariel Manzur
License: Expat

Files: platform/visionos/*
modules/visionos_xr/*
Comment: visionOS platform
Copyright: 2025, Apple Inc.
License: Expat

Files: scene/animation/easing_equations.h
Comment: Robert Penner's Easing Functions
Copyright: 2001, Robert Penner
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 @@ -30,7 +30,7 @@

#import "apple_embedded.h"

#import "app_delegate_service.h"
#import "godot_app_delegate_service_apple_embedded.h"
#import "godot_view_controller.h"

#import <CoreHaptics/CoreHaptics.h>
Expand Down
3 changes: 1 addition & 2 deletions drivers/apple_embedded/bridging_header_apple_embedded.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

#pragma once

#import "app_delegate_service.h"
#import "godot_app_delegate.h"
#import "godot_app_delegate_service_apple_embedded.h"
#import "godot_view_apple_embedded.h"
#import "godot_view_controller.h"
2 changes: 1 addition & 1 deletion drivers/apple_embedded/display_server_apple_embedded.mm
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@

#import "display_server_apple_embedded.h"

#import "app_delegate_service.h"
#import "apple_embedded.h"
#import "godot_app_delegate_service_apple_embedded.h"
#import "godot_keyboard_input_view.h"
#import "godot_view_apple_embedded.h"
#import "godot_view_controller.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**************************************************************************/
/* godot_app_delegate.h */
/* godot_app_delegate_apple_embedded.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
Expand Down Expand Up @@ -34,7 +34,7 @@

typedef NSObject<UIApplicationDelegate> GDTAppDelegateServiceProtocol;

@interface GDTApplicationDelegate : NSObject <UIApplicationDelegate>
@interface GDTAppDelegate : NSObject <UIApplicationDelegate>

@property(class, readonly, strong) NSArray<GDTAppDelegateServiceProtocol *> *services;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**************************************************************************/
/* godot_app_delegate.mm */
/* godot_app_delegate_apple_embedded.mm */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
Expand Down Expand Up @@ -28,12 +28,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/

#import "godot_app_delegate.h"
#import "godot_app_delegate_apple_embedded.h"

#import "godot_app_delegate_service_apple_embedded.h"

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

@implementation GDTApplicationDelegate
@implementation GDTAppDelegate

static NSMutableArray<GDTAppDelegateServiceProtocol *> *services = nil;

Expand All @@ -43,7 +44,7 @@ @implementation GDTApplicationDelegate

+ (void)load {
services = [NSMutableArray new];
[services addObject:[GDTAppDelegateService new]];
// Add the specific GDTAppDelegateService subclass in each inheriting platform
}

+ (void)addService:(GDTAppDelegateServiceProtocol *)service {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**************************************************************************/
/* app_delegate_service.h */
/* godot_app_delegate_service_apple_embedded.h */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
Expand Down Expand Up @@ -36,6 +36,6 @@

@interface GDTAppDelegateService : NSObject <UIApplicationDelegate>

@property(strong, class, nonatomic) GDTViewController *viewController;
@property(weak, class, nonatomic, nullable) GDTViewController *viewController;

@end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**************************************************************************/
/* app_delegate_service.mm */
/* godot_app_delegate_service_apple_embedded.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 "app_delegate_service.h"
#import "godot_app_delegate_service_apple_embedded.h"

#import "godot_view_apple_embedded.h"
#import "godot_view_controller.h"
Expand Down Expand Up @@ -59,14 +59,14 @@ @implementation GDTAppDelegateService
SESSION_CATEGORY_SOLO_AMBIENT
};

static GDTViewController *mainViewController = nil;
static __weak GDTViewController *_viewController = nil;

+ (GDTViewController *)viewController {
return mainViewController;
return _viewController;
}

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

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
Expand Down
49 changes: 49 additions & 0 deletions drivers/apple_embedded/godot_renderer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**************************************************************************/
/* godot_renderer.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 <Foundation/Foundation.h>

inline void safeDispatchSyncToMain(void (^block)(void)) {
if ([NSThread isMainThread]) {
block();
} else {
dispatch_sync(dispatch_get_main_queue(), block);
}
}

@interface GDTRenderer : NSObject

@property(assign, readonly, nonatomic) BOOL hasFinishedSetup;

- (BOOL)setUp;

@end
108 changes: 108 additions & 0 deletions drivers/apple_embedded/godot_renderer.mm
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
/**************************************************************************/
/* godot_renderer.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. */
/**************************************************************************/

#import "godot_renderer.h"

#import "display_server_apple_embedded.h"
#import "os_apple_embedded.h"

#include "core/config/project_settings.h"
#include "main/main.h"

@interface GDTRenderer ()

@property(assign, nonatomic) BOOL hasCalledProjectDataSetUp;
@property(assign, nonatomic) BOOL hasStartedMain;
@property(assign, nonatomic) BOOL hasFinishedSetUp;

@end

@implementation GDTRenderer

- (BOOL)setUp {
if (self.hasFinishedSetUp) {
return NO;
}

if (!OS::get_singleton()) {
exit(0);
}

if (!self.hasCalledProjectDataSetUp) {
[self setUpProjectData];
}

if (!self.hasStartedMain) {
[self startMain];
}

self.hasFinishedSetUp = YES;

return NO;
}

- (void)setUpProjectData {
self.hasCalledProjectDataSetUp = YES;
safeDispatchSyncToMain(^{
Main::setup2();

// this might be necessary before here
NSDictionary *dict = [[NSBundle mainBundle] infoDictionary];
for (NSString *key in dict) {
NSObject *value = [dict objectForKey:key];
String ukey = String::utf8([key UTF8String]);

// we need a NSObject to Variant conversor

if ([value isKindOfClass:[NSString class]]) {
NSString *str = (NSString *)value;
String uval = String::utf8([str UTF8String]);

ProjectSettings::get_singleton()->set("Info.plist/" + ukey, uval);

} else if ([value isKindOfClass:[NSNumber class]]) {
NSNumber *n = (NSNumber *)value;
double dval = [n doubleValue];

ProjectSettings::get_singleton()->set("Info.plist/" + ukey, dval);
}
// do stuff
}
});
}

- (void)startMain {
self.hasStartedMain = YES;
safeDispatchSyncToMain(^{
OS_AppleEmbedded::get_singleton()->start();
});
}

@end
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**************************************************************************/
/* app.swift */
/* godot_swiftui_view_controller.swift */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
Expand Down Expand Up @@ -45,35 +45,42 @@ struct GodotSwiftUIViewController: UIViewControllerRepresentable {

}

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

// UIViewControllerRepresentable does not call viewWillDisappear() nor viewDidDisappear() when
// backgrounding the app, or closing the app's main window, update the renderer here.
private func updateRenderer(with newPhase: ScenePhase) -> Void {
switch newPhase {
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")
}
}

var body: some Scene {
WindowGroup {
if #available(iOS 17, *) {
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")
}
.onChange(of: scenePhase) { _, newPhase in
updateRenderer(with: newPhase)
}
} else {
GodotSwiftUIViewController()
.ignoresSafeArea()
.onChange(of: scenePhase) { newPhase in
updateRenderer(with: newPhase)
}
}
}
}
}
Loading