From 8f3cb045cb5f5923b45f8a3221acee1bfa4aee3d Mon Sep 17 00:00:00 2001 From: schell244 Date: Tue, 25 Feb 2025 03:15:14 +0100 Subject: [PATCH] Fix some compiler warnings and explicitly set C++14 as the standard (#2929) --- CMakeLists.txt | 6 +++++- cmake/platform/unix/settings.cmake | 1 - src/game/Anticheat/WardenAnticheat/WardenScanMgr.cpp | 5 ++++- src/game/GMTicketMgr.cpp | 2 +- src/game/Guild/Guild.cpp | 2 +- src/game/Objects/Player.cpp | 2 +- src/game/PlayerBots/PlayerBotMgr.cpp | 2 +- src/game/PlayerBots/PlayerBotMgr.h | 4 ++-- src/game/Spells/SpellEffects.cpp | 8 ++++---- src/game/Transports/Transport.cpp | 8 ++++---- src/game/Transports/TransportMgr.cpp | 8 ++++---- .../ruins_of_ahnqiraj/instance_ruins_of_ahnqiraj.cpp | 5 ++++- 12 files changed, 31 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index b19b6327e..765df0ca1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,10 @@ cmake_minimum_required(VERSION 3.1...3.20) project(MaNGOS) +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + # Allow -DACE_ROOT, -DTBB_ROOT, etc. if(${CMAKE_VERSION} VERSION_GREATER "3.11") cmake_policy(SET CMP0074 NEW) @@ -62,7 +66,7 @@ if(PREFIX) get_filename_component(PREFIX_ABSOLUTE ${PREFIX} ABSOLUTE) set(CMAKE_INSTALL_PREFIX ${PREFIX} CACHE PATH "Install path prefix." FORCE) else() - set(PREFIX ${CMAKE_INSTALL_PREFIX} CACHE PATH "Install path prefix.") + set(CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE PATH "Install path prefix.") endif() # If win32 put it in the bin dir not lib diff --git a/cmake/platform/unix/settings.cmake b/cmake/platform/unix/settings.cmake index 1fc9908ef..90a3649fc 100644 --- a/cmake/platform/unix/settings.cmake +++ b/cmake/platform/unix/settings.cmake @@ -16,7 +16,6 @@ set(BUILD_ADDITIONAL_FLAGS "${BUILD_ADDITIONAL_FLAGS} --no-warnings -fexceptions if(BUILD_FOR_HOST_CPU) set(BUILD_ADDITIONAL_FLAGS "${BUILD_ADDITIONAL_FLAGS} -march=native") endif() -set(CMAKE_CXX_STANDARD 14) if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") if(PROFILE_GENERATE) set(BUILD_ADDITIONAL_FLAGS "${BUILD_ADDITIONAL_FLAGS} -fprofile-generate") diff --git a/src/game/Anticheat/WardenAnticheat/WardenScanMgr.cpp b/src/game/Anticheat/WardenAnticheat/WardenScanMgr.cpp index 30bbad63d..a28d52fbf 100644 --- a/src/game/Anticheat/WardenAnticheat/WardenScanMgr.cpp +++ b/src/game/Anticheat/WardenAnticheat/WardenScanMgr.cpp @@ -31,6 +31,7 @@ #include #include +#include INSTANTIATE_SINGLETON_1(WardenScanMgr); @@ -318,7 +319,9 @@ std::vector> WardenScanMgr::GetRandomScans(ScanFlags } // randomize the order of matching scans - std::random_shuffle(matches.begin(), matches.end()); + std::random_device rd; + std::mt19937 g(rd()); + std::shuffle(matches.begin(), matches.end(), g); // determine how many of the identified scans we can fit into the client's request and response buffers size_t request = 0, reply = 0; diff --git a/src/game/GMTicketMgr.cpp b/src/game/GMTicketMgr.cpp index 55bbadfa0..40c9c02b4 100644 --- a/src/game/GMTicketMgr.cpp +++ b/src/game/GMTicketMgr.cpp @@ -30,7 +30,7 @@ #include "Player.h" #include "ObjectMgr.h" -inline float GetAge(uint64 t) { return float(time(nullptr) - t) / DAY; } +inline float GetAge(uint64 t) { return float(time(nullptr) - t) / float(DAY); } /////////////////////////////////////////////////////////////////////////////////////////////////// // GM ticket diff --git a/src/game/Guild/Guild.cpp b/src/game/Guild/Guild.cpp index 71659f604..e128f11e7 100644 --- a/src/game/Guild/Guild.cpp +++ b/src/game/Guild/Guild.cpp @@ -826,7 +826,7 @@ void Guild::Roster(WorldSession* session /*= nullptr*/) data << uint8(itr.second.Level); data << uint8(itr.second.Class); data << uint32(itr.second.ZoneId); - data << float(float(time(nullptr) - itr.second.LogoutTime) / DAY); + data << float(float(time(nullptr) - itr.second.LogoutTime) / uint64(DAY)); data << itr.second.Pnote; data << ((session && HasRankRight(session->GetPlayer()->GetRank(), GR_RIGHT_VIEWOFFNOTE)) ? itr.second.OFFnote : ""); } diff --git a/src/game/Objects/Player.cpp b/src/game/Objects/Player.cpp index 4969bb907..aa968a53e 100644 --- a/src/game/Objects/Player.cpp +++ b/src/game/Objects/Player.cpp @@ -14929,7 +14929,7 @@ bool Player::LoadFromDB(ObjectGuid guid, SqlQueryHolder* holder) if (timeDiff > 15 * MINUTE) soberFactor = 0; else - soberFactor = 1 - timeDiff / (15.0f * MINUTE); + soberFactor = 1.0f - float(timeDiff) / (15.0f * float(MINUTE)); uint16 newDrunkenValue = uint16(soberFactor * m_drunk); SetDrunkValue(newDrunkenValue); diff --git a/src/game/PlayerBots/PlayerBotMgr.cpp b/src/game/PlayerBots/PlayerBotMgr.cpp index 7399f2287..f262f9fac 100644 --- a/src/game/PlayerBots/PlayerBotMgr.cpp +++ b/src/game/PlayerBots/PlayerBotMgr.cpp @@ -507,7 +507,7 @@ bool PlayerBotMgr::DeleteBot(uint32 playerGUID) return DeleteBot(iter); } -bool PlayerBotMgr::DeleteBot(std::map>::iterator iter) +bool PlayerBotMgr::DeleteBot(std::map>::iterator iter) { if (iter->second->state == PB_STATE_LOADING) m_stats.loadingCount--; diff --git a/src/game/PlayerBots/PlayerBotMgr.h b/src/game/PlayerBots/PlayerBotMgr.h index f7b753204..a1067512a 100644 --- a/src/game/PlayerBots/PlayerBotMgr.h +++ b/src/game/PlayerBots/PlayerBotMgr.h @@ -81,7 +81,7 @@ class PlayerBotMgr bool AddBot(PlayerBotAI* ai); bool AddBot(uint32 playerGuid, bool chatBot = false, PlayerBotAI* pAI = nullptr); - bool DeleteBot(std::map>::iterator iter); + bool DeleteBot(std::map>::iterator iter); bool DeleteBot(uint32 playerGuid); bool AddRandomBot(); @@ -116,7 +116,7 @@ class PlayerBotMgr uint32 m_maxAccountId; time_t m_lastBattleBotQueueUpdate; - std::map> m_bots; + std::map> m_bots; std::map m_tempBots; PlayerBotStats m_stats; diff --git a/src/game/Spells/SpellEffects.cpp b/src/game/Spells/SpellEffects.cpp index fd40421a6..8b6ebbbeb 100644 --- a/src/game/Spells/SpellEffects.cpp +++ b/src/game/Spells/SpellEffects.cpp @@ -961,7 +961,7 @@ void Spell::EffectDummy(SpellEffectIndex effIdx) switch (m_triggeredByAuraSpell->Id) { case 26467: // Persistent Shield - m_caster->CastCustomSpell(unitTarget, 26470, damage, {}, {}, true); + m_caster->CastCustomSpell(unitTarget, 26470, (int32)damage, {}, {}, true); break; default: sLog.Out(LOG_BASIC, LOG_LVL_ERROR, "EffectDummy: Non-handled case for spell 13567 for triggered aura %u", m_triggeredByAuraSpell->Id); @@ -1120,7 +1120,7 @@ void Spell::EffectDummy(SpellEffectIndex effIdx) damage = dither(damage * (pPlayer->GetInt32Value(UNIT_FIELD_ATTACK_POWER)) / 100); if (damage > 0) - pPlayer->CastCustomSpell(pPlayer, 23234, damage, {}, {}, true, nullptr); + pPlayer->CastCustomSpell(pPlayer, 23234, (int32)(damage), {}, {}, true, nullptr); return; } case 20577: // Cannibalize @@ -1921,7 +1921,7 @@ void Spell::EffectDummy(SpellEffectIndex effIdx) // found spelldamage coefficients of 0.381% per 0.1 speed and 15.244 per 4.0 speed // but own calculation say 0.385 gives at most one point difference to published values float spellDamage = m_caster->SpellBaseDamageBonusDone(m_spellInfo->GetSpellSchoolMask()); - float weaponSpeed = (1.0f / IN_MILLISECONDS) * m_CastItem->GetProto()->Delay; + float weaponSpeed = (1.0f / float(IN_MILLISECONDS)) * m_CastItem->GetProto()->Delay; float totalDamage = (damage + 3.85f * spellDamage) * 0.01f * weaponSpeed; m_caster->CastCustomSpell(unitTarget, 10444, dither(totalDamage), {}, {}, true, m_CastItem); @@ -3225,7 +3225,7 @@ void Spell::EffectDistract(SpellEffectIndex effIdx) unitTarget->ClearUnitState(UNIT_STATE_MOVING); if (unitTarget->GetTypeId() == TYPEID_UNIT) - unitTarget->GetMotionMaster()->MoveDistract(damage * IN_MILLISECONDS); + unitTarget->GetMotionMaster()->MoveDistract(damage * (uint32)IN_MILLISECONDS); AddExecuteLogInfo(effIdx, ExecuteLogInfo(unitTarget->GetObjectGuid())); } diff --git a/src/game/Transports/Transport.cpp b/src/game/Transports/Transport.cpp index e96f07c50..582d067f4 100644 --- a/src/game/Transports/Transport.cpp +++ b/src/game/Transports/Transport.cpp @@ -346,11 +346,11 @@ float Transport::CalculateSegmentPos(float now) KeyFrame const& frame = *m_currentFrame; float const speed = float(m_goInfo->moTransport.moveSpeed); float const accel = float(m_goInfo->moTransport.accelRate); - float timeSinceStop = frame.TimeFrom + (now - (1.0f / IN_MILLISECONDS) * frame.DepartureTime); - float timeUntilStop = frame.TimeTo - (now - (1.0f / IN_MILLISECONDS) * frame.DepartureTime); + float const timeSinceStop = frame.TimeFrom + (now - (1.0f / float(IN_MILLISECONDS)) * float(frame.DepartureTime)); + float const timeUntilStop = frame.TimeTo - (now - (1.0f / float(IN_MILLISECONDS)) * float(frame.DepartureTime)); float segmentPos, dist; - float accelTime = m_transportTemplate.accelTime; - float accelDist = m_transportTemplate.accelDist; + float const accelTime = m_transportTemplate.accelTime; + float const accelDist = m_transportTemplate.accelDist; // calculate from nearest stop, less confusing calculation... if (timeSinceStop < timeUntilStop) { diff --git a/src/game/Transports/TransportMgr.cpp b/src/game/Transports/TransportMgr.cpp index b3062968f..9516a92cb 100644 --- a/src/game/Transports/TransportMgr.cpp +++ b/src/game/Transports/TransportMgr.cpp @@ -271,7 +271,7 @@ bool TransportMgr::GenerateWaypoints(GameObjectInfo const* goinfo, TransportTemp if (keyFrames[0].IsStopFrame()) { curPathTime = float(keyFrames[0].Node->delay); - keyFrames[0].DepartureTime = uint32(curPathTime * IN_MILLISECONDS); + keyFrames[0].DepartureTime = uint32(curPathTime * (uint32)IN_MILLISECONDS); } for (size_t i = 1; i < keyFrames.size(); ++i) @@ -279,15 +279,15 @@ bool TransportMgr::GenerateWaypoints(GameObjectInfo const* goinfo, TransportTemp curPathTime += keyFrames[i - 1].TimeTo; if (keyFrames[i].IsStopFrame()) { - keyFrames[i].ArriveTime = uint32(curPathTime * IN_MILLISECONDS); + keyFrames[i].ArriveTime = uint32(curPathTime * (uint32)IN_MILLISECONDS); keyFrames[i - 1].NextArriveTime = keyFrames[i].ArriveTime; curPathTime += float(keyFrames[i].Node->delay); - keyFrames[i].DepartureTime = uint32(curPathTime * IN_MILLISECONDS); + keyFrames[i].DepartureTime = uint32(curPathTime * (uint32)IN_MILLISECONDS); } else { curPathTime -= keyFrames[i].TimeTo; - keyFrames[i].ArriveTime = uint32(curPathTime * IN_MILLISECONDS); + keyFrames[i].ArriveTime = uint32(curPathTime * (uint32)IN_MILLISECONDS); keyFrames[i - 1].NextArriveTime = keyFrames[i].ArriveTime; keyFrames[i].DepartureTime = keyFrames[i].ArriveTime; } diff --git a/src/scripts/kalimdor/silithus/ruins_of_ahnqiraj/instance_ruins_of_ahnqiraj.cpp b/src/scripts/kalimdor/silithus/ruins_of_ahnqiraj/instance_ruins_of_ahnqiraj.cpp index 50ed79fe1..35be104e9 100644 --- a/src/scripts/kalimdor/silithus/ruins_of_ahnqiraj/instance_ruins_of_ahnqiraj.cpp +++ b/src/scripts/kalimdor/silithus/ruins_of_ahnqiraj/instance_ruins_of_ahnqiraj.cpp @@ -25,6 +25,7 @@ EndScriptData */ #include "Group.h" #include "CreatureGroups.h" #include "ruins_of_ahnqiraj.h" +#include instance_ruins_of_ahnqiraj::instance_ruins_of_ahnqiraj(Map* pMap) : ScriptedInstance(pMap) { @@ -716,7 +717,9 @@ void instance_ruins_of_ahnqiraj::SpawnNewCrystals(ObjectGuid usedCrystal) possibleIndexes.push_back(i); } - std::random_shuffle(possibleIndexes.begin(), possibleIndexes.end()); + std::random_device rd; + std::mt19937 g(rd()); + std::shuffle(possibleIndexes.begin(), possibleIndexes.end(), g); while (crystalIndexes.size() < OSSIRIAN_CRYSTAL_NUM_ACTIVE) {