Change GetCustomMovementLayers to expose an array, not a dictionary.

As there are few custom movement layers, using an array is good for improving lookup speed. Additionally, we can simplify some code by reserving index 0 of the array for the ground layer. Code that needs to maintain a state for the ground layer and every custom movement layer can now maintain a flat array of state using index 0 for the ground layer, and the the ICustomMovementLayer.Index for the custom movement layer. This removes a lot of ternary statements checking for the ground layer special case.
This commit is contained in:
RoosterDragon
2021-10-08 21:11:14 +01:00
committed by Paul Chote
parent 3310f14dea
commit dd9d600ef9
4 changed files with 105 additions and 86 deletions

View File

@@ -428,10 +428,8 @@ namespace OpenRA.Mods.Common.Traits
if (ToCell.Layer == 0)
return true;
if (self.World.GetCustomMovementLayers().TryGetValue(ToCell.Layer, out var layer))
return layer.InteractsWithDefaultLayer;
return true;
var layer = self.World.GetCustomMovementLayers()[ToCell.Layer];
return layer == null || layer.InteractsWithDefaultLayer;
}
#endregion
@@ -862,9 +860,7 @@ namespace OpenRA.Mods.Common.Traits
return;
}
var cml = self.World.WorldActor.TraitsImplementing<ICustomMovementLayer>()
.First(l => l.Index == self.Location.Layer);
var cml = self.World.GetCustomMovementLayers()[self.Location.Layer];
if (!cml.ReturnToGroundLayerOnIdle)
return;