Game Development Reference
In-Depth Information
private:
void SetState(State newState) { m_state = newState; }
};
At the very top of this class is the State enum. There are a number of different
states a process could potentially be in. Its current state determines how the
ProcessManager handles
it during the update loop. Processes
start
in the
UNINITIALIZED state.
Along with its state, every process can have a child process (the m_pChild member).
The child is a suspended process that
s attached to this process. If this process com-
pletes successfully, the ProcessManager will attach the child and process it in the
next frame. This is a very simple yet powerful technique, allowing you to create
chains of processes. For example, if you wanted an NPC to walk to the water cooler
and take a drink, you could create one process for path finding and another for run-
ning an animation. You would then instantiate the path-finding process and attach
the animation process as a child. When you ran it, the character would path up to
the water cooler and run the animation. This was exactly how Rat Race worked.
Actions were built up by the AI and then pushed as a single-chained process.
There are five virtual functions that subclasses are allowed to override. The only
function you have to override is VOnUpdate() since that ' s where the magic happens.
This function defines what your process does and gets run once every loop. The only
parameter is the delta time between this frame and the last.
VOnInit() is called once during the very first update. All of your process initializa-
tion should go here. It
'
s important to remember to call the base class version of this
function at the top of your override to ensure that the process state correctly gets set
to RUNNING .
VOnSuccess() , VOnFail() , and VOnAbort() are exit functions. One of them is
called when your process ends, depending on how it ended. The Succeed() and
Fail() public member functions are used to end a process and tell it if it succeeded
or failed. A process is typically only aborted due to an internal issue. It is perfectly
valid to call Succeed() or Fail() from inside VOnInit() . This is a fairly com-
mon case since initialization can fail. If this happens, the process will never have its
VOnUpdate() function called.
If a process is successful and it has a child process attached, that child will be pro-
moted into the ProcessManager '
'
s list. It will get initialized and run the next frame.
If a process fails or is aborted, the child will not get promoted.
Note the use of the StrongProcessPtr typedef throughout. This is an excellent
example of using smart pointers in a class that uses an STL list. Any reference to a
Search WWH ::




Custom Search