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/BsResource.h" |
4 | #include "Private/RTTI/BsResourceRTTI.h" |
5 | #include "Resources/BsResourceMetaData.h" |
6 | |
7 | namespace bs |
8 | { |
9 | Resource::Resource(bool initializeOnRenderThread) |
10 | :CoreObject(initializeOnRenderThread), mSize(0), mKeepSourceData(true) |
11 | { |
12 | mMetaData = bs_shared_ptr_new<ResourceMetaData>(); |
13 | } |
14 | |
15 | const String& Resource::getName() const |
16 | { |
17 | return mMetaData->displayName; |
18 | } |
19 | |
20 | void Resource::setName(const String& name) |
21 | { |
22 | mMetaData->displayName = name; |
23 | } |
24 | |
25 | void Resource::getResourceDependencies(FrameVector<HResource>& dependencies) const |
26 | { |
27 | Lock lock(mDependenciesMutex); |
28 | |
29 | for(auto& dependency : mDependencies) |
30 | { |
31 | if(dependency != nullptr) |
32 | dependencies.push_back(static_resource_cast<Resource>(dependency)); |
33 | } |
34 | } |
35 | |
36 | bool Resource::areDependenciesLoaded() const |
37 | { |
38 | Lock lock(mDependenciesMutex); |
39 | bs_frame_mark(); |
40 | |
41 | bool areLoaded = true; |
42 | { |
43 | for (auto& dependency : mDependencies) |
44 | { |
45 | if (dependency != nullptr && !dependency.isLoaded()) |
46 | { |
47 | areLoaded = false; |
48 | break; |
49 | } |
50 | } |
51 | } |
52 | |
53 | bs_frame_clear(); |
54 | return areLoaded; |
55 | } |
56 | |
57 | void Resource::addResourceDependency(const HResource& resource) |
58 | { |
59 | if(resource == nullptr) |
60 | return; |
61 | |
62 | Lock lock(mDependenciesMutex); |
63 | mDependencies.push_back(resource.getWeak()); |
64 | } |
65 | |
66 | void Resource::removeResourceDependency(const HResource& resource) |
67 | { |
68 | Lock lock(mDependenciesMutex); |
69 | mDependencies.erase(std::remove(mDependencies.begin(), mDependencies.end(), resource.getWeak()), |
70 | mDependencies.end()); |
71 | } |
72 | |
73 | RTTITypeBase* Resource::getRTTIStatic() |
74 | { |
75 | return ResourceRTTI::instance(); |
76 | } |
77 | |
78 | RTTITypeBase* Resource::getRTTI() const |
79 | { |
80 | return Resource::getRTTIStatic(); |
81 | } |
82 | } |