Rewind cleanup / tweaks.

This commit is contained in:
J.D. Purcell 2017-04-29 14:04:11 -04:00
parent 70991a10a8
commit 3ebcaa8af0
2 changed files with 34 additions and 55 deletions

View File

@ -15,53 +15,31 @@ namespace BizHawk.Client.Common
private long _memoryLimit = MaxByteArraySize; private long _memoryLimit = MaxByteArraySize;
private RewindThreader _rewindThread; private RewindThreader _rewindThread;
private byte[] _lastState; private byte[] _lastState;
private int _rewindFrequency = 1;
private bool _rewindDeltaEnable; private bool _rewindDeltaEnable;
private bool _lastRewindLoadedState; private bool _lastRewindLoadedState;
private byte[] _deltaBuffer = new byte[0]; private byte[] _deltaBuffer = new byte[0];
public Rewinder()
{
RewindActive = true;
}
public Action<string> MessageCallback { get; set; } public Action<string> MessageCallback { get; set; }
public bool RewindActive { get; set; } public bool RewindActive => RewindEnabled && !SuspendRewind;
public float FullnessRatio private bool RewindEnabled { get; set; }
{
get { return _rewindBuffer?.FullnessRatio ?? 0; }
}
public int Count public bool SuspendRewind { get; set; }
{
get { return _rewindBuffer?.Count ?? 0; }
}
public long Size public float FullnessRatio => _rewindBuffer?.FullnessRatio ?? 0;
{
get { return _rewindBuffer?.Size ?? 0; }
}
public bool HasBuffer public int Count => _rewindBuffer?.Count ?? 0;
{
get { return _rewindBuffer != null; }
}
public int RewindFrequency public long Size => _rewindBuffer?.Size ?? 0;
{
get { return _rewindFrequency; }
}
private bool IsRewindEnabledAtAll public bool HasBuffer => _rewindBuffer != null;
{
get { return Global.Config.RewindEnabledLarge || Global.Config.RewindEnabledMedium || Global.Config.RewindEnabledSmall; } public int RewindFrequency { get; private set; }
}
public void Initialize() public void Initialize()
{ {
Clear(); Uninitialize();
if (Global.Emulator.HasSavestates()) if (Global.Emulator.HasSavestates())
{ {
@ -97,8 +75,10 @@ namespace BizHawk.Client.Common
} }
} }
public void Clear() public void Uninitialize()
{ {
Clear();
if (_rewindThread != null) if (_rewindThread != null)
{ {
_rewindThread.Dispose(); _rewindThread.Dispose();
@ -111,6 +91,17 @@ namespace BizHawk.Client.Common
_rewindBuffer = null; _rewindBuffer = null;
} }
RewindEnabled = false;
RewindFrequency = 0;
}
public void Clear()
{
if (_rewindBuffer != null)
{
_rewindBuffer.Clear();
}
_lastState = new byte[0]; _lastState = new byte[0];
} }
@ -121,18 +112,14 @@ namespace BizHawk.Client.Common
private void SetRewindParams(bool enabled, int frequency) private void SetRewindParams(bool enabled, int frequency)
{ {
if (RewindActive != enabled) DoMessage("Rewind " + (enabled ? "enabled" : "disabled"));
{ if (enabled)
DoMessage("Rewind " + (enabled ? "Enabled" : "Disabled"));
}
if (_rewindFrequency != frequency && enabled)
{ {
DoMessage("Rewind frequency set to " + frequency); DoMessage("Rewind frequency set to " + frequency);
} }
RewindActive = enabled; RewindEnabled = enabled;
_rewindFrequency = frequency; RewindFrequency = frequency;
} }
private byte[] BufferManage(byte[] inbuf, ref long size, bool allocate) private byte[] BufferManage(byte[] inbuf, ref long size, bool allocate)
@ -172,7 +159,7 @@ namespace BizHawk.Client.Common
public void Capture() public void Capture()
{ {
if (!IsRewindEnabledAtAll || !Global.Emulator.HasSavestates()) if (!RewindActive)
{ {
return; return;
} }
@ -182,7 +169,7 @@ namespace BizHawk.Client.Common
Initialize(); Initialize();
} }
if (_rewindThread == null || Global.Emulator.Frame % _rewindFrequency != 0) if (_rewindThread == null || Global.Emulator.Frame % RewindFrequency != 0)
{ {
return; return;
} }
@ -315,7 +302,7 @@ namespace BizHawk.Client.Common
public bool Rewind(int frames) public bool Rewind(int frames)
{ {
if (!Global.Emulator.HasSavestates() || _rewindThread == null) if (!RewindActive || _rewindThread == null)
{ {
return false; return false;
} }

View File

@ -3700,7 +3700,7 @@ namespace BizHawk.Client.EmuHawk
GlobalWin.Tools.Restart(); GlobalWin.Tools.Restart();
RewireSound(); RewireSound();
Global.Rewinder.Clear(); Global.Rewinder.Uninitialize();
Text = "BizHawk" + (VersionInfo.DeveloperBuild ? " (interim) " : string.Empty); Text = "BizHawk" + (VersionInfo.DeveloperBuild ? " (interim) " : string.Empty);
HandlePlatformMenus(); HandlePlatformMenus();
_stateSlots.Clear(); _stateSlots.Clear();
@ -3727,16 +3727,8 @@ namespace BizHawk.Client.EmuHawk
public void EnableRewind(bool enabled) public void EnableRewind(bool enabled)
{ {
if (enabled) Global.Rewinder.SuspendRewind = !enabled;
{ GlobalWin.OSD.AddMessage("Rewind " + (enabled ? "enabled" : "suspended"));
Global.Rewinder.RewindActive = true;
GlobalWin.OSD.AddMessage("Rewind enabled");
}
else
{
Global.Rewinder.RewindActive = false;
GlobalWin.OSD.AddMessage("Rewind suspended");
}
} }
public void ClearRewindData() public void ClearRewindData()