@@ -5,6 +5,7 @@
|
||||
#include "Engine/Graphics/GPUContext.h"
|
||||
#include "Engine/Threading/Threading.h"
|
||||
#include "Engine/Graphics/RenderTools.h"
|
||||
#include "Engine/Content/Content.h"
|
||||
#include "Engine/Content/Factories/BinaryAssetFactory.h"
|
||||
#include "Engine/ContentImporters/AssetsImportingManager.h"
|
||||
#include "Engine/Content/Upgraders/TextureAssetUpgrader.h"
|
||||
@@ -92,15 +93,12 @@ SpriteHandle PreviewsCache::FindSlot(const Guid& id)
|
||||
{
|
||||
if (WaitForLoaded())
|
||||
return SpriteHandle::Invalid;
|
||||
|
||||
// Find entry
|
||||
int32 index;
|
||||
if (_assets.Find(id, index))
|
||||
{
|
||||
const String spriteName = StringUtils::ToString(index);
|
||||
return FindSprite(spriteName);
|
||||
}
|
||||
|
||||
return SpriteHandle::Invalid;
|
||||
}
|
||||
|
||||
@@ -114,6 +112,17 @@ Asset::LoadResult PreviewsCache::load()
|
||||
return LoadResult::Failed;
|
||||
_assets.Set(previewsMetaChunk->Get<Guid>(), ASSETS_ICONS_PER_ATLAS);
|
||||
|
||||
// Verify if cached assets still exist (don't store thumbnails for removed files)
|
||||
AssetInfo assetInfo;
|
||||
for (Guid& id : _assets)
|
||||
{
|
||||
if (id.IsValid() && Content::GetAsset(id) == nullptr && !Content::GetAssetInfo(id, assetInfo))
|
||||
{
|
||||
// Free slot (no matter the texture contents)
|
||||
id = Guid::Empty;
|
||||
}
|
||||
}
|
||||
|
||||
// Setup atlas sprites array
|
||||
Sprite sprite;
|
||||
sprite.Area.Size = static_cast<float>(ASSET_ICON_SIZE) / ASSETS_ICONS_ATLAS_SIZE;
|
||||
@@ -162,7 +171,7 @@ SpriteHandle PreviewsCache::OccupySlot(GPUTexture* source, const Guid& id)
|
||||
if (WaitForLoaded())
|
||||
return SpriteHandle::Invalid;
|
||||
|
||||
// Find free slot and for that asset
|
||||
// Find this asset slot or use the first empty
|
||||
int32 index = _assets.Find(id);
|
||||
if (index == INVALID_INDEX)
|
||||
index = _assets.Find(Guid::Empty);
|
||||
@@ -201,14 +210,12 @@ bool PreviewsCache::ReleaseSlot(const Guid& id)
|
||||
{
|
||||
bool result = false;
|
||||
ScopeLock lock(Locker);
|
||||
|
||||
int32 index = _assets.Find(id);
|
||||
if (index != INVALID_INDEX)
|
||||
{
|
||||
_assets[index] = Guid::Empty;
|
||||
result = true;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,15 +21,11 @@ namespace FlaxEditor.Content.Thumbnails
|
||||
/// </summary>
|
||||
public const float MinimumRequiredResourcesQuality = 0.8f;
|
||||
|
||||
// TODO: free atlas slots for deleted assets
|
||||
|
||||
private readonly List<PreviewsCache> _cache = new List<PreviewsCache>(4);
|
||||
private readonly string _cacheFolder;
|
||||
|
||||
private DateTime _lastFlushTime;
|
||||
|
||||
private readonly List<ThumbnailRequest> _requests = new List<ThumbnailRequest>(128);
|
||||
private readonly PreviewRoot _guiRoot = new PreviewRoot();
|
||||
private DateTime _lastFlushTime;
|
||||
private RenderTask _task;
|
||||
private GPUTexture _output;
|
||||
|
||||
@@ -88,7 +84,6 @@ namespace FlaxEditor.Content.Thumbnails
|
||||
}
|
||||
}
|
||||
|
||||
// Add request
|
||||
AddRequest(assetItem, proxy);
|
||||
}
|
||||
}
|
||||
@@ -118,12 +113,10 @@ namespace FlaxEditor.Content.Thumbnails
|
||||
for (int i = 0; i < _cache.Count; i++)
|
||||
{
|
||||
if (_cache[i].ReleaseSlot(assetItem.ID))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal static bool HasMinimumQuality(TextureBase asset)
|
||||
{
|
||||
@@ -198,13 +191,7 @@ namespace FlaxEditor.Content.Thumbnails
|
||||
/// <inheritdoc />
|
||||
void IContentItemOwner.OnItemDeleted(ContentItem item)
|
||||
{
|
||||
if (item is AssetItem assetItem)
|
||||
{
|
||||
lock (_requests)
|
||||
{
|
||||
RemoveRequest(assetItem);
|
||||
}
|
||||
}
|
||||
DeletePreview(item);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
@@ -494,10 +481,7 @@ namespace FlaxEditor.Content.Thumbnails
|
||||
{
|
||||
// Wait some frames before start generating previews (late init feature)
|
||||
if (Time.TimeSinceStartup < 1.0f || HasAllAtlasesLoaded() == false)
|
||||
{
|
||||
// Back
|
||||
return;
|
||||
}
|
||||
|
||||
lock (_requests)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user