/** * \brief 时间循环,发送定时事件,处理受影响npc ai等 */ void SceneTimeTick::run() { const int timeout_value = 500; const int timeout_value2 = 300; DWORD step = 0; int t = 0; while(!isFinal()) { zThread::msleep((10-t)>0?(10-t):1); //获取当前时间 currentTime.now(); //sky 一秒记时器循环遍历队伍处理Roll事宜 if(_one_sec(currentTime)) { SceneManager::getInstance().TeamRollItme(); } if (_five_sec(currentTime)) { OnTimer event(1); EventTable::instance().execute(event); ScenesService::getInstance().checkAndReloadConfig(); } sessionClient->doCmd(); recordClient->doCmd(); SceneTaskManager::getInstance().execEvery(); //specialNpc //MonkeyNpcs affectNpc; //AddSpecialNpcCallBack asncb(affectNpc,step,t > timeout_value2); //SceneNpcManager::getMe().execAllSpecialNpc(asncb); SceneNpc::AI(currentTime,SceneNpcManager::getMe().getSepcialNpc(),step,t > timeout_value2); //250 usec EverySceneEntryAction esea(step); //对所有地图调用回调函数 SceneManager::getInstance().execEveryScene(esea); #if 0 if (0==step) { //20-25 usec sessionClient->doCmd(); recordClient->doCmd(); SceneTaskManager::getInstance().execEvery(); } #endif if (_one_min(currentTime)) {//竞赛处理,一分钟判断一次全国竞赛 CountryDareM::getMe().timer(); //刷新所有全局变量 if (GlobalVar::server_id()) { //ugly,TO BE FIXED ALLVARS(update); ALLVARS(save); } SceneManager::getInstance().checkUnloadOneScene(); } step = (++step) % MAX_NPC_GROUP; zRTime e; t = currentTime.elapse(e); if (t > timeout_value) { Xlogger->debug("---------- 1次循环用时 %u 毫秒----------",t); } scriptTaskManagement::getInstance().execAll(); duplicateManager::getInstance().doClear(); /*scriptTaskManagement::iterator it = _tasklist->begin(); scriptTaskManagement::iterator end = _tasklist->end(); for( ; it != end; ++it) { time_t t = (time(NULL) - it->second->lastTime); if(it->second->doTask(t)) { it->second->lastTime = time(NULL); } }*/ } }
/** * \brief 时间循环,发送定时事件,处理受影响npc ai等 */ void SceneTimeTick::run() { const int timeout_value = 500; // const int timeout_value2 = 300; DWORD step = 0; int t = 0; while(!isFinal()) { zThread::msleep((10-t)>0?(10-t):1); //获取当前时间 currentTime.now(); #if 0 //sky 一秒记时器循环遍历队伍处理Roll事宜 if(_one_sec(currentTime)) { SceneManager::getInstance().TeamRollItme(); } #endif #if 0 if (_five_sec(currentTime)) { OnTimer event(1); EventTable::instance().execute(event); ScenesService::getInstance().checkAndReloadConfig(); } #endif if(_one_sec(currentTime)) { ChallengeGameManager::getMe().timer(); } sessionClient->doCmd(); recordClient->doCmd(); SceneTaskManager::getInstance().execEvery(); #ifndef _MOBILE SceneNpc::AI(currentTime, SceneNpcManager::getMe().getSepcialNpc(), step, false); #endif //250 usec EverySceneEntryAction esea(step); //对所有地图调用回调函数 SceneManager::getInstance().execEveryScene(esea); #if 0 if (0==step) { //20-25 usec sessionClient->doCmd(); recordClient->doCmd(); SceneTaskManager::getInstance().execEvery(); } #endif if (_one_min(currentTime)) { #if 0 //竞赛处理,一分钟判断一次全国竞赛 CountryDareM::getMe().timer(); if (Zebra::global["world_quiz"] == "true") { struct tm tv1; time_t timValue = time(NULL); zRTime::getLocalTime(tv1,timValue); if (tv1.tm_hour==19) { if (tv1.tm_min==5 || tv1.tm_min == 10 || tv1.tm_min==15) { for (SceneManager::CountryMap_iter iter=SceneManager::getInstance(). country_info.begin(); iter!=SceneManager::getInstance().country_info.end(); iter++) { Cmd::Session::t_countryNotify_SceneSession send; bzero(send.info,sizeof(send.info)); sprintf(send.info,"%d 分钟后举办智力竞赛",abs(20-tv1.tm_min)); send.dwCountryID = iter->second.id; sessionClient->sendCmd(&send,sizeof(send)); } } if (!quiz && tv1.tm_min>=20 && tv1.tm_min<25) { quiz = true; Cmd::Session::t_createQuiz_SceneSession send; send.active_time = 30; send.ready_time = 1; send.type = 0; send.subject_type = 0; sessionClient->sendCmd(&send,sizeof(send)); } } if (tv1.tm_hour==12) { if (tv1.tm_min==5 || tv1.tm_min==10 || tv1.tm_min == 15) { for (SceneManager::CountryMap_iter iter=SceneManager::getInstance(). country_info.begin(); iter!=SceneManager::getInstance().country_info.end(); iter++) { Cmd::Session::t_countryNotify_SceneSession send; bzero(send.info,sizeof(send.info)); sprintf(send.info,"%d 分钟后举办智力竞赛",abs(20-tv1.tm_min)); send.dwCountryID = iter->second.id; sessionClient->sendCmd(&send,sizeof(send)); } } if (!quiz && tv1.tm_min>=20 && tv1.tm_min<25) { quiz = true; Cmd::Session::t_createQuiz_SceneSession send; send.active_time = 30; send.ready_time = 1; send.type = 0; send.subject_type = 0; sessionClient->sendCmd(&send,sizeof(send)); } } if (tv1.tm_hour==22) { if (tv1.tm_min==35 || tv1.tm_min==40 || tv1.tm_min == 45) { for (SceneManager::CountryMap_iter iter=SceneManager::getInstance(). country_info.begin(); iter!=SceneManager::getInstance().country_info.end(); iter++) { Cmd::Session::t_countryNotify_SceneSession send; bzero(send.info,sizeof(send.info)); sprintf(send.info,"%d 分钟后举办智力竞赛",abs(50-tv1.tm_min)); send.dwCountryID = iter->second.id; sessionClient->sendCmd(&send,sizeof(send)); } } if (!quiz && tv1.tm_min>=50 && tv1.tm_min<55) { quiz = true; Cmd::Session::t_createQuiz_SceneSession send; send.active_time = 30; send.ready_time = 1; send.type = 0; send.subject_type = 0; sessionClient->sendCmd(&send,sizeof(send)); } } if (tv1.tm_hour==13 || tv1.tm_hour==20 || tv1.tm_hour==0) { quiz = false; } } #endif //刷新所有全局变量 if (GlobalVar::server_id()) { //ugly,TO BE FIXED ALLVARS(update); ALLVARS(save); } SceneManager::getInstance().checkUnloadOneScene(); } ++step; step %= MAX_NPC_GROUP; zRTime e; t = currentTime.elapse(e); if (t > timeout_value) { Zebra::logger->debug("---------- 1次循环用时 %u 毫秒----------",t); } //scriptTaskManagement::getInstance().execAll(); //duplicateManager::getInstance().doClear(); /*scriptTaskManagement::iterator it = _tasklist->begin(); scriptTaskManagement::iterator end = _tasklist->end(); for( ; it != end; ++it) { time_t t = (time(NULL) - it->second->lastTime); if(it->second->doTask(t)) { it->second->lastTime = time(NULL); } }*/ } }