void CRenderableAnimation::UpdateSurface() { animDirection = DetermineDirection(); currentAnimState = DetermineAnimationState(); CRenderableNoAnimation::SetYCrop(GetCorrectYCrop()); DetermineAnimationFrame(); }
void WalkCircleThread( PVOID _pvoid ) { //srand( time( NULL ) ); PPARAMS pParams = (PPARAMS)_pvoid; const SIZE circleSize = { 40, 40 }; HDC hdc; POINT startPoint; std::srand( std::time( NULL ) ); Direction direction; direction = (Direction)( ( std::rand() ) % (int)Direction::N_OF_DIRECTIONS ); startPoint = { std::rand() % ( pParams->m_clientRect.right - circleSize.cx ), std::rand() % ( pParams->m_clientRect.bottom - circleSize.cy ) }; RECT circleDims = { startPoint.x, startPoint.y, startPoint.x + circleSize.cx, startPoint.y + circleSize.cy }; // left top right bottom const UINT step = 1; // Проверяем на необходимость выхода из потока while ( ! pParams->m_bKill ) { // Определяем направление движения окружности DetermineDirection( direction, circleDims, pParams->m_clientRect ); // Определяем след. позицию окружности MoveInDirection( circleDims, direction, step ); // Получаем свою квоту на перерисовку WaitForSingleObject( pParams->m_semaphore, INFINITE ); // Блокируем отрисовку в других потоках EnterCriticalSection( &pParams->m_drawBlocker ); // Рисуем окружность Ellipse( pParams->m_hdc, circleDims ); // Снимаем блокировку LeaveCriticalSection( &pParams->m_drawBlocker ); // Ожидаем завершения отрисовки во всех остальных потоках EnterSynchronizationBarrier( &pParams->m_drawFinished, SYNCHRONIZATION_BARRIER_FLAGS_BLOCK_ONLY ); // Даем возможность другому потоку подменить семафор EnterSynchronizationBarrier( &pParams->m_drawFinished, SYNCHRONIZATION_BARRIER_FLAGS_BLOCK_ONLY ); } }
Direction receiveUserInput() { //just ONE input at a time, then CHECK that input //check where they are tilted to pass threshold of time //then must return to flat for threshold of time Direction userInput = Flat; Direction currentDirection = Flat; unsigned int inputTimestamp = 0; while(1) { calc.x = XAvg - X0; calc.y = YAvg - Y0; calc.z = ZAvg - Z0; calculateArcHypZ(&calc); theta = (long) calc.angleTheta >> 8; //divide by 256 to see angles 0-360 phi = (long) calc.anglePhi >> 8; if(phi > 90) { phi = 360 - phi; } if(phi >= 90-TOLERANCE) LEDDir = Flat; else LEDDir = DetermineDirection(theta); LightLEDsByDirection(LEDDir); if (userInput == Flat && LEDDir != Flat) { if (inputTimestamp == 0) { inputTimestamp = g1mSTimer; currentDirection = LEDDir; } else if (g1mSTimer - inputTimestamp >= TIMER_THRESHOLD && currentDirection == LEDDir) //going in here when flat { userInput = currentDirection; } else if (currentDirection != LEDDir) //resetting if direction switched before time threshold { inputTimestamp = g1mSTimer; currentDirection = LEDDir; } else continue; } else { if(LEDDir != Flat && currentDirection != LEDDir) //put in new direction { inputTimestamp = g1mSTimer; currentDirection = LEDDir; userInput = Flat; } else if (LEDDir == Flat && currentDirection != Flat) { inputTimestamp = g1mSTimer; currentDirection = Flat; } else if (g1mSTimer - inputTimestamp >= TIMER_THRESHOLD && userInput != Flat && LEDDir == Flat) { return userInput; } else continue; //goes here if flat at beginning } } }