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/=Datasheet/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=DEADFACE/@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/=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/=dearchive/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=defctrl/@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> <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/=subframe/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Subshell/@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/=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/=Syncless/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=syncpoint/@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> <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/=untransforms/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=userdata/@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/=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/=vals/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Vblank/@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> <s:Boolean x:Key="/Default/UserDictionary/Words/=Vecna/@EntryIndexedValue">True</s:Boolean>

View File

@ -2,7 +2,7 @@
namespace BizHawk.Client.Common 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)] [AttributeUsage(AttributeTargets.Assembly)]
[Obsolete("last used in 2.4, use [ExternalTool] instead")] [Obsolete("last used in 2.4, use [ExternalTool] instead")]
public sealed class BizHawkExternalToolAttribute : Attribute public sealed class BizHawkExternalToolAttribute : Attribute

View File

@ -12,7 +12,7 @@ namespace BizHawk.Client.Common
{ {
private ClientWebSocket? _w; 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 WebSocketState State => _w?.State ?? WebSocketState.Closed;
public ClientWebSocketWrapper(Uri uri, CancellationToken? cancellationToken = null) public ClientWebSocketWrapper(Uri uri, CancellationToken? cancellationToken = null)
@ -27,7 +27,7 @@ namespace BizHawk.Client.Common
{ {
if (_w == null) throw new ObjectDisposedException(nameof(_w)); if (_w == null) throw new ObjectDisposedException(nameof(_w));
var task = _w.CloseAsync(closeStatus, statusDescription, cancellationToken ?? CancellationToken.None); var task = _w.CloseAsync(closeStatus, statusDescription, cancellationToken ?? CancellationToken.None);
_w?.Dispose(); _w.Dispose();
_w = null; _w = null;
return task; return task;
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -64,7 +64,7 @@ namespace BizHawk.Client.Common
null => null, null => null,
double d => Color.FromArgb((int) (long) d), double d => Color.FromArgb((int) (long) d),
string s => Color.FromName(s), 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 namespace BizHawk.Client.Common
{ {

View File

@ -53,8 +53,8 @@ namespace BizHawk.Client.Common
sb.Append("\r\n"); sb.Append("\r\n");
// Frame timing // Frame timing
double start = (double)Frame; double start = Frame;
double end = (double)(Frame + Duration); double end = Frame + Duration;
int startTime = (int)(start * 1000 / fps); int startTime = (int)(start * 1000 / fps);
int endTime = (int)(end * 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)) if (_source.Definition.Axes.TryGetValue(button, out var range))
{ {
int val; var val = createEmpty ? range.Mid : _source.AxisValue(button);
if (createEmpty)
{
val = range.Mid;
}
else
{
val = (int)_source.AxisValue(button);
}
sb.Append(val.ToString().PadLeft(5, ' ')).Append(','); sb.Append(val.ToString().PadLeft(5, ' ')).Append(',');
} }

View File

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

View File

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

View File

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

View File

@ -1,5 +1,4 @@
using System; using System.Collections.Generic;
using System.Collections.Generic;
using System.IO; using System.IO;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
@ -23,9 +22,6 @@ namespace BizHawk.Client.Common
/// </summary> /// </summary>
void Capture(int frame, IStatable source, bool force = false); 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); bool HasState(int frame);
/// <summary> /// <summary>

View File

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

View File

@ -649,7 +649,7 @@ namespace BizHawk.Client.Common
private readonly string _buttonName; private readonly string _buttonName;
private readonly bool _isAxis = false; 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; _newState = newS ? 1 : 0;
FirstFrame = startFrame; 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; _newState = newS;
FirstFrame = startFrame; FirstFrame = startFrame;
@ -740,7 +740,6 @@ namespace BizHawk.Client.Common
public void Undo(ITasMovie movie) public void Undo(ITasMovie movie)
{ {
bool wasRecording = movie.ChangeLog.IsRecording; bool wasRecording = movie.ChangeLog.IsRecording;
bool wasBinding = movie.BindMarkersToInput;
movie.ChangeLog.IsRecording = false; movie.ChangeLog.IsRecording = false;
movie.BindMarkersToInput = _bindMarkers; movie.BindMarkersToInput = _bindMarkers;
@ -762,7 +761,6 @@ namespace BizHawk.Client.Common
public void Redo(ITasMovie movie) public void Redo(ITasMovie movie)
{ {
bool wasRecording = movie.ChangeLog.IsRecording; bool wasRecording = movie.ChangeLog.IsRecording;
bool wasBinding = movie.BindMarkersToInput;
movie.ChangeLog.IsRecording = false; movie.ChangeLog.IsRecording = false;
movie.BindMarkersToInput = _bindMarkers; movie.BindMarkersToInput = _bindMarkers;

View File

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

View File

@ -1,5 +1,4 @@
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
using System;
namespace BizHawk.Client.Common namespace BizHawk.Client.Common
{ {
@ -184,7 +183,7 @@ namespace BizHawk.Client.Common
{ {
if (Compare.HasValue) 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 else
{ {

View File

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

View File

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