diff --git a/source/core/resources/resource_pack.cpp b/source/core/resources/resource_pack.cpp index ef981fc..1ec55f4 100644 --- a/source/core/resources/resource_pack.cpp +++ b/source/core/resources/resource_pack.cpp @@ -4,6 +4,7 @@ #include #include #include +#include #include "utils/log.hpp" @@ -19,12 +20,7 @@ namespace Resource { auto Pack::calculateChecksum(const std::vector& data) -> std::uint32_t { // djb2: seed 0x12345678. Compatible amb aee/projecte_2026 per si mai // reutilitzem eines de diagnòstic entre projectes. - std::uint32_t checksum = 0x12345678; - for (unsigned char b : data) { - // cppcheck-suppress useStlAlgorithm - checksum = ((checksum << 5) + checksum) + b; - } - return checksum; + return std::accumulate(data.begin(), data.end(), std::uint32_t{0x12345678}, [](std::uint32_t acc, unsigned char b) { return ((acc << 5) + acc) + b; }); } void Pack::xorInPlace(std::vector& data, const std::string& key) { @@ -151,7 +147,7 @@ namespace Resource { return false; } - // cppcheck-suppress useStlAlgorithm + // cppcheck-suppress useStlAlgorithm -- bucle amb early-return en error (addFile fallit) + filtre amb continue: no es pot expressar net amb std::ranges::all_of perquè la lògica combina filtratge i acumulació amb sortida prematura. for (const auto& entry : std::filesystem::recursive_directory_iterator(directory)) { if (!entry.is_regular_file()) { continue; } diff --git a/source/game/entities/animation_component.cpp b/source/game/entities/animation_component.cpp index 2071595..3ac6b25 100644 --- a/source/game/entities/animation_component.cpp +++ b/source/game/entities/animation_component.cpp @@ -1,6 +1,8 @@ #include "game/entities/animation_component.hpp" +#include #include +#include #include #include @@ -33,8 +35,7 @@ namespace { if (speeds.empty()) { return std::vector(frame_count, K_DEFAULT_FRAME_SECONDS); } - // cppcheck-suppress useStlAlgorithm - for (auto& s : speeds) { s = sanitizeSpeed(s); } + std::ranges::transform(speeds, speeds.begin(), sanitizeSpeed); if (speeds.size() == frame_count) { return speeds; } if (speeds.size() > frame_count) { speeds.resize(frame_count); @@ -50,10 +51,7 @@ namespace { // component vàlid. auto parseFrames(const fkyaml::node& anim) -> std::vector { std::vector frames; - for (const auto& f : anim["frames"]) { - // cppcheck-suppress useStlAlgorithm - frames.push_back(f.get_value()); - } + std::ranges::transform(anim["frames"], std::back_inserter(frames), [](const fkyaml::node& f) { return f.template get_value(); }); if (frames.empty()) { frames.push_back(0); } return frames; } @@ -66,10 +64,7 @@ namespace { std::vector speeds_secs; const auto& fm = anim["frame_ms"]; if (fm.is_sequence()) { - for (const auto& v : fm) { - // cppcheck-suppress useStlAlgorithm - speeds_secs.push_back(static_cast(v.get_value()) / 1000.0F); - } + std::ranges::transform(fm, std::back_inserter(speeds_secs), [](const fkyaml::node& v) { return static_cast(v.template get_value()) / 1000.0F; }); } else { const float SECS = static_cast(fm.get_value()) / 1000.0F; speeds_secs.assign(frame_count, SECS); diff --git a/source/game/entities/concrete/whip_attack.cpp b/source/game/entities/concrete/whip_attack.cpp index e39ecc1..176adfd 100644 --- a/source/game/entities/concrete/whip_attack.cpp +++ b/source/game/entities/concrete/whip_attack.cpp @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -41,10 +42,7 @@ namespace { if (!yaml.contains("animations") || !yaml["animations"].contains("swing")) { return; } const auto& sw = yaml["animations"]["swing"]; if (!sw.contains("active_frames")) { return; } - for (const auto& f : sw["active_frames"]) { - // cppcheck-suppress useStlAlgorithm - active_out.push_back(f.get_value()); - } + std::ranges::transform(sw["active_frames"], std::back_inserter(active_out), [](const fkyaml::node& f) { return f.template get_value(); }); } } // namespace diff --git a/source/game/entities/entity_loader.cpp b/source/game/entities/entity_loader.cpp index 934ed25..3b89cd5 100644 --- a/source/game/entities/entity_loader.cpp +++ b/source/game/entities/entity_loader.cpp @@ -1,5 +1,7 @@ #include "game/entities/entity_loader.hpp" +#include +#include #include #include @@ -51,8 +53,7 @@ namespace EntityLoader { const auto& list = root["entities"]; if (!list.is_sequence()) { return spawns; } spawns.reserve(list.size()); - // cppcheck-suppress useStlAlgorithm - for (const auto& item : list) { spawns.push_back(item); } + std::ranges::copy(list, std::back_inserter(spawns)); return spawns; } diff --git a/source/game/entities/entity_manager.cpp b/source/game/entities/entity_manager.cpp index 403bdab..73789a3 100644 --- a/source/game/entities/entity_manager.cpp +++ b/source/game/entities/entity_manager.cpp @@ -87,7 +87,7 @@ auto EntityManager::add(std::unique_ptr entity) -> Entity* { entity->setEntityManager(this); Entity* raw = entity.get(); entities_.push_back(std::move(entity)); - // cppcheck-suppress returnDanglingLifetime + // cppcheck-suppress returnDanglingLifetime -- fals positiu: std::move transfereix ownership del unique_ptr al vector, però l'objecte apuntat per `raw` no es mou ni es destrueix. El punter continua vàlid mentre el vector el posseesca. return raw; } @@ -124,7 +124,7 @@ auto EntityManager::addSarcophagus(std::unique_ptr sarc) -> Sarcoph Sarcophagus* raw = sarc.get(); entities_.push_back(std::move(sarc)); ++total_sarcs_; - // cppcheck-suppress returnDanglingLifetime + // cppcheck-suppress returnDanglingLifetime -- fals positiu: std::move transfereix ownership al vector però l'objecte no es mou. `raw` continua vàlid (vegeu `add` més amunt). return raw; }