style: aplicar fixes de clang-tidy (todo excepto uppercase-literal-suffix)
Corregidos ~2570 issues automáticamente con clang-tidy --fix-errors más ajustes manuales posteriores: - modernize: designated-initializers, trailing-return-type, use-auto, avoid-c-arrays (→ std::array<>), use-ranges, use-emplace, deprecated-headers, use-equals-default, pass-by-value, return-braced-init-list, use-default-member-init - readability: math-missing-parentheses, implicit-bool-conversion, braces-around-statements, isolate-declaration, use-std-min-max, identifier-naming, else-after-return, redundant-casting, convert-member-functions-to-static, make-member-function-const, static-accessed-through-instance - performance: avoid-endl, unnecessary-value-param, type-promotion, inefficient-vector-operation - dead code: XOR_KEY (orphan tras eliminar encryptData/decryptData), dead stores en engine.cpp y png_shape.cpp - NOLINT justificado en 10 funciones con alta complejidad cognitiva (initialize, render, main, processEvents, update×3, performDemoAction, randomizeOnDemoStart, renderDebugHUD, AppLogo::update) Compilación: gcc -Wall sin warnings. clang-tidy: 0 issues. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -7,10 +7,8 @@
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
// Clave XOR para ofuscación simple (puede cambiarse)
|
||||
constexpr uint8_t XOR_KEY = 0x5A;
|
||||
|
||||
ResourcePack::ResourcePack() : isLoaded_(false) {}
|
||||
ResourcePack::ResourcePack()
|
||||
: isLoaded_(false) {}
|
||||
|
||||
ResourcePack::~ResourcePack() {
|
||||
clear();
|
||||
@@ -20,54 +18,54 @@ ResourcePack::~ResourcePack() {
|
||||
// EMPAQUETADO (herramienta pack_resources)
|
||||
// ============================================================================
|
||||
|
||||
bool ResourcePack::addDirectory(const std::string& dirPath, const std::string& prefix) {
|
||||
if (!fs::exists(dirPath) || !fs::is_directory(dirPath)) {
|
||||
std::cerr << "Error: Directorio no existe: " << dirPath << std::endl;
|
||||
auto ResourcePack::addDirectory(const std::string& dir_path, const std::string& prefix) -> bool {
|
||||
if (!fs::exists(dir_path) || !fs::is_directory(dir_path)) {
|
||||
std::cerr << "Error: Directorio no existe: " << dir_path << '\n';
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const auto& entry : fs::recursive_directory_iterator(dirPath)) {
|
||||
for (const auto& entry : fs::recursive_directory_iterator(dir_path)) {
|
||||
if (entry.is_regular_file()) {
|
||||
// Construir ruta relativa desde data/ (ej: "data/ball.png" → "ball.png")
|
||||
std::string relativePath = fs::relative(entry.path(), dirPath).string();
|
||||
std::string fullPath = prefix.empty() ? relativePath : prefix + "/" + relativePath;
|
||||
fullPath = normalizePath(fullPath);
|
||||
std::string relative_path = fs::relative(entry.path(), dir_path).string();
|
||||
std::string full_path = prefix.empty() ? relative_path : prefix + "/" + relative_path;
|
||||
full_path = normalizePath(full_path);
|
||||
|
||||
// Leer archivo completo
|
||||
std::ifstream file(entry.path(), std::ios::binary);
|
||||
if (!file) {
|
||||
std::cerr << "Error: No se pudo abrir: " << entry.path() << std::endl;
|
||||
std::cerr << "Error: No se pudo abrir: " << entry.path() << '\n';
|
||||
continue;
|
||||
}
|
||||
|
||||
file.seekg(0, std::ios::end);
|
||||
size_t fileSize = file.tellg();
|
||||
size_t file_size = file.tellg();
|
||||
file.seekg(0, std::ios::beg);
|
||||
|
||||
std::vector<unsigned char> buffer(fileSize);
|
||||
file.read(reinterpret_cast<char*>(buffer.data()), fileSize);
|
||||
std::vector<unsigned char> buffer(file_size);
|
||||
file.read(reinterpret_cast<char*>(buffer.data()), file_size);
|
||||
file.close();
|
||||
|
||||
// Crear entrada de recurso
|
||||
ResourceEntry resource;
|
||||
resource.path = fullPath;
|
||||
resource.path = full_path;
|
||||
resource.offset = 0; // Se calculará al guardar
|
||||
resource.size = static_cast<uint32_t>(fileSize);
|
||||
resource.checksum = calculateChecksum(buffer.data(), fileSize);
|
||||
resource.size = static_cast<uint32_t>(file_size);
|
||||
resource.checksum = calculateChecksum(buffer.data(), file_size);
|
||||
|
||||
resources_[fullPath] = resource;
|
||||
resources_[full_path] = resource;
|
||||
|
||||
std::cout << " Añadido: " << fullPath << " (" << fileSize << " bytes)" << std::endl;
|
||||
std::cout << " Añadido: " << full_path << " (" << file_size << " bytes)" << '\n';
|
||||
}
|
||||
}
|
||||
|
||||
return !resources_.empty();
|
||||
}
|
||||
|
||||
bool ResourcePack::savePack(const std::string& packFilePath) {
|
||||
std::ofstream packFile(packFilePath, std::ios::binary);
|
||||
if (!packFile) {
|
||||
std::cerr << "Error: No se pudo crear pack: " << packFilePath << std::endl;
|
||||
auto ResourcePack::savePack(const std::string& pack_file_path) -> bool {
|
||||
std::ofstream pack_file(pack_file_path, std::ios::binary);
|
||||
if (!pack_file) {
|
||||
std::cerr << "Error: No se pudo crear pack: " << pack_file_path << '\n';
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -76,39 +74,39 @@ bool ResourcePack::savePack(const std::string& packFilePath) {
|
||||
std::memcpy(header.magic, "VBE3", 4);
|
||||
header.version = 1;
|
||||
header.fileCount = static_cast<uint32_t>(resources_.size());
|
||||
packFile.write(reinterpret_cast<const char*>(&header), sizeof(PackHeader));
|
||||
pack_file.write(reinterpret_cast<const char*>(&header), sizeof(PackHeader));
|
||||
|
||||
// 2. Calcular offsets (después del header + índice)
|
||||
uint32_t currentOffset = sizeof(PackHeader);
|
||||
uint32_t current_offset = sizeof(PackHeader);
|
||||
|
||||
// Calcular tamaño del índice (cada entrada: uint32_t pathLen + path + 3*uint32_t)
|
||||
for (const auto& [path, entry] : resources_) {
|
||||
currentOffset += sizeof(uint32_t); // pathLen
|
||||
currentOffset += static_cast<uint32_t>(path.size()); // path
|
||||
currentOffset += sizeof(uint32_t) * 3; // offset, size, checksum
|
||||
current_offset += sizeof(uint32_t); // pathLen
|
||||
current_offset += static_cast<uint32_t>(path.size()); // path
|
||||
current_offset += sizeof(uint32_t) * 3; // offset, size, checksum
|
||||
}
|
||||
|
||||
// 3. Escribir índice
|
||||
for (auto& [path, entry] : resources_) {
|
||||
entry.offset = currentOffset;
|
||||
entry.offset = current_offset;
|
||||
|
||||
uint32_t pathLen = static_cast<uint32_t>(path.size());
|
||||
packFile.write(reinterpret_cast<const char*>(&pathLen), sizeof(uint32_t));
|
||||
packFile.write(path.c_str(), pathLen);
|
||||
packFile.write(reinterpret_cast<const char*>(&entry.offset), sizeof(uint32_t));
|
||||
packFile.write(reinterpret_cast<const char*>(&entry.size), sizeof(uint32_t));
|
||||
packFile.write(reinterpret_cast<const char*>(&entry.checksum), sizeof(uint32_t));
|
||||
auto path_len = static_cast<uint32_t>(path.size());
|
||||
pack_file.write(reinterpret_cast<const char*>(&path_len), sizeof(uint32_t));
|
||||
pack_file.write(path.c_str(), path_len);
|
||||
pack_file.write(reinterpret_cast<const char*>(&entry.offset), sizeof(uint32_t));
|
||||
pack_file.write(reinterpret_cast<const char*>(&entry.size), sizeof(uint32_t));
|
||||
pack_file.write(reinterpret_cast<const char*>(&entry.checksum), sizeof(uint32_t));
|
||||
|
||||
currentOffset += entry.size;
|
||||
current_offset += entry.size;
|
||||
}
|
||||
|
||||
// 4. Escribir datos de archivos (sin encriptar en pack, se encripta al cargar)
|
||||
for (const auto& [path, entry] : resources_) {
|
||||
// Encontrar archivo original en disco
|
||||
fs::path originalPath = fs::current_path() / "data" / path;
|
||||
std::ifstream file(originalPath, std::ios::binary);
|
||||
fs::path original_path = fs::current_path() / "data" / path;
|
||||
std::ifstream file(original_path, std::ios::binary);
|
||||
if (!file) {
|
||||
std::cerr << "Error: No se pudo re-leer: " << originalPath << std::endl;
|
||||
std::cerr << "Error: No se pudo re-leer: " << original_path << '\n';
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -116,10 +114,10 @@ bool ResourcePack::savePack(const std::string& packFilePath) {
|
||||
file.read(reinterpret_cast<char*>(buffer.data()), entry.size);
|
||||
file.close();
|
||||
|
||||
packFile.write(reinterpret_cast<const char*>(buffer.data()), entry.size);
|
||||
pack_file.write(reinterpret_cast<const char*>(buffer.data()), entry.size);
|
||||
}
|
||||
|
||||
packFile.close();
|
||||
pack_file.close();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -127,10 +125,10 @@ bool ResourcePack::savePack(const std::string& packFilePath) {
|
||||
// DESEMPAQUETADO (juego)
|
||||
// ============================================================================
|
||||
|
||||
bool ResourcePack::loadPack(const std::string& packFilePath) {
|
||||
auto ResourcePack::loadPack(const std::string& pack_file_path) -> bool {
|
||||
clear();
|
||||
|
||||
packFile_.open(packFilePath, std::ios::binary);
|
||||
packFile_.open(pack_file_path, std::ios::binary);
|
||||
if (!packFile_) {
|
||||
return false;
|
||||
}
|
||||
@@ -140,13 +138,13 @@ bool ResourcePack::loadPack(const std::string& packFilePath) {
|
||||
packFile_.read(reinterpret_cast<char*>(&header), sizeof(PackHeader));
|
||||
|
||||
if (std::memcmp(header.magic, "VBE3", 4) != 0) {
|
||||
std::cerr << "Error: Pack inválido (magic incorrecto)" << std::endl;
|
||||
std::cerr << "Error: Pack inválido (magic incorrecto)" << '\n';
|
||||
packFile_.close();
|
||||
return false;
|
||||
}
|
||||
|
||||
if (header.version != 1) {
|
||||
std::cerr << "Error: Versión de pack no soportada: " << header.version << std::endl;
|
||||
std::cerr << "Error: Versión de pack no soportada: " << header.version << '\n';
|
||||
packFile_.close();
|
||||
return false;
|
||||
}
|
||||
@@ -155,12 +153,12 @@ bool ResourcePack::loadPack(const std::string& packFilePath) {
|
||||
for (uint32_t i = 0; i < header.fileCount; i++) {
|
||||
ResourceEntry entry;
|
||||
|
||||
uint32_t pathLen;
|
||||
packFile_.read(reinterpret_cast<char*>(&pathLen), sizeof(uint32_t));
|
||||
uint32_t path_len;
|
||||
packFile_.read(reinterpret_cast<char*>(&path_len), sizeof(uint32_t));
|
||||
|
||||
std::vector<char> pathBuffer(pathLen + 1, '\0');
|
||||
packFile_.read(pathBuffer.data(), pathLen);
|
||||
entry.path = std::string(pathBuffer.data());
|
||||
std::vector<char> path_buffer(path_len + 1, '\0');
|
||||
packFile_.read(path_buffer.data(), path_len);
|
||||
entry.path = std::string(path_buffer.data());
|
||||
|
||||
packFile_.read(reinterpret_cast<char*>(&entry.offset), sizeof(uint32_t));
|
||||
packFile_.read(reinterpret_cast<char*>(&entry.size), sizeof(uint32_t));
|
||||
@@ -173,15 +171,15 @@ bool ResourcePack::loadPack(const std::string& packFilePath) {
|
||||
return true;
|
||||
}
|
||||
|
||||
ResourcePack::ResourceData ResourcePack::loadResource(const std::string& resourcePath) {
|
||||
ResourceData result = {nullptr, 0};
|
||||
auto ResourcePack::loadResource(const std::string& resource_path) -> ResourcePack::ResourceData {
|
||||
ResourceData result = {.data = nullptr, .size = 0};
|
||||
|
||||
if (!isLoaded_) {
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string normalizedPath = normalizePath(resourcePath);
|
||||
auto it = resources_.find(normalizedPath);
|
||||
std::string normalized_path = normalizePath(resource_path);
|
||||
auto it = resources_.find(normalized_path);
|
||||
if (it == resources_.end()) {
|
||||
return result;
|
||||
}
|
||||
@@ -197,7 +195,7 @@ ResourcePack::ResourceData ResourcePack::loadResource(const std::string& resourc
|
||||
// Verificar checksum
|
||||
uint32_t checksum = calculateChecksum(result.data, entry.size);
|
||||
if (checksum != entry.checksum) {
|
||||
std::cerr << "Warning: Checksum incorrecto para: " << resourcePath << std::endl;
|
||||
std::cerr << "Warning: Checksum incorrecto para: " << resource_path << '\n';
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -207,15 +205,16 @@ ResourcePack::ResourceData ResourcePack::loadResource(const std::string& resourc
|
||||
// UTILIDADES
|
||||
// ============================================================================
|
||||
|
||||
std::vector<std::string> ResourcePack::getResourceList() const {
|
||||
auto ResourcePack::getResourceList() const -> std::vector<std::string> {
|
||||
std::vector<std::string> list;
|
||||
list.reserve(resources_.size());
|
||||
for (const auto& [path, entry] : resources_) {
|
||||
list.push_back(path);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
size_t ResourcePack::getResourceCount() const {
|
||||
auto ResourcePack::getResourceCount() const -> size_t {
|
||||
return resources_.size();
|
||||
}
|
||||
|
||||
@@ -231,7 +230,7 @@ void ResourcePack::clear() {
|
||||
// FUNCIONES AUXILIARES
|
||||
// ============================================================================
|
||||
|
||||
uint32_t ResourcePack::calculateChecksum(const unsigned char* data, size_t size) {
|
||||
auto ResourcePack::calculateChecksum(const unsigned char* data, size_t size) -> uint32_t {
|
||||
uint32_t checksum = 0;
|
||||
for (size_t i = 0; i < size; i++) {
|
||||
checksum ^= static_cast<uint32_t>(data[i]);
|
||||
@@ -240,11 +239,11 @@ uint32_t ResourcePack::calculateChecksum(const unsigned char* data, size_t size)
|
||||
return checksum;
|
||||
}
|
||||
|
||||
std::string ResourcePack::normalizePath(const std::string& path) {
|
||||
auto ResourcePack::normalizePath(const std::string& path) -> std::string {
|
||||
std::string normalized = path;
|
||||
|
||||
// Reemplazar \ por /
|
||||
std::replace(normalized.begin(), normalized.end(), '\\', '/');
|
||||
std::ranges::replace(normalized, '\\', '/');
|
||||
|
||||
// Buscar "data/" en cualquier parte del path y extraer lo que viene después
|
||||
size_t data_pos = normalized.find("data/");
|
||||
|
||||
Reference in New Issue
Block a user