[Scummvm-cvs-logs] SF.net SVN: scummvm: [30822] scummvm/trunk/engines/kyra

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Fri Feb 8 00:27:08 CET 2008


Revision: 30822
          http://scummvm.svn.sourceforge.net/scummvm/?rev=30822&view=rev
Author:   lordhoto
Date:     2008-02-07 15:27:08 -0800 (Thu, 07 Feb 2008)

Log Message:
-----------
Fixed kyra3 code.

Modified Paths:
--------------
    scummvm/trunk/engines/kyra/kyra_v3.cpp
    scummvm/trunk/engines/kyra/resource.cpp
    scummvm/trunk/engines/kyra/sound.h
    scummvm/trunk/engines/kyra/sound_digital.cpp

Modified: scummvm/trunk/engines/kyra/kyra_v3.cpp
===================================================================
--- scummvm/trunk/engines/kyra/kyra_v3.cpp	2008-02-07 23:14:53 UTC (rev 30821)
+++ scummvm/trunk/engines/kyra/kyra_v3.cpp	2008-02-07 23:27:08 UTC (rev 30822)
@@ -244,13 +244,9 @@
 	if (_soundDigital->isPlaying(_musicSoundChannel))
 		return;
 
-	/*Common::File *handle = new Common::File();
-	uint32 temp = 0;
-	_res->getFileHandle(_menuAudioFile, &temp, *handle);
-	if (handle->isOpen())
-		_musicSoundChannel = _soundDigital->playSound(handle, true);
-	else
-		delete handle;*/
+	Common::SeekableReadStream *stream = _res->getFileStream(_menuAudioFile);
+	if (stream)
+		_musicSoundChannel = _soundDigital->playSound(stream, true);
 }
 
 void KyraEngine_v3::playMusicTrack(int track, int force) {
@@ -271,22 +267,17 @@
 	if (_musicSoundChannel == -1) {
 		assert(track < _soundListSize && track >= 0);
 
-		/*Common::File *handle = new Common::File();
-		uint32 temp = 0;
-		_res->getFileHandle(_soundList[track], &temp, *handle);
-		if (handle->isOpen())
-			_musicSoundChannel = _soundDigital->playSound(handle);
-		else
-			delete handle;*/
+		Common::SeekableReadStream *stream = _res->getFileStream(_soundList[track]);
+		if (stream)
+			_musicSoundChannel = _soundDigital->playSound(stream);
 	}
 
 	_musicSoundChannel = track;
 }
 
 void KyraEngine_v3::stopMusicTrack() {
-	if (_musicSoundChannel != -1 && _soundDigital->isPlaying(_musicSoundChannel)) {
+	if (_musicSoundChannel != -1 && _soundDigital->isPlaying(_musicSoundChannel))
 		_soundDigital->stopSound(_musicSoundChannel);
-	}
 
 	_curMusicTrack = -1;
 	_musicSoundChannel = -1;

Modified: scummvm/trunk/engines/kyra/resource.cpp
===================================================================
--- scummvm/trunk/engines/kyra/resource.cpp	2008-02-07 23:14:53 UTC (rev 30821)
+++ scummvm/trunk/engines/kyra/resource.cpp	2008-02-07 23:27:08 UTC (rev 30822)
@@ -460,10 +460,8 @@
 	Common::List<ResFileEntry>::iterator entry = entries.begin();
 	Common::List<Common::String>::iterator file = filenames.begin();
 
-	for (; entry != entries.end(); ++entry, ++file) {
-		map.erase(*file);
+	for (; entry != entries.end(); ++entry, ++file)
 		map[*file] = *entry;
-	}
 
 	return true;
 }
@@ -496,10 +494,10 @@
 	stream.seek(3);
 	uint32 size = stream.readUint32LE();
 
-	if (size > stream.size())
+	if (size+7 > stream.size())
 		return false;
 
-	stream.seek(size+1, SEEK_SET);
+	stream.seek(size+5, SEEK_SET);
 	uint8 buffer[2];
 	stream.read(&buffer, 2);
 
@@ -536,8 +534,6 @@
 	stream.seek(3, SEEK_SET);
 
 	for (Common::List<Common::String>::iterator file = filenames.begin(); file != filenames.end(); ++file) {
-		map.erase(*file);
-
 		ResFileEntry entry;
 		entry.parent = filename;
 		entry.type = ResFileEntry::kAutoDetect;

Modified: scummvm/trunk/engines/kyra/sound.h
===================================================================
--- scummvm/trunk/engines/kyra/sound.h	2008-02-07 23:14:53 UTC (rev 30821)
+++ scummvm/trunk/engines/kyra/sound.h	2008-02-07 23:27:08 UTC (rev 30822)
@@ -476,7 +476,7 @@
 	/**
 	 * Plays a sound.
 	 *
-	 * @param fileHandle	file handle used for playback.
+	 * @param stream		Data stream used for playback
 	 *                      It will be deleted when playback is finished
 	 * @param loop			true if the sound should loop (endlessly)
 	 * @param fadeIn		true if the sound should be faded in volume wise
@@ -484,7 +484,7 @@
 	 *
 	 * @return channel playing the sound
 	 */
-	int playSound(Common::File *fileHandle, bool loop = false, bool fadeIn = false, int channel = -1);
+	int playSound(Common::SeekableReadStream *stream, bool loop = false, bool fadeIn = false, int channel = -1);
 
 	/**
 	 * Checks if a given channel is playing a sound.

Modified: scummvm/trunk/engines/kyra/sound_digital.cpp
===================================================================
--- scummvm/trunk/engines/kyra/sound_digital.cpp	2008-02-07 23:14:53 UTC (rev 30821)
+++ scummvm/trunk/engines/kyra/sound_digital.cpp	2008-02-07 23:27:08 UTC (rev 30822)
@@ -36,7 +36,7 @@
 
 class AUDStream : public Audio::AudioStream {
 public:
-	AUDStream(Common::File *file, bool loop = false);
+	AUDStream(Common::SeekableReadStream *stream, bool loop = false);
 	~AUDStream();
 
 	int readBuffer(int16 *buffer, const int numSamples);
@@ -49,7 +49,7 @@
 	void beginFadeIn();
 	void beginFadeOut();
 private:
-	Common::File *_file;
+	Common::SeekableReadStream *_stream;
 	bool _loop;
 	uint32 _loopStart;
 	bool _endOfData;
@@ -82,12 +82,12 @@
 	 0,  1,  2,  3,  4,  5,  6,  8
 };
 
-AUDStream::AUDStream(Common::File *file, bool loop) : _file(file), _endOfData(true), _rate(0),
+AUDStream::AUDStream(Common::SeekableReadStream *stream, bool loop) : _stream(stream), _endOfData(true), _rate(0),
 	_processedSize(0), _totalSize(0), _bytesLeft(0), _outBuffer(0),
 	_outBufferOffset(0), _outBufferSize(0), _inBuffer(0), _inBufferSize(0) {
 
-	_rate = _file->readUint16LE();
-	_totalSize = _file->readUint32LE();
+	_rate = _stream->readUint16LE();
+	_totalSize = _stream->readUint32LE();
 	_loop = loop;
 
 	// TODO: Find the correct number of samples for a fade-in/out. Should
@@ -97,10 +97,10 @@
 	_fading = 0;
 
 	// TODO?: add checks
-	int flags = _file->readByte();	// flags
-	int type = _file->readByte();	// type
+	int flags = _stream->readByte();	// flags
+	int type = _stream->readByte();	// type
 
-	_loopStart = file->pos();
+	_loopStart = stream->pos();
 
 	if (type == 1 && !flags) {
 		_endOfData = false;
@@ -111,7 +111,7 @@
 AUDStream::~AUDStream() {
 	delete [] _outBuffer;
 	delete [] _inBuffer;
-	delete _file;
+	delete _stream;
 }
 
 void AUDStream::beginFadeIn() {
@@ -154,7 +154,7 @@
 	if (_bytesLeft <= 0) {
 		if (_processedSize >= _totalSize) {
 			if (_loop) {
-				_file->seek(_loopStart);
+				_stream->seek(_loopStart);
 				_processedSize = 0;
 			} else {
 				_endOfData = true;
@@ -162,9 +162,9 @@
 			}
 		}
 
-		uint16 size = _file->readUint16LE();
-		uint16 outSize = _file->readUint16LE();
-		uint32 id = _file->readUint32LE();
+		uint16 size = _stream->readUint16LE();
+		uint16 outSize = _stream->readUint16LE();
+		uint32 id = _stream->readUint32LE();
 
 		assert(id == 0x0000DEAF);
 
@@ -181,7 +181,7 @@
 
 			_bytesLeft = size;
 
-			_file->read(_outBuffer, _bytesLeft);
+			_stream->read(_outBuffer, _bytesLeft);
 		} else {
 			_bytesLeft = outSize;
 
@@ -199,7 +199,7 @@
 				assert(_inBuffer);
 			}
 
-			if (_file->read(_inBuffer, size) != size) {
+			if (_stream->read(_inBuffer, size) != size) {
 				_endOfData = true;
 				return 0;
 			}
@@ -328,7 +328,7 @@
 		stopSound(i);
 }
 
-int SoundDigital::playSound(Common::File *fileHandle, bool loop, bool fadeIn, int channel) {
+int SoundDigital::playSound(Common::SeekableReadStream *stream, bool loop, bool fadeIn, int channel) {
 	Sound *use = 0;
 	if (channel != -1 && channel < SOUND_STREAMS) {
 		stopSound(channel);
@@ -343,12 +343,12 @@
 
 		if (!use) {
 			warning("no free sound channel");
-			delete fileHandle;
+			delete stream;
 			return -1;
 		}
 	}
 
-	use->stream = new AUDStream(fileHandle, loop);
+	use->stream = new AUDStream(stream, loop);
 	if (use->stream->endOfData()) {
 		delete use->stream;
 		use->stream = 0;


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