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.
- Listed in Creatures and AI
- Inherits or implements
MonoBehaviour - Attributes
Module - Documented in AgentUpdater, Update modules
Constructors
| Member | What it is |
|---|---|
AgentUpdater() | Unity makes components itself; use AddComponent or spawn a prefab instead of new. |
Fields
10 private and internal fields
| Member | What it is |
|---|---|
private LinkedList<ILinkedAgent> agents | All registered creatures, ordered by priority, highest first. |
private float furthestDistanceSquared | Squared distance past which players add no extra priority. Default 10000 (100 m). |
private static Logger logger | Class logger, used for per-creature errors and PrintAll. |
private int maxExtra | maxPriorityIncrement minus minPriorityIncrement, recomputed each tick. |
private int maxPriorityIncrement | Most priority a creature can gain in one tick, with a player right next to it. Default 100. |
private int minPriorityIncrement | Priority every creature gains each tick. Default 1. |
private static Stopwatch timer | Stopwatch used for the two timing averages. |
private static UpdateModule updateAgents | The "AI Agent Updater" fixed update module, included in server profiling. |
private IUnityUpdateMethod updateAgentsMethod | The registered UpdateAgents call. |
private int updateCount | How many creatures get to decide again each tick. Default 5. |
Properties
| Member | What 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
| Member | What 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
| Member | What 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. |