#pragma once #include "CComponent.h" #include "CResource.h" #include "CResourcesCache.h" #include "CThreadPool.h" #include #include #include #include #include class CResourcesManager : public CComponent { public: using IdentUnit = std::pair; //Type, Name struct PairHash { size_t operator()(const std::pair& p) const noexcept { size_t h1 = std::hash{}(p.first); size_t h2 = std::hash{}(p.second); return h1 ^ (h2 << 1); } }; std::unordered_map, PairHash> Resources; CResourcesManager(); void V_Update() override; void RegisterResource(const std::shared_ptr& res); void StopResource(CResource* res); void V_DeInit() override; std::shared_ptr GetOrCreate(const std::string& type, const std::string& path, bool startPipeline = true); std::shared_ptr LoadResource(const std::string& type, const std::string& path); bool IsResourceExist(const std::string& type, const std::string& name); std::shared_ptr GetResource(const std::string& type, const std::string& name); template std::shared_ptr GetResourceTyped(const std::string& type, const std::string& name) { return std::dynamic_pointer_cast(GetResource(type, name)); } bool V_ScriptInit(std::shared_ptr state, sol::table table) override; CResourcesCache Cache; CThreadPool AsyncLoadingPool; CLoadPipelinesCache PipelinesCache; DEFINE_SOL_USERTYPE(); DEFINE_COMPONENT(); std::mutex RetrieveMutex; };