Add Content.Stats for assets statistics (replaces Content.AssetCount)

This commit is contained in:
Wojtek Figat
2021-07-07 09:52:37 +02:00
parent 6471f880ac
commit 7985196155
2 changed files with 35 additions and 8 deletions

View File

@@ -360,6 +360,25 @@ String Content::CreateTemporaryAssetPath()
return Globals::TemporaryFolder / (Guid::New().ToString(Guid::FormatType::N) + ASSET_FILES_EXTENSION_WITH_DOT);
}
ContentStats Content::GetStats()
{
ContentStats stats;
AssetsLocker.Lock();
stats.AssetsCount = Assets.Count();
for (auto& e : Assets)
{
if (e.Value->IsLoaded())
stats.LoadedAssetsCount++;
else if (e.Value->LastLoadFailed())
stats.LoadingAssetsCount++;
if (e.Value->IsVirtual())
stats.VirtualAssetsCount++;
}
stats.LoadingAssetsCount = stats.AssetsCount - stats.LoadingAssetsCount - stats.LoadedAssetsCount;
AssetsLocker.Unlock();
return stats;
}
Asset* Content::LoadAsyncInternal(const StringView& internalPath, MClass* type)
{
CHECK_RETURN(type, nullptr);
@@ -430,11 +449,6 @@ Asset* Content::LoadAsync(const StringView& path, const ScriptingTypeHandle& typ
return nullptr;
}
int32 Content::GetAssetCount()
{
return Assets.Count();
}
Array<Asset*> Content::GetAssets()
{
Array<Asset*> assets;

View File

@@ -12,6 +12,20 @@ class FlaxFile;
class IAssetFactory;
class AssetsCache;
// Content and assets statistics container.
API_STRUCT() struct FLAXENGINE_API ContentStats
{
DECLARE_SCRIPTING_TYPE_MINIMAL(ContentStats);
// Amount of asset objects in memory.
API_FIELD() int32 AssetsCount = 0;
// Amount of loaded assets.
API_FIELD() int32 LoadedAssetsCount = 0;
// Amount of loading assets.
API_FIELD() int32 LoadingAssetsCount = 0;
// Amount of virtual assets (don't have representation in file).
API_FIELD() int32 VirtualAssetsCount = 0;
};
/// <summary>
/// Loads and manages assets.
/// </summary>
@@ -92,10 +106,9 @@ public:
public:
/// <summary>
/// Gets amount of the assets (in memory).
/// Gets content statistics.
/// </summary>
/// <returns>Amount of assets in the assets.</returns>
API_PROPERTY() static int32 GetAssetCount();
API_PROPERTY() static ContentStats GetStats();
/// <summary>
/// Gets the assets (loaded or during load).