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;
#else
// 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
}

View File

@@ -17,7 +17,6 @@
AssetsCache::AssetsCache()
: _isDirty(false)
, _registry(4096)
, _pathsMapping(256)
{
}
@@ -93,8 +92,8 @@ void AssetsCache::Init()
#if ENABLE_ASSETS_DISCOVERY
stream->Read(&e.FileModified);
#else
DateTime tmp1;
stream->Read(&tmp1);
DateTime tmp1;
stream->Read(&tmp1);
#endif
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
stream->Write(&e.FileModified);
#else
stream->WriteInt64(0);
stream->WriteInt64(0);
#endif
index++;
@@ -233,9 +232,19 @@ bool AssetsCache::Save(const StringView& path, const Registry& entries, const Pa
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)
@@ -587,8 +596,8 @@ bool AssetsCache::IsEntryValid(Entry& e)
#else
// In game we don't care about it because all cached asset entries are valid (precached)
// Skip only entries with missing file
return e.Info.Path.HasChars();
// Skip only entries with missing file
return e.Info.Path.HasChars();
#endif
}

View File

@@ -129,11 +129,11 @@ public:
public:
/// <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>
/// <param name="id">The asset id.</param>
/// <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>
/// Finds the asset info by path.

View File

@@ -46,7 +46,7 @@ const String& JsonAssetBase::GetPath() const
return _path;
#else
// 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
}