Game Development Reference
In-Depth Information
'
“
”
Take note of two things. First, you don
a
DelayProcess
and attach
it to the
ProcessManager
. You have to use the
StrongProcessPtr typedef
(or
the
shared_ptr
template directly) to manage
Process
objects. This fixes problems
when processes get deleted, but other objects may still point to them. Second, you
must call the
Attach()
method of
ProcessManager
to attach the new process to
the Process Manager.
As the main loop is processed and
ProcessManager::UpdateProcesses()
is
called, the
DelayProcess
counts the elapsed time, and once it has passed the wait
period, it calls
Succeed()
. By itself, it
'
s a little underwhelming
—
it just uses up a
little CPU time and goes away. But if you define another process, such as
Kaboom-
Process
, things get a little more interesting. You can then create a nuclear explosion
with a three-second fuse without a physics degree:
t just
new up
// The delay process will stay alive for three seconds
StrongProcessPtr pDelay(new DelayProcess(3000));
processManager.AttachProcess(pDelay);
// The KaboomProcess will wait for the DelayProcess
// Note
kaboom will be attached automatically
StrongProcessPtr pKaboom(new KaboomProcess());
pDelay->AttachChild(pKaboom);
The
Process::AttachChild()
method sets up a simple dependency between the
DelayProcess
and the
KaboomProcess
.
KaboomProcess
will remain inactive
until the
DelayProcess
succeeds. If the
DelayProcess
fails or is aborted for
some reason (maybe the level ended before it finished), then the
KaboomProcess
is simply removed and never actually updates.
-
Data-Driven Processes
If you plan on using processes as the core of your game, you should have a
data format that lets you define chains of processes and dependencies. At
Super-Ego Games, we used XML to define our process chains and how they
all fit together. It allowed us to set up complex game logic without having to
touch a single line of code. An even better way would be to use a visual editor
so designers would be able to move around nodes and create complex game
logic without involving engineers at all. This is basically what the quest system
did in The SimsMedieval.
Every updatable game object can inherit from
Process
. User interface objects such
as buttons, edit boxes, or menus can inherit from
Process
. Audio objects such as