Cleanup TasStateManager.Invalidate

had this written down for after #1591 merge
This commit is contained in:
YoshiRulz 2020-01-04 04:54:26 +10:00
parent 023da20cb9
commit dabbaae075
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
1 changed files with 7 additions and 21 deletions

View File

@ -172,29 +172,15 @@ namespace BizHawk.Client.Common
return _states.ContainsKey(frame); return _states.ContainsKey(frame);
} }
/// <returns>true iff any frames were invalidated</returns>
public bool Invalidate(int frame) public bool Invalidate(int frame)
{ {
bool anyInvalidated = false; if (!Any()) return false;
if (frame == 0) frame = 1; // Never invalidate frame 0
if (Any()) var statesToRemove = _states.Where(s => s.Key >= frame).ToList();
{ foreach (var state in statesToRemove) Remove(state.Key);
if (frame == 0) // Never invalidate frame 0
{
frame = 1;
}
List<KeyValuePair<int, byte[]>> statesToRemove = _states.Where(s => s.Key >= frame).ToList();
anyInvalidated = statesToRemove.Any();
foreach (var state in statesToRemove)
{
Remove(state.Key);
}
InvalidateCallback?.Invoke(frame); InvalidateCallback?.Invoke(frame);
} return statesToRemove.Count != 0;
return anyInvalidated;
} }
public bool Remove(int frame) public bool Remove(int frame)