From 0cc18326284d236e8ce51c474a5edae1ff0c7ce9 Mon Sep 17 00:00:00 2001 From: Glenn Maynard Date: Thu, 30 Nov 2006 01:39:58 +0000 Subject: [PATCH] hide implementation --- stepmania/src/RageSoundPosMap.cpp | 70 +++++++++++++++++++++++-------- stepmania/src/RageSoundPosMap.h | 24 ++--------- 2 files changed, 57 insertions(+), 37 deletions(-) diff --git a/stepmania/src/RageSoundPosMap.cpp b/stepmania/src/RageSoundPosMap.cpp index ca274f461c..5d3f677a68 100644 --- a/stepmania/src/RageSoundPosMap.cpp +++ b/stepmania/src/RageSoundPosMap.cpp @@ -4,26 +4,62 @@ #include "RageUtil.h" #include "RageTimer.h" +#include + /* The number of frames we should keep pos_map data for. This being too high * is mostly harmless; the data is small. */ const int pos_map_backlog_frames = 100000; +struct pos_map_t +{ + /* Frame number from the POV of the sound driver: */ + int64_t m_iFrameNo; + + /* Actual sound position within the sample: */ + int64_t m_iPosition; + + /* The number of frames in this block: */ + int64_t m_iFrames; + + pos_map_t() { m_iFrameNo = 0; m_iPosition = 0; m_iFrames = 0; } + pos_map_t( int64_t iFrame, int iPosition, int iFrames ) { m_iFrameNo = iFrame; m_iPosition = iPosition; m_iFrames = iFrames; } +}; + +struct pos_map_impl +{ + deque m_Queue; + void Cleanup(); +}; + pos_map_queue::pos_map_queue() { + m_pImpl = new pos_map_impl; } +pos_map_queue::~pos_map_queue() +{ + delete m_pImpl; +} pos_map_queue::pos_map_queue( const pos_map_queue &cpy ) { *this = cpy; + m_pImpl = new pos_map_impl( *cpy.m_pImpl ); +} + +pos_map_queue &pos_map_queue::operator=( const pos_map_queue &rhs ) +{ + delete m_pImpl; + m_pImpl = new pos_map_impl( *rhs.m_pImpl ); + return *this; } void pos_map_queue::CommitPosition( int64_t iFrame, int iPosition, int iGotFrames ) { - if( m_Queue.size() ) + if( m_pImpl->m_Queue.size() ) { /* Optimization: If the last entry lines up with this new entry, just merge them. */ - pos_map_t &last = m_Queue.back(); + pos_map_t &last = m_pImpl->m_Queue.back(); if( last.m_iFrameNo+last.m_iFrames == iFrame && last.m_iPosition+last.m_iFrames == iPosition ) { @@ -32,12 +68,12 @@ void pos_map_queue::CommitPosition( int64_t iFrame, int iPosition, int iGotFrame } } - m_Queue.push_back( pos_map_t(iFrame, iPosition, iGotFrames) ); + m_pImpl->m_Queue.push_back( pos_map_t(iFrame, iPosition, iGotFrames) ); - Cleanup(); + m_pImpl->Cleanup(); } -void pos_map_queue::Cleanup() +void pos_map_impl::Cleanup() { /* Determine the number of frames of data we have. */ int64_t iTotalFrames = 0; @@ -66,33 +102,33 @@ int64_t pos_map_queue::Search( int64_t iFrame, bool *bApproximate ) const * it maps to. */ int64_t iClosestPosition = 0, iClosestPositionDist = INT_MAX; int iClosestBlock = 0; /* print only */ - for( unsigned i = 0; i < m_Queue.size(); ++i ) + for( unsigned i = 0; i < m_pImpl->m_Queue.size(); ++i ) { - if( iFrame >= m_Queue[i].m_iFrameNo && - iFrame < m_Queue[i].m_iFrameNo+m_Queue[i].m_iFrames ) + if( iFrame >= m_pImpl->m_Queue[i].m_iFrameNo && + iFrame < m_pImpl->m_Queue[i].m_iFrameNo+m_pImpl->m_Queue[i].m_iFrames ) { /* iFrame lies in this block; it's an exact match. Figure * out the exact position. */ - int64_t diff = m_Queue[i].m_iPosition - m_Queue[i].m_iFrameNo; + int64_t diff = m_pImpl->m_Queue[i].m_iPosition - m_pImpl->m_Queue[i].m_iFrameNo; return iFrame + diff; } /* See if the current position is close to the beginning of this block. */ - int64_t dist = llabs( m_Queue[i].m_iFrameNo - iFrame ); + int64_t dist = llabs( m_pImpl->m_Queue[i].m_iFrameNo - iFrame ); if( dist < iClosestPositionDist ) { iClosestPositionDist = dist; iClosestBlock = i; - iClosestPosition = m_Queue[i].m_iPosition; + iClosestPosition = m_pImpl->m_Queue[i].m_iPosition; } /* See if the current position is close to the end of this block. */ - dist = llabs( m_Queue[i].m_iFrameNo + m_Queue[i].m_iFrames - iFrame ); + dist = llabs( m_pImpl->m_Queue[i].m_iFrameNo + m_pImpl->m_Queue[i].m_iFrames - iFrame ); if( dist < iClosestPositionDist ) { iClosestPositionDist = dist; iClosestBlock = i; - iClosestPosition = m_Queue[i].m_iPosition + m_Queue[i].m_iFrames; + iClosestPosition = m_pImpl->m_Queue[i].m_iPosition + m_pImpl->m_Queue[i].m_iFrames; } } @@ -115,8 +151,8 @@ int64_t pos_map_queue::Search( int64_t iFrame, bool *bApproximate ) const if( last.PeekDeltaTime() >= 1.0f ) { last.GetDeltaTime(); - LOG->Trace( "Approximate sound time: driver frame " LI ", m_Queue frame " LI ".." LI " (dist " LI "), closest position is " LI, - iFrame, m_Queue[iClosestBlock].m_iFrameNo, m_Queue[iClosestBlock].m_iFrameNo+m_Queue[iClosestBlock].m_iFrames, + LOG->Trace( "Approximate sound time: driver frame " LI ", m_pImpl->m_Queue frame " LI ".." LI " (dist " LI "), closest position is " LI, + iFrame, m_pImpl->m_Queue[iClosestBlock].m_iFrameNo, m_pImpl->m_Queue[iClosestBlock].m_iFrameNo+m_pImpl->m_Queue[iClosestBlock].m_iFrames, iClosestPositionDist, iClosestPosition ); } @@ -127,12 +163,12 @@ int64_t pos_map_queue::Search( int64_t iFrame, bool *bApproximate ) const void pos_map_queue::Clear() { - m_Queue.clear(); + m_pImpl->m_Queue.clear(); } bool pos_map_queue::IsEmpty() const { - return m_Queue.empty(); + return m_pImpl->m_Queue.empty(); } /* diff --git a/stepmania/src/RageSoundPosMap.h b/stepmania/src/RageSoundPosMap.h index c792e8370c..0521ab3bbf 100644 --- a/stepmania/src/RageSoundPosMap.h +++ b/stepmania/src/RageSoundPosMap.h @@ -3,29 +3,15 @@ #ifndef RAGE_SOUND_POS_MAP_H #define RAGE_SOUND_POS_MAP_H -#include - -struct pos_map_t -{ - /* Frame number from the POV of the sound driver: */ - int64_t m_iFrameNo; - - /* Actual sound position within the sample: */ - int64_t m_iPosition; - - /* The number of frames in this block: */ - int64_t m_iFrames; - - pos_map_t() { m_iFrameNo = 0; m_iPosition = 0; m_iFrames = 0; } - pos_map_t( int64_t iFrame, int iPosition, int iFrames ) { m_iFrameNo = iFrame; m_iPosition = iPosition; m_iFrames = iFrames; } -}; - /* This class maps one range of frames to another. */ +struct pos_map_impl; class pos_map_queue { public: pos_map_queue(); + ~pos_map_queue(); pos_map_queue( const pos_map_queue &cpy ); + pos_map_queue &operator=( const pos_map_queue &rhs ); /* Insert a mapping from iHardwareFrame to iStreamFrame, containing pos iGotFrames. */ void CommitPosition( int64_t iHardwareFrame, int iStreamFrame, int iGotFrames ); @@ -39,9 +25,7 @@ public: bool IsEmpty() const; private: - deque m_Queue; - - void Cleanup(); + pos_map_impl *m_pImpl; };