[Scummvm-cvs-logs] SF.net SVN: scummvm: [25740] scummvm/trunk/sound

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Tue Feb 20 14:50:20 CET 2007


Revision: 25740
          http://scummvm.svn.sourceforge.net/scummvm/?rev=25740&view=rev
Author:   fingolfin
Date:     2007-02-20 05:50:20 -0800 (Tue, 20 Feb 2007)

Log Message:
-----------
Cleaned up AudioCDManager::getCachedTrack (in particular, don't empty a slot in the track cache if we are not going to use it)

Modified Paths:
--------------
    scummvm/trunk/sound/audiocd.cpp
    scummvm/trunk/sound/audiocd.h

Modified: scummvm/trunk/sound/audiocd.cpp
===================================================================
--- scummvm/trunk/sound/audiocd.cpp	2007-02-20 09:52:07 UTC (rev 25739)
+++ scummvm/trunk/sound/audiocd.cpp	2007-02-20 13:50:20 UTC (rev 25740)
@@ -47,7 +47,7 @@
 	DigitalTrackInfo* (*openTrackFunction)(int);
 };
 
-static const TrackFormat TRACK_FORMATS[] = {
+static const TrackFormat s_trackFormats[] = {
 	/* decoderName,		openTrackFunction */
 #ifdef USE_VORBIS
 	{ "Ogg Vorbis",		getVorbisTrack },
@@ -71,7 +71,7 @@
 	_cd.start = 0;
 	_cd.duration = 0;
 	_cd.numLoops = 0;
-	_currentCache = 0;
+	_currentCacheIdx = 0;
 	_mixer = g_system->getMixer();
 	assert(_mixer);
 }
@@ -142,36 +142,40 @@
 }
 
 int AudioCDManager::getCachedTrack(int track) {
-	int i;
-
 	// See if we find the track in the cache
-	for (i = 0; i < CACHE_TRACKS; i++)
+	for (int i = 0; i < CACHE_TRACKS; i++)
 		if (_cachedTracks[i] == track) {
-			if (_trackInfo[i])
-				return i;
-			else
-				return -1;
+			return _trackInfo[i] ? i : -1;
 		}
-	int currentIndex = _currentCache++;
-	_currentCache %= CACHE_TRACKS;
 
-	// Not found, see if it exists
+	// The track is not already in the cache. Try and see if
+	// we can load it.
+	DigitalTrackInfo *newTrack = 0;
+	for (const TrackFormat *format = s_trackFormats;
+	     format->openTrackFunction != NULL && newTrack == NULL;
+	     ++format) {
+		newTrack = format->openTrackFunction(track);
+	}
 
-	// First, delete the previous track info object
-	delete _trackInfo[currentIndex];
-	_trackInfo[currentIndex] = NULL;
-	_cachedTracks[currentIndex] = 0;
+	int currentIndex = -1;
 
-	for (i = 0; i < ARRAYSIZE(TRACK_FORMATS)-1 && _trackInfo[currentIndex] == NULL; ++i)
-		_trackInfo[currentIndex] = TRACK_FORMATS[i].openTrackFunction(track);
+	if (newTrack != NULL) {
+		// We successfully loaded a digital track. Store it into _trackInfo.
 
-	if (_trackInfo[currentIndex] != NULL) {
+		currentIndex = _currentCacheIdx++;
+		_currentCacheIdx %= CACHE_TRACKS;
+	
+		// First, delete the previous track info object
+		delete _trackInfo[currentIndex];
+
+		// Then, store the new track info object
+		_trackInfo[currentIndex] = newTrack;
 		_cachedTracks[currentIndex] = track;
-		return currentIndex;
+	} else {
+		debug(2, "Track %d not available in compressed format", track);
 	}
 
-	debug(2, "Track %d not available in compressed format", track);
-	return -1;
+	return currentIndex;
 }
 
 } // End of namespace Audio

Modified: scummvm/trunk/sound/audiocd.h
===================================================================
--- scummvm/trunk/sound/audiocd.h	2007-02-20 09:52:07 UTC (rev 25739)
+++ scummvm/trunk/sound/audiocd.h	2007-02-20 13:50:20 UTC (rev 25740)
@@ -34,8 +34,10 @@
 
 class DigitalTrackInfo {
 public:
+	virtual ~DigitalTrackInfo() {}
+
 	virtual void play(Mixer *mixer, SoundHandle *handle, int startFrame, int duration) = 0;
-	virtual ~DigitalTrackInfo() { }
+//	virtual void stop();
 };
 
 
@@ -80,7 +82,7 @@
 	};
 	int _cachedTracks[CACHE_TRACKS];
 	DigitalTrackInfo *_trackInfo[CACHE_TRACKS];
-	int _currentCache;
+	int _currentCacheIdx;
 
 	Mixer	*_mixer;
 };


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list