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.
This commit is contained in:
fracturehill 2021-03-20 19:52:39 +02:00 committed by Eugene Sandulenko
parent bfc6586f78
commit 56c005ef2c
15 changed files with 34 additions and 34 deletions

View File

@ -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);

View File

@ -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];

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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);

View File

@ -145,7 +145,7 @@ uint32 IFF::stringToId(const Common::String &s) {
return id;
}
void IFF::list(Common::Array<Common::String> &nameList) {
void IFF::list(Common::Array<Common::String> &nameList) const {
nameList.reserve(_chunks.size());
for (uint i = 0; i < _chunks.size(); ++i) {
nameList.push_back(idToString(_chunks[i].id));

View File

@ -48,7 +48,7 @@ public:
Common::SeekableReadStream *getChunkStream(const Common::String &id, uint index = 0) const;
// Debugger functions
void list(Common::Array<Common::String> &nameList);
void list(Common::Array<Common::String> &nameList) const;
private:
static Common::String idToString(uint32 id);

View File

@ -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 {

View File

@ -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();

View File

@ -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<Common::String> &nameList, uint type) {
void ResourceManager::list(const Common::String &treeName, Common::Array<Common::String> &nameList, uint type) const {
const CifTree *cifTree = findCifTree(treeName);
if (!cifTree)
@ -844,7 +844,7 @@ void ResourceManager::list(const Common::String &treeName, Common::Array<Common:
cifTree->list(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());

View File

@ -71,16 +71,16 @@ public:
byte *loadData(const Common::String &name, uint &size);
// Debugger functions
void list(const Common::String &treeName, Common::Array<Common::String> &nameList, uint type);
void list(const Common::String &treeName, Common::Array<Common::String> &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<const CifTree *> _cifTrees;

View File

@ -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 {

View File

@ -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);

View File

@ -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; }

View File

@ -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;