Skip to content

Commit

Permalink
Merge branch 'bugfix/emuThreeOptionsAndScreen' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeMatt committed Jan 8, 2025
2 parents 03bc2f9 + ba49285 commit e3171ce
Show file tree
Hide file tree
Showing 52 changed files with 352 additions and 322 deletions.
2 changes: 2 additions & 0 deletions Cores/emuThree/PVEmuThreeCore/Core/PVEmuThreeCoreBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ typedef enum PV3DSButton: NSInteger PV3DSButton;
int8_t cpuOClock;
BOOL enableJIT;
BOOL useNew3DS;
BOOL enableLogging;
BOOL asyncShader;
BOOL asyncPresent;
int8_t shaderType;
Expand All @@ -55,6 +56,7 @@ typedef enum PV3DSButton: NSInteger PV3DSButton;
@property (nonatomic, assign) bool enableHLE;
@property (nonatomic, assign) int8_t cpuOClock;
@property (nonatomic, assign) bool enableJIT;
@property (nonatomic, assign) bool enableLogging;
@property (nonatomic, assign) bool useNew3DS;
@property (nonatomic, assign) bool asyncShader;
@property (nonatomic, assign) bool asyncPresent;
Expand Down
1 change: 1 addition & 0 deletions Cores/emuThree/PVEmuThreeCore/Core/PVEmuThreeCoreBridge.mm
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ - (void)setOptionValues {

[[NSUserDefaults standardUserDefaults] setBool:self.stretchAudio forKey:@"stretch_audio"];
[[NSUserDefaults standardUserDefaults] setBool:self.enableJIT forKey:@"use_cpu_jit"];
[[NSUserDefaults standardUserDefaults] setBool:self.enableLogging forKey:@"enable_logging"];
[[NSUserDefaults standardUserDefaults] setBool:self.useNew3DS forKey:@"is_new_3ds"];
[[NSUserDefaults standardUserDefaults] setBool:self.enableVSync forKey:@"use_vsync_new"];
[[NSUserDefaults standardUserDefaults] setBool:self.enableShaderAccurate forKey:@"shaders_accurate_mul"];
Expand Down
27 changes: 18 additions & 9 deletions Cores/emuThree/PVEmuThreeCore/Core/PVEmuThreeCoreOptions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,14 @@ import PVCoreBridge
defaultValue: false)
}

static var enableLoggingOption: CoreOption {
.bool(.init(
title: "Enable Logging",
description: "May affect performance",
requiresRestart: true),
defaultValue: false)
}

static var enableNew3DSOption: CoreOption {
.bool(.init(
title: "Enable New 3DS",
Expand Down Expand Up @@ -248,8 +256,8 @@ import PVCoreBridge
public static var options: [CoreOption] {
var options = [CoreOption]()
let coreOptions: [CoreOption] = [
resolutionOption, enableHLEOption, cpuClockOption, enableJITOption, enableNew3DSOption, gsOption, enableAsyncShaderOption, enableAsyncPresentOption,
shaderTypeOption, enableShaderAccurateMulOption, enableShaderJITOption, portraitTypeOption, landscapeTypeOption, volumeOption,
resolutionOption, enableHLEOption, cpuClockOption, enableJITOption, enableLoggingOption, enableNew3DSOption, gsOption, enableAsyncShaderOption, enableAsyncPresentOption,
shaderTypeOption, enableVSyncOption, enableShaderAccurateMulOption, enableShaderJITOption, portraitTypeOption, landscapeTypeOption, volumeOption,
stretchAudioOption, swapScreenOption, uprightScreenOption, preloadTextuesOption, stereoRenderOption, threedFactorOption
]
let coreGroup:CoreOption = .group(.init(title: "EmuThreeds Core",
Expand All @@ -266,6 +274,7 @@ extension PVEmuThreeCoreOptions {
@objc public static var enableHLE: Bool { valueForOption(PVEmuThreeCoreOptions.enableHLEOption) }
@objc public static var cpuClock: Int { valueForOption(PVEmuThreeCoreOptions.cpuClockOption) }
@objc public static var enableJIT: Bool { valueForOption(PVEmuThreeCoreOptions.enableJITOption) }
@objc public static var enableLogging: Bool { valueForOption(PVEmuThreeCoreOptions.enableLoggingOption) }
@objc public static var enableNew3DS: Bool { valueForOption(PVEmuThreeCoreOptions.enableNew3DSOption) }
@objc public static var gs: Int { valueForOption(PVEmuThreeCoreOptions.gsOption) }
@objc public static var enableAsyncShader: Bool { valueForOption(PVEmuThreeCoreOptions.enableAsyncShaderOption) }
Expand All @@ -281,27 +290,27 @@ extension PVEmuThreeCoreOptions {

func parseOptions() {
self.gsPreference = NSNumber(value: PVEmuThreeCoreOptions.valueForOption(PVEmuThreeCoreOptions.gsOption).asInt ?? 0).int8Value
self.resFactor = NSNumber(value: PVEmuThreeCoreOptions.valueForOption(PVEmuThreeCoreOptions.resolutionOption).asInt ?? 0).int8Value
self.resFactor = NSNumber(value: PVEmuThreeCoreOptions.valueForOption(PVEmuThreeCoreOptions.resolutionOption).asInt ?? 1).int8Value
self.enableHLE = PVEmuThreeCoreOptions.valueForOption(PVEmuThreeCoreOptions.enableHLEOption).asBool
self.cpuOClock = NSNumber(value:PVEmuThreeCoreOptions.valueForOption(PVEmuThreeCoreOptions.cpuClockOption).asInt ?? 0).int8Value
self.cpuOClock = NSNumber(value:PVEmuThreeCoreOptions.valueForOption(PVEmuThreeCoreOptions.cpuClockOption).asInt ?? 100).int8Value
self.enableJIT = PVEmuThreeCoreOptions.valueForOption(PVEmuThreeCoreOptions.enableJITOption).asBool
self.enableLogging = PVEmuThreeCoreOptions.valueForOption(PVEmuThreeCoreOptions.enableLoggingOption).asBool
self.useNew3DS =
PVEmuThreeCoreOptions.valueForOption(PVEmuThreeCoreOptions.enableNew3DSOption).asBool
self.asyncShader = PVEmuThreeCoreOptions.valueForOption(PVEmuThreeCoreOptions.enableAsyncShaderOption).asBool
self.asyncPresent = PVEmuThreeCoreOptions.valueForOption(PVEmuThreeCoreOptions.enableAsyncPresentOption).asBool
self.shaderType = NSNumber(value:PVEmuThreeCoreOptions.valueForOption(PVEmuThreeCoreOptions.shaderTypeOption).asInt ?? 0).int8Value
self.shaderType = NSNumber(value:PVEmuThreeCoreOptions.valueForOption(PVEmuThreeCoreOptions.shaderTypeOption).asInt ?? 2).int8Value
self.enableVSync = PVEmuThreeCoreOptions.valueForOption(PVEmuThreeCoreOptions.enableVSyncOption).asBool
self.enableShaderAccurate = PVEmuThreeCoreOptions.valueForOption(PVEmuThreeCoreOptions.enableShaderAccurateMulOption).asBool
self.enableShaderJIT = PVEmuThreeCoreOptions.valueForOption(PVEmuThreeCoreOptions.enableShaderJITOption).asBool
self.portraitType = NSNumber(value:PVEmuThreeCoreOptions.valueForOption(PVEmuThreeCoreOptions.portraitTypeOption).asInt ?? 0).int8Value
self.landscapeType = NSNumber(value:PVEmuThreeCoreOptions.valueForOption(PVEmuThreeCoreOptions.landscapeTypeOption).asInt ?? 0).int8Value
self.portraitType = NSNumber(value:PVEmuThreeCoreOptions.valueForOption(PVEmuThreeCoreOptions.portraitTypeOption).asInt ?? 5).int8Value
self.landscapeType = NSNumber(value:PVEmuThreeCoreOptions.valueForOption(PVEmuThreeCoreOptions.landscapeTypeOption).asInt ?? 5).int8Value
self.stretchAudio = PVEmuThreeCoreOptions.valueForOption(PVEmuThreeCoreOptions.stretchAudioOption).asBool
self.volume = NSNumber(value:PVEmuThreeCoreOptions.valueForOption(PVEmuThreeCoreOptions.volumeOption).asInt ?? 100).int8Value
self.swapScreen = PVEmuThreeCoreOptions.valueForOption(PVEmuThreeCoreOptions.swapScreenOption).asBool
self.uprightScreen = PVEmuThreeCoreOptions.valueForOption(PVEmuThreeCoreOptions.uprightScreenOption).asBool
self.preloadTextures = PVEmuThreeCoreOptions.valueForOption(PVEmuThreeCoreOptions.preloadTextuesOption).asBool
self.stereoRender = NSNumber(value:PVEmuThreeCoreOptions.valueForOption(PVEmuThreeCoreOptions.stereoRenderOption).asInt ?? 0).int8Value
self.threedFactor = NSNumber(value:PVEmuThreeCoreOptions.valueForOption(PVEmuThreeCoreOptions.threedFactorOption).asInt ?? 0).int8Value
self.cpuOClock = self.cpuOClock < 100 ? 100 : self.cpuOClock
self.threedFactor = NSNumber(value:PVEmuThreeCoreOptions.valueForOption(PVEmuThreeCoreOptions.threedFactorOption).asInt ?? 100).int8Value
}
}
85 changes: 9 additions & 76 deletions Cores/emuThree/PVEmuThreeCore/emuThree/CitraWrapper.mm
Original file line number Diff line number Diff line change
Expand Up @@ -395,31 +395,14 @@ -(void) start {
-(void) handleTouchEvent:(NSArray*)touches {
if (!CitraWrapper.sharedInstance.isRunning)
return;

/// Get safe area insets from main window
UIEdgeInsets safeAreaInsets = UIApplication.sharedApplication.windows.firstObject.safeAreaInsets;

for (int i = 0; i < touches.count; i++) {
UITouch *touch = [touches objectAtIndex:i];
CGPoint point = [touch locationInView:[touch view]];
bool touchReleased = (touch.phase == UITouchPhaseEnded || touch.phase == UITouchPhaseCancelled);
bool touchBegan = touch.phase == UITouchPhaseBegan;
bool touchMoved = touch.phase == UITouchPhaseMoved;

/// Calculate available screen space (excluding safe area)
CGFloat availableHeight = [touch view].window.bounds.size.height - (safeAreaInsets.top + safeAreaInsets.bottom);
CGFloat availableWidth = [touch view].window.bounds.size.width - (safeAreaInsets.left + safeAreaInsets.right);

float heightRatio = emu_window->framebuffer_layout.height / (availableHeight * [[UIScreen mainScreen] nativeScale]);
float widthRatio = emu_window->framebuffer_layout.width / (availableWidth * [[UIScreen mainScreen] nativeScale]);

/// Adjust point relative to safe area
if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait) {
point.y -= safeAreaInsets.top;
} else {
point.x -= safeAreaInsets.left;
}

UITouch *touch = [touches objectAtIndex:i];
CGPoint point = [touch locationInView:[touch view]];
bool touchReleased=(touch.phase == UITouchPhaseEnded || touch.phase == UITouchPhaseCancelled);
bool touchBegan=touch.phase == UITouchPhaseBegan;
bool touchMoved=touch.phase == UITouchPhaseMoved;
float heightRatio=emu_window->framebuffer_layout.height / ([touch view].window.bounds.size.height * [[UIScreen mainScreen] nativeScale]);
float widthRatio=emu_window->framebuffer_layout.width / ([touch view].window.bounds.size.width * [[UIScreen mainScreen] nativeScale]);
if (touchBegan)
emu_window->OnTouchEvent((point.x) * [[UIScreen mainScreen] nativeScale] * widthRatio, ((point.y) * [[UIScreen mainScreen] nativeScale] * heightRatio), true);
if (touchMoved)
Expand All @@ -432,45 +415,13 @@ -(void) handleTouchEvent:(NSArray*)touches {
-(void) touchesBegan:(CGPoint)point {
if (!CitraWrapper.sharedInstance.isRunning)
return;

/// Get safe area insets and calculate ratios
UIEdgeInsets safeAreaInsets = UIApplication.sharedApplication.windows.firstObject.safeAreaInsets;
CGFloat availableHeight = UIApplication.sharedApplication.windows.firstObject.bounds.size.height - (safeAreaInsets.top + safeAreaInsets.bottom);
CGFloat availableWidth = UIApplication.sharedApplication.windows.firstObject.bounds.size.width - (safeAreaInsets.left + safeAreaInsets.right);

if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait) {
point.y -= safeAreaInsets.top;
} else {
point.x -= safeAreaInsets.left;
}

float scale = [[UIScreen mainScreen] nativeScale];
float heightRatio = emu_window->framebuffer_layout.height / (availableHeight * scale);
float widthRatio = emu_window->framebuffer_layout.width / (availableWidth * scale);

emu_window->OnTouchEvent((point.x * scale * widthRatio) + 0.5, (point.y * scale * heightRatio) + 0.5, true);
emu_window->OnTouchEvent((point.x * [[UIScreen mainScreen] nativeScale]) + 0.5, (point.y * [[UIScreen mainScreen] nativeScale]) + 0.5, true);
}

-(void) touchesMoved:(CGPoint)point {
if (!CitraWrapper.sharedInstance.isRunning)
return;

/// Get safe area insets and calculate ratios
UIEdgeInsets safeAreaInsets = UIApplication.sharedApplication.windows.firstObject.safeAreaInsets;
CGFloat availableHeight = UIApplication.sharedApplication.windows.firstObject.bounds.size.height - (safeAreaInsets.top + safeAreaInsets.bottom);
CGFloat availableWidth = UIApplication.sharedApplication.windows.firstObject.bounds.size.width - (safeAreaInsets.left + safeAreaInsets.right);

if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait) {
point.y -= safeAreaInsets.top;
} else {
point.x -= safeAreaInsets.left;
}

float scale = [[UIScreen mainScreen] nativeScale];
float heightRatio = emu_window->framebuffer_layout.height / (availableHeight * scale);
float widthRatio = emu_window->framebuffer_layout.width / (availableWidth * scale);

emu_window->OnTouchMoved((point.x * scale * widthRatio) + 0.5, (point.y * scale * heightRatio) + 0.5);
emu_window->OnTouchMoved((point.x * [[UIScreen mainScreen] nativeScale]) + 0.5, (point.y * [[UIScreen mainScreen] nativeScale]) + 0.5);
}

-(void) touchesEnded {
Expand All @@ -486,34 +437,16 @@ -(void) refreshSize:(CAMetalLayer *)surface {

-(void) orientationChanged:(UIDeviceOrientation)orientation with:(CAMetalLayer *)surface {
if (CitraWrapper.sharedInstance.isRunning) {
/// Get safe area insets from main window
UIEdgeInsets safeAreaInsets = UIApplication.sharedApplication.windows.firstObject.safeAreaInsets;

if (orientation == UIDeviceOrientationPortrait) {
NSInteger layoutOptionInteger = [[NSNumber numberWithInteger:[[NSUserDefaults standardUserDefaults] integerForKey:@"portrait_layout_option"]] unsignedIntValue];
Settings::values.layout_option.SetValue(layoutOptionInteger == 0 ? Settings::LayoutOption::MobilePortrait : (Settings::LayoutOption)layoutOptionInteger);

/// Adjust surface frame for portrait safe area
CGRect bounds = surface.bounds;
bounds.origin.y += safeAreaInsets.top;
bounds.size.height -= (safeAreaInsets.top + safeAreaInsets.bottom);
surface.frame = bounds;

} else {
NSInteger layoutOptionInteger = [[NSNumber numberWithInteger:[[NSUserDefaults standardUserDefaults] integerForKey:@"landscape_layout_option"]] unsignedIntValue];
Settings::values.layout_option.SetValue(layoutOptionInteger == 0 ? Settings::LayoutOption::MobilePortrait : (Settings::LayoutOption)layoutOptionInteger);

/// Adjust surface frame for landscape safe area
CGRect bounds = surface.bounds;
bounds.origin.x += safeAreaInsets.left;
bounds.size.width -= (safeAreaInsets.left + safeAreaInsets.right);
surface.frame = bounds;
}

emu_window->OrientationChanged(orientation == UIDeviceOrientationPortrait, (__bridge CA::MetalLayer*)surface);
}
}

-(void) SaveState:(NSString *) savePath {
std::string path=std::string([savePath UTF8String]);
Core::SaveState(path, _title_id);
Expand Down
Loading

0 comments on commit e3171ce

Please sign in to comment.