Game Development Reference
In-Depth Information
A great example of where a process is needed is in the AI update for the teapots.
Teapots need a way to periodically update their states and make decisions. This all
starts with the _CreateEnemyProcesses() function you saw in AddEnemy() .
function ActorManager:_CreateEnemyProcesses()
self._enemyProcesses = {};
-- Create all enemy processes. Each process is appended to the end of
-- the _enemyProcesses list.
self._enemyProcesses[#self._enemyProcesses+1] =
EnemyUpdater:Create({_enemies = self._enemies});
self._enemyProcesses[#self._enemyProcesses+1] =
EnemyHealer:Create({_enemies = self._enemies, frequency = 15013});
self._enemyProcesses[#self._enemyProcesses+1] =
EnemyThinker:Create({_enemies = self._enemies, frequency = 3499});
-- attach all the processes
for i, proc in ipairs(self._enemyProcesses) do
AttachProcess(proc);
end
end
This function is responsible for creating the three processes used by the actor man-
ager, which are stored in the _enemyProcesses table. Once the processes have been
created, the function loops through the list and calls the exported C++ function
AttachProcess() to attach it to the game logics Process Manager.
Use Prime Numbers
In the _CreateEnemyProcesses() function, you may note the use of
some odd frequency values. Why would I use 3499 instead of 3500? Those
frequencies are all being set to prime numbers that are close to the value I
want. This makes the processes tend to update on separate frames. It
s not
perfect, but without a process scheduling system, it works well enough.
'
The processes themselves are rather simple. Here
'
s the EnemyThinker process, used
to run an AI update:
EnemyThinker = class(ActorManagerProcess,
{
--
});
 
Search WWH ::




Custom Search