From fdf6306060ea0145e7c40dbb74e7316ee643c79c Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Fri, 14 May 2021 10:33:08 +0200 Subject: [PATCH] Fix asset paths lookup in build --- Source/Engine/Content/BinaryAsset.cpp | 2 +- Source/Engine/Content/Cache/AssetsCache.cpp | 25 ++++++++++++++------- Source/Engine/Content/Cache/AssetsCache.h | 4 ++-- Source/Engine/Content/JsonAsset.cpp | 2 +- 4 files changed, 21 insertions(+), 12 deletions(-) diff --git a/Source/Engine/Content/BinaryAsset.cpp b/Source/Engine/Content/BinaryAsset.cpp index 7b8066d18..ef22bd3c9 100644 --- a/Source/Engine/Content/BinaryAsset.cpp +++ b/Source/Engine/Content/BinaryAsset.cpp @@ -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 } diff --git a/Source/Engine/Content/Cache/AssetsCache.cpp b/Source/Engine/Content/Cache/AssetsCache.cpp index e6ee03d39..35863be60 100644 --- a/Source/Engine/Content/Cache/AssetsCache.cpp +++ b/Source/Engine/Content/Cache/AssetsCache.cpp @@ -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 } diff --git a/Source/Engine/Content/Cache/AssetsCache.h b/Source/Engine/Content/Cache/AssetsCache.h index 25942faec..cee2e0e8f 100644 --- a/Source/Engine/Content/Cache/AssetsCache.h +++ b/Source/Engine/Content/Cache/AssetsCache.h @@ -129,11 +129,11 @@ public: public: /// - /// 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. /// /// The asset id. /// The asset path, or empty if failed to find. - const String& GetAssetPath(const Guid& id) const; + const String& GetEditorAssetPath(const Guid& id) const; /// /// Finds the asset info by path. diff --git a/Source/Engine/Content/JsonAsset.cpp b/Source/Engine/Content/JsonAsset.cpp index dbec5ad74..44baecb12 100644 --- a/Source/Engine/Content/JsonAsset.cpp +++ b/Source/Engine/Content/JsonAsset.cpp @@ -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 }