From f3e01e3a318fea8d7065468df09e32c1765bfef8 Mon Sep 17 00:00:00 2001 From: LaG1924 <12997935+LaG1924@users.noreply.github.com> Date: Sun, 5 Aug 2018 18:21:42 +0500 Subject: Refactored AssetManager --- src/AssetManager.hpp | 51 ++++++++------------------------------------------- 1 file changed, 8 insertions(+), 43 deletions(-) (limited to 'src/AssetManager.hpp') diff --git a/src/AssetManager.hpp b/src/AssetManager.hpp index 3975b37..2940b5f 100644 --- a/src/AssetManager.hpp +++ b/src/AssetManager.hpp @@ -119,60 +119,25 @@ struct AssetTexture : Asset { size_t id; }; -class AssetManager { - std::map assetIds; - std::map blockIdToBlockName; - std::unique_ptr assetTree; - std::unique_ptr atlas; -public: - AssetManager(); - - ~AssetManager(); - - void LoadIds(); - - static AssetManager& Instance(); +namespace AssetManager { + void InitAssetManager(); const BlockModel *GetBlockModelByBlockId(BlockId block); std::string GetAssetNameByBlockId(BlockId block); - void ParseBlockModels(); - - void LoadAssets(); + Asset *GetAssetPtr(const std::string &assetName); template - T *GetAsset(const std::string &assetName) { - AssetTreeNode *node; - if (assetName[0] != '/') - node = GetAssetByAssetName('/'+assetName); - else - node = GetAssetByAssetName(assetName); - if (!node) - return nullptr; - return dynamic_cast(node->asset.get()); + T *GetAsset(const std::string &assetName) { + return dynamic_cast(GetAssetPtr(assetName)); } - void ParseAsset(AssetTreeNode &node); - - void ParseAssetBlockModel(AssetTreeNode &node); - void RecursiveWalkAsset(const std::string &assetPath, std::function fnc); AssetTreeNode *GetAssetByAssetName(const std::string &assetName); + + GLuint GetTextureAtlasId(); - void LoadTextures(); - - void ParseAssetTexture(AssetTreeNode &node); - - inline GLuint GetTextureAtlasId() { - return atlas->GetRawTextureId(); - } - - inline TextureCoord GetTexture(const std::string assetName) { - AssetTexture *asset = GetAsset(assetName); - if (!asset) - return {}; - return atlas->GetTexture(asset->id); - } + TextureCoord GetTexture(const std::string assetName); }; -- cgit v1.2.3