Skip to content

Commit

Permalink
Fetch actors directly in DropPodsPower.
Browse files Browse the repository at this point in the history
Use direct dictionary lookups, rather than iterating the entire actors dictionary.
  • Loading branch information
RoosterDragon authored and PunkPun committed Mar 9, 2024
1 parent 6e89bef commit 00a23e6
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions OpenRA.Mods.Cnc/Traits/SupportPowers/DropPodsPower.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,22 @@ public DropPodsPower(Actor self, DropPodsPowerInfo info)
this.info = info;

unitTypes = info.UnitTypes.Select(unit => unit.ToLowerInvariant()).ToArray();
foreach (var actorInfo in self.World.Map.Rules.Actors.Where(a => unitTypes.Contains(a.Key)))

foreach (var unitType in unitTypes)
{
var aircraftInfo = actorInfo.Value.TraitInfo<AircraftInfo>();
if (!self.World.Map.Rules.Actors.TryGetValue(unitType, out var actorInfo))
throw new NotImplementedException("No rules definition for unit " + unitType);

var aircraftInfo = actorInfo.TraitInfo<AircraftInfo>();
var altitude = aircraftInfo.CruiseAltitude.Length;

var delta =
new WVec(0, -altitude * aircraftInfo.Speed / actorInfo.Value.TraitInfo<FallsToEarthInfo>().Velocity.Length, 0)
new WVec(0, -altitude * aircraftInfo.Speed / actorInfo.TraitInfo<FallsToEarthInfo>().Velocity.Length, 0)
.Rotate(WRot.FromYaw(info.PodFacing));

// PERF: Cache constant values.
getLaunchLocation[actorInfo.Key] = pos => self.World.Map.CenterOfCell(pos) - delta + new WVec(0, 0, altitude);
landableTerrainTypes[actorInfo.Key] = aircraftInfo.LandableTerrainTypes;
getLaunchLocation[unitType] = pos => self.World.Map.CenterOfCell(pos) - delta + new WVec(0, 0, altitude);
landableTerrainTypes[unitType] = aircraftInfo.LandableTerrainTypes;
}
}

Expand Down

0 comments on commit 00a23e6

Please sign in to comment.