IRewinder - dress up the api a bit, fix a potential NRE
This commit is contained in:
parent
843c70d6e1
commit
799742c3ff
|
@ -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();
|
||||
|
|
|
@ -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")}");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue