Avoid multiple AIs all issuing orders in exactly the same tick.
Randomize the initial tick used for each AI so they don't cause lag but all flooding the same tick with orders, but instead (try) and use a different tick for each AI. Order processing is expensive due to the need to sync world state, so it is best to spread out the performance cost of issuing these orders over different ticks.
This commit is contained in:
@@ -195,11 +195,25 @@ namespace OpenRA.Mods.Common.AI
|
|||||||
public Map Map { get { return World.Map; } }
|
public Map Map { get { return World.Map; } }
|
||||||
IBotInfo IBot.Info { get { return this.Info; } }
|
IBotInfo IBot.Info { get { return this.Info; } }
|
||||||
|
|
||||||
|
int rushTicks;
|
||||||
|
int assignRolesTicks;
|
||||||
|
int attackForceTicks;
|
||||||
|
int minAttackForceDelayTicks;
|
||||||
|
|
||||||
public HackyAI(HackyAIInfo info, ActorInitializer init)
|
public HackyAI(HackyAIInfo info, ActorInitializer init)
|
||||||
{
|
{
|
||||||
Info = info;
|
Info = info;
|
||||||
World = init.World;
|
World = init.World;
|
||||||
|
|
||||||
|
// Avoid all AIs trying to rush in the same tick, randomize their initial rush a little.
|
||||||
|
var smallFractionOfRushInterval = Info.RushInterval / 20;
|
||||||
|
rushTicks = World.SharedRandom.Next(Info.RushInterval - smallFractionOfRushInterval, Info.RushInterval + smallFractionOfRushInterval);
|
||||||
|
|
||||||
|
// Avoid all AIs reevaluating assignments on the same tick, randomize their initial evaluation delay.
|
||||||
|
assignRolesTicks = World.SharedRandom.Next(0, Info.AssignRolesInterval);
|
||||||
|
attackForceTicks = World.SharedRandom.Next(0, Info.AttackForceInterval);
|
||||||
|
minAttackForceDelayTicks = World.SharedRandom.Next(0, Info.MinimumAttackForceDelay);
|
||||||
|
|
||||||
foreach (var decision in info.PowerDecisions)
|
foreach (var decision in info.PowerDecisions)
|
||||||
powerDecisions.Add(decision.OrderName, decision);
|
powerDecisions.Add(decision.OrderName, decision);
|
||||||
}
|
}
|
||||||
@@ -520,11 +534,6 @@ namespace OpenRA.Mods.Common.AI
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int assignRolesTicks = 0;
|
|
||||||
int rushTicks = 0;
|
|
||||||
int attackForceTicks = 0;
|
|
||||||
int minAttackForceDelayTicks = 0;
|
|
||||||
|
|
||||||
void AssignRolesToIdleUnits(Actor self)
|
void AssignRolesToIdleUnits(Actor self)
|
||||||
{
|
{
|
||||||
CleanSquads();
|
CleanSquads();
|
||||||
|
|||||||
Reference in New Issue
Block a user