Remove some duplicate/unused code in MultiHawk.
This commit is contained in:
parent
88bb910405
commit
93aeffe69e
|
@ -1,10 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
using BizHawk.Common;
|
|
||||||
using BizHawk.Emulation.Common;
|
|
||||||
using BizHawk.Client.Common;
|
|
||||||
|
|
||||||
using BizHawk.Bizware.BizwareGL;
|
using BizHawk.Bizware.BizwareGL;
|
||||||
|
|
||||||
namespace BizHawk.Client.EmuHawk
|
namespace BizHawk.Client.EmuHawk
|
||||||
|
@ -13,7 +9,7 @@ namespace BizHawk.Client.EmuHawk
|
||||||
/// Recycles a pair of temporary render targets, as long as the dimensions match.
|
/// Recycles a pair of temporary render targets, as long as the dimensions match.
|
||||||
/// When the dimensions dont match, a new one will be allocated
|
/// When the dimensions dont match, a new one will be allocated
|
||||||
/// </summary>
|
/// </summary>
|
||||||
class RenderTargetFrugalizer : IDisposable
|
public class RenderTargetFrugalizer : IDisposable
|
||||||
{
|
{
|
||||||
public RenderTargetFrugalizer(IGL gl)
|
public RenderTargetFrugalizer(IGL gl)
|
||||||
{
|
{
|
||||||
|
|
|
@ -104,15 +104,12 @@
|
||||||
<DependentUpon>RecordMovie.cs</DependentUpon>
|
<DependentUpon>RecordMovie.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="DisplayManager\DisplayManager.cs" />
|
<Compile Include="DisplayManager\DisplayManager.cs" />
|
||||||
<Compile Include="DisplayManager\RenderTargetFrugalizer.cs" />
|
|
||||||
<Compile Include="EmulatorWindow.cs">
|
<Compile Include="EmulatorWindow.cs">
|
||||||
<SubType>Form</SubType>
|
<SubType>Form</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="EmulatorWindow.Designer.cs">
|
<Compile Include="EmulatorWindow.Designer.cs">
|
||||||
<DependentUpon>EmulatorWindow.cs</DependentUpon>
|
<DependentUpon>EmulatorWindow.cs</DependentUpon>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="Extensions\ControlExtensions.cs" />
|
|
||||||
<Compile Include="Extensions\CoreExtensions.cs" />
|
|
||||||
<Compile Include="GlobalWin.cs" />
|
<Compile Include="GlobalWin.cs" />
|
||||||
<Compile Include="InputManager.cs" />
|
<Compile Include="InputManager.cs" />
|
||||||
<Compile Include="Input\GamePad.cs" />
|
<Compile Include="Input\GamePad.cs" />
|
||||||
|
|
|
@ -1,69 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
|
|
||||||
using BizHawk.Common;
|
|
||||||
using BizHawk.Emulation.Common;
|
|
||||||
using BizHawk.Client.Common;
|
|
||||||
|
|
||||||
using BizHawk.Bizware.BizwareGL;
|
|
||||||
|
|
||||||
namespace BizHawk.Client.MultiHawk
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// Recycles a pair of temporary render targets, as long as the dimensions match.
|
|
||||||
/// When the dimensions dont match, a new one will be allocated
|
|
||||||
/// </summary>
|
|
||||||
class RenderTargetFrugalizer : IDisposable
|
|
||||||
{
|
|
||||||
public RenderTargetFrugalizer(IGL gl)
|
|
||||||
{
|
|
||||||
GL = gl;
|
|
||||||
ResetList();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
foreach (var ct in CurrentRenderTargets)
|
|
||||||
if (ct != null)
|
|
||||||
ct.Dispose();
|
|
||||||
ResetList();
|
|
||||||
}
|
|
||||||
|
|
||||||
void ResetList()
|
|
||||||
{
|
|
||||||
CurrentRenderTargets = new List<RenderTarget>();
|
|
||||||
CurrentRenderTargets.Add(null);
|
|
||||||
CurrentRenderTargets.Add(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
IGL GL;
|
|
||||||
List<RenderTarget> CurrentRenderTargets;
|
|
||||||
|
|
||||||
public RenderTarget Get(System.Drawing.Size dimensions) { return Get(dimensions.Width, dimensions.Height); }
|
|
||||||
public RenderTarget Get(int width, int height)
|
|
||||||
{
|
|
||||||
//get the current entry
|
|
||||||
RenderTarget CurrentRenderTarget = CurrentRenderTargets[0];
|
|
||||||
|
|
||||||
//check if its rotten and needs recreating
|
|
||||||
if (CurrentRenderTarget == null || CurrentRenderTarget.Texture2d.IntWidth != width || CurrentRenderTarget.Texture2d.IntHeight != height)
|
|
||||||
{
|
|
||||||
//needs recreating. be sure to kill the old one...
|
|
||||||
if (CurrentRenderTarget != null)
|
|
||||||
CurrentRenderTarget.Dispose();
|
|
||||||
//and make a new one
|
|
||||||
CurrentRenderTarget = GL.CreateRenderTarget(width, height);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//its good! nothing more to do
|
|
||||||
}
|
|
||||||
|
|
||||||
//now shuffle the buffers
|
|
||||||
CurrentRenderTargets[0] = CurrentRenderTargets[1];
|
|
||||||
CurrentRenderTargets[1] = CurrentRenderTarget;
|
|
||||||
|
|
||||||
return CurrentRenderTarget;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,82 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Drawing.Imaging;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
using BizHawk.Common;
|
|
||||||
using BizHawk.Client.Common;
|
|
||||||
|
|
||||||
namespace BizHawk.Client.MultiHawk
|
|
||||||
{
|
|
||||||
/// <summary>
|
|
||||||
/// encapsulates thread-safe concept of pending/current display surfaces, reusing buffers where matching
|
|
||||||
/// sizes are available and keeping them cleaned up when they dont seem like theyll need to be used anymore
|
|
||||||
/// </summary>
|
|
||||||
class SwappableDisplaySurfaceSet
|
|
||||||
{
|
|
||||||
DisplaySurface Pending, Current;
|
|
||||||
bool IsPending;
|
|
||||||
Queue<DisplaySurface> ReleasedSurfaces = new Queue<DisplaySurface>();
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// retrieves a surface with the specified size, reusing an old buffer if available and clearing if requested
|
|
||||||
/// </summary>
|
|
||||||
public DisplaySurface AllocateSurface(int width, int height, bool needsClear = true)
|
|
||||||
{
|
|
||||||
for (; ; )
|
|
||||||
{
|
|
||||||
DisplaySurface trial;
|
|
||||||
lock (this)
|
|
||||||
{
|
|
||||||
if (ReleasedSurfaces.Count == 0) break;
|
|
||||||
trial = ReleasedSurfaces.Dequeue();
|
|
||||||
}
|
|
||||||
if (trial.Width == width && trial.Height == height)
|
|
||||||
{
|
|
||||||
if (needsClear) trial.Clear();
|
|
||||||
return trial;
|
|
||||||
}
|
|
||||||
trial.Dispose();
|
|
||||||
}
|
|
||||||
return new DisplaySurface(width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// sets the provided buffer as pending. takes control of the supplied buffer
|
|
||||||
/// </summary>
|
|
||||||
public void SetPending(DisplaySurface newPending)
|
|
||||||
{
|
|
||||||
lock (this)
|
|
||||||
{
|
|
||||||
if (Pending != null) ReleasedSurfaces.Enqueue(Pending);
|
|
||||||
Pending = newPending;
|
|
||||||
IsPending = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void ReleaseSurface(DisplaySurface surface)
|
|
||||||
{
|
|
||||||
lock (this) ReleasedSurfaces.Enqueue(surface);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// returns the current buffer, making the most recent pending buffer (if there is such) as the new current first.
|
|
||||||
/// </summary>
|
|
||||||
public DisplaySurface GetCurrent()
|
|
||||||
{
|
|
||||||
lock (this)
|
|
||||||
{
|
|
||||||
if (IsPending)
|
|
||||||
{
|
|
||||||
if (Current != null) ReleasedSurfaces.Enqueue(Current);
|
|
||||||
Current = Pending;
|
|
||||||
Pending = null;
|
|
||||||
IsPending = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return Current;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,283 +0,0 @@
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.ComponentModel;
|
|
||||||
using System.Drawing;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using System.Text;
|
|
||||||
using System.Windows.Forms;
|
|
||||||
|
|
||||||
using BizHawk.Common;
|
|
||||||
using BizHawk.Common.ReflectionExtensions;
|
|
||||||
using BizHawk.Client.Common;
|
|
||||||
|
|
||||||
|
|
||||||
namespace BizHawk.Client.MultiHawk.WinFormExtensions
|
|
||||||
{
|
|
||||||
public static class ControlExtensions
|
|
||||||
{
|
|
||||||
public static void PopulateFromEnum<T>(this ComboBox box, object enumVal)
|
|
||||||
where T : struct, IConvertible
|
|
||||||
{
|
|
||||||
if (!typeof(T).IsEnum)
|
|
||||||
{
|
|
||||||
throw new ArgumentException("T must be an enumerated type");
|
|
||||||
}
|
|
||||||
|
|
||||||
box.Items.Clear();
|
|
||||||
box.Items.AddRange(
|
|
||||||
typeof(T).GetEnumDescriptions()
|
|
||||||
.ToArray());
|
|
||||||
box.SelectedItem = enumVal.GetDescription();
|
|
||||||
}
|
|
||||||
|
|
||||||
// extension method to make Control.Invoke easier to use
|
|
||||||
public static object Invoke(this Control control, Action action)
|
|
||||||
{
|
|
||||||
return control.Invoke(action);
|
|
||||||
}
|
|
||||||
|
|
||||||
// extension method to make Control.BeginInvoke easier to use
|
|
||||||
public static IAsyncResult BeginInvoke(this Control control, Action action)
|
|
||||||
{
|
|
||||||
return control.BeginInvoke(action);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AddColumn(this ListView listView, string columnName, bool enabled, int columnWidth)
|
|
||||||
{
|
|
||||||
if (enabled)
|
|
||||||
{
|
|
||||||
if (listView.Columns[columnName] == null)
|
|
||||||
{
|
|
||||||
var column = new ColumnHeader
|
|
||||||
{
|
|
||||||
Name = columnName,
|
|
||||||
Text = columnName.Replace("Column", string.Empty),
|
|
||||||
Width = columnWidth,
|
|
||||||
};
|
|
||||||
|
|
||||||
listView.Columns.Add(column);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void AddColumn(this ListView listView, ToolDialogSettings.Column column)
|
|
||||||
{
|
|
||||||
if (column.Visible)
|
|
||||||
{
|
|
||||||
if (listView.Columns[column.Name] == null)
|
|
||||||
{
|
|
||||||
var lsstViewColumn = new ColumnHeader
|
|
||||||
{
|
|
||||||
Name = column.Name,
|
|
||||||
Text = column.Name.Replace("Column", string.Empty),
|
|
||||||
Width = column.Width,
|
|
||||||
DisplayIndex = column.Index
|
|
||||||
};
|
|
||||||
|
|
||||||
listView.Columns.Add(lsstViewColumn);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static ToolStripMenuItem GenerateColumnsMenu(this ToolDialogSettings.ColumnList list, Action changeCallback)
|
|
||||||
{
|
|
||||||
var menu = new ToolStripMenuItem
|
|
||||||
{
|
|
||||||
Name = "GeneratedColumnsSubMenu",
|
|
||||||
Text = "Columns"
|
|
||||||
};
|
|
||||||
|
|
||||||
var dummyList = list;
|
|
||||||
|
|
||||||
foreach (var column in dummyList)
|
|
||||||
{
|
|
||||||
var menuItem = new ToolStripMenuItem
|
|
||||||
{
|
|
||||||
Name = column.Name,
|
|
||||||
Text = column.Name.Replace("Column", string.Empty)
|
|
||||||
};
|
|
||||||
|
|
||||||
menuItem.Click += (o, ev) =>
|
|
||||||
{
|
|
||||||
dummyList[menuItem.Name].Visible ^= true;
|
|
||||||
changeCallback();
|
|
||||||
};
|
|
||||||
|
|
||||||
menu.DropDownItems.Add(menuItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
menu.DropDownOpened += (o, e) =>
|
|
||||||
{
|
|
||||||
foreach (var column in dummyList)
|
|
||||||
{
|
|
||||||
(menu.DropDownItems[column.Name] as ToolStripMenuItem).Checked = column.Visible;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return menu;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Point ChildPointToScreen(this Control control, Control child)
|
|
||||||
{
|
|
||||||
return control.PointToScreen(new Point(child.Location.X, child.Location.Y));
|
|
||||||
}
|
|
||||||
|
|
||||||
#region Enumerable to Enumerable<T>
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Converts the outdated IEnumerable Controls property to a IEnumerable<T> like .NET should have done a long time ago
|
|
||||||
/// </summary>
|
|
||||||
public static IEnumerable<Control> Controls(this Control control)
|
|
||||||
{
|
|
||||||
return control.Controls
|
|
||||||
.OfType<Control>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IEnumerable<TabPage> TabPages(this TabControl tabControl)
|
|
||||||
{
|
|
||||||
return tabControl.TabPages.Cast<TabPage>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IEnumerable<int> SelectedIndices(this ListView listView)
|
|
||||||
{
|
|
||||||
return listView.SelectedIndices.Cast<int>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static IEnumerable<ColumnHeader> ColumnHeaders(this ListView listView)
|
|
||||||
{
|
|
||||||
return listView.Columns.OfType<ColumnHeader>();
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class ListViewExtensions
|
|
||||||
{
|
|
||||||
[StructLayout(LayoutKind.Sequential)]
|
|
||||||
public struct HDITEM
|
|
||||||
{
|
|
||||||
public Mask mask;
|
|
||||||
public int cxy;
|
|
||||||
[MarshalAs(UnmanagedType.LPTStr)]
|
|
||||||
public string pszText;
|
|
||||||
public IntPtr hbm;
|
|
||||||
public int cchTextMax;
|
|
||||||
public Format fmt;
|
|
||||||
public IntPtr lParam;
|
|
||||||
// _WIN32_IE >= 0x0300
|
|
||||||
public int iImage;
|
|
||||||
public int iOrder;
|
|
||||||
// _WIN32_IE >= 0x0500
|
|
||||||
public uint type;
|
|
||||||
public IntPtr pvFilter;
|
|
||||||
// _WIN32_WINNT >= 0x0600
|
|
||||||
public uint state;
|
|
||||||
|
|
||||||
[Flags]
|
|
||||||
public enum Mask
|
|
||||||
{
|
|
||||||
Format = 0x4, // HDI_FORMAT
|
|
||||||
};
|
|
||||||
|
|
||||||
[Flags]
|
|
||||||
public enum Format
|
|
||||||
{
|
|
||||||
SortDown = 0x200, // HDF_SORTDOWN
|
|
||||||
SortUp = 0x400, // HDF_SORTUP
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
public const int LVM_FIRST = 0x1000;
|
|
||||||
public const int LVM_GETHEADER = LVM_FIRST + 31;
|
|
||||||
|
|
||||||
public const int HDM_FIRST = 0x1200;
|
|
||||||
public const int HDM_GETITEM = HDM_FIRST + 11;
|
|
||||||
public const int HDM_SETITEM = HDM_FIRST + 12;
|
|
||||||
|
|
||||||
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
|
||||||
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 msg, IntPtr wParam, IntPtr lParam);
|
|
||||||
|
|
||||||
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
|
|
||||||
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 msg, IntPtr wParam, ref HDITEM lParam);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Dumps the contents of the ListView into a tab separated list of lines
|
|
||||||
/// </summary>
|
|
||||||
public static string CopyItemsAsText(this ListView listViewControl)
|
|
||||||
{
|
|
||||||
var indexes = listViewControl.SelectedIndices;
|
|
||||||
if (indexes.Count <= 0)
|
|
||||||
{
|
|
||||||
return String.Empty;
|
|
||||||
}
|
|
||||||
|
|
||||||
var sb = new StringBuilder();
|
|
||||||
|
|
||||||
// walk over each selected item and subitem within it to generate a string from it
|
|
||||||
foreach (int index in indexes)
|
|
||||||
{
|
|
||||||
foreach (ListViewItem.ListViewSubItem item in listViewControl.Items[index].SubItems)
|
|
||||||
{
|
|
||||||
if (!String.IsNullOrWhiteSpace(item.Text))
|
|
||||||
{
|
|
||||||
sb.Append(item.Text).Append('\t');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove the last tab
|
|
||||||
sb.Remove(sb.Length - 1, 1);
|
|
||||||
|
|
||||||
sb.Append("\r\n");
|
|
||||||
}
|
|
||||||
|
|
||||||
// remove last newline
|
|
||||||
sb.Length -= 2;
|
|
||||||
|
|
||||||
|
|
||||||
return sb.ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void SetSortIcon(this ListView listViewControl, int columnIndex, SortOrder order)
|
|
||||||
{
|
|
||||||
IntPtr columnHeader = SendMessage(listViewControl.Handle, LVM_GETHEADER, IntPtr.Zero, IntPtr.Zero);
|
|
||||||
for (int columnNumber = 0; columnNumber <= listViewControl.Columns.Count - 1; columnNumber++)
|
|
||||||
{
|
|
||||||
var columnPtr = new IntPtr(columnNumber);
|
|
||||||
var item = new HDITEM
|
|
||||||
{
|
|
||||||
mask = HDITEM.Mask.Format
|
|
||||||
};
|
|
||||||
|
|
||||||
if (SendMessage(columnHeader, HDM_GETITEM, columnPtr, ref item) == IntPtr.Zero)
|
|
||||||
{
|
|
||||||
throw new Win32Exception();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (order != SortOrder.None && columnNumber == columnIndex)
|
|
||||||
{
|
|
||||||
switch (order)
|
|
||||||
{
|
|
||||||
case SortOrder.Ascending:
|
|
||||||
item.fmt &= ~HDITEM.Format.SortDown;
|
|
||||||
item.fmt |= HDITEM.Format.SortUp;
|
|
||||||
break;
|
|
||||||
case SortOrder.Descending:
|
|
||||||
item.fmt &= ~HDITEM.Format.SortUp;
|
|
||||||
item.fmt |= HDITEM.Format.SortDown;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
item.fmt &= ~HDITEM.Format.SortDown & ~HDITEM.Format.SortUp;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (SendMessage(columnHeader, HDM_SETITEM, columnPtr, ref item) == IntPtr.Zero)
|
|
||||||
{
|
|
||||||
throw new Win32Exception();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,25 +0,0 @@
|
||||||
using BizHawk.Emulation.Common;
|
|
||||||
using BizHawk.Emulation.Common.IEmulatorExtensions;
|
|
||||||
using BizHawk.Emulation.Cores.Nintendo.SNES;
|
|
||||||
using BizHawk.Client.Common;
|
|
||||||
|
|
||||||
namespace BizHawk.Client.MultiHawk.CoreExtensions
|
|
||||||
{
|
|
||||||
public static class CoreExtensions
|
|
||||||
{
|
|
||||||
public static string DisplayName(this IEmulator core)
|
|
||||||
{
|
|
||||||
var attributes = core.Attributes();
|
|
||||||
|
|
||||||
var str = (!attributes.Released ? "(Experimental) " : string.Empty) +
|
|
||||||
attributes.CoreName;
|
|
||||||
|
|
||||||
if (core is LibsnesCore)
|
|
||||||
{
|
|
||||||
str += " (" + ((LibsnesCore)core).CurrentProfile + ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
return str;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue