[Scummvm-cvs-logs] SF.net SVN: scummvm:[44589] scummvm/trunk/engines/made

thebluegr at users.sourceforge.net thebluegr at users.sourceforge.net
Sun Oct 4 11:31:37 CEST 2009


Revision: 44589
          http://scummvm.svn.sourceforge.net/scummvm/?rev=44589&view=rev
Author:   thebluegr
Date:     2009-10-04 09:31:37 +0000 (Sun, 04 Oct 2009)

Log Message:
-----------
Applied patch #2872409 "MADE engine fixes" by agent-q, with one small modification (initialized _soundStarted in the ScriptFunctions constructor)

Modified Paths:
--------------
    scummvm/trunk/engines/made/pmvplayer.cpp
    scummvm/trunk/engines/made/redreader.cpp
    scummvm/trunk/engines/made/resource.cpp
    scummvm/trunk/engines/made/resource.h
    scummvm/trunk/engines/made/script.cpp
    scummvm/trunk/engines/made/scriptfuncs.cpp
    scummvm/trunk/engines/made/scriptfuncs.h

Modified: scummvm/trunk/engines/made/pmvplayer.cpp
===================================================================
--- scummvm/trunk/engines/made/pmvplayer.cpp	2009-10-04 09:13:15 UTC (rev 44588)
+++ scummvm/trunk/engines/made/pmvplayer.cpp	2009-10-04 09:31:37 UTC (rev 44589)
@@ -208,6 +208,7 @@
 
 	//delete _audioStream;
 	delete _fd;
+	_surface->free();
 	delete _surface;
 
 	return !_aborted;

Modified: scummvm/trunk/engines/made/redreader.cpp
===================================================================
--- scummvm/trunk/engines/made/redreader.cpp	2009-10-04 09:13:15 UTC (rev 44588)
+++ scummvm/trunk/engines/made/redreader.cpp	2009-10-04 09:31:37 UTC (rev 44589)
@@ -41,16 +41,19 @@
 
 	byte *fileBuf = (byte *)malloc(fileEntry.origSize);
 
-	LzhDecompressor lzhDec;
-	lzhDec.decompress(fd, fileBuf, fileEntry.compSize, fileEntry.origSize);
+	LzhDecompressor* lzhDec = new LzhDecompressor();
+	lzhDec->decompress(fd, fileBuf, fileEntry.compSize, fileEntry.origSize);
+	delete lzhDec;
 
 	return new Common::MemoryReadStream(fileBuf, fileEntry.origSize, true);
 
 }
 
 Common::MemoryReadStream *RedReader::loadFromRed(const char *redFilename, const char *filename) {
-	RedReader redReader;
-	return redReader.load(redFilename, filename);
+	RedReader* red = new RedReader();
+	Common::MemoryReadStream* stream = red->load(redFilename, filename);
+	delete red;
+	return stream;
 }
 
 bool RedReader::seekFile(Common::File &fd, FileEntry &fileEntry, const char *filename) {
@@ -82,8 +85,10 @@
 int LzhDecompressor::decompress(Common::SeekableReadStream &source, byte *dest, uint32 sourceLen, uint32 destLen) {
 
 	int bufsize;
-	byte buffer[DICSIZ];
+	byte* buffer;
 
+	buffer = (byte *) malloc(DICSIZ);
+
 	_source = &source;
 	_compSize = sourceLen;
 
@@ -100,6 +105,8 @@
 		destLen -= bufsize;
 	}
 
+	free(buffer);
+
 	return 0;
 }
 

Modified: scummvm/trunk/engines/made/resource.cpp
===================================================================
--- scummvm/trunk/engines/made/resource.cpp	2009-10-04 09:13:15 UTC (rev 44588)
+++ scummvm/trunk/engines/made/resource.cpp	2009-10-04 09:31:37 UTC (rev 44589)
@@ -45,6 +45,7 @@
 
 PictureResource::~PictureResource() {
 	if (_picture) {
+		_picture->free();
 		delete _picture;
 		_picture = 0;
 	}
@@ -183,8 +184,10 @@
 }
 
 AnimationResource::~AnimationResource() {
-	for (uint i = 0; i < _frames.size(); i++)
+	for (uint i = 0; i < _frames.size(); i++) {
+		_frames[i]->free();
 		delete _frames[i];
+	}
 }
 
 void AnimationResource::load(byte *source, int size) {
@@ -373,6 +376,7 @@
 
 ResourceReader::ResourceReader() {
 	_isV1 = false;
+	_cacheDataSize = 0;
 }
 
 ResourceReader::~ResourceReader() {
@@ -543,8 +547,12 @@
 }
 
 void ResourceReader::addResourceToCache(ResourceSlot *slot, Resource *res) {
-	if (_cacheCount >= kMaxResourceCacheCount)
+	_cacheDataSize += slot->size;
+
+	if (_cacheDataSize >= kMaxResourceCacheSize) {
 		purgeCache();
+	}
+
 	slot->res = res;
 	slot->refCount = 1;
 	_cacheCount++;
@@ -562,11 +570,12 @@
 		for (ResourceSlots::iterator slotIter = slots->begin(); slotIter != slots->end(); ++slotIter) {
 			ResourceSlot *slot = &(*slotIter);
 			if (slot->refCount <= 0 && slot->res) {
+				_cacheDataSize -= slot->size;
 				delete slot->res;
 				slot->res = NULL;
 				slot->refCount = 0;
 				_cacheCount--;
-			}
+			}			
 		}
 	}
 }

Modified: scummvm/trunk/engines/made/resource.h
===================================================================
--- scummvm/trunk/engines/made/resource.h	2009-10-04 09:13:15 UTC (rev 44588)
+++ scummvm/trunk/engines/made/resource.h	2009-10-04 09:31:37 UTC (rev 44589)
@@ -37,8 +37,17 @@
 
 namespace Made {
 
-const int kMaxResourceCacheCount = 100;
+/// This value specifies the size of the resource cache
+/// which stores recently used resources.  On the DS,
+/// 400Kb is all we can spare, while 1Mb seems like a
+/// good value for larger systems.
+#ifndef __DS__
+const int kMaxResourceCacheSize = 1000 * 1024;
+#else
+const int kMaxResourceCacheSize = 400 * 1024;
+#endif
 
+
 enum ResourceType {
 	kResARCH = MKID_BE('ARCH'),
 	kResFREE = MKID_BE('FREE'),
@@ -63,7 +72,7 @@
 class PictureResource : public Resource {
 public:
 	PictureResource();
-	~PictureResource();
+	virtual ~PictureResource();
 	void load(byte *source, int size);
 	Graphics::Surface *getPicture() const { return _picture; }
 	byte *getPalette() const { return _picturePalette; }
@@ -81,7 +90,7 @@
 class AnimationResource : public Resource {
 public:
 	AnimationResource();
-	~AnimationResource();
+	virtual ~AnimationResource();
 	void load(byte *source, int size);
 	int getCount() const { return _frames.size(); }
 	Graphics::Surface *getFrame(int index) const {
@@ -117,14 +126,14 @@
 class SoundResourceV1 : public SoundResource {
 public:
 	SoundResourceV1() {}
-	~SoundResourceV1() {}
+	virtual ~SoundResourceV1() {}
 	void load(byte *source, int size);
 };
 
 class MenuResource : public Resource {
 public:
 	MenuResource();
-	~MenuResource();
+	virtual ~MenuResource();
 	void load(byte *source, int size);
 	int getCount() const { return _strings.size(); }
 	const char *getString(uint index) const;
@@ -135,7 +144,7 @@
 class FontResource : public Resource {
 public:
 	FontResource();
-	~FontResource();
+	virtual ~FontResource();
 	void load(byte *source, int size);
 	int getHeight() const;
 	int getCharWidth(uint c) const;
@@ -150,7 +159,7 @@
 class GenericResource : public Resource {
 public:
 	GenericResource();
-	~GenericResource();
+	virtual ~GenericResource();
 	void load(byte *source, int size);
 	byte *getData() const { return _data; }
 	int getSize() const { return _size; }
@@ -200,6 +209,7 @@
 
 	ResMap _resSlots;
 	int _cacheCount;
+	int _cacheDataSize;
 
 	void loadIndex(ResourceSlots *slots);
 

Modified: scummvm/trunk/engines/made/script.cpp
===================================================================
--- scummvm/trunk/engines/made/script.cpp	2009-10-04 09:13:15 UTC (rev 44588)
+++ scummvm/trunk/engines/made/script.cpp	2009-10-04 09:31:37 UTC (rev 44589)
@@ -32,10 +32,12 @@
 #include "made/scriptfuncs.h"
 #include "made/screen.h"
 
+
 namespace Made {
 
 /* ScriptInterpreter */
 
+
 ScriptInterpreter::ScriptInterpreter(MadeEngine *vm) : _vm(vm) {
 #ifdef DUMP_SCRIPTS
 #define COMMAND(x, sig) { &ScriptInterpreter::x, #x, sig }
@@ -143,7 +145,7 @@
 	_codeBase = _vm->_dat->getObject(_runningScriptObjectIndex)->getData();
 	_codeIp = _codeBase;
 
-	while (!_vm->shouldQuit()) {
+	while (true) {
 		byte opcode = readByte();
 
 		if (opcode >= 1 && opcode <= _commandsMax) {
@@ -158,6 +160,9 @@
 		if (++opcodeSleepCounter > 500) {
 			_vm->_screen->updateScreenAndWait(5);
 			opcodeSleepCounter = 0;
+			if (_vm->shouldQuit()) {
+				break;
+			}
 		}
 
 	}

Modified: scummvm/trunk/engines/made/scriptfuncs.cpp
===================================================================
--- scummvm/trunk/engines/made/scriptfuncs.cpp	2009-10-04 09:13:15 UTC (rev 44588)
+++ scummvm/trunk/engines/made/scriptfuncs.cpp	2009-10-04 09:31:37 UTC (rev 44589)
@@ -187,7 +187,7 @@
 	if (_vm->_screen->isScreenLocked())
 		return 0;
 	if (_vm->_autoStopSound) {
-		_vm->_mixer->stopHandle(_audioStreamHandle);
+		stopSound();
 		_vm->_autoStopSound = false;
 	}
 	_vm->_screen->clearScreen();
@@ -232,7 +232,7 @@
 int16 ScriptFunctions::sfPlaySound(int16 argc, int16 *argv) {
 	int16 soundNum = argv[0];
 	_vm->_autoStopSound = false;
-	_vm->_mixer->stopHandle(_audioStreamHandle);
+	stopSound();
 	if (argc > 1) {
 		soundNum = argv[1];
 		_vm->_autoStopSound = (argv[0] == 1);
@@ -243,6 +243,8 @@
 			soundRes->getAudioStream(_vm->_soundRate, false));
 		_vm->_soundEnergyArray = soundRes->getSoundEnergyArray();
 		_vm->_soundEnergyIndex = 0;
+		_soundStarted = true;
+		_soundResource = soundRes;
 	}
 	return 0;
 }
@@ -563,19 +565,31 @@
 		return 0;
 }
 
+void ScriptFunctions::stopSound() {
+	_vm->_mixer->stopHandle(_audioStreamHandle);
+	if (_soundStarted) {
+		_vm->_res->freeResource(_soundResource);
+		_soundStarted = false;
+	}
+		
+}
+
+
 int16 ScriptFunctions::sfStopSound(int16 argc, int16 *argv) {
-	_vm->_mixer->stopHandle(_audioStreamHandle);
+	stopSound();
 	_vm->_autoStopSound = false;
 	return 0;
 }
 
 int16 ScriptFunctions::sfPlayVoice(int16 argc, int16 *argv) {
 	int16 soundNum = argv[0];
-	_vm->_mixer->stopHandle(_audioStreamHandle);
+	stopSound();
 	if (soundNum > 0) {
+		_soundResource = _vm->_res->getSound(soundNum);
 		_vm->_mixer->playInputStream(Audio::Mixer::kPlainSoundType, &_audioStreamHandle,
-			_vm->_res->getSound(soundNum)->getAudioStream(_vm->_soundRate, false));
+			_soundResource->getAudioStream(_vm->_soundRate, false));
 		_vm->_autoStopSound = true;
+		_soundStarted = true;
 	}
 	return 0;
 }
@@ -863,6 +877,7 @@
 		const char *text = menu->getString(textIndex);
 		if (text)
 			_vm->_screen->printText(text);
+
 		_vm->_res->freeResource(menu);
 	}
 	return 0;

Modified: scummvm/trunk/engines/made/scriptfuncs.h
===================================================================
--- scummvm/trunk/engines/made/scriptfuncs.h	2009-10-04 09:13:15 UTC (rev 44588)
+++ scummvm/trunk/engines/made/scriptfuncs.h	2009-10-04 09:31:37 UTC (rev 44589)
@@ -41,7 +41,7 @@
 
 class ScriptFunctions {
 public:
-	ScriptFunctions(MadeEngine *vm) : _vm(vm) {}
+	ScriptFunctions(MadeEngine *vm) : _vm(vm), _soundStarted(false) {}
 	virtual ~ScriptFunctions() {
 		for (uint i = 0; i < _externalFuncs.size(); ++i)
 			delete _externalFuncs[i];
@@ -55,10 +55,14 @@
 	void setupExternalsTable();
 	const char* getFuncName(int index) { return _externalFuncNames[index]; }
 	int getCount() const { return _externalFuncs.size(); }
+	void stopSound();
+
 protected:
 	MadeEngine *_vm;
 	Audio::SoundHandle _audioStreamHandle;
 	Audio::SoundHandle _voiceStreamHandle;
+	SoundResource* _soundResource;
+	bool _soundStarted;
 
 	Common::Array<const ExternalFunc*> _externalFuncs;
 	Common::Array<const char *> _externalFuncNames;


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