| 11 | #include "Engine/Content/Cache/AssetsCache.h" |
| 12 | |
| 13 | bool CollectAssetsStep::Perform(CookingData& data) |
| 14 | { |
| 15 | LOG(Info, "Searching for assets to include in a build. Using {0} root assets.", data.RootAssets.Count()); |
| 16 | data.StepProgress(TEXT("Collecting assets"), 0); |
| 17 | |
| 18 | // Initialize assets queue |
| 19 | Array<Guid> assetsQueue; |
| 20 | assetsQueue.Clear(); |
| 21 | assetsQueue.EnsureCapacity(1024); |
| 22 | for (auto i = data.RootAssets.Begin(); i.IsNotEnd(); ++i) |
| 23 | assetsQueue.Add(i->Item); |
| 24 | |
| 25 | // Iterate through the assets graph |
| 26 | AssetInfo assetInfo; |
| 27 | Array<Guid> references; |
| 28 | Array<String> files; |
| 29 | while (assetsQueue.HasItems()) |
| 30 | { |
| 31 | BUILD_STEP_CANCEL_CHECK; |
| 32 | const Guid assetId = assetsQueue.Dequeue(); |
| 33 | |
| 34 | // Skip already processed or invalid assets |
| 35 | if (!assetId.IsValid() |
| 36 | || !Content::GetRegistry()->FindAsset(assetId, assetInfo) |
| 37 | || data.Assets.Contains(assetId)) |
| 38 | continue; |
| 39 | |
| 40 | // Skip some assets (with no refs and not required to load) |
| 41 | if (assetInfo.TypeName == Texture::TypeName || |
| 42 | assetInfo.TypeName == CubeTexture::TypeName || |
| 43 | assetInfo.TypeName == Shader::TypeName) |
| 44 | { |
| 45 | LOG_STR(Info, assetInfo.Path); |
| 46 | data.Assets.Add(assetId); |
| 47 | continue; |
| 48 | } |
| 49 | |
| 50 | // Load asset |
| 51 | AssetReference<Asset> asset = Content::LoadAsync<Asset>(assetId); |
| 52 | if (asset == nullptr) |
| 53 | continue; |
| 54 | LOG_STR(Info, asset->GetPath()); |
| 55 | data.Assets.Add(assetId); |
| 56 | |
| 57 | // Skip virtual/temporary assets |
| 58 | if (asset->IsVirtual()) |
| 59 | continue; |
| 60 | |
| 61 | // Asset should have loaded data |
| 62 | if (asset->WaitForLoaded()) |
| 63 | continue; |
| 64 | |
| 65 | // Gather asset references |
| 66 | references.Clear(); |
| 67 | asset->Locker.Lock(); |
| 68 | asset->GetReferences(references, files); |
| 69 | asset->Locker.Unlock(); |
| 70 | assetsQueue.Add(references); |
nothing calls this directly
no test coverage detected