Ticket #9094: made_fixes.patch
File made_fixes.patch, 8.8 KB (added by , 15 years ago) |
---|
-
engines/made/pmvplayer.cpp
208 208 209 209 //delete _audioStream; 210 210 delete _fd; 211 _surface->free(); 211 212 delete _surface; 212 213 213 214 return !_aborted; -
engines/made/redreader.cpp
41 41 42 42 byte *fileBuf = (byte *)malloc(fileEntry.origSize); 43 43 44 LzhDecompressor lzhDec; 45 lzhDec.decompress(fd, fileBuf, fileEntry.compSize, fileEntry.origSize); 44 LzhDecompressor* lzhDec = new LzhDecompressor(); 45 lzhDec->decompress(fd, fileBuf, fileEntry.compSize, fileEntry.origSize); 46 delete lzhDec; 46 47 47 48 return new Common::MemoryReadStream(fileBuf, fileEntry.origSize, true); 48 49 49 50 } 50 51 51 52 Common::MemoryReadStream *RedReader::loadFromRed(const char *redFilename, const char *filename) { 52 RedReader redReader; 53 return redReader.load(redFilename, filename); 53 RedReader* red = new RedReader(); 54 Common::MemoryReadStream* stream = red->load(redFilename, filename); 55 delete red; 56 return stream; 54 57 } 55 58 56 59 bool RedReader::seekFile(Common::File &fd, FileEntry &fileEntry, const char *filename) { … … 82 85 int LzhDecompressor::decompress(Common::SeekableReadStream &source, byte *dest, uint32 sourceLen, uint32 destLen) { 83 86 84 87 int bufsize; 85 byte buffer[DICSIZ];88 byte* buffer; 86 89 90 buffer = (byte *) malloc(DICSIZ); 91 87 92 _source = &source; 88 93 _compSize = sourceLen; 89 94 … … 100 105 destLen -= bufsize; 101 106 } 102 107 108 free(buffer); 109 103 110 return 0; 104 111 } 105 112 -
engines/made/resource.cpp
45 45 46 46 PictureResource::~PictureResource() { 47 47 if (_picture) { 48 _picture->free(); 48 49 delete _picture; 49 50 _picture = 0; 50 51 } … … 183 184 } 184 185 185 186 AnimationResource::~AnimationResource() { 186 for (uint i = 0; i < _frames.size(); i++) 187 for (uint i = 0; i < _frames.size(); i++) { 188 _frames[i]->free(); 187 189 delete _frames[i]; 190 } 188 191 } 189 192 190 193 void AnimationResource::load(byte *source, int size) { … … 373 376 374 377 ResourceReader::ResourceReader() { 375 378 _isV1 = false; 379 _cacheDataSize = 0; 376 380 } 377 381 378 382 ResourceReader::~ResourceReader() { … … 543 547 } 544 548 545 549 void ResourceReader::addResourceToCache(ResourceSlot *slot, Resource *res) { 546 if (_cacheCount >= kMaxResourceCacheCount) 550 _cacheDataSize += slot->size; 551 552 if (_cacheDataSize >= kMaxResourceCacheSize) { 547 553 purgeCache(); 554 } 555 548 556 slot->res = res; 549 557 slot->refCount = 1; 550 558 _cacheCount++; … … 562 570 for (ResourceSlots::iterator slotIter = slots->begin(); slotIter != slots->end(); ++slotIter) { 563 571 ResourceSlot *slot = &(*slotIter); 564 572 if (slot->refCount <= 0 && slot->res) { 573 _cacheDataSize -= slot->size; 565 574 delete slot->res; 566 575 slot->res = NULL; 567 576 slot->refCount = 0; 568 577 _cacheCount--; 569 } 578 } 570 579 } 571 580 } 572 581 } -
engines/made/resource.h
37 37 38 38 namespace Made { 39 39 40 const int kMaxResourceCacheCount = 100; 40 /// This value specifies the size of the resource cache 41 /// which stores recently used resources. On the DS, 42 /// 400Kb is all we can spare, while 1Mb seems like a 43 /// good value for larger systems. 44 #ifndef __DS__ 45 const int kMaxResourceCacheSize = 1000 * 1024; 46 #else 47 const int kMaxResourceCacheSize = 400 * 1024; 48 #endif 41 49 50 42 51 enum ResourceType { 43 52 kResARCH = MKID_BE('ARCH'), 44 53 kResFREE = MKID_BE('FREE'), … … 63 72 class PictureResource : public Resource { 64 73 public: 65 74 PictureResource(); 66 ~PictureResource();75 virtual ~PictureResource(); 67 76 void load(byte *source, int size); 68 77 Graphics::Surface *getPicture() const { return _picture; } 69 78 byte *getPalette() const { return _picturePalette; } … … 81 90 class AnimationResource : public Resource { 82 91 public: 83 92 AnimationResource(); 84 ~AnimationResource();93 virtual ~AnimationResource(); 85 94 void load(byte *source, int size); 86 95 int getCount() const { return _frames.size(); } 87 96 Graphics::Surface *getFrame(int index) const { … … 117 126 class SoundResourceV1 : public SoundResource { 118 127 public: 119 128 SoundResourceV1() {} 120 ~SoundResourceV1() {}129 virtual ~SoundResourceV1() {} 121 130 void load(byte *source, int size); 122 131 }; 123 132 124 133 class MenuResource : public Resource { 125 134 public: 126 135 MenuResource(); 127 ~MenuResource();136 virtual ~MenuResource(); 128 137 void load(byte *source, int size); 129 138 int getCount() const { return _strings.size(); } 130 139 const char *getString(uint index) const; … … 135 144 class FontResource : public Resource { 136 145 public: 137 146 FontResource(); 138 ~FontResource();147 virtual ~FontResource(); 139 148 void load(byte *source, int size); 140 149 int getHeight() const; 141 150 int getCharWidth(uint c) const; … … 150 159 class GenericResource : public Resource { 151 160 public: 152 161 GenericResource(); 153 ~GenericResource();162 virtual ~GenericResource(); 154 163 void load(byte *source, int size); 155 164 byte *getData() const { return _data; } 156 165 int getSize() const { return _size; } … … 200 209 201 210 ResMap _resSlots; 202 211 int _cacheCount; 212 int _cacheDataSize; 203 213 204 214 void loadIndex(ResourceSlots *slots); 205 215 -
engines/made/script.cpp
32 32 #include "made/scriptfuncs.h" 33 33 #include "made/screen.h" 34 34 35 35 36 namespace Made { 36 37 37 38 /* ScriptInterpreter */ 38 39 40 39 41 ScriptInterpreter::ScriptInterpreter(MadeEngine *vm) : _vm(vm) { 40 42 #ifdef DUMP_SCRIPTS 41 43 #define COMMAND(x, sig) { &ScriptInterpreter::x, #x, sig } … … 143 145 _codeBase = _vm->_dat->getObject(_runningScriptObjectIndex)->getData(); 144 146 _codeIp = _codeBase; 145 147 146 while ( !_vm->shouldQuit()) {148 while (true) { 147 149 byte opcode = readByte(); 148 150 149 151 if (opcode >= 1 && opcode <= _commandsMax) { … … 158 160 if (++opcodeSleepCounter > 500) { 159 161 _vm->_screen->updateScreenAndWait(5); 160 162 opcodeSleepCounter = 0; 163 if (_vm->shouldQuit()) { 164 break; 165 } 161 166 } 162 167 163 168 } -
engines/made/scriptfuncs.cpp
187 187 if (_vm->_screen->isScreenLocked()) 188 188 return 0; 189 189 if (_vm->_autoStopSound) { 190 _vm->_mixer->stopHandle(_audioStreamHandle);190 stopSound(); 191 191 _vm->_autoStopSound = false; 192 192 } 193 193 _vm->_screen->clearScreen(); … … 232 232 int16 ScriptFunctions::sfPlaySound(int16 argc, int16 *argv) { 233 233 int16 soundNum = argv[0]; 234 234 _vm->_autoStopSound = false; 235 _vm->_mixer->stopHandle(_audioStreamHandle);235 stopSound(); 236 236 if (argc > 1) { 237 237 soundNum = argv[1]; 238 238 _vm->_autoStopSound = (argv[0] == 1); … … 243 243 soundRes->getAudioStream(_vm->_soundRate, false)); 244 244 _vm->_soundEnergyArray = soundRes->getSoundEnergyArray(); 245 245 _vm->_soundEnergyIndex = 0; 246 _soundStarted = true; 247 _soundResource = soundRes; 246 248 } 247 249 return 0; 248 250 } … … 563 565 return 0; 564 566 } 565 567 568 void ScriptFunctions::stopSound() { 569 _vm->_mixer->stopHandle(_audioStreamHandle); 570 if (_soundStarted) { 571 _vm->_res->freeResource(_soundResource); 572 _soundStarted = false; 573 } 574 575 } 576 577 566 578 int16 ScriptFunctions::sfStopSound(int16 argc, int16 *argv) { 567 _vm->_mixer->stopHandle(_audioStreamHandle);579 stopSound(); 568 580 _vm->_autoStopSound = false; 569 581 return 0; 570 582 } 571 583 572 584 int16 ScriptFunctions::sfPlayVoice(int16 argc, int16 *argv) { 573 585 int16 soundNum = argv[0]; 574 _vm->_mixer->stopHandle(_audioStreamHandle);586 stopSound(); 575 587 if (soundNum > 0) { 588 _soundResource = _vm->_res->getSound(soundNum); 576 589 _vm->_mixer->playInputStream(Audio::Mixer::kPlainSoundType, &_audioStreamHandle, 577 _ vm->_res->getSound(soundNum)->getAudioStream(_vm->_soundRate, false));590 _soundResource->getAudioStream(_vm->_soundRate, false)); 578 591 _vm->_autoStopSound = true; 592 _soundStarted = true; 579 593 } 580 594 return 0; 581 595 } … … 863 877 const char *text = menu->getString(textIndex); 864 878 if (text) 865 879 _vm->_screen->printText(text); 880 866 881 _vm->_res->freeResource(menu); 867 882 } 868 883 return 0; -
engines/made/scriptfuncs.h
55 55 void setupExternalsTable(); 56 56 const char* getFuncName(int index) { return _externalFuncNames[index]; } 57 57 int getCount() const { return _externalFuncs.size(); } 58 void stopSound(); 59 58 60 protected: 59 61 MadeEngine *_vm; 60 62 Audio::SoundHandle _audioStreamHandle; 61 63 Audio::SoundHandle _voiceStreamHandle; 64 SoundResource* _soundResource; 65 bool _soundStarted; 62 66 63 67 Common::Array<const ExternalFunc*> _externalFuncs; 64 68 Common::Array<const char *> _externalFuncNames;