Plumb multi-controller toggle

This commit is contained in:
Cameron Gutman
2018-06-02 13:52:58 -07:00
parent a28049a58c
commit d17f2f9dee
6 changed files with 32 additions and 14 deletions
+3 -2
View File
@@ -11,13 +11,14 @@
#if !TARGET_OS_IPHONE #if !TARGET_OS_IPHONE
#import "Gamepad.h" #import "Gamepad.h"
#endif #endif
#import "StreamConfiguration.h"
@class Controller; @class Controller;
@class OnScreenControls; @class OnScreenControls;
@interface ControllerSupport : NSObject @interface ControllerSupport : NSObject
-(id) init; -(id) initWithConfig:(StreamConfiguration*)streamConfig;
#if TARGET_OS_IPHONE #if TARGET_OS_IPHONE
-(void) initAutoOnScreenControlMode:(OnScreenControls*)osc; -(void) initAutoOnScreenControlMode:(OnScreenControls*)osc;
@@ -42,7 +43,7 @@
-(void) updateFinished:(Controller*)controller; -(void) updateFinished:(Controller*)controller;
+(int) getConnectedGamepadMask; +(int) getConnectedGamepadMask:(StreamConfiguration*)streamConfig;
@property (nonatomic, strong) id connectObserver; @property (nonatomic, strong) id connectObserver;
@property (nonatomic, strong) id disconnectObserver; @property (nonatomic, strong) id disconnectObserver;
+22 -9
View File
@@ -38,6 +38,7 @@
bool _oscEnabled; bool _oscEnabled;
char _controllerNumbers; char _controllerNumbers;
bool _multiController;
} }
// UPDATE_BUTTON_FLAG(controller, flag, pressed) // UPDATE_BUTTON_FLAG(controller, flag, pressed)
@@ -154,7 +155,8 @@
[_controllerStreamLock lock]; [_controllerStreamLock lock];
@synchronized(controller) { @synchronized(controller) {
// Player 1 is always present for OSC // 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]; [_controllerStreamLock unlock];
} }
@@ -360,15 +362,22 @@
return count; return count;
} }
+(int) getConnectedGamepadMask { +(int) getConnectedGamepadMask:(StreamConfiguration*)streamConfig {
int mask = 0; int mask = 0;
int i = 0; if (streamConfig.multiController) {
for (GCController* controller in [GCController controllers]) { int i = 0;
if ([ControllerSupport isSupportedGamepad:controller]) { for (GCController* controller in [GCController controllers]) {
mask |= 1 << i++; 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 #if TARGET_OS_IPHONE
DataManager* dataMan = [[DataManager alloc] init]; DataManager* dataMan = [[DataManager alloc] init];
@@ -377,19 +386,21 @@
// Even if no gamepads are present, we will always count one // Even if no gamepads are present, we will always count one
// if OSC is enabled. // if OSC is enabled.
if (level != OnScreenControlsLevelOff) { if (level != OnScreenControlsLevelOff) {
mask |= 1; mask |= 0x1;
} }
#endif #endif
return mask; return mask;
} }
-(id) init -(id) initWithConfig:(StreamConfiguration*)streamConfig
{ {
self = [super init]; self = [super init];
_controllerStreamLock = [[NSLock alloc] init]; _controllerStreamLock = [[NSLock alloc] init];
_controllers = [[NSMutableDictionary alloc] init]; _controllers = [[NSMutableDictionary alloc] init];
_controllerNumbers = 0; _controllerNumbers = 0;
_multiController = streamConfig.multiController;
_player0osc = [[Controller alloc] init]; _player0osc = [[Controller alloc] init];
_player0osc.playerIndex = 0; _player0osc.playerIndex = 0;
@@ -404,6 +415,8 @@
#endif #endif
Log(LOG_I, @"Number of supported controllers connected: %d", [ControllerSupport getGamepadCount]); Log(LOG_I, @"Number of supported controllers connected: %d", [ControllerSupport getGamepadCount]);
Log(LOG_I, @"Multi-controller: %d", _multiController);
for (GCController* controller in [GCController controllers]) { for (GCController* controller in [GCController controllers]) {
if ([ControllerSupport isSupportedGamepad:controller]) { if ([ControllerSupport isSupportedGamepad:controller]) {
[self assignController:controller]; [self assignController:controller];
+1
View File
@@ -26,5 +26,6 @@
@property int audioChannelCount; @property int audioChannelCount;
@property int audioChannelMask; @property int audioChannelMask;
@property BOOL enableHdr; @property BOOL enableHdr;
@property BOOL multiController;
@end @end
+1 -1
View File
@@ -9,5 +9,5 @@
#import "StreamConfiguration.h" #import "StreamConfiguration.h"
@implementation StreamConfiguration @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 @end
@@ -432,11 +432,14 @@ static NSMutableSet* hostList;
_streamConfig.bitRate = [streamSettings.bitrate intValue]; _streamConfig.bitRate = [streamSettings.bitrate intValue];
_streamConfig.height = [streamSettings.height intValue]; _streamConfig.height = [streamSettings.height intValue];
_streamConfig.width = [streamSettings.width intValue]; _streamConfig.width = [streamSettings.width intValue];
_streamConfig.gamepadMask = [ControllerSupport getConnectedGamepadMask];
_streamConfig.streamingRemotely = [streamSettings.streamingRemotely intValue]; _streamConfig.streamingRemotely = [streamSettings.streamingRemotely intValue];
_streamConfig.optimizeGameSettings = YES; _streamConfig.optimizeGameSettings = YES;
_streamConfig.playAudioOnPC = NO; _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 // TODO: Detect attached surround sound system then address 5.1 TODOs
// in Connection.m // in Connection.m
_streamConfig.audioChannelCount = 2; _streamConfig.audioChannelCount = 2;
@@ -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); 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; [UIApplication sharedApplication].idleTimerDisabled = YES;
_controllerSupport = [[ControllerSupport alloc] init]; _controllerSupport = [[ControllerSupport alloc] initWithConfig:self.streamConfig];
_streamMan = [[StreamManager alloc] initWithConfig:self.streamConfig _streamMan = [[StreamManager alloc] initWithConfig:self.streamConfig
renderView:self.view renderView:self.view