#pragma once #include #include #include #include #include #include #include "asset.h" namespace engineapi { class AssetManager { public: struct AssetWrap { Asset& asset; uint32_t count; AssetWrap(Asset& asset): asset(asset),count(0) { } }; private: std::map mAssetMap; public: template TAsset* LoadAsset(const std::string& asset_url,uint32_t flags) { std::filesystem::path asset_path = getFullPath(asset_url); auto it = mAssetMap.find(asset_path.string()); if (it != mAssetMap.end()) { if (it->second.asset.IsShared()) { return &(it->second.asset); } if (it->second.asset.IsCopyed()) { TAsset* asset = new TAsset(asset_path.string(), flags); *asset = it->second.asset; return asset; } } TAsset* asset = new TAsset(asset_path.string(), flags); if (asset->IsShared() || asset->IsCopyed()) { mAssetMap.emplace(asset_path.string(), *asset); } if (asset->IsAsync()) { //todo: AsyncLoad asset->SyncLoad(); } else { asset->SyncLoad(); } return asset; } std::filesystem::path getFullPath(const std::string& relative_path) const; }; }