Game Development Reference
In-Depth Information
The
ProcessManager
class is pretty small. At the very top is a
typedef
for a list of
pointers to
Process
objects. Note how they are all
StrongProcessPtr
types, which
in turn are of type
shared_ptr<Process>
. This allows you to create a process and
safely hold on to your own reference without worrying about when the object is actually
destroyed. It will be destroyed when the final strong reference is removed.
When you want to run a new process, you instantiate the specific
Process
subclass
you want and then call
AttachProcess()
to attach it to the Process Manager.
This queues it up to be initialized and run the next time the Process Manager
updates.
To update the Process Manager, you call
UpdateProcesses()
. Let
'
s take a look at
that function:
unsigned int ProcessManager::UpdateProcesses(unsigned long deltaMs)
{
unsigned short int successCount = 0;
unsigned short int failCount = 0;
ProcessList::iterator it = m_processList.begin();
while (it != m_processList.end())
{
// grab the next process
StrongProcessPtr pCurrProcess = (*it);
// save the iterator and increment the old one in case we need to remove
// this process from the list
ProcessList::iterator thisIt = it;
++it;
// process is uninitialized, so initialize it
if (pCurrProcess->GetState() == Process::UNINITIALIZED)
pCurrProcess->VOnInit();
// give the process an update tick if it's running
if (pCurrProcess->GetState() == Process::RUNNING)
pCurrProcess->VOnUpdate(deltaMs);
// check to see if the process is dead
if (pCurrProcess->IsDead())
{
// run the appropriate exit function
switch (pCurrProcess->GetState())
{
case Process::SUCCEEDED :