1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-20 20:23:03 +02:00

Fix some 'new' issues reported by Sonar Cloud

This commit is contained in:
Ivan Savenko 2024-05-06 15:33:30 +00:00
parent ee2cd988f4
commit 30e0a16ee9
12 changed files with 43 additions and 45 deletions

View File

@ -418,7 +418,7 @@ void Nullkiller::makeTurn()
scanDepth = ScanDepth::ALL_FULL;
useHeroChain = false;
hasAnySuccess = true;
break;;
break;
}
logAi->trace("Goal %s has too low priority. It is not worth doing it.", taskDescription);

View File

@ -140,7 +140,7 @@ struct GraphPathNodePointer
}
};
typedef std::unordered_map<int3, GraphPathNode[GrapthPathNodeType::LAST]> GraphNodeStorage;
using GraphNodeStorage = std::unordered_map<int3, GraphPathNode[GrapthPathNodeType::LAST]>;
class GraphNodeComparer
{

View File

@ -729,10 +729,10 @@ void BattleInterface::requestAutofightingAIToTakeAction()
// FIXME: unsafe
// Run task in separate thread to avoid UI lock while AI is making turn (which might take some time)
// HOWEVER this thread won't atttempt to lock game state, potentially leading to races
boost::thread aiThread([battleID = this->battleID, curInt = this->curInt, activeStack]()
boost::thread aiThread([localBattleID = battleID, localCurInt = curInt, activeStack]()
{
setThreadName("autofightingAI");
curInt->autofightingAI->activeStack(battleID, activeStack);
localCurInt->autofightingAI->activeStack(localBattleID, activeStack);
});
aiThread.detach();
}

View File

@ -33,14 +33,14 @@
#include <SDL_timer.h>
InputHandler::InputHandler()
: mouseHandler(std::make_unique<InputSourceMouse>())
: enableMouse(settings["input"]["enableMouse"].Bool())
, enableTouch(settings["input"]["enableTouch"].Bool())
, enableController(settings["input"]["enableController"].Bool())
, mouseHandler(std::make_unique<InputSourceMouse>())
, keyboardHandler(std::make_unique<InputSourceKeyboard>())
, fingerHandler(std::make_unique<InputSourceTouch>())
, textHandler(std::make_unique<InputSourceText>())
, gameControllerHandler(std::make_unique<InputSourceGameController>())
, enableMouse(settings["input"]["enableMouse"].Bool())
, enableTouch(settings["input"]["enableTouch"].Bool())
, enableController(settings["input"]["enableController"].Bool())
{
}

View File

@ -28,13 +28,6 @@ void InputSourceGameController::gameControllerDeleter(SDL_GameController * gameC
}
InputSourceGameController::InputSourceGameController():
configTriggerTreshold(settings["input"]["controllerTriggerTreshold"].Float()),
configAxisDeadZone(settings["input"]["controllerAxisDeadZone"].Float()),
configAxisFullZone(settings["input"]["controllerAxisFullZone"].Float()),
configPointerSpeed(settings["input"]["controllerPointerSpeed"].Float()),
configPointerScale(settings["input"]["controllerPointerScale"].Float()),
configPanningSpeed(settings["input"]["controllerPanningSpeed"].Float()),
configPanningScale(settings["input"]["controllerPanningScale"].Float()),
cursorAxisValueX(0),
cursorAxisValueY(0),
cursorPlanDisX(0.0),
@ -45,7 +38,14 @@ InputSourceGameController::InputSourceGameController():
scrollAxisValueX(0),
scrollAxisValueY(0),
scrollPlanDisX(0.0),
scrollPlanDisY(0.0)
scrollPlanDisY(0.0),
configTriggerTreshold(settings["input"]["controllerTriggerTreshold"].Float()),
configAxisDeadZone(settings["input"]["controllerAxisDeadZone"].Float()),
configAxisFullZone(settings["input"]["controllerAxisFullZone"].Float()),
configPointerSpeed(settings["input"]["controllerPointerSpeed"].Float()),
configPointerScale(settings["input"]["controllerPointerScale"].Float()),
configPanningSpeed(settings["input"]["controllerPanningSpeed"].Float()),
configPanningScale(settings["input"]["controllerPanningScale"].Float())
{
tryOpenAllGameControllers();
}
@ -129,7 +129,7 @@ void InputSourceGameController::handleEventDeviceRemapped(const SDL_ControllerDe
openGameController(device.which);
}
double InputSourceGameController::getRealAxisValue(int value)
double InputSourceGameController::getRealAxisValue(int value) const
{
double ratio = static_cast<double>(value) / SDL_JOYSTICK_AXIS_MAX;
double greenZone = configAxisFullZone - configAxisDeadZone;
@ -323,7 +323,7 @@ void InputSourceGameController::handleScrollUpdate(int32_t deltaTimeMs)
}
}
bool InputSourceGameController::isScrollAxisReleased()
bool InputSourceGameController::isScrollAxisReleased() const
{
return scrollAxisValueX == 0 && scrollAxisValueY == 0;
return vstd::isAlmostZero(scrollAxisValueX) && vstd::isAlmostZero(scrollAxisValueY);
}

View File

@ -49,14 +49,14 @@ class InputSourceGameController
void openGameController(int index);
int getJoystickIndex(SDL_GameController * controller);
double getRealAxisValue(int value);
double getRealAxisValue(int value) const;
void dispatchAxisShortcuts(const std::vector<EShortcut> & shortcutsVector, SDL_GameControllerAxis axisID, int axisValue);
void tryToConvertCursor();
void doCursorMove(int deltaX, int deltaY);
int getMoveDis(float planDis);
void handleCursorUpdate(int32_t deltaTimeMs);
void handleScrollUpdate(int32_t deltaTimeMs);
bool isScrollAxisReleased();
bool isScrollAxisReleased() const;
public:
InputSourceGameController();

View File

@ -62,7 +62,7 @@ GlobalLobbyRoomModCard::GlobalLobbyRoomModCard(const GlobalLobbyRoomModInfo & mo
labelStatus = std::make_shared<CLabel>(5, 30, FONT_SMALL, ETextAlignment::CENTERLEFT, Colors::YELLOW, CGI->generaltexth->translate("vcmi.lobby.mod.state." + statusToString.at(modInfo.status)));
}
static const std::string getJoinRoomErrorMessage(const GlobalLobbyRoom & roomDescription, const std::vector<GlobalLobbyRoomModInfo> & modVerificationList)
static std::string getJoinRoomErrorMessage(const GlobalLobbyRoom & roomDescription, const std::vector<GlobalLobbyRoomModInfo> & modVerificationList)
{
bool publicRoom = roomDescription.statusID == "public";
bool privateRoom = roomDescription.statusID == "private";
@ -106,8 +106,8 @@ static const std::string getJoinRoomErrorMessage(const GlobalLobbyRoom & roomDes
GlobalLobbyRoomWindow::GlobalLobbyRoomWindow(GlobalLobbyWindow * window, const std::string & roomUUID)
: CWindowObject(BORDERED)
, roomUUID(roomUUID)
, window(window)
, roomUUID(roomUUID)
{
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;

View File

@ -49,14 +49,15 @@ void CreatureCostBox::createItems(TResources res)
{
int curx = pos.w / 2;
int spacing = 48;
int resourcesCount = static_cast<int>(resources.size());
if (resources.size() > 2)
{
spacing = 32;
curx -= (15 + 16 * ((int)resources.size() - 1));
curx -= (15 + 16 * (resourcesCount - 1));
}
else
{
curx -= ((16 * (int)resources.size()) + (8 * ((int)resources.size() - 1)));
curx -= ((16 * resourcesCount) + (8 * (resourcesCount - 1)));
}
//reverse to display gold as first resource
for(auto & currentRes : boost::adaptors::reverse(resources))

View File

@ -33,7 +33,7 @@ public:
class DLL_LINKAGE CGDwelling : public CArmedInstance
{
public:
typedef std::vector<std::pair<ui32, std::vector<CreatureID> > > TCreaturesSet;
using TCreaturesSet = std::vector<std::pair<ui32, std::vector<CreatureID> > >;
std::optional<CGDwellingRandomizationInfo> randomizationInfo; //random dwelling options; not serialized
TCreaturesSet creatures; //creatures[level] -> <vector of alternative ids (base creature and upgrades, creatures amount>

View File

@ -49,17 +49,17 @@ void ObstacleSet::removeEmptyTemplates()
ObstacleSetFilter::ObstacleSetFilter(std::vector<ObstacleSet::EObstacleType> allowedTypes, TerrainId terrain = TerrainId::ANY_TERRAIN, FactionID faction = FactionID::ANY, EAlignment alignment = EAlignment::ANY):
allowedTypes(allowedTypes),
terrain(terrain),
faction(faction),
alignment(alignment)
alignment(alignment),
terrain(terrain)
{
}
ObstacleSetFilter::ObstacleSetFilter(ObstacleSet::EObstacleType allowedType, TerrainId terrain = TerrainId::ANY_TERRAIN, FactionID faction = FactionID::ANY, EAlignment alignment = EAlignment::ANY):
allowedTypes({allowedType}),
terrain(terrain),
faction(faction),
alignment(alignment)
alignment(alignment),
terrain(terrain)
{
}
@ -142,9 +142,9 @@ ObstacleSet::EObstacleType ObstacleSet::getType() const
return type;
}
void ObstacleSet::setType(EObstacleType type)
void ObstacleSet::setType(EObstacleType newType)
{
this->type = type;
type = newType;
}
std::vector<std::shared_ptr<const ObjectTemplate>> ObstacleSet::getObstacles() const
@ -258,7 +258,7 @@ void ObstacleSetFilter::setType(ObstacleSet::EObstacleType type)
allowedTypes = {type};
}
void ObstacleSetFilter::setTypes(std::vector<ObstacleSet::EObstacleType> types)
void ObstacleSetFilter::setTypes(const std::vector<ObstacleSet::EObstacleType> & types)
{
this->allowedTypes = types;
}
@ -424,10 +424,9 @@ void ObstacleSetHandler::addObstacleSet(std::shared_ptr<ObstacleSet> os)
void ObstacleSetHandler::afterLoadFinalization()
{
for (auto &os :biomes)
{
for(const auto & os : biomes)
os->removeEmptyTemplates();
}
vstd::erase_if(biomes, [](const std::shared_ptr<ObstacleSet> &os)
{
if (os->getObstacles().empty())
@ -439,10 +438,8 @@ void ObstacleSetHandler::afterLoadFinalization()
});
// Populate map
for (auto &os : biomes)
{
for(const auto & os : biomes)
obstacleSets[os->getType()].push_back(os);
}
}
TObstacleTypes ObstacleSetHandler::getObstacles( const ObstacleSetFilter &filter) const

View File

@ -70,7 +70,7 @@ private:
std::vector<std::shared_ptr<const ObjectTemplate>> obstacles;
};
typedef std::vector<std::shared_ptr<ObstacleSet>> TObstacleTypes;
using TObstacleTypes = std::vector<std::shared_ptr<ObstacleSet>>;
class DLL_LINKAGE ObstacleSetFilter
{
@ -81,7 +81,7 @@ public:
bool filter(const ObstacleSet &set) const;
void setType(ObstacleSet::EObstacleType type);
void setTypes(std::vector<ObstacleSet::EObstacleType> types);
void setTypes(const std::vector<ObstacleSet::EObstacleType> & types);
std::vector<ObstacleSet::EObstacleType> getAllowedTypes() const;
TerrainId getTerrain() const;
@ -104,8 +104,8 @@ public:
~ObstacleSetHandler() = default;
std::vector<JsonNode> loadLegacyData() override;
virtual void loadObject(std::string scope, std::string name, const JsonNode & data) override;
virtual void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override;
void loadObject(std::string scope, std::string name, const JsonNode & data) override;
void loadObject(std::string scope, std::string name, const JsonNode & data, size_t index) override;
std::shared_ptr<ObstacleSet> loadFromJson(const std::string & scope, const JsonNode & json, const std::string & name, size_t index);
ObstacleSet::EObstacleType convertObstacleClass(MapObjectID id);
@ -130,4 +130,4 @@ private:
std::map<ObstacleSet::EObstacleType, std::vector<std::shared_ptr<ObstacleSet>>> obstacleSets;
};
VCMI_LIB_NAMESPACE_END
VCMI_LIB_NAMESPACE_END

View File

@ -24,7 +24,7 @@ public:
messageMissingMods = _ss.str();
}
ModIncompatibility(const ModList & _missingMods, ModList & _excessiveMods)
ModIncompatibility(const ModList & _missingMods, const ModList & _excessiveMods)
: ModIncompatibility(_missingMods)
{
std::ostringstream _ss;