Beispiel #1
0
void TaskManagerBase::DrawUpdate()
{
	for(uint32_t i = 0; i < m_vTaskUnit.size(); ++i){
		TaskUnit *pTask = m_vTaskUnit.at(i);
		if(pTask->GetStatus() == TaskUnit::TASK_ALIVE){
			pTask->DrawUpdate();
		}
	}
}
Beispiel #2
0
TaskManagerBase::~TaskManagerBase(void)
{
	std::vector<TaskUnit*>::iterator it = m_vTaskUnit.begin();
	while(m_vTaskUnit.empty() == 0){
		//! 基本的にすべてのタスクは自分で削除するのでここで m_vTaskUnit.size()は0のはず
		TaskUnit *task = *it;
		DEBUG_PRINT("/_/_/解放し忘れタスクがあるよ : %s/_/_/\n",task->GetName().c_str());
		it = m_vTaskUnit.erase(it);
		SAFE_DELETE(task);
	}
	m_vTaskUnit.clear();
}
Beispiel #3
0
/* ================================================ */
void TaskManagerBase::DeleteDieUnit()
{
	std::vector<TaskUnit*>::iterator it = m_vTaskUnit.begin();
	while(it != m_vTaskUnit.end()){
		TaskUnit *task = *it;
		if(task->GetStatus() == TaskUnit::TASK_DIE){
			it = m_vTaskUnit.erase(it);
			SAFE_DELETE(task);
			continue;
		}
		if(it != m_vTaskUnit.end()){
			++it;
		}
	}
}
Beispiel #4
0
/* ================================================ */
bool TaskManagerBase::ReleaseAllEnd()
{
	for(unsigned int i = 0; i < m_vTaskUnit.size(); ++i){
		TaskUnit *pTask = m_vTaskUnit.at(i);
		if(pTask->DieMain()){
			pTask->SetStatus(TaskUnit::TASK_DIE);
		}
	}
	//! 状態がTASK_PRE_DIEになったタスクを解放する
	DeleteDieUnit();

	if(m_vTaskUnit.size() == 0){
		return true;
	}
	return false;
}
Beispiel #5
0
void TaskQueue::pollProcessedTasks(long long maxAllowedTimeMilliseconds)
{
  long long startTime = Time::currentTimeMillis();
  TaskUnitQueue processedCopy;
  {
    boost::mutex::scoped_lock l(mProcessedQueueMutex);
    processedCopy = mProcessedTaskUnits;
    if (mProcessedTaskUnits.size()) {
      mProcessedTaskUnits = TaskUnitQueue();
    }
  }
  while (processedCopy.size()) {

    TaskUnit* taskUnit = processedCopy.front();
    processedCopy.pop();
    try {
      taskUnit->executeInMainThread();
    } catch (const std::exception& ex) {
      S_LOG_FAILURE("Error when executing task in main thread." << ex);
    } catch (...) {
      S_LOG_FAILURE("Unknown error when executing task in main thread.");
    }
    try {
      delete taskUnit;
    } catch (const std::exception& ex) {
      S_LOG_FAILURE("Error when deleting task in main thread." << ex);
    } catch (...) {
      S_LOG_FAILURE("Unknown error when deleting task in main thread.");
    }
    //Try to keep the time spent here each frame down, to keep the framerate up.
    if (maxAllowedTimeMilliseconds > 0 && Time::currentTimeMillis() - startTime > maxAllowedTimeMilliseconds) {
      break;
    }
  }
  //If there are any unprocessed tasks, put them back at the front of the queue.
  if (processedCopy.size()) {
    boost::mutex::scoped_lock l(mProcessedQueueMutex);
    TaskUnitQueue queueCopy(mProcessedTaskUnits);
    mProcessedTaskUnits = processedCopy;
    while (queueCopy.size()) {
      mProcessedTaskUnits.push(queueCopy.front());
      queueCopy.pop();
    }
  }
}
Beispiel #6
0
void TaskQueue::pollProcessedTasks(TimeFrame timeFrame)
{
	TaskUnitQueue processedCopy;
	{
		std::unique_lock<std::mutex> l(mProcessedQueueMutex);
		processedCopy = mProcessedTaskUnits;
		if (!mProcessedTaskUnits.empty()) {
			mProcessedTaskUnits = TaskUnitQueue();
		}
	}
	while (!processedCopy.empty()) {

		TaskUnit* taskUnit = processedCopy.front();
		processedCopy.pop();
		try {
			taskUnit->executeInMainThread();
		} catch (const std::exception& ex) {
			S_LOG_FAILURE("Error when executing task in main thread." << ex);
		} catch (...) {
			S_LOG_FAILURE("Unknown error when executing task in main thread.");
		}
		try {
			delete taskUnit;
		} catch (const std::exception& ex) {
			S_LOG_FAILURE("Error when deleting task in main thread." << ex);
		} catch (...) {
			S_LOG_FAILURE("Unknown error when deleting task in main thread.");
		}
		//Try to keep the time spent here each frame down, to keep the framerate up.
		if (!timeFrame.isTimeLeft()) {
			break;
		}
	}
	//If there are any unprocessed tasks, put them back at the front of the queue.
	if (!processedCopy.empty()) {
		std::unique_lock<std::mutex> l(mProcessedQueueMutex);
		TaskUnitQueue queueCopy(mProcessedTaskUnits);
		mProcessedTaskUnits = processedCopy;
		while (!queueCopy.empty()) {
			mProcessedTaskUnits.push(queueCopy.front());
			queueCopy.pop();
		}
	}
}
Beispiel #7
0
/* ================================================ */
void FlowBase::ChildUpdate()
{
	if( Utility::IsGamePause() ){
		// ポーズ中
	}
	else if( m_vStageEffect.size() != 0
		&& FadeManager::GetInstance()->GetCurrentState() == FadeManager::STATE_IDLE ){
		// フロー演出中
		auto it = m_vStageEffect.begin();
		if( (*it)->IsEffectEnd() ){
			ProcessBase *tmp = *it;
			m_vStageEffect.erase( it );
			SAFE_DELETE(tmp);

			if( m_vStageEffect.size() == 0 ){
				// フィルター終了
				Utility::EndGameStop();
			}
		}
		else{
			(*it)->Exec();
			// フィルターを表示し続ける
			Utility::StartGameStop( /*bool withFilter=*/(*it)->IsNeedPauseFilter() );
		}

		// Effectクラスが作られたときにInitだけは処理しないと描画されないのでここで処理
		for(uint32_t i = 0; i < m_vTaskUnit.size(); ++i){
			TaskUnit *pTask = m_vTaskUnit.at(i);
			if( pTask->GetStatus() == TaskUnit::TASK_INIT ){
				if(pTask->Init()){
					pTask->SetStatus(TaskUnit::TASK_ALIVE);
				}
			}
		}
	}
	else{
		Exec();				//! 位置等の更新
		CollisionManager::GetInstance()->CollisionUpdate();			// 衝突判定更新+各クラスにイベント発行	
		SystemMessageManager::GetInstance()->StartMessageEvent();	// 各クラスの相互イベント処理を行う
	}
	DrawUpdate();		//! 描画等の更新
}
Beispiel #8
0
void TaskExecutor::run()
{
  while (mActive) {
    TaskUnit* taskUnit = mTaskQueue.fetchNextTask();
    //If the queue returns a null pointer, it means that the queue is being shut down, and this executor is expected to exit its main processing loop.
    if (taskUnit) {
      try {
        TaskExecutionContext context(*this, *taskUnit);
        taskUnit->executeInBackgroundThread(context);
        mTaskQueue.addProcessedTask(taskUnit);
      } catch (const std::exception& ex) {
        S_LOG_CRITICAL("Error when executing task in background." << ex);
        delete taskUnit;
      } catch (...) {
        S_LOG_CRITICAL("Unknown error when executing task in background.");
        delete taskUnit;
      }
    } else {
      break;
    }
  }
}
Beispiel #9
0
/* ================================================ */
void TaskManagerBase::Exec()
{
	for(uint32_t i = 0; i < m_vTaskUnit.size(); ++i){
		TaskUnit *pTask = m_vTaskUnit.at(i);
		switch(pTask->GetStatus()){
		default:
			DEBUG_ASSERT( 0, "/_/_/task status が想定外/_/_/");
			break;

		case TaskUnit::TASK_IDLE:
			//! 何もしない
			break;

		case TaskUnit::TASK_INIT:
			if(pTask->Init()){
				pTask->SetStatus(TaskUnit::TASK_ALIVE);
			}
			break;

		case TaskUnit::TASK_ALIVE:
			pTask->Update();
			break;

		case TaskUnit::TASK_PRE_DIE:
			if(pTask->DieMain()){
				pTask->SetStatus(TaskUnit::TASK_DIE);
			}
			break;

		case TaskUnit::TASK_DIE:
			DEBUG_ASSERT( 0, "/_/_/ここに来るのはおかしい/_/_/");
			break;
		}
	}

	//! 状態がTASK_PRE_DIEになったタスクを解放する
	DeleteDieUnit();
}
Beispiel #10
0
void TaskExecutionContext::executeTask(ITask* task, ITaskExecutionListener* listener)
{
	TaskUnit* taskUnit = mTaskUnit.addSubtask(task, listener);
	TaskExecutionContext subtaskContext(mExecutor, *taskUnit);
	taskUnit->executeInBackgroundThread(subtaskContext);
}