void Client::Update(int64_t nNowMS) { int nTimeNow = (int)time(0); //发呆>=30秒才发送 if (nTimeNow - m_nPacketTime >= 30) { //每60秒通知一次 if (nTimeNow - m_nLastNotifyTime < 60) { return; } m_nLastNotifyTime = nTimeNow; Packet* poPacket = Packet::Create(32, nPACKET_OFFSET_SIZE, __FILE__, __LINE__); if (poPacket == NULL) { return; } PacketWriter oWriter(poPacket); oWriter << m_nRoleID << m_nPacketTime; uint16_t uSrcServer = g_poContext->GetServerID(); int8_t nSrcService = g_poContext->GetService()->GetServiceID(); int8_t nTarService = 110; NetAdapter::SERVICE_NAVI oNavi(uSrcServer, nSrcService, g_poContext->GetWorldServerID(), nTarService, m_nSession); NetAdapter::SendInner(NSSysCmd::ssClientLastPacketTimeRet, poPacket, oNavi); } else if (m_nLastNotifyTime > 0) { m_nLastNotifyTime = 0; } }
//保存最高分到文件中 bool CGeneralManager::SaveHighScoreToFile() { string strPath = FileUtils::getInstance()->getWritablePath() + string(HIGHSCORE_FILEPATH); string strContent = FileUtils::getInstance()->getStringFromFile(strPath); rapidjson::Document oDoc; oDoc.Parse<0>(strContent.c_str()); if (oDoc.HasParseError() || oDoc.IsNull()) { oDoc.SetObject(); rapidjson::Document::AllocatorType& allocator = oDoc.GetAllocator(); rapidjson::Value oArray(rapidjson::kArrayType); for (int i = 0; i < GAME_MAX; ++i) { oArray.PushBack(m_mapHighScore[i], allocator); } oDoc.AddMember("HighScore", oArray, allocator); } else { //更新数据 for (rapidjson::SizeType i = 0; i < oDoc["HighScore"].Capacity(); i++) { if (oDoc["HighScore"][i].IsNull()) { return false; } oDoc["HighScore"][i].SetInt(m_mapHighScore[i]); } } rapidjson::StringBuffer oBuffer; rapidjson::Writer<rapidjson::StringBuffer> oWriter(oBuffer); oDoc.Accept(oWriter); FILE* pFile = fopen(strPath.c_str(), "wb+"); if (pFile == NULL) { log("Open File '%s' Failed.", strPath.c_str()); return false; } fputs(oBuffer.GetString(), pFile); fclose(pFile); return true; }
bool rpnoc::Profile::writeXml( const QString &iFilename, QStringList *iItem ) { QString oFileName = iFilename.toLower(); QFile oFile( oFileName ); if( !oFile.open( QFile::ReadWrite | QFile::Text ) ) { log_e( "Failed to open file '" + iFilename + "'." + log_endl + oFile.errorString() ); return false; } QXmlStreamWriter oWriter( &oFile ); oWriter.setAutoFormatting( true ); oWriter.writeStartDocument(); oWriter.writeStartElement( "Profile" ); writeIndexEntry( &oWriter, iItem ); oWriter.writeEndDocument(); oFile.close(); if( oFile.error() ) { log_e( "Failed to close file '" + iFilename + "'." + log_endl + oFile.errorString() ); return false; } return true; }
OGRErr PDFWritableVectorDataset::SyncToDisk() { if (nLayers == 0 || !bModified) return OGRERR_NONE; bModified = FALSE; OGREnvelope sGlobalExtent; int bHasExtent = FALSE; for(int i=0;i<nLayers;i++) { OGREnvelope sExtent; if (papoLayers[i]->GetExtent(&sExtent) == OGRERR_NONE) { bHasExtent = TRUE; sGlobalExtent.Merge(sExtent); } } if (!bHasExtent || sGlobalExtent.MinX == sGlobalExtent.MaxX || sGlobalExtent.MinY == sGlobalExtent.MaxY) { CPLError(CE_Failure, CPLE_AppDefined, "Cannot compute spatial extent of features"); return OGRERR_FAILURE; } PDFCompressMethod eStreamCompressMethod = COMPRESS_DEFLATE; const char* pszStreamCompressMethod = CSLFetchNameValue(papszOptions, "STREAM_COMPRESS"); if (pszStreamCompressMethod) { if( EQUAL(pszStreamCompressMethod, "NONE") ) eStreamCompressMethod = COMPRESS_NONE; else if( EQUAL(pszStreamCompressMethod, "DEFLATE") ) eStreamCompressMethod = COMPRESS_DEFLATE; else { CPLError( CE_Warning, CPLE_NotSupported, "Unsupported value for STREAM_COMPRESS."); } } const char* pszGEO_ENCODING = CSLFetchNameValueDef(papszOptions, "GEO_ENCODING", "ISO32000"); double dfDPI = CPLAtof(CSLFetchNameValueDef(papszOptions, "DPI", "72")); if (dfDPI < 72.0) dfDPI = 72.0; const char* pszNEATLINE = CSLFetchNameValue(papszOptions, "NEATLINE"); int nMargin = atoi(CSLFetchNameValueDef(papszOptions, "MARGIN", "0")); PDFMargins sMargins; sMargins.nLeft = nMargin; sMargins.nRight = nMargin; sMargins.nTop = nMargin; sMargins.nBottom = nMargin; const char* pszLeftMargin = CSLFetchNameValue(papszOptions, "LEFT_MARGIN"); if (pszLeftMargin) sMargins.nLeft = atoi(pszLeftMargin); const char* pszRightMargin = CSLFetchNameValue(papszOptions, "RIGHT_MARGIN"); if (pszRightMargin) sMargins.nRight = atoi(pszRightMargin); const char* pszTopMargin = CSLFetchNameValue(papszOptions, "TOP_MARGIN"); if (pszTopMargin) sMargins.nTop = atoi(pszTopMargin); const char* pszBottomMargin = CSLFetchNameValue(papszOptions, "BOTTOM_MARGIN"); if (pszBottomMargin) sMargins.nBottom = atoi(pszBottomMargin); const char* pszExtraImages = CSLFetchNameValue(papszOptions, "EXTRA_IMAGES"); const char* pszExtraStream = CSLFetchNameValue(papszOptions, "EXTRA_STREAM"); const char* pszExtraLayerName = CSLFetchNameValue(papszOptions, "EXTRA_LAYER_NAME"); const char* pszOGRDisplayField = CSLFetchNameValue(papszOptions, "OGR_DISPLAY_FIELD"); const char* pszOGRDisplayLayerNames = CSLFetchNameValue(papszOptions, "OGR_DISPLAY_LAYER_NAMES"); int bWriteOGRAttributes = CSLFetchBoolean(papszOptions, "OGR_WRITE_ATTRIBUTES", TRUE); const char* pszOGRLinkField = CSLFetchNameValue(papszOptions, "OGR_LINK_FIELD"); const char* pszOffLayers = CSLFetchNameValue(papszOptions, "OFF_LAYERS"); const char* pszExclusiveLayers = CSLFetchNameValue(papszOptions, "EXCLUSIVE_LAYERS"); const char* pszJavascript = CSLFetchNameValue(papszOptions, "JAVASCRIPT"); const char* pszJavascriptFile = CSLFetchNameValue(papszOptions, "JAVASCRIPT_FILE"); /* -------------------------------------------------------------------- */ /* Create file. */ /* -------------------------------------------------------------------- */ VSILFILE* fp = VSIFOpenL(GetDescription(), "wb"); if( fp == NULL ) { CPLError( CE_Failure, CPLE_OpenFailed, "Unable to create PDF file %s.\n", GetDescription() ); return OGRERR_FAILURE; } GDALPDFWriter oWriter(fp); double dfRatio = (sGlobalExtent.MaxY - sGlobalExtent.MinY) / (sGlobalExtent.MaxX - sGlobalExtent.MinX); int nWidth, nHeight; if (dfRatio < 1) { nWidth = 1024; nHeight = nWidth * dfRatio; } else { nHeight = 1024; nWidth = nHeight / dfRatio; } GDALDataset* poSrcDS = MEMDataset::Create( "MEM:::", nWidth, nHeight, 0, GDT_Byte, NULL ); double adfGeoTransform[6]; adfGeoTransform[0] = sGlobalExtent.MinX; adfGeoTransform[1] = (sGlobalExtent.MaxX - sGlobalExtent.MinX) / nWidth; adfGeoTransform[2] = 0; adfGeoTransform[3] = sGlobalExtent.MaxY; adfGeoTransform[4] = 0; adfGeoTransform[5] = - (sGlobalExtent.MaxY - sGlobalExtent.MinY) / nHeight; poSrcDS->SetGeoTransform(adfGeoTransform); OGRSpatialReference* poSRS = papoLayers[0]->GetSpatialRef(); if (poSRS) { char* pszWKT = NULL; poSRS->exportToWkt(&pszWKT); poSrcDS->SetProjection(pszWKT); CPLFree(pszWKT); } oWriter.SetInfo(poSrcDS, papszOptions); oWriter.StartPage(poSrcDS, dfDPI, pszGEO_ENCODING, pszNEATLINE, &sMargins, eStreamCompressMethod, bWriteOGRAttributes); int iObj = 0; char** papszLayerNames = CSLTokenizeString2(pszOGRDisplayLayerNames,",",0); for(int i=0;i<nLayers;i++) { CPLString osLayerName; if (CSLCount(papszLayerNames) < nLayers) osLayerName = papoLayers[i]->GetName(); else osLayerName = papszLayerNames[i]; oWriter.WriteOGRLayer((OGRDataSourceH)this, i, pszOGRDisplayField, pszOGRLinkField, osLayerName, bWriteOGRAttributes, iObj); } CSLDestroy(papszLayerNames); oWriter.EndPage(pszExtraImages, pszExtraStream, pszExtraLayerName, pszOffLayers, pszExclusiveLayers); if (pszJavascript) oWriter.WriteJavascript(pszJavascript); else if (pszJavascriptFile) oWriter.WriteJavascriptFile(pszJavascriptFile); oWriter.Close(); delete poSrcDS; return OGRERR_NONE; }