optimize: Add GetTimeSinceStartFast() that caches the time for archs where GetMicrosecondsSinceStart() is slow

This commit is contained in:
Chris Danford
2005-03-21 21:40:07 +00:00
parent ea59bbfec8
commit 66a30e72b8
14 changed files with 41 additions and 36 deletions
+5 -5
View File
@@ -153,7 +153,7 @@ float ArrowEffects::GetYPos( const PlayerState* pPlayerState, int iCol, float fY
const float* fEffects = pPlayerState->m_CurrentPlayerOptions.m_fEffects; const float* fEffects = pPlayerState->m_CurrentPlayerOptions.m_fEffects;
if( fEffects[PlayerOptions::EFFECT_TIPSY] > 0 ) 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; return f;
} }
@@ -163,7 +163,7 @@ float ArrowEffects::GetYOffsetFromYPos( const PlayerState* pPlayerState, int iCo
const float* fEffects = pPlayerState->m_CurrentPlayerOptions.m_fEffects; const float* fEffects = pPlayerState->m_CurrentPlayerOptions.m_fEffects;
if( fEffects[PlayerOptions::EFFECT_TIPSY] > 0 ) 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; float fShift, fScale;
ArrowGetReverseShiftAndScale( pPlayerState, iCol, fYReverseOffsetPixels, 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 ) 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 ) if( fEffects[PlayerOptions::EFFECT_FLIP] > 0 )
{ {
// TODO: Don't index by PlayerNumber. // TODO: Don't index by PlayerNumber.
@@ -377,8 +377,8 @@ float ArrowGetPercentVisible( const PlayerState* pPlayerState, int iCol, float f
fVisibleAdjust -= fAppearances[PlayerOptions::APPEARANCE_STEALTH]; fVisibleAdjust -= fAppearances[PlayerOptions::APPEARANCE_STEALTH];
if( fAppearances[PlayerOptions::APPEARANCE_BLINK] > 0 ) if( fAppearances[PlayerOptions::APPEARANCE_BLINK] > 0 )
{ {
float f = sinf(RageTimer::GetTimeSinceStart()*10); float f = sinf(RageTimer::GetTimeSinceStartFast()*10);
f = Quantize( f, 0.3333f ); f = Quantize( f, 0.3333f );
fVisibleAdjust += SCALE( f, 0, 1, -1, 0 ); fVisibleAdjust += SCALE( f, 0, 1, -1, 0 );
} }
if( fAppearances[PlayerOptions::APPEARANCE_RANDOMVANISH] > 0) if( fAppearances[PlayerOptions::APPEARANCE_RANDOMVANISH] > 0)
+1 -1
View File
@@ -627,7 +627,7 @@ void BGAnimationLayer::Update( float fDeltaTime )
break; break;
case TYPE_TILES: case TYPE_TILES:
{ {
float fSecs = RageTimer::GetTimeSinceStart(); float fSecs = RageTimer::GetTimeSinceStartFast();
float fTotalWidth = m_iNumTilesWide * m_fTilesSpacingX; float fTotalWidth = m_iNumTilesWide * m_fTilesSpacingX;
float fTotalHeight = m_iNumTilesHigh * m_fTilesSpacingY; float fTotalHeight = m_iNumTilesHigh * m_fTilesSpacingY;
+1 -1
View File
@@ -681,7 +681,7 @@ bool Background::IsDangerAllVisible()
return false; return false;
if( BLINK_DANGER_ALL ) if( BLINK_DANGER_ALL )
return (RageTimer::GetTimeSinceStart() - (int)RageTimer::GetTimeSinceStart()) < 0.5f; return (RageTimer::GetTimeSinceStartFast() - (int)RageTimer::GetTimeSinceStartFast()) < 0.5f;
else else
return true; return true;
} }
+1 -1
View File
@@ -517,7 +517,7 @@ void BitmapText::DrawPrimitives()
////////////////////// //////////////////////
if( m_bRainbow ) 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 ) for( unsigned i=0; i<verts.size(); i+=4 )
{ {
const RageColor color = RAINBOW_COLORS[color_index]; const RageColor color = RAINBOW_COLORS[color_index];
+2 -2
View File
@@ -125,8 +125,8 @@ void Inventory::Update( float fDelta )
GAMESTATE->m_fSongBeat < GAMESTATE->m_pCurSong->m_fLastBeat ) GAMESTATE->m_fSongBeat < GAMESTATE->m_pCurSong->m_fLastBeat )
{ {
// every 1 seconds, try to use an item // every 1 seconds, try to use an item
int iLastSecond = (int)(RageTimer::GetTimeSinceStart() - fDelta); int iLastSecond = (int)(RageTimer::GetTimeSinceStartFast() - fDelta);
int iThisSecond = (int)RageTimer::GetTimeSinceStart(); int iThisSecond = (int)RageTimer::GetTimeSinceStartFast();
if( iLastSecond != iThisSecond ) if( iLastSecond != iThisSecond )
{ {
for( int s=0; s<NUM_INVENTORY_SLOTS; s++ ) for( int s=0; s<NUM_INVENTORY_SLOTS; s++ )
+1 -1
View File
@@ -514,7 +514,7 @@ void LifeMeterBar::DrawPrimitives()
m_pStream->m_fPassingAlpha = m_fPassingAlpha; m_pStream->m_fPassingAlpha = m_fPassingAlpha;
m_pStream->m_fHotAlpha = m_fHotAlpha; 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) ); m_quadBlackBackground.SetDiffuse( RageColor(fPercentRed*0.8f,0,0,1) );
ActorFrame::DrawPrimitives(); ActorFrame::DrawPrimitives();
+3 -3
View File
@@ -96,7 +96,7 @@ void LightsManager::Update( float fDeltaTime )
break; break;
case LIGHTSMODE_ATTRACT: case LIGHTSMODE_ATTRACT:
{ {
int iSec = (int)RageTimer::GetTimeSinceStart(); int iSec = (int)RageTimer::GetTimeSinceStartFast();
int iTopIndex = iSec % 4; int iTopIndex = iSec % 4;
switch( iTopIndex ) switch( iTopIndex )
{ {
@@ -154,7 +154,7 @@ void LightsManager::Update( float fDeltaTime )
break; break;
case LIGHTSMODE_TEST: case LIGHTSMODE_TEST:
{ {
int iSec = (int)RageTimer::GetTimeSinceStart(); int iSec = (int)RageTimer::GetTimeSinceStartFast();
FOREACH_CabinetLight( cl ) FOREACH_CabinetLight( cl )
{ {
bool bOn = (iSec%NUM_CABINET_LIGHTS) == cl; bool bOn = (iSec%NUM_CABINET_LIGHTS) == cl;
@@ -246,7 +246,7 @@ void LightsManager::Update( float fDeltaTime )
break; break;
case LIGHTSMODE_TEST: case LIGHTSMODE_TEST:
{ {
int iSec = (int)RageTimer::GetTimeSinceStart(); int iSec = (int)RageTimer::GetTimeSinceStartFast();
int iNumGameButtonsToShow = GAMESTATE->GetCurrentGame()->GetNumGameplayButtons(); int iNumGameButtonsToShow = GAMESTATE->GetCurrentGame()->GetNumGameplayButtons();
+4 -4
View File
@@ -284,7 +284,7 @@ void NoteField::DrawBPMText( const float fBeat, const float fBPM )
m_textMeasureNumber.SetHorizAlign( Actor::align_right ); m_textMeasureNumber.SetHorizAlign( Actor::align_right );
m_textMeasureNumber.SetDiffuse( RageColor(1,0,0,1) ); 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.SetText( ssprintf("%.2f", fBPM) );
m_textMeasureNumber.SetXY( -GetWidth()/2.f - 60, fYPos ); m_textMeasureNumber.SetXY( -GetWidth()/2.f - 60, fYPos );
m_textMeasureNumber.Draw(); m_textMeasureNumber.Draw();
@@ -297,7 +297,7 @@ void NoteField::DrawFreezeText( const float fBeat, const float fSecs )
m_textMeasureNumber.SetHorizAlign( Actor::align_right ); m_textMeasureNumber.SetHorizAlign( Actor::align_right );
m_textMeasureNumber.SetDiffuse( RageColor(0.8f,0.8f,0,1) ); 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.SetText( ssprintf("%.2f", fSecs) );
m_textMeasureNumber.SetXY( -GetWidth()/2.f - 10, fYPos ); m_textMeasureNumber.SetXY( -GetWidth()/2.f - 10, fYPos );
m_textMeasureNumber.Draw(); m_textMeasureNumber.Draw();
@@ -310,7 +310,7 @@ void NoteField::DrawBGChangeText( const float fBeat, const CString sNewBGName )
m_textMeasureNumber.SetHorizAlign( Actor::align_left ); m_textMeasureNumber.SetHorizAlign( Actor::align_left );
m_textMeasureNumber.SetDiffuse( RageColor(0,1,0,1) ); 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.SetText( sNewBGName );
m_textMeasureNumber.SetXY( +GetWidth()/2.f, fYPos ); m_textMeasureNumber.SetXY( +GetWidth()/2.f, fYPos );
m_textMeasureNumber.Draw(); m_textMeasureNumber.Draw();
@@ -525,7 +525,7 @@ void NoteField::DrawPrimitives()
// draw in big batches. // 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 for( int c=0; c<m_pNoteData->GetNumTracks(); c++ ) // for each arrow column
{ {
+10 -6
View File
@@ -30,24 +30,28 @@
const RageTimer RageZeroTimer(0,0); 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); secs = unsigned(usecs / 1000000);
us = unsigned(usecs % 1000000); us = unsigned(usecs % 1000000);
} }
float RageTimer::GetTimeSinceStart() float RageTimer::GetTimeSinceStart( bool bAccurate )
{ {
unsigned secs, us; unsigned secs, us;
GetTime( secs, us ); GetTime( secs, us, bAccurate );
return secs + us / 1000000.0f; return secs + (us / 1000000.0f);
} }
void RageTimer::Touch() void RageTimer::Touch()
{ {
GetTime( this->m_secs, this->m_us ); GetTime( this->m_secs, this->m_us, true );
} }
float RageTimer::Ago() const float RageTimer::Ago() const
+2 -1
View File
@@ -21,7 +21,8 @@ public:
float PeekDeltaTime() const { return Ago(); } float PeekDeltaTime() const { return Ago(); }
/* deprecated: */ /* 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. */ /* Get a timer representing half of the time ago as this one. */
RageTimer Half() const; RageTimer Half() const;
+7 -7
View File
@@ -285,15 +285,15 @@ void ScreenEz2SelectMusic::Input( const DeviceInput& DeviceI, const InputEventTy
if(ScrollStartTime == 0) if(ScrollStartTime == 0)
{ {
i_SkipAheadOffset = 0; i_SkipAheadOffset = 0;
ScrollStartTime = RageTimer::GetTimeSinceStart(); ScrollStartTime = RageTimer::GetTimeSinceStartFast();
} }
else 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 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 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_soundMusicChange.Play();
m_soundButtonPress.Play(); m_soundButtonPress.Play();
} }
LastInputTime = RageTimer::GetTimeSinceStart(); LastInputTime = RageTimer::GetTimeSinceStartFast();
Screen::Input( DeviceI, type, GameI, MenuI, StyleI ); Screen::Input( DeviceI, type, GameI, MenuI, StyleI );
} }
@@ -468,7 +468,7 @@ void ScreenEz2SelectMusic::MenuStart( PlayerNumber pn )
} }
m_bMadeChoice = true; m_bMadeChoice = true;
m_fRemainingWaitTime = RageTimer::GetTimeSinceStart(); m_fRemainingWaitTime = RageTimer::GetTimeSinceStartFast();
TweenOffScreen(); TweenOffScreen();
@@ -488,7 +488,7 @@ void ScreenEz2SelectMusic::Update( float fDeltaTime )
{ {
m_DifficultyRating.Update(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); 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 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; m_bTransitioning = true;
StartTransitioning( SM_GoToNextScreen ); StartTransitioning( SM_GoToNextScreen );
+2 -2
View File
@@ -273,7 +273,7 @@ void ScreenSystemLayer::UpdateSkips()
if( skip ) if( skip )
{ {
CString time(SecondsToMMSSMsMs(RageTimer::GetTimeSinceStart())); CString time(SecondsToMMSSMsMs(RageTimer::GetTimeSinceStartFast()));
static const RageColor colors[] = static const RageColor colors[] =
{ {
@@ -307,7 +307,7 @@ void ScreenSystemLayer::Update( float fDeltaTime )
UpdateSkips(); UpdateSkips();
if( PREFSMAN->m_bTimestamping ) if( PREFSMAN->m_bTimestamping )
m_textTime.SetText( SecondsToMMSSMsMs(RageTimer::GetTimeSinceStart()) ); m_textTime.SetText( SecondsToMMSSMsMs(RageTimer::GetTimeSinceStartFast()) );
} }
/* /*
+1 -1
View File
@@ -45,7 +45,7 @@ void ScreenTestLights::Update( float fDeltaTime )
{ {
Screen::Update( fDeltaTime ); Screen::Update( fDeltaTime );
int iSec = (int)RageTimer::GetTimeSinceStart(); int iSec = (int)RageTimer::GetTimeSinceStartFast();
CabinetLight cl = (CabinetLight)(iSec%NUM_CABINET_LIGHTS); CabinetLight cl = (CabinetLight)(iSec%NUM_CABINET_LIGHTS);
int iNumGameButtonsToShow = GAMESTATE->GetCurrentGame()->GetNumGameplayButtons(); int iNumGameButtonsToShow = GAMESTATE->GetCurrentGame()->GetNumGameplayButtons();
+1 -1
View File
@@ -69,7 +69,7 @@ void WheelNotifyIcon::Update( float fDeltaTime )
{ {
if( m_vIconsToShow.size() > 0 ) 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()); const int index = (int)(fSecondFraction*m_vIconsToShow.size());
Sprite::SetState( m_vIconsToShow[index] ); Sprite::SetState( m_vIconsToShow[index] );
} }