TasMovie - some reorg in preparation for actual progress
This commit is contained in:
parent
34290be1dc
commit
7173447e8a
|
@ -5,49 +5,13 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
public class MovieRecord
|
||||
{
|
||||
private byte[] _state = new byte[0];
|
||||
|
||||
public MovieRecord(string serializedInput, bool captureState)
|
||||
{
|
||||
SerializedInput = serializedInput;
|
||||
if (captureState)
|
||||
{
|
||||
CaptureSate();
|
||||
}
|
||||
}
|
||||
|
||||
public string SerializedInput { get; private set; }
|
||||
public bool Lagged { get; private set; }
|
||||
|
||||
public void ClearInput()
|
||||
{
|
||||
SerializedInput = string.Empty;
|
||||
}
|
||||
|
||||
public void SetInput(string input)
|
||||
{
|
||||
SerializedInput = input ?? string.Empty;
|
||||
}
|
||||
|
||||
public void CaptureSate()
|
||||
{
|
||||
Lagged = Global.Emulator.IsLagFrame;
|
||||
_state = (byte[])Global.Emulator.SaveStateBinary().Clone();
|
||||
}
|
||||
|
||||
public IEnumerable<byte> State
|
||||
{
|
||||
get { return _state; }
|
||||
}
|
||||
public byte[] State { get; set; }
|
||||
public bool Lagged { get; set; }
|
||||
public string LogEntry { get; set; }
|
||||
|
||||
public bool HasState
|
||||
{
|
||||
get { return State.Any(); }
|
||||
}
|
||||
|
||||
public void ClearState()
|
||||
{
|
||||
_state = new byte[0];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,53 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
public class MovieRecordList : List<MovieRecord>
|
||||
{
|
||||
/// <summary>
|
||||
/// DONT USE ME RIGHT NOW
|
||||
/// </summary>
|
||||
public void WriteToText(TextWriter tw)
|
||||
{
|
||||
tw.WriteLine("[Input]");
|
||||
tw.WriteLine("Frame {0}", Global.Emulator.Frame);
|
||||
ForEach(record => tw.WriteLine(record.ToString()));
|
||||
tw.WriteLine("[/Input]");
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
sb
|
||||
.AppendLine("[Input]")
|
||||
|
||||
.Append("Frame ")
|
||||
.Append(Global.Emulator.Frame)
|
||||
.AppendLine();
|
||||
|
||||
ForEach(record => sb.Append(record.ToString()));
|
||||
|
||||
sb.AppendLine("[/Input]");
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public void Truncate(int index)
|
||||
{
|
||||
if (index < Count)
|
||||
{
|
||||
RemoveRange(index, Count - index);
|
||||
}
|
||||
}
|
||||
|
||||
public void TruncateStates(int index)
|
||||
{
|
||||
for (int i = index; i < Count; i++)
|
||||
{
|
||||
this[i].ClearState();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,142 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
using BizHawk.Common;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
public partial class TasMovie
|
||||
{
|
||||
protected override void Write(string fn)
|
||||
{
|
||||
var file = new FileInfo(fn);
|
||||
if (!file.Directory.Exists)
|
||||
{
|
||||
Directory.CreateDirectory(file.Directory.ToString());
|
||||
}
|
||||
|
||||
using (var fs = new FileStream(fn, FileMode.Create, FileAccess.Write))
|
||||
using (var bs = new BinaryStateSaver(fs, false))
|
||||
{
|
||||
bs.PutLump(BinaryStateLump.Movieheader, tw => tw.WriteLine(Header.ToString()));
|
||||
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()));
|
||||
|
||||
if (StartsFromSavestate)
|
||||
{
|
||||
if (TextSavestate != null)
|
||||
{
|
||||
bs.PutLump(BinaryStateLump.CorestateText, (TextWriter tw) => tw.Write(TextSavestate));
|
||||
}
|
||||
else
|
||||
{
|
||||
bs.PutLump(BinaryStateLump.Corestate, (BinaryWriter bw) => bw.Write(BinarySavestate));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Changes = false;
|
||||
}
|
||||
|
||||
public override bool Load()
|
||||
{
|
||||
var file = new FileInfo(Filename);
|
||||
if (!file.Exists)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
using (var bl = BinaryStateLoader.LoadAndDetect(Filename, true))
|
||||
{
|
||||
if (bl == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
ClearBeforeLoad();
|
||||
ClearTasprojExtrasBeforeLoad();
|
||||
|
||||
bl.GetLump(BinaryStateLump.Movieheader, true, delegate(TextReader tr)
|
||||
{
|
||||
string line;
|
||||
while ((line = tr.ReadLine()) != null)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(line))
|
||||
{
|
||||
var pair = line.Split(new[] { ' ' }, 2, StringSplitOptions.RemoveEmptyEntries);
|
||||
|
||||
if (pair.Length > 1)
|
||||
{
|
||||
Header.Add(pair[0], pair[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
bl.GetLump(BinaryStateLump.Comments, true, delegate(TextReader tr)
|
||||
{
|
||||
string line;
|
||||
while ((line = tr.ReadLine()) != null)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(line))
|
||||
{
|
||||
Comments.Add(line);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
bl.GetLump(BinaryStateLump.Subtitles, true, delegate(TextReader tr)
|
||||
{
|
||||
string line;
|
||||
while ((line = tr.ReadLine()) != null)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(line))
|
||||
{
|
||||
Subtitles.AddFromString(line);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
bl.GetLump(BinaryStateLump.SyncSettings, true, delegate(TextReader tr)
|
||||
{
|
||||
string line;
|
||||
while ((line = tr.ReadLine()) != null)
|
||||
{
|
||||
if (!string.IsNullOrWhiteSpace(line))
|
||||
{
|
||||
SyncSettingsJson = line;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
bl.GetLump(BinaryStateLump.Input, true, delegate(TextReader tr)
|
||||
{
|
||||
var errorMessage = string.Empty;
|
||||
ExtractInputLog(tr, out errorMessage);
|
||||
});
|
||||
|
||||
if (StartsFromSavestate)
|
||||
{
|
||||
bl.GetCoreState(
|
||||
delegate(BinaryReader br)
|
||||
{
|
||||
BinarySavestate = br.ReadBytes((int)br.BaseStream.Length);
|
||||
},
|
||||
delegate(TextReader tr)
|
||||
{
|
||||
TextSavestate = tr.ReadToEnd();
|
||||
});
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private void ClearTasprojExtrasBeforeLoad()
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
}
|
|
@ -9,13 +9,11 @@ using BizHawk.Emulation.Common;
|
|||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
public class TasMovie : Bk2Movie
|
||||
public sealed partial class TasMovie : Bk2Movie
|
||||
{
|
||||
public TasMovie(string path)
|
||||
: base(path)
|
||||
{
|
||||
private readonly List<bool> LagLog = new List<bool>();
|
||||
|
||||
}
|
||||
public TasMovie(string path) : base(path) { }
|
||||
|
||||
public TasMovie()
|
||||
: base()
|
||||
|
@ -25,10 +23,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
public override string PreferredExtension
|
||||
{
|
||||
get
|
||||
{
|
||||
return Extension;
|
||||
}
|
||||
get { return Extension; }
|
||||
}
|
||||
|
||||
public new const string Extension = "tasproj";
|
||||
|
@ -37,14 +32,15 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
get
|
||||
{
|
||||
// TODO
|
||||
return new MovieRecord("", false);
|
||||
return new MovieRecord // TODO
|
||||
{
|
||||
State = null,
|
||||
LogEntry = "",
|
||||
Lagged = false
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public void SetBoolButton(int index, string button, bool value)
|
||||
{
|
||||
// TODO
|
||||
}
|
||||
// _state = (byte[])Global.Emulator.SaveStateBinary().Clone();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue