Refactor movie to get out all the client specific code, the solution usually was to move code into the tool that was calling it since the function itself had little to do with the movie object, move the movie object to client.common
This commit is contained in:
parent
a572935991
commit
11d2997db7
|
@ -53,6 +53,7 @@
|
|||
<Compile Include="helpers\InputValidate.cs" />
|
||||
<Compile Include="KeyTurbo.cs" />
|
||||
<Compile Include="movie\InputAdapters.cs" />
|
||||
<Compile Include="movie\Movie.cs" />
|
||||
<Compile Include="movie\MovieHeader.cs" />
|
||||
<Compile Include="movie\MovieLog.cs" />
|
||||
<Compile Include="movie\MovieMnemonics.cs" />
|
||||
|
|
|
@ -2,9 +2,7 @@
|
|||
using System.IO;
|
||||
using System.Globalization;
|
||||
|
||||
using BizHawk.Client.Common;
|
||||
|
||||
namespace BizHawk.MultiClient
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
public class Movie
|
||||
{
|
||||
|
@ -136,6 +134,7 @@ namespace BizHawk.MultiClient
|
|||
}
|
||||
}
|
||||
|
||||
//TODO: these are getting too lengthy perhaps the log should just be exposed?
|
||||
public int StateFirstIndex
|
||||
{
|
||||
get { return Log.StateFirstIndex; }
|
||||
|
@ -160,6 +159,16 @@ namespace BizHawk.MultiClient
|
|||
}
|
||||
}
|
||||
|
||||
public byte[] GetState(int frame)
|
||||
{
|
||||
return Log.GetState(frame);
|
||||
}
|
||||
|
||||
public byte[] InitState
|
||||
{
|
||||
get { return Log.InitState; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Public Mode Methods
|
||||
|
@ -511,19 +520,8 @@ namespace BizHawk.MultiClient
|
|||
changes = true;
|
||||
}
|
||||
|
||||
public void DeleteFrame(int frame, bool isPaused)
|
||||
public void DeleteFrame(int frame)
|
||||
{
|
||||
if (frame <= StateLastIndex)
|
||||
{
|
||||
if (frame <= StateFirstIndex)
|
||||
{
|
||||
RewindToFrame(0, isPaused);
|
||||
}
|
||||
else
|
||||
{
|
||||
RewindToFrame(frame, isPaused);
|
||||
}
|
||||
}
|
||||
Log.DeleteFrame(frame);
|
||||
changes = true;
|
||||
}
|
||||
|
@ -562,48 +560,6 @@ namespace BizHawk.MultiClient
|
|||
}
|
||||
}
|
||||
|
||||
public void RewindToFrame(int frame, bool isPaused)
|
||||
{
|
||||
if (Mode == MOVIEMODE.INACTIVE || Mode == MOVIEMODE.FINISHED)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (frame <= Global.Emulator.Frame)
|
||||
{
|
||||
if (frame <= Log.StateFirstIndex)
|
||||
{
|
||||
Global.Emulator.LoadStateBinary(new BinaryReader(new MemoryStream(Log.InitState)));
|
||||
if (MOVIEMODE.RECORD == Mode)
|
||||
{
|
||||
Mode = MOVIEMODE.PLAY;
|
||||
GlobalWinF.MainForm.RestoreReadWriteOnStop = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (frame == 0)
|
||||
{
|
||||
Global.Emulator.LoadStateBinary(new BinaryReader(new MemoryStream(Log.InitState)));
|
||||
}
|
||||
else
|
||||
{
|
||||
//frame-1 because we need to go back an extra frame and then run a frame, otherwise the display doesn't get updated.
|
||||
Global.Emulator.LoadStateBinary(new BinaryReader(new MemoryStream(Log.GetState(frame - 1))));
|
||||
GlobalWinF.MainForm.UpdateFrame = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (frame <= Log.StateLastIndex)
|
||||
{
|
||||
Global.Emulator.LoadStateBinary(new BinaryReader(new MemoryStream(Log.GetState(frame - 1))));
|
||||
GlobalWinF.MainForm.UpdateFrame = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
GlobalWinF.MainForm.UnpauseEmulator(); /*TODO*/
|
||||
}
|
||||
}
|
||||
|
||||
public void PokeFrame(int frameNum, string input)
|
||||
{
|
||||
changes = true;
|
||||
|
@ -641,19 +597,11 @@ namespace BizHawk.MultiClient
|
|||
writer.WriteLine("[/Input]");
|
||||
}
|
||||
|
||||
public void LoadLogFromSavestateText(string path)
|
||||
{
|
||||
using (var reader = new StreamReader(path))
|
||||
{
|
||||
LoadLogFromSavestateText(reader);
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadLogFromSavestateText(TextReader reader)
|
||||
public void LoadLogFromSavestateText(TextReader reader, bool isMultitracking)
|
||||
{
|
||||
int? stateFrame = null;
|
||||
//We are in record mode so replace the movie log with the one from the savestate
|
||||
if (!GlobalWinF.MovieSession.MultiTrack.IsActive)
|
||||
if (!isMultitracking)
|
||||
{
|
||||
if (Global.Config.EnableBackupMovies && MakeBackup && Log.Length > 0)
|
||||
{
|
|
@ -7,9 +7,7 @@ using System.Text;
|
|||
using System.Drawing;
|
||||
using System.IO;
|
||||
|
||||
using BizHawk.Client.Common;
|
||||
|
||||
namespace BizHawk.MultiClient
|
||||
namespace BizHawk.Client.Common
|
||||
{
|
||||
public class SubtitleList : IEnumerable<Subtitle>
|
||||
{
|
||||
|
|
|
@ -362,7 +362,6 @@
|
|||
<Compile Include="movie\EditSubtitlesForm.Designer.cs">
|
||||
<DependentUpon>EditSubtitlesForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="movie\Movie.cs" />
|
||||
<Compile Include="movie\MovieImport.cs" />
|
||||
<Compile Include="movie\MovieSession.cs" />
|
||||
<Compile Include="movie\PlayMovie.cs">
|
||||
|
|
|
@ -235,7 +235,7 @@ namespace BizHawk.MultiClient
|
|||
{
|
||||
reader.BaseStream.Position = 0;
|
||||
reader.DiscardBufferedData();
|
||||
GlobalWinF.MovieSession.Movie.LoadLogFromSavestateText(reader);
|
||||
GlobalWinF.MovieSession.Movie.LoadLogFromSavestateText(reader, GlobalWinF.MovieSession.MultiTrack.IsActive);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -251,7 +251,7 @@ namespace BizHawk.MultiClient
|
|||
{
|
||||
reader.BaseStream.Position = 0;
|
||||
reader.DiscardBufferedData();
|
||||
GlobalWinF.MovieSession.Movie.LoadLogFromSavestateText(reader);
|
||||
GlobalWinF.MovieSession.Movie.LoadLogFromSavestateText(reader, GlobalWinF.MovieSession.MultiTrack.IsActive);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
@ -325,7 +325,7 @@ namespace BizHawk.MultiClient
|
|||
SetMainformMovieInfo();
|
||||
reader.BaseStream.Position = 0;
|
||||
reader.DiscardBufferedData();
|
||||
GlobalWinF.MovieSession.Movie.LoadLogFromSavestateText(reader);
|
||||
GlobalWinF.MovieSession.Movie.LoadLogFromSavestateText(reader, GlobalWinF.MovieSession.MultiTrack.IsActive);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
@ -344,7 +344,7 @@ namespace BizHawk.MultiClient
|
|||
SetMainformMovieInfo();
|
||||
reader.BaseStream.Position = 0;
|
||||
reader.DiscardBufferedData();
|
||||
GlobalWinF.MovieSession.Movie.LoadLogFromSavestateText(reader);
|
||||
GlobalWinF.MovieSession.Movie.LoadLogFromSavestateText(reader, GlobalWinF.MovieSession.MultiTrack.IsActive);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
@ -424,7 +424,7 @@ namespace BizHawk.MultiClient
|
|||
SetMainformMovieInfo();
|
||||
reader.BaseStream.Position = 0;
|
||||
reader.DiscardBufferedData();
|
||||
GlobalWinF.MovieSession.Movie.LoadLogFromSavestateText(reader);
|
||||
GlobalWinF.MovieSession.Movie.LoadLogFromSavestateText(reader, GlobalWinF.MovieSession.MultiTrack.IsActive);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
@ -444,7 +444,7 @@ namespace BizHawk.MultiClient
|
|||
SetMainformMovieInfo();
|
||||
reader.BaseStream.Position = 0;
|
||||
reader.DiscardBufferedData();
|
||||
GlobalWinF.MovieSession.Movie.LoadLogFromSavestateText(reader);
|
||||
GlobalWinF.MovieSession.Movie.LoadLogFromSavestateText(reader, GlobalWinF.MovieSession.MultiTrack.IsActive);
|
||||
return true;
|
||||
}
|
||||
else
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
using System;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using BizHawk.Client.Common;
|
||||
|
||||
namespace BizHawk.MultiClient
|
||||
{
|
||||
public partial class EditCommentsForm : Form
|
||||
|
|
|
@ -22,12 +22,20 @@ namespace BizHawk.MultiClient
|
|||
if (File.Exists(path))
|
||||
{
|
||||
Movie m = new Movie(GlobalWinF.MainForm.GetEmuVersion());
|
||||
m.LoadLogFromSavestateText(path);
|
||||
LoadLogFromSavestateText(m, path);
|
||||
AddLog(m.LogDump, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadLogFromSavestateText(Movie movie, string path)
|
||||
{
|
||||
using (var reader = new StreamReader(path))
|
||||
{
|
||||
movie.LoadLogFromSavestateText(reader, GlobalWinF.MovieSession.MultiTrack.IsActive);
|
||||
}
|
||||
}
|
||||
|
||||
public int TimeLineCount
|
||||
{
|
||||
get
|
||||
|
|
|
@ -2,8 +2,8 @@
|
|||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using BizHawk.Client.Common;
|
||||
|
||||
namespace BizHawk.MultiClient
|
||||
|
@ -269,7 +269,7 @@ namespace BizHawk.MultiClient
|
|||
}
|
||||
else
|
||||
{
|
||||
GlobalWinF.MovieSession.Movie.RewindToFrame(Global.Emulator.Frame - 1, GlobalWinF.MainForm.EmulatorPaused);
|
||||
RewindToFrame(Global.Emulator.Frame - 1);
|
||||
}
|
||||
UpdateValues();
|
||||
}
|
||||
|
@ -427,11 +427,11 @@ namespace BizHawk.MultiClient
|
|||
if (TASView.selectedItem <= GlobalWinF.MovieSession.Movie.StateLastIndex)
|
||||
{
|
||||
stopOnFrame = 0;
|
||||
GlobalWinF.MovieSession.Movie.RewindToFrame(TASView.selectedItem, GlobalWinF.MainForm.EmulatorPaused);
|
||||
RewindToFrame(TASView.selectedItem);
|
||||
}
|
||||
else
|
||||
{
|
||||
GlobalWinF.MovieSession.Movie.RewindToFrame(GlobalWinF.MovieSession.Movie.StateLastIndex, GlobalWinF.MainForm.EmulatorPaused);
|
||||
RewindToFrame(GlobalWinF.MovieSession.Movie.StateLastIndex);
|
||||
stopOnFrame = TASView.selectedItem;
|
||||
GlobalWinF.MainForm.PressFrameAdvance = true;
|
||||
}
|
||||
|
@ -480,7 +480,7 @@ namespace BizHawk.MultiClient
|
|||
|
||||
if (e.Delta > 0) //Scroll up
|
||||
{
|
||||
GlobalWinF.MovieSession.Movie.RewindToFrame(Global.Emulator.Frame - 1, GlobalWinF.MainForm.EmulatorPaused);
|
||||
RewindToFrame(Global.Emulator.Frame - 1);
|
||||
}
|
||||
else if (e.Delta < 0) //Scroll down
|
||||
{
|
||||
|
@ -543,12 +543,70 @@ namespace BizHawk.MultiClient
|
|||
UpdateValues();
|
||||
}
|
||||
|
||||
private void RewindToFrame(int frame)
|
||||
{
|
||||
if (!GlobalWinF.MovieSession.Movie.IsActive || GlobalWinF.MovieSession.Movie.IsFinished)
|
||||
{
|
||||
return;
|
||||
}
|
||||
else if (frame <= Global.Emulator.Frame)
|
||||
{
|
||||
if (frame <= GlobalWinF.MovieSession.Movie.StateFirstIndex)
|
||||
{
|
||||
Global.Emulator.LoadStateBinary(new BinaryReader(new MemoryStream(GlobalWinF.MovieSession.Movie.InitState)));
|
||||
if (GlobalWinF.MovieSession.Movie.IsRecording)
|
||||
{
|
||||
GlobalWinF.MovieSession.Movie.StartPlayback();
|
||||
GlobalWinF.MainForm.RestoreReadWriteOnStop = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (frame == 0)
|
||||
{
|
||||
Global.Emulator.LoadStateBinary(new BinaryReader(new MemoryStream(GlobalWinF.MovieSession.Movie.InitState)));
|
||||
}
|
||||
else
|
||||
{
|
||||
//frame-1 because we need to go back an extra frame and then run a frame, otherwise the display doesn't get updated.
|
||||
Global.Emulator.LoadStateBinary(new BinaryReader(new MemoryStream(GlobalWinF.MovieSession.Movie.GetState(frame - 1))));
|
||||
GlobalWinF.MainForm.UpdateFrame = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (frame <= GlobalWinF.MovieSession.Movie.StateLastIndex)
|
||||
{
|
||||
Global.Emulator.LoadStateBinary(new BinaryReader(new MemoryStream(GlobalWinF.MovieSession.Movie.GetState(frame - 1))));
|
||||
GlobalWinF.MainForm.UpdateFrame = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
GlobalWinF.MainForm.UnpauseEmulator();
|
||||
}
|
||||
}
|
||||
|
||||
public void DeleteFrame(int frame)
|
||||
{
|
||||
if (frame <= GlobalWinF.MovieSession.Movie.StateLastIndex)
|
||||
{
|
||||
if (frame <= GlobalWinF.MovieSession.Movie.StateFirstIndex)
|
||||
{
|
||||
RewindToFrame(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
RewindToFrame(frame);
|
||||
}
|
||||
}
|
||||
GlobalWinF.MovieSession.Movie.DeleteFrame(frame);
|
||||
}
|
||||
|
||||
private void DeleteFrames()
|
||||
{
|
||||
ListView.SelectedIndexCollection list = TASView.SelectedIndices;
|
||||
foreach (object t in list)
|
||||
{
|
||||
GlobalWinF.MovieSession.Movie.DeleteFrame(list[0], GlobalWinF.MainForm.EmulatorPaused); //TODO: this doesn't allow of non-continuous deletion, instead it should iterate from last to first and remove the iterated value
|
||||
GlobalWinF.MovieSession.Movie.DeleteFrame(list[0]); //TODO: this doesn't allow of non-continuous deletion, instead it should iterate from last to first and remove the iterated value
|
||||
}
|
||||
|
||||
UpdateValues();
|
||||
|
@ -741,7 +799,7 @@ namespace BizHawk.MultiClient
|
|||
{
|
||||
ClipboardEntry entry = new ClipboardEntry {Frame = list[i], Inputstr = GlobalWinF.MovieSession.Movie.GetInput(list[i])};
|
||||
Clipboard.Add(entry);
|
||||
GlobalWinF.MovieSession.Movie.DeleteFrame(list[0], GlobalWinF.MainForm.EmulatorPaused);
|
||||
DeleteFrame(list[0]);
|
||||
}
|
||||
|
||||
UpdateValues();
|
||||
|
|
Loading…
Reference in New Issue