don't load entire inputlog into a string when parking it in a savestate

This commit is contained in:
zeromus 2016-01-10 23:08:13 -06:00
parent e1ddb51826
commit a355f78631
6 changed files with 32 additions and 20 deletions

View File

@ -219,7 +219,7 @@ namespace BizHawk.Client.Common
{
if (Movie.IsActive)
{
writer.Write(Movie.GetInputLog());
Movie.WriteInputLog(writer);
}
}

View File

@ -183,7 +183,7 @@ namespace BizHawk.Client.Common
bs.PutLump(BinaryStateLump.Subtitles, tw => tw.WriteLine(Subtitles.ToString()));
bs.PutLump(BinaryStateLump.SyncSettings, tw => tw.WriteLine(_syncSettingsJson));
bs.PutLump(BinaryStateLump.Input, tw => tw.WriteLine(RawInputLog()));
bs.PutLump(BinaryStateLump.Input, tw => WriteInputLog(tw));
if (StartsFromSavestate)
{

View File

@ -14,14 +14,19 @@ namespace BizHawk.Client.Common
public string GetInputLog()
{
var sb = new StringBuilder();
sb.AppendLine("[Input]");
sb.Append(RawInputLog());
sb.AppendLine("[/Input]");
var writer = new StringWriter(sb);
WriteInputLog(writer);
writer.Flush();
return sb.ToString();
}
public void WriteInputLog(TextWriter writer)
{
writer.WriteLine("[Input]");
WriteRawInputLog(writer);
writer.WriteLine("[/Input]");
}
public string GetInputLogEntry(int frame)
{
if (frame < FrameCount && frame >= 0)
@ -294,20 +299,17 @@ namespace BizHawk.Client.Common
return true;
}
protected StringBuilder RawInputLog()
protected void WriteRawInputLog(TextWriter writer)
{
var lg = new Bk2LogEntryGenerator(LogKey);
lg.SetSource(Global.MovieOutputHardpoint);
var sb = new StringBuilder();
sb.AppendLine(lg.GenerateLogKey());
sb.EnsureCapacity(sb.Capacity + _log.Count);
writer.WriteLine(lg.GenerateLogKey());
foreach (var record in _log)
{
sb.AppendLine(record);
writer.WriteLine(record);
}
return sb;
}
/// <summary>

View File

@ -13,17 +13,22 @@ namespace BizHawk.Client.Common
public string GetInputLog()
{
var sb = new StringBuilder();
var writer = new StringWriter(sb);
WriteInputLog(writer);
writer.Flush();
return sb.ToString();
}
sb.AppendLine("[Input]");
public void WriteInputLog(TextWriter writer)
{
writer.WriteLine("[Input]");
foreach (var record in _log)
{
sb.AppendLine(record);
writer.WriteLine(record);
}
sb.AppendLine("[/Input]");
return sb.ToString();
writer.WriteLine("[/Input]");
}
public string GetInputLogEntry(int frame)

View File

@ -114,6 +114,11 @@ namespace BizHawk.Client.Common
/// <returns>returns a string represntation of the input log in its current state</returns>
string GetInputLog();
/// <summary>
/// Writes the input log directly to the stream, bypassing the need to load it all into ram as a string
/// </summary>
void WriteInputLog(TextWriter writer);
/// <summary>
/// Gets one frame from the input log.
/// </summary>

View File

@ -31,7 +31,7 @@ namespace BizHawk.Client.Common
bs.PutLump(BinaryStateLump.Comments, tw => tw.WriteLine(CommentsString()));
bs.PutLump(BinaryStateLump.Subtitles, tw => tw.WriteLine(Subtitles.ToString()));
bs.PutLump(BinaryStateLump.SyncSettings, tw => tw.WriteLine(SyncSettingsJson));
bs.PutLump(BinaryStateLump.Input, tw => tw.WriteLine(RawInputLog()));
bs.PutLump(BinaryStateLump.Input, tw => WriteInputLog(tw));
// TasProj extras
bs.PutLump(BinaryStateLump.StateHistorySettings, tw => tw.WriteLine(StateManager.Settings.ToString()));