git.y1.nz

SameBoy

Accurate GB/GBC emulator
download: https://git.y1.nz/archives/sameboy.tar.gz
README | Files | Log | Refs | LICENSE

commit 76500ebf15fdbfdb0b28baef2bb98c43926f683a
parent ffc80b2c0d475d1d9dcc18dac12dd65181c6db0d
Author: Lior Halphon <LIJI32@gmail.com>
Date:   Sat, 14 Jan 2023 21:15:25 +0200

Vibration support on legacy devices

Diffstat:
MiOS/GBHapticManager.m14+++++++-------
AiOS/GBHapticManagerLegacy.h5+++++
AiOS/GBHapticManagerLegacy.m27+++++++++++++++++++++++++++
3 files changed, 39 insertions(+), 7 deletions(-)

diff --git a/iOS/GBHapticManager.m b/iOS/GBHapticManager.m @@ -1,4 +1,5 @@ #import "GBHapticManager.h" +#import "GBHapticManagerLegacy.h" #import <CoreHaptics/CoreHaptics.h> @implementation GBHapticManager @@ -25,15 +26,14 @@ { self = [super init]; if (!self) return nil; + if (self.class != [GBHapticManager class]) return self; + if (@available(iOS 13.0, *)) { - _engine = [[CHHapticEngine alloc] initAndReturnError:nil]; - _engine.playsHapticsOnly = true; - _engine.autoShutdownEnabled = true; - } - else { - return nil; + _engine = [[CHHapticEngine alloc] initAndReturnError:nil]; + _engine.playsHapticsOnly = true; + _engine.autoShutdownEnabled = true; } - if (!_engine) return nil; + if (!_engine) return [[GBHapticManagerLegacy alloc] init]; return self; } diff --git a/iOS/GBHapticManagerLegacy.h b/iOS/GBHapticManagerLegacy.h @@ -0,0 +1,5 @@ +#import "GBHapticManager.h" + +@interface GBHapticManagerLegacy : GBHapticManager + +@end diff --git a/iOS/GBHapticManagerLegacy.m b/iOS/GBHapticManagerLegacy.m @@ -0,0 +1,27 @@ +#import "GBHapticManagerLegacy.h" +#import <UIKit/UIKit.h> +#import <AudioToolbox/AudioToolbox.h> + +@implementation GBHapticManagerLegacy + +- (void)doTapHaptic +{ + [[[UIImpactFeedbackGenerator alloc] initWithStyle:UIImpactFeedbackStyleMedium] impactOccurred]; +} + +- (void)setRumbleStrength:(double)rumble +{ + void AudioServicesStopSystemSound(SystemSoundID inSystemSoundID); + void AudioServicesPlaySystemSoundWithVibration(SystemSoundID inSystemSoundID, id arg, NSDictionary* vibratePattern); + if (rumble) { + AudioServicesPlaySystemSoundWithVibration(kSystemSoundID_Vibrate, nil, @{@"Intensity": @(rumble), + @"OffDuration": @0, + @"OnDuration": @100, + @"VibePattern": @[@YES, @1000], + }); + } + else { + AudioServicesStopSystemSound(kSystemSoundID_Vibrate); + } +} +@end

This webpage is intended to be an accessible preview of this repository. To get a fuller picture, clone it and use the git CLI.