void TraineeWalker::computeWalkerPath() { _maxNeed = 0; // need of this trainee in buildings Propagator pathPropagator; pathPropagator.init( *_originBuilding.object() ); pathPropagator.propagate(_maxDistance); for (std::list<BuildingType>::iterator itType = _buildingNeed.begin(); itType != _buildingNeed.end(); ++itType) { BuildingType buildingType = *itType; checkDestination(buildingType, pathPropagator); } if( _destinationBuilding != NULL ) { // some building needs that trainee! // std::cout << "trainee sent!" << std::endl; PathWay pathWay; pathPropagator.getPath( _destinationBuilding, pathWay); setPathWay( pathWay ); setIJ( _pathWay.getOrigin().getIJ() ); } else { // nobody needs him... // std::cout << "trainee suicide!" << std::endl; deleteLater(); } }
// frame validity checking // -------------------------------------------------------------------------- static header_content_t checkHeader(nrf24com_hdr_t *hdr, UINT8 frame_type) { header_content_t ret = CHECKHDR_OK; if (hdr->proto != NRF24COM_PROTO_V1) { ret = CHECKHDR_UNKN_PROTO; nrf24comm_debug("unknown protocol\n"); goto end; } if (NRF24_COMM_IGNORE_FRAME_TYPE != frame_type) { if (hdr->frmtype != frame_type) { ret = CHECKHDR_DISCARD; nrf24comm_debug("unexpected frame\n"); goto end; } } if (!checkDestination(hdr->dst_node_id)) { nrf24comm_debug("destination mismatch\n"); ret = CHECKHDR_DISCARD; } end: return (ret); }
void initLog(const std::string & sDir) { std::stringstream ss; ss << sDir << "/log"; std::string sTemp = ss.str(); checkDestination(sTemp); // 初始化日志 ss.str(""); ss << sDir << "/log/info_"; sTemp = ss.str(); google::SetLogDestination(google::GLOG_INFO, sTemp.c_str()); ss.str(""); ss << sDir << "/log/error_"; sTemp = ss.str(); google::SetLogDestination(google::GLOG_ERROR, sTemp.c_str()); ss.str(""); ss << sDir << "/log/warning_"; sTemp = ss.str(); google::SetLogDestination(google::GLOG_WARNING, sTemp.c_str()); ss.str(""); ss << sDir << "/log/fatal_"; sTemp = ss.str(); google::SetLogDestination(google::GLOG_FATAL, sTemp.c_str()); google::SetStderrLogging(google::GLOG_ERROR); FLAGS_colorlogtostderr = true; }
void TraineeWalker::computeWalkerPath() { _maxNeed = 0; // need of this trainee in buildings Propagator pathPropagator; pathPropagator.init(*_originBuilding); pathPropagator.propagate(_maxDistance); for (std::list<BuildingType>::iterator itType = _buildingNeed.begin(); itType != _buildingNeed.end(); ++itType) { BuildingType buildingType = *itType; checkDestination(buildingType, pathPropagator); } if (_destinationBuilding != NULL) { // some building needs that trainee! // std::cout << "trainee sent!" << std::endl; PathWay pathWay; pathPropagator.getPath(*_destinationBuilding, pathWay); setPathWay(pathWay); setIJ(_pathWay.getOrigin().getI(), _pathWay.getOrigin().getJ()); Scenario::instance().getCity().getWalkerList().push_back(this); _destinationBuilding->reserveTrainee(_traineeType); } else { // nobody needs him... // std::cout << "trainee suicide!" << std::endl; _isDeleted = true; } }
bool WallScreen::moveViewport (int x, int y, Window moveWin) { CompOption::Vector o(0); if (!x && !y) return false; if (screen->otherGrabExist ("move", "switcher", "group-drag", "wall", 0)) return false; if (!checkDestination (x, y)) return false; if (moveWindow != moveWin) { CompWindow *w; releaseMoveWindow (); w = screen->findWindow (moveWin); if (w) { if (!(w->type () & (CompWindowTypeDesktopMask | CompWindowTypeDockMask))) { if (!(w->state () & CompWindowStateStickyMask)) { moveWindow = w->id (); moveWindowX = w->x (); moveWindowY = w->y (); w->raise (); } } } } if (!moving) { curPosX = screen->vp ().x (); curPosY = screen->vp ().y (); } gotoX = screen->vp ().x () - x; gotoY = screen->vp ().y () - y; determineMovementAngle (); screen->handleCompizEvent ("wall", "start_viewport_switch", o); if (!grabIndex) grabIndex = screen->pushGrab (screen->invisibleCursor (), "wall"); screen->moveViewport (x, y, true); moving = true; focusDefault = true; boxOutputDevice = screen->outputDeviceForPoint (pointerX, pointerY); if (optionGetShowSwitcher ()) boxTimeout = optionGetPreviewTimeout () * 1000; else boxTimeout = 0; timer = optionGetSlideDuration () * 1000; cScreen->damageScreen (); return true; }
void* ExplodeTask::run() { Loader ld; std::string sErrMsg; std::shared_ptr<Tile> spTile(new Tile); std::string sOutFile; std::stringstream ss; ss << Config::Instance()->getOutDir() << "/" << m_nLevel << "/" << m_nCol; checkDestination(ss.str()); ss << "/" << m_nRow << "." << Config::Instance()->getSuffix(); sOutFile = ss.str(); bool bSuccess = false; long lCurlcode = 200; if (R_SUCCESS == ld.loadTile(m_sUrlTemplate, m_nLevel, m_nRow, m_nCol, spTile.get(), lCurlcode)) { std::string sBuffer((char*)(spTile->pData), spTile->nSize); std::ofstream streamOutFile(sOutFile, std::ios_base::out | std::ios_base::binary); streamOutFile << sBuffer; streamOutFile.close(); bSuccess = true; } else { // 将获取不到矢量切片直接写入日志 if (lCurlcode == 403 || lCurlcode == 404) { sErrMsg = ld.getUrl(m_sUrlTemplate, m_nLevel, m_nRow, m_nCol); } else { int nSeconds = 0; while (1) { if (nSeconds > 10) { sErrMsg = ld.getUrl(m_sUrlTemplate, m_nLevel, m_nRow, m_nCol); break; } Sleep(1000); if (R_SUCCESS == ld.loadTile(m_sUrlTemplate, m_nLevel, m_nRow, m_nCol, spTile.get(), lCurlcode)) { std::string sBuffer((char*)(spTile->pData), spTile->nSize); std::ofstream streamOutFile(sOutFile, std::ios_base::out | std::ios_base::binary); streamOutFile << sBuffer; streamOutFile.close(); bSuccess = true; break; } if (lCurlcode == 403 || lCurlcode == 404) { sErrMsg = ld.getUrl(m_sUrlTemplate, m_nLevel, m_nRow, m_nCol); break; } ++nSeconds; } } } if (m_pProgress) { if (bSuccess) { // 成功,设置进度 m_pProgress->addNow(1); } else { // 失败,设置进度并记录失败的数据 m_pProgress->addFail(1); // 写一条错误日志 LOG(ERROR) << "下载瓦片失败" << sErrMsg; } } spTile->clear(); return NULL; }