From 1db338ca8bcf2e453a8917753423fcce40b39c2f Mon Sep 17 00:00:00 2001 From: Daniel Egger Date: Thu, 16 Jul 2020 17:44:30 +0200 Subject: [PATCH] Control game speed with right thumbstick By steering the xAxis of the right thumbstick the player can control the game speed of the emulator directly. Press "right" -> GameSpeed.fast Press "left" -> GameSpeed.slow Neutral position -> GameSpeed.normal --- .../Emulator/PVEmulatorViewController.swift | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Provenance/Emulator/PVEmulatorViewController.swift b/Provenance/Emulator/PVEmulatorViewController.swift index e7a37aa3d6..eecdc5238a 100644 --- a/Provenance/Emulator/PVEmulatorViewController.swift +++ b/Provenance/Emulator/PVEmulatorViewController.swift @@ -705,6 +705,20 @@ extension PVEmulatorViewController { } }) } + + func controllerInputDetected(gamepad: GCExtendedGamepad, element: GCControllerElement) { + if (gamepad.rightThumbstick == element) { + ELOG("RightThumbstickXAxis: \(gamepad.rightThumbstick.xAxis.value)") + if(gamepad.rightThumbstick.xAxis.value > 0.1) { + self.core.gameSpeed = GameSpeed.fast; + } else if(gamepad.rightThumbstick.xAxis.value < -0.1) { + self.core.gameSpeed = GameSpeed.slow; + } + else { + self.core.gameSpeed = GameSpeed.normal; + } + } + } @objc func controllerDidConnect(_ note: Notification?) { let controller = note?.object as? GCController @@ -717,6 +731,11 @@ extension PVEmulatorViewController { controller?.controllerPausedHandler = { [unowned self] controller in self.controllerPauseButtonPressed(controller) } + + controller?.extendedGamepad?.valueChangedHandler = { + (gamepad: GCExtendedGamepad, element: GCControllerElement) in self.controllerInputDetected(gamepad: gamepad, element: element) + + } } #if os(iOS) if #available(iOS 11.0, *) {