Ejemplo n.º 1
0
//---------------------------------------------------------------------------------------------------------------------
// Aborts all processes.  If immediate == true, it immediately calls each ones OnAbort() function and destroys all 
// the processes.
//---------------------------------------------------------------------------------------------------------------------
void ProcessManager::AbortAllProcesses(bool immediate)
{
    ProcessList::iterator it = m_processList.begin();
    while (it != m_processList.end())
    {
        ProcessList::iterator tempIt = it;
        ++it;

        StrongProcessPtr pProcess = *tempIt;
        if (pProcess->IsAlive())
        {
            pProcess->SetState(Process::ABORTED);
            if (immediate)
            {
                pProcess->VOnAbort();
                m_processList.erase(tempIt);
            }
        }
    }
}
void ProcessManager::AbortAllProcesses(bool immediate)
{
	auto it = m_ProcessList.begin();
	while (it != m_ProcessList.end())
	{
		auto tempIt = it;
		++it;

		StrongProcessPtr pProcess = *tempIt;
		if (pProcess->IsAlive())
		{
			pProcess->SetState(Process::ABORTED);
			// if immediate, call the abort code and erase the process now
			if (immediate)
			{
				pProcess->OnAbort();
				m_ProcessList.erase(tempIt);
			}
		}
	}
}
Ejemplo n.º 3
0
void CProcessManager::AbortAllProcesses( bool immediate )
{
    ProcessList::iterator it = m_ProcessList.begin();
    while (it != m_ProcessList.end())
    {
        //in case we need to delete 'it'
        ProcessList::iterator thisIt = it;
        ++it;

        StrongProcessPtr pCurrent = (*thisIt);

        if (immediate)
        {
            (*it)->SetState( CProcess::ABORTED );
            if (pCurrent->IsAlive())
            {
                (*it)->VOnAbort();
                m_ProcessList.erase( thisIt );
            }
        }
    }
}
Ejemplo n.º 4
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);
}
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;
}
Ejemplo n.º 6
0
  void ProcessManager::UpdateProcesses(float elapsed_time)
  {
    // Iterate over all processes.
    ProcessList::iterator it = processes_.begin();
    while (it != processes_.end())
    {
      StrongProcessPtr process = *it;

      // If the process hasn't been initialized yet.
      if (process->GetState() == Process::State::UNINITIALIZED)
      {
        // Initialize it.
        process->OnInit();
      }

      // If the process is running.
      if (process->GetState() == Process::State::RUNNING)
      {
        // Update it.
        process->OnUpdate(elapsed_time);
      }

      // If the process is dead.
      if (process->IsDead())
      {
        // If he exited successfully.
        if (process->GetState() == Process::State::SUCCEEDED)
        {
          // Call the appropriate exit method.
          process->OnSuccess();

          // Attach the children to the process manager if the process had some.
          const std::vector<StrongProcessPtr>& children = process->GetChildren();
          if (!children.empty())
            for (StrongProcessPtr child : children)
              AddProcess(child);
          process->ClearChildren();
        }
        // If he exited with an failure.
        else if (process->GetState() == Process::State::FAILED)
        {
          process->OnFail();
        }
        // If he was aborted.
        else if (process->GetState() == Process::State::ABORTED)
        {
          process->OnAbort();
        }

        // Remove the process and set the iterator to the next process.
        it = processes_.erase(it);
      }
      // If the process isn't dead we have to increment the iterator.
      else
      {
        ++it;
      }
    }
  }
Ejemplo n.º 7
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);
}