CString PercentageDisplay::FormatPercentScore( float fPercentDancePoints ) { // TRICKY: printf will round, but we want to truncate. Otherwise, we may display a percent // score that's too high and doesn't match up with the calculated grade. float fTruncInterval = powf( 0.1f, (float)PERCENT_TOTAL_SIZE-1 ); // TRICKY: ftruncf is rounding 1.0000000 to 0.99990004. Give a little boost to // fPercentDancePoints to correct for this. fPercentDancePoints += 0.000001f; fPercentDancePoints = ftruncf( fPercentDancePoints, fTruncInterval ); CString s = ssprintf( "%*.*f%%", (int)PERCENT_TOTAL_SIZE, (int)PERCENT_DECIMAL_PLACES, fPercentDancePoints*100 ); return s; }
void InputFilter::Update( float fDeltaTime ) { RageTimer now; INPUTMAN->Update(); /* Make sure that nothing gets inserted while we do this, to prevent things * like "key pressed, key release, key repeat". */ LockMut(*queuemutex); DeviceInput di( InputDevice_Invalid, DeviceButton_Invalid, 1.0f, now ); MakeButtonStateList( g_CurrentState ); vector<ButtonStateMap::iterator> ButtonsToErase; FOREACHM( DeviceButtonPair, ButtonState, g_ButtonStates, b ) { di.device = b->first.device; di.button = b->first.button; ButtonState &bs = b->second; // Generate IET_FIRST_PRESS and IET_RELEASE events that were delayed. CheckButtonChange( bs, di, now ); // Generate IET_REPEAT events. if( !bs.m_bLastReportedHeld ) { // If the key isn't pressed, and hasn't been pressed for a while // (so debouncing isn't interested in it), purge the entry. if( now - bs.m_LastReportTime > g_fInputDebounceTime && bs.m_DeviceInput.level == 0.0f ) ButtonsToErase.push_back( b ); continue; } // If repeats are disabled for this button, skip. if( g_DisableRepeat.find(di) != g_DisableRepeat.end() ) continue; const float fOldHoldTime = bs.m_fSecsHeld; bs.m_fSecsHeld += fDeltaTime; const float fNewHoldTime = bs.m_fSecsHeld; if( fNewHoldTime <= g_fTimeBeforeRepeats ) continue; float fRepeatTime; if( fOldHoldTime < g_fTimeBeforeRepeats ) { fRepeatTime = g_fTimeBeforeRepeats; } else { float fAdjustedOldHoldTime = fOldHoldTime - g_fTimeBeforeRepeats; float fAdjustedNewHoldTime = fNewHoldTime - g_fTimeBeforeRepeats; if( int(fAdjustedOldHoldTime/g_fTimeBetweenRepeats) == int(fAdjustedNewHoldTime/g_fTimeBetweenRepeats) ) continue; fRepeatTime = ftruncf( fNewHoldTime, g_fTimeBetweenRepeats ); } /* Set the timestamp to the exact time of the repeat. This way, as long * as tab/` aren't being used, the timestamp will always increase steadily * during repeats. */ di.ts = bs.m_LastInputTime + fRepeatTime; ReportButtonChange( di, IET_REPEAT ); }