Game Development Reference
In-Depth Information
Manipulating commands
Internally, the animation controller uses three main functions to manipulate the command
queue. AddCommandCallback adds a function callback to handle a specific command,
AdvanceExecutingCommand will remove the top command from the command queue
if there is no currently executing command, and ExecuteCommand will call the associate
callback for an executing command once per frame:
SoldierController.lua :
local function _AddCommandCallback(self, commandName,
callback)
self.commandCallbacks[commandName] = callback;
end
local function _AdvanceExecutingCommand(self)
-- Moves the first queued command into execution if the
-- previous command has finished.
if (#self.commands > 0 and not self.executingCommand)
then
local command = self.commands[1];
self.executingCommand = command;
table.remove(self.commands, 1);
end
end
local function _ExecuteCommand(self, agent,
deltaTimeInMillis)
local callback =
self.commandCallbacks[self.executingCommand];
-- Handle any callback that is associated with an
executing
-- command.
if (callback) then
callback(self, agent, deltaTimeInMillis);
end
end
Search WWH ::




Custom Search