From 058e23f3ee544cf4ef89b388bf3f179ad66b8866 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 8 Oct 2021 15:31:13 +0200 Subject: [PATCH] Add `Content.GetAllAssets` to get all asset ids in project --- Source/Engine/Content/Cache/AssetsCache.cpp | 9 +++++++-- Source/Engine/Content/Cache/AssetsCache.h | 6 ++++++ Source/Engine/Content/Content.cpp | 7 +++++++ Source/Engine/Content/Content.h | 6 ++++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/Source/Engine/Content/Cache/AssetsCache.cpp b/Source/Engine/Content/Cache/AssetsCache.cpp index bd416fc8e..1cb7481d7 100644 --- a/Source/Engine/Content/Cache/AssetsCache.cpp +++ b/Source/Engine/Content/Cache/AssetsCache.cpp @@ -328,12 +328,17 @@ bool AssetsCache::FindAsset(const Guid& id, AssetInfo& info) return result; } +void AssetsCache::GetAll(Array& result) const +{ + PROFILE_CPU(); + ScopeLock lock(_locker); + _registry.GetKeys(result); +} + void AssetsCache::GetAllByTypeName(const StringView& typeName, Array& result) const { PROFILE_CPU(); - ScopeLock lock(_locker); - for (auto i = _registry.Begin(); i.IsNotEnd(); ++i) { if (i->Value.Info.TypeName == typeName) diff --git a/Source/Engine/Content/Cache/AssetsCache.h b/Source/Engine/Content/Cache/AssetsCache.h index cee2e0e8f..6364e09d2 100644 --- a/Source/Engine/Content/Cache/AssetsCache.h +++ b/Source/Engine/Content/Cache/AssetsCache.h @@ -173,6 +173,12 @@ public: return FindAsset(id, info); } + /// + /// Gets the asset ids. + /// + /// The result array. + void GetAll(Array& result) const; + /// /// Gets the asset ids that match the given typename. /// diff --git a/Source/Engine/Content/Content.cpp b/Source/Engine/Content/Content.cpp index abe40e285..3f5de3a0a 100644 --- a/Source/Engine/Content/Content.cpp +++ b/Source/Engine/Content/Content.cpp @@ -322,6 +322,13 @@ bool Content::GetAssetInfo(const StringView& path, AssetInfo& info) #endif } +Array Content::GetAllAssets() +{ + Array result; + Cache.GetAll(result); + return result; +} + Array Content::GetAllAssetsByType(const MClass* type) { Array result; diff --git a/Source/Engine/Content/Content.h b/Source/Engine/Content/Content.h index c8e3cad90..d0a277de8 100644 --- a/Source/Engine/Content/Content.h +++ b/Source/Engine/Content/Content.h @@ -73,6 +73,12 @@ public: /// True if found any asset, otherwise false. API_FUNCTION() static bool GetAssetInfo(const StringView& path, API_PARAM(Out) AssetInfo& info); + /// + /// Finds all the asset IDs. Uses asset registry. + /// + /// The list of all asset IDs. + API_FUNCTION() static Array GetAllAssets(); + /// /// Finds all the asset IDs by type (exact type, without inheritance checks). Uses asset registry. ///