chore: Code cleanup (#399)

- [X] Code cleanup
This commit is contained in:
Kamron Batman 2021-01-10 09:14:03 -08:00 • committed by GitHub
parent a6e1172f97
commit 764d303543
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
30 changed files with 93 additions and 265 deletions

View file

@ -135,13 +135,13 @@ namespace Server
}
}
public bool Contains(Point3D p) =>
public readonly bool Contains(Point3D p) =>
m_Start.m_X <= p.m_X && m_Start.m_Y <= p.m_Y && m_End.m_X > p.m_X && m_End.m_Y > p.m_Y;
public bool Contains(Point2D p) =>
public readonly bool Contains(Point2D p) =>
m_Start.m_X <= p.m_X && m_Start.m_Y <= p.m_Y && m_End.m_X > p.m_X && m_End.m_Y > p.m_Y;
public bool Contains(IPoint2D p) => m_Start <= p && m_End > p;
public readonly bool Contains(IPoint2D p) => m_Start <= p && m_End > p;
public override string ToString() => $"({X}, {Y})+({Width}, {Height})";
}

View file

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using Server.ContextMenus;
using Server.Items;
using Server.Network;
@ -2487,6 +2488,7 @@ namespace Server
{
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void SetSaveFlag(ref SaveFlag flags, SaveFlag toSet, bool setIf)
{
if (setIf)

View file

@ -24,7 +24,7 @@ namespace Server.Json
{
public override IPEndPoint Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
if (IPEndPoint.TryParse(reader.GetString(), out var ipep))
if (IPEndPoint.TryParse(reader.GetString()!, out var ipep))
{
return ipep;
}

View file

@ -22,7 +22,7 @@ namespace Server.Json
public class TimeSpanConverter : JsonConverter<TimeSpan>
{
public override TimeSpan Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
=> TimeSpan.Parse(reader.GetString());
=> TimeSpan.Parse(reader.GetString()!);
public override void Write(Utf8JsonWriter writer, TimeSpan value, JsonSerializerOptions options)
=> writer.WriteStringValue(value.ToString());

View file

@ -78,7 +78,7 @@ namespace Server.Json
File.Delete(filePath);
}
Directory.CreateDirectory(Path.GetDirectoryName(filePath));
Directory.CreateDirectory(Path.GetDirectoryName(filePath)!);
File.WriteAllText(filePath, contents);
}

View file

@ -6,7 +6,6 @@ using System.Linq;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using Microsoft.Toolkit.HighPerformance.Extensions;
using Microsoft.Toolkit.HighPerformance.Memory;
using Server.Accounting;
using Server.Buffers;
using Server.ContextMenus;

View file

@ -13,8 +13,6 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
*************************************************************************/
using System;
namespace Server.Network
{
public static class IncomingEntityPackets

View file

@ -239,7 +239,7 @@ namespace Server.Network
_pipe._readContinuation = null;
_pipe._readAwaitBeginning = false;
ThreadPool.UnsafeQueueUserWorkItem(state => continuation(), true);
ThreadPool.UnsafeQueueUserWorkItem(_ => continuation(), true);
}
#region Awaitable
@ -385,7 +385,7 @@ namespace Server.Network
_pipe._writeContinuation = null;
_pipe._readAwaitBeginning = false;
ThreadPool.UnsafeQueueUserWorkItem(state => continuation(), true);
ThreadPool.UnsafeQueueUserWorkItem(_ => continuation(), true);
}
#region Awaitable

View file

@ -343,7 +343,13 @@ namespace Server
fixed (StaticTile* pTiles = staTiles)
{
NativeReader.Read(DataStream.SafeFileHandle.DangerousGetHandle(), pTiles, length);
var ptr = DataStream.SafeFileHandle?.DangerousGetHandle();
if (ptr == null)
{
throw new Exception($"Cannot open {DataStream.Name}");
}
NativeReader.Read(ptr.Value, pTiles, length);
if (m_Lists == null)
{
m_Lists = new TileList[8][];
@ -422,7 +428,12 @@ namespace Server
fixed (LandTile* pTiles = tiles)
{
NativeReader.Read(m_MapStream.SafeFileHandle.DangerousGetHandle(), pTiles, 192);
var ptr = m_MapStream.SafeFileHandle?.DangerousGetHandle();
if (ptr == null)
{
throw new Exception($"Cannot open {m_MapStream.Name}");
}
NativeReader.Read(ptr.Value, pTiles, 192);
}
return tiles;

View file

@ -1,3 +1,4 @@
using System;
using System.IO;
using System.Runtime.CompilerServices;
@ -60,7 +61,13 @@ namespace Server
fixed (LandTile* pTiles = tiles)
{
NativeReader.Read(fsData.SafeFileHandle.DangerousGetHandle(), pTiles, 192);
var ptr = fsData.SafeFileHandle?.DangerousGetHandle();
if (ptr == null)
{
throw new Exception($"Cannot open {fsData.Name}");
}
NativeReader.Read(ptr.Value, pTiles, 192);
}
matrix.SetLandBlock(x, y, tiles);
@ -123,7 +130,14 @@ namespace Server
fixed (StaticTile* pTiles = staTiles)
{
NativeReader.Read(fsData.SafeFileHandle.DangerousGetHandle(), pTiles, length);
var ptr = fsData.SafeFileHandle?.DangerousGetHandle();
if (ptr == null)
{
throw new Exception($"Cannot open {fsData.Name}");
}
NativeReader.Read(ptr.Value, pTiles, length);
StaticTile* pCur = pTiles, pEnd = pTiles + tileCount;
while (pCur < pEnd)