Fix asset paths lookup in build

This commit is contained in:
Wojtek Figat
2021-05-14 10:33:08 +02:00
parent c95e5b0611
commit fdf6306060
4 changed files with 21 additions and 12 deletions

View File

@@ -450,7 +450,7 @@ const String& BinaryAsset::GetPath() const
return Storage ? Storage->GetPath() : String::Empty; return Storage ? Storage->GetPath() : String::Empty;
#else #else
// In build all assets are packed into packages so use ID for original path lookup // In build all assets are packed into packages so use ID for original path lookup
return Content::GetRegistry()->GetAssetPath(_id); return Content::GetRegistry()->GetEditorAssetPath(_id);
#endif #endif
} }

View File

@@ -17,7 +17,6 @@
AssetsCache::AssetsCache() AssetsCache::AssetsCache()
: _isDirty(false) : _isDirty(false)
, _registry(4096) , _registry(4096)
, _pathsMapping(256)
{ {
} }
@@ -93,8 +92,8 @@ void AssetsCache::Init()
#if ENABLE_ASSETS_DISCOVERY #if ENABLE_ASSETS_DISCOVERY
stream->Read(&e.FileModified); stream->Read(&e.FileModified);
#else #else
DateTime tmp1; DateTime tmp1;
stream->Read(&tmp1); stream->Read(&tmp1);
#endif #endif
if (flags & AssetsCacheFlags::RelativePaths && e.Info.Path.HasChars()) if (flags & AssetsCacheFlags::RelativePaths && e.Info.Path.HasChars())
@@ -209,7 +208,7 @@ bool AssetsCache::Save(const StringView& path, const Registry& entries, const Pa
#if ENABLE_ASSETS_DISCOVERY #if ENABLE_ASSETS_DISCOVERY
stream->Write(&e.FileModified); stream->Write(&e.FileModified);
#else #else
stream->WriteInt64(0); stream->WriteInt64(0);
#endif #endif
index++; index++;
@@ -233,9 +232,19 @@ bool AssetsCache::Save(const StringView& path, const Registry& entries, const Pa
return false; return false;
} }
const String& AssetsCache::GetAssetPath(const Guid& id) const const String& AssetsCache::GetEditorAssetPath(const Guid& id) const
{ {
return _registry[id].Info.Path; #if USE_EDITOR
auto e = _registry.TryGet(id);
return e ? e->Info.Path : String::Empty;
#else
for (auto& e : _pathsMapping)
{
if (e.Value == id)
return e.Key;
}
return String::Empty;
#endif
} }
bool AssetsCache::FindAsset(const StringView& path, AssetInfo& info) bool AssetsCache::FindAsset(const StringView& path, AssetInfo& info)
@@ -587,8 +596,8 @@ bool AssetsCache::IsEntryValid(Entry& e)
#else #else
// In game we don't care about it because all cached asset entries are valid (precached) // In game we don't care about it because all cached asset entries are valid (precached)
// Skip only entries with missing file // Skip only entries with missing file
return e.Info.Path.HasChars(); return e.Info.Path.HasChars();
#endif #endif
} }

View File

@@ -129,11 +129,11 @@ public:
public: public:
/// <summary> /// <summary>
/// Finds the asset path by id. /// Finds the asset path by id. In editor it returns the actual asset path, at runtime it returns the mapped asset path.
/// </summary> /// </summary>
/// <param name="id">The asset id.</param> /// <param name="id">The asset id.</param>
/// <returns>The asset path, or empty if failed to find.</returns> /// <returns>The asset path, or empty if failed to find.</returns>
const String& GetAssetPath(const Guid& id) const; const String& GetEditorAssetPath(const Guid& id) const;
/// <summary> /// <summary>
/// Finds the asset info by path. /// Finds the asset info by path.

View File

@@ -46,7 +46,7 @@ const String& JsonAssetBase::GetPath() const
return _path; return _path;
#else #else
// In build all assets are packed into packages so use ID for original path lookup // In build all assets are packed into packages so use ID for original path lookup
return Content::GetRegistry()->GetAssetPath(_id); return Content::GetRegistry()->GetEditorAssetPath(_id);
#endif #endif
} }