diff --git a/BizHawk.Client.Common/movie/tasproj/TasLagLog.cs b/BizHawk.Client.Common/movie/tasproj/TasLagLog.cs index 0c923cb565..bb5476b378 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasLagLog.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasLagLog.cs @@ -65,6 +65,8 @@ namespace BizHawk.Client.Common else WasLag[frame] = wasValue; + if (frame != 0) + WasLag[frame - 1] = LagLog[frame - 1]; if (frame >= LagLog.Count) LagLog.Add(value.Value); else @@ -89,7 +91,8 @@ namespace BizHawk.Client.Common } public void InsertHistoryAt(int frame, bool isLag) { // LagLog was invalidated when the frame was inserted - LagLog.Insert(frame, isLag); + if (frame <= LagLog.Count) + LagLog.Insert(frame, isLag); WasLag.Insert(frame, isLag); } @@ -113,30 +116,30 @@ namespace BizHawk.Client.Common WasLag.Clear(); //if (br.BaseStream.Length > 0) //{ BaseStream.Length does not return the expected value. - int formatVersion = br.ReadByte(); - if (formatVersion == 0) + int formatVersion = br.ReadByte(); + if (formatVersion == 0) + { + int length = (br.ReadByte() << 8) | formatVersion; // The first byte should be a part of length. + length = (br.ReadInt16() << 16) | length; + for (int i = 0; i < length; i++) { - int length = (br.ReadByte() << 8) | formatVersion; // The first byte should be a part of length. - length = (br.ReadInt16() << 16) | length; - for (int i = 0; i < length; i++) - { - br.ReadInt32(); - LagLog.Add(br.ReadBoolean()); - WasLag.Add(LagLog.Last()); - } + br.ReadInt32(); + LagLog.Add(br.ReadBoolean()); + WasLag.Add(LagLog.Last()); } - else if (formatVersion == 1) + } + else if (formatVersion == 1) + { + int length = br.ReadInt32(); + int lenWas = br.ReadInt32(); + for (int i = 0; i < length; i++) { - int length = br.ReadInt32(); - int lenWas = br.ReadInt32(); - for (int i = 0; i < length; i++) - { - LagLog.Add(br.ReadBoolean()); - WasLag.Add(br.ReadBoolean()); - } - for (int i = length; i < lenWas; i++) - WasLag.Add(br.ReadBoolean()); + LagLog.Add(br.ReadBoolean()); + WasLag.Add(br.ReadBoolean()); } + for (int i = length; i < lenWas; i++) + WasLag.Add(br.ReadBoolean()); + } //} } diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs b/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs index 348b1b22e4..769c01bd95 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovie.Editing.cs @@ -87,6 +87,8 @@ namespace BizHawk.Client.Common _log.RemoveAt(frame); if (BindMarkersToInput) { + bool wasRecording = ChangeLog.IsRecording; + ChangeLog.IsRecording = false; int firstIndex = Markers.FindIndex(m => m.Frame >= frame); if (firstIndex != -1) { @@ -99,6 +101,7 @@ namespace BizHawk.Client.Common Markers.Move(m.Frame, m.Frame - 1); } } + ChangeLog.IsRecording = wasRecording; } Changes = true; @@ -122,6 +125,8 @@ namespace BizHawk.Client.Common _log.RemoveAt(frame); if (BindMarkersToInput) // TODO: This is slow, is there a better way to do it? { + bool wasRecording = ChangeLog.IsRecording; + ChangeLog.IsRecording = false; int firstIndex = Markers.FindIndex(m => m.Frame >= frame); if (firstIndex != -1) { @@ -134,6 +139,7 @@ namespace BizHawk.Client.Common Markers.Move(m.Frame, m.Frame - 1); } } + ChangeLog.IsRecording = wasRecording; } } @@ -155,6 +161,8 @@ namespace BizHawk.Client.Common if (BindMarkersToInput) { + bool wasRecording = ChangeLog.IsRecording; + ChangeLog.IsRecording = false; int firstIndex = Markers.FindIndex(m => m.Frame >= removeStart); if (firstIndex != -1) { @@ -167,6 +175,7 @@ namespace BizHawk.Client.Common Markers.Move(m.Frame, m.Frame - (removeUpTo - removeStart)); } } + ChangeLog.IsRecording = wasRecording; } Changes = true; @@ -188,6 +197,8 @@ namespace BizHawk.Client.Common if (BindMarkersToInput) { + bool wasRecording = ChangeLog.IsRecording; + ChangeLog.IsRecording = false; int firstIndex = Markers.FindIndex(m => m.Frame >= frame); if (firstIndex != -1) { @@ -197,6 +208,7 @@ namespace BizHawk.Client.Common Markers.Move(m.Frame, m.Frame + 1); } } + ChangeLog.IsRecording = wasRecording; } ChangeLog.SetGeneralRedo(); @@ -212,9 +224,10 @@ namespace BizHawk.Client.Common Changes = true; InvalidateAfter(frame); - if (BindMarkersToInput) { + bool wasRecording = ChangeLog.IsRecording; + ChangeLog.IsRecording = false; int firstIndex = Markers.FindIndex(m => m.Frame >= frame); if (firstIndex != -1) { @@ -224,6 +237,7 @@ namespace BizHawk.Client.Common Markers.Move(m.Frame, m.Frame + inputLog.Count()); } } + ChangeLog.IsRecording = wasRecording; } ChangeLog.SetGeneralRedo(); @@ -277,6 +291,8 @@ namespace BizHawk.Client.Common if (BindMarkersToInput) { + bool wasRecording = ChangeLog.IsRecording; + ChangeLog.IsRecording = false; int firstIndex = Markers.FindIndex(m => m.Frame >= frame); if (firstIndex != -1) { @@ -286,6 +302,7 @@ namespace BizHawk.Client.Common Markers.Move(m.Frame, m.Frame + count); } } + ChangeLog.IsRecording = wasRecording; } diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovie.History.cs b/BizHawk.Client.Common/movie/tasproj/TasMovie.History.cs index d0871f9f0f..d7a2a4617e 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovie.History.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovie.History.cs @@ -276,6 +276,15 @@ namespace BizHawk.Client.Common History.Last().Add(new MovieActionMarker(newMarker, oldPosition, old_message)); } } + + public void AddInputBind(int frame, bool isDelete, string name = "", bool force = false) + { + if (IsRecording || force) + { + AddMovieAction(name); + History.Last().Add(new MovieActionBindInput(Movie, frame, isDelete)); + } + } #endregion } @@ -502,10 +511,16 @@ namespace BizHawk.Client.Common bool wasRecording = movie.ChangeLog.IsRecording; movie.ChangeLog.IsRecording = false; - //if (isFloat) - // movie.SetFloatStates(FirstFrame, LastFrame - FirstFrame + 1, buttonName, oldState); - //else - // movie.SetBoolState(FirstFrame, buttonName, oldState == 1); + if (isFloat) + { + for (int i = 0; i < oldState.Count; i++) + movie.SetFloatState(FirstFrame + i, buttonName, oldState[i]); + } + else + { + for (int i = 0; i < oldState.Count; i++) + movie.SetBoolState(FirstFrame + i, buttonName, oldState[i] == 1); + } movie.ChangeLog.IsRecording = wasRecording; } @@ -522,5 +537,67 @@ namespace BizHawk.Client.Common movie.ChangeLog.IsRecording = wasRecording; } } + + public class MovieActionBindInput : IMovieAction + { + public int FirstFrame { get; private set; } + public int LastFrame { get; private set; } + + private string log; + private bool delete; + + private bool bindMarkers; + + public MovieActionBindInput(TasMovie movie, int frame, bool isDelete) + { + FirstFrame = LastFrame = frame; + log = movie.GetInputLogEntry(frame); + delete = isDelete; + bindMarkers = movie.BindMarkersToInput; + } + + public void Undo(TasMovie movie) + { + bool wasRecording = movie.ChangeLog.IsRecording; + bool wasBinding = movie.BindMarkersToInput; + movie.ChangeLog.IsRecording = false; + movie.BindMarkersToInput = bindMarkers; + + if (delete) // Insert + { + movie.InsertInput(FirstFrame, log); + movie.InsertLagHistory(FirstFrame + 1, true); + } + else // Delete + { + movie.RemoveFrame(FirstFrame); + movie.RemoveLagHistory(FirstFrame + 1); + } + + movie.ChangeLog.IsRecording = wasRecording; + movie.BindMarkersToInput = bindMarkers; + } + public void Redo(TasMovie movie) + { + bool wasRecording = movie.ChangeLog.IsRecording; + bool wasBinding = movie.BindMarkersToInput; + movie.ChangeLog.IsRecording = false; + movie.BindMarkersToInput = bindMarkers; + + if (delete) + { + movie.RemoveFrame(FirstFrame); + movie.RemoveLagHistory(FirstFrame + 1); + } + else + { + movie.InsertInput(FirstFrame, log); + movie.InsertLagHistory(FirstFrame + 1, true); + } + + movie.ChangeLog.IsRecording = wasRecording; + movie.BindMarkersToInput = bindMarkers; + } + } #endregion } \ No newline at end of file diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.Designer.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.Designer.cs index 596e905a9a..8488b81e49 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/GreenzoneSettings.Designer.cs @@ -165,11 +165,6 @@ namespace BizHawk.Client.EmuHawk 65536, 0, 0, - 0}); - this.DiskCapacityNumeric.Minimum = new decimal(new int[] { - 1, - 0, - 0, 0}); this.DiskCapacityNumeric.Name = "DiskCapacityNumeric"; this.DiskCapacityNumeric.Size = new System.Drawing.Size(55, 20); @@ -206,11 +201,6 @@ namespace BizHawk.Client.EmuHawk 65536, 0, 0, - 0}); - this.SaveCapacityNumeric.Minimum = new decimal(new int[] { - 1, - 0, - 0, 0}); this.SaveCapacityNumeric.Name = "SaveCapacityNumeric"; this.SaveCapacityNumeric.Size = new System.Drawing.Size(55, 20); diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs index 0c8192fda5..1b5d68c827 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs @@ -867,9 +867,9 @@ namespace BizHawk.Client.EmuHawk } int player = 0; - foreach (var column in columns) + foreach (InputRoll.RollColumn column in columns) { - var menuItem = new ToolStripMenuItem + ToolStripMenuItem menuItem = new ToolStripMenuItem { Text = column.Text + " (" + column.Name + ")", Checked = column.Visible, @@ -888,14 +888,16 @@ namespace BizHawk.Client.EmuHawk (sender.OwnerItem as ToolStripMenuItem).ShowDropDown(); }; - if (column.Name.StartsWith("P" + (player + 1))) - { - player++; - ColumnsSubMenu.DropDownItems.Add(playerMenus[player]); - } + if (column.Name.StartsWith("P") && char.IsNumber(column.Name, 1)) + player = int.Parse(column.Name[1].ToString()); + else + player = 0; playerMenus[player].DropDownItems.Add(menuItem); } + for (int i = 1; i < playerMenus.Length; i++) + ColumnsSubMenu.DropDownItems.Add(playerMenus[i]); + ColumnsSubMenu.DropDownItems.Add(new ToolStripSeparator()); for (int i = 1; i < playerMenus.Length; i++) { diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Navigation.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Navigation.cs index 53fb73b594..d6ec5da7d6 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Navigation.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.Navigation.cs @@ -38,7 +38,7 @@ namespace BizHawk.Client.EmuHawk { if (frame < Emulator.Frame) // We are rewinding { - var goToFrame = frame == 0 ? 0 : frame - 1; + int goToFrame = frame == 0 ? 0 : frame - 1; if (CurrentTasMovie[goToFrame].HasState) // Go back 1 frame and emulate to get the display (we don't store that) { @@ -47,7 +47,10 @@ namespace BizHawk.Client.EmuHawk if (frame > 0) // We can't emulate up to frame 0! { + bool wasPaused = GlobalWin.MainForm.EmulatorPaused; GlobalWin.MainForm.FrameAdvance(); + if (!wasPaused) + GlobalWin.MainForm.UnpauseEmulator(); } GlobalWin.DisplayManager.NeedsToPaint = true; @@ -63,7 +66,10 @@ namespace BizHawk.Client.EmuHawk { if (frame == Emulator.Frame + 1) // Just emulate a frame we only have 1 to go! { + bool wasPaused = GlobalWin.MainForm.EmulatorPaused; GlobalWin.MainForm.FrameAdvance(); + if (!wasPaused) + GlobalWin.MainForm.UnpauseEmulator(); } else { @@ -89,7 +95,10 @@ namespace BizHawk.Client.EmuHawk { if (frame == Emulator.Frame + 1) // We are at the end of the movie and advancing one frame, therefore we are recording, simply emulate a frame { + bool wasPaused = GlobalWin.MainForm.EmulatorPaused; GlobalWin.MainForm.FrameAdvance(); + if (!wasPaused) + GlobalWin.MainForm.UnpauseEmulator(); } else { diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index 1bc1cb7a1e..c522422ba0 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -217,6 +217,8 @@ namespace BizHawk.Client.EmuHawk { TasView.LoadSettingsSerialized(settingsJson); RefreshTasView(); + + SetUpToolStripColumns(); } private void SetUpColumns() @@ -353,6 +355,7 @@ namespace BizHawk.Client.EmuHawk CurrentTasMovie.PropertyChanged += new PropertyChangedEventHandler(this.TasMovie_OnPropertyChanged); CurrentTasMovie.Filename = DefaultTasProjName(); // TODO don't do this, take over any mainform actions that can crash without a filename CurrentTasMovie.PopulateWithDefaultHeaderValues(); + SetTasMovieCallbacks(); CurrentTasMovie.ClearChanges(); // Don't ask to save changes here. HandleMovieLoadStuff(); @@ -371,9 +374,9 @@ namespace BizHawk.Client.EmuHawk return false; WantsToControlStopMovie = true; + CurrentTasMovie.ChangeLog.ClearLog(); CurrentTasMovie.ClearChanges(); - SetTasMovieCallbacks(); SetTextProperty(); MessageStatusLabel.Text = Path.GetFileName(CurrentTasMovie.Filename) + " loaded."; @@ -500,6 +503,7 @@ namespace BizHawk.Client.EmuHawk CurrentTasMovie.FlushInputCache(); CurrentTasMovie.UseInputCache = false; + lastRefresh = Global.Emulator.Frame; } private void DoAutoRestore() @@ -508,8 +512,8 @@ namespace BizHawk.Client.EmuHawk { if (_autoRestoreFrame > Emulator.Frame) // Don't unpause if we are already on the desired frame, else runaway seek { - GlobalWin.MainForm.UnpauseEmulator(); GlobalWin.MainForm.PauseOnFrame = _autoRestoreFrame; + GlobalWin.MainForm.UnpauseEmulator(); } } @@ -525,7 +529,8 @@ namespace BizHawk.Client.EmuHawk LoadState(closestState); } - GlobalWin.MainForm.PauseOnFrame = frame; + if (GlobalWin.MainForm.EmulatorPaused) + GlobalWin.MainForm.PauseOnFrame = frame; GlobalWin.MainForm.UnpauseEmulator(); } @@ -751,15 +756,27 @@ namespace BizHawk.Client.EmuHawk { if (lagLog.WasLagged.Value && !isLag) { // Deleting this frame requires rewinding a frame. + CurrentTasMovie.ChangeLog.AddInputBind(Global.Emulator.Frame - 1, true, "Bind Input; Delete " + (Global.Emulator.Frame - 1)); + bool wasRecording = CurrentTasMovie.ChangeLog.IsRecording; + CurrentTasMovie.ChangeLog.IsRecording = false; + CurrentTasMovie.RemoveFrame(Global.Emulator.Frame - 1); - CurrentTasMovie.RemoveLagHistory(Global.Emulator.Frame); // Set frame is not +1. [should change?] + CurrentTasMovie.RemoveLagHistory(Global.Emulator.Frame); // Removes from WasLag + + CurrentTasMovie.ChangeLog.IsRecording = wasRecording; GoToFrame(Emulator.Frame - 1); return true; } else if (!lagLog.WasLagged.Value && isLag) { // (it shouldn't need to rewind, since the inserted input wasn't polled) + CurrentTasMovie.ChangeLog.AddInputBind(Global.Emulator.Frame - 1, false, "Bind Input; Insert " + (Global.Emulator.Frame - 1)); + bool wasRecording = CurrentTasMovie.ChangeLog.IsRecording; + CurrentTasMovie.ChangeLog.IsRecording = false; + CurrentTasMovie.InsertInput(Global.Emulator.Frame - 1, CurrentTasMovie.GetInputLogEntry(Emulator.Frame - 2)); - CurrentTasMovie.InsertLagHistory(Global.Emulator.Frame - 1, true); + CurrentTasMovie.InsertLagHistory(Global.Emulator.Frame, true); + + CurrentTasMovie.ChangeLog.IsRecording = wasRecording; return true; } }