1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-11-28 08:48:48 +02:00

Fixes for various minor issues detected by Sonar Cloud

This commit is contained in:
Ivan Savenko 2024-06-01 11:48:30 +00:00
parent df83fa33a1
commit b8beb4fb13
29 changed files with 58 additions and 61 deletions

View File

@ -603,7 +603,7 @@ void AIGateway::heroGotLevel(const CGHeroInstance * hero, PrimarySkill pskill, s
if(hPtr.validAndSet()) if(hPtr.validAndSet())
{ {
std::unique_lock<std::mutex> lockGuard(nullkiller->aiStateMutex); std::unique_lock lockGuard(nullkiller->aiStateMutex);
nullkiller->heroManager->update(); nullkiller->heroManager->update();
@ -683,7 +683,7 @@ void AIGateway::showBlockingDialog(const std::string & text, const std::vector<C
sel = components.size(); sel = components.size();
{ {
std::unique_lock<std::mutex> mxLock(nullkiller->aiStateMutex); std::unique_lock mxLock(nullkiller->aiStateMutex);
// TODO: Find better way to understand it is Chest of Treasures // TODO: Find better way to understand it is Chest of Treasures
if(hero.validAndSet() if(hero.validAndSet()
@ -804,7 +804,7 @@ void AIGateway::makeTurn()
auto day = cb->getDate(Date::DAY); auto day = cb->getDate(Date::DAY);
logAi->info("Player %d (%s) starting turn, day %d", playerID, playerID.toString(), day); logAi->info("Player %d (%s) starting turn, day %d", playerID, playerID.toString(), day);
boost::shared_lock<boost::shared_mutex> gsLock(CGameState::mutex); boost::shared_lock gsLock(CGameState::mutex);
setThreadName("AIGateway::makeTurn"); setThreadName("AIGateway::makeTurn");
if(nullkiller->isOpenMap()) if(nullkiller->isOpenMap())
@ -864,7 +864,7 @@ void AIGateway::performObjectInteraction(const CGObjectInstance * obj, HeroPtr h
{ {
makePossibleUpgrades(h.get()); makePossibleUpgrades(h.get());
std::unique_lock<std::mutex> lockGuard(nullkiller->aiStateMutex); std::unique_lock lockGuard(nullkiller->aiStateMutex);
if(!h->visitedTown->garrisonHero || !nullkiller->isHeroLocked(h->visitedTown->garrisonHero)) if(!h->visitedTown->garrisonHero || !nullkiller->isHeroLocked(h->visitedTown->garrisonHero))
moveCreaturesToHero(h->visitedTown); moveCreaturesToHero(h->visitedTown);
@ -1529,7 +1529,7 @@ void AIGateway::requestActionASAP(std::function<void()> whatToDo)
{ {
setThreadName("AIGateway::requestActionASAP::whatToDo"); setThreadName("AIGateway::requestActionASAP::whatToDo");
SET_GLOBAL_STATE(this); SET_GLOBAL_STATE(this);
boost::shared_lock<boost::shared_mutex> gsLock(CGameState::mutex); boost::shared_lock gsLock(CGameState::mutex);
whatToDo(); whatToDo();
}); });

View File

@ -216,7 +216,7 @@ void Nullkiller::decompose(Goals::TGoalVec & result, Goals::TSubgoal behavior, i
void Nullkiller::resetAiState() void Nullkiller::resetAiState()
{ {
std::unique_lock<std::mutex> lockGuard(aiStateMutex); std::unique_lock lockGuard(aiStateMutex);
lockedResources = TResources(); lockedResources = TResources();
scanDepth = ScanDepth::MAIN_FULL; scanDepth = ScanDepth::MAIN_FULL;
@ -236,7 +236,7 @@ void Nullkiller::updateAiState(int pass, bool fast)
{ {
boost::this_thread::interruption_point(); boost::this_thread::interruption_point();
std::unique_lock<std::mutex> lockGuard(aiStateMutex); std::unique_lock lockGuard(aiStateMutex);
auto start = std::chrono::high_resolution_clock::now(); auto start = std::chrono::high_resolution_clock::now();

View File

@ -217,7 +217,7 @@ ExchangeResult HeroExchangeMap::tryExchangeNoLock(const ChainActor * other)
ExchangeResult result; ExchangeResult result;
{ {
boost::shared_lock<boost::shared_mutex> lock(sync, boost::try_to_lock); boost::shared_lock lock(sync, boost::try_to_lock);
if(!lock.owns_lock()) if(!lock.owns_lock())
{ {
@ -237,7 +237,7 @@ ExchangeResult HeroExchangeMap::tryExchangeNoLock(const ChainActor * other)
} }
{ {
boost::unique_lock<boost::shared_mutex> uniqueLock(sync, boost::try_to_lock); boost::unique_lock uniqueLock(sync, boost::try_to_lock);
if(!uniqueLock.owns_lock()) if(!uniqueLock.owns_lock())
{ {

View File

@ -773,7 +773,7 @@ void VCAI::makeTurn()
auto day = cb->getDate(Date::DAY); auto day = cb->getDate(Date::DAY);
logAi->info("Player %d (%s) starting turn, day %d", playerID, playerID.toString(), day); logAi->info("Player %d (%s) starting turn, day %d", playerID, playerID.toString(), day);
boost::shared_lock<boost::shared_mutex> gsLock(CGameState::mutex); boost::shared_lock gsLock(CGameState::mutex);
setThreadName("VCAI::makeTurn"); setThreadName("VCAI::makeTurn");
switch(cb->getDate(Date::DAY_OF_WEEK)) switch(cb->getDate(Date::DAY_OF_WEEK))
@ -2479,7 +2479,7 @@ void VCAI::requestActionASAP(std::function<void()> whatToDo)
{ {
setThreadName("VCAI::requestActionASAP::whatToDo"); setThreadName("VCAI::requestActionASAP::whatToDo");
SET_GLOBAL_STATE(this); SET_GLOBAL_STATE(this);
boost::shared_lock<boost::shared_mutex> gsLock(CGameState::mutex); boost::shared_lock gsLock(CGameState::mutex);
whatToDo(); whatToDo();
}); });

View File

@ -1481,7 +1481,7 @@ void CPlayerInterface::playerBlocked(int reason, bool start)
void CPlayerInterface::update() void CPlayerInterface::update()
{ {
// Make sure that gamestate won't change when GUI objects may obtain its parts on event processing or drawing request // Make sure that gamestate won't change when GUI objects may obtain its parts on event processing or drawing request
boost::shared_lock<boost::shared_mutex> gsLock(CGameState::mutex); boost::shared_lock gsLock(CGameState::mutex);
// While mutexes were locked away we may be have stopped being the active interface // While mutexes were locked away we may be have stopped being the active interface
if (LOCPLINT != this) if (LOCPLINT != this)

View File

@ -173,7 +173,7 @@ void CServerHandler::threadRunNetwork()
try { try {
networkHandler->run(); networkHandler->run();
} }
catch (const TerminationRequestedException & e) catch (const TerminationRequestedException &)
{ {
logGlobal->info("Terminating network thread"); logGlobal->info("Terminating network thread");
return; return;

View File

@ -408,7 +408,7 @@ void CClient::handlePack(CPack * pack)
apply->applyOnClBefore(this, pack); apply->applyOnClBefore(this, pack);
logNetwork->trace("\tMade first apply on cl: %s", typeid(*pack).name()); logNetwork->trace("\tMade first apply on cl: %s", typeid(*pack).name());
{ {
boost::unique_lock<boost::shared_mutex> lock(CGameState::mutex); boost::unique_lock lock(CGameState::mutex);
gs->apply(pack); gs->apply(pack);
} }
logNetwork->trace("\tApplied on gs: %s", typeid(*pack).name()); logNetwork->trace("\tApplied on gs: %s", typeid(*pack).name());

View File

@ -33,7 +33,7 @@ class ConditionalWait
void set(bool value) void set(bool value)
{ {
boost::unique_lock<std::mutex> lock(mx); std::unique_lock lock(mx);
isBusyValue = value; isBusyValue = value;
} }
@ -59,15 +59,14 @@ public:
bool isBusy() bool isBusy()
{ {
std::unique_lock<std::mutex> lock(mx); std::unique_lock lock(mx);
return isBusyValue; return isBusyValue;
} }
void waitWhileBusy() void waitWhileBusy()
{ {
std::unique_lock<std::mutex> un(mx); std::unique_lock un(mx);
while(isBusyValue) cond.wait(un, [this](){ return !isBusyValue;});
cond.wait(un);
if (isTerminating) if (isTerminating)
throw TerminationRequestedException(); throw TerminationRequestedException();

View File

@ -48,7 +48,7 @@ void AdventureMapShortcuts::setState(EAdventureState newState)
state = newState; state = newState;
} }
EAdventureState AdventureMapShortcuts::getState() EAdventureState AdventureMapShortcuts::getState() const
{ {
return state; return state;
} }

View File

@ -94,6 +94,6 @@ public:
bool optionMapViewActive(); bool optionMapViewActive();
void setState(EAdventureState newState); void setState(EAdventureState newState);
EAdventureState getState(); EAdventureState getState() const;
void onMapViewMoved(const Rect & visibleArea, int mapLevel); void onMapViewMoved(const Rect & visibleArea, int mapLevel);
}; };

View File

@ -72,7 +72,7 @@ void BattleConsole::showAll(Canvas & to)
to.drawText(line2, FONT_SMALL, Colors::WHITE, ETextAlignment::CENTER, visibleText[1]); to.drawText(line2, FONT_SMALL, Colors::WHITE, ETextAlignment::CENTER, visibleText[1]);
} }
std::vector<std::string> BattleConsole::getVisibleText() std::vector<std::string> BattleConsole::getVisibleText() const
{ {
// high priority texts that hide battle log entries // high priority texts that hide battle log entries
for(const auto & text : {consoleText, hoverText}) for(const auto & text : {consoleText, hoverText})

View File

@ -72,7 +72,7 @@ private:
std::vector<std::string> splitText(const std::string &text); std::vector<std::string> splitText(const std::string &text);
/// select line(s) that will be visible in UI /// select line(s) that will be visible in UI
std::vector<std::string> getVisibleText(); std::vector<std::string> getVisibleText() const;
public: public:
BattleConsole(const BattleInterface & owner, std::shared_ptr<CPicture> backgroundSource, const Point & objectPos, const Point & imagePos, const Point &size); BattleConsole(const BattleInterface & owner, std::shared_ptr<CPicture> backgroundSource, const Point & objectPos, const Point & imagePos, const Point &size);

View File

@ -773,7 +773,7 @@ void BattleWindow::bOpenActiveUnit()
const auto * unit = owner.stacksController->getActiveStack(); const auto * unit = owner.stacksController->getActiveStack();
if (unit) if (unit)
GH.windows().createAndPushWindow<CStackWindow>(unit, false);; GH.windows().createAndPushWindow<CStackWindow>(unit, false);
} }
void BattleWindow::bOpenHoveredUnit() void BattleWindow::bOpenHoveredUnit()

View File

@ -478,7 +478,7 @@ void TownSelector::updateListItems()
{ {
if(y >= line && (y - line) < 3) if(y >= line && (y - line) < 3)
{ {
auto getImageIndex = [](FactionID factionID, bool enabled){ return factionID.toFaction()->town->clientInfo.icons[true][!enabled] + 2; }; auto getImageIndex = [](FactionID targetFactionID, bool enabled){ return targetFactionID.toFaction()->town->clientInfo.icons[true][!enabled] + 2; };
towns[factionID] = std::make_shared<CAnimImage>(AnimationPath::builtin("ITPA"), getImageIndex(factionID, townsEnabled[factionID]), 0, x_offset + 48 * x, 32 * (y - line)); towns[factionID] = std::make_shared<CAnimImage>(AnimationPath::builtin("ITPA"), getImageIndex(factionID, townsEnabled[factionID]), 0, x_offset + 48 * x, 32 * (y - line));
townsArea[factionID] = std::make_shared<LRClickableArea>(Rect(x_offset + 48 * x, 32 * (y - line), 48, 32), [this, getImageIndex, factionID](){ townsArea[factionID] = std::make_shared<LRClickableArea>(Rect(x_offset + 48 * x, 32 * (y - line), 48, 32), [this, getImageIndex, factionID](){
townsEnabled[factionID] = !townsEnabled[factionID]; townsEnabled[factionID] = !townsEnabled[factionID];

View File

@ -698,7 +698,7 @@ void SelectionTab::selectNewestFile()
{ {
time_t newestTime = 0; time_t newestTime = 0;
std::string newestFile = ""; std::string newestFile = "";
for(int i = (int)allItems.size() - 1; i >= 0; i--) for(int i = static_cast<int>(allItems.size()) - 1; i >= 0; i--)
if(allItems[i]->lastWrite > newestTime) if(allItems[i]->lastWrite > newestTime)
{ {
newestTime = allItems[i]->lastWrite; newestTime = allItems[i]->lastWrite;

View File

@ -112,10 +112,10 @@ void CHighScoreScreen::addButtons()
buttons.clear(); buttons.clear();
buttons.push_back(std::make_shared<CButton>(Point(31, 113), AnimationPath::builtin("HISCCAM.DEF"), CButton::tooltip(), [&](){ buttonCampaignClick(); }, EShortcut::HIGH_SCORES_CAMPAIGNS)); buttons.push_back(std::make_shared<CButton>(Point(31, 113), AnimationPath::builtin("HISCCAM.DEF"), CButton::tooltip(), [this](){ buttonCampaignClick(); }, EShortcut::HIGH_SCORES_CAMPAIGNS));
buttons.push_back(std::make_shared<CButton>(Point(31, 345), AnimationPath::builtin("HISCSTA.DEF"), CButton::tooltip(), [&](){ buttonScenarioClick(); }, EShortcut::HIGH_SCORES_SCENARIOS)); buttons.push_back(std::make_shared<CButton>(Point(31, 345), AnimationPath::builtin("HISCSTA.DEF"), CButton::tooltip(), [this](){ buttonScenarioClick(); }, EShortcut::HIGH_SCORES_SCENARIOS));
buttons.push_back(std::make_shared<CButton>(Point(726, 113), AnimationPath::builtin("HISCRES.DEF"), CButton::tooltip(), [&](){ buttonResetClick(); }, EShortcut::HIGH_SCORES_RESET)); buttons.push_back(std::make_shared<CButton>(Point(726, 113), AnimationPath::builtin("HISCRES.DEF"), CButton::tooltip(), [this](){ buttonResetClick(); }, EShortcut::HIGH_SCORES_RESET));
buttons.push_back(std::make_shared<CButton>(Point(726, 345), AnimationPath::builtin("HISCEXT.DEF"), CButton::tooltip(), [&](){ buttonExitClick(); }, EShortcut::GLOBAL_RETURN)); buttons.push_back(std::make_shared<CButton>(Point(726, 345), AnimationPath::builtin("HISCEXT.DEF"), CButton::tooltip(), [this](){ buttonExitClick(); }, EShortcut::GLOBAL_RETURN));
} }
void CHighScoreScreen::addHighScores() void CHighScoreScreen::addHighScores()

View File

@ -117,7 +117,7 @@ void CTextInput::setFilterNumber(int minValue, int maxValue)
onTextFiltering = std::bind(&CTextInput::numberFilter, _1, _2, minValue, maxValue); onTextFiltering = std::bind(&CTextInput::numberFilter, _1, _2, minValue, maxValue);
} }
std::string CTextInput::getVisibleText() std::string CTextInput::getVisibleText() const
{ {
return hasFocus() ? currentText + composedText + "_" : currentText; return hasFocus() ? currentText + composedText + "_" : currentText;
} }
@ -216,7 +216,6 @@ void CTextInput::textEdited(const std::string & enteredText)
composedText = enteredText; composedText = enteredText;
updateLabel(); updateLabel();
//onTextEdited(currentText + composedText);
} }
void CTextInput::filenameFilter(std::string & text, const std::string &oldText) void CTextInput::filenameFilter(std::string & text, const std::string &oldText)

View File

@ -49,7 +49,6 @@ class CTextInput final : public CFocusable
using TextEditedCallback = std::function<void(const std::string &)>; using TextEditedCallback = std::function<void(const std::string &)>;
using TextFilterCallback = std::function<void(std::string &, const std::string &)>; using TextFilterCallback = std::function<void(std::string &, const std::string &)>;
private:
std::string currentText; std::string currentText;
std::string composedText; std::string composedText;
ETextAlignment originalAlignment; ETextAlignment originalAlignment;
@ -66,7 +65,7 @@ private:
//min-max should be set via something like std::bind //min-max should be set via something like std::bind
static void numberFilter(std::string & text, const std::string & oldText, int minValue, int maxValue); static void numberFilter(std::string & text, const std::string & oldText, int minValue, int maxValue);
std::string getVisibleText(); std::string getVisibleText() const;
void createLabel(bool giveFocusToInput); void createLabel(bool giveFocusToInput);
void updateLabel(); void updateLabel();

View File

@ -1039,11 +1039,11 @@ void CCastleBuildings::openTownHall()
void CCastleBuildings::enterAnyThievesGuild() void CCastleBuildings::enterAnyThievesGuild()
{ {
std::vector<const CGTownInstance*> towns = LOCPLINT->cb->getTownsInfo(true); std::vector<const CGTownInstance*> towns = LOCPLINT->cb->getTownsInfo(true);
for(auto & town : towns) for(auto & ownedTown : towns)
{ {
if(town->builtBuildings.count(BuildingID::TAVERN)) if(ownedTown->builtBuildings.count(BuildingID::TAVERN))
{ {
LOCPLINT->showThievesGuildWindow(town); LOCPLINT->showThievesGuildWindow(ownedTown);
return; return;
} }
} }

View File

@ -208,7 +208,7 @@ void CHeroWindow::update()
boost::algorithm::replace_first(helpBox, "%s", CGI->generaltexth->allTexts[43]); boost::algorithm::replace_first(helpBox, "%s", CGI->generaltexth->allTexts[43]);
garr = std::make_shared<CGarrisonInt>(Point(15, 485), 8, Point(), curHero); garr = std::make_shared<CGarrisonInt>(Point(15, 485), 8, Point(), curHero);
auto split = std::make_shared<CButton>(Point(539, 519), AnimationPath::builtin("hsbtns9.def"), CButton::tooltip(CGI->generaltexth->allTexts[256], helpBox), [&](){ garr->splitClick(); }, EShortcut::HERO_ARMY_SPLIT); auto split = std::make_shared<CButton>(Point(539, 519), AnimationPath::builtin("hsbtns9.def"), CButton::tooltip(CGI->generaltexth->allTexts[256], helpBox), [this](){ garr->splitClick(); }, EShortcut::HERO_ARMY_SPLIT);
garr->addSplitBtn(split); garr->addSplitBtn(split);
} }
if(!arts) if(!arts)

View File

@ -1010,10 +1010,10 @@ CGarrisonWindow::CGarrisonWindow(const CArmedInstance * up, const CGHeroInstance
garr = std::make_shared<CGarrisonInt>(Point(92, 127), 4, Point(0,96), up, down, removableUnits); garr = std::make_shared<CGarrisonInt>(Point(92, 127), 4, Point(0,96), up, down, removableUnits);
{ {
auto split = std::make_shared<CButton>(Point(88, 314), AnimationPath::builtin("IDV6432.DEF"), CButton::tooltip(CGI->generaltexth->tcommands[3], ""), [&](){ garr->splitClick(); }, EShortcut::HERO_ARMY_SPLIT ); auto split = std::make_shared<CButton>(Point(88, 314), AnimationPath::builtin("IDV6432.DEF"), CButton::tooltip(CGI->generaltexth->tcommands[3], ""), [this](){ garr->splitClick(); }, EShortcut::HERO_ARMY_SPLIT );
garr->addSplitBtn(split); garr->addSplitBtn(split);
} }
quit = std::make_shared<CButton>(Point(399, 314), AnimationPath::builtin("IOK6432.DEF"), CButton::tooltip(CGI->generaltexth->tcommands[8], ""), [&](){ close(); }, EShortcut::GLOBAL_ACCEPT); quit = std::make_shared<CButton>(Point(399, 314), AnimationPath::builtin("IOK6432.DEF"), CButton::tooltip(CGI->generaltexth->tcommands[8], ""), [this](){ close(); }, EShortcut::GLOBAL_ACCEPT);
std::string titleText; std::string titleText;
if(down->tempOwner == up->tempOwner) if(down->tempOwner == up->tempOwner)

View File

@ -253,7 +253,7 @@ bool CLegacyConfigParser::endLine()
void TextLocalizationContainer::registerStringOverride(const std::string & modContext, const std::string & language, const TextIdentifier & UID, const std::string & localized) void TextLocalizationContainer::registerStringOverride(const std::string & modContext, const std::string & language, const TextIdentifier & UID, const std::string & localized)
{ {
std::lock_guard<std::recursive_mutex> globalLock(globalTextMutex); std::lock_guard globalLock(globalTextMutex);
assert(!modContext.empty()); assert(!modContext.empty());
assert(!language.empty()); assert(!language.empty());
@ -269,7 +269,7 @@ void TextLocalizationContainer::registerStringOverride(const std::string & modCo
void TextLocalizationContainer::addSubContainer(const TextLocalizationContainer & container) void TextLocalizationContainer::addSubContainer(const TextLocalizationContainer & container)
{ {
std::lock_guard<std::recursive_mutex> globalLock(globalTextMutex); std::lock_guard globalLock(globalTextMutex);
assert(!vstd::contains(subContainers, &container)); assert(!vstd::contains(subContainers, &container));
subContainers.push_back(&container); subContainers.push_back(&container);
@ -277,7 +277,7 @@ void TextLocalizationContainer::addSubContainer(const TextLocalizationContainer
void TextLocalizationContainer::removeSubContainer(const TextLocalizationContainer & container) void TextLocalizationContainer::removeSubContainer(const TextLocalizationContainer & container)
{ {
std::lock_guard<std::recursive_mutex> globalLock(globalTextMutex); std::lock_guard globalLock(globalTextMutex);
assert(vstd::contains(subContainers, &container)); assert(vstd::contains(subContainers, &container));
@ -286,7 +286,7 @@ void TextLocalizationContainer::removeSubContainer(const TextLocalizationContain
const std::string & TextLocalizationContainer::deserialize(const TextIdentifier & identifier) const const std::string & TextLocalizationContainer::deserialize(const TextIdentifier & identifier) const
{ {
std::lock_guard<std::recursive_mutex> globalLock(globalTextMutex); std::lock_guard globalLock(globalTextMutex);
if(stringsLocalizations.count(identifier.get()) == 0) if(stringsLocalizations.count(identifier.get()) == 0)
{ {
@ -307,7 +307,7 @@ const std::string & TextLocalizationContainer::deserialize(const TextIdentifier
void TextLocalizationContainer::registerString(const std::string & modContext, const TextIdentifier & UID, const std::string & localized, const std::string & language) void TextLocalizationContainer::registerString(const std::string & modContext, const TextIdentifier & UID, const std::string & localized, const std::string & language)
{ {
std::lock_guard<std::recursive_mutex> globalLock(globalTextMutex); std::lock_guard globalLock(globalTextMutex);
assert(!modContext.empty()); assert(!modContext.empty());
assert(!Languages::getLanguageOptions(language).identifier.empty()); assert(!Languages::getLanguageOptions(language).identifier.empty());
@ -339,7 +339,7 @@ void TextLocalizationContainer::registerString(const std::string & modContext, c
bool TextLocalizationContainer::validateTranslation(const std::string & language, const std::string & modContext, const JsonNode & config) const bool TextLocalizationContainer::validateTranslation(const std::string & language, const std::string & modContext, const JsonNode & config) const
{ {
std::lock_guard<std::recursive_mutex> globalLock(globalTextMutex); std::lock_guard globalLock(globalTextMutex);
bool allPresent = true; bool allPresent = true;
@ -398,14 +398,14 @@ void TextLocalizationContainer::loadTranslationOverrides(const std::string & lan
bool TextLocalizationContainer::identifierExists(const TextIdentifier & UID) const bool TextLocalizationContainer::identifierExists(const TextIdentifier & UID) const
{ {
std::lock_guard<std::recursive_mutex> globalLock(globalTextMutex); std::lock_guard globalLock(globalTextMutex);
return stringsLocalizations.count(UID.get()); return stringsLocalizations.count(UID.get());
} }
void TextLocalizationContainer::exportAllTexts(std::map<std::string, std::map<std::string, std::string>> & storage) const void TextLocalizationContainer::exportAllTexts(std::map<std::string, std::map<std::string, std::string>> & storage) const
{ {
std::lock_guard<std::recursive_mutex> globalLock(globalTextMutex); std::lock_guard globalLock(globalTextMutex);
for (auto const & subContainer : subContainers) for (auto const & subContainer : subContainers)
subContainer->exportAllTexts(storage); subContainer->exportAllTexts(storage);
@ -436,7 +436,7 @@ std::string TextLocalizationContainer::getModLanguage(const std::string & modCon
void TextLocalizationContainer::jsonSerialize(JsonNode & dest) const void TextLocalizationContainer::jsonSerialize(JsonNode & dest) const
{ {
std::lock_guard<std::recursive_mutex> globalLock(globalTextMutex); std::lock_guard globalLock(globalTextMutex);
for(auto & s : stringsLocalizations) for(auto & s : stringsLocalizations)
{ {
@ -712,7 +712,7 @@ std::string CGeneralTextHandler::getInstalledEncoding()
std::vector<std::string> CGeneralTextHandler::findStringsWithPrefix(const std::string & prefix) std::vector<std::string> CGeneralTextHandler::findStringsWithPrefix(const std::string & prefix)
{ {
std::lock_guard<std::recursive_mutex> globalLock(globalTextMutex); std::lock_guard globalLock(globalTextMutex);
std::vector<std::string> result; std::vector<std::string> result;
for(const auto & entry : stringsLocalizations) for(const auto & entry : stringsLocalizations)

View File

@ -140,7 +140,7 @@ public:
{ {
struct Helper : public Serializeable struct Helper : public Serializeable
{ {
void serialize(Handler &h) void serialize(Handler &h) const
{} {}
}; };
Helper helper; Helper helper;

View File

@ -200,7 +200,7 @@ std::shared_ptr<CSkill> CSkillHandler::loadFromJson(const std::string & scope, c
major = json["obligatoryMajor"].Bool(); major = json["obligatoryMajor"].Bool();
minor = json["obligatoryMinor"].Bool(); minor = json["obligatoryMinor"].Bool();
auto skill = std::make_shared<CSkill>(SecondarySkill((si32)index), identifier, major, minor); auto skill = std::make_shared<CSkill>(SecondarySkill(index), identifier, major, minor);
skill->modScope = scope; skill->modScope = scope;
skill->onlyOnWaterMap = json["onlyOnWaterMap"].Bool(); skill->onlyOnWaterMap = json["onlyOnWaterMap"].Bool();

View File

@ -148,7 +148,7 @@ void NetworkConnection::sendPacket(const std::vector<std::byte> & message)
bool messageQueueEmpty = dataToSend.empty(); bool messageQueueEmpty = dataToSend.empty();
dataToSend.push_back(headerVector); dataToSend.push_back(headerVector);
if (message.size() > 0) if (!message.empty())
dataToSend.push_back(message); dataToSend.push_back(message);
if (messageQueueEmpty) if (messageQueueEmpty)
@ -159,7 +159,7 @@ void NetworkConnection::sendPacket(const std::vector<std::byte> & message)
{ {
boost::system::error_code ec; boost::system::error_code ec;
boost::asio::write(*socket, boost::asio::buffer(headerVector), ec ); boost::asio::write(*socket, boost::asio::buffer(headerVector), ec );
if (message.size() > 0) if (!message.empty())
boost::asio::write(*socket, boost::asio::buffer(message), ec ); boost::asio::write(*socket, boost::asio::buffer(message), ec );
} }
} }

View File

@ -63,7 +63,7 @@ struct DLL_LINKAGE LobbyClientConnected : public CLobbyPackToPropagate
else else
version = ESerializationVersion::RELEASE_150; version = ESerializationVersion::RELEASE_150;
} }
catch (const std::runtime_error & e) catch (const std::runtime_error &)
{ {
version = ESerializationVersion::RELEASE_150; version = ESerializationVersion::RELEASE_150;
} }

View File

@ -181,7 +181,7 @@ std::set<Point2D> PenroseTiling::generatePenroseTiling(size_t numZones, CRandomG
for (auto & point : points) for (auto & point : points)
{ {
point = point + Point2D(0.5f, 0.5f); point = point + Point2D(0.5f, 0.5f);
}; }
// For 8XM8 map, only 650 out of 15971 points are in the range // For 8XM8 map, only 650 out of 15971 points are in the range
@ -193,4 +193,4 @@ std::set<Point2D> PenroseTiling::generatePenroseTiling(size_t numZones, CRandomG
return finalPoints; return finalPoints;
} }
VCMI_LIB_NAMESPACE_END VCMI_LIB_NAMESPACE_END

View File

@ -124,7 +124,7 @@ void Graphics::load()
void Graphics::loadHeroAnimations() void Graphics::loadHeroAnimations()
{ {
for(auto & elem : VLC->heroclassesh->objects) for(const auto & elem : VLC->heroclassesh->objects)
{ {
for(auto templ : VLC->objtypeh->getHandlerFor(Obj::HERO, elem->getIndex())->getTemplates()) for(auto templ : VLC->objtypeh->getHandlerFor(Obj::HERO, elem->getIndex())->getTemplates())
{ {

View File

@ -985,7 +985,7 @@ ui8 CVCMIServer::getIdOfFirstUnallocatedPlayer() const
void CVCMIServer::multiplayerWelcomeMessage() void CVCMIServer::multiplayerWelcomeMessage()
{ {
int humanPlayer = 0; int humanPlayer = 0;
for (auto & pi : si->playerInfos) for (const auto & pi : si->playerInfos)
if(pi.second.isControlledByHuman()) if(pi.second.isControlledByHuman())
humanPlayer++; humanPlayer++;
@ -996,9 +996,9 @@ void CVCMIServer::multiplayerWelcomeMessage()
std::vector<std::string> optionIds; std::vector<std::string> optionIds;
if(si->extraOptionsInfo.cheatsAllowed) if(si->extraOptionsInfo.cheatsAllowed)
optionIds.push_back("vcmi.optionsTab.cheatAllowed.hover"); optionIds.emplace_back("vcmi.optionsTab.cheatAllowed.hover");
if(si->extraOptionsInfo.unlimitedReplay) if(si->extraOptionsInfo.unlimitedReplay)
optionIds.push_back("vcmi.optionsTab.unlimitedReplay.hover"); optionIds.emplace_back("vcmi.optionsTab.unlimitedReplay.hover");
if(!optionIds.size()) // No settings to publish if(!optionIds.size()) // No settings to publish
return; return;