From 375eb90a880c0ccb49936b90d0d7101806ced948 Mon Sep 17 00:00:00 2001 From: Chris Forbes Date: Wed, 4 May 2011 22:53:20 +1200 Subject: [PATCH] fix perf of HackyAI AssignRoles, to some extent --- OpenRA.Mods.RA/HackyAI.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/OpenRA.Mods.RA/HackyAI.cs b/OpenRA.Mods.RA/HackyAI.cs index c65ffcd6c4..8966238955 100644 --- a/OpenRA.Mods.RA/HackyAI.cs +++ b/OpenRA.Mods.RA/HackyAI.cs @@ -64,6 +64,9 @@ namespace OpenRA.Mods.RA ret.Add(t.Key, (float)FieldLoader.GetValue("units", typeof(float), t.Value.Value)); return ret; } + + [FieldLoader.Load] + public readonly int AssignRolesInterval = 20; public object Create(ActorInitializer init) { return new HackyAI(this); } } @@ -266,6 +269,8 @@ namespace OpenRA.Mods.RA return possibleTargets.Any() ? possibleTargets.Random(random) : (int2?)null; } + + int assignRolesTicks = 0; void AssignRolesToIdleUnits(Actor self) { @@ -274,6 +279,11 @@ namespace OpenRA.Mods.RA activeUnits.RemoveAll(a => a.Destroyed); unitsHangingAroundTheBase.RemoveAll(a => a.Destroyed); attackForce.RemoveAll(a => a.Destroyed); + + if (--assignRolesTicks > 0) + return; + else + assignRolesTicks = Info.AssignRolesInterval; // don't select harvesters. var newUnits = self.World.ActorsWithTrait()