IStateManager - refactor indexer to not return a keyvalue pair, since it by design will try to return the exact frame, returning the frame is redundant

This commit is contained in:
adelikat 2019-06-15 16:43:21 -05:00
parent 394a6d86b5
commit 3ec2ec325a
3 changed files with 12 additions and 10 deletions

View File

@ -6,14 +6,12 @@ namespace BizHawk.Client.Common
{
public interface IStateManager
{
// byte[] this[int frame] { get; } // TODO: I had it refactored to this back in the day
/// <summary>
/// Retrieves the savestate for the given frame,
/// If this frame does not have a state currently, will return an empty array
/// </summary>
/// <returns>A savestate for the given frame or an empty array if there isn't one</returns>
KeyValuePair<int, byte[]> this[int frame] { get; }
byte[] this[int frame] { get; }
TasStateManagerSettings Settings { get; set; }

View File

@ -60,21 +60,21 @@ namespace BizHawk.Client.Common
public TasStateManagerSettings Settings { get; set; }
public KeyValuePair<int, byte[]> this[int frame]
public byte[] this[int frame]
{
get
{
if (frame == 0)
{
return new KeyValuePair<int, byte[]>(0, InitialState);
return InitialState;
}
if (_states.ContainsKey(frame))
{
return new KeyValuePair<int, byte[]>(frame, _states[frame].State);
return _states[frame].State;
}
return new KeyValuePair<int, byte[]>(-1, new byte[0]);
return new byte[0];
}
}
@ -267,8 +267,12 @@ namespace BizHawk.Client.Common
public KeyValuePair<int, byte[]> GetStateClosestToFrame(int frame)
{
var s = _states.LastOrDefault(state => state.Key < frame);
if (s.Key > 0)
{
return new KeyValuePair<int, byte[]>(s.Key, s.Value.State);
}
return this[s.Key];
return new KeyValuePair<int, byte[]>(0, InitialState);
}
public int GetStateIndexByFrame(int frame)

View File

@ -815,9 +815,9 @@ namespace BizHawk.Client.EmuHawk
if (CurrentTasMovie.TasStateManager.HasState(Emulator.Frame))
{
byte[] state = StatableEmulator.SaveStateBinary();
byte[] greenzone = CurrentTasMovie.TasStateManager[Emulator.Frame].Value;
byte[] greenZone = CurrentTasMovie.TasStateManager[Emulator.Frame];
if (!state.SequenceEqual(greenzone))
if (!state.SequenceEqual(greenZone))
{
MessageBox.Show($"Bad data between frames {lastState} and {Emulator.Frame}");
return;