I round of code cleanup on movie related files
This commit is contained in:
parent
894d9e9c45
commit
affc040dbd
|
@ -1,7 +1,5 @@
|
|||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.IO;
|
||||
using BizHawk.Emulation.Common;
|
||||
using System;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
|
@ -24,23 +22,23 @@ namespace BizHawk.Client.Common
|
|||
#region Properties
|
||||
|
||||
/// <summary>
|
||||
/// The total number of frames that count towards the completion time of the movie
|
||||
/// Gets the total number of frames that count towards the completion time of the movie
|
||||
/// Possibly (but unlikely different from InputLogLength (could be infinity, or maybe an implementation automatically discounts empty frames at the end of a movie, etc)
|
||||
/// </summary>
|
||||
double FrameCount { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The Fps used to calculate the time of the movie
|
||||
/// Gets the Fps used to calculate the time of the movie
|
||||
/// </summary>
|
||||
double Fps { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The time calculation based on FrameCount and Fps
|
||||
/// Gets the time calculation based on FrameCount and Fps
|
||||
/// </summary>
|
||||
TimeSpan Time { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Actual length of the input log, should only be used by code that iterates or needs a real length
|
||||
/// Gets the actual length of the input log, should only be used by code that iterates or needs a real length
|
||||
/// </summary>
|
||||
int InputLogLength { get; }
|
||||
|
||||
|
@ -55,6 +53,8 @@ namespace BizHawk.Client.Common
|
|||
void Save();
|
||||
void SaveAs();
|
||||
string GetInputLog();
|
||||
bool CheckTimeLines(TextReader reader, out string errorMessage);
|
||||
bool ExtractInputLog(TextReader reader, out string errorMessage);
|
||||
|
||||
#endregion
|
||||
|
||||
|
@ -96,16 +96,14 @@ namespace BizHawk.Client.Common
|
|||
#region Editing API
|
||||
|
||||
/// <summary>
|
||||
/// Repalces the given frame's input with an empty frame
|
||||
/// Replaces the given frame's input with an empty frame
|
||||
/// </summary>
|
||||
/// <param name="frame"></param>
|
||||
void ClearFrame(int frame);
|
||||
|
||||
/// <summary>
|
||||
/// Adds the given input to the movie
|
||||
/// Note: this edits the input log without the normal movie recording logic applied
|
||||
/// </summary>
|
||||
/// <param name="mg"></param>
|
||||
void AppendFrame(MnemonicsGenerator mg);
|
||||
|
||||
/// <summary>
|
||||
|
@ -124,12 +122,5 @@ namespace BizHawk.Client.Common
|
|||
string GetInput(int frame);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Dubious, should reconsider
|
||||
|
||||
bool CheckTimeLines(TextReader reader, out string errorMessage); //Can we avoid passing a text reader?
|
||||
bool ExtractInputLog(TextReader reader, out string errorMessage); //Is passing a textreader the only reasonable way to do this?
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
|
@ -11,20 +8,19 @@ namespace BizHawk.Client.Common
|
|||
public interface IMovieRecord
|
||||
{
|
||||
/// <summary>
|
||||
/// String representation of the controller input as a series of mnemonics
|
||||
/// Gets or sets the string representation of the controller input as a series of mnemonics
|
||||
/// </summary>
|
||||
string Input { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not this was a lag frame,
|
||||
/// Gets a value indicating whether or not this was a lag frame,
|
||||
/// where lag is the act of the core failing to poll for input (input on lag frames have no affect)
|
||||
/// </summary>
|
||||
bool Lagged { get; }
|
||||
|
||||
/// <summary>
|
||||
/// A savestate for this frame of input
|
||||
/// Gets the Savestate for this frame of input
|
||||
/// </summary>
|
||||
IEnumerable<byte> State { get; }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,10 +1,8 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using BizHawk.Common;
|
||||
using BizHawk.Emulation.Common;
|
||||
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
|
@ -59,7 +57,6 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
else if (Loaded)
|
||||
{
|
||||
|
||||
return _log.Length;
|
||||
}
|
||||
else
|
||||
|
@ -450,7 +447,7 @@ namespace BizHawk.Client.Common
|
|||
return false;
|
||||
}
|
||||
}
|
||||
if (line[0] == '|')
|
||||
else if (line[0] == '|')
|
||||
{
|
||||
_log.AppendFrame(line);
|
||||
}
|
||||
|
@ -617,8 +614,6 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (stateFrame == 0)
|
||||
{
|
||||
stateFrame = log.Length; // In case the frame count failed to parse, revert to using the entire state input log
|
||||
|
@ -707,9 +702,9 @@ namespace BizHawk.Client.Common
|
|||
sw.WriteLine("LoopOffset " + _loopOffset);
|
||||
}
|
||||
|
||||
for (int i = 0; i < _log.Length; i++)
|
||||
foreach (var input in _log)
|
||||
{
|
||||
sw.WriteLine(_log[i]);
|
||||
sw.WriteLine(input);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,13 +7,21 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
public class MovieSession
|
||||
{
|
||||
public MultitrackRecording MultiTrack = new MultitrackRecording();
|
||||
public IMovie Movie;
|
||||
public MovieControllerAdapter MovieControllerAdapter = new MovieControllerAdapter();
|
||||
public Action<string> MessageCallback; //Not Required
|
||||
public Func<string, string, bool> AskYesNoCallback; //Not Required
|
||||
private readonly MultitrackRecording _multiTrack = new MultitrackRecording();
|
||||
private readonly MovieControllerAdapter _movieControllerAdapter = new MovieControllerAdapter();
|
||||
|
||||
public bool ReadOnly = true;
|
||||
public MovieSession()
|
||||
{
|
||||
ReadOnly = true;
|
||||
}
|
||||
|
||||
public MultitrackRecording MultiTrack { get { return _multiTrack; } }
|
||||
public MovieControllerAdapter MovieControllerAdapter { get { return _movieControllerAdapter; } }
|
||||
|
||||
public IMovie Movie { get; set; }
|
||||
public bool ReadOnly { get; set; }
|
||||
public Action<string> MessageCallback { get; set; }
|
||||
public Func<string, string, bool> AskYesNoCallback { get; set; }
|
||||
|
||||
private void Output(string message)
|
||||
{
|
||||
|
@ -23,42 +31,28 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
}
|
||||
|
||||
private bool AskYesNo(string title, string message)
|
||||
public void LatchMultitrackPlayerInput(IController playerSource, MultitrackRewiringControllerAdapter rewiredSource)
|
||||
{
|
||||
if (AskYesNoCallback != null)
|
||||
if (_multiTrack.IsActive)
|
||||
{
|
||||
return AskYesNoCallback(title, message);
|
||||
rewiredSource.PlayerSource = 1;
|
||||
rewiredSource.PlayerTargetMask = 1 << _multiTrack.CurrentPlayer;
|
||||
if (_multiTrack.RecordAll)
|
||||
{
|
||||
rewiredSource.PlayerTargetMask = unchecked((int)0xFFFFFFFF);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
rewiredSource.PlayerSource = -1;
|
||||
}
|
||||
}
|
||||
|
||||
private bool HandleGuidError()
|
||||
{
|
||||
return AskYesNo(
|
||||
"GUID Mismatch error",
|
||||
"The savestate GUID does not match the current movie. Proceed anyway?"
|
||||
);
|
||||
}
|
||||
|
||||
public void LatchMultitrackPlayerInput(IController playerSource, MultitrackRewiringControllerAdapter rewiredSource)
|
||||
{
|
||||
if (MultiTrack.IsActive)
|
||||
{
|
||||
rewiredSource.PlayerSource = 1;
|
||||
rewiredSource.PlayerTargetMask = 1 << (MultiTrack.CurrentPlayer);
|
||||
if (MultiTrack.RecordAll) rewiredSource.PlayerTargetMask = unchecked((int)0xFFFFFFFF);
|
||||
}
|
||||
else rewiredSource.PlayerSource = -1;
|
||||
|
||||
MovieControllerAdapter.LatchPlayerFromSource(rewiredSource, MultiTrack.CurrentPlayer);
|
||||
_movieControllerAdapter.LatchPlayerFromSource(rewiredSource, _multiTrack.CurrentPlayer);
|
||||
}
|
||||
|
||||
public void LatchInputFromPlayer(IController source)
|
||||
{
|
||||
MovieControllerAdapter.LatchFromSource(source);
|
||||
_movieControllerAdapter.LatchFromSource(source);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -71,13 +65,13 @@ namespace BizHawk.Client.Common
|
|||
// Attempting to get a frame past the end of a movie changes the mode to finished
|
||||
if (!Movie.IsFinished)
|
||||
{
|
||||
MovieControllerAdapter.SetControllersAsMnemonic(input);
|
||||
_movieControllerAdapter.SetControllersAsMnemonic(input);
|
||||
}
|
||||
}
|
||||
|
||||
public void StopMovie(bool saveChanges = true)
|
||||
{
|
||||
string message = "Movie ";
|
||||
var message = "Movie ";
|
||||
if (Movie.IsRecording)
|
||||
{
|
||||
message += "recording ";
|
||||
|
@ -96,12 +90,12 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
Output(Path.GetFileName(Movie.Filename) + " written to disk.");
|
||||
}
|
||||
|
||||
Output(message);
|
||||
ReadOnly = true;
|
||||
}
|
||||
}
|
||||
|
||||
//State handling
|
||||
public void HandleMovieSaveState(StreamWriter writer)
|
||||
{
|
||||
if (Movie.IsActive)
|
||||
|
@ -125,10 +119,9 @@ namespace BizHawk.Client.Common
|
|||
{
|
||||
LatchInputFromPlayer(Global.MovieInputSourceAdapter);
|
||||
}
|
||||
|
||||
else if (Movie.IsFinished)
|
||||
{
|
||||
if (Global.Emulator.Frame < Movie.FrameCount) //This scenario can happen from rewinding (suddenly we are back in the movie, so hook back up to the movie
|
||||
if (Global.Emulator.Frame < Movie.FrameCount) // This scenario can happen from rewinding (suddenly we are back in the movie, so hook back up to the movie
|
||||
{
|
||||
Movie.SwitchToPlay();
|
||||
LatchInputFromLog();
|
||||
|
@ -138,12 +131,11 @@ namespace BizHawk.Client.Common
|
|||
LatchInputFromPlayer(Global.MovieInputSourceAdapter);
|
||||
}
|
||||
}
|
||||
|
||||
else if (Movie.IsPlaying)
|
||||
{
|
||||
LatchInputFromLog();
|
||||
|
||||
//Movie may go into finished mode as a result from latching
|
||||
// Movie may go into finished mode as a result from latching
|
||||
if (!Movie.IsFinished)
|
||||
{
|
||||
if (Global.ClientControls["Scrub Input"])
|
||||
|
@ -168,10 +160,9 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
else if (Movie.IsRecording)
|
||||
{
|
||||
if (MultiTrack.IsActive)
|
||||
if (_multiTrack.IsActive)
|
||||
{
|
||||
LatchMultitrackPlayerInput(Global.MovieInputSourceAdapter, Global.MultitrackRewiringControllerAdapter);
|
||||
}
|
||||
|
@ -203,7 +194,7 @@ namespace BizHawk.Client.Common
|
|||
return true;
|
||||
}
|
||||
|
||||
string errorMsg = String.Empty;
|
||||
string errorMsg;
|
||||
|
||||
if (ReadOnly)
|
||||
{
|
||||
|
@ -247,5 +238,4 @@ namespace BizHawk.Client.Common
|
|||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -21,8 +21,7 @@ namespace BizHawk.Client.Common
|
|||
public TasMovie(bool startsFromSavestate = false)
|
||||
{
|
||||
Filename = String.Empty;
|
||||
Header = new MovieHeader();
|
||||
Header.StartsFromSavestate = startsFromSavestate;
|
||||
Header = new MovieHeader { StartsFromSavestate = startsFromSavestate };
|
||||
_records = new MovieRecordList();
|
||||
_mode = Moviemode.Inactive;
|
||||
IsCountingRerecords = true;
|
||||
|
@ -70,7 +69,7 @@ namespace BizHawk.Client.Common
|
|||
int days = seconds / 86400;
|
||||
int hours = seconds / 3600;
|
||||
int minutes = (seconds / 60) % 60;
|
||||
int milliseconds = (int)((dblseconds - (double)seconds) * 1000);
|
||||
int milliseconds = (int)((dblseconds - seconds) * 1000);
|
||||
return new TimeSpan(days, hours, minutes, seconds, milliseconds);
|
||||
}
|
||||
}
|
||||
|
@ -150,7 +149,7 @@ namespace BizHawk.Client.Common
|
|||
public void AppendFrame(MnemonicsGenerator mg)
|
||||
{
|
||||
Changes = true;
|
||||
_records.Add(new MovieRecord()
|
||||
_records.Add(new MovieRecord
|
||||
{
|
||||
Input = mg.GetControllersAsMnemonic(),
|
||||
});
|
||||
|
@ -183,7 +182,6 @@ namespace BizHawk.Client.Common
|
|||
}
|
||||
|
||||
// TODO:
|
||||
|
||||
public double Fps
|
||||
{
|
||||
get
|
||||
|
@ -233,7 +231,7 @@ namespace BizHawk.Client.Common
|
|||
#region Private
|
||||
|
||||
private enum Moviemode { Inactive, Play, Record, Finished };
|
||||
private MovieRecordList _records;
|
||||
private readonly MovieRecordList _records;
|
||||
private Moviemode _mode;
|
||||
private readonly PlatformFrameRates _frameRates = new PlatformFrameRates();
|
||||
|
||||
|
|
Loading…
Reference in New Issue