Skip to content

Commit

Permalink
fix: warning build ubuntu (opentibiabr#2490)
Browse files Browse the repository at this point in the history
  • Loading branch information
beats-dh authored May 14, 2024
1 parent e0e7ab0 commit 1d025c2
Show file tree
Hide file tree
Showing 76 changed files with 482 additions and 520 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,17 @@ endif()


# === IPO ===
option(OPTIONS_ENABLE_IPO "Check and Enable interprocedural optimization (IPO/LTO)" ON)
if(OPTIONS_ENABLE_IPO)
log_option_enabled("IPO/LTO")
if(MSVC)
log_option_enabled("IPO/LTO")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "${CMAKE_CXX_FLAGS_RELWITHDEBINFO} /GL")
set(CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_SHARED_LINKER_FLAGS_RELWITHDEBINFO} /LTCG")
set(CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_STATIC_LINKER_FLAGS_RELWITHDEBINFO} /LTCG")
set(CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_MODULE_LINKER_FLAGS_RELWITHDEBINFO} /LTCG")
set(CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO "${CMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO} /LTCG")
else()
if(CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo" OR CMAKE_BUILD_TYPE STREQUAL "Release")
log_option_enabled("IPO/LTO")
include(CheckIPOSupported)
check_ipo_supported(RESULT result OUTPUT output)
if(result)
Expand Down
4 changes: 3 additions & 1 deletion cmake/modules/BaseConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ if (MSVC)
endforeach(type)

add_compile_options(/MP /FS /Zf /EHsc)
endif (MSVC)
else()
add_compile_options(-Wno-unused-parameter -Wno-sign-compare -Wno-switch -Wno-implicit-fallthrough -Wno-extra)
endif()

## Link compilation files to build/bin folder, else link to the main dir
function(set_output_directory target_name)
Expand Down
2 changes: 1 addition & 1 deletion src/canary_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ void CanaryServer::loadModules() {
// If "USE_ANY_DATAPACK_FOLDER" is set to true then you can choose any datapack folder for your server
const auto useAnyDatapack = g_configManager().getBoolean(USE_ANY_DATAPACK_FOLDER, __FUNCTION__);
auto datapackName = g_configManager().getString(DATA_DIRECTORY, __FUNCTION__);
if (!useAnyDatapack && (datapackName != "data-canary" && datapackName != "data-otservbr-global" || datapackName != "data-otservbr-global" && datapackName != "data-canary")) {
if (!useAnyDatapack && datapackName != "data-canary" && datapackName != "data-otservbr-global") {
throw FailedToInitializeCanary(fmt::format(
"The datapack folder name '{}' is wrong, please select valid "
"datapack name 'data-canary' or 'data-otservbr-global "
Expand Down
2 changes: 1 addition & 1 deletion src/canary_server.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ class CanaryServer {
FAILED
};

RSA &rsa;
Logger &logger;
RSA &rsa;
ServiceManager &serviceManager;

std::atomic<LoaderStatus> loaderStatus = LoaderStatus::LOADING;
Expand Down
1 change: 0 additions & 1 deletion src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

#include "config/configmanager.hpp"
#include "lib/di/container.hpp"
#include "declarations.hpp"
#include "game/game.hpp"
#include "server/network/webhook/webhook.hpp"

Expand Down
9 changes: 4 additions & 5 deletions src/creatures/appearance/mounts/mounts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ bool Mounts::loadFromXml() {
continue;
}

mounts.emplace_back(std::make_shared<Mount>(
mounts.emplace(std::make_shared<Mount>(
static_cast<uint8_t>(pugi::cast<uint16_t>(mountNode.attribute("id").value())),
lookType,
mountNode.attribute("name").as_string(),
Expand All @@ -44,12 +44,11 @@ bool Mounts::loadFromXml() {
mountNode.attribute("type").as_string()
));
}
mounts.shrink_to_fit();
return true;
}

std::shared_ptr<Mount> Mounts::getMountByID(uint8_t id) {
auto it = std::find_if(mounts.begin(), mounts.end(), [id](const std::shared_ptr<Mount> mount) {
auto it = std::find_if(mounts.begin(), mounts.end(), [id](const std::shared_ptr<Mount> &mount) {
return mount->id == id; // Note the use of -> operator to access the members of the Mount object
});

Expand All @@ -58,15 +57,15 @@ std::shared_ptr<Mount> Mounts::getMountByID(uint8_t id) {

std::shared_ptr<Mount> Mounts::getMountByName(const std::string &name) {
auto mountName = name.c_str();
auto it = std::find_if(mounts.begin(), mounts.end(), [mountName](const std::shared_ptr<Mount> mount) {
auto it = std::find_if(mounts.begin(), mounts.end(), [mountName](const std::shared_ptr<Mount> &mount) {
return strcasecmp(mountName, mount->name.c_str()) == 0;
});

return it != mounts.end() ? *it : nullptr;
}

std::shared_ptr<Mount> Mounts::getMountByClientID(uint16_t clientId) {
auto it = std::find_if(mounts.begin(), mounts.end(), [clientId](const std::shared_ptr<Mount> mount) {
auto it = std::find_if(mounts.begin(), mounts.end(), [clientId](const std::shared_ptr<Mount> &mount) {
return mount->clientId == clientId; // Note the use of -> operator to access the members of the Mount object
});

Expand Down
8 changes: 4 additions & 4 deletions src/creatures/appearance/mounts/mounts.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

struct Mount {
Mount(uint8_t initId, uint16_t initClientId, std::string initName, int32_t initSpeed, bool initPremium, std::string initType) :
name(initName), speed(initSpeed), clientId(initClientId), id(initId), premium(initPremium),
type(initType) { }
name(std::move(initName)), speed(initSpeed), clientId(initClientId), id(initId), premium(initPremium),
type(std::move(initType)) { }

std::string name;
int32_t speed;
Expand All @@ -30,10 +30,10 @@ class Mounts {
std::shared_ptr<Mount> getMountByName(const std::string &name);
std::shared_ptr<Mount> getMountByClientID(uint16_t clientId);

[[nodiscard]] const std::vector<std::shared_ptr<Mount>> &getMounts() const {
[[nodiscard]] const phmap::parallel_flat_hash_set<std::shared_ptr<Mount>> &getMounts() const {
return mounts;
}

private:
std::vector<std::shared_ptr<Mount>> mounts;
phmap::parallel_flat_hash_set<std::shared_ptr<Mount>> mounts;
};
31 changes: 15 additions & 16 deletions src/creatures/appearance/outfit/outfit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
#include "utils/tools.hpp"
#include "game/game.hpp"

bool Outfits::reload() {
for (auto &outfitsVector : outfits) {
outfitsVector.clear();
}
return loadFromXml();
}

bool Outfits::loadFromXml() {
pugi::xml_document doc;
auto folder = g_configManager().getString(CORE_DIRECTORY, __FUNCTION__) + "/XML/outfits.xml";
Expand Down Expand Up @@ -68,10 +75,12 @@ bool Outfits::loadFromXml() {
}

std::shared_ptr<Outfit> Outfits::getOutfitByLookType(PlayerSex_t sex, uint16_t lookType) const {
for (const auto &outfit : outfits[sex]) {
if (outfit->lookType == lookType) {
return outfit;
}
auto it = std::ranges::find_if(outfits[sex], [&lookType](const auto &outfit) {
return outfit->lookType == lookType;
});

if (it != outfits[sex].end()) {
return *it;
}
return nullptr;
}
Expand All @@ -83,17 +92,7 @@ std::shared_ptr<Outfit> Outfits::getOutfitByLookType(PlayerSex_t sex, uint16_t l
* @return <b>const</b> pointer to the outfit or <b>nullptr</b> if it could not be found.
*/

std::shared_ptr<Outfit> Outfits::getOpositeSexOutfitByLookType(PlayerSex_t sex, uint16_t lookType) {
std::shared_ptr<Outfit> Outfits::getOpositeSexOutfitByLookType(PlayerSex_t sex, uint16_t lookType) const {
PlayerSex_t searchSex = (sex == PLAYERSEX_MALE) ? PLAYERSEX_FEMALE : PLAYERSEX_MALE;

for (uint16_t i = 0; i < outfits[sex].size(); i++) {
if (outfits[sex].at(i)->lookType == lookType) {
if (outfits[searchSex].size() > i) {
return outfits[searchSex].at(i);
} else { // looktype found but the oposite sex array doesn't have this index.
return nullptr;
}
}
}
return nullptr;
return getOutfitByLookType(searchSex, lookType);
}
13 changes: 11 additions & 2 deletions src/creatures/appearance/outfit/outfit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,17 @@
#include "declarations.hpp"
#include "lib/di/container.hpp"

struct OutfitEntry {
constexpr OutfitEntry(uint16_t initLookType, uint8_t initAddons) :
lookType(initLookType), addons(initAddons) { }

uint16_t lookType;
uint8_t addons;
};

struct Outfit {
Outfit(std::string initName, uint16_t initLookType, bool initPremium, bool initUnlocked, std::string initFrom) :
name(initName), lookType(initLookType), premium(initPremium), unlocked(initUnlocked), from(initFrom) { }
name(std::move(initName)), lookType(initLookType), premium(initPremium), unlocked(initUnlocked), from(std::move(initFrom)) { }

std::string name;
uint16_t lookType;
Expand All @@ -38,9 +46,10 @@ class Outfits {
return inject<Outfits>();
}

std::shared_ptr<Outfit> getOpositeSexOutfitByLookType(PlayerSex_t sex, uint16_t lookType);
std::shared_ptr<Outfit> getOpositeSexOutfitByLookType(PlayerSex_t sex, uint16_t lookType) const;

bool loadFromXml();
bool reload();

[[nodiscard]] std::shared_ptr<Outfit> getOutfitByLookType(PlayerSex_t sex, uint16_t lookType) const;
[[nodiscard]] const std::vector<std::shared_ptr<Outfit>> &getOutfits(PlayerSex_t sex) const {
Expand Down
24 changes: 12 additions & 12 deletions src/creatures/combat/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ bool Combat::isProtected(std::shared_ptr<Player> attacker, std::shared_ptr<Playe
return true;
}

if (!attacker->getVocation()->canCombat() || !target->getVocation()->canCombat() && (attacker->getVocationId() == VOCATION_NONE || target->getVocationId() == VOCATION_NONE)) {
if ((!attacker->getVocation()->canCombat() || !target->getVocation()->canCombat()) && (attacker->getVocationId() == VOCATION_NONE || target->getVocationId() == VOCATION_NONE)) {
return true;
}

Expand Down Expand Up @@ -707,7 +707,7 @@ bool Combat::checkFearConditionAffected(std::shared_ptr<Player> player) {
auto affectedCount = (party->getMemberCount() + 5) / 5;
g_logger().debug("[{}] Player is member of a party, {} members can be feared", __FUNCTION__, affectedCount);

for (const auto member : party->getMembers()) {
for (const auto &member : party->getMembers()) {
if (member->hasCondition(CONDITION_FEARED)) {
affectedCount -= 1;
}
Expand Down Expand Up @@ -759,7 +759,7 @@ void Combat::CombatConditionFunc(std::shared_ptr<Creature> caster, std::shared_p
}
}

if (caster == target || target && !target->isImmune(condition->getType())) {
if (caster == target || (target && !target->isImmune(condition->getType()))) {
auto conditionCopy = condition->clone();
if (caster) {
conditionCopy->setParam(CONDITION_PARAM_OWNER, caster->getID());
Expand Down Expand Up @@ -1030,10 +1030,10 @@ bool Combat::doCombatChain(std::shared_ptr<Creature> caster, std::shared_ptr<Cre
uint8_t chainDistance;
bool backtracking = false;
params.chainCallback->getChainValues(caster, maxTargets, chainDistance, backtracking);
auto targets = pickChainTargets(caster, params, chainDistance, maxTargets, backtracking, aggressive, target);
auto targets = pickChainTargets(caster, params, chainDistance, maxTargets, aggressive, backtracking, std::move(target));

g_logger().debug("[{}] Chain targets: {}", __FUNCTION__, targets.size());
if (targets.empty() || targets.size() == 1 && targets.begin()->second.empty()) {
if (targets.empty() || (targets.size() == 1 && targets.begin()->second.empty())) {
return false;
}

Expand Down Expand Up @@ -1122,7 +1122,7 @@ void Combat::CombatFunc(std::shared_ptr<Creature> caster, const Position &origin
uint32_t maxY = 0;

// calculate the max viewable range
for (std::shared_ptr<Tile> tile : tileList) {
for (const std::shared_ptr<Tile> &tile : tileList) {
const Position &tilePos = tile->getPosition();

uint32_t diff = Position::getDistanceX(tilePos, pos);
Expand All @@ -1140,7 +1140,7 @@ void Combat::CombatFunc(std::shared_ptr<Creature> caster, const Position &origin
const int32_t rangeY = maxY + MAP_MAX_VIEW_PORT_Y;

int affected = 0;
for (std::shared_ptr<Tile> tile : tileList) {
for (const std::shared_ptr<Tile> &tile : tileList) {
if (canDoCombat(caster, tile, params.aggressive) != RETURNVALUE_NOERROR) {
continue;
}
Expand Down Expand Up @@ -1195,7 +1195,7 @@ void Combat::CombatFunc(std::shared_ptr<Creature> caster, const Position &origin
uint8_t beamAffectedCurrent = 0;

tmpDamage.affected = affected;
for (std::shared_ptr<Tile> tile : tileList) {
for (const std::shared_ptr<Tile> &tile : tileList) {
if (canDoCombat(caster, tile, params.aggressive) != RETURNVALUE_NOERROR) {
continue;
}
Expand Down Expand Up @@ -1241,7 +1241,7 @@ void Combat::CombatFunc(std::shared_ptr<Creature> caster, const Position &origin
}

void Combat::doCombatHealth(std::shared_ptr<Creature> caster, std::shared_ptr<Creature> target, CombatDamage &damage, const CombatParams &params) {
doCombatHealth(caster, target, caster ? caster->getPosition() : Position(), damage, params);
doCombatHealth(caster, std::move(target), caster ? caster->getPosition() : Position(), damage, params);
}

void Combat::doCombatHealth(std::shared_ptr<Creature> caster, std::shared_ptr<Creature> target, const Position &origin, CombatDamage &damage, const CombatParams &params) {
Expand Down Expand Up @@ -1382,7 +1382,7 @@ void Combat::doCombatDispel(std::shared_ptr<Creature> caster, std::shared_ptr<Cr
}
}

void Combat::doCombatDefault(std::shared_ptr<Creature> caster, std::shared_ptr<Creature> target, const CombatParams &params) {
[[maybe_unused]] void Combat::doCombatDefault(std::shared_ptr<Creature> caster, std::shared_ptr<Creature> target, const CombatParams &params) {
doCombatDefault(caster, target, caster ? caster->getPosition() : Position(), params);
}

Expand Down Expand Up @@ -2076,7 +2076,7 @@ void AreaCombat::setupExtArea(const std::list<uint32_t> &list, uint32_t rows) {

void MagicField::onStepInField(const std::shared_ptr<Creature> &creature) {
// remove magic walls/wild growth
if (!isBlocking() && g_game().getWorldType() == WORLD_TYPE_NO_PVP && id == ITEM_MAGICWALL_SAFE || id == ITEM_WILDGROWTH_SAFE) {
if ((!isBlocking() && g_game().getWorldType() == WORLD_TYPE_NO_PVP && id == ITEM_MAGICWALL_SAFE) || id == ITEM_WILDGROWTH_SAFE) {
if (!creature->isInGhostMode()) {
g_game().internalRemoveItem(static_self_cast<Item>(), 1);
}
Expand All @@ -2091,7 +2091,7 @@ void MagicField::onStepInField(const std::shared_ptr<Creature> &creature) {
if (ownerId) {
bool harmfulField = true;
auto itemTile = getTile();
if (g_game().getWorldType() == WORLD_TYPE_NO_PVP || itemTile && itemTile->hasFlag(TILESTATE_NOPVPZONE)) {
if (g_game().getWorldType() == WORLD_TYPE_NO_PVP || (itemTile && itemTile->hasFlag(TILESTATE_NOPVPZONE))) {
auto ownerPlayer = g_game().getPlayerByGUID(ownerId);
if (ownerPlayer) {
harmfulField = false;
Expand Down
8 changes: 4 additions & 4 deletions src/creatures/combat/combat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class ChainCallback final : public CallBack {
private:
void onChainCombat(std::shared_ptr<Creature> creature, uint8_t &chainTargets, uint8_t &chainDistance, bool &backtracking);

uint8_t m_chainTargets = 0;
uint8_t m_chainDistance = 0;
uint8_t m_chainTargets = 0;
bool m_backtracking = false;
bool m_fromLua = false;
};
Expand Down Expand Up @@ -125,7 +125,7 @@ class MatrixArea {
data_[row] = new bool[cols];

for (uint32_t col = 0; col < cols; ++col) {
data_[row][col] = 0;
data_[row][col] = false;
}
}
}
Expand Down Expand Up @@ -324,7 +324,7 @@ class Combat {
}
void setPlayerCombatValues(formulaType_t formulaType, double mina, double minb, double maxa, double maxb);
void postCombatEffects(std::shared_ptr<Creature> caster, const Position &origin, const Position &pos) const {
postCombatEffects(caster, origin, pos, params);
postCombatEffects(std::move(caster), origin, pos, params);
}

void setOrigin(CombatOrigin origin) {
Expand Down Expand Up @@ -393,7 +393,7 @@ class Combat {
* @param damage The combat damage.
* @return The calculated level formula.
*/
int32_t getLevelFormula(std::shared_ptr<Player> player, const std::shared_ptr<Spell> wheelSpell, const CombatDamage &damage) const;
int32_t getLevelFormula(std::shared_ptr<Player> player, std::shared_ptr<Spell> wheelSpell, const CombatDamage &damage) const;
CombatDamage getCombatDamage(std::shared_ptr<Creature> creature, std::shared_ptr<Creature> target) const;

// configureable
Expand Down
16 changes: 7 additions & 9 deletions src/creatures/combat/condition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1472,7 +1472,7 @@ bool ConditionDamage::unserializeProp(ConditionAttr_t attr, PropStream &propStre
} else if (attr == CONDITIONATTR_OWNER) {
return propStream.skip(4);
} else if (attr == CONDITIONATTR_INTERVALDATA) {
IntervalInfo damageInfo;
IntervalInfo damageInfo {};
if (!propStream.read<IntervalInfo>(damageInfo)) {
return false;
}
Expand Down Expand Up @@ -1530,7 +1530,7 @@ bool ConditionDamage::addDamage(int32_t rounds, int32_t time, int32_t value) {

// rounds, time, damage
for (int32_t i = 0; i < rounds; ++i) {
IntervalInfo damageInfo;
IntervalInfo damageInfo {};
damageInfo.interval = time;
damageInfo.timeLeft = time;
damageInfo.value = value;
Expand Down Expand Up @@ -1803,13 +1803,9 @@ void ConditionDamage::generateDamageList(int32_t amount, int32_t start, std::lis
* ConditionFeared
*/
bool ConditionFeared::isStuck(std::shared_ptr<Creature> creature, Position pos) const {
for (Direction dir : m_directionsVector) {
if (canWalkTo(creature, pos, dir)) {
return false;
}
}

return true;
return std::ranges::all_of(m_directionsVector, [&](Direction dir) {
return !canWalkTo(creature, pos, dir);
});
}

bool ConditionFeared::getRandomDirection(std::shared_ptr<Creature> creature, Position pos) {
Expand Down Expand Up @@ -1995,6 +1991,8 @@ bool ConditionFeared::getFleePath(std::shared_ptr<Creature> creature, const Posi
futurePos.y -= wsize;
g_logger().debug("[{}] Trying to flee to NORTHWEST to {} [{}]", __FUNCTION__, futurePos.toString(), wsize);
break;
case DIRECTION_NONE:
break;
}

found = creature->getPathTo(futurePos, dirList, 0, 30);
Expand Down
Loading

0 comments on commit 1d025c2

Please sign in to comment.