double CKRSView::GetStartX(int num_list) { double start_value; if(GetActiveData() == NULL) return 0; if(m_parOfView->flag_time_glub) { if(m_ptmData == NULL) return GetCurTime(); if(m_ptmData->GetSizeData() == 0) start_value = GetCurTime(); else { if(m_ptmData->GetLastData() - m_ptmData->GetFirstData() < GetLenX(num_list)) start_value = m_ptmData->GetFirstData(); else start_value = m_ptmData->GetLastData() - GetLenX(num_list); } } else { if(m_pcurGlub == NULL) return (pGlubina == NULL) ? 0 : pGlubina->fCur; if(m_pcurGlub->GetSizeData() == 0) start_value = pGlubina->fCur; else { if(m_pcurGlub->GetLastData() - m_pcurGlub->GetFirstData() < GetLenX(num_list)) start_value = m_pcurGlub->GetFirstData(); else start_value = m_pcurGlub->GetLastData() - GetLenX(num_list); } } return start_value; }
void AutoFrameSkip_NextFrame() { endticks = GetCurTime(); // calculate time since last frame u64 diffticks = endticks - beginticks; float diff = (float)diffticks / afsfreq; // calculate time since last frame not including throttle sleep time if(!preThrottleEndticks) // if we didn't throttle, use the non-throttle time preThrottleEndticks = endticks; u64 diffticksUnthrottled = preThrottleEndticks - beginticks; float diffUnthrottled = (float)diffticksUnthrottled / afsfreq; float error = diffUnthrottled - desiredspf; // reset way-out-of-range values if(diff > 1) diff = 1; if(error > 1 || error < -1) error = 0; if(diffUnthrottled > 1) diffUnthrottled = desiredspf; float derivative = (error - lastError) / diff; lastError = error; integral = integral + (error * diff); integral *= 0.99f; // since our integral isn't reliable, reduce it to 0 over time. // "PID controller" constants // this stuff is probably being done all wrong, but these seem to work ok static const float Kp = 40.0f; static const float Ki = 0.55f; static const float Kd = 0.04f; float errorTerm = error * Kp; float derivativeTerm = derivative * Kd; float integralTerm = integral * Ki; float adjustment = errorTerm + derivativeTerm + integralTerm; // apply the output adjustment fSkipFrames += adjustment; // if we're running too slowly, prevent the throttle from kicking in if(adjustment > 0 && fSkipFrames > 0) ltime-=tfreq/desiredfps; preThrottleEndticks = 0; beginticks = GetCurTime(); }
double classTimeControl::GetDifferenceTime() { double s_sys_time=GetCurTime(); if (!run) return 0; return s_sys_time-old_time_mark; }
//发送头部 bool CHttpProtocol::SendHeader(PREQUEST pReq) { int iResult; char Header[2048]; while(false == FileExist(pReq)) {//文件不存在,更改到错误标志文件路径 strcpy_s(pReq->szFileName, strRootDir); strcat_s(pReq->szFileName, "/error.html"); } GetCurTime(Time); //取得文件长度 DWORD length; length = GetFileSize(pReq->hFile, NULL); //取得文件的last-modified时间 char last_modified[100]; GetLastModified(pReq->hFile, (char*)last_modified); //取得文件的类型 char ContenType[100]; GetContenType(pReq, (char*)ContenType); sprintf_s(Header, sizeof(Header), "HTTP/1.0 %s\r\nDate: %s\r\nServer: %s\r\nContent-Type: %s\r\nContent-Length: %d\r\nLast-Modified: %s\r\n\r\n", HTTP_STATUS_OK, Time, // Date "My Web Server", // Server ContenType, // Content-Type length, // Content-length last_modified); // Last-Modified //发送头部 iResult = send(pReq->Socket, Header, strlen(Header), 0); pReq->dwSend += iResult; if (iResult == SOCKET_ERROR) { printf("send failed with error: %d\n", WSAGetLastError()); return false; } return true; }
int CFileLog::CheckFile() { char szFileName[256] = {0}; long lCurTime = 0; int length = 0; //要检查日期,一旦日期发生变化写日志就要修改 lCurTime = GetCurTime(); if (lCurTime > m_lCurTime) { m_lCurTime = lCurTime; m_iFileNum = 0; ReOpen(); } else { //超过50M就写下一个文件 length = m_file.tellg(); if (length > MAX_FILE_LENGTH) { m_file.flush(); m_iFileNum++; ReOpen(); } } return 0; }
void SpeedThrottle() { AutoFrameSkip_BeforeThrottle(); waiter: if(FastForward) return; u64 ttime = GetCurTime(); if((ttime - ltime) < (tfreq / desiredfps)) { u64 sleepy; sleepy = (tfreq / desiredfps) - (ttime - ltime); sleepy *= 1000; if(tfreq >= 65536) sleepy /= afsfreq; else sleepy = 0; if(sleepy >= 10) Sleep((sleepy / 2)); // reduce it further beacuse Sleep usually sleeps for more than the amount we tell it to #ifndef ANDROID else if(sleepy > 0) // spin for <1 millisecond waits SwitchToThread(); // limit to other threads on the same CPU core for other short waits #endif goto waiter; } if( (ttime-ltime) >= (tfreq*4/desiredfps)) ltime=ttime; else ltime+=tfreq/desiredfps; }
int main(int argc,char** argv) { pthread_t ListenerThread; pthread_t PublisherThread; SDMInit(argc,argv); myPort = getPort(); if(myPort == SDM_PM_NOT_AVAILABLE) { printf("No PM is available to get port from!\n"); printf("Using port 5001\n"); myPort = 5001; } pthread_attr_t threadAttr; pthread_attr_init(&threadAttr); pthread_attr_setstacksize(&threadAttr, THREAD_STACK_SIZE); pthread_create(&ListenerThread,&threadAttr,&Listener,NULL); usleep(1000); SDMHello hello; hello.source.setPort(myPort); hello.type = 'A'; double endTime = 0; double timeOut = 5.0; while(!helloReply) { if(GetCurTime() > endTime) { hello.Send(); printf("Sending Hello\n"); endTime = GetCurTime() + timeOut; } usleep(10000); } while (waitForReg) { usleep(10000); } printf("Registering xTEDS\n"); RegisterxTEDS(); pthread_create(&PublisherThread,&threadAttr,&Publisher,NULL); pthread_join(PublisherThread,NULL); CancelxTEDS(); pthread_cancel(ListenerThread); pthread_join(ListenerThread,NULL); }
// open archive void *PAK_Open(tOpenArchiveData *arch) { archive_t *a=NULL; int n; // find free arhive: for(n=0; n<2; n++) { if(!arh[n].in_use) { a=&arh[n]; break; } } if(n==2) { arch->OpenResult=E_UNKNOWN_FORMAT; return NULL; } // trying to open! arch->OpenResult=E_UNKNOWN_FORMAT; // CTAHDAPTHAR OTMA3KA [standart disclamer]! memset(a, 0, sizeof(archive_t)); a->fp=fopen(arch->ArcName, "rb"); if(!a->fp) return NULL; if(!fread(&a->header, sizeof(pakheader_t), 1, a->fp)) goto error; // Signature check if( a->header.magic[0]!='P' || a->header.magic[1]!='A' || a->header.magic[2]!='C' || a->header.magic[3]!='K') {// Not a PAK file! goto error; } a->total=a->header.dirsize/sizeof(pakentry_t); a->entry=malloc(a->header.dirsize); if(!a->entry) goto error; fseek(a->fp, a->header.diroffset, SEEK_SET); if(!fread(a->entry, a->header.dirsize, 1, a->fp)) goto error; // set vars strcpy(a->name, arch->ArcName); a->current=0; a->in_use=1; a->opentime=GetCurTime(); a->mode=arch->OpenMode; arch->OpenResult=0; return a; error: // free all & return error if(a->entry) free(a->entry); if(a->fp) fclose(a->fp); return NULL; }
UINT32 CPlayer::GetKillTime() { if ( m_KillTime ) { return GetCurTime() - m_KillTime; } return 0; }
string PlannerCommandInterface::ActivateEvent(bool enabled) { dragging = false; currentLink=-1; planner->currentPath.ramps.resize(0); lastPlanTime = nextPlanTime = GetCurTime(); return ""; }
UINT32 CPlayer::GetCloseSocketTime() { if ( m_SocketCloseTime ) { return GetCurTime() - m_SocketCloseTime; } return 0; }
void CCardsHandler::AddDenys(CCard *card) { const char *cardnum = card->GetCardNumber(); const char *account = card->GetSellerAccount(); if(!cardnum) return ; map<string,DenyInfo*>::iterator itC = _DenyCards.find(cardnum); if( itC == _DenyCards.end() ) // insert { // init di DenyInfo *di = new DenyInfo; di->last_time = GetCurTime(); di->times = 1; // inser di into map _DenyCards.insert(pair<string,DenyInfo*>(cardnum,di)); } else { itC->second->times++; itC->second->last_time = GetCurTime(); } if(!account) return ; map<string,DenyInfo*>::iterator itA = _DenyAccounts.find(account); if( itA == _DenyAccounts.end() ) // insert { // init di DenyInfo *di = new DenyInfo; di->last_time = GetCurTime(); di->times = 1; // inser di into map _DenyAccounts.insert(pair<string,DenyInfo*>(account,di)); } else { itA->second->times++; itA->second->last_time = GetCurTime(); } }
void AutoFrameSkip_IgnorePreviousDelay() { beginticks = GetCurTime(); // this seems to be a stable way of allowing the skip frames to // quickly adjust to a faster environment (e.g. after a loadstate) // without causing oscillation or a sudden change in skip rate fSkipFrames *= 0.5f; }
void JAnmSound::Render() { if (IsPlaying() && g_pSoundServer) { JAnmContext& ctx = GetContext(); if (ctx.m_bStateOnly) { Stop(); } else if (GetCurTime() >= GetDuration() && g_pSoundServer->IsPlaying( m_SoundID ) && !IsLooped()) { SetDuration( GetCurTime() + c_FltEpsilon ); } g_pSoundServer->Pause( m_SoundID, GetContext().m_TimeDelta == 0.0f || IsPaused() ); } JAnimation::Render(); } // JAnmSound::Render
classTimeControl::classTimeControl(bool start) { if (start) { old_time_mark=GetCurTime(); } else old_time_mark=0; run=start; }
bool need_update_code_compile() { BYTE ucBuf[6]; GetCurTime(ucBuf, 6); if( ucBuf[3] == 0x14 ) { return true; } return false; }
void AddFileLogTime(File_Action_Log &filelog) { char *pszTime = GetCurTime(); memcpy(filelog.szLogTime, pszTime, strlen(pszTime)); if (pszTime) { delete pszTime; pszTime = NULL; } }
BOOL CQuest::StartSubQuest( DWORD dwQuestIdx, DWORD dwSubQuestIdx ) { if( m_CurSubQuestInfoArray[dwSubQuestIdx] == NULL ) { m_CurSubQuestInfoArray[dwSubQuestIdx] = m_pQuestInfo->GetSubQuestInfo( dwSubQuestIdx ); m_SubQuestTable[dwSubQuestIdx].dwData = 0; m_SubQuestTable[dwSubQuestIdx].dwTime = GetCurTime(); return TRUE; } return FALSE; }
bool CPlayer::CloseSocket() { if( this->m_pClientSocket ) { this->m_pClientSocket->Close(); this->m_pClientSocket = NULL; } m_SocketCloseTime = GetCurTime(); return true; }
void Util::GetTimeStr(const size_t buf_size, char *time_stamp) { struct stTimeInfo timeInfo; timeInfo = GetCurTime(); sprintf_s(time_stamp, buf_size, "%4d/%02d/%02d %02d:%02d:%02d.%03d", timeInfo.year, timeInfo.month, timeInfo.day, timeInfo.hour, timeInfo.min, timeInfo.sec, timeInfo.msec); printf("NOW TIME:[%s]\n", time_stamp); }
void Thread::OnLoop() { long old_time = GetCurTime(); long tick_time = old_time; while(!flag_) { LoopNoDelay(); //data service long cur_time = GetCurTime(); if (cur_time - tick_time > 100) { Loop(cur_time); //logical service tick_time = cur_time; } if (cur_time - old_time >= 10) { usleep(0); old_time = cur_time; }else usleep((10 -(cur_time - old_time)) * 1000); } }
void CPlayer::DisAttachSocket() { DebugInfo("DisAttachSocket Start Socket=%d PID=%d",reinterpret_cast<int>(m_pClientSocket),m_PID); if( this->m_pClientSocket ) { this->m_pClientSocket->Close(); this->m_pClientSocket = NULL; } m_SocketCloseTime = GetCurTime(); DebugInfo("DisAttachSocket End"); }
bool IAppInterface::SendProtocol(int32_t fd, ProtocolContext *context, int32_t send_timeout_ms/*=-1*/) { if(fd<0 || context==NULL) return false; context->timeout_ms = send_timeout_ms; if(context->timeout_ms > 0) { uint64_t now; GetCurTime(now); context->expire_time = now+context->timeout_ms; } SendMap::iterator it = m_SendMap.find(fd); if(it == m_SendMap.end()) { ProtocolList temp_list; std::pair<SendMap::iterator, bool> result = m_SendMap.insert(std::make_pair(fd, temp_list)); if(result.second == false) { LOG_ERROR(logger, "add protocol to list failed. fd="<<fd<<", context="<<context); return false; } it = result.first; } ProtocolList *protocol_list = &it->second; /*ProtocolList::iterator list_it = protocol_list->begin(); for(; list_it!=protocol_list->end(); ++list_it) //按超时时间点从小到大排列 { ProtocolContext *temp_context = *list_it; if(context->expire_time < temp_context->expire_time) break; } protocol_list->insert(list_it, context); */ protocol_list->push_back(context); //直接添加到队列尾 //添加可写事件监控 int32_t timeout_ms = GetSocketIdleTimeout(); IEventServer *event_server = GetEventServer(); IEventHandler* event_handler = GetTransHandler(); assert(event_server != NULL); assert(event_handler != NULL); if(!event_server->SetEvent(fd, ET_WRITE, event_handler, timeout_ms)) { LOG_ERROR(logger, "add write event to event_server failed when send protocol. fd="<<fd<<", context="<<context); return false; } return true; }
BOOL CQuest::EndSubQuest( DWORD dwQuestIdx, DWORD dwSubQuestIdx ) { if( m_CurSubQuestInfoArray[dwSubQuestIdx] ) { m_CurSubQuestInfoArray[dwSubQuestIdx] = NULL; m_SubQuestTable[dwSubQuestIdx].dwData = 0; m_SubQuestTable[dwSubQuestIdx].dwTime = GetCurTime(); SetSubQuestFlag( dwSubQuestIdx ); if( dwSubQuestIdx == 0 ) // Quest Start { m_dwData = 0; } return TRUE; } return FALSE; }
double classTimeControl::GetChangeDifferenceTime() { double s_sys_time=GetCurTime(); double outTime; if (!run) { run=true; outTime=0; } else { outTime=s_sys_time-old_time_mark; } old_time_mark=s_sys_time; return outTime; }
void CPlayer::CheckMaxWinMoney(INT64 nWinMoney) { if ( nWinMoney > m_MaxWin ) { m_MaxWin = nWinMoney; m_MaxWinTime = GetCurTime(); SendMaxWin(); DBServerXY::WDB_MaxWin msgMW; msgMW.m_AID = m_AID; msgMW.m_PID = m_PID; msgMW.m_MaxWin = nWinMoney; msgMW.m_MaxWinTime = m_MaxWinTime; m_pServer->SendMsgToDBServer(msgMW); } }
void CPlayer::CheckMaxGameMoney() { if ( m_nGameMoney > m_MaxMoney ) { m_MaxMoney = m_nGameMoney; m_MaxMoneyTime = GetCurTime(); SendMaxMoney(); DBServerXY::WDB_MaxMoney wdbMM; wdbMM.m_AID = m_AID; wdbMM.m_PID = m_PID; wdbMM.m_MaxMoney = m_nGameMoney; wdbMM.m_MaxMoneyTime = m_MaxMoneyTime; m_pServer->SendMsgToDBServer(wdbMM); } }
void SessionMgr::save(Session* pSession) { if (NULL == pSession) { return; } unsigned __int64 sid = pSession->getSId(); if (0 == sid) { return; } SKeyInfo key; key.qKey = sid; unsigned int now = GetCurTime(); if (now >= pSession->getDestroyTime()) { m_db->Delete(m_writeOpt, key.nKey[1]); return; } string& str = pSession->getData(); if (str.empty()) { return; } static char szSaveBuff[1024 * 32]; SSessionTime* pTime = (SSessionTime*)szSaveBuff; pTime->uCreateTime = key.nKey[0]; pTime->uDestroyTime = pSession->getDestroyTime(); memcpy(szSaveBuff + sizeof(SSessionTime), str.c_str(), str.size()); string strData; strData.append(szSaveBuff, sizeof(SSessionTime) + str.size()); leveldb::Status ret = m_db->Put(m_writeOpt, key.nKey[1], strData); if (!ret.ok()) { SYS_CRITICAL("save session failed, sid = %llu", sid); } }
void CFileLog::Init() { char szAllPath[128] = {0}; //配置文件读取日志文件存放路径 TODO: memset(m_szFilePath, 0, sizeof(m_szFilePath)); auto strLogDir = ConfigIni::ReadStr("FILE", "FILENAME"); if (strLogDir == "") { std::cout << "read FILENAME failed" << std::endl; exit(-1); } strncpy(m_szFilePath, strLogDir.c_str(), sizeof(m_szFilePath)-1); //获取当前日期作为路径 m_lCurTime = GetCurTime(); snprintf(szAllPath, sizeof(szAllPath)-1, "%s/%ld", m_szFilePath, m_lCurTime ); CheckDir(szAllPath); ReOpen(); }
void CSimplePhysics::Simulate( CSimplePhysics::CNode *pNodes, int nNodes, CSimplePhysics::IHelper *pHelper, float dt, float flDamp ) { // Figure out how many time steps to run. m_flPredictedTime += dt; int newTimeStep = (int)ceil( m_flPredictedTime / m_flTimeStep ); int nTimeSteps = newTimeStep - m_iCurTimeStep; for( int iTimeStep=0; iTimeStep < nTimeSteps; iTimeStep++ ) { // Simulate everything.. for( int iNode=0; iNode < nNodes; iNode++ ) { CSimplePhysics::CNode *pNode = &pNodes[iNode]; // Apply forces. Vector vAccel; pHelper->GetNodeForces( pNodes, iNode, &vAccel ); Assert( vAccel.IsValid() ); Vector vPrevPos = pNode->m_vPos; pNode->m_vPos = pNode->m_vPos + (pNode->m_vPos - pNode->m_vPrevPos) * flDamp + vAccel * m_flTimeStepMul; pNode->m_vPrevPos = vPrevPos; } // Apply constraints. pHelper->ApplyConstraints( pNodes, nNodes ); } m_iCurTimeStep = newTimeStep; // Setup predicted positions. float flInterpolant = (m_flPredictedTime - (GetCurTime() - m_flTimeStep)) / m_flTimeStep; for( int iNode=0; iNode < nNodes; iNode++ ) { CSimplePhysics::CNode *pNode = &pNodes[iNode]; VectorLerp( pNode->m_vPrevPos, pNode->m_vPos, flInterpolant, pNode->m_vPredicted ); } }