Store GCController in Controller object to allow us to fetch controller attributes later

This commit is contained in:
Cameron Gutman
2019-02-11 18:21:04 -08:00
parent 442a791e0c
commit 918e1248f2
7 changed files with 54 additions and 43 deletions
+24
View File
@@ -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
+13
View File
@@ -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
-26
View File
@@ -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
}
+1 -2
View File
@@ -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;
+8 -5
View File
@@ -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
+1 -4
View File
@@ -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)))