Esempio n. 1
0
void GroundEyeshot::onFound(int nGridX,int nGridY)
{
	GroundTile *pGT = static_cast<GroundTile*>(getGroundTile(nGridX,nGridY));
	if(!pGT)return;
	
	//Info("Found!"<<nGridY<<","<<nGridX<<","<<(ulong)pGT<<endl);

	// 地表资源ID由mapID、nGridX、nGridY组合产生
	ulong uResID = 0;
	if(getRunType() == RUN_TYPE_GAME)
	{
		IEntityClient* pEntityClient = gGlobalClient->getEntityClient();
		if (NULL != pEntityClient)
		{
			uResID = pEntityClient->GetMapID();
		}			
	}		
	uResID <<= 22;
	uResID |= (nGridX << 11);
	uResID |= nGridY;

	if(m_pResourceManager)
	{
		if(m_pMapStream)
		{
			m_pMapStream->seek(m_pGroundTileTable[nGridY * m_nTotalGridX + nGridX]);
			pGT->loadAlphaMaps(m_pMapStream);
			
			//PP_BY_NAME_START("同步加载地表");
			//一定不能在主线程里面做加载和解码
			//add by yhc,防止地图加载时候出现花屏,在创建的时候使用同步加载
			if(m_bFirstEnterArea)
				pGT->setResHandle(m_pResourceManager->requestResource(uResID,typeResourceGroundTile,true));
			else
				pGT->setResHandle(m_pResourceManager->requestResource(uResID,typeResourceGroundTile,false,10));//by yhc 地表的优先级高
			//PP_BY_NAME_STOP();
			//是否播放区域的音效
			if(getRunType() == RUN_TYPE_EDITOR)
			{
				return ;
			}
		}
		else
		{
			//地图编辑器创建新地图的时候,m_pMapStream == 0
			//ulong lst = ((IGlobalClient*)::xs::getGlobal())->getTimeStamp();
			//一定不能在主线程里面做加载和解码
			if(m_bFirstEnterArea)
				pGT->setResHandle(m_pResourceManager->requestResource(uResID,typeResourceGroundTile,true));
			else
				pGT->setResHandle(m_pResourceManager->requestResource(uResID,typeResourceGroundTile,false,10));//by yhc 地表的优先级高 
			//pGT->setResHandle(m_pResourceManager->requestResource((m_hash ^ (ulong)pGT),typeResourceGroundTile,true));
			//ulong lend = lst - ((IGlobalClient*)::xs::getGlobal())->getTimeStamp();
		}
	}
}
void CAdvThread::threadMainFunction()
{
    getCurrentHandle();
    setAffinity();
    while (isThreadWork)
    {
        std::unique_lock<std::mutex> locker(threadMutex);
        // wait notification and check that it does not a false awakening
        // Thread must awake if list is not empty or it was poweroff
        conditionVariable.wait(locker, [&](){ return !taskArray.empty() || !isThreadWork || affinityData.coreChanged;});

        while(!taskArray.empty())
        {
            if(!isThreadWork)//if stop thread of pool
            {
                while(!taskArray.empty())//stop all tasks
                {
                    runnable_closure runClosure = taskArray.front();//get task from array
                    taskArray.pop();
                    locker.unlock();//unlock before task call
                    runClosure(int(eRUN_MODES::STOP), 0);
                    locker.lock();
                }
                return;
            }

            currentRunnableClosure = taskArray.front();//get task from array
            taskArray.pop();

            locker.unlock();//unlock before task call
            try
            {
                if(threadType == eThreadType::THREAD_SHARED && getRunType() == eRunnableType::SHORT_TASK)
                {
                    QString stringTimerResult = currentRunnableClosure(int(eRUN_MODES::IS_TIMER_OVER), 0);
                    if(stringTimerResult == QString("1"))
                    {
                        lastTimeOfTaskLaunch = std::chrono::high_resolution_clock::now();
                        isReadyForSend_WarningAboutShortTaskFreeze = true;
                        currentRunnableClosure(int(eRUN_MODES::RUN), 0);
                        isReadyForSend_WarningAboutShortTaskFreeze = false;
                    }
                    else //task hold over
                        appendRunnableTask(currentRunnableClosure, eRunnableType::SHORT_TASK);
                }
                else
                {
                    lastTimeOfTaskLaunch = std::chrono::high_resolution_clock::now();
                    isReadyForSend_WarningAboutShortTaskFreeze = true;
                    currentRunnableClosure(int(eRUN_MODES::RUN), 0);
                    isReadyForSend_WarningAboutShortTaskFreeze = false;
                }

            }
            catch(holdOverTask_Exception action)
            {
                if(threadType == eThreadType::THREAD_SHARED && getRunType() == eRunnableType::SHORT_TASK)
                {
                    int counterOfExecution = currentRunnableClosure(int(eRUN_MODES::GET_COUNTER), 0).toInt();
                    if(counterOfExecution>0)
                    {
                        CAdvThreadPool::getInstance().getEmitter()->addWarningToShell(QString("Task was hold over - counter = %1 (%2)").arg(counterOfExecution)
                                                                                      .arg(QString::fromStdString(action.what())),
                                                                                      eLogWarning::message);
                        currentRunnableClosure(int(eRUN_MODES::DECREASE_COUNTER), 0);
                        currentRunnableClosure(int(eRUN_MODES::START_TIMER_FOR_INTERVAL), action.getInterval());
                        appendRunnableTask(currentRunnableClosure, eRunnableType::SHORT_TASK);
                    }
                    else
                    {
                        CAdvThreadPool::getInstance().getEmitter()->addWarningToShell(QString("Task will not processing - counter over (%2)").arg(counterOfExecution)
                                                                                      .arg(QString::fromStdString(action.what())),
                                                                                      eLogWarning::warning);
                    }
                }

            }
            catch(std::exception& e)
            {
                QString temp = QString("%1 - CAdvThread::threadMainFunction - ").arg(e.what());
                temp += getWho();
                std::cout<<temp.toStdString()<<std::endl;
                CAdvThreadPool::getInstance().getEmitter()->addWarningToShell(temp, eLogWarning::warning);
            }
            catch(...)
            {               
                QString temp = QString("Undefined exception - CAdvThread::threadMainFunction - ");
                temp += getWho();
                std::cout<<temp.toStdString()<<std::endl;
                CAdvThreadPool::getInstance().getEmitter()->addWarningToShell(temp, eLogWarning::warning);
            }

            locker.lock(); // lock before m_TaskArray.empty()
            currentRunnableClosure = nullptr;

            if(threadType == eThreadType::THREAD_NOT_SHARED)
                CAdvThreadPool::getInstance().getEmitter()->sendSignal_DeleteLongTask(getThreadNumber());
            else if(threadType == eThreadType::THREAD_NOT_SHARED_EXTRA)
                CAdvThreadPool::getInstance().getEmitter()->sendSignal_DeleteExtraLongTask(getThreadNumber());
        }
    }
}