Jelajahi Sumber

Merge pull request #68190 from ztc0611/3.x-ios-promotion

[3.x] Add ProMotion/High Refresh Rate Support to iOS Exports
Rémi Verschelde 2 tahun lalu
induk
melakukan
92aedd5063

+ 3 - 0
doc/classes/ProjectSettings.xml

@@ -480,6 +480,9 @@
 			The default screen orientation to use on mobile devices.
 			The default screen orientation to use on mobile devices.
 			[b]Note:[/b] When set to a portrait orientation, this project setting does not flip the project resolution's width and height automatically. Instead, you have to set [member display/window/size/width] and [member display/window/size/height] accordingly.
 			[b]Note:[/b] When set to a portrait orientation, this project setting does not flip the project resolution's width and height automatically. Instead, you have to set [member display/window/size/width] and [member display/window/size/height] accordingly.
 		</member>
 		</member>
+		<member name="display/window/ios/allow_high_refresh_rate" type="bool" setter="" getter="" default="true">
+			If [code]true[/code], iOS devices that support high refresh rate/"ProMotion" will be allowed to render at up to 120 frames per second.
+		</member>
 		<member name="display/window/ios/hide_home_indicator" type="bool" setter="" getter="" default="true">
 		<member name="display/window/ios/hide_home_indicator" type="bool" setter="" getter="" default="true">
 			If [code]true[/code], the home indicator is hidden automatically. This only affects iOS devices without a physical home button.
 			If [code]true[/code], the home indicator is hidden automatically. This only affects iOS devices without a physical home button.
 		</member>
 		</member>

+ 1 - 0
main/main.cpp

@@ -1280,6 +1280,7 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
 		OS::get_singleton()->set_delta_smoothing(GLOBAL_GET("application/run/delta_smoothing"));
 		OS::get_singleton()->set_delta_smoothing(GLOBAL_GET("application/run/delta_smoothing"));
 	}
 	}
 
 
+	GLOBAL_DEF("display/window/ios/allow_high_refresh_rate", true);
 	GLOBAL_DEF("display/window/ios/hide_home_indicator", true);
 	GLOBAL_DEF("display/window/ios/hide_home_indicator", true);
 	GLOBAL_DEF("display/window/ios/hide_status_bar", true);
 	GLOBAL_DEF("display/window/ios/hide_status_bar", true);
 	GLOBAL_DEF("display/window/ios/suppress_ui_gesture", true);
 	GLOBAL_DEF("display/window/ios/suppress_ui_gesture", true);

+ 1 - 0
misc/dist/ios_xcode/godot_ios/godot_ios-Info.plist

@@ -58,5 +58,6 @@
 	</array>
 	</array>
 	$additional_plist_content
 	$additional_plist_content
 	$plist_launch_screen_name
 	$plist_launch_screen_name
+	<key>CADisableMinimumFrameDurationOnPhone</key><true/>
 </dict>
 </dict>
 </plist>
 </plist>

+ 6 - 6
platform/iphone/godot_view.mm

@@ -176,16 +176,16 @@ static const int max_touches = 8;
 	if (self.useCADisplayLink) {
 	if (self.useCADisplayLink) {
 		self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(drawView)];
 		self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(drawView)];
 
 
-		// Approximate frame rate
-		// assumes device refreshes at 60 fps
-		int displayFPS = (NSInteger)(1.0 / self.renderingInterval);
-
-		self.displayLink.preferredFramesPerSecond = displayFPS;
+		if (GLOBAL_GET("display/window/ios/allow_high_refresh_rate")) {
+			self.displayLink.preferredFramesPerSecond = 120;
+		} else {
+			self.displayLink.preferredFramesPerSecond = 60;
+		}
 
 
 		// Setup DisplayLink in main thread
 		// Setup DisplayLink in main thread
 		[self.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
 		[self.displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
 	} else {
 	} else {
-		self.animationTimer = [NSTimer scheduledTimerWithTimeInterval:self.renderingInterval target:self selector:@selector(drawView) userInfo:nil repeats:YES];
+		self.animationTimer = [NSTimer scheduledTimerWithTimeInterval:(1.0 / 60) target:self selector:@selector(drawView) userInfo:nil repeats:YES];
 	}
 	}
 }
 }