mirror of
https://github.com/moonlight-stream/moonlight-ios.git
synced 2026-02-16 10:31:02 +00:00
Plumb multi-controller toggle
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -26,5 +26,6 @@
|
||||
@property int audioChannelCount;
|
||||
@property int audioChannelMask;
|
||||
@property BOOL enableHdr;
|
||||
@property BOOL multiController;
|
||||
|
||||
@end
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user