Skip to content

Commit 50f9599

Browse files
committed
asset manager method to check asset
1 parent 920b4ac commit 50f9599

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

sources/include/cage-core/assetsManager.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ namespace cage
4747
return get_(Scheme, assetId).template cast<T>();
4848
}
4949

50+
// returns true if the asset exists and is successfully loaded
51+
bool check(uint32 assetId) const;
52+
5053
// end thread-safe methods
5154

5255
void listen(const String &address = "localhost", uint16 port = 65042, uint64 listenerPeriod = 100000);

sources/libcore/assets/assetsManager.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,18 @@ namespace cage
587587
return name++;
588588
}
589589

590+
bool AssetsManager::check(uint32 assetId) const
591+
{
592+
CAGE_ASSERT(assetId != 0 && assetId != m);
593+
const AssetsManagerImpl *impl = (const AssetsManagerImpl *)this;
594+
const auto &publicIndex = impl->publicIndex;
595+
ScopeLock lock(impl->publicMutex, ReadLockTag());
596+
auto it = publicIndex.find(assetId);
597+
if (it == publicIndex.end())
598+
return false; // not found
599+
return !it->second->failed;
600+
}
601+
590602
void AssetsManager::listen(const String &address, uint16 port, uint64 listenerPeriod)
591603
{
592604
class AssetListenerImpl

0 commit comments

Comments
 (0)