From b7db34cdf7a989232dd011a3abfdaa0bd3a85783 Mon Sep 17 00:00:00 2001 From: Sergio Date: Tue, 18 Nov 2025 12:41:30 +0100 Subject: [PATCH] arreglos d'estil en source/core/resources --- .../rendering/surface_animated_sprite.cpp | 11 +- .../rendering/surface_animated_sprite.hpp | 8 +- source/core/resources/resource_cache.cpp | 36 ++- source/core/resources/resource_cache.hpp | 244 +++++------------- source/core/resources/resource_helper.hpp | 5 +- source/core/resources/resource_loader.hpp | 45 +--- source/core/resources/resource_pack.cpp | 13 +- source/core/resources/resource_pack.hpp | 62 ++--- ...check-result-warning-style-performance.txt | 6 +- 9 files changed, 135 insertions(+), 295 deletions(-) diff --git a/source/core/rendering/surface_animated_sprite.cpp b/source/core/rendering/surface_animated_sprite.cpp index 07845f2..0b72aee 100644 --- a/source/core/rendering/surface_animated_sprite.cpp +++ b/source/core/rendering/surface_animated_sprite.cpp @@ -7,10 +7,10 @@ #include // Para runtime_error #include -#include "external/fkyaml_node.hpp" // Para fkyaml::node #include "core/rendering/surface.hpp" // Para Surface #include "core/resources/resource_cache.hpp" // Para Resource #include "core/resources/resource_helper.hpp" // Para ResourceHelper +#include "external/fkyaml_node.hpp" // Para fkyaml::node #include "utils/utils.hpp" // Para printWithDots // Helper: Convierte un nodo YAML de frames (array) a vector de SDL_FRect @@ -105,8 +105,7 @@ auto SurfaceAnimatedSprite::loadAnimationsFromYAML(const std::string& file_path, frame_width, frame_height, frames_per_row, - max_tiles - ); + max_tiles); } animations.push_back(animation); @@ -125,7 +124,7 @@ auto SurfaceAnimatedSprite::loadAnimationsFromYAML(const std::string& file_path, } // Constructor con bytes YAML del cache (parsing lazy) -SurfaceAnimatedSprite::SurfaceAnimatedSprite(const ResourceAnimation& cached_data) { +SurfaceAnimatedSprite::SurfaceAnimatedSprite(const AnimationResource& cached_data) { // Parsear YAML desde los bytes cargados en cache std::string yaml_content(cached_data.yaml_data.begin(), cached_data.yaml_data.end()); @@ -190,8 +189,7 @@ SurfaceAnimatedSprite::SurfaceAnimatedSprite(const ResourceAnimation& cached_dat frame_width, frame_height, frames_per_row, - max_tiles - ); + max_tiles); } animations_.push_back(animation); @@ -216,7 +214,6 @@ SurfaceAnimatedSprite::SurfaceAnimatedSprite(const ResourceAnimation& cached_dat } } - // Obtiene el indice de la animación a partir del nombre auto SurfaceAnimatedSprite::getIndex(const std::string& name) -> int { auto index = -1; diff --git a/source/core/rendering/surface_animated_sprite.hpp b/source/core/rendering/surface_animated_sprite.hpp index 8e02054..ed4916c 100644 --- a/source/core/rendering/surface_animated_sprite.hpp +++ b/source/core/rendering/surface_animated_sprite.hpp @@ -10,7 +10,7 @@ #include "core/rendering/surface_moving_sprite.hpp" // Para SMovingSprite class Surface; -struct ResourceAnimation; // Forward declaration +struct AnimationResource; // Forward declaration class SurfaceAnimatedSprite : public SurfaceMovingSprite { public: @@ -31,15 +31,15 @@ class SurfaceAnimatedSprite : public SurfaceMovingSprite { static auto loadAnimationsFromYAML(const std::string& file_path, std::shared_ptr& surface, float& frame_width, float& frame_height) -> std::vector; // Carga las animaciones desde fichero YAML // Constructores - explicit SurfaceAnimatedSprite(const ResourceAnimation& cached_data); // Constructor con datos pre-cargados del cache + explicit SurfaceAnimatedSprite(const AnimationResource& cached_data); // Constructor con datos pre-cargados del cache ~SurfaceAnimatedSprite() override = default; // Destructor void update(float delta_time) override; // Actualiza las variables del objeto (time-based) // Consultas de estado - auto animationIsCompleted() -> bool; // Comprueba si ha terminado la animación - auto getIndex(const std::string& name) -> int; // Obtiene el índice de la animación por nombre + auto animationIsCompleted() -> bool; // Comprueba si ha terminado la animación + auto getIndex(const std::string& name) -> int; // Obtiene el índice de la animación por nombre auto getCurrentAnimationSize() -> int { return static_cast(animations_[current_animation_].frames.size()); } // Número de frames de la animación actual // Modificadores de animación diff --git a/source/core/resources/resource_cache.cpp b/source/core/resources/resource_cache.cpp index 61bf5fb..5c2cda4 100644 --- a/source/core/resources/resource_cache.cpp +++ b/source/core/resources/resource_cache.cpp @@ -148,7 +148,7 @@ auto Cache::getText(const std::string& name) -> std::shared_ptr { } // Obtiene los datos de animación parseados a partir de un nombre -auto Cache::getAnimationData(const std::string& name) -> const ResourceAnimation& { +auto Cache::getAnimationData(const std::string& name) -> const AnimationResource& { auto it = std::ranges::find_if(animations_, [&name](const auto& a) { return a.name == name; }); if (it != animations_.end()) { @@ -172,7 +172,7 @@ auto Cache::getRoom(const std::string& name) -> std::shared_ptr { } // Obtiene todas las habitaciones -auto Cache::getRooms() -> std::vector& { +auto Cache::getRooms() -> std::vector& { return rooms_; } @@ -197,7 +197,7 @@ void Cache::loadSounds() { sound = JA_LoadSound(l.c_str()); } - sounds_.emplace_back(name, sound); + sounds_.emplace_back(SoundResource{name, sound}); printWithDots("Sound : ", name, "[ LOADED ]"); updateLoadingProgress(); } @@ -224,7 +224,7 @@ void Cache::loadMusics() { music = JA_LoadMusic(l.c_str()); } - musics_.emplace_back(name, music); + musics_.emplace_back(MusicResource{name, music}); printWithDots("Music : ", name, "[ LOADED ]"); updateLoadingProgress(1); } @@ -238,7 +238,7 @@ void Cache::loadSurfaces() { for (const auto& l : list) { auto name = getFileName(l); - surfaces_.emplace_back(name, std::make_shared(l)); + surfaces_.emplace_back(SurfaceResource{name, std::make_shared(l)}); surfaces_.back().surface->setTransparentColor(0); updateLoadingProgress(); } @@ -261,7 +261,7 @@ void Cache::loadPalettes() { for (const auto& l : list) { auto name = getFileName(l); - palettes_.emplace_back(name, readPalFile(l)); + palettes_.emplace_back(ResourcePalette{name, readPalFile(l)}); updateLoadingProgress(); } } @@ -274,7 +274,7 @@ void Cache::loadTextFiles() { for (const auto& l : list) { auto name = getFileName(l); - text_files_.emplace_back(name, Text::loadTextFile(l)); + text_files_.emplace_back(TextFileResource{name, Text::loadTextFile(l)}); updateLoadingProgress(); } } @@ -291,7 +291,7 @@ void Cache::loadAnimations() { // Cargar bytes del archivo YAML sin parsear (carga lazy) auto yaml_bytes = Helper::loadFile(l); - animations_.emplace_back(name, yaml_bytes); + animations_.emplace_back(AnimationResource{name, yaml_bytes}); printWithDots("Animation : ", name, "[ LOADED ]"); updateLoadingProgress(); } @@ -305,7 +305,7 @@ void Cache::loadRooms() { for (const auto& l : list) { auto name = getFileName(l); - rooms_.emplace_back(name, std::make_shared(Room::loadYAML(l))); + rooms_.emplace_back(RoomResource{name, std::make_shared(Room::loadYAML(l))}); printWithDots("Room : ", name, "[ LOADED ]"); updateLoadingProgress(); } @@ -313,15 +313,9 @@ void Cache::loadRooms() { void Cache::createText() { struct ResourceInfo { - std::string key; // Identificador del recurso - std::string texture_file; // Nombre del archivo de textura - std::string text_file; // Nombre del archivo de texto - - // Constructor para facilitar la creación de objetos ResourceInfo - ResourceInfo(std::string k, std::string t_file, std::string txt_file) - : key(std::move(k)), - texture_file(std::move(t_file)), - text_file(std::move(txt_file)) {} + std::string key{}; // Identificador del recurso + std::string texture_file{}; // Nombre del archivo de textura + std::string text_file{}; // Nombre del archivo de texto }; std::cout << "\n>> CREATING TEXT_OBJECTS" << '\n'; @@ -334,7 +328,7 @@ void Cache::createText() { {"8bithud", "8bithud.gif", "8bithud.txt"}}; for (const auto& res_info : resources) { - texts_.emplace_back(res_info.key, std::make_shared(getSurface(res_info.texture_file), getTextFile(res_info.text_file))); + texts_.emplace_back(TextResource{res_info.key, std::make_shared(getSurface(res_info.texture_file), getTextFile(res_info.text_file))}); printWithDots("Text : ", res_info.key, "[ DONE ]"); } } @@ -374,13 +368,13 @@ void Cache::calculateTotal() { List::Type::ANIMATION, List::Type::ROOM}; - size_t total = 0; + int total = 0; for (const auto& asset_type : asset_types) { auto list = List::get()->getListByType(asset_type); total += list.size(); } - count_ = ResourceCount(total, 0); + count_ = ResourceCount{total, 0}; } // Muestra el progreso de carga diff --git a/source/core/resources/resource_cache.hpp b/source/core/resources/resource_cache.hpp index 20ba99f..d84ee6d 100644 --- a/source/core/resources/resource_cache.hpp +++ b/source/core/resources/resource_cache.hpp @@ -13,233 +13,131 @@ struct JA_Music_t; // lines 11-11 struct JA_Sound_t; // lines 12-12 // Estructura para almacenar ficheros de sonido y su nombre -struct ResourceSound { - std::string name; // Nombre del sonido - JA_Sound_t* sound; // Objeto con el sonido - - // Constructor - ResourceSound(std::string name, JA_Sound_t* sound) - : name(std::move(name)), - sound(sound) {} +struct SoundResource { + std::string name{}; // Nombre del sonido + JA_Sound_t* sound{nullptr}; // Objeto con el sonido }; // Estructura para almacenar ficheros musicales y su nombre -struct ResourceMusic { - std::string name; // Nombre de la musica - JA_Music_t* music; // Objeto con la música - - // Constructor - ResourceMusic(std::string name, JA_Music_t* music) - : name(std::move(name)), - music(music) {} +struct MusicResource { + std::string name{}; // Nombre de la musica + JA_Music_t* music{nullptr}; // Objeto con la música }; // Estructura para almacenar objetos Surface y su nombre -struct ResourceSurface { - std::string name; // Nombre de la surface - std::shared_ptr surface; // Objeto con la surface - - // Constructor - ResourceSurface(std::string name, std::shared_ptr surface) - : name(std::move(name)), - surface(std::move(std::move(surface))) {} +struct SurfaceResource { + std::string name{}; // Nombre de la surface + std::shared_ptr surface{}; // Objeto con la surface }; // Estructura para almacenar objetos Palette y su nombre struct ResourcePalette { - std::string name; // Nombre de la surface - Palette palette; // Paleta - - // Constructor - ResourcePalette(std::string name, const Palette& palette) - : name(std::move(name)), - palette(palette) {} + std::string name{}; // Nombre de la surface + Palette palette{}; // Paleta }; // Estructura para almacenar ficheros TextFile y su nombre -struct ResourceTextFile { - std::string name; // Nombre del fichero - std::shared_ptr text_file; // Objeto con los descriptores de la fuente de texto - - // Constructor - ResourceTextFile(std::string name, std::shared_ptr text_file) - : name(std::move(name)), - text_file(std::move(std::move(text_file))) {} +struct TextFileResource { + std::string name{}; // Nombre del fichero + std::shared_ptr text_file{}; // Objeto con los descriptores de la fuente de texto }; // Estructura para almacenar objetos Text y su nombre -struct ResourceText { - std::string name; // Nombre del objeto - std::shared_ptr text; // Objeto - - // Constructor - ResourceText(std::string name, std::shared_ptr text) - : name(std::move(name)), - text(std::move(std::move(text))) {} +struct TextResource { + std::string name{}; // Nombre del objeto + std::shared_ptr text{}; // Objeto }; // Estructura para almacenar ficheros animaciones y su nombre -struct ResourceAnimation { - std::string name; // Nombre del fichero - std::vector yaml_data; // Bytes del archivo YAML sin parsear - - // Constructor - ResourceAnimation(std::string name, std::vector yaml_data) - : name(std::move(name)), - yaml_data(std::move(yaml_data)) {} +struct AnimationResource { + std::string name{}; // Nombre del fichero + std::vector yaml_data{}; // Bytes del archivo YAML sin parsear }; // Estructura para almacenar habitaciones y su nombre -struct ResourceRoom { - std::string name; // Nombre de la habitación - std::shared_ptr room; // Habitación - - // Constructor - ResourceRoom(std::string name, std::shared_ptr room) - : name(std::move(name)), - room(std::move(std::move(room))) {} -}; - -// Estructura para llevar la cuenta de los recursos cargados -struct ResourceCount { - int total; // Número total de recursos - int loaded; // Número de recursos cargados - - // Constructor - ResourceCount() - : total(0), - loaded(0) {} - - // Constructor - ResourceCount(int total, int loaded) - : total(total), - loaded(loaded) {} - - // Añade una cantidad a los recursos cargados - void add(int amount) { - loaded += amount; - } - - // Obtiene el porcentaje de recursos cargados - [[nodiscard]] auto getPercentage() const -> float { - return static_cast(loaded) / static_cast(total); - } +struct RoomResource { + std::string name{}; // Nombre de la habitación + std::shared_ptr room{}; // Habitación }; namespace Resource { class Cache { + public: + static void init(); // Inicialización singleton + static void destroy(); // Destrucción singleton + static auto get() -> Cache*; // Acceso al singleton + + auto getSound(const std::string& name) -> JA_Sound_t*; // Getters de recursos + auto getMusic(const std::string& name) -> JA_Music_t*; + auto getSurface(const std::string& name) -> std::shared_ptr; + auto getPalette(const std::string& name) -> Palette; + auto getTextFile(const std::string& name) -> std::shared_ptr; + auto getText(const std::string& name) -> std::shared_ptr; + auto getAnimationData(const std::string& name) -> const AnimationResource&; + auto getRoom(const std::string& name) -> std::shared_ptr; + auto getRooms() -> std::vector&; + + void reload(); // Recarga todos los recursos + private: - // [SINGLETON] Objeto cache privado para Don Melitón - static Cache* cache; + // Estructura para llevar la cuenta de los recursos cargados + struct ResourceCount { + int total{0}; // Número total de recursos + int loaded{0}; // Número de recursos cargados - std::vector sounds_; // Vector con los sonidos - std::vector musics_; // Vector con las musicas - std::vector surfaces_; // Vector con las surfaces - std::vector palettes_; // Vector con las paletas - std::vector text_files_; // Vector con los ficheros de texto - std::vector texts_; // Vector con los objetos de texto - std::vector animations_; // Vector con las animaciones - std::vector rooms_; // Vector con las habitaciones + // Añade una cantidad a los recursos cargados + void add(int amount) { + loaded += amount; + } - ResourceCount count_; // Contador de recursos - std::shared_ptr loading_text_; // Texto para la pantalla de carga + // Obtiene el porcentaje de recursos cargados + [[nodiscard]] auto getPercentage() const -> float { + return static_cast(loaded) / static_cast(total); + } + }; - // Carga los sonidos + // Métodos de carga de recursos void loadSounds(); - - // Carga las musicas void loadMusics(); - - // Carga las surfaces void loadSurfaces(); - - // Carga las paletas void loadPalettes(); - - // Carga los ficheros de texto void loadTextFiles(); - - // Carga las animaciones void loadAnimations(); - - // Carga las habitaciones void loadRooms(); - - // Crea los objetos de texto void createText(); - // Vacia todos los vectores de recursos + // Métodos de limpieza void clear(); - - // Carga todos los recursos - void load(); - - // Vacía el vector de sonidos void clearSounds(); - - // Vacía el vector de musicas void clearMusics(); - // Calcula el numero de recursos para cargar + // Métodos de gestión de carga + void load(); void calculateTotal(); - - // Muestra el progreso de carga void renderProgress(); - - // Comprueba los eventosstatic static void checkEvents(); - - // Actualiza el progreso de carga void updateLoadingProgress(int steps = 5); - // [SINGLETON] Ahora el constructor y el destructor son privados, para no poder crear objetos cache desde fuera - - // Constructor + // Constructor y destructor Cache(); - - // Destructor ~Cache() = default; - public: - // [SINGLETON] Crearemos el objeto cache con esta función estática - static void init(); + // Singleton instance + static Cache* cache; - // [SINGLETON] Destruiremos el objeto cache con esta función estática - static void destroy(); + // Variables miembro + std::vector sounds_{}; // Vector con los sonidos + std::vector musics_{}; // Vector con las musicas + std::vector surfaces_{}; // Vector con las surfaces + std::vector palettes_{}; // Vector con las paletas + std::vector text_files_{}; // Vector con los ficheros de texto + std::vector texts_{}; // Vector con los objetos de texto + std::vector animations_{}; // Vector con las animaciones + std::vector rooms_{}; // Vector con las habitaciones - // [SINGLETON] Con este método obtenemos el objeto cache y podemos trabajar con él - static auto get() -> Cache*; - - // Obtiene el sonido a partir de un nombre - auto getSound(const std::string& name) -> JA_Sound_t*; - - // Obtiene la música a partir de un nombre - auto getMusic(const std::string& name) -> JA_Music_t*; - - // Obtiene la surface a partir de un nombre - auto getSurface(const std::string& name) -> std::shared_ptr; - - // Obtiene la paleta a partir de un nombre - auto getPalette(const std::string& name) -> Palette; - - // Obtiene el fichero de texto a partir de un nombre - auto getTextFile(const std::string& name) -> std::shared_ptr; - - // Obtiene el objeto de texto a partir de un nombre - auto getText(const std::string& name) -> std::shared_ptr; - - // Obtiene los bytes YAML de animación a partir de un nombre (parsing lazy) - auto getAnimationData(const std::string& name) -> const ResourceAnimation&; - - // Obtiene la habitación a partir de un nombre - auto getRoom(const std::string& name) -> std::shared_ptr; - - // Obtiene todas las habitaciones - auto getRooms() -> std::vector&; - - // Recarga todos los recursos - void reload(); + ResourceCount count_{}; // Contador de recursos + std::shared_ptr loading_text_{}; // Texto para la pantalla de carga }; } // namespace Resource diff --git a/source/core/resources/resource_helper.hpp b/source/core/resources/resource_helper.hpp index 2e337c1..da2568c 100644 --- a/source/core/resources/resource_helper.hpp +++ b/source/core/resources/resource_helper.hpp @@ -1,8 +1,7 @@ // resource_helper.hpp // Helper functions for resource loading (bridge to pack system) -#ifndef RESOURCE_HELPER_HPP -#define RESOURCE_HELPER_HPP +#pragma once #include #include @@ -37,5 +36,3 @@ auto shouldUseResourcePack(const std::string& filepath) -> bool; auto isPackLoaded() -> bool; } // namespace Resource::Helper - -#endif // RESOURCE_HELPER_HPP diff --git a/source/core/resources/resource_loader.hpp b/source/core/resources/resource_loader.hpp index 924bc45..ebe5b92 100644 --- a/source/core/resources/resource_loader.hpp +++ b/source/core/resources/resource_loader.hpp @@ -1,8 +1,7 @@ // resource_loader.hpp // Singleton resource loader for managing pack and filesystem access -#ifndef RESOURCE_LOADER_HPP -#define RESOURCE_LOADER_HPP +#pragma once #include #include @@ -15,35 +14,21 @@ namespace Resource { // Singleton class for loading resources from pack or filesystem class Loader { public: - // Get singleton instance - static auto get() -> Loader&; + static auto get() -> Loader&; // Singleton instance access - // Initialize with a pack file (optional) - auto initialize(const std::string& pack_file, bool enable_fallback = true) -> bool; + auto initialize(const std::string& pack_file, bool enable_fallback = true) -> bool; // Initialize loader with pack file - // Load a resource (tries pack first, then filesystem if fallback enabled) - auto loadResource(const std::string& filename) -> std::vector; + auto loadResource(const std::string& filename) -> std::vector; // Load resource data + auto resourceExists(const std::string& filename) -> bool; // Check resource availability - // Check if a resource exists - auto resourceExists(const std::string& filename) -> bool; - - // Check if pack is loaded - [[nodiscard]] auto isPackLoaded() const -> bool; - - // Get pack statistics + [[nodiscard]] auto isPackLoaded() const -> bool; // Pack status queries [[nodiscard]] auto getPackResourceCount() const -> size_t; + [[nodiscard]] auto validatePack() const -> bool; // Validate pack integrity + [[nodiscard]] auto loadAssetsConfig() const -> std::string; // Load assets.yaml from pack - // Validate pack integrity (checksum) - [[nodiscard]] auto validatePack() const -> bool; + void shutdown(); // Cleanup - // Load assets.yaml from pack (for release builds) - [[nodiscard]] auto loadAssetsConfig() const -> std::string; - - // Cleanup - void shutdown(); - - // Disable copy/move - Loader(const Loader&) = delete; + Loader(const Loader&) = delete; // Deleted copy/move constructors auto operator=(const Loader&) -> Loader& = delete; Loader(Loader&&) = delete; auto operator=(Loader&&) -> Loader& = delete; @@ -52,18 +37,12 @@ class Loader { Loader() = default; ~Loader() = default; - // Load from filesystem - static auto loadFromFilesystem(const std::string& filepath) -> std::vector; - - // Check if file exists on filesystem + static auto loadFromFilesystem(const std::string& filepath) -> std::vector; // Filesystem helpers static auto fileExistsOnFilesystem(const std::string& filepath) -> bool; - // Member data - std::unique_ptr resource_pack_; + std::unique_ptr resource_pack_; // Member variables bool fallback_to_files_{true}; bool initialized_{false}; }; } // namespace Resource - -#endif // RESOURCE_LOADER_HPP diff --git a/source/core/resources/resource_pack.cpp b/source/core/resources/resource_pack.cpp index 93e8507..6222f3f 100644 --- a/source/core/resources/resource_pack.cpp +++ b/source/core/resources/resource_pack.cpp @@ -64,11 +64,12 @@ auto Pack::addFile(const std::string& filepath, const std::string& pack_name) return false; } - ResourceEntry entry; - entry.filename = pack_name; - entry.offset = data_.size(); - entry.size = file_data.size(); - entry.checksum = calculateChecksum(file_data); + ResourceEntry entry{ + .filename = pack_name, + .offset = data_.size(), + .size = file_data.size(), + .checksum = calculateChecksum(file_data) + }; // Append file data to the data block data_.insert(data_.end(), file_data.begin(), file_data.end()); @@ -200,7 +201,7 @@ auto Pack::loadPack(const std::string& pack_file) -> bool { file.read(filename.data(), name_len); // Read entry data - ResourceEntry entry; + ResourceEntry entry{}; entry.filename = filename; file.read(reinterpret_cast(&entry.offset), sizeof(entry.offset)); file.read(reinterpret_cast(&entry.size), sizeof(entry.size)); diff --git a/source/core/resources/resource_pack.hpp b/source/core/resources/resource_pack.hpp index 85fc87d..cbfcf21 100644 --- a/source/core/resources/resource_pack.hpp +++ b/source/core/resources/resource_pack.hpp @@ -1,9 +1,7 @@ // resource_pack.hpp // Resource pack file format and management for JailDoctor's Dilemma -// Based on Coffee Crisis Arcade Edition resource pack system -#ifndef RESOURCE_PACK_HPP -#define RESOURCE_PACK_HPP +#pragma once #include #include @@ -15,10 +13,10 @@ namespace Resource { // 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{0}; // Byte offset in data block + uint64_t size{0}; // Size in bytes + uint32_t checksum{0}; // CRC32 checksum for verification }; // Resource pack file format @@ -30,65 +28,41 @@ class Pack { Pack() = default; ~Pack() = default; - // Disable copy/move - Pack(const Pack&) = delete; + Pack(const Pack&) = delete; // Deleted copy/move constructors auto operator=(const Pack&) -> Pack& = delete; Pack(Pack&&) = delete; auto operator=(Pack&&) -> Pack& = delete; - // Add a single file to the pack - auto addFile(const std::string& filepath, const std::string& pack_name) -> bool; + auto addFile(const std::string& filepath, const std::string& pack_name) -> bool; // Building packs + 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; - - // Load a pack from a file + auto savePack(const std::string& pack_file) -> bool; // Pack I/O auto loadPack(const std::string& pack_file) -> bool; - // Get a resource by name - auto getResource(const std::string& filename) -> std::vector; - - // Check if a resource exists + auto getResource(const std::string& filename) -> std::vector; // Resource access auto hasResource(const std::string& filename) const -> bool; - - // Get list of all resources auto getResourceList() const -> std::vector; - // Check if pack is loaded - auto isLoaded() const -> bool { return loaded_; } - - // Get pack statistics + auto isLoaded() const -> bool { return loaded_; } // Status queries 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; + auto calculatePackChecksum() const -> uint32_t; // Validation private: - static constexpr std::array MAGIC_HEADER = {'J', 'D', 'D', 'I'}; + static constexpr std::array MAGIC_HEADER = {'J', 'D', 'D', 'I'}; // Pack format constants 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& data) -> uint32_t; + static auto calculateChecksum(const std::vector& data) -> uint32_t; // Utility methods - // XOR encryption/decryption - static void encryptData(std::vector& data, const std::string& key); + static void encryptData(std::vector& data, const std::string& key); // Encryption/decryption static void decryptData(std::vector& data, const std::string& key); - // Read file from disk - static auto readFile(const std::string& filepath) -> std::vector; + static auto readFile(const std::string& filepath) -> std::vector; // File I/O - // Member data - std::unordered_map resources_; - std::vector data_; // Encrypted data block + std::unordered_map resources_{}; // Member variables + std::vector data_{}; // Encrypted data block bool loaded_{false}; }; } // namespace Resource - -#endif // RESOURCE_PACK_HPP diff --git a/tools/linter/cppcheck-result-warning-style-performance.txt b/tools/linter/cppcheck-result-warning-style-performance.txt index a31d8a0..d135b7e 100644 --- a/tools/linter/cppcheck-result-warning-style-performance.txt +++ b/tools/linter/cppcheck-result-warning-style-performance.txt @@ -1,3 +1,3 @@ -/home/sergio/gitea/jaildoctors_dilemma/source/utils/utils.hpp:8:1: error: syntax error [syntaxError] -enum class PaletteColor : Uint8 { -^ +source/core/resources/resource_pack.cpp:19:18: style: Consider using std::accumulate algorithm instead of a raw loop. [useStlAlgorithm] + checksum = ((checksum << 5) + checksum) + byte; + ^