diff --git a/Limelight/Input/Controller.h b/Limelight/Input/Controller.h new file mode 100644 index 0000000..b1a41de --- /dev/null +++ b/Limelight/Input/Controller.h @@ -0,0 +1,24 @@ +// +// Controller.h +// Moonlight +// +// Created by Cameron Gutman on 2/11/19. +// Copyright © 2019 Moonlight Game Streaming Project. All rights reserved. +// + +@import GameController; + +@interface Controller : NSObject + +@property (nullable, nonatomic, retain) GCController* gamepad; +@property (nonatomic) int playerIndex; +@property (nonatomic) int lastButtonFlags; +@property (nonatomic) int emulatingButtonFlags; +@property (nonatomic) unsigned char lastLeftTrigger; +@property (nonatomic) unsigned char lastRightTrigger; +@property (nonatomic) short lastLeftStickX; +@property (nonatomic) short lastLeftStickY; +@property (nonatomic) short lastRightStickX; +@property (nonatomic) short lastRightStickY; + +@end diff --git a/Limelight/Input/Controller.m b/Limelight/Input/Controller.m new file mode 100644 index 0000000..7587928 --- /dev/null +++ b/Limelight/Input/Controller.m @@ -0,0 +1,13 @@ +// +// Controller.m +// Moonlight +// +// Created by Cameron Gutman on 2/11/19. +// Copyright © 2019 Moonlight Game Streaming Project. All rights reserved. +// + +#include "Controller.h" + +@implementation Controller + +@end diff --git a/Limelight/Input/Controller.swift b/Limelight/Input/Controller.swift deleted file mode 100644 index 6feff3b..0000000 --- a/Limelight/Input/Controller.swift +++ /dev/null @@ -1,26 +0,0 @@ -// -// Controller.swift -// Moonlight -// -// Created by David Aghassi on 4/11/16. -// Copyright © 2016 Moonlight Stream. All rights reserved. -// - -import Foundation - -@objc -/** - Defines a controller layout - */ -class Controller: NSObject { - // Swift requires initial properties - @objc var playerIndex: CInt = 0 // Controller number (e.g. 1, 2 ,3 etc) - @objc var lastButtonFlags: CInt = 0 - @objc var emulatingButtonFlags: CInt = 0 - @objc var lastLeftTrigger: CChar = 0 // Last left trigger pressed - @objc var lastRightTrigger: CChar = 0 // Last right trigger pressed - @objc var lastLeftStickX: CShort = 0 // Last X direction the left joystick went - @objc var lastLeftStickY: CShort = 0 // Last Y direction the left joystick went - @objc var lastRightStickX: CShort = 0 // Last X direction the right joystick went - @objc var lastRightStickY: CShort = 0 // Last Y direction the right joystick went -} diff --git a/Limelight/Input/ControllerSupport.h b/Limelight/Input/ControllerSupport.h index c686eda..e8d0295 100644 --- a/Limelight/Input/ControllerSupport.h +++ b/Limelight/Input/ControllerSupport.h @@ -7,12 +7,11 @@ // // Swift -#import "Moonlight-Swift.h" #if !TARGET_OS_IPHONE #import "Gamepad.h" #endif #import "StreamConfiguration.h" -@class Controller; +#import "Controller.h" @class OnScreenControls; diff --git a/Limelight/Input/ControllerSupport.m b/Limelight/Input/ControllerSupport.m index 3479949..5e75d2d 100644 --- a/Limelight/Input/ControllerSupport.m +++ b/Limelight/Input/ControllerSupport.m @@ -7,6 +7,7 @@ // #import "ControllerSupport.h" +#import "Controller.h" #import "OnScreenControls.h" #if !TARGET_OS_IPHONE @@ -17,10 +18,6 @@ #import "DataManager.h" #include "Limelight.h" -// Swift -#import "Moonlight-Swift.h" -@class Controller; - @import GameController; @implementation ControllerSupport { @@ -322,6 +319,8 @@ limeController = [[Controller alloc] init]; limeController.playerIndex = i; } + + limeController.gamepad = controller; [_controllers setObject:limeController forKey:[NSNumber numberWithInteger:controller.playerIndex]]; @@ -477,8 +476,12 @@ self->_controllerNumbers &= ~(1 << controller.playerIndex); Log(LOG_I, @"Unassigning controller index: %ld", (long)controller.playerIndex); + // Unset the GCController on this object (in case it is the OSC, which will persist) + Controller* limeController = [self->_controllers objectForKey:[NSNumber numberWithInteger:controller.playerIndex]]; + limeController.gamepad = nil; + // Inform the server of the updated active gamepads before removing this controller - [self updateFinished:[self->_controllers objectForKey:[NSNumber numberWithInteger:controller.playerIndex]]]; + [self updateFinished:limeController]; [self->_controllers removeObjectForKey:[NSNumber numberWithInteger:controller.playerIndex]]; // Re-evaluate the on-screen control mode diff --git a/Limelight/Input/OnScreenControls.m b/Limelight/Input/OnScreenControls.m index b855e55..b80ed12 100644 --- a/Limelight/Input/OnScreenControls.m +++ b/Limelight/Input/OnScreenControls.m @@ -8,12 +8,9 @@ #import "OnScreenControls.h" #import "ControllerSupport.h" -//#import "Controller.h" +#import "Controller.h" #include "Limelight.h" -#import "Moonlight-Swift.h" -@class Controller; - #define UPDATE_BUTTON(x, y) (buttonFlags = \ (y) ? (buttonFlags | (x)) : (buttonFlags & ~(x))) diff --git a/Moonlight.xcodeproj/project.pbxproj b/Moonlight.xcodeproj/project.pbxproj index a8c34f4..1d45eb8 100644 --- a/Moonlight.xcodeproj/project.pbxproj +++ b/Moonlight.xcodeproj/project.pbxproj @@ -17,11 +17,11 @@ 9865DC3C2132922E0005B9B9 /* GameController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9865DC3B2132922E0005B9B9 /* GameController.framework */; }; 9865DC3E21332D660005B9B9 /* MainFrameViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = FB89462519F646E200339C8A /* MainFrameViewController.m */; }; 9890CF6B203B7EE1006C4B06 /* libxml2.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 9890CF6A203B7EE1006C4B06 /* libxml2.tbd */; }; + 9897B6A1221260EF00966419 /* Controller.m in Sources */ = {isa = PBXBuildFile; fileRef = 9897B6A0221260EF00966419 /* Controller.m */; }; 98CFB82F1CAD481B0048EF74 /* libmoonlight-common.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 98AB2E841CAD46840089BB98 /* libmoonlight-common.a */; }; 98D5856D1C0EA79600F6CC00 /* TemporaryHost.m in Sources */ = {isa = PBXBuildFile; fileRef = 98D5856C1C0EA79600F6CC00 /* TemporaryHost.m */; }; 98D585701C0ED0E800F6CC00 /* TemporarySettings.m in Sources */ = {isa = PBXBuildFile; fileRef = 98D5856F1C0ED0E800F6CC00 /* TemporarySettings.m */; }; D46A73AD1CBC7D090039F1EE /* ControllerUnitTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = D46A73AC1CBC7D090039F1EE /* ControllerUnitTests.swift */; }; - D4746EEC1CBC740C006FB401 /* Controller.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4746EEB1CBC740C006FB401 /* Controller.swift */; }; DC1F5A07206436B20037755F /* ConnectionHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = DC1F5A06206436B20037755F /* ConnectionHelper.m */; }; FB1A674D2131E65900507771 /* KeyboardSupport.m in Sources */ = {isa = PBXBuildFile; fileRef = FB1A674C2131E65900507771 /* KeyboardSupport.m */; }; FB1A67602132419700507771 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = FB1A675E2132419700507771 /* Main.storyboard */; }; @@ -52,7 +52,6 @@ FB1A67D1213245F800507771 /* TemporaryHost.m in Sources */ = {isa = PBXBuildFile; fileRef = 98D5856C1C0EA79600F6CC00 /* TemporaryHost.m */; }; FB1A67D3213245F800507771 /* TemporarySettings.m in Sources */ = {isa = PBXBuildFile; fileRef = 98D5856F1C0ED0E800F6CC00 /* TemporarySettings.m */; }; FB1A67D52132460400507771 /* ControllerSupport.m in Sources */ = {isa = PBXBuildFile; fileRef = FB89460B19F646E200339C8A /* ControllerSupport.m */; }; - FB1A67D62132460400507771 /* Controller.swift in Sources */ = {isa = PBXBuildFile; fileRef = D4746EEB1CBC740C006FB401 /* Controller.swift */; }; FB1A67D82132460400507771 /* StreamView.m in Sources */ = {isa = PBXBuildFile; fileRef = FB89460D19F646E200339C8A /* StreamView.m */; }; FB1A67DA2132460400507771 /* OnScreenControls.m in Sources */ = {isa = PBXBuildFile; fileRef = FB4678EC1A50C40900377732 /* OnScreenControls.m */; }; FB1A67DC2132460400507771 /* KeyboardSupport.m in Sources */ = {isa = PBXBuildFile; fileRef = FB1A674C2131E65900507771 /* KeyboardSupport.m */; }; @@ -170,6 +169,8 @@ 986CCE6C2133E45300168291 /* Moonlight v1.2.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "Moonlight v1.2.xcdatamodel"; sourceTree = ""; }; 98878AE0206A226D00586E90 /* OSPortabilityDefs.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = OSPortabilityDefs.h; sourceTree = ""; }; 9890CF6A203B7EE1006C4B06 /* libxml2.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libxml2.tbd; path = usr/lib/libxml2.tbd; sourceTree = SDKROOT; }; + 9897B6A0221260EF00966419 /* Controller.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = Controller.m; sourceTree = ""; }; + 9897B6A32212610800966419 /* Controller.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Controller.h; sourceTree = ""; }; 98AB2E7F1CAD46830089BB98 /* moonlight-common.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = "moonlight-common.xcodeproj"; path = "moonlight-common/moonlight-common.xcodeproj"; sourceTree = ""; }; 98D5856B1C0EA79600F6CC00 /* TemporaryHost.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TemporaryHost.h; path = Database/TemporaryHost.h; sourceTree = ""; }; 98D5856C1C0EA79600F6CC00 /* TemporaryHost.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TemporaryHost.m; path = Database/TemporaryHost.m; sourceTree = ""; }; @@ -180,7 +181,6 @@ D46A73AB1CBC7D080039F1EE /* MoonlightUnitTests-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "MoonlightUnitTests-Bridging-Header.h"; sourceTree = ""; }; D46A73AC1CBC7D090039F1EE /* ControllerUnitTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; name = ControllerUnitTests.swift; path = Input/ControllerUnitTests.swift; sourceTree = ""; }; D4746EEA1CBC740C006FB401 /* Moonlight-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "Moonlight-Bridging-Header.h"; path = "Input/Moonlight-Bridging-Header.h"; sourceTree = ""; }; - D4746EEB1CBC740C006FB401 /* Controller.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Controller.swift; sourceTree = ""; }; DC1F5A05206436B10037755F /* ConnectionHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ConnectionHelper.h; sourceTree = ""; }; DC1F5A06206436B20037755F /* ConnectionHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ConnectionHelper.m; sourceTree = ""; }; FB1A674B2131E65900507771 /* KeyboardSupport.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = KeyboardSupport.h; sourceTree = ""; }; @@ -549,13 +549,14 @@ children = ( FB89460A19F646E200339C8A /* ControllerSupport.h */, FB89460B19F646E200339C8A /* ControllerSupport.m */, - D4746EEB1CBC740C006FB401 /* Controller.swift */, FB89460C19F646E200339C8A /* StreamView.h */, FB89460D19F646E200339C8A /* StreamView.m */, FB4678EB1A50C40900377732 /* OnScreenControls.h */, FB4678EC1A50C40900377732 /* OnScreenControls.m */, FB1A674B2131E65900507771 /* KeyboardSupport.h */, FB1A674C2131E65900507771 /* KeyboardSupport.m */, + 9897B6A0221260EF00966419 /* Controller.m */, + 9897B6A32212610800966419 /* Controller.h */, ); path = Input; sourceTree = ""; @@ -1020,8 +1021,8 @@ FB1A67DE2132460A00507771 /* Utils.m in Sources */, FB1A67E02132460A00507771 /* Logger.m in Sources */, FB1A67D52132460400507771 /* ControllerSupport.m in Sources */, - FB1A67D62132460400507771 /* Controller.swift in Sources */, FB1A67D82132460400507771 /* StreamView.m in Sources */, + 9897B6A2221260EF00966419 /* Controller.m in Sources */, FB1A67DA2132460400507771 /* OnScreenControls.m in Sources */, FB1A67DC2132460400507771 /* KeyboardSupport.m in Sources */, FB1A67CD213245F800507771 /* DataManager.m in Sources */, @@ -1067,6 +1068,7 @@ FB9AFD321A7D867C00872C98 /* AppAssetRetriever.m in Sources */, FB4678FF1A565DAC00377732 /* WakeOnLanManager.m in Sources */, FB53E1431BE5DC4400CD6ECE /* IdManager.m in Sources */, + 9897B6A1221260EF00966419 /* Controller.m in Sources */, FB89462919F646E200339C8A /* mkcert.c in Sources */, FB9AFD281A7C84ED00872C98 /* HttpResponse.m in Sources */, FBDE86E019F7A837001C18A8 /* UIComputerView.m in Sources */, @@ -1096,7 +1098,6 @@ FB89462A19F646E200339C8A /* ControllerSupport.m in Sources */, FB9AFD3D1A7E111600872C98 /* AppAssetResponse.m in Sources */, FBD349621A0089F6002D2A60 /* DataManager.m in Sources */, - D4746EEC1CBC740C006FB401 /* Controller.swift in Sources */, FB4A23B81A9D3637004D2EF2 /* LoadingFrameViewController.m in Sources */, FB9AFD3A1A7E05CE00872C98 /* ServerInfoResponse.m in Sources */, FB89463119F646E200339C8A /* StreamManager.m in Sources */,