diff options
author | Filippos Karapetis | 2009-10-04 09:31:37 +0000 |
---|---|---|
committer | Filippos Karapetis | 2009-10-04 09:31:37 +0000 |
commit | decdc5771a6c4733ab4a1276fc60c2454c8340a6 (patch) | |
tree | e07fb4c33053c840447cac524fb8e45cb0d77fda /engines/made | |
parent | 1ed6a2668be5462694c81369cc5abb89e199e2dc (diff) | |
download | scummvm-rg350-decdc5771a6c4733ab4a1276fc60c2454c8340a6.tar.gz scummvm-rg350-decdc5771a6c4733ab4a1276fc60c2454c8340a6.tar.bz2 scummvm-rg350-decdc5771a6c4733ab4a1276fc60c2454c8340a6.zip |
Applied patch #2872409 "MADE engine fixes" by agent-q, with one small modification (initialized _soundStarted in the ScriptFunctions constructor)
svn-id: r44589
Diffstat (limited to 'engines/made')
-rw-r--r-- | engines/made/pmvplayer.cpp | 1 | ||||
-rw-r--r-- | engines/made/redreader.cpp | 17 | ||||
-rw-r--r-- | engines/made/resource.cpp | 15 | ||||
-rw-r--r-- | engines/made/resource.h | 24 | ||||
-rw-r--r-- | engines/made/script.cpp | 7 | ||||
-rw-r--r-- | engines/made/scriptfuncs.cpp | 25 | ||||
-rw-r--r-- | engines/made/scriptfuncs.h | 6 |
7 files changed, 73 insertions, 22 deletions
diff --git a/engines/made/pmvplayer.cpp b/engines/made/pmvplayer.cpp index a6ee649eda..5fe67b3ba1 100644 --- a/engines/made/pmvplayer.cpp +++ b/engines/made/pmvplayer.cpp @@ -208,6 +208,7 @@ bool PmvPlayer::play(const char *filename) { //delete _audioStream; delete _fd; + _surface->free(); delete _surface; return !_aborted; diff --git a/engines/made/redreader.cpp b/engines/made/redreader.cpp index ac9bcb4610..ca3b2af644 100644 --- a/engines/made/redreader.cpp +++ b/engines/made/redreader.cpp @@ -41,16 +41,19 @@ Common::MemoryReadStream *RedReader::load(const char *redFilename, const char *f 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,7 +85,9 @@ LzhDecompressor::~LzhDecompressor() { 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 @@ int LzhDecompressor::decompress(Common::SeekableReadStream &source, byte *dest, destLen -= bufsize; } + free(buffer); + return 0; } diff --git a/engines/made/resource.cpp b/engines/made/resource.cpp index cfa4f43f65..a2e057f65d 100644 --- a/engines/made/resource.cpp +++ b/engines/made/resource.cpp @@ -45,6 +45,7 @@ PictureResource::PictureResource() : _picture(NULL), _picturePalette(NULL) { PictureResource::~PictureResource() { if (_picture) { + _picture->free(); delete _picture; _picture = 0; } @@ -183,8 +184,10 @@ AnimationResource::AnimationResource() { } 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 @@ void GenericResource::load(byte *source, int size) { ResourceReader::ResourceReader() { _isV1 = false; + _cacheDataSize = 0; } ResourceReader::~ResourceReader() { @@ -543,8 +547,12 @@ Resource *ResourceReader::getResourceFromCache(ResourceSlot *slot) { } 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 @@ void ResourceReader::purgeCache() { 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--; - } + } } } } diff --git a/engines/made/resource.h b/engines/made/resource.h index 8af111551c..ca71dc86f7 100644 --- a/engines/made/resource.h +++ b/engines/made/resource.h @@ -37,7 +37,16 @@ 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'), @@ -63,7 +72,7 @@ public: 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 @@ protected: 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 @@ protected: 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 @@ protected: 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 @@ protected: 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 @@ protected: ResMap _resSlots; int _cacheCount; + int _cacheDataSize; void loadIndex(ResourceSlots *slots); diff --git a/engines/made/script.cpp b/engines/made/script.cpp index 4c3bff77c3..91b932cc92 100644 --- a/engines/made/script.cpp +++ b/engines/made/script.cpp @@ -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 @@ void ScriptInterpreter::runScript(int16 scriptObjectIndex) { _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 @@ void ScriptInterpreter::runScript(int16 scriptObjectIndex) { if (++opcodeSleepCounter > 500) { _vm->_screen->updateScreenAndWait(5); opcodeSleepCounter = 0; + if (_vm->shouldQuit()) { + break; + } } } diff --git a/engines/made/scriptfuncs.cpp b/engines/made/scriptfuncs.cpp index 0f1e7b4512..2e5636d908 100644 --- a/engines/made/scriptfuncs.cpp +++ b/engines/made/scriptfuncs.cpp @@ -187,7 +187,7 @@ int16 ScriptFunctions::sfClearScreen(int16 argc, int16 *argv) { 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::sfSetVisualEffect(int16 argc, int16 *argv) { 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 @@ int16 ScriptFunctions::sfPlaySound(int16 argc, int16 *argv) { soundRes->getAudioStream(_vm->_soundRate, false)); _vm->_soundEnergyArray = soundRes->getSoundEnergyArray(); _vm->_soundEnergyIndex = 0; + _soundStarted = true; + _soundResource = soundRes; } return 0; } @@ -563,19 +565,31 @@ int16 ScriptFunctions::sfSoundPlaying(int16 argc, int16 *argv) { return 0; } -int16 ScriptFunctions::sfStopSound(int16 argc, int16 *argv) { +void ScriptFunctions::stopSound() { _vm->_mixer->stopHandle(_audioStreamHandle); + if (_soundStarted) { + _vm->_res->freeResource(_soundResource); + _soundStarted = false; + } + +} + + +int16 ScriptFunctions::sfStopSound(int16 argc, int16 *argv) { + 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 @@ int16 ScriptFunctions::sfDrawMenu(int16 argc, int16 *argv) { const char *text = menu->getString(textIndex); if (text) _vm->_screen->printText(text); + _vm->_res->freeResource(menu); } return 0; diff --git a/engines/made/scriptfuncs.h b/engines/made/scriptfuncs.h index 39dd9ad77e..5fdfb77f45 100644 --- a/engines/made/scriptfuncs.h +++ b/engines/made/scriptfuncs.h @@ -41,7 +41,7 @@ typedef Common::Functor2<int16, int16*, int16> ExternalFunc; 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 @@ public: 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; |