From 27171288d4417287001c60418549d8ddf9e2aa37 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Wed, 28 Jan 2004 21:28:43 +0000 Subject: [PATCH] cleanup, simplify --- stepmania/src/TimingData.cpp | 94 +++++++++++++++++------------------- 1 file changed, 43 insertions(+), 51 deletions(-) diff --git a/stepmania/src/TimingData.cpp b/stepmania/src/TimingData.cpp index 3dbce00f9d..4163b94329 100644 --- a/stepmania/src/TimingData.cpp +++ b/stepmania/src/TimingData.cpp @@ -3,6 +3,7 @@ #include "global.h" #include "TimingData.h" #include "PrefsManager.h" +#include "RageUtil.h" TimingData::TimingData() { @@ -99,7 +100,6 @@ BPMSegment& TimingData::GetBPMSegmentAtBeat( float fBeat ) void TimingData::GetBeatAndBPSFromElapsedTime( float fElapsedTime, float &fBeatOut, float &fBPSOut, bool &bFreezeOut ) const { // LOG->Trace( "GetBeatAndBPSFromElapsedTime( fElapsedTime = %f )", fElapsedTime ); - // This function is a nightmare. Don't even try to understand it. :-) fElapsedTime += PREFSMAN->m_fGlobalOffsetSeconds; @@ -108,53 +108,31 @@ void TimingData::GetBeatAndBPSFromElapsedTime( float fElapsedTime, float &fBeatO for( unsigned i=0; i fSecondsInThisSegment ) - { - // this BPMSegement is NOT the current segment - fElapsedTime -= fSecondsInThisSegment; - continue; - } - - // this BPMSegment IS the current segment - - float fBeatEstimate = fStartBeatThisSegment + fElapsedTime*fBPS; - - for( j=0; j m_StopSegments[j].m_fStartBeat || - m_StopSegments[j].m_fStartBeat > fStartBeatNextSegment ) + if( fStartBeatThisSegment >= m_StopSegments[j].m_fStartBeat ) + continue; + if( !bIsLastBPMSegment && m_StopSegments[j].m_fStartBeat > fStartBeatNextSegment ) continue; // this freeze lies within this BPMSegment - - if( m_StopSegments[j].m_fStartBeat > fBeatEstimate ) + const float fBeatsSinceStartOfSegment = m_StopSegments[j].m_fStartBeat - fStartBeatThisSegment; + const float fFreezeStartSecond = fBeatsSinceStartOfSegment / fBPS; + + if( fFreezeStartSecond >= fElapsedTime ) break; + // the freeze segment is <= current time fElapsedTime -= m_StopSegments[j].m_fStopSeconds; - // re-estimate - fBeatEstimate = fStartBeatThisSegment + fElapsedTime*fBPS; - if( fBeatEstimate < m_StopSegments[j].m_fStartBeat ) + + if( fFreezeStartSecond >= fElapsedTime ) { + /* The time lies within the stop. */ fBeatOut = m_StopSegments[j].m_fStartBeat; fBPSOut = fBPS; bFreezeOut = true; @@ -162,10 +140,19 @@ void TimingData::GetBeatAndBPSFromElapsedTime( float fElapsedTime, float &fBeatO } } - fBeatOut = fBeatEstimate; - fBPSOut = fBPS; - bFreezeOut = false; - return; + const float fBeatsInThisSegment = fStartBeatNextSegment - fStartBeatThisSegment; + const float fSecondsInThisSegment = fBeatsInThisSegment / fBPS; + if( bIsLastBPMSegment || fElapsedTime <= fSecondsInThisSegment ) + { + // this BPMSegment IS the current segment + fBeatOut = fStartBeatThisSegment + fElapsedTime*fBPS; + fBPSOut = fBPS; + bFreezeOut = false; + return; + } + + // this BPMSegment is NOT the current segment + fElapsedTime -= fSecondsInThisSegment; } } @@ -178,6 +165,7 @@ float TimingData::GetElapsedTimeFromBeat( float fBeat ) const for( unsigned j=0; j=, not >. */ if( m_StopSegments[j].m_fStartBeat >= fBeat ) break; fElapsedTime += m_StopSegments[j].m_fStopSeconds; @@ -185,22 +173,26 @@ float TimingData::GetElapsedTimeFromBeat( float fBeat ) const for( unsigned i=0; i