Move the readonly flag from Global to MovieSession

This commit is contained in:
adelikat 2013-12-03 18:08:45 +00:00
parent a03213e0e4
commit b7d553cb4e
11 changed files with 77 additions and 79 deletions

View File

@ -20,7 +20,6 @@ namespace BizHawk.Client.Common
/// </summary>
public static MultitrackRewiringControllerAdapter MultitrackRewiringControllerAdapter = new MultitrackRewiringControllerAdapter();
public static MovieSession MovieSession = new MovieSession();
public static bool ReadOnly = true; //Global Movie Read only setting
/// <summary>
/// whether throttling is force-disabled by use of fast forward

View File

@ -58,7 +58,7 @@ namespace BizHawk.Client.Common
public static bool movie_getreadonly()
{
return Global.ReadOnly;
return Global.MovieSession.ReadOnly;
}
public static bool movie_getrerecordcounting()
@ -103,7 +103,7 @@ namespace BizHawk.Client.Common
public static void movie_setreadonly(object lua_input)
{
Global.ReadOnly = (lua_input.ToString().ToUpper() == "TRUE"
Global.MovieSession.ReadOnly = (lua_input.ToString().ToUpper() == "TRUE"
|| lua_input.ToString() == "1");
}

View File

@ -116,7 +116,8 @@ namespace BizHawk.Client.Common
#region Dubious, should reconsider
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
void ExtractInputLog(TextReader reader, bool isMultitracking); // how about the movie know if it is multi-tracking rather than having to pass it in
void ExtractInputLog(TextReader reader); //Is passing a textreader the only reasonable way to do this?
#endregion
}

View File

@ -407,12 +407,12 @@ namespace BizHawk.Client.Common
return sb.ToString();
}
public void ExtractInputLog(TextReader reader, bool isMultitracking)
public void ExtractInputLog(TextReader reader)
{
int? stateFrame = null;
// We are in record mode so replace the movie log with the one from the savestate
if (!isMultitracking)
if (!Global.MovieSession.MultiTrack.IsActive)
{
if (Global.Config.EnableBackupMovies && MakeBackup && _log.Length > 0)
{
@ -816,7 +816,7 @@ namespace BizHawk.Client.Common
var pal = Header.ContainsKey(HeaderKeys.PAL) &&
Header[HeaderKeys.PAL] == "1";
return frames / FrameRates[system, pal];
return frames / _frameRates[system, pal];
}
public double Fps
@ -827,16 +827,12 @@ namespace BizHawk.Client.Common
var pal = Header.ContainsKey(HeaderKeys.PAL) &&
Header[HeaderKeys.PAL] == "1";
return FrameRates[system, pal];
return _frameRates[system, pal];
}
}
#endregion
private readonly PlatformFrameRates _frameRates = new PlatformFrameRates();
public PlatformFrameRates FrameRates
{
get { return _frameRates; }
}
}
}

View File

@ -13,6 +13,8 @@ namespace BizHawk.Client.Common
public Action<string> MessageCallback; //Not Required
public Func<string, string, bool> AskYesNoCallback; //Not Required
public bool ReadOnly = true;
private void Output(string message)
{
if (MessageCallback != null)
@ -69,9 +71,7 @@ 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(
Movie.GetInput(Global.Emulator.Frame)
);
MovieControllerAdapter.SetControllersAsMnemonic(input);
}
}
@ -97,7 +97,7 @@ namespace BizHawk.Client.Common
Output(Path.GetFileName(Movie.Filename) + " written to disk.");
}
Output(message);
Global.ReadOnly = true;
ReadOnly = true;
}
}
@ -115,7 +115,7 @@ namespace BizHawk.Client.Common
if (Movie.IsPlaying)
{
Movie.ClearFrame(Global.Emulator.Frame);
Output("Scrubbed input at frame " + Global.Emulator.Frame.ToString());
Output("Scrubbed input at frame " + Global.Emulator.Frame);
}
}
@ -179,8 +179,9 @@ namespace BizHawk.Client.Common
{
LatchInputFromPlayer(Global.MovieInputSourceAdapter);
}
//the movie session makes sure that the correct input has been read and merged to its MovieControllerAdapter;
//this has been wired to Global.MovieOutputHardpoint in RewireInputChain
// the movie session makes sure that the correct input has been read and merged to its MovieControllerAdapter;
// this has been wired to Global.MovieOutputHardpoint in RewireInputChain
var mg = new MnemonicsGenerator();
mg.SetSource(Global.MovieOutputHardpoint);
Movie.RecordFrame(Global.Emulator.Frame, mg);
@ -191,7 +192,7 @@ namespace BizHawk.Client.Common
{
using (var sr = new StreamReader(path))
{
return Global.MovieSession.HandleMovieLoadState(sr);
return HandleMovieLoadState(sr);
}
}
@ -207,7 +208,7 @@ namespace BizHawk.Client.Common
else if (Movie.IsRecording)
{
if (Global.ReadOnly)
if (ReadOnly)
{
var result = Movie.CheckTimeLines(reader, onlyGuid: false, ignoreGuidMismatch: false, errorMessage: out ErrorMSG);
if (result == LoadStateResult.Pass)
@ -255,7 +256,7 @@ namespace BizHawk.Client.Common
{
reader.BaseStream.Position = 0;
reader.DiscardBufferedData();
Movie.ExtractInputLog(reader, MultiTrack.IsActive);
Movie.ExtractInputLog(reader);
}
else
{
@ -268,7 +269,7 @@ namespace BizHawk.Client.Common
{
reader.BaseStream.Position = 0;
reader.DiscardBufferedData();
Movie.ExtractInputLog(reader, MultiTrack.IsActive);
Movie.ExtractInputLog(reader);
return true;
}
else
@ -293,9 +294,9 @@ namespace BizHawk.Client.Common
else if (Movie.IsPlaying && !Movie.IsFinished)
{
if (Global.ReadOnly)
if (ReadOnly)
{
var result = Movie.CheckTimeLines(reader, onlyGuid: !Global.ReadOnly, ignoreGuidMismatch: false, errorMessage: out ErrorMSG);
var result = Movie.CheckTimeLines(reader, onlyGuid: !ReadOnly, ignoreGuidMismatch: false, errorMessage: out ErrorMSG);
if (result == LoadStateResult.Pass)
{
//Frame loop automatically handles the rewinding effect based on Global.Emulator.Frame so nothing else is needed here
@ -307,7 +308,7 @@ namespace BizHawk.Client.Common
{
if (HandleGuidError())
{
var newresult = Movie.CheckTimeLines(reader, onlyGuid: !Global.ReadOnly, ignoreGuidMismatch: true, errorMessage: out ErrorMSG);
var newresult = Movie.CheckTimeLines(reader, onlyGuid: !ReadOnly, ignoreGuidMismatch: true, errorMessage: out ErrorMSG);
if (newresult == LoadStateResult.Pass)
{
return true;
@ -332,13 +333,13 @@ namespace BizHawk.Client.Common
}
else
{
var result = Movie.CheckTimeLines(reader, onlyGuid: !Global.ReadOnly, ignoreGuidMismatch: false, errorMessage: out ErrorMSG);
var result = Movie.CheckTimeLines(reader, onlyGuid: !ReadOnly, ignoreGuidMismatch: false, errorMessage: out ErrorMSG);
if (result == LoadStateResult.Pass)
{
Movie.SwitchToRecord();
reader.BaseStream.Position = 0;
reader.DiscardBufferedData();
Movie.ExtractInputLog(reader, MultiTrack.IsActive);
Movie.ExtractInputLog(reader);
return true;
}
else
@ -347,13 +348,13 @@ namespace BizHawk.Client.Common
{
if (HandleGuidError())
{
var newresult = Movie.CheckTimeLines(reader, onlyGuid: !Global.ReadOnly, ignoreGuidMismatch: true, errorMessage: out ErrorMSG);
var newresult = Movie.CheckTimeLines(reader, onlyGuid: !ReadOnly, ignoreGuidMismatch: true, errorMessage: out ErrorMSG);
if (newresult == LoadStateResult.Pass)
{
Movie.SwitchToRecord();
reader.BaseStream.Position = 0;
reader.DiscardBufferedData();
Movie.ExtractInputLog(reader, MultiTrack.IsActive);
Movie.ExtractInputLog(reader);
return true;
}
else
@ -377,7 +378,7 @@ namespace BizHawk.Client.Common
}
else if (Movie.IsFinished)
{
if (Global.ReadOnly)
if (ReadOnly)
{
var result = Movie.CheckTimeLines(reader, onlyGuid: false, ignoreGuidMismatch: false, errorMessage: out ErrorMSG);
if (result != LoadStateResult.Pass)
@ -420,14 +421,14 @@ namespace BizHawk.Client.Common
}
else
{
var result = Movie.CheckTimeLines(reader, onlyGuid: !Global.ReadOnly, ignoreGuidMismatch: false, errorMessage: out ErrorMSG);
var result = Movie.CheckTimeLines(reader, onlyGuid: !ReadOnly, ignoreGuidMismatch: false, errorMessage: out ErrorMSG);
if (result == LoadStateResult.Pass)
{
Global.Emulator.ClearSaveRam();
Movie.StartNewRecording();
reader.BaseStream.Position = 0;
reader.DiscardBufferedData();
Movie.ExtractInputLog(reader, MultiTrack.IsActive);
Movie.ExtractInputLog(reader);
return true;
}
else
@ -436,14 +437,14 @@ namespace BizHawk.Client.Common
{
if (HandleGuidError())
{
var newresult = Movie.CheckTimeLines(reader, onlyGuid: !Global.ReadOnly, ignoreGuidMismatch: true, errorMessage: out ErrorMSG);
var newresult = Movie.CheckTimeLines(reader, onlyGuid: !ReadOnly, ignoreGuidMismatch: true, errorMessage: out ErrorMSG);
if (newresult == LoadStateResult.Pass)
{
Global.Emulator.ClearSaveRam();
Movie.StartNewRecording();
reader.BaseStream.Position = 0;
reader.DiscardBufferedData();
Movie.ExtractInputLog(reader, MultiTrack.IsActive);
Movie.ExtractInputLog(reader);
return true;
}
else

View File

@ -65,7 +65,6 @@ namespace BizHawk.Client.Common
{
get
{
return new TimeSpan();
double dblseconds = GetSeconds(_records.Count);
int seconds = (int)(dblseconds % 60);
int days = seconds / 86400;
@ -139,34 +138,6 @@ namespace BizHawk.Client.Common
_records.Truncate(frame);
}
// TODO:
public void StartNewRecording()
{
SwitchToRecord();
if (Global.Config.EnableBackupMovies && true/*TODO*/ && _records.Any())
{
// TODO
}
}
public bool Load()
{
throw new NotImplementedException();
}
public void Save()
{
Changes = false;
throw new NotImplementedException();
}
public void SaveAs()
{
Changes = false;
throw new NotImplementedException();
}
public void ClearFrame(int frame)
{
if (frame < _records.Count)
@ -211,12 +182,40 @@ namespace BizHawk.Client.Common
}
}
// TODO:
public void StartNewRecording()
{
SwitchToRecord();
if (Global.Config.EnableBackupMovies && true/*TODO*/ && _records.Any())
{
// TODO
}
}
public bool Load()
{
throw new NotImplementedException();
}
public void Save()
{
Changes = false;
throw new NotImplementedException();
}
public void SaveAs()
{
Changes = false;
throw new NotImplementedException();
}
public LoadStateResult CheckTimeLines(System.IO.TextReader reader, bool onlyGuid, bool ignoreGuidMismatch, out string errorMessage)
{
throw new NotImplementedException();
}
public void ExtractInputLog(System.IO.TextReader reader, bool isMultitracking)
public void ExtractInputLog(System.IO.TextReader reader)
{
throw new NotImplementedException();
}

View File

@ -232,7 +232,7 @@ namespace BizHawk.Client.EmuHawk
= SaveMovieMenuItem.Enabled
= Global.MovieSession.Movie.IsActive;
ReadonlyMenuItem.Checked = Global.ReadOnly;
ReadonlyMenuItem.Checked = Global.MovieSession.ReadOnly;
BindSavestatesToMoviesMenuItem.Checked = Global.Config.BindSavestatesToMovies;
AutomaticallyBackupMoviesMenuItem.Checked = Global.Config.EnableBackupMovies;
FullMovieLoadstatesMenuItem.Checked = Global.Config.VBAStyleMovieLoadState;
@ -1760,7 +1760,7 @@ namespace BizHawk.Client.EmuHawk
StopNoSaveContextMenuItem.Visible = Global.MovieSession.Movie.IsActive && Global.MovieSession.Movie.Changes;
AddSubtitleContextMenuItem.Visible = !(Global.Emulator is NullEmulator) && Global.MovieSession.Movie.IsActive && Global.ReadOnly;
AddSubtitleContextMenuItem.Visible = !(Global.Emulator is NullEmulator) && Global.MovieSession.Movie.IsActive && Global.MovieSession.ReadOnly;
ConfigContextMenuItem.Visible = _inFullscreen;
@ -1773,7 +1773,7 @@ namespace BizHawk.Client.EmuHawk
if (Global.MovieSession.Movie.IsActive)
{
if (Global.ReadOnly)
if (Global.MovieSession.ReadOnly)
{
ViewSubtitlesContextMenuItem.Text = "View Subtitles";
ViewCommentsContextMenuItem.Text = "View Comments";
@ -1847,7 +1847,7 @@ namespace BizHawk.Client.EmuHawk
{
if (Global.MovieSession.Movie.IsActive)
{
var form = new EditSubtitlesForm { ReadOnly = Global.ReadOnly };
var form = new EditSubtitlesForm { ReadOnly = Global.MovieSession.ReadOnly };
form.GetMovie(Global.MovieSession.Movie);
form.ShowDialog();
}

View File

@ -43,16 +43,17 @@ namespace BizHawk.Client.EmuHawk
LoadStateFile(Global.MovieSession.Movie.Filename, Path.GetFileName(Global.MovieSession.Movie.Filename));
Global.Emulator.ResetCounters();
}
if (record)
{
Global.Emulator.ClearSaveRam();
Global.MovieSession.Movie.StartNewRecording();
Global.ReadOnly = false;
Global.MovieSession.ReadOnly = false;
}
else
{
Global.MovieSession.Movie.StartNewPlayback();
}
SetMainformMovieInfo();
GlobalWin.Tools.Restart<TAStudio>();
GlobalWin.Tools.Restart<VirtualPadForm>();
@ -117,10 +118,11 @@ namespace BizHawk.Client.EmuHawk
LoadStateFile(Global.MovieSession.Movie.Filename, Path.GetFileName(Global.MovieSession.Movie.Filename));
Global.Emulator.ResetCounters();
}
Global.MovieSession.Movie.StartNewPlayback();
SetMainformMovieInfo();
GlobalWin.OSD.AddMessage("Replaying movie file in read-only mode");
Global.ReadOnly = true;
Global.MovieSession.ReadOnly = true;
}
}

View File

@ -209,7 +209,7 @@ namespace BizHawk.Client.EmuHawk
else
{
var movie = new Movie(cmdMovie);
Global.ReadOnly = true;
Global.MovieSession.ReadOnly = true;
// if user is dumping and didnt supply dump length, make it as long as the loaded movie
if (_autoDumpLength == 0)
{
@ -1548,7 +1548,7 @@ namespace BizHawk.Client.EmuHawk
}
else
{
Global.ReadOnly = true;
Global.MovieSession.ReadOnly = true;
StartNewMovie(movie, false);
}
}
@ -2074,8 +2074,8 @@ namespace BizHawk.Client.EmuHawk
{
if (Global.MovieSession.Movie.IsActive)
{
Global.ReadOnly ^= true;
if (Global.ReadOnly)
Global.MovieSession.ReadOnly ^= true;
if (Global.MovieSession.ReadOnly)
{
GlobalWin.OSD.AddMessage("Movie read-only mode");
}

View File

@ -16,7 +16,7 @@ namespace BizHawk.Client.EmuHawk
private void EditCommentsForm_Load(object sender, EventArgs e)
{
if (Global.ReadOnly)
if (Global.MovieSession.ReadOnly)
{
CommentGrid.Columns[0].ReadOnly = true;
Text = "View Comments";
@ -36,7 +36,7 @@ namespace BizHawk.Client.EmuHawk
private void OK_Click(object sender, EventArgs e)
{
if (!Global.ReadOnly)
if (!Global.MovieSession.ReadOnly)
{
_selectedMovie.Header.Comments.Clear();
for (int i = 0; i < CommentGrid.Rows.Count - 1; i++)

View File

@ -63,7 +63,7 @@ namespace BizHawk.Client.EmuHawk
private void OK_Click(object sender, EventArgs e)
{
Global.ReadOnly = ReadOnlyCheckBox.Checked;
Global.MovieSession.ReadOnly = ReadOnlyCheckBox.Checked;
Run();
Close();
}