misc cleanups in Client.Common

This commit is contained in:
adelikat 2020-12-04 15:39:52 -06:00
parent 206817dab8
commit e0c1fc4a4d
24 changed files with 70 additions and 78 deletions

View File

@ -95,6 +95,7 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=IRQ/@EntryIndexedValue">IRQ</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=LR/@EntryIndexedValue">LR</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=MGBA/@EntryIndexedValue">MGBA</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=NDS/@EntryIndexedValue">NDS</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=NES/@EntryIndexedValue">NES</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=NMI/@EntryIndexedValue">NMI</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=NT/@EntryIndexedValue">NT</s:String>
@ -117,6 +118,7 @@
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SGX/@EntryIndexedValue">SGX</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SHA/@EntryIndexedValue">SHA</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SNES/@EntryIndexedValue">SNES</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=SQ/@EntryIndexedValue">SQ</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=TA/@EntryIndexedValue">TA</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=TAS/@EntryIndexedValue">TAS</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/CSharpNaming/Abbreviations/=TI/@EntryIndexedValue">TI</s:String>
@ -261,6 +263,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=colesced/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Colour/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Commavid/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Comparers/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Compositing/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Compumate/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Conout/@EntryIndexedValue">True</s:Boolean>
@ -272,6 +275,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=curr/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=CURRINDEX/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=CURRTRACK/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Cygne/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Cyotek/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Daaaaaaa/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=databus/@EntryIndexedValue">True</s:Boolean>
@ -306,6 +310,8 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=endianess/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=endrift/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=EPRO/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Exts/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Faaaaaaa/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Fairchild/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Famicom/@EntryIndexedValue">True</s:Boolean>

View File

@ -8,7 +8,7 @@ using BizHawk.Client.Common;
namespace BizHawk.Bizware.DirectX
{
public sealed class DirectInputAdapter : HostInputAdapter
public sealed class DirectInputAdapter : IHostInputAdapter
{
private Config? _config;

View File

@ -196,7 +196,7 @@ namespace BizHawk.Client.Common
QuickNES quickNes => quickNes.GetSettings(),
SMS sms => sms.GetSettings(),
WonderSwan ws => ws.GetSettings(),
_ => (object) null
_ => null
};
public PutSettingsDirtyBits PutSettings(object settings) => Emulator switch
@ -214,7 +214,7 @@ namespace BizHawk.Client.Common
public void SetRenderPlanes(params bool[] args)
{
static bool GetSetting(bool[] settings, int index) => index >= settings.Length || settings[index];
void SetBSNES(LibsnesCore core)
void SetBsnes(LibsnesCore core)
{
var s = core.GetSettings();
s.ShowBG1_0 = s.ShowBG1_1 = GetSetting(args, 0);
@ -273,7 +273,7 @@ namespace BizHawk.Client.Common
else if (!showSp && s.NumSprites > 0) s.NumSprites = 0;
quicknes.PutSettings(s);
}
void SetSMSHawk(SMS sms)
void SetSmsHawk(SMS sms)
{
var s = sms.GetSettings();
s.DispOBJ = GetSetting(args, 0);
@ -286,7 +286,7 @@ namespace BizHawk.Client.Common
SetGPGX(gpgx);
break;
case LibsnesCore snes:
SetBSNES(snes);
SetBsnes(snes);
break;
case NES nes:
SetNesHawk(nes);
@ -298,7 +298,7 @@ namespace BizHawk.Client.Common
SetQuickNES(quicknes);
break;
case SMS sms:
SetSMSHawk(sms);
SetSmsHawk(sms);
break;
case WonderSwan ws:
SetCygne(ws);

View File

@ -165,7 +165,7 @@ namespace BizHawk.Client.Common
}
case 4:
{
d.PokeUint(addr, (uint)value, _isBigEndian);
d.PokeUint(addr, value, _isBigEndian);
break;
}
}

View File

@ -36,8 +36,8 @@ namespace BizHawk.Client.Common.Filters
var output = FindOutput(channel);
if (input != null && output != null)
{
point.X *= ((float)input.SurfaceFormat.Size.Width) / (float)output.SurfaceFormat.Size.Width;
point.Y *= ((float)input.SurfaceFormat.Size.Height) / (float)output.SurfaceFormat.Size.Height;
point.X *= input.SurfaceFormat.Size.Width / (float)output.SurfaceFormat.Size.Width;
point.Y *= input.SurfaceFormat.Size.Height / (float)output.SurfaceFormat.Size.Height;
}
return point;
}
@ -49,8 +49,8 @@ namespace BizHawk.Client.Common.Filters
var output = FindOutput(channel);
if (input != null && output != null)
{
point.X *= ((float)output.SurfaceFormat.Size.Width) / (float)input.SurfaceFormat.Size.Width;
point.Y *= ((float)output.SurfaceFormat.Size.Height) / (float)input.SurfaceFormat.Size.Height;
point.X *= output.SurfaceFormat.Size.Width / (float)input.SurfaceFormat.Size.Width;
point.Y *= output.SurfaceFormat.Size.Height / (float)input.SurfaceFormat.Size.Height;
}
return point;
}

View File

@ -40,8 +40,8 @@ namespace BizHawk.Client.Common.Filters
//zero 02-jun-2014 - we passed these in, but ignored them. kind of weird..
int oldSourceWidth = sourceWidth;
int oldSourceHeight = sourceHeight;
sourceWidth = (int)virtualWidth;
sourceHeight = (int)virtualHeight;
sourceWidth = virtualWidth;
sourceHeight = virtualHeight;
// this doesn't make sense
if (!maintainAspect)
@ -83,7 +83,7 @@ namespace BizHawk.Client.Common.Filters
PS + new Vector2(1, 1)
};
bool[] trialsLimited = new bool[3] { false,false,false};
bool[] trialsLimited = new bool[] { false, false, false};
int bestIndex = -1;
float bestValue = 1000.0f;
for (int t = 0; t < trials.Length; t++)
@ -177,7 +177,7 @@ namespace BizHawk.Client.Common.Filters
public IGL GL;
public IGuiRenderer GuiRenderer;
private MelonDS nds;
private readonly MelonDS nds;
//TODO: actually use this
private bool nop = false;
@ -344,7 +344,7 @@ namespace BizHawk.Client.Common.Filters
{
point = Transform(matBotInvert, point);
//hack to accomodate input tracking system's float-point sense (based on the core's videobuffer height)
//hack to accomodate input tracking system's float-point sense (based on the core's VideoBuffer height)
//actually, this is needed for a reason similar to the "TouchScreenStart" that I removed.
//So, something like that needs readding if we're to get rid of this hack.
//(should redo it as a mouse coordinate offset or something.. but the key is to pipe it to the point where this is needed.. that is where MainForm does DisplayManager.UntransformPoint()
@ -425,7 +425,7 @@ namespace BizHawk.Client.Common.Filters
public FinalPresentation(Size size)
{
this.OutputSize = size;
OutputSize = size;
}
private Size OutputSize, InputSize;
@ -489,13 +489,7 @@ namespace BizHawk.Client.Common.Filters
public override void SetInputFormat(string channel, SurfaceState state)
{
bool need = false;
if (state.SurfaceFormat.Size != OutputSize)
need = true;
if (FilterOption != eFilterOption.None)
need = true;
if (Flip)
need = true;
bool need = state.SurfaceFormat.Size != OutputSize || FilterOption != eFilterOption.None || Flip;
if (!need)
{

View File

@ -153,7 +153,7 @@ namespace BizHawk.Client.Common.Filters
Passes.Add(sp);
sp.InputFilterLinear = FetchBool(dict, $"filter_linear{i}", false); //Should this value not be defined, the filtering option is implementation defined.
sp.OuputFloat = FetchBool(dict, $"float_framebuffer{i}", false);
sp.OutputFloat = FetchBool(dict, $"float_framebuffer{i}", false);
sp.FrameCountMod = FetchInt(dict, $"frame_count_mod{i}", 1);
sp.ShaderPath = FetchString(dict, $"shader{i}", "?"); //todo - change extension to .cg for better compatibility? just change .cg to .glsl transparently at last second?
@ -191,24 +191,24 @@ namespace BizHawk.Client.Common.Filters
public int Index;
public string ShaderPath;
public bool InputFilterLinear;
public bool OuputFloat;
public bool OutputFloat;
public int FrameCountMod;
public ScaleType ScaleTypeX;
public ScaleType ScaleTypeY;
public Vector2 Scale;
}
private string FetchString(IDictionary<string, string> dict, string key, string @default)
private static string FetchString(IDictionary<string, string> dict, string key, string @default)
{
return dict.TryGetValue(key, out var str) ? str : @default;
}
private int FetchInt(IDictionary<string, string> dict, string key, int @default)
private static int FetchInt(IDictionary<string, string> dict, string key, int @default)
{
return dict.TryGetValue(key, out var str) ? int.Parse(str) : @default;
}
private float FetchFloat(IDictionary<string, string> dict, string key, float @default)
private static float FetchFloat(IDictionary<string, string> dict, string key, float @default)
{
return dict.TryGetValue(key, out var str) ? float.Parse(str) : @default;
}

View File

@ -14,7 +14,7 @@ namespace BizHawk.Client.Common
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return ((sourceType == typeof(string)) || base.CanConvertFrom(context, sourceType));
return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
@ -44,7 +44,7 @@ namespace BizHawk.Client.Common
{
if (destinationType == null)
{
throw new ArgumentNullException("destinationType");
throw new ArgumentNullException(nameof(destinationType));
}
if (destinationType == typeof(string))

View File

@ -5,6 +5,7 @@ using System.Runtime.InteropServices;
using BizHawk.Common;
using BizHawk.Emulation.Common;
// ReSharper disable FieldCanBeMadeReadOnly.Local
// ReSharper disable InconsistentNaming
// ReSharper disable StyleCop.SA1304
// ReSharper disable StyleCop.SA1307

View File

@ -98,11 +98,6 @@ namespace BizHawk.Client.Common
// For not throwing errors but simply outputting information to the screen
public Action<string> MessageCallback { get; set; }
private void DoMessageCallback(string message)
{
MessageCallback?.Invoke(message);
}
// TODO: reconsider the need for exposing these;
public IEmulator LoadedEmulator { get; private set; }
public GameInfo Game { get; private set; }
@ -237,7 +232,6 @@ namespace BizHawk.Client.Common
private GameInfo MakeGameFromDisc(Disc disc, string ext, string name)
{
GameInfo game;
// TODO - use more sophisticated IDer
var discType = new DiscIdentifier(disc).DetectDiscType();
var discHasher = new DiscHasher(disc);
@ -245,7 +239,7 @@ namespace BizHawk.Client.Common
? discHasher.Calculate_PSX_BizIDHash().ToString("X8")
: discHasher.OldHash();
game = Database.CheckDatabase(discHash);
var game = Database.CheckDatabase(discHash);
if (game == null)
{
// try to use our wizard methods

View File

@ -21,7 +21,7 @@ namespace BizHawk.Client.Common
* Why use this, when each core has it's own Async sound output?
*
* It is true that each emulation core provides its own async sound output, either through directly
* rendering to arbitrary buffers (pce not turbocd, sms), or using one of the metaspus (nes, turbocd).
* rendering to arbitrary buffers (pce not TurboCD, sms), or using one of the metaspus (nes, TurboCD).
*
* Unfortunately, the vecna metaspu is not perfect, and for maintaining near-realtime playback (the usual
* situation which we want to optimize for), it simply sounds better with a BufferedAsync on top of it.

View File

@ -47,7 +47,7 @@ namespace BizHawk.Client.Common.cheats
};
private IDecodeResult GameBoy(string code)
private static IDecodeResult GameBoy(string code)
{
// Game Genie
if (code.LastIndexOf("-") == 7 && code.IndexOf("-") == 3)
@ -65,7 +65,7 @@ namespace BizHawk.Client.Common.cheats
return new InvalidCheatCode($"Unknown code type: {code}");
}
private IDecodeResult Gba(string code)
private static IDecodeResult Gba(string code)
{
if (code.Length == 12)
{
@ -75,7 +75,7 @@ namespace BizHawk.Client.Common.cheats
return GbaGameSharkDecoder.Decode(code);
}
private IDecodeResult Gen(string code)
private static IDecodeResult Gen(string code)
{
// Game Genie only
if (code.Length == 9 && code.Contains("-"))
@ -99,15 +99,15 @@ namespace BizHawk.Client.Common.cheats
return new InvalidCheatCode($"Unknown code type: {code}");
}
private IDecodeResult N64(string code) => N64GameSharkDecoder.Decode(code);
private static IDecodeResult N64(string code) => N64GameSharkDecoder.Decode(code);
private IDecodeResult Nes(string code) => NesGameGenieDecoder.Decode(code);
private static IDecodeResult Nes(string code) => NesGameGenieDecoder.Decode(code);
private IDecodeResult Psx(string code) => PsxGameSharkDecoder.Decode(code);
private static IDecodeResult Psx(string code) => PsxGameSharkDecoder.Decode(code);
private IDecodeResult Saturn(string code) => SaturnGameSharkDecoder.Decode(code);
private static IDecodeResult Saturn(string code) => SaturnGameSharkDecoder.Decode(code);
private IDecodeResult Sms(string code)
private static IDecodeResult Sms(string code)
{
// Game Genie
if (code.LastIndexOf("-") == 7 && code.IndexOf("-") == 3)
@ -124,7 +124,7 @@ namespace BizHawk.Client.Common.cheats
return new InvalidCheatCode($"Unknown code type: {code}");
}
private IDecodeResult Snes(string code)
private static IDecodeResult Snes(string code)
{
if (code.Contains("-") && code.Length == 9)
{

View File

@ -1,5 +1,8 @@
#nullable enable
// ReSharper disable CommentTypo
// ReSharper disable IdentifierTypo
// ReSharper disable UnusedMember.Global
namespace BizHawk.Client.Common
{
/// <summary>values are one-to-one with <c>System.Windows.Input.Key</c> except <see cref="NumPadEnter"/> and <see cref="Unknown"/> which were added for this project</summary>

View File

@ -6,7 +6,7 @@ using System.Collections.Generic;
namespace BizHawk.Client.Common
{
/// <remarks>this was easier than trying to make static classes instantiable...</remarks>
public interface HostInputAdapter
public interface IHostInputAdapter
{
void DeInitAll();

View File

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Net.WebSockets;
using System.Text;
namespace BizHawk.Client.Common

View File

@ -48,7 +48,7 @@ namespace BizHawk.Client.Common
public void SetDefaultBackgroundColor(Color color) => APIs.Gui.SetDefaultBackgroundColor(color);
[LuaMethodExample("gui.defaultTextBackground( 0x000000FF );")]
[LuaMethod("defaultTextBackground", "Sets the default backgroiund color to use in text drawing methods, half-transparent black by default")]
[LuaMethod("defaultTextBackground", "Sets the default background color to use in text drawing methods, half-transparent black by default")]
public void SetDefaultTextBackground(Color color) => APIs.Gui.SetDefaultTextBackground(color);
[LuaMethodExample("gui.defaultPixelFont( \"Arial Narrow\");")]

View File

@ -209,20 +209,17 @@ namespace BizHawk.Client.Common
{
if (string.IsNullOrWhiteSpace(movie.Core))
{
if (preferredCores.TryGetValue(systemId, out var coreName))
{
PopupMessage($"No core specified in the movie file, using the preferred core {preferredCores[systemId]} instead.");
}
else
{
PopupMessage($"No core specified in the movie file, using the default core instead.");
}
PopupMessage(preferredCores.TryGetValue(systemId, out _)
? $"No core specified in the movie file, using the preferred core {preferredCores[systemId]} instead."
: "No core specified in the movie file, using the default core instead.");
}
else
{
var keys = preferredCores.Keys.ToList();
foreach (var k in keys)
{
preferredCores[k] = movie.Core;
}
}
}

View File

@ -23,18 +23,18 @@ namespace BizHawk.Client.Common
["SNES_PAL"] = 21281370.0 / (4 * 341 * 312), // 50.0069789082
["SGB"] = 21477272.0 / (4 * 341 * 262), // 60.098475521
["SGB_PAL"] = 21281370.0 / (4 * 341 * 312), // 50.0069789082
["PCE"] = (7159090.90909090 / 455 / 263), // 59.8261054535
["PCECD"] = (7159090.90909090 / 455 / 263), // 59.8261054535
["SMS"] = (3579545 / 262.0 / 228.0), // 59.9227434043
["SMS_PAL"] = (3546893 / 313.0 / 228.0), // 49.7014320946
["GG"] = (3579545 / 262.0 / 228.0), // 59.9227434043
["GG_PAL"] = (3546893 / 313.0 / 228.0), // 49.7014320946
["SG"] = (3579545 / 262.0 / 228.0), // 59.9227434043
["SG_PAL"] = (3546893 / 313.0 / 228.0), // 49.7014320946
["NGP"] = (6144000.0 / (515 * 198)), // 60.2530155928
["VB"] = (20000000.0 / (259 * 384 * 4)), // 50.2734877735
["PCE"] = 7159090.90909090 / 455 / 263, // 59.8261054535
["PCECD"] = 7159090.90909090 / 455 / 263, // 59.8261054535
["SMS"] = 3579545 / 262.0 / 228.0, // 59.9227434043
["SMS_PAL"] = 3546893 / 313.0 / 228.0, // 49.7014320946
["GG"] = 3579545 / 262.0 / 228.0, // 59.9227434043
["GG_PAL"] = 3546893 / 313.0 / 228.0, // 49.7014320946
["SG"] = 3579545 / 262.0 / 228.0, // 59.9227434043
["SG_PAL"] = 3546893 / 313.0 / 228.0, // 49.7014320946
["NGP"] = 6144000.0 / (515 * 198), // 60.2530155928
["VB"] = 20000000.0 / (259 * 384 * 4), // 50.2734877735
["Lynx"] = 16000000.0 / (16 * 105 * 159), // 59.89817310572028
["WSWAN"] = (3072000.0 / (159 * 256)), // 75.4716981132
["WSWAN"] = 3072000.0 / (159 * 256), // 75.4716981132
["GB"] = 262144.0 / 4389.0, // 59.7275005696
["GBC"] = 262144.0 / 4389.0, // 59.7275005696

View File

@ -95,7 +95,7 @@ namespace BizHawk.Client.Common
}
}
private void CreateDirectoryIfNotExists(string fn)
private static void CreateDirectoryIfNotExists(string fn)
{
var file = new FileInfo(fn);
if (file.Directory != null && !file.Directory.Exists)

View File

@ -83,7 +83,7 @@ namespace BizHawk.Client.Common
// Just to simplify some other code.
public RewindConfig Current()
{
return new RewindConfig()
return new RewindConfig
{
UseCompression = CurrentUseCompression,
BufferSize = CurrentBufferSize,
@ -92,7 +92,7 @@ namespace BizHawk.Client.Common
}
public RewindConfig Recent()
{
return new RewindConfig()
return new RewindConfig
{
UseCompression = RecentUseCompression,
BufferSize = RecentBufferSize,
@ -101,7 +101,7 @@ namespace BizHawk.Client.Common
}
public RewindConfig GapFiller()
{
return new RewindConfig()
return new RewindConfig
{
UseCompression = GapsUseCompression,
BufferSize = GapsBufferSize,

View File

@ -1,7 +1,6 @@
using System;
using System.IO;
using System.IO.Compression;
using System.Runtime.InteropServices;
using BizHawk.BizInvoke;
using BizHawk.Common;

View File

@ -5,7 +5,6 @@ using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BizHawk.Emulation.Common;

View File

@ -110,7 +110,7 @@ namespace BizHawk.Client.EmuHawk
private readonly Thread _updateThread;
public readonly HostInputAdapter Adapter;
public readonly IHostInputAdapter Adapter;
private readonly Func<Config> _getConfigCallback;

View File

@ -7,7 +7,7 @@ using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
{
public sealed class OpenTKInputAdapter : HostInputAdapter
public sealed class OpenTKInputAdapter : IHostInputAdapter
{
public void DeInitAll() {}