From d17f2f9dee910b63ec56bcb52b5082485050b485 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sat, 2 Jun 2018 13:52:58 -0700 Subject: [PATCH] Plumb multi-controller toggle --- Limelight/Input/ControllerSupport.h | 5 +-- Limelight/Input/ControllerSupport.m | 31 +++++++++++++------ Limelight/Stream/StreamConfiguration.h | 1 + Limelight/Stream/StreamConfiguration.m | 2 +- .../ViewControllers/MainFrameViewController.m | 5 ++- .../StreamFrameViewController.m | 2 +- 6 files changed, 32 insertions(+), 14 deletions(-) diff --git a/Limelight/Input/ControllerSupport.h b/Limelight/Input/ControllerSupport.h index b11cf18..c686eda 100644 --- a/Limelight/Input/ControllerSupport.h +++ b/Limelight/Input/ControllerSupport.h @@ -11,13 +11,14 @@ #if !TARGET_OS_IPHONE #import "Gamepad.h" #endif +#import "StreamConfiguration.h" @class Controller; @class OnScreenControls; @interface ControllerSupport : NSObject --(id) init; +-(id) initWithConfig:(StreamConfiguration*)streamConfig; #if TARGET_OS_IPHONE -(void) initAutoOnScreenControlMode:(OnScreenControls*)osc; @@ -42,7 +43,7 @@ -(void) updateFinished:(Controller*)controller; -+(int) getConnectedGamepadMask; ++(int) getConnectedGamepadMask:(StreamConfiguration*)streamConfig; @property (nonatomic, strong) id connectObserver; @property (nonatomic, strong) id disconnectObserver; diff --git a/Limelight/Input/ControllerSupport.m b/Limelight/Input/ControllerSupport.m index a38c1a2..8acda13 100644 --- a/Limelight/Input/ControllerSupport.m +++ b/Limelight/Input/ControllerSupport.m @@ -38,6 +38,7 @@ bool _oscEnabled; char _controllerNumbers; + bool _multiController; } // UPDATE_BUTTON_FLAG(controller, flag, pressed) @@ -154,7 +155,8 @@ [_controllerStreamLock lock]; @synchronized(controller) { // Player 1 is always present for OSC - LiSendMultiControllerEvent(controller.playerIndex, _controllerNumbers | (_oscEnabled ? 1 : 0), controller.lastButtonFlags, controller.lastLeftTrigger, controller.lastRightTrigger, controller.lastLeftStickX, controller.lastLeftStickY, controller.lastRightStickX, controller.lastRightStickY); + LiSendMultiControllerEvent(_multiController ? controller.playerIndex : 0, + (_multiController ? _controllerNumbers : 1) | (_oscEnabled ? 1 : 0), controller.lastButtonFlags, controller.lastLeftTrigger, controller.lastRightTrigger, controller.lastLeftStickX, controller.lastLeftStickY, controller.lastRightStickX, controller.lastRightStickY); } [_controllerStreamLock unlock]; } @@ -360,15 +362,22 @@ return count; } -+(int) getConnectedGamepadMask { ++(int) getConnectedGamepadMask:(StreamConfiguration*)streamConfig { int mask = 0; - - int i = 0; - for (GCController* controller in [GCController controllers]) { - if ([ControllerSupport isSupportedGamepad:controller]) { - mask |= 1 << i++; + + if (streamConfig.multiController) { + int i = 0; + for (GCController* controller in [GCController controllers]) { + if ([ControllerSupport isSupportedGamepad:controller]) { + mask |= 1 << i++; + } } } + else { + // Some games don't deal with having controller reconnected + // properly so always report controller 1 if not in MC mode + mask = 0x1; + } #if TARGET_OS_IPHONE DataManager* dataMan = [[DataManager alloc] init]; @@ -377,19 +386,21 @@ // Even if no gamepads are present, we will always count one // if OSC is enabled. if (level != OnScreenControlsLevelOff) { - mask |= 1; + mask |= 0x1; } #endif + return mask; } --(id) init +-(id) initWithConfig:(StreamConfiguration*)streamConfig { self = [super init]; _controllerStreamLock = [[NSLock alloc] init]; _controllers = [[NSMutableDictionary alloc] init]; _controllerNumbers = 0; + _multiController = streamConfig.multiController; _player0osc = [[Controller alloc] init]; _player0osc.playerIndex = 0; @@ -404,6 +415,8 @@ #endif Log(LOG_I, @"Number of supported controllers connected: %d", [ControllerSupport getGamepadCount]); + Log(LOG_I, @"Multi-controller: %d", _multiController); + for (GCController* controller in [GCController controllers]) { if ([ControllerSupport isSupportedGamepad:controller]) { [self assignController:controller]; diff --git a/Limelight/Stream/StreamConfiguration.h b/Limelight/Stream/StreamConfiguration.h index 3954980..110ceed 100644 --- a/Limelight/Stream/StreamConfiguration.h +++ b/Limelight/Stream/StreamConfiguration.h @@ -26,5 +26,6 @@ @property int audioChannelCount; @property int audioChannelMask; @property BOOL enableHdr; +@property BOOL multiController; @end diff --git a/Limelight/Stream/StreamConfiguration.m b/Limelight/Stream/StreamConfiguration.m index 4386f61..f9625bb 100644 --- a/Limelight/Stream/StreamConfiguration.m +++ b/Limelight/Stream/StreamConfiguration.m @@ -9,5 +9,5 @@ #import "StreamConfiguration.h" @implementation StreamConfiguration -@synthesize host, appID, width, height, frameRate, bitRate, riKeyId, riKey, gamepadMask, streamingRemotely, appName, optimizeGameSettings, playAudioOnPC, audioChannelMask, audioChannelCount, enableHdr; +@synthesize host, appID, width, height, frameRate, bitRate, riKeyId, riKey, gamepadMask, streamingRemotely, appName, optimizeGameSettings, playAudioOnPC, audioChannelMask, audioChannelCount, enableHdr, multiController; @end diff --git a/Limelight/ViewControllers/MainFrameViewController.m b/Limelight/ViewControllers/MainFrameViewController.m index 9b779bf..f2c284b 100644 --- a/Limelight/ViewControllers/MainFrameViewController.m +++ b/Limelight/ViewControllers/MainFrameViewController.m @@ -432,11 +432,14 @@ static NSMutableSet* hostList; _streamConfig.bitRate = [streamSettings.bitrate intValue]; _streamConfig.height = [streamSettings.height intValue]; _streamConfig.width = [streamSettings.width intValue]; - _streamConfig.gamepadMask = [ControllerSupport getConnectedGamepadMask]; _streamConfig.streamingRemotely = [streamSettings.streamingRemotely intValue]; _streamConfig.optimizeGameSettings = YES; _streamConfig.playAudioOnPC = NO; + // multiController must be set before calling getConnectedGamepadMask + _streamConfig.multiController = YES; + _streamConfig.gamepadMask = [ControllerSupport getConnectedGamepadMask:_streamConfig]; + // TODO: Detect attached surround sound system then address 5.1 TODOs // in Connection.m _streamConfig.audioChannelCount = 2; diff --git a/Limelight/ViewControllers/StreamFrameViewController.m b/Limelight/ViewControllers/StreamFrameViewController.m index 577dbc8..0c230d8 100644 --- a/Limelight/ViewControllers/StreamFrameViewController.m +++ b/Limelight/ViewControllers/StreamFrameViewController.m @@ -41,7 +41,7 @@ self.spinner.center = CGPointMake(self.view.frame.size.width / 2, self.view.frame.size.height / 2 - self.stageLabel.frame.size.height - self.spinner.frame.size.height); [UIApplication sharedApplication].idleTimerDisabled = YES; - _controllerSupport = [[ControllerSupport alloc] init]; + _controllerSupport = [[ControllerSupport alloc] initWithConfig:self.streamConfig]; _streamMan = [[StreamManager alloc] initWithConfig:self.streamConfig renderView:self.view