Skip to main content

AgentUpdater

A class in Root.Township, Alta.Intelligence.

Server: the scene singleton that ticks every creature. Each fixed update it raises each creature's priority by how close the nearest player is, re-sorts, and lets the top few decide again.

Constructors​

MemberWhat it is
AgentUpdater()Unity makes components itself; use AddComponent or spawn a prefab instead of new.

Fields​

10 private and internal fields
MemberWhat it is
private LinkedList<ILinkedAgent> agentsAll registered creatures, ordered by priority, highest first.
private float furthestDistanceSquaredSquared distance past which players add no extra priority. Default 10000 (100 m).
private static Logger loggerClass logger, used for per-creature errors and PrintAll.
private int maxExtramaxPriorityIncrement minus minPriorityIncrement, recomputed each tick.
private int maxPriorityIncrementMost priority a creature can gain in one tick, with a player right next to it. Default 100.
private int minPriorityIncrementPriority every creature gains each tick. Default 1.
private static Stopwatch timerStopwatch used for the two timing averages.
private static UpdateModule updateAgentsThe "AI Agent Updater" fixed update module, included in server profiling.
private IUnityUpdateMethod updateAgentsMethodThe registered UpdateAgents call.
private int updateCountHow many creatures get to decide again each tick. Default 5.

Properties​

MemberWhat it is
static int AgentCount { get; }Number of creatures registered.
static AgentUpdater Instance { get; private set; }The scene's updater, set in Awake.
static AverageNumber SortingAgentsTimeMs { get; }Running average of the time spent updating priorities and sorting each tick.
int TopPriority { get; }Priority of the first creature in the list, or 1 if there are none.
static AverageNumber UpdatingAgentsTimeMs { get; }Running average of the time spent deciding and updating creatures each tick.

Methods​

MemberWhat it is
void Deregister(ILinkedAgent agent)Removes a creature from the list. Warns if it wasn't registered.
static void PrintAll()The agents print console command: logs each creature and its priority at trace level, then the total.
void Register(ILinkedAgent agent)Adds a creature at the end of the list with priority 0 and runs its first decision and update. Errors if already registered.
7 private and internal methods
MemberWhat it is
private void Awake()Sets Instance, initializes all senses and starts updating once the server has started.
private void OnDestroy()Unhooks the server start event and stops updating.
private void OnServerStarted()Registers UpdateAgents on the fixed update module.
private void Sort(ILinkedAgent agent)Moves a creature forward in the list past every creature with a lower priority.
private void UpdateAgents()The fixed update: caches player head positions, drops destroyed creatures, raises priorities, sorts, then runs UpdateAndMoveToEnd.
private void UpdateAndMoveToEnd()Lets the first updateCount creatures decide again (more if some didn't change), resets them to priority 0 and moves them to the end. Updates every creature.
private void UpdatePriority(ILinkedAgent agent)Adds minPriorityIncrement plus up to maxExtra more the closer the nearest player is, within furthestDistanceSquared.