Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Source/GameCoreManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ extension GameCoreManager: OEGameCoreHelper {
public func setVolume(_ value: Float) {
gameCoreHelper?.setVolume(value)
}

public func setGameplayRate(_ normalRate: Float, fastForwardRate: Float) {
gameCoreHelper?.setGameplayRate(normalRate, fastForwardRate: fastForwardRate)
}

public func setPauseEmulation(_ pauseEmulation: Bool) {
gameCoreHelper?.setPauseEmulation(pauseEmulation)
Expand Down
7 changes: 7 additions & 0 deletions Source/OEGameCoreHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ import AudioToolbox
///
/// - Parameter value: The new volume level, from @c [0,1.0]
func setVolume(_ value: Float)

/// Sets the rates used for normal gameplay and fast-forwarding.
///
/// - Parameters:
/// - normalRate: The multiplier used during normal gameplay.
/// - fastForwardRate: The multiplier used while fast-forward is active.
func setGameplayRate(_ normalRate: Float, fastForwardRate: Float)

/**
* Manage the paused status of the core.
Expand Down
32 changes: 29 additions & 3 deletions Source/OpenEmuHelperApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,10 @@ extension OSLog {
var _handleKeyboardEvents: Bool = false

var loadedRom = false

private var normalGameplayRate: Float = 1.0
private var fastForwardGameplayRate: Float = 5.0
private var isFastForwarding = false

// frame rate debugging
var previous = CFTimeInterval()
Expand Down Expand Up @@ -143,6 +147,19 @@ extension OSLog {
self._shaderParameters = nil
}
}

private func applyGameplayRate() {
let rate = isFastForwarding ? fastForwardGameplayRate : normalGameplayRate

// nextDrawable() otherwise limits cores running faster than the display refresh rate.
// Fixes: https://github.com/OpenEmu/OpenEmu/issues/4780
_videoLayer?.displaySyncEnabled = rate <= 1.0

gameCore.perform {
guard !self.gameCore.isEmulationPaused else { return }
self.gameCore.rate = rate
}
}

// MARK: - Core Video and Generic Video

Expand Down Expand Up @@ -361,10 +378,20 @@ extension OSLog {
self._gameAudio.volume = volume
}
}

public func setGameplayRate(_ normalRate: Float, fastForwardRate: Float) {
normalGameplayRate = normalRate
fastForwardGameplayRate = fastForwardRate
applyGameplayRate()
}

public func setPauseEmulation(_ paused: Bool) {
let rate = isFastForwarding ? fastForwardGameplayRate : normalGameplayRate
gameCore.perform {
self.gameCore.setPauseEmulation(paused)
if !paused {
self.gameCore.rate = rate
}
}
}

Expand Down Expand Up @@ -828,9 +855,8 @@ extension OSLog {
}

public func fastForwardGameplay(_ enable: Bool) {
// Required so that _videoLayer.nextDrawable() vends frames faster than the display refresh rate
// Fixes: https://github.com/OpenEmu/OpenEmu/issues/4780
_videoLayer.displaySyncEnabled = !enable
isFastForwarding = enable
applyGameplayRate()
gameCoreOwner.fastForwardGameplay(enable)
}

Expand Down