-
-
Notifications
You must be signed in to change notification settings - Fork 4
Feature: AI Task Scan Throttle
This feature controls how often AI scans for new tasks under load while still processing running tasks each tick.
AiRuntimeConfig adds a dynamic scan interval:
public static float TaskScanIntervalSeconds = BaseTaskScanIntervalSeconds;
private const float BaseTaskScanIntervalSeconds = 0.2f;
private const float HighPlayerTaskScanIntervalSeconds = 0.3f;
private const float OverloadedTaskScanIntervalSeconds = 0.4f;
private const int HighPlayerThreshold = 150;
private const int OverloadedPlayerThreshold = 250;Updated every 250ms based on online player count:
int onlinePlayerCount = serverApi?.World.AllOnlinePlayers.Length ?? 0;
TaskScanIntervalSeconds = onlinePlayerCount >= OverloadedPlayerThreshold
? OverloadedTaskScanIntervalSeconds
: onlinePlayerCount >= HighPlayerThreshold
? HighPlayerTaskScanIntervalSeconds
: BaseTaskScanIntervalSeconds;AiTaskManager.OnGameTick accumulates delta and only runs StartNewTasks() when the interval is reached.
startTaskAccum += dt;
if (startTaskAccum >= startTaskIntervalSeconds)
{
startTaskAccum -= startTaskIntervalSeconds;
...
StartNewTasks();
}
ProcessRunningTasks(dt);Running tasks still continue each tick; the throttle is specifically on new-task scanning.
The patch also records timings for task scan and task continue paths through StratumEntityBehaviorTimings.
patches/VSEssentials/Entity/AI/AiTaskManager.cs.patch-
VSEssentials/Entity/AI/AiTaskManager.csinterval:
public static float TaskScanIntervalSeconds = BaseTaskScanIntervalSeconds;
private const float BaseTaskScanIntervalSeconds = 0.2f;
private const float HighPlayerTaskScanIntervalSeconds = 0.3f;
private const float OverloadedTaskScanIntervalSeconds = 0.4f;
private const int HighPlayerThreshold = 150;
private const int OverloadedPlayerThreshold = 250;Updated every 250ms based on online player count:
int onlinePlayerCount = serverApi?.World.AllOnlinePlayers.Length ?? 0;
TaskScanIntervalSeconds = onlinePlayerCount >= OverloadedPlayerThreshold
? OverloadedTaskScanIntervalSeconds
: onlinePlayerCount >= HighPlayerThreshold
? HighPlayerTaskScanIntervalSeconds
: BaseTaskScanIntervalSeconds;AiTaskManager.OnGameTick accumulates delta and only runs StartNewTasks() when the interval is reached.
startTaskAccum += dt;
if (startTaskAccum >= startTaskIntervalSeconds)
{
startTaskAccum -= startTaskIntervalSeconds;
...
StartNewTasks();
}
ProcessRunningTasks(dt);Running tasks still continue each tick; the throttle is specifically on new-task scanning.
The patch also records timings for task scan and task continue paths through StratumEntityBehaviorTimings.
patches/VSEssentials/Entity/AI/AiTaskManager.cs.patchVSEssentials/Entity/AI/AiTaskManager.cs