From 0f43de2138a603a32e9d6807c70c5e6ad4a4d424 Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Sun, 29 May 2016 05:40:42 -0500 Subject: [PATCH] Updates EmulationViewController Game Controller methods & matches DeltaCore refactoring --- Cores/DeltaCore | 2 +- Cores/SNESDeltaCore | 2 +- Delta/Emulation/EmulationViewController.swift | 27 ++++++++++++------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/Cores/DeltaCore b/Cores/DeltaCore index d8532bd..1476246 160000 --- a/Cores/DeltaCore +++ b/Cores/DeltaCore @@ -1 +1 @@ -Subproject commit d8532bd184a9a1e87b48ad5ad9f4a6d24d81783f +Subproject commit 1476246c71526677acf299907ec5ec4fbc3f6d89 diff --git a/Cores/SNESDeltaCore b/Cores/SNESDeltaCore index 58dce56..99aeaa0 160000 --- a/Cores/SNESDeltaCore +++ b/Cores/SNESDeltaCore @@ -1 +1 @@ -Subproject commit 58dce561dd80baf954f487fc8fa15aae998559a6 +Subproject commit 99aeaa0ce70be0d943c49a124f8781d08cacf634 diff --git a/Delta/Emulation/EmulationViewController.swift b/Delta/Emulation/EmulationViewController.swift index 58a639b..0fc9143 100644 --- a/Delta/Emulation/EmulationViewController.swift +++ b/Delta/Emulation/EmulationViewController.swift @@ -103,8 +103,6 @@ class EmulationViewController: UIViewController self.controllerView.containerView = self.view self.controllerView.controllerSkin = controllerSkin - self.controllerView.addReceiver(self) - self.emulatorCore.setGameController(self.controllerView, atIndex: 0) self.updateControllers() } @@ -290,14 +288,25 @@ private extension EmulationViewController if let index = Settings.localControllerPlayerIndex { - self.emulatorCore.setGameController(self.controllerView, atIndex: index) + self.controllerView.playerIndex = index } - for controller in ExternalControllerManager.sharedManager.connectedControllers + var controllers = [GameControllerProtocol]() + controllers.append(self.controllerView) + + // We need to map each item as a GameControllerProtocol due to a Swift bug + controllers.appendContentsOf(ExternalControllerManager.sharedManager.connectedControllers.map { $0 as GameControllerProtocol }) + + for controller in controllers { if let index = controller.playerIndex { self.emulatorCore.setGameController(controller, atIndex: index) + controller.addReceiver(self) + } + else + { + controller.removeReceiver(self) } } @@ -318,7 +327,7 @@ private extension EmulationViewController } } - func sustainInput(input: InputType, gameController: GameControllerType) + func sustainInput(input: InputType, gameController: GameControllerProtocol) { if let input = input as? ControllerInput { @@ -485,11 +494,11 @@ private extension EmulationViewController //MARK: - - /// -extension EmulationViewController: GameControllerReceiverType +extension EmulationViewController: GameControllerReceiverProtocol { - func gameController(gameController: GameControllerType, didActivateInput input: InputType) + func gameController(gameController: GameControllerProtocol, didActivateInput input: InputType) { - if UIDevice.currentDevice().supportsVibration + if gameController is ControllerView && UIDevice.currentDevice().supportsVibration { UIDevice.currentDevice().vibrate() } @@ -510,7 +519,7 @@ extension EmulationViewController: GameControllerReceiverType } } - func gameController(gameController: GameControllerType, didDeactivateInput input: InputType) + func gameController(gameController: GameControllerProtocol, didDeactivateInput input: InputType) { guard let input = input as? ControllerInput else { return }