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>
64 lines
2.0 KiB
C++
64 lines
2.0 KiB
C++
#pragma once
|
|
|
|
#include <cstdint>
|
|
#include <fstream>
|
|
#include <map>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
/**
|
|
* ResourcePack - Sistema de empaquetado de recursos para ViBe3 Physics
|
|
*
|
|
* Permite empaquetar todos los recursos (imágenes, etc.) en un archivo binario
|
|
* único y ofuscado. Proporciona fallback automático a carpeta data/ si no existe pack.
|
|
*/
|
|
class ResourcePack {
|
|
public:
|
|
ResourcePack();
|
|
~ResourcePack();
|
|
|
|
// Empaquetado (usado por herramienta pack_resources)
|
|
bool addDirectory(const std::string& dir_path, const std::string& prefix = "");
|
|
bool savePack(const std::string& pack_file_path);
|
|
|
|
// Desempaquetado (usado por el juego)
|
|
bool loadPack(const std::string& pack_file_path);
|
|
|
|
// Carga de recursos individuales
|
|
struct ResourceData {
|
|
unsigned char* data;
|
|
size_t size;
|
|
};
|
|
ResourceData loadResource(const std::string& resource_path);
|
|
|
|
// Utilidades
|
|
std::vector<std::string> getResourceList() const;
|
|
size_t getResourceCount() const;
|
|
void clear();
|
|
|
|
private:
|
|
// Header del pack (12 bytes)
|
|
struct PackHeader {
|
|
char magic[4]; // "VBE3"
|
|
uint32_t version; // Versión del formato (1)
|
|
uint32_t fileCount; // Número de archivos empaquetados
|
|
};
|
|
|
|
// Índice de un recurso (variable length)
|
|
struct ResourceEntry {
|
|
std::string path; // Ruta relativa del recurso
|
|
uint32_t offset; // Offset en el archivo pack
|
|
uint32_t size; // Tamaño en bytes
|
|
uint32_t checksum; // Checksum simple (XOR de bytes)
|
|
};
|
|
|
|
// Datos internos
|
|
std::map<std::string, ResourceEntry> resources_;
|
|
std::ifstream packFile_;
|
|
bool isLoaded_;
|
|
|
|
// Funciones auxiliares
|
|
static uint32_t calculateChecksum(const unsigned char* data, size_t size);
|
|
static std::string normalizePath(const std::string& path);
|
|
};
|