Use 'new' expression in places where the type is evident for content (#2590)

* Content.Client

* Content.Benchmarks

* Content.IntegrationTests

* Content.Server

* Content.Server.Database

* Content.Shared

* Content.Tests

* Merge fixes

Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
This commit is contained in:
DrSmugleaf
2020-11-27 11:00:49 +01:00
committed by GitHub
parent 4a56df749b
commit 5c0cf1b1a0
235 changed files with 431 additions and 433 deletions

View File

@@ -24,7 +24,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI
public Faction GetHostileFactions(Faction faction) => _hostileFactions.TryGetValue(faction, out var hostiles) ? hostiles : Faction.None;
private readonly Dictionary<Faction, Faction> _hostileFactions = new Dictionary<Faction, Faction>
private readonly Dictionary<Faction, Faction> _hostileFactions = new()
{
{Faction.NanoTransen,
Faction.SimpleHostile | Faction.Syndicate | Faction.Xeno},

View File

@@ -28,15 +28,15 @@ namespace Content.Server.GameObjects.EntitySystems.AI
[Dependency] private readonly IDynamicTypeFactory _typeFactory = default!;
[Dependency] private readonly IReflectionManager _reflectionManager = default!;
private readonly Dictionary<string, Type> _processorTypes = new Dictionary<string, Type>();
private readonly Dictionary<string, Type> _processorTypes = new();
/// <summary>
/// To avoid iterating over dead AI continuously they can wake and sleep themselves when necessary.
/// </summary>
private readonly HashSet<AiLogicProcessor> _awakeAi = new HashSet<AiLogicProcessor>();
private readonly HashSet<AiLogicProcessor> _awakeAi = new();
// To avoid modifying awakeAi while iterating over it.
private readonly List<SleepAiMessage> _queuedSleepMessages = new List<SleepAiMessage>();
private readonly List<SleepAiMessage> _queuedSleepMessages = new();
public bool IsAwake(AiLogicProcessor processor) => _awakeAi.Contains(processor);

View File

@@ -9,7 +9,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.LoadBalancer
/// </summary>
public class AiActionSystem : EntitySystem
{
private readonly AiActionJobQueue _aiRequestQueue = new AiActionJobQueue();
private readonly AiActionJobQueue _aiRequestQueue = new();
public AiActionRequestJob RequestAction(AiActionRequest request, CancellationTokenSource cancellationToken)
{

View File

@@ -45,7 +45,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
/// <summary>
/// Queued region updates
/// </summary>
private readonly HashSet<PathfindingChunk> _queuedUpdates = new HashSet<PathfindingChunk>();
private readonly HashSet<PathfindingChunk> _queuedUpdates = new();
// Oh god the nesting. Shouldn't need to go beyond this
/// <summary>
@@ -54,7 +54,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
/// i.e. same collision, not-space, same access, etc.
/// </summary>
private readonly Dictionary<GridId, Dictionary<PathfindingChunk, HashSet<PathfindingRegion>>> _regions =
new Dictionary<GridId, Dictionary<PathfindingChunk, HashSet<PathfindingRegion>>>();
new();
/// <summary>
/// Minimum time for the cached reachable regions to be stored
@@ -71,9 +71,9 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
// Also, didn't use a dictionary because there didn't seem to be a clean way to do the lookup
// Plus this way we can check if everything is equal except for vision so an entity with a lower vision radius can use an entity with a higher vision radius' cached result
private readonly Dictionary<ReachableArgs, Dictionary<PathfindingRegion, (TimeSpan CacheTime, HashSet<PathfindingRegion> Regions)>> _cachedAccessible =
new Dictionary<ReachableArgs, Dictionary<PathfindingRegion, (TimeSpan, HashSet<PathfindingRegion>)>>();
new();
private readonly List<PathfindingRegion> _queuedCacheDeletions = new List<PathfindingRegion>();
private readonly List<PathfindingRegion> _queuedCacheDeletions = new();
#if DEBUG
private int _runningCacheIdx = 0;

View File

@@ -27,7 +27,7 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Accessible
public int Width { get; private set; } = 1;
public PathfindingChunk ParentChunk => OriginNode.ParentChunk;
public HashSet<PathfindingRegion> Neighbors { get; } = new HashSet<PathfindingRegion>();
public HashSet<PathfindingRegion> Neighbors { get; } = new();
public bool IsDoor { get; }
public HashSet<PathfindingNode> Nodes => _nodes;

View File

@@ -22,17 +22,17 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
/// Whenever there's a change in the collision layers we update the mask as the graph has more reads than writes
/// </summary>
public int BlockedCollisionMask { get; private set; }
private readonly Dictionary<IEntity, int> _blockedCollidables = new Dictionary<IEntity, int>(0);
private readonly Dictionary<IEntity, int> _blockedCollidables = new(0);
public IReadOnlyDictionary<IEntity, int> PhysicsLayers => _physicsLayers;
private readonly Dictionary<IEntity, int> _physicsLayers = new Dictionary<IEntity, int>(0);
private readonly Dictionary<IEntity, int> _physicsLayers = new(0);
/// <summary>
/// The entities on this tile that require access to traverse
/// </summary>
/// We don't store the ICollection, at least for now, as we'd need to replicate the access code here
public IReadOnlyCollection<AccessReader> AccessReaders => _accessReaders.Values;
private readonly Dictionary<IEntity, AccessReader> _accessReaders = new Dictionary<IEntity, AccessReader>(0);
private readonly Dictionary<IEntity, AccessReader> _accessReaders = new(0);
public PathfindingNode(PathfindingChunk parent, TileRef tileRef)
{

View File

@@ -35,18 +35,18 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Pathfinding
[Dependency] private readonly IEntityManager _entityManager = default!;
public IReadOnlyDictionary<GridId, Dictionary<Vector2i, PathfindingChunk>> Graph => _graph;
private readonly Dictionary<GridId, Dictionary<Vector2i, PathfindingChunk>> _graph = new Dictionary<GridId, Dictionary<Vector2i, PathfindingChunk>>();
private readonly Dictionary<GridId, Dictionary<Vector2i, PathfindingChunk>> _graph = new();
private readonly PathfindingJobQueue _pathfindingQueue = new PathfindingJobQueue();
private readonly PathfindingJobQueue _pathfindingQueue = new();
// Queued pathfinding graph updates
private readonly Queue<CollisionChangeMessage> _collidableUpdateQueue = new Queue<CollisionChangeMessage>();
private readonly Queue<MoveEvent> _moveUpdateQueue = new Queue<MoveEvent>();
private readonly Queue<AccessReaderChangeMessage> _accessReaderUpdateQueue = new Queue<AccessReaderChangeMessage>();
private readonly Queue<TileRef> _tileUpdateQueue = new Queue<TileRef>();
private readonly Queue<CollisionChangeMessage> _collidableUpdateQueue = new();
private readonly Queue<MoveEvent> _moveUpdateQueue = new();
private readonly Queue<AccessReaderChangeMessage> _accessReaderUpdateQueue = new();
private readonly Queue<TileRef> _tileUpdateQueue = new();
// Need to store previously known entity positions for collidables for when they move
private readonly Dictionary<IEntity, PathfindingNode> _lastKnownPositions = new Dictionary<IEntity, PathfindingNode>();
private readonly Dictionary<IEntity, PathfindingNode> _lastKnownPositions = new();
public const int TrackedCollisionLayers = (int)
(CollisionGroup.Impassable |

View File

@@ -52,37 +52,37 @@ namespace Content.Server.GameObjects.EntitySystems.AI.Steering
// agent's steering. Should help a lot given this is the most expensive operator by far.
// The AI will keep moving, it's just it'll keep moving in its existing direction.
// If we change to 20/30 TPS you might want to change this but for now it's fine
private readonly List<Dictionary<IEntity, IAiSteeringRequest>> _agentLists = new List<Dictionary<IEntity, IAiSteeringRequest>>(AgentListCount);
private readonly List<Dictionary<IEntity, IAiSteeringRequest>> _agentLists = new(AgentListCount);
private const int AgentListCount = 2;
private int _listIndex;
// Cache nextGrid
private readonly Dictionary<IEntity, EntityCoordinates> _nextGrid = new Dictionary<IEntity, EntityCoordinates>();
private readonly Dictionary<IEntity, EntityCoordinates> _nextGrid = new();
/// <summary>
/// Current live paths for AI
/// </summary>
private readonly Dictionary<IEntity, Queue<TileRef>> _paths = new Dictionary<IEntity, Queue<TileRef>>();
private readonly Dictionary<IEntity, Queue<TileRef>> _paths = new();
/// <summary>
/// Pathfinding request jobs we're waiting on
/// </summary>
private readonly Dictionary<IEntity, (CancellationTokenSource CancelToken, Job<Queue<TileRef>> Job)> _pathfindingRequests =
new Dictionary<IEntity, (CancellationTokenSource, Job<Queue<TileRef>>)>();
new();
/// <summary>
/// Keep track of how long we've been in 1 position and re-path if it's been too long
/// </summary>
private readonly Dictionary<IEntity, int> _stuckCounter = new Dictionary<IEntity, int>();
private readonly Dictionary<IEntity, int> _stuckCounter = new();
/// <summary>
/// Get a fixed position for the target entity; if they move then re-path
/// </summary>
private readonly Dictionary<IEntity, EntityCoordinates> _entityTargetPosition = new Dictionary<IEntity, EntityCoordinates>();
private readonly Dictionary<IEntity, EntityCoordinates> _entityTargetPosition = new();
// Anti-Stuck
// Given the collision avoidance can lead to twitching need to store a reference position and check if we've been near this too long
private readonly Dictionary<IEntity, EntityCoordinates> _stuckPositions = new Dictionary<IEntity, EntityCoordinates>();
private readonly Dictionary<IEntity, EntityCoordinates> _stuckPositions = new();
public override void Initialize()
{