diff --git a/Natives/LauncherPreferencesViewController.m b/Natives/LauncherPreferencesViewController.m index 311d122d7d..fe4d4ecb82 100644 --- a/Natives/LauncherPreferencesViewController.m +++ b/Natives/LauncherPreferencesViewController.m @@ -183,6 +183,14 @@ - (void)viewDidLoad return whenNotInGame() && (UIScreen.mainScreen.maximumFramesPerSecond > 60); } }, + @{@"key": @"performance_hud", + @"hasDetail": @YES, + @"icon": @"waveform.path.ecg", + @"type": self.typeSwitch, + @"enableCondition": ^BOOL(){ + return [CAMetalLayer instancesRespondToSelector:@selector(developerHUDProperties)]; + } + }, @{@"key": @"fullscreen_airplay", @"hasDetail": @YES, @"icon": @"airplayvideo", diff --git a/Natives/PLPreferences.m b/Natives/PLPreferences.m index f2e715d80a..b7be3d52e9 100644 --- a/Natives/PLPreferences.m +++ b/Natives/PLPreferences.m @@ -21,6 +21,7 @@ + (id)defaultPrefForGlobal:(BOOL)global { @"renderer": @"auto", @"resolution": @(100), @"max_framerate": @YES, + @"performance_hud": @NO, @"fullscreen_airplay": @YES, @"silence_other_audio": @NO, @"silence_with_switch": @NO diff --git a/Natives/SurfaceViewController.m b/Natives/SurfaceViewController.m index 37f204f323..16544587cd 100644 --- a/Natives/SurfaceViewController.m +++ b/Natives/SurfaceViewController.m @@ -19,12 +19,13 @@ #import "SurfaceViewController.h" #import "TrackedTextField.h" #import "UIKit+hook.h" - #import "ios_uikit_bridge.h" #include "glfw_keycodes.h" #include "utils.h" +#include + int memorystatus_control(uint32_t command, int32_t pid, uint32_t flags, void *buffer, size_t buffersize); #define MEMORYSTATUS_CMD_SET_JETSAM_TASK_LIMIT 6 @@ -73,7 +74,9 @@ - (void)viewDidLoad [super viewDidLoad]; isControlModifiable = NO; self.isMacCatalystApp = NSProcessInfo.processInfo.isMacCatalystApp; - + // Load MetalHUD library + dlopen("/usr/lib/libMTLHud.dylib", 0); + self.lightHaptic = [[UIImpactFeedbackGenerator alloc] initWithStyle:(UIImpactFeedbackStyleLight)]; self.mediumHaptic = [[UIImpactFeedbackGenerator alloc] initWithStyle:(UIImpactFeedbackStyleMedium)]; @@ -357,6 +360,13 @@ - (void)updatePreferenceChanges { [self updateAudioSettings]; // Update resolution [self updateSavedResolution]; + // Update performance HUD visibility + if (@available(iOS 16, tvOS 16, *)) { + if ([self.surfaceView.layer isKindOfClass:CAMetalLayer.class]) { + BOOL perfHUDEnabled = getPrefBool(@"video.performance_hud"); + ((CAMetalLayer *)self.surfaceView.layer).developerHUDProperties = perfHUDEnabled ? @{@"mode": @"default"} : nil; + } + } } - (void)updateSavedResolution { diff --git a/Natives/resources/en.lproj/Localizable.strings b/Natives/resources/en.lproj/Localizable.strings index e1c54ba135..4dc4c05593 100644 --- a/Natives/resources/en.lproj/Localizable.strings +++ b/Natives/resources/en.lproj/Localizable.strings @@ -189,6 +189,9 @@ "preference.title.max_framerate" = "Maximum framerate"; "preference.detail.max_framerate" = "Allows you to limit the game framerate to 60FPS on ProMotion displays."; +"preference.title.performance_hud" = "Show Performance HUD"; +"preference.detail.performance_hud" = "When available, show the performance monitoring overlay."; + "preference.title.fullscreen_airplay" = "Fullscreen AirPlay"; "preference.detail.fullscreen_airplay" = "Allows presenting fullscreen game window on the external display rather than mirroring everything on screen."; "preference.title.silence_other_audio" = "Pause audio when game opens";