diff --git a/BizHawk.MultiClient/DisplayManager/DisplayManager.cs b/BizHawk.MultiClient/DisplayManager/DisplayManager.cs index c71845a615..5f00d989b6 100644 --- a/BizHawk.MultiClient/DisplayManager/DisplayManager.cs +++ b/BizHawk.MultiClient/DisplayManager/DisplayManager.cs @@ -249,11 +249,11 @@ namespace BizHawk.MultiClient { if (Global.MovieSession.Movie.Mode == MOVIEMODE.FINISHED) { - return Global.Emulator.Frame.ToString() + "/" + Global.MovieSession.Movie.Length().ToString() + " (Finished)"; + return Global.Emulator.Frame.ToString() + "/" + Global.MovieSession.Movie.LogLength().ToString() + " (Finished)"; } else if (Global.MovieSession.Movie.Mode == MOVIEMODE.PLAY) { - return Global.Emulator.Frame.ToString() + "/" + Global.MovieSession.Movie.Length().ToString(); + return Global.Emulator.Frame.ToString() + "/" + Global.MovieSession.Movie.LogLength().ToString(); } else if (Global.MovieSession.Movie.Mode == MOVIEMODE.RECORD) return Global.Emulator.Frame.ToString(); diff --git a/BizHawk.MultiClient/LuaImplementation.cs b/BizHawk.MultiClient/LuaImplementation.cs index c086faad27..c167b8a5f5 100644 --- a/BizHawk.MultiClient/LuaImplementation.cs +++ b/BizHawk.MultiClient/LuaImplementation.cs @@ -1445,7 +1445,7 @@ namespace BizHawk.MultiClient public int movie_length() { - return Global.MovieSession.Movie.Length(); + return Global.MovieSession.Movie.LogLength(); } public string movie_filename() diff --git a/BizHawk.MultiClient/MainForm.cs b/BizHawk.MultiClient/MainForm.cs index 9ade9ae44f..1ab04f3388 100644 --- a/BizHawk.MultiClient/MainForm.cs +++ b/BizHawk.MultiClient/MainForm.cs @@ -1894,7 +1894,7 @@ namespace BizHawk.MultiClient if (Global.MovieSession.Movie.Mode == MOVIEMODE.PLAY) { - if (Global.MovieSession.Movie.Length() == Global.Emulator.Frame+1 && true == StopOnEnd) + if (Global.MovieSession.Movie.LogLength() == Global.Emulator.Frame + 1 && true == StopOnEnd) { if (true == Global.MovieSession.Movie.TastudioOn) { @@ -1905,7 +1905,7 @@ namespace BizHawk.MultiClient } if (Global.MovieSession.Movie.Mode == MOVIEMODE.FINISHED) { - if (Global.MovieSession.Movie.Length() > Global.Emulator.Frame+1) + if (Global.MovieSession.Movie.LogLength() > Global.Emulator.Frame + 1) { Global.MovieSession.Movie.StartPlayback(); //Global.MovieSession.MovieControllerAdapter.SetControllersAsMnemonic(Global.MovieSession.Movie.GetInputFrame(Global.Emulator.Frame)); @@ -1998,8 +1998,8 @@ namespace BizHawk.MultiClient { //The other tool updates are earlier, TAStudio needs to be later so it can display the latest //frame of execution in its list view. - TAStudio1.UpdateValues(); Global.MovieSession.Movie.CheckValidity(); + TAStudio1.UpdateValues(); } private unsafe Image MakeScreenshotImage() diff --git a/BizHawk.MultiClient/PlayMovie.cs b/BizHawk.MultiClient/PlayMovie.cs index fcc11407a7..1f0c045798 100644 --- a/BizHawk.MultiClient/PlayMovie.cs +++ b/BizHawk.MultiClient/PlayMovie.cs @@ -88,7 +88,7 @@ namespace BizHawk.MultiClient { Movie m = new Movie(file.FullName, MOVIEMODE.INACTIVE); m.LoadMovie(); //State files will have to load everything unfortunately - if (m.Length() == 0) + if (m.LogLength() == 0) { MessageBox.Show("No input log detected in this savestate, aborting", "Can not load file", MessageBoxButtons.OK, MessageBoxIcon.Hand); return; @@ -119,7 +119,7 @@ namespace BizHawk.MultiClient { Movie m = new Movie(file.CanonicalFullPath, MOVIEMODE.INACTIVE); m.LoadMovie(); //State files will have to load everything unfortunately - if (m.Length() > 0) + if (m.LogLength() > 0) { MovieList.Add(m); sortReverse = false; diff --git a/BizHawk.MultiClient/Rewind.cs b/BizHawk.MultiClient/Rewind.cs index 07544e05a6..e320a84dfb 100644 --- a/BizHawk.MultiClient/Rewind.cs +++ b/BizHawk.MultiClient/Rewind.cs @@ -163,7 +163,7 @@ namespace BizHawk.MultiClient { for (int i = 0; i < frames; i++) { - if (RewindBuf.Count == 0 || (true == Global.MovieSession.Movie.Loaded && 0 == Global.MovieSession.Movie.Length())) + if (RewindBuf.Count == 0 || (true == Global.MovieSession.Movie.Loaded && 0 == Global.MovieSession.Movie.LogLength())) return; if (LastState.Length < 0x10000) Rewind64K(); diff --git a/BizHawk.MultiClient/movie/Movie.cs b/BizHawk.MultiClient/movie/Movie.cs index ccadfe57b0..34f63e0029 100644 --- a/BizHawk.MultiClient/movie/Movie.cs +++ b/BizHawk.MultiClient/movie/Movie.cs @@ -72,15 +72,23 @@ namespace BizHawk.MultiClient return Header.GetHeaderLine(MovieHeader.GAMENAME); } - public int Length() - { - if (Loaded) - return Log.Length(); - else - return Frames; - } + public int LogLength() + { + if (Loaded) + return Log.MovieLength(); + else + return Frames; + } - public void UpdateFileName(string filename) + public int StateLength() + { + if (Loaded) + return Log.StateLength(); + else + return Frames; + } + + public void UpdateFileName(string filename) { this.Filename = filename; } @@ -123,9 +131,9 @@ namespace BizHawk.MultiClient Global.MainForm.TAStudio1.UpdateValues(); } - public int LastValidState() + public int ValidStateCount() { - return Log.LastValidState(); + return Log.ValidStateCount(); } public void CheckValidity() @@ -146,7 +154,7 @@ namespace BizHawk.MultiClient { ClearSaveRAM(); Mode = MOVIEMODE.RECORD; - if (Global.Config.EnableBackupMovies && MakeBackup && Log.Length() > 0) + if (Global.Config.EnableBackupMovies && MakeBackup && Log.MovieLength() > 0) { WriteBackup(); MakeBackup = false; @@ -205,7 +213,7 @@ namespace BizHawk.MultiClient public string GetInputFrame(int frame) { lastLog = frame; - if (frame < Log.Length()) + if (frame < Log.MovieLength()) return Log.GetFrame(frame); else return ""; @@ -252,7 +260,7 @@ namespace BizHawk.MultiClient private void WriteText(string file) { if (file.Length == 0) return; //Nothing to write - int length = Log.Length(); + int length = Log.MovieLength(); using (StreamWriter sw = new StreamWriter(file)) { @@ -409,7 +417,7 @@ namespace BizHawk.MultiClient writer.WriteLine("[Input]"); string s = MovieHeader.GUID + " " + Header.GetHeaderLine(MovieHeader.GUID); writer.WriteLine(s); - for (int x = 0; x < Log.Length(); x++) + for (int x = 0; x < Log.MovieLength(); x++) writer.WriteLine(Log.GetFrame(x)); writer.WriteLine("[/Input]"); } @@ -421,7 +429,7 @@ namespace BizHawk.MultiClient //We are in record mode so replace the movie log with the one from the savestate if (!Global.MovieSession.MultiTrack.IsActive) { - if (Global.Config.EnableBackupMovies && MakeBackup && Log.Length() > 0) + if (Global.Config.EnableBackupMovies && MakeBackup && Log.MovieLength() > 0) { WriteBackup(); MakeBackup = false; @@ -497,9 +505,9 @@ namespace BizHawk.MultiClient } } } - if (stateFrame > 0 && stateFrame < Log.Length()) + if (stateFrame > 0 && stateFrame < Log.MovieLength()) { - Log.Truncate(Global.Emulator.Frame); + Log.TruncateStates(Global.Emulator.Frame); } IncrementRerecords(); reader.Close(); @@ -534,7 +542,7 @@ namespace BizHawk.MultiClient if (preLoad) seconds = GetSeconds(Frames); else - seconds = GetSeconds(Log.Length()); + seconds = GetSeconds(Log.MovieLength()); int hours = ((int)seconds) / 3600; int minutes = (((int)seconds) / 60) % 60; double sec = seconds % 60; @@ -697,7 +705,7 @@ namespace BizHawk.MultiClient return true; } - if (stateFrame > l.Length()) //stateFrame is greater than state input log, so movie finished mode + if (stateFrame > l.MovieLength()) //stateFrame is greater than state input log, so movie finished mode { if (Mode == MOVIEMODE.PLAY || Mode == MOVIEMODE.FINISHED) { @@ -710,13 +718,13 @@ namespace BizHawk.MultiClient if (stateFrame == 0) { - stateFrame = l.Length(); //In case the frame count failed to parse, revert to using the entire state input log + stateFrame = l.MovieLength(); //In case the frame count failed to parse, revert to using the entire state input log } - if (Log.Length() < stateFrame) + if (Log.MovieLength() < stateFrame) { //Future event error - MessageBox.Show("The savestate is from frame " + l.Length().ToString() + " which is greater than the current movie length of " + - Log.Length().ToString() + ".\nCan not load this savestate.", "Future event Error", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("The savestate is from frame " + l.MovieLength().ToString() + " which is greater than the current movie length of " + + Log.MovieLength().ToString() + ".\nCan not load this savestate.", "Future event Error", MessageBoxButtons.OK, MessageBoxIcon.Error); reader.Close(); return false; } diff --git a/BizHawk.MultiClient/movie/MovieImport.cs b/BizHawk.MultiClient/movie/MovieImport.cs index be23b891c4..ae00a24233 100644 --- a/BizHawk.MultiClient/movie/MovieImport.cs +++ b/BizHawk.MultiClient/movie/MovieImport.cs @@ -212,7 +212,7 @@ namespace BizHawk.MultiClient case '1': break; case '2': - if (m.Length() != 0) + if (m.LogLength() != 0) warningMsg = "hard reset"; break; case '4': diff --git a/BizHawk.MultiClient/movie/MovieLog.cs b/BizHawk.MultiClient/movie/MovieLog.cs index 9afbfdf992..7dcdf76897 100644 --- a/BizHawk.MultiClient/movie/MovieLog.cs +++ b/BizHawk.MultiClient/movie/MovieLog.cs @@ -15,23 +15,26 @@ namespace BizHawk.MultiClient List MovieRecords = new List(); - private List StateList = new List(); - private int StateLastValidIndex = -1; + private List StateRecords = new List(); public MovieLog() { - //Should this class initialize with an empty string to MovieRecords so that first frame is index 1? - //MovieRecords.Add(""); } - public int Length() + public int MovieLength() { return MovieRecords.Count; } + public int StateLength() + { + return StateRecords.Count; + } + public void Clear() { MovieRecords.Clear(); + StateRecords.Clear(); } public void AddFrame(string frame) @@ -41,10 +44,9 @@ namespace BizHawk.MultiClient public void AddState(byte[] state) { - if (Global.Emulator.Frame >= StateList.Count) + if (Global.Emulator.Frame >= StateRecords.Count) { - StateList.Add(state); - StateLastValidIndex = Global.Emulator.Frame; + StateRecords.Add(state); } } @@ -59,63 +61,64 @@ namespace BizHawk.MultiClient { MovieRecords.Insert(frameNum, frame); - if (frameNum <= StateList.Count - 1) + if (frameNum <= StateRecords.Count - 1) { - StateList.RemoveRange(frameNum, StateList.Count - frameNum); - } - if (StateLastValidIndex >= frameNum) - { - StateLastValidIndex = frameNum - 1; + StateRecords.RemoveRange(frameNum, StateRecords.Count - frameNum); } } public void CheckValidity() { byte[] state = Global.Emulator.SaveStateBinary(); - if (Global.Emulator.Frame < StateList.Count && (null == StateList[Global.Emulator.Frame] || !state.SequenceEqual((byte[])StateList[Global.Emulator.Frame]))) + if (Global.Emulator.Frame < StateRecords.Count && !state.SequenceEqual((byte[])StateRecords[Global.Emulator.Frame])) { - StateLastValidIndex = Global.Emulator.Frame; + TruncateStates(Global.Emulator.Frame); } } public int CapturedStateCount() { - return StateList.Count; + return StateRecords.Count; } - public int LastValidState() + public int ValidStateCount() { - return StateLastValidIndex; + return StateRecords.Count; } public byte[] GetState(int frame) { - return StateList[frame]; + return StateRecords[frame]; } public void DeleteFrame(int frame) { MovieRecords.RemoveAt(frame); - if (frame < StateList.Count) + if (frame < StateRecords.Count) { - StateList.RemoveAt(frame); - } - if (StateLastValidIndex > frame) - { - StateLastValidIndex = frame; + StateRecords.RemoveAt(frame); } } public void ClearStates() { - StateList.Clear(); - StateLastValidIndex = -1; + StateRecords.Clear(); } - public void Truncate(int frame) + public void TruncateFrames(int frame) { - if (frame >= 0 && frame < Length()) - { MovieRecords.RemoveRange(frame, Length() - frame); } + if (frame >= 0 && frame < MovieLength()) + { + MovieRecords.RemoveRange(frame, MovieLength() - frame); + } + } + + public void TruncateStates(int frame) + { + if (frame >= 0 && frame < StateLength()) + { + StateRecords.RemoveRange(frame, StateLength() - frame); + } } public string GetFrame(int frameCount) //Frame count is 0 based here, should it be? @@ -133,7 +136,7 @@ namespace BizHawk.MultiClient public void WriteText(StreamWriter sw) { - int length = Length(); + int length = MovieLength(); for (int x = 0; x < length; x++) { sw.WriteLine(GetFrame(x)); diff --git a/BizHawk.MultiClient/tools/TAStudio.Designer.cs b/BizHawk.MultiClient/tools/TAStudio.Designer.cs index 0a7a3e8330..8503b40503 100644 --- a/BizHawk.MultiClient/tools/TAStudio.Designer.cs +++ b/BizHawk.MultiClient/tools/TAStudio.Designer.cs @@ -64,7 +64,8 @@ this.ReadOnlyCheckBox = new System.Windows.Forms.CheckBox(); this.toolTip1 = new System.Windows.Forms.ToolTip(this.components); this.contextMenuStrip1 = new System.Windows.Forms.ContextMenuStrip(this.components); - this.InsertOneFrame = new System.Windows.Forms.ToolStripMenuItem(); + this.Insert = new System.Windows.Forms.ToolStripMenuItem(); + this.Delete = new System.Windows.Forms.ToolStripMenuItem(); this.SelectAll = new System.Windows.Forms.ToolStripMenuItem(); this.ControllerBox = new System.Windows.Forms.GroupBox(); this.ControllersContext = new System.Windows.Forms.ContextMenuStrip(this.components); @@ -82,7 +83,6 @@ this.TASView = new BizHawk.VirtualListView(); this.Frame = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.Log = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); - this.DeleteFrames = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip1.SuspendLayout(); this.contextMenuStrip1.SuspendLayout(); this.ControllersContext.SuspendLayout(); @@ -294,18 +294,25 @@ // contextMenuStrip1 // this.contextMenuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.InsertOneFrame, - this.DeleteFrames, + this.Insert, + this.Delete, this.SelectAll}); this.contextMenuStrip1.Name = "contextMenuStrip1"; this.contextMenuStrip1.Size = new System.Drawing.Size(157, 70); // - // InsertOneFrame + // Insert // - this.InsertOneFrame.Name = "InsertOneFrame"; - this.InsertOneFrame.Size = new System.Drawing.Size(156, 22); - this.InsertOneFrame.Text = "Insert Frame"; - this.InsertOneFrame.Click += new System.EventHandler(this.InsertOneFrame_Click); + this.Insert.Name = "Insert"; + this.Insert.Size = new System.Drawing.Size(156, 22); + this.Insert.Text = "Insert Frame(s)"; + this.Insert.Click += new System.EventHandler(this.Insert_Click); + // + // Delete + // + this.Delete.Name = "Delete"; + this.Delete.Size = new System.Drawing.Size(156, 22); + this.Delete.Text = "Delete Frame(s)"; + this.Delete.Click += new System.EventHandler(this.Delete_Click); // // SelectAll // @@ -483,13 +490,6 @@ this.Log.Text = "Log"; this.Log.Width = 201; // - // DeleteFrames - // - this.DeleteFrames.Name = "DeleteFrames"; - this.DeleteFrames.Size = new System.Drawing.Size(156, 22); - this.DeleteFrames.Text = "Delete Frame(s)"; - this.DeleteFrames.Click += new System.EventHandler(this.DeleteFrames_Click); - // // TAStudio // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); @@ -551,7 +551,7 @@ private System.Windows.Forms.ToolStripButton FastFowardToEnd; private System.Windows.Forms.ToolStripMenuItem insertFrameToolStripMenuItem; private System.Windows.Forms.ContextMenuStrip contextMenuStrip1; - private System.Windows.Forms.ToolStripMenuItem InsertOneFrame; + private System.Windows.Forms.ToolStripMenuItem Insert; private System.Windows.Forms.ToolStripMenuItem SelectAll; private System.Windows.Forms.GroupBox ControllerBox; private System.Windows.Forms.ToolStripSeparator toolStripSeparator6; @@ -564,6 +564,6 @@ private System.Windows.Forms.ToolStripMenuItem clearToolStripMenuItem1; private System.Windows.Forms.ToolStripButton FastForward; private System.Windows.Forms.ToolStripButton TurboFastForward; - private System.Windows.Forms.ToolStripMenuItem DeleteFrames; + private System.Windows.Forms.ToolStripMenuItem Delete; } } \ No newline at end of file diff --git a/BizHawk.MultiClient/tools/TAStudio.cs b/BizHawk.MultiClient/tools/TAStudio.cs index b941bdf87d..eb74285be9 100644 --- a/BizHawk.MultiClient/tools/TAStudio.cs +++ b/BizHawk.MultiClient/tools/TAStudio.cs @@ -104,9 +104,9 @@ namespace BizHawk.MultiClient private void TASView_QueryItemBkColor(int index, int column, ref Color color) { - if (index <= Global.MovieSession.Movie.LastValidState()) + if (index < Global.MovieSession.Movie.ValidStateCount()) color = Color.LightGreen; - else if (Global.MovieSession.Movie.GetInputFrame(index)[1] == 'L') + else if ("" != Global.MovieSession.Movie.GetInputFrame(index) && Global.MovieSession.Movie.GetInputFrame(index)[1] == 'L') color = Color.Pink; if (index == Global.Emulator.Frame) { @@ -117,15 +117,25 @@ namespace BizHawk.MultiClient private void TASView_QueryItemText(int index, int column, out string text) { text = ""; - if (column == 0) - text = String.Format("{0:#,##0}", index); - if (column == 1) - text = Global.MovieSession.Movie.GetInputFrame(index); + + //If this is just for an actual frame and not just the list view cursor at the end + if (Global.MovieSession.Movie.LogLength() != index) + { + if (column == 0) + text = String.Format("{0:#,##0}", index); + if (column == 1) + text = Global.MovieSession.Movie.GetInputFrame(index); + } } private void DisplayList() { - TASView.ItemCount = Global.MovieSession.Movie.Length(); + TASView.ItemCount = Global.MovieSession.Movie.LogLength(); + if (Global.MovieSession.Movie.LogLength() == Global.Emulator.Frame && Global.MovieSession.Movie.StateLength() == Global.Emulator.Frame) + { + //If we're at the end of the movie add one to show the cursor as a blank frame + TASView.ItemCount++; + } TASView.ensureVisible(Global.Emulator.Frame-1); } @@ -473,15 +483,23 @@ namespace BizHawk.MultiClient Global.MovieSession.Movie.RewindToFrame(TASView.selectedItem); } - private void InsertOneFrame_Click(object sender, EventArgs e) + private void Insert_Click(object sender, EventArgs e) { - Global.MovieSession.Movie.InsertFrame(Global.MovieSession.Movie.GetInputFrame(TASView.selectedItem), TASView.selectedItem); + ListView.SelectedIndexCollection list = TASView.SelectedIndices; + for (int index = 0; index < list.Count; index++) + { + Global.MovieSession.Movie.InsertFrame(Global.MovieSession.Movie.GetInputFrame(list[index]), (int)list[index]); + } Global.MovieSession.Movie.RewindToFrame(TASView.selectedItem); } - private void DeleteFrames_Click(object sender, EventArgs e) + private void Delete_Click(object sender, EventArgs e) { - Global.MovieSession.Movie.DeleteFrame(TASView.selectedItem); + ListView.SelectedIndexCollection list = TASView.SelectedIndices; + for (int index = 0; index < list.Count; index++) + { + Global.MovieSession.Movie.DeleteFrame(TASView.selectedItem); + } } } }