Avoid unnecessary lookups in the production logic
by improving the GetBuildTime method and moving lookups around.
This commit is contained in:
@@ -125,14 +125,19 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (bi == null)
|
if (bi == null)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
return GetBuildTime(ai);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetBuildTime(ActorInfo unit)
|
||||||
|
{
|
||||||
if (self.World.AllowDevCommands && self.Owner.PlayerActor.Trait<DeveloperMode>().FastBuild)
|
if (self.World.AllowDevCommands && self.Owner.PlayerActor.Trait<DeveloperMode>().FastBuild)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
var time = (int)(ai.GetBuildTime() * Info.BuildSpeed);
|
var time = (int)(unit.GetBuildTime() * Info.BuildSpeed);
|
||||||
|
|
||||||
if (info.SpeedUp)
|
if (info.SpeedUp)
|
||||||
{
|
{
|
||||||
var type = bi.BuildAtProductionType ?? info.Type;
|
var type = unit.TraitInfo<BuildableInfo>().BuildAtProductionType ?? info.Type;
|
||||||
|
|
||||||
var selfsameProductionsCount = self.World.ActorsWithTrait<Production>()
|
var selfsameProductionsCount = self.World.ActorsWithTrait<Production>()
|
||||||
.Count(p => p.Actor.Owner == self.Owner && p.Trait.Info.Produces.Contains(type));
|
.Count(p => p.Actor.Owner == self.Owner && p.Trait.Info.Produces.Contains(type));
|
||||||
|
|||||||
@@ -256,9 +256,6 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (!bi.Queue.Contains(Info.Type))
|
if (!bi.Queue.Contains(Info.Type))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var cost = unit.HasTraitInfo<ValuedInfo>() ? unit.TraitInfo<ValuedInfo>().Cost : 0;
|
|
||||||
var time = GetBuildTime(order.TargetString);
|
|
||||||
|
|
||||||
// You can't build that
|
// You can't build that
|
||||||
if (BuildableItems().All(b => b.Name != order.TargetString))
|
if (BuildableItems().All(b => b.Name != order.TargetString))
|
||||||
return;
|
return;
|
||||||
@@ -275,6 +272,9 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var valued = unit.TraitInfoOrDefault<ValuedInfo>();
|
||||||
|
var cost = valued != null ? valued.Cost : 0;
|
||||||
|
var time = GetBuildTime(unit);
|
||||||
var amountToBuild = Math.Min(fromLimit, order.ExtraData);
|
var amountToBuild = Math.Min(fromLimit, order.ExtraData);
|
||||||
for (var n = 0; n < amountToBuild; n++)
|
for (var n = 0; n < amountToBuild; n++)
|
||||||
{
|
{
|
||||||
@@ -313,11 +313,15 @@ namespace OpenRA.Mods.Common.Traits
|
|||||||
if (unit == null || !unit.HasTraitInfo<BuildableInfo>())
|
if (unit == null || !unit.HasTraitInfo<BuildableInfo>())
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
return GetBuildTime(unit);
|
||||||
|
}
|
||||||
|
|
||||||
|
public virtual int GetBuildTime(ActorInfo unit)
|
||||||
|
{
|
||||||
if (self.World.AllowDevCommands && self.Owner.PlayerActor.Trait<DeveloperMode>().FastBuild)
|
if (self.World.AllowDevCommands && self.Owner.PlayerActor.Trait<DeveloperMode>().FastBuild)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
var time = unit.GetBuildTime() * Info.BuildSpeed;
|
var time = unit.GetBuildTime() * Info.BuildSpeed;
|
||||||
|
|
||||||
return (int)time;
|
return (int)time;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,7 +81,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
|||||||
powerIcon.IsVisible = () => power != 0;
|
powerIcon.IsVisible = () => power != 0;
|
||||||
|
|
||||||
var lowpower = pm.PowerState != PowerState.Normal;
|
var lowpower = pm.PowerState != PowerState.Normal;
|
||||||
var time = palette.CurrentQueue == null ? 0 : palette.CurrentQueue.GetBuildTime(actor.Name)
|
var time = palette.CurrentQueue == null ? 0 : palette.CurrentQueue.GetBuildTime(actor)
|
||||||
* (lowpower ? palette.CurrentQueue.Info.LowPowerSlowdown : 1);
|
* (lowpower ? palette.CurrentQueue.Info.LowPowerSlowdown : 1);
|
||||||
var timeString = WidgetUtils.FormatTime(time, world.Timestep);
|
var timeString = WidgetUtils.FormatTime(time, world.Timestep);
|
||||||
timeLabel.GetText = () => timeString;
|
timeLabel.GetText = () => timeString;
|
||||||
|
|||||||
Reference in New Issue
Block a user