From 4188f2105e37cc5b42604300b4186cf02439282c Mon Sep 17 00:00:00 2001 From: adelikat Date: Sun, 19 Jul 2015 10:37:53 -0400 Subject: [PATCH] Tastudio - branches - ability to load a branch, currently the frame buffer does not have OSD info --- BizHawk.Client.Common/SavestateManager.cs | 11 +++ .../movie/tasproj/TasBranch.cs | 3 +- .../movie/tasproj/TasLagLog.cs | 20 +++++- .../movie/tasproj/TasMovie.cs | 11 +++ .../movie/tasproj/TasStateManager.cs | 3 +- .../TAStudio/BookmarksBranchesBox.Designer.cs | 70 ++++++++++++------- .../tools/TAStudio/BookmarksBranchesBox.cs | 38 ++++++++-- .../tools/TAStudio/TAStudio.cs | 2 +- 8 files changed, 123 insertions(+), 35 deletions(-) diff --git a/BizHawk.Client.Common/SavestateManager.cs b/BizHawk.Client.Common/SavestateManager.cs index 58885a8b0d..6d126d966a 100644 --- a/BizHawk.Client.Common/SavestateManager.cs +++ b/BizHawk.Client.Common/SavestateManager.cs @@ -106,6 +106,17 @@ namespace BizHawk.Client.Common } } + public static void PopulateFramebuffer(byte[] bytes) + { + using (var ms = new MemoryStream(bytes)) + { + using (var br = new BinaryReader(ms)) + { + PopulateFramebuffer(br); + } + } + } + public static bool LoadStateFile(string path, string name) { var core = Global.Emulator.AsStatable(); diff --git a/BizHawk.Client.Common/movie/tasproj/TasBranch.cs b/BizHawk.Client.Common/movie/tasproj/TasBranch.cs index 72c3fa6068..d7fe08ac64 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasBranch.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasBranch.cs @@ -9,7 +9,8 @@ namespace BizHawk.Client.Common public int Frame { get; set; } public byte[] CoreData { get; set; } public List InputLog { get; set; } - public byte[] OSDFrameBuffer { get; set; } + public int[] OSDFrameBuffer { get; set; } + public TasLagLog LagLog { get; set; } } public class TasBranchCollection : List diff --git a/BizHawk.Client.Common/movie/tasproj/TasLagLog.cs b/BizHawk.Client.Common/movie/tasproj/TasLagLog.cs index 060600b441..62ff8864d4 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasLagLog.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasLagLog.cs @@ -10,9 +10,9 @@ namespace BizHawk.Client.Common public class TasLagLog { // TODO: Change this into a regular list. - private readonly List LagLog = new List(); + private List LagLog = new List(); - private readonly List WasLag = new List(); + private List WasLag = new List(); public bool? this[int frame] { @@ -155,6 +155,7 @@ namespace BizHawk.Client.Common return null; } + public int LastValidFrame { get @@ -164,5 +165,20 @@ namespace BizHawk.Client.Common return LagLog.Count - 1; } } + + public TasLagLog Clone() + { + var log = new TasLagLog(); + log.LagLog = LagLog.ToList(); + log.WasLag = LagLog.ToList(); + + return log; + } + + public void FromLagLog(TasLagLog log) + { + LagLog = log.LagLog; + WasLag = log.WasLag; + } } } diff --git a/BizHawk.Client.Common/movie/tasproj/TasMovie.cs b/BizHawk.Client.Common/movie/tasproj/TasMovie.cs index 6ce8d7302c..dbc5ce1479 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasMovie.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasMovie.cs @@ -455,5 +455,16 @@ namespace BizHawk.Client.Common return true; } + + public void LoadBranch(TasBranch branch) + { + // TODO: undo? + _log = branch.InputLog; + _changes = true; + StateManager.ClearStateHistory(); + StateManager.SetState(branch.Frame, branch.CoreData); + LagLog.Clear(); + LagLog.FromLagLog(branch.LagLog); + } } } diff --git a/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs b/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs index 394783343a..e0d1f1a1eb 100644 --- a/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs +++ b/BizHawk.Client.Common/movie/tasproj/TasStateManager.cs @@ -259,7 +259,8 @@ namespace BizHawk.Client.Common File.Delete(path); } - private void SetState(int frame, byte[] state) + + internal void SetState(int frame, byte[] state) { if (States.ContainsKey(frame)) { diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.Designer.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.Designer.cs index 874aef230f..3c4978e9a1 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.Designer.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.Designer.cs @@ -30,13 +30,15 @@ { this.components = new System.ComponentModel.Container(); this.BookmarksBranchesGroupBox = new System.Windows.Forms.GroupBox(); - this.BranchesContextMenu = new System.Windows.Forms.ContextMenuStrip(this.components); - this.AddContextMenu = new System.Windows.Forms.ToolStripMenuItem(); - this.RemoveBranchContextMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.BranchView = new BizHawk.Client.EmuHawk.VirtualListView(); this.BranchNumberColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.FrameColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); this.TimeColumn = ((System.Windows.Forms.ColumnHeader)(new System.Windows.Forms.ColumnHeader())); + this.BranchesContextMenu = new System.Windows.Forms.ContextMenuStrip(this.components); + this.AddContextMenu = new System.Windows.Forms.ToolStripMenuItem(); + this.RemoveBranchContextMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.LoadBranchContextMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.BookmarksBranchesGroupBox.SuspendLayout(); this.BranchesContextMenu.SuspendLayout(); this.SuspendLayout(); @@ -54,29 +56,6 @@ this.BookmarksBranchesGroupBox.TabStop = false; this.BookmarksBranchesGroupBox.Text = "Bookmarks / Branches"; // - // BranchesContextMenu - // - this.BranchesContextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { - this.AddContextMenu, - this.RemoveBranchContextMenuItem}); - this.BranchesContextMenu.Name = "BranchesContextMenu"; - this.BranchesContextMenu.Size = new System.Drawing.Size(153, 70); - this.BranchesContextMenu.Opening += new System.ComponentModel.CancelEventHandler(this.BranchesContextMenu_Opening); - // - // AddContextMenu - // - this.AddContextMenu.Name = "AddContextMenu"; - this.AddContextMenu.Size = new System.Drawing.Size(152, 22); - this.AddContextMenu.Text = "Add"; - this.AddContextMenu.Click += new System.EventHandler(this.AddContextMenu_Click); - // - // RemoveBranchContextMenuItem - // - this.RemoveBranchContextMenuItem.Name = "RemoveBranchContextMenuItem"; - this.RemoveBranchContextMenuItem.Size = new System.Drawing.Size(152, 22); - this.RemoveBranchContextMenuItem.Text = "Remove"; - this.RemoveBranchContextMenuItem.Click += new System.EventHandler(this.RemoveBranchContextMenuItem_Click); - // // BranchView // this.BranchView.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) @@ -118,6 +97,43 @@ this.TimeColumn.Text = "Length"; this.TimeColumn.Width = 83; // + // BranchesContextMenu + // + this.BranchesContextMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { + this.LoadBranchContextMenuItem, + this.toolStripSeparator1, + this.AddContextMenu, + this.RemoveBranchContextMenuItem}); + this.BranchesContextMenu.Name = "BranchesContextMenu"; + this.BranchesContextMenu.Size = new System.Drawing.Size(153, 98); + this.BranchesContextMenu.Opening += new System.ComponentModel.CancelEventHandler(this.BranchesContextMenu_Opening); + // + // AddContextMenu + // + this.AddContextMenu.Name = "AddContextMenu"; + this.AddContextMenu.Size = new System.Drawing.Size(152, 22); + this.AddContextMenu.Text = "Add"; + this.AddContextMenu.Click += new System.EventHandler(this.AddContextMenu_Click); + // + // RemoveBranchContextMenuItem + // + this.RemoveBranchContextMenuItem.Name = "RemoveBranchContextMenuItem"; + this.RemoveBranchContextMenuItem.Size = new System.Drawing.Size(152, 22); + this.RemoveBranchContextMenuItem.Text = "Remove"; + this.RemoveBranchContextMenuItem.Click += new System.EventHandler(this.RemoveBranchContextMenuItem_Click); + // + // LoadBranchContextMenuItem + // + this.LoadBranchContextMenuItem.Name = "LoadBranchContextMenuItem"; + this.LoadBranchContextMenuItem.Size = new System.Drawing.Size(152, 22); + this.LoadBranchContextMenuItem.Text = "Load"; + this.LoadBranchContextMenuItem.Click += new System.EventHandler(this.LoadBranchContextMenuItem_Click); + // + // toolStripSeparator1 + // + this.toolStripSeparator1.Name = "toolStripSeparator1"; + this.toolStripSeparator1.Size = new System.Drawing.Size(149, 6); + // // BookmarksBranchesBox // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit; @@ -140,5 +156,7 @@ private System.Windows.Forms.ContextMenuStrip BranchesContextMenu; private System.Windows.Forms.ToolStripMenuItem AddContextMenu; private System.Windows.Forms.ToolStripMenuItem RemoveBranchContextMenuItem; + private System.Windows.Forms.ToolStripMenuItem LoadBranchContextMenuItem; + private System.Windows.Forms.ToolStripSeparator toolStripSeparator1; } } diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs index 83a24969fe..2681a01e65 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/BookmarksBranchesBox.cs @@ -9,6 +9,7 @@ using System.Windows.Forms; using BizHawk.Emulation.Common; using BizHawk.Client.Common; +using BizHawk.Common; namespace BizHawk.Client.EmuHawk { @@ -77,9 +78,11 @@ namespace BizHawk.Client.EmuHawk var branch = new TasBranch { Frame = Global.Emulator.Frame, - CoreData = (Global.Emulator as IStatable).SaveStateBinary(), + CoreData = (byte[])((Global.Emulator as IStatable).SaveStateBinary().Clone()), InputLog = Tastudio.CurrentTasMovie.InputLog.ToList(), - OSDFrameBuffer = GlobalWin.MainForm.CurrentFrameBuffer(captureOSD: true) + //OSDFrameBuffer = GlobalWin.MainForm.CurrentFrameBuffer(captureOSD: true), + OSDFrameBuffer = (int[])(Global.Emulator.VideoProvider().GetVideoBuffer().Clone()), + LagLog = Tastudio.CurrentTasMovie.TasLagLog.Clone() }; Branches.Add(branch); @@ -94,9 +97,19 @@ namespace BizHawk.Client.EmuHawk } } + private void LoadBranchContextMenuItem_Click(object sender, EventArgs e) + { + if (SelectedBranch != null) + { + LoadBranch(SelectedBranch); + } + } + private void BranchesContextMenu_Opening(object sender, CancelEventArgs e) { - RemoveBranchContextMenuItem.Enabled = SelectedBranch != null; + RemoveBranchContextMenuItem.Enabled = + LoadBranchContextMenuItem.Enabled = + SelectedBranch != null; } private void RemoveBranchContextMenuItem_Click(object sender, EventArgs e) @@ -108,9 +121,26 @@ namespace BizHawk.Client.EmuHawk } } + private void Temp(int[] framebuffer) + { + var buff = Global.Emulator.VideoProvider().GetVideoBuffer(); + for (int i = 0; i < buff.Length; i++) + { + buff[i] = framebuffer[i]; + } + } + private void LoadBranch(TasBranch branch) { - MessageBox.Show("TODO: load this branch"); + Tastudio.CurrentTasMovie.LoadBranch(branch); + GlobalWin.DisplayManager.NeedsToPaint = true; + var stateInfo = new KeyValuePair(branch.Frame, branch.CoreData); + Tastudio.LoadState(stateInfo); + //SavestateManager.PopulateFramebuffer(branch.OSDFrameBuffer); + Temp(branch.OSDFrameBuffer); + GlobalWin.MainForm.PauseEmulator(); + GlobalWin.MainForm.PauseOnFrame = null; + Tastudio.RefreshDialog(); } } } diff --git a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index bcf5c5d60d..0646b3e9ff 100644 --- a/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -558,7 +558,7 @@ namespace BizHawk.Client.EmuHawk } } - private void LoadState(KeyValuePair state) + public void LoadState(KeyValuePair state) { StatableEmulator.LoadStateBinary(new BinaryReader(new MemoryStream(state.Value.ToArray())));