From 1b874ce9c1d4571a7a9342e643d91d9d1c53c3ff Mon Sep 17 00:00:00 2001 From: Riley Testut Date: Mon, 11 Jan 2021 15:57:54 -0600 Subject: [PATCH] Displays preview save state image even if context menu previews are disabled --- Cores/DeltaCore | 2 +- .../Emulation/PreviewGameViewController.swift | 27 +++++++++++++++- .../GameCollectionViewController.swift | 31 +++++++++++++------ 3 files changed, 49 insertions(+), 11 deletions(-) diff --git a/Cores/DeltaCore b/Cores/DeltaCore index a07abad..135b053 160000 --- a/Cores/DeltaCore +++ b/Cores/DeltaCore @@ -1 +1 @@ -Subproject commit a07abad3214a310785055eddf86bed36ae7612ca +Subproject commit 135b0532a3b17e0a970e23bdc81bf80595ed81b2 diff --git a/Delta/Emulation/PreviewGameViewController.swift b/Delta/Emulation/PreviewGameViewController.swift index 7dff3f7..a59c700 100644 --- a/Delta/Emulation/PreviewGameViewController.swift +++ b/Delta/Emulation/PreviewGameViewController.swift @@ -27,6 +27,8 @@ class PreviewGameViewController: DeltaCore.GameViewController } } + var isLivePreview: Bool = true + private var emulatorCoreQueue = DispatchQueue(label: "com.rileytestut.Delta.PreviewGameViewController.emulatorCoreQueue", qos: .userInitiated) private var copiedSaveFiles = [(originalURL: URL, copyURL: URL)]() @@ -58,6 +60,20 @@ class PreviewGameViewController: DeltaCore.GameViewController return previewActionItems } + public required init() + { + super.init() + + self.delegate = self + } + + public required init?(coder aDecoder: NSCoder) + { + super.init(coder: aDecoder) + + self.delegate = self + } + deinit { // Explicitly stop emulatorCore _before_ we remove ourselves as observer @@ -77,6 +93,7 @@ extension PreviewGameViewController super.viewDidLoad() self.controllerView.isHidden = true + self.controllerView.controllerSkin = nil // Skip loading controller skin from disk, which may be slow. // Temporarily prevent emulatorCore from updating gameView to prevent flicker of black, or other visual glitches self.emulatorCore?.remove(self.gameView) @@ -94,7 +111,7 @@ extension PreviewGameViewController super.viewDidAppear(animated) self.emulatorCoreQueue.async { - self.emulatorCore?.start() + self.startEmulation() } } @@ -264,3 +281,11 @@ private extension PreviewGameViewController } } } + +extension PreviewGameViewController: GameViewControllerDelegate +{ + func gameViewControllerShouldResumeEmulation(_ gameViewController: DeltaCore.GameViewController) -> Bool + { + return self.isLivePreview + } +} diff --git a/Delta/Game Selection/GameCollectionViewController.swift b/Delta/Game Selection/GameCollectionViewController.swift index bc7f4dd..893c803 100644 --- a/Delta/Game Selection/GameCollectionViewController.swift +++ b/Delta/Game Selection/GameCollectionViewController.swift @@ -821,9 +821,16 @@ extension GameCollectionViewController: UIViewControllerPreviewingDelegate gameViewController.pauseEmulation() let indexPath = self.dataSource.fetchedResultsController.indexPath(forObject: game)! - let fileURL = FileManager.default.uniqueTemporaryURL() - self.activeSaveState = gameViewController.emulatorCore?.saveSaveState(to: fileURL) + + if gameViewController.isLivePreview + { + self.activeSaveState = gameViewController.emulatorCore?.saveSaveState(to: fileURL) + } + else + { + self.activeSaveState = gameViewController.previewSaveState + } gameViewController.emulatorCore?.stop() @@ -831,13 +838,16 @@ extension GameCollectionViewController: UIViewControllerPreviewingDelegate self.launchGame(at: indexPath, clearScreen: true, ignoreAlreadyRunningError: true) - do + if gameViewController.isLivePreview { - try FileManager.default.removeItem(at: fileURL) - } - catch - { - print(error) + do + { + try FileManager.default.removeItem(at: fileURL) + } + catch + { + print(error) + } } } } @@ -926,9 +936,12 @@ extension GameCollectionViewController let actions = self.actions(for: game) return UIContextMenuConfiguration(identifier: indexPath as NSIndexPath, previewProvider: { [weak self] in - guard let self = self, Settings.isPreviewsEnabled else { return nil } + guard let self = self else { return nil } let previewViewController = self.makePreviewGameViewController(for: game) + previewViewController.isLivePreview = Settings.isPreviewsEnabled + + guard previewViewController.isLivePreview || previewViewController.previewSaveState != nil else { return nil } self._previewTransitionViewController = previewViewController return previewViewController