From 56c005ef2cb385b56088b11d37b95dab43d58005 Mon Sep 17 00:00:00 2001 From: fracturehill Date: Sat, 20 Mar 2021 19:52:39 +0200 Subject: [PATCH] NANCY: Mark functions and iterators as const Added the const keyword to several auto & iterators inside for loops, as well as to a number of class member functions. --- engines/nancy/action/passwordpuzzle.cpp | 2 +- engines/nancy/action/primaryvideo.cpp | 6 +++--- engines/nancy/action/recordtypes.cpp | 6 +++--- engines/nancy/graphics.cpp | 2 +- engines/nancy/graphics.h | 2 +- engines/nancy/iff.cpp | 2 +- engines/nancy/iff.h | 2 +- engines/nancy/nancy.cpp | 4 ++-- engines/nancy/nancy.h | 4 ++-- engines/nancy/resource.cpp | 14 +++++++------- engines/nancy/resource.h | 12 ++++++------ engines/nancy/sound.cpp | 4 ++-- engines/nancy/sound.h | 4 ++-- engines/nancy/ui/inventorybox.h | 2 +- engines/nancy/ui/textbox.cpp | 2 +- 15 files changed, 34 insertions(+), 34 deletions(-) diff --git a/engines/nancy/action/passwordpuzzle.cpp b/engines/nancy/action/passwordpuzzle.cpp index 101df86ae54..0f7bb6f3a4f 100644 --- a/engines/nancy/action/passwordpuzzle.cpp +++ b/engines/nancy/action/passwordpuzzle.cpp @@ -220,7 +220,7 @@ void PasswordPuzzle::onPause(bool pause) { void PasswordPuzzle::drawText() { _drawSurface.clear(GraphicsManager::getTransColor()); - Graphics::Font *font = g_nancy->_graphicsManager->getFont(_fontID); + const Graphics::Font *font = g_nancy->_graphicsManager->getFont(_fontID); Common::Rect bounds = _nameBounds; bounds = NancySceneState.getViewport().convertViewportToScreen(bounds); diff --git a/engines/nancy/action/primaryvideo.cpp b/engines/nancy/action/primaryvideo.cpp index e11d4a945a5..db44d304f52 100644 --- a/engines/nancy/action/primaryvideo.cpp +++ b/engines/nancy/action/primaryvideo.cpp @@ -317,10 +317,10 @@ void PlayPrimaryVideoChan0::execute() { } void PlayPrimaryVideoChan0::addConditionalResponses() { - for (auto &res : nancy1ConditionalResponses) { + for (const auto &res : nancy1ConditionalResponses) { if (res.characterID == _conditionalResponseCharacterID) { bool isSatisfied = true; - for (auto & cond : res.conditions) { + for (const auto & cond : res.conditions) { if (cond.label == -1) { break; } @@ -354,7 +354,7 @@ void PlayPrimaryVideoChan0::addConditionalResponses() { } void PlayPrimaryVideoChan0::addGoodbye() { - for (auto &res : nancy1Goodbyes) { + for (const auto &res : nancy1Goodbyes) { if (res.characterID == _goodbyeResponseCharacterID) { Common::File file; char snd[9]; diff --git a/engines/nancy/action/recordtypes.cpp b/engines/nancy/action/recordtypes.cpp index c63fbc42935..0aa369bcbb0 100644 --- a/engines/nancy/action/recordtypes.cpp +++ b/engines/nancy/action/recordtypes.cpp @@ -545,14 +545,14 @@ void HintSystem::execute() { } void HintSystem::selectHint() { - for (auto &hint : nancy1Hints) { + for (const auto &hint : nancy1Hints) { if (hint.characterID != _characterID) { continue; } bool satisfied = true; - for (auto &flag : hint.flagConditions) { + for (const auto &flag : hint.flagConditions) { if (flag.label == -1) { break; } @@ -563,7 +563,7 @@ void HintSystem::selectHint() { } } - for (auto &inv : hint.inventoryCondition) { + for (const auto &inv : hint.inventoryCondition) { if (inv.label == -1) { break; } diff --git a/engines/nancy/graphics.cpp b/engines/nancy/graphics.cpp index 988ca361831..1d384336bad 100644 --- a/engines/nancy/graphics.cpp +++ b/engines/nancy/graphics.cpp @@ -94,7 +94,7 @@ void GraphicsManager::draw() { } void GraphicsManager::addObject(RenderObject *object) { - for (auto &r : _objects) { + for (const auto &r : _objects) { if (r == object) { return; } diff --git a/engines/nancy/graphics.h b/engines/nancy/graphics.h index 8dcb756ef1c..31ffae87fb1 100644 --- a/engines/nancy/graphics.h +++ b/engines/nancy/graphics.h @@ -48,7 +48,7 @@ public: void redrawAll(); - Font *getFont(uint id) { return id < _fonts.size() ? &_fonts[id] : nullptr; } + const Font *getFont(uint id) const { return id < _fonts.size() ? &_fonts[id] : nullptr; } static void loadSurfacePalette(Graphics::ManagedSurface &inSurf, const Common::String paletteFilename); static void copyToManaged(const Graphics::Surface &src, Graphics::ManagedSurface &dst, bool verticalFlip = false, bool doubleSize = false); diff --git a/engines/nancy/iff.cpp b/engines/nancy/iff.cpp index 372a613f090..669867e76e0 100644 --- a/engines/nancy/iff.cpp +++ b/engines/nancy/iff.cpp @@ -145,7 +145,7 @@ uint32 IFF::stringToId(const Common::String &s) { return id; } -void IFF::list(Common::Array &nameList) { +void IFF::list(Common::Array &nameList) const { nameList.reserve(_chunks.size()); for (uint i = 0; i < _chunks.size(); ++i) { nameList.push_back(idToString(_chunks[i].id)); diff --git a/engines/nancy/iff.h b/engines/nancy/iff.h index ca9093b4b9f..e297b5b2170 100644 --- a/engines/nancy/iff.h +++ b/engines/nancy/iff.h @@ -48,7 +48,7 @@ public: Common::SeekableReadStream *getChunkStream(const Common::String &id, uint index = 0) const; // Debugger functions - void list(Common::Array &nameList); + void list(Common::Array &nameList) const; private: static Common::String idToString(uint32 id); diff --git a/engines/nancy/nancy.cpp b/engines/nancy/nancy.cpp index b958efabe12..01419c930fb 100644 --- a/engines/nancy/nancy.cpp +++ b/engines/nancy/nancy.cpp @@ -349,7 +349,7 @@ void NancyEngine::bootGameEngine() { _cursorManager->init(); } -State::State *NancyEngine::getStateObject(GameState state) { +State::State *NancyEngine::getStateObject(GameState state) const { switch (state) { case kLogo: return &State::Logo::instance(); @@ -373,7 +373,7 @@ bool NancyEngine::addBootChunk(const Common::String &name, Common::SeekableReadS return true; } -Common::SeekableReadStream *NancyEngine::getBootChunkStream(const Common::String &name) { +Common::SeekableReadStream *NancyEngine::getBootChunkStream(const Common::String &name) const { if (_bootChunks.contains(name)) { return _bootChunks[name]; } else { diff --git a/engines/nancy/nancy.h b/engines/nancy/nancy.h index 8ab8fb7f70d..31ed891bed3 100644 --- a/engines/nancy/nancy.h +++ b/engines/nancy/nancy.h @@ -129,7 +129,7 @@ public: void setPreviousState(); // Chunks found in BOOT get extracted and cached at startup, this function lets other classes access them - Common::SeekableReadStream *getBootChunkStream(const Common::String &name); + Common::SeekableReadStream *getBootChunkStream(const Common::String &name) const; void setMouseEnabled(bool enabled); @@ -164,7 +164,7 @@ private: void bootGameEngine(); - State::State *getStateObject(GameState state); + State::State *getStateObject(GameState state) const; bool addBootChunk(const Common::String &name, Common::SeekableReadStream *stream); void clearBootChunks(); diff --git a/engines/nancy/resource.cpp b/engines/nancy/resource.cpp index 4988d96f57d..2a8eb34b6ba 100644 --- a/engines/nancy/resource.cpp +++ b/engines/nancy/resource.cpp @@ -305,7 +305,7 @@ byte *CifTree::getCifData(const Common::String &name, ResourceManager::CifInfo & return buf; } -byte *ResourceManager::getCifData(const Common::String &treeName, const Common::String &name, CifInfo &info, uint *size) { +byte *ResourceManager::getCifData(const Common::String &treeName, const Common::String &name, CifInfo &info, uint *size) const { const CifFile *cifFile = CifFile::load(name); byte *buf; @@ -635,8 +635,8 @@ void ResourceManager::initialize() { loadCifTree("ciftree", "dat"); } -bool ResourceManager::getCifInfo(const Common::String &name, CifInfo &info) { - for (auto &tree : _cifTrees) { +bool ResourceManager::getCifInfo(const Common::String &name, CifInfo &info) const { + for (const auto &tree : _cifTrees) { if (getCifInfo(tree->getName(), name, info)) { return true; } @@ -645,7 +645,7 @@ bool ResourceManager::getCifInfo(const Common::String &name, CifInfo &info) { return false; } -bool ResourceManager::getCifInfo(const Common::String &treeName, const Common::String &name, CifInfo &info) { +bool ResourceManager::getCifInfo(const Common::String &treeName, const Common::String &name, CifInfo &info) const { const CifFile *cifFile = CifFile::load(name); if (cifFile) { @@ -662,7 +662,7 @@ bool ResourceManager::getCifInfo(const Common::String &treeName, const Common::S return cifTree->getCifInfo(name, info); } -byte *ResourceManager::getCifData(const Common::String &name, CifInfo &info, uint *size) { +byte *ResourceManager::getCifData(const Common::String &name, CifInfo &info, uint *size) const { // Try to open name.cif const CifFile *cifFile = CifFile::load(name); byte *buf = nullptr; @@ -835,7 +835,7 @@ bool ResourceManager::loadImage(const Common::String &name, Graphics::ManagedSur } } -void ResourceManager::list(const Common::String &treeName, Common::Array &nameList, uint type) { +void ResourceManager::list(const Common::String &treeName, Common::Array &nameList, uint type) const { const CifTree *cifTree = findCifTree(treeName); if (!cifTree) @@ -844,7 +844,7 @@ void ResourceManager::list(const Common::String &treeName, Common::Arraylist(nameList, type); } -Common::String ResourceManager::getCifDescription(const Common::String &treeName, const Common::String &name) { +Common::String ResourceManager::getCifDescription(const Common::String &treeName, const Common::String &name) const { CifInfo info; if (!getCifInfo(treeName, name, info)) return Common::String::format("Couldn't find '%s' in CifTree '%s'\n", name.c_str(), treeName.c_str()); diff --git a/engines/nancy/resource.h b/engines/nancy/resource.h index e6eb51e4f5c..ec015192be2 100644 --- a/engines/nancy/resource.h +++ b/engines/nancy/resource.h @@ -71,16 +71,16 @@ public: byte *loadData(const Common::String &name, uint &size); // Debugger functions - void list(const Common::String &treeName, Common::Array &nameList, uint type); + void list(const Common::String &treeName, Common::Array &nameList, uint type) const; byte *loadCif(const Common::String &treeName, const Common::String &name, uint &size); bool exportCif(const Common::String &treeName, const Common::String &name); - Common::String getCifDescription(const Common::String &treeName, const Common::String &name); + Common::String getCifDescription(const Common::String &treeName, const Common::String &name) const; private: - byte *getCifData(const Common::String &name, CifInfo &info, uint *size = nullptr); - byte *getCifData(const Common::String &treeName, const Common::String &name, CifInfo &info, uint *size = nullptr); - bool getCifInfo(const Common::String &name, CifInfo &info); - bool getCifInfo(const Common::String &treeName, const Common::String &name, CifInfo &info); + byte *getCifData(const Common::String &name, CifInfo &info, uint *size = nullptr) const; + byte *getCifData(const Common::String &treeName, const Common::String &name, CifInfo &info, uint *size = nullptr) const; + bool getCifInfo(const Common::String &name, CifInfo &info) const; + bool getCifInfo(const Common::String &treeName, const Common::String &name, CifInfo &info) const; const CifTree *findCifTree(const Common::String &name) const; Common::Array _cifTrees; diff --git a/engines/nancy/sound.cpp b/engines/nancy/sound.cpp index 8ca3568918e..9e26788704c 100644 --- a/engines/nancy/sound.cpp +++ b/engines/nancy/sound.cpp @@ -244,14 +244,14 @@ void SoundManager::pauseSound(const SoundDescription &description, bool pause) { } } -bool SoundManager::isSoundPlaying(uint16 channelID) { +bool SoundManager::isSoundPlaying(uint16 channelID) const { if (channelID > 32) return false; return _mixer->isSoundHandleActive(_channels[channelID].handle); } -bool SoundManager::isSoundPlaying(const SoundDescription &description) { +bool SoundManager::isSoundPlaying(const SoundDescription &description) const { if (description.name == "NO SOUND") { return false; } else { diff --git a/engines/nancy/sound.h b/engines/nancy/sound.h index 0565c0769b4..cd402e1e587 100644 --- a/engines/nancy/sound.h +++ b/engines/nancy/sound.h @@ -56,8 +56,8 @@ public: void pauseSound(uint16 channelID, bool pause); void pauseSound(const SoundDescription &description, bool pause); - bool isSoundPlaying(uint16 channelID); - bool isSoundPlaying(const SoundDescription &description); + bool isSoundPlaying(uint16 channelID) const; + bool isSoundPlaying(const SoundDescription &description) const; void stopSound(uint16 channelID); void stopSound(const SoundDescription &description); diff --git a/engines/nancy/ui/inventorybox.h b/engines/nancy/ui/inventorybox.h index 20e477e3cc0..ebb6d4dae24 100644 --- a/engines/nancy/ui/inventorybox.h +++ b/engines/nancy/ui/inventorybox.h @@ -72,7 +72,7 @@ public: void addItem(int16 itemID); void removeItem(int16 itemID); - ItemDescription getItemDescription(uint id) { return _itemDescriptions[id]; } + ItemDescription getItemDescription(uint id) const { return _itemDescriptions[id]; } protected: virtual uint16 getZOrder() const override { return 6; } diff --git a/engines/nancy/ui/textbox.cpp b/engines/nancy/ui/textbox.cpp index a40dfdebf8a..9db17ef1d4c 100644 --- a/engines/nancy/ui/textbox.cpp +++ b/engines/nancy/ui/textbox.cpp @@ -126,7 +126,7 @@ void Textbox::drawTextbox() { _numLines = 0; - Font *font = g_nancy->_graphicsManager->getFont(_fontID); + const Font *font = g_nancy->_graphicsManager->getFont(_fontID); uint maxWidth = _fullSurface.w - _borderWidth * 2; uint lineDist = _lineHeight + _lineHeight / 4;