[Scummvm-cvs-logs] SF.net SVN: scummvm:[39178] scummvm/trunk/engines/sci/sfx

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Sat Mar 7 07:57:20 CET 2009


Revision: 39178
          http://scummvm.svn.sourceforge.net/scummvm/?rev=39178&view=rev
Author:   fingolfin
Date:     2009-03-07 06:57:17 +0000 (Sat, 07 Mar 2009)

Log Message:
-----------
SCI: Replaced linked list of Sci1Samples by a Common::List

Modified Paths:
--------------
    scummvm/trunk/engines/sci/sfx/iterator.cpp
    scummvm/trunk/engines/sci/sfx/iterator_internal.h

Modified: scummvm/trunk/engines/sci/sfx/iterator.cpp
===================================================================
--- scummvm/trunk/engines/sci/sfx/iterator.cpp	2009-03-07 06:56:39 UTC (rev 39177)
+++ scummvm/trunk/engines/sci/sfx/iterator.cpp	2009-03-07 06:57:17 UTC (rev 39178)
@@ -509,12 +509,12 @@
 
 	pcm_data = self->_data + offset;
 
-	size = getUInt16(pcm_data + SCI0_PCM_SIZE_OFFSET);
+	size = READ_LE_UINT16(pcm_data + SCI0_PCM_SIZE_OFFSET);
 
 	/* Two of the format parameters are fixed by design: */
 	format->format = SFX_PCM_FORMAT_U8;
 	format->stereo = SFX_PCM_MONO;
-	format->rate = getUInt16(pcm_data + SCI0_PCM_SAMPLE_RATE_OFFSET);
+	format->rate = READ_LE_UINT16(pcm_data + SCI0_PCM_SAMPLE_RATE_OFFSET);
 
 	if (offset + SCI0_PCM_DATA_OFFSET + size != self->_size) {
 		int d = offset + SCI0_PCM_DATA_OFFSET + size - self->_size;
@@ -709,7 +709,7 @@
 #define SCI1_CHANDATA(off) self->_data[channel->offset + (off)]
 
 static int _sci1_sample_init(Sci1SongIterator *self, int offset) {
-	Sci1Sample *sample, **seekerp;
+	Sci1Sample sample;
 	int rate;
 	int length;
 	int begin;
@@ -721,46 +721,41 @@
 		          self->_data[offset + 1]);
 
 	rate = getInt16(self->_data + offset + 2);
-	length = getUInt16(self->_data + offset + 4);
+	length = READ_LE_UINT16(self->_data + offset + 4);
 	begin = getInt16(self->_data + offset + 6);
 	end = getInt16(self->_data + offset + 8);
 
 	CHECK_FOR_END_ABSOLUTE((uint)(offset + 10 + length));
 
-	sample = new Sci1Sample();
-	sample->delta = begin;
-	sample->size = length;
-	sample->_data = self->_data + offset + 10;
+	sample.delta = begin;
+	sample.size = length;
+	sample._data = self->_data + offset + 10;
 
 #ifdef DEBUG_VERBOSE
 	fprintf(stderr, "[SAMPLE] %x/%x/%x/%x l=%x\n",
 	        offset + 10, begin, end, self->_size, length);
 #endif
 
-	sample->format.format = SFX_PCM_FORMAT_U8;
-	sample->format.stereo = SFX_PCM_MONO;
-	sample->format.rate = rate;
+	sample.format.format = SFX_PCM_FORMAT_U8;
+	sample.format.stereo = SFX_PCM_MONO;
+	sample.format.rate = rate;
 
-	sample->announced = false;
+	sample.announced = false;
 
 	/* Perform insertion sort */
-	seekerp = &(self->_nextSample);
+	Common::List<Sci1Sample>::iterator seeker = self->_samples.begin();
+	while (seeker != self->_samples.end() && seeker->delta < begin)
+		++seeker;
+	self->_samples.insert(seeker, sample);
 
-	while (*seekerp && (*seekerp)->delta < begin)
-		seekerp = &((*seekerp)->next);
-
-	sample->next = *seekerp;
-	*seekerp = sample;
-
 	return 0; /* Everything's fine */
 }
 
 static int _sci1_song_init(Sci1SongIterator *self) {
-	Sci1Sample *seeker;
 	int last_time;
 	uint offset = 0;
 	self->_numChannels = 0;
-	self->_nextSample = 0;
+	self->_samples.clear();
 //	self->_deviceId = 0x0c;
 
 	if (SONGDATA(0) == 0xf0) {
@@ -796,8 +791,8 @@
 
 		CHECK_FOR_END_ABSOLUTE(offset + 4);
 
-		track_offset = getUInt16(self->_data + offset);
-		end = getUInt16(self->_data + offset + 2);
+		track_offset = READ_LE_UINT16(self->_data + offset);
+		end = READ_LE_UINT16(self->_data + offset + 2);
 
 		CHECK_FOR_END_ABSOLUTE(track_offset - 1);
 
@@ -842,19 +837,18 @@
 		CHECK_FOR_END_ABSOLUTE(offset);
 	}
 
-	/* Now ensure that sapmle deltas are relative to the previous sample */
-	seeker = self->_nextSample;
+	/* Now ensure that sam\xFCle deltas are relative to the previous sample */
 	last_time = 0;
 	self->active_channels = self->_numChannels;
 	self->_numLoopedChannels = 0;
 
-	while (seeker) {
+	for (Common::List<Sci1Sample>::iterator seeker = self->_samples.begin();
+			seeker != self->_samples.end(); ++seeker) {
 		int prev_last_time = last_time;
 		sciprintf("[iterator-1] Detected sample: %d Hz, %d bytes at time %d\n",
 		          seeker->format.rate, seeker->size, seeker->delta);
 		last_time = seeker->delta;
 		seeker->delta -= prev_last_time;
-		seeker = seeker->next;
 	}
 
 	return 0; /* Success */
@@ -869,8 +863,8 @@
 		        && (d == -1 || self->_channels[i].delay < d))
 			d = self->_channels[i].delay;
 
-	if (self->_nextSample && self->_nextSample->delta < d)
-		return self->_nextSample->delta;
+	if (!self->_samples.empty() && self->_samples.begin()->delta < d)
+		return self->_samples.begin()->delta;
 	else
 		return d;
 }
@@ -878,8 +872,8 @@
 static void _sci1_update_delta(Sci1SongIterator *self, int delta) {
 	int i;
 
-	if (self->_nextSample)
-		self->_nextSample->delta -= delta;
+	if (!self->_samples.empty())
+		self->_samples.begin()->delta -= delta;
 
 	for (i = 0; i < self->_numChannels; i++)
 		if (self->_channels[i].state == SI_STATE_COMMAND)
@@ -925,9 +919,9 @@
 		}
 		sciprintf("\n");
 	}
-	if (self->_nextSample) {
+	if (!self->_samples.empty()) {
 		sciprintf("\t[sample %d]\n",
-		          self->_nextSample->delta);
+		          self->_samples.begin()->delta);
 	}
 	sciprintf("------------------------------------------\n");
 }
@@ -957,7 +951,7 @@
 			}
 		}
 
-	if (self->_nextSample && base_delay >= self->_nextSample->delta)
+	if (!self->_samples.empty() && base_delay >= self->_samples.begin()->delta)
 		return COMMAND_INDEX_PCM;
 
 	return best_chan;
@@ -965,15 +959,11 @@
 
 
 Audio::AudioStream *Sci1SongIterator::getAudioStream() {
-	if (_nextSample && _nextSample->delta <= 0) {
-		Sci1Sample *sample = _nextSample;
-
+	Common::List<Sci1Sample>::iterator sample = _samples.begin();
+	if (sample != _samples.end() && sample->delta <= 0) {
 		Audio::AudioStream *feed = makeStream(sample->_data, sample->size, sample->format);
+		_samples.erase(sample);
 
-		_nextSample = _nextSample->next;
-
-		delete sample;
-
 		return feed;
 	} else
 		return NULL;
@@ -1007,19 +997,19 @@
 
 		if (chan == COMMAND_INDEX_PCM) {
 
-			if (_nextSample->announced) {
+			if (_samples.begin()->announced) {
 				/* Already announced; let's discard it */
 				Audio::AudioStream *feed = getAudioStream();
 				delete feed;
 			} else {
-				int delay = _nextSample->delta;
+				int delay = _samples.begin()->delta;
 
 				if (delay) {
 					_sci1_update_delta(this, delay);
 					return delay;
 				}
 				/* otherwise we're touching a PCM */
-				_nextSample->announced = true;
+				_samples.begin()->announced = true;
 				return SI_PCM;
 			}
 		} else { /* Not a PCM */
@@ -1088,22 +1078,11 @@
 
 		case _SIMSG_BASEMSG_CLONE: {
 			Sci1SongIterator *mem = new Sci1SongIterator(*this);
-			Sci1Sample **samplep;
 			int delta = msg.args[0].i; /* Delay until next step */
 
-			samplep = &(mem->_nextSample);
-
 			sci_refcount_incref(mem->_data);
-
 			mem->_delayRemaining += delta;
 
-			/* Clone chain of samples */
-			while (*samplep) {
-				Sci1Sample *newsample = new Sci1Sample(**samplep);
-				*samplep = newsample;
-				samplep = &(newsample->next);
-			}
-
 			return mem; /* Assume caller has another copy of this */
 		}
 
@@ -1214,7 +1193,6 @@
 
 	ccc = 127;
 	_deviceId = 0x00; // Default to Sound Blaster/Adlib for purposes of cue computation
-	_nextSample = NULL;
 	_numChannels = 0;
 	_initialised = false;
 	_delayRemaining = 0;
@@ -1225,12 +1203,6 @@
 }
 
 Sci1SongIterator::~Sci1SongIterator() {
-	Sci1Sample *sample_seeker = _nextSample;
-	while (sample_seeker) {
-		Sci1Sample *old_sample = sample_seeker;
-		sample_seeker = sample_seeker->next;
-		delete old_sample;
-	}
 }
 
 int Sci1SongIterator::getTimepos() {

Modified: scummvm/trunk/engines/sci/sfx/iterator_internal.h
===================================================================
--- scummvm/trunk/engines/sci/sfx/iterator_internal.h	2009-03-07 06:56:39 UTC (rev 39177)
+++ scummvm/trunk/engines/sci/sfx/iterator_internal.h	2009-03-07 06:57:17 UTC (rev 39178)
@@ -29,6 +29,8 @@
 #include "sci/sfx/iterator.h"
 #include "sci/sfx/sci_midi.h"
 
+#include "common/list.h"
+
 namespace Sci {
 
 /* States */
@@ -133,7 +135,6 @@
 	bool announced; /* Announced for download (SI_PCM) */
 	sfx_pcm_config_t format;
 	byte *_data;
-	Sci1Sample *next;
 };
 
 class Sci1SongIterator : public BaseSongIterator {
@@ -145,7 +146,7 @@
 
 	bool _initialised; /* Whether the MIDI channel setup has been initialised */
 	int _numChannels; /* Number of channels actually used */
-	Sci1Sample *_nextSample;
+	Common::List<Sci1Sample> _samples;
 	int _numLoopedChannels; /* Number of channels that are ready to loop */
 
 	int _delayRemaining; /* Number of ticks that haven't been polled yet */


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