misc cleanups in Bk2Movie and TasMovie
This commit is contained in:
parent
e29b02a472
commit
c6b39492a0
|
@ -184,35 +184,33 @@ namespace BizHawk.Client.Common
|
||||||
Directory.CreateDirectory(file.Directory.ToString());
|
Directory.CreateDirectory(file.Directory.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var bs = new BinaryStateSaver(fn, false))
|
using var bs = new BinaryStateSaver(fn, 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, WriteInputLog);
|
||||||
|
|
||||||
|
if (StartsFromSavestate)
|
||||||
{
|
{
|
||||||
bs.PutLump(BinaryStateLump.Movieheader, tw => tw.WriteLine(Header.ToString()));
|
if (TextSavestate != null)
|
||||||
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, WriteInputLog);
|
|
||||||
|
|
||||||
if (StartsFromSavestate)
|
|
||||||
{
|
{
|
||||||
if (TextSavestate != null)
|
bs.PutLump(BinaryStateLump.CorestateText, (TextWriter tw) => tw.Write(TextSavestate));
|
||||||
{
|
|
||||||
bs.PutLump(BinaryStateLump.CorestateText, (TextWriter tw) => tw.Write(TextSavestate));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bs.PutLump(BinaryStateLump.Corestate, (BinaryWriter bw) => bw.Write(BinarySavestate));
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SavestateFramebuffer != null)
|
|
||||||
{
|
|
||||||
bs.PutLump(BinaryStateLump.Framebuffer, (BinaryWriter bw) => bw.Write(SavestateFramebuffer));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (StartsFromSaveRam)
|
else
|
||||||
{
|
{
|
||||||
bs.PutLump(BinaryStateLump.MovieSaveRam, (BinaryWriter bw) => bw.Write(SaveRam));
|
bs.PutLump(BinaryStateLump.Corestate, (BinaryWriter bw) => bw.Write(BinarySavestate));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (SavestateFramebuffer != null)
|
||||||
|
{
|
||||||
|
bs.PutLump(BinaryStateLump.Framebuffer, (BinaryWriter bw) => bw.Write(SavestateFramebuffer));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (StartsFromSaveRam)
|
||||||
|
{
|
||||||
|
bs.PutLump(BinaryStateLump.MovieSaveRam, (BinaryWriter bw) => bw.Write(SaveRam));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!backup)
|
if (!backup)
|
||||||
|
|
|
@ -18,20 +18,10 @@ namespace BizHawk.Client.Common
|
||||||
Log.Clear();
|
Log.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void StartNewPlayback()
|
public void StartNewPlayback() => Mode = MovieMode.Play;
|
||||||
{
|
public void SwitchToRecord() => Mode = MovieMode.Record;
|
||||||
Mode = MovieMode.Play;
|
public void SwitchToPlay() => Mode = MovieMode.Play;
|
||||||
}
|
public void FinishedMode() => Mode = MovieMode.Finished;
|
||||||
|
|
||||||
public virtual void SwitchToRecord()
|
|
||||||
{
|
|
||||||
Mode = MovieMode.Record;
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual void SwitchToPlay()
|
|
||||||
{
|
|
||||||
Mode = MovieMode.Play;
|
|
||||||
}
|
|
||||||
|
|
||||||
public virtual bool Stop(bool saveChanges = true)
|
public virtual bool Stop(bool saveChanges = true)
|
||||||
{
|
{
|
||||||
|
@ -50,10 +40,5 @@ namespace BizHawk.Client.Common
|
||||||
|
|
||||||
return saved;
|
return saved;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void FinishedMode()
|
|
||||||
{
|
|
||||||
Mode = MovieMode.Finished;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,4 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
using BizHawk.Emulation.Common;
|
using BizHawk.Emulation.Common;
|
||||||
using BizHawk.Emulation.Cores.Nintendo.Gameboy;
|
using BizHawk.Emulation.Cores.Nintendo.Gameboy;
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Security.AccessControl;
|
using System.Security.AccessControl;
|
||||||
|
using System.Text;
|
||||||
using BizHawk.Common;
|
using BizHawk.Common;
|
||||||
|
|
||||||
namespace BizHawk.Client.Common
|
namespace BizHawk.Client.Common
|
||||||
|
@ -30,6 +31,36 @@ namespace BizHawk.Client.Common
|
||||||
|
|
||||||
return new ListStringLog();
|
return new ListStringLog();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int? DivergentPoint(this IStringLog currentLog, IStringLog newLog)
|
||||||
|
{
|
||||||
|
int max = newLog.Count;
|
||||||
|
if (currentLog.Count < newLog.Count)
|
||||||
|
{
|
||||||
|
max = currentLog.Count;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < max; i++)
|
||||||
|
{
|
||||||
|
if (newLog[i] != currentLog[i])
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static string ToInputLog(this IStringLog log)
|
||||||
|
{
|
||||||
|
var sb = new StringBuilder();
|
||||||
|
foreach (var record in log)
|
||||||
|
{
|
||||||
|
sb.AppendLine(record);
|
||||||
|
}
|
||||||
|
|
||||||
|
return sb.ToString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IStringLog : IDisposable, IEnumerable<string>
|
public interface IStringLog : IDisposable, IEnumerable<string>
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
namespace BizHawk.Client.Common
|
namespace BizHawk.Client.Common
|
||||||
|
@ -19,59 +18,57 @@ namespace BizHawk.Client.Common
|
||||||
Directory.CreateDirectory(file.Directory.ToString());
|
Directory.CreateDirectory(file.Directory.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var bs = new BinaryStateSaver(fn, false))
|
using var bs = new BinaryStateSaver(fn, 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, WriteInputLog);
|
||||||
|
|
||||||
|
// TasProj extras
|
||||||
|
var settings = JsonConvert.SerializeObject(TasStateManager.Settings);
|
||||||
|
bs.PutLump(BinaryStateLump.StateHistorySettings, tw => tw.WriteLine(settings));
|
||||||
|
|
||||||
|
bs.PutLump(BinaryStateLump.LagLog, tw => TasLagLog.Save(tw));
|
||||||
|
bs.PutLump(BinaryStateLump.Markers, tw => tw.WriteLine(Markers.ToString()));
|
||||||
|
|
||||||
|
if (StartsFromSavestate)
|
||||||
{
|
{
|
||||||
bs.PutLump(BinaryStateLump.Movieheader, tw => tw.WriteLine(Header.ToString()));
|
if (TextSavestate != null)
|
||||||
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, WriteInputLog);
|
|
||||||
|
|
||||||
// TasProj extras
|
|
||||||
var settings = JsonConvert.SerializeObject(TasStateManager.Settings);
|
|
||||||
bs.PutLump(BinaryStateLump.StateHistorySettings, tw => tw.WriteLine(settings));
|
|
||||||
|
|
||||||
bs.PutLump(BinaryStateLump.LagLog, tw => TasLagLog.Save(tw));
|
|
||||||
bs.PutLump(BinaryStateLump.Markers, tw => tw.WriteLine(Markers.ToString()));
|
|
||||||
|
|
||||||
if (StartsFromSavestate)
|
|
||||||
{
|
{
|
||||||
if (TextSavestate != null)
|
bs.PutLump(BinaryStateLump.CorestateText, (TextWriter tw) => tw.Write(TextSavestate));
|
||||||
{
|
|
||||||
bs.PutLump(BinaryStateLump.CorestateText, (TextWriter tw) => tw.Write(TextSavestate));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
bs.PutLump(BinaryStateLump.Corestate, (BinaryWriter bw) => bw.Write(BinarySavestate));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (StartsFromSaveRam)
|
else
|
||||||
{
|
{
|
||||||
bs.PutLump(BinaryStateLump.MovieSaveRam, (BinaryWriter bw) => bw.Write(SaveRam));
|
bs.PutLump(BinaryStateLump.Corestate, (BinaryWriter bw) => bw.Write(BinarySavestate));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else if (StartsFromSaveRam)
|
||||||
|
{
|
||||||
|
bs.PutLump(BinaryStateLump.MovieSaveRam, (BinaryWriter bw) => bw.Write(SaveRam));
|
||||||
|
}
|
||||||
|
|
||||||
if (ClientSettingsForSave != null)
|
if (ClientSettingsForSave != null)
|
||||||
{
|
{
|
||||||
var clientSettingsJson = ClientSettingsForSave();
|
var clientSettingsJson = ClientSettingsForSave();
|
||||||
bs.PutLump(BinaryStateLump.ClientSettings, (TextWriter tw) => tw.Write(clientSettingsJson));
|
bs.PutLump(BinaryStateLump.ClientSettings, (TextWriter tw) => tw.Write(clientSettingsJson));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (VerificationLog.Any())
|
if (VerificationLog.Any())
|
||||||
{
|
{
|
||||||
bs.PutLump(BinaryStateLump.VerificationLog, tw => tw.WriteLine(InputLogToString(VerificationLog)));
|
bs.PutLump(BinaryStateLump.VerificationLog, tw => tw.WriteLine(VerificationLog.ToInputLog()));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Branches.Any())
|
if (Branches.Any())
|
||||||
{
|
{
|
||||||
Branches.Save(bs);
|
Branches.Save(bs);
|
||||||
}
|
}
|
||||||
|
|
||||||
bs.PutLump(BinaryStateLump.Session, tw => tw.WriteLine(JsonConvert.SerializeObject(Session)));
|
bs.PutLump(BinaryStateLump.Session, tw => tw.WriteLine(JsonConvert.SerializeObject(Session)));
|
||||||
|
|
||||||
if (TasStateManager.Settings.SaveStateHistory && !backup)
|
if (TasStateManager.Settings.SaveStateHistory && !backup)
|
||||||
{
|
{
|
||||||
bs.PutLump(BinaryStateLump.StateHistory, bw => TasStateManager.Save(bw));
|
bs.PutLump(BinaryStateLump.StateHistory, bw => TasStateManager.Save(bw));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!backup)
|
if (!backup)
|
||||||
|
@ -293,16 +290,5 @@ namespace BizHawk.Client.Common
|
||||||
Markers.Clear();
|
Markers.Clear();
|
||||||
ChangeLog.ClearLog();
|
ChangeLog.ClearLog();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string InputLogToString(IStringLog log)
|
|
||||||
{
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
foreach (var record in log)
|
|
||||||
{
|
|
||||||
sb.AppendLine(record);
|
|
||||||
}
|
|
||||||
|
|
||||||
return sb.ToString();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,26 +58,6 @@ namespace BizHawk.Client.Common
|
||||||
Markers.Add(0, startsFromSavestate ? "Savestate" : "Power on");
|
Markers.Add(0, startsFromSavestate ? "Savestate" : "Power on");
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: use LogGenerators rather than string comparisons
|
|
||||||
private int? DivergentPoint(IStringLog currentLog, IStringLog newLog)
|
|
||||||
{
|
|
||||||
int max = newLog.Count;
|
|
||||||
if (currentLog.Count < newLog.Count)
|
|
||||||
{
|
|
||||||
max = currentLog.Count;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < max; i++)
|
|
||||||
{
|
|
||||||
if (newLog[i] != currentLog[i])
|
|
||||||
{
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void StartNewRecording()
|
public override void StartNewRecording()
|
||||||
{
|
{
|
||||||
ClearTasprojExtras();
|
ClearTasprojExtras();
|
||||||
|
@ -87,16 +67,6 @@ namespace BizHawk.Client.Common
|
||||||
base.StartNewRecording();
|
base.StartNewRecording();
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void SwitchToPlay()
|
|
||||||
{
|
|
||||||
Mode = MovieMode.Play;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override void SwitchToRecord()
|
|
||||||
{
|
|
||||||
Mode = MovieMode.Record;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Removes lag log and greenzone after this frame
|
/// Removes lag log and greenzone after this frame
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -202,10 +172,7 @@ namespace BizHawk.Client.Common
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IStringLog GetLogEntries()
|
public IStringLog GetLogEntries() => Log;
|
||||||
{
|
|
||||||
return Log;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int? _timelineBranchFrame;
|
private int? _timelineBranchFrame;
|
||||||
|
|
||||||
|
@ -434,7 +401,7 @@ namespace BizHawk.Client.Common
|
||||||
|
|
||||||
public void LoadBranch(TasBranch branch)
|
public void LoadBranch(TasBranch branch)
|
||||||
{
|
{
|
||||||
int? divergentPoint = DivergentPoint(Log, branch.InputLog);
|
int? divergentPoint = Log.DivergentPoint(branch.InputLog);
|
||||||
|
|
||||||
Log?.Dispose();
|
Log?.Dispose();
|
||||||
Log = branch.InputLog.Clone();
|
Log = branch.InputLog.Clone();
|
||||||
|
@ -508,15 +475,8 @@ namespace BizHawk.Client.Common
|
||||||
Changes = true;
|
Changes = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ClearChanges()
|
public void ClearChanges() => Changes = false;
|
||||||
{
|
public void FlagChanges() => Changes = true;
|
||||||
Changes = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void FlagChanges()
|
|
||||||
{
|
|
||||||
Changes = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue