TasMovie - save and load lag log to file

This commit is contained in:
adelikat 2014-07-07 19:32:37 +00:00
parent 6d61db045f
commit 96b36cc230
5 changed files with 60 additions and 4 deletions

View File

@ -18,7 +18,11 @@ namespace BizHawk.Client.Common
Movieheader, Movieheader,
Comments, Comments,
Subtitles, Subtitles,
SyncSettings SyncSettings,
// TasMovie
LagLog,
Greenzone
} }
public class BinaryStateFileNames public class BinaryStateFileNames
@ -48,6 +52,10 @@ namespace BizHawk.Client.Common
LumpNames[BinaryStateLump.Comments] = "Comments"; LumpNames[BinaryStateLump.Comments] = "Comments";
LumpNames[BinaryStateLump.Subtitles] = "Subtitles"; LumpNames[BinaryStateLump.Subtitles] = "Subtitles";
LumpNames[BinaryStateLump.SyncSettings] = "SyncSettings"; LumpNames[BinaryStateLump.SyncSettings] = "SyncSettings";
// TasMovie
LumpNames[BinaryStateLump.LagLog] = "LagLog";
LumpNames[BinaryStateLump.Greenzone] = "GreenZone";
} }
public static string Get(BinaryStateLump lump) public static string Get(BinaryStateLump lump)

View File

@ -1,7 +1,10 @@
using System; using System;
using System.IO; using System.IO;
using System.Linq;
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Common.CollectionExtensions;
using BizHawk.Common.IOExtensions;
namespace BizHawk.Client.Common namespace BizHawk.Client.Common
{ {
@ -25,6 +28,8 @@ namespace BizHawk.Client.Common
bs.PutLump(BinaryStateLump.Input, tw => tw.WriteLine(RawInputLog())); bs.PutLump(BinaryStateLump.Input, tw => tw.WriteLine(RawInputLog()));
bs.PutLump(BinaryStateLump.LagLog, (BinaryWriter bw) => bw.Write(LagLog.ToByteArray()));
if (StartsFromSavestate) if (StartsFromSavestate)
{ {
if (TextSavestate != null) if (TextSavestate != null)
@ -118,6 +123,12 @@ namespace BizHawk.Client.Common
ExtractInputLog(tr, out errorMessage); ExtractInputLog(tr, out errorMessage);
}); });
bl.GetLump(BinaryStateLump.LagLog, true, delegate(BinaryReader br)
{
var bytes = br.BaseStream.ReadAllBytes();
LagLog = bytes.ToBools().ToList();
});
if (StartsFromSavestate) if (StartsFromSavestate)
{ {
bl.GetCoreState( bl.GetCoreState(
@ -136,7 +147,13 @@ namespace BizHawk.Client.Common
private void ClearTasprojExtrasBeforeLoad() private void ClearTasprojExtrasBeforeLoad()
{ {
// TODO LagLog.Clear();
StateManager.Clear();
}
private void RestoreLagLog(byte[] buffer)
{
} }
} }
} }

View File

@ -11,7 +11,7 @@ namespace BizHawk.Client.Common
{ {
public sealed partial class TasMovie : Bk2Movie public sealed partial class TasMovie : Bk2Movie
{ {
private readonly List<bool> LagLog = new List<bool>(); private List<bool> LagLog = new List<bool>();
private readonly TasStateManager StateManager = new TasStateManager(); private readonly TasStateManager StateManager = new TasStateManager();
public TasMovie(string path) : base(path) { } public TasMovie(string path) : base(path) { }
@ -37,7 +37,7 @@ namespace BizHawk.Client.Common
{ {
State = StateManager[index], State = StateManager[index],
LogEntry = GetInput(index), LogEntry = GetInput(index),
Lagged = LagLog[index] Lagged = (index < LagLog.Count) ? LagLog[index] : false
}; };
} }
} }

View File

@ -63,5 +63,13 @@ namespace BizHawk.Client.Common
States.Remove(f); States.Remove(f);
} }
} }
/// <summary>
/// Clears all state information
/// </summary>
public void Clear()
{
States.Clear();
}
} }
} }

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -94,5 +95,27 @@ namespace BizHawk.Common.CollectionExtensions
throw new InvalidOperationException("Item not found"); throw new InvalidOperationException("Item not found");
} }
public static byte[] ToByteArray(this IEnumerable<bool> list)
{
var bits = new BitArray(list.ToArray());
byte [] bytes = new byte[bits.Length / 8 + ( bits.Length % 8 == 0 ? 0 : 1 )];
bits.CopyTo(bytes, 0);
return bytes;
}
/// <summary>
/// Converts any byte array into a bit array represented as a list of bools
/// </summary>
public static IEnumerable<bool> ToBools(this byte[] bytes)
{
var bits = new BitArray(bytes);
var bools = new bool[bits.Length];
bits.CopyTo(bools, 0);
return bools;
}
} }
} }