diff --git a/Flax.flaxproj b/Flax.flaxproj index fbf48cc2b..263ba739f 100644 --- a/Flax.flaxproj +++ b/Flax.flaxproj @@ -3,7 +3,7 @@ "Version": { "Major": 1, "Minor": 6, - "Build": 6345 + "Build": 6346 }, "Company": "Flax", "Copyright": "Copyright (c) 2012-2023 Wojciech Figat. All rights reserved.", diff --git a/Source/Engine/Content/Cache/AssetsCache.cpp b/Source/Engine/Content/Cache/AssetsCache.cpp index ddb7159f9..c9a10f721 100644 --- a/Source/Engine/Content/Cache/AssetsCache.cpp +++ b/Source/Engine/Content/Cache/AssetsCache.cpp @@ -15,15 +15,8 @@ #include "Engine/Engine/Globals.h" #include "FlaxEngine.Gen.h" -AssetsCache::AssetsCache() - : _isDirty(false) - , _registry(4096) -{ -} - void AssetsCache::Init() { - // Cache data Entry e; int32 count; const DateTime loadStartTime = DateTime::Now(); @@ -32,13 +25,11 @@ void AssetsCache::Init() #else _path = Globals::ProjectContentFolder / TEXT("AssetsCache.dat"); #endif - LOG(Info, "Loading Asset Cache {0}...", _path); // Check if assets registry exists if (!FileSystem::FileExists(_path)) { - // Back _isDirty = true; LOG(Warning, "Cannot find assets cache file"); return; @@ -49,7 +40,6 @@ void AssetsCache::Init() DeleteMe deleteStream(stream); // Load version - // Note: every Engine build is using different assets cache int32 version; stream->ReadInt32(&version); if (version != FLAXENGINE_VERSION_BUILD) @@ -58,24 +48,28 @@ void AssetsCache::Init() return; } - // Load Engine workspace path - String workspacePath; - stream->ReadString(&workspacePath, -410); + // Load paths + String enginePath, projectPath; + stream->ReadString(&enginePath, -410); + stream->ReadString(&projectPath, -410); // Flags AssetsCacheFlags flags; stream->ReadInt32((int32*)&flags); - // Check if other engine instance used this cache (cache depends on engine build and install location) - // Skip it for relative paths mode - if (!(flags & AssetsCacheFlags::RelativePaths) && workspacePath != Globals::StartupFolder) + // Check if other workspace instance used this cache + if (EnumHasNoneFlags(flags, AssetsCacheFlags::RelativePaths) && enginePath != Globals::StartupFolder) { - LOG(Warning, "Assets cache generated by the different engine installation in \'{0}\'", workspacePath); + LOG(Warning, "Assets cache generated by the different {1} installation in \'{0}\'", enginePath, TEXT("engine")); + return; + } + if (EnumHasNoneFlags(flags, AssetsCacheFlags::RelativePaths) && projectPath != Globals::ProjectFolder) + { + LOG(Warning, "Assets cache generated by the different {1} installation in \'{0}\'", projectPath, TEXT("project")); return; } ScopeLock lock(_locker); - _isDirty = false; // Load elements count @@ -103,15 +97,11 @@ void AssetsCache::Init() e.Info.Path = Globals::StartupFolder / e.Info.Path; } - // Validate entry - if (!IsEntryValid(e)) - { - // Reject + // Use only valid entries + if (IsEntryValid(e)) + _registry.Add(e.Info.ID, e); + else rejectedCount++; - continue; - } - - _registry.Add(e.Info.ID, e); } // Paths mapping @@ -148,7 +138,6 @@ void AssetsCache::Init() } } - // End const int32 loadTimeInMs = static_cast((DateTime::Now() - loadStartTime).GetTotalMilliseconds()); LOG(Info, "Asset Cache loaded {0} entries in {1} ms ({2} rejected)", _registry.Count(), loadTimeInMs, rejectedCount); } @@ -188,8 +177,9 @@ bool AssetsCache::Save(const StringView& path, const Registry& entries, const Pa // Version stream->WriteInt32(FLAXENGINE_VERSION_BUILD); - // Engine workspace path + // Paths stream->WriteString(Globals::StartupFolder, -410); + stream->WriteString(Globals::ProjectFolder, -410); // Flags stream->WriteInt32((int32)flags); @@ -202,7 +192,6 @@ bool AssetsCache::Save(const StringView& path, const Registry& entries, const Pa for (auto i = entries.Begin(); i.IsNotEnd(); ++i) { auto& e = i->Value; - stream->Write(e.Info.ID); stream->WriteString(e.Info.TypeName, index - 13); stream->WriteString(e.Info.Path, index); @@ -211,7 +200,6 @@ bool AssetsCache::Save(const StringView& path, const Registry& entries, const Pa #else stream->WriteInt64(0); #endif - index++; } @@ -222,7 +210,6 @@ bool AssetsCache::Save(const StringView& path, const Registry& entries, const Pa { stream->Write(i->Value); stream->WriteString(i->Key, index + 73); - index++; } diff --git a/Source/Engine/Content/Cache/AssetsCache.h b/Source/Engine/Content/Cache/AssetsCache.h index 4f12c0d22..6dd9471e3 100644 --- a/Source/Engine/Content/Cache/AssetsCache.h +++ b/Source/Engine/Content/Cache/AssetsCache.h @@ -74,7 +74,7 @@ public: typedef Dictionary PathsMapping; private: - bool _isDirty; + bool _isDirty = false; CriticalSection _locker; Registry _registry; PathsMapping _pathsMapping; @@ -82,15 +82,8 @@ private: public: /// - /// Initializes a new instance of the class. + /// Gets amount of registered assets. /// - AssetsCache(); - -public: - /// - /// Gets amount of registered assets - /// - /// Registry size int32 Size() const { _locker.Lock();