Skip to content

Commit

Permalink
Feat: add switch to toggle Metal perf HUD
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhduytran0 committed Jun 21, 2024
1 parent 2752cf5 commit 60e04dc
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
8 changes: 8 additions & 0 deletions Natives/LauncherPreferencesViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions Natives/PLPreferences.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 12 additions & 2 deletions Natives/SurfaceViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 <dlfcn.h>

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

Expand Down Expand Up @@ -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)];

Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 3 additions & 0 deletions Natives/resources/en.lproj/Localizable.strings
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit 60e04dc

Please sign in to comment.