TAStudio - add capacity and SaveGreenzone settings to the greenzone and make greenzone respect the capacity. When adding a new state that exceeds capacity, the first one added will be removed (more intelligent logic will be done later). Respect the SaveGreenzone flag when saving and loading. Save and load greenzone settings to tasproj file, still todo: UI to let user manage greenzone settings
This commit is contained in:
parent
4c9c8e3cb1
commit
9f94ee1e33
|
@ -23,6 +23,7 @@ namespace BizHawk.Client.Common
|
|||
// TasMovie
|
||||
LagLog,
|
||||
Greenzone,
|
||||
GreenzoneSettings,
|
||||
Markers
|
||||
}
|
||||
|
||||
|
@ -57,6 +58,7 @@ namespace BizHawk.Client.Common
|
|||
// TasMovie
|
||||
LumpNames[BinaryStateLump.LagLog] = "LagLog";
|
||||
LumpNames[BinaryStateLump.Greenzone] = "GreenZone";
|
||||
LumpNames[BinaryStateLump.GreenzoneSettings] = "GreenZoneSettings";
|
||||
LumpNames[BinaryStateLump.Markers] = "Markers";
|
||||
}
|
||||
|
||||
|
|
|
@ -28,7 +28,13 @@ namespace BizHawk.Client.Common
|
|||
|
||||
bs.PutLump(BinaryStateLump.Input, tw => tw.WriteLine(RawInputLog()));
|
||||
|
||||
bs.PutLump(BinaryStateLump.Greenzone, (BinaryWriter bw) => bw.Write(StateManager.ToArray()));
|
||||
|
||||
bs.PutLump(BinaryStateLump.GreenzoneSettings, tw => tw.WriteLine(StateManager.Settings.ToString()));
|
||||
if (StateManager.Settings.SaveGreenzone)
|
||||
{
|
||||
bs.PutLump(BinaryStateLump.Greenzone, (BinaryWriter bw) => bw.Write(StateManager.ToArray()));
|
||||
}
|
||||
|
||||
bs.PutLump(BinaryStateLump.LagLog, (BinaryWriter bw) => bw.Write(LagLog.ToByteArray()));
|
||||
bs.PutLump(BinaryStateLump.Markers, tw => tw.WriteLine(Markers.ToString()));
|
||||
|
||||
|
@ -145,11 +151,19 @@ namespace BizHawk.Client.Common
|
|||
LagLog = bytes.ToBools().ToList();
|
||||
});
|
||||
|
||||
bl.GetLump(BinaryStateLump.Greenzone, false, delegate(BinaryReader br)
|
||||
bl.GetLump(BinaryStateLump.GreenzoneSettings, false, delegate(TextReader tr)
|
||||
{
|
||||
StateManager.FromArray(br.BaseStream.ReadAllBytes());
|
||||
StateManager.Settings.PopulateFromString(tr.ReadToEnd());
|
||||
});
|
||||
|
||||
if (StateManager.Settings.SaveGreenzone)
|
||||
{
|
||||
bl.GetLump(BinaryStateLump.Greenzone, false, delegate(BinaryReader br)
|
||||
{
|
||||
StateManager.FromArray(br.BaseStream.ReadAllBytes());
|
||||
});
|
||||
}
|
||||
|
||||
bl.GetLump(BinaryStateLump.Markers, false, delegate(TextReader tr)
|
||||
{
|
||||
string line;
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
|
@ -13,6 +15,13 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
private readonly Dictionary<int, byte[]> States = new Dictionary<int, byte[]>();
|
||||
|
||||
public TasStateManager()
|
||||
{
|
||||
Settings = new ManagerSettings();
|
||||
}
|
||||
|
||||
public ManagerSettings Settings { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Retrieves the savestate for the given frame,
|
||||
/// If this frame does not have a state currently, will return an empty array
|
||||
|
@ -45,6 +54,11 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
else
|
||||
{
|
||||
if (Used + state.Length >= Settings.Cap)
|
||||
{
|
||||
States.Remove(0);
|
||||
}
|
||||
|
||||
States.Add(frame, state);
|
||||
}
|
||||
}
|
||||
|
@ -123,5 +137,54 @@ namespace BizHawk.Client.Common
|
|||
States.Add(frame, state);
|
||||
}
|
||||
}
|
||||
|
||||
private int Used
|
||||
{
|
||||
get
|
||||
{
|
||||
return States.Sum(s => s.Value.Length);
|
||||
}
|
||||
}
|
||||
|
||||
public class ManagerSettings
|
||||
{
|
||||
public ManagerSettings()
|
||||
{
|
||||
SaveGreenzone = true;
|
||||
Capacitymb = 512;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not to save greenzone information to disk
|
||||
/// </summary>
|
||||
public bool SaveGreenzone { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The total amount of memory to devote to greenzone in megabytes
|
||||
/// </summary>
|
||||
public int Capacitymb { get; set; }
|
||||
|
||||
public int Cap
|
||||
{
|
||||
get { return Capacitymb * 1024 * 1024; }
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
sb.AppendLine(SaveGreenzone.ToString());
|
||||
sb.AppendLine(Capacitymb.ToString());
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public void PopulateFromString(string settings)
|
||||
{
|
||||
var lines = settings.Split(new [] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries);
|
||||
SaveGreenzone = bool.Parse(lines[0]);
|
||||
Capacitymb = int.Parse(lines[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue