Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Selinux24 committed Mar 11, 2024
1 parent b5e08fc commit fd8c0fe
Show file tree
Hide file tree
Showing 46 changed files with 530 additions and 658 deletions.
2 changes: 1 addition & 1 deletion Engine.PathFinding.RecastNavigation/ArrayUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static void ResetArray<T>(T[] array, int start, int count, T value)
return;
}

if (array?.Any() != true)
if ((array?.Length ?? 0) == 0)
{
return;
}
Expand Down
22 changes: 11 additions & 11 deletions Engine.PathFinding.RecastNavigation/ChunkyTriMesh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ class SubdivideData
/// <summary>
/// Node list
/// </summary>
public List<ChunkyTriMeshNode> Nodes { get; set; } = new List<ChunkyTriMeshNode>();
public List<ChunkyTriMeshNode> Nodes { get; set; } = [];
/// <summary>
/// Indexed triangle list
/// </summary>
public List<int> OutTris { get; set; } = new List<int>();
public List<int> OutTris { get; set; } = [];
/// <summary>
/// Tirangles per chunk
/// </summary>
Expand Down Expand Up @@ -137,16 +137,16 @@ public static ChunkyTriMesh Build(IEnumerable<Triangle> triangles, int trisPerCh
{
MaxNodes = maxNodes,
TrisPerChunk = trisPerChunk,
Items = items.ToArray(),
Items = [.. items],
};

Subdivide(0, items.Count, data);

return new ChunkyTriMesh
{
triangles = triangles.ToArray(),
nodes = data.Nodes.ToArray(),
triangleIndices = data.OutTris.ToArray()
nodes = [.. data.Nodes],
triangleIndices = [.. data.OutTris]
};
}
/// <summary>
Expand Down Expand Up @@ -269,7 +269,7 @@ private static RectangleF CalcExtends(BoundsItem[] items, int imin, int imax)
/// <returns>Returns the triangle list</returns>
public Triangle[] GetTriangles()
{
return triangles?.ToArray() ?? Array.Empty<Triangle>();
return triangles?.ToArray() ?? [];
}
/// <summary>
/// Gets the triangles in the specified node
Expand All @@ -289,13 +289,13 @@ public Triangle[] GetTriangles(ChunkyTriMeshNode node)
{
if (node.Index < 0)
{
return Array.Empty<Triangle>();
return [];
}

var tris = GetTriangles();
if (!tris.Any())
if (tris.Length == 0)
{
return Array.Empty<Triangle>();
return [];
}

var indices = triangleIndices.Skip(node.Index).Take(node.Count);
Expand All @@ -307,7 +307,7 @@ public Triangle[] GetTriangles(ChunkyTriMeshNode node)
res.Add(tris[index]);
}

return res.ToArray();
return [.. res];
}

/// <summary>
Expand Down Expand Up @@ -344,7 +344,7 @@ public int[] GetChunksOverlappingRect(Vector2 bmin, Vector2 bmax)
}
}

return ids.ToArray();
return [.. ids];
}
}
}
23 changes: 10 additions & 13 deletions Engine.PathFinding.RecastNavigation/Detour/NavMeshQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1160,7 +1160,7 @@ public Status FinalizeSlicedFindPathPartial(int maxPath, int[] existing, out Sim
{
path = null;

if (existing?.Any() != true || maxPath <= 0)
if ((existing?.Length ?? 0) == 0 || maxPath <= 0)
{
return Status.DT_FAILURE | Status.DT_INVALID_PARAM;
}
Expand Down Expand Up @@ -1308,7 +1308,7 @@ private int[] StorePath(Node node, int maxPath)
}
while (node != null);

return pathList.ToArray();
return [.. pathList];
}
/// <summary>
/// Builds the node partial path from node to next
Expand Down Expand Up @@ -1358,7 +1358,7 @@ private Status BuildNodePath(Node node, Node next, int maxPath, out int[] partia
}
}

partialPath = pathList.ToArray();
partialPath = [.. pathList];

return status;
}
Expand Down Expand Up @@ -2022,7 +2022,7 @@ public Status MoveAlongSurface(int startRef, Vector3 startPos, Vector3 endPos, Q
var verts = cur.Tile.GetPolyVerts(cur.Poly);

// If target is inside the poly, stop search.
if (Utils.PointInPolygon2D(endPos, verts.ToArray()))
if (Utils.PointInPolygon2D(endPos, verts))
{
bestNode = curNode;
bestPos = endPos;
Expand Down Expand Up @@ -2656,9 +2656,9 @@ private Status ProcessLinksNeighbourFindDistance(Link link, TileRef best, Vector
/// <returns>The status flags for the query.</returns>
public Status GetPolyWallSegments(int r, QueryFilter filter, int maxSegments, out Segment[] segmentsRes)
{
segmentsRes = Array.Empty<Segment>();
segmentsRes = [];

var segments = new List<Segment>();
List<Segment> segments = [];

var cur = m_nav.GetTileAndPolyByRef(r);
if (cur.Ref == 0)
Expand Down Expand Up @@ -2787,7 +2787,7 @@ public Status GetPolyWallSegments(int r, QueryFilter filter, int maxSegments, ou
}
}

segmentsRes = segments.ToArray();
segmentsRes = [.. segments];

return status;
}
Expand Down Expand Up @@ -3572,10 +3572,7 @@ private bool CalcPathFollow(
ClosestPointOnPoly(startRef, startPos, out Vector3 iterPos, out _);
ClosestPointOnPoly(iterPath.End, endPos, out Vector3 targetPos, out _);

var smoothPath = new List<Vector3>
{
iterPos
};
List<Vector3> smoothPath = [iterPos];

// Move towards target a small advancement at a time until target reached or
// when ran out of memory to store the path.
Expand All @@ -3588,7 +3585,7 @@ private bool CalcPathFollow(
}
}

resultPath = smoothPath.ToArray();
resultPath = smoothPath;

return smoothPath.Count > 0;
}
Expand Down Expand Up @@ -3743,7 +3740,7 @@ private bool CalcPathStraigh(

if (polys.Count < 0)
{
resultPath = Array.Empty<Vector3>();
resultPath = [];

return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using SharpDX;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Engine.PathFinding.RecastNavigation.Detour.Tiles
{
Expand Down Expand Up @@ -48,9 +47,9 @@ public static TileCacheData[] RasterizeTileLayers(int x, int y, InputGeometry ge
var tbmax = new Vector2(cfg.BoundingBox.Maximum.X, cfg.BoundingBox.Maximum.Z);

var cid = chunkyMesh.GetChunksOverlappingRect(tbmin, tbmax);
if (!cid.Any())
if (cid.Length == 0)
{
return Array.Empty<TileCacheData>(); // empty
return []; // empty
}

foreach (var id in cid)
Expand Down Expand Up @@ -88,7 +87,7 @@ public static TileCacheData[] RasterizeTileLayers(int x, int y, InputGeometry ge
tiles.Add(lset.Layers[i].Create(x, y, i));
}

return tiles.ToArray();
return [.. tiles];
}

/// <inheritdoc/>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using SharpDX;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Engine.PathFinding.RecastNavigation.Recast
{
Expand Down Expand Up @@ -355,7 +354,7 @@ private int[] AllocateRegionCell(int x, int y)
}
}

return lregs.ToArray();
return [.. lregs];
}
/// <summary>
/// Update overlapping regions.
Expand Down Expand Up @@ -406,7 +405,7 @@ private void Create2Dlayers()
stack.Clear();
stack.Add(i);

while (stack.Any())
while (stack.Count != 0)
{
// Pop front
var reg = Regions[stack.PopFirst()];
Expand Down
7 changes: 3 additions & 4 deletions Engine.PathFinding.RecastNavigation/Recast/PolyMesh.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using SharpDX;
using System;
using System.Collections.Generic;
using System.Linq;

namespace Engine.PathFinding.RecastNavigation.Recast
{
Expand Down Expand Up @@ -273,7 +272,7 @@ public static PolyMesh Build(ContourSet cset, int nvp)
/// <returns>Returns the new polygon mesh</returns>
public static PolyMesh Merge(PolyMesh[] meshes, ContourSet cset)
{
if (!meshes.Any())
if (meshes.Length == 0)
{
return null;
}
Expand Down Expand Up @@ -369,7 +368,7 @@ private static (int MaxVerts, int MaxPolys, int MaxVersPerMesh) UpdateBounds(Pol
/// <param name="p">Indexed polygon</param>
public Vector3[] BuildPolyVertices(IndexedPolygon p)
{
var res = new List<Vector3>();
List<Vector3> res = [];

float cs = CellSize;
float ch = CellHeight;
Expand All @@ -387,7 +386,7 @@ public Vector3[] BuildPolyVertices(IndexedPolygon p)
res.Add(pv);
}

return res.ToArray();
return [.. res];
}
/// <summary>
/// Finds polygon bounds
Expand Down
27 changes: 11 additions & 16 deletions Engine.Physics/Simulator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ namespace Engine.Physics
/// <summary>
/// Simulator
/// </summary>
public sealed class Simulator
/// <remarks>
/// Constructor
/// </remarks>
public sealed class Simulator(BoundingBox worldBounds, int itemsPerNode)
{
/// <summary>
/// Maximum iterations in the update pass
Expand All @@ -23,27 +26,27 @@ public sealed class Simulator
/// <summary>
/// Physics object list
/// </summary>
private readonly List<IPhysicsObject> physicsObjects = new();
private readonly List<IPhysicsObject> physicsObjects = [];
/// <summary>
/// Global force generator list
/// </summary>
private readonly List<IGlobalForceGenerator> globalForceGenerators = new();
private readonly List<IGlobalForceGenerator> globalForceGenerators = [];
/// <summary>
/// Local force generator list
/// </summary>
private readonly List<ILocalForceGenerator> localForceGenerators = new();
private readonly List<ILocalForceGenerator> localForceGenerators = [];
/// <summary>
/// Contact generator list
/// </summary>
private readonly List<IContactGenerator> contactGenerators = new();
private readonly List<IContactGenerator> contactGenerators = [];
/// <summary>
/// Space partitioning OcTree
/// </summary>
private readonly OcTree<IPhysicsObject> octree;
private readonly OcTree<IPhysicsObject> octree = new(worldBounds, itemsPerNode);
/// <summary>
/// Broad phase contact pair list
/// </summary>
private readonly List<ContactPair> contactPairs = new();
private readonly List<ContactPair> contactPairs = [];

/// <summary>
/// Simulation velocity
Expand Down Expand Up @@ -71,14 +74,6 @@ public sealed class Simulator
/// </summary>
public int ContactGeneratorsCount { get => contactGenerators?.Count ?? 0; }

/// <summary>
/// Constructor
/// </summary>
public Simulator(BoundingBox worldBounds, int itemsPerNode)
{
octree = new OcTree<IPhysicsObject>(worldBounds, itemsPerNode);
}

/// <summary>
/// Update physics
/// </summary>
Expand Down Expand Up @@ -257,7 +252,7 @@ private void AddPair(IPhysicsObject obj1, IPhysicsObject obj2)
/// </summary>
private void NarrowPhase()
{
if (!contactPairs.Any())
if (contactPairs.Count == 0)
{
return;
}
Expand Down
11 changes: 5 additions & 6 deletions Engine.Windows/WindowsFonts.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using Engine.UI;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Text;
Expand All @@ -19,12 +18,12 @@ public class WindowsFonts : IFonts
/// </summary>
/// <param name="fontFamily">Comma separated font family string</param>
/// <returns>Returns an array of families</returns>
private static IEnumerable<string> ParseFontFamilies(string fontFamily)
private static string[] ParseFontFamilies(string fontFamily)
{
string[] fonts = fontFamily.Split(",".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
if (!fonts.Any())
if (fonts.Length == 0)
{
return Enumerable.Empty<string>();
return [];
}

return fonts
Expand All @@ -51,7 +50,7 @@ private static FontMapDescription FromFamily(FontMapKeycodeGenerator generator,
FontName = family.Name,
FontSize = size,
FontStyle = style,
Map = new Dictionary<char, FontMapChar>(),
Map = [],
};

using (var bmp = new Bitmap(mapSize.Width, mapSize.Height))
Expand Down Expand Up @@ -206,7 +205,7 @@ public string FindFonts(string fontFamily)
}

var fonts = ParseFontFamilies(fontFamily);
if (!fonts.Any())
if (fonts.Length == 0)
{
return null;
}
Expand Down
Loading

0 comments on commit fd8c0fe

Please sign in to comment.