diff options
Diffstat (limited to 'engines')
-rw-r--r-- | engines/toon/anim.cpp | 1 | ||||
-rw-r--r-- | engines/toon/audio.cpp | 26 | ||||
-rw-r--r-- | engines/toon/character.cpp | 3 | ||||
-rw-r--r-- | engines/toon/drew.cpp | 2 | ||||
-rw-r--r-- | engines/toon/drew.h | 2 | ||||
-rw-r--r-- | engines/toon/flux.cpp | 2 | ||||
-rw-r--r-- | engines/toon/flux.h | 2 | ||||
-rw-r--r-- | engines/toon/hotspot.cpp | 8 | ||||
-rw-r--r-- | engines/toon/movie.cpp | 3 | ||||
-rw-r--r-- | engines/toon/resource.cpp | 24 | ||||
-rw-r--r-- | engines/toon/resource.h | 4 | ||||
-rw-r--r-- | engines/toon/script.cpp | 13 | ||||
-rw-r--r-- | engines/toon/script_func.cpp | 3 | ||||
-rw-r--r-- | engines/toon/text.cpp | 6 | ||||
-rw-r--r-- | engines/toon/toon.cpp | 57 |
15 files changed, 99 insertions, 57 deletions
diff --git a/engines/toon/anim.cpp b/engines/toon/anim.cpp index 169d53de5d..aa85db954e 100644 --- a/engines/toon/anim.cpp +++ b/engines/toon/anim.cpp @@ -108,6 +108,7 @@ bool Animation::loadAnimation(Common::String file) { } } + //delete[] fileData; delete[] finalBuffer; return true; } diff --git a/engines/toon/audio.cpp b/engines/toon/audio.cpp index 592d1a7388..3fba7d6cd8 100644 --- a/engines/toon/audio.cpp +++ b/engines/toon/audio.cpp @@ -44,10 +44,10 @@ static int ADPCM_table[89] = { AudioManager::AudioManager(ToonEngine *vm, Audio::Mixer *mixer) : _vm(vm), _mixer(mixer) { for (int32 i = 0; i < 16; i++) - _channels[i] = 0; + _channels[i] = NULL; for (int32 i = 0; i < 4; i++) - _audioPacks[i] = 0; + _audioPacks[i] = NULL; for (int32 i = 0; i < 4; i++) { _ambientSFXs[i]._delay = 0; @@ -90,7 +90,7 @@ void AudioManager::removeInstance(AudioStreamInstance *inst) { for (int32 i = 0; i < 16; i++) { if (inst == _channels[i]) - _channels[i] = 0; + _channels[i] = NULL; } } @@ -130,9 +130,7 @@ void AudioManager::playMusic(Common::String dir, Common::String music) { _currentMusicChannel = 0; } - - //if (!_channels[_currentMusicChannel]) - // delete _channels[_currentMusicChannel]; + delete _channels[_currentMusicChannel]; _channels[_currentMusicChannel] = new AudioStreamInstance(this, _mixer, srs, true); _channels[_currentMusicChannel]->setVolume(_musicMuted ? 0 : 255); _channels[_currentMusicChannel]->play(true, Audio::Mixer::kMusicSoundType); @@ -159,6 +157,7 @@ void AudioManager::playVoice(int32 id, bool genericVoice) { else stream = _audioPacks[1]->getStream(id); + delete _channels[2]; _channels[2] = new AudioStreamInstance(this, _mixer, stream); _channels[2]->play(false, Audio::Mixer::kSpeechSoundType); _channels[2]->setVolume(_voiceMuted ? 0 : 255); @@ -240,10 +239,10 @@ void AudioManager::stopMusic() { AudioStreamInstance::AudioStreamInstance(AudioManager *man, Audio::Mixer *mixer, Common::SeekableReadStream *stream , bool looping) { _compBufferSize = 0; - _buffer = 0; + _buffer = NULL; _bufferMaxSize = 0; _mixer = mixer; - _compBuffer = 0; + _compBuffer = NULL; _bufferOffset = 0; _lastADPCMval1 = 0; _lastADPCMval2 = 0; @@ -269,6 +268,9 @@ AudioStreamInstance::AudioStreamInstance(AudioManager *man, Audio::Mixer *mixer, } AudioStreamInstance::~AudioStreamInstance() { + delete[] _buffer; + delete[] _compBuffer; + if (_man) _man->removeInstance(this); } @@ -319,15 +321,13 @@ bool AudioStreamInstance::readPacket() { _file->readSint32LE(); if (numCompressedBytes > _compBufferSize) { - if (_compBuffer) - delete[] _compBuffer; + delete[] _compBuffer; _compBufferSize = numCompressedBytes; _compBuffer = new uint8[_compBufferSize]; } if (numDecompressedBytes > _bufferMaxSize) { - if (_buffer) - delete [] _buffer; + delete [] _buffer; _bufferMaxSize = numDecompressedBytes; _buffer = new int16[numDecompressedBytes]; } @@ -450,9 +450,7 @@ void AudioStreamInstance::handleFade(int32 numSamples) { _musicAttenuation = 1000; } - _mixer->setChannelVolume(_handle, finalVolume * _musicAttenuation / 1000); - } void AudioStreamInstance::stop(bool fade /*= false*/) { diff --git a/engines/toon/character.cpp b/engines/toon/character.cpp index 113054c1b8..dc0f47ea4f 100644 --- a/engines/toon/character.cpp +++ b/engines/toon/character.cpp @@ -31,7 +31,7 @@ namespace Toon { Character::Character(ToonEngine *vm) : _vm(vm) { - _animationInstance = 0; + _animationInstance = NULL; _shadowAnimationInstance = NULL; _x = 0; _y = 0; @@ -66,6 +66,7 @@ Character::Character(ToonEngine *vm) : _vm(vm) { } Character::~Character(void) { + delete _animationInstance; delete _shadowAnimationInstance; delete _walkAnim; diff --git a/engines/toon/drew.cpp b/engines/toon/drew.cpp index b50a8db3dc..a82343c852 100644 --- a/engines/toon/drew.cpp +++ b/engines/toon/drew.cpp @@ -35,7 +35,7 @@ CharacterDrew::CharacterDrew(ToonEngine *vm) : Character(vm) { vm->getAnimationManager()->addInstance(_animationInstance); } -CharacterDrew::~CharacterDrew(void) { +CharacterDrew::~CharacterDrew() { } bool CharacterDrew::setupPalette() { diff --git a/engines/toon/drew.h b/engines/toon/drew.h index a5be4c76c3..35afa6ccdf 100644 --- a/engines/toon/drew.h +++ b/engines/toon/drew.h @@ -36,7 +36,7 @@ class ToonEngine; class CharacterDrew : public Character { public: CharacterDrew(ToonEngine *vm); - virtual ~CharacterDrew(void); + virtual ~CharacterDrew(); bool setupPalette(); void setFacing(int32 facing); void playStandingAnim(); diff --git a/engines/toon/flux.cpp b/engines/toon/flux.cpp index 9dd38cd37a..2b5551732b 100644 --- a/engines/toon/flux.cpp +++ b/engines/toon/flux.cpp @@ -34,7 +34,7 @@ CharacterFlux::CharacterFlux(ToonEngine *vm) : Character(vm) { vm->getAnimationManager()->addInstance(_animationInstance); } -CharacterFlux::~CharacterFlux(void) { +CharacterFlux::~CharacterFlux() { } void CharacterFlux::playStandingAnim() { diff --git a/engines/toon/flux.h b/engines/toon/flux.h index 7981799cba..a90853cb02 100644 --- a/engines/toon/flux.h +++ b/engines/toon/flux.h @@ -36,7 +36,7 @@ namespace Toon { class CharacterFlux : public Character { public: CharacterFlux(ToonEngine *vm); - virtual ~CharacterFlux(void); + virtual ~CharacterFlux(); void setPosition(int32 x, int32 y); void playStandingAnim(); diff --git a/engines/toon/hotspot.cpp b/engines/toon/hotspot.cpp index 782e49c2d5..687ea6ee83 100644 --- a/engines/toon/hotspot.cpp +++ b/engines/toon/hotspot.cpp @@ -29,11 +29,12 @@ namespace Toon { Hotspots::Hotspots(ToonEngine *vm) : _vm(vm) { - _items = 0; + _items = NULL; _numItems = 0; } Hotspots::~Hotspots() { + delete[] _items; } void Hotspots::load(Common::ReadStream *Stream) { @@ -49,7 +50,6 @@ void Hotspots::load(Common::ReadStream *Stream) { } void Hotspots::save(Common::WriteStream *Stream) { - Stream->writeSint16BE(_numItems); for (int32 i = 0; i < _numItems; i++) { @@ -123,9 +123,7 @@ bool Hotspots::LoadRif(Common::String rifName, Common::String additionalRifName) _numItems = (rifsize + rifsize2) / 512; - if (_items) - delete[] _items; - + delete[] _items; _items = new HotspotData[_numItems]; // RIFs are compressed in RNC1 diff --git a/engines/toon/movie.cpp b/engines/toon/movie.cpp index 91ea98a91f..e56bb82cfa 100644 --- a/engines/toon/movie.cpp +++ b/engines/toon/movie.cpp @@ -56,9 +56,9 @@ bool ToonstruckSmackerDecoder::loadFile(const Common::String &filename, int forc } ToonstruckSmackerDecoder::ToonstruckSmackerDecoder(Audio::Mixer *mixer, Audio::Mixer::SoundType soundType) : Graphics::SmackerDecoder(mixer, soundType) { - } +// decoder is deallocated with Movie destruction i.e. new ToonstruckSmackerDecoder is needed Movie::Movie(ToonEngine *vm , ToonstruckSmackerDecoder *decoder) { _vm = vm; _playing = false; @@ -66,6 +66,7 @@ Movie::Movie(ToonEngine *vm , ToonstruckSmackerDecoder *decoder) { } Movie::~Movie() { + delete _decoder; } void Movie::init() const { diff --git a/engines/toon/resource.cpp b/engines/toon/resource.cpp index 470c54f8f4..f76db47539 100644 --- a/engines/toon/resource.cpp +++ b/engines/toon/resource.cpp @@ -30,6 +30,17 @@ namespace Toon { +Resources::Resources(ToonEngine *vm) : _vm(vm) { +} + +Resources::~Resources() { + while(!_pakFiles.empty()) { + PakFile *temp = _pakFiles.back(); + _pakFiles.pop_back(); + delete temp; + } +} + void Resources::openPackage(Common::String fileName, bool preloadEntirePackage) { debugC(1, kDebugResource, "openPackage(%s, %d)", fileName.c_str(), (preloadEntirePackage) ? 1 : 0); @@ -39,7 +50,6 @@ void Resources::openPackage(Common::String fileName, bool preloadEntirePackage) if (!opened) return; - PakFile *pakFile = new PakFile(); pakFile->open(&file, fileName, preloadEntirePackage); @@ -59,10 +69,6 @@ void Resources::closePackage(Common::String fileName) { } } -Resources::Resources(ToonEngine *vm) : _vm(vm) { - -} - uint8 *Resources::getFileData(Common::String fileName, uint32 *fileSize) { debugC(4, kDebugResource, "getFileData(%s, fileSize)", fileName.c_str()); @@ -200,10 +206,6 @@ void PakFile::close() { } } -PakFile::~PakFile() { - close(); -} - PakFile::PakFile() { _bufferSize = 0; _buffer = NULL; @@ -211,4 +213,8 @@ PakFile::PakFile() { _fileHandle = NULL; } +PakFile::~PakFile() { + close(); +} + } // End of namespace Toon diff --git a/engines/toon/resource.h b/engines/toon/resource.h index 3a080fe894..7e7f3d007a 100644 --- a/engines/toon/resource.h +++ b/engines/toon/resource.h @@ -58,8 +58,6 @@ protected: uint32 _numFiles; Common::Array<File> _files; Common::File *_fileHandle; - - }; class ToonEngine; @@ -67,6 +65,7 @@ class ToonEngine; class Resources { public: Resources(ToonEngine *vm); + ~Resources(); void openPackage(Common::String file, bool preloadEntirePackage); void closePackage(Common::String fileName); Common::SeekableReadStream *openFile(Common::String file); @@ -75,7 +74,6 @@ public: protected: ToonEngine *_vm; Common::Array<PakFile *> _pakFiles; - }; } // End of namespace Toon diff --git a/engines/toon/script.cpp b/engines/toon/script.cpp index 5e56432012..e72dafe1cc 100644 --- a/engines/toon/script.cpp +++ b/engines/toon/script.cpp @@ -72,6 +72,7 @@ EMCInterpreter::~EMCInterpreter() { bool EMCInterpreter::callback(Common::IFFChunk &chunk) { switch (chunk._type) { case MKID_BE('TEXT'): + delete[] _scriptData->text; _scriptData->text = new byte[chunk._size]; assert(_scriptData->text); if (chunk._stream->read(_scriptData->text, chunk._size) != chunk._size) @@ -79,6 +80,7 @@ bool EMCInterpreter::callback(Common::IFFChunk &chunk) { break; case MKID_BE('ORDR'): + delete[] _scriptData->ordr; _scriptData->ordr = new uint16[chunk._size >> 1]; assert(_scriptData->ordr); if (chunk._stream->read(_scriptData->ordr, chunk._size) != chunk._size) @@ -89,6 +91,7 @@ bool EMCInterpreter::callback(Common::IFFChunk &chunk) { break; case MKID_BE('DATA'): + delete[] _scriptData->data; _scriptData->data = new uint16[chunk._size >> 1]; assert(_scriptData->data); if (chunk._stream->read(_scriptData->data, chunk._size) != chunk._size) @@ -148,11 +151,13 @@ void EMCInterpreter::unload(EMCData *data) { return; delete[] data->text; + data->text = NULL; + delete[] data->ordr; - delete[] data->data; + data->ordr = NULL; - data->text = 0; - data->ordr = data->data = 0; + delete[] data->data; + data->data = NULL; } void EMCInterpreter::init(EMCState *scriptStat, const EMCData *data) { @@ -184,7 +189,6 @@ bool EMCInterpreter::isValid(EMCState *script) { } bool EMCInterpreter::run(EMCState *script) { - if (script->running) return false; @@ -195,7 +199,6 @@ bool EMCInterpreter::run(EMCState *script) { script->running = true; - // Should be no Problem at all to cast to uint32 here, since that's the biggest ptrdiff the original // would allow, of course that's not realistic to happen to be somewhere near the limit of uint32 anyway. const uint32 instOffset = (uint32)((const byte *)script->ip - (const byte *)script->dataPtr->data); diff --git a/engines/toon/script_func.cpp b/engines/toon/script_func.cpp index 4c30b1530a..3b21d1def5 100644 --- a/engines/toon/script_func.cpp +++ b/engines/toon/script_func.cpp @@ -224,8 +224,9 @@ ScriptFunc::ScriptFunc(ToonEngine *vm) { ScriptFunc::~ScriptFunc(void) { while(!_opcodes.empty()) { - //delete _opcodes.end(); + const OpcodeV2 *temp = _opcodes.back(); _opcodes.pop_back(); + delete temp; } } diff --git a/engines/toon/text.cpp b/engines/toon/text.cpp index c18e0cbdc8..c54ea87d50 100644 --- a/engines/toon/text.cpp +++ b/engines/toon/text.cpp @@ -27,14 +27,13 @@ namespace Toon { - TextResource::TextResource(ToonEngine *vm) : _vm(vm) { _numTexts = 0; - _textData = 0; + _textData = NULL; } TextResource::~TextResource(void) { - + delete[] _textData; } bool TextResource::loadTextResource(Common::String fileName) { @@ -45,6 +44,7 @@ bool TextResource::loadTextResource(Common::String fileName) { if (!data) return false; + delete[] _textData; _textData = new uint8[fileSize]; memcpy(_textData, data, fileSize); _numTexts = READ_LE_UINT16(data); diff --git a/engines/toon/toon.cpp b/engines/toon/toon.cpp index e44d7bc8f2..7b8a12d0b6 100644 --- a/engines/toon/toon.cpp +++ b/engines/toon/toon.cpp @@ -105,7 +105,7 @@ void ToonEngine::init() { resources()->openPackage("misc/drew.pak", true); for (int32 i = 0; i < 32; i++) - _characters[i] = 0; + _characters[i] = NULL; _characters[0] = new CharacterDrew(this); _characters[1] = new CharacterFlux(this); @@ -737,10 +737,8 @@ ToonEngine::ToonEngine(OSystem *syst, const ADGameDescription *gameDescription) : Engine(syst), _gameDescription(gameDescription), _language(gameDescription->language) { _system = syst; _tickLength = 16; - _currentMask = 0; - _currentPicture = 0; - _roomScaleData = 0; - _shadowLUT = 0; + _currentPicture = NULL; + _currentMask = NULL; _showConversationText = true; _isDemo = _gameDescription->flags & ADGF_DEMO; @@ -757,6 +755,8 @@ ToonEngine::ToonEngine(OSystem *syst, const ADGameDescription *gameDescription) DebugMan.addDebugChannel(kDebugTools, "Tools", "Tools debug level"); DebugMan.addDebugChannel(kDebugText, "Text", "Text debug level"); + _resources = NULL; + _animationManager = NULL; _moviePlayer = NULL; _mainSurface = NULL; @@ -768,6 +768,9 @@ ToonEngine::ToonEngine(OSystem *syst, const ADGameDescription *gameDescription) _universalPalette = NULL; _fluxPalette = NULL; + _roomScaleData = NULL; + _shadowLUT = NULL; + _conversationData = NULL; _fontRenderer = NULL; @@ -778,9 +781,20 @@ ToonEngine::ToonEngine(OSystem *syst, const ADGameDescription *gameDescription) _roomTexts = NULL; _script_func = NULL; _script = NULL; + + _saveBufferStream = NULL; + _pathFinding = NULL; _console = new ToonConsole(this); + _cursorAnimation = NULL; + _cursorAnimationInstance = NULL; + _dialogIcons = NULL; + _inventoryIcons = NULL; + _inventoryIconSlots = NULL; + _genericTexts = NULL; + _audioManager = NULL; + switch (_language) { case Common::EN_GRB: case Common::EN_USA: @@ -807,6 +821,11 @@ ToonEngine::ToonEngine(OSystem *syst, const ADGameDescription *gameDescription) } ToonEngine::~ToonEngine() { + delete _currentPicture; + delete _currentMask; + + delete _resources; + delete _animationManager; delete _moviePlayer; delete _mainSurface; @@ -818,6 +837,9 @@ ToonEngine::~ToonEngine() { delete[] _universalPalette; delete[] _fluxPalette; + delete[] _roomScaleData; + delete[] _shadowLUT; + delete[] _conversationData; delete _fontRenderer; @@ -829,8 +851,21 @@ ToonEngine::~ToonEngine() { delete _script_func; delete _script; + delete _saveBufferStream; + delete _pathFinding; + for (int32 i = 0; i < 32; i++) + delete _characters[i]; + + delete _cursorAnimation; + delete _cursorAnimationInstance; + delete _dialogIcons; + delete _inventoryIcons; + delete _inventoryIconSlots; + //delete _genericTexts; + //delete _audioManager; + DebugMan.clearAllDebugChannels(); delete _console; } @@ -940,7 +975,6 @@ void ToonEngine::loadScene(int32 SceneId, bool forGameLoad) { char temp[256]; char temp2[256]; - _firstFrame = true; _gameState->_lastVisitedScene = _gameState->_currentScene; @@ -1002,7 +1036,6 @@ void ToonEngine::loadScene(int32 SceneId, bool forGameLoad) { _mouseButton = 0; _lastMouseButton = 0x3; - // load package strcpy(temp, createRoomFilename(Common::String::format("%s.pak", _gameState->_locations[_gameState->_currentScene]._name).c_str()).c_str()); resources()->openPackage(temp, true); @@ -1022,27 +1055,30 @@ void ToonEngine::loadScene(int32 SceneId, bool forGameLoad) { // load artwork strcpy(temp, state()->_locations[SceneId]._name); strcat(temp, ".cps"); + delete _currentPicture; _currentPicture = new Picture(this); _currentPicture->loadPicture(temp); _currentPicture->setupPalette(); strcpy(temp, state()->_locations[SceneId]._name); strcat(temp, ".msc"); + delete _currentMask; _currentMask = new Picture(this); if (_currentMask->loadPicture(temp)) _pathFinding->init(_currentMask); strcpy(temp, state()->_locations[SceneId]._name); strcat(temp, ".tre"); + delete _roomTexts; _roomTexts = new TextResource(this); _roomTexts->loadTextResource(temp); - strcpy(temp, state()->_locations[SceneId]._name); strcat(temp, ".dat"); uint32 fileSize; uint8 *sceneData = resources()->getFileData(temp, &fileSize); if (sceneData) { + delete[] _roomScaleData; _roomScaleData = new uint8[fileSize]; memcpy(_roomScaleData, sceneData, fileSize); } @@ -1068,7 +1104,6 @@ void ToonEngine::loadScene(int32 SceneId, bool forGameLoad) { _hotspots->LoadRif(temp, temp2); restoreRifFlags(_gameState->_currentScene); - strcpy(temp, state()->_locations[SceneId]._name); strcat(temp, ".cnv"); uint32 convfileSize; @@ -1090,7 +1125,6 @@ void ToonEngine::loadScene(int32 SceneId, bool forGameLoad) { _drew->update(0); _flux->update(0); - _script->load(temp, &_scriptData, &_script_func->_opcodes); _script->init(&_scriptState[0], &_scriptData); _script->init(&_scriptState[1], &_scriptData); @@ -1124,7 +1158,6 @@ void ToonEngine::loadScene(int32 SceneId, bool forGameLoad) { _lastProcessedSceneScript = 0; _gameState->_locations[SceneId]._visited = true; - setupGeneralPalette(); createShadowLUT(); @@ -1224,8 +1257,10 @@ void ToonEngine::initChapter() { } void ToonEngine::loadCursor() { + delete _cursorAnimation; _cursorAnimation = new Animation(this); _cursorAnimation->loadAnimation("MOUSE.CAF"); + delete _cursorAnimationInstance; _cursorAnimationInstance = _animationManager->createNewInstance(kAnimationCursor); _cursorAnimationInstance->setAnimation(_cursorAnimation); _cursorAnimationInstance->setVisible(true); |