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>
87 lines
2.9 KiB
C++
87 lines
2.9 KiB
C++
#pragma once
|
|
|
|
#include <map>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
class ResourcePack;
|
|
|
|
/**
|
|
* ResourceManager - Gestor centralizado de recursos empaquetados
|
|
*
|
|
* Singleton que administra el sistema de recursos empaquetados (resources.pack)
|
|
* y proporciona fallback automático a disco cuando el pack no está disponible.
|
|
*
|
|
* Uso:
|
|
* // En main.cpp, antes de inicializar cualquier sistema:
|
|
* ResourceManager::init("resources.pack");
|
|
*
|
|
* // Desde cualquier clase que necesite recursos:
|
|
* unsigned char* data = nullptr;
|
|
* size_t size = 0;
|
|
* if (ResourceManager::loadResource("textures/ball.png", data, size)) {
|
|
* // Usar datos...
|
|
* delete[] data; // Liberar cuando termine
|
|
* }
|
|
*/
|
|
class ResourceManager {
|
|
public:
|
|
/**
|
|
* Inicializa el sistema de recursos empaquetados
|
|
* Debe llamarse una única vez al inicio del programa
|
|
*
|
|
* @param packFilePath Ruta al archivo .pack (ej: "resources.pack")
|
|
* @return true si el pack se cargó correctamente, false si no existe (fallback a disco)
|
|
*/
|
|
static bool init(const std::string& pack_file_path);
|
|
|
|
/**
|
|
* Libera el sistema de recursos
|
|
* Opcional - se llama automáticamente al cerrar el programa
|
|
*/
|
|
static void shutdown();
|
|
|
|
/**
|
|
* Carga un recurso desde el pack (o disco si no existe pack)
|
|
*
|
|
* @param resourcePath Ruta relativa del recurso (ej: "textures/ball.png")
|
|
* @param data [out] Puntero donde se almacenará el buffer (debe liberar con delete[])
|
|
* @param size [out] Tamaño del buffer en bytes
|
|
* @return true si se cargó correctamente, false si falla
|
|
*/
|
|
static bool loadResource(const std::string& resource_path, unsigned char*& data, size_t& size);
|
|
|
|
/**
|
|
* Verifica si el pack está cargado
|
|
* @return true si hay un pack cargado, false si se usa disco
|
|
*/
|
|
static bool isPackLoaded();
|
|
|
|
/**
|
|
* Obtiene la lista de recursos disponibles en el pack
|
|
* @return Vector con las rutas de todos los recursos, vacío si no hay pack
|
|
*/
|
|
static std::vector<std::string> getResourceList();
|
|
|
|
/**
|
|
* Obtiene el número de recursos en el pack
|
|
* @return Número de recursos, 0 si no hay pack
|
|
*/
|
|
static size_t getResourceCount();
|
|
|
|
private:
|
|
// Constructor privado (singleton)
|
|
ResourceManager() = default;
|
|
~ResourceManager() = default;
|
|
|
|
// Deshabilitar copia y asignación
|
|
ResourceManager(const ResourceManager&) = delete;
|
|
ResourceManager& operator=(const ResourceManager&) = delete;
|
|
|
|
// Instancia del pack (nullptr si no está cargado)
|
|
static ResourcePack* resourcePack_;
|
|
|
|
// Caché en RAM para evitar I/O repetido en el bucle principal
|
|
static std::map<std::string, std::vector<unsigned char>> cache_;
|
|
};
|