Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4.0] [iOS] Switch to ARC. Refactoring and cleanup. #42503

Merged
merged 2 commits into from
Oct 2, 2020
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
4 changes: 2 additions & 2 deletions misc/dist/ios_xcode/godot_ios.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@
CONFIGURATION_BUILD_DIR = "$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)";
DEVELOPMENT_TEAM = $team_id;
INFOPLIST_FILE = "$binary/$binary-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down Expand Up @@ -416,7 +416,7 @@
CONFIGURATION_BUILD_DIR = "$(BUILD_DIR)/$(CONFIGURATION)$(EFFECTIVE_PLATFORM_NAME)";
DEVELOPMENT_TEAM = $team_id;
INFOPLIST_FILE = "$binary/$binary-Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
IPHONEOS_DEPLOYMENT_TARGET = 11.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
13 changes: 11 additions & 2 deletions modules/arkit/arkit_interface.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@
// forward declaration for some needed objects
class ARKitShader;

#ifdef __OBJC__

typedef ARAnchor GodotARAnchor;

#else

typedef void GodotARAnchor;
#endif

class ARKitInterface : public XRInterface {
GDCLASS(ARKitInterface, XRInterface);

Expand Down Expand Up @@ -115,8 +124,8 @@ class ARKitInterface : public XRInterface {
virtual void process() override;

// called by delegate (void * because C++ and Obj-C don't always mix, should really change all platform/iphone/*.cpp files to .mm)
void _add_or_update_anchor(void *p_anchor);
void _remove_anchor(void *p_anchor);
void _add_or_update_anchor(GodotARAnchor *p_anchor);
void _remove_anchor(GodotARAnchor *p_anchor);

ARKitInterface();
~ARKitInterface();
Expand Down
12 changes: 5 additions & 7 deletions modules/arkit/arkit_interface.mm
Original file line number Diff line number Diff line change
Expand Up @@ -306,12 +306,10 @@
remove_all_anchors();

if (@available(iOS 11.0, *)) {
[ar_session release];
ar_session = NULL;
ar_session = nil;
}
[ar_delegate release];

ar_delegate = NULL;
ar_delegate = nil;
initialized = false;
session_was_started = false;
}
Expand Down Expand Up @@ -687,7 +685,7 @@
}
}

void ARKitInterface::_add_or_update_anchor(void *p_anchor) {
void ARKitInterface::_add_or_update_anchor(GodotARAnchor *p_anchor) {
// _THREAD_SAFE_METHOD_

if (@available(iOS 11.0, *)) {
Expand Down Expand Up @@ -749,7 +747,7 @@
}
}

void ARKitInterface::_remove_anchor(void *p_anchor) {
void ARKitInterface::_remove_anchor(GodotARAnchor *p_anchor) {
// _THREAD_SAFE_METHOD_

if (@available(iOS 11.0, *)) {
Expand All @@ -768,7 +766,7 @@
plane_detection_is_enabled = false;
light_estimation_is_enabled = false;
if (@available(iOS 11.0, *)) {
ar_session = NULL;
ar_session = nil;
}
z_near = 0.01;
z_far = 1000.0;
Expand Down
24 changes: 6 additions & 18 deletions modules/camera/camera_ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -124,18 +124,12 @@ - (void)cleanup {
if (output) {
[self removeOutput:output];
[output setSampleBufferDelegate:nil queue:NULL];
[output release];
output = nil;
}

[self commitConfiguration];
}

- (void)dealloc {
// bye bye
[super dealloc];
}

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {
// This gets called every time our camera has a new image for us to process.
// May need to investigate in a way to throttle this if we get more images then we're rendering frames..
Expand Down Expand Up @@ -272,7 +266,6 @@ - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CM

void CameraFeedIOS::set_device(AVCaptureDevice *p_device) {
device = p_device;
[device retain];

// get some info
NSString *device_name = p_device.localizedName;
Expand All @@ -286,14 +279,12 @@ - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CM
};

CameraFeedIOS::~CameraFeedIOS() {
if (capture_session != NULL) {
[capture_session release];
capture_session = NULL;
if (capture_session) {
capture_session = nil;
};

if (device != NULL) {
[device release];
device = NULL;
if (device) {
device = nil;
};
};

Expand All @@ -312,8 +303,7 @@ - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CM
// end camera capture if we have one
if (capture_session) {
[capture_session cleanup];
[capture_session release];
capture_session = NULL;
capture_session = nil;
};
};

Expand Down Expand Up @@ -347,8 +337,6 @@ - (void)dealloc {
// remove notifications
[[NSNotificationCenter defaultCenter] removeObserver:self name:AVCaptureDeviceWasConnectedNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:AVCaptureDeviceWasDisconnectedNotification object:nil];

[super dealloc];
}

@end
Expand Down Expand Up @@ -453,5 +441,5 @@ - (void)dealloc {
};

CameraIOS::~CameraIOS() {
[device_notifications release];
device_notifications = nil;
};
3 changes: 1 addition & 2 deletions modules/mono/mono_gd/support/ios_support.mm
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,7 @@ GD_PINVOKE_EXPORT void xamarin_log(const uint16_t *p_unicode_message) {
NSTimeZone *tz = nil;
if (p_name) {
NSString *n = [[NSString alloc] initWithUTF8String:p_name];
tz = [[[NSTimeZone alloc] initWithName:n] autorelease];
[n release];
tz = [[NSTimeZone alloc] initWithName:n];
} else {
tz = [NSTimeZone localTimeZone];
}
Expand Down
2 changes: 2 additions & 0 deletions platform/iphone/SCsub
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ iphone_lib = [
"display_layer.mm",
"godot_view_renderer.mm",
"godot_view_gesture_recognizer.mm",
"device_metrics.m",
"native_video_view.m",
]

env_ios = env.Clone()
Expand Down
3 changes: 1 addition & 2 deletions platform/iphone/app_delegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
CGRect windowBounds = [[UIScreen mainScreen] bounds];

// Create a full-screen window
self.window = [[[UIWindow alloc] initWithFrame:windowBounds] autorelease];
self.window = [[UIWindow alloc] initWithFrame:windowBounds];

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
Expand Down Expand Up @@ -140,7 +140,6 @@ - (void)applicationDidBecomeActive:(UIApplication *)application {

- (void)dealloc {
self.window = nil;
[super dealloc];
}

@end
4 changes: 2 additions & 2 deletions platform/iphone/detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def configure(env):
detect_darwin_sdk_path("iphone", env)
env.Append(
CCFLAGS=(
"-fno-objc-arc -arch armv7 -fmessage-length=0 -fno-strict-aliasing"
"-fobjc-arc -arch armv7 -fmessage-length=0 -fno-strict-aliasing"
" -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits"
" -fpascal-strings -fblocks -isysroot $IPHONESDK -fvisibility=hidden -mthumb"
' "-DIBOutlet=__attribute__((iboutlet))"'
Expand All @@ -141,7 +141,7 @@ def configure(env):
detect_darwin_sdk_path("iphone", env)
env.Append(
CCFLAGS=(
"-fno-objc-arc -arch arm64 -fmessage-length=0 -fno-strict-aliasing"
"-fobjc-arc -arch arm64 -fmessage-length=0 -fno-strict-aliasing"
" -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits"
" -fpascal-strings -fblocks -fvisibility=hidden -MMD -MT dependencies -miphoneos-version-min=11.0"
" -isysroot $IPHONESDK".split()
Expand Down
37 changes: 37 additions & 0 deletions platform/iphone/device_metrics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*************************************************************************/
/* device_metrics.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/*************************************************************************/
/* Copyright (c) 2007-2020 Juan Linietsky, Ariel Manzur. */
/* Copyright (c) 2014-2020 Godot Engine contributors (cf. AUTHORS.md). */
/* */
/* 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 <Foundation/Foundation.h>

@interface GodotDeviceMetrics : NSObject

@property(nonatomic, class, readonly, strong) NSDictionary<NSArray *, NSNumber *> *dpiList;

@end
Loading