neteja cppcheck (44 → 0) i aïllar impls de tercers
This commit is contained in:
@@ -2075,11 +2075,10 @@ auto MapEditor::deleteRoom() -> std::string { // NOLINT(readability-function-co
|
||||
|
||||
if (target == "0") {
|
||||
// Buscar la primera room que no sea esta
|
||||
for (const auto& r : Resource::Cache::get()->getRooms()) {
|
||||
if (r.name != deleted_name) {
|
||||
target = r.name;
|
||||
break;
|
||||
}
|
||||
const auto& ROOMS = Resource::Cache::get()->getRooms();
|
||||
auto it = std::ranges::find_if(ROOMS, [&](const auto& r) { return r.name != deleted_name; });
|
||||
if (it != ROOMS.end()) {
|
||||
target = it->name;
|
||||
}
|
||||
}
|
||||
if (target == "0") { return "Cannot delete: no other room to navigate to"; }
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#include "game/gameplay/room_format.hpp"
|
||||
|
||||
#include <algorithm> // Para std::ranges::copy, transform
|
||||
#include <exception> // Para exception
|
||||
#include <iostream> // Para cout, cerr
|
||||
#include <iterator> // Para std::back_inserter
|
||||
|
||||
#include "core/resources/resource_helper.hpp" // Para Resource::Helper
|
||||
#include "external/fkyaml_node.hpp" // Para fkyaml::node
|
||||
@@ -38,9 +40,7 @@ namespace {
|
||||
std::vector<int> row;
|
||||
row.reserve(Map::WIDTH);
|
||||
|
||||
for (const auto& tile_node : row_node) {
|
||||
row.push_back(tile_node.get_value<int>());
|
||||
}
|
||||
std::ranges::transform(row_node, std::back_inserter(row), [](const auto& tile_node) { return tile_node.template get_value<int>(); });
|
||||
|
||||
tilemap_2d.push_back(row);
|
||||
}
|
||||
@@ -81,9 +81,7 @@ auto RoomFormat::flattenTilemap(const std::vector<std::vector<int>>& tilemap_2d)
|
||||
tilemap_flat.reserve(static_cast<size_t>(Map::WIDTH) * static_cast<size_t>(Map::HEIGHT));
|
||||
|
||||
for (const auto& row : tilemap_2d) {
|
||||
for (int tile : row) {
|
||||
tilemap_flat.push_back(tile);
|
||||
}
|
||||
std::ranges::copy(row, std::back_inserter(tilemap_flat));
|
||||
}
|
||||
|
||||
return tilemap_flat;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#include "game/gameplay/zone_manager.hpp"
|
||||
|
||||
#include <algorithm> // Para std::ranges::find_if, transform
|
||||
#include <exception> // Para exception
|
||||
#include <iostream> // Para cerr, cout
|
||||
#include <iterator> // Para std::back_inserter
|
||||
#include <string> // Para string
|
||||
|
||||
#include "core/resources/resource_helper.hpp" // Para Resource::Helper::loadFile
|
||||
@@ -78,12 +80,8 @@ void ZoneManager::loadFromFile(const std::string& file_path) {
|
||||
}
|
||||
|
||||
auto ZoneManager::getZone(const std::string& name) const -> const Zone::Data* {
|
||||
for (const auto& zone : zones_) {
|
||||
if (zone.name == name) {
|
||||
return &zone;
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
auto it = std::ranges::find_if(zones_, [&](const auto& z) { return z.name == name; });
|
||||
return (it != zones_.end()) ? &(*it) : nullptr;
|
||||
}
|
||||
|
||||
auto ZoneManager::getDefaultZone() const -> const Zone::Data* {
|
||||
@@ -94,8 +92,6 @@ auto ZoneManager::getDefaultZone() const -> const Zone::Data* {
|
||||
auto ZoneManager::getZoneNames() const -> std::vector<std::string> {
|
||||
std::vector<std::string> names;
|
||||
names.reserve(zones_.size());
|
||||
for (const auto& zone : zones_) {
|
||||
names.push_back(zone.name);
|
||||
}
|
||||
std::ranges::transform(zones_, std::back_inserter(names), [](const auto& z) { return z.name; });
|
||||
return names;
|
||||
}
|
||||
|
||||
@@ -2,8 +2,9 @@
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <algorithm> // Para std::clamp
|
||||
#include <algorithm> // Para std::clamp, std::ranges::copy
|
||||
#include <array> // Para std::array
|
||||
#include <iterator> // Para std::back_inserter
|
||||
#include <random> // Para generador aleatorio
|
||||
|
||||
#include "core/audio/audio.hpp" // Para Audio
|
||||
@@ -245,9 +246,7 @@ void Logo::initColors() {
|
||||
10,
|
||||
12,
|
||||
15};
|
||||
for (const auto& color : COLORS) {
|
||||
color_.push_back(color);
|
||||
}
|
||||
std::ranges::copy(COLORS, std::back_inserter(color_));
|
||||
}
|
||||
|
||||
// Crea los sprites de cada linea
|
||||
|
||||
+10
-14
@@ -2,8 +2,10 @@
|
||||
|
||||
#include <SDL3/SDL.h>
|
||||
|
||||
#include <algorithm> // Para ranges::transform
|
||||
#include <algorithm> // Para ranges::transform, copy_if
|
||||
#include <cctype> // Para toupper
|
||||
#include <iterator> // Para std::back_inserter
|
||||
#include <numeric> // Para std::accumulate
|
||||
#include <sstream> // Para std::istringstream
|
||||
#include <string> // Para string
|
||||
#include <vector> // Para vector
|
||||
@@ -209,11 +211,10 @@ void Console::update(float delta_time) { // NOLINT(readability-function-cogniti
|
||||
|
||||
// Efecto typewriter: revelar letras una a una (solo cuando ACTIVE)
|
||||
if (status_ == Status::ACTIVE) {
|
||||
int total_chars = 0;
|
||||
for (const auto& line : msg_lines_) { total_chars += static_cast<int>(line.size()); }
|
||||
if (typewriter_chars_ < total_chars) {
|
||||
const int TOTAL_CHARS = std::accumulate(msg_lines_.begin(), msg_lines_.end(), 0, [](int acc, const auto& line) { return acc + static_cast<int>(line.size()); });
|
||||
if (typewriter_chars_ < TOTAL_CHARS) {
|
||||
typewriter_timer_ += delta_time;
|
||||
while (typewriter_timer_ >= TYPEWRITER_CHAR_DELAY && typewriter_chars_ < total_chars) {
|
||||
while (typewriter_timer_ >= TYPEWRITER_CHAR_DELAY && typewriter_chars_ < TOTAL_CHARS) {
|
||||
typewriter_timer_ -= TYPEWRITER_CHAR_DELAY;
|
||||
++typewriter_chars_;
|
||||
}
|
||||
@@ -394,11 +395,8 @@ void Console::handleEvent(const SDL_Event& event) { // NOLINT(readability-funct
|
||||
const size_t SPACE_POS = upper.rfind(' ');
|
||||
if (SPACE_POS == std::string::npos) {
|
||||
// Modo comando: ciclar keywords visibles que empiecen por el prefijo
|
||||
for (const auto& kw : registry_.getVisibleKeywords()) {
|
||||
if (upper.empty() || kw.starts_with(upper)) {
|
||||
tab_matches_.emplace_back(kw);
|
||||
}
|
||||
}
|
||||
const auto VISIBLE = registry_.getVisibleKeywords();
|
||||
std::ranges::copy_if(VISIBLE, std::back_inserter(tab_matches_), [&](const auto& kw) { return upper.empty() || kw.starts_with(upper); });
|
||||
} else {
|
||||
const std::string BASE_CMD = upper.substr(0, SPACE_POS);
|
||||
const std::string SUB_PREFIX = upper.substr(SPACE_POS + 1);
|
||||
@@ -417,7 +415,7 @@ void Console::handleEvent(const SDL_Event& event) { // NOLINT(readability-funct
|
||||
if (tab_matches_.empty()) { break; }
|
||||
tab_index_ = (tab_index_ + 1) % static_cast<int>(tab_matches_.size());
|
||||
std::string result = tab_matches_[static_cast<size_t>(tab_index_)];
|
||||
for (char& c : result) { c = static_cast<char>(std::tolower(static_cast<unsigned char>(c))); }
|
||||
std::ranges::transform(result, result.begin(), [](unsigned char c) { return static_cast<char>(std::tolower(c)); });
|
||||
input_line_ = result;
|
||||
break;
|
||||
}
|
||||
@@ -463,9 +461,7 @@ void Console::processCommand() {
|
||||
|
||||
// Typewriter: instantáneo si el comando lo requiere, letra a letra si no
|
||||
if (instant) {
|
||||
int total = 0;
|
||||
for (const auto& l : msg_lines_) { total += static_cast<int>(l.size()); }
|
||||
typewriter_chars_ = total;
|
||||
typewriter_chars_ = std::accumulate(msg_lines_.begin(), msg_lines_.end(), 0, [](int acc, const auto& l) { return acc + static_cast<int>(l.size()); });
|
||||
} else {
|
||||
typewriter_chars_ = 0;
|
||||
}
|
||||
|
||||
@@ -1054,9 +1054,8 @@ void CommandRegistry::registerHandlers() { // NOLINT(readability-function-cogni
|
||||
dynamic_providers_["PALETTE"] = []() -> std::vector<std::string> {
|
||||
std::vector<std::string> result = {"NEXT", "PREV", "SORT", "DEFAULT"};
|
||||
if (Screen::get() != nullptr) {
|
||||
for (const auto& name : Screen::get()->getPaletteNames()) {
|
||||
result.push_back(toUpper(name));
|
||||
}
|
||||
const auto NAMES = Screen::get()->getPaletteNames();
|
||||
std::ranges::transform(NAMES, std::back_inserter(result), [](const auto& name) { return toUpper(name); });
|
||||
}
|
||||
return result;
|
||||
};
|
||||
@@ -1065,10 +1064,11 @@ void CommandRegistry::registerHandlers() { // NOLINT(readability-function-cogni
|
||||
dynamic_providers_["SHADER PRESET"] = []() -> std::vector<std::string> {
|
||||
std::vector<std::string> result = {"NEXT", "PREV"};
|
||||
const bool IS_CRTPI = Options::video.shader.current_shader == Rendering::ShaderType::CRTPI;
|
||||
auto upper_name = [](const auto& p) { return toUpper(p.name); };
|
||||
if (IS_CRTPI) {
|
||||
for (const auto& p : Options::crtpi_presets) { result.push_back(toUpper(p.name)); }
|
||||
std::ranges::transform(Options::crtpi_presets, std::back_inserter(result), upper_name);
|
||||
} else {
|
||||
for (const auto& p : Options::postfx_presets) { result.push_back(toUpper(p.name)); }
|
||||
std::ranges::transform(Options::postfx_presets, std::back_inserter(result), upper_name);
|
||||
}
|
||||
return result;
|
||||
};
|
||||
@@ -1162,7 +1162,7 @@ void CommandRegistry::load(const std::string& yaml_path) { // NOLINT(readabilit
|
||||
if (cat_node.contains("scope")) {
|
||||
const auto& scope_node = cat_node["scope"];
|
||||
if (scope_node.is_sequence()) {
|
||||
for (const auto& s : scope_node) { cat_scopes.push_back(s.get_value<std::string>()); }
|
||||
std::ranges::transform(scope_node, std::back_inserter(cat_scopes), [](const auto& s) { return s.template get_value<std::string>(); });
|
||||
} else {
|
||||
cat_scopes.push_back(scope_node.get_value<std::string>());
|
||||
}
|
||||
@@ -1187,7 +1187,7 @@ void CommandRegistry::load(const std::string& yaml_path) { // NOLINT(readabilit
|
||||
if (cmd_node.contains("scope")) {
|
||||
const auto& scope_node = cmd_node["scope"];
|
||||
if (scope_node.is_sequence()) {
|
||||
for (const auto& s : scope_node) { def.scopes.push_back(s.get_value<std::string>()); }
|
||||
std::ranges::transform(scope_node, std::back_inserter(def.scopes), [](const auto& s) { return s.template get_value<std::string>(); });
|
||||
} else {
|
||||
def.scopes.push_back(scope_node.get_value<std::string>());
|
||||
}
|
||||
@@ -1203,9 +1203,8 @@ void CommandRegistry::load(const std::string& yaml_path) { // NOLINT(readabilit
|
||||
for (auto it = completions_node.begin(); it != completions_node.end(); ++it) {
|
||||
auto path = it.key().get_value<std::string>();
|
||||
std::vector<std::string> opts;
|
||||
for (const auto& opt : *it) {
|
||||
opts.push_back(opt.get_value<std::string>());
|
||||
}
|
||||
const auto& options_node = *it;
|
||||
std::ranges::transform(options_node, std::back_inserter(opts), [](const auto& opt) { return opt.template get_value<std::string>(); });
|
||||
def.completions[path] = std::move(opts);
|
||||
}
|
||||
}
|
||||
@@ -1224,9 +1223,8 @@ void CommandRegistry::load(const std::string& yaml_path) { // NOLINT(readabilit
|
||||
for (auto it = extras_completions.begin(); it != extras_completions.end(); ++it) {
|
||||
auto path = it.key().get_value<std::string>();
|
||||
std::vector<std::string> opts;
|
||||
for (const auto& opt : *it) {
|
||||
opts.push_back(opt.get_value<std::string>());
|
||||
}
|
||||
const auto& options_node = *it;
|
||||
std::ranges::transform(options_node, std::back_inserter(opts), [](const auto& opt) { return opt.template get_value<std::string>(); });
|
||||
def.completions[path] = std::move(opts);
|
||||
}
|
||||
}
|
||||
@@ -1285,9 +1283,8 @@ void CommandRegistry::load(const std::string& yaml_path) { // NOLINT(readabilit
|
||||
dynamic_providers_["HELP KEYS"] = []() -> std::vector<std::string> {
|
||||
std::vector<std::string> names;
|
||||
if (KeyConfig::get() != nullptr) {
|
||||
for (const auto& scope : KeyConfig::get()->getScopes()) {
|
||||
names.push_back(scope.name);
|
||||
}
|
||||
const auto& scopes = KeyConfig::get()->getScopes();
|
||||
std::ranges::transform(scopes, std::back_inserter(names), [](const auto& sc) { return sc.name; });
|
||||
}
|
||||
return names;
|
||||
};
|
||||
@@ -1321,10 +1318,8 @@ auto CommandRegistry::generateKeysHelp(const std::string& scope_filter) -> std::
|
||||
}
|
||||
|
||||
auto CommandRegistry::findCommand(const std::string& keyword) const -> const CommandDef* {
|
||||
for (const auto& cmd : commands_) {
|
||||
if (cmd.keyword == keyword) { return &cmd; }
|
||||
}
|
||||
return nullptr;
|
||||
auto it = std::ranges::find_if(commands_, [&](const auto& cmd) { return cmd.keyword == keyword; });
|
||||
return (it != commands_.end()) ? &(*it) : nullptr;
|
||||
}
|
||||
|
||||
auto CommandRegistry::execute(const std::string& keyword, const std::vector<std::string>& args) const -> std::string {
|
||||
|
||||
@@ -24,7 +24,7 @@ Notifier* Notifier::notifier = nullptr;
|
||||
|
||||
// Parte un texto en varias líneas cuando no cabe en max_width píxeles.
|
||||
// Divide por espacios; si una palabra sola excede el ancho, queda en su propia línea.
|
||||
static auto wrapToWidth(const std::string& text, int max_width, Text* text_obj, int kerning = 1) -> std::vector<std::string> {
|
||||
static auto wrapToWidth(const std::string& text, int max_width, const Text* text_obj, int kerning = 1) -> std::vector<std::string> {
|
||||
if (max_width <= 0 || text_obj->length(text, kerning) <= max_width) {
|
||||
return {text};
|
||||
}
|
||||
@@ -45,11 +45,11 @@ static auto wrapToWidth(const std::string& text, int max_width, Text* text_obj,
|
||||
word.clear();
|
||||
};
|
||||
|
||||
for (const char c : text) {
|
||||
if (c == ' ') {
|
||||
for (const char CH : text) {
|
||||
if (CH == ' ') {
|
||||
flush_word();
|
||||
} else {
|
||||
word += c;
|
||||
word += CH;
|
||||
}
|
||||
}
|
||||
flush_word();
|
||||
@@ -336,8 +336,8 @@ auto Notifier::getVisibleHeight() const -> int {
|
||||
int bottom = 0;
|
||||
for (const auto& n : notifications_) {
|
||||
if (n.state == Status::FINISHED) { continue; }
|
||||
int n_bottom = static_cast<int>(n.rect.y + n.rect.h) - y_offset_;
|
||||
if (n_bottom > bottom) { bottom = n_bottom; }
|
||||
const int N_BOTTOM = static_cast<int>(n.rect.y + n.rect.h) - y_offset_;
|
||||
bottom = std::max(N_BOTTOM, bottom);
|
||||
}
|
||||
return bottom;
|
||||
}
|
||||
@@ -346,8 +346,6 @@ auto Notifier::getVisibleHeight() const -> int {
|
||||
auto Notifier::getCodes() -> std::vector<std::string> {
|
||||
std::vector<std::string> codes;
|
||||
codes.reserve(notifications_.size());
|
||||
for (const auto& notification : notifications_) {
|
||||
codes.emplace_back(notification.code);
|
||||
}
|
||||
std::ranges::transform(notifications_, std::back_inserter(codes), [](const auto& n) { return n.code; });
|
||||
return codes;
|
||||
}
|
||||
Reference in New Issue
Block a user