Backport `KeyValuePair<,>.Deconstruct`

it's infuriating that you can't use this for lambda parameters
This commit is contained in:
YoshiRulz 2021-11-12 21:20:58 +10:00
parent 3d56e23e8a
commit c52c880101
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
38 changed files with 212 additions and 229 deletions

View File

@ -6,6 +6,7 @@ using System.Threading;
using BizHawk.Bizware.BizwareGL; using BizHawk.Bizware.BizwareGL;
using BizHawk.Bizware.OpenTK3; using BizHawk.Bizware.OpenTK3;
using BizHawk.Common;
using SlimDX.Direct3D9; using SlimDX.Direct3D9;
@ -352,9 +353,8 @@ namespace BizHawk.Bizware.DirectX
var ves = new VertexElement[vertexLayout.Items.Count]; var ves = new VertexElement[vertexLayout.Items.Count];
int stride = 0; int stride = 0;
foreach (var kvp in vertexLayout.Items) foreach (var (i, item) in vertexLayout.Items)
{ {
var item = kvp.Value;
DeclarationType declType; DeclarationType declType;
switch (item.AttribType) switch (item.AttribType)
{ {
@ -391,7 +391,7 @@ namespace BizHawk.Bizware.DirectX
throw new NotSupportedException(); throw new NotSupportedException();
} }
ves[kvp.Key] = new VertexElement(0, (short)item.Offset, declType, DeclarationMethod.Default, usage, usageIndex); ves[i] = new VertexElement(0, (short) item.Offset, declType, DeclarationMethod.Default, usage, usageIndex);
} }
var pw = new PipelineWrapper var pw = new PipelineWrapper

View File

@ -768,19 +768,19 @@ namespace BizHawk.Bizware.OpenTK3
} }
GL.ClientActiveTexture(TextureUnit.Texture0); GL.ClientActiveTexture(TextureUnit.Texture0);
foreach (var kvp in layout.Items) foreach (var (i, item) in layout.Items)
{ {
if(_currPipeline.Memo == "gui") if(_currPipeline.Memo == "gui")
{ {
GL.VertexAttribPointer( GL.VertexAttribPointer(
kvp.Key, i,
kvp.Value.Components, item.Components,
(VertexAttribPointerType) (int) kvp.Value.AttribType, // these are the same enum (VertexAttribPointerType) (int) item.AttribType, // these are the same enum
kvp.Value.Normalized, item.Normalized,
kvp.Value.Stride, item.Stride,
pData + kvp.Value.Offset); pData + item.Offset);
GL.EnableVertexAttribArray(kvp.Key); GL.EnableVertexAttribArray(i);
currBindings.Add(kvp.Key); currBindings.Add(i);
} }
else else
{ {
@ -788,21 +788,21 @@ namespace BizHawk.Bizware.OpenTK3
var pw = _currPipeline.Opaque as PipelineWrapper; var pw = _currPipeline.Opaque as PipelineWrapper;
//comment SNACKPANTS //comment SNACKPANTS
switch (kvp.Value.Usage) switch (item.Usage)
{ {
case AttribUsage.Position: case AttribUsage.Position:
GL.EnableClientState(ArrayCap.VertexArray); GL.EnableClientState(ArrayCap.VertexArray);
GL.VertexPointer(kvp.Value.Components,VertexPointerType.Float,kvp.Value.Stride,pData + kvp.Value.Offset); GL.VertexPointer(item.Components, VertexPointerType.Float, item.Stride, pData + item.Offset);
break; break;
case AttribUsage.Texcoord0: case AttribUsage.Texcoord0:
GL.ClientActiveTexture(TextureUnit.Texture0); GL.ClientActiveTexture(TextureUnit.Texture0);
GL.EnableClientState(ArrayCap.TextureCoordArray); GL.EnableClientState(ArrayCap.TextureCoordArray);
GL.TexCoordPointer(kvp.Value.Components, TexCoordPointerType.Float, kvp.Value.Stride, pData + kvp.Value.Offset); GL.TexCoordPointer(item.Components, TexCoordPointerType.Float, item.Stride, pData + item.Offset);
break; break;
case AttribUsage.Texcoord1: case AttribUsage.Texcoord1:
GL.ClientActiveTexture(TextureUnit.Texture1); GL.ClientActiveTexture(TextureUnit.Texture1);
GL.EnableClientState(ArrayCap.TextureCoordArray); GL.EnableClientState(ArrayCap.TextureCoordArray);
GL.TexCoordPointer(kvp.Value.Components, TexCoordPointerType.Float, kvp.Value.Stride, pData + kvp.Value.Offset); GL.TexCoordPointer(item.Components, TexCoordPointerType.Float, item.Stride, pData + item.Offset);
GL.ClientActiveTexture(TextureUnit.Texture0); GL.ClientActiveTexture(TextureUnit.Texture0);
break; break;
case AttribUsage.Color0: case AttribUsage.Color0:

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.ComponentModel; using System.ComponentModel;
using BizHawk.Common;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES; using BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES;
using BizHawk.Emulation.Cores.Consoles.Sega.gpgx; using BizHawk.Emulation.Cores.Consoles.Sega.gpgx;
@ -117,7 +118,7 @@ namespace BizHawk.Client.Common
if (DebuggableCore != null) if (DebuggableCore != null)
{ {
var table = new Dictionary<string, ulong>(); var table = new Dictionary<string, ulong>();
foreach (var kvp in DebuggableCore.GetCpuFlagsAndRegisters()) table[kvp.Key] = kvp.Value.Value; foreach (var (name, rv) in DebuggableCore.GetCpuFlagsAndRegisters()) table[name] = rv.Value;
return table; return table;
} }
} }

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using BizHawk.Common;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common namespace BizHawk.Client.Common
@ -26,7 +27,7 @@ namespace BizHawk.Client.Common
{ {
var options = new Dictionary<string, string?>(); var options = new Dictionary<string, string?>();
if (_game == null) return options; if (_game == null) return options;
foreach (var option in ((GameInfo) _game).GetOptions()) options[option.Key] = option.Value; foreach (var (k, v) in ((GameInfo) _game).GetOptions()) options[k] = v;
return options; return options;
} }
} }

View File

@ -1,6 +1,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using BizHawk.Common;
namespace BizHawk.Client.Common namespace BizHawk.Client.Common
{ {
public sealed class InputApi : IInputApi public sealed class InputApi : IInputApi
@ -18,7 +20,7 @@ namespace BizHawk.Client.Common
public Dictionary<string, bool> Get() public Dictionary<string, bool> Get()
{ {
var buttons = new Dictionary<string, bool>(); var buttons = new Dictionary<string, bool>();
foreach (var kvp in _inputManager.ControllerInputCoalescer.BoolButtons().Where(kvp => kvp.Value)) buttons[kvp.Key] = true; foreach (var (button, _) in _inputManager.ControllerInputCoalescer.BoolButtons().Where(kvp => kvp.Value)) buttons[button] = true;
return buttons; return buttons;
} }

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using BizHawk.Common;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common namespace BizHawk.Client.Common
@ -90,7 +91,7 @@ namespace BizHawk.Client.Common
public void SetAnalog(IReadOnlyDictionary<string, int?> controls, object controller = null) public void SetAnalog(IReadOnlyDictionary<string, int?> controls, object controller = null)
{ {
foreach (var kvp in controls) SetAnalog(kvp.Key, kvp.Value, controller); foreach (var (k, v) in controls) SetAnalog(k, v, controller);
} }
public void SetAnalog(string control, int? value = null, object controller = null) public void SetAnalog(string control, int? value = null, object controller = null)

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using BizHawk.Common;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common namespace BizHawk.Client.Common
@ -79,7 +80,7 @@ namespace BizHawk.Client.Common
{ {
return table; return table;
} }
foreach (var kvp in _movieSession.Movie.HeaderEntries) table[kvp.Key] = kvp.Value; foreach (var (k, v) in _movieSession.Movie.HeaderEntries) table[k] = v;
return table; return table;
} }

View File

@ -12,10 +12,10 @@ namespace BizHawk.Client.Common
public Controller(ControllerDefinition definition) public Controller(ControllerDefinition definition)
{ {
Definition = definition; Definition = definition;
foreach (var kvp in Definition.Axes) foreach (var (k, v) in Definition.Axes)
{ {
_axes[kvp.Key] = kvp.Value.Neutral; _axes[k] = v.Neutral;
_axisRanges[kvp.Key] = kvp.Value; _axisRanges[k] = v;
} }
foreach (var channel in Definition.HapticsChannels) _haptics[channel] = 0; foreach (var channel in Definition.HapticsChannels) _haptics[channel] = 0;
} }
@ -65,54 +65,54 @@ namespace BizHawk.Client.Common
{ {
_buttons.Clear(); _buttons.Clear();
foreach (var kvp in _bindings) foreach (var (k, v) in _bindings)
{ {
_buttons[kvp.Key] = false; _buttons[k] = false;
foreach (var button in kvp.Value) foreach (var button in v)
{ {
if (finalHostController.IsPressed(button)) if (finalHostController.IsPressed(button))
{ {
_buttons[kvp.Key] = true; _buttons[k] = true;
} }
} }
} }
foreach (var kvp in _axisBindings) foreach (var (k, v) in _axisBindings)
{ {
// values from finalHostController are ints in -10000..10000 (or 0..10000), so scale to -1..1, using floats to keep fractional part // values from finalHostController are ints in -10000..10000 (or 0..10000), so scale to -1..1, using floats to keep fractional part
var value = finalHostController.AxisValue(kvp.Value.Value) / 10000.0f; var value = finalHostController.AxisValue(v.Value) / 10000.0f;
// apply deadzone (and scale diminished range back up to -1..1) // apply deadzone (and scale diminished range back up to -1..1)
var deadzone = kvp.Value.Deadzone; var deadzone = v.Deadzone;
if (value < -deadzone) value += deadzone; if (value < -deadzone) value += deadzone;
else if (value < deadzone) value = 0.0f; else if (value < deadzone) value = 0.0f;
else value -= deadzone; else value -= deadzone;
value /= 1.0f - deadzone; value /= 1.0f - deadzone;
// scale by user-set multiplier (which is -2..2, therefore value is now in -2..2) // scale by user-set multiplier (which is -2..2, therefore value is now in -2..2)
value *= kvp.Value.Mult; value *= v.Mult;
// -1..1 -> -A..A (where A is the larger "side" of the range e.g. a range of 0..50, neutral=10 would give A=40, and thus a value in -40..40) // -1..1 -> -A..A (where A is the larger "side" of the range e.g. a range of 0..50, neutral=10 would give A=40, and thus a value in -40..40)
var range = _axisRanges[kvp.Key]; var range = _axisRanges[k];
value *= Math.Max(range.Neutral - range.Min, range.Max - range.Neutral); value *= Math.Max(range.Neutral - range.Min, range.Max - range.Neutral);
// shift the midpoint, so a value of 0 becomes range.Neutral (and, assuming >=1x multiplier, all values in range are reachable) // shift the midpoint, so a value of 0 becomes range.Neutral (and, assuming >=1x multiplier, all values in range are reachable)
value += range.Neutral; value += range.Neutral;
// finally, constrain to range // finally, constrain to range
_axes[kvp.Key] = ((int) value).ConstrainWithin(range.Range); _axes[k] = ((int) value).ConstrainWithin(range.Range);
} }
} }
public void PrepareHapticsForHost(SimpleController finalHostController) public void PrepareHapticsForHost(SimpleController finalHostController)
{ {
foreach (var kvp in _feedbackBindings) foreach (var (k, v) in _feedbackBindings)
{ {
if (_haptics.TryGetValue(kvp.Key, out var strength)) if (_haptics.TryGetValue(k, out var strength))
{ {
foreach (var hostChannel in kvp.Value.Channels!.Split('+')) foreach (var hostChannel in v.Channels!.Split('+'))
{ {
finalHostController.SetHapticChannelStrength(kvp.Value.GamepadPrefix + hostChannel, (int) ((double) strength * kvp.Value.Prescale)); finalHostController.SetHapticChannelStrength(v.GamepadPrefix + hostChannel, (int) ((double) strength * v.Prescale));
} }
} }
} }

View File

@ -10,6 +10,7 @@ using System.Drawing;
using BizHawk.Client.Common.FilterManager; using BizHawk.Client.Common.FilterManager;
using BizHawk.Bizware.BizwareGL; using BizHawk.Bizware.BizwareGL;
using BizHawk.Common;
namespace BizHawk.Client.Common.Filters namespace BizHawk.Client.Common.Filters
{ {
@ -288,11 +289,11 @@ namespace BizHawk.Client.Common.Filters
// apply all parameters to this shader.. even if it was meant for other shaders. kind of lame. // apply all parameters to this shader.. even if it was meant for other shaders. kind of lame.
if(Parameters != null) if(Parameters != null)
{ {
foreach (var kvp in Parameters) foreach (var (k, v) in Parameters)
{ {
if (kvp.Value is float value) if (v is float value)
{ {
shader.Pipeline[kvp.Key].Set(value); shader.Pipeline[k].Set(value);
} }
} }
} }

View File

@ -59,26 +59,26 @@ namespace BizHawk.Client.Common
{ {
internal_frame = _emulator.Frame; internal_frame = _emulator.Frame;
foreach (var kvp in _bindings) foreach (var (k, v) in _bindings)
{ {
foreach (var boundBtn in kvp.Value) foreach (var boundBtn in v)
{ {
if (_buttons[kvp.Key] == false && controller.IsPressed(boundBtn)) if (_buttons[k] == false && controller.IsPressed(boundBtn))
{ {
_buttonStarts[kvp.Key] = _emulator.Frame; _buttonStarts[k] = _emulator.Frame;
} }
} }
} }
_buttons.Clear(); _buttons.Clear();
foreach (var kvp in _bindings) foreach (var (k, v) in _bindings)
{ {
_buttons[kvp.Key] = false; _buttons[k] = false;
foreach (var button in kvp.Value) foreach (var button in v)
{ {
if (controller.IsPressed(button)) if (controller.IsPressed(button))
{ {
_buttons[kvp.Key] = true; _buttons[k] = true;
} }
} }
} }

View File

@ -4,6 +4,8 @@ using System.Drawing;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using BizHawk.Common;
using NLua; using NLua;
namespace BizHawk.Client.Common namespace BizHawk.Client.Common
@ -25,12 +27,7 @@ namespace BizHawk.Client.Common
public LuaTable DictToTable<T>(IReadOnlyDictionary<string, T> dictionary) public LuaTable DictToTable<T>(IReadOnlyDictionary<string, T> dictionary)
{ {
var table = _lua.NewTable(); var table = _lua.NewTable();
foreach (var (k, v) in dictionary) table[k] = v;
foreach (var kvp in dictionary)
{
table[kvp.Key] = kvp.Value;
}
return table; return table;
} }

View File

@ -25,10 +25,7 @@ namespace BizHawk.Client.Common
old.Truncate(0); // Trying to minimize ram usage old.Truncate(0); // Trying to minimize ram usage
tas.HeaderEntries.Clear(); tas.HeaderEntries.Clear();
foreach (var kvp in old.HeaderEntries) foreach (var (k, v) in old.HeaderEntries) tas.HeaderEntries[k] = v;
{
tas.HeaderEntries[kvp.Key] = kvp.Value;
}
// TODO: we have this version number string generated in multiple places // TODO: we have this version number string generated in multiple places
tas.HeaderEntries[HeaderKeys.MovieVersion] = $"BizHawk v2.0 Tasproj v{TasMovie.CurrentVersion}"; tas.HeaderEntries[HeaderKeys.MovieVersion] = $"BizHawk v2.0 Tasproj v{TasMovie.CurrentVersion}";
@ -61,10 +58,7 @@ namespace BizHawk.Client.Common
bk2.CopyLog(old.GetLogEntries()); bk2.CopyLog(old.GetLogEntries());
bk2.HeaderEntries.Clear(); bk2.HeaderEntries.Clear();
foreach (var kvp in old.HeaderEntries) foreach (var (k, v) in old.HeaderEntries) bk2.HeaderEntries[k] = v;
{
bk2.HeaderEntries[kvp.Key] = kvp.Value;
}
// TODO: we have this version number string generated in multiple places // TODO: we have this version number string generated in multiple places
bk2.HeaderEntries[HeaderKeys.MovieVersion] = "BizHawk v2.0"; bk2.HeaderEntries[HeaderKeys.MovieVersion] = "BizHawk v2.0";
@ -113,10 +107,7 @@ namespace BizHawk.Client.Common
tas.LagLog.StartFromFrame(frame); tas.LagLog.StartFromFrame(frame);
tas.HeaderEntries.Clear(); tas.HeaderEntries.Clear();
foreach (var kvp in old.HeaderEntries) foreach (var (k, v) in old.HeaderEntries) tas.HeaderEntries[k] = v;
{
tas.HeaderEntries[kvp.Key] = kvp.Value;
}
tas.StartsFromSavestate = true; tas.StartsFromSavestate = true;
tas.SyncSettingsJson = old.SyncSettingsJson; tas.SyncSettingsJson = old.SyncSettingsJson;
@ -162,10 +153,7 @@ namespace BizHawk.Client.Common
tas.CopyVerificationLog(entries); tas.CopyVerificationLog(entries);
tas.HeaderEntries.Clear(); tas.HeaderEntries.Clear();
foreach (var kvp in old.HeaderEntries) foreach (var (k, v) in old.HeaderEntries) tas.HeaderEntries[k] = v;
{
tas.HeaderEntries[kvp.Key] = kvp.Value;
}
tas.StartsFromSaveRam = true; tas.StartsFromSaveRam = true;
tas.SyncSettingsJson = old.SyncSettingsJson; tas.SyncSettingsJson = old.SyncSettingsJson;

View File

@ -73,10 +73,7 @@ namespace BizHawk.Client.Common
} }
// axes don't have sticky logic, so latch default value // axes don't have sticky logic, so latch default value
foreach (var kvp in Definition.Axes) foreach (var (k, v) in Definition.Axes) _myAxisControls[k] = v.Neutral;
{
_myAxisControls[kvp.Key] = kvp.Value.Neutral;
}
} }
public void SetFromMnemonic(string mnemonic) public void SetFromMnemonic(string mnemonic)

View File

@ -1,6 +1,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using BizHawk.Common;
namespace BizHawk.Client.Common namespace BizHawk.Client.Common
{ {
public class Bk2Header : Dictionary<string, string> public class Bk2Header : Dictionary<string, string>
@ -14,16 +16,7 @@ namespace BizHawk.Client.Common
public override string ToString() public override string ToString()
{ {
var sb = new StringBuilder(); var sb = new StringBuilder();
foreach (var (k, v) in this) sb.Append(k).Append(' ').Append(v).AppendLine();
foreach (var kvp in this)
{
sb
.Append(kvp.Key)
.Append(' ')
.Append(kvp.Value)
.AppendLine();
}
return sb.ToString(); return sb.ToString();
} }
} }

View File

@ -1,4 +1,6 @@
namespace BizHawk.Client.Common.movie.import using BizHawk.Common;
namespace BizHawk.Client.Common.movie.import
{ {
// ReSharper disable once UnusedMember.Global // ReSharper disable once UnusedMember.Global
[ImporterFor("BizHawk", ".bkm")] [ImporterFor("BizHawk", ".bkm")]
@ -16,10 +18,7 @@
} }
Result.Movie.HeaderEntries.Clear(); Result.Movie.HeaderEntries.Clear();
foreach (var kvp in bkm.Header) foreach (var (k, v) in bkm.Header) Result.Movie.HeaderEntries[k] = v;
{
Result.Movie.HeaderEntries[kvp.Key] = kvp.Value;
}
Result.Movie.SyncSettingsJson = bkm.SyncSettingsJson; Result.Movie.SyncSettingsJson = bkm.SyncSettingsJson;

View File

@ -66,14 +66,11 @@ namespace BizHawk.Client.Common
{ {
get get
{ {
var kvp = GetStateClosestToFrame(frame); var (f, data) = GetStateClosestToFrame(frame);
if (kvp.Key != frame) if (f != frame) return NonState;
{
return NonState;
}
var ms = new MemoryStream(); var ms = new MemoryStream();
kvp.Value.CopyTo(ms); data.CopyTo(ms);
return ms.ToArray(); return ms.ToArray();
} }
} }
@ -148,8 +145,7 @@ namespace BizHawk.Client.Common
} }
if (_reserved != null) if (_reserved != null)
{ {
foreach (var kvp in _reserved) foreach (var (f, data) in _reserved) newReserved.Add(f, data);
newReserved.Add(kvp.Key, kvp.Value);
(_reserved as TempFileStateDictionary)?.Dispose(); (_reserved as TempFileStateDictionary)?.Dispose();
} }
_reserved = newReserved; _reserved = newReserved;
@ -568,11 +564,11 @@ namespace BizHawk.Client.Common
_gapFiller.SaveStateBinary(bw); _gapFiller.SaveStateBinary(bw);
bw.Write(_reserved.Count); bw.Write(_reserved.Count);
foreach (var s in _reserved) foreach (var (f, data) in _reserved)
{ {
bw.Write(s.Key); bw.Write(f);
bw.Write(s.Value.Length); bw.Write(data.Length);
bw.Write(s.Value); bw.Write(data);
} }
} }

View File

@ -182,10 +182,7 @@ namespace BizHawk.Client.Common
{ {
var bag = (Dictionary<string, object>)ConfigService.LoadWithType(userData); var bag = (Dictionary<string, object>)ConfigService.LoadWithType(userData);
_userBag.Clear(); _userBag.Clear();
foreach (var kvp in bag) foreach (var (k, v) in bag) _userBag.Add(k, v);
{
_userBag.Add(kvp.Key, kvp.Value);
}
} }
if (_movieSession.Movie.IsActive() && _movieSession.Movie is ITasMovie) if (_movieSession.Movie.IsActive() && _movieSession.Movie is ITasMovie)

View File

@ -342,11 +342,10 @@ namespace BizHawk.Client.EmuHawk
{ {
lock (_axisValues) lock (_axisValues)
{ {
foreach (var kvp in _axisDeltas) foreach (var (k, v) in _axisDeltas)
{ {
// need to wiggle the stick a bit // need to wiggle the stick a bit
if (kvp.Value >= 20000.0f) if (v >= 20000.0f) return k;
return kvp.Key;
} }
} }
return null; return null;

View File

@ -3812,17 +3812,17 @@ namespace BizHawk.Client.EmuHawk
{ {
var ext = Path.GetExtension(xmlGame.AssetFullPaths[xg])?.ToLowerInvariant(); var ext = Path.GetExtension(xmlGame.AssetFullPaths[xg])?.ToLowerInvariant();
var (filename, data) = xmlGame.Assets[xg];
if (ext == ".cue" || ext == ".ccd" || ext == ".toc" || ext == ".mds") if (ext == ".cue" || ext == ".ccd" || ext == ".toc" || ext == ".mds")
{ {
xSw.WriteLine(Path.GetFileNameWithoutExtension(xmlGame.Assets[xg].Key)); xSw.WriteLine(Path.GetFileNameWithoutExtension(filename));
xSw.WriteLine("SHA1:N/A"); xSw.WriteLine("SHA1:N/A");
xSw.WriteLine("MD5:N/A"); xSw.WriteLine("MD5:N/A");
xSw.WriteLine(); xSw.WriteLine();
} }
else else
{ {
xSw.WriteLine(xmlGame.Assets[xg].Key); xSw.WriteLine(filename);
var data = xmlGame.Assets[xg].Value;
xSw.WriteLine(SHA1Checksum.ComputePrefixedHex(data)); xSw.WriteLine(SHA1Checksum.ComputePrefixedHex(data));
xSw.WriteLine(MD5Checksum.ComputePrefixedHex(data)); xSw.WriteLine(MD5Checksum.ComputePrefixedHex(data));
xSw.WriteLine(); xSw.WriteLine();

View File

@ -7,6 +7,7 @@ using System.Text.RegularExpressions;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.Client.Common; using BizHawk.Client.Common;
using BizHawk.Common;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
@ -166,11 +167,10 @@ namespace BizHawk.Client.EmuHawk
var tt = new TabControl { Dock = DockStyle.Fill }; var tt = new TabControl { Dock = DockStyle.Fill };
dest.Controls.Add(tt); dest.Controls.Add(tt);
int pageIdx = 0; int pageIdx = 0;
foreach (var kvp in orderedBuckets) foreach (var (tabName, buttons) in orderedBuckets)
{ {
string tabName = kvp.Key;
tt.TabPages.Add(tabName); tt.TabPages.Add(tabName);
tt.TabPages[pageIdx++].Controls.Add(createPanel(settings, kvp.Value, tt.Size)); tt.TabPages[pageIdx++].Controls.Add(createPanel(settings, buttons, tt.Size));
} }
} }
} }

View File

@ -4,6 +4,8 @@ using System.Drawing;
using System.Linq; using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.Common;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {
public partial class FileExtensionPreferences : Form public partial class FileExtensionPreferences : Form
@ -20,12 +22,12 @@ namespace BizHawk.Client.EmuHawk
{ {
int spacing = UIHelper.ScaleY(30); int spacing = UIHelper.ScaleY(30);
int count = 0; int count = 0;
foreach (var kvp in _preferredPlatformsForExtensions) foreach (var (fileExt, sysID) in _preferredPlatformsForExtensions)
{ {
var picker = new FileExtensionPreferencesPicker(_preferredPlatformsForExtensions) var picker = new FileExtensionPreferencesPicker(_preferredPlatformsForExtensions)
{ {
FileExtension = kvp.Key, FileExtension = fileExt,
OriginalPreference = kvp.Value, OriginalPreference = sysID,
Location = new Point(UIHelper.ScaleX(15), UIHelper.ScaleY(15) + (spacing * count)) Location = new Point(UIHelper.ScaleX(15), UIHelper.ScaleY(15) + (spacing * count))
}; };

View File

@ -4,6 +4,7 @@ using System.Drawing;
using System.Linq; using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.Client.Common; using BizHawk.Client.Common;
using BizHawk.Common;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {
@ -80,19 +81,19 @@ namespace BizHawk.Client.EmuHawk
MessageTypeBox.Controls.Clear(); MessageTypeBox.Controls.Clear();
int y = 12; int y = 12;
foreach (var position in Positions) foreach (var (name, pos) in Positions)
{ {
var row = new MessageRow var row = new MessageRow
{ {
Name = position.Key, Name = name,
Location = new Point(10, y) Location = new Point(10, y)
}; };
row.Size = new Size(MessageTypeBox.Width - 12, row.Size.Height); row.Size = new Size(MessageTypeBox.Width - 12, row.Size.Height);
row.Bind(position.Key, position.Value, (e) => { SetMessagePosition(row, e); }); row.Bind(name, pos, e => SetMessagePosition(row, e));
if (position.Value == _fps) if (pos == _fps)
{ {
row.Checked = true; row.Checked = true;
MessageEditor.Bind(position.Value, () => { row.SetText(); }); MessageEditor.Bind(pos, row.SetText);
} }
y += row.Size.Height; y += row.Size.Height;
@ -104,14 +105,14 @@ namespace BizHawk.Client.EmuHawk
{ {
ColorBox.Controls.Clear(); ColorBox.Controls.Clear();
int y = 20; int y = 20;
foreach (var color in Colors) foreach (var (name, argb) in Colors)
{ {
var row = new ColorRow var row = new ColorRow
{ {
Name = color.Key, Name = name,
Location = new Point(10, y), Location = new Point(10, y),
DisplayName = color.Key, DisplayName = name,
SelectedColor = color.Value SelectedColor = argb
}; };
row.Size = new Size(ColorBox.Width - 12, row.Size.Height); row.Size = new Size(ColorBox.Width - 12, row.Size.Height);
y += row.Size.Height; y += row.Size.Height;

View File

@ -1,6 +1,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Data; using System.Data;
using BizHawk.Common;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {
public class DataTableDictionaryBind<TKey, TValue> public class DataTableDictionaryBind<TKey, TValue>
@ -22,10 +24,7 @@ namespace BizHawk.Client.EmuHawk
Table = new DataTable(); Table = new DataTable();
Table.Columns.Add("Key", typeof(TKey)); Table.Columns.Add("Key", typeof(TKey));
Table.Columns.Add("Value", typeof(TValue)); Table.Columns.Add("Value", typeof(TValue));
foreach (var kvp in Dictionary) foreach (var (k, v) in Dictionary) Table.Rows.Add(k, v);
{
Table.Rows.Add(kvp.Key, kvp.Value);
}
Table.RowChanged += Table_RowChanged; Table.RowChanged += Table_RowChanged;
WasModified = false; WasModified = false;

View File

@ -384,32 +384,32 @@ namespace BizHawk.Client.EmuHawk
var firstIndex = MovieView.SelectedIndices[0]; var firstIndex = MovieView.SelectedIndices[0];
MovieView.EnsureVisible(firstIndex); MovieView.EnsureVisible(firstIndex);
foreach (var kvp in _movieList[firstIndex].HeaderEntries) foreach (var (k, v) in _movieList[firstIndex].HeaderEntries)
{ {
var item = new ListViewItem(kvp.Key); var item = new ListViewItem(k);
item.SubItems.Add(kvp.Value); item.SubItems.Add(v);
item.ToolTipText = kvp.Value; item.ToolTipText = v;
switch (kvp.Key) switch (k)
{ {
case HeaderKeys.Sha1: case HeaderKeys.Sha1:
if (_game.Hash != kvp.Value) if (_game.Hash != v)
{ {
item.BackColor = Color.Pink; item.BackColor = Color.Pink;
item.ToolTipText = $"Expected: {kvp.Value}\nActual: {_game.Hash}"; item.ToolTipText = $"Expected: {v}\nActual: {_game.Hash}";
} }
break; break;
case HeaderKeys.EmulatorVersion: case HeaderKeys.EmulatorVersion:
if (VersionInfo.GetEmuVersion() != kvp.Value) if (VersionInfo.GetEmuVersion() != v)
{ {
item.BackColor = Color.Yellow; item.BackColor = Color.Yellow;
item.ToolTipText = $"Expected: {kvp.Value}\nActual: {VersionInfo.GetEmuVersion()}"; item.ToolTipText = $"Expected: {v}\nActual: {VersionInfo.GetEmuVersion()}";
} }
break; break;
case HeaderKeys.Platform: case HeaderKeys.Platform:
if (_emulator.SystemId != kvp.Value) if (_emulator.SystemId != v)
{ {
item.BackColor = Color.Pink; item.BackColor = Color.Pink;
item.ToolTipText = $"Expected: {kvp.Value}\n Actual: {_emulator.SystemId}"; item.ToolTipText = $"Expected: {v}\n Actual: {_emulator.SystemId}";
} }
break; break;
} }

View File

@ -637,10 +637,10 @@ namespace BizHawk.Client.EmuHawk
.OfType<BotControlsRow>() .OfType<BotControlsRow>()
.ToList(); .ToList();
foreach (var kvp in botData.ControlProbabilities) foreach (var (button, p) in botData.ControlProbabilities)
{ {
var control = probabilityControls.Single(c => c.ButtonName == kvp.Key); var control = probabilityControls.Single(c => c.ButtonName == button);
control.Probability = kvp.Value; control.Probability = p;
} }
MaximizeAddress = botData.Maximize; MaximizeAddress = botData.Maximize;

View File

@ -7,6 +7,7 @@ using BizHawk.Emulation.Common;
using BizHawk.Client.Common; using BizHawk.Client.Common;
using BizHawk.Client.EmuHawk.Properties; using BizHawk.Client.EmuHawk.Properties;
using BizHawk.Client.EmuHawk.ToolExtensions; using BizHawk.Client.EmuHawk.ToolExtensions;
using BizHawk.Common;
// TODO - select which memorydomains go out to the CDL file. will this cause a problem when re-importing it? // TODO - select which memorydomains go out to the CDL file. will this cause a problem when re-importing it?
// perhaps missing domains shouldn't fail a check // perhaps missing domains shouldn't fail a check
@ -133,7 +134,7 @@ namespace BizHawk.Client.EmuHawk
_listContents = new string[_cdl.Count][]; _listContents = new string[_cdl.Count][];
int idx = 0; int idx = 0;
foreach (var kvp in _cdl) foreach (var (scope, dataA) in _cdl)
{ {
int[] totals = new int[8]; int[] totals = new int[8];
int total = 0; int total = 0;
@ -141,10 +142,10 @@ namespace BizHawk.Client.EmuHawk
for (int i = 0; i < 256; i++) for (int i = 0; i < 256; i++)
map[i] = 0; map[i] = 0;
fixed (byte* data = kvp.Value) fixed (byte* data = dataA)
{ {
byte* src = data; byte* src = data;
byte* end = data + kvp.Value.Length; byte* end = data + dataA.Length;
while (src < end) while (src < end)
{ {
byte s = *src++; byte s = *src++;
@ -166,28 +167,28 @@ namespace BizHawk.Client.EmuHawk
} }
var bm = _cdl.GetBlockMap(); var bm = _cdl.GetBlockMap();
long addr = bm[kvp.Key]; long addr = bm[scope];
var lvi = _listContents[idx++] = new string[13]; var lvi = _listContents[idx++] = new string[13];
lvi[0] = $"{addr:X8}"; lvi[0] = $"{addr:X8}";
lvi[1] = kvp.Key; lvi[1] = scope;
lvi[2] = $"{total / (float)kvp.Value.Length * 100f:0.00}%"; lvi[2] = $"{total / (float) dataA.Length * 100f:0.00}%";
if (tsbViewStyle.SelectedIndex == 2) if (tsbViewStyle.SelectedIndex == 2)
lvi[3] = $"{total / 1024.0f:0.00}"; lvi[3] = $"{total / 1024.0f:0.00}";
else else
lvi[3] = $"{total}"; lvi[3] = $"{total}";
if (tsbViewStyle.SelectedIndex == 2) if (tsbViewStyle.SelectedIndex == 2)
{ {
int n = (int)(kvp.Value.Length / 1024.0f); int n = (int) (dataA.Length / 1024.0f);
float ncheck = kvp.Value.Length / 1024.0f; float ncheck = dataA.Length / 1024.0f;
lvi[4] = $"of {(n == ncheck ? "" : "~")}{n} KBytes"; lvi[4] = $"of {(n == ncheck ? "" : "~")}{n} KBytes";
} }
else else
lvi[4] = $"of {kvp.Value.Length} Bytes"; lvi[4] = $"of {dataA.Length} Bytes";
for (int i = 0; i < 8; i++) for (int i = 0; i < 8; i++)
{ {
if (tsbViewStyle.SelectedIndex == 0) if (tsbViewStyle.SelectedIndex == 0)
lvi[5 + i] = $"{totals[i] / (float)kvp.Value.Length * 100f:0.00}%"; lvi[5 + i] = $"{totals[i] / (float) dataA.Length * 100f:0.00}%";
if (tsbViewStyle.SelectedIndex == 1) if (tsbViewStyle.SelectedIndex == 1)
lvi[5 + i] = $"{totals[i]}"; lvi[5 + i] = $"{totals[i]}";
if (tsbViewStyle.SelectedIndex == 2) if (tsbViewStyle.SelectedIndex == 2)

View File

@ -3,6 +3,7 @@ using System.Drawing;
using System.Linq; using System.Linq;
using System.Windows.Forms; using System.Windows.Forms;
using BizHawk.Common;
using BizHawk.Common.NumberExtensions; using BizHawk.Common.NumberExtensions;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
@ -30,7 +31,7 @@ namespace BizHawk.Client.EmuHawk
var registers = Core.GetCpuFlagsAndRegisters(); var registers = Core.GetCpuFlagsAndRegisters();
_suppressChangeEvents = true; _suppressChangeEvents = true;
foreach (var register in registers) foreach (var (name, rv) in registers)
{ {
if (Controls.OfType<Panel>().Any(p => p.Name == "FlagPanel")) if (Controls.OfType<Panel>().Any(p => p.Name == "FlagPanel"))
{ {
@ -39,9 +40,9 @@ namespace BizHawk.Client.EmuHawk
.Controls .Controls
.OfType<CheckBox>()) .OfType<CheckBox>())
{ {
if (checkbox.Name == register.Key) if (checkbox.Name == name)
{ {
checkbox.Checked = register.Value.Value == 1; checkbox.Checked = rv.Value == 1;
} }
} }
} }
@ -50,9 +51,9 @@ namespace BizHawk.Client.EmuHawk
{ {
foreach (var textBox in Controls.OfType<TextBox>()) foreach (var textBox in Controls.OfType<TextBox>())
{ {
if (textBox.Name == register.Key) if (textBox.Name == name)
{ {
textBox.Text = register.Value.Value.ToHexString(register.Value.BitSize / 4); textBox.Text = rv.Value.ToHexString(rv.BitSize / 4);
} }
} }
} }
@ -60,9 +61,9 @@ namespace BizHawk.Client.EmuHawk
{ {
foreach (var label in Controls.OfType<Label>()) foreach (var label in Controls.OfType<Label>())
{ {
if (label.Name == register.Key) if (label.Name == name)
{ {
label.Text = register.Value.Value.ToHexString(register.Value.BitSize / 4); label.Text = rv.Value.ToHexString(rv.BitSize / 4);
} }
} }
} }
@ -132,11 +133,11 @@ namespace BizHawk.Client.EmuHawk
width = 20; width = 20;
} }
foreach (var register in registers.Where(r => r.Value.BitSize != 1)) foreach (var (name, rv) in registers.Where(r => r.Value.BitSize != 1))
{ {
Controls.Add(new Label Controls.Add(new Label
{ {
Text = register.Key, Text = name,
Location = new Point(UIHelper.ScaleX(5), y + UIHelper.ScaleY(2)), Location = new Point(UIHelper.ScaleX(5), y + UIHelper.ScaleY(2)),
Size = new Size(UIHelper.ScaleX(width + 5), UIHelper.ScaleY(15)) Size = new Size(UIHelper.ScaleX(width + 5), UIHelper.ScaleY(15))
}); });
@ -145,11 +146,11 @@ namespace BizHawk.Client.EmuHawk
{ {
var t = new TextBox var t = new TextBox
{ {
Name = register.Key, Name = name,
Text = register.Value.Value.ToHexString(register.Value.BitSize / 4), Text = rv.Value.ToHexString(rv.BitSize / 4),
Width = UIHelper.ScaleX(6 + ((register.Value.BitSize / 4) * 9)), Width = UIHelper.ScaleX(6 + ((rv.BitSize / 4) * 9)),
Location = new Point(UIHelper.ScaleX(width + 10), y), Location = new Point(UIHelper.ScaleX(width + 10), y),
MaxLength = register.Value.BitSize / 4, MaxLength = rv.BitSize / 4,
CharacterCasing = CharacterCasing.Upper CharacterCasing = CharacterCasing.Upper
}; };
@ -180,9 +181,9 @@ namespace BizHawk.Client.EmuHawk
{ {
Controls.Add(new Label Controls.Add(new Label
{ {
Name = register.Key, Name = name,
Text = register.Value.Value.ToHexString(register.Value.BitSize / 4), Text = rv.Value.ToHexString(rv.BitSize / 4),
Size = new Size(UIHelper.ScaleX(6 + ((register.Value.BitSize / 4) * 9)), UIHelper.ScaleY(15)), Size = new Size(UIHelper.ScaleX(6 + ((rv.BitSize / 4) * 9)), UIHelper.ScaleY(15)),
Location = new Point(UIHelper.ScaleX(width + 12), y + 2) Location = new Point(UIHelper.ScaleX(width + 12), y + 2)
}); });
} }
@ -203,14 +204,14 @@ namespace BizHawk.Client.EmuHawk
AutoScroll = true AutoScroll = true
}; };
foreach (var flag in registers.Where(r => r.Value.BitSize == 1).OrderByDescending(x => x.Key)) foreach (var (name, rv) in registers.Where(r => r.Value.BitSize == 1).OrderByDescending(x => x.Key))
{ {
var c = new CheckBox var c = new CheckBox
{ {
Appearance = Appearance.Button, Appearance = Appearance.Button,
Name = flag.Key, Name = name,
Text = flag.Key.Replace("Flag", "").Trim(), // Hack Text = name.Replace("Flag", "").Trim(), // Hack
Checked = flag.Value.Value == 1, Checked = rv.Value == 1,
Location = new Point(UIHelper.ScaleX(40), y), Location = new Point(UIHelper.ScaleX(40), y),
Dock = DockStyle.Left, Dock = DockStyle.Left,
Size = new Size(UIHelper.ScaleX(23), UIHelper.ScaleY(23)), Size = new Size(UIHelper.ScaleX(23), UIHelper.ScaleY(23)),

View File

@ -8,6 +8,7 @@ using System.ComponentModel;
using BizHawk.Client.Common; using BizHawk.Client.Common;
using BizHawk.Client.EmuHawk.ToolExtensions; using BizHawk.Client.EmuHawk.ToolExtensions;
using BizHawk.Client.EmuHawk.Properties; using BizHawk.Client.EmuHawk.Properties;
using BizHawk.Common;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Nintendo.N64; using BizHawk.Emulation.Cores.Nintendo.N64;
@ -343,22 +344,22 @@ namespace BizHawk.Client.EmuHawk
.LogGeneratorInstance(MovieSession.MovieController) .LogGeneratorInstance(MovieSession.MovieController)
.Map(); .Map();
foreach (var kvp in columnNames) foreach (var (name, mnemonic) in columnNames)
{ {
ColumnType type; ColumnType type;
int digits; int digits;
if (ControllerType.Axes.TryGetValue(kvp.Key, out var range)) if (ControllerType.Axes.TryGetValue(name, out var range))
{ {
type = ColumnType.Axis; type = ColumnType.Axis;
digits = Math.Max(kvp.Value.Length, range.MaxDigits); digits = Math.Max(mnemonic.Length, range.MaxDigits);
} }
else else
{ {
type = ColumnType.Boolean; type = ColumnType.Boolean;
digits = kvp.Value.Length; digits = mnemonic.Length;
} }
AddColumn(kvp.Key, kvp.Value, (digits * 6) + 14, type); // magic numbers reused in EditBranchTextPopUp() AddColumn(name, mnemonic, (digits * 6) + 14, type); // magic numbers reused in EditBranchTextPopUp()
} }
var columnsToHide = TasView.AllColumns var columnsToHide = TasView.AllColumns

View File

@ -60,10 +60,10 @@ namespace BizHawk.Common
var temp = firstIsDesc var temp = firstIsDesc
? list.OrderByDescending(_predicates[idOfFirst]) ? list.OrderByDescending(_predicates[idOfFirst])
: list.OrderBy(_predicates[idOfFirst]); : list.OrderBy(_predicates[idOfFirst]);
foreach (var kvp in _predicates) foreach (var (id, pred) in _predicates)
{ {
if (kvp.Key == idOfFirst) continue; if (id == idOfFirst) continue;
temp = temp.ThenBy(kvp.Value); temp = temp.ThenBy(pred);
} }
return temp.ToList(); return temp.ToList();
} }
@ -73,10 +73,10 @@ namespace BizHawk.Common
var temp = isDescMap[idOfFirst] var temp = isDescMap[idOfFirst]
? list.OrderByDescending(_predicates[idOfFirst]) ? list.OrderByDescending(_predicates[idOfFirst])
: list.OrderBy(_predicates[idOfFirst]); : list.OrderBy(_predicates[idOfFirst]);
foreach (var kvp in _predicates) foreach (var (id, pred) in _predicates)
{ {
if (kvp.Key == idOfFirst) continue; if (id == idOfFirst) continue;
temp = isDescMap[kvp.Key] ? temp.ThenByDescending(kvp.Value) : temp.ThenBy(kvp.Value); temp = isDescMap[id] ? temp.ThenByDescending(pred) : temp.ThenBy(pred);
} }
return temp.ToList(); return temp.ToList();
} }

View File

@ -56,6 +56,12 @@ namespace BizHawk.Common
return data; return data;
} }
public static void Deconstruct<TKey, TValue>(this KeyValuePair<TKey, TValue> kvp, out TKey key, out TValue value)
{
key = kvp.Key;
value = kvp.Value;
}
/// <remarks>adapted from https://stackoverflow.com/a/3928856/7467292, values are compared using <see cref="EqualityComparer{T}.Default">EqualityComparer.Default</see></remarks> /// <remarks>adapted from https://stackoverflow.com/a/3928856/7467292, values are compared using <see cref="EqualityComparer{T}.Default">EqualityComparer.Default</see></remarks>
public static bool DictionaryEqual<TKey, TValue>(IDictionary<TKey, TValue> a, IDictionary<TKey, TValue> b) public static bool DictionaryEqual<TKey, TValue>(IDictionary<TKey, TValue> a, IDictionary<TKey, TValue> b)
where TKey : notnull where TKey : notnull

View File

@ -3,6 +3,8 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using BizHawk.Common;
namespace BizHawk.Emulation.Common namespace BizHawk.Emulation.Common
{ {
/// <summary> /// <summary>
@ -26,10 +28,7 @@ namespace BizHawk.Emulation.Common
throw new InvalidOperationException("incremental astrological examination"); throw new InvalidOperationException("incremental astrological examination");
} }
foreach (var kvp in this) foreach (var (scope, data) in this) _pins[scope] = GCHandle.Alloc(data, GCHandleType.Pinned);
{
_pins[kvp.Key] = GCHandle.Alloc(kvp.Value, GCHandleType.Pinned);
}
} }
/// <summary> /// <summary>
@ -91,9 +90,9 @@ namespace BizHawk.Emulation.Common
return false; return false;
} }
foreach (var kvp in this) foreach (var (scope, data) in this)
{ {
if (!other.TryGetValue(kvp.Key, out var oval) || oval.Length != kvp.Value.Length) return false; if (!other.TryGetValue(scope, out var oval) || oval.Length != data.Length) return false;
} }
// don't need to check keys present in other but not in this -- `Count` would differ // don't need to check keys present in other but not in this -- `Count` would differ
@ -111,10 +110,9 @@ namespace BizHawk.Emulation.Common
throw new InvalidDataException("Dictionaries must have the same number of keys!"); throw new InvalidDataException("Dictionaries must have the same number of keys!");
} }
foreach (var kvp in other) foreach (var (scope, fromData) in other)
{ {
byte[] fromData = kvp.Value; var toData = this[scope];
byte[] toData = this[kvp.Key];
if (fromData.Length != toData.Length) if (fromData.Length != toData.Length)
{ {
@ -152,21 +150,21 @@ namespace BizHawk.Emulation.Common
long addr = s.Position; long addr = s.Position;
if (forReal) if (forReal)
{ {
foreach (var kvp in this) foreach (var (scope, data) in this)
{ {
w.Write(kvp.Key); w.Write(scope);
w.Write(kvp.Value.Length); w.Write(data.Length);
w.Write(kvp.Value); w.Write(data);
} }
} }
else else
{ {
foreach (var kvp in this) foreach (var (scope, data) in this)
{ {
addr += kvp.Key.Length + 1; //assumes shortly-encoded key names addr += scope.Length + 1; // assumes shortly-encoded key names
addr += 4; addr += 4;
ret[kvp.Key] = addr; ret[scope] = addr;
addr += kvp.Value.Length; addr += data.Length;
} }
} }

View File

@ -4,6 +4,8 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using BizHawk.Common;
namespace BizHawk.Emulation.Common namespace BizHawk.Emulation.Common
{ {
/// <summary> /// <summary>
@ -47,14 +49,14 @@ namespace BizHawk.Emulation.Common
public void ApplyAxisConstraints(string constraintClass, IDictionary<string, int> axes) public void ApplyAxisConstraints(string constraintClass, IDictionary<string, int> axes)
{ {
if (!Axes.HasContraints) return; if (!Axes.HasContraints) return;
foreach (var kvp in Axes) foreach (var (k, v) in Axes)
{ {
var constraint = kvp.Value.Constraint; var constraint = v.Constraint;
if (constraint == null || constraint.Class != constraintClass) continue; if (constraint == null || constraint.Class != constraintClass) continue;
switch (constraint) switch (constraint)
{ {
case CircularAxisConstraint circular: case CircularAxisConstraint circular:
var xAxis = kvp.Key; var xAxis = k;
var yAxis = circular.PairedAxis; var yAxis = circular.PairedAxis;
(axes[xAxis], axes[yAxis]) = circular.ApplyTo(axes[xAxis], axes[yAxis]); (axes[xAxis], axes[yAxis]) = circular.ApplyTo(axes[xAxis], axes[yAxis]);
break; break;

View File

@ -3,6 +3,8 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using BizHawk.Common;
namespace BizHawk.Emulation.Common namespace BizHawk.Emulation.Common
{ {
// the idea here is that various connected peripherals have their controls all merged // the idea here is that various connected peripherals have their controls all merged
@ -42,11 +44,11 @@ namespace BizHawk.Emulation.Common
buttonAxisRemaps[s] = r; buttonAxisRemaps[s] = r;
} }
foreach (var kvp in def.Axes) foreach (var (k, v) in def.Axes)
{ {
string r = Allocate(kvp.Key, ref plr, ref playerNext); var r = Allocate(k, ref plr, ref playerNext);
ret.Axes.Add(r, kvp.Value); ret.Axes.Add(r, v);
buttonAxisRemaps[kvp.Key] = r; buttonAxisRemaps[k] = r;
} }
plr = playerNext; plr = playerNext;

View File

@ -248,12 +248,12 @@ namespace BizHawk.Emulation.DiscSystem
private void Flush() private void Flush()
{ {
subchunks.Clear(); subchunks.Clear();
foreach (KeyValuePair<string, string> kvp in dictionary) foreach (var (subchunkTag, s) in dictionary)
{ {
RiffSubchunk rs = new RiffSubchunk RiffSubchunk rs = new RiffSubchunk
{ {
tag = kvp.Key, tag = subchunkTag,
Source = new MemoryStream(System.Text.Encoding.ASCII.GetBytes(kvp.Value)), Source = new MemoryStream(System.Text.Encoding.ASCII.GetBytes(s)),
Position = 0 Position = 0
}; };
rs.Length = (uint)rs.Source.Length; rs.Length = (uint)rs.Source.Length;

View File

@ -3,6 +3,8 @@ using System.IO;
using System.Globalization; using System.Globalization;
using System.Collections.Generic; using System.Collections.Generic;
using BizHawk.Common;
//check out ccd2iso linux program? //check out ccd2iso linux program?
//https://wiki.archlinux.org/index.php/CD_Burning#TOC.2FCUE.2FBIN_for_mixed-mode_disks advice here //https://wiki.archlinux.org/index.php/CD_Burning#TOC.2FCUE.2FBIN_for_mixed-mode_disks advice here
//also referencing mednafen sources //also referencing mednafen sources
@ -307,15 +309,10 @@ namespace BizHawk.Emulation.DiscSystem
CCDTrack track = new CCDTrack(entryNum); CCDTrack track = new CCDTrack(entryNum);
ccdf.Tracks.Add(track); ccdf.Tracks.Add(track);
ccdf.TracksByNumber[entryNum] = track; ccdf.TracksByNumber[entryNum] = track;
foreach (var kvp in section) foreach (var (k, v) in section)
{ {
if (kvp.Key == "MODE") if (k == "MODE") track.Mode = v;
track.Mode = kvp.Value; else if (k.StartsWith("INDEX")) track.Indexes[int.Parse(k.Split(' ')[1])] = v;
if (kvp.Key.StartsWith("INDEX"))
{
int inum = int.Parse(kvp.Key.Split(' ')[1]);
track.Indexes[inum] = kvp.Value;
}
} }
} }
} //sections loop } //sections loop

View File

@ -139,9 +139,9 @@ namespace BizHawk.Tests.Client.Common.Movie
ss.Frame = frame; ss.Frame = frame;
zw.Capture(frame, ss); zw.Capture(frame, ss);
} }
var kvp = zw.GetStateClosestToFrame(10440); var (f, data) = zw.GetStateClosestToFrame(10440);
var actual = StateSource.GetFrameNumberInState(kvp.Value); var actual = StateSource.GetFrameNumberInState(data);
Assert.AreEqual(kvp.Key, actual); Assert.AreEqual(f, actual);
Assert.IsTrue(actual <= 10440); Assert.IsTrue(actual <= 10440);
} }

View File

@ -35,9 +35,9 @@ namespace BizHawk.Tests.Client.Common.config
public void AssertNoMissingCores() public void AssertNoMissingCores()
{ {
var allCoreNames = CoreInventory.Instance.SystemsFlat.Select(coreInfo => coreInfo.Name).ToHashSet(); var allCoreNames = CoreInventory.Instance.SystemsFlat.Select(coreInfo => coreInfo.Name).ToHashSet();
foreach (var kvp in DefaultCorePrefDict) foreach (var (sysID, coreName) in DefaultCorePrefDict)
{ {
Assert.IsTrue(allCoreNames.Contains(kvp.Value), $"default core preference for {kvp.Key} is \"{kvp.Value}\", which doesn't exist"); Assert.IsTrue(allCoreNames.Contains(coreName), $"default core preference for {sysID} is \"{coreName}\", which doesn't exist");
} }
foreach (var (appliesTo, coreNames) in Config.CorePickerUIData) foreach (var coreName in coreNames) foreach (var (appliesTo, coreNames) in Config.CorePickerUIData) foreach (var coreName in coreNames)
{ {

View File

@ -90,10 +90,10 @@ namespace BizHawk.Tests.Client.Common.config
{ {
static object Deser(string s, Type type) => JToken.Parse(s).ToObject(type, ConfigService.Serializer)!; static object Deser(string s, Type type) => JToken.Parse(s).ToObject(type, ConfigService.Serializer)!;
static string Ser(object o) => JToken.FromObject(o, ConfigService.Serializer).ToString(Formatting.None); static string Ser(object o) => JToken.FromObject(o, ConfigService.Serializer).ToString(Formatting.None);
foreach (var kvp in KnownGoodFromBizHawk) foreach (var (type, s) in KnownGoodFromBizHawk)
{ {
if (kvp.Value == "TODO") continue; if (s == "TODO") continue;
Assert.AreEqual(kvp.Value, Ser(Deser(kvp.Value, kvp.Key)), $"{kvp.Key} failed serialization round-trip"); Assert.AreEqual(s, Ser(Deser(s, type)), $"{type} failed serialization round-trip");
} }
} }
} }