optimize: Add GetTimeSinceStartFast() that caches the time for archs where GetMicrosecondsSinceStart() is slow
This commit is contained in:
@@ -153,7 +153,7 @@ float ArrowEffects::GetYPos( const PlayerState* pPlayerState, int iCol, float fY
|
||||
const float* fEffects = pPlayerState->m_CurrentPlayerOptions.m_fEffects;
|
||||
|
||||
if( fEffects[PlayerOptions::EFFECT_TIPSY] > 0 )
|
||||
f += fEffects[PlayerOptions::EFFECT_TIPSY] * ( cosf( RageTimer::GetTimeSinceStart()*1.2f + iCol*1.8f) * ARROW_SIZE*0.4f );
|
||||
f += fEffects[PlayerOptions::EFFECT_TIPSY] * ( cosf( RageTimer::GetTimeSinceStartFast()*1.2f + iCol*1.8f) * ARROW_SIZE*0.4f );
|
||||
return f;
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ float ArrowEffects::GetYOffsetFromYPos( const PlayerState* pPlayerState, int iCo
|
||||
|
||||
const float* fEffects = pPlayerState->m_CurrentPlayerOptions.m_fEffects;
|
||||
if( fEffects[PlayerOptions::EFFECT_TIPSY] > 0 )
|
||||
f -= fEffects[PlayerOptions::EFFECT_TIPSY] * ( cosf( RageTimer::GetTimeSinceStart()*1.2f + iCol*2.f) * ARROW_SIZE*0.4f );
|
||||
f -= fEffects[PlayerOptions::EFFECT_TIPSY] * ( cosf( RageTimer::GetTimeSinceStartFast()*1.2f + iCol*2.f) * ARROW_SIZE*0.4f );
|
||||
|
||||
float fShift, fScale;
|
||||
ArrowGetReverseShiftAndScale( pPlayerState, iCol, fYReverseOffsetPixels, fShift, fScale );
|
||||
@@ -218,7 +218,7 @@ float ArrowEffects::GetXPos( const PlayerState* pPlayerState, int iColNum, float
|
||||
}
|
||||
|
||||
if( fEffects[PlayerOptions::EFFECT_DRUNK] > 0 )
|
||||
fPixelOffsetFromCenter += fEffects[PlayerOptions::EFFECT_DRUNK] * ( cosf( RageTimer::GetTimeSinceStart() + iColNum*0.2f + fYOffset*10/SCREEN_HEIGHT) * ARROW_SIZE*0.5f );
|
||||
fPixelOffsetFromCenter += fEffects[PlayerOptions::EFFECT_DRUNK] * ( cosf( RageTimer::GetTimeSinceStartFast() + iColNum*0.2f + fYOffset*10/SCREEN_HEIGHT) * ARROW_SIZE*0.5f );
|
||||
if( fEffects[PlayerOptions::EFFECT_FLIP] > 0 )
|
||||
{
|
||||
// TODO: Don't index by PlayerNumber.
|
||||
@@ -377,8 +377,8 @@ float ArrowGetPercentVisible( const PlayerState* pPlayerState, int iCol, float f
|
||||
fVisibleAdjust -= fAppearances[PlayerOptions::APPEARANCE_STEALTH];
|
||||
if( fAppearances[PlayerOptions::APPEARANCE_BLINK] > 0 )
|
||||
{
|
||||
float f = sinf(RageTimer::GetTimeSinceStart()*10);
|
||||
f = Quantize( f, 0.3333f );
|
||||
float f = sinf(RageTimer::GetTimeSinceStartFast()*10);
|
||||
f = Quantize( f, 0.3333f );
|
||||
fVisibleAdjust += SCALE( f, 0, 1, -1, 0 );
|
||||
}
|
||||
if( fAppearances[PlayerOptions::APPEARANCE_RANDOMVANISH] > 0)
|
||||
|
||||
@@ -627,7 +627,7 @@ void BGAnimationLayer::Update( float fDeltaTime )
|
||||
break;
|
||||
case TYPE_TILES:
|
||||
{
|
||||
float fSecs = RageTimer::GetTimeSinceStart();
|
||||
float fSecs = RageTimer::GetTimeSinceStartFast();
|
||||
float fTotalWidth = m_iNumTilesWide * m_fTilesSpacingX;
|
||||
float fTotalHeight = m_iNumTilesHigh * m_fTilesSpacingY;
|
||||
|
||||
|
||||
@@ -681,7 +681,7 @@ bool Background::IsDangerAllVisible()
|
||||
return false;
|
||||
|
||||
if( BLINK_DANGER_ALL )
|
||||
return (RageTimer::GetTimeSinceStart() - (int)RageTimer::GetTimeSinceStart()) < 0.5f;
|
||||
return (RageTimer::GetTimeSinceStartFast() - (int)RageTimer::GetTimeSinceStartFast()) < 0.5f;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -517,7 +517,7 @@ void BitmapText::DrawPrimitives()
|
||||
//////////////////////
|
||||
if( m_bRainbow )
|
||||
{
|
||||
int color_index = int(RageTimer::GetTimeSinceStart() / 0.200) % NUM_RAINBOW_COLORS;
|
||||
int color_index = int(RageTimer::GetTimeSinceStartFast() / 0.200) % NUM_RAINBOW_COLORS;
|
||||
for( unsigned i=0; i<verts.size(); i+=4 )
|
||||
{
|
||||
const RageColor color = RAINBOW_COLORS[color_index];
|
||||
|
||||
@@ -125,8 +125,8 @@ void Inventory::Update( float fDelta )
|
||||
GAMESTATE->m_fSongBeat < GAMESTATE->m_pCurSong->m_fLastBeat )
|
||||
{
|
||||
// every 1 seconds, try to use an item
|
||||
int iLastSecond = (int)(RageTimer::GetTimeSinceStart() - fDelta);
|
||||
int iThisSecond = (int)RageTimer::GetTimeSinceStart();
|
||||
int iLastSecond = (int)(RageTimer::GetTimeSinceStartFast() - fDelta);
|
||||
int iThisSecond = (int)RageTimer::GetTimeSinceStartFast();
|
||||
if( iLastSecond != iThisSecond )
|
||||
{
|
||||
for( int s=0; s<NUM_INVENTORY_SLOTS; s++ )
|
||||
|
||||
@@ -514,7 +514,7 @@ void LifeMeterBar::DrawPrimitives()
|
||||
m_pStream->m_fPassingAlpha = m_fPassingAlpha;
|
||||
m_pStream->m_fHotAlpha = m_fHotAlpha;
|
||||
|
||||
float fPercentRed = (m_fTrailingLifePercentage<DANGER_THRESHOLD) ? sinf( RageTimer::GetTimeSinceStart()*PI*4 )/2+0.5f : 0;
|
||||
float fPercentRed = (m_fTrailingLifePercentage<DANGER_THRESHOLD) ? sinf( RageTimer::GetTimeSinceStartFast()*PI*4 )/2+0.5f : 0;
|
||||
m_quadBlackBackground.SetDiffuse( RageColor(fPercentRed*0.8f,0,0,1) );
|
||||
|
||||
ActorFrame::DrawPrimitives();
|
||||
|
||||
@@ -96,7 +96,7 @@ void LightsManager::Update( float fDeltaTime )
|
||||
break;
|
||||
case LIGHTSMODE_ATTRACT:
|
||||
{
|
||||
int iSec = (int)RageTimer::GetTimeSinceStart();
|
||||
int iSec = (int)RageTimer::GetTimeSinceStartFast();
|
||||
int iTopIndex = iSec % 4;
|
||||
switch( iTopIndex )
|
||||
{
|
||||
@@ -154,7 +154,7 @@ void LightsManager::Update( float fDeltaTime )
|
||||
break;
|
||||
case LIGHTSMODE_TEST:
|
||||
{
|
||||
int iSec = (int)RageTimer::GetTimeSinceStart();
|
||||
int iSec = (int)RageTimer::GetTimeSinceStartFast();
|
||||
FOREACH_CabinetLight( cl )
|
||||
{
|
||||
bool bOn = (iSec%NUM_CABINET_LIGHTS) == cl;
|
||||
@@ -246,7 +246,7 @@ void LightsManager::Update( float fDeltaTime )
|
||||
break;
|
||||
case LIGHTSMODE_TEST:
|
||||
{
|
||||
int iSec = (int)RageTimer::GetTimeSinceStart();
|
||||
int iSec = (int)RageTimer::GetTimeSinceStartFast();
|
||||
|
||||
int iNumGameButtonsToShow = GAMESTATE->GetCurrentGame()->GetNumGameplayButtons();
|
||||
|
||||
|
||||
@@ -284,7 +284,7 @@ void NoteField::DrawBPMText( const float fBeat, const float fBPM )
|
||||
|
||||
m_textMeasureNumber.SetHorizAlign( Actor::align_right );
|
||||
m_textMeasureNumber.SetDiffuse( RageColor(1,0,0,1) );
|
||||
m_textMeasureNumber.SetGlow( RageColor(1,1,1,cosf(RageTimer::GetTimeSinceStart()*2)/2+0.5f) );
|
||||
m_textMeasureNumber.SetGlow( RageColor(1,1,1,cosf(RageTimer::GetTimeSinceStartFast()*2)/2+0.5f) );
|
||||
m_textMeasureNumber.SetText( ssprintf("%.2f", fBPM) );
|
||||
m_textMeasureNumber.SetXY( -GetWidth()/2.f - 60, fYPos );
|
||||
m_textMeasureNumber.Draw();
|
||||
@@ -297,7 +297,7 @@ void NoteField::DrawFreezeText( const float fBeat, const float fSecs )
|
||||
|
||||
m_textMeasureNumber.SetHorizAlign( Actor::align_right );
|
||||
m_textMeasureNumber.SetDiffuse( RageColor(0.8f,0.8f,0,1) );
|
||||
m_textMeasureNumber.SetGlow( RageColor(1,1,1,cosf(RageTimer::GetTimeSinceStart()*2)/2+0.5f) );
|
||||
m_textMeasureNumber.SetGlow( RageColor(1,1,1,cosf(RageTimer::GetTimeSinceStartFast()*2)/2+0.5f) );
|
||||
m_textMeasureNumber.SetText( ssprintf("%.2f", fSecs) );
|
||||
m_textMeasureNumber.SetXY( -GetWidth()/2.f - 10, fYPos );
|
||||
m_textMeasureNumber.Draw();
|
||||
@@ -310,7 +310,7 @@ void NoteField::DrawBGChangeText( const float fBeat, const CString sNewBGName )
|
||||
|
||||
m_textMeasureNumber.SetHorizAlign( Actor::align_left );
|
||||
m_textMeasureNumber.SetDiffuse( RageColor(0,1,0,1) );
|
||||
m_textMeasureNumber.SetGlow( RageColor(1,1,1,cosf(RageTimer::GetTimeSinceStart()*2)/2+0.5f) );
|
||||
m_textMeasureNumber.SetGlow( RageColor(1,1,1,cosf(RageTimer::GetTimeSinceStartFast()*2)/2+0.5f) );
|
||||
m_textMeasureNumber.SetText( sNewBGName );
|
||||
m_textMeasureNumber.SetXY( +GetWidth()/2.f, fYPos );
|
||||
m_textMeasureNumber.Draw();
|
||||
@@ -525,7 +525,7 @@ void NoteField::DrawPrimitives()
|
||||
// draw in big batches.
|
||||
//
|
||||
|
||||
float fSelectedRangeGlow = SCALE( cosf(RageTimer::GetTimeSinceStart()*2), -1, 1, 0.1f, 0.3f );
|
||||
float fSelectedRangeGlow = SCALE( cosf(RageTimer::GetTimeSinceStartFast()*2), -1, 1, 0.1f, 0.3f );
|
||||
|
||||
for( int c=0; c<m_pNoteData->GetNumTracks(); c++ ) // for each arrow column
|
||||
{
|
||||
|
||||
@@ -30,24 +30,28 @@
|
||||
|
||||
const RageTimer RageZeroTimer(0,0);
|
||||
|
||||
static void GetTime( unsigned &secs, unsigned &us )
|
||||
static void GetTime( unsigned &secs, unsigned &us, bool bAccurate )
|
||||
{
|
||||
uint64_t usecs = ArchHooks::GetMicrosecondsSinceStart( true );
|
||||
// if !bAccurate, then don't call ArchHooks to find the current time. Just return the
|
||||
// last calculated time. GetMicrosecondsSinceStart is slow on some archs.
|
||||
static uint64_t usecs = 0;
|
||||
if( bAccurate )
|
||||
usecs = ArchHooks::GetMicrosecondsSinceStart( true );
|
||||
|
||||
secs = unsigned(usecs / 1000000);
|
||||
us = unsigned(usecs % 1000000);
|
||||
}
|
||||
|
||||
float RageTimer::GetTimeSinceStart()
|
||||
float RageTimer::GetTimeSinceStart( bool bAccurate )
|
||||
{
|
||||
unsigned secs, us;
|
||||
GetTime( secs, us );
|
||||
return secs + us / 1000000.0f;
|
||||
GetTime( secs, us, bAccurate );
|
||||
return secs + (us / 1000000.0f);
|
||||
}
|
||||
|
||||
void RageTimer::Touch()
|
||||
{
|
||||
GetTime( this->m_secs, this->m_us );
|
||||
GetTime( this->m_secs, this->m_us, true );
|
||||
}
|
||||
|
||||
float RageTimer::Ago() const
|
||||
|
||||
@@ -21,7 +21,8 @@ public:
|
||||
float PeekDeltaTime() const { return Ago(); }
|
||||
|
||||
/* deprecated: */
|
||||
static float GetTimeSinceStart(); // seconds since the program was started
|
||||
static float GetTimeSinceStart( bool bAccurate = true ); // seconds since the program was started
|
||||
static float GetTimeSinceStartFast() { return GetTimeSinceStart(false); }
|
||||
|
||||
/* Get a timer representing half of the time ago as this one. */
|
||||
RageTimer Half() const;
|
||||
|
||||
@@ -285,15 +285,15 @@ void ScreenEz2SelectMusic::Input( const DeviceInput& DeviceI, const InputEventTy
|
||||
if(ScrollStartTime == 0)
|
||||
{
|
||||
i_SkipAheadOffset = 0;
|
||||
ScrollStartTime = RageTimer::GetTimeSinceStart();
|
||||
ScrollStartTime = RageTimer::GetTimeSinceStartFast();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(RageTimer::GetTimeSinceStart() - ScrollStartTime > 5) // been cycling for more than 5 seconds
|
||||
if(RageTimer::GetTimeSinceStartFast() - ScrollStartTime > 5) // been cycling for more than 5 seconds
|
||||
{
|
||||
i_SkipAheadOffset = 2; // start skipping ahead in twos
|
||||
}
|
||||
else if (RageTimer::GetTimeSinceStart() - ScrollStartTime > 10) // been cycling for more than 10 seconds
|
||||
else if (RageTimer::GetTimeSinceStartFast() - ScrollStartTime > 10) // been cycling for more than 10 seconds
|
||||
{
|
||||
i_SkipAheadOffset = 3; // start skipping ahead 3 at a time
|
||||
}
|
||||
@@ -307,7 +307,7 @@ void ScreenEz2SelectMusic::Input( const DeviceInput& DeviceI, const InputEventTy
|
||||
// m_soundMusicChange.Play();
|
||||
m_soundButtonPress.Play();
|
||||
}
|
||||
LastInputTime = RageTimer::GetTimeSinceStart();
|
||||
LastInputTime = RageTimer::GetTimeSinceStartFast();
|
||||
Screen::Input( DeviceI, type, GameI, MenuI, StyleI );
|
||||
}
|
||||
|
||||
@@ -468,7 +468,7 @@ void ScreenEz2SelectMusic::MenuStart( PlayerNumber pn )
|
||||
}
|
||||
|
||||
m_bMadeChoice = true;
|
||||
m_fRemainingWaitTime = RageTimer::GetTimeSinceStart();
|
||||
m_fRemainingWaitTime = RageTimer::GetTimeSinceStartFast();
|
||||
|
||||
TweenOffScreen();
|
||||
|
||||
@@ -488,7 +488,7 @@ void ScreenEz2SelectMusic::Update( float fDeltaTime )
|
||||
{
|
||||
m_DifficultyRating.Update(fDeltaTime);
|
||||
|
||||
if(i_SkipAheadOffset > 0 && RageTimer::GetTimeSinceStart() - LastInputTime < 0.5)
|
||||
if(i_SkipAheadOffset > 0 && RageTimer::GetTimeSinceStartFast() - LastInputTime < 0.5)
|
||||
{
|
||||
m_MusicBannerWheel.SetScanMode(true);
|
||||
}
|
||||
@@ -504,7 +504,7 @@ void ScreenEz2SelectMusic::Update( float fDeltaTime )
|
||||
this->PostScreenMessage( SM_NoSongs, 5.5f ); // timeout incase the user decides to do nothing :D
|
||||
}
|
||||
|
||||
if(m_bMadeChoice && RageTimer::GetTimeSinceStart() > m_fRemainingWaitTime + 2 && !m_bTransitioning)
|
||||
if(m_bMadeChoice && RageTimer::GetTimeSinceStartFast() > m_fRemainingWaitTime + 2 && !m_bTransitioning)
|
||||
{
|
||||
m_bTransitioning = true;
|
||||
StartTransitioning( SM_GoToNextScreen );
|
||||
|
||||
@@ -273,7 +273,7 @@ void ScreenSystemLayer::UpdateSkips()
|
||||
|
||||
if( skip )
|
||||
{
|
||||
CString time(SecondsToMMSSMsMs(RageTimer::GetTimeSinceStart()));
|
||||
CString time(SecondsToMMSSMsMs(RageTimer::GetTimeSinceStartFast()));
|
||||
|
||||
static const RageColor colors[] =
|
||||
{
|
||||
@@ -307,7 +307,7 @@ void ScreenSystemLayer::Update( float fDeltaTime )
|
||||
UpdateSkips();
|
||||
|
||||
if( PREFSMAN->m_bTimestamping )
|
||||
m_textTime.SetText( SecondsToMMSSMsMs(RageTimer::GetTimeSinceStart()) );
|
||||
m_textTime.SetText( SecondsToMMSSMsMs(RageTimer::GetTimeSinceStartFast()) );
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -45,7 +45,7 @@ void ScreenTestLights::Update( float fDeltaTime )
|
||||
{
|
||||
Screen::Update( fDeltaTime );
|
||||
|
||||
int iSec = (int)RageTimer::GetTimeSinceStart();
|
||||
int iSec = (int)RageTimer::GetTimeSinceStartFast();
|
||||
|
||||
CabinetLight cl = (CabinetLight)(iSec%NUM_CABINET_LIGHTS);
|
||||
int iNumGameButtonsToShow = GAMESTATE->GetCurrentGame()->GetNumGameplayButtons();
|
||||
|
||||
@@ -69,7 +69,7 @@ void WheelNotifyIcon::Update( float fDeltaTime )
|
||||
{
|
||||
if( m_vIconsToShow.size() > 0 )
|
||||
{
|
||||
const float fSecondFraction = fmodf( RageTimer::GetTimeSinceStart(), 1 );
|
||||
const float fSecondFraction = fmodf( RageTimer::GetTimeSinceStartFast(), 1 );
|
||||
const int index = (int)(fSecondFraction*m_vIconsToShow.size());
|
||||
Sprite::SetState( m_vIconsToShow[index] );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user