Movie - don't expose the log directly, clean up, and remove StateVisualizer since I've given up on working on it!
This commit is contained in:
parent
4cb01d8ed4
commit
c95732ed31
|
@ -18,6 +18,7 @@ namespace BizHawk.Client.Common
|
|||
bool Loaded { get; }
|
||||
|
||||
ulong Rerecords { get; set; }
|
||||
IMovieHeader Header { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -78,6 +79,7 @@ namespace BizHawk.Client.Common
|
|||
#endregion
|
||||
|
||||
#region Dubious, should reconsider
|
||||
|
||||
void CommitFrame(int frameNum, IController source); // Why pass in frameNum? Calling api
|
||||
void PokeFrame(int frameNum, string input); // Why does this exist as something different than Commit Frame?
|
||||
LoadStateResult CheckTimeLines(TextReader reader, bool onlyGuid, bool ignoreGuidMismatch, out string errorMessage); // No need to return a status, no reason to have hacky flags, no need to pass a textreader
|
||||
|
@ -89,9 +91,6 @@ namespace BizHawk.Client.Common
|
|||
|
||||
string GetInput(int frame); // Should be a property of a Record object
|
||||
|
||||
IMovieHeader Header { get; } // Expose IMovieHEader instead
|
||||
MovieLog LogDump { get; } // Don't expose this!!!
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -414,11 +414,6 @@ namespace BizHawk.Client.Common
|
|||
|
||||
#region Public Misc Methods
|
||||
|
||||
public MovieLog LogDump
|
||||
{
|
||||
get { return _log; }
|
||||
}
|
||||
|
||||
public void PokeFrame(int frameNum, string input)
|
||||
{
|
||||
_changes = true;
|
||||
|
|
|
@ -81,11 +81,13 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
InitState = state;
|
||||
}
|
||||
|
||||
if (Global.Emulator.Frame < StateFirstIndex)
|
||||
{
|
||||
_state_records.Clear();
|
||||
_state_records.Add(new StateRecord(Global.Emulator.Frame, state));
|
||||
}
|
||||
|
||||
if (Global.Emulator.Frame > StateLastIndex)
|
||||
{
|
||||
if (StateSizeInBytes + state.Length > MAXSTATERECORDSIZE)
|
||||
|
@ -93,6 +95,7 @@ namespace BizHawk.Client.Common
|
|||
// Discard the oldest state to save space.
|
||||
_state_records.RemoveAt(0);
|
||||
}
|
||||
|
||||
_state_records.Add(new StateRecord(Global.Emulator.Frame,state));
|
||||
}
|
||||
}
|
||||
|
@ -101,7 +104,7 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
if (frameNum < StateLastIndex && (frameNum < StateFirstIndex || frame != _movie_records[frameNum]))
|
||||
{
|
||||
TruncateStates(frameNum+1);
|
||||
TruncateStates(frameNum + 1);
|
||||
}
|
||||
|
||||
if (_movie_records.Count > frameNum)
|
||||
|
@ -123,12 +126,10 @@ namespace BizHawk.Client.Common
|
|||
if (frame <= StateFirstIndex)
|
||||
{
|
||||
_state_records.Clear();
|
||||
//Global.MovieSession.Movie.RewindToFrame(0); //TODO: unbreak this, also don't do it this way
|
||||
}
|
||||
else
|
||||
{
|
||||
_state_records.RemoveRange(frame - StateFirstIndex, StateLastIndex - frame + 1);
|
||||
//Global.MovieSession.Movie.RewindToFrame(frame); //TODO: unbreak this, also don't do it this way
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -209,7 +210,7 @@ namespace BizHawk.Client.Common
|
|||
|
||||
#region private fields
|
||||
|
||||
private class StateRecord
|
||||
private sealed class StateRecord
|
||||
{
|
||||
public StateRecord(int index, byte[] state)
|
||||
{
|
||||
|
@ -226,8 +227,8 @@ namespace BizHawk.Client.Common
|
|||
private readonly List<string> _movie_records = new List<string>();
|
||||
private readonly List<StateRecord> _state_records = new List<StateRecord>();
|
||||
|
||||
//TODO: Make this size limit configurable by the user
|
||||
private const int MAXSTATERECORDSIZE = 512*1024*1024; //To limit memory usage.
|
||||
// TODO: Make this size limit configurable by the user
|
||||
private const int MAXSTATERECORDSIZE = 512 * 1024 * 1024; //To limit memory usage.
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
|
|
@ -590,7 +590,6 @@
|
|||
<Compile Include="tools\SNES\SNESGraphicsViewer.cs">
|
||||
<SubType>Component</SubType>
|
||||
</Compile>
|
||||
<Compile Include="tools\StateVisualizer.cs" />
|
||||
<Compile Include="tools\TI83\TI83KeyPad.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
|
|
@ -1,187 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.IO;
|
||||
|
||||
using BizHawk.Client.Common;
|
||||
|
||||
namespace BizHawk.Client.EmuHawk
|
||||
{
|
||||
class StateVisualizer
|
||||
{
|
||||
public StateVisualizer()
|
||||
{
|
||||
TimeLine movietimeline = new TimeLine(Global.MovieSession.Movie.LogDump);
|
||||
|
||||
Timelines = new List<TimeLine> {movietimeline};
|
||||
|
||||
//Load all 10 saveslots and process
|
||||
for (int i = 0; i < 10; i++)
|
||||
{
|
||||
string name = "QuickSave" + i.ToString();
|
||||
string path = PathManager.SaveStatePrefix(Global.Game) + "." + name + ".State";
|
||||
if (File.Exists(path))
|
||||
{
|
||||
Movie movie = new Movie();
|
||||
LoadLogFromSavestateText(movie, path);
|
||||
AddLog(movie.LogDump, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadLogFromSavestateText(Movie movie, string path)
|
||||
{
|
||||
using (var reader = new StreamReader(path))
|
||||
{
|
||||
movie.LoadLogFromSavestateText(reader, Global.MovieSession.MultiTrack.IsActive);
|
||||
}
|
||||
}
|
||||
|
||||
public int TimeLineCount
|
||||
{
|
||||
get
|
||||
{
|
||||
return Timelines.Count;
|
||||
}
|
||||
}
|
||||
|
||||
private void AddLog(MovieLog log, int? slot)
|
||||
{
|
||||
sort();
|
||||
|
||||
bool added = false;
|
||||
foreach (TimeLine timeline in Timelines)
|
||||
{
|
||||
if (timeline.TryAddToTimeline(log, slot))
|
||||
{
|
||||
added = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!added)
|
||||
{
|
||||
TimeLine t = new TimeLine(log);
|
||||
Timelines.Add(t);
|
||||
}
|
||||
}
|
||||
|
||||
private void sort()
|
||||
{
|
||||
Timelines = Timelines.OrderByDescending(x => x.Length).ToList();
|
||||
}
|
||||
|
||||
List<TimeLine> Timelines; //MovieLogs of all savestates and the loaded movie
|
||||
|
||||
//Represents a single timeline that consists of at least 1 slot
|
||||
private class TimeLine
|
||||
{
|
||||
public TimeLine(MovieLog log, int? slot_number = null)
|
||||
{
|
||||
timeline = new Event(log, slot_number);
|
||||
subevents = new List<Event>();
|
||||
}
|
||||
|
||||
private Event timeline;
|
||||
private List<Event> subevents;
|
||||
|
||||
private class Event
|
||||
{
|
||||
public int? Slot;
|
||||
public MovieLog Log;
|
||||
|
||||
public Event(MovieLog log, int? slot)
|
||||
{
|
||||
Slot = slot;
|
||||
Log = log;
|
||||
}
|
||||
|
||||
public Event()
|
||||
{
|
||||
Slot = null;
|
||||
Log = new MovieLog();
|
||||
}
|
||||
}
|
||||
|
||||
public int Points
|
||||
{
|
||||
get
|
||||
{
|
||||
return subevents.Count + 1;
|
||||
}
|
||||
}
|
||||
|
||||
public int Length
|
||||
{
|
||||
get
|
||||
{
|
||||
return timeline.Log.Length;
|
||||
}
|
||||
}
|
||||
|
||||
public int? GetPoint(int position)
|
||||
{
|
||||
sort();
|
||||
if (position < subevents.Count)
|
||||
{
|
||||
return subevents[position].Log.Length;
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryAddToTimeline(MovieLog log, int? slot)
|
||||
{
|
||||
bool isdifferent = false;
|
||||
if (log.Length < timeline.Log.Length)
|
||||
{
|
||||
for (int i = 0; i < log.Length; i++)
|
||||
{
|
||||
if (log[i] != timeline.Log[i])
|
||||
{
|
||||
isdifferent = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isdifferent)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
subevents.Add(new Event(log, slot));
|
||||
sort();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < timeline.Log.Length; i++)
|
||||
{
|
||||
if (log[i] != timeline.Log[i])
|
||||
{
|
||||
isdifferent = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (isdifferent)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
subevents.Add(timeline);
|
||||
timeline = new Event(log, slot);
|
||||
sort();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void sort()
|
||||
{
|
||||
subevents = subevents.OrderByDescending(x => x.Log.Length).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue