create IStateManager interface and use that instead of TasStateManager
This commit is contained in:
parent
1bcf6394ed
commit
3c27a332bb
|
@ -186,6 +186,7 @@
|
|||
</Compile>
|
||||
<Compile Include="movie\bk2\StringLogs.cs" />
|
||||
<Compile Include="movie\import\PXMImport.cs" />
|
||||
<Compile Include="movie\tasproj\IStateManager.cs" />
|
||||
<Compile Include="movie\tasproj\StateManagerDecay.cs" />
|
||||
<Compile Include="movie\tasproj\StateManagerState.cs" />
|
||||
<Compile Include="movie\tasproj\TasBranch.cs" />
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
using System;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
using BizHawk.Common;
|
||||
|
||||
public interface IStateManager : IDisposable
|
||||
{
|
||||
// byte[] this[int frame] { get; } // TODO: I had it refactored to this back in the day
|
||||
KeyValuePair<int, byte[]> this[int frame] { get; }
|
||||
|
||||
TasStateManagerSettings Settings { get; set; }
|
||||
|
||||
Action<int> InvalidateCallback { set; }
|
||||
|
||||
void Capture(bool force = false);
|
||||
|
||||
bool HasState(int frame);
|
||||
|
||||
bool Invalidate(int frame);
|
||||
|
||||
// TODO: rename to Clear()
|
||||
// TODO: consider it passing a bool if anything was cleared, and the .Any() could go away
|
||||
void ClearStateHistory();
|
||||
|
||||
void Save(BinaryWriter bw);
|
||||
|
||||
void Load(BinaryReader br);
|
||||
|
||||
KeyValuePair<int, byte[]> GetStateClosestToFrame(int frame);
|
||||
|
||||
bool Any();
|
||||
|
||||
// TODO: rename to Last
|
||||
int LastStatedFrame { get; }
|
||||
|
||||
// ********* Delete these **********
|
||||
void MountWriteAccess();
|
||||
|
||||
// TODO: delete me, I don't work
|
||||
NDBDatabase NdbDatabase { get; }
|
||||
|
||||
// *********** Reconsider these ************/
|
||||
void LimitStateCount();
|
||||
|
||||
void UpdateStateFrequency();
|
||||
|
||||
bool RemoveState(int frame);
|
||||
|
||||
int LastEditedFrame { get; }
|
||||
bool StateIsMarker(int frame);
|
||||
|
||||
int StateCount { get; }
|
||||
|
||||
int GetStateIndexByFrame(int frame);
|
||||
|
||||
int GetStateFrameByIndex(int index);
|
||||
}
|
||||
}
|
|
@ -44,7 +44,7 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
internal class StateManagerDecay
|
||||
{
|
||||
private TasStateManager _tsm; // access tsm methods to make life easier
|
||||
private readonly IStateManager _tsm; // access tsm methods to make life easier
|
||||
private List<int> _zeros; // amount of least significant zeros in bitwise view (also max pattern step)
|
||||
private int _bits; // size of _zeros is 2 raised to the power of _bits
|
||||
private int _mask; // for remainder calculation using bitwise instead of division
|
||||
|
@ -53,7 +53,7 @@ namespace BizHawk.Client.Common
|
|||
private int _step; // initial memory state gap
|
||||
private bool _align; // extra care about fine alignment. TODO: do we want it?
|
||||
|
||||
public StateManagerDecay(TasStateManager tsm)
|
||||
public StateManagerDecay(IStateManager tsm)
|
||||
{
|
||||
_tsm = tsm;
|
||||
_align = false;
|
||||
|
|
|
@ -9,14 +9,14 @@ namespace BizHawk.Client.Common
|
|||
internal class StateManagerState : IDisposable
|
||||
{
|
||||
private static long _stateId;
|
||||
private readonly TasStateManager _manager;
|
||||
private readonly IStateManager _manager;
|
||||
private readonly long _id;
|
||||
|
||||
private byte[] _state;
|
||||
|
||||
public int Frame { get; }
|
||||
|
||||
public static StateManagerState Read(BinaryReader r, TasStateManager m)
|
||||
public static StateManagerState Read(BinaryReader r, IStateManager m)
|
||||
{
|
||||
int frame = r.ReadInt32();
|
||||
byte[] data = r.ReadBytes(r.ReadInt32());
|
||||
|
@ -59,7 +59,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public bool IsOnDisk => _state == null;
|
||||
|
||||
public StateManagerState(TasStateManager manager, byte[] state, int frame)
|
||||
public StateManagerState(IStateManager manager, byte[] state, int frame)
|
||||
{
|
||||
_manager = manager;
|
||||
_state = state;
|
||||
|
|
|
@ -13,7 +13,7 @@ namespace BizHawk.Client.Common
|
|||
public sealed partial class TasMovie : Bk2Movie, INotifyPropertyChanged
|
||||
{
|
||||
private readonly Bk2MnemonicConstants _mnemonics = new Bk2MnemonicConstants();
|
||||
private readonly TasStateManager _stateManager;
|
||||
private readonly IStateManager _stateManager;
|
||||
private readonly TasLagLog _lagLog = new TasLagLog();
|
||||
private readonly Dictionary<int, IController> _inputStateCache = new Dictionary<int, IController>();
|
||||
private BackgroundWorker _progressReportWorker;
|
||||
|
@ -37,7 +37,7 @@ namespace BizHawk.Client.Common
|
|||
public int BranchCount => Branches.Count;
|
||||
public int LastStatedFrame => _stateManager.LastStatedFrame;
|
||||
public override string PreferredExtension => Extension;
|
||||
public TasStateManager TasStateManager => _stateManager;
|
||||
public IStateManager TasStateManager => _stateManager;
|
||||
|
||||
public TasMovieRecord this[int index] => new TasMovieRecord
|
||||
{
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace BizHawk.Client.Common
|
|||
/// Captures savestates and manages the logic of adding, retrieving,
|
||||
/// invalidating/clearing of states. Also does memory management and limiting of states
|
||||
/// </summary>
|
||||
public class TasStateManager : IDisposable
|
||||
public class TasStateManager : IStateManager
|
||||
{
|
||||
// TODO: pass this in, and find a solution to a stale reference (this is instantiated BEFORE a new core instance is made, making this one stale if it is simply set in the constructor
|
||||
private IStatable Core => Global.Emulator.AsStatable();
|
||||
|
@ -27,7 +27,7 @@ namespace BizHawk.Client.Common
|
|||
InvalidateCallback?.Invoke(index);
|
||||
}
|
||||
|
||||
internal NDBDatabase NdbDatabase { get; set; }
|
||||
public NDBDatabase NdbDatabase { get; private set; }
|
||||
private Guid _guid = Guid.NewGuid();
|
||||
private SortedList<int, StateManagerState> _states = new SortedList<int, StateManagerState>();
|
||||
|
||||
|
|
Loading…
Reference in New Issue