#pragma once #include "delegates.hpp" #include "interfaces/Task.hpp" #include "typedefs.hpp" #include "Assets.hpp" #include "data/dv.hpp" #include "io/fwd.hpp" #include #include #include #include #include #include #include class ResPaths; class AssetsLoader; class Content; class Engine; namespace gui { class GUI; } struct AssetCfg { virtual ~AssetCfg() { } }; struct LayoutCfg : AssetCfg { gui::GUI* gui; scriptenv env; LayoutCfg(gui::GUI* gui, scriptenv env) : gui(gui), env(std::move(env)) {} }; struct SoundCfg : AssetCfg { bool keepPCM; SoundCfg(bool keepPCM) : keepPCM(keepPCM) {} }; struct FontCfg : AssetCfg { int size; FontCfg(int size) : size(size) {} }; enum class AtlasType { ATLAS, SEPARATE }; struct AtlasCfg : AssetCfg { AtlasType type; AtlasCfg(AtlasType type) : type(type) {} }; struct PostEffectCfg : AssetCfg { bool advanced; PostEffectCfg(bool advanced) : advanced(advanced) {} }; struct ModelCfg : AssetCfg { bool squashed; ModelCfg(bool squashed) : squashed(squashed) {} }; using aloader_func = std::function< assetload:: postfunc( AssetsLoader&, const ResPaths&, const std::string&, const std::string&, std::shared_ptr)>; struct aloader_entry { AssetType tag; std::string filename; std::string alias; std::shared_ptr config; }; using AssetFullId = std::pair; struct AssetsLoadInfo { std::map processedEntries; std::multimap referencedAssets; }; class AssetsLoader { public: AssetsLoader(Engine& engine, Assets& assets, const ResPaths& paths); AssetsLoader(const AssetsLoader&) = delete; void addLoader(AssetType tag, aloader_func func); /// @brief Enqueue asset load /// @param tag asset type /// @param filename asset file path /// @param alias internal asset name /// @param settings asset loading settings (based on asset type) void add( AssetType tag, const std::string& filename, const std::string& alias, std::shared_ptr settings = nullptr, bool overwrite = false ); bool hasNext() const; /// @throws assetload::error void loadNext(); std::shared_ptr startTask(runnable onDone, int maxWorkers); const ResPaths& getPaths() const; aloader_func getLoader(AssetType tag); /// @brief Enqueue core and content assets /// @param content engine content void addDefaults(const Content* content); static bool loadExternalTexture( AssetsLoader& loader, const std::string& name, const std::vector& alternatives ); int addReload(const io::path& path); void attachToFile(const io::path& file, AssetFullId assetId); Assets& getAssets(); Engine& getEngine(); private: Engine& engine; Assets& assets; std::map loaders; std::queue entries; std::set enqueued; const ResPaths& paths; AssetsLoadInfo& assetsLoadInfo; void processPreload( AssetType tag, const std::string& name, const dv::value& map ); void processPreloadList(AssetType tag, const dv::value& list); void processPreloadConfig(const io::path& file); void processPreloadConfigs(const Content* content); };