forked from jaildesigner-jailgames/jaildoctors_dilemma
migrat Input a la ultima versió
cohesionats tots els metodes update de les escenes
This commit is contained in:
@@ -102,7 +102,7 @@ struct ResourceTileMap {
|
||||
|
||||
// Estructura para almacenar habitaciones y su nombre
|
||||
struct ResourceRoom {
|
||||
std::string name; // Nombre de la habitación
|
||||
std::string name; // Nombre de la habitación
|
||||
std::shared_ptr<Room::Data> room; // Habitación
|
||||
|
||||
// Constructor
|
||||
@@ -152,7 +152,7 @@ class Resource {
|
||||
std::vector<ResourceTileMap> tile_maps_; // Vector con los mapas de tiles
|
||||
std::vector<ResourceRoom> rooms_; // Vector con las habitaciones
|
||||
|
||||
ResourceCount count_; // Contador de recursos
|
||||
ResourceCount count_; // Contador de recursos
|
||||
std::shared_ptr<Text> loading_text_; // Texto para la pantalla de carga
|
||||
|
||||
// Carga los sonidos
|
||||
|
||||
@@ -3,13 +3,13 @@
|
||||
|
||||
#include "resource_helper.hpp"
|
||||
|
||||
#include "resource_loader.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "resource_loader.hpp"
|
||||
|
||||
namespace jdd {
|
||||
namespace ResourceHelper {
|
||||
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
#ifndef RESOURCE_HELPER_HPP
|
||||
#define RESOURCE_HELPER_HPP
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
|
||||
namespace jdd {
|
||||
namespace ResourceHelper {
|
||||
@@ -15,7 +15,7 @@ namespace ResourceHelper {
|
||||
// pack_file: Path to resources.pack
|
||||
// enable_fallback: Allow loading from filesystem if pack not available
|
||||
auto initializeResourceSystem(const std::string& pack_file = "resources.pack",
|
||||
bool enable_fallback = true) -> bool;
|
||||
bool enable_fallback = true) -> bool;
|
||||
|
||||
// Shutdown the resource system
|
||||
void shutdownResourceSystem();
|
||||
|
||||
@@ -4,64 +4,64 @@
|
||||
#ifndef RESOURCE_LOADER_HPP
|
||||
#define RESOURCE_LOADER_HPP
|
||||
|
||||
#include "resource_pack.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "resource_pack.hpp"
|
||||
|
||||
namespace jdd {
|
||||
|
||||
// Singleton class for loading resources from pack or filesystem
|
||||
class ResourceLoader {
|
||||
public:
|
||||
// Get singleton instance
|
||||
static auto get() -> ResourceLoader&;
|
||||
public:
|
||||
// Get singleton instance
|
||||
static auto get() -> ResourceLoader&;
|
||||
|
||||
// Initialize with a pack file (optional)
|
||||
auto initialize(const std::string& pack_file, bool enable_fallback = true) -> bool;
|
||||
// Initialize with a pack file (optional)
|
||||
auto initialize(const std::string& pack_file, bool enable_fallback = true) -> bool;
|
||||
|
||||
// Load a resource (tries pack first, then filesystem if fallback enabled)
|
||||
auto loadResource(const std::string& filename) -> std::vector<uint8_t>;
|
||||
// Load a resource (tries pack first, then filesystem if fallback enabled)
|
||||
auto loadResource(const std::string& filename) -> std::vector<uint8_t>;
|
||||
|
||||
// Check if a resource exists
|
||||
auto resourceExists(const std::string& filename) -> bool;
|
||||
// Check if a resource exists
|
||||
auto resourceExists(const std::string& filename) -> bool;
|
||||
|
||||
// Check if pack is loaded
|
||||
auto isPackLoaded() const -> bool;
|
||||
// Check if pack is loaded
|
||||
auto isPackLoaded() const -> bool;
|
||||
|
||||
// Get pack statistics
|
||||
auto getPackResourceCount() const -> size_t;
|
||||
// Get pack statistics
|
||||
auto getPackResourceCount() const -> size_t;
|
||||
|
||||
// Validate pack integrity (checksum)
|
||||
auto validatePack() const -> bool;
|
||||
// Validate pack integrity (checksum)
|
||||
auto validatePack() const -> bool;
|
||||
|
||||
// Load assets.txt from pack (for release builds)
|
||||
auto loadAssetsConfig() const -> std::string;
|
||||
// Load assets.txt from pack (for release builds)
|
||||
auto loadAssetsConfig() const -> std::string;
|
||||
|
||||
// Cleanup
|
||||
void shutdown();
|
||||
// Cleanup
|
||||
void shutdown();
|
||||
|
||||
private:
|
||||
ResourceLoader() = default;
|
||||
~ResourceLoader() = default;
|
||||
private:
|
||||
ResourceLoader() = default;
|
||||
~ResourceLoader() = default;
|
||||
|
||||
// Disable copy/move
|
||||
ResourceLoader(const ResourceLoader&) = delete;
|
||||
ResourceLoader& operator=(const ResourceLoader&) = delete;
|
||||
ResourceLoader(ResourceLoader&&) = delete;
|
||||
ResourceLoader& operator=(ResourceLoader&&) = delete;
|
||||
// Disable copy/move
|
||||
ResourceLoader(const ResourceLoader&) = delete;
|
||||
ResourceLoader& operator=(const ResourceLoader&) = delete;
|
||||
ResourceLoader(ResourceLoader&&) = delete;
|
||||
ResourceLoader& operator=(ResourceLoader&&) = delete;
|
||||
|
||||
// Load from filesystem
|
||||
static auto loadFromFilesystem(const std::string& filepath) -> std::vector<uint8_t>;
|
||||
// Load from filesystem
|
||||
static auto loadFromFilesystem(const std::string& filepath) -> std::vector<uint8_t>;
|
||||
|
||||
// Check if file exists on filesystem
|
||||
static auto fileExistsOnFilesystem(const std::string& filepath) -> bool;
|
||||
// Check if file exists on filesystem
|
||||
static auto fileExistsOnFilesystem(const std::string& filepath) -> bool;
|
||||
|
||||
// Member data
|
||||
std::unique_ptr<ResourcePack> resource_pack_;
|
||||
bool fallback_to_files_{true};
|
||||
bool initialized_{false};
|
||||
// Member data
|
||||
std::unique_ptr<ResourcePack> resource_pack_;
|
||||
bool fallback_to_files_{true};
|
||||
bool initialized_{false};
|
||||
};
|
||||
|
||||
} // namespace jdd
|
||||
|
||||
@@ -81,7 +81,7 @@ auto ResourcePack::addFile(const std::string& filepath, const std::string& pack_
|
||||
|
||||
// Add all files from a directory recursively
|
||||
auto ResourcePack::addDirectory(const std::string& dir_path,
|
||||
const std::string& base_path) -> bool {
|
||||
const std::string& base_path) -> bool {
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
if (!fs::exists(dir_path) || !fs::is_directory(dir_path)) {
|
||||
@@ -244,7 +244,7 @@ auto ResourcePack::getResource(const std::string& filename) -> std::vector<uint8
|
||||
}
|
||||
|
||||
std::vector<uint8_t> result(data_.begin() + entry.offset,
|
||||
data_.begin() + entry.offset + entry.size);
|
||||
data_.begin() + entry.offset + entry.size);
|
||||
|
||||
// Verify checksum
|
||||
uint32_t checksum = calculateChecksum(result);
|
||||
|
||||
@@ -15,10 +15,10 @@ namespace jdd {
|
||||
|
||||
// Entry metadata for each resource in the pack
|
||||
struct ResourceEntry {
|
||||
std::string filename; // Relative path within pack
|
||||
uint64_t offset; // Byte offset in data block
|
||||
uint64_t size; // Size in bytes
|
||||
uint32_t checksum; // CRC32 checksum for verification
|
||||
std::string filename; // Relative path within pack
|
||||
uint64_t offset; // Byte offset in data block
|
||||
uint64_t size; // Size in bytes
|
||||
uint32_t checksum; // CRC32 checksum for verification
|
||||
};
|
||||
|
||||
// Resource pack file format
|
||||
@@ -26,67 +26,67 @@ struct ResourceEntry {
|
||||
// Metadata: Count + array of ResourceEntry
|
||||
// Data: Encrypted data block
|
||||
class ResourcePack {
|
||||
public:
|
||||
ResourcePack() = default;
|
||||
~ResourcePack() = default;
|
||||
public:
|
||||
ResourcePack() = default;
|
||||
~ResourcePack() = default;
|
||||
|
||||
// Disable copy/move
|
||||
ResourcePack(const ResourcePack&) = delete;
|
||||
ResourcePack& operator=(const ResourcePack&) = delete;
|
||||
ResourcePack(ResourcePack&&) = delete;
|
||||
ResourcePack& operator=(ResourcePack&&) = delete;
|
||||
// Disable copy/move
|
||||
ResourcePack(const ResourcePack&) = delete;
|
||||
ResourcePack& operator=(const ResourcePack&) = delete;
|
||||
ResourcePack(ResourcePack&&) = delete;
|
||||
ResourcePack& operator=(ResourcePack&&) = delete;
|
||||
|
||||
// Add a single file to the pack
|
||||
auto addFile(const std::string& filepath, const std::string& pack_name) -> bool;
|
||||
// Add a single file to the pack
|
||||
auto addFile(const std::string& filepath, const std::string& pack_name) -> bool;
|
||||
|
||||
// Add all files from a directory recursively
|
||||
auto addDirectory(const std::string& dir_path, const std::string& base_path = "")
|
||||
-> bool;
|
||||
// Add all files from a directory recursively
|
||||
auto addDirectory(const std::string& dir_path, const std::string& base_path = "")
|
||||
-> bool;
|
||||
|
||||
// Save the pack to a file
|
||||
auto savePack(const std::string& pack_file) -> bool;
|
||||
// Save the pack to a file
|
||||
auto savePack(const std::string& pack_file) -> bool;
|
||||
|
||||
// Load a pack from a file
|
||||
auto loadPack(const std::string& pack_file) -> bool;
|
||||
// Load a pack from a file
|
||||
auto loadPack(const std::string& pack_file) -> bool;
|
||||
|
||||
// Get a resource by name
|
||||
auto getResource(const std::string& filename) -> std::vector<uint8_t>;
|
||||
// Get a resource by name
|
||||
auto getResource(const std::string& filename) -> std::vector<uint8_t>;
|
||||
|
||||
// Check if a resource exists
|
||||
auto hasResource(const std::string& filename) const -> bool;
|
||||
// Check if a resource exists
|
||||
auto hasResource(const std::string& filename) const -> bool;
|
||||
|
||||
// Get list of all resources
|
||||
auto getResourceList() const -> std::vector<std::string>;
|
||||
// Get list of all resources
|
||||
auto getResourceList() const -> std::vector<std::string>;
|
||||
|
||||
// Check if pack is loaded
|
||||
auto isLoaded() const -> bool { return loaded_; }
|
||||
// Check if pack is loaded
|
||||
auto isLoaded() const -> bool { return loaded_; }
|
||||
|
||||
// Get pack statistics
|
||||
auto getResourceCount() const -> size_t { return resources_.size(); }
|
||||
auto getDataSize() const -> size_t { return data_.size(); }
|
||||
// Get pack statistics
|
||||
auto getResourceCount() const -> size_t { return resources_.size(); }
|
||||
auto getDataSize() const -> size_t { return data_.size(); }
|
||||
|
||||
// Calculate overall pack checksum (for validation)
|
||||
auto calculatePackChecksum() const -> uint32_t;
|
||||
// Calculate overall pack checksum (for validation)
|
||||
auto calculatePackChecksum() const -> uint32_t;
|
||||
|
||||
private:
|
||||
static constexpr std::array<char, 4> MAGIC_HEADER = {'J', 'D', 'D', 'I'};
|
||||
static constexpr uint32_t VERSION = 1;
|
||||
static constexpr const char* DEFAULT_ENCRYPT_KEY = "JDDI_RESOURCES_2024";
|
||||
private:
|
||||
static constexpr std::array<char, 4> MAGIC_HEADER = {'J', 'D', 'D', 'I'};
|
||||
static constexpr uint32_t VERSION = 1;
|
||||
static constexpr const char* DEFAULT_ENCRYPT_KEY = "JDDI_RESOURCES_2024";
|
||||
|
||||
// Calculate CRC32 checksum
|
||||
static auto calculateChecksum(const std::vector<uint8_t>& data) -> uint32_t;
|
||||
// Calculate CRC32 checksum
|
||||
static auto calculateChecksum(const std::vector<uint8_t>& data) -> uint32_t;
|
||||
|
||||
// XOR encryption/decryption
|
||||
static void encryptData(std::vector<uint8_t>& data, const std::string& key);
|
||||
static void decryptData(std::vector<uint8_t>& data, const std::string& key);
|
||||
// XOR encryption/decryption
|
||||
static void encryptData(std::vector<uint8_t>& data, const std::string& key);
|
||||
static void decryptData(std::vector<uint8_t>& data, const std::string& key);
|
||||
|
||||
// Read file from disk
|
||||
static auto readFile(const std::string& filepath) -> std::vector<uint8_t>;
|
||||
// Read file from disk
|
||||
static auto readFile(const std::string& filepath) -> std::vector<uint8_t>;
|
||||
|
||||
// Member data
|
||||
std::unordered_map<std::string, ResourceEntry> resources_;
|
||||
std::vector<uint8_t> data_; // Encrypted data block
|
||||
bool loaded_{false};
|
||||
// Member data
|
||||
std::unordered_map<std::string, ResourceEntry> resources_;
|
||||
std::vector<uint8_t> data_; // Encrypted data block
|
||||
bool loaded_{false};
|
||||
};
|
||||
|
||||
} // namespace jdd
|
||||
|
||||
Reference in New Issue
Block a user