IRewinder - dress up the api a bit, fix a potential NRE

This commit is contained in:
adelikat 2020-06-08 11:29:08 -05:00
parent 843c70d6e1
commit 799742c3ff
2 changed files with 28 additions and 6 deletions

View File

@ -12,10 +12,12 @@ namespace BizHawk.Client.Common
int RewindFrequency { get; }
bool Active { get; }
bool Suspend { get; set; }
void Capture(int frame);
bool Rewind(int frames);
void Suspend();
void Resume();
}
public class Rewinder : IRewinder
@ -33,11 +35,11 @@ namespace BizHawk.Client.Common
private bool _lastRewindLoadedState;
private byte[] _deltaBuffer = new byte[0];
public bool Active => RewindEnabled && !Suspend;
public bool Active => RewindEnabled && !_suspend;
private bool RewindEnabled { get; }
public bool Suspend { get; set; }
private bool _suspend;
public float FullnessRatio => _rewindBuffer?.FullnessRatio ?? 0;
@ -79,6 +81,16 @@ namespace BizHawk.Client.Common
}
}
public void Suspend()
{
_suspend = true;
}
public void Resume()
{
_suspend = false;
}
private void Clear()
{
_rewindBuffer?.Clear();

View File

@ -4009,12 +4009,22 @@ namespace BizHawk.Client.EmuHawk
public void EnableRewind(bool enabled)
{
if (Rewinder == null && Emulator.HasSavestates())
if (!Emulator.HasSavestates())
{
Rewinder = new Rewinder(Emulator.AsStatable(), Config.Rewind);
return;
}
Rewinder ??= new Rewinder(Emulator.AsStatable(), Config.Rewind);
if (enabled)
{
Rewinder.Resume();
}
else
{
Rewinder.Suspend();
}
Rewinder.Suspend = !enabled;
AddOnScreenMessage($"Rewind {(enabled ? "enabled" : "suspended")}");
}