misc cleanups in client.common

This commit is contained in:
adelikat 2020-08-06 21:02:08 -05:00
parent 476295ccec
commit 0818e40149
23 changed files with 54 additions and 95 deletions

View File

@ -280,6 +280,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=Datasheet/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=DEADFACE/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Deadzone/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=dearchival/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=dearchive/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=defctrl/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Dega/@EntryIndexedValue">True</s:Boolean>
@ -521,6 +522,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=subframe/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Subshell/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=sums_000D_000A_0009_0009_0009/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=SUPERSCOPE/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Syncless/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=syncpoint/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Synth/@EntryIndexedValue">True</s:Boolean>
@ -563,6 +565,7 @@
<s:Boolean x:Key="/Default/UserDictionary/Words/=untransforms/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=userdata/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Usings/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Uzebox/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=vals/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Vblank/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Vecna/@EntryIndexedValue">True</s:Boolean>

View File

@ -2,7 +2,7 @@
namespace BizHawk.Client.Common
{
/// <remarks>This class needs to be in the assembly or old tools will throw on load instead of being recognised as old.</remarks>
/// <remarks>This class needs to be in the assembly or old tools will throw on load instead of being recognized as old.</remarks>
[AttributeUsage(AttributeTargets.Assembly)]
[Obsolete("last used in 2.4, use [ExternalTool] instead")]
public sealed class BizHawkExternalToolAttribute : Attribute

View File

@ -12,7 +12,7 @@ namespace BizHawk.Client.Common
{
private ClientWebSocket? _w;
/// <summary>calls <see cref="ClientWebSocket.State"/> getter (unless closed/disposed, then <see cref="WebSocketState.Closed"/> is alwars returned)</summary>
/// <summary>calls <see cref="ClientWebSocket.State"/> getter (unless closed/disposed, then <see cref="WebSocketState.Closed"/> is always returned)</summary>
public WebSocketState State => _w?.State ?? WebSocketState.Closed;
public ClientWebSocketWrapper(Uri uri, CancellationToken? cancellationToken = null)
@ -27,7 +27,7 @@ namespace BizHawk.Client.Common
{
if (_w == null) throw new ObjectDisposedException(nameof(_w));
var task = _w.CloseAsync(closeStatus, statusDescription, cancellationToken ?? CancellationToken.None);
_w?.Dispose();
_w.Dispose();
_w = null;
return task;
}

View File

@ -497,7 +497,7 @@ namespace BizHawk.Client.Common
})
.ToList(),
Discs = xmlGame.AssetFullPaths
.Where(path => Disc.IsValidExtension(Path.GetExtension(path)))
.Where(p => Disc.IsValidExtension(Path.GetExtension(p)))
.Select(path => new
{
d = DiscExtensions.CreateAnyType(path, str => DoLoadErrorCallback(str, system, LoadErrorType.DiscError)),

View File

@ -1,13 +1,9 @@
#nullable enable
using System;
using System.IO;
using System.Linq;
using BizHawk.Common;
using SharpCompress.Archives;
using SharpCompress.Common;
namespace BizHawk.Client.Common
{

View File

@ -1,8 +1,4 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace BizHawk.Client.Common
namespace BizHawk.Client.Common
{
public interface ICheatConfig
{

View File

@ -39,7 +39,7 @@ namespace BizHawk.Client.Common
{
if (_source.Definition.Axes.TryGetValue(button, out var range))
{
var val = (int)_source.AxisValue(button);
var val = _source.AxisValue(button);
if (val == range.Mid)
{

View File

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Net.WebSockets;
using System.Text;
@ -48,7 +47,7 @@ namespace BizHawk.Client.Common
public string SocketServerScreenShotResponse()
{
CheckSocketServer();
return APIs.Comm.Sockets?.SendScreenshot(1000).ToString();
return APIs.Comm.Sockets?.SendScreenshot(1000);
}
[LuaMethod("socketServerSend", "sends a string to the Socket server")]
@ -110,11 +109,9 @@ namespace BizHawk.Client.Common
[LuaMethod("socketServerGetInfo", "returns the IP and port of the Lua socket server")]
public string SocketServerGetInfo()
{
if (!CheckSocketServer())
{
return "";
}
return APIs.Comm.Sockets.GetInfo();
return CheckSocketServer()
? APIs.Comm.Sockets.GetInfo()
: "";
}
private bool CheckSocketServer()
@ -160,7 +157,7 @@ namespace BizHawk.Client.Common
public string MmfRead(string mmf_filename, int expectedSize)
{
CheckMmf();
return APIs.Comm.MMF?.ReadFromFile(mmf_filename, expectedSize).ToString();
return APIs.Comm.MMF?.ReadFromFile(mmf_filename, expectedSize);
}
private void CheckMmf()

View File

@ -70,7 +70,7 @@ namespace BizHawk.Client.Common
[LuaMethod("rshift", "Logical shift right of 'val' by 'amt' bits")]
public static uint Rshift(uint val, int amt)
{
return (uint)(val >> amt);
return val >> amt;
}
[LuaMethodExample("local inbitars = bit.arshift( -1000, 4 );")]
@ -91,7 +91,7 @@ namespace BizHawk.Client.Common
[LuaMethod("set", "Sets the bit 'pos' in 'num'")]
public static uint Set(uint num, int pos)
{
return (uint)(num | 1U << pos);
return num | 1U << pos;
}
[LuaMethodExample("local lobitcle = bit.clear( 25, 35 );")]

View File

@ -64,7 +64,7 @@ namespace BizHawk.Client.Common
null => null,
double d => Color.FromArgb((int) (long) d),
string s => Color.FromName(s),
_ => (Color?) null
_ => null
};
}

View File

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
namespace BizHawk.Client.Common
{

View File

@ -53,8 +53,8 @@ namespace BizHawk.Client.Common
sb.Append("\r\n");
// Frame timing
double start = (double)Frame;
double end = (double)(Frame + Duration);
double start = Frame;
double end = Frame + Duration;
int startTime = (int)(start * 1000 / fps);
int endTime = (int)(end * 1000 / fps);

View File

@ -75,16 +75,7 @@ namespace BizHawk.Client.Common
{
if (_source.Definition.Axes.TryGetValue(button, out var range))
{
int val;
if (createEmpty)
{
val = range.Mid;
}
else
{
val = (int)_source.AxisValue(button);
}
var val = createEmpty ? range.Mid : _source.AxisValue(button);
sb.Append(val.ToString().PadLeft(5, ' ')).Append(',');
}

View File

@ -2,7 +2,6 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Security.AccessControl;
using System.Text;
using BizHawk.Common;

View File

@ -1,5 +1,4 @@
using System;
using System.IO;
using System.IO;
using System.Linq;
using System.Text;
using BizHawk.Emulation.Cores;

View File

@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.Linq;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Consoles.Sega.Saturn;
namespace BizHawk.Client.Common.movie.import
{
@ -18,18 +17,18 @@ namespace BizHawk.Client.Common.movie.import
{
PortDevices =
{
{ 0, "gamepad" },
{ 1, "none" },
{ 2, "none" },
{ 3, "none" },
{ 4, "none" },
{ 5, "none" },
{ 6, "none" },
{ 7, "none" },
{ 8, "none" },
{ 9, "none" },
{ 10, "none" },
{ 11, "none" },
[0] = "gamepad",
[1] = "none",
[2] = "none",
[3] = "none",
[4] = "none",
[5] = "none",
[6] = "none",
[7] = "none",
[8] = "none",
[9] = "none",
[10] = "none",
[11] = "none",
}
};

View File

@ -1,5 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.Generic;
using System.IO;
using BizHawk.Emulation.Common;
@ -23,9 +22,6 @@ namespace BizHawk.Client.Common
/// </summary>
void Capture(int frame, IStatable source, bool force = false);
// TODO: should this be used for markers?
//void CaptureHighPriority(int frame, IStatable source);
bool HasState(int frame);
/// <summary>

View File

@ -111,18 +111,18 @@ namespace BizHawk.Client.Common
{
// Separate the given frames into contiguous blocks
// and process each block independently
List<int> framesToDelete = frames.OrderBy(f => f).ToList();
List<int> framesToDelete = frames.OrderBy(fr => fr).ToList();
// f is the current index for framesToDelete
int startFrame, prevFrame, frame;
int f = 0;
int numDeleted = 0;
while (numDeleted != framesToDelete.Count)
{
prevFrame = startFrame = framesToDelete[f];
int startFrame;
var prevFrame = startFrame = framesToDelete[f];
f++;
for (; f < framesToDelete.Count; f++)
{
frame = framesToDelete[f];
var frame = framesToDelete[f];
if (frame - 1 != prevFrame)
{
f--;
@ -183,8 +183,7 @@ namespace BizHawk.Client.Common
public void InsertInput(int frame, string inputState)
{
var inputLog = new List<string>();
inputLog.Add(inputState);
var inputLog = new List<string> { inputState };
InsertInput(frame, inputLog); // ChangeLog handled within
}

View File

@ -649,7 +649,7 @@ namespace BizHawk.Client.Common
private readonly string _buttonName;
private readonly bool _isAxis = false;
public MovieActionPaint(int startFrame, int endFrame, string button, bool newS, ITasMovie movie)
public MovieActionPaint(int startFrame, int endFrame, string button, bool newS, IMovie movie)
{
_newState = newS ? 1 : 0;
FirstFrame = startFrame;
@ -663,7 +663,7 @@ namespace BizHawk.Client.Common
}
}
public MovieActionPaint(int startFrame, int endFrame, string button, int newS, ITasMovie movie)
public MovieActionPaint(int startFrame, int endFrame, string button, int newS, IMovie movie)
{
_newState = newS;
FirstFrame = startFrame;
@ -740,7 +740,6 @@ namespace BizHawk.Client.Common
public void Undo(ITasMovie movie)
{
bool wasRecording = movie.ChangeLog.IsRecording;
bool wasBinding = movie.BindMarkersToInput;
movie.ChangeLog.IsRecording = false;
movie.BindMarkersToInput = _bindMarkers;
@ -762,7 +761,6 @@ namespace BizHawk.Client.Common
public void Redo(ITasMovie movie)
{
bool wasRecording = movie.ChangeLog.IsRecording;
bool wasBinding = movie.BindMarkersToInput;
movie.ChangeLog.IsRecording = false;
movie.BindMarkersToInput = _bindMarkers;

View File

@ -109,10 +109,8 @@ namespace BizHawk.Client.Common
{
if (_entriesByName.TryGetValue(lump.ReadName, out var e))
{
using (var zs = _zip.GetInputStream(e))
{
callback(zs, e.Size);
}
using var zs = _zip.GetInputStream(e);
callback(zs, e.Size);
return true;
}

View File

@ -1,5 +1,4 @@
using BizHawk.Emulation.Common;
using System;
namespace BizHawk.Client.Common
{
@ -184,7 +183,7 @@ namespace BizHawk.Client.Common
{
if (Compare.HasValue)
{
_watch.Domain.SendCheatToCore((int)Address.Value, (byte)Value, Compare.Value, (int)ComparisonType);
_watch.Domain.SendCheatToCore((int)Address.Value, (byte)Value, Compare.Value, (int)ComparisonType);
}
else
{

View File

@ -267,32 +267,23 @@ namespace BizHawk.Client.Common
protected byte GetByte()
{
if (!IsValid)
{
return 0;
}
return _domain.PeekByte(Address);
return IsValid
? _domain.PeekByte(Address)
: (byte) 0;
}
protected ushort GetWord()
{
if (!IsValid)
{
return 0;
}
return _domain.PeekUshort(Address, BigEndian);
return IsValid
? _domain.PeekUshort(Address, BigEndian)
: (ushort) 0;
}
protected uint GetDWord()
{
if (!IsValid)
{
return 0;
}
return _domain.PeekUint(Address, BigEndian);
return IsValid
? _domain.PeekUint(Address, BigEndian)
: 0;
}
protected void PokeByte(byte val)

View File

@ -7,7 +7,6 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common