| 1 | //************************************ bs::framework - Copyright 2018 Marko Pintera **************************************// |
| 2 | //*********** Licensed under the MIT license. See LICENSE.md for full terms. This notice is not to be removed. ***********// |
| 3 | #include "Resources/BsGameResourceManager.h" |
| 4 | #include "Private/RTTI/BsResourceMappingRTTI.h" |
| 5 | #include "FileSystem/BsFileSystem.h" |
| 6 | |
| 7 | namespace bs |
| 8 | { |
| 9 | void ResourceMapping::add(const Path& from, const Path& to) |
| 10 | { |
| 11 | mMapping[from] = to; |
| 12 | } |
| 13 | |
| 14 | SPtr<ResourceMapping> ResourceMapping::create() |
| 15 | { |
| 16 | return bs_shared_ptr_new<ResourceMapping>(); |
| 17 | } |
| 18 | |
| 19 | RTTITypeBase* ResourceMapping::getRTTIStatic() |
| 20 | { |
| 21 | return ResourceMappingRTTI::instance(); |
| 22 | } |
| 23 | |
| 24 | RTTITypeBase* ResourceMapping::getRTTI() const |
| 25 | { |
| 26 | return getRTTIStatic(); |
| 27 | } |
| 28 | |
| 29 | HResource StandaloneResourceLoader::load(const Path& path, ResourceLoadFlags flags, bool async) const |
| 30 | { |
| 31 | auto iterFind = mMapping.find(path); |
| 32 | if(iterFind != mMapping.end()) |
| 33 | { |
| 34 | if(!async) |
| 35 | return gResources().load(iterFind->second, flags); |
| 36 | else |
| 37 | return gResources().loadAsync(iterFind->second, flags); |
| 38 | } |
| 39 | |
| 40 | if (!async) |
| 41 | return gResources().load(path, flags); |
| 42 | else |
| 43 | return gResources().loadAsync(path, flags); |
| 44 | } |
| 45 | |
| 46 | void StandaloneResourceLoader::setMapping(const SPtr<ResourceMapping>& mapping) |
| 47 | { |
| 48 | mMapping = mapping->getMap(); |
| 49 | } |
| 50 | |
| 51 | GameResourceManager::GameResourceManager() |
| 52 | :mLoader(bs_shared_ptr_new<StandaloneResourceLoader>()) |
| 53 | { |
| 54 | |
| 55 | } |
| 56 | |
| 57 | HResource GameResourceManager::load(const Path& path, ResourceLoadFlags flags, bool async) const |
| 58 | { |
| 59 | return mLoader->load(path, flags, async); |
| 60 | } |
| 61 | |
| 62 | void GameResourceManager::setMapping(const SPtr<ResourceMapping>& mapping) |
| 63 | { |
| 64 | mLoader->setMapping(mapping); |
| 65 | } |
| 66 | |
| 67 | void GameResourceManager::setLoader(const SPtr<IGameResourceLoader>& loader) |
| 68 | { |
| 69 | mLoader = loader; |
| 70 | |
| 71 | if (mLoader == nullptr) |
| 72 | mLoader = bs_shared_ptr_new<StandaloneResourceLoader>(); |
| 73 | } |
| 74 | } |