#pragma once #include #include #include #include #include "core/resources/resource_types.hpp" namespace Resource { // Cache singleton: precarga + decode dels assets llistats al // `Resource::List`. Implementa carrega incremental amb pressupost // de temps per frame (`loadStep`) per a poder mostrar una barra de // progrés des de l'escena `BootLoader`. class Cache { public: static void init(); static void destroy(); static auto get() -> Cache*; Cache(const Cache&) = delete; auto operator=(const Cache&) -> Cache& = delete; // Getters: throw runtime_error si el nom no existeix al cache. auto getMusic(const std::string& name) -> JA_Music_t*; auto getSound(const std::string& name) -> JA_Sound_t*; auto getSurfacePixels(const std::string& name) -> const std::vector&; auto getPaletteBytes(const std::string& name) -> const std::vector&; auto getTextFile(const std::string& name) -> const std::vector&; // Loader incremental. void beginLoad(); auto loadStep(int budget_ms) -> bool; // true → DONE [[nodiscard]] auto isLoadDone() const -> bool { return stage_ == LoadStage::DONE; } [[nodiscard]] auto getProgress() const -> float; // 0.0..1.0 [[nodiscard]] auto getCurrentLoadingName() const -> const std::string& { return current_loading_name_; } private: Cache() = default; ~Cache() = default; enum class LoadStage { MUSICS, SOUNDS, BITMAPS, TEXT_FILES, DONE, }; void calculateTotal(); void loadOneMusic(size_t index); void loadOneSound(size_t index); void loadOneBitmap(size_t index); void loadOneTextFile(size_t index); std::vector musics_; std::vector sounds_; std::vector surfaces_; std::vector text_files_; LoadStage stage_{LoadStage::DONE}; size_t stage_index_{0}; int total_count_{0}; int loaded_count_{0}; std::string current_loading_name_; static Cache* instance; }; } // namespace Resource