diff --git a/OpenRA.Game/Graphics/HardwarePalette.cs b/OpenRA.Game/Graphics/HardwarePalette.cs index 7032261f39..14549ce694 100644 --- a/OpenRA.Game/Graphics/HardwarePalette.cs +++ b/OpenRA.Game/Graphics/HardwarePalette.cs @@ -24,8 +24,8 @@ namespace OpenRA.Graphics readonly Dictionary palettes = new Dictionary(); readonly Dictionary mutablePalettes = new Dictionary(); readonly Dictionary indices = new Dictionary(); - byte[] buffer = new byte[0]; - float[] colorShiftBuffer = new float[0]; + byte[] buffer = Array.Empty(); + float[] colorShiftBuffer = Array.Empty(); public HardwarePalette() { diff --git a/OpenRA.Game/Graphics/SpriteRenderable.cs b/OpenRA.Game/Graphics/SpriteRenderable.cs index fb9b86514f..54c7de6c25 100644 --- a/OpenRA.Game/Graphics/SpriteRenderable.cs +++ b/OpenRA.Game/Graphics/SpriteRenderable.cs @@ -9,6 +9,7 @@ */ #endregion +using System; using System.Collections.Generic; using OpenRA.Primitives; @@ -16,7 +17,7 @@ namespace OpenRA.Graphics { public class SpriteRenderable : IPalettedRenderable, IModifyableRenderable, IFinalizedRenderable { - public static readonly IEnumerable None = new IRenderable[0]; + public static readonly IEnumerable None = Array.Empty(); readonly Sprite sprite; readonly WPos pos; diff --git a/OpenRA.Game/Map/MapPreview.cs b/OpenRA.Game/Map/MapPreview.cs index 9ffc9a6dab..38c99e78b7 100644 --- a/OpenRA.Game/Map/MapPreview.cs +++ b/OpenRA.Game/Map/MapPreview.cs @@ -370,11 +370,11 @@ namespace OpenRA newData.SpawnPoints = spawns.ToArray(); } else - newData.SpawnPoints = new CPos[0]; + newData.SpawnPoints = Array.Empty(); } catch (Exception) { - newData.SpawnPoints = new CPos[0]; + newData.SpawnPoints = Array.Empty(); newData.Status = MapStatus.Unavailable; } diff --git a/OpenRA.Game/Primitives/TypeDictionary.cs b/OpenRA.Game/Primitives/TypeDictionary.cs index 8292b2eca3..7893d596c6 100644 --- a/OpenRA.Game/Primitives/TypeDictionary.cs +++ b/OpenRA.Game/Primitives/TypeDictionary.cs @@ -77,7 +77,7 @@ namespace OpenRA.Primitives { if (data.TryGetValue(typeof(T), out var objs)) return objs.Cast(); - return new T[0]; + return Array.Empty(); } public void Remove(T val) diff --git a/OpenRA.Game/Scripting/ScriptContext.cs b/OpenRA.Game/Scripting/ScriptContext.cs index 0ca88bbef2..f78a050b67 100644 --- a/OpenRA.Game/Scripting/ScriptContext.cs +++ b/OpenRA.Game/Scripting/ScriptContext.cs @@ -279,7 +279,7 @@ namespace OpenRA.Scripting return outer.SelectMany(i => i.GetGenericArguments()); } - static readonly object[] NoArguments = new object[0]; + static readonly object[] NoArguments = Array.Empty(); Type[] FilterActorCommands(ActorInfo ai) { return FilterCommands(ai, knownActorCommands); diff --git a/OpenRA.Game/StreamExts.cs b/OpenRA.Game/StreamExts.cs index 2a1ec12554..5b9aa0733f 100644 --- a/OpenRA.Game/StreamExts.cs +++ b/OpenRA.Game/StreamExts.cs @@ -229,7 +229,7 @@ namespace OpenRA if (!string.IsNullOrEmpty(text)) bytes = encoding.GetBytes(text); else - bytes = new byte[0]; + bytes = Array.Empty(); s.Write(bytes.Length); s.WriteArray(bytes); diff --git a/OpenRA.Game/Traits/Player/FrozenActorLayer.cs b/OpenRA.Game/Traits/Player/FrozenActorLayer.cs index 24fecae879..1fd5a13fca 100644 --- a/OpenRA.Game/Traits/Player/FrozenActorLayer.cs +++ b/OpenRA.Game/Traits/Player/FrozenActorLayer.cs @@ -72,8 +72,8 @@ namespace OpenRA.Traits public Polygon MouseBounds = Polygon.Empty; - static readonly IRenderable[] NoRenderables = new IRenderable[0]; - static readonly Rectangle[] NoBounds = new Rectangle[0]; + static readonly IRenderable[] NoRenderables = Array.Empty(); + static readonly Rectangle[] NoBounds = Array.Empty(); int flashTicks; TintModifiers flashModifiers; diff --git a/OpenRA.Game/Traits/World/ScreenMap.cs b/OpenRA.Game/Traits/World/ScreenMap.cs index 7221b1ee87..363fbd4898 100644 --- a/OpenRA.Game/Traits/World/ScreenMap.cs +++ b/OpenRA.Game/Traits/World/ScreenMap.cs @@ -41,7 +41,7 @@ namespace OpenRA.Traits public class ScreenMap : IWorldLoaded { - static readonly IEnumerable NoFrozenActors = new FrozenActor[0]; + static readonly IEnumerable NoFrozenActors = Array.Empty(); readonly Func frozenActorIsValid = fa => fa.IsValid; readonly Func actorIsInWorld = a => a.IsInWorld; readonly Func selectActorAndBounds; diff --git a/OpenRA.Game/World.cs b/OpenRA.Game/World.cs index 8b7d399a2b..6125a2197e 100644 --- a/OpenRA.Game/World.cs +++ b/OpenRA.Game/World.cs @@ -51,7 +51,7 @@ namespace OpenRA public LongBitSet AllPlayersMask = default(LongBitSet); public readonly LongBitSet NoPlayersMask = default(LongBitSet); - public Player[] Players = new Player[0]; + public Player[] Players = Array.Empty(); public event Action RenderPlayerChanged; diff --git a/OpenRA.Mods.Cnc/Graphics/TeslaZapRenderable.cs b/OpenRA.Mods.Cnc/Graphics/TeslaZapRenderable.cs index 556995d524..be41a054be 100644 --- a/OpenRA.Mods.Cnc/Graphics/TeslaZapRenderable.cs +++ b/OpenRA.Mods.Cnc/Graphics/TeslaZapRenderable.cs @@ -58,7 +58,7 @@ namespace OpenRA.Mods.Cnc.Graphics cachedPos = WPos.Zero; cachedLength = WVec.Zero; - cache = new IFinalizedRenderable[] { }; + cache = Array.Empty(); } public WPos Pos => pos; diff --git a/OpenRA.Mods.Cnc/SpriteLoaders/TmpRALoader.cs b/OpenRA.Mods.Cnc/SpriteLoaders/TmpRALoader.cs index 4b9629322e..225b694abd 100644 --- a/OpenRA.Mods.Cnc/SpriteLoaders/TmpRALoader.cs +++ b/OpenRA.Mods.Cnc/SpriteLoaders/TmpRALoader.cs @@ -9,6 +9,7 @@ */ #endregion +using System; using System.IO; using OpenRA.Graphics; using OpenRA.Primitives; @@ -32,7 +33,7 @@ namespace OpenRA.Mods.Cnc.SpriteLoaders Data = data; if (data == null) - Data = new byte[0]; + Data = Array.Empty(); else Size = size; } diff --git a/OpenRA.Mods.Cnc/SpriteLoaders/TmpTDLoader.cs b/OpenRA.Mods.Cnc/SpriteLoaders/TmpTDLoader.cs index e4be4befaa..0d842ab2ae 100644 --- a/OpenRA.Mods.Cnc/SpriteLoaders/TmpTDLoader.cs +++ b/OpenRA.Mods.Cnc/SpriteLoaders/TmpTDLoader.cs @@ -9,6 +9,7 @@ */ #endregion +using System; using System.IO; using OpenRA.Graphics; using OpenRA.Primitives; @@ -32,7 +33,7 @@ namespace OpenRA.Mods.Cnc.SpriteLoaders Data = data; if (data == null) - Data = new byte[0]; + Data = Array.Empty(); else Size = size; } diff --git a/OpenRA.Mods.Cnc/SpriteLoaders/TmpTSLoader.cs b/OpenRA.Mods.Cnc/SpriteLoaders/TmpTSLoader.cs index 7491449d5a..476562bb5d 100644 --- a/OpenRA.Mods.Cnc/SpriteLoaders/TmpTSLoader.cs +++ b/OpenRA.Mods.Cnc/SpriteLoaders/TmpTSLoader.cs @@ -9,6 +9,7 @@ */ #endregion +using System; using System.IO; using OpenRA.Graphics; using OpenRA.Primitives; @@ -109,7 +110,7 @@ namespace OpenRA.Mods.Cnc.SpriteLoaders } } else - Data = new byte[0]; + Data = Array.Empty(); } } diff --git a/OpenRA.Mods.Cnc/UtilityCommands/RemapShpCommand.cs b/OpenRA.Mods.Cnc/UtilityCommands/RemapShpCommand.cs index e3c16322c1..48c2b6b9fe 100644 --- a/OpenRA.Mods.Cnc/UtilityCommands/RemapShpCommand.cs +++ b/OpenRA.Mods.Cnc/UtilityCommands/RemapShpCommand.cs @@ -50,7 +50,7 @@ namespace OpenRA.Mods.Cnc.UtilityCommands Game.ModData = destModData; var destPaletteInfo = destModData.DefaultRules.Actors[SystemActors.Player].TraitInfo(); var destRemapIndex = destPaletteInfo.RemapIndex; - var shadowIndex = new int[] { }; + var shadowIndex = Array.Empty(); // the remap range is always 16 entries, but their location and order changes for (var i = 0; i < 16; i++) diff --git a/OpenRA.Mods.Common/Activities/Air/Land.cs b/OpenRA.Mods.Common/Activities/Air/Land.cs index 1fcf8fa24a..f7ea151885 100644 --- a/OpenRA.Mods.Common/Activities/Air/Land.cs +++ b/OpenRA.Mods.Common/Activities/Air/Land.cs @@ -54,7 +54,7 @@ namespace OpenRA.Mods.Common.Activities aircraft = self.Trait(); this.target = target; this.offset = offset; - this.clearCells = clearCells ?? new CPos[0]; + this.clearCells = clearCells ?? Array.Empty(); this.landRange = landRange.Length >= 0 ? landRange : aircraft.Info.LandRange; this.targetLineColor = targetLineColor; diff --git a/OpenRA.Mods.Common/Effects/SpawnActorEffect.cs b/OpenRA.Mods.Common/Effects/SpawnActorEffect.cs index cd591f0cde..fc27dee1b0 100644 --- a/OpenRA.Mods.Common/Effects/SpawnActorEffect.cs +++ b/OpenRA.Mods.Common/Effects/SpawnActorEffect.cs @@ -9,6 +9,7 @@ */ #endregion +using System; using System.Collections.Generic; using OpenRA.Activities; using OpenRA.Effects; @@ -26,10 +27,10 @@ namespace OpenRA.Mods.Common.Effects int remainingDelay; public SpawnActorEffect(Actor actor) - : this(actor, 0, new CPos[0], null) { } + : this(actor, 0, Array.Empty(), null) { } public SpawnActorEffect(Actor actor, int delay) - : this(actor, delay, new CPos[0], null) { } + : this(actor, delay, Array.Empty(), null) { } public SpawnActorEffect(Actor actor, int delay, CPos[] pathAfterSpawn, Activity activityAtDestination) { diff --git a/OpenRA.Mods.Common/SpriteLoaders/TgaLoader.cs b/OpenRA.Mods.Common/SpriteLoaders/TgaLoader.cs index bb24336961..c82c4c045b 100644 --- a/OpenRA.Mods.Common/SpriteLoaders/TgaLoader.cs +++ b/OpenRA.Mods.Common/SpriteLoaders/TgaLoader.cs @@ -9,6 +9,7 @@ */ #endregion +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -78,7 +79,7 @@ namespace OpenRA.Mods.Common.SpriteLoaders public TgaFrame() { - Data = new byte[0]; + Data = Array.Empty(); } public TgaFrame(Stream stream) diff --git a/OpenRA.Mods.Common/Traits/Buildings/LineBuild.cs b/OpenRA.Mods.Common/Traits/Buildings/LineBuild.cs index 852d1a3497..6633f365b7 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/LineBuild.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/LineBuild.cs @@ -9,6 +9,7 @@ */ #endregion +using System; using System.Collections.Generic; using System.Linq; using OpenRA.Traits; @@ -27,7 +28,7 @@ namespace OpenRA.Mods.Common.Traits readonly Actor[] parents = null; public LineBuildParentInit(Actor[] value) - : base(new string[0]) + : base(Array.Empty()) { parents = value; } @@ -70,7 +71,7 @@ namespace OpenRA.Mods.Common.Traits public class LineBuild : INotifyKilled, INotifyAddedToWorld, INotifyRemovedFromWorld, INotifyLineBuildSegmentsChanged { readonly LineBuildInfo info; - readonly Actor[] parentNodes = new Actor[0]; + readonly Actor[] parentNodes = Array.Empty(); HashSet segments; public LineBuild(ActorInitializer init, LineBuildInfo info) diff --git a/OpenRA.Mods.Common/Traits/Immobile.cs b/OpenRA.Mods.Common/Traits/Immobile.cs index cdf08d900b..51deab5489 100644 --- a/OpenRA.Mods.Common/Traits/Immobile.cs +++ b/OpenRA.Mods.Common/Traits/Immobile.cs @@ -9,6 +9,7 @@ */ #endregion +using System; using System.Collections.Generic; using OpenRA.Traits; @@ -46,7 +47,7 @@ namespace OpenRA.Mods.Common.Traits if (info.OccupiesSpace) occupied = new[] { (TopLeft, SubCell.FullCell) }; else - occupied = new (CPos, SubCell)[0]; + occupied = Array.Empty<(CPos, SubCell)>(); } public CPos TopLeft => location; diff --git a/OpenRA.Mods.Common/Traits/Targetable.cs b/OpenRA.Mods.Common/Traits/Targetable.cs index afef4a0efd..2980385d6f 100644 --- a/OpenRA.Mods.Common/Traits/Targetable.cs +++ b/OpenRA.Mods.Common/Traits/Targetable.cs @@ -9,6 +9,7 @@ */ #endregion +using System; using System.Linq; using OpenRA.Primitives; using OpenRA.Traits; @@ -29,7 +30,7 @@ namespace OpenRA.Mods.Common.Traits public class Targetable : ConditionalTrait, ITargetable { - protected static readonly string[] None = new string[] { }; + protected static readonly string[] None = Array.Empty(); protected Cloak[] cloaks; public Targetable(Actor self, TargetableInfo info) diff --git a/OpenRA.Mods.Common/UtilityCommands/ConvertSpriteToPngCommand.cs b/OpenRA.Mods.Common/UtilityCommands/ConvertSpriteToPngCommand.cs index e14e24ee3b..f80bbdc9d6 100644 --- a/OpenRA.Mods.Common/UtilityCommands/ConvertSpriteToPngCommand.cs +++ b/OpenRA.Mods.Common/UtilityCommands/ConvertSpriteToPngCommand.cs @@ -35,7 +35,7 @@ namespace OpenRA.Mods.Common.UtilityCommands var modData = Game.ModData = utility.ModData; var src = args[1]; - var shadowIndex = new int[] { }; + var shadowIndex = Array.Empty(); if (args.Contains("--noshadow")) { Array.Resize(ref shadowIndex, shadowIndex.Length + 3); diff --git a/OpenRA.Mods.Common/UtilityCommands/CreateManPage.cs b/OpenRA.Mods.Common/UtilityCommands/CreateManPage.cs index b963409e9e..a8d8be22e1 100644 --- a/OpenRA.Mods.Common/UtilityCommands/CreateManPage.cs +++ b/OpenRA.Mods.Common/UtilityCommands/CreateManPage.cs @@ -38,7 +38,7 @@ namespace OpenRA.Mods.Common.UtilityCommands Console.WriteLine(".SH OPTIONS"); var sections = Game.Settings.Sections; - sections.Add("Launch", new LaunchArguments(new Arguments(new string[0]))); + sections.Add("Launch", new LaunchArguments(new Arguments(Array.Empty()))); foreach (var section in sections.OrderBy(s => s.Key)) { var fields = section.Value.GetType().GetFields(); diff --git a/OpenRA.Mods.Common/UtilityCommands/DumpSequenceSheetsCommand.cs b/OpenRA.Mods.Common/UtilityCommands/DumpSequenceSheetsCommand.cs index ef159dea37..619f35d9bd 100644 --- a/OpenRA.Mods.Common/UtilityCommands/DumpSequenceSheetsCommand.cs +++ b/OpenRA.Mods.Common/UtilityCommands/DumpSequenceSheetsCommand.cs @@ -32,7 +32,7 @@ namespace OpenRA.Mods.Common.UtilityCommands // HACK: The engine code assumes that Game.modData is set. var modData = Game.ModData = utility.ModData; - var palette = new ImmutablePalette(args[1], new[] { 0 }, new int[0]); + var palette = new ImmutablePalette(args[1], new[] { 0 }, Array.Empty()); SequenceProvider sequences = null; var mapPackage = new Folder(Platform.EngineDir).OpenPackage(args[2], modData.ModFiles); diff --git a/OpenRA.Mods.Common/Warheads/FireClusterWarhead.cs b/OpenRA.Mods.Common/Warheads/FireClusterWarhead.cs index a6bc3aa83d..8e0dcda39a 100644 --- a/OpenRA.Mods.Common/Warheads/FireClusterWarhead.cs +++ b/OpenRA.Mods.Common/Warheads/FireClusterWarhead.cs @@ -9,6 +9,7 @@ */ #endregion +using System; using System.Collections.Generic; using System.Linq; using OpenRA.GameRules; @@ -80,8 +81,8 @@ namespace OpenRA.Mods.Common.Warheads CurrentMuzzleFacing = () => (map.CenterOfCell(targetCell) - target.CenterPosition).Yaw, DamageModifiers = args.DamageModifiers, - InaccuracyModifiers = new int[0], - RangeModifiers = new int[0], + InaccuracyModifiers = Array.Empty(), + RangeModifiers = Array.Empty(), Source = target.CenterPosition, CurrentSource = () => target.CenterPosition, diff --git a/OpenRA.Mods.Common/Widgets/ActorPreviewWidget.cs b/OpenRA.Mods.Common/Widgets/ActorPreviewWidget.cs index 434dbe62ef..d0a2597840 100644 --- a/OpenRA.Mods.Common/Widgets/ActorPreviewWidget.cs +++ b/OpenRA.Mods.Common/Widgets/ActorPreviewWidget.cs @@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Widgets readonly WorldRenderer worldRenderer; - IActorPreview[] preview = new IActorPreview[0]; + IActorPreview[] preview = Array.Empty(); public int2 PreviewOffset { get; private set; } public int2 IdealPreviewSize { get; private set; } diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/CommandBarLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/CommandBarLogic.cs index 800cbe77c7..791ed392f2 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/CommandBarLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/CommandBarLogic.cs @@ -39,7 +39,7 @@ namespace OpenRA.Mods.Common.Widgets int scatterHighlighted; int stopHighlighted; - TraitPair[] selectedDeploys = { }; + TraitPair[] selectedDeploys = Array.Empty>(); [ObjectCreator.UseCtor] public CommandBarLogic(Widget widget, World world, Dictionary logicArgs) diff --git a/OpenRA.Mods.Common/Widgets/Logic/Ingame/StanceSelectorLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Ingame/StanceSelectorLogic.cs index 0e2ef04a4a..a66ed0a758 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Ingame/StanceSelectorLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Ingame/StanceSelectorLogic.cs @@ -9,6 +9,7 @@ */ #endregion +using System; using System.Linq; using OpenRA.Mods.Common.Traits; using OpenRA.Widgets; @@ -20,7 +21,7 @@ namespace OpenRA.Mods.Common.Widgets readonly World world; int selectionHash; - TraitPair[] actorStances = { }; + TraitPair[] actorStances = Array.Empty>(); [ObjectCreator.UseCtor] public StanceSelectorLogic(Widget widget, World world) diff --git a/OpenRA.Utility/Program.cs b/OpenRA.Utility/Program.cs index 69f4c9b215..038c7247d9 100644 --- a/OpenRA.Utility/Program.cs +++ b/OpenRA.Utility/Program.cs @@ -68,7 +68,7 @@ namespace OpenRA if (args.Length == 0) { - PrintUsage(new InstalledMods(modSearchPaths, new string[0]), null); + PrintUsage(new InstalledMods(modSearchPaths, Array.Empty()), null); return; }