void C_AreaEvent::PushEvent( Poco::Net::StreamSocket& sktClient, LPCTSTR pszMac ) { m_PushedVecMutex.lock(); for (EventList::iterator it = m_vecPushedEvent.begin(); it != m_vecPushedEvent.end(); ) { if(CompareTime((*it)->szEndTime.c_str() , GetCurrTime().c_str()) < 0) it = m_vecPushedEvent.erase(it); else ++it; } m_PushedVecMutex.unlock(); tstring szAreaid = m_DBOperate.GetAreaidByMac(pszMac); if(szAreaid.compare(_T("")) == 0) return; m_PushedVecMutex.lock(); for (EventList::iterator itor = m_vecPushedEvent.begin(); itor != m_vecPushedEvent.end(); ++itor) { if((*itor)->szAreaId == szAreaid) { tstring szJson = GetJsonText(*itor); sktClient.sendBytes(szJson.c_str(), szJson.length()); } } m_PushedVecMutex.unlock(); }
tstring C_AreaEvent::GetJsonText( Event *pEvent ) { C_StringConvertor convertor; convertor.SetUnicodeString(GetCurrTime().c_str()); LPCSTR lpCurTime = convertor.GetMultiByte(); C_StringConvertor convertor2; convertor2.SetUnicodeString(pEvent->szEndTime.c_str()); LPCSTR lpEndTime = convertor2.GetMultiByte(); time_t lCurTime = C_TimeHelper::TimeStrToLong((CHAR*)lpCurTime); time_t lEndTime = C_TimeHelper::TimeStrToLong((CHAR*)lpEndTime); long nPlayTime = lEndTime - lCurTime; if(nPlayTime < 0) return _T(""); char cPlayTime[20]; itoa(nPlayTime,cPlayTime,10); tstring szPlayTime = cPlayTime; m_NetCmdComposer.SetCmdName(_T("content embed")); m_NetCmdComposer.SetCmdType(_T("request")); m_NetCmdComposer.AddParameters(_T("resource type"), pEvent->szType.c_str()); m_NetCmdComposer.AddParameters(_T("content"), pEvent->szContent.c_str()); m_NetCmdComposer.AddParameters(_T("playtime"), szPlayTime.c_str()); m_NetCmdComposer.AppendPara2Root(); return m_NetCmdComposer.Compose(); }
void CFrameTimer::OnNewFrame() { DWORD dwLastTime = GetCurrTime(); m_iBufferIndex = (m_iBufferIndex + 1) % g_iFrameTimingCount; m_dwTimings[m_iBufferIndex] = GetTickCount(); m_dwDeltaT = m_dwTimings[m_iBufferIndex] - dwLastTime; }
uint32 ElunaUtil::GetTimeDiff(uint32 oldMSTime) { #ifndef TRINITY return WorldTimer::getMSTimeDiff(oldMSTime, GetCurrTime()); #else return GetMSTimeDiffToNow(oldMSTime); #endif }
/* * Class: com_zjhlogo_spank_SpankLibrary * Method: update * Signature: ()V */ JNIEXPORT void JNICALL Java_com_zjhlogo_spank_SpankLibrary_update(JNIEnv* env, jclass cls) { if (g_bFirstStep) { g_nCurrTime = GetCurrTime(); g_nPrevTime = g_nCurrTime; g_bFirstStep = false; } else { g_nCurrTime = GetCurrTime(); } ICore::GetInstance().Update((g_nCurrTime - g_nPrevTime)/1000.0f); g_nPrevTime = g_nCurrTime; }
inline void SPEEDSCTRL::LimitSpeed(double TotalData, DWORD Unit, double Speed_Per_Sec) { if(Speed_Per_Sec == 0) return; DataUnit = Unit; CurrTime = GetCurrTime(); DoDelay(BaseTime, CurrTime, TotalData - PrevSize, Speed_Per_Sec/1000); PrevTime = CurrTime; PrevSpeed = Speed_Per_Sec/1000; }
void NumbersHolder::CreateNumber(Dim i) { Sprite *sprite = new Sprite(218, 20, AnimationFilmHolder::GetFilm( std::string(names.at(i)) )); MovingAnimation* aMovAnimn = (MovingAnimation*) new FrameRangeAnimation( 0, 0, 0, 0, 1000, true, ParseMarioInfo::GetAnimationIdOf(ParseMarioInfo::GetIndexOf(name[i])) ); MovingAnimator* aMovAnimr = (MovingAnimator*)new FrameRangeAnimator(); suspending[i].push_back( aMovAnimr ); aMovAnimr->Start( sprite, aMovAnimn, GetCurrTime()); }
void NumbersHolder::InitEpi() { Sprite *sprite = new Sprite(100, 20, AnimationFilmHolder::GetFilm( std::string("epi") )); MovingAnimation* aMovAnimn = (MovingAnimation*) new FrameRangeAnimation( 0, 0, 0, 0, 1000, true, ParseMarioInfo::GetAnimationIdOf(ParseMarioInfo::GetIndexOf("epi")) ); MovingAnimator* aMovAnimr = (MovingAnimator*)new FrameRangeAnimator(); Epi = aMovAnimr; aMovAnimr->Start( sprite, aMovAnimn, GetCurrTime()); AnimatorHolder::Register( aMovAnimr ); AnimatorHolder::MarkAsRunning(Epi); }
void NumbersHolder::InitCoin() { Sprite *sprite = new Sprite(85, 15, AnimationFilmHolder::GetFilm( std::string("coinanimation") )); MovingAnimation* aMovAnimn = (MovingAnimation*) new FrameRangeAnimation( 0, 2, 0, 0, 200, true, ParseMarioInfo::GetAnimationIdOf(ParseMarioInfo::GetIndexOf("coinanimation")) ); MovingAnimator* aMovAnimr = (MovingAnimator*)new FrameRangeAnimator(); Coin = aMovAnimr; aMovAnimr->Start( sprite, aMovAnimn, GetCurrTime()); AnimatorHolder::Register( aMovAnimr ); AnimatorHolder::MarkAsRunning(Coin); }
int RunScript(char* pstrFilename) { // Initialize the runtime environment script_env *sc = Poly_Initialize(); // 注册宿主api Poly_RegisterHostFunc(POLY_GLOBAL_FUNC, "Average", average); Poly_RegisterHostFunc(POLY_GLOBAL_FUNC, "Explode", h_PrintInt); Poly_RegisterHostFunc(POLY_GLOBAL_FUNC, "pause", poly_pause); Poly_RegisterHostFunc(POLY_GLOBAL_FUNC, "Division", h_Division); Poly_RegisterHostFunc(POLY_GLOBAL_FUNC, "PrintString", h_PrintString); // Load the demo script int iErrorCode = Poly_LoadScript(sc, pstrFilename); // Check for an error if (iErrorCode != POLY_LOAD_OK) { printf("载入脚本失败\n"); exit(1); } unsigned long start = GetCurrTime(); // Run we're loaded script from Main() Poly_RunScript(sc, POLY_INFINITE_TIMESLICE); printf("耗时 %fs\n", (GetCurrTime() - start) / 1000.0); int iExitCode = Poly_GetExitCode(sc); // Free resources and perform general cleanup Poly_ShutDown(sc); return iExitCode; }
void GreenKoopa::Dead(const char* id) { Sprite *sprite = new Sprite(20, 100, AnimationFilmHolder::GetFilm( std::string(id) )); MovingAnimation* aMovAnimn = (MovingAnimation*) new FrameRangeAnimation( 0, 0, 0, 0, 10000, false, ParseMarioInfo::GetAnimationIdOf(ParseMarioInfo::GetIndexOf( id ) ) ); MovingAnimator* aMovAnimr = (MovingAnimator*)new FrameRangeAnimator(); suspendingdead[id].push_back( aMovAnimr ); aMovAnimr->Start( sprite, aMovAnimn, GetCurrTime()); aMovAnimr->SetOnFinish(ComeOutFromShell, NULL); AnimatorHolder::Register( aMovAnimr ); }
void GreenKoopa::Create(const char* id) { Sprite *greenKoopaSprite = new Sprite(20, 100, AnimationFilmHolder::GetFilm( std::string(id) )); MovingAnimation* aMovAnimn = (MovingAnimation*) new FrameRangeAnimation( 0, 1, -2, 0, delay, true, ParseMarioInfo::GetIndexOf(id) ); MovingAnimator* aMovAnimr = (MovingAnimator*)new FrameRangeAnimator(); suspending[id].push_back( aMovAnimr ); aMovAnimr->Start( greenKoopaSprite, aMovAnimn, GetCurrTime()); //aMovAnimr->SetOnFinish(Mario::MarioFinishWalking, NULL); AnimatorHolder::Register( aMovAnimr ); }
void CCryptAes::GenerateKey(unsigned char *pKey, int keyLen) { assert(NULL != pKey); assert(keyLen >= 16); char seed[4]; TVT_DATE_TIME dateTime = GetCurrTime(); memcpy(seed, &dateTime.microsecond, 3); unsigned long tickCount = PUB_GetTickCount(); memcpy(seed+3, &tickCount, 1); RAND_seed(seed, 4); int ret = RAND_bytes(pKey, 16); if(ret != 1) { assert(false); } }
void Eluna::RunScripts() { uint32 oldMSTime = GetCurrTime(); uint32 count = 0; ScriptList scripts; scripts.insert(scripts.end(), lua_extensions.begin(), lua_extensions.end()); scripts.insert(scripts.end(), lua_scripts.begin(), lua_scripts.end()); lua_getglobal(L, "package"); luaL_getsubtable(L, -1, "loaded"); int modules = lua_gettop(L); for (ScriptList::const_iterator it = scripts.begin(); it != scripts.end(); ++it) { lua_getfield(L, modules, it->modulepath.c_str()); if (!lua_isnoneornil(L, -1)) { lua_pop(L, 1); ELUNA_LOG_DEBUG("[Eluna]: Extension was already loaded or required `%s`", it->filepath.c_str()); continue; } lua_pop(L, 1); if (!luaL_loadfile(L, it->filepath.c_str()) && !lua_pcall(L, 0, 1, 0)) { if (!lua_toboolean(L, -1)) { lua_pop(L, 1); Push(L, true); } lua_setfield(L, modules, it->modulepath.c_str()); // successfully loaded and ran file ELUNA_LOG_DEBUG("[Eluna]: Successfully loaded `%s`", it->filepath.c_str()); ++count; continue; } ELUNA_LOG_ERROR("[Eluna]: Error loading extension `%s`", it->filepath.c_str()); report(L); } lua_pop(L, 2); ELUNA_LOG_INFO("[Eluna]: Executed %u Lua scripts in %u ms", count, GetTimeDiff(oldMSTime)); }
void Eluna::Initialize() { uint32 oldMSTime = GetCurrTime(); lua_scripts.clear(); lua_extensions.clear(); lua_folderpath = eConfigMgr->GetStringDefault("Eluna.ScriptPath", "lua_scripts"); #if PLATFORM == PLATFORM_UNIX || PLATFORM == PLATFORM_APPLE if (lua_folderpath[0] == '~') if (const char* home = getenv("HOME")) lua_folderpath.replace(0, 1, home); #endif ELUNA_LOG_INFO("[Eluna]: Searching scripts from `%s`", lua_folderpath.c_str()); GetScripts(lua_folderpath + "/extensions", lua_extensions); GetScripts(lua_folderpath, lua_scripts); ELUNA_LOG_DEBUG("[Eluna]: Loaded %u scripts in %u ms", uint32(lua_scripts.size()), GetTimeDiff(oldMSTime)); // Create global eluna new Eluna(); }
void C_AreaEvent::DoUpdateEventList() { while (::WaitForSingleObject(m_hStopEvent, 0) != WAIT_OBJECT_0) { m_PushVecMutex.lock(); for (EventList::iterator it = m_vecEventList.begin(); it != m_vecEventList.end();) { tstring szAreaid = (*it)->szAreaId; tstring szStartTime = (*it)->szStartTime; if(CompareTime(szStartTime.c_str(), GetCurrTime().c_str()) <= 0 ) { tstring szJson = GetJsonText(*it); StringVector vecMacList; m_DBOperate.GetMacListByAreaid(vecMacList, szAreaid.c_str()); for (StringVector::iterator itor = vecMacList.begin(); itor != vecMacList.end(); ++itor) { Poco::Net::StreamSocket* psktClient = C_ClientMac2Socket::GetInstance()->FindSocketByMacAddr((*itor).c_str()); if (psktClient != NULL) psktClient->sendBytes(szJson.c_str(), szJson.length()); } m_PushedVecMutex.lock(); m_vecPushedEvent.push_back(*it); m_PushedVecMutex.unlock(); it = m_vecEventList.erase(it); } else ++it; } m_PushVecMutex.unlock(); Sleep(10000);//10s } }
bool ConvertXML2PO(std::string LangDir, std::string LCode, int nPlurals, std::string PluralForm, bool bIsForeignLang) { int stringCount = 0; std::string OutputPOFilename; OutputPOFilename = LangDir + "strings.po"; // Initalize the output po document pPOTFile = fopen (OutputPOFilename.c_str(),"wb"); if (pPOTFile == NULL) { printf("Error opening output file: %s\n", OutputPOFilename.c_str()); return false; } printf("%s\t\t", LCode.c_str()); fprintf(pPOTFile, "# XBMC Media Center language file\n" "%s" "%s%s%s%s%s%s%s%s%s" "msgid \"\"\n" "msgstr \"\"\n" "\"Project-Id-Version: %s\\n\"\n" "\"Report-Msgid-Bugs-To: [email protected]\\n\"\n" "\"POT-Creation-Date: %s\\n\"\n" "\"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n\"\n" "\"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n\"\n" "\"Language-Team: LANGUAGE\\n\"\n" "\"MIME-Version: 1.0\\n\"\n" "\"Content-Type: text/plain; charset=UTF-8\\n\"\n" "\"Content-Transfer-Encoding: 8bit\\n\"\n" "\"Language: %s\\n\"\n" "\"Plural-Forms: nplurals=%i; plural=%s\\n\"\n", (projType == CORE) ? ("XBMC " + ProjVersion + "\n").c_str() : "", (projType == CORE || projType == UNKNOWN) ? "" : "# Addon Name: ", (projType == CORE || projType == UNKNOWN) ? "" : ProjTextName.c_str(), (projType == CORE || projType == UNKNOWN) ? "" : "\n# Addon id: ", (projType == CORE || projType == UNKNOWN) ? "" : ProjName.c_str(), (projType == CORE || projType == UNKNOWN) ? "" : "\n# Addon version: ", (projType == CORE || projType == UNKNOWN) ? "" : ProjVersion.c_str(), (projType == CORE || projType == UNKNOWN) ? "" : "\n# Addon Provider: ", (projType == CORE || projType == UNKNOWN) ? "" : ProjProvider.c_str(), (projType == CORE || projType == UNKNOWN) ? "" : "\n", (projType == CORE) ? "XBMC-Main" : "XBMC-Addons", GetCurrTime().c_str(), (!LCode.empty()) ? LCode.c_str() : "LANGUAGE", nPlurals, PluralForm.c_str()); bhasLFWritten =false; if (!mapAddonXMLData["en"].strSummary.empty()) { WriteLF(pPOTFile); WriteStrLine("msgctxt ", "Addon Summary", addonXMLEncoding); WriteStrLine("msgid ", mapAddonXMLData["en"].strSummary.c_str(), addonXMLEncoding); WriteStrLine("msgstr ", LCode == "en" ? "": mapAddonXMLData[LCode].strSummary.c_str(), addonXMLEncoding); bhasLFWritten =false; stringCount++; } if (!mapAddonXMLData["en"].strDescription.empty()) { WriteLF(pPOTFile); WriteStrLine("msgctxt ", "Addon Description", addonXMLEncoding); WriteStrLine("msgid ", mapAddonXMLData["en"].strDescription.c_str(), addonXMLEncoding); WriteStrLine("msgstr ", LCode == "en" ? "": mapAddonXMLData[LCode].strDescription.c_str(), addonXMLEncoding); bhasLFWritten =false; stringCount++; } if (!mapAddonXMLData["en"].strDisclaimer.empty()) { WriteLF(pPOTFile); WriteStrLine("msgctxt ", "Addon Disclaimer", addonXMLEncoding); WriteStrLine("msgid ", mapAddonXMLData["en"].strDisclaimer.c_str(), addonXMLEncoding); WriteStrLine("msgstr ", LCode == "en" ? "": mapAddonXMLData[LCode].strDisclaimer.c_str(), addonXMLEncoding); bhasLFWritten =false; stringCount++; } // if (projType == ADDON_NOSTRINGS) // return true; int previd = -1; for (itSourceXmlId = mapSourceXmlId.begin(); itSourceXmlId != mapSourceXmlId.end(); itSourceXmlId++) { int id = itSourceXmlId->first; std::string value = itSourceXmlId->second; bhasLFWritten = false; //create comment lines, if empty string id or ids found and //re-create original xml comments between entries. Only for the source language if (!bIsForeignLang) WriteComments(previd, true); if ((id-previd >= 2) && !bIsForeignLang && previd > -1) { WriteLF(pPOTFile); if (id-previd == 2) fprintf(pPOTFile,"#empty string with id %i\n", id-1); if (id-previd > 2) fprintf(pPOTFile,"#empty strings from id %i to %i\n", previd+1, id-1); } bhasLFWritten = false; //write comment originally placed next to the string entry //convert it into #. style gettext comment if (!bIsForeignLang) WriteComments(id, false); //create msgctxt, including the string id WriteLF(pPOTFile); fprintf(pPOTFile,"msgctxt \"#%i\"\n", id); //create msgid and msgstr lines WriteLF(pPOTFile); WriteStrLine("msgid ", value.c_str(), sourceXMLEncoding); if (bIsForeignLang) { itForeignXmlId = mapForeignXmlId.find(id); if (itForeignXmlId != mapForeignXmlId.end()) { stringCount++; WriteStrLine("msgstr ", itForeignXmlId->second.c_str(), foreignXMLEncoding); } else fprintf(pPOTFile,"msgstr \"\"\n"); } else fprintf(pPOTFile,"msgstr \"\"\n"); if (!bIsForeignLang) stringCount++; previd =id; } fclose(pPOTFile); printf("%i\t\t", stringCount); printf("%s\n", OutputPOFilename.erase(0,WorkingDir.length()).c_str()); mapForeignXmlId.clear(); return true; }
bool ConvertXML2PO(std::string LangDir, std::string LCode, int nPlurals, std::string PluralForm, bool bIsForeignLang) { int contextCount = 0; int stringCountSource = 0; int stringCountForeign = 0; std::string OutputPOFilename; OutputPOFilename = LangDir + "strings.po"; // Initalize the output po document pPOTFile = fopen (OutputPOFilename.c_str(),"wb"); if (pPOTFile == NULL) { printf("Error opening output file: %s\n", OutputPOFilename.c_str()); return false; } printf("%s\t\t", LCode.c_str()); fprintf(pPOTFile, "# XBMC Media Center language file\n" "msgid \"\"\n" "msgstr \"\"\n" "\"Project-Id-Version: %s-%s\\n\"\n" "\"Report-Msgid-Bugs-To: [email protected]\\n\"\n" "\"POT-Creation-Date: %s\\n\"\n" "\"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\\n\"\n" "\"Last-Translator: FULL NAME <EMAIL@ADDRESS>\\n\"\n" "\"Language-Team: LANGUAGE\\n\"\n" "\"MIME-Version: 1.0\\n\"\n" "\"Content-Type: text/plain; charset=UTF-8\\n\"\n" "\"Content-Transfer-Encoding: 8bit\\n\"\n" "\"Language: %s\\n\"\n" "\"Plural-Forms: nplurals=%i; plural=%s\\n\"\n\n", (pProjectName != NULL) ? pProjectName : "xbmc-unnamed", (pVersionNumber != NULL) ? pVersionNumber : "rev_unknown", GetCurrTime().c_str(), (!LCode.empty()) ? LCode.c_str() : "LANGUAGE", nPlurals, PluralForm.c_str()); int previd = -1; bool bCommentWritten = false; for (itSourceXmlId = mapSourceXmlId.begin(); itSourceXmlId != mapSourceXmlId.end(); itSourceXmlId++) { int id = itSourceXmlId->first; std::string value = itSourceXmlId->second; //create comment lines, if empty string id or ids found and //re-create original xml comments between entries. Only for the source language bCommentWritten = false; if (!bIsForeignLang) bCommentWritten = WriteComments(previd, true); if ((id-previd >= 2) && !bIsForeignLang) { if (id-previd == 2 && previd > -1) fprintf(pPOTFile,"#empty string with id %i\n", id-1); if (id-previd > 2 && previd > -1) fprintf(pPOTFile,"#empty strings from id %i to %i\n", previd+1, id-1); bCommentWritten = true; } if (bCommentWritten) fprintf(pPOTFile, "\n"); //create comment, including string id fprintf(pPOTFile,"#: id:%i\n", id); //write comment originally placed next to the string entry //convert it into #. style gettext comment if (!bIsForeignLang) WriteComments(id, false); if (multimapSourceXmlStrings.count(value) > 1) // if we have multiple IDs for the same string value { //create autogenerated context message for multiple msgid entries fprintf(pPOTFile,"msgctxt \"Auto context with id %i\"\n", id); contextCount++; } //create msgid and msgstr lines WriteStrLine("msgid ", value.c_str(), sourceXMLEncoding); if (bIsForeignLang) { itForeignXmlId = mapForeignXmlId.find(id); if (itForeignXmlId != mapForeignXmlId.end()) { stringCountForeign++; WriteStrLine("msgstr ", itForeignXmlId->second.c_str(), foreignXMLEncoding); fprintf(pPOTFile,"\n"); } else fprintf(pPOTFile,"msgstr \"\"\n\n"); } else fprintf(pPOTFile,"msgstr \"\"\n\n"); stringCountSource++; previd =id; } fclose(pPOTFile); printf("%i\t\t", bIsForeignLang ? stringCountForeign : stringCountSource); printf("%i\t\t", contextCount); printf("%s\n", OutputPOFilename.erase(0,WorkingDir.length()).c_str()); mapForeignXmlId.clear(); return true; }
inline double SPEEDSCTRL::Init() { return BaseTime = PrevTime = GetCurrTime(); }