bool IntervalIntersect(const Vector* A, int Anum, const Vector* B, int Bnum, const Vector& xAxis, const Vector& xOffset) { float min0, max0; float min1, max1; GetInterval(A, Anum, xAxis, min0, max0); GetInterval(B, Bnum, xAxis, min1, max1); float h = xOffset * xAxis; min0 += h; max0 += h; float d0 = min0 - max1; float d1 = min1 - max0; if (d0 > 0.0f || d1 > 0.0f) { return false; } else { return true; } }
UINT CDuiTimerBase::CalInterval() { if(!IsInverted() && GetInterval() < GetTotalTimer()){ if(GetCurTimer() + GetInterval() > GetTotalTimer() && GetCurTimer() < GetTotalTimer()) return m_iCurTimer = GetTotalTimer(); else if(GetCurTimer() + GetInterval() > GetTotalTimer() && IsRevers()){ m_bInverted = true; m_iCurTimer -= GetInterval(); return GetCurTimer(); } return m_iCurTimer += GetInterval(); } else if(IsInverted() && GetInterval() < GetTotalTimer()){ if(GetCurTimer() - GetInterval() < 0 && GetCurTimer() > 0) return m_iCurTimer = 0; else if(GetCurTimer() - GetInterval() < 0 && IsRevers()){ m_bInverted = false; m_iCurTimer += GetInterval(); return GetCurTimer(); } return m_iCurTimer -= GetInterval(); } return GetCurTimer(); }
/* * fn: 添加指定ID号的定时器 * fun: 定时器回调函数 * arg: 定时器回调函数参数 * second: 函数每隔多少秒执行一次 * timerId: out,定时器节点ID,根据他可以找到已经add 的定时器节点 * !!!注意: 1. 回调函数fun中不能再次调用定时器中的接口函数, 否则会造成死锁 !!! ( Init(), Destroy(), Add(...), Delete(id) ) 2. 建议回调函数尽量简单,不要阻塞 */ int ClTimer::Add( TIMER_CMD fun, void *arg, unsigned second, unsigned int *timerId ) { int nRet = -1; if ( m_TimerThread == 0 ) { TIMER_NODE_T *pTimer = ( TIMER_NODE_T * )Malloc( sizeof(TIMER_NODE_T) ); if ( pTimer != NULL ) { pTimer->id = GetTimerID(); pTimer->interval = GetInterval( second ); pTimer->elapse = 0; pTimer->fun = fun; pTimer->arg = arg; pTimer->next = NULL; if( NULL != timerId ) { *timerId = pTimer->id; } InsertTimerList( pTimer ); nRet = 0; } } return nRet; }
//////////////////////////////////////////////////////////////////////////// // Function to wait for the beginning of a second // (needed for accurate timing) //////////////////////////////////////////////////////////////////////////// void CClockTimer::Wait(int64_t lMilliSeconds) { time_t t, Bidon; time(&t); while (static_cast<int64_t>(time(&Bidon)) <= static_cast<int64_t>(t + lMilliSeconds / 1000)); GetInterval(); }
void T_Engine::StartEngine() { MSG msg; static int TickElapsed = 0; int nowTick; GameWinInit(); srand( (unsigned)time( NULL ) ); while (TRUE) { if (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) { if (msg.message == WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); } else { if (!GetSleep()) { nowTick = GetTickCount(); if (nowTick > TickElapsed) { TickElapsed = nowTick + GetInterval(); GameLogic(); GamePaint(bufferDC); HDC hDC = GetDC(m_hWnd); BitBlt(hDC, 0, 0, WIN_WIDTH, WIN_HEIGHT, bufferDC, 0, 0, SRCCOPY); ReleaseDC(m_hWnd, hDC); } } } } pEngine->GameEnd(); }
void ScheduledTask::Resume(void) // Resume (start) this scheduled task { Suspend(); mTaskId = ::SetTimer(NULL, 0, GetInterval(), TimerProc); mTimerMap[mTaskId] = this; }
//////////////////////////////////////////////////////////////////////////// // Function to wait for the beginning of a second // (needed for accurate timing) //////////////////////////////////////////////////////////////////////////// void CClockTimer::Wait(long lMilliSeconds) { time_t t, Bidon; time (&t); while ((long)(time(&Bidon)) <= (long)(t + lMilliSeconds / 1000)); GetInterval(); }
//start timer void CTimer::Start() { //stop timer if already exists if(GetTimerID()) Stop(); //start the timer m_TimerID=SDL_AddTimer(GetInterval(),CTimer::TimerProc,this); }
double Tachometer::PIDGet() { uint32_t interval = GetInterval(); if (interval) { return 60.e6 / (double) interval; } else { return 0.; } }
bool CDuiTimerBase::FinshTimered() { if(!IsLoop() && GetInterval() < GetTotalTimer()){ if(!IsRevers()) return GetCurTimer() > GetTotalTimer(); else if(IsRevers()) return GetCurTimer() < 0; } else if(IsLoop() && GetInterval() < GetTotalTimer()){ if(!IsRevers() && GetCurTimer() > GetTotalTimer()) m_iCurTimer = 0; else if(IsRevers() && GetCurTimer() < 0) m_iCurTimer = GetTotalTimer(); } if(GetInterval() >= GetTotalTimer()) m_iCurTimer += GetInterval(); return false; }
/************************************************************************* Function Name : UartCheckTxStat Arguments : Null Return : Null Description : Check TX state, if space time reached, set TX state to TX_IDLE. **************************************************************************/ void UartCheckTxStat(void) { if (txCtrl.stat == TX_FNS) { if ((!txCtrl.frmSpaceSet) || (GetInterval(txCtrl.lastTxTime) >= txCtrl.frmSpaceSet)) { txCtrl.stat = TX_IDLE; //UartInitTxInfo(); //unnecessary! } } }
bool wxQtTimerImpl::Start( int millisecs, bool oneShot ) { if ( !wxTimerImpl::Start( millisecs, oneShot ) ) return false; if ( m_timerId >= 0 ) return false; m_timerId = startTimer( GetInterval() ); return m_timerId >= 0; }
bool IntervalIntersect(const std::vector<float2> &aVertices, const std::vector<float2> &bVertices, const float2 &axis, const float2 &relPos, const Mat22 &xOrient, f32 &taxis, f32 tmax) { SATProjection proj0 = GetInterval(aVertices, axis * xOrient.Transpose()); SATProjection proj1 = GetInterval(bVertices, axis); f32 h = relPos.dot(axis); proj0.min += h; proj0.max += h; f32 d0 = proj0.min - proj1.max; f32 d1 = proj1.min - proj0.max; if(d0 > 0.0f || d1 > 0.0f) { return false; } taxis = d0 > d1 ? d0 : d1; return true; };
bool IntrLine2Triangle2<Real>::Find () { Real afDist[3]; int aiSign[3], iPositive, iNegative, iZero; TriangleLineRelations(m_pkLine->Origin,m_pkLine->Direction,*m_pkTriangle, afDist,aiSign,iPositive,iNegative,iZero); if (iPositive == 3 || iNegative == 3) { // No intersections. m_iQuantity = 0; m_iIntersectionType = IT_EMPTY; } else { Real afParam[2]; GetInterval(m_pkLine->Origin,m_pkLine->Direction,*m_pkTriangle,afDist, aiSign,afParam); Intersector1<Real> kIntr(afParam[0],afParam[1], -Math<Real>::MAX_REAL,+Math<Real>::MAX_REAL); kIntr.Find(); m_iQuantity = kIntr.GetQuantity(); if (m_iQuantity == 2) { // Segment intersection. m_iIntersectionType = IT_SEGMENT; m_akPoint[0] = m_pkLine->Origin + kIntr.GetOverlap(0)* m_pkLine->Direction; m_akPoint[1] = m_pkLine->Origin + kIntr.GetOverlap(1)* m_pkLine->Direction; } else if (m_iQuantity == 1) { // Point intersection. m_iIntersectionType = IT_POINT; m_akPoint[0] = m_pkLine->Origin + kIntr.GetOverlap(0)* m_pkLine->Direction; } else { // No intersections. m_iIntersectionType = IT_EMPTY; } } return m_iIntersectionType != IT_EMPTY; }
bool IntrLine2Triangle2<Real>::Find () { Real dist[3]; int sign[3], positive, negative, zero; TriangleLineRelations(mLine->Origin, mLine->Direction, *mTriangle, dist, sign, positive, negative, zero); if (positive == 3 || negative == 3) { // No intersections. mQuantity = 0; mIntersectionType = IT_EMPTY; } else { Real param[2]; GetInterval(mLine->Origin, mLine->Direction, *mTriangle, dist, sign, param); Intersector1<Real> intr(param[0], param[1], -Math<Real>::MAX_REAL, +Math<Real>::MAX_REAL); intr.Find(); mQuantity = intr.GetNumIntersections(); if (mQuantity == 2) { // Segment intersection. mIntersectionType = IT_SEGMENT; mPoint[0] = mLine->Origin + intr.GetIntersection(0)*mLine->Direction; mPoint[1] = mLine->Origin + intr.GetIntersection(1)*mLine->Direction; } else if (mQuantity == 1) { // Point intersection. mIntersectionType = IT_POINT; mPoint[0] = mLine->Origin + intr.GetIntersection(0)*mLine->Direction; } else { // No intersections. mIntersectionType = IT_EMPTY; } } return mIntersectionType != IT_EMPTY; }
void CIntervalPage::CreateNotes() { m_csNotesPlayed = ""; UpdateData(FALSE); m_vNotes.clear(); DWORD dwFirstNote = GetFirstNote(); DWORD dwInterval = GetInterval(); DWORD dwNextNote = dwFirstNote + dwInterval; m_vNotes.push_back(dwFirstNote); m_vNotes.push_back(dwNextNote); }
void CFrameTimer::addFrame() { Stop(); dt = GetInterval(); _nframes++; _print_nframes++; if (_print_interval != 0 && _nframes != 0 && (GetTotal() > _print_interval)) { float _print_fps = (float)(_print_nframes) / (_print_interval); CLog::getInstance()->addInfo(printStr + std::to_string((int)_print_fps)); if (needToCollectFps) fpsList->push_back(_print_fps); _print_nframes = 0; Reset(); } Continue(); }
//////////////////////////////////////////////////////////////////////////// // Function to wait for a clock tick // (needed for accurate timing) //////////////////////////////////////////////////////////////////////////// void CClockTimer::Wait(long lMilliSeconds) { long t = MilliSeconds(); while (MilliSeconds() <= t + lMilliSeconds) {} GetInterval(); }
//////////////////////////////////////////////////////////////////////////// // Function to wait for a clock tick // (needed for accurate timing) //////////////////////////////////////////////////////////////////////////// void CClockTimer::Wait(int64_t lMilliSeconds) { int64_t t = MilliSeconds(); while (MilliSeconds() <= t + lMilliSeconds) {} GetInterval(); }
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { ALLOCATES(); real *G, *X, *out, x, distance; int i,I,n,N,closest; int issorted = 0, InfOutside = 0; char STR[100]; G = myGetPr( prhs[0] ); I = myNumel( prhs[0] ); if( I == 0 ){ plhs[0] = mxCreateDoubleMatrix( 0, 0, mxREAL ); goto EXIT; } X = myGetPr( prhs[1] ); N = myNumel( prhs[1] ); if( nrhs > 2 ){ if( !mxIsChar(prhs[2]) ){ myErrMsgTxt("String expected\n"); } mxGetString( prhs[2], STR, 100 ); if( ! myStrcmpi( STR , "sorted" ) ){ issorted = 1; } if( ! myStrcmpi( STR , "inside" ) ){ InfOutside = 1; } } if( nrhs > 3 ){ if( !mxIsChar(prhs[3]) ){ myErrMsgTxt("String expected\n"); } mxGetString( prhs[3], STR, 100 ); if( ! myStrcmpi( STR , "sorted" ) ){ issorted = 1; } if( ! myStrcmpi( STR , "inside" ) ){ InfOutside = 1; } } plhs[0] = mxCreateNumericArray( mxGetNumberOfDimensions(prhs[1]) , mxGetDimensions(prhs[1]) , mxREAL_CLASS , mxREAL ); out = (real *) mxGetData( plhs[0] ); if( !issorted ){ issorted = checkIsSorted(G,I); } if( issorted ) { i = -1; for( n = 0 ; n<N ; n++ ){ x = X[n]; if( InfOutside ){ if( x < G[ 0 ] ){ out[n] = INFn; continue; } if( x > G[I-1] ){ out[n] = INFp; continue; } } /***************************************************************************** I = numel(G) ... -2 ) [. 0 ) [. 1 ) [. 2 ) ... [. I-3 ) [. I-2 ] ( -101 ... * * * * * * G0 G1 G2 GI-3 GI-2 GI-1 *****************************************************************************/ i = GetInterval( x , G , I , i ); if( i == -2 ){ i = 0; } else if( i == -101 ){ i = I-1; } else if( fabs( x - G[ i ] ) > fabs( x - G[i+1] ) ){ i++; } out[n] = i+1; } } else { if( InfOutside ){ myErrMsgTxt("No se puede usar la opcion 'inside' si la grilla no esta sorted\n"); } for( n = 0 ; n<N ; n++ ){ x = X[n]; closest = 0; distance = fabs( x - G[0] ); for( i = I-1 ; i ; i-- ){ // for( i = 0 ; i < I ; i++ ){ if( fabs( x - G[i] ) < distance ){ closest = i; distance = fabs( x - G[i] ); } if( distance == 0 ){ break; } } out[n] = closest+1; } } EXIT: myFreeALLOCATES(); }
// Reverse a gamma table cmsToneCurve* CMSEXPORT cmsReverseToneCurveEx(cmsInt32Number nResultSamples, const cmsToneCurve* InCurve) { cmsToneCurve *out; cmsFloat64Number a = 0, b = 0, y, x1, y1, x2, y2; int i, j; int Ascending; _cmsAssert(InCurve != NULL); // Try to reverse it analytically whatever possible if (InCurve ->nSegments == 1 && InCurve ->Segments[0].Type > 0 && InCurve -> Segments[0].Type <= 5) { return cmsBuildParametricToneCurve(InCurve ->InterpParams->ContextID, -(InCurve -> Segments[0].Type), InCurve -> Segments[0].Params); } // Nope, reverse the table. out = cmsBuildTabulatedToneCurve16(InCurve ->InterpParams->ContextID, nResultSamples, NULL); if (out == NULL) return NULL; // We want to know if this is an ascending or descending table Ascending = !cmsIsToneCurveDescending(InCurve); // Iterate across Y axis for (i=0; i < nResultSamples; i++) { y = (cmsFloat64Number) i * 65535.0 / (nResultSamples - 1); // Find interval in which y is within. j = GetInterval(y, InCurve->Table16, InCurve->InterpParams); if (j >= 0) { // Get limits of interval x1 = InCurve ->Table16[j]; x2 = InCurve ->Table16[j+1]; y1 = (cmsFloat64Number) (j * 65535.0) / (InCurve ->nEntries - 1); y2 = (cmsFloat64Number) ((j+1) * 65535.0 ) / (InCurve ->nEntries - 1); // If collapsed, then use any if (x1 == x2) { out ->Table16[i] = _cmsQuickSaturateWord(Ascending ? y2 : y1); continue; } else { // Interpolate a = (y2 - y1) / (x2 - x1); b = y2 - a * x2; } } out ->Table16[i] = _cmsQuickSaturateWord(a* y + b); } return out; }