unsigned int ProcessManager::UpdateProcesses(float deltaTime) { unsigned short int successCount = 0; unsigned short int failCount = 0; auto it = m_ProcessList.begin(); while (it != m_ProcessList.end()) { StrongProcessPtr pCurrentProcess = (*it); // save an iterator to this process and increment our list iterator auto thisIt = it; ++it; // init the current process if it has not intialized yet if (pCurrentProcess->GetState() == Process::UNINITIALIZED) { pCurrentProcess->OnInit(); } // update a running process if (pCurrentProcess->GetState() == Process::RUNNING) { pCurrentProcess->OnUpdate(deltaTime); } // if a process is dead, run the correct exit method if (pCurrentProcess->IsDead()) { switch (pCurrentProcess->GetState()) { case Process::SUCCEEDED: { pCurrentProcess->OnSuccess(); StrongProcessPtr pChild = pCurrentProcess->RemoveChild(); if (pChild) AttachProcess(pChild); else ++successCount; break; } case Process::FAILED: { pCurrentProcess->OnFail(); ++failCount; break; } case Process::ABORTED: { pCurrentProcess->OnAbort(); ++failCount; break; } } // destroy the dead process m_ProcessList.erase(thisIt); } } return (successCount << 16) | failCount; }
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); }
//--------------------------------------------------------------------------------------------------------------------- // 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); }