Contents

Games Should Be Fun

Process Manager

Process Peaking

The Process Manager

The Process Manager (PM) meets the requirements (a) to (d) identified above. It is implemented in C++ and runs on Sony Computer Entertainment's PlayStation2.

The PM is a simple operating system for game AI code. The PM allows users to specify an upper time limit for AI processing. If the limit is exceeded the PM attempts to alter the timing of processing to meet the upper limit. The PM provides a common execution framework for active and passive objects in games. When there is sufficient time in the current frame to complete all scheduled AI processing, the PM acts as a normal scheduler or "task system". But if there isn't sufficient time the PM starts to behave very differently from a normal scheduler and begins to employ the "egocentric" principle. Under high loads it maintains a constant AI time by postponing or avoiding the less "important" computational work, where "importance" can be defined by the user (e.g., more "important" if nearer the main camera).

This functionality is provided via several mechanisms:

  1. Specification of a global per-frame time limit for AI processing, the "AI time". (Requirement a)
  2. Allocation and control of available execution time between agents and AI behaviours according to user specified priorities, reducing the need for manual optimisation of AI code. (Requirement a)
  3. "Dynamic activation delay" of newly created agents to evenly distribute AI processing over frames. (Requirement a)
  4. Simple method invocation of the list of AI processes as defined by user. (Requirement b)
  5. Control of process execution frequency and frame-by-frame interleaving of agents and their constituent behaviours. (Requirement c)
  6. Control of execution order of agents and AI behaviours. (Requirement c)
  7. Time-slicing of AI processes. (Requirement d)

Together these mechanisms provide users with a high level of control over the time profile of their AI code, and also an ability to maintain a constant frame rate despite a variable AI load.

The PM assumes that each agent consists of the following, possibly empty, sets: perception sets, behavioursets, and action sets. Each perception set contains methods to translate game state into an internal agent representation, a behaviourset contains methods that create and modify the agent's internal representations, and an action set translates internal representations to changes to game state. The decomposition of an agent into sensing, acting and thinking parts does not impose any restrictions on the type of AI code. For example, a road cone agent in a racing car game may have an empty perception set, a single behaviourset that performs physical calculations based on the cone's position and velocity, and a single action set that updates the velocity and position based on those calculations. The racing car itself, however, may be more complex. For example, it could have a perception set that updates an internal representation of the car's position, and the position of competitors; a behaviourset that contains methods to calculate steering, brake and acceleration inputs based on current perceptions; and an action set that translates the inputs to update the car's velocity and position. Behaviours within behavioursets, perceptions within perception sets and actions within action sets are the indivisible code "atoms" that the PM executes.

The Time Allocation Algorithm

The Process Manager is called every game cycle with a single parameter that specifies the AI time. The PM holds a user-defined AgentList, which is the list of currently active agents. When invoked the PM executes all the currently active agents and attempts to ensure that this processing does not exceed AI time.

The PM allocates AI time between active agents, according to the user-specified priority of each agent. In turn, each agent allocates its share of AI time between its constituent behavioursets that are active in the current frame, also according to user-specified priorities. The time allocation process is shown in Figure 1.

Figure 1. Allocation of available processor time

The PM's functionality is distributed between the PM class and the agent class. The PM provides a base class for the PM and agents, which provides the necessary functionality at each level.

Each agent and behaviourset is allocated a portion of AI time as follows:


Where

ti = CPU time allocated to agent/behaviourset i
t = AI time
n = number of agents/behavioursets to be executed
pi = priority of agent/behaviourset i (in the range 1-100)

The pseudo-code in Listing 1 illustrates the execution of the PM.

Specifying a Game Agent

In order for the PM to control AI execution, certain execution parameters are required. The execution parameters required for agents and behavioursets are described in table 1.

Table 1. Execution parameters
Execution Parameter
Meaning
Execution priority
Used by PM to allocate AI time according to priorities. If agent A has a higher priority than agent B then A will get a larger portion of AI time than B.
Execution period
Used to specify execution period for behavioursets and agents. For example, a period of 1 executes every frame, period 30 every 30 frames, and so forth.
Execution method

Used to specify the mode of execution of a behaviourset:·

  • Suspendable: Behaviourset may be suspended but, when behaviourset is next scheduled to execute, execution must begin from the start of the behaviourset.
  • Suspendable with immediate resumption (suspendableIR): As above, except resumption occurs on immediately following frame(s).
  • Sliceable: Behaviourset may be suspended and, when next scheduled to execute, execution may resume from previous point in the behaviourset.
  • Sliceable with immediate resumption (sliceableIR): As above, except resumption occurs on immediately following frame(s).
  • Unsuspendable: Behaviourset may not be suspended.
  • Reserve: Behaviourset may be executed when other behavioursets do not consume all of agent's allotted time.
Activation delay
Used to specify delay, in frames, of activation of behaviourset. Reduces per frame AI computational load. (See text).

________________________________________________________

Process Peaking