treballant en resources.pack

This commit is contained in:
2025-08-19 09:46:19 +02:00
parent 2819b3628e
commit ed077c1da5
30 changed files with 1099 additions and 15 deletions

46
source/resource_helper.h Normal file
View File

@@ -0,0 +1,46 @@
#pragma once
#include "resource_loader.h"
#include <string>
#include <vector>
#include <memory>
#include <filesystem>
#include <fstream>
// Helper functions para integrar ResourceLoader con el sistema existente
namespace ResourceHelper {
// Inicializa ResourceLoader (llamar al inicio del programa)
bool initializeResourceSystem(const std::string& pack_file = "resources.pack");
// Cierra ResourceLoader
void shutdownResourceSystem();
// Carga un archivo usando ResourceLoader o fallback a filesystem
std::vector<uint8_t> loadFile(const std::string& filepath);
// Verifica si un archivo debería cargarse del pack vs filesystem
bool shouldUseResourcePack(const std::string& filepath);
// Convierte ruta Asset a ruta relativa para ResourceLoader
std::string getPackPath(const std::string& asset_path);
// Wrappea la carga de archivos para mantener compatibilidad
template<typename T>
T* loadResourceFile(const std::string& asset_path, T* (*loader_func)(const char*)) {
auto data = loadFile(asset_path);
if (data.empty()) {
return loader_func(asset_path.c_str());
}
// Crear archivo temporal para funciones que esperan path
std::string temp_path = "/tmp/ccae_" + std::to_string(std::hash<std::string>{}(asset_path));
std::ofstream temp_file(temp_path, std::ios::binary);
temp_file.write(reinterpret_cast<const char*>(data.data()), data.size());
temp_file.close();
T* result = loader_func(temp_path.c_str());
std::filesystem::remove(temp_path);
return result;
}
}