use switch expressions in some various places in EmuHawk, and some other simplifications

This commit is contained in:
adelikat 2020-03-04 20:18:43 -06:00
parent 8430d145ab
commit 9584ff1f53
40 changed files with 349 additions and 688 deletions

View File

@ -34,18 +34,12 @@ namespace BizHawk.Client.EmuHawk
private void NumericUpDown2_ValueChanged(object sender, EventArgs e)
{
if (numericUpDown2.Value == -1)
label3.Text = numericUpDown2.Value switch
{
label3.Text = "Auto";
}
else if (numericUpDown2.Value == 0)
{
label3.Text = "Fastest";
}
else
{
label3.Text = $"{(int)((100 + numericUpDown2.Value / 2) / numericUpDown2.Value)} FPS";
}
-1 => "Auto",
0 => "Fastest",
_ => $"{(int) ((100 + numericUpDown2.Value / 2) / numericUpDown2.Value)} FPS"
};
}
}
}

View File

@ -37,12 +37,7 @@ namespace BizHawk.Client.EmuHawk
public static bool operator ==(Cell a, Cell b)
{
if (ReferenceEquals(a, null))
{
return ReferenceEquals(b, null);
}
return a.Equals(b);
return a?.Equals(b) ?? ReferenceEquals(b, null);
}
public static bool operator !=(Cell a, Cell b)

View File

@ -100,8 +100,7 @@ namespace BizHawk.Client.EmuHawk.CustomControls
{
if (_msgIcon != null)
{
Graphics g = e.Graphics;
g.DrawIconUnstretched(_msgIcon, new Rectangle(FormXMargin, FormYMargin, _msgIcon.Width, _msgIcon.Height));
e.Graphics.DrawIconUnstretched(_msgIcon, new Rectangle(FormXMargin, FormYMargin, _msgIcon.Width, _msgIcon.Height));
}
base.OnPaint(e);
@ -110,19 +109,14 @@ namespace BizHawk.Client.EmuHawk.CustomControls
// Get system icon for MessageBoxIcon.
private static Icon GetMessageBoxIcon(MessageBoxIcon icon)
{
switch (icon)
return icon switch
{
case MessageBoxIcon.Asterisk:
return SystemIcons.Asterisk;
case MessageBoxIcon.Error:
return SystemIcons.Error;
case MessageBoxIcon.Exclamation:
return SystemIcons.Exclamation;
case MessageBoxIcon.Question:
return SystemIcons.Question;
default:
return null;
}
MessageBoxIcon.Asterisk => SystemIcons.Asterisk,
MessageBoxIcon.Error => SystemIcons.Error,
MessageBoxIcon.Exclamation => SystemIcons.Exclamation,
MessageBoxIcon.Question => SystemIcons.Question,
_ => null
};
}
// Sets button text and returns the width.

View File

@ -100,9 +100,8 @@ namespace BizHawk.Client.EmuHawk.FilterManager
/// </summary>
public Vector2 TransformPoint(string channel, Vector2 point)
{
for (int i = 0; i < Filters.Count; i++)
foreach (var filter in Filters)
{
var filter = Filters[i];
point = filter.TransformPoint(channel, point);
}

View File

@ -7,6 +7,8 @@ using BizHawk.Client.Common;
using BizHawk.Client.EmuHawk.CustomControls;
using BizHawk.Common;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Consoles.Nintendo.QuickNES;
using BizHawk.Emulation.Cores.Nintendo.SNES9X;
using Cores = BizHawk.Emulation.Cores;
namespace BizHawk.Client.EmuHawk
@ -41,16 +43,12 @@ namespace BizHawk.Client.EmuHawk
return true;
}
if (emulator is Cores.Nintendo.SNES9X.Snes9x)
return emulator switch
{
return PromptToSwitchCore("Snes9x", "bsnes", () => Global.Config.SnesInSnes9x = false);
}
if (emulator is Cores.Consoles.Nintendo.QuickNES.QuickNES)
{
return PromptToSwitchCore("QuickNes", "NesHawk", () => Global.Config.NesInQuickNes = false);
}
return true;
Snes9x _ => PromptToSwitchCore("Snes9x", "bsnes", () => Global.Config.SnesInSnes9x = false),
QuickNES _ => PromptToSwitchCore("QuickNes", "NesHawk", () => Global.Config.NesInQuickNes = false),
_ => true
};
}
/// <remarks>http://stackoverflow.com/questions/139010/how-to-resolve-a-lnk-in-c-sharp</remarks>

View File

@ -25,47 +25,18 @@ namespace BizHawk.Client.EmuHawk.CoreExtensions
return Properties.Resources.CorpHawkSmall;
}
if (core is QuickNES)
return core switch
{
return Properties.Resources.QuickNes;
}
if (core is LibsnesCore)
{
return Properties.Resources.bsnes;
}
if (core is GPGX)
{
return Properties.Resources.genplus;
}
if (core is PSP)
{
return Properties.Resources.ppsspp;
}
if (core is Gameboy)
{
return Properties.Resources.gambatte;
}
if (core is Snes9x)
{
return Properties.Resources.snes9x;
}
if (core is MAME)
{
return Properties.Resources.mame;
}
if (core is MGBAHawk)
{
return Properties.Resources.mGba;
}
return null;
QuickNES _ => Properties.Resources.QuickNes,
LibsnesCore _ => Properties.Resources.bsnes,
GPGX _ => Properties.Resources.genplus,
PSP _ => Properties.Resources.ppsspp,
Gameboy _ => Properties.Resources.gambatte,
Snes9x _ => Properties.Resources.snes9x,
MAME _ => Properties.Resources.mame,
MGBAHawk _ => Properties.Resources.mGba,
_ => null
};
}
public static string DisplayName(this IEmulator core)

View File

@ -282,21 +282,15 @@ namespace BizHawk.Client.EmuHawk
private BlendOperation ConvertBlendOp(gl.BlendEquationMode glMode)
{
switch (glMode)
return glMode switch
{
case gl.BlendEquationMode.FuncAdd:
return BlendOperation.Add;
case gl.BlendEquationMode.FuncSubtract:
return BlendOperation.Subtract;
case gl.BlendEquationMode.Max:
return BlendOperation.Maximum;
case gl.BlendEquationMode.Min:
return BlendOperation.Minimum;
case gl.BlendEquationMode.FuncReverseSubtract:
return BlendOperation.ReverseSubtract;
default:
throw new ArgumentOutOfRangeException();
}
gl.BlendEquationMode.FuncAdd => BlendOperation.Add,
gl.BlendEquationMode.FuncSubtract => BlendOperation.Subtract,
gl.BlendEquationMode.Max => BlendOperation.Maximum,
gl.BlendEquationMode.Min => BlendOperation.Minimum,
gl.BlendEquationMode.FuncReverseSubtract => BlendOperation.ReverseSubtract,
_ => throw new ArgumentOutOfRangeException()
};
}
private Blend ConvertBlendArg(gl.BlendingFactorDest glMode) => ConvertBlendArg((gl.BlendingFactorSrc)glMode);

View File

@ -88,19 +88,18 @@ namespace BizHawk.Client.EmuHawk
{
public static bool IsModifier (this Key key)
{
if (key == Key.ShiftLeft)
return true;
if (key == Key.ShiftRight)
return true;
if (key == Key.ControlLeft)
return true;
if (key == Key.ControlRight)
return true;
if (key == Key.AltLeft)
return true;
if (key == Key.AltRight)
return true;
return false;
switch (key)
{
case Key.ShiftLeft:
case Key.ShiftRight:
case Key.ControlLeft:
case Key.ControlRight:
case Key.AltLeft:
case Key.AltRight:
return true;
default:
return false;
}
}
}

View File

@ -1373,21 +1373,14 @@ namespace BizHawk.Client.EmuHawk
if (Emulator is LibsnesCore bsnes)
{
var s = bsnes.GetSettings();
switch (layer)
result = layer switch
{
case 1:
result = s.ShowOBJ_0 ^= true;
break;
case 2:
result = s.ShowOBJ_1 ^= true;
break;
case 3:
result = s.ShowOBJ_2 ^= true;
break;
case 4:
result = s.ShowOBJ_3 ^= true;
break;
}
1 => (s.ShowOBJ_0 ^= true),
2 => (s.ShowOBJ_1 ^= true),
3 => (s.ShowOBJ_2 ^= true),
4 => (s.ShowOBJ_3 ^= true),
_ => result
};
bsnes.PutSettings(s);
AddOnScreenMessage($"Obj {layer} Layer {(result ? "On" : "Off")}");
@ -1395,21 +1388,14 @@ namespace BizHawk.Client.EmuHawk
else if (Emulator is Snes9x snes9X)
{
var s = snes9X.GetSettings();
switch (layer)
result = layer switch
{
case 1:
result = s.ShowSprites0 ^= true;
break;
case 2:
result = s.ShowSprites1 ^= true;
break;
case 3:
result = s.ShowSprites2 ^= true;
break;
case 4:
result = s.ShowSprites3 ^= true;
break;
}
1 => (s.ShowSprites0 ^= true),
2 => (s.ShowSprites1 ^= true),
3 => (s.ShowSprites2 ^= true),
4 => (s.ShowSprites3 ^= true),
_ => result
};
snes9X.PutSettings(s);
AddOnScreenMessage($"Sprite {layer} Layer {(result ? "On" : "Off")}");
@ -2835,18 +2821,7 @@ namespace BizHawk.Client.EmuHawk
PressFrameAdvance = false;
}
public bool IsLagFrame
{
get
{
if (Emulator.CanPollInput())
{
return Emulator.AsInputPollable().IsLagFrame;
}
return false;
}
}
public bool IsLagFrame => Emulator.CanPollInput() && Emulator.AsInputPollable().IsLagFrame;
private void StepRunLoop_Core(bool force = false)
{

View File

@ -38,8 +38,9 @@ namespace BizHawk.Client.EmuHawk
public static IEnumerable<string> GetDeviceNames()
{
if (!Alc.IsExtensionPresent(IntPtr.Zero, "ALC_ENUMERATION_EXT")) return Enumerable.Empty<string>();
return Alc.GetString(IntPtr.Zero, AlcGetStringList.AllDevicesSpecifier);
return !Alc.IsExtensionPresent(IntPtr.Zero, "ALC_ENUMERATION_EXT")
? Enumerable.Empty<string>()
: Alc.GetString(IntPtr.Zero, AlcGetStringList.AllDevicesSpecifier);
}
private int BufferSizeSamples { get; set; }

View File

@ -239,7 +239,7 @@ namespace BizHawk.Client.EmuHawk
float derivative = (error - lastError) / diff;
lastError = error;
integral = integral + (error * diff);
integral += error * diff;
integral *= 0.99f; // since our integral isn't reliable, reduce it to 0 over time.
// "PID controller" constants

View File

@ -97,19 +97,13 @@ namespace BizHawk.Client.EmuHawk
private void UpdateBorderNotes(AmstradCPC.BorderType type)
{
switch (type)
lblBorderInfo.Text = type switch
{
case AmstradCPC.BorderType.Uniform:
lblBorderInfo.Text = "Attempts to equalize the border areas";
break;
case AmstradCPC.BorderType.Uncropped:
lblBorderInfo.Text = "Pretty much the signal the gate array is generating (looks pants)";
break;
case AmstradCPC.BorderType.Widescreen:
lblBorderInfo.Text = "Top and bottom border removed so that the result is *almost* 16:9";
break;
}
AmstradCPC.BorderType.Uniform => "Attempts to equalize the border areas",
AmstradCPC.BorderType.Uncropped => "Pretty much the signal the gate array is generating (looks pants)",
AmstradCPC.BorderType.Widescreen => "Top and bottom border removed so that the result is *almost* 16:9",
_ => lblBorderInfo.Text
};
}
}
}

View File

@ -104,21 +104,14 @@ namespace BizHawk.Client.EmuHawk
int.Parse(VideoResolutionYTextBox.Text) : 240;
}
switch (PluginComboBox.Text)
_ss.VideoPlugin = PluginComboBox.Text switch
{
case "Rice":
_ss.VideoPlugin = PluginType.Rice;
break;
case "Glide64":
_ss.VideoPlugin = PluginType.Glide;
break;
case "Glide64mk2":
_ss.VideoPlugin = PluginType.GlideMk2;
break;
case "GLideN64":
_ss.VideoPlugin = PluginType.GLideN64;
break;
}
"Rice" => PluginType.Rice,
"Glide64" => PluginType.Glide,
"Glide64mk2" => PluginType.GlideMk2,
"GLideN64" => PluginType.GLideN64,
_ => _ss.VideoPlugin
};
// Rice
_ss.RicePlugin.NormalAlphaBlender = RiceNormalAlphaBlender_CB.Checked;
@ -746,15 +739,15 @@ namespace BizHawk.Client.EmuHawk
// GLideN64
GLideN64_UseDefaultHacks.Checked = _ss.GLideN64Plugin.UseDefaultHacks;
switch (_ss.GLideN64Plugin.MultiSampling)
GLideN64_MultiSampling.SelectedIndex = _ss.GLideN64Plugin.MultiSampling switch
{
case 0: GLideN64_MultiSampling.SelectedIndex = 0; break;
case 2: GLideN64_MultiSampling.SelectedIndex = 1; break;
case 4: GLideN64_MultiSampling.SelectedIndex = 2; break;
case 8: GLideN64_MultiSampling.SelectedIndex = 3; break;
case 16: GLideN64_MultiSampling.SelectedIndex = 4; break;
default: GLideN64_MultiSampling.SelectedIndex = 0; break;
}
0 => 0,
2 => 1,
4 => 2,
8 => 3,
16 => 4,
_ => 0
};
GLideN64_AspectRatio
.PopulateFromEnum<N64SyncSettings.N64GLideN64PluginSettings.AspectRatioMode>(_ss.GLideN64Plugin.AspectRatio);
GLideN64_BufferSwapMode

View File

@ -67,11 +67,15 @@ namespace BizHawk.Client.EmuHawk
for (int i = 0; i < 8; i++)
{
var combo = combos[i];
if (combo.SelectedIndex == 0) uc.Devices8[i] = OctoshockDll.ePeripheralType.None;
if (combo.SelectedIndex == 1) uc.Devices8[i] = OctoshockDll.ePeripheralType.Pad;
if (combo.SelectedIndex == 2) uc.Devices8[i] = OctoshockDll.ePeripheralType.DualShock;
if (combo.SelectedIndex == 3) uc.Devices8[i] = OctoshockDll.ePeripheralType.DualAnalog;
if (combo.SelectedIndex == 4) uc.Devices8[i] = OctoshockDll.ePeripheralType.NegCon;
uc.Devices8[i] = combo.SelectedIndex switch
{
0 => OctoshockDll.ePeripheralType.None,
1 => OctoshockDll.ePeripheralType.Pad,
2 => OctoshockDll.ePeripheralType.DualShock,
3 => OctoshockDll.ePeripheralType.DualAnalog,
4 => OctoshockDll.ePeripheralType.NegCon,
_ => uc.Devices8[i]
};
}
return uc;

View File

@ -32,60 +32,42 @@ namespace BizHawk.Client.EmuHawk
private void ProfileConfig_Load(object sender, EventArgs e)
{
switch (_config.SelectedProfile)
ProfileSelectComboBox.SelectedItem = _config.SelectedProfile switch
{
default:
case ClientProfile.Casual:
ProfileSelectComboBox.SelectedItem = "Casual Gaming";
break;
case ClientProfile.Longplay:
ProfileSelectComboBox.SelectedItem = "Longplays";
break;
case ClientProfile.Tas:
ProfileSelectComboBox.SelectedItem = "Tool-assisted Speedruns";
break;
case ClientProfile.N64Tas:
ProfileSelectComboBox.SelectedItem = "N64 Tool-assisted Speedruns";
break;
}
ClientProfile.Casual => "Casual Gaming",
ClientProfile.Longplay => "Longplays",
ClientProfile.Tas => "Tool-assisted Speedruns",
ClientProfile.N64Tas => "N64 Tool-assisted Speedruns",
_ => "Casual Gaming"
};
AutoCheckForUpdates.Checked = _config.UpdateAutoCheckEnabled;
}
private void OkBtn_Click(object sender, EventArgs e)
{
switch (ProfileSelectComboBox.SelectedItem.ToString())
_config.SelectedProfile = ProfileSelectComboBox.SelectedItem.ToString() switch
{
default:
case "Custom Profile": // For now
case "Casual Gaming":
_config.SelectedProfile = ClientProfile.Casual;
break;
case "Longplays":
_config.SelectedProfile = ClientProfile.Longplay;
break;
case "Tool-assisted Speedruns":
_config.SelectedProfile = ClientProfile.Tas;
break;
case "N64 Tool-assisted Speedruns":
_config.SelectedProfile = ClientProfile.N64Tas;
break;
}
"Longplays" => ClientProfile.Longplay,
"Tool-assisted Speedruns" => ClientProfile.Tas,
"N64 Tool-assisted Speedruns" => ClientProfile.N64Tas,
_ => ClientProfile.Casual
};
SetCasual();
if (_config.SelectedProfile == ClientProfile.Longplay)
switch (_config.SelectedProfile)
{
SetLongPlay();
}
else if (_config.SelectedProfile == ClientProfile.Tas)
{
SetTas();
}
else if (_config.SelectedProfile == ClientProfile.N64Tas)
{
SetTas();
SetN64Tas();
case ClientProfile.Longplay:
SetLongPlay();
break;
case ClientProfile.Tas:
SetTas();
break;
case ClientProfile.N64Tas:
SetTas();
SetN64Tas();
break;
}
bool oldUpdateAutoCheckEnabled = _config.UpdateAutoCheckEnabled;

View File

@ -98,24 +98,15 @@ namespace BizHawk.Client.EmuHawk
private void UpdateBorderNotes(ZXSpectrum.BorderType type)
{
switch (type)
lblBorderInfo.Text = type switch
{
case ZXSpectrum.BorderType.Full:
lblBorderInfo.Text = "Original border sizes";
break;
case ZXSpectrum.BorderType.Medium:
lblBorderInfo.Text = "All borders 24px";
break;
case ZXSpectrum.BorderType.None:
lblBorderInfo.Text = "No border at all";
break;
case ZXSpectrum.BorderType.Small:
lblBorderInfo.Text = "All borders 10px";
break;
case ZXSpectrum.BorderType.Widescreen:
lblBorderInfo.Text = "No top and bottom border (almost 16:9)";
break;
}
ZXSpectrum.BorderType.Full => "Original border sizes",
ZXSpectrum.BorderType.Medium => "All borders 24px",
ZXSpectrum.BorderType.None => "No border at all",
ZXSpectrum.BorderType.Small => "All borders 10px",
ZXSpectrum.BorderType.Widescreen => "No top and bottom border (almost 16:9)",
_ => lblBorderInfo.Text
};
}
}
}

View File

@ -749,20 +749,13 @@ namespace BizHawk.Client.EmuHawk
private int GetRamValue(int addr)
{
int val;
switch (_dataSize)
var val = _dataSize switch
{
default:
case 1:
val = _currentDomain.PeekByte(addr);
break;
case 2:
val = _currentDomain.PeekUshort(addr, _bigEndian);
break;
case 4:
val = (int)_currentDomain.PeekUint(addr, _bigEndian);
break;
}
1 => _currentDomain.PeekByte(addr),
2 => _currentDomain.PeekUshort(addr, _bigEndian),
4 => (int) _currentDomain.PeekUint(addr, _bigEndian),
_ => _currentDomain.PeekByte(addr)
};
return val;
}
@ -878,20 +871,15 @@ namespace BizHawk.Client.EmuHawk
private bool TestValue(byte operation, int currentValue, int bestValue)
{
switch (operation)
return operation switch
{
case 0:
return currentValue > bestValue;
case 1:
return currentValue >= bestValue;
case 2:
return currentValue == bestValue;
case 3:
return currentValue <= bestValue;
case 4:
return currentValue < bestValue;
}
return false;
0 => (currentValue > bestValue),
1 => (currentValue >= bestValue),
2 => (currentValue == bestValue),
3 => (currentValue <= bestValue),
4 => (currentValue < bestValue),
_ => false
};
}
private void UpdateBestAttempt()

View File

@ -37,7 +37,7 @@ namespace BizHawk.Client.EmuHawk
[ConfigPersist]
private bool CDLAutoResume { get; set; } = true;
void SetCurrentFilename(string fname)
private void SetCurrentFilename(string fname)
{
_currentFilename = fname;
Text = _currentFilename == null

View File

@ -312,34 +312,17 @@ namespace BizHawk.Client.EmuHawk
BigEndianCheckBox.Checked,
NameBox.Text);
Cheat.CompareType comparisonType;
switch (CompareTypeDropDown.SelectedItem.ToString())
var comparisonType = CompareTypeDropDown.SelectedItem.ToString() switch
{
case "":
comparisonType = Cheat.CompareType.None;
break;
case "=":
comparisonType = Cheat.CompareType.Equal;
break;
case ">":
comparisonType = Cheat.CompareType.GreaterThan;
break;
case ">=":
comparisonType = Cheat.CompareType.GreaterThanOrEqual;
break;
case "<":
comparisonType = Cheat.CompareType.LessThan;
break;
case "<=":
comparisonType = Cheat.CompareType.LessThanOrEqual;
break;
case "!=":
comparisonType = Cheat.CompareType.NotEqual;
break;
default:
comparisonType = Cheat.CompareType.None;
break;
}
"" => Cheat.CompareType.None,
"=" => Cheat.CompareType.Equal,
">" => Cheat.CompareType.GreaterThan,
">=" => Cheat.CompareType.GreaterThanOrEqual,
"<" => Cheat.CompareType.LessThan,
"<=" => Cheat.CompareType.LessThanOrEqual,
"!=" => Cheat.CompareType.NotEqual,
_ => Cheat.CompareType.None
};
return new Cheat(
watch,
@ -348,11 +331,9 @@ namespace BizHawk.Client.EmuHawk
true,
comparisonType);
}
else
{
MessageBox.Show($"{address} is not a valid address for the domain {domain.Name}", "Index out of range", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return Cheat.Separator;
}
MessageBox.Show($"{address} is not a valid address for the domain {domain.Name}", "Index out of range", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return Cheat.Separator;
}
public void SetAddEvent(Action addCallback)
@ -369,8 +350,7 @@ namespace BizHawk.Client.EmuHawk
private void CompareBox_TextChanged(object sender, EventArgs e)
{
WatchValueBox compareBox = (WatchValueBox)sender;
var compareBox = (WatchValueBox)sender;
PopulateComparisonTypeBox(string.IsNullOrWhiteSpace(compareBox.Text));
}

View File

@ -278,34 +278,18 @@ namespace BizHawk.Client.EmuHawk
text = Watch.DisplayTypeToString(Global.CheatList[index].Type);
break;
case ComparisonTypeColumn:
switch (Global.CheatList[index].ComparisonType)
{
case Cheat.CompareType.None:
text = "";
break;
case Cheat.CompareType.Equal:
text = "=";
break;
case Cheat.CompareType.GreaterThan:
text = ">";
break;
case Cheat.CompareType.GreaterThanOrEqual:
text = ">=";
break;
case Cheat.CompareType.LessThan:
text = "<";
break;
case Cheat.CompareType.LessThanOrEqual:
text = "<=";
break;
case Cheat.CompareType.NotEqual:
text = "!=";
break;
default:
text = "";
break;
}
text = Global.CheatList[index].ComparisonType switch
{
Cheat.CompareType.None => "",
Cheat.CompareType.Equal => "=",
Cheat.CompareType.GreaterThan => ">",
Cheat.CompareType.GreaterThanOrEqual => ">=",
Cheat.CompareType.LessThan => "<",
Cheat.CompareType.LessThanOrEqual => "<=",
Cheat.CompareType.NotEqual => "!=",
_ => ""
};
break;
}
}

View File

@ -150,8 +150,7 @@ namespace BizHawk.Client.EmuHawk
return;
}
var scrollBar = sender as ScrollBar;
if (scrollBar != null)
if (sender is ScrollBar scrollBar)
{
if (scrollBar.Value > 0)
{

View File

@ -16,10 +16,7 @@ namespace BizHawk.Client.EmuHawk
[Browsable(false)]
public bool ShouldDraw => Visible;
public override string ToString()
{
return Text;
}
public override string ToString() => Text;
public void ChangeViewSize(Size size)
{

View File

@ -12,10 +12,7 @@ namespace BizHawk.Client.EmuHawk
public BmpView BmpView => bmpView1;
public override string ToString()
{
return Text;
}
public override string ToString() => Text;
private void MobileDetailView_SizeChanged(object sender, EventArgs e)
{

View File

@ -386,12 +386,7 @@ namespace BizHawk.Client.EmuHawk
{
if (_textTable.Any())
{
if (_textTable.ContainsKey(val))
{
return _textTable[val];
}
return '?';
return _textTable.ContainsKey(val) ? _textTable[val] : '?';
}
if (val < ' ' || val >= 0x7F)
@ -412,12 +407,7 @@ namespace BizHawk.Client.EmuHawk
using var file = new HawkFile(path);
if (!file.Exists)
{
return false;
}
return file.IsArchive;
return file.Exists && file.IsArchive;
}
private byte[] GetRomBytes()

View File

@ -73,11 +73,7 @@ namespace BizHawk.Client.EmuHawk
[LuaMethod("socketServerSuccessful", "returns the status of the last Socket server action")]
public bool SocketServerSuccessful()
{
if (!CheckSocketServer())
{
return false;
}
return GlobalWin.socketServer.Successful();
return CheckSocketServer() && GlobalWin.socketServer.Successful();
}
[LuaMethod("socketServerSetTimeout", "sets the timeout in milliseconds for receiving messages")]
@ -130,6 +126,7 @@ namespace BizHawk.Client.EmuHawk
Log("Socket server was not initialized, please initialize it via the command line");
return false;
}
return true;
}

View File

@ -268,9 +268,9 @@ namespace BizHawk.Client.EmuHawk
{
if (control.Handle == ptr)
{
if (control is LuaDropDown)
if (control is LuaDropDown dd)
{
return (control as LuaDropDown).SelectedItem.ToString();
return dd.SelectedItem.ToString();
}
return control.Text;

View File

@ -12,28 +12,22 @@ namespace BizHawk.Client.EmuHawk
public bool IsInstalled(TextEditors editor)
{
switch (editor)
return editor switch
{
case TextEditors.Sublime2:
return IsSublimeInstalled();
case TextEditors.NotePad:
return IsNotepadInstalled();
}
return false;
TextEditors.Sublime2 => IsSublimeInstalled(),
TextEditors.NotePad => IsNotepadInstalled(),
_ => false
};
}
public bool IsBizLuaRegistered(TextEditors editor)
{
switch (editor)
return editor switch
{
case TextEditors.Sublime2:
return IsBizLuaSublimeInstalled();
case TextEditors.NotePad:
return IsBizLuaNotepadInstalled();
}
return false;
TextEditors.Sublime2 => IsBizLuaSublimeInstalled(),
TextEditors.NotePad => IsBizLuaNotepadInstalled(),
_ => false
};
}
public void InstallBizLua(TextEditors editor, LuaDocumentation docs)
@ -57,26 +51,14 @@ namespace BizHawk.Client.EmuHawk
{
// The most likely location of the app, eventually we should consider looking through the registry or installed apps as a more robust way to detect it;
string exePath = @"C:\Program Files\Sublime Text 2\sublime_text.exe";
if (File.Exists(exePath))
{
return true;
}
return false;
return File.Exists(exePath);
}
private bool IsNotepadInstalled()
{
// The most likely location of the app, eventually we should consider looking through the registry or installed apps as a more robust way to detect it;
string exePath = @"C:\Program Files (x86)\Notepad++\notepad++.exe";
if (File.Exists(exePath))
{
return true;
}
return false;
return File.Exists(exePath);
}
private string SublimeLuaPath = @"Sublime Text 2\Packages\Lua";
@ -85,13 +67,7 @@ namespace BizHawk.Client.EmuHawk
private bool IsBizLuaSublimeInstalled()
{
var bizCompletions = Path.Combine(AppDataFolder, SublimeLuaPath, SublimeCompletionsFilename);
if (File.Exists(bizCompletions))
{
return true;
}
return false;
return File.Exists(bizCompletions);
}
private string NotepadPath = "TODO";
@ -100,13 +76,7 @@ namespace BizHawk.Client.EmuHawk
private bool IsBizLuaNotepadInstalled()
{
var bizCompletions = Path.Combine(AppDataFolder, NotepadPath, NotepadAutoCompleteFileName);
if (File.Exists(bizCompletions))
{
return true;
}
return false;
return File.Exists(bizCompletions);
}
private void InstallBizLuaToSublime2(LuaDocumentation docs)

View File

@ -435,12 +435,7 @@ namespace BizHawk.Client.EmuHawk
private string DressUpRelative(string path)
{
if (path.StartsWith(".\\"))
{
return path.Replace(".\\", "");
}
return path;
return path.StartsWith(".\\") ? path.Replace(".\\", "") : path;
}
private void UpdateNumberOfScripts()

View File

@ -62,7 +62,7 @@ namespace BizHawk.Client.EmuHawk
}
else if (e.KeyData == (Keys.Control | Keys.A))
{
base.SelectAll();
SelectAll();
}
else
{
@ -76,11 +76,11 @@ namespace BizHawk.Client.EmuHawk
switch (_boxType)
{
case BoxType.Hex:
var hval = uint.Parse(text, NumberStyles.HexNumber);
if (hval < uint.MaxValue)
var hVal = uint.Parse(text, NumberStyles.HexNumber);
if (hVal < uint.MaxValue)
{
hval++;
Text = hval.ToString("X");
hVal++;
Text = hVal.ToString("X");
}
else
{
@ -123,11 +123,11 @@ namespace BizHawk.Client.EmuHawk
switch (_boxType)
{
case BoxType.Hex:
var hval = uint.Parse(text, NumberStyles.HexNumber);
if (hval > 0)
var hVal = uint.Parse(text, NumberStyles.HexNumber);
if (hVal > 0)
{
hval--;
Text = hval.ToString("X");
hVal--;
Text = hVal.ToString("X");
}
break;

View File

@ -288,22 +288,14 @@ namespace BizHawk.Client.EmuHawk
}
else
{
switch (NameTableView.Which)
nameTable = NameTableView.Which switch
{
default:
case NameTableViewer.WhichNametable.NT_2000:
nameTable = 0;
break;
case NameTableViewer.WhichNametable.NT_2400:
nameTable = 1;
break;
case NameTableViewer.WhichNametable.NT_2800:
nameTable = 2;
break;
case NameTableViewer.WhichNametable.NT_2C00:
nameTable = 3;
break;
}
NameTableViewer.WhichNametable.NT_2000 => 0,
NameTableViewer.WhichNametable.NT_2400 => 1,
NameTableViewer.WhichNametable.NT_2800 => 2,
NameTableViewer.WhichNametable.NT_2C00 => 3,
_ => 0
};
tileX = e.X / 16;
tileY = e.Y / 16;

View File

@ -86,18 +86,13 @@ namespace BizHawk.Client.EmuHawk
return;
}
switch (column.Name)
text = column.Name switch
{
case BranchNumberColumnName:
text = index.ToString();
break;
case FrameColumnName:
text = GetBranch(index).Frame.ToString();
break;
case UserTextColumnName:
text = GetBranch(index).UserText;
break;
}
BranchNumberColumnName => index.ToString(),
FrameColumnName => GetBranch(index).Frame.ToString(),
UserTextColumnName => GetBranch(index).UserText,
_ => text
};
}
private void QueryItemBkColor(int index, RollColumn column, ref Color color)

View File

@ -107,15 +107,12 @@ namespace BizHawk.Client.EmuHawk
text = "";
if (index < _instructions.Count)
{
switch (column.Name)
text = column.Name switch
{
case DisasmColumnName:
text = _instructions[index].Disassembly.TrimEnd();
break;
case RegistersColumnName:
text = _instructions[index].RegisterInfo;
break;
}
DisasmColumnName => _instructions[index].Disassembly.TrimEnd(),
RegistersColumnName => _instructions[index].RegisterInfo,
_ => text
};
}
}
@ -128,7 +125,7 @@ namespace BizHawk.Client.EmuHawk
SetTracerBoxTitle();
}
class CallbackSink : ITraceSink
private class CallbackSink : ITraceSink
{
public void Put(TraceInfo info)
{

View File

@ -18,7 +18,6 @@ namespace BizHawk.Client.EmuHawk
private bool IsSet
{
get => _isSet;
set
{
_isSet = value;
@ -60,7 +59,6 @@ namespace BizHawk.Client.EmuHawk
public bool ReadOnly
{
get => _readonly;
set
{
if (_readonly != value)
@ -83,7 +81,7 @@ namespace BizHawk.Client.EmuHawk
{
if (x.HasValue)
{
CurrentValue = CurrentValue + x.Value;
CurrentValue += x.Value;
}
}
@ -97,7 +95,6 @@ namespace BizHawk.Client.EmuHawk
public string DisplayName
{
get => _displayName;
set
{
_displayName = value ?? "";
@ -190,7 +187,6 @@ namespace BizHawk.Client.EmuHawk
public int CurrentValue
{
get => AnalogTrackBar.Value;
set
{
int val;

View File

@ -34,7 +34,7 @@ namespace BizHawk.Client.EmuHawk
object lastCoreOwner;
void UpdateCoreAssociation()
private void UpdateCoreAssociation()
{
if (lastCoreOwner == OwnerEmulator)
return;
@ -144,9 +144,7 @@ namespace BizHawk.Client.EmuHawk
#endif
//emergency measure: if no selection, set no disc
if (lvDiscs.SelectedIndices.Count == 0)
Global.StickyXORAdapter.SetFloat(_discSelectName, 0);
else Global.StickyXORAdapter.SetFloat(_discSelectName, lvDiscs.SelectedIndices[0]);
Global.StickyXORAdapter.SetFloat(_discSelectName, lvDiscs.SelectedIndices.Count == 0 ? 0 : lvDiscs.SelectedIndices[0]);
}
private void btnClose_Click(object sender, EventArgs e)

View File

@ -148,12 +148,12 @@ namespace BizHawk.Client.EmuHawk
{
if (x.HasValue)
{
X = X + x.Value;
X += x.Value;
}
if (y.HasValue)
{
Y = Y + y.Value;
Y += y.Value;
}
Refresh();

View File

@ -31,20 +31,15 @@ namespace BizHawk.Client.EmuHawk
private static PadSchema PadSchemaFromSetting(Atari2600ControllerTypes type, int controller)
{
switch (type)
return type switch
{
default:
case Atari2600ControllerTypes.Unplugged:
return null;
case Atari2600ControllerTypes.Joystick:
return StandardController(controller);
case Atari2600ControllerTypes.Paddle:
return PaddleController(controller);
case Atari2600ControllerTypes.BoostGrip:
return BoostGripController(controller);
case Atari2600ControllerTypes.Driving:
return DrivingController(controller);
}
Atari2600ControllerTypes.Unplugged => null,
Atari2600ControllerTypes.Joystick => StandardController(controller),
Atari2600ControllerTypes.Paddle => PaddleController(controller),
Atari2600ControllerTypes.BoostGrip => BoostGripController(controller),
Atari2600ControllerTypes.Driving => DrivingController(controller),
_ => null
};
}
private static PadSchema StandardController(int controller)

View File

@ -11,22 +11,21 @@ namespace BizHawk.Client.EmuHawk
{
public IEnumerable<PadSchema> GetPadSchemas(IEmulator core)
{
if (core.ControllerDefinition.Name == "Gameboy Controller + Tilt")
switch (core.ControllerDefinition.Name)
{
yield return StandardControllerH();
yield return ConsoleButtonsH();
yield return TiltControls();
}
else if (core.ControllerDefinition.Name == "Gameboy Controller H")
{
yield return StandardControllerH();
yield return ConsoleButtonsH();
}
else
{
yield return StandardController();
yield return ConsoleButtons();
case "Gameboy Controller + Tilt":
yield return StandardControllerH();
yield return ConsoleButtonsH();
yield return TiltControls();
break;
case "Gameboy Controller H":
yield return StandardControllerH();
yield return ConsoleButtonsH();
break;
default:
yield return StandardController();
yield return ConsoleButtons();
break;
}
}

View File

@ -179,13 +179,14 @@ namespace BizHawk.Client.EmuHawk
string disp = b.DisName;
if (txtLength == 1)
disp = $" {disp}";
switch(b.DisName)
disp = b.DisName switch
{
case "SPACE": disp = $" {disp} "; break;
case "I": disp = $" {disp} "; break;
case "W": disp = b.DisName; break;
}
"SPACE" => $" {disp} ",
"I" => $" {disp} ",
"W" => b.DisName,
_ => disp
};
if (b.IsActive)
{
@ -253,7 +254,6 @@ namespace BizHawk.Client.EmuHawk
Location = new Point(100, 52),
Type = PadSchema.PadInputType.Boolean
},
}
};
}

View File

@ -45,34 +45,23 @@ namespace BizHawk.Client.EmuHawk
{
default:
case Mode.New:
switch (MemoryDomains.First().WordSize)
SizeDropDown.SelectedItem = MemoryDomains.First().WordSize switch
{
default:
case 1:
SizeDropDown.SelectedItem = SizeDropDown.Items[0];
break;
case 2:
SizeDropDown.SelectedItem = SizeDropDown.Items[1];
break;
case 4:
SizeDropDown.SelectedItem = SizeDropDown.Items[2];
break;
}
1 => SizeDropDown.Items[0],
2 => SizeDropDown.Items[1],
4 => SizeDropDown.Items[2],
_ => SizeDropDown.Items[0]
};
break;
case Mode.Duplicate:
case Mode.Edit:
switch (Watches[0].Size)
SizeDropDown.SelectedItem = Watches[0].Size switch
{
case WatchSize.Byte:
SizeDropDown.SelectedItem = SizeDropDown.Items[0];
break;
case WatchSize.Word:
SizeDropDown.SelectedItem = SizeDropDown.Items[1];
break;
case WatchSize.DWord:
SizeDropDown.SelectedItem = SizeDropDown.Items[2];
break;
}
WatchSize.Byte => SizeDropDown.Items[0],
WatchSize.Word => SizeDropDown.Items[1],
WatchSize.DWord => SizeDropDown.Items[2],
_ => SizeDropDown.SelectedItem
};
var index = DisplayTypeDropDown.Items.IndexOf(Watch.DisplayTypeToString(Watches[0].Type));
DisplayTypeDropDown.SelectedItem = DisplayTypeDropDown.Items[index];
@ -125,19 +114,13 @@ namespace BizHawk.Client.EmuHawk
private void SetTitle()
{
switch (_mode)
Text = _mode switch
{
default:
case Mode.New:
Text = "New Watch";
break;
case Mode.Edit:
Text = $"Edit {(Watches.Count == 1 ? "Watch" : "Watches")}";
break;
case Mode.Duplicate:
Text = "Duplicate Watch";
break;
}
Mode.New => "New Watch",
Mode.Edit => $"Edit {(Watches.Count == 1 ? "Watch" : "Watches")}",
Mode.Duplicate => "Duplicate Watch",
_ => "New Watch"
};
}
private void SetAddressBoxProperties()
@ -288,19 +271,12 @@ namespace BizHawk.Client.EmuHawk
{
for (var i = 0; i < Watches.Count; i++)
{
var size = WatchSize.Byte;
switch (SizeDropDown.SelectedIndex)
var size = SizeDropDown.SelectedIndex switch
{
case 0:
size = WatchSize.Byte;
break;
case 1:
size = WatchSize.Word;
break;
case 2:
size = WatchSize.DWord;
break;
}
1 => WatchSize.Word,
2 => WatchSize.DWord,
_ => WatchSize.Byte
};
Watches[i] = Watch.GenerateWatch(
Watches[i].Domain,

View File

@ -24,7 +24,6 @@ namespace BizHawk.Client.EmuHawk
public WatchSize ByteSize
{
get => _size;
set
{
var changed = _size != value;
@ -34,21 +33,13 @@ namespace BizHawk.Client.EmuHawk
{
SetMaxLength();
bool isTypeCompatible = false;
switch (value)
var isTypeCompatible = value switch
{
case WatchSize.Byte:
isTypeCompatible = ByteWatch.ValidTypes.Any(t => t == _type);
break;
case WatchSize.Word:
isTypeCompatible = WordWatch.ValidTypes.Any(t => t == _type);
break;
case WatchSize.DWord:
isTypeCompatible = DWordWatch.ValidTypes.Any(t => t == _type);
break;
}
WatchSize.Byte => ByteWatch.ValidTypes.Any(t => t == _type),
WatchSize.Word => WordWatch.ValidTypes.Any(t => t == _type),
WatchSize.DWord => DWordWatch.ValidTypes.Any(t => t == _type),
_ => false
};
if (!isTypeCompatible)
{
@ -63,7 +54,6 @@ namespace BizHawk.Client.EmuHawk
public DisplayType Type
{
get => _type;
set
{
var val = ToRawInt();
@ -73,56 +63,29 @@ namespace BizHawk.Client.EmuHawk
}
}
private uint MaxUnsignedInt
{
get
private uint MaxUnsignedInt =>
ByteSize switch
{
switch (ByteSize)
{
default:
case WatchSize.Byte:
return byte.MaxValue;
case WatchSize.Word:
return ushort.MaxValue;
case WatchSize.DWord:
return uint.MaxValue;
}
}
}
WatchSize.Word => ushort.MaxValue,
WatchSize.DWord => uint.MaxValue,
_ => byte.MaxValue
};
private int MaxSignedInt
{
get
private int MaxSignedInt =>
ByteSize switch
{
switch (ByteSize)
{
default:
case WatchSize.Byte:
return sbyte.MaxValue;
case WatchSize.Word:
return short.MaxValue;
case WatchSize.DWord:
return int.MaxValue;
}
}
}
WatchSize.Word => short.MaxValue,
WatchSize.DWord => int.MaxValue,
_ => sbyte.MaxValue
};
private int MinSignedInt
{
get
private int MinSignedInt =>
ByteSize switch
{
switch (ByteSize)
{
default:
case WatchSize.Byte:
return sbyte.MinValue;
case WatchSize.Word:
return short.MinValue;
case WatchSize.DWord:
return int.MinValue;
}
}
}
WatchSize.Word => short.MinValue,
WatchSize.DWord => int.MinValue,
_ => sbyte.MinValue
};
private double Max12_4 => MaxUnsignedInt / 16.0;
@ -175,65 +138,39 @@ namespace BizHawk.Client.EmuHawk
MaxLength = 8;
break;
case DisplayType.Binary:
switch (_size)
MaxLength = _size switch
{
default:
case WatchSize.Byte:
MaxLength = 8;
break;
case WatchSize.Word:
MaxLength = 16;
break;
}
WatchSize.Byte => 8,
WatchSize.Word => 16,
_ => 8
};
break;
case DisplayType.Hex:
switch (_size)
MaxLength = _size switch
{
default:
case WatchSize.Byte:
MaxLength = 2;
break;
case WatchSize.Word:
MaxLength = 4;
break;
case WatchSize.DWord:
MaxLength = 8;
break;
}
WatchSize.Byte => 2,
WatchSize.Word => 4,
WatchSize.DWord => 8,
_ => 2
};
break;
case DisplayType.Signed:
switch (_size)
MaxLength = _size switch
{
default:
case WatchSize.Byte:
MaxLength = 4;
break;
case WatchSize.Word:
MaxLength = 6;
break;
case WatchSize.DWord:
MaxLength = 11;
break;
}
WatchSize.Byte => 4,
WatchSize.Word => 6,
WatchSize.DWord => 11,
_ => 4
};
break;
case DisplayType.Unsigned:
switch (_size)
MaxLength = _size switch
{
default:
case WatchSize.Byte:
MaxLength = 3;
break;
case WatchSize.Word:
MaxLength = 5;
break;
case WatchSize.DWord:
MaxLength = 10;
break;
}
WatchSize.Byte => 3,
WatchSize.Word => 5,
WatchSize.DWord => 10,
_ => 3
};
break;
case DisplayType.FixedPoint_12_4:
MaxLength = 9;
@ -357,18 +294,18 @@ namespace BizHawk.Client.EmuHawk
Text = uval.ToString();
break;
case DisplayType.Binary:
var bval = (uint)(ToRawInt() ?? 0);
if (bval == MaxUnsignedInt)
var bVal = (uint)(ToRawInt() ?? 0);
if (bVal == MaxUnsignedInt)
{
bval = 0;
bVal = 0;
}
else
{
bval++;
bVal++;
}
var numBits = ((int)ByteSize) * 8;
Text = Convert.ToString(bval, 2).PadLeft(numBits, '0');
Text = Convert.ToString(bVal, 2).PadLeft(numBits, '0');
break;
case DisplayType.Hex:
var hexVal = (uint)(ToRawInt() ?? 0);
@ -423,17 +360,17 @@ namespace BizHawk.Client.EmuHawk
Text = f16val.ToString();
break;
case DisplayType.Float:
var dval = double.Parse(text);
if (dval > double.MaxValue - 1)
var dVal = double.Parse(text);
if (dVal > double.MaxValue - 1)
{
dval = 0;
dVal = 0;
}
else
{
dval++;
dVal++;
}
Text = dval.ToString();
Text = dVal.ToString();
break;
}
}
@ -473,18 +410,18 @@ namespace BizHawk.Client.EmuHawk
Text = uval.ToString();
break;
case DisplayType.Binary:
var bval = (uint)(ToRawInt() ?? 0);
if (bval == 0)
var bVal = (uint)(ToRawInt() ?? 0);
if (bVal == 0)
{
bval = MaxUnsignedInt;
bVal = MaxUnsignedInt;
}
else
{
bval--;
bVal--;
}
var numBits = ((int)ByteSize) * 8;
Text = Convert.ToString(bval, 2).PadLeft(numBits, '0');
Text = Convert.ToString(bVal, 2).PadLeft(numBits, '0');
break;
case DisplayType.Hex:
var hexVal = (uint)(ToRawInt() ?? 0);
@ -612,12 +549,7 @@ namespace BizHawk.Client.EmuHawk
case DisplayType.Signed:
if (Text.IsSigned())
{
if (Text == "-")
{
return 0;
}
return int.Parse(Text);
return Text == "-" ? 0 : int.Parse(Text);
}
break;
@ -697,9 +629,9 @@ namespace BizHawk.Client.EmuHawk
Text = uval.ToString();
break;
case DisplayType.Binary:
var bval = (uint)val.Value;
var bVal = (uint)val.Value;
var numBits = ((int)ByteSize) * 8;
Text = Convert.ToString(bval, 2).PadLeft(numBits, '0');
Text = Convert.ToString(bVal, 2).PadLeft(numBits, '0');
break;
case DisplayType.Hex:
Text = val.Value.ToHexString(MaxLength);