From f9ad14dc2d0a7007413fa6cbde4c9a694446b0a4 Mon Sep 17 00:00:00 2001 From: Willem Jan Palenstijn Date: Sat, 26 Nov 2011 22:26:47 +0100 Subject: TOON: Clean up Common::String usage Thanks to Sylvain for testing. --- engines/toon/anim.cpp | 2 +- engines/toon/anim.h | 2 +- engines/toon/audio.cpp | 6 +-- engines/toon/audio.h | 6 +-- engines/toon/character.cpp | 8 ++-- engines/toon/character.h | 8 ++-- engines/toon/font.cpp | 6 +-- engines/toon/font.h | 6 +-- engines/toon/hotspot.cpp | 2 +- engines/toon/hotspot.h | 2 +- engines/toon/movie.cpp | 2 +- engines/toon/movie.h | 2 +- engines/toon/picture.cpp | 2 +- engines/toon/picture.h | 2 +- engines/toon/resource.cpp | 20 +++++----- engines/toon/resource.h | 20 +++++----- engines/toon/text.cpp | 2 +- engines/toon/text.h | 2 +- engines/toon/toon.cpp | 94 ++++++++++++++++------------------------------ engines/toon/toon.h | 10 ++--- 20 files changed, 88 insertions(+), 116 deletions(-) diff --git a/engines/toon/anim.cpp b/engines/toon/anim.cpp index a529001af5..98c667c303 100644 --- a/engines/toon/anim.cpp +++ b/engines/toon/anim.cpp @@ -29,7 +29,7 @@ namespace Toon { -bool Animation::loadAnimation(Common::String file) { +bool Animation::loadAnimation(const Common::String &file) { debugC(1, kDebugAnim, "loadAnimation(%s)", file.c_str()); uint32 fileSize = 0; diff --git a/engines/toon/anim.h b/engines/toon/anim.h index 4b95b6cf40..eb8dcbd600 100644 --- a/engines/toon/anim.h +++ b/engines/toon/anim.h @@ -60,7 +60,7 @@ public: int32 _paletteEntries; char _name[32]; - bool loadAnimation(Common::String file); + bool loadAnimation(const Common::String &file); void drawFrame(Graphics::Surface &surface, int32 frame, int32 x, int32 y); void drawFontFrame(Graphics::Surface &surface, int32 frame, int32 x, int32 y, byte *colorMap); void drawFrameOnPicture(int32 frame, int32 x, int32 y); diff --git a/engines/toon/audio.cpp b/engines/toon/audio.cpp index 5b2d06b74d..b9adfa7eeb 100644 --- a/engines/toon/audio.cpp +++ b/engines/toon/audio.cpp @@ -84,7 +84,7 @@ void AudioManager::removeInstance(AudioStreamInstance *inst) { } } -void AudioManager::playMusic(Common::String dir, Common::String music) { +void AudioManager::playMusic(const Common::String &dir, const Common::String &music) { debugC(1, kDebugAudio, "playMusic(%s, %s)", dir.c_str(), music.c_str()); // two musics can be played at same time @@ -199,7 +199,7 @@ void AudioManager::closeAudioPack(int32 id) { _audioPacks[id] = NULL; } -bool AudioManager::loadAudioPack(int32 id, Common::String indexFile, Common::String packFile) { +bool AudioManager::loadAudioPack(int32 id, const Common::String &indexFile, const Common::String &packFile) { debugC(4, kDebugAudio, "loadAudioPack(%d, %s, %s)", id, indexFile.c_str(), packFile.c_str()); closeAudioPack(id); @@ -481,7 +481,7 @@ AudioStreamPackage::~AudioStreamPackage() { delete _file; } -bool AudioStreamPackage::loadAudioPackage(Common::String indexFile, Common::String streamFile) { +bool AudioStreamPackage::loadAudioPackage(const Common::String &indexFile, const Common::String &streamFile) { debugC(4, kDebugAudio, "loadAudioPackage(%s, %s)", indexFile.c_str(), streamFile.c_str()); uint32 size = 0; diff --git a/engines/toon/audio.h b/engines/toon/audio.h index 61a534265e..25063603eb 100644 --- a/engines/toon/audio.h +++ b/engines/toon/audio.h @@ -103,7 +103,7 @@ public: AudioStreamPackage(ToonEngine *vm); ~AudioStreamPackage(); - bool loadAudioPackage(Common::String indexFile, Common::String streamFile); + bool loadAudioPackage(const Common::String &indexFile, const Common::String &streamFile); void getInfo(int32 id, int32 *offset, int32 *size); Common::SeekableReadStream *getStream(int32 id, bool ownMemory = false); protected: @@ -131,7 +131,7 @@ public: bool voiceStillPlaying(); - void playMusic(Common::String dir, Common::String music); + void playMusic(const Common::String &dir, const Common::String &music); void playVoice(int32 id, bool genericVoice); int32 playSFX(int32 id, int volume, bool genericSFX); void stopCurrentVoice(); @@ -152,7 +152,7 @@ public: void setAmbientSFXVolume(int32 id, int volume); void closeAudioPack(int32 id); - bool loadAudioPack(int32 id, Common::String indexFile, Common::String packFile); + bool loadAudioPack(int32 id, const Common::String &indexFile, const Common::String &packFile); AudioStreamInstance *_channels[16]; // 0-1 : music // 2 : voice diff --git a/engines/toon/character.cpp b/engines/toon/character.cpp index 7d9a31c170..715bd33433 100644 --- a/engines/toon/character.cpp +++ b/engines/toon/character.cpp @@ -292,21 +292,21 @@ int32 Character::getFacing() { return _facing; } -bool Character::loadWalkAnimation(Common::String animName) { +bool Character::loadWalkAnimation(const Common::String &animName) { debugC(1, kDebugCharacter, "loadWalkAnimation(%s)", animName.c_str()); delete _walkAnim; _walkAnim = new Animation(_vm); return _walkAnim->loadAnimation(animName); } -bool Character::loadIdleAnimation(Common::String animName) { +bool Character::loadIdleAnimation(const Common::String &animName) { debugC(1, kDebugCharacter, "loadIdleAnimation(%s)", animName.c_str()); delete _idleAnim; _idleAnim = new Animation(_vm); return _idleAnim->loadAnimation(animName); } -bool Character::loadTalkAnimation(Common::String animName) { +bool Character::loadTalkAnimation(const Common::String &animName) { debugC(1, kDebugCharacter, "loadTalkAnimation(%s)", animName.c_str()); delete _talkAnim; _talkAnim = new Animation(_vm); @@ -977,7 +977,7 @@ const SpecialCharacterAnimation *Character::getSpecialAnimation(int32 characterI return &anims[characterAnims[characterId] + animationId]; } -bool Character::loadShadowAnimation(Common::String animName) { +bool Character::loadShadowAnimation(const Common::String &animName) { debugC(1, kDebugCharacter, "loadShadowAnimation(%s)", animName.c_str()); delete _shadowAnim; diff --git a/engines/toon/character.h b/engines/toon/character.h index b48991732c..de58a41e43 100644 --- a/engines/toon/character.h +++ b/engines/toon/character.h @@ -74,10 +74,10 @@ public: virtual bool walkTo(int32 newPosX, int32 newPosY); virtual bool getVisible(); virtual void setVisible(bool visible); - virtual bool loadWalkAnimation(Common::String animName); - virtual bool loadIdleAnimation(Common::String animName); - virtual bool loadTalkAnimation(Common::String animName); - virtual bool loadShadowAnimation(Common::String animName); + virtual bool loadWalkAnimation(const Common::String &animName); + virtual bool loadIdleAnimation(const Common::String &animName); + virtual bool loadTalkAnimation(const Common::String &animName); + virtual bool loadShadowAnimation(const Common::String &animName); virtual bool setupPalette(); virtual void playStandingAnim(); virtual void playWalkAnim(int32 start, int32 end); diff --git a/engines/toon/font.cpp b/engines/toon/font.cpp index 63304c905f..d58663a00c 100644 --- a/engines/toon/font.cpp +++ b/engines/toon/font.cpp @@ -65,7 +65,7 @@ byte FontRenderer::textToFont(byte c) { return map_textToFont[c - 0x80]; } -void FontRenderer::renderText(int32 x, int32 y, Common::String origText, int32 mode) { +void FontRenderer::renderText(int32 x, int32 y, const Common::String &origText, int32 mode) { debugC(5, kDebugFont, "renderText(%d, %d, %s, %d)", x, y, origText.c_str(), mode); int32 xx, yy; @@ -104,7 +104,7 @@ void FontRenderer::renderText(int32 x, int32 y, Common::String origText, int32 m } } -void FontRenderer::computeSize(Common::String origText, int32 *retX, int32 *retY) { +void FontRenderer::computeSize(const Common::String &origText, int32 *retX, int32 *retY) { debugC(4, kDebugFont, "computeSize(%s, retX, retY)", origText.c_str()); int32 lineWidth = 0; @@ -189,7 +189,7 @@ void FontRenderer::setFontColor(int32 fontColor1, int32 fontColor2, int32 fontCo _currentFontColor[3] = fontColor3; } -void FontRenderer::renderMultiLineText(int32 x, int32 y, Common::String origText, int32 mode) { +void FontRenderer::renderMultiLineText(int32 x, int32 y, const Common::String &origText, int32 mode) { debugC(5, kDebugFont, "renderMultiLineText(%d, %d, %s, %d)", x, y, origText.c_str(), mode); // divide the text in several lines diff --git a/engines/toon/font.h b/engines/toon/font.h index 168c61f27e..349d9d1ee7 100644 --- a/engines/toon/font.h +++ b/engines/toon/font.h @@ -33,9 +33,9 @@ public: ~FontRenderer(); void setFont(Animation *font); - void computeSize(Common::String origText, int32 *retX, int32 *retY); - void renderText(int32 x, int32 y, Common::String origText, int32 mode); - void renderMultiLineText(int32 x, int32 y, Common::String origText, int32 mode); + void computeSize(const Common::String &origText, int32 *retX, int32 *retY); + void renderText(int32 x, int32 y, const Common::String &origText, int32 mode); + void renderMultiLineText(int32 x, int32 y, const Common::String &origText, int32 mode); void setFontColorByCharacter(int32 characterId); void setFontColor(int32 fontColor1, int32 fontColor2, int32 fontColor3); protected: diff --git a/engines/toon/hotspot.cpp b/engines/toon/hotspot.cpp index ee81b87417..ce2cdf1bb9 100644 --- a/engines/toon/hotspot.cpp +++ b/engines/toon/hotspot.cpp @@ -96,7 +96,7 @@ int32 Hotspots::Find(int32 x, int32 y) { return foundId; } -bool Hotspots::LoadRif(Common::String rifName, Common::String additionalRifName) { +bool Hotspots::LoadRif(const Common::String &rifName, const Common::String &additionalRifName) { debugC(1, kDebugHotspot, "LoadRif(%s, %s)", rifName.c_str(), additionalRifName.c_str()); uint32 size = 0; diff --git a/engines/toon/hotspot.h b/engines/toon/hotspot.h index 49ac1a4af8..70e80046e1 100644 --- a/engines/toon/hotspot.h +++ b/engines/toon/hotspot.h @@ -50,7 +50,7 @@ public: Hotspots(ToonEngine *vm); ~Hotspots(); - bool LoadRif(Common::String rifName, Common::String additionalRifName); + bool LoadRif(const Common::String &rifName, const Common::String &additionalRifName); int32 Find(int32 x, int32 y); int32 FindBasedOnCorner(int32 x, int32 y); HotspotData *Get(int32 id); diff --git a/engines/toon/movie.cpp b/engines/toon/movie.cpp index 7637f4e62f..59ad8484d5 100644 --- a/engines/toon/movie.cpp +++ b/engines/toon/movie.cpp @@ -83,7 +83,7 @@ Movie::~Movie() { void Movie::init() const { } -void Movie::play(Common::String video, int32 flags) { +void Movie::play(const Common::String &video, int32 flags) { debugC(1, kDebugMovie, "play(%s, %d)", video.c_str(), flags); bool isFirstIntroVideo = false; if (video == "209_1M.SMK") diff --git a/engines/toon/movie.h b/engines/toon/movie.h index 7e443fd8ab..2cd33302f2 100644 --- a/engines/toon/movie.h +++ b/engines/toon/movie.h @@ -45,7 +45,7 @@ public: virtual ~Movie(void); void init() const; - void play(Common::String video, int32 flags = 0); + void play(const Common::String &video, int32 flags = 0); bool isPlaying() { return _playing; } protected: diff --git a/engines/toon/picture.cpp b/engines/toon/picture.cpp index 6367165d6f..ff136e5acb 100644 --- a/engines/toon/picture.cpp +++ b/engines/toon/picture.cpp @@ -29,7 +29,7 @@ namespace Toon { -bool Picture::loadPicture(Common::String file) { +bool Picture::loadPicture(const Common::String &file) { debugC(1, kDebugPicture, "loadPicture(%s)", file.c_str()); uint32 size = 0; diff --git a/engines/toon/picture.h b/engines/toon/picture.h index ee0e006702..460c5b58a2 100644 --- a/engines/toon/picture.h +++ b/engines/toon/picture.h @@ -38,7 +38,7 @@ class Picture { public: Picture(ToonEngine *vm); ~Picture(); - bool loadPicture(Common::String file); + bool loadPicture(const Common::String &file); void setupPalette(); void draw(Graphics::Surface &surface, int32 x, int32 y, int32 dx, int32 dy); void drawWithRectList(Graphics::Surface& surface, int32 x, int32 y, int32 dx, int32 dy, Common::Array& rectArray); diff --git a/engines/toon/resource.cpp b/engines/toon/resource.cpp index 384a363d7d..2d419ec027 100644 --- a/engines/toon/resource.cpp +++ b/engines/toon/resource.cpp @@ -50,13 +50,13 @@ Resources::~Resources() { purgeFileData(); } -void Resources::removePackageFromCache(Common::String packName) { +void Resources::removePackageFromCache(const Common::String &packName) { // I'm not sure what's a good strategy here. It seems unnecessary to // actually remove the cached resources, because the player may be // wandering back and forth between rooms. So for now, do nothing. } -bool Resources::getFromCache(Common::String fileName, uint32 *fileSize, uint8 **fileData) { +bool Resources::getFromCache(const Common::String &fileName, uint32 *fileSize, uint8 **fileData) { for (Common::Array::iterator entry = _resourceCache.begin(); entry != _resourceCache.end(); ++entry) { if ((*entry)->_data && (*entry)->_fileName.compareToIgnoreCase(fileName) == 0) { debugC(5, kDebugResource, "getFromCache(%s) - Got %d bytes from %s", fileName.c_str(), (*entry)->_size, (*entry)->_packName.c_str()); @@ -69,7 +69,7 @@ bool Resources::getFromCache(Common::String fileName, uint32 *fileSize, uint8 ** return false; } -void Resources::addToCache(Common::String packName, Common::String fileName, uint32 fileSize, uint8 *fileData) { +void Resources::addToCache(const Common::String &packName, const Common::String &fileName, uint32 fileSize, uint8 *fileData) { debugC(5, kDebugResource, "addToCache(%s, %s, %d) - Total Size: %d", packName.c_str(), fileName.c_str(), fileSize, _cacheSize + fileSize); for (Common::Array::iterator entry = _resourceCache.begin(); entry != _resourceCache.end(); ++entry) { if ((*entry)->_data) { @@ -115,7 +115,7 @@ void Resources::addToCache(Common::String packName, Common::String fileName, uin _resourceCache.push_back(entry); } -void Resources::openPackage(Common::String fileName) { +void Resources::openPackage(const Common::String &fileName) { debugC(1, kDebugResource, "openPackage(%s)", fileName.c_str()); Common::File file; @@ -132,7 +132,7 @@ void Resources::openPackage(Common::String fileName) { _pakFiles.push_back(pakFile); } -void Resources::closePackage(Common::String fileName) { +void Resources::closePackage(const Common::String &fileName) { removePackageFromCache(fileName); for (uint32 i = 0; i < _pakFiles.size(); i++) { @@ -144,7 +144,7 @@ void Resources::closePackage(Common::String fileName) { } } -uint8 *Resources::getFileData(Common::String fileName, uint32 *fileSize) { +uint8 *Resources::getFileData(const Common::String &fileName, uint32 *fileSize) { debugC(4, kDebugResource, "getFileData(%s, fileSize)", fileName.c_str()); // first try to find files outside of .pak @@ -184,7 +184,7 @@ uint8 *Resources::getFileData(Common::String fileName, uint32 *fileSize) { } } -Common::SeekableReadStream *Resources::openFile(Common::String fileName) { +Common::SeekableReadStream *Resources::openFile(const Common::String &fileName) { debugC(1, kDebugResource, "openFile(%s)", fileName.c_str()); // first try to find files outside of .pak @@ -216,7 +216,7 @@ void Resources::purgeFileData() { _allocatedFileData.clear(); } -Common::SeekableReadStream *PakFile::createReadStream(Common::String fileName) { +Common::SeekableReadStream *PakFile::createReadStream(const Common::String &fileName) { debugC(1, kDebugResource, "createReadStream(%s)", fileName.c_str()); uint32 fileSize = 0; @@ -227,7 +227,7 @@ Common::SeekableReadStream *PakFile::createReadStream(Common::String fileName) { return 0; } -uint8 *PakFile::getFileData(Common::String fileName, uint32 *fileSize) { +uint8 *PakFile::getFileData(const Common::String &fileName, uint32 *fileSize) { debugC(4, kDebugResource, "getFileData(%s, fileSize)", fileName.c_str()); for (uint32 i = 0; i < _numFiles; i++) { @@ -250,7 +250,7 @@ uint8 *PakFile::getFileData(Common::String fileName, uint32 *fileSize) { return 0; } -void PakFile::open(Common::SeekableReadStream *rs, Common::String packName) { +void PakFile::open(Common::SeekableReadStream *rs, const Common::String &packName) { debugC(1, kDebugResource, "open(rs)"); char buffer[64]; diff --git a/engines/toon/resource.h b/engines/toon/resource.h index 0cecad8187..c80ac2216e 100644 --- a/engines/toon/resource.h +++ b/engines/toon/resource.h @@ -37,10 +37,10 @@ public: PakFile(); ~PakFile(); - void open(Common::SeekableReadStream *rs, Common::String packName); - uint8 *getFileData(Common::String fileName, uint32 *fileSize); + void open(Common::SeekableReadStream *rs, const Common::String &packName); + uint8 *getFileData(const Common::String &fileName, uint32 *fileSize); Common::String getPackName() { return _packName; } - Common::SeekableReadStream *createReadStream(Common::String fileName); + Common::SeekableReadStream *createReadStream(const Common::String &fileName); void close(); protected: @@ -76,10 +76,10 @@ class Resources { public: Resources(ToonEngine *vm); ~Resources(); - void openPackage(Common::String file); - void closePackage(Common::String fileName); - Common::SeekableReadStream *openFile(Common::String file); - uint8 *getFileData(Common::String fileName, uint32 *fileSize); // this memory must be copied to your own structures! + void openPackage(const Common::String &file); + void closePackage(const Common::String &fileName); + Common::SeekableReadStream *openFile(const Common::String &file); + uint8 *getFileData(const Common::String &fileName, uint32 *fileSize); // this memory must be copied to your own structures! void purgeFileData(); protected: @@ -89,9 +89,9 @@ protected: uint32 _cacheSize; Common::Array _resourceCache; - void removePackageFromCache(Common::String packName); - bool getFromCache(Common::String fileName, uint32 *fileSize, uint8 **fileData); - void addToCache(Common::String packName, Common::String fileName, uint32 fileSize, uint8 *fileData); + void removePackageFromCache(const Common::String &packName); + bool getFromCache(const Common::String &fileName, uint32 *fileSize, uint8 **fileData); + void addToCache(const Common::String &packName, const Common::String &fileName, uint32 fileSize, uint8 *fileData); }; } // End of namespace Toon diff --git a/engines/toon/text.cpp b/engines/toon/text.cpp index 0f72d58b3b..bd4583d799 100644 --- a/engines/toon/text.cpp +++ b/engines/toon/text.cpp @@ -35,7 +35,7 @@ TextResource::~TextResource(void) { delete[] _textData; } -bool TextResource::loadTextResource(Common::String fileName) { +bool TextResource::loadTextResource(const Common::String &fileName) { debugC(1, kDebugText, "loadTextResource(%s)", fileName.c_str()); uint32 fileSize = 0; diff --git a/engines/toon/text.h b/engines/toon/text.h index b8f4a96a6a..cd575736b7 100644 --- a/engines/toon/text.h +++ b/engines/toon/text.h @@ -32,7 +32,7 @@ public: TextResource(ToonEngine *vm); ~TextResource(void); - bool loadTextResource(Common::String fileName); + bool loadTextResource(const Common::String &fileName); char *getText(int32 id); int32 getId(int32 offset); int32 getNext(int32 offset); diff --git a/engines/toon/toon.cpp b/engines/toon/toon.cpp index b3ab591ba7..13f702e3dd 100644 --- a/engines/toon/toon.cpp +++ b/engines/toon/toon.cpp @@ -192,7 +192,7 @@ void ToonEngine::parseInput() { } if (event.kbd.keycode == Common::KEYCODE_F5 && !hasModifier) { if (canSaveGameStateCurrently()) - saveGame(-1, Common::String()); + saveGame(-1, ""); } if (event.kbd.keycode == Common::KEYCODE_F6 && !hasModifier) { if (canLoadGameStateCurrently()) @@ -214,7 +214,7 @@ void ToonEngine::parseInput() { if (event.kbd.flags & Common::KBD_ALT) { int slotNum = event.kbd.ascii - '0'; if (slotNum >= 0 && slotNum <= 9 && canSaveGameStateCurrently()) { - if (saveGame(slotNum, Common::String())) { + if (saveGame(slotNum, "")) { // ok Common::String buf = Common::String::format("Saved game in slot #%d ", slotNum); GUI::TimedMessageDialog dialog(buf, 1000); @@ -1084,9 +1084,6 @@ void ToonEngine::updateAnimationSceneScripts(int32 timeElapsed) { } void ToonEngine::loadScene(int32 SceneId, bool forGameLoad) { - char temp[256]; - char temp2[256]; - _firstFrame = true; _gameState->_lastVisitedScene = _gameState->_currentScene; @@ -1148,79 +1145,54 @@ void ToonEngine::loadScene(int32 SceneId, bool forGameLoad) { _mouseButton = 0; _lastMouseButton = 0x3; + Common::String locationName = state()->_locations[SceneId]._name; + // load package - strcpy(temp, createRoomFilename(Common::String::format("%s.PAK", _gameState->_locations[_gameState->_currentScene]._name).c_str()).c_str()); - resources()->openPackage(temp); + resources()->openPackage(createRoomFilename(locationName + ".PAK")); - strcpy(temp, state()->_locations[SceneId]._name); - strcat(temp, ".NPP"); - loadAdditionalPalette(temp, 0); + loadAdditionalPalette(locationName + ".NPP", 0); _additionalPalette2Present = false; - strcpy(temp, state()->_locations[SceneId]._name); - strcat(temp, ".NP2"); - loadAdditionalPalette(temp, 1); + loadAdditionalPalette(locationName + ".NP2", 1); - strcpy(temp, state()->_locations[SceneId]._name); - strcat(temp, ".CUP"); - loadAdditionalPalette(temp, 2); + loadAdditionalPalette(locationName + ".CUP", 2); // load artwork - strcpy(temp, state()->_locations[SceneId]._name); - strcat(temp, ".CPS"); delete _currentPicture; _currentPicture = new Picture(this); - _currentPicture->loadPicture(temp); + _currentPicture->loadPicture(locationName + ".CPS"); _currentPicture->setupPalette(); - strcpy(temp, state()->_locations[SceneId]._name); - strcat(temp, ".MSC"); delete _currentMask; _currentMask = new Picture(this); - if (_currentMask->loadPicture(temp)) + if (_currentMask->loadPicture(locationName + ".MSC")) _pathFinding->init(_currentMask); - strcpy(temp, state()->_locations[SceneId]._name); - strcat(temp, ".TRE"); delete _roomTexts; _roomTexts = new TextResource(this); - _roomTexts->loadTextResource(temp); + _roomTexts->loadTextResource(locationName + ".TRE"); - strcpy(temp, state()->_locations[SceneId]._name); - strcat(temp, ".DAT"); uint32 fileSize; - uint8 *sceneData = resources()->getFileData(temp, &fileSize); + uint8 *sceneData = resources()->getFileData(locationName + ".DAT", &fileSize); if (sceneData) { delete[] _roomScaleData; _roomScaleData = new uint8[fileSize]; memcpy(_roomScaleData, sceneData, fileSize); } - strcpy(temp, state()->_locations[SceneId]._name); - strcat(temp, ".SVI"); - strcpy(temp2, createRoomFilename(Common::String::format("%s.SVL", _gameState->_locations[_gameState->_currentScene]._name).c_str()).c_str()); - _audioManager->loadAudioPack(1, temp, temp2); - strcpy(temp, state()->_locations[SceneId]._name); - strcpy(temp2, state()->_locations[SceneId]._name); - strcat(temp, ".SEI"); - strcat(temp2, ".SEL"); - _audioManager->loadAudioPack(3, temp, temp2); + _audioManager->loadAudioPack(1, locationName + ".SVI", createRoomFilename(locationName + ".SVL")); + _audioManager->loadAudioPack(3, locationName + ".SEI", locationName + ".SEL"); - strcpy(temp, state()->_locations[SceneId]._name); - strcat(temp, ".RIC"); if (state()->_locations[SceneId]._flags & 0x40) { - strcpy(temp2, state()->_locations[SceneId]._cutaway); - strcat(temp2, ".RIC"); + Common::String cutaway = state()->_locations[SceneId]._cutaway; + _hotspots->LoadRif(locationName + ".RIC", cutaway + ".RIC"); } else { - strcpy(temp2, ""); + _hotspots->LoadRif(locationName + ".RIC", ""); } - _hotspots->LoadRif(temp, temp2); restoreRifFlags(_gameState->_currentScene); - strcpy(temp, state()->_locations[SceneId]._name); - strcat(temp, ".CNV"); uint32 convfileSize; - uint8 *convData = resources()->getFileData(temp, &convfileSize); + uint8 *convData = resources()->getFileData(locationName + ".CNV", &convfileSize); if (convData) { assert(convfileSize < 4096 * sizeof(int16)); memcpy(_conversationData , convData, convfileSize); @@ -1228,8 +1200,6 @@ void ToonEngine::loadScene(int32 SceneId, bool forGameLoad) { } // load script - strcpy(temp, state()->_locations[SceneId]._name); - strcat(temp, ".EMC"); _oldTimer = _system->getMillis(); _oldTimer2 = _oldTimer; @@ -1239,7 +1209,8 @@ void ToonEngine::loadScene(int32 SceneId, bool forGameLoad) { _flux->update(0); _script->unload(&_scriptData); - _script->load(temp, &_scriptData, &_script_func->_opcodes); + Common::String emcfile = locationName + ".EMC"; + _script->load(emcfile.c_str(), &_scriptData, &_script_func->_opcodes); _script->init(&_scriptState[0], &_scriptData); _script->init(&_scriptState[1], &_scriptData); _script->init(&_scriptState[2], &_scriptData); @@ -1312,7 +1283,7 @@ void ToonEngine::setupGeneralPalette() { _drew->setupPalette(); } -void ToonEngine::loadAdditionalPalette(Common::String fileName, int32 mode) { +void ToonEngine::loadAdditionalPalette(const Common::String &fileName, int32 mode) { uint32 size = 0; uint8 *palette = resources()->getFileData(fileName, &size); @@ -1779,9 +1750,8 @@ void ToonEngine::exitScene() { _currentTextLineId = -1; _currentTextLineCharacterId = 0; - char temp[256]; - strcpy(temp, createRoomFilename(Common::String::format("%s.PAK", _gameState->_locations[_gameState->_currentScene]._name).c_str()).c_str()); - resources()->closePackage(temp); + Common::String locationName = _gameState->_locations[_gameState->_currentScene]._name; + resources()->closePackage(createRoomFilename(locationName + ".PAK")); _drew->stopWalk(); _flux->stopWalk(); @@ -2785,13 +2755,15 @@ void ToonEngine::deleteMouseItem() { setCursor(0); } -void ToonEngine::showCutaway(Common::String cutawayPicture) { +void ToonEngine::showCutaway(const Common::String &cutawayPicture) { _gameState->_inCutaway = true; _currentCutaway = new Picture(this); - if (cutawayPicture == "") { - cutawayPicture = Common::String(_gameState->_locations[_gameState->_currentScene]._cutaway) + ".CPS"; + if (cutawayPicture.empty()) { + Common::String name = _gameState->_locations[_gameState->_currentScene]._cutaway; + _currentCutaway->loadPicture(name + ".CPS"); + } else { + _currentCutaway->loadPicture(cutawayPicture); } - _currentCutaway->loadPicture(cutawayPicture); _currentCutaway->setupPalette(); _oldScrollValue = _gameState->_currentScrollValue; _gameState->_currentScrollValue = 0; @@ -2942,7 +2914,7 @@ void ToonEngine::drawConversationLine() { if (_currentTextLine && _showConversationText) { _fontRenderer->setFontColorByCharacter(_currentTextLineCharacterId); _fontRenderer->setFont(_fontToon); - _fontRenderer->renderMultiLineText(_currentTextLineX, _currentTextLineY, Common::String(_currentTextLine), 0); + _fontRenderer->renderMultiLineText(_currentTextLineX, _currentTextLineY, _currentTextLine, 0); } } @@ -2988,7 +2960,7 @@ Common::String ToonEngine::getSavegameName(int nr) { return _targetName + Common::String::format(".%03d", nr); } -bool ToonEngine::saveGame(int32 slot, Common::String saveGameDesc) { +bool ToonEngine::saveGame(int32 slot, const Common::String &saveGameDesc) { const EnginePlugin *plugin = NULL; int16 savegameId; Common::String savegameDescription; @@ -3418,7 +3390,7 @@ const char *ToonEngine::getSpecialConversationMusic(int32 conversationId) { return specialMusic[randRange(0, 1) + conversationId * 2]; } -void ToonEngine::viewInventoryItem(Common::String str, int32 lineId, int32 itemDest) { +void ToonEngine::viewInventoryItem(const Common::String &str, int32 lineId, int32 itemDest) { storePalette(); fadeOut(5); @@ -4511,7 +4483,7 @@ int32 ToonEngine::pauseSceneAnimationScript(int32 animScriptId, int32 tickToWait return nextTicks; } -Common::String ToonEngine::createRoomFilename(Common::String name) { +Common::String ToonEngine::createRoomFilename(const Common::String& name) { Common::String file = Common::String::format("ACT%d/%s/%s", _gameState->_currentChapter, _gameState->_locations[_gameState->_currentScene]._name, name.c_str()); return file; } diff --git a/engines/toon/toon.h b/engines/toon/toon.h index cad684d590..540f3e403b 100644 --- a/engines/toon/toon.h +++ b/engines/toon/toon.h @@ -126,7 +126,7 @@ public: void exitScene(); void loadCursor(); void setCursor(int32 type, bool inventory = false, int32 offsetX = 0, int offsetY = 0); - void loadAdditionalPalette(Common::String fileName, int32 mode); + void loadAdditionalPalette(const Common::String &fileName, int32 mode); void setupGeneralPalette(); void render(); void update(int32 timeIncrement); @@ -167,7 +167,7 @@ public: void rearrangeInventory(); void createMouseItem(int32 item); void deleteMouseItem(); - void showCutaway(Common::String cutawayPicture); + void showCutaway(const Common::String &cutawayPicture); void hideCutaway(); void drawPalette(); void newGame(); @@ -181,7 +181,7 @@ public: Character *getCharacterById(int32 charId); Common::String getSavegameName(int nr); bool loadGame(int32 slot); - bool saveGame(int32 slot, Common::String saveGameDesc); + bool saveGame(int32 slot, const Common::String &saveGameDesc); void fadeIn(int32 numFrames); void fadeOut(int32 numFrames); void initCharacter(int32 characterId, int32 animScriptId, int32 animToPlayId, int32 sceneAnimationId); @@ -190,7 +190,7 @@ public: int32 handleInventoryOnDrew(int32 itemId); int32 pauseSceneAnimationScript(int32 animScriptId, int32 tickToWait); void updateTimer(int32 timeIncrement); - Common::String createRoomFilename(Common::String name); + Common::String createRoomFilename(const Common::String &name); void createShadowLUT(); void playTalkAnimOnCharacter(int32 animID, int32 characterId, bool talker); void updateScrolling(bool force, int32 timeIncrement); @@ -201,7 +201,7 @@ public: void makeLineNonWalkable(int32 x, int32 y, int32 x2, int32 y2); void makeLineWalkable(int32 x, int32 y, int32 x2, int32 y2); void renderInventory(); - void viewInventoryItem(Common::String str, int32 lineId, int32 itemDest); + void viewInventoryItem(const Common::String &str, int32 lineId, int32 itemDest); void storePalette(); void restorePalette(); const char *getSpecialConversationMusic(int32 locationId); -- cgit v1.2.3