예제 #1
0
unsigned int CProcessManager::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())
    {
        //Get the value from the iterator
        StrongProcessPtr ptr = (*it);

        //use this and increment the old one just in case we need to remove it from the list
        ProcessList::iterator thisIt = it;
        ++it;

        //if the process is uninitialized, then initialize it
        if (ptr->GetState() == CProcess::UNINITIALIZED)
            ptr->VOnInit();


        //the the process is running, update it
        if (ptr->GetState() == CProcess::RUNNING)
            ptr->VOnUpdated( deltaMs );


        //if the process is dead, then remove it and call the appropriate exit function
        if (ptr->IsDead())
        {
            switch (ptr->GetState())
            {
            case CProcess::SUCCEEDED:
            {
                ptr->VOnSuccess();
                StrongProcessPtr pChild = ptr->RemoveChild();
                if (pChild)
                    AttachProcess( pChild );
                else
                    ++successCount;//this only counts if the chain has succeeded
                break;
            }
            case CProcess::ABORTED:
                ptr->VOnAbort();

                ++failCount;

                break;
            case CProcess::FAILED:
                ptr->VOnFail();

                ++failCount;

                break;
            }

            //the object is dead, so remove it from this list
            m_ProcessList.erase( thisIt );
        }
    }

    return ((successCount << 16) | !failCount);
}
예제 #2
0
//---------------------------------------------------------------------------------------------------------------------
// The process update tick.  Called every logic tick.  This function returns the number of process chains that 
// succeeded in the upper 32 bits and the number of process chains that failed or were aborted in the lower 32 bits.
//---------------------------------------------------------------------------------------------------------------------
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 :
                {
                    pCurrProcess->VOnSuccess();
                    StrongProcessPtr pChild = pCurrProcess->RemoveChild();
                    if (pChild)
                        AttachProcess(pChild);
                    else
                        ++successCount;  // only counts if the whole chain completed
                    break;
                }

                case Process::FAILED :
                {
                    pCurrProcess->VOnFail();
                    ++failCount;
                    break;
                }

                case Process::ABORTED :
                {
                    pCurrProcess->VOnAbort();
                    ++failCount;
                    break;
                }
            }

            // remove the process and destroy it
            m_processList.erase(thisIt);
        }
    }

    return ((successCount << 16) | failCount);
}