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:
committed by
Paul Chote
parent
3310f14dea
commit
dd9d600ef9
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user